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() { private void CreateZoom() {
if (zoomForm == null) { if (zoomForm == null) {
zoomForm = new ZoomForm(capture); zoomForm = new ZoomForm(capture);
zoomForm.Show(); zoomForm.Show(this);
WindowDetails.ToForeground(zoomForm.Handle);
// Fix missing focus issue // Fix missing focus issue
WindowDetails.ToForeground(this.Handle); WindowDetails.ToForeground(this.Handle);
this.TopMost = false;
zoomForm.TopMost = true;
Activate();
} }
} }
@ -149,7 +145,6 @@ namespace Greenshot.Forms {
zoomForm.Close(); zoomForm.Close();
// Fix missing focus issue // Fix missing focus issue
WindowDetails.ToForeground(this.Handle); WindowDetails.ToForeground(this.Handle);
this.TopMost = true;
zoomForm = null; zoomForm = null;
} }
} }

View file

@ -34,10 +34,14 @@ namespace Greenshot.Forms {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ZoomForm)); private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ZoomForm));
private ICapture captureToZoom = null; private ICapture captureToZoom = null;
private Point mouseLocation = Point.Empty; private Point mouseLocation = Point.Empty;
private const int distanceX = 20;
private const int distanceY = 20;
private Rectangle screenBounds;
public ZoomForm(ICapture captureToZoom) { public ZoomForm(ICapture captureToZoom) {
InitializeComponent(); InitializeComponent();
this.captureToZoom = captureToZoom; this.captureToZoom = captureToZoom;
screenBounds = new Rectangle(Point.Empty, captureToZoom.Image.Size);
Zoom = 400; Zoom = 400;
} }
@ -47,7 +51,21 @@ namespace Greenshot.Forms {
} }
set { set {
mouseLocation = value; 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(); this.Invalidate();
} }
} }

View file

@ -168,6 +168,13 @@ namespace GreenshotPlugin.Core {
private static List<IntPtr> ignoreHandles = new List<IntPtr>(); private static List<IntPtr> ignoreHandles = new List<IntPtr>();
private static Dictionary<string, Image> iconCache = new Dictionary<string, Image>(); private static Dictionary<string, Image> iconCache = new Dictionary<string, Image>();
private static List<string> excludeProcessesFromFreeze = new List<string>(); 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) { public static void AddProcessToExcludeFromFreeze(string processname) {
if (!excludeProcessesFromFreeze.Contains(processname)) { if (!excludeProcessesFromFreeze.Contains(processname)) {
@ -598,24 +605,30 @@ namespace GreenshotPlugin.Core {
public bool Visible { public bool Visible {
get { get {
if (isApp) { if (isApp) {
// IAppVisibility appVisibility = COMWrapper.CreateInstance<IAppVisibility>(); Rectangle windowRectangle = WindowRectangle;
// if (appVisibility != null) { foreach (Screen screen in Screen.AllScreens) {
//foreach (Screen screen in Screen.AllScreens) { if (screen.Bounds.Contains(windowRectangle)) {
// RECT rect = new RECT(screen.Bounds); if (windowRectangle.Equals(screen.Bounds)) {
// IntPtr monitor = User32.MonitorFromRect(ref rect, User32.MONITOR_DEFAULTTONULL); // Fullscreen, it's "visible" when AppVisibilityOnMonitor says yes
// if (monitor != IntPtr.Zero) { // Although it might be the other App, this is not "very" important
// LOG.DebugFormat("Monitor {0} has hMonitor {1}", screen.DeviceName, monitor); RECT rect = new RECT(screen.Bounds);
// } IntPtr monitor = User32.MonitorFromRect(ref rect, User32.MONITOR_DEFAULTTONULL);
//} if (monitor != IntPtr.Zero) {
// IntPtr monitor = User32.MonitorFromWindow(Handle, User32.MONITOR_DEFAULTTONULL); if (appVisibility != null) {
// if (monitor != IntPtr.Zero) { MONITOR_APP_VISIBILITY monitorAppVisibility = appVisibility.GetAppVisibilityOnMonitor(monitor);
// LOG.DebugFormat("Monitor = {0}", monitor); LOG.DebugFormat("App visible: {0}", monitorAppVisibility);
// MONITOR_APP_VISIBILITY monitorAppVisibility = appVisibility.GetAppVisibilityOnMonitor(monitor); if (monitorAppVisibility == MONITOR_APP_VISIBILITY.MAV_APP_VISIBLE) {
// LOG.DebugFormat("App visible: {0}", monitorAppVisibility); return true;
// return monitorAppVisibility == MONITOR_APP_VISIBILITY.MAV_APP_VISIBLE; }
// } }
// } }
} else {
// Not Fullscreen -> Than it's visible!
return true;
}
}
}
return false;
} }
if (isAppLauncher) { if (isAppLauncher) {
return IsAppLauncherVisible; return IsAppLauncherVisible;
@ -1578,14 +1591,10 @@ namespace GreenshotPlugin.Core {
/// <returns></returns> /// <returns></returns>
public static bool IsAppLauncherVisible { public static bool IsAppLauncherVisible {
get { get {
try { if (appVisibility != null) {
IAppVisibility appVisibility = COMWrapper.CreateInstance<IAppVisibility>(); return appVisibility.IsLauncherVisible;
if (appVisibility != null) { }
return appVisibility.IsLauncherVisible;
}
} catch {}
return false; return false;
} }
} }
} }

View file

@ -158,13 +158,13 @@ namespace Greenshot.Interop {
try { try {
comType = Type.GetTypeFromCLSID(guid); comType = Type.GetTypeFromCLSID(guid);
} catch (Exception ex) { } catch (Exception ex) {
LOG.Warn("Error type for " + progId, ex); LOG.WarnFormat("Error {1} type for {0}", progId, ex.Message);
} }
} else { } else {
try { try {
comType = Type.GetTypeFromProgID(progId, true); comType = Type.GetTypeFromProgID(progId, true);
} catch (Exception ex) { } catch (Exception ex) {
LOG.Warn("Error type for " + progId, ex); LOG.WarnFormat("Error {1} type for {0}", progId, ex.Message);
} }
} }
object comObject = null; object comObject = null;
@ -175,7 +175,7 @@ namespace Greenshot.Interop {
LOG.DebugFormat("Created new instance of {0} object.", progId); LOG.DebugFormat("Created new instance of {0} object.", progId);
} }
} catch (Exception e) { } 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) { if (comObject != null) {