diff --git a/QuickLook.Plugin.ImageViewer/ImagePanel.xaml b/QuickLook.Plugin.ImageViewer/ImagePanel.xaml new file mode 100644 index 0000000..670bf8d --- /dev/null +++ b/QuickLook.Plugin.ImageViewer/ImagePanel.xaml @@ -0,0 +1,15 @@ + + + + + + + \ No newline at end of file diff --git a/QuickLook.Plugin.ImageViewer/ImagePanel.xaml.cs b/QuickLook.Plugin.ImageViewer/ImagePanel.xaml.cs new file mode 100644 index 0000000..0ce4483 --- /dev/null +++ b/QuickLook.Plugin.ImageViewer/ImagePanel.xaml.cs @@ -0,0 +1,108 @@ +using System; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; + +namespace QuickLook.Plugin.ImageViewer +{ + /// + /// Interaction logic for ImagePanel.xaml + /// + public partial class ImagePanel : UserControl + { + private Point? _dragInitPos; + private double _minZoomFactor = 1d; + private double _zoomFactor = 1d; + + public ImagePanel(string path) + { + InitializeComponent(); + + viewPanelImage.Source = new BitmapImage(new Uri(path)); + + Loaded += (sender, e) => { ZoomToFit(); }; + + viewPanel.PreviewMouseWheel += ViewPanel_PreviewMouseWheel; + + viewPanel.PreviewMouseLeftButtonDown += ViewPanel_PreviewMouseLeftButtonDown; + viewPanel.PreviewMouseMove += ViewPanel_PreviewMouseMove; + } + + private void ViewPanel_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + _dragInitPos = e.GetPosition(viewPanel); + var temp = _dragInitPos.Value; // Point is a type value + temp.Offset(viewPanel.HorizontalOffset, viewPanel.VerticalOffset); + _dragInitPos = temp; + } + + private void ViewPanel_PreviewMouseMove(object sender, MouseEventArgs e) + { + if (!_dragInitPos.HasValue) + return; + + if (e.LeftButton == MouseButtonState.Released) + { + _dragInitPos = null; + return; + } + + e.Handled = true; + + var delta = _dragInitPos.Value - e.GetPosition(viewPanel); + + viewPanel.ScrollToHorizontalOffset(delta.X); + viewPanel.ScrollToVerticalOffset(delta.Y); + } + + private void ViewPanel_PreviewMouseWheel(object sender, MouseWheelEventArgs e) + { + if ((Keyboard.Modifiers & ModifierKeys.Control) == 0) + return; + + e.Handled = true; + + var newZoom = _zoomFactor + e.Delta / 120 * 0.1; + + newZoom = Math.Max(newZoom, _minZoomFactor); + newZoom = Math.Min(newZoom, 3); + + Zoom(newZoom, false); + } + + private void ZoomToFit() + { + var factor = Math.Min(viewPanel.ActualWidth / viewPanelImage.Source.Width, + viewPanel.ActualHeight / viewPanelImage.Source.Height); + + _minZoomFactor = factor; + + Zoom(factor, true); + } + + private void Zoom(double factor, bool fromCenter) + { + _zoomFactor = factor; + + var position = fromCenter + ? new Point(viewPanelImage.Source.Width / 2, viewPanelImage.Source.Height / 2) + : Mouse.GetPosition(viewPanelImage); + + viewPanelImage.LayoutTransform = new ScaleTransform(factor, factor); + + viewPanel.InvalidateMeasure(); + + // critical for calcuating offset + viewPanel.ScrollToHorizontalOffset(0); + viewPanel.ScrollToVerticalOffset(0); + UpdateLayout(); + + var offset = viewPanelImage.TranslatePoint(position, viewPanel) - Mouse.GetPosition(viewPanel); + viewPanel.ScrollToHorizontalOffset(offset.X); + viewPanel.ScrollToVerticalOffset(offset.Y); + UpdateLayout(); + } + } +} \ No newline at end of file diff --git a/QuickLook.Plugin.ImageViewer/Plugin.cs b/QuickLook.Plugin.ImageViewer/Plugin.cs new file mode 100644 index 0000000..e4d7375 --- /dev/null +++ b/QuickLook.Plugin.ImageViewer/Plugin.cs @@ -0,0 +1,58 @@ +using System; +using System.IO; +using System.Windows; +using System.Windows.Media.Imaging; + +namespace QuickLook.Plugin.ImageViewer +{ + public class Plugin : IViewer + { + private ImagePanel _ip; + private BitmapDecoder decoder; + + public int Priority { get; } + + public bool CanHandle(string path) + { + // TODO: determine file type by content + + if (Directory.Exists(path)) + return false; + + switch (Path.GetExtension(path).ToLower()) + { + case ".bmp": + case ".gif": + case ".ico": + case ".jpg": + case ".png": + case ".wdp": + case ".tiff": + return true; + + default: + return false; + } + } + + public void Prepare(string path, ViewContentContainer container) + { + decoder = BitmapDecoder.Create(new Uri(path), BitmapCreateOptions.None, BitmapCacheOption.None); + var frame = decoder.Frames[0]; + + container.SetPreferedSizeFit(new Size {Width = frame.Width, Height = frame.Height}, 0.6); + } + + public void View(string path, ViewContentContainer container) + { + _ip = new ImagePanel(path); + + container.SetContent(_ip); + container.Title = $"{Path.GetFileName(path)}"; + } + + public void Close() + { + } + } +} \ No newline at end of file diff --git a/QuickLook.Plugin.ImageViewer/Properties/AssemblyInfo.cs b/QuickLook.Plugin.ImageViewer/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..910e15d --- /dev/null +++ b/QuickLook.Plugin.ImageViewer/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("QuickLook.Plugin.ImageViewer")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("QuickLook.Plugin.ImageViewer")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("fe5a5111-9607-4721-a7be-422754002ed8")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/QuickLook.Plugin.ImageViewer/QuickLook.Plugin.ImageViewer.csproj b/QuickLook.Plugin.ImageViewer/QuickLook.Plugin.ImageViewer.csproj new file mode 100644 index 0000000..7332d0d --- /dev/null +++ b/QuickLook.Plugin.ImageViewer/QuickLook.Plugin.ImageViewer.csproj @@ -0,0 +1,75 @@ + + + + + Debug + AnyCPU + {FE5A5111-9607-4721-A7BE-422754002ED8} + Library + Properties + QuickLook.Plugin.ImageViewer + QuickLook.Plugin.ImageViewer + v4.5.2 + 512 + + + true + full + false + ..\Build\Debug\Plugins\QuickLook.Plugin.ImageViewer\ + DEBUG;TRACE + prompt + 4 + x86 + + + pdbonly + true + ..\Build\Release\Plugins\QuickLook.Plugin.ImageViewer\ + TRACE + prompt + 4 + x86 + + + + + + + + + + + + + + + + ..\packages\WpfAnimatedGif.1.4.14\lib\net\WpfAnimatedGif.dll + + + + + ImagePanel.xaml + + + + + + + {8b4a9ce5-67b5-4a94-81cb-3771f688fdeb} + QuickLook + False + + + + + Designer + MSBuild:Compile + + + + + + + \ No newline at end of file diff --git a/QuickLook.Plugin.ImageViewer/packages.config b/QuickLook.Plugin.ImageViewer/packages.config new file mode 100644 index 0000000..96339f3 --- /dev/null +++ b/QuickLook.Plugin.ImageViewer/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/QuickLook.Plugin.LastResort/InfoPanel.xaml.cs b/QuickLook.Plugin.LastResort/InfoPanel.xaml.cs index 656959e..041f1a3 100644 --- a/QuickLook.Plugin.LastResort/InfoPanel.xaml.cs +++ b/QuickLook.Plugin.LastResort/InfoPanel.xaml.cs @@ -1,4 +1,6 @@ -using System.Windows.Controls; +using System.IO; +using System.Threading.Tasks; +using System.Windows.Controls; namespace QuickLook.Plugin.LastResort { @@ -7,9 +9,57 @@ namespace QuickLook.Plugin.LastResort /// public partial class InfoPanel : UserControl { + private bool _stop; + public InfoPanel() { InitializeComponent(); } + + public bool Stop + { + set => _stop = value; + get => _stop; + } + + public void DisplayInfo(string path) + { + var icon = IconHelper.GetBitmapFromPath(path, IconHelper.IconSizeEnum.ExtraLargeIcon).ToBitmapSource(); + + image.Source = icon; + + var name = Path.GetFileName(path); + filename.Content = string.IsNullOrEmpty(name) ? path : name; + + var last = File.GetLastWriteTime(path); + modDate.Content = $"{last.ToLongDateString()} {last.ToLongTimeString()}"; + + Stop = false; + + Task.Run(() => + { + if (File.Exists(path)) + { + var size = new FileInfo(path).Length; + + Dispatcher.Invoke(() => { totalSize.Content = size.ToPrettySize(2); }); + } + else if (Directory.Exists(path)) + { + long totalDirsL; + long totalFilesL; + long totalSizeL; + + FileHelper.CountFolder(path, ref _stop, out totalDirsL, out totalFilesL, out totalSizeL); + + if (!Stop) + Dispatcher.Invoke(() => + { + totalSize.Content = + $"{totalSizeL.ToPrettySize(2)} ({totalDirsL} folders and {totalFilesL} files)"; + }); + } + }); + } } } \ No newline at end of file diff --git a/QuickLook.Plugin.LastResort/Plugin.cs b/QuickLook.Plugin.LastResort/Plugin.cs index 1f874d0..585ba16 100644 --- a/QuickLook.Plugin.LastResort/Plugin.cs +++ b/QuickLook.Plugin.LastResort/Plugin.cs @@ -1,13 +1,10 @@ -using System.IO; -using System.Threading.Tasks; -using System.Windows; +using System.Windows; namespace QuickLook.Plugin.LastResort { public class Plugin : IViewer { private InfoPanel _ip; - private bool _stop; public int Priority => int.MinValue; @@ -16,7 +13,7 @@ namespace QuickLook.Plugin.LastResort return true; } - public void BoundSize(string path, ViewContentContainer container) + public void Prepare(string path, ViewContentContainer container) { _ip = new InfoPanel(); @@ -26,55 +23,14 @@ namespace QuickLook.Plugin.LastResort public void View(string path, ViewContentContainer container) { - DisplayInfo(path); + _ip.DisplayInfo(path); container.SetContent(_ip); } public void Close() { - _stop = true; - } - - - private void DisplayInfo(string path) - { - var icon = IconHelper.GetBitmapFromPath(path, IconHelper.IconSizeEnum.ExtraLargeIcon).ToBitmapSource(); - - _ip.image.Source = icon; - - var name = Path.GetFileName(path); - _ip.filename.Content = string.IsNullOrEmpty(name) ? path : name; - - var last = File.GetLastWriteTime(path); - _ip.modDate.Content = $"{last.ToLongDateString()} {last.ToLongTimeString()}"; - - _stop = false; - - Task.Run(() => - { - if (File.Exists(path)) - { - var size = new FileInfo(path).Length; - - _ip.Dispatcher.Invoke(() => { _ip.totalSize.Content = size.ToPrettySize(2); }); - } - else if (Directory.Exists(path)) - { - long totalDirs; - long totalFiles; - long totalSize; - - FileHelper.CountFolder(path, ref _stop, out totalDirs, out totalFiles, out totalSize); - - if (!_stop) - _ip.Dispatcher.Invoke(() => - { - _ip.totalSize.Content = - $"{totalSize.ToPrettySize(2)} ({totalDirs} folders and {totalFiles} files.)"; - }); - } - }); + _ip.Stop = true; } } } \ No newline at end of file diff --git a/QuickLook.Plugin.PDFViewer/PdfViewerControl.xaml.cs b/QuickLook.Plugin.PDFViewer/PdfViewerControl.xaml.cs index db6d518..b9fb3dc 100644 --- a/QuickLook.Plugin.PDFViewer/PdfViewerControl.xaml.cs +++ b/QuickLook.Plugin.PDFViewer/PdfViewerControl.xaml.cs @@ -15,6 +15,7 @@ namespace QuickLook.Plugin.PDFViewer /// public partial class PdfViewerControl : UserControl, INotifyPropertyChanged, IDisposable { + private Point? _dragInitPos; private PreviewMouseWheelMonitor _whellMonitor; public PdfViewerControl() @@ -36,6 +37,8 @@ namespace QuickLook.Plugin.PDFViewer public double ZoomFactor { get; set; } + public double MinZoomFactor { get; set; } + public int TotalPages => PdfHandle.TotalPages; public int CurrectPage @@ -114,6 +117,8 @@ namespace QuickLook.Plugin.PDFViewer pageViewPanelImage.LayoutTransform = new ScaleTransform(viewZoom, viewZoom); + pageViewPanel.InvalidateMeasure(); + // critical for calcuating offset pageViewPanel.ScrollToHorizontalOffset(0); pageViewPanel.ScrollToVerticalOffset(0); @@ -140,6 +145,8 @@ namespace QuickLook.Plugin.PDFViewer // reset view zoom factor pageViewPanelImage.LayoutTransform = new ScaleTransform(); + pageViewPanel.InvalidateMeasure(); + GC.Collect(); } @@ -164,6 +171,7 @@ namespace QuickLook.Plugin.PDFViewer var factor = Math.Min(pageViewPanel.ActualWidth / size.Width, pageViewPanel.ActualHeight / size.Height); ZoomFactor = factor; + MinZoomFactor = factor; ReRenderCurrentPage(); } @@ -175,7 +183,7 @@ namespace QuickLook.Plugin.PDFViewer var size = tempHandle.GetPageSize(0, 1d); tempHandle.Dispose(); - size.Width += /*listThumbnails.ActualWidth*/ 150 + 1; + size.Width += /*listThumbnails.ActualWidth*/ 150; return size; } @@ -201,8 +209,39 @@ namespace QuickLook.Plugin.PDFViewer // register events listThumbnails.SelectionChanged += UpdatePageViewWhenSelectionChanged; //pageViewPanel.SizeChanged += ReRenderCurrentPageWhenSizeChanged; + pageViewPanel.PreviewMouseWheel += NavigatePage; StartMouseWhellDelayedZoomMonitor(pageViewPanel); + + pageViewPanel.PreviewMouseLeftButtonDown += DragScrollStart; + pageViewPanel.PreviewMouseMove += DragScrolling; + } + + private void DragScrolling(object sender, MouseEventArgs e) + { + if (!_dragInitPos.HasValue) + return; + + if (e.LeftButton == MouseButtonState.Released) + { + _dragInitPos = null; + return; + } + + e.Handled = true; + + var delta = _dragInitPos.Value - e.GetPosition(pageViewPanel); + + pageViewPanel.ScrollToHorizontalOffset(delta.X); + pageViewPanel.ScrollToVerticalOffset(delta.Y); + } + + private void DragScrollStart(object sender, MouseButtonEventArgs e) + { + _dragInitPos = e.GetPosition(pageViewPanel); + var temp = _dragInitPos.Value; // Point is a type value + temp.Offset(pageViewPanel.HorizontalOffset, pageViewPanel.VerticalOffset); + _dragInitPos = temp; } private void StartMouseWhellDelayedZoomMonitor(UIElement ui) @@ -230,7 +269,7 @@ namespace QuickLook.Plugin.PDFViewer newZoom = newZoom + e.Delta / 120 * 0.1; - newZoom = Math.Max(newZoom, 0.2); + newZoom = Math.Max(newZoom, MinZoomFactor); newZoom = Math.Min(newZoom, 3); ReRenderCurrentPageLowQuality(newZoom / ZoomFactor, false); diff --git a/QuickLook.Plugin.PDFViewer/Plugin.cs b/QuickLook.Plugin.PDFViewer/Plugin.cs index 700a37e..91e7236 100644 --- a/QuickLook.Plugin.PDFViewer/Plugin.cs +++ b/QuickLook.Plugin.PDFViewer/Plugin.cs @@ -22,14 +22,12 @@ namespace QuickLook.Plugin.PDFViewer } } - public void BoundSize(string path, ViewContentContainer container) + public void Prepare(string path, ViewContentContainer container) { _pdfControl = new PdfViewerControl(); var desiredSize = _pdfControl.GetDesiredControlSizeByFirstPage(path); - desiredSize.Width += 150; // add thumbnails column - container.SetPreferedSizeFit(desiredSize, 0.7); } diff --git a/QuickLook.Plugin.TextViewer/Plugin.cs b/QuickLook.Plugin.TextViewer/Plugin.cs index 329f630..743697d 100644 --- a/QuickLook.Plugin.TextViewer/Plugin.cs +++ b/QuickLook.Plugin.TextViewer/Plugin.cs @@ -41,7 +41,7 @@ namespace QuickLook.Plugin.TextViewer } } - public void BoundSize(string path, ViewContentContainer container) + public void Prepare(string path, ViewContentContainer container) { container.PreferedSize = new Size {Width = 800, Height = 600}; } diff --git a/QuickLook.sln b/QuickLook.sln index 751f860..3eb75e0 100644 --- a/QuickLook.sln +++ b/QuickLook.sln @@ -16,6 +16,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickLook.Plugin.LastResort EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickLook.Plugin.TextViewer", "QuickLook.Plugin.TextViewer\QuickLook.Plugin.TextViewer.csproj", "{AE041682-E3A1-44F6-8BB4-916A98D89FBE}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickLook.Plugin.ImageViewer", "QuickLook.Plugin.ImageViewer\QuickLook.Plugin.ImageViewer.csproj", "{FE5A5111-9607-4721-A7BE-422754002ED8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -62,6 +64,14 @@ Global {AE041682-E3A1-44F6-8BB4-916A98D89FBE}.Release|Any CPU.Build.0 = Release|Any CPU {AE041682-E3A1-44F6-8BB4-916A98D89FBE}.Release|x86.ActiveCfg = Release|Any CPU {AE041682-E3A1-44F6-8BB4-916A98D89FBE}.Release|x86.Build.0 = Release|Any CPU + {FE5A5111-9607-4721-A7BE-422754002ED8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FE5A5111-9607-4721-A7BE-422754002ED8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FE5A5111-9607-4721-A7BE-422754002ED8}.Debug|x86.ActiveCfg = Debug|Any CPU + {FE5A5111-9607-4721-A7BE-422754002ED8}.Debug|x86.Build.0 = Debug|Any CPU + {FE5A5111-9607-4721-A7BE-422754002ED8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FE5A5111-9607-4721-A7BE-422754002ED8}.Release|Any CPU.Build.0 = Release|Any CPU + {FE5A5111-9607-4721-A7BE-422754002ED8}.Release|x86.ActiveCfg = Release|Any CPU + {FE5A5111-9607-4721-A7BE-422754002ED8}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/QuickLook/BackgroundListener.cs b/QuickLook/BackgroundListener.cs index 9a9b413..0110b59 100644 --- a/QuickLook/BackgroundListener.cs +++ b/QuickLook/BackgroundListener.cs @@ -58,7 +58,7 @@ namespace QuickLook _showingWindow.viewContentContainer.ViewerPlugin = matched; // get window size before showing it - matched.BoundSize(path, _showingWindow.viewContentContainer); + matched.Prepare(path, _showingWindow.viewContentContainer); _showingWindow.Show(); diff --git a/QuickLook/MainWindow.xaml b/QuickLook/MainWindow.xaml index 7fa53cf..e123636 100644 --- a/QuickLook/MainWindow.xaml +++ b/QuickLook/MainWindow.xaml @@ -10,13 +10,14 @@ mc:Ignorable="d" x:Class="QuickLook.MainWindow" x:Name="mainWindow" AllowsTransparency="True" WindowStyle="None" UseLayoutRounding="True" Topmost="True" d:DesignWidth="624" d:DesignHeight="700" + MinWidth="275" MinHeight="150" WindowStartupLocation="CenterScreen" ResizeMode="CanResizeWithGrip" - x:ClassModifier="internal"> + x:ClassModifier="internal" Focusable="False" ShowActivated="False" ShowInTaskbar="False"> - + diff --git a/QuickLook/MainWindow.xaml.cs b/QuickLook/MainWindow.xaml.cs index df24e6e..c9541b1 100644 --- a/QuickLook/MainWindow.xaml.cs +++ b/QuickLook/MainWindow.xaml.cs @@ -3,6 +3,7 @@ using System.ComponentModel; using System.Runtime.CompilerServices; using System.Windows; using System.Windows.Input; +using System.Windows.Interop; using System.Windows.Media.Animation; using System.Windows.Threading; using QuickLook.Annotations; @@ -34,18 +35,25 @@ namespace QuickLook private void MainWindow_Closed(object sender, EventArgs e) { viewContentContainer.ViewerPlugin.Close(); + viewContentContainer.ViewerPlugin = null; + + GC.Collect(); } internal new void Show() { loadingIconLayer.Opacity = 1; - Height = viewContentContainer.PreferedSize.Height + titlebar.Height; - Width = viewContentContainer.PreferedSize.Width; + Height = viewContentContainer.PreferedSize.Height + titlebar.Height + windowBorder.BorderThickness.Top + + windowBorder.BorderThickness.Bottom; + Width = viewContentContainer.PreferedSize.Width + windowBorder.BorderThickness.Left + + windowBorder.BorderThickness.Right; ResizeMode = viewContentContainer.CanResize ? ResizeMode.CanResizeWithGrip : ResizeMode.NoResize; base.Show(); + + NoactivateWindowHelper.SetNoactivate(new WindowInteropHelper(this)); } internal void ShowFinishLoadingAnimation() diff --git a/QuickLook/NativeMethods/User32.cs b/QuickLook/NativeMethods/User32.cs index 5baf70d..d82d605 100644 --- a/QuickLook/NativeMethods/User32.cs +++ b/QuickLook/NativeMethods/User32.cs @@ -16,6 +16,12 @@ namespace QuickLook.NativeMethods [DllImport("user32.dll")] internal static extern int CallNextHookEx(IntPtr idHook, int nCode, int wParam, ref KeyboardHookStruct lParam); + [DllImport("user32.dll")] + public static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); + + [DllImport("user32.dll")] + public static extern int GetWindowLong(IntPtr hWnd, int nIndex); + internal delegate int KeyboardHookProc(int code, int wParam, ref KeyboardHookStruct lParam); [SuppressMessage("ReSharper", "InconsistentNaming")] @@ -34,6 +40,8 @@ namespace QuickLook.NativeMethods internal const int WM_KEYUP = 0x101; internal const int WM_SYSKEYDOWN = 0x104; internal const int WM_SYSKEYUP = 0x105; + internal const int GWL_EXSTYLE = -20; + internal const int WS_EX_NOACTIVATE = 0x08000000; // ReSharper restore InconsistentNaming } } \ No newline at end of file diff --git a/QuickLook/Plugin/IViewer.cs b/QuickLook/Plugin/IViewer.cs index 9d2d1a4..0b94d1a 100644 --- a/QuickLook/Plugin/IViewer.cs +++ b/QuickLook/Plugin/IViewer.cs @@ -4,7 +4,7 @@ { int Priority { get; } bool CanHandle(string path); - void BoundSize(string path, ViewContentContainer container); + void Prepare(string path, ViewContentContainer container); void View(string path, ViewContentContainer container); void Close(); } diff --git a/QuickLook/Plugin/ViewContentContainer.xaml.cs b/QuickLook/Plugin/ViewContentContainer.xaml.cs index 211b310..dd2cffa 100644 --- a/QuickLook/Plugin/ViewContentContainer.xaml.cs +++ b/QuickLook/Plugin/ViewContentContainer.xaml.cs @@ -54,6 +54,8 @@ namespace QuickLook.Plugin var ratio = Math.Min(widthRatio, heightRatio); + if (ratio > 1) ratio = 1; + PreferedSize = new Size {Width = size.Width * ratio, Height = size.Height * ratio}; return ratio; diff --git a/QuickLook/QuickLook.csproj b/QuickLook/QuickLook.csproj index 52ab907..6efc481 100644 --- a/QuickLook/QuickLook.csproj +++ b/QuickLook/QuickLook.csproj @@ -79,6 +79,7 @@ ViewContentContainer.xaml + Designer MSBuild:Compile diff --git a/QuickLook/Utilities/NoactivateWindowHelper.cs b/QuickLook/Utilities/NoactivateWindowHelper.cs new file mode 100644 index 0000000..cc7364c --- /dev/null +++ b/QuickLook/Utilities/NoactivateWindowHelper.cs @@ -0,0 +1,15 @@ +using System.Windows.Interop; +using QuickLook.NativeMethods; + +namespace QuickLook.Utilities +{ + internal class NoactivateWindowHelper + { + internal static void SetNoactivate(WindowInteropHelper window) + { + User32.SetWindowLong(window.Handle, User32.GWL_EXSTYLE, + User32.GetWindowLong(window.Handle, User32.GWL_EXSTYLE) | + User32.WS_EX_NOACTIVATE); + } + } +} \ No newline at end of file