2010-07-25 Carlos Alberto Cortez <calberto.cortez@gmail.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms.Theming / ThemeElements.cs
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
8 //\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
11 //\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
19 //\r
20 // Copyright (c) 2007 Novell, Inc.\r
21 //\r
22 // Authors:\r
23 //      Jonathan Pobst (monkey@jpobst.com)\r
24 //      Everaldo Canuto  <ecanuto@novell.com>
25 \r
26 using System;\r
27 using System.Drawing;\r
28 using System.Reflection;\r
29 \r
30 namespace System.Windows.Forms.Theming\r
31 {\r
32         internal class ThemeElements\r
33         {\r
34                 private static ThemeElementsDefault theme;\r
35                 public static ThemeElementsDefault CurrentTheme {\r
36                         get { return theme; }\r
37                 }\r
38 \r
39                 static ThemeElements ()\r
40                 {\r
41                         string theme_var;\r
42 \r
43                         theme_var = Environment.GetEnvironmentVariable ("MONO_THEME");\r
44 \r
45                         if (theme_var == null)\r
46                                 theme_var = "win32";\r
47                         else\r
48                                 theme_var = theme_var.ToLower ();\r
49         \r
50                         theme = LoadTheme (theme_var);\r
51 \r
52                 }\r
53 \r
54                 private static ThemeElementsDefault LoadTheme (string themeName) \r
55                 {\r
56                         if (themeName == "visualstyles")\r
57                                 if (Application.VisualStylesEnabled)\r
58                                         return new ThemeElementsVisualStyles ();\r
59                                 else\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
65                         if (type != null) {\r
66                                 object o = ass.CreateInstance (type.FullName);\r
67                                 if (o != null)\r
68                                         return (ThemeElementsDefault) o;\r
69                         }\r
70                         return new ThemeElementsDefault ();\r
71                 }\r
72 \r
73                 #region Buttons\r
74                 public static void DrawButton (Graphics g, Rectangle bounds, ButtonThemeState state, Color backColor, Color foreColor)\r
75                 {\r
76                         theme.ButtonPainter.Draw (g, bounds, state, backColor, foreColor);\r
77                 }\r
78 \r
79                 public static void DrawFlatButton (Graphics g, Rectangle bounds, ButtonThemeState state, Color backColor, Color foreColor, FlatButtonAppearance appearance)\r
80                 {\r
81                         theme.ButtonPainter.DrawFlat (g, bounds, state, backColor, foreColor, appearance);\r
82                 }\r
83 \r
84                 public static void DrawPopupButton (Graphics g, Rectangle bounds, ButtonThemeState state, Color backColor, Color foreColor)\r
85                 {\r
86                         theme.ButtonPainter.DrawPopup (g, bounds, state, backColor, foreColor);\r
87                 }\r
88                 #endregion
89                 
90                 #region Painters
91
92                 public virtual Default.ButtonPainter ButtonPainter {\r
93                         get { return theme.ButtonPainter; }\r
94                 }\r
95
96                 public static Default.LabelPainter LabelPainter {
97                         get { return theme.LabelPainter; }
98                 }\r
99
100                 public static Default.LinkLabelPainter LinkLabelPainter {
101                         get { return theme.LinkLabelPainter; }
102                 }\r
103
104                 public virtual Default.TabControlPainter TabControlPainter {\r
105                         get { return theme.TabControlPainter; }\r
106                 }\r
107
108 #if NET_2_0\r
109                 public virtual Default.CheckBoxPainter CheckBoxPainter {\r
110                         get { return theme.CheckBoxPainter; }\r
111                 }\r
112 \r
113                 public virtual Default.RadioButtonPainter RadioButtonPainter {\r
114                         get { return theme.RadioButtonPainter; }\r
115                 }\r
116
117                 public virtual Default.ToolStripPainter ToolStripPainter {\r
118                         get { return theme.ToolStripPainter; }\r
119                 }\r
120 #endif\r
121
122                 #endregion\r
123         }\r
124 \r
125         #region Internal Enums\r
126         [Flags]\r
127         internal enum ButtonThemeState\r
128         {\r
129                 Normal = 1,\r
130                 Entered = 2,\r
131                 Pressed = 4,\r
132                 Disabled = 8,\r
133                 Default = 16\r
134         }\r
135 \r
136         internal enum ElementState\r
137         {\r
138                 Normal = 1,\r
139                 Hot = 2,\r
140                 Pressed = 3,\r
141                 Disabled = 4\r
142         }\r
143         #endregion\r
144 }