using System; using System.Windows.Forms; namespace PaintDotNet.SystemLayer { /// /// This class adds on to the functionality provided in System.Windows.Forms.MenuStrip. /// public class MenuStripEx : MenuStrip { private bool clickThrough = true; private static int openCount = 0; public MenuStripEx() { this.ImageScalingSize = new System.Drawing.Size(UI.ScaleWidth(16), UI.ScaleHeight(16)); } /// /// Gets or sets whether the ToolStripEx honors item clicks when its containing form does /// not have input focus. /// /// /// Default value is true, which is the opposite of the behavior provided by the base /// ToolStrip class. /// 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) { UI.ClickThroughWndProc(ref m); } } /// /// Gets a value indicating whether any menu is currently open. /// /// /// To be precise, this will return true if any menu has raised its MenuActivate event /// but has yet to raise its MenuDeactivate event. public static bool IsAnyMenuActive { get { return openCount > 0; } } public static void PushMenuActivate() { ++openCount; } public static void PopMenuActivate() { --openCount; } protected override void OnMenuActivate(EventArgs e) { ++openCount; base.OnMenuActivate(e); } protected override void OnMenuDeactivate(EventArgs e) { --openCount; base.OnMenuDeactivate(e); } } }