Skip to content

Commit

Permalink
WatchList - Fixed builder.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stan-Kudri committed Feb 17, 2024
1 parent eeb2295 commit a97c63b
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 54 deletions.
18 changes: 8 additions & 10 deletions WatchList.WinForms/Control/CheckComboBox/CheckBoxComboBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -664,18 +664,19 @@ protected override void OnCheckedChanged(EventArgs e)
// Found that when this event is raised, the bool value of the binded item is not yet updated.
if (_checkBoxComboBox.DataSource != null)
{
PropertyInfo PI = ComboBoxItem.GetType().GetProperty(_checkBoxComboBox.ValueMember);
PI.SetValue(ComboBoxItem, Checked, null);
PropertyInfo pI = ComboBoxItem.GetType().GetProperty(_checkBoxComboBox.ValueMember);
pI.SetValue(ComboBoxItem, Checked, null);
}

base.OnCheckedChanged(e);
// Forces a refresh of the Text displayed in the main TextBox of the ComboBox,

Check warning on line 672 in WatchList.WinForms/Control/CheckComboBox/CheckBoxComboBox.cs

View workflow job for this annotation

GitHub Actions / Lint

Single-line comment should be preceded by blank line
// since that Text will most probably represent a concatenation of selected values.
// Also see DisplayMemberSingleItem on the CheckBoxComboBox for more information.
if (_checkBoxComboBox.DataSource != null)
{
string OldDisplayMember = _checkBoxComboBox.DisplayMember;
string oldDisplayMember = _checkBoxComboBox.DisplayMember;
_checkBoxComboBox.DisplayMember = null;
_checkBoxComboBox.DisplayMember = OldDisplayMember;
_checkBoxComboBox.DisplayMember = oldDisplayMember;
}
}

Expand Down Expand Up @@ -816,22 +817,19 @@ public CheckBoxComboBoxItem this[string displayName]
&& _CheckBoxComboBox.DataSource
== null ? 1 : 0;



for (var Index = startIndex; Index <= Count - 1; Index++)
{
CheckBoxComboBoxItem Item = this[Index];

string text;
string? text;

if (string.IsNullOrEmpty(Item.Text)
&& Item.DataBindings != null
&& Item.DataBindings["Text"] != null)
{
PropertyInfo propertyInfo = Item
.ComboBoxItem.GetType()
PropertyInfo propertyInfo = Item.ComboBoxItem.GetType()
.GetProperty(Item.DataBindings["Text"].BindingMemberInfo.BindingMember);
text = (string)propertyInfo.GetValue(Item.ComboBoxItem, null);
text = propertyInfo.GetValue(Item.ComboBoxItem, null) as string;
}
else
{
Expand Down
113 changes: 69 additions & 44 deletions WatchList.WinForms/Control/CheckComboBox/Popup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@

namespace TestTask.Controls.CheckComboBox
{
[CLSCompliant(true), ToolboxItem(false)]
[CLSCompliant(true)]
[ToolboxItem(false)]
public partial class Popup : ToolStripDropDown
{
#region " Fields & Properties "

private Control content;

/// <summary>
/// Gets the content of the pop-up.
/// </summary>
Expand All @@ -19,23 +21,29 @@ public Control Content
get { return content; }
}

private bool fade;
private bool _fade;

/// <summary>
/// Gets a value indicating whether the <see cref="PopupControl.Popup"/> uses the fade effect.
/// </summary>
/// <value><c>true</c> if pop-up uses the fade effect; otherwise, <c>false</c>.</value>
/// <remarks>To use the fade effect, the FocusOnOpen property also has to be set to <c>true</c>.</remarks>
public bool UseFadeEffect
{
get { return fade; }
get => _fade;
set
{
if (fade == value) return;
fade = value;
if (_fade == value)
{
return;
}

_fade = value;
}
}

private bool focusOnOpen = true;

/// <summary>
/// Gets or sets a value indicating whether to focus the content after the pop-up has been opened.
/// </summary>
Expand All @@ -48,6 +56,7 @@ public bool FocusOnOpen
}

private bool acceptAlt = true;

/// <summary>
/// Gets or sets a value indicating whether presing the alt key should close the pop-up.
/// </summary>
Expand All @@ -58,11 +67,12 @@ public bool AcceptAlt
set { acceptAlt = value; }
}

private Popup ownerPopup;
private Popup childPopup;
private Popup _ownerPopup;
private Popup _childPopup;

private bool _resizable;
private bool resizable;

/// <summary>
/// Gets or sets a value indicating whether this <see cref="PopupControl.Popup" /> is resizable.
/// </summary>
Expand All @@ -76,6 +86,7 @@ public bool Resizable
private ToolStripControlHost host;

Check warning on line 86 in WatchList.WinForms/Control/CheckComboBox/Popup.cs

View workflow job for this annotation

GitHub Actions / Lint

Make field readonly

private Size minSize;

/// <summary>
/// Gets or sets the size that is the lower limit that <see cref="M:System.Windows.Forms.Control.GetPreferredSize(System.Drawing.Size)" /> can specify.
/// </summary>
Expand All @@ -87,6 +98,7 @@ public bool Resizable
}

private Size maxSize;

/// <summary>
/// Gets or sets the size that is the upper limit that <see cref="M:System.Windows.Forms.Control.GetPreferredSize(System.Drawing.Size)" /> can specify.
/// </summary>
Expand Down Expand Up @@ -124,15 +136,15 @@ protected override CreateParams CreateParams
/// Pop-up will be disposed immediately after disposion of the content control.
/// </remarks>
/// <exception cref="T:System.ArgumentNullException"><paramref name="content" /> is <code>null</code>.</exception>
public Popup(Control content)
public Popup(Control? content)
{
if (content == null)
{
throw new ArgumentNullException("content");
}

this.content = content;
fade = SystemInformation.IsMenuAnimationEnabled && SystemInformation.IsMenuFadeEnabled;
_fade = SystemInformation.IsMenuAnimationEnabled && SystemInformation.IsMenuFadeEnabled;
_resizable = true;
InitializeComponent();
AutoSize = false;
Expand All @@ -147,16 +159,16 @@ public Popup(Control content)
Size = content.Size;
content.Location = Point.Empty;
Items.Add(host);
content.Disposed += delegate (object sender, EventArgs e)
content.Disposed += (sender, e) =>
{
content = null;
Dispose(true);
};
content.RegionChanged += delegate (object sender, EventArgs e)
content.RegionChanged += (sender, e) =>
{
UpdateRegion();
};
content.Paint += delegate (object sender, PaintEventArgs e)
content.Paint += (sender, e) =>
{
PaintSizeGrip(e);
};
Expand Down Expand Up @@ -187,6 +199,7 @@ protected void UpdateRegion()
Region.Dispose();
Region = null;
}

if (content.Region != null)
{
Region = content.Region.Clone();
Expand Down Expand Up @@ -229,29 +242,29 @@ public void Show(Control control, Rectangle area)
}

SetOwnerItem(control);
resizableTop = resizableRight = false;
_resizableTop = _resizableRight = false;
Point location = control.PointToScreen(new Point(area.Left, area.Top + area.Height));
Rectangle screen = Screen.FromControl(control).WorkingArea;

if (location.X + Size.Width > (screen.Left + screen.Width))
{
resizableRight = true;
_resizableRight = true;
location.X = (screen.Left + screen.Width) - Size.Width;
}

if (location.Y + Size.Height > (screen.Top + screen.Height))
{
resizableTop = true;
_resizableTop = true;
location.Y -= Size.Height + area.Height;
}

location = control.PointToClient(location);
Show(control, location, ToolStripDropDownDirection.BelowRight);
}

private const int frames = 1;
private const int totalduration = 0; // ML : 2007-11-05 : was 100 but caused a flicker.
private const int frameduration = totalduration / frames;
private const int Frames = 1;
private const int Totalduration = 0; // ML : 2007-11-05 : was 100 but caused a flicker.
private const int Frameduration = Totalduration / Frames;

/// <summary>
/// Adjusts the size of the owner <see cref="T:System.Windows.Forms.ToolStrip" /> to accommodate the <see cref="T:System.Windows.Forms.ToolStripDropDown" /> if the owner <see cref="T:System.Windows.Forms.ToolStrip" /> is currently displayed, or clears and resets active <see cref="T:System.Windows.Forms.ToolStripDropDown" /> child controls of the <see cref="T:System.Windows.Forms.ToolStrip" /> if the <see cref="T:System.Windows.Forms.ToolStrip" /> is not currently displayed.
Expand All @@ -260,22 +273,32 @@ public void Show(Control control, Rectangle area)
protected override void SetVisibleCore(bool visible)
{
double opacity = Opacity;
if (visible && fade && focusOnOpen) Opacity = 0;
if (visible && _fade && focusOnOpen)
{
Opacity = 0;
}

base.SetVisibleCore(visible);
if (!visible || !fade || !focusOnOpen) return;
for (int i = 1; i <= frames; i++)
if (!visible || !_fade || !focusOnOpen)
{
return;
}

for (int i = 1; i <= Frames; i++)
{
if (i > 1)
{
System.Threading.Thread.Sleep(frameduration);
Thread.Sleep(Frameduration);
}
Opacity = opacity * i / frames;

Opacity = opacity * i / Frames;
}

Opacity = opacity;
}

private bool resizableTop;
private bool resizableRight;
private bool _resizableTop;
private bool _resizableRight;

private void SetOwnerItem(Control control)
{
Expand All @@ -287,8 +310,8 @@ private void SetOwnerItem(Control control)
if (control is Popup)
{
Popup popupControl = control as Popup;
ownerPopup = popupControl;
ownerPopup.childPopup = this;
_ownerPopup = popupControl;
_ownerPopup._childPopup = this;
OwnerItem = popupControl.Items[0];
return;
}
Expand Down Expand Up @@ -334,9 +357,9 @@ protected override void OnOpening(CancelEventArgs e)
/// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data.</param>
protected override void OnOpened(EventArgs e)
{
if (ownerPopup != null)
if (_ownerPopup != null)
{
ownerPopup._resizable = false;
_ownerPopup._resizable = false;
}

if (focusOnOpen)
Expand All @@ -349,9 +372,9 @@ protected override void OnOpened(EventArgs e)

protected override void OnClosed(ToolStripDropDownClosedEventArgs e)
{
if (ownerPopup != null)
if (_ownerPopup != null)
{
ownerPopup._resizable = true;
_ownerPopup._resizable = true;
}

base.OnClosed(e);
Expand Down Expand Up @@ -394,17 +417,14 @@ protected override void WndProc(ref Message m)
/// <param name="m">The message.</param>
/// <returns>true, if the WndProc method from the base class shouldn't be invoked.</returns>
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
public bool ProcessResizing(ref Message m)
{
return InternalProcessResizing(ref m, true);
}
public bool ProcessResizing(ref Message m) => InternalProcessResizing(ref m, true);

[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
private bool InternalProcessResizing(ref Message m, bool contentControl)
{
if (m.Msg == NativeMethods.WM_NCACTIVATE && m.WParam != IntPtr.Zero && childPopup != null && childPopup.Visible)
if (m.Msg == NativeMethods.WM_NCACTIVATE && m.WParam != IntPtr.Zero && _childPopup != null && _childPopup.Visible)
{
childPopup.Hide();
_childPopup.Hide();
}

if (!Resizable)
Expand Down Expand Up @@ -443,15 +463,15 @@ private bool OnNcHitTest(ref Message m, bool contentControl)
GripBounds gripBouns = new GripBounds(contentControl ? content.ClientRectangle : ClientRectangle);
IntPtr transparent = new IntPtr(NativeMethods.HTTRANSPARENT);

if (resizableTop)
if (_resizableTop)
{
if (resizableRight && gripBouns.TopLeft.Contains(clientLocation))
if (_resizableRight && gripBouns.TopLeft.Contains(clientLocation))
{
m.Result = contentControl ? transparent : (IntPtr)NativeMethods.HTTOPLEFT;
return true;
}

if (!resizableRight && gripBouns.TopRight.Contains(clientLocation))
if (!_resizableRight && gripBouns.TopRight.Contains(clientLocation))
{
m.Result = contentControl ? transparent : (IntPtr)NativeMethods.HTTOPRIGHT;
return true;
Expand All @@ -465,30 +485,32 @@ private bool OnNcHitTest(ref Message m, bool contentControl)
}
else
{
if (resizableRight && gripBouns.BottomLeft.Contains(clientLocation))
if (_resizableRight && gripBouns.BottomLeft.Contains(clientLocation))
{
m.Result = contentControl ? transparent : (IntPtr)NativeMethods.HTBOTTOMLEFT;
return true;
}
if (!resizableRight && gripBouns.BottomRight.Contains(clientLocation))

if (!_resizableRight && gripBouns.BottomRight.Contains(clientLocation))
{
m.Result = contentControl ? transparent : (IntPtr)NativeMethods.HTBOTTOMRIGHT;
return true;
}

if (gripBouns.Bottom.Contains(clientLocation))
{
m.Result = contentControl ? transparent : (IntPtr)NativeMethods.HTBOTTOM;
return true;
}
}

if (resizableRight && gripBouns.Left.Contains(clientLocation))
if (_resizableRight && gripBouns.Left.Contains(clientLocation))
{
m.Result = contentControl ? transparent : (IntPtr)NativeMethods.HTLEFT;
return true;
}

if (!resizableRight && gripBouns.Right.Contains(clientLocation))
if (!_resizableRight && gripBouns.Right.Contains(clientLocation))
{
m.Result = contentControl ? transparent : (IntPtr)NativeMethods.HTRIGHT;
return true;
Expand All @@ -498,6 +520,7 @@ private bool OnNcHitTest(ref Message m, bool contentControl)
}

private VS.VisualStyleRenderer sizeGripRenderer;

/// <summary>
/// Paints the size grip.
/// </summary>
Expand All @@ -508,13 +531,15 @@ public void PaintSizeGrip(PaintEventArgs e)
{
return;
}

Size clientSize = content.ClientSize;
if (Application.RenderWithVisualStyles)
{
if (sizeGripRenderer == null)
{
sizeGripRenderer = new VS.VisualStyleRenderer(VS.VisualStyleElement.Status.Gripper.Normal);
}

sizeGripRenderer.DrawBackground(e.Graphics, new Rectangle(clientSize.Width - 0x10, clientSize.Height - 0x10, 0x10, 0x10));
}
else
Expand Down

0 comments on commit a97c63b

Please sign in to comment.