static private SetActiveToolStrip ( |
||
toolStrip | ||
keyboard | bool | |
return | void |
public void Show(Point position, ToolStripDropDownDirection direction) { this.PerformLayout(); Point show_point = CalculateShowPoint(position, direction, Size); if (this.Location != show_point) { this.Location = show_point; } // Prevents recursion if (Visible) { return; } CancelEventArgs e = new CancelEventArgs(); this.OnOpening(e); if (e.Cancel) { return; } // The tracker lets us know when the form is clicked or loses focus ToolStripManager.AppClicked += new EventHandler(ToolStripMenuTracker_AppClicked); ToolStripManager.AppFocusChange += new EventHandler(ToolStripMenuTracker_AppFocusChange); bool useNativeMenu = true; foreach (var item in this.Items) { useNativeMenu &= item is ToolStripMenuItem || item is ToolStripSeparator; } if (useNativeMenu) { currentMenu = ToNSMenu(); ((MonoMenuDelegate)currentMenu.Delegate).BeforePopup(); show_point = CalculateShowPoint(position, direction, new Size((int)currentMenu.Size.Width, (int)currentMenu.Size.Height)); NSApplication.SharedApplication.BeginInvokeOnMainThread(delegate { Size displaySize; XplatUI.GetDisplaySize(out displaySize); currentMenu.PopUpMenu(null, new CGPoint(show_point.X, displaySize.Height - show_point.Y), null); }); } base.Show(); ToolStripManager.SetActiveToolStrip(this, ToolStripManager.ActivatedByKeyboard); // Called from NSMenuDelegate for native menus if (!useNativeMenu) { this.OnOpened(EventArgs.Empty); } }
internal override void Dismiss(ToolStripDropDownCloseReason reason) { 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 bool ProcessArrowKey(Keys keyData) { switch (keyData) { case Keys.Down: case Keys.Tab: this.SelectNextToolStripItem(this.GetCurrentlySelectedItem(), true); return(true); case Keys.Up: case Keys.Shift | Keys.Tab: this.SelectNextToolStripItem(this.GetCurrentlySelectedItem(), false); return(true); case Keys.Right: this.GetTopLevelToolStrip().SelectNextToolStripItem(this.TopLevelOwnerItem, true); return(true); case Keys.Left: 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); if (parent_strip is MenuStrip && keyData == Keys.Left) { parent_strip.SelectNextToolStripItem(this.TopLevelOwnerItem, false); this.TopLevelOwnerItem.Invalidate(); } else if (parent_strip is MenuStrip && keyData == Keys.Escape) { (parent_strip as MenuStrip).MenuDroppedDown = false; this.TopLevelOwnerItem.Select(); } return(true); } return(false); }
internal override bool OnMenuKey() { // Set ourselves active and select our first item ToolStripManager.SetActiveToolStrip(this, true); ToolStripItem tsi = this.SelectNextToolStripItem(null, true); if (tsi == null) { return(false); } if (tsi is MdiControlStrip.SystemMenuItem) { this.SelectNextToolStripItem(tsi, true); } return(true); }
protected internal override bool ProcessMnemonic(char charCode) { if (!this.Selected) { this.Parent.ChangeSelection(this); } if (this.HasDropDownItems) { ToolStripManager.SetActiveToolStrip(this.Parent, true); this.ShowDropDown(); this.DropDown.SelectNextToolStripItem(null, true); } else { this.PerformClick(); } return(true); }
public void Show(Point position, ToolStripDropDownDirection direction) { this.PerformLayout(); Point show_point = position; 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... // X direction switch (direction) { case ToolStripDropDownDirection.AboveLeft: if (show_point.X - this.Width < 0) { direction = ToolStripDropDownDirection.AboveRight; } break; case ToolStripDropDownDirection.BelowLeft: if (show_point.X - this.Width < 0) { direction = ToolStripDropDownDirection.BelowRight; } break; case ToolStripDropDownDirection.Left: if (show_point.X - this.Width < 0) { direction = ToolStripDropDownDirection.Right; } break; case ToolStripDropDownDirection.AboveRight: if (show_point.X + this.Width > max_screen.X) { direction = ToolStripDropDownDirection.AboveLeft; } break; case ToolStripDropDownDirection.BelowRight: case ToolStripDropDownDirection.Default: if (show_point.X + this.Width > max_screen.X) { direction = ToolStripDropDownDirection.BelowLeft; } break; case ToolStripDropDownDirection.Right: if (show_point.X + this.Width > max_screen.X) { direction = ToolStripDropDownDirection.Left; } break; } // Y direction switch (direction) { case ToolStripDropDownDirection.AboveLeft: if (show_point.Y - this.Height < 0) { direction = ToolStripDropDownDirection.BelowLeft; } break; case ToolStripDropDownDirection.AboveRight: if (show_point.Y - this.Height < 0) { direction = ToolStripDropDownDirection.BelowRight; } break; case ToolStripDropDownDirection.BelowLeft: 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 && show_point.Y - this.Height > 0) { direction = ToolStripDropDownDirection.AboveRight; } break; case ToolStripDropDownDirection.Left: 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 && show_point.Y - this.Height > 0) { direction = ToolStripDropDownDirection.AboveRight; } break; } } switch (direction) { case ToolStripDropDownDirection.AboveLeft: show_point.Y -= this.Height; show_point.X -= this.Width; break; case ToolStripDropDownDirection.AboveRight: show_point.Y -= this.Height; break; case ToolStripDropDownDirection.BelowLeft: show_point.X -= this.Width; break; case ToolStripDropDownDirection.Left: show_point.X -= this.Width; break; case ToolStripDropDownDirection.Right: break; } // 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; } CancelEventArgs e = new CancelEventArgs(); this.OnOpening(e); if (e.Cancel) { return; } // The tracker lets us know when the form is clicked or loses focus ToolStripManager.AppClicked += new EventHandler(ToolStripMenuTracker_AppClicked); ToolStripManager.AppFocusChange += new EventHandler(ToolStripMenuTracker_AppFocusChange); base.Show(); ToolStripManager.SetActiveToolStrip(this, ToolStripManager.ActivatedByKeyboard); this.OnOpened(EventArgs.Empty); }
private void ShowInternal(Control control, Point screenPosition, ToolStripDropDownDirection direction) { this.PerformLayout(); Point show_point = CalculateShowPoint(screenPosition, direction, Size); if (this.Location != show_point) { this.Location = show_point; } // Prevents recursion if (Visible) { return; } SetSourceControl(control); CancelEventArgs e = new CancelEventArgs(); this.OnOpening(e); if (e.Cancel) { return; } // The tracker lets us know when the form is clicked or loses focus ToolStripManager.AppClicked += new EventHandler(ToolStripMenuTracker_AppClicked); ToolStripManager.AppFocusChange += new EventHandler(ToolStripMenuTracker_AppFocusChange); bool useNativeMenu = true; foreach (var item in this.Items) { useNativeMenu &= item is ToolStripMenuItem || item is ToolStripSeparator; } // Prevent closing native menus by the Application object - it would be too early, in MouseDown. // Native menus will close automatically, *after MouseUp*. This way, we can handle both // ways of selecting the item: mouse_down-move-mouse_up and click-move-click. ToolStripManager.DismissingHandledNatively = useNativeMenu; #if XAMARINMAC if (useNativeMenu) { currentMenu = ToNSMenu(); ((MonoMenuDelegate)currentMenu.Delegate).BeforePopup(); show_point = CalculateShowPoint(screenPosition, direction, new Size((int)currentMenu.Size.Width, (int)currentMenu.Size.Height)); PostMouseUp(control, show_point); NSApplication.SharedApplication.BeginInvokeOnMainThread(delegate { if (control != null) { var winPosition = control.PointToClient(show_point); currentMenu.PopUpMenu(null, new CGPoint(winPosition.X, winPosition.Y), control.Handle.ToNSView()); } else { Size displaySize; XplatUI.GetDisplaySize(out displaySize); currentMenu.PopUpMenu(null, new CGPoint(show_point.X, displaySize.Height - show_point.Y), null); } }); } #endif base.Show(); ToolStripManager.SetActiveToolStrip(this, ToolStripManager.ActivatedByKeyboard); // Called from NSMenuDelegate for native menus if (!useNativeMenu) { this.OnOpened(EventArgs.Empty); } }