/// <summary> /// Get the list of access key targets for the sender of the keyboard event. If sender is null, /// pretend key was pressed in the active window. /// </summary> /// <param name="sender"></param> /// <param name="key"></param> /// <returns></returns> private List <IInputElement> GetTargetsForSender(IInputElement sender, string key) { // Find the scope for the sender -- will be matched against the possible targets' scopes AccessKeyInformation senderInfo = GetInfoForElement(sender, key); return(GetTargetsForScope(senderInfo.Scope, key, sender, senderInfo)); }
/// <summary> /// Returns scope for the given element. /// </summary> /// <param name="element"></param> /// <param name="key"></param> /// <returns>Scope for the given element, null means the context global scope</returns> private AccessKeyInformation GetInfoForElement(IInputElement element, string key) { AccessKeyInformation info = new AccessKeyInformation(); if (element != null) { AccessKeyPressedEventArgs args = new AccessKeyPressedEventArgs(key); element.RaiseEvent(args); info.Scope = args.Scope; info.target = args.Target; if (info.Scope == null) { info.Scope = GetSourceForElement(element); } } else { info.Scope = CriticalGetActiveSource(); } return(info); }
private List <IInputElement> GetTargetsForScope(object scope, string key, IInputElement sender, AccessKeyInformation senderInfo) { // null scope defaults to the active window if (scope == null) { scope = CriticalGetActiveSource(); // if there is no active scope then give up if (scope == null) { return(null); } } if (CoreCompatibilityPreferences.GetIsAltKeyRequiredInAccessKeyDefaultScope() && (scope is PresentationSource) && (Keyboard.Modifiers & ModifierKeys.Alt) != ModifierKeys.Alt) { // If AltKey is required and it isnt pressed then dont match against any targets return(null); } //Scoping: // 1) When key is pressed, find matching AKs -> S // 3) find scope for keyevent.Source // 4) find scope for everything in S. throw away those that don't match. // 5) Final selection uses S. yay! // // List <IInputElement> possibleElements; lock (_keyToElements) { possibleElements = CopyAndPurgeDead(_keyToElements[key] as ArrayList); } if (possibleElements == null) { return(null); } List <IInputElement> finalTargets = new List <IInputElement>(1); // Go through all the possible elements, find the interesting candidates for (int i = 0; i < possibleElements.Count; i++) { IInputElement element = possibleElements[i]; if (element != sender) { if (IsTargetable(element)) { AccessKeyInformation elementInfo = GetInfoForElement(element, key); if (elementInfo.target == null) { continue; } if (scope == elementInfo.Scope) { finalTargets.Add(elementInfo.target); } } } else { // This is the same element that sent the event so it must be in the same scope. // Just add it to the final targets if (senderInfo.target != null) { finalTargets.Add(senderInfo.target); } } } return(finalTargets); }
private AccessKeyInformation GetInfoForElement(IInputElement element, string key) { AccessKeyInformation info = new AccessKeyInformation(); if (element != null) { AccessKeyPressedEventArgs args = new AccessKeyPressedEventArgs(key); element.RaiseEvent(args); info.Scope = args.Scope; info.target = args.Target; if (info.Scope == null) { info.Scope = GetSourceForElement(element); } } else { info.Scope = CriticalGetActiveSource(); } return info; }
private List<IInputElement> GetTargetsForScope(object scope, string key, IInputElement sender, AccessKeyInformation senderInfo) { // null scope defaults to the active window if (scope == null) { scope = CriticalGetActiveSource(); // if there is no active scope then give up if (scope == null) { return null; } } if (CoreCompatibilityPreferences.GetIsAltKeyRequiredInAccessKeyDefaultScope() && (scope is PresentationSource) && (Keyboard.Modifiers & ModifierKeys.Alt) != ModifierKeys.Alt) { // If AltKey is required and it isnt pressed then dont match against any targets return null; } //Scoping: // 1) When key is pressed, find matching AKs -> S // 3) find scope for keyevent.Source // 4) find scope for everything in S. throw away those that don't match. // 5) Final selection uses S. yay! // // List<IInputElement> possibleElements; lock (_keyToElements) { possibleElements = CopyAndPurgeDead(_keyToElements[key] as ArrayList); } if (possibleElements == null) return null; List<IInputElement> finalTargets = new List<IInputElement>(1); // Go through all the possible elements, find the interesting candidates for (int i = 0; i < possibleElements.Count; i++) { IInputElement element = possibleElements[i]; if (element != sender) { if (IsTargetable(element)) { AccessKeyInformation elementInfo = GetInfoForElement(element, key); if (elementInfo.target == null) continue; if (scope == elementInfo.Scope) { finalTargets.Add(elementInfo.target); } } } else { // This is the same element that sent the event so it must be in the same scope. // Just add it to the final targets if (senderInfo.target != null) { finalTargets.Add(senderInfo.target); } } } return finalTargets; }