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
24 // Peter Dennis Bartok, pbartok@novell.com
28 using System.Collections;
30 using System.Drawing.Drawing2D;
31 using System.Drawing.Imaging;
32 using System.Reflection;
34 namespace System.Windows.Forms
38 // Implements a pool of system resources
39 internal class SystemResPool
41 private Hashtable pens = new Hashtable ();
42 private Hashtable solidbrushes = new Hashtable ();
43 private Hashtable hatchbrushes = new Hashtable ();
45 public SystemResPool () {}
47 public Pen GetPen (Color color)
49 int hash = color.ToArgb ();
51 Pen res = pens [hash] as Pen;
55 Pen pen = new Pen (color);
60 public SolidBrush GetSolidBrush (Color color)
62 int hash = color.ToArgb ();
64 SolidBrush res = solidbrushes [hash] as SolidBrush;
68 SolidBrush brush = new SolidBrush (color);
69 solidbrushes.Add (hash, brush);
73 public HatchBrush GetHatchBrush (HatchStyle hatchStyle, Color foreColor, Color backColor)
75 string hash = hatchStyle.ToString () + foreColor.ToString () + backColor.ToString ();
77 if (hatchbrushes.Contains (hash))
78 return (HatchBrush) hatchbrushes[hash];
80 HatchBrush brush = new HatchBrush (hatchStyle, foreColor, backColor);
81 hatchbrushes.Add (hash, brush);
87 internal abstract class Theme
89 protected Array syscolors;
90 protected Font default_font;
91 protected Color defaultWindowBackColor;
92 protected Color defaultWindowForeColor;
93 internal SystemResPool ResPool = new SystemResPool ();
94 private Type system_colors = Type.GetType("System.Drawing.SystemColors, System.Drawing");
96 private void SetSystemColors(string name, Color value) {
97 if (system_colors != null) {
100 system_colors.GetField(name, System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).SetValue(null, value);
101 update = system_colors.GetMethod("UpdateColors", BindingFlags.Static | BindingFlags.NonPublic);
102 if (update != null) {
103 update.Invoke(null, null);
109 /* OS Feature support */
110 public abstract Version Version {
114 /* Default properties */
115 public virtual Color ColorScrollBar {
116 get { return SystemColors.ScrollBar;}
117 set { SetSystemColors("scroll_bar", value); }
120 public virtual Color ColorDesktop {
121 get { return SystemColors.Desktop;}
122 set { SetSystemColors("desktop", value); }
125 public virtual Color ColorActiveCaption {
126 get { return SystemColors.ActiveCaption;}
127 set { SetSystemColors("active_caption", value); }
130 public virtual Color ColorInactiveCaption {
131 get { return SystemColors.InactiveCaption;}
132 set { SetSystemColors("inactive_caption", value); }
135 public virtual Color ColorMenu {
136 get { return SystemColors.Menu;}
137 set { SetSystemColors("menu", value); }
140 public virtual Color ColorWindow {
141 get { return SystemColors.Window;}
142 set { SetSystemColors("window", value); }
145 public virtual Color ColorWindowFrame {
146 get { return SystemColors.WindowFrame;}
147 set { SetSystemColors("window_frame", value); }
150 public virtual Color ColorMenuText {
151 get { return SystemColors.MenuText;}
152 set { SetSystemColors("menu_text", value); }
155 public virtual Color ColorWindowText {
156 get { return SystemColors.WindowText;}
157 set { SetSystemColors("window_text", value); }
160 public virtual Color ColorActiveCaptionText {
161 get { return SystemColors.ActiveCaptionText;}
162 set { SetSystemColors("active_caption_text", value); }
165 public virtual Color ColorActiveBorder {
166 get { return SystemColors.ActiveBorder;}
167 set { SetSystemColors("active_border", value); }
170 public virtual Color ColorInactiveBorder{
171 get { return SystemColors.InactiveBorder;}
172 set { SetSystemColors("inactive_border", value); }
175 public virtual Color ColorAppWorkspace {
176 get { return SystemColors.AppWorkspace;}
177 set { SetSystemColors("app_workspace", value); }
180 public virtual Color ColorHighlight {
181 get { return SystemColors.Highlight;}
182 set { SetSystemColors("highlight", value); }
185 public virtual Color ColorHighlightText {
186 get { return SystemColors.HighlightText;}
187 set { SetSystemColors("highlight_text", value); }
190 public virtual Color ColorControl {
191 get { return SystemColors.Control;}
192 set { SetSystemColors("control", value); }
195 public virtual Color ColorControlDark {
196 get { return SystemColors.ControlDark;}
197 set { SetSystemColors("control_dark", value); }
200 public virtual Color ColorGrayText {
201 get { return SystemColors.GrayText;}
202 set { SetSystemColors("gray_text", value); }
205 public virtual Color ColorControlText {
206 get { return SystemColors.ControlText;}
207 set { SetSystemColors("control_text", value); }
210 public virtual Color ColorInactiveCaptionText {
211 get { return SystemColors.InactiveCaptionText;}
212 set { SetSystemColors("inactive_caption_text", value); }
215 public virtual Color ColorControlLight {
216 get { return SystemColors.ControlLight;}
217 set { SetSystemColors("control_light", value); }
220 public virtual Color ColorControlDarkDark {
221 get { return SystemColors.ControlDarkDark;}
222 set { SetSystemColors("control_dark_dark", value); }
225 public virtual Color ColorControlLightLight {
226 get { return SystemColors.ControlLightLight;}
227 set { SetSystemColors("control_light_light", value); }
230 public virtual Color ColorInfoText {
231 get { return SystemColors.InfoText;}
232 set { SetSystemColors("info_text", value); }
235 public virtual Color ColorInfo {
236 get { return SystemColors.Info;}
237 set { SetSystemColors("info", value); }
240 public virtual Color ColorHotTrack {
241 get { return SystemColors.HotTrack;}
242 set { SetSystemColors("hot_track", value);}
245 public virtual Color DefaultControlBackColor {
246 get { return ColorControl; }
247 set { ColorControl = value; }
250 public virtual Color DefaultControlForeColor {
251 get { return ColorControlText; }
252 set { ColorControlText = value; }
255 public virtual Font DefaultFont {
256 get { return default_font; }
259 public virtual Color DefaultWindowBackColor {
260 get { return defaultWindowBackColor; }
263 public virtual Color DefaultWindowForeColor {
264 get { return defaultWindowForeColor; }
267 public virtual Color GetColor (XplatUIWin32.GetSysColorIndex idx)
269 return (Color) syscolors.GetValue ((int)idx);
272 public virtual void SetColor (XplatUIWin32.GetSysColorIndex idx, Color color)
274 syscolors.SetValue (color, (int) idx);
277 // Theme/UI specific defaults
278 public virtual ArrangeDirection ArrangeDirection {
280 return ArrangeDirection.Down;
284 public virtual ArrangeStartingPosition ArrangeStartingPosition {
286 return ArrangeStartingPosition.BottomLeft;
290 public virtual Size Border3DSize {
292 return new Size(2, 2);
296 public virtual Size BorderSize {
298 return new Size(1, 1);
302 public virtual Size CaptionButtonSize {
304 return new Size(18, 18);
308 public virtual int CaptionHeight {
310 return XplatUI.CaptionHeight;
314 public virtual Size DoubleClickSize {
316 return new Size(4, 4);
320 public virtual int DoubleClickTime {
326 public virtual Size FixedFrameBorderSize {
328 return new Size(3, 3);
332 public virtual Size FrameBorderSize {
334 return XplatUI.FrameBorderSize;
338 public virtual int HorizontalScrollBarArrowWidth {
344 public virtual int HorizontalScrollBarHeight {
350 public virtual int HorizontalScrollBarThumbWidth {
356 public virtual Size IconSpacingSize {
358 return new Size(75, 75);
362 public virtual Size MenuButtonSize {
364 return new Size(18, 18);
368 public virtual Size MenuCheckSize {
370 return new Size(13, 13);
374 public virtual Font MenuFont {
380 public virtual int MenuHeight {
386 public virtual int MouseWheelScrollLines {
392 public virtual bool RightAlignedMenus {
398 public virtual Size ToolWindowCaptionButtonSize {
400 return new Size(15, 15);
404 public virtual int ToolWindowCaptionHeight {
410 public virtual int VerticalScrollBarArrowHeight {
416 public virtual int VerticalScrollBarThumbHeight {
422 public virtual int VerticalScrollBarWidth {
427 #region Principal Theme Methods
428 // 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)
429 public abstract void ResetDefaults();
431 // If the theme writes directly to a window instead of a device context
432 public abstract bool DoubleBufferingSupported {get;}
433 #endregion // Principal Theme Methods
435 #region OwnerDraw Support
436 public abstract void DrawOwnerDrawBackground (DrawItemEventArgs e);
437 public abstract void DrawOwnerDrawFocusRectangle (DrawItemEventArgs e);
438 #endregion // OwnerDraw Support
445 public abstract void DrawButtonBase(Graphics dc, Rectangle clip_area, ButtonBase button);
448 public abstract Size ButtonBaseDefaultSize{get;}
449 #endregion // ButtonBase
452 public abstract void DrawCheckBox(Graphics dc, Rectangle clip_area, CheckBox checkbox);
453 #endregion // CheckBox
455 #region CheckedListBox
457 public abstract void DrawCheckedListBoxItem (CheckedListBox ctrl, DrawItemEventArgs e);
458 public abstract Rectangle CheckedListBoxCheckRectangle ();
459 #endregion // CheckedListBox
463 public abstract void DrawComboBoxEditDecorations (Graphics dc, ComboBox ctrl, Rectangle rect);
464 public abstract void DrawComboListBoxDecorations (Graphics dc, ComboBox ctrl, Rectangle rect);
465 public abstract void DrawComboBoxItem (ComboBox ctrl, DrawItemEventArgs e);
468 public abstract int DrawComboBoxEditDecorationTop ();
469 public abstract int DrawComboBoxEditDecorationBottom ();
470 public abstract int DrawComboBoxEditDecorationRight ();
471 public abstract int DrawComboBoxEditDecorationLeft ();
472 public abstract int DrawComboListBoxDecorationTop (ComboBoxStyle style);
473 public abstract int DrawComboListBoxDecorationBottom (ComboBoxStyle style);
474 public abstract int DrawComboListBoxDecorationRight (ComboBoxStyle style);
475 public abstract int DrawComboListBoxDecorationLeft (ComboBoxStyle style);
476 #endregion // ComboBox
479 #endregion // Control
482 public abstract int DataGridPreferredColumnWidth { get; }
483 public abstract int DataGridMinimumColumnCheckBoxHeight { get; }
484 public abstract int DataGridMinimumColumnCheckBoxWidth { get; }
487 public abstract Color DataGridAlternatingBackColor { get; }
488 public abstract Color DataGridBackColor { get; }
489 public abstract Color DataGridBackgroundColor { get; }
490 public abstract Color DataGridCaptionBackColor { get; }
491 public abstract Color DataGridCaptionForeColor { get; }
492 public abstract Color DataGridGridLineColor { get; }
493 public abstract Color DataGridHeaderBackColor { get; }
494 public abstract Color DataGridHeaderForeColor { get; }
495 public abstract Color DataGridLinkColor { get; }
496 public abstract Color DataGridLinkHoverColor { get; }
497 public abstract Color DataGridParentRowsBackColor { get; }
498 public abstract Color DataGridParentRowsForeColor { get; }
499 public abstract Color DataGridSelectionBackColor { get; }
500 public abstract Color DataGridSelectionForeColor { get; }
502 public abstract void DataGridPaint (PaintEventArgs pe, DataGrid grid);
503 public abstract void DataGridPaintCaption (Graphics g, Rectangle clip, DataGrid grid);
504 public abstract void DataGridPaintColumnsHdrs (Graphics g, Rectangle clip, DataGrid grid);
505 public abstract void DataGridPaintRowsHeaders (Graphics g, Rectangle clip, DataGrid grid);
506 public abstract void DataGridPaintRowHeader (Graphics g, Rectangle bounds, int row, DataGrid grid);
507 public abstract void DataGridPaintRowHeaderArrow (Graphics g, Rectangle bounds, DataGrid grid);
508 public abstract void DataGridPaintRows (Graphics g, Rectangle cells, Rectangle clip, DataGrid grid);
509 public abstract void DataGridPaintRow (Graphics g, int row, Rectangle row_rect, bool is_newrow, DataGrid grid);
512 #endregion // Datagrid
514 #region DateTimePicker
516 public abstract void DrawDateTimePicker(Graphics dc, Rectangle clip_rectangle, DateTimePicker dtp);
518 #endregion // DateTimePicker
522 public abstract void DrawGroupBox (Graphics dc, Rectangle clip_area, GroupBox box);
525 public abstract Size GroupBoxDefaultSize{get;}
526 #endregion // GroupBox
529 public abstract Size HScrollBarDefaultSize{get;} // Default size of the scrollbar
530 #endregion // HScrollBar
534 public abstract void DrawLabel (Graphics dc, Rectangle clip_rectangle, Label label);
537 public abstract Size LabelDefaultSize{get;}
541 public abstract void DrawLinkLabel (Graphics dc, Rectangle clip_rectangle, LinkLabel label);
542 #endregion // LinkLabel
546 public abstract void DrawListBoxItem (ListBox ctrl, DrawItemEventArgs e);
547 #endregion // ListBox
551 public abstract void DrawListView (Graphics dc, Rectangle clip_rectangle, ListView control);
554 public abstract Size ListViewCheckBoxSize { get; }
555 public abstract int ListViewColumnHeaderHeight { get; }
556 public abstract int ListViewDefaultColumnWidth { get; }
557 public abstract int ListViewVerticalSpacing { get; }
558 public abstract int ListViewEmptyColumnWidth { get; }
559 public abstract int ListViewHorizontalSpacing { get; }
560 public abstract Size ListViewDefaultSize { get; }
561 #endregion // ListView
564 public abstract void CalcItemSize (Graphics dc, MenuAPI.MENUITEM item, int y, int x, bool menuBar);
565 public abstract void CalcPopupMenuSize (Graphics dc, IntPtr hMenu);
566 public abstract int CalcMenuBarSize (Graphics dc, IntPtr hMenu, int width);
567 public abstract void DrawMenuBar (Graphics dc, IntPtr hMenu, Rectangle rect);
568 public abstract void DrawMenuItem (MenuItem item, DrawItemEventArgs e);
569 public abstract void DrawPopupMenu (Graphics dc, IntPtr hMenu, Rectangle cliparea, Rectangle rect);
572 #region MonthCalendar
573 public abstract void DrawMonthCalendar(Graphics dc, Rectangle clip_rectangle, MonthCalendar month_calendar);
574 #endregion // MonthCalendar
578 public abstract Size PanelDefaultSize{get;}
583 public abstract void DrawPictureBox (Graphics dc, Rectangle clip, PictureBox pb);
586 public abstract Size PictureBoxDefaultSize{get;}
587 #endregion // PictureBox
591 public abstract void DrawProgressBar (Graphics dc, Rectangle clip_rectangle, ProgressBar progress_bar);
594 public abstract Size ProgressBarDefaultSize{get;}
595 #endregion // ProgressBar
599 public abstract void DrawRadioButton (Graphics dc, Rectangle clip_rectangle, RadioButton radio_button);
602 public abstract Size RadioButtonDefaultSize{get;}
603 #endregion // RadioButton
607 //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);
608 public abstract void DrawScrollBar (Graphics dc, Rectangle clip_rectangle, ScrollBar bar);
611 public abstract int ScrollBarButtonSize {get;} // Size of the scroll button
612 #endregion // ScrollBar
616 public abstract void DrawStatusBar (Graphics dc, Rectangle clip_rectangle, StatusBar sb);
619 public abstract int StatusBarSizeGripWidth {get;} // Size of Resize area
620 public abstract int StatusBarHorzGapWidth {get;} // Gap between panels
621 public abstract Size StatusBarDefaultSize{get;}
622 #endregion // StatusBar
625 public abstract Size TabControlDefaultItemSize { get; }
626 public abstract Point TabControlDefaultPadding { get; }
627 public abstract int TabControlMinimumTabWidth { get; }
629 public abstract Rectangle GetTabControlLeftScrollRect (TabControl tab);
630 public abstract Rectangle GetTabControlRightScrollRect (TabControl tab);
631 public abstract Rectangle GetTabControlDisplayRectangle (TabControl tab);
632 public abstract Size TabControlGetSpacing (TabControl tab);
633 public abstract void DrawTabControl (Graphics dc, Rectangle area, TabControl tab);
638 public abstract void DrawToolBar (Graphics dc, Rectangle clip_rectangle, ToolBar control);
641 public abstract int ToolBarGripWidth {get;} // Grip width for the ToolBar
642 public abstract int ToolBarImageGripWidth {get;} // Grip width for the Image on the ToolBarButton
643 public abstract int ToolBarSeparatorWidth {get;} // width of the separator
644 public abstract int ToolBarDropDownWidth { get; } // width of the dropdown arrow rect
645 public abstract int ToolBarDropDownArrowWidth { get; } // width for the dropdown arrow on the ToolBarButton
646 public abstract int ToolBarDropDownArrowHeight { get; } // height for the dropdown arrow on the ToolBarButton
647 public abstract Size ToolBarDefaultSize{get;}
648 #endregion // ToolBar
651 public abstract void DrawToolTip(Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control);
652 public abstract Size ToolTipSize(ToolTip.ToolTipWindow tt, string text);
653 #endregion // ToolTip
658 public abstract void DrawTrackBar (Graphics dc, Rectangle clip_rectangle, TrackBar tb);
661 public abstract Size TrackBarDefaultSize{get; } // Default size for the TrackBar control
662 #endregion // TrackBar
665 public abstract Size VScrollBarDefaultSize{get;} // Default size of the scrollbar
666 #endregion // VScrollBar
669 public abstract Size TreeViewDefaultSize { get; }
672 #region ControlPaint Methods
673 public abstract void CPDrawBorder (Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth,
674 ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
675 Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
676 int bottomWidth, ButtonBorderStyle bottomStyle);
678 public abstract void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides);
679 public abstract void CPDrawButton (Graphics graphics, Rectangle rectangle, ButtonState state);
680 public abstract void CPDrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state);
681 public abstract void CPDrawCheckBox (Graphics graphics, Rectangle rectangle, ButtonState state);
682 public abstract void CPDrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state);
683 public abstract void CPDrawContainerGrabHandle (Graphics graphics, Rectangle bounds);
684 public abstract void CPDrawFocusRectangle (Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor);
685 public abstract void CPDrawGrabHandle (Graphics graphics, Rectangle rectangle, bool primary, bool enabled);
686 public abstract void CPDrawGrid (Graphics graphics, Rectangle area, Size pixelsBetweenDots, Color backColor);
687 public abstract void CPDrawImageDisabled (Graphics graphics, Image image, int x, int y, Color background);
688 public abstract void CPDrawLockedFrame (Graphics graphics, Rectangle rectangle, bool primary);
689 public abstract void CPDrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph);
690 public abstract void CPDrawRadioButton (Graphics graphics, Rectangle rectangle, ButtonState state);
691 public abstract void CPDrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style);
692 public abstract void CPDrawReversibleLine (Point start, Point end, Color backColor);
693 public abstract void CPDrawScrollButton (Graphics graphics, Rectangle rectangle, ScrollButton button, ButtonState state);
694 public abstract void CPDrawSelectionFrame (Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect,
696 public abstract void CPDrawSizeGrip (Graphics graphics, Color backColor, Rectangle bounds);
697 public abstract void CPDrawStringDisabled (Graphics graphics, string s, Font font, Color color, RectangleF layoutRectangle,
698 StringFormat format);
699 public abstract void CPDrawBorderStyle (Graphics dc, Rectangle area, BorderStyle border_style);
700 #endregion // ControlPaint Methods