// Jonathan Pobst (monkey@jpobst.com)
//
-#if NET_2_0
using System.Drawing;
using System.Runtime.InteropServices;
using System.ComponentModel;
get { return this.owner_item; }
set { this.owner_item = value;
- if (this.owner_item != null)
+ if (this.owner_item != null) {
if (this.owner_item.Owner != null && this.owner_item.Owner.RenderMode != ToolStripRenderMode.ManagerRenderMode)
this.Renderer = this.owner_item.Owner.Renderer;
+
+ Font = owner_item.Font;
+ }
}
}
{
if (control == null)
throw new ArgumentNullException ("control");
-
+
+ XplatUI.SetOwner (Handle, control.Handle);
Show (control.PointToScreen (position), DefaultDropDownDirection);
}
this.PerformLayout ();
Point show_point = position;
- Point max_screen = new Point (SystemInformation.WorkingArea.Width, SystemInformation.WorkingArea.Height);
+ Point max_screen = new Point (SystemInformation.VirtualScreen.Width, SystemInformation.VirtualScreen.Height);
if (this is ContextMenuStrip) {
// If we are going to go offscreen, adjust our direction so we don't...
direction = ToolStripDropDownDirection.BelowRight;
break;
case ToolStripDropDownDirection.BelowLeft:
- if (show_point.Y + this.Height > max_screen.Y)
+ if (show_point.Y + this.Height > max_screen.Y && show_point.Y - this.Height > 0)
direction = ToolStripDropDownDirection.AboveLeft;
break;
case ToolStripDropDownDirection.BelowRight:
case ToolStripDropDownDirection.Default:
- if (show_point.Y + this.Height > max_screen.Y)
+ if (show_point.Y + this.Height > max_screen.Y && show_point.Y - this.Height > 0)
direction = ToolStripDropDownDirection.AboveRight;
break;
case ToolStripDropDownDirection.Left:
- if (show_point.Y + this.Height > max_screen.Y)
+ if (show_point.Y + this.Height > max_screen.Y && show_point.Y - this.Height > 0)
direction = ToolStripDropDownDirection.AboveLeft;
break;
case ToolStripDropDownDirection.Right:
- if (show_point.Y + this.Height > max_screen.Y)
+ if (show_point.Y + this.Height > max_screen.Y && show_point.Y - this.Height > 0)
direction = ToolStripDropDownDirection.AboveRight;
break;
}
break;
}
- // Fix offscreen positions
+ // Fix offscreen horizontal positions
if ((show_point.X + this.Width) > max_screen.X)
show_point.X = max_screen.X - this.Width;
if (show_point.X < 0)
show_point.X = 0;
-
+
+ // Fix offscreen vertical positions
+ if ((show_point.Y + this.Height) > max_screen.Y)
+ show_point.Y = max_screen.Y - this.Height;
+ if (show_point.Y < 0)
+ show_point.Y = 0;
+
if (this.Location != show_point)
this.Location = show_point;
if (control == null)
throw new ArgumentNullException ("control");
+ XplatUI.SetOwner (Handle, control.Handle);
Show (control.PointToScreen (position), direction);
}
#endregion
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) {
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) {
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));
- y += tsi.Height + tsi.Margin.Bottom;
+ tsi.SetBounds (new Rectangle (x, y, preferred_size.Width, height));
+ y += 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 ();
protected override void OnVisibleChanged (EventArgs e)
{
base.OnVisibleChanged (e);
+
+ if (owner_item != null && owner_item is ToolStripDropDownItem) {
+ ToolStripDropDownItem dropdown_owner = (ToolStripDropDownItem)owner_item;
+ if (Visible)
+ dropdown_owner.OnDropDownOpened (EventArgs.Empty);
+ else
+ dropdown_owner.OnDropDownClosed (EventArgs.Empty);
+ }
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
{
this.Close (reason);
base.Dismiss (reason);
+
+ // ContextMenuStrip won't have a parent
+ if (this.OwnerItem == null)
+ return;
+
+ // Ensure Submenu loes keyboard capture when closing.
+ ToolStripManager.SetActiveToolStrip (null, false);
}
internal override ToolStrip GetTopLevelToolStrip ()
case Keys.Escape:
this.Dismiss (ToolStripDropDownCloseReason.Keyboard);
+ // ContextMenuStrip won't have a parent
+ if (this.OwnerItem == null)
+ return true;
+
ToolStrip parent_strip = this.OwnerItem.Parent;
ToolStripManager.SetActiveToolStrip (parent_strip, true);
#endregion
}
}
-#endif