Skip to content

Commit

Permalink
Add alternate system color experimental feature
Browse files Browse the repository at this point in the history
Allows overriding KnownColor system values with an alternate set, which in the initial iteration is "dark mode" colors. Enables "dark mode" features in Windows Forms.

This is from the approved part of dotnet/winforms#7641 with further naming iteration done offline with API review.
  • Loading branch information
JeremyKuhne committed Jul 29, 2024
1 parent f2d2fac commit 4800f19
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 88 deletions.
1 change: 1 addition & 0 deletions docs/project/list-of-diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,4 @@ Diagnostic id values for experimental APIs must not be recycled, as that could s
| Diagnostic ID | Introduced | Removed | Description |
| :---------------- | ---------: | ------: | :---------- |
| __`SYSLIB5001`__ | .NET 9 | TBD | `Tensor<T>` and related APIs in System.Numerics.Tensors are experimental in .NET 9 |
| __`SYSLIB5002`__ | .NET 9 | TBD | `SystemColors` alternate colors are experimental in .NET 9 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class User32
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public unsafe partial struct HIGHCONTRASTW
{
internal uint cbSize;
internal HIGHCONTRASTW_FLAGS dwFlags;
internal void* lpszDefaultScheme;
}

[Flags]
public enum HIGHCONTRASTW_FLAGS : uint
{
HCF_HIGHCONTRASTON = 0x00000001,
HCF_AVAILABLE = 0x00000002,
HCF_HOTKEYACTIVE = 0x00000004,
HCF_CONFIRMHOTKEY = 0x00000008,
HCF_HOTKEYSOUND = 0x00000010,
HCF_INDICATOR = 0x00000020,
HCF_HOTKEYAVAILABLE = 0x00000040,
HCF_OPTION_NOTHEMECHANGE = 0x00001000
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ internal static partial class User32
public enum SystemParametersAction : uint
{
SPI_GETICONTITLELOGFONT = 0x1F,
SPI_GETNONCLIENTMETRICS = 0x29
SPI_GETNONCLIENTMETRICS = 0x29,
SPI_GETHIGHCONTRAST = 0x42
}

[LibraryImport(Libraries.User32)]
Expand Down
3 changes: 3 additions & 0 deletions src/libraries/Common/src/System/Experimentals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ internal static class Experimentals
// Tensor<T> and related APIs are marked as [Experimental] in .NET 9
internal const string TensorTDiagId = "SYSLIB5001";

// SystemColors alternate colors are marked as [Experimental] in .NET 9
internal const string SystemColorsDiagId = "SYSLIB5002";

// When adding a new diagnostic ID, add it to the table in docs\project\list-of-diagnostics.md as well.
// Keep new const identifiers above this comment.
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
Microsoft Visual Studio Solution File, Format Version 12.00

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.11.35111.106
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestUtilities", "..\Common\tests\TestUtilities\TestUtilities.csproj", "{39205290-06C5-468E-B5C9-D9C5737909EE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Collections.NonGeneric", "..\System.Collections.NonGeneric\ref\System.Collections.NonGeneric.csproj", "{4B06D595-C5B5-49E3-BC5D-7CA55B52D91B}"
Expand Down Expand Up @@ -45,11 +49,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{722DCDC1-751
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "gen", "gen", "{8349AD04-5979-4347-A869-7F76B043453E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "gen", "tools\gen", "{1ACFEEFC-7E61-483E-9CAF-1EB2DFC11558}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "gen", "gen", "{1ACFEEFC-7E61-483E-9CAF-1EB2DFC11558}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "tools\src", "{D99A011B-F48D-4E22-9C5B-050294758522}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{D99A011B-F48D-4E22-9C5B-050294758522}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ref", "tools\ref", "{5CB40A8A-59D5-4E57-8F9A-D716C5BDFDC7}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ref", "ref", "{5CB40A8A-59D5-4E57-8F9A-D716C5BDFDC7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{0205F064-E9AB-408E-BC47-D1EB62C753C7}"
EndProject
Expand Down Expand Up @@ -141,29 +145,33 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{39205290-06C5-468E-B5C9-D9C5737909EE} = {B004DC3D-DA89-4C76-8D15-327CCDB6D7C0}
{515B6C1E-757F-497E-9707-37B5822FFC9A} = {B004DC3D-DA89-4C76-8D15-327CCDB6D7C0}
{4B06D595-C5B5-49E3-BC5D-7CA55B52D91B} = {F2D0660B-B4A3-4039-A47D-63F9D1CE19B6}
{6ED31F56-EBDB-4E4D-A6D5-8F6078B1A241} = {F2D0660B-B4A3-4039-A47D-63F9D1CE19B6}
{9D080C1F-6334-4C14-BABF-D0D9132C0D83} = {F2D0660B-B4A3-4039-A47D-63F9D1CE19B6}
{F92BFBC7-A148-44D5-A977-01926068615D} = {F2D0660B-B4A3-4039-A47D-63F9D1CE19B6}
{D2E753F4-34A3-4641-9C0F-53539147CCF2} = {F2D0660B-B4A3-4039-A47D-63F9D1CE19B6}
{80A68643-0E37-4525-BF06-F50C3BF7B867} = {722DCDC1-7510-4B50-93F4-51E5FF833B2A}
{515B6C1E-757F-497E-9707-37B5822FFC9A} = {B004DC3D-DA89-4C76-8D15-327CCDB6D7C0}
{731DA2F5-004D-46F0-8751-4945163E8DF4} = {F2D0660B-B4A3-4039-A47D-63F9D1CE19B6}
{D8C6E8A8-4E73-42CD-A310-C63B64844A4C} = {F2D0660B-B4A3-4039-A47D-63F9D1CE19B6}
{FD462F99-C9F6-4D3E-B080-F5E337E8F2F8} = {F2D0660B-B4A3-4039-A47D-63F9D1CE19B6}
{80A68643-0E37-4525-BF06-F50C3BF7B867} = {722DCDC1-7510-4B50-93F4-51E5FF833B2A}
{F06CCE8D-0066-4B17-8EF0-162AE711F6D8} = {8349AD04-5979-4347-A869-7F76B043453E}
{315E574D-6A26-4A89-83B5-1C948F3C83D2} = {8349AD04-5979-4347-A869-7F76B043453E}
{9ECCC771-064F-403E-8E0E-7B049AAFAD36} = {8349AD04-5979-4347-A869-7F76B043453E}
{FD462F99-C9F6-4D3E-B080-F5E337E8F2F8} = {F2D0660B-B4A3-4039-A47D-63F9D1CE19B6}
{D5E974B9-EB58-4D32-A4F4-C31559436DEA} = {1ACFEEFC-7E61-483E-9CAF-1EB2DFC11558}
{D2D8DF0A-836A-4521-A9F5-349F91E87046} = {1ACFEEFC-7E61-483E-9CAF-1EB2DFC11558}
{1ACFEEFC-7E61-483E-9CAF-1EB2DFC11558} = {0205F064-E9AB-408E-BC47-D1EB62C753C7}
{198C17DB-F65F-4165-996B-128E3123A6CF} = {D99A011B-F48D-4E22-9C5B-050294758522}
{A92D7FC7-E3A9-4260-8F25-7FCF3AA900DC} = {D99A011B-F48D-4E22-9C5B-050294758522}
{D99A011B-F48D-4E22-9C5B-050294758522} = {0205F064-E9AB-408E-BC47-D1EB62C753C7}
{0A6457CF-5932-44F6-9983-978FA163B3A5} = {5CB40A8A-59D5-4E57-8F9A-D716C5BDFDC7}
{1ACFEEFC-7E61-483E-9CAF-1EB2DFC11558} = {0205F064-E9AB-408E-BC47-D1EB62C753C7}
{D99A011B-F48D-4E22-9C5B-050294758522} = {0205F064-E9AB-408E-BC47-D1EB62C753C7}
{5CB40A8A-59D5-4E57-8F9A-D716C5BDFDC7} = {0205F064-E9AB-408E-BC47-D1EB62C753C7}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E2DD25F1-FA29-41D5-AB37-65DDC6A49304}
EndGlobalSection
GlobalSection(SharedMSBuildProjectFiles) = preSolution
..\..\tools\illink\src\ILLink.Shared\ILLink.Shared.projitems*{a92d7fc7-e3a9-4260-8f25-7fcf3aa900dc}*SharedItemsImports = 5
..\..\tools\illink\src\ILLink.Shared\ILLink.Shared.projitems*{d2d8df0a-836a-4521-a9f5-349f91e87046}*SharedItemsImports = 5
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -625,5 +625,7 @@ public static partial class SystemColors
public static System.Drawing.Color Window { get { throw null; } }
public static System.Drawing.Color WindowFrame { get { throw null; } }
public static System.Drawing.Color WindowText { get { throw null; } }
[System.Diagnostics.CodeAnalysis.Experimental("SYSLIB5002", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
public static bool UseAlternativeColorSet { get { throw null; } set { } }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,20 @@
Link="System\Drawing\ColorConverterCommon.cs" />
<Compile Include="$(CommonPath)System\Drawing\ColorTable.cs"
Link="System\Drawing\ColorTable.cs" />
<Compile Include="$(CommonPath)System\Experimentals.cs" Link="Common\System\Experimentals.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'windows'">
<Compile Include="$(CommonPath)Interop\Windows\Interop.Libraries.cs"
Link="Common\Interop\Windows\Interop.Libraries.cs" />
<Compile Include="$(CommonPath)Interop\Windows\User32\Interop.GetSysColor.cs"
Link="Common\Interop\Windows\User32\Interop.GetSysColor.cs" />
<Compile Include="$(CommonPath)Interop\Windows\User32\Interop.HIGHCONTRASTW.cs"
Link="Common\Interop\Windows\User32\Interop.HIGHCONTRASTW.cs" />
<Compile Include="$(CommonPath)Interop\Windows\User32\Interop.Win32SystemColors.cs"
Link="Common\Interop\Windows\User32\Interop.Win32SystemColors.cs" />
<Compile Include="$(CommonPath)Interop\Windows\User32\Interop.SystemParametersInfo.cs"
Link="Common\Interop\Windows\User32\Interop.SystemParametersInfo.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 4800f19

Please sign in to comment.