private void Show() { // Check whether the window is still active // (it prevent keytips showing during Alt-Tab'ing) if (!this.window.IsActive) { this.RestoreFocuses(); return; } this.currentUserInput = string.Empty; this.activeAdornerChain = new KeyTipAdorner(this.ribbon, this.ribbon, null); this.activeAdornerChain.Terminated += this.OnAdornerChainTerminated; // Special behavior for backstage var backstage = this.ribbon.Menu as Backstage; if (backstage != null && backstage.IsOpen) { var keys = KeyTip.GetKeys(backstage); if (!String.IsNullOrEmpty(keys)) { this.activeAdornerChain.Forward(KeyTip.GetKeys(backstage), false); } else { this.activeAdornerChain.Attach(); } } else { this.activeAdornerChain.Attach(); } }
// Window's messages hook up private IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { // We must terminate the keytip's adorner chain if: // - mouse clicks in non client area // - the window is deactivated if (((msg >= 161) && (msg <= 173)) || msg == NativeMethods.WM_NCACTIVATE) { if ((activeAdornerChain != null) && (activeAdornerChain.IsAdornerChainAlive)) { activeAdornerChain.Terminate(); activeAdornerChain = null; } } return(IntPtr.Zero); }
/// <summary> /// Construcotor /// </summary> /// <param name="adornedElement"></param> /// <param name="parentAdorner">Parent adorner or null</param> /// <param name="keyTipElementContainer">The element which is container for elements</param> public KeyTipAdorner(UIElement adornedElement, UIElement keyTipElementContainer, KeyTipAdorner parentAdorner) : base(adornedElement) { this.parentAdorner = parentAdorner; this.keyTipElementContainer = keyTipElementContainer; // Try to find supported elements FindKeyTips(this.keyTipElementContainer, false); oneOfAssociatedElements = (FrameworkElement)(associatedElements.Count != 0 ? associatedElements[0] : adornedElement // Maybe here is bug, coz we need keytipped item here... ); keyTipPositions = new Point[keyTips.Count]; }
private void OnWindowKeyUp(object sender, KeyEventArgs e) { if (this.ribbon.IsCollapsed) { return; } if ((e.Key == Key.System) && ((e.SystemKey == Key.LeftAlt) || (e.SystemKey == Key.RightAlt) || (e.SystemKey == Key.F10) || (e.SystemKey == Key.Space))) { this.currentUserInput = string.Empty; e.Handled = true; if (this.timer.IsEnabled) { this.timer.Stop(); this.backUpFocusedElement = Keyboard.FocusedElement; // Focus ribbon this.ribbon.Focusable = true; //this.ribbon.Focus(); this.Show(); } else if (this.activeAdornerChain != null && this.activeAdornerChain.IsAdornerChainAlive) { // Focus ribbon this.backUpFocusedElement = Keyboard.FocusedElement; this.ribbon.Focusable = true; //this.ribbon.Focus(); this.activeAdornerChain.Terminate(); this.activeAdornerChain = null; } } else { this.timer.Stop(); } }
// Forward to the next element private void Forward(UIElement element, bool click) { this.Detach(); if (click) { //element.RaiseEvent(new RoutedEventArgs(Button.ClickEvent, null)); var control = element as IKeyTipedControl; if (control != null) { control.OnKeyTipPressed(); } } var children = LogicalTreeHelper.GetChildren(element) .OfType <UIElement>() .ToArray(); if (children.Length == 0) { this.Terminate(); return; } this.childAdorner = ReferenceEquals(GetTopLevelElement(children[0]), GetTopLevelElement(element)) == false ? new KeyTipAdorner(children[0], element, this) : new KeyTipAdorner(element, element, this); // Stop if no further KeyTips can be displayed. if (!this.childAdorner.keyTips.Any()) { this.Terminate(); return; } this.Detach(); this.childAdorner.Attach(); }
private void OnWindowKeyDown(object sender, KeyEventArgs e) { if (e.IsRepeat) { return; } if (this.ribbon.IsCollapsed) { return; } if ((e.Key == Key.System) && ((e.SystemKey == Key.LeftAlt) || (e.SystemKey == Key.RightAlt) || (e.SystemKey == Key.F10) || (e.SystemKey == Key.Space))) { if (this.activeAdornerChain == null || (!this.activeAdornerChain.IsAdornerChainAlive || !this.activeAdornerChain.AreAnyKeyTipsVisible)) { if (this.activeAdornerChain != null) { this.activeAdornerChain.Terminate(); } this.activeAdornerChain = null; this.timer.Start(); } else { this.currentUserInput = string.Empty; } } else if (e.Key == Key.Escape) { if (this.activeAdornerChain != null) { this.activeAdornerChain.ActiveKeyTipAdorner.Back(); } } else { if (e.Key == Key.System && e.SystemKey != Key.Escape && e.KeyboardDevice.Modifiers == ModifierKeys.Alt) { if (this.activeAdornerChain == null || (!this.activeAdornerChain.IsAdornerChainAlive || !this.activeAdornerChain.AreAnyKeyTipsVisible)) { this.timer.Stop(); this.backUpFocusedElement = Keyboard.FocusedElement; // Focus ribbon this.ribbon.Focusable = true; //this.ribbon.Focus(); this.Show(); } if (this.activeAdornerChain != null) { this.currentUserInput += this.keyConverter.ConvertToString(e.SystemKey); if (this.activeAdornerChain.ActiveKeyTipAdorner.Forward(this.currentUserInput, true)) { this.currentUserInput = string.Empty; e.Handled = true; } } } } }