bool ComponentPeer::handleKeyUpOrDown (const bool isKeyDown) { ModifierKeys::updateCurrentModifiers(); bool keyWasUsed = false; for (Component* target = getTargetForKeyPress(); target != nullptr; target = target->getParentComponent()) { const WeakReference<Component> deletionChecker (target); keyWasUsed = target->keyStateChanged (isKeyDown); if (keyWasUsed || deletionChecker == nullptr) break; if (const Array<KeyListener*>* const keyListeners = target->keyListeners) { for (int i = keyListeners->size(); --i >= 0;) { keyWasUsed = keyListeners->getUnchecked(i)->keyStateChanged (isKeyDown, target); if (keyWasUsed || deletionChecker == nullptr) return keyWasUsed; i = jmin (i, keyListeners->size()); } } } return keyWasUsed; }
bool ComponentPeer::handleKeyPress (const int keyCode, const juce_wchar textCharacter) { ModifierKeys::updateCurrentModifiers(); bool keyWasUsed = false; const KeyPress keyInfo (keyCode, ModifierKeys::getCurrentModifiers().withoutMouseButtons(), textCharacter); for (Component* target = getTargetForKeyPress(); target != nullptr; target = target->getParentComponent()) { const WeakReference<Component> deletionChecker (target); if (const Array<KeyListener*>* const keyListeners = target->keyListeners) { for (int i = keyListeners->size(); --i >= 0;) { keyWasUsed = keyListeners->getUnchecked(i)->keyPressed (keyInfo, target); if (keyWasUsed || deletionChecker == nullptr) return keyWasUsed; i = jmin (i, keyListeners->size()); } } keyWasUsed = target->keyPressed (keyInfo); if (keyWasUsed || deletionChecker == nullptr) break; if (Component* const currentlyFocused = Component::getCurrentlyFocusedComponent()) { const bool isTab = (keyInfo == KeyPress::tabKey); const bool isShiftTab = (keyInfo == KeyPress (KeyPress::tabKey, ModifierKeys::shiftModifier, 0)); if (isTab || isShiftTab) { currentlyFocused->moveKeyboardFocusToSibling (isTab); keyWasUsed = (currentlyFocused != Component::getCurrentlyFocusedComponent()); if (keyWasUsed || deletionChecker == nullptr) break; } } } return keyWasUsed; }
bool ComponentPeer::handleKeyPress (const KeyPress& keyInfo) { bool keyWasUsed = false; for (auto* target = getTargetForKeyPress(); target != nullptr; target = target->getParentComponent()) { const WeakReference<Component> deletionChecker (target); if (auto* keyListeners = target->keyListeners.get()) { for (int i = keyListeners->size(); --i >= 0;) { keyWasUsed = keyListeners->getUnchecked(i)->keyPressed (keyInfo, target); if (keyWasUsed || deletionChecker == nullptr) return keyWasUsed; i = jmin (i, keyListeners->size()); } } keyWasUsed = target->keyPressed (keyInfo); if (keyWasUsed || deletionChecker == nullptr) break; if (auto* currentlyFocused = Component::getCurrentlyFocusedComponent()) { const bool isTab = (keyInfo == KeyPress::tabKey); const bool isShiftTab = (keyInfo == KeyPress (KeyPress::tabKey, ModifierKeys::shiftModifier, 0)); if (isTab || isShiftTab) { currentlyFocused->moveKeyboardFocusToSibling (isTab); keyWasUsed = (currentlyFocused != Component::getCurrentlyFocusedComponent()); if (keyWasUsed || deletionChecker == nullptr) break; } } } return keyWasUsed; }