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
This commit is contained in:
RKrom 2012-11-13 21:13:09 +00:00
commit 831a3b4d5b
4 changed files with 57 additions and 35 deletions

View file

@ -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;
}
}

View file

@ -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();
}
}

View file

@ -168,6 +168,13 @@ namespace GreenshotPlugin.Core {
private static List<IntPtr> ignoreHandles = new List<IntPtr>();
private static Dictionary<string, Image> iconCache = new Dictionary<string, Image>();
private static List<string> excludeProcessesFromFreeze = new List<string>();
private static IAppVisibility appVisibility = null;
static WindowDetails() {
try {
appVisibility = COMWrapper.CreateInstance<IAppVisibility>();
} 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<IAppVisibility>();
// 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 {
/// <returns></returns>
public static bool IsAppLauncherVisible {
get {
try {
IAppVisibility appVisibility = COMWrapper.CreateInstance<IAppVisibility>();
if (appVisibility != null) {
return appVisibility.IsLauncherVisible;
}
} catch {}
return false;
}
}
}

View file

@ -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) {