protected virtual void OnWindowlessNavigate(Control sender, WindowlessNavigateEventArgs e) { if (WindowlessNavigate != null) { WindowlessNavigate(sender, e); } }
protected override void OnWindowlessNavigate(Control sender, WindowlessNavigateEventArgs e) { if ((e.Key == Keys.Down || e.Key == Keys.Up) && e.Destination == null && !e.Handled) { e.Handled = true; e.Destination = myDropdownSource; } base.OnWindowlessNavigate(sender, e); }
protected override void OnWindowlessNavigatingTo(WindowlessControlHost sender, WindowlessNavigateEventArgs e) { base.OnWindowlessNavigatingTo(sender, e); if (sender != this) { return; } // if we have a selection already, just leave it if (myCurrentSelection != null) { return; } if (Items.Count == 0) { return; } Point me = WindowlessPointToForm(this, Point.Empty); Point other = WindowlessPointToForm(e.Source, Point.Empty); Rectangle otherRect = e.SourceRectangle; otherRect.X += other.X; otherRect.Y += other.Y; Rectangle rect = new Rectangle(otherRect.X - me.X, otherRect.Y - me.Y, otherRect.Width, otherRect.Height); NavigateSelection(rect, e.Key); }
/// <summary> /// If a key down event is unhandled, this will attempt to handle it by navigating or scrolling. /// </summary> /// <param name="control"></param> /// <param name="e"></param> static void OnWindowlessUnhandledKeyDown(Control control, KeyEventArgs e) { if (e.Handled) return; WindowlessControlHost host = control as WindowlessControlHost; switch (e.KeyCode) { case Keys.F19: case Keys.F20: case Keys.Up: case Keys.Down: case Keys.Left: case Keys.Right: { // attempt to navigate first Point p = WindowlessPointToForm(control, Point.Empty); Rectangle sourceRect; if (host != null) { sourceRect = host.GetNavigationSourceRectangle(); } else { sourceRect = new Rectangle(0, 0, control.Width, control.Height); } Rectangle rect = sourceRect; rect.X += p.X; rect.Y += p.Y; Control bestControl = null; Control topLevelControl = FormlessTopLevelControl(control); if (e.KeyCode == Keys.F19 || e.KeyCode == Keys.F20) { Control previous = null; Control next = null; bool found = false; RecurseControls(topLevelControl, (current) => { if (current == control) { found = true; return true; } if (!IsFocusable(current)) return true; if (!found) previous = current; next = current; return !found; }, null); if (e.KeyCode == Keys.F19) bestControl = previous; else bestControl = next; //WindowlessNavigateEventArgs ne = new WindowlessNavigateEventArgs(control, } else { ulong bestScore; bestControl = GetBestNavigationHost(rect, e.KeyCode, topLevelControl, control, out bestScore); } WindowlessNavigateEventArgs ne = new WindowlessNavigateEventArgs(control, sourceRect, e.KeyCode, bestControl); Control parent = control; while (parent != null) { WindowlessControlHost parentHost = parent as WindowlessControlHost; if (parentHost != null) parentHost.OnWindowlessNavigate(control, ne); parent = parent.Parent; } if (ne.Destination != null && ne.Destination != control) { WindowlessControlHost destHost = ne.Destination as WindowlessControlHost; if (destHost != null) { WindowlessControlHost reportChain = destHost; while (reportChain != null) { reportChain.OnWindowlessNavigatingTo(destHost, ne); reportChain = reportChain.Parent as WindowlessControlHost; } } if (ne.Destination != null) { e.Handled = true; // focus causes problems if this is not actually on a form if (topLevelControl is Form) ne.Destination.Focus(); } } const int scrollSpeed = 8; // now attempt to scroll parent = control; while (!e.Handled && parent != null) { ScrollableControl scrollControl = parent as ScrollableControl; if (scrollControl != null) { // see if we want to scroll this window if (scrollControl.AutoScroll && !e.Handled) { int left = Int32.MaxValue; int top = Int32.MaxValue; int right = Int32.MinValue; int bottom = Int32.MinValue; foreach (Control childControl in scrollControl.Controls) { left = Math.Min(left, childControl.Left); top = Math.Min(top, childControl.Top); bottom = Math.Max(bottom, childControl.Bottom); right = Math.Max(right, childControl.Right); } Point oldPos = scrollControl.AutoScrollPosition; if (e.KeyCode == Keys.Down && bottom > scrollControl.ClientSize.Height) { scrollControl.AutoScrollPosition = new Point(Math.Abs(scrollControl.AutoScrollPosition.X), Math.Min(Math.Abs(scrollControl.AutoScrollPosition.Y) + scrollSpeed, Math.Abs(scrollControl.AutoScrollPosition.Y) + (bottom - scrollControl.ClientSize.Height))); } if (e.KeyCode == Keys.Up && scrollControl.AutoScrollPosition.Y < 0) { scrollControl.AutoScrollPosition = new Point(Math.Abs(scrollControl.AutoScrollPosition.X), Math.Max(0, Math.Abs(scrollControl.AutoScrollPosition.Y) - scrollSpeed)); } if (e.KeyCode == Keys.Right && right > scrollControl.ClientSize.Width) { scrollControl.AutoScrollPosition = new Point(Math.Min(Math.Abs(scrollControl.AutoScrollPosition.X) + scrollSpeed, Math.Abs(scrollControl.AutoScrollPosition.X) + (right - scrollControl.ClientSize.Width)), Math.Abs(scrollControl.AutoScrollPosition.Y)); } if (e.KeyCode == Keys.Left && scrollControl.AutoScrollPosition.X < 0) { scrollControl.AutoScrollPosition = new Point(Math.Max(0, Math.Abs(scrollControl.AutoScrollPosition.X) - scrollSpeed), Math.Abs(scrollControl.AutoScrollPosition.Y)); } e.Handled = scrollControl.AutoScrollPosition != oldPos; } } parent = parent.Parent; } } break; } }
protected virtual void OnWindowlessNavigatingTo(WindowlessControlHost sender, WindowlessNavigateEventArgs e) { if (WindowlessNavigatingTo != null) WindowlessNavigatingTo(sender, e); }
protected virtual void OnWindowlessNavigate(Control sender, WindowlessNavigateEventArgs e) { if (WindowlessNavigate != null) WindowlessNavigate(sender, e); }
protected virtual void OnWindowlessNavigatingTo(WindowlessControlHost sender, WindowlessNavigateEventArgs e) { if (WindowlessNavigatingTo != null) { WindowlessNavigatingTo(sender, e); } }
/// <summary> /// If a key down event is unhandled, this will attempt to handle it by navigating or scrolling. /// </summary> /// <param name="control"></param> /// <param name="e"></param> static void OnWindowlessUnhandledKeyDown(Control control, KeyEventArgs e) { if (e.Handled) { return; } WindowlessControlHost host = control as WindowlessControlHost; switch (e.KeyCode) { case Keys.F19: case Keys.F20: case Keys.Up: case Keys.Down: case Keys.Left: case Keys.Right: { // attempt to navigate first Point p = WindowlessPointToForm(control, Point.Empty); Rectangle sourceRect; if (host != null) { sourceRect = host.GetNavigationSourceRectangle(); } else { sourceRect = new Rectangle(0, 0, control.Width, control.Height); } Rectangle rect = sourceRect; rect.X += p.X; rect.Y += p.Y; Control bestControl = null; Control topLevelControl = FormlessTopLevelControl(control); if (e.KeyCode == Keys.F19 || e.KeyCode == Keys.F20) { Control previous = null; Control next = null; bool found = false; RecurseControls(topLevelControl, (current) => { if (current == control) { found = true; return(true); } if (!IsFocusable(current)) { return(true); } if (!found) { previous = current; } next = current; return(!found); }, null); if (e.KeyCode == Keys.F19) { bestControl = previous; } else { bestControl = next; } //WindowlessNavigateEventArgs ne = new WindowlessNavigateEventArgs(control, } else { ulong bestScore; bestControl = GetBestNavigationHost(rect, e.KeyCode, topLevelControl, control, out bestScore); } WindowlessNavigateEventArgs ne = new WindowlessNavigateEventArgs(control, sourceRect, e.KeyCode, bestControl); Control parent = control; while (parent != null) { WindowlessControlHost parentHost = parent as WindowlessControlHost; if (parentHost != null) { parentHost.OnWindowlessNavigate(control, ne); } parent = parent.Parent; } if (ne.Destination != null && ne.Destination != control) { WindowlessControlHost destHost = ne.Destination as WindowlessControlHost; if (destHost != null) { WindowlessControlHost reportChain = destHost; while (reportChain != null) { reportChain.OnWindowlessNavigatingTo(destHost, ne); reportChain = reportChain.Parent as WindowlessControlHost; } } if (ne.Destination != null) { e.Handled = true; // focus causes problems if this is not actually on a form if (topLevelControl is Form) { ne.Destination.Focus(); } } } const int scrollSpeed = 8; // now attempt to scroll parent = control; while (!e.Handled && parent != null) { ScrollableControl scrollControl = parent as ScrollableControl; if (scrollControl != null) { // see if we want to scroll this window if (scrollControl.AutoScroll && !e.Handled) { int left = Int32.MaxValue; int top = Int32.MaxValue; int right = Int32.MinValue; int bottom = Int32.MinValue; foreach (Control childControl in scrollControl.Controls) { left = Math.Min(left, childControl.Left); top = Math.Min(top, childControl.Top); bottom = Math.Max(bottom, childControl.Bottom); right = Math.Max(right, childControl.Right); } Point oldPos = scrollControl.AutoScrollPosition; if (e.KeyCode == Keys.Down && bottom > scrollControl.ClientSize.Height) { scrollControl.AutoScrollPosition = new Point(Math.Abs(scrollControl.AutoScrollPosition.X), Math.Min(Math.Abs(scrollControl.AutoScrollPosition.Y) + scrollSpeed, Math.Abs(scrollControl.AutoScrollPosition.Y) + (bottom - scrollControl.ClientSize.Height))); } if (e.KeyCode == Keys.Up && scrollControl.AutoScrollPosition.Y < 0) { scrollControl.AutoScrollPosition = new Point(Math.Abs(scrollControl.AutoScrollPosition.X), Math.Max(0, Math.Abs(scrollControl.AutoScrollPosition.Y) - scrollSpeed)); } if (e.KeyCode == Keys.Right && right > scrollControl.ClientSize.Width) { scrollControl.AutoScrollPosition = new Point(Math.Min(Math.Abs(scrollControl.AutoScrollPosition.X) + scrollSpeed, Math.Abs(scrollControl.AutoScrollPosition.X) + (right - scrollControl.ClientSize.Width)), Math.Abs(scrollControl.AutoScrollPosition.Y)); } if (e.KeyCode == Keys.Left && scrollControl.AutoScrollPosition.X < 0) { scrollControl.AutoScrollPosition = new Point(Math.Max(0, Math.Abs(scrollControl.AutoScrollPosition.X) - scrollSpeed), Math.Abs(scrollControl.AutoScrollPosition.Y)); } e.Handled = scrollControl.AutoScrollPosition != oldPos; } } parent = parent.Parent; } } break; } }
protected override void OnWindowlessNavigatingTo(WindowlessControlHost sender, WindowlessNavigateEventArgs e) { base.OnWindowlessNavigatingTo(sender, e); if (sender != this) return; // if we have a selection already, just leave it if (myCurrentSelection != null) return; if (Items.Count == 0) return; Point me = WindowlessPointToForm(this, Point.Empty); Point other = WindowlessPointToForm(e.Source, Point.Empty); Rectangle otherRect = e.SourceRectangle; otherRect.X += other.X; otherRect.Y += other.Y; Rectangle rect = new Rectangle(otherRect.X - me.X, otherRect.Y - me.Y, otherRect.Width, otherRect.Height); NavigateSelection(rect, e.Key); }