Repository navigation
Expand file tree
/
Copy pathToolStripEx.cs
More file actions
91 lines (78 loc) · 2.83 KB
/
Copy pathToolStripEx.cs
File metadata and controls
91 lines (78 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using System.Text;
using System.Windows.Forms;
using System.Collections.Generic;
using PluginCore.Managers;
using System.Reflection;
namespace PluginCore.Controls
{
public class ToolStripEx : ToolStrip
{
#region Win32
private const UInt32 MA_ACTIVATE = 1;
private const UInt32 MA_ACTIVATEANDEAT = 2;
private const UInt32 WM_MOUSEACTIVATE = 0x21;
#endregion
private Boolean clickThrough = true;
/// <summary>
/// Listen for all items added
/// </summary>
public ToolStripEx()
{
this.ItemAdded += new ToolStripItemEventHandler(this.OnItemAdded);
((Form)PluginBase.MainForm).Deactivate += new EventHandler(this.OnFormDeactivate);
((Form)PluginBase.MainForm).Activated += new EventHandler(this.OnFormDeactivate);
}
/// <summary>
/// When the main form loses or gains input focus, clear all selections and repaint
/// </summary>
private void OnFormDeactivate(object sender, EventArgs e)
{
try
{
MethodInfo method = typeof(ToolStrip).GetMethod("ClearAllSelections", BindingFlags.NonPublic | BindingFlags.Instance);
method.Invoke(this, null);
this.Invalidate();
}
catch { /* No errors... */ }
}
/// <summary>
/// When button is added, listen for it's hover events
/// </summary>
private void OnItemAdded(Object sender, ToolStripItemEventArgs e)
{
if (e.Item is ToolStripButton)
{
e.Item.MouseEnter += new EventHandler(this.OnOverChange);
e.Item.MouseLeave += new EventHandler(this.OnOverChange);
}
}
/// <summary>
/// Invalidate button if it is not selected to workaround the "textbox selected, no button hover" issue. :)
/// </summary>
private void OnOverChange(Object sender, EventArgs e)
{
ToolStripItem item = sender as ToolStripItem;
if (!item.Selected) item.Invalidate();
}
/// <summary>
/// Gets or sets whether the ToolStripEx honors item clicks when its containing form does not have input focus.
/// </summary>
public bool ClickThrough
{
get { return this.clickThrough; }
set { this.clickThrough = value; }
}
/// <summary>
/// If ClickThrough is enabled do not eat the activate event.
/// </summary>
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (this.clickThrough && m.Msg == WM_MOUSEACTIVATE && m.Result == (IntPtr)MA_ACTIVATEANDEAT)
{
m.Result = (IntPtr)MA_ACTIVATE;
}
}
}
}