Theme.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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.10 $
  27. // $Modtime: $
  28. // $Log: Theme.cs,v $
  29. // Revision 1.10 2004/09/28 18:44:25 pbartok
  30. // - Streamlined Theme interfaces:
  31. // * Each DrawXXX method for a control now is passed the object for the
  32. // control to be drawn in order to allow accessing any state the theme
  33. // might require
  34. //
  35. // * ControlPaint methods for the theme now have a CP prefix to avoid
  36. // name clashes with the Draw methods for controls
  37. //
  38. // * Every control now retrieves it's DefaultSize from the current theme
  39. //
  40. // Revision 1.9 2004/09/17 12:18:42 jordi
  41. // Very early menu support
  42. //
  43. // Revision 1.8 2004/09/07 17:12:26 jordi
  44. // GroupBox control
  45. //
  46. // Revision 1.7 2004/09/07 09:40:15 jordi
  47. // LinkLabel fixes, methods, multiple links
  48. //
  49. // Revision 1.6 2004/09/02 16:32:54 jordi
  50. // implements resource pool for pens, brushes, and hatchbruses
  51. //
  52. // Revision 1.5 2004/08/25 20:04:40 ravindra
  53. // Added the missing divider code and grip for ToolBar Control.
  54. //
  55. // Revision 1.4 2004/08/24 18:37:02 jordi
  56. // fixes formmating, methods signature, and adds missing events
  57. //
  58. // Revision 1.3 2004/08/24 16:16:46 jackson
  59. // Handle drawing picture boxes in the theme now. Draw picture box borders and obey sizing modes
  60. //
  61. // Revision 1.2 2004/08/20 00:12:51 jordi
  62. // fixes methods signature
  63. //
  64. // Revision 1.1 2004/08/19 22:26:30 jordi
  65. // move themes from an interface to a class
  66. //
  67. //
  68. using System.Drawing;
  69. using System.Drawing.Drawing2D;
  70. using System.Drawing.Imaging;
  71. using System.Collections;
  72. namespace System.Windows.Forms
  73. {
  74. // Implements a pool of system resources
  75. internal class SystemResPool
  76. {
  77. private Hashtable pens = new Hashtable ();
  78. private Hashtable solidbrushes = new Hashtable ();
  79. private Hashtable hatchbrushes = new Hashtable ();
  80. public SystemResPool () {}
  81. public Pen GetPen (Color color)
  82. {
  83. string hash = color.ToString();
  84. if (pens.Contains (hash))
  85. return (Pen) pens[hash];
  86. Pen pen = new Pen (color);
  87. pens.Add (hash, pen);
  88. return pen;
  89. }
  90. public SolidBrush GetSolidBrush (Color color)
  91. {
  92. string hash = color.ToString ();
  93. if (solidbrushes.Contains (hash))
  94. return (SolidBrush) solidbrushes[hash];
  95. SolidBrush brush = new SolidBrush (color);
  96. solidbrushes.Add (hash, brush);
  97. return brush;
  98. }
  99. public HatchBrush GetHatchBrush (HatchStyle hatchStyle, Color foreColor, Color backColor)
  100. {
  101. string hash = hatchStyle.ToString () + foreColor.ToString () + backColor.ToString ();
  102. if (hatchbrushes.Contains (hash))
  103. return (HatchBrush) hatchbrushes[hash];
  104. HatchBrush brush = new HatchBrush (hatchStyle, foreColor, backColor);
  105. hatchbrushes.Add (hash, brush);
  106. return brush;
  107. }
  108. }
  109. internal abstract class Theme
  110. {
  111. protected Array syscolors;
  112. protected Font default_font;
  113. protected Color defaultWindowBackColor;
  114. protected Color defaultWindowForeColor;
  115. internal SystemResPool ResPool = new SystemResPool ();
  116. /* Default properties */
  117. public virtual Color ColorScrollbar {
  118. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_SCROLLBAR);}
  119. }
  120. public virtual Color ColorBackground {
  121. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_BACKGROUND);}
  122. }
  123. public virtual Color ColorActiveTitle {
  124. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_ACTIVECAPTION);}
  125. }
  126. public virtual Color ColorInactiveTitle {
  127. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_INACTIVECAPTION);}
  128. }
  129. public virtual Color ColorMenu {
  130. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_MENU);}
  131. }
  132. public virtual Color ColorWindow {
  133. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_WINDOW);}
  134. }
  135. public virtual Color ColorWindowFrame {
  136. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_WINDOWFRAME);}
  137. }
  138. public virtual Color ColorMenuText {
  139. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_MENUTEXT);}
  140. }
  141. public virtual Color ColorWindowText {
  142. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_WINDOWTEXT);}
  143. }
  144. public virtual Color ColorTitleText {
  145. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_CAPTIONTEXT);}
  146. }
  147. public virtual Color ColorActiveBorder {
  148. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_ACTIVEBORDER);}
  149. }
  150. public virtual Color ColorInactiveBorder{
  151. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_INACTIVEBORDER);}
  152. }
  153. public virtual Color ColorAppWorkSpace {
  154. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_APPWORKSPACE);}
  155. }
  156. public virtual Color ColorHilight {
  157. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_HIGHLIGHT);}
  158. }
  159. public virtual Color ColorHilightText {
  160. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_HIGHLIGHTTEXT);}
  161. }
  162. public virtual Color ColorButtonFace {
  163. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_BTNFACE);}
  164. }
  165. public virtual Color ColorButtonShadow {
  166. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_BTNSHADOW);}
  167. }
  168. public virtual Color ColorGrayText {
  169. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_GRAYTEXT);}
  170. }
  171. public virtual Color ColorButtonText {
  172. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_BTNTEXT);}
  173. }
  174. public virtual Color ColorInactiveTitleText {
  175. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_INACTIVECAPTIONTEXT);}
  176. }
  177. public virtual Color ColorButtonHilight {
  178. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_BTNHIGHLIGHT);}
  179. }
  180. public virtual Color ColorButtonDkShadow {
  181. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_3DDKSHADOW);}
  182. }
  183. public virtual Color ColorButtonLight {
  184. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_3DLIGHT);}
  185. }
  186. public virtual Color ColorInfoText {
  187. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_INFOTEXT);}
  188. }
  189. public virtual Color ColorInfoWindow {
  190. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_INFOBK);}
  191. }
  192. public virtual Color DefaultControlBackColor {
  193. get { return ColorButtonFace; }
  194. }
  195. public virtual Color DefaultControlForeColor {
  196. get { return ColorButtonText; }
  197. }
  198. public virtual Font DefaultFont {
  199. get { return default_font; }
  200. }
  201. public virtual Color DefaultWindowBackColor {
  202. get { return defaultWindowBackColor; }
  203. }
  204. public virtual Color DefaultWindowForeColor {
  205. get { return defaultWindowForeColor; }
  206. }
  207. public virtual Color GetColor (XplatUIWin32.GetSysColorIndex idx)
  208. {
  209. return (Color) syscolors.GetValue ((int)idx);
  210. }
  211. public virtual void SetColor (XplatUIWin32.GetSysColorIndex idx, Color color)
  212. {
  213. syscolors.SetValue (color, (int) idx);
  214. }
  215. #region Principal Theme Methods
  216. // If the theme writes directly to a window instead of a device context
  217. public abstract bool DoubleBufferingSupported {get;}
  218. #endregion // Principal Theme Methods
  219. #region OwnerDraw Support
  220. public abstract void DrawOwnerDrawBackground (DrawItemEventArgs e);
  221. public abstract void DrawOwnerDrawFocusRectangle (DrawItemEventArgs e);
  222. #endregion // OwnerDraw Support
  223. #region Button
  224. #endregion // Button
  225. #region ButtonBase
  226. // Drawing
  227. public abstract void DrawButtonBase(Graphics dc, Rectangle clip_area, ButtonBase button);
  228. // Sizing
  229. public abstract Size ButtonBaseDefaultSize{get;}
  230. #endregion // ButtonBase
  231. #region CheckBox
  232. public abstract void DrawCheckBox(Graphics dc, Rectangle clip_area, CheckBox checkbox);
  233. #endregion // CheckBox
  234. #region Control
  235. #endregion // Control
  236. #region GroupBox
  237. // Drawing
  238. public abstract void DrawGroupBox (Graphics dc, Rectangle clip_area, GroupBox box);
  239. // Sizing
  240. public abstract Size GroupBoxDefaultSize{get;}
  241. #endregion // GroupBox
  242. #region HScrollBar
  243. public abstract Size HScrollBarDefaultSize{get;} // Default size of the scrollbar
  244. #endregion // HScrollBar
  245. #region Label
  246. // Drawing
  247. public abstract void DrawLabel (Graphics dc, Rectangle clip_rectangle, Label label);
  248. // Sizing
  249. public abstract Size LabelDefaultSize{get;}
  250. #endregion // Label
  251. #region LinkLabel
  252. #endregion // LinkLabel
  253. #region Panel
  254. // Sizing
  255. public abstract Size PanelDefaultSize{get;}
  256. #endregion // Panel
  257. #region PictureBox
  258. // Drawing
  259. public abstract void DrawPictureBox (Graphics dc, PictureBox pb);
  260. // Sizing
  261. public abstract Size PictureBoxDefaultSize{get;}
  262. #endregion // PictureBox
  263. #region ProgressBar
  264. // Drawing
  265. public abstract void DrawProgressBar (Graphics dc, Rectangle clip_rectangle, ProgressBar progress_bar);
  266. // Sizing
  267. public abstract Size ProgressBarDefaultSize{get;}
  268. #endregion // ProgressBar
  269. #region RadioButton
  270. // Drawing
  271. public abstract void DrawRadioButton (Graphics dc, Rectangle clip_rectangle, RadioButton radio_button);
  272. // Sizing
  273. public abstract Size RadioButtonDefaultSize{get;}
  274. #endregion // RadioButton
  275. #region ScrollBar
  276. // Drawing
  277. //public abstract void DrawScrollBar (Graphics dc, Rectangle area, ScrollBar bar, ref Rectangle thumb_pos, ref Rectangle first_arrow_area, ref Rectangle second_arrow_area, ButtonState first_arrow, ButtonState second_arrow, ref int scrollbutton_width, ref int scrollbutton_height, bool vert);
  278. public abstract void DrawScrollBar (Graphics dc, Rectangle clip_rectangle, ScrollBar bar);
  279. // Sizing
  280. public abstract int ScrollBarButtonSize {get;} // Size of the scroll button
  281. #endregion // ScrollBar
  282. #region StatusBar
  283. // Drawing
  284. public abstract void DrawStatusBar (Graphics dc, Rectangle clip_rectangle, StatusBar sb);
  285. // Sizing
  286. public abstract int StatusBarSizeGripWidth {get;} // Size of Resize area
  287. public abstract int StatusBarHorzGapWidth {get;} // Gap between panels
  288. public abstract Size StatusBarDefaultSize{get;}
  289. #endregion // StatusBar
  290. #region ToolBar
  291. // Drawing
  292. public abstract void DrawToolBar (Graphics dc, Rectangle clip_area, ToolBar control);
  293. // Sizing
  294. public abstract int ToolBarGripWidth {get;} // Grip width for the ToolBar
  295. public abstract int ToolBarImageGripWidth {get;} // Grip width for the Image on the ToolBarButton
  296. public abstract int ToolBarSeparatorWidth {get;} // width of the separator
  297. public abstract int ToolBarDropDownWidth { get; } // width of the dropdown arrow rect
  298. public abstract int ToolBarDropDownArrowWidth { get; } // width for the dropdown arrow on the ToolBarButton
  299. public abstract int ToolBarDropDownArrowHeight { get; } // height for the dropdown arrow on the ToolBarButton
  300. public abstract Size ToolBarDefaultSize{get;}
  301. #endregion // ToolBar
  302. #region TrackBar
  303. // Drawing
  304. public abstract void DrawTrackBar (Graphics dc, Rectangle clip_rectangle, TrackBar tb);
  305. //public abstract void DrawTrackBar (Graphics dc, Rectangle area, TrackBar tb,
  306. //ref Rectangle thumb_pos,
  307. //ref Rectangle thumb_area,
  308. //bool highli_thumb,
  309. //float ticks,
  310. //int value_pos,
  311. //bool mouse_value);
  312. // Sizing
  313. public abstract Size TrackBarDefaultSize{get; } // Default size for the TrackBar control
  314. #endregion // TrackBar
  315. #region VScrollBar
  316. public abstract Size VScrollBarDefaultSize{get;} // Default size of the scrollbar
  317. #endregion // VScrollBar
  318. #region ControlPaint Methods
  319. public abstract void CPDrawBorder (Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth,
  320. ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
  321. Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
  322. int bottomWidth, ButtonBorderStyle bottomStyle);
  323. public abstract void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides);
  324. public abstract void CPDrawButton (Graphics graphics, Rectangle rectangle, ButtonState state);
  325. public abstract void CPDrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state);
  326. public abstract void CPDrawCheckBox (Graphics graphics, Rectangle rectangle, ButtonState state);
  327. public abstract void CPDrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state);
  328. public abstract void CPDrawContainerGrabHandle (Graphics graphics, Rectangle bounds);
  329. public abstract void CPDrawFocusRectangle (Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor);
  330. public abstract void CPDrawGrabHandle (Graphics graphics, Rectangle rectangle, bool primary, bool enabled);
  331. public abstract void CPDrawGrid (Graphics graphics, Rectangle area, Size pixelsBetweenDots, Color backColor);
  332. public abstract void CPDrawImageDisabled (Graphics graphics, Image image, int x, int y, Color background);
  333. public abstract void CPDrawLockedFrame (Graphics graphics, Rectangle rectangle, bool primary);
  334. public abstract void CPDrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph);
  335. public abstract void CPDrawRadioButton (Graphics graphics, Rectangle rectangle, ButtonState state);
  336. public abstract void CPDrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style);
  337. public abstract void CPDrawReversibleLine (Point start, Point end, Color backColor);
  338. public abstract void CPDrawScrollButton (Graphics graphics, Rectangle rectangle, ScrollButton button, ButtonState state);
  339. public abstract void CPDrawSelectionFrame (Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect,
  340. Color backColor);
  341. public abstract void CPDrawSizeGrip (Graphics graphics, Color backColor, Rectangle bounds);
  342. public abstract void CPDrawStringDisabled (Graphics graphics, string s, Font font, Color color, RectangleF layoutRectangle,
  343. StringFormat format);
  344. public abstract void CPDrawBorderStyle (Graphics dc, Rectangle area, BorderStyle border_style);
  345. #endregion // ControlPaint Methods
  346. }
  347. }