Fixed focus problems with the EditorForm: Problems when clicking on a ToolStrip/MenuStrip when the form didn't have focus by adding two new controls for this. Also fixed the PrintDialog issue by using a BeginInvoke.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1623 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-02-02 12:02:07 +00:00
commit 0e522f6afc
5 changed files with 152 additions and 17 deletions

View file

@ -0,0 +1,66 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2011 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace Greenshot.Controls {
/// <summary>
/// This is an extension of the default MenuStrip and allows us to click it even when the form doesn't have focus.
/// See: http://blogs.msdn.com/b/rickbrew/archive/2006/01/09/511003.aspx
/// </summary>
public class MenuStripEx : MenuStrip {
private const int WM_MOUSEACTIVATE = 0x21;
enum NativeConstants : uint {
MA_ACTIVATE = 1,
MA_ACTIVATEANDEAT = 2,
MA_NOACTIVATE = 3,
MA_NOACTIVATEANDEAT = 4,
}
private bool clickThrough = false;
/// <summary>
/// Gets or sets whether the ToolStripEx honors item clicks when its containing form does not have input focus.
/// </summary>
/// <remarks>
/// Default value is false, which is the same behavior provided by the base ToolStrip class.
/// </remarks>
public bool ClickThrough {
get {
return this.clickThrough;
}
set {
this.clickThrough = value;
}
}
protected override void WndProc(ref Message m) {
base.WndProc(ref m);
if (this.clickThrough && m.Msg == WM_MOUSEACTIVATE && m.Result == (IntPtr)NativeConstants.MA_ACTIVATEANDEAT) {
m.Result = (IntPtr)NativeConstants.MA_ACTIVATE;
}
}
}
}

View file

@ -0,0 +1,66 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2011 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace Greenshot.Controls {
/// <summary>
/// This is an extension of the default ToolStrip and allows us to click it even when the form doesn't have focus.
/// See: http://blogs.msdn.com/b/rickbrew/archive/2006/01/09/511003.aspx
/// </summary>
class ToolStripEx : ToolStrip {
private const int WM_MOUSEACTIVATE = 0x21;
enum NativeConstants : uint {
MA_ACTIVATE = 1,
MA_ACTIVATEANDEAT = 2,
MA_NOACTIVATE = 3,
MA_NOACTIVATEANDEAT = 4,
}
private bool clickThrough = false;
/// <summary>
/// Gets or sets whether the ToolStripEx honors item clicks when its containing form does not have input focus.
/// </summary>
/// <remarks>
/// Default value is false, which is the same behavior provided by the base ToolStrip class.
/// </remarks>
public bool ClickThrough {
get {
return this.clickThrough;
}
set {
this.clickThrough = value;
}
}
protected override void WndProc(ref Message m) {
base.WndProc(ref m);
if (this.clickThrough && m.Msg == WM_MOUSEACTIVATE && m.Result == (IntPtr)NativeConstants.MA_ACTIVATEANDEAT) {
m.Result = (IntPtr)NativeConstants.MA_ACTIVATE;
}
}
}
}

View file

@ -52,7 +52,7 @@ namespace Greenshot {
this.statusLabel = new System.Windows.Forms.ToolStripStatusLabel(); this.statusLabel = new System.Windows.Forms.ToolStripStatusLabel();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.panel1 = new GreenshotPlugin.Controls.NonJumpingPanel(); this.panel1 = new GreenshotPlugin.Controls.NonJumpingPanel();
this.toolStrip2 = new System.Windows.Forms.ToolStrip(); this.toolStrip2 = new Greenshot.Controls.ToolStripEx();
this.btnCursor = new System.Windows.Forms.ToolStripButton(); this.btnCursor = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.btnRect = new System.Windows.Forms.ToolStripButton(); this.btnRect = new System.Windows.Forms.ToolStripButton();
@ -68,7 +68,7 @@ namespace Greenshot {
this.btnFreehand = new System.Windows.Forms.ToolStripButton(); this.btnFreehand = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparator13 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripSeparator13 = new System.Windows.Forms.ToolStripSeparator();
this.btnCrop = new System.Windows.Forms.ToolStripButton(); this.btnCrop = new System.Windows.Forms.ToolStripButton();
this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.menuStrip1 = new Greenshot.Controls.MenuStripEx();
this.fileStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.fileStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator9 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripSeparator9 = new System.Windows.Forms.ToolStripSeparator();
this.closeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.closeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@ -104,7 +104,7 @@ namespace Greenshot {
this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.helpToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.helpToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStrip1 = new System.Windows.Forms.ToolStrip(); this.toolStrip1 = new Greenshot.Controls.ToolStripEx();
this.btnSave = new System.Windows.Forms.ToolStripButton(); this.btnSave = new System.Windows.Forms.ToolStripButton();
this.btnClipboard = new System.Windows.Forms.ToolStripButton(); this.btnClipboard = new System.Windows.Forms.ToolStripButton();
this.btnPrint = new System.Windows.Forms.ToolStripButton(); this.btnPrint = new System.Windows.Forms.ToolStripButton();
@ -120,7 +120,7 @@ namespace Greenshot {
this.btnSettings = new System.Windows.Forms.ToolStripButton(); this.btnSettings = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparator11 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripSeparator11 = new System.Windows.Forms.ToolStripSeparator();
this.btnHelp = new System.Windows.Forms.ToolStripButton(); this.btnHelp = new System.Windows.Forms.ToolStripButton();
this.propertiesToolStrip = new System.Windows.Forms.ToolStrip(); this.propertiesToolStrip = new Greenshot.Controls.ToolStripEx();
this.obfuscateModeButton = new Greenshot.Controls.BindableToolStripDropDownButton(); this.obfuscateModeButton = new Greenshot.Controls.BindableToolStripDropDownButton();
this.pixelizeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.pixelizeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.blurToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.blurToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@ -161,7 +161,6 @@ namespace Greenshot {
this.btnCancel = new Greenshot.Controls.BindableToolStripButton(); this.btnCancel = new Greenshot.Controls.BindableToolStripButton();
this.btnLineColor_ = new Greenshot.Controls.ToolStripColorButton(); this.btnLineColor_ = new Greenshot.Controls.ToolStripColorButton();
this.btnFillColor_ = new Greenshot.Controls.ToolStripColorButton(); this.btnFillColor_ = new Greenshot.Controls.ToolStripColorButton();
this.printDialog1 = new System.Windows.Forms.PrintDialog();
this.fileSavedStatusContextMenu = new System.Windows.Forms.ContextMenuStrip(this.components); this.fileSavedStatusContextMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
this.copyPathMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.copyPathMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.openDirectoryMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.openDirectoryMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@ -282,6 +281,7 @@ namespace Greenshot {
this.toolStrip2.Size = new System.Drawing.Size(24, 387); this.toolStrip2.Size = new System.Drawing.Size(24, 387);
this.toolStrip2.Stretch = true; this.toolStrip2.Stretch = true;
this.toolStrip2.TabIndex = 0; this.toolStrip2.TabIndex = 0;
this.toolStrip2.ClickThrough = true;
// //
// btnCursor // btnCursor
// //
@ -420,6 +420,7 @@ namespace Greenshot {
this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(785, 24); this.menuStrip1.Size = new System.Drawing.Size(785, 24);
this.menuStrip1.TabIndex = 1; this.menuStrip1.TabIndex = 1;
this.menuStrip1.ClickThrough = true;
// //
// fileStripMenuItem // fileStripMenuItem
// //
@ -762,6 +763,7 @@ namespace Greenshot {
this.toolStrip1.Size = new System.Drawing.Size(785, 25); this.toolStrip1.Size = new System.Drawing.Size(785, 25);
this.toolStrip1.Stretch = true; this.toolStrip1.Stretch = true;
this.toolStrip1.TabIndex = 0; this.toolStrip1.TabIndex = 0;
this.toolStrip1.ClickThrough = true;
// //
// btnSave // btnSave
// //
@ -935,6 +937,7 @@ namespace Greenshot {
this.propertiesToolStrip.Size = new System.Drawing.Size(785, 27); this.propertiesToolStrip.Size = new System.Drawing.Size(785, 27);
this.propertiesToolStrip.Stretch = true; this.propertiesToolStrip.Stretch = true;
this.propertiesToolStrip.TabIndex = 2; this.propertiesToolStrip.TabIndex = 2;
this.propertiesToolStrip.ClickThrough = true;
// //
// obfuscateModeButton // obfuscateModeButton
// //
@ -1423,10 +1426,6 @@ namespace Greenshot {
this.btnFillColor_.SelectedColor = System.Drawing.SystemColors.Control; this.btnFillColor_.SelectedColor = System.Drawing.SystemColors.Control;
this.btnFillColor_.Size = new System.Drawing.Size(23, 23); this.btnFillColor_.Size = new System.Drawing.Size(23, 23);
// //
// printDialog1
//
this.printDialog1.UseEXDialog = true;
//
// fileSavedStatusContextMenu // fileSavedStatusContextMenu
// //
this.fileSavedStatusContextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.fileSavedStatusContextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
@ -1549,7 +1548,7 @@ namespace Greenshot {
private System.Windows.Forms.ToolStripLabel blurRadiusLabel; private System.Windows.Forms.ToolStripLabel blurRadiusLabel;
private Greenshot.Controls.ToolStripColorButton btnFillColor_; private Greenshot.Controls.ToolStripColorButton btnFillColor_;
private Greenshot.Controls.ToolStripColorButton btnLineColor_; private Greenshot.Controls.ToolStripColorButton btnLineColor_;
private System.Windows.Forms.ToolStrip propertiesToolStrip; private Greenshot.Controls.ToolStripEx propertiesToolStrip;
private System.Windows.Forms.ToolStripLabel lineThicknessLabel; private System.Windows.Forms.ToolStripLabel lineThicknessLabel;
private Greenshot.Controls.ToolStripNumericUpDown lineThicknessUpDown; private Greenshot.Controls.ToolStripNumericUpDown lineThicknessUpDown;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator14; private System.Windows.Forms.ToolStripSeparator toolStripSeparator14;
@ -1568,7 +1567,7 @@ namespace Greenshot {
private System.Windows.Forms.ToolStripMenuItem upOneLevelToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem upOneLevelToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem arrangeToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem arrangeToolStripMenuItem;
private System.Windows.Forms.ToolStripButton btnCursor; private System.Windows.Forms.ToolStripButton btnCursor;
private System.Windows.Forms.ToolStrip toolStrip2; private Greenshot.Controls.ToolStripEx toolStrip2;
private System.Windows.Forms.ToolStripButton btnArrow; private System.Windows.Forms.ToolStripButton btnArrow;
private System.Windows.Forms.ToolStripMenuItem drawArrowToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem drawArrowToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem drawFreehandToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem drawFreehandToolStripMenuItem;
@ -1589,7 +1588,6 @@ namespace Greenshot {
private System.Windows.Forms.ToolStripSeparator toolStripSeparator8; private System.Windows.Forms.ToolStripSeparator toolStripSeparator8;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator6; private System.Windows.Forms.ToolStripSeparator toolStripSeparator6;
private System.Windows.Forms.ToolStripButton btnPrint; private System.Windows.Forms.ToolStripButton btnPrint;
private System.Windows.Forms.PrintDialog printDialog1;
private System.Windows.Forms.ToolStripMenuItem duplicateToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem duplicateToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator4; private System.Windows.Forms.ToolStripSeparator toolStripSeparator4;
private System.Windows.Forms.ToolStripMenuItem fileStripMenuItem; private System.Windows.Forms.ToolStripMenuItem fileStripMenuItem;
@ -1604,7 +1602,7 @@ namespace Greenshot {
private System.Windows.Forms.ToolStripMenuItem copyToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem copyToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem cutToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem cutToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem editToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem editToolStripMenuItem;
private System.Windows.Forms.MenuStrip menuStrip1; private Greenshot.Controls.MenuStripEx menuStrip1;
private System.Windows.Forms.ToolStripStatusLabel statusLabel; private System.Windows.Forms.ToolStripStatusLabel statusLabel;
private System.Windows.Forms.StatusStrip statusStrip1; private System.Windows.Forms.StatusStrip statusStrip1;
private System.Windows.Forms.ToolStripButton btnCut; private System.Windows.Forms.ToolStripButton btnCut;
@ -1622,7 +1620,7 @@ namespace Greenshot {
private System.Windows.Forms.ToolStripButton btnSave; private System.Windows.Forms.ToolStripButton btnSave;
private System.Windows.Forms.ToolStripButton btnRect; private System.Windows.Forms.ToolStripButton btnRect;
private System.Windows.Forms.ToolStripContainer toolStripContainer1; private System.Windows.Forms.ToolStripContainer toolStripContainer1;
private System.Windows.Forms.ToolStrip toolStrip1; private Greenshot.Controls.ToolStripEx toolStrip1;
private GreenshotPlugin.Controls.NonJumpingPanel panel1; private GreenshotPlugin.Controls.NonJumpingPanel panel1;
private Greenshot.Controls.ToolStripColorButton btnFillColor; private Greenshot.Controls.ToolStripColorButton btnFillColor;
private Greenshot.Controls.ToolStripColorButton btnLineColor; private Greenshot.Controls.ToolStripColorButton btnLineColor;

View file

@ -24,7 +24,6 @@ using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Drawing.Printing;
using System.IO; using System.IO;
using System.Windows.Forms; using System.Windows.Forms;
@ -38,6 +37,7 @@ using Greenshot.Helpers;
using Greenshot.Plugin; using Greenshot.Plugin;
using GreenshotPlugin.Core; using GreenshotPlugin.Core;
using IniFile; using IniFile;
using System.Threading;
namespace Greenshot { namespace Greenshot {
/// <summary> /// <summary>
@ -476,7 +476,10 @@ namespace Greenshot {
} }
void BtnPrintClick(object sender, EventArgs e) { void BtnPrintClick(object sender, EventArgs e) {
// The BeginInvoke is a solution for the printdialog not having focus
this.BeginInvoke((MethodInvoker) delegate {
DestinationHelper.ExportCapture(Destinations.PrinterDestination.DESIGNATION, surface, surface.CaptureDetails); DestinationHelper.ExportCapture(Destinations.PrinterDestination.DESIGNATION, surface, surface.CaptureDetails);
});
} }
void CloseToolStripMenuItemClick(object sender, System.EventArgs e) { void CloseToolStripMenuItemClick(object sender, System.EventArgs e) {

View file

@ -65,6 +65,8 @@
<Compile Include="Controls\ToolStripColorButton.cs" /> <Compile Include="Controls\ToolStripColorButton.cs" />
<Compile Include="Controls\FontFamilyComboBox.cs" /> <Compile Include="Controls\FontFamilyComboBox.cs" />
<Compile Include="Controls\ToolStripNumericUpDown.cs" /> <Compile Include="Controls\ToolStripNumericUpDown.cs" />
<Compile Include="Controls\ToolStripEx.cs" />
<Compile Include="Controls\MenuStripEx.cs" />
<Compile Include="Destinations\ClipboardDestination.cs" /> <Compile Include="Destinations\ClipboardDestination.cs" />
<Compile Include="Destinations\EditorDestination.cs" /> <Compile Include="Destinations\EditorDestination.cs" />
<Compile Include="Destinations\EmailDestination.cs" /> <Compile Include="Destinations\EmailDestination.cs" />