2 // System.Drawing.SystemColors.cs
4 // Copyright (C) 2002 Ximian, Inc (http://www.ximian.com)
5 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
7 // Permission is hereby granted, free of charge, to any person obtaining
8 // a copy of this software and associated documentation files (the
9 // "Software"), to deal in the Software without restriction, including
10 // without limitation the rights to use, copy, modify, merge, publish,
11 // distribute, sublicense, and/or sell copies of the Software, and to
12 // permit persons to whom the Software is furnished to do so, subject to
13 // the following conditions:
15 // The above copyright notice and this permission notice shall be
16 // included in all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
28 // Peter Dennis Bartok (pbartok@novell.com)
32 // The following method can be (and was) used to generate the defaults for the properties
33 //private static void GenerateColorTable (Type type) {
\r
34 // PropertyInfo [] props = type.GetProperties ();
\r
35 // foreach (PropertyInfo prop in props){
\r
36 // if (prop.PropertyType != typeof (Color))
\r
39 // MethodInfo getget = prop.GetGetMethod ();
\r
40 // if (getget == null || getget.IsStatic == false)
\r
43 // object o = prop.GetValue (null, null);
\r
45 // Color c = (Color) o;
\r
47 // StringBuilder name = new StringBuilder(prop.Name);
\r
48 // name[0] = Char.ToLower(name[0]);
\r
49 // for (int i = 1; i < name.Length; i++) {
\r
50 // if (Char.IsUpper(name[i])) {
\r
51 // name[i] = Char.ToLower(name[i]);
\r
52 // name.Insert(i, '_');
\r
56 // Console.WriteLine("static private Color " + name.ToString() + " = Color.FromArgbSystem (" +
\r
57 // c.A.ToString() + ", " +
\r
58 // c.R.ToString() + ", " +
\r
59 // c.G.ToString() + ", " +
\r
60 // c.B.ToString() + ", " +
\r
61 // "\"" + prop.Name + "\", " +
\r
62 // "KnownColor." + prop.Name + ");");
\r
68 using System.Reflection;
69 using System.Runtime.InteropServices;
71 namespace System.Drawing {
72 public sealed class SystemColors
74 // Default Windows XP color table
75 static private Color active_border = Color.FromArgbSystem (255, 212, 208, 200, "ActiveBorder", KnownColor.ActiveBorder);
\r
76 static private Color active_caption = Color.FromArgbSystem (255, 0, 164, 164, "ActiveCaption", KnownColor.ActiveCaption);
\r
77 static private Color active_caption_text = Color.FromArgbSystem (255, 255, 255, 255, "ActiveCaptionText", KnownColor.ActiveCaptionText);
\r
78 static private Color app_workspace = Color.FromArgbSystem (255, 128, 128, 128, "AppWorkspace", KnownColor.AppWorkspace);
\r
79 static private Color control = Color.FromArgbSystem (255, 212, 208, 200, "Control", KnownColor.Control);
\r
80 static private Color control_dark = Color.FromArgbSystem (255, 128, 128, 128, "ControlDark", KnownColor.ControlDark);
\r
81 static private Color control_dark_dark = Color.FromArgbSystem (255, 64, 64, 64, "ControlDarkDark", KnownColor.ControlDarkDark);
\r
82 static private Color control_light = Color.FromArgbSystem (255, 212, 208, 200, "ControlLight", KnownColor.ControlLight);
\r
83 static private Color control_light_light = Color.FromArgbSystem (255, 255, 255, 255, "ControlLightLight", KnownColor.ControlLightLight);
\r
84 static private Color control_text = Color.FromArgbSystem (255, 0, 0, 0, "ControlText", KnownColor.ControlText);
\r
85 static private Color desktop = Color.FromArgbSystem (255, 0, 0, 0, "Desktop", KnownColor.Desktop);
\r
86 static private Color gray_text = Color.FromArgbSystem (255, 128, 128, 128, "GrayText", KnownColor.GrayText);
\r
87 static private Color highlight = Color.FromArgbSystem (255, 10, 36, 106, "Highlight", KnownColor.Highlight);
\r
88 static private Color highlight_text = Color.FromArgbSystem (255, 255, 255, 255, "HighlightText", KnownColor.HighlightText);
\r
89 static private Color hot_track = Color.FromArgbSystem (255, 0, 0, 128, "HotTrack", KnownColor.HotTrack);
\r
90 static private Color inactive_border = Color.FromArgbSystem (255, 212, 208, 200, "InactiveBorder", KnownColor.InactiveBorder);
\r
91 static private Color inactive_caption = Color.FromArgbSystem (255, 128, 128, 128, "InactiveCaption", KnownColor.InactiveCaption);
\r
92 static private Color inactive_caption_text = Color.FromArgbSystem (255, 212, 208, 200, "InactiveCaptionText", KnownColor.InactiveCaptionText);
\r
93 static private Color info = Color.FromArgbSystem (255, 255, 255, 225, "Info", KnownColor.Info);
\r
94 static private Color info_text = Color.FromArgbSystem (255, 0, 0, 0, "InfoText", KnownColor.InfoText);
\r
95 static private Color menu = Color.FromArgbSystem (255, 212, 208, 200, "Menu", KnownColor.Menu);
\r
96 static private Color menu_text = Color.FromArgbSystem (255, 0, 0, 0, "MenuText", KnownColor.MenuText);
\r
97 static private Color scroll_bar = Color.FromArgbSystem (255, 212, 208, 200, "ScrollBar", KnownColor.ScrollBar);
\r
98 // This would give a better looking gray background instead of the high-contrast white background
\r
99 //static private Color window = Color.FromArgbSystem (255, 212, 208, 200, "Window", KnownColor.Window);
\r
100 static private Color window = Color.FromArgbSystem (255, 255, 255, 255, "Window", KnownColor.Window);
\r
101 static private Color window_frame = Color.FromArgbSystem (255, 0, 0, 0, "WindowFrame", KnownColor.WindowFrame);
\r
102 static private Color window_text = Color.FromArgbSystem (255, 0, 0, 0, "WindowText", KnownColor.WindowText);
105 static private Color button_face = Color.FromArgbSystem (255, 192, 192, 192, "ButtonFace", KnownColor.ButtonFace);
106 static private Color button_highlight = Color.FromArgbSystem (255, 255, 255, 255, "ButtonHighlight", KnownColor.ButtonHighlight);
107 static private Color button_shadow = Color.FromArgbSystem (255, 128, 128, 128, "ButtonShadow", KnownColor.ButtonShadow);
108 static private Color gradient_activecaption = Color.FromArgbSystem (255, 16, 132, 208, "GradientActiveCaption", KnownColor.GradientActiveCaption);
109 static private Color gradient_inactivecaption = Color.FromArgbSystem (255, 181, 181, 181, "GradientInactiveCaption", KnownColor.GradientInactiveCaption);
110 static private Color menubar = Color.FromArgbSystem (255, 192, 192, 192, "MenuBar", KnownColor.MenuBar);
111 static private Color menu_highlight = Color.FromArgbSystem (255, 0, 0, 0, "MenuHighlight", KnownColor.MenuHighlight);
115 static private Color active_border = Color.FromArgbSystem (255, 131, 153, 177, "ActiveBorder", KnownColor.ActiveBorder);
116 static private Color active_caption = Color.FromArgbSystem (255, 79, 101, 125, "ActiveCaption", KnownColor.ActiveCaption);
117 static private Color active_caption_text = Color.FromArgbSystem (255, 255, 255, 255, "ActiveCaptionText", KnownColor.ActiveCaptionText);
118 static private Color app_workspace = Color.FromArgbSystem (255, 128, 128, 128, "AppWorkspace", KnownColor.AppWorkspace);
119 static private Color control = Color.FromArgbSystem (255, 192, 192, 192, "Control", KnownColor.Control);
120 static private Color control_dark = Color.FromArgbSystem (255, 79, 101, 125, "ControlDark", KnownColor.ControlDark);
121 static private Color control_dark_dark = Color.FromArgbSystem (255, 0, 0, 0, "ControlDarkDark", KnownColor.ControlDarkDark);
122 static private Color control_light = Color.FromArgbSystem (255, 131, 153, 177, "ControlLight", KnownColor.ControlLight);
123 static private Color control_light_light = Color.FromArgbSystem (255, 193, 204, 217, "ControlLightLight", KnownColor.ControlLightLight);
124 static private Color control_text = Color.FromArgbSystem (255, 0, 0, 0, "ControlText", KnownColor.ControlText);
125 static private Color desktop = Color.FromArgbSystem (255, 0, 0, 0, "Desktop", KnownColor.Desktop);
126 static private Color gray_text = Color.FromArgbSystem (255, 79, 101, 125, "GrayText", KnownColor.GrayText);
127 static private Color highlight = Color.FromArgbSystem (255, 0, 0, 128, "Highlight", KnownColor.Highlight);
128 static private Color highlight_text = Color.FromArgbSystem (255, 255, 255, 255, "HighlightText", KnownColor.HighlightText);
129 static private Color hot_track = Color.FromArgbSystem (255, 0, 0, 255, "HotTrack", KnownColor.HotTrack);
130 static private Color inactive_border = Color.FromArgbSystem (255, 131, 153, 177, "InactiveBorder", KnownColor.InactiveBorder);
131 static private Color inactive_caption = Color.FromArgbSystem (255, 128, 128, 128, "InactiveCaption", KnownColor.InactiveCaption);
132 static private Color inactive_caption_text = Color.FromArgbSystem (255, 193, 204, 217, "InactiveCaptionText", KnownColor.InactiveCaptionText);
133 static private Color info = Color.FromArgbSystem (255, 255, 255, 255, "Info", KnownColor.Info);
134 static private Color info_text = Color.FromArgbSystem (255, 0, 0, 0, "InfoText", KnownColor.InfoText);
135 static private Color menu = Color.FromArgbSystem (255, 131, 153, 177, "Menu", KnownColor.Menu);
136 static private Color menu_text = Color.FromArgbSystem (255, 0, 0, 0, "MenuText", KnownColor.MenuText);
137 static private Color scroll_bar = Color.FromArgbSystem (255, 193, 204, 217, "ScrollBar", KnownColor.ScrollBar);
138 static private Color window = Color.FromArgbSystem (255, 255, 255, 255, "Window", KnownColor.Window);
139 static private Color window_frame = Color.FromArgbSystem (255, 0, 0, 0, "WindowFrame", KnownColor.WindowFrame);
140 static private Color window_text = Color.FromArgbSystem (255, 0, 0, 0, "WindowText", KnownColor.WindowText);
142 private enum GetSysColorIndex {
144 COLOR_BACKGROUND = 1,
145 COLOR_ACTIVECAPTION = 2,
146 COLOR_INACTIVECAPTION = 3,
149 COLOR_WINDOWFRAME = 6,
151 COLOR_WINDOWTEXT = 8,
152 COLOR_CAPTIONTEXT = 9,
153 COLOR_ACTIVEBORDER = 10,
154 COLOR_INACTIVEBORDER = 11,
155 COLOR_APPWORKSPACE = 12,
156 COLOR_HIGHLIGHT = 13,
157 COLOR_HIGHLIGHTTEXT = 14,
159 COLOR_BTNSHADOW = 16,
162 COLOR_INACTIVECAPTIONTEXT = 19,
163 COLOR_BTNHIGHLIGHT = 20,
164 COLOR_3DDKSHADOW = 21,
170 COLOR_GRADIENTACTIVECAPTION = 27,
171 COLOR_GRADIENTINACTIVECAPTION = 28,
172 COLOR_MENUHIGHLIGHT = 29,
178 COLOR_3DHIGHLIGHT = 20,
179 COLOR_3DHILIGHT = 20,
180 COLOR_BTNHILIGHT = 20,
182 COLOR_MAXVALUE = 30,/* Maximum value */
185 [DllImport ("user32.dll", EntryPoint="GetSysColor", CallingConvention=CallingConvention.StdCall)]
186 private extern static uint Win32GetSysColor(GetSysColorIndex index);
188 private static Color GetSysColor(GetSysColorIndex index, string name, KnownColor knownColor) {
191 color = Win32GetSysColor(index);
193 return Color.FromArgbSystem(255, (byte)(color & 0xff), (byte)((color >> 8) & 0xff), (byte)((color >> 16) & 0xff), name, knownColor);
196 // When this method is called, we teach any new color(s) to the Color class
197 private static void UpdateColors() {
198 Color.UpdateKnownColor (active_border.A, active_border.R, active_border.G, active_border.B, "ActiveBorder", KnownColor.ActiveBorder);
199 Color.UpdateKnownColor (active_caption.A, active_caption.R, active_caption.G, active_caption.B, "ActiveCaption", KnownColor.ActiveCaption);
200 Color.UpdateKnownColor (active_caption_text.A, active_caption_text.R, active_caption_text.G, active_caption_text.B, "ActiveCaptionText", KnownColor.ActiveCaptionText);
201 Color.UpdateKnownColor (app_workspace.A, app_workspace.R, app_workspace.G, app_workspace.B, "AppWorkspace", KnownColor.AppWorkspace);
202 Color.UpdateKnownColor (control.A, control.R, control.G, control.B, "Control", KnownColor.Control);
203 Color.UpdateKnownColor (control_dark.A, control_dark.R, control_dark.G, control_dark.B, "ControlDark", KnownColor.ControlDark);
204 Color.UpdateKnownColor (control_dark_dark.A, control_dark_dark.R, control_dark_dark.G, control_dark_dark.B, "ControlDarkDark", KnownColor.ControlDarkDark);
205 Color.UpdateKnownColor (control_light.A, control_light.R, control_light.G, control_light.B, "ControlLight", KnownColor.ControlLight);
206 Color.UpdateKnownColor (control_light_light.A, control_light_light.R, control_light_light.G, control_light_light.B, "ControlLightLight", KnownColor.ControlLightLight);
207 Color.UpdateKnownColor (control_text.A, control_text.R, control_text.G, control_text.B, "ControlText", KnownColor.ControlText);
208 Color.UpdateKnownColor (desktop.A, desktop.R, desktop.G, desktop.B, "Desktop", KnownColor.Desktop);
209 Color.UpdateKnownColor (gray_text.A, gray_text.R, gray_text.G, gray_text.B, "GrayText", KnownColor.GrayText);
210 Color.UpdateKnownColor (highlight.A, highlight.R, highlight.G, highlight.B, "Highlight", KnownColor.Highlight);
211 Color.UpdateKnownColor (highlight_text.A, highlight_text.R, highlight_text.G, highlight_text.B, "HighlightText", KnownColor.HighlightText);
212 Color.UpdateKnownColor (hot_track.A, hot_track.R, hot_track.G, hot_track.B, "HotTrack", KnownColor.HotTrack);
213 Color.UpdateKnownColor (inactive_border.A, inactive_border.R, inactive_border.G, inactive_border.B, "InactiveBorder", KnownColor.InactiveBorder);
214 Color.UpdateKnownColor (inactive_caption.A, inactive_caption.R, inactive_caption.G, inactive_caption.B, "InactiveCaption", KnownColor.InactiveCaption);
215 Color.UpdateKnownColor (inactive_caption_text.A, inactive_caption_text.R, inactive_caption_text.G, inactive_caption_text.B, "InactiveCaptionText", KnownColor.InactiveCaptionText);
216 Color.UpdateKnownColor (info.A, info.R, info.G, info.B, "Info", KnownColor.Info);
217 Color.UpdateKnownColor (info_text.A, info_text.R, info_text.G, info_text.B, "InfoText", KnownColor.InfoText);
218 Color.UpdateKnownColor (menu.A, menu.R, menu.G, menu.B, "Menu", KnownColor.Menu);
219 Color.UpdateKnownColor (menu_text.A, menu_text.R, menu_text.G, menu_text.B, "MenuText", KnownColor.MenuText);
220 Color.UpdateKnownColor (scroll_bar.A, scroll_bar.R, scroll_bar.G, scroll_bar.B, "ScrollBar", KnownColor.ScrollBar);
221 Color.UpdateKnownColor (window.A, window.R, window.G, window.B, "Window", KnownColor.Window);
222 Color.UpdateKnownColor (window_frame.A, window_frame.R, window_frame.G, window_frame.B, "WindowFrame", KnownColor.WindowFrame);
223 Color.UpdateKnownColor (window_text.A, window_text.R, window_text.G, window_text.B, "WindowText", KnownColor.WindowText);
226 static SystemColors () {
227 // If we're on a Win32 platform we should behave like MS and pull the colors
228 if (((int)Environment.OSVersion.Platform != 4) && ((int)Environment.OSVersion.Platform != 128)) {
229 active_border = GetSysColor(GetSysColorIndex.COLOR_ACTIVEBORDER, "ActiveBorder", KnownColor.ActiveBorder);
230 active_caption = GetSysColor(GetSysColorIndex.COLOR_ACTIVECAPTION, "ActiveCaption", KnownColor.ActiveCaption);
231 active_caption_text = GetSysColor(GetSysColorIndex.COLOR_CAPTIONTEXT, "ActiveCaptionText", KnownColor.ActiveCaptionText);
232 app_workspace = GetSysColor(GetSysColorIndex.COLOR_APPWORKSPACE, "AppWorkspace", KnownColor.AppWorkspace);
233 control = GetSysColor(GetSysColorIndex.COLOR_BTNFACE, "Control", KnownColor.Control);
234 control_dark = GetSysColor(GetSysColorIndex.COLOR_BTNSHADOW, "ControlDark", KnownColor.ControlDark);
235 control_dark_dark = GetSysColor(GetSysColorIndex.COLOR_3DDKSHADOW, "ControlDarkDark", KnownColor.ControlDarkDark);
236 control_light = GetSysColor(GetSysColorIndex.COLOR_3DLIGHT, "ControlLight", KnownColor.ControlLight);
237 control_light_light = GetSysColor(GetSysColorIndex.COLOR_BTNHIGHLIGHT, "ControlLightLight", KnownColor.ControlLightLight);
238 control_text = GetSysColor(GetSysColorIndex.COLOR_BTNTEXT, "ControlText", KnownColor.ControlText);
239 desktop = GetSysColor(GetSysColorIndex.COLOR_DESKTOP, "Desktop", KnownColor.Desktop);
240 gray_text = GetSysColor(GetSysColorIndex.COLOR_GRAYTEXT, "GrayText", KnownColor.GrayText);
241 highlight = GetSysColor(GetSysColorIndex.COLOR_HIGHLIGHT, "Highlight", KnownColor.Highlight);
242 highlight_text = GetSysColor(GetSysColorIndex.COLOR_HIGHLIGHTTEXT, "HighlightText", KnownColor.HighlightText);
243 hot_track = GetSysColor(GetSysColorIndex.COLOR_HOTLIGHT, "HotTrack", KnownColor.HotTrack);
244 inactive_border = GetSysColor(GetSysColorIndex.COLOR_INACTIVEBORDER, "InactiveBorder", KnownColor.InactiveBorder);
245 inactive_caption = GetSysColor(GetSysColorIndex.COLOR_INACTIVECAPTION, "InactiveCaption", KnownColor.InactiveCaption);
246 inactive_caption_text = GetSysColor(GetSysColorIndex.COLOR_INACTIVECAPTIONTEXT, "InactiveCaptionText", KnownColor.InactiveCaptionText);
247 info = GetSysColor(GetSysColorIndex.COLOR_INFOBK, "Info", KnownColor.Info);
248 info_text = GetSysColor(GetSysColorIndex.COLOR_INFOTEXT, "InfoText", KnownColor.InfoText);
249 menu = GetSysColor(GetSysColorIndex.COLOR_MENU, "Menu", KnownColor.Menu);
250 menu_text = GetSysColor(GetSysColorIndex.COLOR_MENUTEXT, "MenuText", KnownColor.MenuText);
251 scroll_bar = GetSysColor(GetSysColorIndex.COLOR_SCROLLBAR, "ScrollBar", KnownColor.ScrollBar);
252 window = GetSysColor(GetSysColorIndex.COLOR_WINDOW, "Window", KnownColor.Window);
253 window_frame = GetSysColor(GetSysColorIndex.COLOR_WINDOWFRAME, "WindowFrame", KnownColor.WindowFrame);
254 window_text = GetSysColor(GetSysColorIndex.COLOR_WINDOWTEXT, "WindowText", KnownColor.WindowText);
259 private SystemColors ()
263 static public Color ActiveBorder
266 return active_border;
270 static public Color ActiveCaption
273 return active_caption;
277 static public Color ActiveCaptionText
280 return active_caption_text;
284 static public Color AppWorkspace
287 return app_workspace;
291 static public Color Control
298 static public Color ControlDark
305 static public Color ControlDarkDark
308 return control_dark_dark;
312 static public Color ControlLight
315 return control_light;
319 static public Color ControlLightLight
322 return control_light_light;
326 static public Color ControlText
333 static public Color Desktop
340 static public Color GrayText
347 static public Color Highlight
354 static public Color HighlightText
357 return highlight_text;
361 static public Color HotTrack
368 static public Color InactiveBorder
371 return inactive_border;
375 static public Color InactiveCaption
378 return inactive_caption;
382 static public Color InactiveCaptionText
385 return inactive_caption_text;
389 static public Color Info
396 static public Color InfoText
403 static public Color Menu
410 static public Color MenuText
417 static public Color ScrollBar
424 static public Color Window
431 static public Color WindowFrame
438 static public Color WindowText
446 static public Color ButtonFace
453 static public Color ButtonHighlight
456 return button_highlight;
460 static public Color ButtonShadow
463 return button_shadow;
467 static public Color GradientActiveCaption
470 return gradient_activecaption;
474 static public Color GradientInactiveCaption
477 return gradient_inactivecaption;
481 static public Color MenuBar
488 static public Color MenuHighlight
491 return menu_highlight;