Skip to content

Commit

Permalink
Merge branch 'main' into Mods-for-dotnet#12042
Browse files Browse the repository at this point in the history
  • Loading branch information
pcblues authored Dec 21, 2024
2 parents f68fedc + 084bbeb commit db63d99
Show file tree
Hide file tree
Showing 8 changed files with 447 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Winforms.sln
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Analyzers", "Analyzers", "{
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Private.Windows.GdiPlus", "src\System.Private.Windows.GdiPlus\System.Private.Windows.GdiPlus.csproj", "{442C867C-51C0-8CE5-F067-DF065008E3DA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScratchProject2", "src\System.Windows.Forms\tests\IntegrationTests\ScratchProject2\ScratchProject2.csproj", "{9A195C79-D335-485B-B5AB-9A1EF1F9E58A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1102,6 +1104,22 @@ Global
{442C867C-51C0-8CE5-F067-DF065008E3DA}.Release|x64.Build.0 = Release|Any CPU
{442C867C-51C0-8CE5-F067-DF065008E3DA}.Release|x86.ActiveCfg = Release|Any CPU
{442C867C-51C0-8CE5-F067-DF065008E3DA}.Release|x86.Build.0 = Release|Any CPU
{9A195C79-D335-485B-B5AB-9A1EF1F9E58A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9A195C79-D335-485B-B5AB-9A1EF1F9E58A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9A195C79-D335-485B-B5AB-9A1EF1F9E58A}.Debug|arm64.ActiveCfg = Debug|Any CPU
{9A195C79-D335-485B-B5AB-9A1EF1F9E58A}.Debug|arm64.Build.0 = Debug|Any CPU
{9A195C79-D335-485B-B5AB-9A1EF1F9E58A}.Debug|x64.ActiveCfg = Debug|Any CPU
{9A195C79-D335-485B-B5AB-9A1EF1F9E58A}.Debug|x64.Build.0 = Debug|Any CPU
{9A195C79-D335-485B-B5AB-9A1EF1F9E58A}.Debug|x86.ActiveCfg = Debug|Any CPU
{9A195C79-D335-485B-B5AB-9A1EF1F9E58A}.Debug|x86.Build.0 = Debug|Any CPU
{9A195C79-D335-485B-B5AB-9A1EF1F9E58A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9A195C79-D335-485B-B5AB-9A1EF1F9E58A}.Release|Any CPU.Build.0 = Release|Any CPU
{9A195C79-D335-485B-B5AB-9A1EF1F9E58A}.Release|arm64.ActiveCfg = Release|Any CPU
{9A195C79-D335-485B-B5AB-9A1EF1F9E58A}.Release|arm64.Build.0 = Release|Any CPU
{9A195C79-D335-485B-B5AB-9A1EF1F9E58A}.Release|x64.ActiveCfg = Release|Any CPU
{9A195C79-D335-485B-B5AB-9A1EF1F9E58A}.Release|x64.Build.0 = Release|Any CPU
{9A195C79-D335-485B-B5AB-9A1EF1F9E58A}.Release|x86.ActiveCfg = Release|Any CPU
{9A195C79-D335-485B-B5AB-9A1EF1F9E58A}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
using Windows.Win32.UI.Accessibility;
using static System.Windows.Forms.TreeNode;





namespace System.Windows.Forms;

/// <summary>
Expand All @@ -30,6 +34,9 @@ public partial class TreeView : Control
private const string BackSlash = "\\";
private const int DefaultTreeViewIndent = 19;

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

private DrawTreeNodeEventHandler? _onDrawNode;
private NodeLabelEditEventHandler? _onBeforeLabelEdit;
private NodeLabelEditEventHandler? _onAfterLabelEdit;
Expand Down Expand Up @@ -2558,6 +2565,38 @@ private unsafe void TvnSelected(NMTREEVIEWW* nmtv)
}
}

private enum DWMWINDOWATTRIBUTE
{
DWMWA_NCRENDERING_ENABLED = 1,
DWMWA_NCRENDERING_POLICY,
DWMWA_TRANSITIONS_FORCEDISABLED,
DWMWA_ALLOW_NCPAINT,
DWMWA_CAPTION_BUTTON_BOUNDS,
DWMWA_NONCLIENT_RTL_LAYOUT,
DWMWA_FORCE_ICONIC_REPRESENTATION,
DWMWA_FLIP3D_POLICY,
DWMWA_EXTENDED_FRAME_BOUNDS,
DWMWA_HAS_ICONIC_BITMAP,
DWMWA_DISALLOW_PEEK,
DWMWA_EXCLUDED_FROM_PEEK,
DWMWA_CLOAK,
DWMWA_CLOAKED,
DWMWA_FREEZE_REPRESENTATION,
DWMWA_PASSIVE_UPDATE_MODE,
DWMWA_USE_HOSTBACKDROPBRUSH,
DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 = 19,
DWMWA_USE_IMMERSIVE_DARK_MODE = 20,
DWMWA_WINDOW_CORNER_PREFERENCE = 33,
DWMWA_BORDER_COLOR,
DWMWA_CAPTION_COLOR,
DWMWA_TEXT_COLOR,
DWMWA_VISIBLE_FRAME_BORDER_THICKNESS,
DWMWA_SYSTEMBACKDROP_TYPE,
DWMWA_LAST
}



private LRESULT TvnBeginLabelEdit(NMTVDISPINFOW nmtvdi)
{
// Check for invalid node handle
Expand Down Expand Up @@ -2586,8 +2625,81 @@ private LRESULT TvnBeginLabelEdit(NMTVDISPINFOW nmtvdi)
if (!e.CancelEdit)
{
_labelEdit = new TreeViewLabelEditNativeWindow(this);

_labelEdit.AssignHandle(PInvokeCore.SendMessage(this, PInvoke.TVM_GETEDITCONTROL));
}



/*
// Force dark mode on editing label if necessary
[DllImport("dwmapi.dll", PreserveSig = false)]
static extern void DwmSetWindowAttribute(IntPtr hwnd, int attr,
ref int attrValue, int attrSize);
#pragma warning disable WFO5001
SystemColorMode thisColorMode;
if (Application.ColorMode == SystemColorMode.System)
{
thisColorMode = Application.SystemColorMode;
}
else
{
thisColorMode = Application.ColorMode;
}
if (thisColorMode == SystemColorMode.Dark)
{
// Try different dwm attributes and values
// May be a problem with WIN 10 compatibility
//int trueVal = 1;
//var attr = (int)DWMWINDOWATTRIBUTE.DWMWA_CAPTION_COLOR;
//var attrVal = 0x00ff0000;
IntPtr handle = _labelEdit.Handle;
Debug.WriteLine(handle.ToString());
for (int attrVal = 0; attrVal <= 10; attrVal++)
{
Debug.WriteLine("");
for (int attr = 1; attr <= 50; attr++)
{
Debug.WriteLine("");
try
{
DwmSetWindowAttribute(handle, attr, ref attrVal, Marshal.SizeOf(attrVal));
}
catch (Exception dwmEx)
{
string msg = dwmEx.Message;
if (dwmEx.InnerException is not null)
{
msg = msg + Environment.NewLine + dwmEx.InnerException.Message;
}
Debug.WriteLine("Attribute:" + attr.ToString());
Debug.WriteLine("Attr Valu:" + attrVal.ToString());
Debug.WriteLine(msg);
}
}
}
}
// do I need to invalidate to get an update?
#pragma warning restore WFO5001
*/


return (LRESULT)(e.CancelEdit ? 1 : 0);
}
Expand Down Expand Up @@ -2789,6 +2901,7 @@ private unsafe void CustomDraw(ref Message m)
// when one item is selected, click and hold on another). This needs to be fixed.
Color riFore = renderinfo.ForeColor;
Color riBack = renderinfo.BackColor;

if (renderinfo is not null && !riFore.IsEmpty)
{
nmtvcd->clrText = ColorTranslator.ToWin32(riFore);
Expand Down Expand Up @@ -3170,6 +3283,7 @@ protected override unsafe void WndProc(ref Message m)
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)
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

using System.Diagnostics;

namespace ScratchProject2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Load += Form1_Load;
}

private void Form1_Load(object? sender, EventArgs e)
{
treeView1.BeforeLabelEdit += treeView1_BeforeLabelEdit;
listView1.BeforeLabelEdit += listView1_BeforeLabelEdit;
}

private void listView1_BeforeLabelEdit(object? sender, LabelEditEventArgs e)
{
Debug.WriteLine("ListView Here!");
}


private void treeView1_BeforeLabelEdit(object? sender, NodeLabelEditEventArgs e)
{
Debug.WriteLine("TreeView Here!");
}

}
}
Loading

0 comments on commit db63d99

Please sign in to comment.