2007-08-28 Jonathan Pobst <monkey@jpobst.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ThemeClearlooks.cs
index d3d9201503b4acdb770b896561fce204099f7b6a..d1dbafcce00dde70e6de7ee639ac3ff7efa4e2c0 100644 (file)
@@ -17,7 +17,7 @@
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-// Copyright (c) 2004-2005 Novell, Inc.
+// Copyright (c) 2006 Alexander Olk
 //
 // Authors:
 //     Alexander Olk, alex.olk@googlemail.com
@@ -73,7 +73,7 @@ namespace System.Windows.Forms {
                static readonly Color scrollbar_gradient_first_color = Color.FromArgb( 248, 247, 245 );
                static readonly Color scrollbar_gradient_second_color = Color.FromArgb( 234, 229, 224 );
                
-               static readonly Color arrow_color = Color.FromArgb( 16, 16, 16 );
+               new static readonly Color arrow_color = Color.FromArgb( 16, 16, 16 );
                
                static readonly Color tab_border_color = Color.FromArgb( 166, 151, 138 );
                static readonly Color tab_not_selected_gradient_first_color = Color.FromArgb( 227, 223, 220 );
@@ -95,7 +95,7 @@ namespace System.Windows.Forms {
                
                static readonly Color combobox_border_color = Color.FromArgb( 159, 146, 132 );
                static readonly Color combobox_focus_border_color = Color.FromArgb( 70, 91, 110 );
-               static readonly Color combobox_focus_inner_border_color = Color.FromArgb( 167, 198, 225 );
+               //static readonly Color combobox_focus_inner_border_color = Color.FromArgb( 167, 198, 225 );
                static readonly Color combobox_button_second_gradient_color = Color.FromArgb( 226, 220, 213 );
                
                static readonly Color progressbar_edge_dot_color = Color.FromArgb( 219, 212, 205 );
@@ -113,7 +113,7 @@ namespace System.Windows.Forms {
                static readonly Color trackbar_inner_second_gradient_color = Color.FromArgb( 223, 215, 208 );
                static readonly Color trackbar_inner_pressed_second_gradient_color = Color.FromArgb( 224, 217, 210 );
                
-               static readonly Color disabled_color_foreground = Color.FromArgb( 182, 180, 173 );
+               //static readonly Color disabled_color_foreground = Color.FromArgb( 182, 180, 173 );
                
                static readonly Color active_caption = Color.FromArgb( 85, 152, 215 );
                
@@ -121,17 +121,14 @@ namespace System.Windows.Forms {
                static readonly Color radio_button_dot_color = Color.FromArgb( 94, 160, 221 );
                
                const int SEPARATOR_HEIGHT = 7;
-               const int MENU_TAB_SPACE = 8;           // Pixels added to the width of an item because of a tab
-               const int MENU_BAR_ITEMS_SPACE = 8;     // Space between menu bar items
-               
-               int platform = (int) Environment.OSVersion.Platform;
+               const int MENU_TAB_SPACE = 8;           // Pixels added to the width of an item because of a tab
+               const int MENU_BAR_ITEMS_SPACE = 8;     // Space between menu bar items
                
                static Color control_parent_backcolor;
                
                #region Principal Theme Methods
                public ThemeClearlooks( ) {
                        ColorControl = theme_back_color;
-                       always_draw_hotkeys = true;
                }
                
                public override Color DefaultControlBackColor {
@@ -160,30 +157,38 @@ namespace System.Windows.Forms {
                        }
                }
                
+               public override Color ColorInfo {
+                       get { return Color.FromArgb (255, 255, 191); }
+               }
+               
+               static readonly Color info_border_color = Color.FromArgb (218, 178, 85);
+#if NET_2_0
+               static readonly Color info_second_color = Color.FromArgb (220, 220, 160);
+#endif 
                public override Image Images(UIIcon index, int size) {
                        switch (index) {
                        case UIIcon.PlacesRecentDocuments:
-                               if ((platform == 4) || (platform == 128))
+                               if (XplatUI.RunningOnUnix)
                                        return MimeIconEngine.GetIconForMimeTypeAndSize( "recently/recently", new Size(size, size) );
                                else
                                        return base.Images (UIIcon.PlacesRecentDocuments, size);
                        case UIIcon.PlacesDesktop:
-                               if ((platform == 4) || (platform == 128))
+                               if (XplatUI.RunningOnUnix)
                                        return MimeIconEngine.GetIconForMimeTypeAndSize( "desktop/desktop", new Size(size, size) );
                                else
                                        return base.Images (UIIcon.PlacesDesktop, size);
                        case UIIcon.PlacesPersonal:
-                               if ((platform == 4) || (platform == 128))
+                               if (XplatUI.RunningOnUnix)
                                        return MimeIconEngine.GetIconForMimeTypeAndSize( "directory/home", new Size(size, size) );
                                else
                                        return base.Images (UIIcon.PlacesPersonal, size);
                        case UIIcon.PlacesMyComputer:
-                               if ((platform == 4) || (platform == 128))
+                               if (XplatUI.RunningOnUnix)
                                        return MimeIconEngine.GetIconForMimeTypeAndSize( "workplace/workplace", new Size(size, size) );
                                else
                                        return base.Images (UIIcon.PlacesMyComputer, size);
                        case UIIcon.PlacesMyNetwork:
-                               if ((platform == 4) || (platform == 128))
+                               if (XplatUI.RunningOnUnix)
                                        return MimeIconEngine.GetIconForMimeTypeAndSize( "network/network", new Size(size, size) );
                                else
                                        return base.Images (UIIcon.PlacesMyNetwork, size);
@@ -196,7 +201,7 @@ namespace System.Windows.Forms {
                                
                                // misc Icons
                        case UIIcon.NormalFolder:
-                               if ((platform == 4) || (platform == 128))
+                               if (XplatUI.RunningOnUnix)
                                        return MimeIconEngine.GetIconForMimeTypeAndSize( "inode/directory", new Size(size, size) );
                                else
                                        return base.Images (UIIcon.NormalFolder, size);
@@ -239,7 +244,7 @@ namespace System.Windows.Forms {
                        if (form != null && (form.AcceptButton == button as IButtonControl))
                                paint_acceptbutton_black_border = true;
                        
-                       CL_Draw_Button(dc, button.ClientRectangle, button.flat_style,
+                       CL_Draw_Button(dc, button.ClientRectangle, button.FlatStyle,
                                          button.is_entered, button.is_enabled, button.is_pressed,
                                          first_gradient_color, second_gradient_color,
                                          paint_acceptbutton_black_border);
@@ -384,7 +389,7 @@ namespace System.Windows.Forms {
                
                protected override void ButtonBase_DrawFocus( ButtonBase button, Graphics dc ) {
                        
-                       if ( !button.is_enabled || button.flat_style == FlatStyle.Popup )
+                       if ( !button.is_enabled || button.FlatStyle == FlatStyle.Popup )
                                return;
                        
                        Pen pen = ResPool.GetPen( button_focus_color );
@@ -1003,7 +1008,7 @@ namespace System.Windows.Forms {
                                dc.FillRectangle( ResPool.GetSolidBrush( tab.Parent.BackColor ), area );
                        else
                                dc.FillRectangle( ResPool.GetSolidBrush( tab.BackColor ), area );
-                       Rectangle panel_rect = GetTabPanelRectExt( tab );
+                       Rectangle panel_rect = TabControlGetPanelRect( tab );
                        
                        if ( tab.Appearance == TabAppearance.Normal ) {
                                
@@ -1090,14 +1095,14 @@ namespace System.Windows.Forms {
                        }
                        
                        if (tab.ShowSlider) {
-                               Rectangle right = GetTabControlRightScrollRect (tab);
-                               Rectangle left = GetTabControlLeftScrollRect (tab);
+                               Rectangle right = TabControlGetRightScrollRect (tab);
+                               Rectangle left = TabControlGetLeftScrollRect (tab);
                                CPDrawScrollButton (dc, right, ScrollButton.Right, tab.RightSliderState);
                                CPDrawScrollButton (dc, left, ScrollButton.Left, tab.LeftSliderState);
                        }
                }
                
-               protected override int DrawTab (Graphics dc, TabPage page, TabControl tab, Rectangle bounds, bool is_selected)
+               protected virtual int DrawTab (Graphics dc, TabPage page, TabControl tab, Rectangle bounds, bool is_selected)
                {
                        int FlatButtonSpacing = 8;
                        Rectangle interior;
@@ -1794,9 +1799,7 @@ namespace System.Windows.Forms {
                }
                
                #region ToolBar
-               public override bool ToolBarInvalidateEntireButton {
-                       get { return true; }
-               }
+
                #endregion // ToolBar
 
                #region GroupBox
@@ -3086,7 +3089,7 @@ namespace System.Windows.Forms {
                        CPDrawBorder3D( graphics, rectangle, style, sides, ColorControl );
                }
                
-               protected override void CPDrawBorder3D( Graphics dc, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color ) {
+               public override void CPDrawBorder3D( Graphics dc, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color ) {
                        // currently we don't take care of Border3DStyle or Border3DSide
                        
                        Pen tmp_pen = ResPool.GetPen( edge_bottom_inner_color );
@@ -3289,6 +3292,125 @@ namespace System.Windows.Forms {
                                dc.FillPie (buttonBrush, rectangle.X + lineWidth + lineWidth / 2, rectangle.Y + lineWidth + lineWidth / 2, (rectangle.Width - lineWidth * 2) / 3, (rectangle.Height - lineWidth * 2) / 3, 0, 359);
                        }
                }
+
+               #region ToolTip
+               public override void DrawToolTip (Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control)
+               {
+                       dc.FillRectangle(ResPool.GetSolidBrush (ColorInfo), control.ClientRectangle);
+                       dc.DrawRectangle(ResPool.GetPen (info_border_color), 0, 0, control.Width-1, control.Height-1);
+       
+                       TextFormatFlags flags = TextFormatFlags.HidePrefix | TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter;
+                       TextRenderer.DrawTextInternal (dc, control.Text, control.Font, control.ClientRectangle, this.ColorInfoText, flags, false);
+               }
+               #endregion      // ToolTip
+
+               #region BalloonWindow
+#if NET_2_0
+               NotifyIcon.BalloonWindow balloon_window;
+               
+               public override void ShowBalloonWindow (IntPtr handle, int timeout, string title, string text, ToolTipIcon icon)
+               {
+                       Control control = Control.FromHandle(handle);
+                       
+                       if (control == null)
+                               return;
+
+                       if (balloon_window != null) {
+                               balloon_window.Close ();
+                               balloon_window.Dispose ();
+                       }
+
+                       balloon_window = new NotifyIcon.BalloonWindow (handle);
+                       balloon_window.Title = title;
+                       balloon_window.Text = text;
+                       balloon_window.Icon = icon;
+                       balloon_window.Timeout = timeout;
+                       balloon_window.Show ();
+               }
+
+               private const int balloon_iconsize = 48;
+               private const int balloon_bordersize = 8; 
+               
+               public override void DrawBalloonWindow (Graphics dc, Rectangle clip, NotifyIcon.BalloonWindow control) 
+               {
+                       Brush solidbrush = ResPool.GetSolidBrush(this.ColorInfoText);
+                       Rectangle rect = control.ClientRectangle;
+                       int iconsize = (control.Icon == ToolTipIcon.None) ? 0 : balloon_iconsize;
+                       
+                       // Rectangle borders and background.
+                       dc.FillRectangle (ResPool.GetSolidBrush (ColorInfo), rect);
+                       dc.FillRectangle (ResPool.GetSolidBrush (info_second_color), new Rectangle (rect.X, rect.Y, (balloon_iconsize/2)+balloon_bordersize, rect.Height));
+                       dc.DrawRectangle (ResPool.GetPen (info_border_color), 0, 0, rect.Width - 1, rect.Height - 1);
+
+                       // Icon
+                       Image image;
+                       switch (control.Icon) {
+                               case ToolTipIcon.Info: {
+                                       image = ThemeEngine.Current.Images(UIIcon.MessageBoxInfo, balloon_iconsize);
+                                       break;
+                               }
+
+                               case ToolTipIcon.Warning: {
+                                       image = ThemeEngine.Current.Images(UIIcon.MessageBoxError, balloon_iconsize);
+                                       break;
+                               }
+
+                               case ToolTipIcon.Error: {
+                                       image = ThemeEngine.Current.Images(UIIcon.MessageBoxWarning, balloon_iconsize);
+                                       break;
+                               }
+                               
+                               default: {
+                                       image = null;
+                                       break;
+                               }
+                       }
+
+                       if (control.Icon != ToolTipIcon.None)
+                               dc.DrawImage (image, new Rectangle (balloon_bordersize, (2*balloon_bordersize)+7, iconsize, iconsize));
+                       
+                       // Title
+                       Rectangle titlerect = new Rectangle (rect.X + balloon_bordersize + (balloon_iconsize/2) + balloon_bordersize, 
+                                                                                               rect.Y + balloon_bordersize, 
+                                                                                               rect.Width - ((3 * balloon_bordersize) + (balloon_iconsize/2)), 
+                                                                                               rect.Height - (2 * balloon_bordersize));
+                       
+                       Font titlefont = new Font (control.Font.FontFamily, control.Font.Size, control.Font.Style | FontStyle.Bold, control.Font.Unit);
+                       dc.DrawString (control.Title, titlefont, solidbrush, titlerect, control.Format);
+                       
+                       // Text
+                       Rectangle textrect = new Rectangle (rect.X + (2 * balloon_bordersize) + balloon_iconsize, 
+                                                                                               rect.Y + balloon_bordersize, 
+                                                                                               rect.Width - ((2 * balloon_bordersize) + balloon_iconsize), 
+                                                                                               rect.Height - (2 * balloon_bordersize));
+
+                       StringFormat textformat = control.Format;
+                       textformat.LineAlignment = StringAlignment.Far;
+                       dc.DrawString (control.Text, control.Font, solidbrush, textrect, textformat);
+               }
+
+               public override Rectangle BalloonWindowRect (NotifyIcon.BalloonWindow control)
+               {
+                       Rectangle deskrect = Screen.GetWorkingArea (control);
+                       SizeF maxsize = new SizeF (250, 200);
+
+                       SizeF titlesize = TextRenderer.MeasureString (control.Title, control.Font, maxsize, control.Format);
+                       SizeF textsize = TextRenderer.MeasureString (control.Text, control.Font, maxsize, control.Format);
+                       
+                       if (textsize.Height < balloon_iconsize)
+                               textsize.Height = balloon_iconsize;
+                       
+                       Rectangle rect = new Rectangle ();
+                       rect.Height = (int) (titlesize.Height + textsize.Height + (3 * balloon_bordersize));
+                       rect.Width = (int) ((titlesize.Width > textsize.Width) ? titlesize.Width : textsize.Width) + (3 * balloon_bordersize) + balloon_iconsize;
+                       rect.X = deskrect.Width - rect.Width - 2;
+                       rect.Y = deskrect.Height - rect.Height - 2;
+                       
+                       return rect;
+               }
+#endif
+               #endregion      // BalloonWindow
+               
        } //class
 }