2006-08-04 Jonathan Pobst <monkey@jpobst.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms.VisualStyles / VisualStyleInformation.cs
1 //\r
2 // VisualStyleInformation.cs\r
3 //\r
4 // Permission is hereby granted, free of charge, to any person obtaining\r
5 // a copy of this software and associated documentation files (the\r
6 // "Software"), to deal in the Software without restriction, including\r
7 // without limitation the rights to use, copy, modify, merge, publish,\r
8 // distribute, sublicense, and/or sell copies of the Software, and to\r
9 // permit persons to whom the Software is furnished to do so, subject to\r
10 // the following conditions:\r
11 // \r
12 // The above copyright notice and this permission notice shall be\r
13 // included in all copies or substantial portions of the Software.\r
14 // \r
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
22 //\r
23 // Copyright (c) 2006 Novell, Inc.\r
24 //\r
25 // Authors:\r
26 //      Jonathan Pobst (monkey@jpobst.com)\r
27 //\r
28 \r
29 #if NET_2_0\r
30 using System.Drawing;\r
31 \r
32 namespace System.Windows.Forms.VisualStyles\r
33 {\r
34         public static class VisualStyleInformation\r
35         {\r
36                 #region Public Static Properties\r
37                 public static string Author {\r
38                         get {\r
39                                 if (!VisualStyleRenderer.IsSupported)\r
40                                         return string.Empty;\r
41 \r
42                                 return GetData ("AUTHOR");\r
43                         }\r
44                 }\r
45 \r
46                 public static string ColorScheme {\r
47                         get {\r
48                                 if (!VisualStyleRenderer.IsSupported)\r
49                                         return string.Empty;\r
50 \r
51                                 Text.StringBuilder ThemeName = new Text.StringBuilder (260);\r
52                                 Text.StringBuilder ColorName = new Text.StringBuilder (260);\r
53                                 Text.StringBuilder SizeName = new Text.StringBuilder (260);\r
54                                 UXTheme.GetCurrentThemeName (ThemeName, ThemeName.Capacity, ColorName, ColorName.Capacity, SizeName, SizeName.Capacity);\r
55 \r
56                                 return ColorName.ToString ();\r
57                         }\r
58                 }\r
59 \r
60                 public static string Company {\r
61                         get {\r
62                                 if (!VisualStyleRenderer.IsSupported)\r
63                                         return string.Empty;\r
64 \r
65                                 return GetData ("COMPANY");\r
66                         }\r
67                 }\r
68 \r
69                 [MonoTODO(@"Cannot get this to return the same as MS's...")]\r
70                 public static Color ControlHighlightHot {\r
71                         get {\r
72                                 if (!VisualStyleRenderer.IsSupported)\r
73                                         return SystemColors.ButtonHighlight;\r
74 \r
75                                 IntPtr theme = UXTheme.OpenThemeData (IntPtr.Zero, "BUTTON");\r
76 \r
77                                 uint retval = UXTheme.GetThemeSysColor (theme, 1621);\r
78                                 UXTheme.CloseThemeData (theme);\r
79 \r
80                                 return System.Drawing.Color.FromArgb ((int)(0x000000FFU & retval),\r
81                                         (int)(0x0000FF00U & retval) >> 8, (int)(0x00FF0000U & retval) >> 16);\r
82                         }\r
83                 }\r
84 \r
85                 public static string Copyright {\r
86                         get {\r
87                                 if (!VisualStyleRenderer.IsSupported)\r
88                                         return string.Empty;\r
89 \r
90                                 return GetData ("COPYRIGHT");\r
91                         }\r
92                 }\r
93 \r
94                 public static string Description {\r
95                         get {\r
96                                 if (!VisualStyleRenderer.IsSupported)\r
97                                         return string.Empty;\r
98 \r
99                                 return GetData ("DESCRIPTION");\r
100                         }\r
101                 }\r
102 \r
103                 public static string DisplayName {\r
104                         get {\r
105                                 if (!VisualStyleRenderer.IsSupported)\r
106                                         return string.Empty;\r
107 \r
108                                 return GetData ("DISPLAYNAME");\r
109                         }\r
110                 }\r
111 \r
112                 public static bool IsEnabledByUser {\r
113                         get {\r
114                                 if (!VisualStyleInformation.IsSupportedByOS) \r
115                                         return false;\r
116                                 \r
117                                 return (UXTheme.IsAppThemed () && UXTheme.IsThemeActive ());\r
118                         }\r
119                 }\r
120  \r
121                 public static bool IsSupportedByOS {\r
122                         get {\r
123                                 // Supported OS's should be NT based and at least XP (XP, 2003, Vista)\r
124                                 if ((Environment.OSVersion.Platform == PlatformID.Win32NT) && (Environment.OSVersion.Version >= new Version (5, 1))) \r
125                                         return true;\r
126                                 \r
127                                 return false;\r
128                         }\r
129                 }\r
130  \r
131                 public static int MinimumColorDepth {\r
132                         get {\r
133                                 if (!VisualStyleRenderer.IsSupported)\r
134                                         return 0;\r
135 \r
136                                 IntPtr theme = UXTheme.OpenThemeData (IntPtr.Zero, "BUTTON");\r
137                                 int retval;\r
138                                 \r
139                                 UXTheme.GetThemeSysInt (theme, 1301, out retval);\r
140                                 UXTheme.CloseThemeData (theme);\r
141 \r
142                                 return retval;\r
143                         }\r
144                 }\r
145 \r
146                 public static string Size {\r
147                         get {\r
148                                 if (!VisualStyleRenderer.IsSupported)\r
149                                         return string.Empty;\r
150 \r
151                                 Text.StringBuilder ThemeName = new Text.StringBuilder (260);\r
152                                 Text.StringBuilder ColorName = new Text.StringBuilder (260);\r
153                                 Text.StringBuilder SizeName = new Text.StringBuilder (260);\r
154                                 UXTheme.GetCurrentThemeName (ThemeName, ThemeName.Capacity, ColorName, ColorName.Capacity, SizeName, SizeName.Capacity);\r
155 \r
156                                 return SizeName.ToString ();\r
157                         }\r
158                 }\r
159 \r
160                 public static bool SupportsFlatMenus {\r
161                         get {\r
162                                 if (!VisualStyleRenderer.IsSupported)\r
163                                         return false;\r
164 \r
165                                 IntPtr theme = UXTheme.OpenThemeData (IntPtr.Zero, "BUTTON");\r
166                                 bool retval;\r
167 \r
168                                 retval = UXTheme.GetThemeSysBool (theme, 1001) == 0 ? false : true;\r
169                                 UXTheme.CloseThemeData (theme);\r
170 \r
171                                 return retval;\r
172                         }\r
173                 }\r
174 \r
175                 [MonoTODO(@"Cannot get this to return the same as MS's...")]\r
176                 public static Color TextControlBorder {\r
177                         get {\r
178                                 if (!VisualStyleRenderer.IsSupported)\r
179                                         return SystemColors.ControlDarkDark;\r
180 \r
181                                 IntPtr theme = UXTheme.OpenThemeData (IntPtr.Zero, "EDIT");\r
182 \r
183                                 uint retval = UXTheme.GetThemeSysColor (theme, 1611);\r
184                                 UXTheme.CloseThemeData (theme);\r
185 \r
186                                 return System.Drawing.Color.FromArgb ((int)(0x000000FFU & retval),\r
187                                                      (int)(0x0000FF00U & retval) >> 8, (int)(0x00FF0000U & retval) >> 16);\r
188                         }\r
189                 }\r
190 \r
191                 public static string Url {\r
192                         get {\r
193                                 if (!VisualStyleRenderer.IsSupported)\r
194                                         return string.Empty;\r
195 \r
196                                 return GetData ("URL");\r
197                         }\r
198                 }\r
199 \r
200                 public static string Version {\r
201                         get {\r
202                                 if (!VisualStyleRenderer.IsSupported)\r
203                                         return string.Empty;\r
204 \r
205                                 return GetData ("VERSION");\r
206                         }\r
207                 }\r
208                 #endregion\r
209                 \r
210                 #region Internal Helper Methods\r
211                 internal static string GetData (string propertyName)\r
212                 {\r
213                         Text.StringBuilder ThemeName = new Text.StringBuilder (260);\r
214                         Text.StringBuilder ColorName = new Text.StringBuilder (260);\r
215                         Text.StringBuilder SizeName = new Text.StringBuilder (260);\r
216 \r
217                         UXTheme.GetCurrentThemeName (ThemeName, ThemeName.Capacity, ColorName, ColorName.Capacity, SizeName, SizeName.Capacity);\r
218 \r
219                         Text.StringBuilder PropertyValue = new Text.StringBuilder (260);\r
220 \r
221                         UXTheme.GetThemeDocumentationProperty (ThemeName.ToString(), propertyName, PropertyValue, PropertyValue.Capacity);\r
222 \r
223                         return PropertyValue.ToString ();\r
224                 }\r
225                 #endregion\r
226         }\r
227 }\r
228 #endif