Theme.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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. using System.Drawing;
  26. using System.Drawing.Drawing2D;
  27. using System.Drawing.Imaging;
  28. using System.Collections;
  29. namespace System.Windows.Forms
  30. {
  31. // Implements a pool of system resources
  32. internal class SystemResPool
  33. {
  34. private Hashtable pens = new Hashtable ();
  35. private Hashtable solidbrushes = new Hashtable ();
  36. private Hashtable hatchbrushes = new Hashtable ();
  37. public SystemResPool () {}
  38. public Pen GetPen (Color color)
  39. {
  40. int hash = color.ToArgb ();
  41. Pen res = pens [hash] as Pen;
  42. if (res != null)
  43. return res;
  44. Pen pen = new Pen (color);
  45. pens.Add (hash, pen);
  46. return pen;
  47. }
  48. public SolidBrush GetSolidBrush (Color color)
  49. {
  50. int hash = color.ToArgb ();
  51. SolidBrush res = solidbrushes [hash] as SolidBrush;
  52. if (res != null)
  53. return res;
  54. SolidBrush brush = new SolidBrush (color);
  55. solidbrushes.Add (hash, brush);
  56. return brush;
  57. }
  58. public HatchBrush GetHatchBrush (HatchStyle hatchStyle, Color foreColor, Color backColor)
  59. {
  60. string hash = hatchStyle.ToString () + foreColor.ToString () + backColor.ToString ();
  61. if (hatchbrushes.Contains (hash))
  62. return (HatchBrush) hatchbrushes[hash];
  63. HatchBrush brush = new HatchBrush (hatchStyle, foreColor, backColor);
  64. hatchbrushes.Add (hash, brush);
  65. return brush;
  66. }
  67. }
  68. internal abstract class Theme
  69. {
  70. protected Array syscolors;
  71. protected Font default_font;
  72. protected Color defaultWindowBackColor;
  73. protected Color defaultWindowForeColor;
  74. internal SystemResPool ResPool = new SystemResPool ();
  75. /* OS Feature support */
  76. public abstract Version Version {
  77. get;
  78. }
  79. /* Default properties */
  80. public virtual Color ColorScrollbar {
  81. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_SCROLLBAR);}
  82. }
  83. public virtual Color ColorBackground {
  84. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_BACKGROUND);}
  85. }
  86. public virtual Color ColorActiveTitle {
  87. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_ACTIVECAPTION);}
  88. }
  89. public virtual Color ColorInactiveTitle {
  90. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_INACTIVECAPTION);}
  91. }
  92. public virtual Color ColorMenu {
  93. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_MENU);}
  94. }
  95. public virtual Color ColorWindow {
  96. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_WINDOW);}
  97. }
  98. public virtual Color ColorWindowFrame {
  99. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_WINDOWFRAME);}
  100. }
  101. public virtual Color ColorMenuText {
  102. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_MENUTEXT);}
  103. }
  104. public virtual Color ColorWindowText {
  105. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_WINDOWTEXT);}
  106. }
  107. public virtual Color ColorTitleText {
  108. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_CAPTIONTEXT);}
  109. }
  110. public virtual Color ColorActiveBorder {
  111. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_ACTIVEBORDER);}
  112. }
  113. public virtual Color ColorInactiveBorder{
  114. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_INACTIVEBORDER);}
  115. }
  116. public virtual Color ColorAppWorkSpace {
  117. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_APPWORKSPACE);}
  118. }
  119. public virtual Color ColorHilight {
  120. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_HIGHLIGHT);}
  121. }
  122. public virtual Color ColorHilightText {
  123. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_HIGHLIGHTTEXT);}
  124. }
  125. public virtual Color ColorButtonFace {
  126. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_BTNFACE);}
  127. }
  128. public virtual Color ColorButtonShadow {
  129. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_BTNSHADOW);}
  130. }
  131. public virtual Color ColorGrayText {
  132. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_GRAYTEXT);}
  133. }
  134. public virtual Color ColorButtonText {
  135. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_BTNTEXT);}
  136. }
  137. public virtual Color ColorInactiveTitleText {
  138. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_INACTIVECAPTIONTEXT);}
  139. }
  140. public virtual Color ColorButtonHilight {
  141. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_BTNHIGHLIGHT);}
  142. }
  143. public virtual Color ColorButtonDkShadow {
  144. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_3DDKSHADOW);}
  145. }
  146. public virtual Color ColorButtonLight {
  147. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_3DLIGHT);}
  148. }
  149. public virtual Color ColorInfoText {
  150. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_INFOTEXT);}
  151. }
  152. public virtual Color ColorInfoWindow {
  153. get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_INFOBK);}
  154. }
  155. public virtual Color DefaultControlBackColor {
  156. get { return ColorButtonFace; }
  157. }
  158. public virtual Color DefaultControlForeColor {
  159. get { return ColorButtonText; }
  160. }
  161. public virtual Font DefaultFont {
  162. get { return default_font; }
  163. }
  164. public virtual Color DefaultWindowBackColor {
  165. get { return defaultWindowBackColor; }
  166. }
  167. public virtual Color DefaultWindowForeColor {
  168. get { return defaultWindowForeColor; }
  169. }
  170. public virtual Color GetColor (XplatUIWin32.GetSysColorIndex idx)
  171. {
  172. return (Color) syscolors.GetValue ((int)idx);
  173. }
  174. public virtual void SetColor (XplatUIWin32.GetSysColorIndex idx, Color color)
  175. {
  176. syscolors.SetValue (color, (int) idx);
  177. }
  178. #region Principal Theme Methods
  179. // If the theme writes directly to a window instead of a device context
  180. public abstract bool DoubleBufferingSupported {get;}
  181. #endregion // Principal Theme Methods
  182. #region OwnerDraw Support
  183. public abstract void DrawOwnerDrawBackground (DrawItemEventArgs e);
  184. public abstract void DrawOwnerDrawFocusRectangle (DrawItemEventArgs e);
  185. #endregion // OwnerDraw Support
  186. #region Button
  187. #endregion // Button
  188. #region ButtonBase
  189. // Drawing
  190. public abstract void DrawButtonBase(Graphics dc, Rectangle clip_area, ButtonBase button);
  191. // Sizing
  192. public abstract Size ButtonBaseDefaultSize{get;}
  193. #endregion // ButtonBase
  194. #region CheckBox
  195. public abstract void DrawCheckBox(Graphics dc, Rectangle clip_area, CheckBox checkbox);
  196. #endregion // CheckBox
  197. #region ComboBox
  198. // Drawing
  199. public abstract void DrawComboBoxEditDecorations (Graphics dc, ComboBox ctrl, Rectangle rect);
  200. public abstract void DrawComboListBoxDecorations (Graphics dc, ComboBox ctrl, Rectangle rect);
  201. // Sizing
  202. public abstract int DrawComboBoxEditDecorationTop ();
  203. public abstract int DrawComboBoxEditDecorationBottom ();
  204. public abstract int DrawComboBoxEditDecorationRight ();
  205. public abstract int DrawComboBoxEditDecorationLeft ();
  206. public abstract int DrawComboListBoxDecorationTop (ComboBoxStyle style);
  207. public abstract int DrawComboListBoxDecorationBottom (ComboBoxStyle style);
  208. public abstract int DrawComboListBoxDecorationRight (ComboBoxStyle style);
  209. public abstract int DrawComboListBoxDecorationLeft (ComboBoxStyle style);
  210. #endregion // ComboBox
  211. #region Control
  212. #endregion // Control
  213. #region GroupBox
  214. // Drawing
  215. public abstract void DrawGroupBox (Graphics dc, Rectangle clip_area, GroupBox box);
  216. // Sizing
  217. public abstract Size GroupBoxDefaultSize{get;}
  218. #endregion // GroupBox
  219. #region HScrollBar
  220. public abstract Size HScrollBarDefaultSize{get;} // Default size of the scrollbar
  221. #endregion // HScrollBar
  222. #region Label
  223. // Drawing
  224. public abstract void DrawLabel (Graphics dc, Rectangle clip_rectangle, Label label);
  225. // Sizing
  226. public abstract Size LabelDefaultSize{get;}
  227. #endregion // Label
  228. #region LinkLabel
  229. #endregion // LinkLabel
  230. #region ListBox
  231. // Drawing
  232. public abstract void DrawListBoxDecorations (Graphics dc, ListBox ctrl);
  233. // Sizing
  234. public abstract int DrawListBoxDecorationTop (BorderStyle border_style);
  235. public abstract int DrawListBoxDecorationBottom (BorderStyle border_style);
  236. public abstract int DrawListBoxDecorationRight (BorderStyle border_style);
  237. public abstract int DrawListBoxDecorationLeft (BorderStyle border_style);
  238. #endregion // ListBox
  239. #region ListView
  240. // Drawing
  241. public abstract void DrawListView (Graphics dc, Rectangle clip_rectangle, ListView control);
  242. // Sizing
  243. public abstract Size ListViewCheckBoxSize { get; }
  244. public abstract int ListViewColumnHeaderHeight { get; }
  245. public abstract int ListViewDefaultColumnWidth { get; }
  246. public abstract int ListViewVerticalSpacing { get; }
  247. public abstract int ListViewEmptyColumnWidth { get; }
  248. public abstract int ListViewHorizontalSpacing { get; }
  249. public abstract Size ListViewDefaultSize { get; }
  250. #endregion // ListView
  251. #region Panel
  252. // Sizing
  253. public abstract Size PanelDefaultSize{get;}
  254. #endregion // Panel
  255. #region PictureBox
  256. // Drawing
  257. public abstract void DrawPictureBox (Graphics dc, PictureBox pb);
  258. // Sizing
  259. public abstract Size PictureBoxDefaultSize{get;}
  260. #endregion // PictureBox
  261. #region ProgressBar
  262. // Drawing
  263. public abstract void DrawProgressBar (Graphics dc, Rectangle clip_rectangle, ProgressBar progress_bar);
  264. // Sizing
  265. public abstract Size ProgressBarDefaultSize{get;}
  266. #endregion // ProgressBar
  267. #region RadioButton
  268. // Drawing
  269. public abstract void DrawRadioButton (Graphics dc, Rectangle clip_rectangle, RadioButton radio_button);
  270. // Sizing
  271. public abstract Size RadioButtonDefaultSize{get;}
  272. #endregion // RadioButton
  273. #region ScrollBar
  274. // Drawing
  275. //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);
  276. public abstract void DrawScrollBar (Graphics dc, Rectangle clip_rectangle, ScrollBar bar);
  277. // Sizing
  278. public abstract int ScrollBarButtonSize {get;} // Size of the scroll button
  279. #endregion // ScrollBar
  280. #region StatusBar
  281. // Drawing
  282. public abstract void DrawStatusBar (Graphics dc, Rectangle clip_rectangle, StatusBar sb);
  283. // Sizing
  284. public abstract int StatusBarSizeGripWidth {get;} // Size of Resize area
  285. public abstract int StatusBarHorzGapWidth {get;} // Gap between panels
  286. public abstract Size StatusBarDefaultSize{get;}
  287. #endregion // StatusBar
  288. #region TabControl
  289. public abstract Size TabControlDefaultItemSize { get; }
  290. public abstract Point TabControlDefaultPadding { get; }
  291. public abstract int TabControlMinimumTabWidth { get; }
  292. public abstract Rectangle GetTabControlLeftScrollRect (TabControl tab);
  293. public abstract Rectangle GetTabControlRightScrollRect (TabControl tab);
  294. public abstract Rectangle GetTabControlDisplayRectangle (TabControl tab);
  295. public abstract Size TabControlGetSpacing (TabControl tab);
  296. public abstract void DrawTabControl (Graphics dc, Rectangle area, TabControl tab);
  297. #endregion
  298. #region ToolBar
  299. // Drawing
  300. public abstract void DrawToolBar (Graphics dc, Rectangle clip_rectangle, ToolBar control);
  301. // Sizing
  302. public abstract int ToolBarGripWidth {get;} // Grip width for the ToolBar
  303. public abstract int ToolBarImageGripWidth {get;} // Grip width for the Image on the ToolBarButton
  304. public abstract int ToolBarSeparatorWidth {get;} // width of the separator
  305. public abstract int ToolBarDropDownWidth { get; } // width of the dropdown arrow rect
  306. public abstract int ToolBarDropDownArrowWidth { get; } // width for the dropdown arrow on the ToolBarButton
  307. public abstract int ToolBarDropDownArrowHeight { get; } // height for the dropdown arrow on the ToolBarButton
  308. public abstract Size ToolBarDefaultSize{get;}
  309. #endregion // ToolBar
  310. #region ToolTip
  311. public abstract void DrawToolTip(Graphics dc, Rectangle clip_rectangle, ToolTip tt);
  312. public abstract Size ToolTipSize(ToolTip tt, string text);
  313. #endregion // ToolTip
  314. #region MonthCalendar
  315. public abstract void DrawMonthCalendar(Graphics dc, Rectangle clip_rectangle, MonthCalendar month_calendar);
  316. #endregion // MonthCalendar
  317. #region TrackBar
  318. // Drawing
  319. public abstract void DrawTrackBar (Graphics dc, Rectangle clip_rectangle, TrackBar tb);
  320. //public abstract void DrawTrackBar (Graphics dc, Rectangle area, TrackBar tb,
  321. //ref Rectangle thumb_pos,
  322. //ref Rectangle thumb_area,
  323. //bool highli_thumb,
  324. //float ticks,
  325. //int value_pos,
  326. //bool mouse_value);
  327. // Sizing
  328. public abstract Size TrackBarDefaultSize{get; } // Default size for the TrackBar control
  329. #endregion // TrackBar
  330. #region VScrollBar
  331. public abstract Size VScrollBarDefaultSize{get;} // Default size of the scrollbar
  332. #endregion // VScrollBar
  333. #region TreeView
  334. public abstract Size TreeViewDefaultSize { get; }
  335. #endregion
  336. #region ControlPaint Methods
  337. public abstract void CPDrawBorder (Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth,
  338. ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
  339. Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
  340. int bottomWidth, ButtonBorderStyle bottomStyle);
  341. public abstract void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides);
  342. public abstract void CPDrawButton (Graphics graphics, Rectangle rectangle, ButtonState state);
  343. public abstract void CPDrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state);
  344. public abstract void CPDrawCheckBox (Graphics graphics, Rectangle rectangle, ButtonState state);
  345. public abstract void CPDrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state);
  346. public abstract void CPDrawContainerGrabHandle (Graphics graphics, Rectangle bounds);
  347. public abstract void CPDrawFocusRectangle (Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor);
  348. public abstract void CPDrawGrabHandle (Graphics graphics, Rectangle rectangle, bool primary, bool enabled);
  349. public abstract void CPDrawGrid (Graphics graphics, Rectangle area, Size pixelsBetweenDots, Color backColor);
  350. public abstract void CPDrawImageDisabled (Graphics graphics, Image image, int x, int y, Color background);
  351. public abstract void CPDrawLockedFrame (Graphics graphics, Rectangle rectangle, bool primary);
  352. public abstract void CPDrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph);
  353. public abstract void CPDrawRadioButton (Graphics graphics, Rectangle rectangle, ButtonState state);
  354. public abstract void CPDrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style);
  355. public abstract void CPDrawReversibleLine (Point start, Point end, Color backColor);
  356. public abstract void CPDrawScrollButton (Graphics graphics, Rectangle rectangle, ScrollButton button, ButtonState state);
  357. public abstract void CPDrawSelectionFrame (Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect,
  358. Color backColor);
  359. public abstract void CPDrawSizeGrip (Graphics graphics, Color backColor, Rectangle bounds);
  360. public abstract void CPDrawStringDisabled (Graphics graphics, string s, Font font, Color color, RectangleF layoutRectangle,
  361. StringFormat format);
  362. public abstract void CPDrawBorderStyle (Graphics dc, Rectangle area, BorderStyle border_style);
  363. #endregion // ControlPaint Methods
  364. }
  365. }