From 7d953a629ddf12700dba87ceafd6a10e587bf613 Mon Sep 17 00:00:00 2001 From: jules Date: Fri, 7 Sep 2012 18:52:30 +0100 Subject: [PATCH] OSX modal behaviour fix. --- .../native/juce_mac_FileChooser.mm | 9 ++++----- .../native/juce_mac_MainMenu.mm | 5 ++--- .../native/juce_mac_NSViewComponentPeer.mm | 20 +++++++------------ 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/modules/juce_gui_basics/native/juce_mac_FileChooser.mm b/modules/juce_gui_basics/native/juce_mac_FileChooser.mm index 2611bb3a97..002cad56ca 100644 --- a/modules/juce_gui_basics/native/juce_mac_FileChooser.mm +++ b/modules/juce_gui_basics/native/juce_mac_FileChooser.mm @@ -136,15 +136,14 @@ private: // The OS view already plays an alert when clicking outside // the modal comp, so this override avoids adding extra // inappropriate noises when the cancel button is pressed. + // This override is also important because it stops the base class + // calling ModalComponentManager::bringToFront, which can get + // recursive when file dialogs are involved class SilentDummyModalComp : public Component { public: SilentDummyModalComp() {} - - void inputAttemptWhenModal() - { - ModalComponentManager::getInstance()->bringModalComponentsToFront(); - } + void inputAttemptWhenModal() {} }; SilentDummyModalComp dummyModalComponent; diff --git a/modules/juce_gui_basics/native/juce_mac_MainMenu.mm b/modules/juce_gui_basics/native/juce_mac_MainMenu.mm index 868935e222..e0f8bc55d0 100644 --- a/modules/juce_gui_basics/native/juce_mac_MainMenu.mm +++ b/modules/juce_gui_basics/native/juce_mac_MainMenu.mm @@ -246,9 +246,8 @@ public: { const KeyPress& kp = keyPresses.getReference(0); - if ((kp.getKeyCode() != KeyPress::backspaceKey // (adding these is annoying because it flashes the menu bar - && kp.getKeyCode() != KeyPress::deleteKey) // every time you press the key while editing text) - || kp.getModifiers().isAnyModifierKeyDown()) + if (kp != KeyPress::backspaceKey // (adding these is annoying because it flashes the menu bar + && kp != KeyPress::deleteKey) // every time you press the key while editing text) { juce_wchar key = kp.getTextCharacter(); if (key == 0) diff --git a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm index fa2ff16bec..d6681fd2ba 100644 --- a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm @@ -792,9 +792,6 @@ public: bool canBecomeKeyWindow() { - if (sendModalInputAttemptIfBlocked()) - return false; - return (getStyleFlags() & juce::ComponentPeer::windowIgnoresKeyPresses) == 0; } @@ -1668,16 +1665,17 @@ private: static BOOL canBecomeKeyWindow (id self, SEL) { NSViewComponentPeer* const owner = getOwner (self); - return owner != nullptr && owner->canBecomeKeyWindow(); + + return owner != nullptr + && owner->canBecomeKeyWindow() + && ! owner->sendModalInputAttemptIfBlocked(); } static void becomeKeyWindow (id self, SEL) { sendSuperclassMessage (self, @selector (becomeKeyWindow)); - NSViewComponentPeer* const owner = getOwner (self); - - if (owner != nullptr) + if (NSViewComponentPeer* const owner = getOwner (self)) owner->becomeKeyWindow(); } @@ -1689,9 +1687,7 @@ private: static NSRect constrainFrameRect (id self, SEL, NSRect frameRect, NSScreen*) { - NSViewComponentPeer* const owner = getOwner (self); - - if (owner != nullptr) + if (NSViewComponentPeer* const owner = getOwner (self)) frameRect = owner->constrainRect (frameRect); return frameRect; @@ -1718,9 +1714,7 @@ private: static void zoom (id self, SEL, id sender) { - NSViewComponentPeer* const owner = getOwner (self); - - if (owner != nullptr) + if (NSViewComponentPeer* const owner = getOwner (self)) { owner->isZooming = true; objc_super s = { self, [NSWindow class] };