merged Sys.Web.Services 2.0 support in my branch:
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / Theme.cs
index da34301d543656067c1552cac608d6f6b3f9ac59..b7bcaa73d8429daebbb7f3dbd39743b872cc3aba 100644 (file)
@@ -24,7 +24,6 @@
 //     Peter Dennis Bartok, pbartok@novell.com
 //
 
-
 using System.Collections;
 using System.Drawing;
 using System.Drawing.Drawing2D;
@@ -47,61 +46,112 @@ namespace System.Windows.Forms
                NormalFolder
        }
        
-       // Implements a pool of system resources        
+       internal struct CPColor {
+               internal Color Dark;
+               internal Color DarkDark;
+               internal Color Light;
+               internal Color LightLight;
+               
+               internal static CPColor Empty;
+       }
+       
+       // Implements a pool of system resources
        internal class SystemResPool
        {
                private Hashtable pens = new Hashtable ();
+               private Hashtable dashpens = new Hashtable ();
+               private Hashtable sizedpens = new Hashtable ();
                private Hashtable solidbrushes = new Hashtable ();
                private Hashtable hatchbrushes = new Hashtable ();
                private Hashtable uiImages = new Hashtable();
+               private Hashtable cpcolors = new Hashtable ();
                
                public SystemResPool () {}
                
                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 pen = new Pen (color);
+                               pen.DashStyle = dashStyle;
+                               dashpens [hash] = pen;
+                               return pen;
+                       }
+               }
+               
+               public Pen GetSizedPen (Color color, int size)
+               {
+                       string hash = color.ToString () + size;
+                       
+                       lock (sizedpens) {
+                               Pen res = sizedpens [hash] as Pen;
+                               if (res != null)
+                                       return res;
+                       
+                               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 ();
 
-                       HatchBrush brush = new HatchBrush (hatchStyle, foreColor, backColor);
-                       hatchbrushes.Add (hash, brush);
-                       return brush;
+                       lock (hatchbrushes) {
+                               if (hatchbrushes.Contains (hash))
+                                       return (HatchBrush) hatchbrushes[hash];
+
+                               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)
@@ -112,17 +162,48 @@ namespace System.Windows.Forms
                        
                        return image;
                }
+               
+               public CPColor GetCPColor (Color 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);
+                               
+                                       cpcolors.Add (color, cpcolor);
+
+                                       return cpcolor;
+                               }
+                       
+                               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 Color defaultWindowForeColor;
                protected bool always_draw_hotkeys = true;
                internal SystemResPool ResPool = new SystemResPool ();
-               private Type system_colors = Type.GetType("System.Drawing.SystemColors, System.Drawing");
+               private Type system_colors = Type.GetType ("System.Drawing.SystemColors, " + Consts.AssemblySystem_Drawing);
+
+               protected Theme ()
+               {
+#if NET_2_0
+                       default_font = SystemFonts.DefaultFont;
+#else
+                       default_font = new Font (FontFamily.GenericSansSerif, 8.25f);
+#endif
+               }
 
                private void SetSystemColors(string name, Color value) {
                        if (system_colors != null) {
@@ -142,7 +223,7 @@ namespace System.Windows.Forms
                        get;
                }
 
-               /* Default properties */                
+               /* Default properties */
                public virtual Color ColorScrollBar {
                        get { return SystemColors.ScrollBar;}
                        set { SetSystemColors("scroll_bar", value); }
@@ -288,7 +369,7 @@ namespace System.Windows.Forms
                }
 
                public virtual Color DefaultWindowBackColor {
-                       get { return defaultWindowBackColor; }                  
+                       get { return defaultWindowBackColor; }
                }
 
                public virtual Color DefaultWindowForeColor {
@@ -410,7 +491,7 @@ namespace System.Windows.Forms
 
                public virtual int MenuHeight {
                        get {
-                               return 19;
+                               return XplatUI.MenuHeight;
                        }
                }
 
@@ -455,7 +536,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) {
@@ -490,52 +584,45 @@ namespace System.Windows.Forms
                        }
                }
 
-               private Image GetSizedResourceImage(string name, int size) {
-                       
-                       Image image = ResPool.GetUIImage (name, size);
+               //
+               // This routine fetches images embedded as assembly resources (not
+               // resgen resources).  It optionally scales the image to fit the
+               // specified size x dimension (it adjusts y automatically to fit that).
+               //
+               private Image GetSizedResourceImage(string name, int width)
+               {
+                       Image image = ResPool.GetUIImage (name, width);
                        if (image != null)
                                return image;
                        
                        string  fullname;
 
-                       if (size > 0) {
-                               // Try name name_sizexsize
-                               fullname = String.Format("{0}_{1}x{1}", name, size);
-                               image = ResPool.GetUIImage (fullname, size);
-                               if (image != null)
-                                       return image;
-                               else {
-                                       image = (Image)Locale.GetResource(fullname);
-                                       if (image != null) {
-                                               ResPool.AddUIImage (image, fullname, size);
-                                               return image;
-                                       }
-                               }
-
-                               // Try name_size
-                               fullname = String.Format("{0}_{1}", name, size);
-                               image = ResPool.GetUIImage (fullname, size);
-                               if (image != null)
-                                       return image;
-                               else {
-                                       image = (Image)Locale.GetResource(fullname);
-                                       if (image != null) {
-                                               ResPool.AddUIImage (image, fullname, size);
-                                               return image;
-                                       }
-                               }
-                               
-                               image = (Image)Locale.GetResource(name);
-                               if (image != null) {
-                                       image = new Bitmap (image, new Size (size, size));
-                                       ResPool.AddUIImage (image, name, size);
+                       if (width > 0) {
+                               // Try name_width
+                               fullname = String.Format("{1}_{0}", name, width);
+                               image = ResourceImageLoader.Get (fullname);
+                               if (image != null){
+                                       ResPool.AddUIImage (image, name, width);
                                        return image;
                                }
                        }
 
                        // Just try name
-                       image = (Image)Locale.GetResource(name);
-                       ResPool.AddUIImage (image, name, size);
+                       image = ResourceImageLoader.Get (name);
+                       if (image == null)
+                               return null;
+                       
+                       ResPool.AddUIImage (image, name, 0);
+                       if (image.Width != width && width != 0){
+                               Console.Error.WriteLine ("warning: requesting icon that not been tuned {0}_{1} {2}", width, name, image.Width);
+                               int height = (image.Height * width)/image.Width;
+                               Bitmap b = new Bitmap (width, height);
+                               Graphics g = Graphics.FromImage (b);
+                               g.DrawImage (image, 0, 0, width, height);
+                               ResPool.AddUIImage (b, name, width);
+
+                               return b;
+                       }
                        return image;
                }
                
@@ -545,26 +632,35 @@ namespace System.Windows.Forms
                        
                public virtual Image Images(UIIcon index, int size) {
                        switch (index) {
-                               case UIIcon.PlacesRecentDocuments:      return GetSizedResourceImage ("last_open", size);
-                               case UIIcon.PlacesDesktop:              return GetSizedResourceImage ("desktop", size);
-                               case UIIcon.PlacesPersonal:             return GetSizedResourceImage ("folder_with_paper", size);
-                               case UIIcon.PlacesMyComputer:           return GetSizedResourceImage ("monitor-computer", size);
-                               case UIIcon.PlacesMyNetwork:            return GetSizedResourceImage ("monitor-planet", size);
+                               case UIIcon.PlacesRecentDocuments:
+                                       return GetSizedResourceImage ("document-open.png", size);
+                               case UIIcon.PlacesDesktop:
+                                       return GetSizedResourceImage ("user-desktop.png", size);
+                               case UIIcon.PlacesPersonal:
+                                       return GetSizedResourceImage ("user-home.png", size);
+                               case UIIcon.PlacesMyComputer:
+                                       return GetSizedResourceImage ("computer.png", size);
+                               case UIIcon.PlacesMyNetwork:
+                                       return GetSizedResourceImage ("folder-remote.png", size);
 
                                // Icons for message boxes
-                               case UIIcon.MessageBoxError:            return GetSizedResourceImage ("mbox_error.png", size);
-                               case UIIcon.MessageBoxInfo:             return GetSizedResourceImage ("mbox_info.png", size);
-                               case UIIcon.MessageBoxQuestion:         return GetSizedResourceImage ("mbox_question.png", size);
-                               case UIIcon.MessageBoxWarning:          return GetSizedResourceImage ("mbox_warn.png", size);
+                               case UIIcon.MessageBoxError:
+                                       return GetSizedResourceImage ("dialog-error.png", size);
+                               case UIIcon.MessageBoxInfo:
+                                       return GetSizedResourceImage ("dialog-information.png", size);
+                               case UIIcon.MessageBoxQuestion:
+                                       return GetSizedResourceImage ("dialog-question.png", size);
+                               case UIIcon.MessageBoxWarning:
+                                       return GetSizedResourceImage ("dialog-warning.png", size);
                                
                                // misc Icons
-                               case UIIcon.NormalFolder:               return GetSizedResourceImage ("folder", size);
+                               case UIIcon.NormalFolder:
+                                       return GetSizedResourceImage ("folder.png", size);
 
                                default: {
                                        throw new ArgumentException("Invalid Icon type requested", "index");
                                }
                        }
-                       return null;
                }
 
                public virtual Image Images(string mimetype, string extension, int size) {
@@ -600,26 +696,13 @@ namespace System.Windows.Forms
                #endregion      // CheckBox
                
                #region CheckedListBox
-               // Drawing              
+               // Drawing
                public abstract void DrawCheckedListBoxItem (CheckedListBox ctrl, DrawItemEventArgs e);
-               public abstract Rectangle CheckedListBoxCheckRectangle ();
                #endregion // CheckedListBox
                
                #region ComboBox
                // Drawing
-               public abstract void DrawComboBoxEditDecorations (Graphics dc, ComboBox ctrl, Rectangle rect);
-               public abstract void DrawComboListBoxDecorations (Graphics dc, ComboBox ctrl, Rectangle rect);
                public abstract void DrawComboBoxItem (ComboBox ctrl, DrawItemEventArgs e);
-               
-               // Sizing
-               public abstract int DrawComboBoxEditDecorationTop ();
-               public abstract int DrawComboBoxEditDecorationBottom ();
-               public abstract int DrawComboBoxEditDecorationRight ();
-               public abstract int DrawComboBoxEditDecorationLeft ();
-               public abstract int DrawComboListBoxDecorationTop (ComboBoxStyle style);
-               public abstract int DrawComboListBoxDecorationBottom (ComboBoxStyle style);
-               public abstract int DrawComboListBoxDecorationRight (ComboBoxStyle style);
-               public abstract int DrawComboListBoxDecorationLeft (ComboBoxStyle style);
                #endregion      // ComboBox
 
                #region Control
@@ -631,11 +714,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; }
@@ -648,13 +731,15 @@ namespace System.Windows.Forms
                // Paint                
                public abstract void DataGridPaint (PaintEventArgs pe, DataGrid grid);
                public abstract void DataGridPaintCaption (Graphics g, Rectangle clip, DataGrid grid);
-               public abstract void DataGridPaintColumnsHdrs (Graphics g, Rectangle clip, DataGrid grid);
-               public abstract void DataGridPaintRowsHeaders (Graphics g, Rectangle clip, DataGrid grid);
+               public abstract void DataGridPaintColumnHeaders (Graphics g, Rectangle clip, DataGrid grid);
+               public abstract void DataGridPaintRowContents (Graphics g, int row, Rectangle row_rect, bool is_newrow, Rectangle clip, DataGrid grid);
                public abstract void DataGridPaintRowHeader (Graphics g, Rectangle bounds, int row, DataGrid grid);
                public abstract void DataGridPaintRowHeaderArrow (Graphics g, Rectangle bounds, DataGrid grid);
+               public abstract void DataGridPaintParentRows (Graphics g, Rectangle bounds, DataGrid grid);
+               public abstract void DataGridPaintParentRow (Graphics g, Rectangle bounds, DataGridDataSource row, DataGrid grid);
                public abstract void DataGridPaintRows (Graphics g, Rectangle cells, Rectangle clip, DataGrid grid);
-               public abstract void DataGridPaintRow (Graphics g, int row, Rectangle row_rect, bool is_newrow, DataGrid grid);
-               
+               public abstract void DataGridPaintRow (Graphics g, int row, Rectangle row_rect, bool is_newrow, Rectangle clip, DataGrid grid);
+               public abstract void DataGridPaintRelationRow (Graphics g, int row, Rectangle row_rect, bool is_newrow, Rectangle clip, DataGrid grid);
                
                #endregion // Datagrid
 
@@ -690,12 +775,14 @@ 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
-               public abstract void DrawListView (Graphics dc, Rectangle clip_rectangle, ListView control);
+               public abstract void DrawListViewItems (Graphics dc, Rectangle clip_rectangle, ListView control);
+               public abstract void DrawListViewHeader (Graphics dc, Rectangle clip_rectangle, ListView control);
+               public abstract void DrawListViewHeaderDragDetails (Graphics dc, ListView control, ColumnHeader drag_column, int target_x);
 
                // Sizing
                public abstract Size ListViewCheckBoxSize { get; }
@@ -705,6 +792,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
@@ -713,7 +803,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
@@ -733,6 +823,12 @@ namespace System.Windows.Forms
                public abstract Size PictureBoxDefaultSize{get;}
                #endregion      // PictureBox
 
+               #region PrintPreviewControl
+               public abstract int PrintPreviewControlPadding{get;}
+               public abstract Size PrintPreviewControlGetPageSize (PrintPreviewControl preview);
+               public abstract void PrintPreviewControlPaint (PaintEventArgs pe, PrintPreviewControl preview, Size page_image_size);
+               #endregion      // PrintPreviewControl
+
                #region ProgressBar
                // Drawing
                public abstract void DrawProgressBar (Graphics dc, Rectangle clip_rectangle, ProgressBar progress_bar);
@@ -792,12 +888,13 @@ namespace System.Windows.Forms
                public abstract int ToolBarDropDownArrowWidth { get; }   // width for the dropdown arrow on the ToolBarButton
                public abstract int ToolBarDropDownArrowHeight { get; }  // height for the dropdown arrow on the ToolBarButton
                public abstract Size ToolBarDefaultSize{get;}
+               public abstract bool ToolBarInvalidateEntireButton { get; }
                #endregion      // ToolBar
 
                #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 TrackBar
@@ -816,6 +913,40 @@ namespace System.Windows.Forms
                public abstract Size TreeViewDefaultSize { get; }
                #endregion
 
+               public virtual void DrawManagedWindowDecorations (Graphics dc, Rectangle clip, InternalWindowManager wm)
+               {
+                       // Just making virtual for now so all the themes still build.
+               }
+
+               public virtual int ManagedWindowTitleBarHeight (InternalWindowManager wm)
+               {
+                       // Just making virtual for now so all the themes still build.
+                       return 15;
+               }
+
+               public virtual int ManagedWindowBorderWidth (InternalWindowManager wm)
+               {
+                       // Just making virtual for now so all the themes still build.
+                       return 3;
+               }
+
+               public virtual int ManagedWindowIconWidth (InternalWindowManager wm)
+               {
+                       // Just making virtual for now so all the themes still build.
+                       return ManagedWindowTitleBarHeight (wm) - 5;
+               }
+
+               public virtual Size ManagedWindowButtonSize (InternalWindowManager wm)
+               {
+                       // Just making virtual for now so all the themes still build.
+                       return new Size (10, 10);
+               }
+
+               public virtual void ManagedWindowSetButtonLocations (InternalWindowManager wm)
+               {
+                       // Just making virtual for now so all the themes still build.
+               }
+
                #region ControlPaint Methods
                public abstract void CPDrawBorder (Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth,
                        ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
@@ -833,7 +964,7 @@ namespace System.Windows.Forms
                public abstract void CPDrawGrid (Graphics graphics, Rectangle area, Size pixelsBetweenDots, Color backColor);
                public abstract void CPDrawImageDisabled (Graphics graphics, Image image, int x, int y, Color background);
                public abstract void CPDrawLockedFrame (Graphics graphics, Rectangle rectangle, bool primary);
-               public abstract void CPDrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph);
+               public abstract void CPDrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph, Color color);
                public abstract void CPDrawRadioButton (Graphics graphics, Rectangle rectangle, ButtonState state);
                public abstract void CPDrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style);
                public abstract void CPDrawReversibleLine (Point start, Point end, Color backColor);