2007-04-25 Jonathan Pobst <monkey@jpobst.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / Theme.cs
index 82617862d0c90f858ac24bc9ecc6a1dcb08350d9..c6c221e647ab9453cd4d752cda5e365d0801e3fc 100644 (file)
@@ -24,7 +24,6 @@
 //     Peter Dennis Bartok, pbartok@novell.com
 //
 
-
 using System.Collections;
 using System.Drawing;
 using System.Drawing.Drawing2D;
@@ -56,7 +55,7 @@ namespace System.Windows.Forms
                internal static CPColor Empty;
        }
        
-       // Implements a pool of system resources        
+       // Implements a pool of system resources
        internal class SystemResPool
        {
                private Hashtable pens = new Hashtable ();
@@ -71,76 +70,88 @@ namespace System.Windows.Forms
                
                public Pen GetPen (Color color)
                {
-                       int hash = color.ToArgb ();                     
+                       int hash = color.ToArgb ();
 
-                       Pen res = pens [hash] as Pen;
-                       if (res != null)
-                               return res;
+                       lock (pens) {
+                               Pen res = pens [hash] as Pen;
+                               if (res != null)
+                                       return res;
                        
-                       Pen pen = new Pen (color);
-                       pens.Add (hash, pen);
-                       return pen;
+                               Pen pen = new Pen (color);
+                               pens.Add (hash, pen);
+                               return pen;
+                       }
                }
                
                public Pen GetDashPen (Color color, DashStyle dashStyle)
                {
                        string hash = color.ToString() + dashStyle;
+
+                       lock (dashpens) {
+                               Pen res = dashpens [hash] as Pen;
+                               if (res != null)
+                                       return res;
                        
-                       Pen res = dashpens [hash] as Pen;
-                       if (res != null)
-                               return res;
-                       
-                       Pen pen = new Pen (color);
-                       pen.DashStyle = dashStyle;
-                       dashpens [hash] = pen;
-                       return pen;
+                               Pen pen = new Pen (color);
+                               pen.DashStyle = dashStyle;
+                               dashpens [hash] = pen;
+                               return pen;
+                       }
                }
                
                public Pen GetSizedPen (Color color, int size)
                {
                        string hash = color.ToString () + size;
                        
-                       Pen res = sizedpens [hash] as Pen;
-                       if (res != null)
-                               return res;
+                       lock (sizedpens) {
+                               Pen res = sizedpens [hash] as Pen;
+                               if (res != null)
+                                       return res;
                        
-                       Pen pen = new Pen (color, size);
-                       sizedpens [hash] = pen;
-                       return pen;
+                               Pen pen = new Pen (color, size);
+                               sizedpens [hash] = pen;
+                               return pen;
+                       }
                }
                
                public SolidBrush GetSolidBrush (Color color)
                {
                        int hash = color.ToArgb ();
 
-                       SolidBrush res = solidbrushes [hash] as SolidBrush;
-                       if (res != null)
-                               return res;
+                       lock (solidbrushes) {
+                               SolidBrush res = solidbrushes [hash] as SolidBrush;
+                               if (res != null)
+                                       return res;
                        
-                       SolidBrush brush = new SolidBrush (color);
-                       solidbrushes.Add (hash, brush);
-                       return brush;
+                               SolidBrush brush = new SolidBrush (color);
+                               solidbrushes.Add (hash, brush);
+                               return brush;
+                       }
                }               
                
                public HatchBrush GetHatchBrush (HatchStyle hatchStyle, Color foreColor, Color backColor)
                {
-                       string hash = hatchStyle.ToString () + foreColor.ToString () + backColor.ToString ();                   
-                                               
-                       if (hatchbrushes.Contains (hash))
-                               return (HatchBrush) hatchbrushes[hash];                                                 
+                       string hash = hatchStyle.ToString () + foreColor.ToString () + backColor.ToString ();
+
+                       lock (hatchbrushes) {
+                               if (hatchbrushes.Contains (hash))
+                                       return (HatchBrush) hatchbrushes[hash];
 
-                       HatchBrush brush = new HatchBrush (hatchStyle, foreColor, backColor);
-                       hatchbrushes.Add (hash, brush);
-                       return brush;
+                               HatchBrush brush = new HatchBrush (hatchStyle, foreColor, backColor);
+                               hatchbrushes.Add (hash, brush);
+                               return brush;
+                       }
                }
                
                public void AddUIImage (Image image, string name, int size)
                {
                        string hash = name + size.ToString();
-                       
-                       if (uiImages.Contains (hash))
-                               return;
-                       uiImages.Add (hash, image);
+
+                       lock (uiImages) {
+                               if (uiImages.Contains (hash))
+                                       return;
+                               uiImages.Add (hash, image);
+                       }
                }
                
                public Image GetUIImage(string name, int size)
@@ -154,181 +165,190 @@ namespace System.Windows.Forms
                
                public CPColor GetCPColor (Color color)
                {
-                       object tmp = cpcolors [color];
+                       lock (cpcolors) {
+                               object tmp = cpcolors [color];
                        
-                       if (tmp == null) {
-                               CPColor cpcolor = new CPColor ();
-                               cpcolor.Dark = ControlPaint.Dark (color);
-                               cpcolor.DarkDark = ControlPaint.DarkDark (color);
-                               cpcolor.Light = ControlPaint.Light (color);
-                               cpcolor.LightLight = ControlPaint.LightLight (color);
+                               if (tmp == null) {
+                                       CPColor cpcolor = new CPColor ();
+                                       cpcolor.Dark = ControlPaint.Dark (color);
+                                       cpcolor.DarkDark = ControlPaint.DarkDark (color);
+                                       cpcolor.Light = ControlPaint.Light (color);
+                                       cpcolor.LightLight = ControlPaint.LightLight (color);
                                
-                               cpcolors.Add (color, cpcolor);
-                               
-                               return cpcolor;
-                       }
+                                       cpcolors.Add (color, cpcolor);
+
+                                       return cpcolor;
+                               }
                        
-                       return (CPColor)tmp;
+                               return (CPColor)tmp;
+                       }
                }
        }
 
        internal abstract class Theme
-       {               
+       {
                protected Array syscolors;
-               protected Font default_font;
+               private readonly Font default_font;
+               protected Font window_border_font;
                protected Color defaultWindowBackColor;
-               protected Color defaultWindowForeColor;         
-               protected bool always_draw_hotkeys = true;
+               protected Color defaultWindowForeColor;
                internal SystemResPool ResPool = new SystemResPool ();
-               private Type system_colors = Type.GetType("System.Drawing.SystemColors, System.Drawing");
+               private MethodInfo update;
 
-               private void SetSystemColors(string name, Color value) {
-                       if (system_colors != null) {
-                               MethodInfo update;
+               protected Theme ()
+               {
+#if NET_2_0
+                       default_font = SystemFonts.DefaultFont;
+#else
+                       default_font = new Font (FontFamily.GenericSansSerif, 8.25f);
+#endif
+               }
 
-                               system_colors.GetField(name, System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).SetValue(null, value);
-                               update = system_colors.GetMethod("UpdateColors", BindingFlags.Static | BindingFlags.NonPublic);
-                               if (update != null) {
-                                       update.Invoke(null, null);
-                               }
+               private void SetSystemColors (KnownColor kc, Color value)
+               {
+                       if (update == null) {
+                               Type known_colors = Type.GetType ("System.Drawing.KnownColors, " + Consts.AssemblySystem_Drawing);
+                               if (known_colors != null)
+                                       update = known_colors.GetMethod ("Update", BindingFlags.Static | BindingFlags.Public);
                        }
+                       if (update != null)
+                               update.Invoke (null, new object [2] { (int)kc, value.ToArgb () });
                }
 
-
                /* OS Feature support */
                public abstract Version Version {
                        get;
                }
 
-               /* Default properties */                
+               /* Default properties */
                public virtual Color ColorScrollBar {
-                       get { return SystemColors.ScrollBar;}
-                       set { SetSystemColors("scroll_bar", value); }
+                       get { return SystemColors.ScrollBar; }
+                       set { SetSystemColors (KnownColor.ScrollBar, value); }
                }
 
                public virtual Color ColorDesktop {
                        get { return SystemColors.Desktop;}
-                       set { SetSystemColors("desktop", value); }
+                       set { SetSystemColors (KnownColor.Desktop, value); }
                }
 
                public virtual Color ColorActiveCaption {
                        get { return SystemColors.ActiveCaption;}
-                       set { SetSystemColors("active_caption", value); }
+                       set { SetSystemColors (KnownColor.ActiveCaption, value); }
                }
 
                public virtual Color ColorInactiveCaption {
                        get { return SystemColors.InactiveCaption;}
-                       set { SetSystemColors("inactive_caption", value); }
+                       set { SetSystemColors (KnownColor.InactiveCaption, value); }
                }
 
                public virtual Color ColorMenu {
                        get { return SystemColors.Menu;}
-                       set { SetSystemColors("menu", value); }
+                       set { SetSystemColors (KnownColor.Menu, value); }
                }
 
                public virtual Color ColorWindow {
                        get { return SystemColors.Window;}
-                       set { SetSystemColors("window", value); }
+                       set { SetSystemColors (KnownColor.Window, value); }
                }
 
                public virtual Color ColorWindowFrame {
                        get { return SystemColors.WindowFrame;}
-                       set { SetSystemColors("window_frame", value); }
+                       set { SetSystemColors (KnownColor.WindowFrame, value); }
                }
 
                public virtual Color ColorMenuText {
                        get { return SystemColors.MenuText;}
-                       set { SetSystemColors("menu_text", value); }
+                       set { SetSystemColors (KnownColor.MenuText, value); }
                }
 
                public virtual Color ColorWindowText {
                        get { return SystemColors.WindowText;}
-                       set { SetSystemColors("window_text", value); }
+                       set { SetSystemColors (KnownColor.WindowText, value); }
                }
 
                public virtual Color ColorActiveCaptionText {
                        get { return SystemColors.ActiveCaptionText;}
-                       set { SetSystemColors("active_caption_text", value); }
+                       set { SetSystemColors (KnownColor.ActiveCaptionText, value); }
                }
 
                public virtual Color ColorActiveBorder {
                        get { return SystemColors.ActiveBorder;}
-                       set { SetSystemColors("active_border", value); }
+                       set { SetSystemColors (KnownColor.ActiveBorder, value); }
                }
 
                public virtual Color ColorInactiveBorder{
                        get { return SystemColors.InactiveBorder;}
-                       set { SetSystemColors("inactive_border", value); }
+                       set { SetSystemColors (KnownColor.InactiveBorder, value); }
                }
 
                public virtual Color ColorAppWorkspace {
                        get { return SystemColors.AppWorkspace;}
-                       set { SetSystemColors("app_workspace", value); }
+                       set { SetSystemColors (KnownColor.AppWorkspace, value); }
                }
 
                public virtual Color ColorHighlight {
                        get { return SystemColors.Highlight;}
-                       set { SetSystemColors("highlight", value); }
+                       set { SetSystemColors (KnownColor.Highlight, value); }
                }
 
                public virtual Color ColorHighlightText {
                        get { return SystemColors.HighlightText;}
-                       set { SetSystemColors("highlight_text", value); }
+                       set { SetSystemColors (KnownColor.HighlightText, value); }
                }
 
                public virtual Color ColorControl {
                        get { return SystemColors.Control;}
-                       set { SetSystemColors("control", value); }
+                       set { SetSystemColors (KnownColor.Control, value); }
                }
 
                public virtual Color ColorControlDark {
                        get { return SystemColors.ControlDark;}
-                       set { SetSystemColors("control_dark", value); }
+                       set { SetSystemColors (KnownColor.ControlDark, value); }
                }
 
                public virtual Color ColorGrayText {
                        get { return SystemColors.GrayText;}
-                       set { SetSystemColors("gray_text", value); }
+                       set { SetSystemColors (KnownColor.GrayText, value); }
                }
 
                public virtual Color ColorControlText {
                        get { return SystemColors.ControlText;}
-                       set { SetSystemColors("control_text", value); }
+                       set { SetSystemColors (KnownColor.ControlText, value); }
                }
 
                public virtual Color ColorInactiveCaptionText {
                        get { return SystemColors.InactiveCaptionText;}
-                       set { SetSystemColors("inactive_caption_text", value); }
+                       set { SetSystemColors (KnownColor.InactiveCaptionText, value); }
                }
 
                public virtual Color ColorControlLight {
                        get { return SystemColors.ControlLight;}
-                       set { SetSystemColors("control_light", value); }
+                       set { SetSystemColors (KnownColor.ControlLight, value); }
                }
 
                public virtual Color ColorControlDarkDark {
                        get { return SystemColors.ControlDarkDark;}
-                       set { SetSystemColors("control_dark_dark", value); }
+                       set { SetSystemColors (KnownColor.ControlDarkDark, value); }
                }
 
                public virtual Color ColorControlLightLight {
                        get { return SystemColors.ControlLightLight;}
-                       set { SetSystemColors("control_light_light", value); }
+                       set { SetSystemColors (KnownColor.ControlLightLight, value); }
                }
 
                public virtual Color ColorInfoText {
                        get { return SystemColors.InfoText;}
-                       set { SetSystemColors("info_text", value); }
+                       set { SetSystemColors (KnownColor.InfoText, value); }
                }
 
                public virtual Color ColorInfo {
                        get { return SystemColors.Info;}
-                       set { SetSystemColors("info", value); }
+                       set { SetSystemColors (KnownColor.Info, value); }
                }
 
                public virtual Color ColorHotTrack {
                        get { return SystemColors.HotTrack;}
-                       set { SetSystemColors("hot_track", value);}
+                       set { SetSystemColors (KnownColor.HotTrack, value);}
                }
 
                public virtual Color DefaultControlBackColor {
@@ -346,7 +366,7 @@ namespace System.Windows.Forms
                }
 
                public virtual Color DefaultWindowBackColor {
-                       get { return defaultWindowBackColor; }                  
+                       get { return defaultWindowBackColor; }
                }
 
                public virtual Color DefaultWindowForeColor {
@@ -376,21 +396,33 @@ namespace System.Windows.Forms
                        }
                }
 
+               public virtual Size BorderSizableSize {
+                       get {
+                               return new Size (3, 3);
+                       }
+               }
+
                public virtual Size Border3DSize {
                        get {
-                               return new Size(2, 2);
+                               return XplatUI.Border3DSize;
                        }
                }
 
-               public virtual Size BorderSize {
+               public virtual Size BorderStaticSize {
                        get {
                                return new Size(1, 1);
                        }
                }
 
+               public virtual Size BorderSize {
+                       get {
+                               return XplatUI.BorderSize;
+                       }
+               }
+
                public virtual Size CaptionButtonSize {
                        get {
-                               return new Size(18, 18);
+                               return XplatUI.CaptionButtonSize;
                        }
                }
 
@@ -414,7 +446,7 @@ namespace System.Windows.Forms
 
                public virtual Size FixedFrameBorderSize {
                        get {
-                               return new Size(3, 3);
+                               return XplatUI.FixedFrameBorderSize;
                        }
                }
 
@@ -448,6 +480,12 @@ namespace System.Windows.Forms
                        }
                }
 
+               public virtual bool MenuAccessKeysUnderlined {
+                       get {
+                               return XplatUI.MenuAccessKeysUnderlined;
+                       }
+               }
+               
                public virtual Size MenuButtonSize {
                        get {
                                return new Size(18, 18);
@@ -513,7 +551,20 @@ namespace System.Windows.Forms
                                return 16;
                        }
                }
-               
+
+               public virtual Font WindowBorderFont {
+                       get {
+                               return window_border_font;
+                       }
+               }
+
+               public int Clamp (int value, int lower, int upper)
+               {
+                       if (value < lower) return lower;
+                       else if (value > upper) return upper;
+                       else return value;
+               }
+
                [MonoTODO("Figure out where to point for My Network Places")]
                public virtual string Places(UIIcon index) {
                        switch (index) {
@@ -601,7 +652,7 @@ namespace System.Windows.Forms
                                case UIIcon.PlacesDesktop:
                                        return GetSizedResourceImage ("user-desktop.png", size);
                                case UIIcon.PlacesPersonal:
-                                       return GetSizedResourceImage ("document-open.png", size);
+                                       return GetSizedResourceImage ("user-home.png", size);
                                case UIIcon.PlacesMyComputer:
                                        return GetSizedResourceImage ("computer.png", size);
                                case UIIcon.PlacesMyNetwork:
@@ -645,6 +696,10 @@ namespace System.Windows.Forms
                #endregion      // OwnerDraw Support
 
                #region Button
+               public abstract void CalculateButtonTextAndImageLayout (Button b, out Rectangle textRectangle, out Rectangle imageRectangle);
+               public abstract void DrawButton (Graphics g, Button b, Rectangle textBounds, Rectangle imageBounds, Rectangle clipRectangle);
+               public abstract void DrawFlatButton (Graphics g, Button b, Rectangle textBounds, Rectangle imageBounds, Rectangle clipRectangle);
+               public abstract void DrawPopupButton (Graphics g, Button b, Rectangle textBounds, Rectangle imageBounds, Rectangle clipRectangle);
                #endregion      // Button
 
                #region ButtonBase
@@ -660,16 +715,18 @@ namespace System.Windows.Forms
                #endregion      // CheckBox
                
                #region CheckedListBox
-               // Drawing              
+               // Drawing
                public abstract void DrawCheckedListBoxItem (CheckedListBox ctrl, DrawItemEventArgs e);
                #endregion // CheckedListBox
                
                #region ComboBox
                // Drawing
                public abstract void DrawComboBoxItem (ComboBox ctrl, DrawItemEventArgs e);
+               public abstract void DrawFlatStyleComboButton (Graphics graphics, Rectangle rectangle, ButtonState state);
                #endregion      // ComboBox
 
                #region Control
+               public abstract Font GetLinkFont (Control control);
                #endregion      // Control
                
                #region Datagrid
@@ -678,11 +735,11 @@ namespace System.Windows.Forms
                public abstract int DataGridMinimumColumnCheckBoxWidth { get; }
                
                // Default colours
-               public abstract Color DataGridAlternatingBackColor { get; }             
-               public abstract Color DataGridBackColor { get; }                
+               public abstract Color DataGridAlternatingBackColor { get; }
+               public abstract Color DataGridBackColor { get; }
                public abstract Color DataGridBackgroundColor { get; }
                public abstract Color DataGridCaptionBackColor { get; }
-               public abstract Color DataGridCaptionForeColor { get; }         
+               public abstract Color DataGridCaptionForeColor { get; }
                public abstract Color DataGridGridLineColor { get; }
                public abstract Color DataGridHeaderBackColor { get; }
                public abstract Color DataGridHeaderForeColor { get; }
@@ -739,8 +796,8 @@ namespace System.Windows.Forms
                
                #region ListBox
                // Drawing
-               public abstract void DrawListBoxItem (ListBox ctrl, DrawItemEventArgs e);               
-               #endregion      // ListBox              
+               public abstract void DrawListBoxItem (ListBox ctrl, DrawItemEventArgs e);
+               #endregion      // ListBox
                
                #region ListView
                // Drawing
@@ -756,6 +813,9 @@ namespace System.Windows.Forms
                public abstract int ListViewEmptyColumnWidth { get; }
                public abstract int ListViewHorizontalSpacing { get; }
                public abstract Size ListViewDefaultSize { get; }
+               public abstract int ListViewGroupHeight { get; }
+               public abstract int ListViewTileWidthFactor { get; }
+               public abstract int ListViewTileHeightFactor { get; }
                #endregion      // ListView
                
                #region Menus
@@ -764,7 +824,7 @@ namespace System.Windows.Forms
                public abstract int CalcMenuBarSize (Graphics dc, Menu menu, int width);
                public abstract void DrawMenuBar (Graphics dc, Menu menu, Rectangle rect);
                public abstract void DrawMenuItem (MenuItem item, DrawItemEventArgs e);
-               public abstract void DrawPopupMenu (Graphics dc, Menu menu, Rectangle cliparea, Rectangle rect);                
+               public abstract void DrawPopupMenu (Graphics dc, Menu menu, Rectangle cliparea, Rectangle rect);
                #endregion      // Menus
 
                #region MonthCalendar
@@ -826,13 +886,21 @@ namespace System.Windows.Forms
                #endregion      // StatusBar
 
                #region TabControl
-               public abstract Size TabControlDefaultItemSize { get; }
-               public abstract Point TabControlDefaultPadding { get; }
-               public abstract int TabControlMinimumTabWidth { get; }
-
-               public abstract Rectangle GetTabControlLeftScrollRect (TabControl tab);
-               public abstract Rectangle GetTabControlRightScrollRect (TabControl tab);
-               public abstract Rectangle GetTabControlDisplayRectangle (TabControl tab);
+               public abstract Size TabControlDefaultItemSize {get; }
+               public abstract Point TabControlDefaultPadding {get; }
+               public abstract int TabControlMinimumTabWidth {get; }
+               public abstract Rectangle TabControlSelectedDelta { get; }
+               public abstract int TabControlSelectedSpacing { get; }
+               public abstract int TabPanelOffsetX { get; }
+               public abstract int TabPanelOffsetY { get; }
+               public abstract int TabControlColSpacing { get; }
+               public abstract Point TabControlImagePadding { get; }
+               public abstract int TabControlScrollerWidth { get; }
+
+               public abstract Rectangle TabControlGetLeftScrollRect (TabControl tab);
+               public abstract Rectangle TabControlGetRightScrollRect (TabControl tab);
+               public abstract Rectangle TabControlGetDisplayRectangle (TabControl tab);
+               public abstract Rectangle TabControlGetPanelRect (TabControl tab);
                public abstract Size TabControlGetSpacing (TabControl tab);
                public abstract void DrawTabControl (Graphics dc, Rectangle area, TabControl tab);
                #endregion
@@ -854,8 +922,15 @@ namespace System.Windows.Forms
                #region ToolTip
                public abstract void DrawToolTip(Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control);
                public abstract Size ToolTipSize(ToolTip.ToolTipWindow tt, string text);
-               #endregion      // ToolTip              
+               #endregion      // ToolTip
                
+               #region BalloonWindow
+#if NET_2_0
+               public abstract void ShowBalloonWindow (IntPtr handle, int timeout, string title, string text, ToolTipIcon icon);
+               public abstract void DrawBalloonWindow (Graphics dc, Rectangle clip, NotifyIcon.BalloonWindow control);
+               public abstract Rectangle BalloonWindowRect (NotifyIcon.BalloonWindow control);
+#endif
+               #endregion      // BalloonWindow
 
                #region TrackBar
                // Drawing
@@ -863,6 +938,8 @@ namespace System.Windows.Forms
 
                // Sizing
                public abstract Size TrackBarDefaultSize{get; }         // Default size for the TrackBar control
+               
+               public abstract int TrackBarValueFromMousePosition (int x, int y, TrackBar tb);
                #endregion      // TrackBar
 
                #region VScrollBar
@@ -914,6 +991,7 @@ namespace System.Windows.Forms
                        int bottomWidth, ButtonBorderStyle bottomStyle);
 
                public abstract void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides);
+               public abstract void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color);
                public abstract void CPDrawButton (Graphics graphics, Rectangle rectangle, ButtonState state);
                public abstract void CPDrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state);
                public abstract void CPDrawCheckBox (Graphics graphics, Rectangle rectangle, ButtonState state);