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