2006-03-21 Alexander Olk <alex.olk@googlemail.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ThemeWin32Classic.cs
index 1dcb7cceef22d1412815aadd0112ca4c1f3a6e2a..b4da2611af4cfc42953cdd59f0ca3609e0307854 100644 (file)
@@ -605,6 +605,11 @@ namespace System.Windows.Forms
                        }
                        
                        /* Place the text; to be compatible with Windows place it after the checkbox has been drawn */
+
+                       // Windows seems to not wrap text in certain situations, this matches as close as I could get it
+                       if ((float)(checkbox.Font.Height * 1.5f) > text_rectangle.Height) {
+                               text_format.FormatFlags |= StringFormatFlags.NoWrap;
+                       }
                        if (checkbox.Enabled) {
                                sb = ResPool.GetSolidBrush(checkbox.ForeColor);
                                dc.DrawString(checkbox.Text, checkbox.Font, sb, text_rectangle, text_format);                   
@@ -666,7 +671,7 @@ namespace System.Windows.Forms
                                                ControlPaint.DrawBorder(graphics, checkbox_rectangle, checkbox.ForeColor, ButtonBorderStyle.Solid);
                                        } else {
                                                // draw sunken effect
-                                               CPDrawBorder3D (graphics, checkbox_rectangle, Border3DStyle.SunkenInner, Border3DSide.All, checkbox.BackColor);
+                                               CPDrawBorder3D (graphics, checkbox_rectangle, Border3DStyle.SunkenInner, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, checkbox.BackColor);
                                        }
                                } else {
                                        graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);                           
@@ -1197,7 +1202,7 @@ namespace System.Windows.Forms
                        if (!dtp.ShowUpDown && clip_rectangle.IntersectsWith (dtp.ClientRectangle)) {
                                // draw the outer border
                                Rectangle button_bounds = dtp.ClientRectangle;
-                               this.CPDrawBorder3D (dc, button_bounds, Border3DStyle.Sunken, Border3DSide.All, dtp.BackColor);
+                               this.CPDrawBorder3D (dc, button_bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, dtp.BackColor);
                                
                                // deflate by the border width
                                if (clip_rectangle.IntersectsWith (dtp.drop_down_arrow_rect)) {
@@ -1407,31 +1412,16 @@ namespace System.Windows.Forms
 
                #region ListView
                // Drawing
-               public override void DrawListView (Graphics dc, Rectangle clip, ListView control)
+               public override void DrawListViewItems (Graphics dc, Rectangle clip, ListView control)
                {
-                       bool details = (control.View == View.Details);
-                       Rectangle client_area_nohdrs;                   
-                       DrawListViewHeader (dc, clip, control);
-                       
-                       if (details && control.HeaderStyle != ColumnHeaderStyle.None && control.Columns.Count > 0) {
-                               client_area_nohdrs = control.client_area;
-                               client_area_nohdrs.Y += control.Columns[0].Ht;
-                               client_area_nohdrs.Height -= control.Columns[0].Ht;
-                               dc.SetClip (client_area_nohdrs);                                
-                       } else
-                               dc.SetClip (control.client_area);
-                       
+                       bool details = control.View == View.Details;
+
                        dc.FillRectangle (ResPool.GetSolidBrush (control.BackColor), clip);                                             
-                                               
-                       // In case of details view draw the items only if
-                       // columns are non-zero                 
-                       if (!details || control.Columns.Count > 0) {
-                               int first = control.FirstVisibleIndex;  
-                               
-                               for (int i = first; i <= control.LastVisibleIndex; i ++) {                                      
-                                       if (clip.IntersectsWith (control.Items[i].GetBounds (ItemBoundsPortion.Entire)))
-                                               DrawListViewItem (dc, control, control.Items[i]);
-                               }                               
+                       int first = control.FirstVisibleIndex;  
+
+                       for (int i = first; i <= control.LastVisibleIndex; i ++) {                                      
+                               if (clip.IntersectsWith (control.Items[i].GetBounds (ItemBoundsPortion.Entire)))
+                                       DrawListViewItem (dc, control, control.Items [i]);
                        }       
                        
                        // draw the gridlines
@@ -1477,7 +1467,7 @@ namespace System.Windows.Forms
 
                }
                
-               private void DrawListViewHeader (Graphics dc, Rectangle clip, ListView control)
+               public override void DrawListViewHeader (Graphics dc, Rectangle clip, ListView control)
                {       
                        bool details = (control.View == View.Details);
                                
@@ -1497,6 +1487,8 @@ namespace System.Windows.Forms
                                                this.CPDrawButton (dc, rect, state);
                                                rect.X += 3;
                                                rect.Width -= 8;
+                                               if (rect.Width <= 0)
+                                                       continue;
                                                dc.DrawString (col.Text, DefaultFont,
                                                               ResPool.GetSolidBrush (ColorControlText),
                                                               rect, col.Format);
@@ -1505,14 +1497,40 @@ namespace System.Windows.Forms
                        }
                }
 
+               public override void DrawListViewHeaderDragDetails (Graphics dc, ListView view, ColumnHeader col, int target_x)
+               {
+                       Rectangle rect = col.Rect;
+                       rect.X -= view.h_marker;
+                       Color color = Color.FromArgb (0x7f, ColorControlDark.R, ColorControlDark.G, ColorControlDark.B);
+                       dc.FillRectangle (ResPool.GetSolidBrush (color), rect);
+                       rect.X += 3;
+                       rect.Width -= 8;
+                       if (rect.Width <= 0)
+                               return;
+                       color = Color.FromArgb (0x7f, ColorControlText.R, ColorControlText.G, ColorControlText.B);
+                       dc.DrawString (col.Text, DefaultFont, ResPool.GetSolidBrush (color), rect, col.Format);
+                       Pen pen = new Pen (ColorHighlight, 2);
+                       dc.DrawLine (pen, target_x, 0, target_x, col.Rect.Height);
+               }
+
                // draws the ListViewItem of the given index
                protected virtual void DrawListViewItem (Graphics dc, ListView control, ListViewItem item)
                {                               
+                       int col_offset;
+                       if (control.View == View.Details && control.Columns.Count > 0)
+                               col_offset = control.Columns [0].Rect.X;
+                       else
+                               col_offset = 0;
+                       
                        Rectangle rect_checkrect = item.CheckRectReal;
+                       rect_checkrect.X += col_offset;
                        Rectangle rect_iconrect = item.GetBounds (ItemBoundsPortion.Icon);
+                       rect_iconrect.X += col_offset;
                        Rectangle full_rect = item.GetBounds (ItemBoundsPortion.Entire);
+                       full_rect.X += col_offset;
                        Rectangle text_rect = item.GetBounds (ItemBoundsPortion.Label);                 
-                       
+                       text_rect.X += col_offset;
+
                        if (control.CheckBoxes) {
                                if (control.StateImageList == null) {
                                        // Make sure we've got at least a line width of 1
@@ -2404,7 +2422,7 @@ namespace System.Windows.Forms
                                dc.DrawRectangle (SystemPens.ControlDark, button_rect);
                        }
                        else {
-                               CPDrawBorder3D (dc, button_rect, Border3DStyle.Raised, Border3DSide.All);
+                               CPDrawBorder3D (dc, button_rect, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
                        }
                        // draw the arrow
                        dc.FillPolygon (SystemBrushes.ControlText, arrow_path);                 
@@ -2589,7 +2607,7 @@ namespace System.Windows.Forms
                        increment = block_width + space_betweenblocks;
 
                        /* Draw border */
-                       CPDrawBorder3D (dc, ctrl.ClientRectangle, Border3DStyle.SunkenInner, Border3DSide.All & ~Border3DSide.Middle, ColorControl);
+                       CPDrawBorder3D (dc, ctrl.ClientRectangle, Border3DStyle.SunkenInner, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom & ~Border3DSide.Middle, ColorControl);
                        
                        /* Draw Blocks */
                        block_rect = new Rectangle (client_area.X, client_area.Y, block_width, client_area.Height);
@@ -2803,8 +2821,6 @@ namespace System.Windows.Forms
                
                protected virtual void RadioButton_DrawText(RadioButton radio_button, Rectangle text_rectangle, Graphics dc, StringFormat text_format)
                {
-                       SolidBrush sb;
-                       
                        // offset the text if it's pressed and a button
                        if (radio_button.Appearance == Appearance.Button) {
                                if (radio_button.Checked || (radio_button.Capture && radio_button.FlatStyle != FlatStyle.Flat)) {
@@ -2816,11 +2832,14 @@ namespace System.Windows.Forms
                        } 
                        
                        /* Place the text; to be compatible with Windows place it after the radiobutton has been drawn */                       
-                       dc.DrawString (radio_button.Text, radio_button.Font, ResPool.GetSolidBrush (radio_button.ForeColor), text_rectangle, text_format);
-                       
+
+                       // Windows seems to not wrap text in certain situations, this matches as close as I could get it
+                       if ((float)(radio_button.Font.Height * 1.5f) > text_rectangle.Height) {
+                               text_format.FormatFlags |= StringFormatFlags.NoWrap;
+                       }
+
                        if (radio_button.Enabled) {
-                               sb = ResPool.GetSolidBrush(radio_button.ForeColor);
-                               dc.DrawString(radio_button.Text, radio_button.Font, sb, text_rectangle, text_format);
+                               dc.DrawString (radio_button.Text, radio_button.Font, ResPool.GetSolidBrush (radio_button.ForeColor), text_rectangle, text_format);
                        } else if (radio_button.FlatStyle == FlatStyle.Flat) {
                                dc.DrawString(radio_button.Text, radio_button.Font, ResPool.GetSolidBrush (ControlPaint.DarkDark (this.ColorControl)), text_rectangle, text_format);
                        } else {
@@ -3152,7 +3171,7 @@ namespace System.Windows.Forms
                                Border3DStyle border_style = Border3DStyle.SunkenInner;
                                if (panel.BorderStyle == StatusBarPanelBorderStyle.Raised)
                                        border_style = Border3DStyle.RaisedOuter;
-                               CPDrawBorder3D(dc, area, border_style, Border3DSide.All, panel.Parent.BackColor);
+                               CPDrawBorder3D(dc, area, border_style, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, panel.Parent.BackColor);
                        }
 
                        if (panel.Style == StatusBarPanelStyle.OwnerDraw) {
@@ -3377,9 +3396,9 @@ namespace System.Windows.Forms
                                }
 
                                if (is_selected) {
-                                       CPDrawBorder3D (dc, bounds, Border3DStyle.Sunken, Border3DSide.All);
+                                       CPDrawBorder3D (dc, bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
                                } else if (tab.Appearance != TabAppearance.FlatButtons) {
-                                       CPDrawBorder3D (dc, bounds, Border3DStyle.Raised, Border3DSide.All);
+                                       CPDrawBorder3D (dc, bounds, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
                                }
 
                                interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 4, bounds.Height - 4);
@@ -3507,7 +3526,7 @@ namespace System.Windows.Forms
                                return res;
                        }
 
-                       if (page.Focused) {
+                       if (page.parent.Focused && is_selected) {
                                CPDrawFocusRectangle (dc, interior, tab.ForeColor, tab.BackColor);
                        }
 
@@ -3587,7 +3606,7 @@ namespace System.Windows.Forms
                                        /* Draw the button frame, only if it is not a separator */
                                        if (flat) { 
                                                if (button.Pushed || button.Pressed) {
-                                                       CPDrawBorder3D (dc, buttonArea, Border3DStyle.SunkenOuter, Border3DSide.All, ColorControl);
+                                                       CPDrawBorder3D (dc, buttonArea, Border3DStyle.SunkenOuter, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, ColorControl);
                                                } else if (button.Hilight) {
                                                        dc.DrawRectangle (ResPool.GetPen (ColorControlText), buttonArea);
                                                        if (! ddRect.IsEmpty) {
@@ -3600,7 +3619,7 @@ namespace System.Windows.Forms
                                        else { // normal toolbar
                                                if (button.Pushed || button.Pressed) {
                                                        CPDrawBorder3D (dc, buttonArea, Border3DStyle.SunkenInner,
-                                                               Border3DSide.All, ColorControl);
+                                                               Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, ColorControl);
                                                        if (! ddRect.IsEmpty) {
                                                                CPDrawBorder3D (dc, ddRect, Border3DStyle.SunkenInner,
                                                                        Border3DSide.Left, ColorControl);
@@ -3609,7 +3628,7 @@ namespace System.Windows.Forms
                                                }
                                                else {
                                                        CPDrawBorder3D (dc, buttonArea, Border3DStyle.RaisedInner,
-                                                               Border3DSide.All, ColorControl);
+                                                               Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, ColorControl);
                                                        if (! ddRect.IsEmpty) {
                                                                CPDrawBorder3D (dc, ddRect, Border3DStyle.RaisedInner,
                                                                        Border3DSide.Left, ColorControl);
@@ -3830,6 +3849,7 @@ namespace System.Windows.Forms
                        float pixels_betweenticks;
                        const int space_from_right = 8;
                        const int space_from_left = 8;
+                       const int space_from_bottom = 11;
                        Rectangle area = tb.ClientRectangle;
                        
                        switch (tb.TickStyle)   {
@@ -3878,19 +3898,19 @@ namespace System.Windows.Forms
                        
                        /* Convert thumb position from mouse position to value*/
                        if (mouse_value) {
-                               
-                               if (value_pos >= channel_startpoint.Y)
-                                       value_pos = (int)(((float) (value_pos - channel_startpoint.Y)) / pixels_betweenticks);
+                               if (value_pos < thumb_area.Bottom)
+                                       value_pos = (int) ((thumb_area.Bottom - value_pos) / pixels_betweenticks);
                                else
                                        value_pos = 0;                  
 
                                if (value_pos + tb.Minimum > tb.Maximum)
                                        value_pos = tb.Maximum - tb.Minimum;
-                                
+
                                tb.Value = value_pos + tb.Minimum;
                        }                       
-                       
-                       thumb_pos.Y = channel_startpoint.Y + (int) (pixels_betweenticks * (float) value_pos);
+
+                       // thumb_pos.Y = channel_startpoint.Y ; // + (int) (pixels_betweenticks * (float) value_pos);
+                       thumb_pos.Y = thumb_area.Bottom - space_from_bottom - (int) (pixels_betweenticks * (float) value_pos);
                        
                        /* Draw thumb fixed 10x22 size */
                        thumb_pos.Width = 10;