Theme.cs 16 KB

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