diff --git a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/APNGAnimationProvider.cs b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/APNGAnimationProvider.cs index f51feb5..b061cf7 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/APNGAnimationProvider.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/APNGAnimationProvider.cs @@ -21,6 +21,7 @@ using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using LibAPNG; +using QuickLook.Helpers; namespace QuickLook.Plugin.ImageViewer.AnimatedImage { @@ -99,7 +100,7 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage var bitmap = new RenderTargetBitmap( header.Width, header.Height, - 96, 96, + DpiHelper.DefaultDpi, DpiHelper.DefaultDpi, PixelFormats.Pbgra32); bitmap.Render(visual); return bitmap; diff --git a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/ImagePanel.xaml b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/ImagePanel.xaml index 240b2fc..9f50929 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/ImagePanel.xaml +++ b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/ImagePanel.xaml @@ -9,6 +9,12 @@ x:Name="imagePanel" d:DesignHeight="300" d:DesignWidth="300"> + + + + + Always + \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Resources/background.png b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Resources/background.png new file mode 100644 index 0000000..c0b7cbf Binary files /dev/null and b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Resources/background.png differ diff --git a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/Plugin.cs index a37e5ba..2ed378e 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/Plugin.cs @@ -92,7 +92,8 @@ namespace QuickLook.Plugin.PDFViewer { GC.SuppressFinalize(this); - _pdfControl.CurrentPageChanged -= UpdateVindowCaption; + if (_pdfControl != null) + _pdfControl.CurrentPageChanged -= UpdateVindowCaption; _pdfControl?.Dispose(); _pdfControl = null; diff --git a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Plugin.cs index 4bb7e7f..0315b41 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Plugin.cs @@ -90,7 +90,8 @@ namespace QuickLook.Plugin.VideoViewer public void Cleanup() { - _vp.mediaElement.VlcMediaPlayer.Opening -= MarkReady; + if (_vp != null) + _vp.mediaElement.VlcMediaPlayer.Opening -= MarkReady; _vp?.Dispose(); _vp = null; diff --git a/QuickLook/Controls/GlassLayer/GlassLayer.xaml b/QuickLook/Controls/GlassLayer/GlassLayer.xaml index ff03cc7..4cb963e 100644 --- a/QuickLook/Controls/GlassLayer/GlassLayer.xaml +++ b/QuickLook/Controls/GlassLayer/GlassLayer.xaml @@ -10,7 +10,7 @@ - diff --git a/QuickLook/Controls/GlassLayer/GlassLayer.xaml.cs b/QuickLook/Controls/GlassLayer/GlassLayer.xaml.cs index 6331f0d..4ab6149 100644 --- a/QuickLook/Controls/GlassLayer/GlassLayer.xaml.cs +++ b/QuickLook/Controls/GlassLayer/GlassLayer.xaml.cs @@ -18,6 +18,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Media; +using QuickLook.Helpers; namespace QuickLook.Controls.GlassLayer { @@ -29,6 +30,11 @@ namespace QuickLook.Controls.GlassLayer public GlassLayer() { InitializeComponent(); + + var scale = DpiHelper.GetCurrentScaleFactor(); + noiseBrush.Viewport = new Rect(new Size( + noiseBrush.ImageSource.Width / scale.Horizontal, + noiseBrush.ImageSource.Height / scale.Vertical)); } #region public Visual BlurredElement diff --git a/QuickLook/Controls/MainWindowBase.cs b/QuickLook/Controls/MainWindowBase.cs new file mode 100644 index 0000000..c6450f2 --- /dev/null +++ b/QuickLook/Controls/MainWindowBase.cs @@ -0,0 +1,55 @@ +// Copyright © 2017 Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System; +using System.Windows; +using System.Windows.Interop; +using QuickLook.Helpers; + +namespace QuickLook.Controls +{ + public class MainWindowBase : Window + { + public MainWindowBase() + { + WindowStyle = WindowStyle.None; + AllowsTransparency = true; + + SourceInitialized += SourceInitializedHandler; + } + + private void SourceInitializedHandler(object sender, EventArgs e) + { + var handle = new WindowInteropHelper(this).Handle; + var handleSource = HwndSource.FromHwnd(handle); + handleSource?.AddHook(WindowProc); + } + + private static IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) + { + switch (msg) + { + case 0x0024: /* WM_GETMINMAXINFO */ + WindowHelper.WmGetMinMaxInfo(hwnd, lParam); + //handled = true; + break; + } + + return (IntPtr) 0; + } + } +} \ No newline at end of file diff --git a/QuickLook/Converters/WindowStateToThicknessConverter.cs b/QuickLook/Converters/WindowStateToThicknessConverter.cs new file mode 100644 index 0000000..f964a8d --- /dev/null +++ b/QuickLook/Converters/WindowStateToThicknessConverter.cs @@ -0,0 +1,42 @@ +// Copyright © 2017 Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System; +using System.Globalization; +using System.Windows; +using System.Windows.Data; + +namespace QuickLook.Converters +{ + public sealed class WindowStateToThicknessConverter : DependencyObject, IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + var def = parameter as Thickness? ?? new Thickness(); + + if (value == null) + return def; + + return (WindowState) value == WindowState.Maximized ? new Thickness(0) : def; + } + + object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/QuickLook/ExtensionMethods/BitmapExtensions.cs b/QuickLook/ExtensionMethods/BitmapExtensions.cs index b35d6ac..3d79161 100644 --- a/QuickLook/ExtensionMethods/BitmapExtensions.cs +++ b/QuickLook/ExtensionMethods/BitmapExtensions.cs @@ -37,7 +37,7 @@ namespace QuickLook.ExtensionMethods ImageLockMode.ReadOnly, source.PixelFormat); bs = BitmapSource.Create(source.Width, source.Height, source.HorizontalResolution, - source.VerticalResolution, PixelFormats.Bgra32, null, + source.VerticalResolution, ConvertPixelFormat(source.PixelFormat), null, data.Scan0, data.Stride * source.Height, data.Stride); source.UnlockBits(data); @@ -55,5 +55,22 @@ namespace QuickLook.ExtensionMethods return bs; } + + private static System.Windows.Media.PixelFormat ConvertPixelFormat( + System.Drawing.Imaging.PixelFormat sourceFormat) + { + switch (sourceFormat) + { + case System.Drawing.Imaging.PixelFormat.Format24bppRgb: + return PixelFormats.Bgr24; + + case System.Drawing.Imaging.PixelFormat.Format32bppArgb: + return PixelFormats.Bgra32; + + case System.Drawing.Imaging.PixelFormat.Format32bppRgb: + return PixelFormats.Bgr32; + } + return new System.Windows.Media.PixelFormat(); + } } } \ No newline at end of file diff --git a/QuickLook/Helpers/WindowHelper.cs b/QuickLook/Helpers/WindowHelper.cs index f14fb02..5cc4664 100644 --- a/QuickLook/Helpers/WindowHelper.cs +++ b/QuickLook/Helpers/WindowHelper.cs @@ -17,6 +17,7 @@ using System; using System.Diagnostics; +using System.Runtime.InteropServices; using System.Windows; using System.Windows.Forms; using System.Windows.Interop; @@ -99,5 +100,53 @@ namespace QuickLook.Helpers User32.GetWindowLong(window.Handle, User32.GWL_EXSTYLE) | User32.WS_EX_NOACTIVATE); } + + internal static void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam) + { + var mmi = (MinMaxInfo) Marshal.PtrToStructure(lParam, typeof(MinMaxInfo)); + + // Adjust the maximized size and position to fit the work area of the correct monitor + var currentScreen = Screen.FromHandle(hwnd); + var workArea = currentScreen.WorkingArea; + var monitorArea = currentScreen.Bounds; + mmi.ptMaxPosition.x = Math.Abs(workArea.Left - monitorArea.Left); + mmi.ptMaxPosition.y = Math.Abs(workArea.Top - monitorArea.Top); + mmi.ptMaxSize.x = Math.Abs(workArea.Right - workArea.Left); + mmi.ptMaxSize.y = Math.Abs(workArea.Bottom - workArea.Top); + + Marshal.StructureToPtr(mmi, lParam, true); + } + + [StructLayout(LayoutKind.Sequential)] + public struct MinMaxInfo + { + public POINT ptReserved; + public POINT ptMaxSize; + public POINT ptMaxPosition; + public POINT ptMinTrackSize; + public POINT ptMaxTrackSize; + } + + [StructLayout(LayoutKind.Sequential)] + public struct POINT + { + /// + /// x coordinate of point. + /// + public int x; + /// + /// y coordinate of point. + /// + public int y; + + /// + /// Construct a point of coordinates (x,y). + /// + public POINT(int x, int y) + { + this.x = x; + this.y = y; + } + } } } \ No newline at end of file diff --git a/QuickLook/MainWindowTransparent.xaml b/QuickLook/MainWindowTransparent.xaml index 98c916d..ff11544 100644 --- a/QuickLook/MainWindowTransparent.xaml +++ b/QuickLook/MainWindowTransparent.xaml @@ -1,4 +1,4 @@ - - + + - - - + + + + - + - + + + + @@ -160,4 +188,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/QuickLook/MainWindowTransparent.xaml.cs b/QuickLook/MainWindowTransparent.xaml.cs index 57c8d6b..5d9ea19 100644 --- a/QuickLook/MainWindowTransparent.xaml.cs +++ b/QuickLook/MainWindowTransparent.xaml.cs @@ -28,6 +28,7 @@ using System.Windows.Input; using System.Windows.Media; using System.Windows.Threading; using QuickLook.Annotations; +using QuickLook.Controls; using QuickLook.Helpers; using QuickLook.Plugin; @@ -36,7 +37,7 @@ namespace QuickLook /// /// Interaction logic for MainWindowTransparent.xaml /// - public partial class MainWindowTransparent : Window, INotifyPropertyChanged + public partial class MainWindowTransparent : MainWindowBase, INotifyPropertyChanged { private bool _pinned; private bool _restoreForDragMove; @@ -116,6 +117,8 @@ namespace QuickLook private void WindowDragMoving(object sender, MouseEventArgs e) { + if (e.LeftButton != MouseButtonState.Pressed) + return; if (!_restoreForDragMove) return; _restoreForDragMove = false; @@ -133,7 +136,7 @@ namespace QuickLook Top = point.Y - RestoreBounds.Height * precentTop; WindowState = WindowState.Normal; - + DragMove(); } @@ -281,9 +284,11 @@ namespace QuickLook // revert UI changes ContextObject.IsBusy = true; - var newHeight = ContextObject.PreferredSize.Height + 10 + + var margin = windowFrameContainer.Margin.Top * 2; + + var newHeight = ContextObject.PreferredSize.Height + margin + (ContextObject.TitlebarOverlap ? 0 : windowCaptionContainer.Height); - var newWidth = ContextObject.PreferredSize.Width + 10; + var newWidth = ContextObject.PreferredSize.Width + margin; ResizeAndCenter(new Size(newWidth, newHeight)); diff --git a/QuickLook/QuickLook.csproj b/QuickLook/QuickLook.csproj index 5fc9626..e4d5d5a 100644 --- a/QuickLook/QuickLook.csproj +++ b/QuickLook/QuickLook.csproj @@ -115,6 +115,8 @@ GlassLayer.xaml + + diff --git a/QuickLook/Styles/MainWindowStyles.xaml b/QuickLook/Styles/MainWindowStyles.xaml index 2a22a11..84fc0fe 100644 --- a/QuickLook/Styles/MainWindowStyles.xaml +++ b/QuickLook/Styles/MainWindowStyles.xaml @@ -2,8 +2,8 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:system="clr-namespace:System;assembly=mscorlib" xmlns:fa="http://schemas.fontawesome.io/icons/"> - 5 - 5 + 6 + 6 32