From 831a3b4d5b9175911ab38a7aa849492a718849d9 Mon Sep 17 00:00:00 2001 From: RKrom Date: Tue, 13 Nov 2012 21:13:09 +0000 Subject: [PATCH] Made zoom move to a different location if it goes outside the screen. Also changed the Metro-App visibility property, this might work (up to an acceptable level) but is untested. git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2284 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- Greenshot/Forms/CaptureForm.cs | 7 +--- Greenshot/Forms/ZoomForm.cs | 20 ++++++++- GreenshotPlugin/Core/WindowsHelper.cs | 59 +++++++++++++++------------ GreenshotPlugin/Interop/COMWrapper.cs | 6 +-- 4 files changed, 57 insertions(+), 35 deletions(-) diff --git a/Greenshot/Forms/CaptureForm.cs b/Greenshot/Forms/CaptureForm.cs index c0549c418..d41dae78d 100644 --- a/Greenshot/Forms/CaptureForm.cs +++ b/Greenshot/Forms/CaptureForm.cs @@ -133,14 +133,10 @@ namespace Greenshot.Forms { private void CreateZoom() { if (zoomForm == null) { zoomForm = new ZoomForm(capture); - zoomForm.Show(); - WindowDetails.ToForeground(zoomForm.Handle); + zoomForm.Show(this); // Fix missing focus issue WindowDetails.ToForeground(this.Handle); - this.TopMost = false; - zoomForm.TopMost = true; - Activate(); } } @@ -149,7 +145,6 @@ namespace Greenshot.Forms { zoomForm.Close(); // Fix missing focus issue WindowDetails.ToForeground(this.Handle); - this.TopMost = true; zoomForm = null; } } diff --git a/Greenshot/Forms/ZoomForm.cs b/Greenshot/Forms/ZoomForm.cs index 59dcdc875..3a32e5dd4 100644 --- a/Greenshot/Forms/ZoomForm.cs +++ b/Greenshot/Forms/ZoomForm.cs @@ -34,10 +34,14 @@ namespace Greenshot.Forms { private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ZoomForm)); private ICapture captureToZoom = null; private Point mouseLocation = Point.Empty; + private const int distanceX = 20; + private const int distanceY = 20; + private Rectangle screenBounds; public ZoomForm(ICapture captureToZoom) { InitializeComponent(); this.captureToZoom = captureToZoom; + screenBounds = new Rectangle(Point.Empty, captureToZoom.Image.Size); Zoom = 400; } @@ -47,7 +51,21 @@ namespace Greenshot.Forms { } set { mouseLocation = value; - this.Location = new Point(mouseLocation.X + 20, mouseLocation.Y + 20); + + Rectangle tl = new Rectangle(mouseLocation.X - (distanceX + Width), mouseLocation.Y - (distanceY + Height), Width, Height); + Rectangle tr = new Rectangle(mouseLocation.X + distanceX, mouseLocation.Y - (distanceY + Height), Width, Height); + Rectangle bl = new Rectangle(mouseLocation.X - (distanceX + Width), mouseLocation.Y + distanceY, Width, Height); + Rectangle br = new Rectangle(mouseLocation.X + distanceX, mouseLocation.Y + distanceY, Width, Height); + if (screenBounds.Contains(br)) { + this.Location = br.Location; + } else if (screenBounds.Contains(bl)) { + this.Location = bl.Location; + } else if (screenBounds.Contains(tr)) { + this.Location = tr.Location; + } else { + this.Location = tl.Location; + } + this.Invalidate(); } } diff --git a/GreenshotPlugin/Core/WindowsHelper.cs b/GreenshotPlugin/Core/WindowsHelper.cs index cd93f900a..b500033d4 100644 --- a/GreenshotPlugin/Core/WindowsHelper.cs +++ b/GreenshotPlugin/Core/WindowsHelper.cs @@ -168,6 +168,13 @@ namespace GreenshotPlugin.Core { private static List ignoreHandles = new List(); private static Dictionary iconCache = new Dictionary(); private static List excludeProcessesFromFreeze = new List(); + private static IAppVisibility appVisibility = null; + + static WindowDetails() { + try { + appVisibility = COMWrapper.CreateInstance(); + } catch {} + } public static void AddProcessToExcludeFromFreeze(string processname) { if (!excludeProcessesFromFreeze.Contains(processname)) { @@ -598,24 +605,30 @@ namespace GreenshotPlugin.Core { public bool Visible { get { if (isApp) { - // IAppVisibility appVisibility = COMWrapper.CreateInstance(); - // if (appVisibility != null) { - //foreach (Screen screen in Screen.AllScreens) { - // RECT rect = new RECT(screen.Bounds); - // IntPtr monitor = User32.MonitorFromRect(ref rect, User32.MONITOR_DEFAULTTONULL); - // if (monitor != IntPtr.Zero) { - // LOG.DebugFormat("Monitor {0} has hMonitor {1}", screen.DeviceName, monitor); - // } - //} - // IntPtr monitor = User32.MonitorFromWindow(Handle, User32.MONITOR_DEFAULTTONULL); - // if (monitor != IntPtr.Zero) { - // LOG.DebugFormat("Monitor = {0}", monitor); - // MONITOR_APP_VISIBILITY monitorAppVisibility = appVisibility.GetAppVisibilityOnMonitor(monitor); - // LOG.DebugFormat("App visible: {0}", monitorAppVisibility); - // return monitorAppVisibility == MONITOR_APP_VISIBILITY.MAV_APP_VISIBLE; - // } - // } - + Rectangle windowRectangle = WindowRectangle; + foreach (Screen screen in Screen.AllScreens) { + if (screen.Bounds.Contains(windowRectangle)) { + if (windowRectangle.Equals(screen.Bounds)) { + // Fullscreen, it's "visible" when AppVisibilityOnMonitor says yes + // Although it might be the other App, this is not "very" important + RECT rect = new RECT(screen.Bounds); + IntPtr monitor = User32.MonitorFromRect(ref rect, User32.MONITOR_DEFAULTTONULL); + if (monitor != IntPtr.Zero) { + if (appVisibility != null) { + MONITOR_APP_VISIBILITY monitorAppVisibility = appVisibility.GetAppVisibilityOnMonitor(monitor); + LOG.DebugFormat("App visible: {0}", monitorAppVisibility); + if (monitorAppVisibility == MONITOR_APP_VISIBILITY.MAV_APP_VISIBLE) { + return true; + } + } + } + } else { + // Not Fullscreen -> Than it's visible! + return true; + } + } + } + return false; } if (isAppLauncher) { return IsAppLauncherVisible; @@ -1578,14 +1591,10 @@ namespace GreenshotPlugin.Core { /// public static bool IsAppLauncherVisible { get { - try { - IAppVisibility appVisibility = COMWrapper.CreateInstance(); - if (appVisibility != null) { - return appVisibility.IsLauncherVisible; - } - } catch {} + if (appVisibility != null) { + return appVisibility.IsLauncherVisible; + } return false; - } } } diff --git a/GreenshotPlugin/Interop/COMWrapper.cs b/GreenshotPlugin/Interop/COMWrapper.cs index eb0e7e476..11d993cd7 100644 --- a/GreenshotPlugin/Interop/COMWrapper.cs +++ b/GreenshotPlugin/Interop/COMWrapper.cs @@ -158,13 +158,13 @@ namespace Greenshot.Interop { try { comType = Type.GetTypeFromCLSID(guid); } catch (Exception ex) { - LOG.Warn("Error type for " + progId, ex); + LOG.WarnFormat("Error {1} type for {0}", progId, ex.Message); } } else { try { comType = Type.GetTypeFromProgID(progId, true); } catch (Exception ex) { - LOG.Warn("Error type for " + progId, ex); + LOG.WarnFormat("Error {1} type for {0}", progId, ex.Message); } } object comObject = null; @@ -175,7 +175,7 @@ namespace Greenshot.Interop { LOG.DebugFormat("Created new instance of {0} object.", progId); } } catch (Exception e) { - LOG.Warn("Error creating object for " + progId, e); + LOG.WarnFormat("Error {1} creating object for {0}", progId, e.Message); } } if (comObject != null) {