Added better IE checking, this allows us to capture windows which display a IE in them. Need to check if we really need this in the auto-capture, but at least the context menu function is really cool! Also fixed a small issue with the destination picker showing in the task-bar (without icon).

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1975 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-08-07 14:38:42 +00:00
parent bc3cac8c87
commit 0b94cc4940
4 changed files with 101 additions and 42 deletions

View file

@ -30,6 +30,7 @@ using Greenshot.Plugin;
using Greenshot.Helpers; using Greenshot.Helpers;
using Greenshot.Forms; using Greenshot.Forms;
using Greenshot.IniFile; using Greenshot.IniFile;
using GreenshotPlugin.UnmanagedHelpers;
namespace Greenshot.Destinations { namespace Greenshot.Destinations {
/// <summary> /// <summary>
@ -84,26 +85,26 @@ namespace Greenshot.Destinations {
if (clickedDestination == null) { if (clickedDestination == null) {
return; return;
} }
bool isEditor = EditorDestination.DESIGNATION.Equals(clickedDestination.Designation); bool isEditor = EditorDestination.DESIGNATION.Equals(clickedDestination.Designation);
// Make sure the menu is invisible, don't close it // Make sure the menu is invisible, don't close it
menu.Hide(); menu.Hide();
// Export // Export
bool result = clickedDestination.ExportCapture(true, surface, captureDetails); bool result = clickedDestination.ExportCapture(true, surface, captureDetails);
LOG.InfoFormat("Destination was {0} and result {1}", clickedDestination.Designation, result); LOG.InfoFormat("Destination was {0} and result {1}", clickedDestination.Designation, result);
if (result == true) { if (result == true) {
LOG.Info("Export success, closing menu"); LOG.Info("Export success, closing menu");
// close menu if the destination wasn't the editor // close menu if the destination wasn't the editor
menu.Close(); menu.Close();
// Cleanup surface, only if the destination wasn't the editor // Cleanup surface, only if the destination wasn't the editor
if (!isEditor) { if (!isEditor) {
surface.Dispose(); surface.Dispose();
} }
} else { } else {
LOG.Info("Export failed, showing menu again"); LOG.Info("Export failed, showing menu again");
menu.Show(); menu.Show();
} }
} }
); );
if (item != null) { if (item != null) {
@ -136,6 +137,8 @@ namespace Greenshot.Destinations {
} else { } else {
location.Offset(-40, -10); location.Offset(-40, -10);
} }
// This prevents the problem that the context menu shows in the task-bar
User32.SetForegroundWindow(MainForm.instance.notifyIcon.ContextMenuStrip.Handle);
menu.Show(location); menu.Show(location);
menu.Focus(); menu.Focus();
} }

View file

@ -596,7 +596,7 @@ namespace Greenshot {
} }
void CaptureIE() { void CaptureIE() {
CaptureHelper.CaptureIE(true); CaptureHelper.CaptureIE(true, null);
} }
void CaptureWindow() { void CaptureWindow() {
@ -840,7 +840,7 @@ namespace Greenshot {
LOG.Error(exception); LOG.Error(exception);
} }
try { try {
CaptureHelper.CaptureIE(false); CaptureHelper.CaptureIE(false, tabData.Key);
} catch (Exception exception) { } catch (Exception exception) {
LOG.Error(exception); LOG.Error(exception);
} }

View file

@ -76,9 +76,13 @@ namespace Greenshot.Helpers {
public static void CaptureLastRegion(bool captureMouse) { public static void CaptureLastRegion(bool captureMouse) {
new CaptureHelper(CaptureMode.LastRegion, captureMouse).MakeCapture(); new CaptureHelper(CaptureMode.LastRegion, captureMouse).MakeCapture();
} }
public static void CaptureIE(bool captureMouse) {
new CaptureHelper(CaptureMode.IE, captureMouse).MakeCapture(); public static void CaptureIE(bool captureMouse, WindowDetails windowToCapture) {
CaptureHelper captureHelper = new CaptureHelper(CaptureMode.IE, captureMouse);
captureHelper.SelectedCaptureWindow = windowToCapture;
captureHelper.MakeCapture();
} }
public static void CaptureWindow(bool captureMouse) { public static void CaptureWindow(bool captureMouse) {
new CaptureHelper(CaptureMode.ActiveWindow, captureMouse).MakeCapture(); new CaptureHelper(CaptureMode.ActiveWindow, captureMouse).MakeCapture();
} }
@ -224,7 +228,7 @@ namespace Greenshot.Helpers {
HandleCapture(); HandleCapture();
break; break;
case CaptureMode.IE: case CaptureMode.IE:
if (IECaptureHelper.CaptureIE(capture) != null) { if (IECaptureHelper.CaptureIE(capture, SelectedCaptureWindow) != null) {
capture.CaptureDetails.AddMetaData("source", "Internet Explorer"); capture.CaptureDetails.AddMetaData("source", "Internet Explorer");
HandleCapture(); HandleCapture();
} }
@ -673,9 +677,10 @@ namespace Greenshot.Helpers {
// 2) Is Windows >= Vista & DWM enabled: use DWM // 2) Is Windows >= Vista & DWM enabled: use DWM
// 3) Otherwise use GDI (Screen might be also okay but might lose content) // 3) Otherwise use GDI (Screen might be also okay but might lose content)
if (isAutoMode) { if (isAutoMode) {
if (conf.IECapture && windowToCapture.ClassName == "IEFrame") { // TODO: Decided if this is smart, although we do consider a part of the window...
if (conf.IECapture && IECaptureHelper.IsMostlyIEWindow(windowToCapture, 60)) {
try { try {
ICapture ieCapture = IECaptureHelper.CaptureIE(captureForWindow); ICapture ieCapture = IECaptureHelper.CaptureIE(captureForWindow, windowToCapture);
if (ieCapture != null) { if (ieCapture != null) {
return ieCapture; return ieCapture;
} }

View file

@ -55,16 +55,56 @@ namespace Greenshot.Helpers {
// Activate Tab // Activate Tab
ieAccessible.ActivateIETab(tabIndex); ieAccessible.ActivateIETab(tabIndex);
} }
/// <summary> /// <summary>
/// Return true if the supplied window has a sub-window which covers more than the supplied percentage
/// </summary>
/// <param name="someWindow">WindowDetails to check</param>
/// <param name="minimumPercentage">min percentage</param>
/// <returns></returns>
public static bool IsMostlyIEWindow(WindowDetails someWindow, int minimumPercentage) {
WindowDetails ieWindow = someWindow.GetChild("Internet Explorer_Server");
if (ieWindow != null) {
Rectangle wholeClient = someWindow.ClientRectangle;
Rectangle partClient = ieWindow.ClientRectangle;
int percentage = (int)(100*((float)(partClient.Width * partClient.Height)) / ((float)(wholeClient.Width * wholeClient.Height)));
LOG.InfoFormat("Window {0}, ie part {1}, percentage {2}", wholeClient, partClient, percentage);
if (percentage > minimumPercentage) {
return true;
}
}
return false;
}
/// <summary>
/// Does the supplied window have a IE part?
/// </summary>
/// <param name="someWindow"></param>
/// <returns></returns>
public static bool IsIEWindow(WindowDetails someWindow) {
return someWindow.GetChild("Internet Explorer_Server") != null;
}
/// <summary>
/// Get Windows displaying an IE
/// </summary>
/// <returns>List<WindowDetails></returns>
public static List<WindowDetails> GetIEWindows() {
List<WindowDetails> ieWindows = new List<WindowDetails>();
foreach (WindowDetails possibleIEWindow in WindowDetails.GetVisibleWindows()) {
if (IsIEWindow(possibleIEWindow)) {
ieWindows.Add(possibleIEWindow);
}
}
return ieWindows;
}
/// <summary>
/// Simple check if IE is running /// Simple check if IE is running
/// </summary> /// </summary>
/// <returns>bool</returns> /// <returns>bool</returns>
public static bool IsIERunning() { public static bool IsIERunning() {
foreach (WindowDetails shellWindow in WindowDetails.GetAllWindows("IEFrame")) { return GetIEWindows().Count > 0;
return true;
}
return false;
} }
/// <summary> /// <summary>
@ -76,7 +116,8 @@ namespace Greenshot.Helpers {
Dictionary<WindowDetails, List<string>> browserWindows = new Dictionary<WindowDetails, List<string>>(); Dictionary<WindowDetails, List<string>> browserWindows = new Dictionary<WindowDetails, List<string>>();
// Find the IE windows // Find the IE windows
foreach (WindowDetails ieWindow in WindowDetails.GetAllWindows("IEFrame")) { List<WindowDetails> ieWindows = GetIEWindows();
foreach (WindowDetails ieWindow in ieWindows) {
try { try {
if (!ieHandleList.Contains(ieWindow.Handle)) { if (!ieHandleList.Contains(ieWindow.Handle)) {
WindowDetails directUIWD = IEHelper.GetDirectUI(ieWindow); WindowDetails directUIWD = IEHelper.GetDirectUI(ieWindow);
@ -108,10 +149,10 @@ namespace Greenshot.Helpers {
/// Helper method which will retrieve the IHTMLDocument2 for the supplied window, /// Helper method which will retrieve the IHTMLDocument2 for the supplied window,
/// or return the first if none is supplied. /// or return the first if none is supplied.
/// </summary> /// </summary>
/// <param name="browserWindowDetails">The WindowDetails to get the IHTMLDocument2 for</param> /// <param name="browserWindow">The WindowDetails to get the IHTMLDocument2 for</param>
/// <param name="document2">Ref to the IHTMLDocument2 to return</param> /// <param name="document2">Ref to the IHTMLDocument2 to return</param>
/// <returns>The WindowDetails to which the IHTMLDocument2 belongs</returns> /// <returns>The WindowDetails to which the IHTMLDocument2 belongs</returns>
private static DocumentContainer GetDocument(WindowDetails activeWindow) { private static DocumentContainer GetDocument(WindowDetails browserWindow) {
DocumentContainer returnDocumentContainer = null; DocumentContainer returnDocumentContainer = null;
WindowDetails returnWindow = null; WindowDetails returnWindow = null;
IHTMLDocument2 returnDocument2 = null; IHTMLDocument2 returnDocument2 = null;
@ -119,8 +160,8 @@ namespace Greenshot.Helpers {
WindowDetails alternativeReturnWindow = null; WindowDetails alternativeReturnWindow = null;
IHTMLDocument2 alternativeReturnDocument2 = null; IHTMLDocument2 alternativeReturnDocument2 = null;
// Find the IE window // Find the IE windows
foreach (WindowDetails ieWindow in WindowDetails.GetAllWindows("IEFrame")) { foreach (WindowDetails ieWindow in GetIEWindows()) {
LOG.DebugFormat("Processing {0} - {1}", ieWindow.ClassName, ieWindow.Text); LOG.DebugFormat("Processing {0} - {1}", ieWindow.ClassName, ieWindow.Text);
Accessible ieAccessible = null; Accessible ieAccessible = null;
@ -129,8 +170,8 @@ namespace Greenshot.Helpers {
ieAccessible = new Accessible(directUIWD.Handle); ieAccessible = new Accessible(directUIWD.Handle);
} }
if (ieAccessible == null) { if (ieAccessible == null) {
LOG.InfoFormat("Active Window is {0}", activeWindow.Text); LOG.InfoFormat("Active Window is {0}", browserWindow.Text);
if (!ieWindow.Equals(activeWindow)) { if (!ieWindow.Equals(browserWindow)) {
LOG.WarnFormat("No ieAccessible for {0}", ieWindow.Text); LOG.WarnFormat("No ieAccessible for {0}", ieWindow.Text);
continue; continue;
} }
@ -185,7 +226,7 @@ namespace Greenshot.Helpers {
break; break;
} }
try { try {
if (ieWindow.Equals(activeWindow)) { if (ieWindow.Equals(browserWindow)) {
returnDocument2 = document2; returnDocument2 = document2;
returnWindow = new WindowDetails(contentWindowHandle); returnWindow = new WindowDetails(contentWindowHandle);
break; break;
@ -234,15 +275,25 @@ namespace Greenshot.Helpers {
/// <param name="capture">ICapture where the capture needs to be stored</param> /// <param name="capture">ICapture where the capture needs to be stored</param>
/// <returns>ICapture with the content (if any)</returns> /// <returns>ICapture with the content (if any)</returns>
public static ICapture CaptureIE(ICapture capture) { public static ICapture CaptureIE(ICapture capture) {
WindowDetails activeWindow = WindowDetails.GetActiveWindow(); return CaptureIE(capture, WindowDetails.GetActiveWindow());
}
/// <summary>
/// Here the logic for capturing the IE Content is located
/// </summary>
/// <param name="capture">ICapture where the capture needs to be stored</param>
/// <param name="windowToCapture">window to use</param>
/// <returns>ICapture with the content (if any)</returns>
public static ICapture CaptureIE(ICapture capture, WindowDetails windowToCapture) {
if (windowToCapture == null) {
return CaptureIE(capture, WindowDetails.GetActiveWindow());
}
// Show backgroundform after retrieving the active window.. // Show backgroundform after retrieving the active window..
BackgroundForm backgroundForm = new BackgroundForm(Language.GetString(LangKey.contextmenu_captureie), Language.GetString(LangKey.wait_ie_capture)); BackgroundForm backgroundForm = new BackgroundForm(Language.GetString(LangKey.contextmenu_captureie), Language.GetString(LangKey.wait_ie_capture));
backgroundForm.Show(); backgroundForm.Show();
//BackgroundForm backgroundForm = BackgroundForm.ShowAndWait(language.GetString(LangKey.contextmenu_captureie), language.GetString(LangKey.wait_ie_capture)); //BackgroundForm backgroundForm = BackgroundForm.ShowAndWait(language.GetString(LangKey.contextmenu_captureie), language.GetString(LangKey.wait_ie_capture));
try { try {
//Get IHTMLDocument2 for the current active window //Get IHTMLDocument2 for the current active window
DocumentContainer documentContainer = GetDocument(activeWindow); DocumentContainer documentContainer = GetDocument(windowToCapture);
// Nothing found // Nothing found
if (documentContainer == null) { if (documentContainer == null) {
@ -299,7 +350,7 @@ namespace Greenshot.Helpers {
if (documentContainer.Name != null) { if (documentContainer.Name != null) {
capture.CaptureDetails.Title = documentContainer.Name; capture.CaptureDetails.Title = documentContainer.Name;
} else { } else {
capture.CaptureDetails.Title = activeWindow.Text; capture.CaptureDetails.Title = windowToCapture.Text;
} }
// Store the URL of the page // Store the URL of the page