Updates to DropDownPanel, Baseline, & Controls

This commit is contained in:
2026-08-05 15:16:53 -04:00
parent 6f0fcdded2
commit 6d7d127b63
14 changed files with 356 additions and 453 deletions
@@ -1,4 +1,3 @@
using System;
using System.Drawing;
using System.Windows.Forms;
@@ -21,59 +20,48 @@ namespace AT.STO.UI.Win
private const int WM_NCLBUTTONDOWN = 0x0A1;
private const int WM_NCRBUTTONDOWN = 0x0A4;
private const int WM_NCMBUTTONDOWN = 0x0A7;
#endregion
#region Private Variable Declarations
private Form _dropDown = null;
private DropDownWindowHelper _owner = null;
#endregion
#region Private Variable Declarations
private readonly DropDownWindowHelper _owner = null;
#endregion
#region Event Declarations
public event DropDownCancelEventHandler DropDownCancel;
#endregion
#region Constructor / Destructor
/// <summary>
/// Constructs a new instance of this class and sets the owning
/// object.
/// </summary>
/// <param name="Owner">The <see cref="DropDownWindowHelper"/> object
/// which owns this class.</param>
public DropDownMessageFilter(DropDownWindowHelper Owner)
{
_owner = Owner;
}
#endregion
#region Public Properties
/// <summary>
/// Gets/sets the dropdown form which is being displayed.
/// </summary>
public Form DropDown
{
get { return _dropDown; }
set { _dropDown = value; }
}
#endregion
#region Private Methods
private void OnMouseDown()
#endregion
#region Constructor / Destructor
/// <summary>
/// Constructs a new instance of this class and sets the owning
/// object.
/// </summary>
/// <param name="Owner">The <see cref="DropDownWindowHelper"/> object
/// which owns this class.</param>
public DropDownMessageFilter(DropDownWindowHelper Owner) => _owner = Owner;
#endregion
#region Public Properties
/// <summary>
/// Gets/sets the dropdown form which is being displayed.
/// </summary>
public Form DropDown { get; set; } = null;
#endregion
#region Private Methods
private void OnMouseDown()
{
Point cursorPos = Cursor.Position; // Get the cursor location
if (!_dropDown.Bounds.Contains(cursorPos)) // Check if it is within the popup form
if (!DropDown.Bounds.Contains(cursorPos)) // Check if it is within the popup form
{
OnDropDownCancel(new DropDownCancelEventArgs(_dropDown, cursorPos)); // If not, then call to see if it should be closed
OnDropDownCancel(new DropDownCancelEventArgs(DropDown, cursorPos)); // If not, then call to see if it should be closed
}
}
#endregion
#region DropDownCancelEvent Implementation
protected virtual void OnDropDownCancel(DropDownCancelEventArgs e)
{
if (this.DropDownCancel != null)
{
this.DropDownCancel(this, e);
}
DropDownCancel?.Invoke(this, e);
if (!e.Cancel)
if (!e.Cancel)
{
_owner.CloseDropDown();
_dropDown = null; // Clear reference for GC
DropDown = null; // Clear reference for GC
}
}
#endregion
@@ -90,7 +78,7 @@ namespace AT.STO.UI.Win
/// This implementation always returns <c>false</c>.</returns>
public bool PreFilterMessage(ref Message m)
{
if (_dropDown != null)
if (DropDown != null)
{
switch (m.Msg)
{
@@ -1,6 +1,5 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace AT.STO.UI.Win
@@ -22,7 +21,7 @@ namespace AT.STO.UI.Win
private Form _dropDown = null;
private bool _dropDownShowing = false;
private DropDownMessageFilter _filter = null;
private readonly DropDownMessageFilter _filter = null;
private Form _owner = null;
private bool _skipClose = false;
#endregion
@@ -42,31 +41,25 @@ namespace AT.STO.UI.Win
_filter.DropDownCancel -= new DropDownCancelEventHandler(Popup_Cancel);
_filter.DropDownCancel += new DropDownCancelEventHandler(Popup_Cancel);
}
#endregion
#region Event Handler
private void Popup_Cancel(object sender, DropDownCancelEventArgs e)
{
OnDropDownCancel(e);
}
#endregion
#region Event Handler
private void Popup_Cancel(object sender, DropDownCancelEventArgs e) => OnDropDownCancel(e);
/// <summary>
/// Responds to the <see cref="System.Windows.Forms.Form.Closed"/>
/// event from the popup form.
/// </summary>
/// <param name="sender">Popup form that has been closed.</param>
/// <param name="e">Not used.</param>
private void Popup_Closed(object sender, EventArgs e)
{
CloseDropDown();
}
/// <summary>
/// Subclasses the owning form's existing Window Procedure to enables the
/// title bar to remain active when a popup is show, and to detect if
/// the user clicks onto another application whilst the popup is visible.
/// </summary>
/// <param name="m">Window Procedure Message</param>
protected override void WndProc(ref Message m)
/// <summary>
/// Responds to the <see cref="System.Windows.Forms.Form.Closed"/>
/// event from the popup form.
/// </summary>
/// <param name="sender">Popup form that has been closed.</param>
/// <param name="e">Not used.</param>
private void Popup_Closed(object sender, EventArgs e) => CloseDropDown();
/// <summary>
/// Subclasses the owning form's existing Window Procedure to enables the
/// title bar to remain active when a popup is show, and to detect if
/// the user clicks onto another application whilst the popup is visible.
/// </summary>
/// <param name="m">Window Procedure Message</param>
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
@@ -76,7 +69,7 @@ namespace AT.STO.UI.Win
{
if (((int)m.WParam) == 0) // Check if the title bar will made inactive:
{ // Note it's no good to try and consume this message; if you try to do that you'll end up with windows
UIApiCalls.SendMessage(this.Handle, UIApiCalls.WM_NCACTIVATE, 1, IntPtr.Zero); // If so reactivate it.
UIApiCalls.SendMessage(Handle, UIApiCalls.WM_NCACTIVATE, 1, IntPtr.Zero); // If so reactivate it.
}
}
else if (m.Msg == UIApiCalls.WM_ACTIVATEAPP)
@@ -84,7 +77,7 @@ namespace AT.STO.UI.Win
if ((int)m.WParam == 0) // Check if the application is being deactivated.
{
CloseDropDown(); // It is so cancel the popup:
UIApiCalls.PostMessage(this.Handle, UIApiCalls.WM_NCACTIVATE, 0, IntPtr.Zero); // And put the title bar into the inactive state:
UIApiCalls.PostMessage(Handle, UIApiCalls.WM_NCACTIVATE, 0, IntPtr.Zero); // And put the title bar into the inactive state:
}
}
}
@@ -168,22 +161,19 @@ namespace AT.STO.UI.Win
_owner = null;
}
}
#endregion
#region Public Properties
/// <summary>
/// Indicator weither the DropDown is showing.
/// </summary>
public bool DropDownShowing
#endregion
#region Public Properties
/// <summary>
/// Indicator weither the DropDown is showing.
/// </summary>
public bool DropDownShowing => _dropDownShowing;
#endregion
#region Event Implementation
protected virtual void OnDropDownCancel(DropDownCancelEventArgs e)
{
get { return _dropDownShowing; }
}
#endregion
#region Event Implementation
protected virtual void OnDropDownCancel(DropDownCancelEventArgs e)
{
if (this.DropDownCancel != null)
if (DropDownCancel != null)
{
this.DropDownCancel(this, e);
DropDownCancel(this, e);
if (!e.Cancel)
{
@@ -191,14 +181,8 @@ namespace AT.STO.UI.Win
}
}
}
protected virtual void OnPDropDownClosed(DropDownClosedEventArgs e)
{
if (this.DropDownClosed != null)
{
this.DropDownClosed(this, e);
}
}
#endregion
}
protected virtual void OnPDropDownClosed(DropDownClosedEventArgs e) => DropDownClosed?.Invoke(this, e);
#endregion
}
}