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