Alex Shulgin wrote:
Jonathan Pobst wrote:
How about this one?
Yes, this patch fixes my issue.
Unfortunately, it breaks things elsewhere: see attached screenshot for
the sample.
I'm now trying to properly override CalcPreferredSize method in
ToolStripItem-derived classes to fix the whole issue. My progress on
this is, well... fair. ;)
BTW, lets not forget about ToolStripDropDownMenu--it has it's own
copy-pasted implementation of OnLayout method with minor changes.
Ok, this will get out of hand pretty quickly, so lets take little steps.
Attached is the same patch, except it moves your label1 back to the
left. If this one is ok with you, I'd like to go ahead and commit it.
I've been intentionally not touching ToolStripDropDownMenu because it
currently works, even though its not really done right. I was hoping if
I could get your stuff fixed, I could just leave it the way it is.
The issue is that we don't handle correctly is that setting
ShowCheckMargin or ShowImageMargin on ToolStripDropDownMenu updates the
Padding, which we don't do. Because I never knew where these values
came from, I have those hardcoded values all over the place. Fixing the
Padding issue causes just about every menustrip thing to break. (See
the attached patch: padding.patch.)
It is relatively safe to touch ToolStripDropDown.OnLayout because the
only thing that uses it is ToolStripOverflow, and of course anyone using
it directly.
Jonathan
Index: System.Windows.Forms/ToolStripDropDown.cs
===================================================================
--- System.Windows.Forms/ToolStripDropDown.cs (revision 128604)
+++ System.Windows.Forms/ToolStripDropDown.cs (working copy)
@@ -577,7 +577,7 @@
protected override void OnLayout (LayoutEventArgs e)
{
- // Find the widest menu item
+ // Find the widest menu item, so we know how wide to
make our dropdown
int widest = 0;
foreach (ToolStripItem tsi in this.Items) {
@@ -586,12 +586,13 @@
tsi.SetPlacement (ToolStripItemPlacement.Main);
- if (tsi.GetPreferredSize (Size.Empty).Width >
widest)
- widest = tsi.GetPreferredSize
(Size.Empty).Width;
+ widest = Math.Max (widest, tsi.GetPreferredSize
(Size.Empty).Width + tsi.Margin.Horizontal);
}
+ // Add any padding our dropdown has set
+ widest += this.Padding.Horizontal;
+
int x = this.Padding.Left;
- widest += 68 - this.Padding.Horizontal;
int y = this.Padding.Top;
foreach (ToolStripItem tsi in this.Items) {
@@ -602,16 +603,20 @@
int height = 0;
- if (tsi is ToolStripSeparator)
+ Size preferred_size = tsi.GetPreferredSize
(Size.Empty);
+
+ if (preferred_size.Height > 22)
+ height = preferred_size.Height;
+ else if (tsi is ToolStripSeparator)
height = 7;
else
height = 22;
- tsi.SetBounds (new Rectangle (x, y, widest,
height));
+ tsi.SetBounds (new Rectangle (x, y,
preferred_size.Width, height));
y += tsi.Height + tsi.Margin.Bottom;
}
- this.Size = new Size (widest + this.Padding.Horizontal,
y + this.Padding.Bottom);// + 2);
+ this.Size = new Size (widest, y + this.Padding.Bottom);
this.SetDisplayedItems ();
this.OnLayoutCompleted (EventArgs.Empty);
this.Invalidate ();
Index: System.Windows.Forms/ToolStripDropDownButton.cs
===================================================================
--- System.Windows.Forms/ToolStripDropDownButton.cs (revision 128604)
+++ System.Windows.Forms/ToolStripDropDownButton.cs (working copy)
@@ -104,7 +104,9 @@
#region Protected Methods
protected override ToolStripDropDown CreateDefaultDropDown ()
{
- return base.CreateDefaultDropDown ();
+ ToolStripDropDownMenu tsdd = new ToolStripDropDownMenu
();
+ tsdd.OwnerItem = this;
+ return tsdd;
}
protected override void OnMouseDown (MouseEventArgs e)
Index: System.Windows.Forms/ToolStripItem.cs
===================================================================
--- System.Windows.Forms/ToolStripItem.cs (revision 128604)
+++ System.Windows.Forms/ToolStripItem.cs (working copy)
@@ -1856,7 +1856,7 @@
return true;
if (!(this.Owner is ToolStripDropDownMenu))
- return true;
+ return false;
ToolStripDropDownMenu tsddm =
(ToolStripDropDownMenu)this.Owner;
@@ -1870,7 +1870,7 @@
return true;
if (!(this.Owner is ToolStripDropDownMenu))
- return true;
+ return false;
ToolStripDropDownMenu tsddm =
(ToolStripDropDownMenu)this.Owner;
Index: System.Windows.Forms/ToolStripDropDownMenu.cs
===================================================================
--- System.Windows.Forms/ToolStripDropDownMenu.cs (revision 128604)
+++ System.Windows.Forms/ToolStripDropDownMenu.cs (working copy)
@@ -71,6 +71,7 @@
set {
if (this.show_check_margin != value) {
this.show_check_margin = value;
+ CalculatePadding ();
PerformLayout (this, "ShowCheckMargin");
}
}
@@ -82,6 +83,7 @@
set {
if (this.show_image_margin != value) {
this.show_image_margin = value;
+ CalculatePadding ();
PerformLayout (this, "ShowImageMargin");
}
}
@@ -90,7 +92,7 @@
#region Protected Properties
protected override Padding DefaultPadding {
- get { return base.DefaultPadding; }
+ get { return new Padding (33, 2, 1, 2); }
}
protected internal override Size MaxItemSize {
@@ -187,6 +189,18 @@
return base.CalculateConnectedArea ();
}
+
+ private void CalculatePadding ()
+ {
+ int left = 8;
+
+ if (show_check_margin && show_image_margin)
+ left = 55;
+ else if (show_check_margin || show_image_margin)
+ left = 33;
+
+ Padding = new Padding (left, Padding.Top,
Padding.Right, Padding.Bottom);
+ }
#endregion
}
}
_______________________________________________
Mono-winforms-list maillist - Mono-winforms-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-winforms-list