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