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
+32 -45
View File
@@ -1,6 +1,5 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
@@ -15,7 +14,7 @@ namespace AT.STO.UI.Win
{
#region Private Variable Declarations
private IDropDownAware _dropDownControl = null;
private DropDownWindowHelper _dropDownHelper = null;
private readonly DropDownWindowHelper _dropDownHelper = null;
private Form _owner = null;
#endregion
#region Constructor / Destructor
@@ -47,7 +46,7 @@ namespace AT.STO.UI.Win
/// <param name="e"></param>
protected override void OnHandleCreated(EventArgs e)
{
_owner = this.FindForm();
_owner = FindForm();
_dropDownHelper.ReleaseHandle();
if (_owner != null)
@@ -66,8 +65,8 @@ namespace AT.STO.UI.Win
{
base.OnResize(e);
combo.Location = new Point(0, 0);
combo.Width = this.ClientRectangle.Width;
this.Height = combo.Height;
combo.Width = ClientRectangle.Width;
Height = combo.Height;
}
#endregion
#region Event Handler
@@ -96,7 +95,7 @@ namespace AT.STO.UI.Win
else
{
_dropDownHelper.CloseDropDown();
this.Focus();
Focus();
}
}
@@ -115,7 +114,7 @@ namespace AT.STO.UI.Win
private void DropDownHelper_DropDownCancel(object sender, DropDownCancelEventArgs e)
{
if (this.Bounds.Contains(Parent.PointToClient(e.CursorLocation)))
if (Bounds.Contains(Parent.PointToClient(e.CursorLocation)))
{
e.Cancel = true;
}
@@ -137,31 +136,22 @@ namespace AT.STO.UI.Win
{
SetValue<long>(e.Value as ILookupItem<long>);
}
if (this.FinishEditing != null)
{
this.FinishEditing(this, e);
}
_dropDownControl.FinishEditing -= new DropDownValueChangedEventHandler(DropDown_FinishEditing);
FinishEditing?.Invoke(this, e);
_dropDownControl.FinishEditing -= new DropDownValueChangedEventHandler(DropDown_FinishEditing);
_dropDownControl.ValueChanged -= new DropDownValueChangedEventHandler(DropDown_ValueChanged);
_dropDownHelper.CloseDropDown();
}
private void DropDown_ValueChanged(object sender, DropDownValueChangedEventArgs e)
{
if (this.ValueChanged != null)
{
this.ValueChanged(this, e);
}
}
#endregion
#region Public Properties
/// <summary>
/// Get or set the control (has to implement IDropDownAware) that is to
/// be displayed as the dropdown portion of the combobox.
/// </summary>
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
private void DropDown_ValueChanged(object sender, DropDownValueChangedEventArgs e) => ValueChanged?.Invoke(this, e);
#endregion
#region Public Properties
/// <summary>
/// Get or set the control (has to implement IDropDownAware) that is to
/// be displayed as the dropdown portion of the combobox.
/// </summary>
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public IDropDownAware DropDownControl
{
get { return _dropDownControl; }
@@ -169,24 +159,21 @@ namespace AT.STO.UI.Win
{
_dropDownControl = value;
this.Controls.Add(_dropDownControl as Control);
Controls.Add(_dropDownControl as Control);
}
}
#endregion
#region Public Methods
public override string ToString()
{
return this.Name;
}
#endregion
#region Private Methods
/// <summary>
/// Calculate an acceptable position of the DropDownForm even in a
/// multi screen environment.
/// </summary>
/// <param name="DropDown"></param>
/// <returns></returns>
private Point GetDropDownPosition(DropDownForm DropDown)
#endregion
#region Public Methods
public override string ToString() => Name;
#endregion
#region Private Methods
/// <summary>
/// Calculate an acceptable position of the DropDownForm even in a
/// multi screen environment.
/// </summary>
/// <param name="DropDown"></param>
/// <returns></returns>
private Point GetDropDownPosition(DropDownForm DropDown)
{
Point lt = Parent.PointToScreen(new Point(Left, Top));
Point rb = Parent.PointToScreen(new Point(Right, Bottom));
+58 -83
View File
@@ -35,10 +35,9 @@ namespace AT.STO.UI.Win
/// </summary>
public class DropDownCancelEventArgs : EventArgs
{
#region Private Variable Declarations
private bool _cancel = false;
private Point _cursorLocation;
private Form _dropDown = null;
#region Private Variable Declarations
private Point _cursorLocation;
private readonly Form _dropDown = null;
#endregion
#region Constructor / Destructor
/// <summary>
@@ -51,36 +50,26 @@ namespace AT.STO.UI.Win
{
_dropDown = DropDown;
_cursorLocation = CursorLocation;
_cancel = false;
}
#endregion
#region Public Properties
/// <summary>
///
/// </summary>
public bool Cancel
{
get { return _cancel; }
set { _cancel = value; }
Cancel = false;
}
#endregion
#region Public Properties
/// <summary>
///
/// </summary>
public bool Cancel { get; set; } = false;
/// <summary>
///
/// </summary>
public Point CursorLocation
{
get { return _cursorLocation; }
}
/// <summary>
///
/// </summary>
public Point CursorLocation => _cursorLocation;
/// <summary>
///
/// </summary>
public Form DropDown
{
get { return _dropDown; }
}
#endregion
}
/// <summary>
///
/// </summary>
public Form DropDown => _dropDown;
#endregion
}
/// <summary>
/// Contains event information for a <see cref="DropDownClosed"/> event.
@@ -91,64 +80,50 @@ namespace AT.STO.UI.Win
public class DropDownClosedEventArgs : EventArgs
{
#region Private Variable Declarations
private Form _dropDown = null;
#endregion
#region Constructor / Destructor
/// <summary>
/// Constructs a new instance of this class for the specified
/// popup form.
/// </summary>
/// <param name="DropDown">DropDown Form which is being closed.</param>
public DropDownClosedEventArgs(Form DropDown)
{
_dropDown = DropDown;
}
#endregion
#region Public Properties
/// <summary>
/// Gets the dropdown form which is being closed.
/// </summary>
public Form DropDown
{
get { return _dropDown; }
}
#endregion
}
private readonly Form _dropDown = null;
#endregion
#region Constructor / Destructor
/// <summary>
/// Constructs a new instance of this class for the specified
/// popup form.
/// </summary>
/// <param name="DropDown">DropDown Form which is being closed.</param>
public DropDownClosedEventArgs(Form DropDown) => _dropDown = DropDown;
#endregion
#region Public Properties
/// <summary>
/// Gets the dropdown form which is being closed.
/// </summary>
public Form DropDown => _dropDown;
#endregion
}
/// <summary>
/// Contains event information for DropDownValueChangedEventHandler.
/// </summary>
public class DropDownValueChangedEventArgs : EventArgs
{
#region Private Variable Declarations
private object _value = null;
#endregion
#region Constructor / Destructor
/// <summary>
/// Default Constructor
/// </summary>
public DropDownValueChangedEventArgs()
#region Private Variable Declarations
#endregion
#region Constructor / Destructor
/// <summary>
/// Default Constructor
/// </summary>
public DropDownValueChangedEventArgs()
{
}
/// <summary>
/// Initialization with the control's value.
/// </summary>
/// <param name="Value"></param>
public DropDownValueChangedEventArgs(object Value)
{
_value = Value;
}
#endregion
#region Public Properties
/// <summary>
/// Gets or sets the control's value.
/// </summary>
public object Value
{
get { return _value; }
set { _value = value; }
}
#endregion
}
/// <summary>
/// Initialization with the control's value.
/// </summary>
/// <param name="Value"></param>
public DropDownValueChangedEventArgs(object Value) => this.Value = Value;
#endregion
#region Public Properties
/// <summary>
/// Gets or sets the control's value.
/// </summary>
public object Value { get; set; } = null;
#endregion
}
}
+28 -40
View File
@@ -13,22 +13,19 @@ namespace AT.STO.UI.Win
internal partial class DropDownForm : Form, IDropDownAware
{
#region Private Variable Declaration
private IDropDownAware _control = null;
#endregion
#region Constructor / Destructor
/// <summary>
/// Default Constructor
/// </summary>
public DropDownForm()
{
InitializeComponent();
}
private readonly IDropDownAware _control = null;
#endregion
#region Constructor / Destructor
/// <summary>
/// Default Constructor
/// </summary>
public DropDownForm() => InitializeComponent();
/// <summary>
/// Constructor to initialize the for with the control to display.
/// </summary>
/// <param name="Ctrl">The control to display.</param>
public DropDownForm(IDropDownAware Ctrl) : this()
/// <summary>
/// Constructor to initialize the for with the control to display.
/// </summary>
/// <param name="Ctrl">The control to display.</param>
public DropDownForm(IDropDownAware Ctrl) : this()
{
if (Ctrl != null)
{
@@ -41,7 +38,7 @@ namespace AT.STO.UI.Win
#region Form Events
protected override void OnClosing(CancelEventArgs e)
{
this.Controls.Remove(_control as Control);
Controls.Remove(_control as Control);
base.OnClosing(e);
}
@@ -58,29 +55,20 @@ namespace AT.STO.UI.Win
#region Event Handler
private void Ctrl_FinishEditing(object sender, DropDownValueChangedEventArgs e)
{
if (this.FinishEditing != null)
{
this.FinishEditing(this, e);
}
FinishEditing?.Invoke(this, e);
_control.FinishEditing -= new DropDownValueChangedEventHandler(Ctrl_FinishEditing);
_control.FinishEditing -= new DropDownValueChangedEventHandler(Ctrl_FinishEditing);
_control.ValueChanged -= new DropDownValueChangedEventHandler(Ctrl_ValueChanged);
}
private void Ctrl_ValueChanged(object sender, DropDownValueChangedEventArgs e)
{
if (this.ValueChanged != null)
{
this.ValueChanged(this, e);
}
}
#endregion
#region IDropDownAware Implementation
/// <summary>
/// Fired either on OK, Cancel or a click outside the control to indicate
/// that the user has finished editing.
/// </summary>
public event DropDownValueChangedEventHandler FinishEditing;
private void Ctrl_ValueChanged(object sender, DropDownValueChangedEventArgs e) => ValueChanged?.Invoke(this, e);
#endregion
#region IDropDownAware Implementation
/// <summary>
/// Fired either on OK, Cancel or a click outside the control to indicate
/// that the user has finished editing.
/// </summary>
public event DropDownValueChangedEventHandler FinishEditing;
/// <summary>
/// Fired on any change of the controls's value during the editing process.
@@ -100,15 +88,15 @@ namespace AT.STO.UI.Win
private void InitializeControl(Control Ctrl)
{
Size size = Ctrl.Size;
Size inner = this.ClientRectangle.Size;
Size outer = this.Size;
Size inner = ClientRectangle.Size;
Size outer = Size;
int gap = outer.Width - inner.Width;
size.Width += gap;
size.Height += gap;
this.Size = size;
this.Controls.Add(Ctrl);
Size = size;
Controls.Add(Ctrl);
Ctrl.Location = new Point(0, 0);
Ctrl.Visible = true;
Ctrl.Invalidate();
@@ -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
}
}
@@ -1,5 +1,3 @@
using System;
namespace AT.STO.UI.Win
{
/// <summary>
@@ -1,5 +1,3 @@
using System;
namespace AT.STO.UI.Win
{
public interface ILookupItem<T> where T: struct