Skip to content

Commit

Permalink
Refactor SystemColors to use UseAlternativeColorSet.
Browse files Browse the repository at this point in the history
  • Loading branch information
KlausLoeffelmann committed Aug 1, 2024
1 parent 652290e commit a83fbb4
Show file tree
Hide file tree
Showing 25 changed files with 90 additions and 545 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ internal class FlyoutDialog : Form
private readonly Control _hostedControl;
private readonly Control _parentControl;

#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.
public FlyoutDialog(Control hostedControl, Control parentControl, Color borderColor, Font font)
{
_hostedControl = hostedControl;
_parentControl = parentControl;
BackColor = ControlSystemColors.Current.Window;
BackColor = SystemColors.Window;
ControlBox = false;
Font = font;
FormBorderStyle = FormBorderStyle.None;
Expand Down Expand Up @@ -54,7 +53,6 @@ public FlyoutDialog(Control hostedControl, Control parentControl, Color borderCo
ResumeLayout();
}
}
#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.

protected override CreateParams CreateParams
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace System.ComponentModel.Design;

internal sealed partial class DesignerActionPanel
{
#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 sealed partial class EditorPropertyLine : TextBoxPropertyLine, IWindowsFormsEditorService, IServiceProvider
{
private readonly EditorButton _button;
Expand Down Expand Up @@ -109,7 +108,7 @@ private unsafe void ActivateDropDown()

try
{
ShowDropDown(listBox, ControlSystemColors.Current.ControlDark);
ShowDropDown(listBox, SystemColors.ControlDark);
}
finally
{
Expand Down Expand Up @@ -483,5 +482,4 @@ public override Line CreateLine(IServiceProvider serviceProvider, DesignerAction
public override Type LineType => typeof(EditorPropertyLine);
}
}
#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.
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace System.ComponentModel.Design;

internal sealed partial class DesignerActionPanel
{
#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 class TextBoxPropertyLine : PropertyLine
{
private readonly TextBox _textBox;
Expand All @@ -33,9 +32,7 @@ protected TextBoxPropertyLine(IServiceProvider serviceProvider, DesignerActionPa
_readOnlyTextBoxLabel = new EditorLabel
{
BackColor = Color.Transparent,
#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.
ForeColor = ControlSystemColors.Current.WindowText,
#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.
ForeColor = SystemColors.WindowText,
TabStop = true,
TextAlign = ContentAlignment.TopLeft,
UseMnemonic = false,
Expand Down Expand Up @@ -160,19 +157,17 @@ protected virtual void OnReadOnlyTextBoxLabelClick(object? sender, MouseEventArg
}
}

#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 void OnReadOnlyTextBoxLabelEnter(object? sender, EventArgs e)
{
_readOnlyTextBoxLabel.ForeColor = ControlSystemColors.Current.HighlightText;
_readOnlyTextBoxLabel.BackColor = ControlSystemColors.Current.Highlight;
_readOnlyTextBoxLabel.ForeColor = SystemColors.HighlightText;
_readOnlyTextBoxLabel.BackColor = SystemColors.Highlight;
}

private void OnReadOnlyTextBoxLabelLeave(object? sender, EventArgs e)
{
_readOnlyTextBoxLabel.ForeColor = ControlSystemColors.Current.WindowText;
_readOnlyTextBoxLabel.BackColor = ControlSystemColors.Current.Window;
_readOnlyTextBoxLabel.ForeColor = SystemColors.WindowText;
_readOnlyTextBoxLabel.BackColor = SystemColors.Window;
}
#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.

protected TypeConverter.StandardValuesCollection? GetStandardValues()
{
Expand Down Expand Up @@ -371,5 +366,4 @@ public override Line CreateLine(IServiceProvider serviceProvider, DesignerAction
public override Type LineType => typeof(TextBoxPropertyLine);
}
}
#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.
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace System.ComponentModel.Design;

internal sealed partial class DesignerActionPanel : ContainerControl
{
#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 readonly object s_eventFormActivated = new();
private static readonly object s_eventFormDeactivate = new();

Expand Down Expand Up @@ -118,9 +117,9 @@ public DesignerActionPanel(IServiceProvider serviceProvider)
MinimumSize = new Size(150, 0);
}

public Color ActiveLinkColor { get; } = ControlSystemColors.Current.HotTrack;
public Color ActiveLinkColor { get; } = SystemColors.HotTrack;

public Color BorderColor { get; } = ControlSystemColors.Current.ActiveBorder;
public Color BorderColor { get; } = SystemColors.ActiveBorder;

/// <summary>
/// Returns the list of commands that should be filtered by the form that hosts this panel. This is done so that these specific commands will not get passed on to VS, and can instead be handled by the panel itself.
Expand Down Expand Up @@ -168,23 +167,23 @@ public DesignerActionPanel(IServiceProvider serviceProvider)
/// </summary>
private Line? FocusedLine => ActiveControl?.Tag as Line;

public Color GradientDarkColor { get; } = ControlSystemColors.Current.Control;
public Color GradientDarkColor { get; } = SystemColors.Control;

public Color GradientLightColor { get; } = ControlSystemColors.Current.Control;
public Color GradientLightColor { get; } = SystemColors.Control;

public bool InMethodInvoke { get; internal set; }

public Color LinkColor { get; } = ControlSystemColors.Current.HotTrack;
public Color LinkColor { get; } = SystemColors.HotTrack;

public Color SeparatorColor { get; } = ControlSystemColors.Current.ControlDark;
public Color SeparatorColor { get; } = SystemColors.ControlDark;

public Color TitleBarColor { get; } = ControlSystemColors.Current.ActiveCaption;
public Color TitleBarColor { get; } = SystemColors.ActiveCaption;

public Color TitleBarTextColor { get; } = ControlSystemColors.Current.ActiveCaptionText;
public Color TitleBarTextColor { get; } = SystemColors.ActiveCaptionText;

public Color TitleBarUnselectedColor { get; } = ControlSystemColors.Current.InactiveCaption;
public Color TitleBarUnselectedColor { get; } = SystemColors.InactiveCaption;

public Color LabelForeColor { get; } = ControlSystemColors.Current.ControlText;
public Color LabelForeColor { get; } = SystemColors.ControlText;

/// <summary>
/// Helper event so that Lines can be notified of this event.
Expand Down Expand Up @@ -909,5 +908,4 @@ public void UpdateTasks(DesignerActionListCollection actionLists, DesignerAction

Invalidate();
}
#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.
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,8 @@ public virtual void DoPaint(Graphics graphics)
Rectangle inner = _innerRect;
Rectangle outer = _outerRect;
Region oldClip = graphics.Clip;
#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.
Color borderColor = ControlSystemColors.Current.Control;
#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.
Color borderColor = SystemColors.Control;

if (_control is not null && _control.Parent is not null)
{
Control parent = _control.Parent;
Expand Down
37 changes: 0 additions & 37 deletions src/System.Windows.Forms/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ override System.Windows.Forms.CheckBox.OnPaint(System.Windows.Forms.PaintEventAr
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.Form.FormBorderColor.get -> System.Drawing.Color
System.Windows.Forms.Form.FormBorderColor.set -> void
System.Windows.Forms.Form.FormBorderColorChanged -> System.EventHandler?
Expand All @@ -25,8 +23,6 @@ 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?
System.Windows.Forms.ControlStyles.ApplyThemingImplicitly = 524288 -> System.Windows.Forms.ControlStyles
override System.Windows.Forms.ProgressBar.OnCreateControl() -> void
Expand All @@ -47,39 +43,6 @@ virtual System.Windows.Forms.Control.DefaultVisualStylesMode.get -> System.Windo
virtual System.Windows.Forms.Control.OnDebuggerBreak(string! ticket) -> bool
virtual System.Windows.Forms.Control.OnParentVisualStylesModeChanged(System.EventArgs! e) -> void
virtual System.Windows.Forms.Control.OnVisualStylesModeChanged(System.EventArgs! e) -> void
System.Windows.Forms.Control.ControlSystemColors.ActiveBorder.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.ActiveCaption.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.ActiveCaptionText.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.AppWorkspace.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.ButtonFace.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.ButtonHighlight.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.ButtonShadow.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.Control.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.ControlDark.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.ControlDarkDark.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.ControlLight.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.ControlLightLight.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.ControlText.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.Desktop.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.GradientActiveCaption.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.GradientInactiveCaption.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.GrayText.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.Highlight.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.HighlightText.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.HotTrack.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.InactiveBorder.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.InactiveCaption.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.InactiveCaptionText.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.Info.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.InfoText.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.Menu.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.MenuBar.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.MenuHighlight.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.MenuText.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.ScrollBar.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.Window.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.WindowFrame.get -> System.Drawing.Color
System.Windows.Forms.Control.ControlSystemColors.WindowText.get -> System.Drawing.Color
virtual System.Windows.Forms.Form.OnFormBorderColorChanged(System.EventArgs! e) -> void
virtual System.Windows.Forms.Form.OnFormCaptionBackColorChanged(System.EventArgs! e) -> void
virtual System.Windows.Forms.Form.OnFormCaptionTextColorChanged(System.EventArgs! e) -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3361,10 +3361,8 @@ private unsafe bool QuickActivate()
}
else
{
#pragma warning disable WFO9001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
qaContainer.colorFore = GetOleColorFromColor(ControlSystemColors.Current.WindowText);
qaContainer.colorBack = GetOleColorFromColor(ControlSystemColors.Current.Window);
#pragma warning restore WFO9001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
qaContainer.colorFore = GetOleColorFromColor(SystemColors.WindowText);
qaContainer.colorBack = GetOleColorFromColor(SystemColors.Window);
}

qaContainer.dwAmbientFlags = QACONTAINERFLAGS.QACONTAINER_AUTOCLIP
Expand Down
17 changes: 12 additions & 5 deletions src/System.Windows.Forms/src/System/Windows/Forms/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,20 @@ internal static bool CustomThreadExceptionHandlerAttached
[Experimental("WFO9001")]
public static void SetColorMode(SystemColorMode systemColorMode)
{
if (GetSystemColorModeInternal() > -1)
try
{
s_systemColorMode = systemColorMode;
return;
}
if (GetSystemColorModeInternal() > -1)
{
s_systemColorMode = systemColorMode;
return;
}

s_systemColorMode = SystemColorMode.Classic;
s_systemColorMode = SystemColorMode.Classic;
}
finally
{
SystemColors.UseAlternativeColorSet = IsDarkModeEnabled;
}
}

/// <summary>
Expand Down
Loading

0 comments on commit a83fbb4

Please sign in to comment.