| @@ -1067,7 +1067,8 @@ public: | |||||
| if (windowH != 0 | if (windowH != 0 | ||||
| && XGetWindowAttributes (display, windowH, &atts) | && XGetWindowAttributes (display, windowH, &atts) | ||||
| && atts.map_state == IsViewable) | |||||
| && atts.map_state == IsViewable | |||||
| && ! isFocused()) | |||||
| { | { | ||||
| XSetInputFocus (display, windowH, RevertToParent, CurrentTime); | XSetInputFocus (display, windowH, RevertToParent, CurrentTime); | ||||
| @@ -6,6 +6,7 @@ | |||||
| ============================================================================== | ============================================================================== | ||||
| Changelist for version 1.44 | Changelist for version 1.44 | ||||
| - change to the keyPressed() and keyStateChanged() callbacks in Component and KeyListener. These used to be void, but they now return a bool to indicate whether the key event was needed or not. Any existing code you've got will break in the compiler, so just change it to return true if the key was used, or false to allow the event to be passed up to the next component in the chain. (This change is a better architecture than before, and was also needed so that plugins can allow unused key events to be passed on to the host application) | |||||
| - swapped the look and feel classes around, so that the basic LookAndFeel class is now what used to be the "shiny" one. The ShinyLookAndFeel class has been removed, and for that old fashioned look, I've added an OldSchoolLookAndFeel that you can use if you need the original L+F. This means that any custom looks that you were using may need to change their base class. | - swapped the look and feel classes around, so that the basic LookAndFeel class is now what used to be the "shiny" one. The ShinyLookAndFeel class has been removed, and for that old fashioned look, I've added an OldSchoolLookAndFeel that you can use if you need the original L+F. This means that any custom looks that you were using may need to change their base class. | ||||
| - changed the MouseEvent structure so that it now contains a pointer to the event component and also the original component. | - changed the MouseEvent structure so that it now contains a pointer to the event component and also the original component. | ||||
| - added a PopupMenu::dismissAllActiveMenus() method. | - added a PopupMenu::dismissAllActiveMenus() method. | ||||
| @@ -299,8 +299,8 @@ void JucerDocument::getOptionalMethods (StringArray& baseClasses, | |||||
| addMethod ("Component", "void", "mouseDoubleClick (const MouseEvent& e)", "", baseClasses, returnValues, methods, initialContents); | addMethod ("Component", "void", "mouseDoubleClick (const MouseEvent& e)", "", baseClasses, returnValues, methods, initialContents); | ||||
| addMethod ("Component", "void", "mouseWheelMove (const MouseEvent& e, float wheelIncrement)", "", baseClasses, returnValues, methods, initialContents); | addMethod ("Component", "void", "mouseWheelMove (const MouseEvent& e, float wheelIncrement)", "", baseClasses, returnValues, methods, initialContents); | ||||
| addMethod ("Component", "void", "keyPressed (const KeyPress& key)", "", baseClasses, returnValues, methods, initialContents); | |||||
| addMethod ("Component", "void", "keyStateChanged()", "", baseClasses, returnValues, methods, initialContents); | |||||
| addMethod ("Component", "bool", "keyPressed (const KeyPress& key)", "return false; // Return true if your handler uses this key event, or false to allow it to be passed-on.", baseClasses, returnValues, methods, initialContents); | |||||
| addMethod ("Component", "bool", "keyStateChanged()", "return false; // Return true if your handler uses this key event, or false to allow it to be passed-on.", baseClasses, returnValues, methods, initialContents); | |||||
| addMethod ("Component", "void", "modifierKeysChanged (const ModifierKeys& modifiers)", "", baseClasses, returnValues, methods, initialContents); | addMethod ("Component", "void", "modifierKeysChanged (const ModifierKeys& modifiers)", "", baseClasses, returnValues, methods, initialContents); | ||||
| addMethod ("Component", "void", "focusGained (FocusChangeType cause)", "", baseClasses, returnValues, methods, initialContents); | addMethod ("Component", "void", "focusGained (FocusChangeType cause)", "", baseClasses, returnValues, methods, initialContents); | ||||
| @@ -325,7 +325,7 @@ static void moveOrStretch (ComponentLayout& layout, int x, int y, bool snap, boo | |||||
| layout.moveSelectedComps (x, y, snap); | layout.moveSelectedComps (x, y, snap); | ||||
| } | } | ||||
| void ComponentLayoutEditor::keyPressed (const KeyPress& key) | |||||
| bool ComponentLayoutEditor::keyPressed (const KeyPress& key) | |||||
| { | { | ||||
| const bool snap = key.getModifiers().isAltDown(); | const bool snap = key.getModifiers().isAltDown(); | ||||
| const bool stretch = key.getModifiers().isShiftDown(); | const bool stretch = key.getModifiers().isShiftDown(); | ||||
| @@ -351,8 +351,10 @@ void ComponentLayoutEditor::keyPressed (const KeyPress& key) | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| Component::keyPressed (key); | |||||
| return false; | |||||
| } | } | ||||
| return true; | |||||
| } | } | ||||
| bool ComponentLayoutEditor::filesDropped (const StringArray& filenames, int x, int y) | bool ComponentLayoutEditor::filesDropped (const StringArray& filenames, int x, int y) | ||||
| @@ -58,7 +58,7 @@ public: | |||||
| void mouseDown (const MouseEvent& e); | void mouseDown (const MouseEvent& e); | ||||
| void mouseDrag (const MouseEvent& e); | void mouseDrag (const MouseEvent& e); | ||||
| void mouseUp (const MouseEvent& e); | void mouseUp (const MouseEvent& e); | ||||
| void keyPressed (const KeyPress& key); | |||||
| bool keyPressed (const KeyPress& key); | |||||
| bool filesDropped (const StringArray& filenames, int x, int y); | bool filesDropped (const StringArray& filenames, int x, int y); | ||||
| ComponentLayout& getLayout() const throw() { return layout; } | ComponentLayout& getLayout() const throw() { return layout; } | ||||
| @@ -601,34 +601,40 @@ bool Button::isRegisteredForShortcut (const KeyPress& key) const throw() | |||||
| return false; | return false; | ||||
| } | } | ||||
| void Button::keyStateChanged (Component*) | |||||
| bool Button::keyStateChanged (Component*) | |||||
| { | { | ||||
| if (isEnabled()) | |||||
| { | |||||
| const bool wasDown = isKeyDown; | |||||
| isKeyDown = isShortcutPressed(); | |||||
| if (! isEnabled()) | |||||
| return false; | |||||
| if (autoRepeatDelay >= 0 && (isKeyDown && !wasDown)) | |||||
| getRepeatTimer().startTimer (autoRepeatDelay); | |||||
| const bool wasDown = isKeyDown; | |||||
| isKeyDown = isShortcutPressed(); | |||||
| updateState (0); | |||||
| if (autoRepeatDelay >= 0 && (isKeyDown && ! wasDown)) | |||||
| getRepeatTimer().startTimer (autoRepeatDelay); | |||||
| if (isEnabled() && wasDown && ! isKeyDown) | |||||
| internalClickCallback (ModifierKeys::getCurrentModifiers()); | |||||
| } | |||||
| updateState (0); | |||||
| if (isEnabled() && wasDown && ! isKeyDown) | |||||
| internalClickCallback (ModifierKeys::getCurrentModifiers()); | |||||
| return isKeyDown || wasDown; | |||||
| } | } | ||||
| void Button::keyPressed (const KeyPress&, Component*) | |||||
| bool Button::keyPressed (const KeyPress&, Component*) | |||||
| { | { | ||||
| // (not actually used - the key detection happens in keyStateChanged) | |||||
| // return true to avoid forwarding events for keys that we're using as shortcuts | |||||
| return isShortcutPressed(); | |||||
| } | } | ||||
| void Button::keyPressed (const KeyPress& key) | |||||
| bool Button::keyPressed (const KeyPress& key) | |||||
| { | { | ||||
| if (isEnabled() && key.isKeyCode (KeyPress::returnKey)) | if (isEnabled() && key.isKeyCode (KeyPress::returnKey)) | ||||
| { | |||||
| triggerClick(); | triggerClick(); | ||||
| else | |||||
| Component::keyPressed (key); | |||||
| return true; | |||||
| } | |||||
| return false; | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -439,11 +439,11 @@ protected: | |||||
| /** @internal */ | /** @internal */ | ||||
| void mouseUp (const MouseEvent& e); | void mouseUp (const MouseEvent& e); | ||||
| /** @internal */ | /** @internal */ | ||||
| void keyPressed (const KeyPress& key); | |||||
| bool keyPressed (const KeyPress& key); | |||||
| /** @internal */ | /** @internal */ | ||||
| void keyPressed (const KeyPress& key, Component* originatingComponent); | |||||
| bool keyPressed (const KeyPress& key, Component* originatingComponent); | |||||
| /** @internal */ | /** @internal */ | ||||
| void keyStateChanged (Component* originatingComponent); | |||||
| bool keyStateChanged (Component* originatingComponent); | |||||
| /** @internal */ | /** @internal */ | ||||
| void paint (Graphics& g); | void paint (Graphics& g); | ||||
| /** @internal */ | /** @internal */ | ||||
| @@ -282,9 +282,9 @@ int ComboBox::getSelectedItemIndex() const throw() | |||||
| } | } | ||||
| void ComboBox::setSelectedItemIndex (const int index, | void ComboBox::setSelectedItemIndex (const int index, | ||||
| const bool dontSendChangeMessage) | |||||
| const bool dontSendChangeMessage) throw() | |||||
| { | { | ||||
| if (getSelectedItemIndex() != index) | |||||
| if (currentIndex != index) | |||||
| { | { | ||||
| if (index >= 0 && index < getNumItems()) | if (index >= 0 && index < getNumItems()) | ||||
| currentIndex = index; | currentIndex = index; | ||||
| @@ -299,7 +299,7 @@ void ComboBox::setSelectedItemIndex (const int index, | |||||
| } | } | ||||
| void ComboBox::setSelectedId (const int newItemId, | void ComboBox::setSelectedId (const int newItemId, | ||||
| const bool dontSendChangeMessage) | |||||
| const bool dontSendChangeMessage) throw() | |||||
| { | { | ||||
| for (int i = getNumItems(); --i >= 0;) | for (int i = getNumItems(); --i >= 0;) | ||||
| { | { | ||||
| @@ -349,7 +349,7 @@ const String ComboBox::getText() const throw() | |||||
| } | } | ||||
| void ComboBox::setText (const String& newText, | void ComboBox::setText (const String& newText, | ||||
| const bool dontSendChangeMessage) | |||||
| const bool dontSendChangeMessage) throw() | |||||
| { | { | ||||
| for (int i = items.size(); --i >= 0;) | for (int i = items.size(); --i >= 0;) | ||||
| { | { | ||||
| @@ -461,38 +461,38 @@ void ComboBox::colourChanged() | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| void ComboBox::keyPressed (const KeyPress& key) | |||||
| bool ComboBox::keyPressed (const KeyPress& key) | |||||
| { | { | ||||
| bool used = false; | |||||
| if (key.isKeyCode (KeyPress::upKey) | if (key.isKeyCode (KeyPress::upKey) | ||||
| || key.isKeyCode (KeyPress::leftKey)) | || key.isKeyCode (KeyPress::leftKey)) | ||||
| { | { | ||||
| setSelectedItemIndex (jmax (0, currentIndex - 1)); | setSelectedItemIndex (jmax (0, currentIndex - 1)); | ||||
| used = true; | |||||
| } | } | ||||
| else if (key.isKeyCode (KeyPress::downKey) | else if (key.isKeyCode (KeyPress::downKey) | ||||
| || key.isKeyCode (KeyPress::rightKey)) | || key.isKeyCode (KeyPress::rightKey)) | ||||
| { | { | ||||
| setSelectedItemIndex (jmin (currentIndex + 1, getNumItems() - 1)); | setSelectedItemIndex (jmin (currentIndex + 1, getNumItems() - 1)); | ||||
| used = true; | |||||
| } | } | ||||
| else if (key.isKeyCode (KeyPress::returnKey)) | else if (key.isKeyCode (KeyPress::returnKey)) | ||||
| { | { | ||||
| showPopup(); | showPopup(); | ||||
| used = true; | |||||
| } | } | ||||
| else | |||||
| { | |||||
| Component::keyPressed (key); | |||||
| } | |||||
| return used; | |||||
| } | } | ||||
| void ComboBox::keyStateChanged() | |||||
| bool ComboBox::keyStateChanged() | |||||
| { | { | ||||
| // only forward key events that aren't used by this component | // only forward key events that aren't used by this component | ||||
| if (! (KeyPress::isKeyCurrentlyDown (KeyPress::upKey) | |||||
| || KeyPress::isKeyCurrentlyDown (KeyPress::leftKey) | |||||
| || KeyPress::isKeyCurrentlyDown (KeyPress::downKey) | |||||
| || KeyPress::isKeyCurrentlyDown (KeyPress::rightKey))) | |||||
| { | |||||
| Component::keyStateChanged(); | |||||
| } | |||||
| return KeyPress::isKeyCurrentlyDown (KeyPress::upKey) | |||||
| || KeyPress::isKeyCurrentlyDown (KeyPress::leftKey) | |||||
| || KeyPress::isKeyCurrentlyDown (KeyPress::downKey) | |||||
| || KeyPress::isKeyCurrentlyDown (KeyPress::rightKey); | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -212,7 +212,7 @@ public: | |||||
| @see getSelectedId, setSelectedItemIndex, setText | @see getSelectedId, setSelectedItemIndex, setText | ||||
| */ | */ | ||||
| void setSelectedId (const int newItemId, | void setSelectedId (const int newItemId, | ||||
| const bool dontSendChangeMessage = false); | |||||
| const bool dontSendChangeMessage = false) throw(); | |||||
| //============================================================================== | //============================================================================== | ||||
| /** Returns the index of the item that's currently shown in the box. | /** Returns the index of the item that's currently shown in the box. | ||||
| @@ -236,7 +236,7 @@ public: | |||||
| @see getSelectedItemIndex, setSelectedId, setText | @see getSelectedItemIndex, setSelectedId, setText | ||||
| */ | */ | ||||
| void setSelectedItemIndex (const int newItemIndex, | void setSelectedItemIndex (const int newItemIndex, | ||||
| const bool dontSendChangeMessage = false); | |||||
| const bool dontSendChangeMessage = false) throw(); | |||||
| //============================================================================== | //============================================================================== | ||||
| /** Returns the text that is currently shown in the combo-box's text field. | /** Returns the text that is currently shown in the combo-box's text field. | ||||
| @@ -262,7 +262,7 @@ public: | |||||
| @see getText | @see getText | ||||
| */ | */ | ||||
| void setText (const String& newText, | void setText (const String& newText, | ||||
| const bool dontSendChangeMessage = false); | |||||
| const bool dontSendChangeMessage = false) throw(); | |||||
| //============================================================================== | //============================================================================== | ||||
| /** Registers a listener that will be called when the box's content changes. */ | /** Registers a listener that will be called when the box's content changes. */ | ||||
| @@ -366,8 +366,8 @@ private: | |||||
| void lookAndFeelChanged(); | void lookAndFeelChanged(); | ||||
| void paint (Graphics&); | void paint (Graphics&); | ||||
| void resized(); | void resized(); | ||||
| void keyStateChanged(); | |||||
| void keyPressed (const KeyPress&); | |||||
| bool keyStateChanged(); | |||||
| bool keyPressed (const KeyPress&); | |||||
| void showPopup(); | void showPopup(); | ||||
| @@ -664,7 +664,7 @@ void ListBox::scrollToEnsureRowIsOnscreen (const int row) | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| void ListBox::keyPressed (const KeyPress& key) | |||||
| bool ListBox::keyPressed (const KeyPress& key) | |||||
| { | { | ||||
| const int numVisibleRows = viewport->getHeight() / getRowHeight(); | const int numVisibleRows = viewport->getHeight() / getRowHeight(); | ||||
| @@ -734,22 +734,21 @@ void ListBox::keyPressed (const KeyPress& key) | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| Component::keyPressed (key); | |||||
| return false; | |||||
| } | } | ||||
| return true; | |||||
| } | } | ||||
| void ListBox::keyStateChanged() | |||||
| bool ListBox::keyStateChanged() | |||||
| { | { | ||||
| if (! (KeyPress::isKeyCurrentlyDown (KeyPress::upKey) | |||||
| || KeyPress::isKeyCurrentlyDown (KeyPress::pageUpKey) | |||||
| || KeyPress::isKeyCurrentlyDown (KeyPress::downKey) | |||||
| || KeyPress::isKeyCurrentlyDown (KeyPress::pageDownKey) | |||||
| || KeyPress::isKeyCurrentlyDown (KeyPress::homeKey) | |||||
| || KeyPress::isKeyCurrentlyDown (KeyPress::endKey) | |||||
| || KeyPress::isKeyCurrentlyDown (KeyPress::returnKey))) | |||||
| { | |||||
| Component::keyStateChanged(); | |||||
| } | |||||
| return KeyPress::isKeyCurrentlyDown (KeyPress::upKey) | |||||
| || KeyPress::isKeyCurrentlyDown (KeyPress::pageUpKey) | |||||
| || KeyPress::isKeyCurrentlyDown (KeyPress::downKey) | |||||
| || KeyPress::isKeyCurrentlyDown (KeyPress::pageDownKey) | |||||
| || KeyPress::isKeyCurrentlyDown (KeyPress::homeKey) | |||||
| || KeyPress::isKeyCurrentlyDown (KeyPress::endKey) | |||||
| || KeyPress::isKeyCurrentlyDown (KeyPress::returnKey); | |||||
| } | } | ||||
| void ListBox::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY) | void ListBox::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY) | ||||
| @@ -502,9 +502,9 @@ public: | |||||
| //============================================================================== | //============================================================================== | ||||
| /** @internal */ | /** @internal */ | ||||
| void keyPressed (const KeyPress& key); | |||||
| bool keyPressed (const KeyPress& key); | |||||
| /** @internal */ | /** @internal */ | ||||
| void keyStateChanged(); | |||||
| bool keyStateChanged(); | |||||
| /** @internal */ | /** @internal */ | ||||
| void paint (Graphics& g); | void paint (Graphics& g); | ||||
| /** @internal */ | /** @internal */ | ||||
| @@ -397,6 +397,26 @@ const Rectangle TableListBox::getCellPosition (const int columnId, const int row | |||||
| headerCell.getWidth(), row.getHeight()); | headerCell.getWidth(), row.getHeight()); | ||||
| } | } | ||||
| void TableListBox::scrollToEnsureColumnIsOnscreen (const int columnId) | |||||
| { | |||||
| ScrollBar* const scrollbar = getHorizontalScrollBar(); | |||||
| if (scrollbar != 0) | |||||
| { | |||||
| const Rectangle pos (header->getColumnPosition (header->getIndexOfColumnId (columnId, true))); | |||||
| double x = scrollbar->getCurrentRangeStart(); | |||||
| double w = scrollbar->getCurrentRangeSize(); | |||||
| if (pos.getX() < x) | |||||
| x = pos.getX(); | |||||
| else if (pos.getRight() > x + w) | |||||
| x += jmax (0.0, pos.getRight() - (x + w)); | |||||
| scrollbar->setCurrentRangeStart (x); | |||||
| } | |||||
| } | |||||
| int TableListBox::getNumRows() | int TableListBox::getNumRows() | ||||
| { | { | ||||
| return model != 0 ? model->getNumRows() : 0; | return model != 0 ? model->getNumRows() : 0; | ||||
| @@ -270,6 +270,12 @@ public: | |||||
| */ | */ | ||||
| const Rectangle getCellPosition (const int columnId, const int rowNumber) const; | const Rectangle getCellPosition (const int columnId, const int rowNumber) const; | ||||
| /** Scrolls horizontally if necessary to make sure that a particular column is visible. | |||||
| @see ListBox::scrollToEnsureRowIsOnscreen | |||||
| */ | |||||
| void scrollToEnsureColumnIsOnscreen (const int columnId); | |||||
| //============================================================================== | //============================================================================== | ||||
| /** @internal */ | /** @internal */ | ||||
| int getNumRows(); | int getNumRows(); | ||||
| @@ -1678,13 +1678,10 @@ void TextEditor::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, flo | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| void TextEditor::keyPressed (const KeyPress& key) | |||||
| bool TextEditor::keyPressed (const KeyPress& key) | |||||
| { | { | ||||
| if (isReadOnly() && key != KeyPress (T('c'), ModifierKeys::commandModifier, 0)) | if (isReadOnly() && key != KeyPress (T('c'), ModifierKeys::commandModifier, 0)) | ||||
| { | |||||
| Component::keyPressed (key); | |||||
| return; | |||||
| } | |||||
| return false; | |||||
| const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown(); | const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown(); | ||||
| @@ -1850,13 +1847,16 @@ void TextEditor::keyPressed (const KeyPress& key) | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| Component::keyPressed (key); | |||||
| return false; | |||||
| } | } | ||||
| return true; | |||||
| } | } | ||||
| void TextEditor::keyStateChanged() | |||||
| bool TextEditor::keyStateChanged() | |||||
| { | { | ||||
| // (overridden to avoid forwarding key events to the parent) | // (overridden to avoid forwarding key events to the parent) | ||||
| return true; | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -484,9 +484,9 @@ l */ | |||||
| /** @internal */ | /** @internal */ | ||||
| void mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY); | void mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY); | ||||
| /** @internal */ | /** @internal */ | ||||
| void keyPressed (const KeyPress& key); | |||||
| bool keyPressed (const KeyPress& key); | |||||
| /** @internal */ | /** @internal */ | ||||
| void keyStateChanged(); | |||||
| bool keyStateChanged(); | |||||
| /** @internal */ | /** @internal */ | ||||
| void focusGained (FocusChangeType cause); | void focusGained (FocusChangeType cause); | ||||
| /** @internal */ | /** @internal */ | ||||
| @@ -512,7 +512,7 @@ void TreeView::scrollToKeepItemVisible (TreeViewItem* item) | |||||
| } | } | ||||
| } | } | ||||
| void TreeView::keyPressed (const KeyPress& key) | |||||
| bool TreeView::keyPressed (const KeyPress& key) | |||||
| { | { | ||||
| if (key.isKeyCode (KeyPress::upKey)) | if (key.isKeyCode (KeyPress::upKey)) | ||||
| { | { | ||||
| @@ -587,8 +587,10 @@ void TreeView::keyPressed (const KeyPress& key) | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| Component::keyPressed (key); | |||||
| return false; | |||||
| } | } | ||||
| return true; | |||||
| } | } | ||||
| void TreeView::itemsChanged() throw() | void TreeView::itemsChanged() throw() | ||||
| @@ -557,7 +557,7 @@ public: | |||||
| /** @internal */ | /** @internal */ | ||||
| void resized(); | void resized(); | ||||
| /** @internal */ | /** @internal */ | ||||
| void keyPressed (const KeyPress& key); | |||||
| bool keyPressed (const KeyPress& key); | |||||
| /** @internal */ | /** @internal */ | ||||
| void colourChanged(); | void colourChanged(); | ||||
| @@ -1525,7 +1525,7 @@ bool Component::isCurrentlyBlockedByAnotherModalComponent() const throw() | |||||
| && ! mc->canModalEventBeSentToComponent (this); | && ! mc->canModalEventBeSentToComponent (this); | ||||
| } | } | ||||
| Component* Component::getCurrentlyModalComponent() throw() | |||||
| Component* JUCE_CALLTYPE Component::getCurrentlyModalComponent() throw() | |||||
| { | { | ||||
| Component* const c = (Component*) modalComponentStack.getLast(); | Component* const c = (Component*) modalComponentStack.getLast(); | ||||
| @@ -3466,81 +3466,14 @@ void Component::removeKeyListener (KeyListener* const listenerToRemove) throw() | |||||
| keyListeners_->removeValue (listenerToRemove); | keyListeners_->removeValue (listenerToRemove); | ||||
| } | } | ||||
| void Component::keyPressed (const KeyPress& key) | |||||
| bool Component::keyPressed (const KeyPress&) | |||||
| { | { | ||||
| const ComponentDeletionWatcher deletionChecker (this); | |||||
| if (key.isKeyCode (KeyPress::tabKey) | |||||
| && getCurrentlyFocusedComponent()->isValidComponent()) | |||||
| { | |||||
| getCurrentlyFocusedComponent()->moveKeyboardFocusToSibling (! key.getModifiers().isShiftDown()); | |||||
| } | |||||
| else if (parentComponent_ != 0) | |||||
| { | |||||
| parentComponent_->keyPressed (key); | |||||
| } | |||||
| if ((! deletionChecker.hasBeenDeleted()) && keyListeners_ != 0) | |||||
| { | |||||
| for (int i = keyListeners_->size(); --i >= 0;) | |||||
| { | |||||
| ((KeyListener*) keyListeners_->getUnchecked(i))->keyPressed (key, this); | |||||
| if (deletionChecker.hasBeenDeleted()) | |||||
| return; | |||||
| i = jmin (i, keyListeners_->size()); | |||||
| } | |||||
| } | |||||
| } | |||||
| void Component::keyStateChanged() | |||||
| { | |||||
| const ComponentDeletionWatcher deletionChecker (this); | |||||
| if (parentComponent_ != 0) | |||||
| parentComponent_->keyStateChanged(); | |||||
| if ((! deletionChecker.hasBeenDeleted()) && keyListeners_ != 0) | |||||
| { | |||||
| for (int i = keyListeners_->size(); --i >= 0;) | |||||
| { | |||||
| ((KeyListener*) keyListeners_->getUnchecked(i))->keyStateChanged (this); | |||||
| if (deletionChecker.hasBeenDeleted()) | |||||
| return; | |||||
| i = jmin (i, keyListeners_->size()); | |||||
| } | |||||
| } | |||||
| } | |||||
| bool Component::internalKeyPress (const int key, const juce_wchar textCharacter) | |||||
| { | |||||
| const KeyPress keyPress (key, | |||||
| ModifierKeys::getCurrentModifiers().getRawFlags() | |||||
| & ModifierKeys::allKeyboardModifiers, | |||||
| textCharacter); | |||||
| if (isCurrentlyBlockedByAnotherModalComponent()) | |||||
| { | |||||
| Component* const currentModalComp = getCurrentlyModalComponent(); | |||||
| if (currentModalComp != 0) | |||||
| currentModalComp->keyPressed (keyPress); | |||||
| } | |||||
| else | |||||
| { | |||||
| keyPressed (keyPress); | |||||
| } | |||||
| return true; | |||||
| return false; | |||||
| } | } | ||||
| bool Component::internalKeyStateChanged() | |||||
| bool Component::keyStateChanged() | |||||
| { | { | ||||
| keyStateChanged(); | |||||
| return true; | |||||
| return false; | |||||
| } | } | ||||
| void Component::modifierKeysChanged (const ModifierKeys& modifiers) | void Component::modifierKeysChanged (const ModifierKeys& modifiers) | ||||
| @@ -1452,21 +1452,17 @@ public: | |||||
| method called. Remember that a component will only be given the focus if its | method called. Remember that a component will only be given the focus if its | ||||
| setWantsKeyboardFocus() method has been used to enable this. | setWantsKeyboardFocus() method has been used to enable this. | ||||
| The default implementation of this method does the following: | |||||
| If your implementation returns true, the event will be consumed and not passed | |||||
| on to any other listeners. If it returns false, the key will be passed to any | |||||
| KeyListeners that have been registered with this component. As soon as one of these | |||||
| returns true, the process will stop, but if they all return false, the event will | |||||
| be passed upwards to this component's parent, and so on. | |||||
| - calls its parent's keyPressed() method, so that its parents will get a chance | |||||
| to use any keypresses that this component isn't interested in. | |||||
| - calls the keyPressed() methods of any KeyListeners that have registered with the | |||||
| addKeyListener() method. | |||||
| If you want to use the keypresses that reach this component and stop them being sent up to | |||||
| the parents, override this method. Of course a component can consume some keypresses | |||||
| selectively and then for others, just call the superclass's Component::keyPressed method | |||||
| to pass on the unwanted ones. | |||||
| The default implementation of this method does nothing and returns false. | |||||
| @see keyStateChanged, getCurrentlyFocusedComponent, addKeyListener | @see keyStateChanged, getCurrentlyFocusedComponent, addKeyListener | ||||
| */ | */ | ||||
| virtual void keyPressed (const KeyPress& key); | |||||
| virtual bool keyPressed (const KeyPress& key); | |||||
| /** Called when a key is pressed or released. | /** Called when a key is pressed or released. | ||||
| @@ -1475,19 +1471,20 @@ public: | |||||
| has the keyboard focus. Remember that a component will only be given the focus if | has the keyboard focus. Remember that a component will only be given the focus if | ||||
| its setWantsKeyboardFocus() method has been used to enable this. | its setWantsKeyboardFocus() method has been used to enable this. | ||||
| To find out which keys are up or down at any time, see the KeyPress::isKeyCurrentlyDown() | |||||
| method. | |||||
| If your implementation returns true, the event will be consumed and not passed | |||||
| on to any other listeners. If it returns false, then any KeyListeners that have | |||||
| been registered with this component will have their keyStateChanged methods called. | |||||
| As soon as one of these returns true, the process will stop, but if they all return | |||||
| false, the event will be passed upwards to this component's parent, and so on. | |||||
| The default implementation of this method does the following: | |||||
| The default implementation of this method does nothing and returns false. | |||||
| - calls its parent's keyStateChanged() method, so that its parents will get a chance | |||||
| to use any events that this component isn't interested in. | |||||
| - calls the keyStateChanged() methods of any KeyListeners that have registered with the | |||||
| addKeyListener() method. | |||||
| To find out which keys are up or down at any time, see the KeyPress::isKeyCurrentlyDown() | |||||
| method. | |||||
| @see keyPressed, KeyPress, getCurrentlyFocusedComponent, addKeyListener | @see keyPressed, KeyPress, getCurrentlyFocusedComponent, addKeyListener | ||||
| */ | */ | ||||
| virtual void keyStateChanged(); | |||||
| virtual bool keyStateChanged(); | |||||
| /** Called when a modifier key is pressed or released. | /** Called when a modifier key is pressed or released. | ||||
| @@ -1787,7 +1784,7 @@ public: | |||||
| @returns the modal component, or null if no components are modal | @returns the modal component, or null if no components are modal | ||||
| @see runModalLoop, isCurrentlyModal | @see runModalLoop, isCurrentlyModal | ||||
| */ | */ | ||||
| static Component* getCurrentlyModalComponent() throw(); | |||||
| static Component* JUCE_CALLTYPE getCurrentlyModalComponent() throw(); | |||||
| /** Checks whether there's a modal component somewhere that's stopping this one | /** Checks whether there's a modal component somewhere that's stopping this one | ||||
| from receiving messages. | from receiving messages. | ||||
| @@ -2078,8 +2075,6 @@ private: | |||||
| void internalFocusLoss (const FocusChangeType cause); | void internalFocusLoss (const FocusChangeType cause); | ||||
| void internalChildFocusChange (FocusChangeType cause); | void internalChildFocusChange (FocusChangeType cause); | ||||
| void internalModalInputAttempt(); | void internalModalInputAttempt(); | ||||
| bool internalKeyPress (const int key, const juce_wchar textCharacter); | |||||
| bool internalKeyStateChanged(); | |||||
| void internalModifierKeysChanged(); | void internalModifierKeysChanged(); | ||||
| void internalChildrenChanged(); | void internalChildrenChanged(); | ||||
| void internalHierarchyChanged(); | void internalHierarchyChanged(); | ||||
| @@ -37,8 +37,9 @@ BEGIN_JUCE_NAMESPACE | |||||
| //============================================================================== | //============================================================================== | ||||
| void KeyListener::keyStateChanged (Component*) | |||||
| bool KeyListener::keyStateChanged (Component*) | |||||
| { | { | ||||
| return false; | |||||
| } | } | ||||
| @@ -54,10 +54,15 @@ public: | |||||
| //============================================================================== | //============================================================================== | ||||
| /** Called to indicate that a key has been pressed. | /** Called to indicate that a key has been pressed. | ||||
| If your implementation returns true, then the key event is considered to have | |||||
| been consumed, and will not be passed on to any other components. If it returns | |||||
| false, then the key will be passed to other components that might want to use it. | |||||
| @param key the keystroke, including modifier keys | @param key the keystroke, including modifier keys | ||||
| @param originatingComponent the component that received the key event | @param originatingComponent the component that received the key event | ||||
| @see keyStateChanged, Component::keyPressed | |||||
| */ | */ | ||||
| virtual void keyPressed (const KeyPress& key, | |||||
| virtual bool keyPressed (const KeyPress& key, | |||||
| Component* originatingComponent) = 0; | Component* originatingComponent) = 0; | ||||
| /** Called when any key is pressed or released. | /** Called when any key is pressed or released. | ||||
| @@ -66,10 +71,14 @@ public: | |||||
| the state of one or more keys can use KeyPress::isKeyCurrentlyDown() to | the state of one or more keys can use KeyPress::isKeyCurrentlyDown() to | ||||
| check whether their key has changed. | check whether their key has changed. | ||||
| If your implementation returns true, then the key event is considered to have | |||||
| been consumed, and will not be passed on to any other components. If it returns | |||||
| false, then the key will be passed to other components that might want to use it. | |||||
| @param originatingComponent the component that received the key event | @param originatingComponent the component that received the key event | ||||
| @see KeyPress | |||||
| @see KeyPress, Component::keyStateChanged | |||||
| */ | */ | ||||
| virtual void keyStateChanged (Component* originatingComponent); | |||||
| virtual bool keyStateChanged (Component* originatingComponent); | |||||
| }; | }; | ||||
| @@ -471,7 +471,7 @@ public: | |||||
| { | { | ||||
| } | } | ||||
| void keyPressed (const KeyPress& key) | |||||
| bool keyPressed (const KeyPress& key) | |||||
| { | { | ||||
| lastPress = key; | lastPress = key; | ||||
| String message (TRANS("Key: ") + owner->getDescriptionForKeyPress (key)); | String message (TRANS("Key: ") + owner->getDescriptionForKeyPress (key)); | ||||
| @@ -487,6 +487,13 @@ public: | |||||
| } | } | ||||
| setMessage (message); | setMessage (message); | ||||
| return true; | |||||
| } | |||||
| bool keyStateChanged() | |||||
| { | |||||
| return true; | |||||
| } | } | ||||
| }; | }; | ||||
| @@ -336,9 +336,11 @@ XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefault | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| void KeyPressMappingSet::keyPressed (const KeyPress& key, | |||||
| bool KeyPressMappingSet::keyPressed (const KeyPress& key, | |||||
| Component* originatingComponent) | Component* originatingComponent) | ||||
| { | { | ||||
| bool used = false; | |||||
| const CommandID commandID = findCommandForKeyPress (key); | const CommandID commandID = findCommandForKeyPress (key); | ||||
| const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID); | const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID); | ||||
| @@ -352,16 +354,20 @@ void KeyPressMappingSet::keyPressed (const KeyPress& key, | |||||
| && (info.flags & ApplicationCommandInfo::isDisabled) == 0) | && (info.flags & ApplicationCommandInfo::isDisabled) == 0) | ||||
| { | { | ||||
| invokeCommand (commandID, key, true, 0, originatingComponent); | invokeCommand (commandID, key, true, 0, originatingComponent); | ||||
| used = true; | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| PlatformUtilities::beep(); | PlatformUtilities::beep(); | ||||
| } | } | ||||
| } | } | ||||
| return used; | |||||
| } | } | ||||
| void KeyPressMappingSet::keyStateChanged (Component* originatingComponent) | |||||
| bool KeyPressMappingSet::keyStateChanged (Component* originatingComponent) | |||||
| { | { | ||||
| bool used = false; | |||||
| const uint32 now = Time::getMillisecondCounter(); | const uint32 now = Time::getMillisecondCounter(); | ||||
| for (int i = mappings.size(); --i >= 0;) | for (int i = mappings.size(); --i >= 0;) | ||||
| @@ -411,10 +417,13 @@ void KeyPressMappingSet::keyStateChanged (Component* originatingComponent) | |||||
| } | } | ||||
| invokeCommand (cm->commandID, key, isDown, millisecs, originatingComponent); | invokeCommand (cm->commandID, key, isDown, millisecs, originatingComponent); | ||||
| used = true; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return used; | |||||
| } | } | ||||
| void KeyPressMappingSet::globalFocusChanged (Component* focusedComponent) | void KeyPressMappingSet::globalFocusChanged (Component* focusedComponent) | ||||
| @@ -228,9 +228,9 @@ public: | |||||
| //============================================================================== | //============================================================================== | ||||
| /** @internal */ | /** @internal */ | ||||
| void keyPressed (const KeyPress& key, Component* originatingComponent); | |||||
| bool keyPressed (const KeyPress& key, Component* originatingComponent); | |||||
| /** @internal */ | /** @internal */ | ||||
| void keyStateChanged (Component* originatingComponent); | |||||
| bool keyStateChanged (Component* originatingComponent); | |||||
| /** @internal */ | /** @internal */ | ||||
| void globalFocusChanged (Component* focusedComponent); | void globalFocusChanged (Component* focusedComponent); | ||||
| @@ -433,23 +433,27 @@ void ScrollBar::timerCallback() | |||||
| } | } | ||||
| } | } | ||||
| void ScrollBar::keyPressed (const KeyPress& key) | |||||
| bool ScrollBar::keyPressed (const KeyPress& key) | |||||
| { | { | ||||
| if (isVisible()) | |||||
| { | |||||
| if (key.isKeyCode (KeyPress::upKey) || key.isKeyCode (KeyPress::leftKey)) | |||||
| moveScrollbarInSteps (-1); | |||||
| else if (key.isKeyCode (KeyPress::downKey) || key.isKeyCode (KeyPress::rightKey)) | |||||
| moveScrollbarInSteps (1); | |||||
| else if (key.isKeyCode (KeyPress::pageUpKey)) | |||||
| moveScrollbarInPages (-1); | |||||
| else if (key.isKeyCode (KeyPress::pageDownKey)) | |||||
| moveScrollbarInPages (1); | |||||
| else if (key.isKeyCode (KeyPress::homeKey)) | |||||
| scrollToTop(); | |||||
| else if (key.isKeyCode (KeyPress::endKey)) | |||||
| scrollToBottom(); | |||||
| } | |||||
| if (! isVisible()) | |||||
| return false; | |||||
| if (key.isKeyCode (KeyPress::upKey) || key.isKeyCode (KeyPress::leftKey)) | |||||
| moveScrollbarInSteps (-1); | |||||
| else if (key.isKeyCode (KeyPress::downKey) || key.isKeyCode (KeyPress::rightKey)) | |||||
| moveScrollbarInSteps (1); | |||||
| else if (key.isKeyCode (KeyPress::pageUpKey)) | |||||
| moveScrollbarInPages (-1); | |||||
| else if (key.isKeyCode (KeyPress::pageDownKey)) | |||||
| moveScrollbarInPages (1); | |||||
| else if (key.isKeyCode (KeyPress::homeKey)) | |||||
| scrollToTop(); | |||||
| else if (key.isKeyCode (KeyPress::endKey)) | |||||
| scrollToBottom(); | |||||
| else | |||||
| return false; | |||||
| return true; | |||||
| } | } | ||||
| END_JUCE_NAMESPACE | END_JUCE_NAMESPACE | ||||
| @@ -259,7 +259,7 @@ public: | |||||
| //============================================================================== | //============================================================================== | ||||
| /** @internal */ | /** @internal */ | ||||
| void keyPressed (const KeyPress& key); | |||||
| bool keyPressed (const KeyPress& key); | |||||
| /** @internal */ | /** @internal */ | ||||
| void mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY); | void mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY); | ||||
| /** @internal */ | /** @internal */ | ||||
| @@ -304,7 +304,7 @@ bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, float wheelIncrem | |||||
| return false; | return false; | ||||
| } | } | ||||
| void Viewport::keyPressed (const KeyPress& key) | |||||
| bool Viewport::keyPressed (const KeyPress& key) | |||||
| { | { | ||||
| const bool isUpDownKey = key.isKeyCode (KeyPress::upKey) | const bool isUpDownKey = key.isKeyCode (KeyPress::upKey) | ||||
| || key.isKeyCode (KeyPress::downKey) | || key.isKeyCode (KeyPress::downKey) | ||||
| @@ -313,21 +313,17 @@ void Viewport::keyPressed (const KeyPress& key) | |||||
| || key.isKeyCode (KeyPress::homeKey) | || key.isKeyCode (KeyPress::homeKey) | ||||
| || key.isKeyCode (KeyPress::endKey); | || key.isKeyCode (KeyPress::endKey); | ||||
| if (verticalScrollBar->isVisible() && isUpDownKey) | |||||
| return verticalScrollBar->keyPressed (key); | |||||
| const bool isLeftRightKey = key.isKeyCode (KeyPress::leftKey) | const bool isLeftRightKey = key.isKeyCode (KeyPress::leftKey) | ||||
| || key.isKeyCode (KeyPress::rightKey); | || key.isKeyCode (KeyPress::rightKey); | ||||
| if (verticalScrollBar->isVisible() && isUpDownKey) | |||||
| { | |||||
| verticalScrollBar->keyPressed (key); | |||||
| } | |||||
| else if (horizontalScrollBar->isVisible() && (isLeftRightKey || isUpDownKey)) | |||||
| { | |||||
| horizontalScrollBar->keyPressed (key); | |||||
| } | |||||
| else | |||||
| { | |||||
| Component::keyPressed (key); | |||||
| } | |||||
| if (horizontalScrollBar->isVisible() && (isUpDownKey || isLeftRightKey)) | |||||
| return horizontalScrollBar->keyPressed (key); | |||||
| return false; | |||||
| } | } | ||||
| END_JUCE_NAMESPACE | END_JUCE_NAMESPACE | ||||
| @@ -224,7 +224,7 @@ public: | |||||
| /** @internal */ | /** @internal */ | ||||
| void mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY); | void mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY); | ||||
| /** @internal */ | /** @internal */ | ||||
| void keyPressed (const KeyPress& key); | |||||
| bool keyPressed (const KeyPress& key); | |||||
| /** @internal */ | /** @internal */ | ||||
| void componentMovedOrResized (Component& component, bool wasMoved, bool wasResized); | void componentMovedOrResized (Component& component, bool wasMoved, bool wasResized); | ||||
| /** @internal */ | /** @internal */ | ||||
| @@ -385,19 +385,24 @@ void MenuBarComponent::mouseMove (const MouseEvent& e) | |||||
| } | } | ||||
| } | } | ||||
| void MenuBarComponent::keyPressed (const KeyPress& key) | |||||
| bool MenuBarComponent::keyPressed (const KeyPress& key) | |||||
| { | { | ||||
| bool used = false; | |||||
| const int numMenus = menuNames.size(); | const int numMenus = menuNames.size(); | ||||
| const int currentIndex = jlimit (0, menuNames.size() - 1, currentPopupIndex); | const int currentIndex = jlimit (0, menuNames.size() - 1, currentPopupIndex); | ||||
| if (key.isKeyCode (KeyPress::leftKey)) | if (key.isKeyCode (KeyPress::leftKey)) | ||||
| { | { | ||||
| showMenu ((currentIndex + numMenus - 1) % numMenus); | showMenu ((currentIndex + numMenus - 1) % numMenus); | ||||
| used = true; | |||||
| } | } | ||||
| else if (key.isKeyCode (KeyPress::rightKey)) | else if (key.isKeyCode (KeyPress::rightKey)) | ||||
| { | { | ||||
| showMenu ((currentIndex + 1) % numMenus); | showMenu ((currentIndex + 1) % numMenus); | ||||
| used = true; | |||||
| } | } | ||||
| return used; | |||||
| } | } | ||||
| void MenuBarComponent::inputAttemptWhenModal() | void MenuBarComponent::inputAttemptWhenModal() | ||||
| @@ -96,7 +96,7 @@ public: | |||||
| /** @internal */ | /** @internal */ | ||||
| void handleCommandMessage (int commandId); | void handleCommandMessage (int commandId); | ||||
| /** @internal */ | /** @internal */ | ||||
| void keyPressed (const KeyPress& key); | |||||
| bool keyPressed (const KeyPress& key); | |||||
| /** @internal */ | /** @internal */ | ||||
| void menuBarItemsChanged (MenuBarModel* menuBarModel); | void menuBarItemsChanged (MenuBarModel* menuBarModel); | ||||
| /** @internal */ | /** @internal */ | ||||
| @@ -552,7 +552,7 @@ public: | |||||
| lastMouseX = -1; | lastMouseX = -1; | ||||
| } | } | ||||
| void keyPressed (const KeyPress& key) | |||||
| bool keyPressed (const KeyPress& key) | |||||
| { | { | ||||
| if (key.isKeyCode (KeyPress::downKey)) | if (key.isKeyCode (KeyPress::downKey)) | ||||
| { | { | ||||
| @@ -607,6 +607,12 @@ public: | |||||
| { | { | ||||
| dismissMenu (0); | dismissMenu (0); | ||||
| } | } | ||||
| else | |||||
| { | |||||
| return false; | |||||
| } | |||||
| return true; | |||||
| } | } | ||||
| void inputAttemptWhenModal() | void inputAttemptWhenModal() | ||||
| @@ -834,7 +834,7 @@ void MidiKeyboardComponent::setKeyPressBaseOctave (const int newOctaveNumber) | |||||
| keyMappingOctave = newOctaveNumber; | keyMappingOctave = newOctaveNumber; | ||||
| } | } | ||||
| void MidiKeyboardComponent::keyStateChanged() | |||||
| bool MidiKeyboardComponent::keyStateChanged() | |||||
| { | { | ||||
| bool keyPressUsed = false; | bool keyPressUsed = false; | ||||
| @@ -862,8 +862,7 @@ void MidiKeyboardComponent::keyStateChanged() | |||||
| } | } | ||||
| } | } | ||||
| if (! keyPressUsed) | |||||
| Component::keyStateChanged(); | |||||
| return keyPressUsed; | |||||
| } | } | ||||
| void MidiKeyboardComponent::focusLost (FocusChangeType) | void MidiKeyboardComponent::focusLost (FocusChangeType) | ||||
| @@ -292,7 +292,7 @@ public: | |||||
| /** @internal */ | /** @internal */ | ||||
| void timerCallback(); | void timerCallback(); | ||||
| /** @internal */ | /** @internal */ | ||||
| void keyStateChanged(); | |||||
| bool keyStateChanged(); | |||||
| /** @internal */ | /** @internal */ | ||||
| void focusLost (FocusChangeType cause); | void focusLost (FocusChangeType cause); | ||||
| /** @internal */ | /** @internal */ | ||||
| @@ -565,7 +565,7 @@ void AlertWindow::mouseDrag (const MouseEvent& e) | |||||
| dragger.dragComponent (this, e); | dragger.dragComponent (this, e); | ||||
| } | } | ||||
| void AlertWindow::keyPressed (const KeyPress& key) | |||||
| bool AlertWindow::keyPressed (const KeyPress& key) | |||||
| { | { | ||||
| for (int i = buttons.size(); --i >= 0;) | for (int i = buttons.size(); --i >= 0;) | ||||
| { | { | ||||
| @@ -574,20 +574,22 @@ void AlertWindow::keyPressed (const KeyPress& key) | |||||
| if (b->isRegisteredForShortcut (key)) | if (b->isRegisteredForShortcut (key)) | ||||
| { | { | ||||
| b->triggerClick(); | b->triggerClick(); | ||||
| return; | |||||
| return true; | |||||
| } | } | ||||
| } | } | ||||
| if (buttons.size() == 0) | |||||
| if (key.isKeyCode (KeyPress::escapeKey) && buttons.size() == 0) | |||||
| { | { | ||||
| exitModalState (0); | exitModalState (0); | ||||
| return true; | |||||
| } | } | ||||
| else if (key.isKeyCode (KeyPress::returnKey) | |||||
| && buttons.size() == 1) | |||||
| else if (key.isKeyCode (KeyPress::returnKey) && buttons.size() == 1) | |||||
| { | { | ||||
| AlertWindowTextButton* const mb = (AlertWindowTextButton*) buttons.getFirst(); | |||||
| mb->triggerClick(); | |||||
| ((AlertWindowTextButton*) buttons.getFirst())->triggerClick(); | |||||
| return true; | |||||
| } | } | ||||
| return false; | |||||
| } | } | ||||
| void AlertWindow::lookAndFeelChanged() | void AlertWindow::lookAndFeelChanged() | ||||
| @@ -332,7 +332,7 @@ protected: | |||||
| /** @internal */ | /** @internal */ | ||||
| void mouseDrag (const MouseEvent& e); | void mouseDrag (const MouseEvent& e); | ||||
| /** @internal */ | /** @internal */ | ||||
| void keyPressed (const KeyPress& key); | |||||
| bool keyPressed (const KeyPress& key); | |||||
| /** @internal */ | /** @internal */ | ||||
| void buttonClicked (Button* button); | void buttonClicked (Button* button); | ||||
| /** @internal */ | /** @internal */ | ||||
| @@ -408,18 +408,106 @@ bool ComponentPeer::handleKeyPress (const int keyCode, | |||||
| { | { | ||||
| updateCurrentModifiers(); | updateCurrentModifiers(); | ||||
| return (Component::currentlyFocusedComponent->isValidComponent() | |||||
| ? Component::currentlyFocusedComponent : component) | |||||
| ->internalKeyPress (keyCode, textCharacter); | |||||
| Component* target = Component::currentlyFocusedComponent->isValidComponent() | |||||
| ? Component::currentlyFocusedComponent | |||||
| : component; | |||||
| if (target->isCurrentlyBlockedByAnotherModalComponent()) | |||||
| { | |||||
| Component* const currentModalComp = Component::getCurrentlyModalComponent(); | |||||
| if (currentModalComp != 0) | |||||
| target = currentModalComp; | |||||
| } | |||||
| const KeyPress keyInfo (keyCode, | |||||
| ModifierKeys::getCurrentModifiers().getRawFlags() | |||||
| & ModifierKeys::allKeyboardModifiers, | |||||
| textCharacter); | |||||
| bool keyWasUsed = false; | |||||
| while (target != 0) | |||||
| { | |||||
| const ComponentDeletionWatcher deletionChecker (target); | |||||
| keyWasUsed = target->keyPressed (keyInfo); | |||||
| if (keyWasUsed || deletionChecker.hasBeenDeleted()) | |||||
| break; | |||||
| if (target->keyListeners_ != 0) | |||||
| { | |||||
| for (int i = target->keyListeners_->size(); --i >= 0;) | |||||
| { | |||||
| keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyPressed (keyInfo, target); | |||||
| if (keyWasUsed || deletionChecker.hasBeenDeleted()) | |||||
| return keyWasUsed; | |||||
| i = jmin (i, target->keyListeners_->size()); | |||||
| } | |||||
| } | |||||
| if (keyInfo.isKeyCode (KeyPress::tabKey) && Component::getCurrentlyFocusedComponent() != 0) | |||||
| { | |||||
| Component::getCurrentlyFocusedComponent() | |||||
| ->moveKeyboardFocusToSibling (! keyInfo.getModifiers().isShiftDown()); | |||||
| keyWasUsed = true; | |||||
| break; | |||||
| } | |||||
| target = target->parentComponent_; | |||||
| } | |||||
| return keyWasUsed; | |||||
| } | } | ||||
| bool ComponentPeer::handleKeyUpOrDown() | bool ComponentPeer::handleKeyUpOrDown() | ||||
| { | { | ||||
| updateCurrentModifiers(); | updateCurrentModifiers(); | ||||
| return (Component::currentlyFocusedComponent->isValidComponent() | |||||
| ? Component::currentlyFocusedComponent : component) | |||||
| ->internalKeyStateChanged(); | |||||
| Component* target = Component::currentlyFocusedComponent->isValidComponent() | |||||
| ? Component::currentlyFocusedComponent | |||||
| : component; | |||||
| if (target->isCurrentlyBlockedByAnotherModalComponent()) | |||||
| { | |||||
| Component* const currentModalComp = Component::getCurrentlyModalComponent(); | |||||
| if (currentModalComp != 0) | |||||
| target = currentModalComp; | |||||
| } | |||||
| bool keyWasUsed = false; | |||||
| while (target != 0) | |||||
| { | |||||
| const ComponentDeletionWatcher deletionChecker (target); | |||||
| keyWasUsed = target->keyStateChanged(); | |||||
| if (keyWasUsed || deletionChecker.hasBeenDeleted()) | |||||
| break; | |||||
| if (target->keyListeners_ != 0) | |||||
| { | |||||
| for (int i = target->keyListeners_->size(); --i >= 0;) | |||||
| { | |||||
| keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyStateChanged (target); | |||||
| if (keyWasUsed || deletionChecker.hasBeenDeleted()) | |||||
| return keyWasUsed; | |||||
| i = jmin (i, target->keyListeners_->size()); | |||||
| } | |||||
| } | |||||
| target = target->parentComponent_; | |||||
| } | |||||
| return keyWasUsed; | |||||
| } | } | ||||
| void ComponentPeer::handleModifierKeysChange() | void ComponentPeer::handleModifierKeysChange() | ||||