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:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
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.
20 // Copyright (c) 2004-2005 Novell, Inc.
23 // Jordi Mas i Hernandez, jordi@ximian.com
28 using System.Drawing.Drawing2D;
29 using System.Drawing.Imaging;
30 using System.Collections;
32 namespace System.Windows.Forms
36 // Implements a pool of system resources
37 internal class SystemResPool
39 private Hashtable pens = new Hashtable ();
40 private Hashtable solidbrushes = new Hashtable ();
41 private Hashtable hatchbrushes = new Hashtable ();
43 public SystemResPool () {}
45 public Pen GetPen (Color color)
47 int hash = color.ToArgb ();
49 Pen res = pens [hash] as Pen;
53 Pen pen = new Pen (color);
58 public SolidBrush GetSolidBrush (Color color)
60 int hash = color.ToArgb ();
62 SolidBrush res = solidbrushes [hash] as SolidBrush;
66 SolidBrush brush = new SolidBrush (color);
67 solidbrushes.Add (hash, brush);
71 public HatchBrush GetHatchBrush (HatchStyle hatchStyle, Color foreColor, Color backColor)
73 string hash = hatchStyle.ToString () + foreColor.ToString () + backColor.ToString ();
75 if (hatchbrushes.Contains (hash))
76 return (HatchBrush) hatchbrushes[hash];
78 HatchBrush brush = new HatchBrush (hatchStyle, foreColor, backColor);
79 hatchbrushes.Add (hash, brush);
85 internal abstract class Theme
87 protected Array syscolors;
88 protected Font default_font;
89 protected Color defaultWindowBackColor;
90 protected Color defaultWindowForeColor;
91 internal SystemResPool ResPool = new SystemResPool ();
93 /* OS Feature support */
94 public abstract Version Version {
98 /* Default properties */
99 public virtual Color ColorScrollbar {
100 get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_SCROLLBAR);}
103 public virtual Color ColorBackground {
104 get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_BACKGROUND);}
107 public virtual Color ColorActiveTitle {
108 get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_ACTIVECAPTION);}
111 public virtual Color ColorInactiveTitle {
112 get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_INACTIVECAPTION);}
115 public virtual Color ColorMenu {
116 get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_MENU);}
119 public virtual Color ColorWindow {
120 get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_WINDOW);}
123 public virtual Color ColorWindowFrame {
124 get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_WINDOWFRAME);}
127 public virtual Color ColorMenuText {
128 get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_MENUTEXT);}
131 public virtual Color ColorWindowText {
132 get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_WINDOWTEXT);}
135 public virtual Color ColorTitleText {
136 get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_CAPTIONTEXT);}
139 public virtual Color ColorActiveBorder {
140 get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_ACTIVEBORDER);}
143 public virtual Color ColorInactiveBorder{
144 get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_INACTIVEBORDER);}
147 public virtual Color ColorAppWorkSpace {
148 get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_APPWORKSPACE);}
151 public virtual Color ColorHilight {
152 get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_HIGHLIGHT);}
155 public virtual Color ColorHilightText {
156 get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_HIGHLIGHTTEXT);}
159 public virtual Color ColorButtonFace {
160 get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_BTNFACE);}
163 public virtual Color ColorButtonShadow {
164 get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_BTNSHADOW);}
167 public virtual Color ColorGrayText {
168 get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_GRAYTEXT);}
171 public virtual Color ColorButtonText {
172 get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_BTNTEXT);}
175 public virtual Color ColorInactiveTitleText {
176 get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_INACTIVECAPTIONTEXT);}
179 public virtual Color ColorButtonHilight {
180 get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_BTNHIGHLIGHT);}
183 public virtual Color ColorButtonDkShadow {
184 get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_3DDKSHADOW);}
187 public virtual Color ColorButtonLight {
188 get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_3DLIGHT);}
191 public virtual Color ColorInfoText {
192 get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_INFOTEXT);}
195 public virtual Color ColorInfoWindow {
196 get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_INFOBK);}
199 public virtual Color DefaultControlBackColor {
200 get { return ColorButtonFace; }
203 public virtual Color DefaultControlForeColor {
204 get { return ColorButtonText; }
207 public virtual Font DefaultFont {
208 get { return default_font; }
211 public virtual Color DefaultWindowBackColor {
212 get { return defaultWindowBackColor; }
215 public virtual Color DefaultWindowForeColor {
216 get { return defaultWindowForeColor; }
219 public virtual Color GetColor (XplatUIWin32.GetSysColorIndex idx)
221 return (Color) syscolors.GetValue ((int)idx);
224 public virtual void SetColor (XplatUIWin32.GetSysColorIndex idx, Color color)
226 syscolors.SetValue (color, (int) idx);
229 // Theme/UI specific defaults
230 public virtual ArrangeDirection ArrangeDirection {
232 return ArrangeDirection.Down;
236 public virtual ArrangeStartingPosition ArrangeStartingPosition {
238 return ArrangeStartingPosition.BottomLeft;
242 public virtual Size Border3DSize {
244 return new Size(2, 2);
248 public virtual Size BorderSize {
250 return new Size(1, 1);
254 public virtual Size CaptionButtonSize {
256 return new Size(18, 18);
260 public virtual int CaptionHeight {
266 public virtual Size DoubleClickSize {
268 return new Size(4, 4);
272 public virtual int DoubleClickTime {
278 public virtual Size FixedFrameBorderSize {
280 return new Size(3, 3);
284 public virtual Size FrameBorderSize {
286 return new Size(4, 4);
290 public virtual int HorizontalScrollBarArrowWidth {
296 public virtual int HorizontalScrollBarHeight {
302 public virtual int HorizontalScrollBarThumbWidth {
308 public virtual Size IconSpacingSize {
310 return new Size(75, 75);
314 public virtual Size MenuButtonSize {
316 return new Size(18, 18);
320 public virtual Size MenuCheckSize {
322 return new Size(13, 13);
326 public virtual Font MenuFont {
332 public virtual int MenuHeight {
338 public virtual int MouseWheelScrollLines {
344 public virtual bool RightAlignedMenus {
350 public virtual Size ToolWindowCaptionButtonSize {
352 return new Size(15, 15);
356 public virtual int ToolWindowCaptionHeight {
362 public virtual int VerticalScrollBarArrowHeight {
368 public virtual int VerticalScrollBarThumbHeight {
374 public virtual int VerticalScrollBarWidth {
379 #region Principal Theme Methods
380 // To let the theme now that a change of defaults (colors, etc) was detected and force a re-read (and possible recreation of cached resources)
381 public abstract void ResetDefaults();
383 // If the theme writes directly to a window instead of a device context
384 public abstract bool DoubleBufferingSupported {get;}
385 #endregion // Principal Theme Methods
387 #region OwnerDraw Support
388 public abstract void DrawOwnerDrawBackground (DrawItemEventArgs e);
389 public abstract void DrawOwnerDrawFocusRectangle (DrawItemEventArgs e);
390 #endregion // OwnerDraw Support
397 public abstract void DrawButtonBase(Graphics dc, Rectangle clip_area, ButtonBase button);
400 public abstract Size ButtonBaseDefaultSize{get;}
401 #endregion // ButtonBase
404 public abstract void DrawCheckBox(Graphics dc, Rectangle clip_area, CheckBox checkbox);
405 #endregion // CheckBox
407 #region CheckedListBox
409 public abstract void DrawCheckedListBoxItem (CheckedListBox ctrl, DrawItemEventArgs e);
410 public abstract Rectangle CheckedListBoxCheckRectangle ();
411 #endregion // CheckedListBox
415 public abstract void DrawComboBoxEditDecorations (Graphics dc, ComboBox ctrl, Rectangle rect);
416 public abstract void DrawComboListBoxDecorations (Graphics dc, ComboBox ctrl, Rectangle rect);
417 public abstract void DrawComboBoxItem (ComboBox ctrl, DrawItemEventArgs e);
420 public abstract int DrawComboBoxEditDecorationTop ();
421 public abstract int DrawComboBoxEditDecorationBottom ();
422 public abstract int DrawComboBoxEditDecorationRight ();
423 public abstract int DrawComboBoxEditDecorationLeft ();
424 public abstract int DrawComboListBoxDecorationTop (ComboBoxStyle style);
425 public abstract int DrawComboListBoxDecorationBottom (ComboBoxStyle style);
426 public abstract int DrawComboListBoxDecorationRight (ComboBoxStyle style);
427 public abstract int DrawComboListBoxDecorationLeft (ComboBoxStyle style);
428 #endregion // ComboBox
431 #endregion // Control
433 #region DateTimePicker
435 public abstract void DrawDateTimePicker(Graphics dc, Rectangle clip_rectangle, DateTimePicker dtp);
437 #endregion // DateTimePicker
441 public abstract void DrawGroupBox (Graphics dc, Rectangle clip_area, GroupBox box);
444 public abstract Size GroupBoxDefaultSize{get;}
445 #endregion // GroupBox
448 public abstract Size HScrollBarDefaultSize{get;} // Default size of the scrollbar
449 #endregion // HScrollBar
453 public abstract void DrawLabel (Graphics dc, Rectangle clip_rectangle, Label label);
456 public abstract Size LabelDefaultSize{get;}
460 public abstract void DrawLinkLabel (Graphics dc, Rectangle clip_rectangle, LinkLabel label);
461 #endregion // LinkLabel
465 public abstract void DrawListBoxDecorations (Graphics dc, ListBox ctrl);
466 public abstract void DrawListBoxItem (ListBox ctrl, DrawItemEventArgs e);
469 public abstract int DrawListBoxDecorationTop (BorderStyle border_style);
470 public abstract int DrawListBoxDecorationBottom (BorderStyle border_style);
471 public abstract int DrawListBoxDecorationRight (BorderStyle border_style);
472 public abstract int DrawListBoxDecorationLeft (BorderStyle border_style);
473 #endregion // ListBox
477 public abstract void DrawListView (Graphics dc, Rectangle clip_rectangle, ListView control);
480 public abstract Size ListViewCheckBoxSize { get; }
481 public abstract int ListViewColumnHeaderHeight { get; }
482 public abstract int ListViewDefaultColumnWidth { get; }
483 public abstract int ListViewVerticalSpacing { get; }
484 public abstract int ListViewEmptyColumnWidth { get; }
485 public abstract int ListViewHorizontalSpacing { get; }
486 public abstract Size ListViewDefaultSize { get; }
487 #endregion // ListView
490 public abstract void CalcItemSize (Graphics dc, MenuAPI.MENUITEM item, int y, int x, bool menuBar);
491 public abstract void CalcPopupMenuSize (Graphics dc, IntPtr hMenu);
492 public abstract int CalcMenuBarSize (Graphics dc, IntPtr hMenu, int width);
493 public abstract void DrawMenuBar (Graphics dc, IntPtr hMenu, Rectangle rect);
494 public abstract void DrawMenuItem (MenuItem item, DrawItemEventArgs e);
495 public abstract void DrawPopupMenu (Graphics dc, IntPtr hMenu, Rectangle cliparea, Rectangle rect);
498 #region MonthCalendar
499 public abstract void DrawMonthCalendar(Graphics dc, Rectangle clip_rectangle, MonthCalendar month_calendar);
500 #endregion // MonthCalendar
504 public abstract Size PanelDefaultSize{get;}
509 public abstract void DrawPictureBox (Graphics dc, PictureBox pb);
512 public abstract Size PictureBoxDefaultSize{get;}
513 #endregion // PictureBox
517 public abstract void DrawProgressBar (Graphics dc, Rectangle clip_rectangle, ProgressBar progress_bar);
520 public abstract Size ProgressBarDefaultSize{get;}
521 #endregion // ProgressBar
525 public abstract void DrawRadioButton (Graphics dc, Rectangle clip_rectangle, RadioButton radio_button);
528 public abstract Size RadioButtonDefaultSize{get;}
529 #endregion // RadioButton
533 //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);
534 public abstract void DrawScrollBar (Graphics dc, Rectangle clip_rectangle, ScrollBar bar);
537 public abstract int ScrollBarButtonSize {get;} // Size of the scroll button
538 #endregion // ScrollBar
542 public abstract void DrawStatusBar (Graphics dc, Rectangle clip_rectangle, StatusBar sb);
545 public abstract int StatusBarSizeGripWidth {get;} // Size of Resize area
546 public abstract int StatusBarHorzGapWidth {get;} // Gap between panels
547 public abstract Size StatusBarDefaultSize{get;}
548 #endregion // StatusBar
551 public abstract Size TabControlDefaultItemSize { get; }
552 public abstract Point TabControlDefaultPadding { get; }
553 public abstract int TabControlMinimumTabWidth { get; }
555 public abstract Rectangle GetTabControlLeftScrollRect (TabControl tab);
556 public abstract Rectangle GetTabControlRightScrollRect (TabControl tab);
557 public abstract Rectangle GetTabControlDisplayRectangle (TabControl tab);
558 public abstract Size TabControlGetSpacing (TabControl tab);
559 public abstract void DrawTabControl (Graphics dc, Rectangle area, TabControl tab);
564 public abstract void DrawToolBar (Graphics dc, Rectangle clip_rectangle, ToolBar control);
567 public abstract int ToolBarGripWidth {get;} // Grip width for the ToolBar
568 public abstract int ToolBarImageGripWidth {get;} // Grip width for the Image on the ToolBarButton
569 public abstract int ToolBarSeparatorWidth {get;} // width of the separator
570 public abstract int ToolBarDropDownWidth { get; } // width of the dropdown arrow rect
571 public abstract int ToolBarDropDownArrowWidth { get; } // width for the dropdown arrow on the ToolBarButton
572 public abstract int ToolBarDropDownArrowHeight { get; } // height for the dropdown arrow on the ToolBarButton
573 public abstract Size ToolBarDefaultSize{get;}
574 #endregion // ToolBar
577 public abstract void DrawToolTip(Graphics dc, Rectangle clip_rectangle, ToolTip tt);
578 public abstract Size ToolTipSize(ToolTip tt, string text);
579 #endregion // ToolTip
584 public abstract void DrawTrackBar (Graphics dc, Rectangle clip_rectangle, TrackBar tb);
587 public abstract Size TrackBarDefaultSize{get; } // Default size for the TrackBar control
588 #endregion // TrackBar
591 public abstract Size VScrollBarDefaultSize{get;} // Default size of the scrollbar
592 #endregion // VScrollBar
595 public abstract Size TreeViewDefaultSize { get; }
598 #region ControlPaint Methods
599 public abstract void CPDrawBorder (Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth,
600 ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
601 Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
602 int bottomWidth, ButtonBorderStyle bottomStyle);
604 public abstract void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides);
605 public abstract void CPDrawButton (Graphics graphics, Rectangle rectangle, ButtonState state);
606 public abstract void CPDrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state);
607 public abstract void CPDrawCheckBox (Graphics graphics, Rectangle rectangle, ButtonState state);
608 public abstract void CPDrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state);
609 public abstract void CPDrawContainerGrabHandle (Graphics graphics, Rectangle bounds);
610 public abstract void CPDrawFocusRectangle (Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor);
611 public abstract void CPDrawGrabHandle (Graphics graphics, Rectangle rectangle, bool primary, bool enabled);
612 public abstract void CPDrawGrid (Graphics graphics, Rectangle area, Size pixelsBetweenDots, Color backColor);
613 public abstract void CPDrawImageDisabled (Graphics graphics, Image image, int x, int y, Color background);
614 public abstract void CPDrawLockedFrame (Graphics graphics, Rectangle rectangle, bool primary);
615 public abstract void CPDrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph);
616 public abstract void CPDrawRadioButton (Graphics graphics, Rectangle rectangle, ButtonState state);
617 public abstract void CPDrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style);
618 public abstract void CPDrawReversibleLine (Point start, Point end, Color backColor);
619 public abstract void CPDrawScrollButton (Graphics graphics, Rectangle rectangle, ScrollButton button, ButtonState state);
620 public abstract void CPDrawSelectionFrame (Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect,
622 public abstract void CPDrawSizeGrip (Graphics graphics, Color backColor, Rectangle bounds);
623 public abstract void CPDrawStringDisabled (Graphics graphics, string s, Font font, Color color, RectangleF layoutRectangle,
624 StringFormat format);
625 public abstract void CPDrawBorderStyle (Graphics dc, Rectangle area, BorderStyle border_style);
626 #endregion // ControlPaint Methods