ThemeElements.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 ([email protected])
  24. // Everaldo Canuto <[email protected]>
  25. using System;
  26. using System.Drawing;
  27. using System.Reflection;
  28. namespace System.Windows.Forms.Theming
  29. {
  30. internal class ThemeElements
  31. {
  32. private static ThemeElementsDefault theme;
  33. public static ThemeElementsDefault CurrentTheme {
  34. get { return theme; }
  35. }
  36. static ThemeElements ()
  37. {
  38. string theme_var;
  39. theme_var = Environment.GetEnvironmentVariable ("MONO_THEME");
  40. if (theme_var == null)
  41. theme_var = "win32";
  42. else
  43. theme_var = theme_var.ToLower ();
  44. theme = LoadTheme (theme_var);
  45. }
  46. private static ThemeElementsDefault LoadTheme (string themeName)
  47. {
  48. if (themeName == "visualstyles")
  49. if (Application.VisualStylesEnabled)
  50. return new ThemeElementsVisualStyles ();
  51. else
  52. return new ThemeElementsDefault ();
  53. Assembly ass = Assembly.GetExecutingAssembly ();
  54. string iname = typeof(ThemeElements).FullName;
  55. string assemblyname = iname + themeName;
  56. Type type = ass.GetType (assemblyname, false, true);
  57. if (type != null) {
  58. object o = ass.CreateInstance (type.FullName);
  59. if (o != null)
  60. return (ThemeElementsDefault) o;
  61. }
  62. return new ThemeElementsDefault ();
  63. }
  64. #region Buttons
  65. public static void DrawButton (Graphics g, Rectangle bounds, ButtonThemeState state, Color backColor, Color foreColor)
  66. {
  67. theme.ButtonPainter.Draw (g, bounds, state, backColor, foreColor);
  68. }
  69. public static void DrawFlatButton (Graphics g, Rectangle bounds, ButtonThemeState state, Color backColor, Color foreColor, FlatButtonAppearance appearance)
  70. {
  71. theme.ButtonPainter.DrawFlat (g, bounds, state, backColor, foreColor, appearance);
  72. }
  73. public static void DrawPopupButton (Graphics g, Rectangle bounds, ButtonThemeState state, Color backColor, Color foreColor)
  74. {
  75. theme.ButtonPainter.DrawPopup (g, bounds, state, backColor, foreColor);
  76. }
  77. #endregion
  78. #region Painters
  79. public virtual Default.ButtonPainter ButtonPainter {
  80. get { return theme.ButtonPainter; }
  81. }
  82. public static Default.LabelPainter LabelPainter {
  83. get { return theme.LabelPainter; }
  84. }
  85. public static Default.LinkLabelPainter LinkLabelPainter {
  86. get { return theme.LinkLabelPainter; }
  87. }
  88. public virtual Default.TabControlPainter TabControlPainter {
  89. get { return theme.TabControlPainter; }
  90. }
  91. public virtual Default.CheckBoxPainter CheckBoxPainter {
  92. get { return theme.CheckBoxPainter; }
  93. }
  94. public virtual Default.RadioButtonPainter RadioButtonPainter {
  95. get { return theme.RadioButtonPainter; }
  96. }
  97. public virtual Default.ToolStripPainter ToolStripPainter {
  98. get { return theme.ToolStripPainter; }
  99. }
  100. #endregion
  101. }
  102. #region Internal Enums
  103. [Flags]
  104. internal enum ButtonThemeState
  105. {
  106. Normal = 1,
  107. Entered = 2,
  108. Pressed = 4,
  109. Disabled = 8,
  110. Default = 16
  111. }
  112. internal enum ElementState
  113. {
  114. Normal = 1,
  115. Hot = 2,
  116. Pressed = 3,
  117. Disabled = 4
  118. }
  119. #endregion
  120. }