From bd0c750cc8635b7086fa03b90d5f5ef87a2060ec Mon Sep 17 00:00:00 2001 From: Klaus Loeffelmann Date: Mon, 29 Jul 2024 16:37:41 -0700 Subject: [PATCH] Revert cc99a677. --- .../Analyzers/Diagnostics/DiagnosticIDs.cs | 2 +- .../ComponentCodeDomSerializer.cs | 2 +- .../Windows/Forms/Design/Behavior/Adorner.cs | 2 +- .../Windows/Forms/Design/Behavior/Behavior.cs | 2 +- .../Windows/Forms/Design/ControlDesigner.cs | 4 +- .../Forms/Design/TableLayoutPanelDesigner.cs | 2 +- .../Windows/Forms/Design/ToolStripDesigner.cs | 2 +- .../Forms/Design/ToolStripDropDownDesigner.cs | 2 +- .../ToolStripItemCustomMenuItemCollection.cs | 4 +- .../Forms/Design/ToolStripItemDesigner.cs | 2 +- .../Forms/Design/ToolStripPanelDesigner.cs | 2 +- .../Design/DesignerActionServiceTests.cs | 2 +- .../Forms/Design/InheritanceUITests.cs | 6 +- .../System.Windows.Forms.Primitives.csproj | 1 + .../src/PublicAPI.Unshipped.txt | 15 +-- .../Forms/ActiveX/Control.ActiveXImpl.cs | 2 +- .../src/System/Windows/Forms/Application.cs | 92 ++++++++----------- .../src/System/Windows/Forms/ColorMode.cs | 26 ------ .../Forms/Control.ControlSystemColors.cs | 2 +- .../src/System/Windows/Forms/Control.cs | 4 +- .../Forms/Controls/Labels/LinkLabel.cs | 4 +- .../Forms/Controls/ProgressBar/ProgressBar.cs | 2 +- .../TabControl.TabControlAccessibleObject.cs | 2 +- .../TabControl/TabPage.TabAccessibleObject.cs | 2 +- .../Windows/Forms/Controls/TextBox/TextBox.cs | 2 +- .../Forms/Controls/ToolStrips/StatusStrip.cs | 3 +- ...pButton.ToolStripButtonAccessibleObject.cs | 2 +- ...StripItem.ToolStripItemAccessibleObject.cs | 2 +- .../Controls/ToolStrips/ToolStripItem.cs | 4 +- .../ToolStrips/ToolStripSystemRenderer.cs | 2 +- .../ToolstripProfessionalRenderer.cs | 4 +- .../ICommandBindingTargetProvider.cs | 2 +- .../src/System/Windows/Forms/Form.cs | 4 +- .../Containers/ValidationConstraints.cs | 2 +- .../Animation/AnimatedControlRenderer.cs | 3 +- .../Windows/Forms/Rendering/TextRenderer.cs | 2 +- .../System/Windows/Forms/SystemColorMode.cs | 24 +++++ .../System/Windows/Forms/VisualStylesMode.cs | 13 ++- 38 files changed, 121 insertions(+), 134 deletions(-) delete mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/ColorMode.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/SystemColorMode.cs diff --git a/src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/Analyzers/Diagnostics/DiagnosticIDs.cs b/src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/Analyzers/Diagnostics/DiagnosticIDs.cs index 10381e1b716..b94aa74ad4a 100644 --- a/src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/Analyzers/Diagnostics/DiagnosticIDs.cs +++ b/src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/Analyzers/Diagnostics/DiagnosticIDs.cs @@ -13,7 +13,7 @@ internal static class DiagnosticIDs // Security, number group 1000+ public const string MissingPropertySerializationConfiguration = "WFO1000"; - // WinForms best practize, number group 2000+ + // WinForms best practice, number group 2000+ public const string DisposeModalDialog = "WFO2000"; // Experimental, number group 9000+ diff --git a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/ComponentCodeDomSerializer.cs b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/ComponentCodeDomSerializer.cs index a4cb586a81d..c3129b7ff07 100644 --- a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/ComponentCodeDomSerializer.cs +++ b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/ComponentCodeDomSerializer.cs @@ -135,7 +135,7 @@ protected override object DeserializeInstance(IDesignerSerializationManager mana // // 2. Should we generate an init expression for this // object? - // a) System or existing expression: no + // a) Inherited or existing expression: no // b) otherwise, yes. statements = []; diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/Adorner.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/Adorner.cs index a0d935782e2..bbb8877f80a 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/Adorner.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/Adorner.cs @@ -7,7 +7,7 @@ namespace System.Windows.Forms.Design.Behavior; /// /// An Adorner manages a collection of UI-related Glyphs. Each Adorner -/// can be enabled/disabled. Only Dark Adorners will receive hit test +/// can be enabled/disabled. Only Enabled Adorners will receive hit test /// and paint messages from the BehaviorService. An Adorner can be viewed /// as a proxy between UI-related elements (all Glyphs) and the BehaviorService. /// diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/Behavior.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/Behavior.cs index c96e3435b33..a7a2cdc2041 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/Behavior.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/Behavior.cs @@ -44,7 +44,7 @@ protected Behavior(bool callParentBehavior, BehaviorService? behaviorService) /// /// Returning true from here indicates to the BehaviorService that all MenuCommands the designer receives - /// should have their state set to 'Dark = false' when this Behavior is active. + /// should have their state set to 'Enabled = false' when this Behavior is active. /// public virtual bool DisableAllCommands { diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ControlDesigner.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ControlDesigner.cs index e9ec97b4811..736664de377 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ControlDesigner.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ControlDesigner.cs @@ -919,7 +919,7 @@ public override void Initialize(IComponent component) || !visibleProp.ShouldSerializeValue(component) || (bool)visibleProp.GetValue(component)!; - PropertyDescriptor? enabledProp = props["Dark"]; + PropertyDescriptor? enabledProp = props["Enabled"]; Enabled = enabledProp is null || enabledProp.PropertyType != typeof(bool) || !enabledProp.ShouldSerializeValue(component) @@ -1624,7 +1624,7 @@ protected override void PreFilterProperties(IDictionary properties) base.PreFilterProperties(properties); // Handle shadowed properties - string[] shadowProps = ["Visible", "Dark", "AllowDrop", "Location", "Name"]; + string[] shadowProps = ["Visible", "Enabled", "AllowDrop", "Location", "Name"]; for (int i = 0; i < shadowProps.Length; i++) { diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/TableLayoutPanelDesigner.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/TableLayoutPanelDesigner.cs index 427adc5494d..eff1340fe0f 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/TableLayoutPanelDesigner.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/TableLayoutPanelDesigner.cs @@ -1587,7 +1587,7 @@ private void OnRowColMenuOpening(object sender, CancelEventArgs e) selCount = selSvc.SelectionCount; } - // Always make sure and set the Dark state in case the user + // Always make sure and set the Enabled state in case the user // has changed the selection since the last time the menu was shown. bool enabled = (selCount == 1) && (InheritanceAttribute != InheritanceAttribute.InheritedReadOnly); diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripDesigner.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripDesigner.cs index 332d95df4a8..5bec255140d 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripDesigner.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripDesigner.cs @@ -1207,7 +1207,7 @@ protected override void Dispose(bool disposing) /// public override void DoDefaultAction() { - // Don't Fire the Events if the Component is System. + // Don't Fire the Events if the Component is Inherited. if (InheritanceAttribute != InheritanceAttribute.InheritedReadOnly) { IComponent selectedItem = SelectionService.PrimarySelection as IComponent; diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripDropDownDesigner.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripDropDownDesigner.cs index 321b8d4c7e0..a37ee557e6b 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripDropDownDesigner.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripDropDownDesigner.cs @@ -106,7 +106,7 @@ internal bool EditingCollection } } - // ContextMenuStrip if System ACT as Readonly. + // ContextMenuStrip if Inherited ACT as Readonly. protected override InheritanceAttribute InheritanceAttribute { get diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripItemCustomMenuItemCollection.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripItemCustomMenuItemCollection.cs index 12f520ca0c3..0ef6fcffc55 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripItemCustomMenuItemCollection.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripItemCustomMenuItemCollection.cs @@ -124,7 +124,7 @@ private void PopulateList() }; // Add event Handlers _imageToolStripMenuItem.Click += new EventHandler(OnImageToolStripMenuItemClick); - _enabledToolStripMenuItem = CreateBooleanItem("E&nabled", "Dark"); + _enabledToolStripMenuItem = CreateBooleanItem("E&nabled", "Enabled"); AddRange([_imageToolStripMenuItem, _enabledToolStripMenuItem]); if (selectedItem is ToolStripMenuItem) { @@ -632,7 +632,7 @@ public override void RefreshItems() ToolStripItem selectedItem = _currentItem; if (selectedItem is not ToolStripControlHost and not ToolStripSeparator) { - _enabledToolStripMenuItem.Checked = (bool)GetProperty("Dark"); + _enabledToolStripMenuItem.Checked = (bool)GetProperty("Enabled"); if (selectedItem is ToolStripMenuItem) { _checkedToolStripMenuItem.Checked = (bool)GetProperty("Checked"); diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripItemDesigner.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripItemDesigner.cs index 61dfef1f83f..43fcccf97ee 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripItemDesigner.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripItemDesigner.cs @@ -114,7 +114,7 @@ internal virtual ToolStripTemplateNode Editor set => _editorNode = value; } - // ToolStripItems if System ACT as Readonly. + // ToolStripItems if Inherited ACT as Readonly. protected override InheritanceAttribute InheritanceAttribute { get diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripPanelDesigner.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripPanelDesigner.cs index c3df847af4a..bbe9b2064a0 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripPanelDesigner.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripPanelDesigner.cs @@ -87,7 +87,7 @@ private ContextMenuStrip? DesignerContextMenu public override ToolStripPanel Control => (ToolStripPanel)Component; - // ToolStripPanels if System ACT as Readonly. + // ToolStripPanels if Inherited ACT as Readonly. protected override InheritanceAttribute? InheritanceAttribute { get => Control.Parent is ToolStripContainer && (base.InheritanceAttribute == InheritanceAttribute.Inherited) diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignerActionServiceTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignerActionServiceTests.cs index 130d68516e9..0e89f9bc356 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignerActionServiceTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignerActionServiceTests.cs @@ -543,7 +543,7 @@ public void GetComponentDesignerActionsVerbs_GetSortedActionItems_ReturnsExpecte DesignerActionList actionList = Assert.IsAssignableFrom(Assert.Single(actionListBuffer)); Assert.Single(actionList.GetSortedActionItems()); - // Not Classic. + // Not Disabled. verb.Enabled = false; Assert.Empty(actionList.GetSortedActionItems()); verb.Enabled = true; diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/InheritanceUITests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/InheritanceUITests.cs index 38bbb30db2b..83af8848171 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/InheritanceUITests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/InheritanceUITests.cs @@ -8,9 +8,9 @@ namespace System.Windows.Forms.Design.Tests; public sealed class InheritanceUITests { [Theory] - [InlineData(InheritanceLevel.Inherited, "System control")] - [InlineData(InheritanceLevel.InheritedReadOnly, "System control (Private)")] - [InlineData(InheritanceLevel.NotInherited, "System control")] + [InlineData(InheritanceLevel.Inherited, "Inherited control")] + [InlineData(InheritanceLevel.InheritedReadOnly, "Inherited control (Private)")] + [InlineData(InheritanceLevel.NotInherited, "Inherited control")] public void AddInheritedControl_ShouldSetToolTipText(InheritanceLevel inheritanceLevel, string expectedText) { InheritanceUI inheritanceUI = new(); diff --git a/src/System.Windows.Forms.Primitives/src/System.Windows.Forms.Primitives.csproj b/src/System.Windows.Forms.Primitives/src/System.Windows.Forms.Primitives.csproj index 3f8e590182a..647bf2ebc2e 100644 --- a/src/System.Windows.Forms.Primitives/src/System.Windows.Forms.Primitives.csproj +++ b/src/System.Windows.Forms.Primitives/src/System.Windows.Forms.Primitives.csproj @@ -56,6 +56,7 @@ + diff --git a/src/System.Windows.Forms/src/PublicAPI.Unshipped.txt b/src/System.Windows.Forms/src/PublicAPI.Unshipped.txt index b88cbc11233..f69fcbca1ec 100644 --- a/src/System.Windows.Forms/src/PublicAPI.Unshipped.txt +++ b/src/System.Windows.Forms/src/PublicAPI.Unshipped.txt @@ -1,13 +1,13 @@ override System.Windows.Forms.CheckBox.OnPaint(System.Windows.Forms.PaintEventArgs! pevent) -> void -static System.Windows.Forms.Application.DefaultDarkMode.get -> System.Windows.Forms.ColorMode -static System.Windows.Forms.Application.SetDefaultColorMode(System.Windows.Forms.ColorMode darkMode, bool throwIfImpossible = false) -> void -static System.Windows.Forms.Application.SystemColorMode.get -> System.Windows.Forms.ColorMode +static System.Windows.Forms.Application.ColorMode.get -> System.Windows.Forms.SystemColorMode +static System.Windows.Forms.Application.SetColorMode(System.Windows.Forms.SystemColorMode systemColorMode) -> void +static System.Windows.Forms.Application.SystemColorMode.get -> System.Windows.Forms.SystemColorMode static System.Windows.Forms.Control.ControlSystemColors.Current.get -> System.Windows.Forms.Control.ControlSystemColors! static System.Windows.Forms.Control.ControlSystemColors.GetAdaptedDarkModeColorFromKnownColor(System.Drawing.KnownColor knownColor, bool darkMode) -> System.Drawing.Color -System.Windows.Forms.ColorMode -System.Windows.Forms.ColorMode.Classic = 0 -> System.Windows.Forms.ColorMode -System.Windows.Forms.ColorMode.Dark = 1 -> System.Windows.Forms.ColorMode -System.Windows.Forms.ColorMode.System = 2 -> System.Windows.Forms.ColorMode +System.Windows.Forms.SystemColorMode +System.Windows.Forms.SystemColorMode.Classic = 0 -> System.Windows.Forms.SystemColorMode +System.Windows.Forms.SystemColorMode.Dark = 2 -> System.Windows.Forms.SystemColorMode +System.Windows.Forms.SystemColorMode.System = 1 -> System.Windows.Forms.SystemColorMode System.Windows.Forms.Control.ControlSystemColors System.Windows.Forms.Control.SystemColors.get -> System.Windows.Forms.Control.ControlSystemColors! System.Windows.Forms.Control.VisualStylesModeChanged -> System.EventHandler? @@ -33,6 +33,7 @@ System.Windows.Forms.Form.WindowCornerPreference.RoundSmall = 3 -> System.Window System.Windows.Forms.VisualStylesMode System.Windows.Forms.VisualStylesMode.Classic = 0 -> System.Windows.Forms.VisualStylesMode System.Windows.Forms.VisualStylesMode.Disabled = 1 -> System.Windows.Forms.VisualStylesMode +System.Windows.Forms.VisualStylesMode.Latest = 32767 -> System.Windows.Forms.VisualStylesMode System.Windows.Forms.VisualStylesMode.Net10 = 2 -> System.Windows.Forms.VisualStylesMode virtual System.Windows.Forms.Control.DefaultVisualStylesMode.get -> System.Windows.Forms.VisualStylesMode virtual System.Windows.Forms.Control.OnDebuggerBreak(string! ticket) -> bool diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ActiveX/Control.ActiveXImpl.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ActiveX/Control.ActiveXImpl.cs index b05f92f9df5..bbb34638ee9 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ActiveX/Control.ActiveXImpl.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ActiveX/Control.ActiveXImpl.cs @@ -1237,7 +1237,7 @@ private static void CallParentPropertyChanged(Control control, string propName) case "BindingContext": control.OnParentBindingContextChanged(EventArgs.Empty); break; - case "Dark": + case "Enabled": control.OnParentEnabledChanged(EventArgs.Empty); break; case "Font": diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Application.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Application.cs index ba5871a5007..5516d038c66 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Application.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Application.cs @@ -6,6 +6,7 @@ using System.Globalization; using System.Reflection; using System.Text; +using System.Windows.Forms.Analyzers.Diagnostics; using System.Windows.Forms.VisualStyles; using Microsoft.Office; using Microsoft.Win32; @@ -41,7 +42,7 @@ public sealed partial class Application private static bool s_useWaitCursor; #pragma warning disable WFO9001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. - private static ColorMode? s_darkMode; + private static SystemColorMode? s_systemColorMode; #pragma warning restore WFO9001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. private const string DarkModeKeyPath = "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"; @@ -243,43 +244,35 @@ internal static bool CustomThreadExceptionHandlerAttached => ThreadContext.FromCurrent().CustomThreadExceptionHandlerAttached; /// - /// Gets the default dark mode for the application. This is the ColorMode which either has been set - /// by or its default value . + /// Gets the default dark mode for the application. This is the SystemColorMode which either has been set + /// by or its default value . /// [Experimental("WFO9001")] - public static ColorMode DefaultDarkMode - { - get - { - if (!s_darkMode.HasValue) - { - return ColorMode.Classic; - } - - return s_darkMode.Value; - } - } + public static SystemColorMode ColorMode => + !s_systemColorMode.HasValue + // No value set: we default to classic (light mode) + ? SystemColorMode.Classic + // If System is set + : s_systemColorMode.Value == SystemColorMode.System + // We return the system color mode + ? SystemColorMode + // Otherwise we return the value set by the user + : s_systemColorMode.Value; /// /// Sets the default dark mode for the application. /// - /// The default dark mode to set. - /// Flag, if set to , leads to an exception if the color mode is not supported. + /// The default dark mode to set. [Experimental("WFO9001")] - public static void SetDefaultColorMode(ColorMode darkMode, bool throwIfImpossible = false) + public static void SetColorMode(SystemColorMode systemColorMode) { - if (GetSystemColorModeCore() > -1) + if (GetSystemColorModeInternal() > -1) { - s_darkMode = darkMode; + s_systemColorMode = systemColorMode; return; } - if (throwIfImpossible) - { - throw new ArgumentException(SR.DarkModeNotSupported); - } - - s_darkMode = ColorMode.Classic; + s_systemColorMode = SystemColorMode.Classic; } /// @@ -327,30 +320,28 @@ public static void SetDefaultVisualStylesMode(VisualStylesMode styleSetting) internal static Font DefaultFont => s_defaultFontScaled ?? s_defaultFont!; /// - /// Gets the color mode setting of the OS system environment. + /// Gets the system color mode setting of the OS system environment. /// /// /// - /// The color setting is determined based on the operating system version and its system settings. It returns - /// if the dark mode is enabled in the system settings, - /// if the color mode equals the light, standard color setting. + /// The color setting is determined based on the operating system version and its system settings. + /// It returns if the dark mode is enabled in the system settings, + /// if the color mode equals the light, standard color setting. /// /// - /// Color modes is supported on Windows 11 or later versions. + /// SystemColorMode is supported on Windows 11 or later versions. /// /// - /// Color modes is not supported, if the Windows OS High Contrast Mode has been enabled in the system settings. + /// SystemColorModes is not supported, if the Windows OS High Contrast Mode has been enabled in the system settings. /// /// - [Experimental("WFO9001")] - public static ColorMode SystemColorMode => - GetSystemColorModeCore() switch - { - 0 => ColorMode.Dark, - _ => ColorMode.Classic, - }; + [Experimental(DiagnosticIDs.ExperimentalDarkMode)] + public static SystemColorMode SystemColorMode => + GetSystemColorModeInternal() == 0 + ? SystemColorMode.Dark + : SystemColorMode.Classic; - private static int GetSystemColorModeCore() + private static int GetSystemColorModeInternal() { if (SystemInformation.HighContrast) { @@ -379,24 +370,13 @@ private static int GetSystemColorModeCore() } /// - /// Gets a value indicating whether the application is running in a dark mode context. + /// Gets a value indicating whether the application is running in a dark system color context. /// Note: In a high contrast mode, this will always return . /// - [Experimental("WFO9001")] - public static bool IsDarkModeEnabled => !SystemInformation.HighContrast - && DefaultDarkMode switch - { - ColorMode.Dark => true, - ColorMode.Classic => false, - _ => SystemColorMode switch - { - ColorMode.Dark => true, - ColorMode.Classic => false, - - // We return false even if ColorMode is not supported so that we ALWAYS have a valid result here. - _ => false - } - }; + [Experimental(DiagnosticIDs.ExperimentalDarkMode)] + public static bool IsDarkModeEnabled => + !SystemInformation.HighContrast + && (ColorMode == SystemColorMode.Dark); /// /// Gets the path for the executable file that started the application. diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ColorMode.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ColorMode.cs deleted file mode 100644 index 0642d338fc2..00000000000 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ColorMode.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace System.Windows.Forms -{ - [Experimental("WFO9001")] - public enum ColorMode - { - /// - /// Dark mode for the current context is or should be disabled. - /// - Classic = 0, - - /// - /// Dark mode for the current context is or should be enabled. - /// - Dark = 1, - - /// - /// The setting for the current color mode context is inherited from the parent context. Note, that you - /// can even pass this value to , in which case - /// the actual dark mode setting will be inherited from the Windows OS system setting. - /// - System = 2 - } -} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Control.ControlSystemColors.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Control.ControlSystemColors.cs index 52fee5e8573..5e4185bdb02 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Control.ControlSystemColors.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Control.ControlSystemColors.cs @@ -83,7 +83,7 @@ public class ControlSystemColors unchecked(Color.FromArgb((int)0xFF101010)), // FFFFFFFF - FF101010: ButtonHighlight - White unchecked(Color.FromArgb((int)0xFF464646)), // FFA0A0A0 - FF464646: ButtonShadow - Same as Scrollbar Elements unchecked(Color.FromArgb((int)0XFF416482)), // FFB9D1EA - FF416482: GradientActiveCaption - Same as Highlighted Text Background - unchecked(Color.FromArgb((int)0xFF557396)), // FFD7E4F2 - FF557396: GradientInactiveCaption - Same as Highlighted Panel in ColorMode + unchecked(Color.FromArgb((int)0xFF557396)), // FFD7E4F2 - FF557396: GradientInactiveCaption - Same as Highlighted Panel in SystemColorMode unchecked(Color.FromArgb((int)0xFF373737)), // FFF0F0F0 - FF373737: MenuBar - Same as Normal Menu Background unchecked(Color.FromArgb((int)0xFF2A80D2)) // FF3399FF - FF2A80D2: MenuHighlight - Same as Highlighted Menu Background ]; diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs index 97a3fd28d04..64d4c02f4ae 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs @@ -161,7 +161,7 @@ public unsafe partial class Control : private static FontHandleWrapper? s_defaultFontHandleWrapper; - internal const string DarkModeIdentifier = "ColorMode"; + internal const string DarkModeIdentifier = "DarkMode"; internal const string ExplorerThemeIdentifier = "Explorer"; internal const string ItemsViewThemeIdentifier = "ItemsView"; @@ -3680,7 +3680,7 @@ public event EventHandler? VisualStylesModeChanged /// /// /// As an ambient property, if the control is a top-level control and its VisualStylesMode is not explicitly set, - /// it will inherit the setting from . System controls can + /// it will inherit the setting from . Inherited controls can /// overwrite to ensure backwards compatibility for controls, which /// rely on a specific version of the visual styles of a base control (see as an example). /// diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Labels/LinkLabel.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Labels/LinkLabel.cs index b10f1ff4dcc..acecccfba5b 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Labels/LinkLabel.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Labels/LinkLabel.cs @@ -1007,7 +1007,7 @@ protected override void OnPaint(PaintEventArgs e) void PaintEnabled() { - // Control.Dark not to be confused with Link.Dark + // Control.Enabled not to be confused with Link.Enabled bool optimizeBackgroundRendering = !GetStyle(ControlStyles.OptimizedDoubleBuffer); using var foreBrush = ForeColor.GetCachedSolidBrushScope(); using var linkBrush = LinkColor.GetCachedSolidBrushScope(); @@ -1262,7 +1262,7 @@ void PaintLink() if (link.Enabled) { - // Not to be confused with Control.Dark. + // Not to be confused with Control.Enabled. if ((linkState & LinkState.Active) == LinkState.Active) { brushColor = ActiveLinkColor; diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ProgressBar/ProgressBar.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ProgressBar/ProgressBar.cs index de14fa7903b..02cba39fa91 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ProgressBar/ProgressBar.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ProgressBar/ProgressBar.cs @@ -79,7 +79,7 @@ protected override void OnCreateControl() { base.OnCreateControl(); - // If ColorMode is enabled, we need to disable the Visual Styles + // If SystemColorMode is enabled, we need to disable the Visual Styles // so Windows allows setting Fore- and Background color. // There are more ideal ways imaginable, but this does the trick for now. #pragma warning disable WFO9001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TabControl/TabControl.TabControlAccessibleObject.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TabControl/TabControl.TabControlAccessibleObject.cs index 630be67489a..8176f07446c 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TabControl/TabControl.TabControlAccessibleObject.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TabControl/TabControl.TabControlAccessibleObject.cs @@ -144,7 +144,7 @@ internal override VARIANT GetPropertyValue(UIA_PROPERTY_ID propertyID) internal override bool IsPatternSupported(UIA_PATTERN_ID patternId) => patternId switch { - // The "Dark" property of the TabControl does not affect the behavior of that property, + // The "Enabled" property of the TabControl does not affect the behavior of that property, // so it is always true UIA_PATTERN_ID.UIA_SelectionPatternId => true, _ => base.IsPatternSupported(patternId) diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TabControl/TabPage.TabAccessibleObject.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TabControl/TabPage.TabAccessibleObject.cs index 5220d0ef1e9..14d5d6d135e 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TabControl/TabPage.TabAccessibleObject.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TabControl/TabPage.TabAccessibleObject.cs @@ -131,7 +131,7 @@ internal override VARIANT GetPropertyValue(UIA_PROPERTY_ID propertyID) internal override bool IsPatternSupported(UIA_PATTERN_ID patternId) => patternId switch { - // The "Dark" property of the TabControl does not affect the behavior of that property, + // The "Enabled" property of the TabControl does not affect the behavior of that property, // so it is always true UIA_PATTERN_ID.UIA_SelectionItemPatternId => true, UIA_PATTERN_ID.UIA_InvokePatternId => false, diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TextBox/TextBox.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TextBox/TextBox.cs index cd7e1044b03..be3786d95be 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TextBox/TextBox.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TextBox/TextBox.cs @@ -726,7 +726,7 @@ private protected override void SelectInternal(int start, int length, int textLe /// private unsafe void SetAutoComplete(bool reset) { - // Autocomplete Not Dark for Password enabled and MultiLine Textboxes. + // Autocomplete Not Enabled for Password enabled and MultiLine Textboxes. if (Multiline || _passwordChar != 0 || _useSystemPasswordChar || AutoCompleteSource == AutoCompleteSource.None) { return; diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/StatusStrip.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/StatusStrip.cs index aa1d02f3f77..3d7c133c41b 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/StatusStrip.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/StatusStrip.cs @@ -30,9 +30,8 @@ public StatusStrip() CanOverflow = false; LayoutStyle = ToolStripLayoutStyle.Table; - // Default changed for ColorMode from System to ManagerRenderMode. + // Default changed for SystemColorMode from System to ManagerRenderMode. // Also to be consistent to the MenuStrip. - // TODO: We'd need to quirk that! RenderMode = ToolStripRenderMode.ManagerRenderMode; GripStyle = ToolStripGripStyle.Hidden; diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripButton.ToolStripButtonAccessibleObject.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripButton.ToolStripButtonAccessibleObject.cs index b4ff03154c3..5469e7e8878 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripButton.ToolStripButtonAccessibleObject.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripButton.ToolStripButtonAccessibleObject.cs @@ -55,7 +55,7 @@ public override AccessibleStates State return base.State | AccessibleStates.Checked; } - // Classic ToolStripButton, that is selected, must have focus state so that + // Disabled ToolStripButton, that is selected, must have focus state so that // Narrator can announce it if (!_ownerItem.Enabled && _ownerItem.Selected) { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripItem.ToolStripItemAccessibleObject.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripItem.ToolStripItemAccessibleObject.cs index c4f329540f9..d880ba1d6e2 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripItem.ToolStripItemAccessibleObject.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripItem.ToolStripItemAccessibleObject.cs @@ -173,7 +173,7 @@ public override AccessibleStates State return AccessibleStates.Unavailable | _additionalState | AccessibleStates.Focused; } - // Classic menu items that are selected must have focus + // Disabled menu items that are selected must have focus // state so that Narrator can announce them. if (_ownerItem.Selected && _ownerItem is ToolStripMenuItem) { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripItem.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripItem.cs index d4965efa0be..a7b91ba59a1 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripItem.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripItem.cs @@ -2320,7 +2320,7 @@ internal void FireEvent(EventArgs e, ToolStripItemEventType met) break; case ToolStripItemEventType.MouseMove: - // Classic items typically don't get mouse move + // Disabled items typically don't get mouse move // but they should be allowed to re-order if the ALT key is pressed if (!Enabled && ParentInternal is not null) { @@ -2959,7 +2959,7 @@ protected virtual void OnParentChanged(ToolStrip? oldParent, ToolStrip? newParen } /// - /// Occurs when this.Parent.Dark changes. + /// Occurs when this.Parent.Enabled changes. /// protected internal virtual void OnParentEnabledChanged(EventArgs e) => OnEnabledChanged(EventArgs.Empty); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripSystemRenderer.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripSystemRenderer.cs index 53f5d843cb2..60b1e3926cf 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripSystemRenderer.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripSystemRenderer.cs @@ -461,7 +461,7 @@ protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs ? SystemColors.Highlight : ProfessionalColors.MenuItemBorder; - // Draw selection border - always drawn regardless of Dark. + // Draw selection border - always drawn regardless of Enabled. using var pen = borderColor.GetCachedPenScope(); g.DrawRectangle(pen, bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolstripProfessionalRenderer.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolstripProfessionalRenderer.cs index f0ff8606972..7535e6f9d86 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolstripProfessionalRenderer.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolstripProfessionalRenderer.cs @@ -579,7 +579,7 @@ protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs } } - // Draw selection border - always drawn regardless of Dark. + // Draw selection border - always drawn regardless of Enabled. using var pen = borderColor.GetCachedPenScope(); g.DrawRectangle(pen, bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1); } @@ -636,7 +636,7 @@ protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs } } - // Draw selection border - always drawn regardless of Dark. + // Draw selection border - always drawn regardless of Enabled. using var pen = borderColor.GetCachedPenScope(); g.DrawRectangle(pen, bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataBinding/ICommandBindingTargetProvider.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataBinding/ICommandBindingTargetProvider.cs index e717de110d1..14ff7630373 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/DataBinding/ICommandBindingTargetProvider.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataBinding/ICommandBindingTargetProvider.cs @@ -95,7 +95,7 @@ private void CommandSetter( { commandBackingField.CanExecuteChanged -= CommandCanExecuteChangedProc; - // We need to restore Dark, should we go from a defined Command to an undefined Command. + // We need to restore Enabled, should we go from a defined Command to an undefined Command. if (newCommand is null) { if (PreviousEnabledStatus.HasValue) diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Form.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Form.cs index 5bebfc45fb4..4507a4d9361 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Form.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Form.cs @@ -307,7 +307,7 @@ public Form? ActiveMdiChild Form? mdiChild = ActiveMdiChildInternal; // We keep the active mdi child in the cached in the property store; when changing its value - // (due to a change to one of the following properties/methods: Visible, Dark, Active, Show/Hide, + // (due to a change to one of the following properties/methods: Visible, Enabled, Active, Show/Hide, // Focus() or as the result of WM_SETFOCUS/WM_ACTIVATE/WM_MDIACTIVATE) we temporarily set it to null // (to properly handle menu merging among other things) rendering the cache out-of-date; the problem // arises when the user has an event handler that is raised during this process; in that case we ask @@ -4029,7 +4029,7 @@ protected internal override void OnEnter(EventArgs e) { base.OnEnter(e); - // Enter events are not raised on mdi child form controls on form Dark. + // Enter events are not raised on mdi child form controls on form Enabled. if (IsMdiChild) { UpdateFocusedControl(); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Layout/Containers/ValidationConstraints.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Layout/Containers/ValidationConstraints.cs index 7f8031eb9e9..19b03f7c8c0 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Layout/Containers/ValidationConstraints.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Layout/Containers/ValidationConstraints.cs @@ -27,7 +27,7 @@ public enum ValidationConstraints Selectable = 0x01, /// - /// Child control must be enabled to be validated (Control.Dark = true). + /// Child control must be enabled to be validated (Control.Enabled = true). /// Enabled = 0x02, diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Rendering/Animation/AnimatedControlRenderer.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Rendering/Animation/AnimatedControlRenderer.cs index fb2e3347d4c..9f7b228d283 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Rendering/Animation/AnimatedControlRenderer.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Rendering/Animation/AnimatedControlRenderer.cs @@ -31,7 +31,8 @@ public virtual void AnimationProc(float animationProgress) public abstract void RenderControl(Graphics graphics); /// - /// Invalidates the control, causing it to be redrawn, which in turns triggersRenderControl(PaintEventArgs). + /// Invalidates the control, causing it to be redrawn, which in turns triggers + /// . /// public void Invalidate() => control.Invalidate(); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Rendering/TextRenderer.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Rendering/TextRenderer.cs index fbad0654b61..f85b99997e0 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Rendering/TextRenderer.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Rendering/TextRenderer.cs @@ -632,7 +632,7 @@ internal static ApplyGraphicsProperties GetApplyStateFlags(IDeviceContext device // translation (rotation for example), and this likely impacted the decision to only have a translation // flag when this was originally written. - // Classic. We are getting this pretty much whenever we call a DrawText. + // Disabled. We are getting this pretty much whenever we call a DrawText. // Debug.Assert(apply.HasFlag(ApplyGraphicsProperties.Clipping) // || graphics.Clip is null diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/SystemColorMode.cs b/src/System.Windows.Forms/src/System/Windows/Forms/SystemColorMode.cs new file mode 100644 index 00000000000..2dca2b453d7 --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/SystemColorMode.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Windows.Forms +{ + [Experimental("WFO9001")] + public enum SystemColorMode + { + /// + /// Dark mode for the current context is or should be disabled. + /// + Classic = 0, + + /// + /// The setting for the current system color mode is inherited from the Windows OS. + /// + System = 1, + + /// + /// Dark mode for the current context is enabled. + /// + Dark = 2 + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/VisualStylesMode.cs b/src/System.Windows.Forms/src/System/Windows/Forms/VisualStylesMode.cs index 852741160fd..8ac2d2b8146 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/VisualStylesMode.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/VisualStylesMode.cs @@ -15,13 +15,20 @@ public enum VisualStylesMode : short Classic = 0, /// - /// Visual renderers are not in use. See ; Controls are based on Version 5 of ComCtl. + /// Visual renderers are not in use - see ; + /// Controls are based on Version 5 of ComCtl. /// Disabled = 1, /// /// The .NET 10 version of the visual renderer. Controls are rendered using the latest version - /// of ComCtl and customized adorner rendering and layout handling in addition. + /// of ComCtl and the adorners rendering or the layout of specific controls has been improved/updated + /// based on latest accessibility requirements. /// - Net10 = 2 + Net10 = 2, + + /// + /// The latest version of the visual renderer. + /// + Latest = short.MaxValue }