Theme.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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) 2004 Novell, Inc.
  21. //
  22. // Authors:
  23. // Jordi Mas i Hernandez, [email protected]
  24. //
  25. //
  26. // $Revision: 1.8 $
  27. // $Modtime: $
  28. // $Log: Theme.cs,v $
  29. // Revision 1.8 2004/09/07 17:12:26 jordi
  30. // GroupBox control
  31. //
  32. // Revision 1.7 2004/09/07 09:40:15 jordi
  33. // LinkLabel fixes, methods, multiple links
  34. //
  35. // Revision 1.6 2004/09/02 16:32:54 jordi
  36. // implements resource pool for pens, brushes, and hatchbruses
  37. //
  38. // Revision 1.5 2004/08/25 20:04:40 ravindra
  39. // Added the missing divider code and grip for ToolBar Control.
  40. //
  41. // Revision 1.4 2004/08/24 18:37:02 jordi
  42. // fixes formmating, methods signature, and adds missing events
  43. //
  44. // Revision 1.3 2004/08/24 16:16:46 jackson
  45. // Handle drawing picture boxes in the theme now. Draw picture box borders and obey sizing modes
  46. //
  47. // Revision 1.2 2004/08/20 00:12:51 jordi
  48. // fixes methods signature
  49. //
  50. // Revision 1.1 2004/08/19 22:26:30 jordi
  51. // move themes from an interface to a class
  52. //
  53. //
  54. using System.Drawing;
  55. using System.Drawing.Drawing2D;
  56. using System.Drawing.Imaging;
  57. using System.Collections;
  58. namespace System.Windows.Forms
  59. {
  60. // Implements a pool of system resources
  61. internal class SystemResPool
  62. {
  63. private Hashtable pens = new Hashtable ();
  64. private Hashtable solidbrushes = new Hashtable ();
  65. private Hashtable hatchbrushes = new Hashtable ();
  66. public SystemResPool () {}
  67. public Pen GetPen (Color color)
  68. {
  69. string hash = color.ToString();
  70. if (pens.Contains (hash))
  71. return (Pen) pens[hash];
  72. Pen pen = new Pen (color);
  73. pens.Add (hash, pen);
  74. return pen;
  75. }
  76. public SolidBrush GetSolidBrush (Color color)
  77. {
  78. string hash = color.ToString ();
  79. if (solidbrushes.Contains (hash))
  80. return (SolidBrush) solidbrushes[hash];
  81. SolidBrush brush = new SolidBrush (color);
  82. solidbrushes.Add (hash, brush);
  83. return brush;
  84. }
  85. public HatchBrush GetHatchBrush (HatchStyle hatchStyle, Color foreColor, Color backColor)
  86. {
  87. string hash = hatchStyle.ToString () + foreColor.ToString () + backColor.ToString ();
  88. if (hatchbrushes.Contains (hash))
  89. return (HatchBrush) hatchbrushes[hash];
  90. HatchBrush brush = new HatchBrush (hatchStyle, foreColor, backColor);
  91. hatchbrushes.Add (hash, brush);
  92. return brush;
  93. }
  94. }
  95. internal abstract class Theme
  96. {
  97. protected Array syscolors;
  98. protected Font default_font;
  99. protected Color defaultWindowBackColor;
  100. protected Color defaultWindowForeColor;
  101. static protected SystemResPool ResPool = new SystemResPool ();
  102. /* Default properties */
  103. public virtual Color ColorScrollbar {
  104. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_SCROLLBAR);}
  105. }
  106. public virtual Color ColorBackground {
  107. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_BACKGROUND);}
  108. }
  109. public virtual Color ColorActiveTitle {
  110. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_ACTIVECAPTION);}
  111. }
  112. public virtual Color ColorInactiveTitle {
  113. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_INACTIVECAPTION);}
  114. }
  115. public virtual Color ColorMenu {
  116. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_MENU);}
  117. }
  118. public virtual Color ColorWindow {
  119. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_WINDOW);}
  120. }
  121. public virtual Color ColorWindowFrame {
  122. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_WINDOWFRAME);}
  123. }
  124. public virtual Color ColorMenuText {
  125. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_MENUTEXT);}
  126. }
  127. public virtual Color ColorWindowText {
  128. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_WINDOWTEXT);}
  129. }
  130. public virtual Color ColorTitleText {
  131. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_CAPTIONTEXT);}
  132. }
  133. public virtual Color ColorActiveBorder {
  134. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_ACTIVEBORDER);}
  135. }
  136. public virtual Color ColorInactiveBorder{
  137. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_INACTIVEBORDER);}
  138. }
  139. public virtual Color ColorAppWorkSpace {
  140. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_APPWORKSPACE);}
  141. }
  142. public virtual Color ColorHilight {
  143. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_HIGHLIGHT);}
  144. }
  145. public virtual Color ColorHilightText {
  146. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_HIGHLIGHTTEXT);}
  147. }
  148. public virtual Color ColorButtonFace {
  149. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_BTNFACE);}
  150. }
  151. public virtual Color ColorButtonShadow {
  152. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_BTNSHADOW);}
  153. }
  154. public virtual Color ColorGrayText {
  155. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_GRAYTEXT);}
  156. }
  157. public virtual Color ColorButtonText {
  158. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_BTNTEXT);}
  159. }
  160. public virtual Color ColorInactiveTitleText {
  161. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_INACTIVECAPTIONTEXT);}
  162. }
  163. public virtual Color ColorButtonHilight {
  164. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_BTNHIGHLIGHT);}
  165. }
  166. public virtual Color ColorButtonDkShadow {
  167. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_3DDKSHADOW);}
  168. }
  169. public virtual Color ColorButtonLight {
  170. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_3DLIGHT);}
  171. }
  172. public virtual Color ColorInfoText {
  173. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_INFOTEXT);}
  174. }
  175. public virtual Color ColorInfoWindow {
  176. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_INFOBK);}
  177. }
  178. public virtual Color DefaultControlBackColor {
  179. get { return ColorButtonFace; }
  180. }
  181. public virtual Color DefaultControlForeColor {
  182. get { return ColorButtonText; }
  183. }
  184. public virtual Font DefaultFont {
  185. get { return default_font; }
  186. }
  187. public virtual Color DefaultWindowBackColor {
  188. get { return defaultWindowBackColor; }
  189. }
  190. public virtual Color DefaultWindowForeColor {
  191. get { return defaultWindowForeColor; }
  192. }
  193. public virtual Color GetColor (XplatUIWin32.GetSysColorIndex idx)
  194. {
  195. return (Color) syscolors.GetValue ((int)idx);
  196. }
  197. public virtual void SetColor (XplatUIWin32.GetSysColorIndex idx, Color color)
  198. {
  199. syscolors.SetValue (color, (int) idx);
  200. }
  201. // If the theme writes directly to a window instead of a device context
  202. public abstract bool WriteToWindow {get;}
  203. /*
  204. Control sizing properties
  205. */
  206. public abstract int SizeGripWidth {get;}
  207. public abstract int StatusBarHorzGapWidth {get;}
  208. public abstract int ScrollBarButtonSize {get;}
  209. /*
  210. ToolBar Control properties
  211. */
  212. public abstract int ToolBarGripWidth {get;} // Grip width for the ToolBar
  213. public abstract int ToolBarImageGripWidth {get;} // Grip width for the Image on the ToolBarButton
  214. public abstract int ToolBarSeparatorWidth {get;} // width of the separator
  215. public abstract int ToolBarDropDownWidth { get; } // width of the dropdown arrow rect
  216. public abstract int ToolBarDropDownArrowWidth { get; } // width for the dropdown arrow on the ToolBarButton
  217. public abstract int ToolBarDropDownArrowHeight { get; } // height for the dropdown arrow on the ToolBarButton
  218. /*
  219. Methods that mimic ControlPaint signature and draw basic objects
  220. */
  221. public abstract void DrawBorder (Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth,
  222. ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
  223. Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
  224. int bottomWidth, ButtonBorderStyle bottomStyle);
  225. public abstract void DrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides);
  226. public abstract void DrawButton (Graphics graphics, Rectangle rectangle, ButtonState state);
  227. public abstract void DrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state);
  228. public abstract void DrawCheckBox (Graphics graphics, Rectangle rectangle, ButtonState state);
  229. public abstract void DrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state);
  230. public abstract void DrawContainerGrabHandle (Graphics graphics, Rectangle bounds);
  231. public abstract void DrawFocusRectangle (Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor);
  232. public abstract void DrawGrabHandle (Graphics graphics, Rectangle rectangle, bool primary, bool enabled);
  233. public abstract void DrawGrid (Graphics graphics, Rectangle area, Size pixelsBetweenDots, Color backColor);
  234. public abstract void DrawImageDisabled (Graphics graphics, Image image, int x, int y, Color background);
  235. public abstract void DrawLockedFrame (Graphics graphics, Rectangle rectangle, bool primary);
  236. public abstract void DrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph);
  237. public abstract void DrawRadioButton (Graphics graphics, Rectangle rectangle, ButtonState state);
  238. public abstract void DrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style);
  239. public abstract void DrawReversibleLine (Point start, Point end, Color backColor);
  240. public abstract void DrawScrollButton (Graphics graphics, Rectangle rectangle, ScrollButton button, ButtonState state);
  241. public abstract void DrawSelectionFrame (Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect,
  242. Color backColor);
  243. public abstract void DrawSizeGrip (Graphics graphics, Color backColor, Rectangle bounds);
  244. public abstract void DrawStringDisabled (Graphics graphics, string s, Font font, Color color, RectangleF layoutRectangle,
  245. StringFormat format);
  246. public abstract void DrawBorderStyle (Graphics dc, Rectangle area, BorderStyle border_style);
  247. /*
  248. Methods that draw complete controls
  249. */
  250. public abstract void DrawLabel (Graphics dc, Rectangle area, BorderStyle border_style, string text,
  251. Color fore_color, Color back_color, Font font, StringFormat string_format, bool Enabled);
  252. public abstract void DrawScrollBar (Graphics dc, Rectangle area, ScrollBar bar,
  253. ref Rectangle thumb_pos, ref Rectangle first_arrow_area, ref Rectangle second_arrow_area,
  254. ButtonState first_arrow, ButtonState second_arrow, ref int scrollbutton_width,
  255. ref int scrollbutton_height, bool vert);
  256. public abstract void DrawTrackBar (Graphics dc, Rectangle area, TrackBar tb,
  257. ref Rectangle thumb_pos, ref Rectangle thumb_area, bool highli_thumb,
  258. float ticks, int value_pos, bool mouse_value);
  259. public abstract void DrawProgressBar (Graphics dc, Rectangle area, Rectangle client_area,
  260. int barpos_pixels, int block_width);
  261. public abstract void DrawToolBar (Graphics dc, ToolBar control, StringFormat format);
  262. public abstract void DrawStatusBar (Graphics dc, Rectangle area, StatusBar sb);
  263. public abstract void DrawOwnerDrawBackground (DrawItemEventArgs e);
  264. public abstract void DrawOwnerDrawFocusRectangle (DrawItemEventArgs e);
  265. public abstract void DrawStatusBarPanel (Graphics dc, Rectangle area, int index,
  266. SolidBrush br_forecolor, StatusBarPanel panel);
  267. public abstract void DrawPictureBox (Graphics dc, PictureBox pb);
  268. public abstract void DrawGroupBox (Graphics dc, Rectangle area, GroupBox box);
  269. }
  270. }