mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-11 17:59:17 +00:00
adjust resize behaviour
This commit is contained in:
@@ -58,8 +58,6 @@ namespace QuickLook.Plugin.PDFViewer
|
|||||||
var desiredSize = PdfViewerControl.GetDesiredControlSizeByFirstPage(path);
|
var desiredSize = PdfViewerControl.GetDesiredControlSizeByFirstPage(path);
|
||||||
|
|
||||||
context.SetPreferredSizeFit(desiredSize, 0.6);
|
context.SetPreferredSizeFit(desiredSize, 0.6);
|
||||||
|
|
||||||
context.PreferredSize = new Size(context.PreferredSize.Width, context.PreferredSize.Height + 32);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void View(string path, ContextObject context)
|
public void View(string path, ContextObject context)
|
||||||
|
@@ -47,6 +47,7 @@ namespace QuickLook
|
|||||||
private string _path;
|
private string _path;
|
||||||
private bool _pinned;
|
private bool _pinned;
|
||||||
private bool _restoreForDragMove;
|
private bool _restoreForDragMove;
|
||||||
|
private bool _canOldPluginResize;
|
||||||
|
|
||||||
internal ViewerWindow()
|
internal ViewerWindow()
|
||||||
{
|
{
|
||||||
@@ -240,40 +241,40 @@ namespace QuickLook
|
|||||||
BeginClose();
|
BeginClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ResizeAndCenter(Size size, bool canResize)
|
private static void ResizeAndCenter(Window window, Size size, bool canOldPluginResize, bool canNextPluginResize)
|
||||||
{
|
{
|
||||||
// resize to MinSize first
|
// resize to MinSize first
|
||||||
size.Width = Math.Max(size.Width, MinWidth);
|
size.Width = Math.Max(size.Width, window.MinWidth);
|
||||||
size.Height = Math.Max(size.Height, MinHeight);
|
size.Height = Math.Max(size.Height, window.MinHeight);
|
||||||
|
|
||||||
if (!IsLoaded)
|
if (!window.IsLoaded)
|
||||||
{
|
{
|
||||||
// if the window is not loaded yet, just leave the problem to WPF
|
// if the window is not loaded yet, just leave the problem to WPF
|
||||||
Width = size.Width;
|
window.Width = size.Width;
|
||||||
Height = size.Height;
|
window.Height = size.Height;
|
||||||
WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
||||||
Dispatcher.BeginInvoke(new Action(this.BringToFront), DispatcherPriority.Render);
|
window.Dispatcher.BeginInvoke(new Action(window.BringToFront), DispatcherPriority.Render);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// is the window is now now maximized, do not move it
|
// is the window is now now maximized, do not move it
|
||||||
if (WindowState == WindowState.Maximized)
|
if (window.WindowState == WindowState.Maximized)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// if this is a new window, place it to top
|
// if this is a new window, place it to top
|
||||||
if (Visibility != Visibility.Visible)
|
if (window.Visibility != Visibility.Visible)
|
||||||
this.BringToFront();
|
window.BringToFront();
|
||||||
|
|
||||||
var screen = WindowHelper.GetCurrentWindowRect();
|
var screen = WindowHelper.GetCurrentWindowRect();
|
||||||
|
|
||||||
// do not resize or reposition the window is it is visible - unless the next window is size-fixed
|
// do not resize or reposition the window is it is visible - unless the next window is size-fixed
|
||||||
if (Visibility == Visibility.Visible && canResize)
|
if (window.Visibility == Visibility.Visible && canOldPluginResize && canNextPluginResize)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// otherwise, resize it and place it to the old window center.
|
// otherwise, resize it and place it to the old window center.
|
||||||
var oldCenterX = Left + Width / 2;
|
var oldCenterX = window.Left + window.Width / 2;
|
||||||
var oldCenterY = Top + Height / 2;
|
var oldCenterY = window.Top + window.Height / 2;
|
||||||
|
|
||||||
var newLeft = oldCenterX - size.Width / 2;
|
var newLeft = oldCenterX - size.Width / 2;
|
||||||
var newTop = oldCenterY - size.Height / 2;
|
var newTop = oldCenterY - size.Height / 2;
|
||||||
@@ -284,7 +285,7 @@ namespace QuickLook
|
|||||||
newLeft = newLeft + size.Width > screen.Right ? screen.Right - size.Width : newLeft; // right
|
newLeft = newLeft + size.Width > screen.Right ? screen.Right - size.Width : newLeft; // right
|
||||||
newTop = newTop + size.Height > screen.Bottom ? screen.Bottom - size.Height : newTop; // bottom
|
newTop = newTop + size.Height > screen.Bottom ? screen.Bottom - size.Height : newTop; // bottom
|
||||||
|
|
||||||
this.MoveWindow(newLeft, newTop, size.Width, size.Height);
|
window.MoveWindow(newLeft, newTop, size.Width, size.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void UnloadPlugin()
|
internal void UnloadPlugin()
|
||||||
@@ -295,6 +296,8 @@ namespace QuickLook
|
|||||||
RestoreFocusMode.None; // WPF will put the focused item into a "_restoreFocus" list ... omg
|
RestoreFocusMode.None; // WPF will put the focused item into a "_restoreFocus" list ... omg
|
||||||
Keyboard.ClearFocus();
|
Keyboard.ClearFocus();
|
||||||
|
|
||||||
|
_canOldPluginResize = ContextObject.CanResize;
|
||||||
|
|
||||||
ContextObject.Reset();
|
ContextObject.Reset();
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -332,7 +335,7 @@ namespace QuickLook
|
|||||||
(ContextObject.TitlebarOverlap ? 0 : windowCaptionContainer.Height);
|
(ContextObject.TitlebarOverlap ? 0 : windowCaptionContainer.Height);
|
||||||
var newWidth = ContextObject.PreferredSize.Width + margin;
|
var newWidth = ContextObject.PreferredSize.Width + margin;
|
||||||
|
|
||||||
ResizeAndCenter(new Size(newWidth, newHeight), ContextObject.CanResize);
|
ResizeAndCenter(this, new Size(newWidth, newHeight), _canOldPluginResize, ContextObject.CanResize);
|
||||||
|
|
||||||
if (Visibility != Visibility.Visible)
|
if (Visibility != Visibility.Visible)
|
||||||
Show();
|
Show();
|
||||||
|
Reference in New Issue
Block a user