2 // VisualStyleInformation.cs
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:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
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.
23 // Copyright (c) 2006 Novell, Inc.
26 // Jonathan Pobst (monkey@jpobst.com)
32 namespace System.Windows.Forms.VisualStyles
34 public static class VisualStyleInformation
36 #region Public Static Properties
37 public static string Author {
39 if (!VisualStyleRenderer.IsSupported)
42 return GetData ("AUTHOR");
46 public static string ColorScheme {
48 if (!VisualStyleRenderer.IsSupported)
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);
56 return ColorName.ToString ();
60 public static string Company {
62 if (!VisualStyleRenderer.IsSupported)
65 return GetData ("COMPANY");
69 [MonoTODO(@"Cannot get this to return the same as MS's...")]
70 public static Color ControlHighlightHot {
72 if (!VisualStyleRenderer.IsSupported)
73 return SystemColors.ButtonHighlight;
75 IntPtr theme = UXTheme.OpenThemeData (IntPtr.Zero, "BUTTON");
77 uint retval = UXTheme.GetThemeSysColor (theme, 1621);
78 UXTheme.CloseThemeData (theme);
80 return System.Drawing.Color.FromArgb ((int)(0x000000FFU & retval),
81 (int)(0x0000FF00U & retval) >> 8, (int)(0x00FF0000U & retval) >> 16);
85 public static string Copyright {
87 if (!VisualStyleRenderer.IsSupported)
90 return GetData ("COPYRIGHT");
94 public static string Description {
96 if (!VisualStyleRenderer.IsSupported)
99 return GetData ("DESCRIPTION");
103 public static string DisplayName {
105 if (!VisualStyleRenderer.IsSupported)
108 return GetData ("DISPLAYNAME");
112 public static bool IsEnabledByUser {
114 if (!VisualStyleInformation.IsSupportedByOS)
117 return (UXTheme.IsAppThemed () && UXTheme.IsThemeActive ());
121 public static bool IsSupportedByOS {
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)))
131 public static int MinimumColorDepth {
133 if (!VisualStyleRenderer.IsSupported)
136 IntPtr theme = UXTheme.OpenThemeData (IntPtr.Zero, "BUTTON");
139 UXTheme.GetThemeSysInt (theme, 1301, out retval);
140 UXTheme.CloseThemeData (theme);
146 public static string Size {
148 if (!VisualStyleRenderer.IsSupported)
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);
156 return SizeName.ToString ();
160 public static bool SupportsFlatMenus {
162 if (!VisualStyleRenderer.IsSupported)
165 IntPtr theme = UXTheme.OpenThemeData (IntPtr.Zero, "BUTTON");
168 retval = UXTheme.GetThemeSysBool (theme, 1001) == 0 ? false : true;
169 UXTheme.CloseThemeData (theme);
175 [MonoTODO(@"Cannot get this to return the same as MS's...")]
176 public static Color TextControlBorder {
178 if (!VisualStyleRenderer.IsSupported)
179 return SystemColors.ControlDarkDark;
181 IntPtr theme = UXTheme.OpenThemeData (IntPtr.Zero, "EDIT");
183 uint retval = UXTheme.GetThemeSysColor (theme, 1611);
184 UXTheme.CloseThemeData (theme);
186 return System.Drawing.Color.FromArgb ((int)(0x000000FFU & retval),
187 (int)(0x0000FF00U & retval) >> 8, (int)(0x00FF0000U & retval) >> 16);
191 public static string Url {
193 if (!VisualStyleRenderer.IsSupported)
196 return GetData ("URL");
200 public static string Version {
202 if (!VisualStyleRenderer.IsSupported)
205 return GetData ("VERSION");
210 #region Internal Helper Methods
211 internal static string GetData (string propertyName)
213 Text.StringBuilder ThemeName = new Text.StringBuilder (260);
214 Text.StringBuilder ColorName = new Text.StringBuilder (260);
215 Text.StringBuilder SizeName = new Text.StringBuilder (260);
217 UXTheme.GetCurrentThemeName (ThemeName, ThemeName.Capacity, ColorName, ColorName.Capacity, SizeName, SizeName.Capacity);
219 Text.StringBuilder PropertyValue = new Text.StringBuilder (260);
221 UXTheme.GetThemeDocumentationProperty (ThemeName.ToString(), propertyName, PropertyValue, PropertyValue.Capacity);
223 return PropertyValue.ToString ();