Skip to content

Commit

Permalink
Changes for dotnet#12042 to prep for pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
pcblues committed Dec 21, 2024
1 parent 8d96e56 commit f68fedc
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public partial class ListView : Control
private View _viewStyle = View.LargeIcon;
private string? _toolTipCaption = string.Empty;

private HBRUSH _hBrush; // To hold created dark mode brush for deletion

private const int LISTVIEWSTATE_ownerDraw = 0x00000001;
private const int LISTVIEWSTATE_allowColumnReorder = 0x00000002;
private const int LISTVIEWSTATE_autoArrange = 0x00000004;
Expand Down Expand Up @@ -4331,6 +4333,12 @@ internal void ListViewItemToolTipChanged(ListViewItem item)
protected virtual void OnAfterLabelEdit(LabelEditEventArgs e)
{
_onAfterLabelEdit?.Invoke(this, e);

// Delete created _hBrush if it exists
[DllImport("Gdi32.dll", PreserveSig = true)]
static extern void DeleteObject(HGDIOBJ ho);
DeleteObject(_hBrush);

}

protected override void OnBackgroundImageChanged(EventArgs e)
Expand Down Expand Up @@ -6908,6 +6916,32 @@ protected override void WndProc(ref Message m)
{
switch (m.MsgInternal)
{
case PInvokeCore.WM_CTLCOLOREDIT:
// Default handling of edit label colors
m.ResultInternal = (LRESULT)0;
#pragma warning disable WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
if (Application.IsDarkModeEnabled)
{
// Make background of dark mode edit labels the correct color
[DllImport("Gdi32.dll", PreserveSig = true)]
static extern HBRUSH CreateSolidBrush(COLORREF color);
[DllImport("Gdi32.dll", PreserveSig = true)]
static extern COLORREF SetBkColor(HDC hdc, COLORREF color);
[DllImport("Gdi32.dll", PreserveSig = true)]
static extern COLORREF SetTextColor(HDC hdc, COLORREF color);

Color tvColor = BackColor;
Color tvTextColor = ForeColor;
_hBrush = CreateSolidBrush(tvColor);
HDC editHDC = (HDC)m.WParamInternal;
SetBkColor(editHDC, tvColor);
SetTextColor(editHDC, tvTextColor);
LRESULT lrBrush = (LRESULT)(IntPtr)_hBrush;
m.ResultInternal = lrBrush;
}
#pragma warning restore WFO5001
break;

case MessageId.WM_REFLECT_NOTIFY:
WmReflectNotify(ref m);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public partial class TreeView : Control
private bool _hoveredAlready;
private bool _rightToLeftLayout;

private HBRUSH _hBrush; // To hold created dark mode brush for deletion

private nint _mouseDownNode = 0; // ensures we fire nodeClick on the correct node

private const int TREEVIEWSTATE_hideSelection = 0x00000001;
Expand Down Expand Up @@ -2102,6 +2104,11 @@ protected virtual void OnAfterLabelEdit(NodeLabelEditEventArgs e)
{
e.Node.AccessibilityObject?.RaiseAutomationEvent(UIA_EVENT_ID.UIA_AutomationFocusChangedEventId);
}

// Delete created _hBrush if it exists
[DllImport("Gdi32.dll", PreserveSig = true)]
static extern void DeleteObject(HGDIOBJ ho);
DeleteObject(_hBrush);
}

/// <summary>
Expand Down Expand Up @@ -3160,6 +3167,32 @@ protected override unsafe void WndProc(ref Message m)
{
switch (m.MsgInternal)
{
case PInvokeCore.WM_CTLCOLOREDIT:
// Default handling of edit label colors
m.ResultInternal = (LRESULT)0;
#pragma warning disable WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
if (Application.IsDarkModeEnabled)
{
// Make background of dark mode edit labels the correct color
[DllImport("Gdi32.dll", PreserveSig = true)]
static extern HBRUSH CreateSolidBrush(COLORREF color);
[DllImport("Gdi32.dll", PreserveSig = true)]
static extern COLORREF SetBkColor(HDC hdc, COLORREF color);
[DllImport("Gdi32.dll", PreserveSig = true)]
static extern COLORREF SetTextColor(HDC hdc, COLORREF color);

Color tvColor = BackColor;
Color tvTextColor = ForeColor;
_hBrush = CreateSolidBrush(tvColor);
HDC editHDC = (HDC)m.WParamInternal;
SetBkColor(editHDC, tvColor);
SetTextColor(editHDC, tvTextColor);
LRESULT lrBrush = (LRESULT)(IntPtr)_hBrush;
m.ResultInternal = lrBrush;
}
#pragma warning restore WFO5001
break;

case PInvokeCore.WM_WINDOWPOSCHANGING:
case PInvokeCore.WM_NCCALCSIZE:
case PInvokeCore.WM_WINDOWPOSCHANGED:
Expand Down

0 comments on commit f68fedc

Please sign in to comment.