disable broken tests on net_4_0
[mcs.git] / class / Managed.Windows.Forms / System.Windows.Forms.Theming / ThemeElements.cs
blobde33265af672f004a56045b3467ed61a75fc63a7
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 //
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2007 Novell, Inc.
22 // Authors:
23 // Jonathan Pobst (monkey@jpobst.com)
24 // Everaldo Canuto <ecanuto@novell.com>
26 using System;
27 using System.Drawing;
28 using System.Reflection;
30 namespace System.Windows.Forms.Theming
32 internal class ThemeElements
34 private static ThemeElementsDefault theme;
35 public static ThemeElementsDefault CurrentTheme {
36 get { return theme; }
39 static ThemeElements ()
41 string theme_var;
43 theme_var = Environment.GetEnvironmentVariable ("MONO_THEME");
45 if (theme_var == null)
46 theme_var = "win32";
47 else
48 theme_var = theme_var.ToLower ();
50 theme = LoadTheme (theme_var);
54 private static ThemeElementsDefault LoadTheme (string themeName)
56 if (themeName == "visualstyles")
57 if (Application.VisualStylesEnabled)
58 return new ThemeElementsVisualStyles ();
59 else
60 return new ThemeElementsDefault ();
61 Assembly ass = Assembly.GetExecutingAssembly ();
62 string iname = typeof(ThemeElements).FullName;
63 string assemblyname = iname + themeName;
64 Type type = ass.GetType (assemblyname, false, true);
65 if (type != null) {
66 object o = ass.CreateInstance (type.FullName);
67 if (o != null)
68 return (ThemeElementsDefault) o;
70 return new ThemeElementsDefault ();
73 #region Buttons
74 public static void DrawButton (Graphics g, Rectangle bounds, ButtonThemeState state, Color backColor, Color foreColor)
76 theme.ButtonPainter.Draw (g, bounds, state, backColor, foreColor);
79 public static void DrawFlatButton (Graphics g, Rectangle bounds, ButtonThemeState state, Color backColor, Color foreColor, FlatButtonAppearance appearance)
81 theme.ButtonPainter.DrawFlat (g, bounds, state, backColor, foreColor, appearance);
84 public static void DrawPopupButton (Graphics g, Rectangle bounds, ButtonThemeState state, Color backColor, Color foreColor)
86 theme.ButtonPainter.DrawPopup (g, bounds, state, backColor, foreColor);
88 #endregion
90 #region Painters
92 public virtual Default.ButtonPainter ButtonPainter {
93 get { return theme.ButtonPainter; }
96 public static Default.LabelPainter LabelPainter {
97 get { return theme.LabelPainter; }
100 public static Default.LinkLabelPainter LinkLabelPainter {
101 get { return theme.LinkLabelPainter; }
104 public virtual Default.TabControlPainter TabControlPainter {
105 get { return theme.TabControlPainter; }
108 #if NET_2_0
109 public virtual Default.CheckBoxPainter CheckBoxPainter {
110 get { return theme.CheckBoxPainter; }
113 public virtual Default.RadioButtonPainter RadioButtonPainter {
114 get { return theme.RadioButtonPainter; }
117 public virtual Default.ToolStripPainter ToolStripPainter {
118 get { return theme.ToolStripPainter; }
120 #endif
122 #endregion
125 #region Internal Enums
126 [Flags]
127 internal enum ButtonThemeState
129 Normal = 1,
130 Entered = 2,
131 Pressed = 4,
132 Disabled = 8,
133 Default = 16
136 internal enum ElementState
138 Normal = 1,
139 Hot = 2,
140 Pressed = 3,
141 Disabled = 4
143 #endregion