Skip to content

Commit

Permalink
Revert cc99a67.
Browse files Browse the repository at this point in the history
  • Loading branch information
KlausLoeffelmann committed Jul 31, 2024
1 parent 83b2f79 commit bd0c750
Show file tree
Hide file tree
Showing 38 changed files with 121 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace System.Windows.Forms.Design.Behavior;

/// <summary>
/// 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.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected Behavior(bool callParentBehavior, BehaviorService? behaviorService)

/// <summary>
/// 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.
/// </summary>
public virtual bool DisableAllCommands
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ protected override void Dispose(bool disposing)
/// </summary>
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ internal bool EditingCollection
}
}

// ContextMenuStrip if System ACT as Readonly.
// ContextMenuStrip if Inherited ACT as Readonly.
protected override InheritanceAttribute InheritanceAttribute
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ public void GetComponentDesignerActionsVerbs_GetSortedActionItems_ReturnsExpecte
DesignerActionList actionList = Assert.IsAssignableFrom<DesignerActionList>(Assert.Single(actionListBuffer));
Assert.Single(actionList.GetSortedActionItems());

// Not Classic.
// Not Disabled.
verb.Enabled = false;
Assert.Empty(actionList.GetSortedActionItems());
verb.Enabled = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

<ItemGroup>
<Compile Include="..\..\Common\src\WeakRefCollection.cs" Link="System\Collections\Generic\WeakRefCollection.cs" />
<Compile Include="..\..\System.Windows.Forms.Analyzers\src\System\Windows\Forms\Analyzers\Diagnostics\DiagnosticIDs.cs" Link="System\Windows\Forms\Analyzers\Diagnostics\DiagnosticIDs.cs" />
</ItemGroup>

</Project>
15 changes: 8 additions & 7 deletions src/System.Windows.Forms/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -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?
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
92 changes: 36 additions & 56 deletions src/System.Windows.Forms/src/System/Windows/Forms/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -243,43 +244,35 @@ internal static bool CustomThreadExceptionHandlerAttached
=> ThreadContext.FromCurrent().CustomThreadExceptionHandlerAttached;

/// <summary>
/// Gets the default dark mode for the application. This is the ColorMode which either has been set
/// by <see cref="SetDefaultColorMode(ColorMode, bool)"/> or its default value <see cref="ColorMode.Classic"/>.
/// Gets the default dark mode for the application. This is the SystemColorMode which either has been set
/// by <see cref="SetColorMode(SystemColorMode)"/> or its default value <see cref="SystemColorMode.Classic"/>.
/// </summary>
[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;

/// <summary>
/// Sets the default dark mode for the application.
/// </summary>
/// <param name="darkMode">The default dark mode to set.</param>
/// <param name="throwIfImpossible">Flag, if set to <see langword="true"/>, leads to an exception if the color mode is not supported.</param>
/// <param name="systemColorMode">The default dark mode to set.</param>
[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;
}

/// <summary>
Expand Down Expand Up @@ -327,30 +320,28 @@ public static void SetDefaultVisualStylesMode(VisualStylesMode styleSetting)
internal static Font DefaultFont => s_defaultFontScaled ?? s_defaultFont!;

/// <summary>
/// Gets the color mode setting of the OS system environment.
/// Gets the system color mode setting of the OS system environment.
/// </summary>
/// <remarks>
/// <para>
/// The color setting is determined based on the operating system version and its system settings. It returns
/// <see cref="ColorMode.Dark"/> if the dark mode is enabled in the system settings, <see cref="ColorMode.Classic"/>
/// 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 <see cref="SystemColorMode.Dark"/> if the dark mode is enabled in the system settings,
/// <see cref="SystemColorMode.Classic"/> if the color mode equals the light, standard color setting.
/// </para>
/// <para>
/// Color modes is supported on Windows 11 or later versions.
/// SystemColorMode is supported on Windows 11 or later versions.
/// </para>
/// <para>
/// Color modes is not supported, if the Windows OS <c>High Contrast Mode</c> has been enabled in the system settings.
/// SystemColorModes is not supported, if the Windows OS <c>High Contrast Mode</c> has been enabled in the system settings.
/// </para>
/// </remarks>
[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)
{
Expand Down Expand Up @@ -379,24 +370,13 @@ private static int GetSystemColorModeCore()
}

/// <summary>
/// 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 <see langword="false"/>.
/// </summary>
[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);

/// <summary>
/// Gets the path for the executable file that started the application.
Expand Down
26 changes: 0 additions & 26 deletions src/System.Windows.Forms/src/System/Windows/Forms/ColorMode.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
];
Expand Down
4 changes: 2 additions & 2 deletions src/System.Windows.Forms/src/System/Windows/Forms/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -3680,7 +3680,7 @@ public event EventHandler? VisualStylesModeChanged
/// </para>
/// <para>
/// 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 <see cref="Application.DefaultVisualStylesMode"/>. System controls can
/// it will inherit the setting from <see cref="Application.DefaultVisualStylesMode"/>. Inherited controls can
/// overwrite <see cref="DefaultVisualStylesMode"/> to ensure backwards compatibility for controls, which
/// rely on a specific version of the visual styles of a base control (see <see cref="TextBoxBase"/> as an example).
/// </para>
Expand Down
Loading

0 comments on commit bd0c750

Please sign in to comment.