Skip to content

Commit 63cb7ec

Browse files
authored
Add alternate system color experimental feature (#105525)
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.
1 parent 4c58b5a commit 63cb7ec

File tree

10 files changed

+230
-88
lines changed

10 files changed

+230
-88
lines changed

docs/project/list-of-diagnostics.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,4 @@ Diagnostic id values for experimental APIs must not be recycled, as that could s
293293
| Diagnostic ID | Introduced | Removed | Description |
294294
| :---------------- | ---------: | ------: | :---------- |
295295
| __`SYSLIB5001`__ | .NET 9 | TBD | `Tensor<T>` and related APIs in System.Numerics.Tensors are experimental in .NET 9 |
296+
| __`SYSLIB5002`__ | .NET 9 | TBD | `SystemColors` alternate colors are experimental in .NET 9 |
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Runtime.InteropServices;
6+
7+
internal static partial class Interop
8+
{
9+
internal static partial class User32
10+
{
11+
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
12+
public unsafe partial struct HIGHCONTRASTW
13+
{
14+
internal uint cbSize;
15+
internal HIGHCONTRASTW_FLAGS dwFlags;
16+
internal void* lpszDefaultScheme;
17+
}
18+
19+
[Flags]
20+
public enum HIGHCONTRASTW_FLAGS : uint
21+
{
22+
HCF_HIGHCONTRASTON = 0x00000001,
23+
HCF_AVAILABLE = 0x00000002,
24+
HCF_HOTKEYACTIVE = 0x00000004,
25+
HCF_CONFIRMHOTKEY = 0x00000008,
26+
HCF_HOTKEYSOUND = 0x00000010,
27+
HCF_INDICATOR = 0x00000020,
28+
HCF_HOTKEYAVAILABLE = 0x00000040,
29+
HCF_OPTION_NOTHEMECHANGE = 0x00001000
30+
}
31+
}
32+
}

src/libraries/Common/src/Interop/Windows/User32/Interop.SystemParametersInfo.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ internal static partial class User32
1111
public enum SystemParametersAction : uint
1212
{
1313
SPI_GETICONTITLELOGFONT = 0x1F,
14-
SPI_GETNONCLIENTMETRICS = 0x29
14+
SPI_GETNONCLIENTMETRICS = 0x29,
15+
SPI_GETHIGHCONTRAST = 0x42
1516
}
1617

1718
[LibraryImport(Libraries.User32)]

src/libraries/Common/src/System/Experimentals.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ internal static class Experimentals
1919
// Tensor<T> and related APIs are marked as [Experimental] in .NET 9
2020
internal const string TensorTDiagId = "SYSLIB5001";
2121

22+
// SystemColors alternate colors are marked as [Experimental] in .NET 9
23+
internal const string SystemColorsDiagId = "SYSLIB5002";
24+
2225
// When adding a new diagnostic ID, add it to the table in docs\project\list-of-diagnostics.md as well.
2326
// Keep new const identifiers above this comment.
2427
}

src/libraries/System.Drawing.Primitives/System.Drawing.Primitives.sln

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
Microsoft Visual Studio Solution File, Format Version 12.00
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.11.35111.106
5+
MinimumVisualStudioVersion = 10.0.40219.1
26
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestUtilities", "..\Common\tests\TestUtilities\TestUtilities.csproj", "{39205290-06C5-468E-B5C9-D9C5737909EE}"
37
EndProject
48
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Collections.NonGeneric", "..\System.Collections.NonGeneric\ref\System.Collections.NonGeneric.csproj", "{4B06D595-C5B5-49E3-BC5D-7CA55B52D91B}"
@@ -45,11 +49,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{722DCDC1-751
4549
EndProject
4650
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "gen", "gen", "{8349AD04-5979-4347-A869-7F76B043453E}"
4751
EndProject
48-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "gen", "tools\gen", "{1ACFEEFC-7E61-483E-9CAF-1EB2DFC11558}"
52+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "gen", "gen", "{1ACFEEFC-7E61-483E-9CAF-1EB2DFC11558}"
4953
EndProject
50-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "tools\src", "{D99A011B-F48D-4E22-9C5B-050294758522}"
54+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{D99A011B-F48D-4E22-9C5B-050294758522}"
5155
EndProject
52-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ref", "tools\ref", "{5CB40A8A-59D5-4E57-8F9A-D716C5BDFDC7}"
56+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ref", "ref", "{5CB40A8A-59D5-4E57-8F9A-D716C5BDFDC7}"
5357
EndProject
5458
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{0205F064-E9AB-408E-BC47-D1EB62C753C7}"
5559
EndProject
@@ -141,29 +145,33 @@ Global
141145
EndGlobalSection
142146
GlobalSection(NestedProjects) = preSolution
143147
{39205290-06C5-468E-B5C9-D9C5737909EE} = {B004DC3D-DA89-4C76-8D15-327CCDB6D7C0}
144-
{515B6C1E-757F-497E-9707-37B5822FFC9A} = {B004DC3D-DA89-4C76-8D15-327CCDB6D7C0}
145148
{4B06D595-C5B5-49E3-BC5D-7CA55B52D91B} = {F2D0660B-B4A3-4039-A47D-63F9D1CE19B6}
146149
{6ED31F56-EBDB-4E4D-A6D5-8F6078B1A241} = {F2D0660B-B4A3-4039-A47D-63F9D1CE19B6}
147150
{9D080C1F-6334-4C14-BABF-D0D9132C0D83} = {F2D0660B-B4A3-4039-A47D-63F9D1CE19B6}
148151
{F92BFBC7-A148-44D5-A977-01926068615D} = {F2D0660B-B4A3-4039-A47D-63F9D1CE19B6}
149152
{D2E753F4-34A3-4641-9C0F-53539147CCF2} = {F2D0660B-B4A3-4039-A47D-63F9D1CE19B6}
153+
{80A68643-0E37-4525-BF06-F50C3BF7B867} = {722DCDC1-7510-4B50-93F4-51E5FF833B2A}
154+
{515B6C1E-757F-497E-9707-37B5822FFC9A} = {B004DC3D-DA89-4C76-8D15-327CCDB6D7C0}
150155
{731DA2F5-004D-46F0-8751-4945163E8DF4} = {F2D0660B-B4A3-4039-A47D-63F9D1CE19B6}
151156
{D8C6E8A8-4E73-42CD-A310-C63B64844A4C} = {F2D0660B-B4A3-4039-A47D-63F9D1CE19B6}
152-
{FD462F99-C9F6-4D3E-B080-F5E337E8F2F8} = {F2D0660B-B4A3-4039-A47D-63F9D1CE19B6}
153-
{80A68643-0E37-4525-BF06-F50C3BF7B867} = {722DCDC1-7510-4B50-93F4-51E5FF833B2A}
154157
{F06CCE8D-0066-4B17-8EF0-162AE711F6D8} = {8349AD04-5979-4347-A869-7F76B043453E}
155158
{315E574D-6A26-4A89-83B5-1C948F3C83D2} = {8349AD04-5979-4347-A869-7F76B043453E}
156159
{9ECCC771-064F-403E-8E0E-7B049AAFAD36} = {8349AD04-5979-4347-A869-7F76B043453E}
160+
{FD462F99-C9F6-4D3E-B080-F5E337E8F2F8} = {F2D0660B-B4A3-4039-A47D-63F9D1CE19B6}
157161
{D5E974B9-EB58-4D32-A4F4-C31559436DEA} = {1ACFEEFC-7E61-483E-9CAF-1EB2DFC11558}
158162
{D2D8DF0A-836A-4521-A9F5-349F91E87046} = {1ACFEEFC-7E61-483E-9CAF-1EB2DFC11558}
159-
{1ACFEEFC-7E61-483E-9CAF-1EB2DFC11558} = {0205F064-E9AB-408E-BC47-D1EB62C753C7}
160163
{198C17DB-F65F-4165-996B-128E3123A6CF} = {D99A011B-F48D-4E22-9C5B-050294758522}
161164
{A92D7FC7-E3A9-4260-8F25-7FCF3AA900DC} = {D99A011B-F48D-4E22-9C5B-050294758522}
162-
{D99A011B-F48D-4E22-9C5B-050294758522} = {0205F064-E9AB-408E-BC47-D1EB62C753C7}
163165
{0A6457CF-5932-44F6-9983-978FA163B3A5} = {5CB40A8A-59D5-4E57-8F9A-D716C5BDFDC7}
166+
{1ACFEEFC-7E61-483E-9CAF-1EB2DFC11558} = {0205F064-E9AB-408E-BC47-D1EB62C753C7}
167+
{D99A011B-F48D-4E22-9C5B-050294758522} = {0205F064-E9AB-408E-BC47-D1EB62C753C7}
164168
{5CB40A8A-59D5-4E57-8F9A-D716C5BDFDC7} = {0205F064-E9AB-408E-BC47-D1EB62C753C7}
165169
EndGlobalSection
166170
GlobalSection(ExtensibilityGlobals) = postSolution
167171
SolutionGuid = {E2DD25F1-FA29-41D5-AB37-65DDC6A49304}
168172
EndGlobalSection
173+
GlobalSection(SharedMSBuildProjectFiles) = preSolution
174+
..\..\tools\illink\src\ILLink.Shared\ILLink.Shared.projitems*{a92d7fc7-e3a9-4260-8f25-7fcf3aa900dc}*SharedItemsImports = 5
175+
..\..\tools\illink\src\ILLink.Shared\ILLink.Shared.projitems*{d2d8df0a-836a-4521-a9f5-349f91e87046}*SharedItemsImports = 5
176+
EndGlobalSection
169177
EndGlobal

src/libraries/System.Drawing.Primitives/ref/System.Drawing.Primitives.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,5 +625,7 @@ public static partial class SystemColors
625625
public static System.Drawing.Color Window { get { throw null; } }
626626
public static System.Drawing.Color WindowFrame { get { throw null; } }
627627
public static System.Drawing.Color WindowText { get { throw null; } }
628+
[System.Diagnostics.CodeAnalysis.Experimental("SYSLIB5002", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
629+
public static bool UseAlternativeColorSet { get { throw null; } set { } }
628630
}
629631
}

src/libraries/System.Drawing.Primitives/src/System.Drawing.Primitives.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,20 @@
2929
Link="System\Drawing\ColorConverterCommon.cs" />
3030
<Compile Include="$(CommonPath)System\Drawing\ColorTable.cs"
3131
Link="System\Drawing\ColorTable.cs" />
32+
<Compile Include="$(CommonPath)System\Experimentals.cs" Link="Common\System\Experimentals.cs" />
3233
</ItemGroup>
3334

3435
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'windows'">
3536
<Compile Include="$(CommonPath)Interop\Windows\Interop.Libraries.cs"
3637
Link="Common\Interop\Windows\Interop.Libraries.cs" />
3738
<Compile Include="$(CommonPath)Interop\Windows\User32\Interop.GetSysColor.cs"
3839
Link="Common\Interop\Windows\User32\Interop.GetSysColor.cs" />
40+
<Compile Include="$(CommonPath)Interop\Windows\User32\Interop.HIGHCONTRASTW.cs"
41+
Link="Common\Interop\Windows\User32\Interop.HIGHCONTRASTW.cs" />
3942
<Compile Include="$(CommonPath)Interop\Windows\User32\Interop.Win32SystemColors.cs"
4043
Link="Common\Interop\Windows\User32\Interop.Win32SystemColors.cs" />
44+
<Compile Include="$(CommonPath)Interop\Windows\User32\Interop.SystemParametersInfo.cs"
45+
Link="Common\Interop\Windows\User32\Interop.SystemParametersInfo.cs" />
4146
</ItemGroup>
4247

4348
<ItemGroup>

0 commit comments

Comments
 (0)