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