Author: jpobst
Date: 2007-03-16 15:37:39 -0500 (Fri, 16 Mar 2007)
New Revision: 74490

Modified:
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStrip.cs
   
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripProfessionalRenderer.cs
   
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripSplitStackLayout.cs
Log:
2007-03-16  Jonathan Pobst  <[EMAIL PROTECTED]>

        * ToolStrip.cs, ToolStripProfessionalRenderer.cs,
        ToolStripSplitStackLayout.cs: Implement some basic vertical toolbar 
support.

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2007-03-16 20:35:50 UTC (rev 74489)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2007-03-16 20:37:39 UTC (rev 74490)
@@ -1,3 +1,8 @@
+2007-03-16  Jonathan Pobst  <[EMAIL PROTECTED]>
+
+       * ToolStrip.cs, ToolStripProfessionalRenderer.cs,
+       ToolStripSplitStackLayout.cs: Implement some basic vertical toolbar 
support.
+
 2007-03-16  Rolf Bjarne Kvinge <[EMAIL PROTECTED]> 
 
        * ButtonBase.cs, ToolStrip.cs, SendKeys.cs, TextRenderer.cs,

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStrip.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStrip.cs     
2007-03-16 20:35:50 UTC (rev 74489)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStrip.cs     
2007-03-16 20:37:39 UTC (rev 74490)
@@ -47,7 +47,6 @@
                private ToolStripDropDownDirection default_drop_down_direction;
                internal ToolStripItemCollection displayed_items;
                private Color fore_color;
-               private ToolStripGripDisplayStyle grip_display_style;
                private Padding grip_margin;
                private ToolStripGripStyle grip_style;
                private ImageList image_list;
@@ -90,7 +89,6 @@
                        this.Dock = this.DefaultDock;
                        base.Font = new Font ("Tahoma", 8.25f);
                        this.fore_color = Control.DefaultForeColor;
-                       this.grip_display_style = 
ToolStripGripDisplayStyle.Vertical;
                        this.grip_margin = this.DefaultGripMargin;
                        this.grip_style = ToolStripGripStyle.Visible;
                        this.image_scaling_size = new Size (16, 16);
@@ -180,10 +178,10 @@
                                        else
                                                return new Rectangle 
(this.GripRectangle.Right + this.GripMargin.Right, this.Padding.Top, this.Width 
- this.Padding.Horizontal - this.GripRectangle.Right - this.GripMargin.Right, 
this.Height - this.Padding.Vertical);
                                else
-                                       if (this.grip_style == 
ToolStripGripStyle.Hidden)
+                                       if (this.grip_style == 
ToolStripGripStyle.Hidden || this.layout_style == ToolStripLayoutStyle.Flow || 
this.layout_style == ToolStripLayoutStyle.Table)
                                                return new Rectangle 
(this.Padding.Left, this.Padding.Top, this.Width - this.Padding.Horizontal, 
this.Height - this.Padding.Vertical);
                                        else
-                                               return new Rectangle 
(this.Padding.Left, this.GripRectangle.Bottom + this.GripMargin.Bottom + 
this.Padding.Top, this.Width - this.Padding.Horizontal - 
this.GripRectangle.Right - this.GripMargin.Right, this.Height - 
this.Padding.Vertical);
+                                               return new Rectangle 
(this.Padding.Left, this.GripRectangle.Bottom + this.GripMargin.Bottom + 
this.Padding.Top, this.Width - this.Padding.Horizontal, this.Height - 
this.Padding.Vertical - this.GripRectangle.Bottom - this.GripMargin.Bottom);
                        }
                }
 
@@ -201,11 +199,11 @@
                                                case DockStyle.Top:
                                                case DockStyle.Bottom:
                                                case DockStyle.None:
-                                                       this.orientation = 
Orientation.Horizontal;
+                                                       this.LayoutStyle = 
ToolStripLayoutStyle.HorizontalStackWithOverflow;
                                                        break;
                                                case DockStyle.Left:
                                                case DockStyle.Right:
-                                                       this.orientation = 
Orientation.Vertical;
+                                                       this.LayoutStyle = 
ToolStripLayoutStyle.VerticalStackWithOverflow;
                                                        break;
                                        }
 
@@ -341,12 +339,24 @@
                                                throw new 
InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not 
valid for ToolStripLayoutStyle", value));
 
                                        this.layout_style = value;
-                                       
-                                       if (value == ToolStripLayoutStyle.Flow)
+
+                                       if (this.layout_style == 
ToolStripLayoutStyle.Flow)
                                                this.layout_engine = new 
FlowLayout ();
                                        else
                                                this.layout_engine = new 
ToolStripSplitStackLayout ();
 
+                                       if (this.layout_style == 
ToolStripLayoutStyle.StackWithOverflow) {
+                                               if (this.Dock == DockStyle.Left 
|| this.Dock == DockStyle.Right)
+                                                       this.layout_style = 
ToolStripLayoutStyle.VerticalStackWithOverflow;
+                                               else
+                                                       this.layout_style = 
ToolStripLayoutStyle.HorizontalStackWithOverflow;
+                                       }
+
+                                       if (this.layout_style == 
ToolStripLayoutStyle.HorizontalStackWithOverflow)
+                                               this.orientation = 
Orientation.Horizontal;
+                                       else if (this.layout_style == 
ToolStripLayoutStyle.VerticalStackWithOverflow)
+                                               this.orientation = 
Orientation.Vertical;
+                                               
                                        this.layout_settings = 
this.CreateLayoutSettings (value);
                                        
                                        this.PerformLayout ();
@@ -526,9 +536,10 @@
                
                protected override void Dispose (bool disposing)
                {
-                       ToolStripManager.RemoveToolStrip (this);
-                       
-                       base.Dispose (disposing);
+                       if (!IsDisposed) {
+                               ToolStripManager.RemoveToolStrip (this);
+                               base.Dispose (disposing);
+                       }
                }
                
                protected override void OnDockChanged (EventArgs e)
@@ -784,8 +795,8 @@
                                else
                                        e.Graphics.TranslateTransform (0, 2);
                        }
-                               
-                       this.Renderer.DrawGrip (new 
ToolStripGripRenderEventArgs (e.Graphics, this, this.GripRectangle, 
this.grip_display_style, this.grip_style));
+
+                       this.Renderer.DrawGrip (new 
ToolStripGripRenderEventArgs (e.Graphics, this, this.GripRectangle, 
this.GripDisplayStyle, this.grip_style));
                        e.Graphics.ResetTransform ();
                }
 
@@ -812,6 +823,11 @@
                        base.OnVisibleChanged (e);
                }
 
+               protected override bool ProcessCmdKey (ref Message msg, Keys 
keyData)
+               {
+                       return base.ProcessCmdKey (ref msg, keyData);
+               }
+               
                protected override void SetBoundsCore (int x, int y, int width, 
int height, BoundsSpecified specified)
                {
                        base.SetBoundsCore (x, y, width, height, specified);

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripProfessionalRenderer.cs
===================================================================
--- 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripProfessionalRenderer.cs
 2007-03-16 20:35:50 UTC (rev 74489)
+++ 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripProfessionalRenderer.cs
 2007-03-16 20:37:39 UTC (rev 74490)
@@ -273,32 +273,27 @@
                {
                        base.OnRenderOverflowButtonBackground (e);
 
-                       Rectangle paint_here = new Rectangle (e.Item.Width - 
11, 0, 11, e.Item.Height - 1);
-
+                       Rectangle paint_here;
+                       LinearGradientMode gradient_direction = 
e.ToolStrip.Orientation == Orientation.Vertical ? LinearGradientMode.Horizontal 
: LinearGradientMode.Vertical;
+                       
+                       if (e.ToolStrip.Orientation == Orientation.Horizontal)
+                               paint_here = new Rectangle (e.Item.Width - 11, 
0, 11, e.Item.Height - 1);
+                       else
+                               paint_here = new Rectangle (0, e.Item.Height - 
11, e.Item.Width - 1, 11);
+                       
                        // Paint gradient background
                        if (e.Item.Selected && !e.Item.Pressed)
-                               using (Brush b = new LinearGradientBrush 
(paint_here, this.ColorTable.ButtonSelectedGradientBegin, 
this.ColorTable.ButtonSelectedGradientEnd, LinearGradientMode.Vertical))
+                               using (Brush b = new LinearGradientBrush 
(paint_here, this.ColorTable.ButtonSelectedGradientBegin, 
this.ColorTable.ButtonSelectedGradientEnd, gradient_direction))
                                        e.Graphics.FillRectangle (b, 
paint_here);
                        else if (e.Item.Pressed)
-                               using (Brush b = new LinearGradientBrush 
(paint_here, this.ColorTable.ButtonPressedGradientBegin, 
this.ColorTable.ButtonPressedGradientEnd, LinearGradientMode.Vertical))
+                               using (Brush b = new LinearGradientBrush 
(paint_here, this.ColorTable.ButtonPressedGradientBegin, 
this.ColorTable.ButtonPressedGradientEnd, gradient_direction))
                                        e.Graphics.FillRectangle (b, 
paint_here);
                        else
-                               using (Brush b = new LinearGradientBrush 
(paint_here, this.ColorTable.OverflowButtonGradientBegin, 
this.ColorTable.OverflowButtonGradientEnd, LinearGradientMode.Vertical))
+                               using (Brush b = new LinearGradientBrush 
(paint_here, this.ColorTable.OverflowButtonGradientBegin, 
this.ColorTable.OverflowButtonGradientEnd, gradient_direction))
                                        e.Graphics.FillRectangle (b, 
paint_here);
 
-                       // Paint down arrow
-                       Point arrow_loc = new Point (paint_here.X + 2, 
paint_here.Bottom - 9);
-
-                       e.Graphics.DrawLine (Pens.White, arrow_loc.X + 1, 
arrow_loc.Y + 1, arrow_loc.X + 5, arrow_loc.Y + 1);
-                       e.Graphics.DrawLine (Pens.Black, arrow_loc.X, 
arrow_loc.Y, arrow_loc.X + 4, arrow_loc.Y);
-
-                       e.Graphics.DrawLine (Pens.White, arrow_loc.X + 3, 
arrow_loc.Y + 4, arrow_loc.X + 5, arrow_loc.Y + 4);
-                       e.Graphics.DrawLine (Pens.White, arrow_loc.X + 3, 
arrow_loc.Y + 5, arrow_loc.X + 4, arrow_loc.Y + 5);
-                       e.Graphics.DrawLine (Pens.White, arrow_loc.X + 3, 
arrow_loc.Y + 4, arrow_loc.X + 3, arrow_loc.Y + 6);
-
-                       e.Graphics.DrawLine (Pens.Black, arrow_loc.X, 
arrow_loc.Y + 3, arrow_loc.X + 4, arrow_loc.Y + 3);
-                       e.Graphics.DrawLine (Pens.Black, arrow_loc.X + 1, 
arrow_loc.Y + 4, arrow_loc.X + 3, arrow_loc.Y + 4);
-                       e.Graphics.DrawLine (Pens.Black, arrow_loc.X + 2, 
arrow_loc.Y + 4, arrow_loc.X + 2, arrow_loc.Y + 5);
+                       // Paint the arrow
+                       PaintOverflowArrow (e, paint_here);
                }
 
                protected override void OnRenderSeparator 
(ToolStripSeparatorRenderEventArgs e)
@@ -427,6 +422,40 @@
                        base.OnRenderToolStripStatusLabelBackground (e);
                }
                #endregion
+
+               #region Private Methods
+               private static void PaintOverflowArrow 
(ToolStripItemRenderEventArgs e, Rectangle paint_here)
+               {
+                       if (e.ToolStrip.Orientation == Orientation.Horizontal) {
+                               // Paint down arrow
+                               Point arrow_loc = new Point (paint_here.X + 2, 
paint_here.Bottom - 9);
+
+                               e.Graphics.DrawLine (Pens.White, arrow_loc.X + 
1, arrow_loc.Y + 1, arrow_loc.X + 5, arrow_loc.Y + 1);
+                               e.Graphics.DrawLine (Pens.Black, arrow_loc.X, 
arrow_loc.Y, arrow_loc.X + 4, arrow_loc.Y);
+
+                               e.Graphics.DrawLine (Pens.White, arrow_loc.X + 
3, arrow_loc.Y + 4, arrow_loc.X + 5, arrow_loc.Y + 4);
+                               e.Graphics.DrawLine (Pens.White, arrow_loc.X + 
3, arrow_loc.Y + 5, arrow_loc.X + 4, arrow_loc.Y + 5);
+                               e.Graphics.DrawLine (Pens.White, arrow_loc.X + 
3, arrow_loc.Y + 4, arrow_loc.X + 3, arrow_loc.Y + 6);
+
+                               e.Graphics.DrawLine (Pens.Black, arrow_loc.X, 
arrow_loc.Y + 3, arrow_loc.X + 4, arrow_loc.Y + 3);
+                               e.Graphics.DrawLine (Pens.Black, arrow_loc.X + 
1, arrow_loc.Y + 4, arrow_loc.X + 3, arrow_loc.Y + 4);
+                               e.Graphics.DrawLine (Pens.Black, arrow_loc.X + 
2, arrow_loc.Y + 4, arrow_loc.X + 2, arrow_loc.Y + 5);
+                       } else {
+                               Point arrow_loc = new Point (paint_here.Right - 
9, paint_here.Y + 2);
+
+                               e.Graphics.DrawLine (Pens.White, arrow_loc.X + 
1, arrow_loc.Y + 1, arrow_loc.X + 1, arrow_loc.Y + 5);
+                               e.Graphics.DrawLine (Pens.Black, arrow_loc.X, 
arrow_loc.Y, arrow_loc.X, arrow_loc.Y + 4);
+
+                               e.Graphics.DrawLine (Pens.White, arrow_loc.X + 
4, arrow_loc.Y + 3, arrow_loc.X + 4, arrow_loc.Y + 5);
+                               e.Graphics.DrawLine (Pens.White, arrow_loc.X + 
5, arrow_loc.Y + 3, arrow_loc.X + 5, arrow_loc.Y + 4);
+                               e.Graphics.DrawLine (Pens.White, arrow_loc.X + 
4, arrow_loc.Y + 3, arrow_loc.X + 6, arrow_loc.Y + 3);
+
+                               e.Graphics.DrawLine (Pens.Black, arrow_loc.X + 
3, arrow_loc.Y, arrow_loc.X + 3, arrow_loc.Y + 4);
+                               e.Graphics.DrawLine (Pens.Black, arrow_loc.X + 
4, arrow_loc.Y + 1, arrow_loc.X + 4, arrow_loc.Y + 3);
+                               e.Graphics.DrawLine (Pens.Black, arrow_loc.X + 
4, arrow_loc.Y + 2, arrow_loc.X + 5, arrow_loc.Y + 2);
+                       }
+               }
+               #endregion
        }
 }
 #endif

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripSplitStackLayout.cs
===================================================================
--- 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripSplitStackLayout.cs
     2007-03-16 20:35:50 UTC (rev 74489)
+++ 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripSplitStackLayout.cs
     2007-03-16 20:37:39 UTC (rev 74490)
@@ -44,32 +44,14 @@
                                if (ts.Items == null)
                                        return false;
                                        
-                               if (ts.Orientation == Orientation.Horizontal) {
-                                       Rectangle ts_rect = ts.DisplayRectangle;
+                               Rectangle ts_rect = ts.DisplayRectangle;
                                        
+                               if (ts.Orientation == Orientation.Horizontal)   
                                
                                        LayoutHorizontalToolStrip (ts, ts_rect);
-                                       return false;
-                               } else {
-                                       int x = ts.DisplayRectangle.Left;
-                                       int y = ts.DisplayRectangle.Top + 2;
-
-                                       foreach (ToolStripItem tsi in ts.Items) 
{
-                                               if (!tsi.Visible)
-                                                       continue;
-                                               
-                                               Rectangle new_bounds = new 
Rectangle ();
-
-                                               y += tsi.Margin.Top;
-
-                                               new_bounds.Location = new Point 
(x + (tsi is ToolStripSeparator ? 0 : tsi.Margin.Left), y);
-                                               new_bounds.Width = 
ts.DisplayRectangle.Width - tsi.Margin.Horizontal - 3;
-                                               new_bounds.Height = 
tsi.GetPreferredSize (new Size (new_bounds.Width, 0)).Height;
-
-                                               tsi.SetBounds (new_bounds);
-
-                                               y += new_bounds.Height + 
tsi.Margin.Bottom;
-                                       }
-                               }
+                               else
+                                       LayoutVerticalToolStrip (ts, ts_rect);
+                                       
+                               return false;
                        } else  {
                                ToolStripContentPanel ts = 
(ToolStripContentPanel)container;
                                int x = ts.DisplayRectangle.Left;
@@ -166,6 +148,80 @@
                                i++;
                        }                       
                }
+
+               private void LayoutVerticalToolStrip (ToolStrip ts, Rectangle 
bounds)
+               {
+                       if (!ts.Visible) return;
+
+                       ToolStripItemOverflow[] overflow = new 
ToolStripItemOverflow[ts.Items.Count];
+                       ToolStripItemPlacement[] placement = new 
ToolStripItemPlacement[ts.Items.Count];
+                       Size proposedSize = new Size (bounds.Width, 0);
+                       int[] heights = new int[ts.Items.Count];
+                       int total_height = 0;
+                       int toolstrip_height = bounds.Height;
+                       int i = 0;
+                       bool can_overflow = ts.CanOverflow & !(ts is MenuStrip) 
& !(ts is StatusStrip);
+
+                       foreach (ToolStripItem tsi in ts.Items) {
+                               overflow[i] = tsi.Overflow;
+                               placement[i] = tsi.Overflow == 
ToolStripItemOverflow.Always ? ToolStripItemPlacement.Overflow : 
ToolStripItemPlacement.Main;
+                               heights[i] = tsi.GetPreferredSize 
(proposedSize).Height + tsi.Margin.Vertical;
+                               if (!tsi.Available)
+                                       placement[i] = 
ToolStripItemPlacement.None;
+                               total_height += placement[i] == 
ToolStripItemPlacement.Main ? heights[i] : 0;
+                               i++;
+                       }
+
+                       ts.OverflowButton.Visible = false;
+
+                       while (total_height > toolstrip_height) {
+                               // If we can overflow, get our overflow button 
setup, and subtract it's width
+                               // from our available width                     
        
+                               if (can_overflow && !ts.OverflowButton.Visible) 
{
+                                       ts.OverflowButton.Visible = true;
+                                       ts.OverflowButton.SetBounds (new 
Rectangle (0, ts.Height - 16,  ts.Width, 16));
+                                       toolstrip_height -= 
ts.OverflowButton.Height;
+                               }
+
+                               bool removed_one = false;
+
+                               // Start at the right, removing 
Overflow.AsNeeded first
+                               for (int j = heights.Length - 1; j >= 0; j--)
+                                       if (overflow[j] == 
ToolStripItemOverflow.AsNeeded && placement[j] == ToolStripItemPlacement.Main) {
+                                               placement[j] = 
ToolStripItemPlacement.Overflow;
+                                               total_height -= heights[j];
+                                               removed_one = true;
+                                               break;
+                                       }
+
+                               // If we didn't remove any AsNeeded ones, we 
have to start removing Never ones
+                               // These are not put on the Overflow, they are 
simply not shown
+                               if (!removed_one)
+                                       for (int j = heights.Length - 1; j >= 
0; j--)
+                                               if (overflow[j] == 
ToolStripItemOverflow.Never && placement[j] == ToolStripItemPlacement.Main) {
+                                                       placement[j] = 
ToolStripItemPlacement.None;
+                                                       total_height -= 
heights[j];
+                                                       removed_one = true;
+                                                       break;
+                                               }
+                       }
+
+                       i = 0;
+                       Point layout_pointer = new Point 
(ts.DisplayRectangle.Left, ts.DisplayRectangle.Top);
+                       int button_width = ts.DisplayRectangle.Width;
+
+                       // Now we should know where everything goes, so lay 
everything out
+                       foreach (ToolStripItem tsi in ts.Items) {
+                               tsi.SetPlacement (placement[i]);
+
+                               if (placement[i] == 
ToolStripItemPlacement.Main) {
+                                       tsi.SetBounds (new Rectangle 
(layout_pointer.X + tsi.Margin.Left, layout_pointer.Y + tsi.Margin.Top, 
button_width - tsi.Margin.Horizontal, heights[i] - tsi.Margin.Vertical));
+                                       layout_pointer.Y += heights[i];
+                               }
+
+                               i++;
+                       }
+               }
        }
 }
 #endif

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to