2005-10-07 Peter Dennis Bartok <pbartok@novell.com>
[mono.git] / mcs / class / System.Drawing / System.Drawing / SystemColors.cs
1 //
2 // System.Drawing.SystemColors.cs
3 //
4 // Copyright (C) 2002 Ximian, Inc (http://www.ximian.com)
5 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
6 //
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:
14 // 
15 // The above copyright notice and this permission notice shall be
16 // included in all copies or substantial portions of the Software.
17 // 
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.
25 //
26 // Authors:
27 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
28 //      Peter Dennis Bartok (pbartok@novell.com)
29 //
30
31
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
37 //                      continue;\r
38 //\r
39 //              MethodInfo getget = prop.GetGetMethod ();\r
40 //              if (getget == null || getget.IsStatic == false)\r
41 //                      continue;\r
42 //\r
43 //              object o = prop.GetValue (null, null);\r
44 //\r
45 //              Color c = (Color) o;\r
46 //\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
53 //                      }\r
54 //              }\r
55 //\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
63 //      }\r
64 //}\r
65
66
67 using System;
68 using System.Reflection;
69 using System.Runtime.InteropServices;
70
71 namespace System.Drawing {
72         public sealed class SystemColors
73         {
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);\r
103
104 #if old
105                 static private Color active_border = Color.FromArgbSystem (255, 131, 153, 177, "ActiveBorder", KnownColor.ActiveBorder);
106                 static private Color active_caption = Color.FromArgbSystem (255, 79, 101, 125, "ActiveCaption", KnownColor.ActiveCaption);
107                 static private Color active_caption_text = Color.FromArgbSystem (255, 255, 255, 255, "ActiveCaptionText", KnownColor.ActiveCaptionText);
108                 static private Color app_workspace = Color.FromArgbSystem (255, 128, 128, 128, "AppWorkspace", KnownColor.AppWorkspace);
109                 static private Color control = Color.FromArgbSystem (255, 192, 192, 192, "Control", KnownColor.Control);
110                 static private Color control_dark = Color.FromArgbSystem (255, 79, 101, 125, "ControlDark", KnownColor.ControlDark);
111                 static private Color control_dark_dark = Color.FromArgbSystem (255, 0, 0, 0, "ControlDarkDark", KnownColor.ControlDarkDark);
112                 static private Color control_light = Color.FromArgbSystem (255, 131, 153, 177, "ControlLight", KnownColor.ControlLight);
113                 static private Color control_light_light = Color.FromArgbSystem (255, 193, 204, 217, "ControlLightLight", KnownColor.ControlLightLight);
114                 static private Color control_text = Color.FromArgbSystem (255, 0, 0, 0, "ControlText", KnownColor.ControlText);
115                 static private Color desktop = Color.FromArgbSystem (255, 0, 0, 0, "Desktop", KnownColor.Desktop);
116                 static private Color gray_text = Color.FromArgbSystem (255, 79, 101, 125, "GrayText", KnownColor.GrayText);
117                 static private Color highlight = Color.FromArgbSystem (255, 0, 0, 128, "Highlight", KnownColor.Highlight);
118                 static private Color highlight_text = Color.FromArgbSystem (255, 255, 255, 255, "HighlightText", KnownColor.HighlightText);
119                 static private Color hot_track = Color.FromArgbSystem (255, 0, 0, 255, "HotTrack", KnownColor.HotTrack);
120                 static private Color inactive_border = Color.FromArgbSystem (255, 131, 153, 177, "InactiveBorder", KnownColor.InactiveBorder);
121                 static private Color inactive_caption = Color.FromArgbSystem (255, 128, 128, 128, "InactiveCaption", KnownColor.InactiveCaption);
122                 static private Color inactive_caption_text = Color.FromArgbSystem (255, 193, 204, 217, "InactiveCaptionText", KnownColor.InactiveCaptionText);
123                 static private Color info = Color.FromArgbSystem (255, 255, 255, 255, "Info", KnownColor.Info);
124                 static private Color info_text = Color.FromArgbSystem (255, 0, 0, 0, "InfoText", KnownColor.InfoText);
125                 static private Color menu = Color.FromArgbSystem (255, 131, 153, 177, "Menu", KnownColor.Menu);
126                 static private Color menu_text = Color.FromArgbSystem (255, 0, 0, 0, "MenuText", KnownColor.MenuText);
127                 static private Color scroll_bar = Color.FromArgbSystem (255, 193, 204, 217, "ScrollBar", KnownColor.ScrollBar);
128                 static private Color window = Color.FromArgbSystem (255, 255, 255, 255, "Window", KnownColor.Window);
129                 static private Color window_frame = Color.FromArgbSystem (255, 0, 0, 0, "WindowFrame", KnownColor.WindowFrame);
130                 static private Color window_text = Color.FromArgbSystem (255, 0, 0, 0, "WindowText", KnownColor.WindowText);
131 #endif
132                 private enum GetSysColorIndex {
133                         COLOR_SCROLLBAR                 = 0,
134                         COLOR_BACKGROUND                = 1,
135                         COLOR_ACTIVECAPTION             = 2,
136                         COLOR_INACTIVECAPTION           = 3,
137                         COLOR_MENU                      = 4,
138                         COLOR_WINDOW                    = 5,
139                         COLOR_WINDOWFRAME               = 6,
140                         COLOR_MENUTEXT                  = 7,
141                         COLOR_WINDOWTEXT                = 8,
142                         COLOR_CAPTIONTEXT               = 9,
143                         COLOR_ACTIVEBORDER              = 10,
144                         COLOR_INACTIVEBORDER            = 11,
145                         COLOR_APPWORKSPACE              = 12,
146                         COLOR_HIGHLIGHT                 = 13,
147                         COLOR_HIGHLIGHTTEXT             = 14,
148                         COLOR_BTNFACE                   = 15,
149                         COLOR_BTNSHADOW                 = 16,
150                         COLOR_GRAYTEXT                  = 17,
151                         COLOR_BTNTEXT                   = 18,
152                         COLOR_INACTIVECAPTIONTEXT       = 19,
153                         COLOR_BTNHIGHLIGHT              = 20,
154                         COLOR_3DDKSHADOW                = 21,
155                         COLOR_3DLIGHT                   = 22,
156                         COLOR_INFOTEXT                  = 23,
157                         COLOR_INFOBK                    = 24,
158                         
159                         COLOR_HOTLIGHT                  = 26,
160                         COLOR_GRADIENTACTIVECAPTION     = 27,
161                         COLOR_GRADIENTINACTIVECAPTION   = 28,
162                         COLOR_MENUHIGHLIGHT             = 29,
163                         COLOR_MENUBAR                   = 30,
164
165                         COLOR_DESKTOP                   = 1,
166                         COLOR_3DFACE                    = 16,
167                         COLOR_3DSHADOW                  = 16,
168                         COLOR_3DHIGHLIGHT               = 20,
169                         COLOR_3DHILIGHT                 = 20,
170                         COLOR_BTNHILIGHT                = 20,
171
172                         COLOR_MAXVALUE                  = 30,/* Maximum value */
173                 }       
174
175                 [DllImport ("user32.dll", EntryPoint="GetSysColor", CallingConvention=CallingConvention.StdCall)]
176                 private extern static uint Win32GetSysColor(GetSysColorIndex index);
177
178                 private static Color GetSysColor(GetSysColorIndex index) {
179                         uint color;
180
181                         color = Win32GetSysColor(index);
182
183                         return Color.FromArgb((byte)(color & 0xff), (byte)((color >> 8) & 0xff), (byte)((color >> 16) & 0xff));
184                 }
185
186                 // When this method is called, we teach any new color(s) to the Color class
187                 private static void UpdateColors() {
188                         Color.UpdateKnownColor (active_border.A, active_border.R, active_border.G, active_border.B, "ActiveBorder", KnownColor.ActiveBorder);
189                         Color.UpdateKnownColor (active_caption.A, active_caption.R, active_caption.G, active_caption.B, "ActiveCaption", KnownColor.ActiveCaption);
190                         Color.UpdateKnownColor (active_caption_text.A, active_caption_text.R, active_caption_text.G, active_caption_text.B, "ActiveCaptionText", KnownColor.ActiveCaptionText);
191                         Color.UpdateKnownColor (app_workspace.A, app_workspace.R, app_workspace.G, app_workspace.B, "AppWorkspace", KnownColor.AppWorkspace);
192                         Color.UpdateKnownColor (control.A, control.R, control.G, control.B, "Control", KnownColor.Control);
193                         Color.UpdateKnownColor (control_dark.A, control_dark.R, control_dark.G, control_dark.B, "ControlDark", KnownColor.ControlDark);
194                         Color.UpdateKnownColor (control_dark_dark.A, control_dark_dark.R, control_dark_dark.G, control_dark_dark.B, "ControlDarkDark", KnownColor.ControlDarkDark);
195                         Color.UpdateKnownColor (control_light.A, control_light.R, control_light.G, control_light.B, "ControlLight", KnownColor.ControlLight);
196                         Color.UpdateKnownColor (control_light_light.A, control_light_light.R, control_light_light.G, control_light_light.B, "ControlLightLight", KnownColor.ControlLightLight);
197                         Color.UpdateKnownColor (control_text.A, control_text.R, control_text.G, control_text.B, "ControlText", KnownColor.ControlText);
198                         Color.UpdateKnownColor (desktop.A, desktop.R, desktop.G, desktop.B, "Desktop", KnownColor.Desktop);
199                         Color.UpdateKnownColor (gray_text.A, gray_text.R, gray_text.G, gray_text.B, "GrayText", KnownColor.GrayText);
200                         Color.UpdateKnownColor (highlight.A, highlight.R, highlight.G, highlight.B, "Highlight", KnownColor.Highlight);
201                         Color.UpdateKnownColor (highlight_text.A, highlight_text.R, highlight_text.G, highlight_text.B, "HighlightText", KnownColor.HighlightText);
202                         Color.UpdateKnownColor (hot_track.A, hot_track.R, hot_track.G, hot_track.B, "HotTrack", KnownColor.HotTrack);
203                         Color.UpdateKnownColor (inactive_border.A, inactive_border.R, inactive_border.G, inactive_border.B, "InactiveBorder", KnownColor.InactiveBorder);
204                         Color.UpdateKnownColor (inactive_caption.A, inactive_caption.R, inactive_caption.G, inactive_caption.B, "InactiveCaption", KnownColor.InactiveCaption);
205                         Color.UpdateKnownColor (inactive_caption_text.A, inactive_caption_text.R, inactive_caption_text.G, inactive_caption_text.B, "InactiveCaptionText", KnownColor.InactiveCaptionText);
206                         Color.UpdateKnownColor (info.A, info.R, info.G, info.B, "Info", KnownColor.Info);
207                         Color.UpdateKnownColor (info_text.A, info_text.R, info_text.G, info_text.B, "InfoText", KnownColor.InfoText);
208                         Color.UpdateKnownColor (menu.A, menu.R, menu.G, menu.B, "Menu", KnownColor.Menu);
209                         Color.UpdateKnownColor (menu_text.A, menu_text.R, menu_text.G, menu_text.B, "MenuText", KnownColor.MenuText);
210                         Color.UpdateKnownColor (scroll_bar.A, scroll_bar.R, scroll_bar.G, scroll_bar.B, "ScrollBar", KnownColor.ScrollBar);
211                         Color.UpdateKnownColor (window.A, window.R, window.G, window.B, "Window", KnownColor.Window);
212                         Color.UpdateKnownColor (window_frame.A, window_frame.R, window_frame.G, window_frame.B, "WindowFrame", KnownColor.WindowFrame);
213                         Color.UpdateKnownColor (window_text.A, window_text.R, window_text.G, window_text.B, "WindowText", KnownColor.WindowText);
214                 }
215
216                 static SystemColors () {
217                         // If we're on a Win32 platform we should behave like MS and pull the colors
218                         if (((int)Environment.OSVersion.Platform != 4) && ((int)Environment.OSVersion.Platform != 128)) {
219                                 active_border = GetSysColor(GetSysColorIndex.COLOR_ACTIVEBORDER);
220                                 active_caption = GetSysColor(GetSysColorIndex.COLOR_ACTIVECAPTION);
221                                 active_caption_text = GetSysColor(GetSysColorIndex.COLOR_CAPTIONTEXT);
222                                 app_workspace = GetSysColor(GetSysColorIndex.COLOR_APPWORKSPACE);
223                                 control = GetSysColor(GetSysColorIndex.COLOR_BTNFACE);
224                                 control_dark = GetSysColor(GetSysColorIndex.COLOR_BTNSHADOW);
225                                 control_dark_dark = GetSysColor(GetSysColorIndex.COLOR_3DDKSHADOW);
226                                 control_light = GetSysColor(GetSysColorIndex.COLOR_BTNHIGHLIGHT);
227                                 control_light_light = GetSysColor(GetSysColorIndex.COLOR_3DLIGHT);
228                                 control_text = GetSysColor(GetSysColorIndex.COLOR_BTNTEXT);
229                                 desktop = GetSysColor(GetSysColorIndex.COLOR_DESKTOP);
230                                 gray_text = GetSysColor(GetSysColorIndex.COLOR_GRAYTEXT);
231                                 highlight = GetSysColor(GetSysColorIndex.COLOR_HIGHLIGHT);
232                                 highlight_text = GetSysColor(GetSysColorIndex.COLOR_HIGHLIGHTTEXT);
233                                 hot_track = GetSysColor(GetSysColorIndex.COLOR_HOTLIGHT);
234                                 inactive_border = GetSysColor(GetSysColorIndex.COLOR_INACTIVEBORDER);
235                                 inactive_caption = GetSysColor(GetSysColorIndex.COLOR_INACTIVECAPTION);
236                                 inactive_caption_text = GetSysColor(GetSysColorIndex.COLOR_INACTIVECAPTIONTEXT);
237                                 info = GetSysColor(GetSysColorIndex.COLOR_INFOBK);
238                                 info_text = GetSysColor(GetSysColorIndex.COLOR_INFOTEXT);
239                                 menu = GetSysColor(GetSysColorIndex.COLOR_MENU);
240                                 menu_text = GetSysColor(GetSysColorIndex.COLOR_MENUTEXT);
241                                 scroll_bar = GetSysColor(GetSysColorIndex.COLOR_SCROLLBAR);
242                                 window = GetSysColor(GetSysColorIndex.COLOR_WINDOW);
243                                 window_frame = GetSysColor(GetSysColorIndex.COLOR_WINDOWFRAME);
244                                 window_text = GetSysColor(GetSysColorIndex.COLOR_WINDOWTEXT);
245                         }
246                 }
247
248
249                 private SystemColors ()
250                 {
251                 }
252
253                 static public Color ActiveBorder
254                 {       
255                         get {
256                                 return active_border;
257                         }
258                 }
259
260                 static public Color ActiveCaption
261                 {       
262                         get {
263                                 return active_caption;
264                         }
265                 }
266
267                 static public Color ActiveCaptionText
268                 {       
269                         get {
270                                 return active_caption_text;
271                         }
272                 }
273
274                 static public Color AppWorkspace
275                 {       
276                         get {
277                                 return app_workspace;
278                         }
279                 }
280
281                 static public Color Control
282                 {       
283                         get {
284                                 return control;
285                         }
286                 }
287
288                 static public Color ControlDark
289                 {       
290                         get {
291                                 return control_dark;
292                         }
293                 }
294
295                 static public Color ControlDarkDark
296                 {       
297                         get {
298                                 return control_dark_dark;
299                         }
300                 }
301
302                 static public Color ControlLight
303                 {       
304                         get {
305                                 return control_light;
306                         }
307                 }
308
309                 static public Color ControlLightLight
310                 {       
311                         get {
312                                 return control_light_light;
313                         }
314                 }
315
316                 static public Color ControlText
317                 {       
318                         get {
319                                 return control_text;
320                         }
321                 }
322
323                 static public Color Desktop
324                 {       
325                         get {
326                                 return desktop;
327                         }
328                 }
329
330                 static public Color GrayText
331                 {       
332                         get {
333                                 return gray_text;
334                         }
335                 }
336
337                 static public Color Highlight
338                 {       
339                         get {
340                                 return highlight;
341                         }
342                 }
343
344                 static public Color HighlightText
345                 {       
346                         get {
347                                 return highlight_text;
348                         }
349                 }
350
351                 static public Color HotTrack
352                 {       
353                         get {
354                                 return hot_track;
355                         }
356                 }
357
358                 static public Color InactiveBorder
359                 {       
360                         get {
361                                 return inactive_border;
362                         }
363                 }
364
365                 static public Color InactiveCaption
366                 {       
367                         get {
368                                 return inactive_caption;
369                         }
370                 }
371
372                 static public Color InactiveCaptionText
373                 {       
374                         get {
375                                 return inactive_caption_text;
376                         }
377                 }
378
379                 static public Color Info
380                 {       
381                         get {
382                                 return info;
383                         }
384                 }
385
386                 static public Color InfoText
387                 {       
388                         get {
389                                 return info_text;
390                         }
391                 }
392
393                 static public Color Menu
394                 {       
395                         get {
396                                 return menu;
397                         }
398                 }
399
400                 static public Color MenuText
401                 {       
402                         get {
403                                 return menu_text;
404                         }
405                 }
406
407                 static public Color ScrollBar
408                 {       
409                         get {
410                                 return scroll_bar;
411                         }
412                 }
413
414                 static public Color Window
415                 {       
416                         get {
417                                 return window;
418                         }
419                 }
420
421                 static public Color WindowFrame
422                 {       
423                         get {
424                                 return window_frame;
425                         }
426                 }
427
428                 static public Color WindowText
429                 {       
430                         get {
431                                 return window_text;
432                         }
433                 }
434         }
435 }
436