mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-23 01:44:22 +00:00
Improvements to modal event blocking for plugins; small bugfix for OwnedArrays.
This commit is contained in:
parent
4570818cc0
commit
44938b9cd0
12 changed files with 238 additions and 60 deletions
|
|
@ -276,28 +276,70 @@ static bool isEventBlockedByModalComps (NSEvent* e)
|
|||
if (Component::getNumCurrentlyModalComponents() == 0)
|
||||
return false;
|
||||
|
||||
[[NSApp mainMenu] update];
|
||||
NSWindow* const w = [e window];
|
||||
if (w == 0 || [w worksWhenModal])
|
||||
return false;
|
||||
|
||||
bool isKey = false, isInputAttempt = false;
|
||||
|
||||
switch ([e type])
|
||||
{
|
||||
case NSKeyDown:
|
||||
case NSKeyUp:
|
||||
isKey = isInputAttempt = true;
|
||||
break;
|
||||
|
||||
case NSLeftMouseDown:
|
||||
case NSRightMouseDown:
|
||||
case NSOtherMouseDown:
|
||||
isInputAttempt = true;
|
||||
break;
|
||||
|
||||
case NSLeftMouseDragged:
|
||||
case NSRightMouseDragged:
|
||||
case NSLeftMouseUp:
|
||||
case NSRightMouseUp:
|
||||
case NSOtherMouseUp:
|
||||
case NSOtherMouseDragged:
|
||||
if (Component::getComponentUnderMouse() != 0)
|
||||
return false;
|
||||
break;
|
||||
|
||||
case NSMouseMoved:
|
||||
case NSMouseEntered:
|
||||
case NSMouseExited:
|
||||
case NSCursorUpdate:
|
||||
case NSScrollWheel:
|
||||
case NSTabletPoint:
|
||||
case NSTabletProximity:
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
|
||||
{
|
||||
ComponentPeer* const peer = ComponentPeer::getPeer (i);
|
||||
NSView* const compView = (NSView*) peer->getNativeHandle();
|
||||
|
||||
if ([compView window] == w
|
||||
&& (NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil],
|
||||
[compView bounds])
|
||||
|| peer->getComponent()->isMouseButtonDown()))
|
||||
if ([compView window] == w)
|
||||
{
|
||||
return false;
|
||||
if (isKey)
|
||||
{
|
||||
if (compView == [w firstResponder])
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil],
|
||||
[compView bounds]))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ([e type] == NSLeftMouseDown
|
||||
|| [e type] == NSRightMouseDown
|
||||
|| [e type] == NSOtherMouseDown)
|
||||
if (isInputAttempt)
|
||||
{
|
||||
if (! [NSApp isActive])
|
||||
[NSApp activateIgnoringOtherApps: YES];
|
||||
|
|
@ -330,7 +372,7 @@ bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
|
|||
inMode: NSDefaultRunLoopMode
|
||||
dequeue: YES];
|
||||
|
||||
if (! isEventBlockedByModalComps (e))
|
||||
if (e != 0 && ! isEventBlockedByModalComps (e))
|
||||
[NSApp sendEvent: e];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1141,6 +1141,8 @@ void juce_HandleProcessFocusChange()
|
|||
if (Process::isForegroundProcess())
|
||||
{
|
||||
currentlyFocusedPeer->handleFocusGain();
|
||||
|
||||
ComponentPeer::bringModalComponentToFront();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1223,13 +1225,19 @@ bool NSViewComponentPeer::redirectKeyDown (NSEvent* ev)
|
|||
used = (isValidPeer (this) && handleKeyEvent (ev, false)) || used;
|
||||
}
|
||||
|
||||
// (If we're running modally, don't allow unused keystrokes to be passed
|
||||
// along to other blocked views..)
|
||||
if (Component::getCurrentlyModalComponent() != 0)
|
||||
used = true;
|
||||
|
||||
return used;
|
||||
}
|
||||
|
||||
bool NSViewComponentPeer::redirectKeyUp (NSEvent* ev)
|
||||
{
|
||||
updateKeysDown (ev, false);
|
||||
return handleKeyEvent (ev, false);
|
||||
return handleKeyEvent (ev, false)
|
||||
|| Component::getCurrentlyModalComponent() != 0;
|
||||
}
|
||||
|
||||
void NSViewComponentPeer::redirectModKeyChange (NSEvent* ev)
|
||||
|
|
|
|||
|
|
@ -164,6 +164,10 @@ public:
|
|||
|
||||
renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
|
||||
shareContext: sharedContext] autorelease];
|
||||
|
||||
const long swapInterval = 1;
|
||||
[renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
|
||||
|
||||
[view setOpenGLContext: renderContext];
|
||||
[renderContext setView: view];
|
||||
|
||||
|
|
|
|||
|
|
@ -1477,7 +1477,8 @@ private:
|
|||
sendModifierKeyChangeIfNeeded();
|
||||
}
|
||||
|
||||
return handleKeyUpOrDown();
|
||||
return handleKeyUpOrDown()
|
||||
|| Component::getCurrentlyModalComponent() != 0;
|
||||
}
|
||||
|
||||
bool doKeyDown (const WPARAM key)
|
||||
|
|
@ -1563,6 +1564,9 @@ private:
|
|||
break;
|
||||
}
|
||||
|
||||
if (Component::getCurrentlyModalComponent() != 0)
|
||||
used = true;
|
||||
|
||||
return used;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39433,6 +39433,8 @@ void Component::exitModalState (const int returnValue)
|
|||
modalComponentStack.removeValue (this);
|
||||
|
||||
flags.currentlyModalFlag = false;
|
||||
|
||||
bringModalComponentToFront();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -39469,6 +39471,34 @@ Component* JUCE_CALLTYPE Component::getCurrentlyModalComponent (int index) throw
|
|||
return c->isValidComponent() ? c : 0;
|
||||
}
|
||||
|
||||
void Component::bringModalComponentToFront()
|
||||
{
|
||||
ComponentPeer* lastOne = 0;
|
||||
|
||||
for (int i = 0; i < getNumCurrentlyModalComponents(); ++i)
|
||||
{
|
||||
Component* const c = getCurrentlyModalComponent (i);
|
||||
|
||||
if (c == 0)
|
||||
break;
|
||||
|
||||
ComponentPeer* peer = c->getPeer();
|
||||
|
||||
if (peer != 0 && peer != lastOne)
|
||||
{
|
||||
if (lastOne == 0)
|
||||
{
|
||||
peer->toFront (true);
|
||||
peer->grabFocus();
|
||||
}
|
||||
else
|
||||
peer->toBehind (lastOne);
|
||||
|
||||
lastOne = peer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Component::setBroughtToFrontOnMouseClick (const bool shouldBeBroughtToFront) throw()
|
||||
{
|
||||
flags.bringToFrontOnClickFlag = shouldBeBroughtToFront;
|
||||
|
|
@ -40063,8 +40093,7 @@ void Component::removeComponentListener (ComponentListener* const listenerToRemo
|
|||
|
||||
void Component::inputAttemptWhenModal()
|
||||
{
|
||||
getTopLevelComponent()->toFront (true);
|
||||
|
||||
bringModalComponentToFront();
|
||||
getLookAndFeel().playAlertSound();
|
||||
}
|
||||
|
||||
|
|
@ -40982,9 +41011,7 @@ void Component::internalBroughtToFront()
|
|||
Component* const cm = getCurrentlyModalComponent();
|
||||
|
||||
if (cm != 0 && cm->getTopLevelComponent() != getTopLevelComponent())
|
||||
{
|
||||
cm->getTopLevelComponent()->toFront (true);
|
||||
}
|
||||
bringModalComponentToFront();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -60913,7 +60940,7 @@ AlertWindow* LookAndFeel::createAlertWindow (const String& title,
|
|||
int numButtons,
|
||||
Component* associatedComponent)
|
||||
{
|
||||
AlertWindow* aw = new AlertWindow (title, message, iconType);
|
||||
AlertWindow* aw = new AlertWindow (title, message, iconType, associatedComponent);
|
||||
|
||||
if (numButtons == 1)
|
||||
{
|
||||
|
|
@ -73091,16 +73118,9 @@ void ComponentPeer::handleFocusGain()
|
|||
else
|
||||
{
|
||||
if (! component->isCurrentlyBlockedByAnotherModalComponent())
|
||||
{
|
||||
component->grabKeyboardFocus();
|
||||
}
|
||||
else
|
||||
{
|
||||
Component* const currentModalComp = Component::getCurrentlyModalComponent();
|
||||
|
||||
if (currentModalComp != 0)
|
||||
currentModalComp->toFront (! currentModalComp->hasKeyboardFocus (true));
|
||||
}
|
||||
Component::bringModalComponentToFront();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -73257,6 +73277,11 @@ void ComponentPeer::handleUserClosingWindow()
|
|||
component->userTriedToCloseWindow();
|
||||
}
|
||||
|
||||
void ComponentPeer::bringModalComponentToFront()
|
||||
{
|
||||
Component::bringModalComponentToFront();
|
||||
}
|
||||
|
||||
void ComponentPeer::clearMaskedRegion() throw()
|
||||
{
|
||||
maskedRegion.clear();
|
||||
|
|
@ -244470,7 +244495,8 @@ private:
|
|||
sendModifierKeyChangeIfNeeded();
|
||||
}
|
||||
|
||||
return handleKeyUpOrDown();
|
||||
return handleKeyUpOrDown()
|
||||
|| Component::getCurrentlyModalComponent() != 0;
|
||||
}
|
||||
|
||||
bool doKeyDown (const WPARAM key)
|
||||
|
|
@ -244556,6 +244582,9 @@ private:
|
|||
break;
|
||||
}
|
||||
|
||||
if (Component::getCurrentlyModalComponent() != 0)
|
||||
used = true;
|
||||
|
||||
return used;
|
||||
}
|
||||
|
||||
|
|
@ -267916,6 +267945,8 @@ void juce_HandleProcessFocusChange()
|
|||
if (Process::isForegroundProcess())
|
||||
{
|
||||
currentlyFocusedPeer->handleFocusGain();
|
||||
|
||||
ComponentPeer::bringModalComponentToFront();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -267998,13 +268029,19 @@ bool NSViewComponentPeer::redirectKeyDown (NSEvent* ev)
|
|||
used = (isValidPeer (this) && handleKeyEvent (ev, false)) || used;
|
||||
}
|
||||
|
||||
// (If we're running modally, don't allow unused keystrokes to be passed
|
||||
// along to other blocked views..)
|
||||
if (Component::getCurrentlyModalComponent() != 0)
|
||||
used = true;
|
||||
|
||||
return used;
|
||||
}
|
||||
|
||||
bool NSViewComponentPeer::redirectKeyUp (NSEvent* ev)
|
||||
{
|
||||
updateKeysDown (ev, false);
|
||||
return handleKeyEvent (ev, false);
|
||||
return handleKeyEvent (ev, false)
|
||||
|| Component::getCurrentlyModalComponent() != 0;
|
||||
}
|
||||
|
||||
void NSViewComponentPeer::redirectModKeyChange (NSEvent* ev)
|
||||
|
|
@ -268984,6 +269021,10 @@ public:
|
|||
|
||||
renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
|
||||
shareContext: sharedContext] autorelease];
|
||||
|
||||
const long swapInterval = 1;
|
||||
[renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
|
||||
|
||||
[view setOpenGLContext: renderContext];
|
||||
[renderContext setView: view];
|
||||
|
||||
|
|
@ -270977,28 +271018,70 @@ static bool isEventBlockedByModalComps (NSEvent* e)
|
|||
if (Component::getNumCurrentlyModalComponents() == 0)
|
||||
return false;
|
||||
|
||||
[[NSApp mainMenu] update];
|
||||
NSWindow* const w = [e window];
|
||||
if (w == 0 || [w worksWhenModal])
|
||||
return false;
|
||||
|
||||
bool isKey = false, isInputAttempt = false;
|
||||
|
||||
switch ([e type])
|
||||
{
|
||||
case NSKeyDown:
|
||||
case NSKeyUp:
|
||||
isKey = isInputAttempt = true;
|
||||
break;
|
||||
|
||||
case NSLeftMouseDown:
|
||||
case NSRightMouseDown:
|
||||
case NSOtherMouseDown:
|
||||
isInputAttempt = true;
|
||||
break;
|
||||
|
||||
case NSLeftMouseDragged:
|
||||
case NSRightMouseDragged:
|
||||
case NSLeftMouseUp:
|
||||
case NSRightMouseUp:
|
||||
case NSOtherMouseUp:
|
||||
case NSOtherMouseDragged:
|
||||
if (Component::getComponentUnderMouse() != 0)
|
||||
return false;
|
||||
break;
|
||||
|
||||
case NSMouseMoved:
|
||||
case NSMouseEntered:
|
||||
case NSMouseExited:
|
||||
case NSCursorUpdate:
|
||||
case NSScrollWheel:
|
||||
case NSTabletPoint:
|
||||
case NSTabletProximity:
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
|
||||
{
|
||||
ComponentPeer* const peer = ComponentPeer::getPeer (i);
|
||||
NSView* const compView = (NSView*) peer->getNativeHandle();
|
||||
|
||||
if ([compView window] == w
|
||||
&& (NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil],
|
||||
[compView bounds])
|
||||
|| peer->getComponent()->isMouseButtonDown()))
|
||||
if ([compView window] == w)
|
||||
{
|
||||
return false;
|
||||
if (isKey)
|
||||
{
|
||||
if (compView == [w firstResponder])
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil],
|
||||
[compView bounds]))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ([e type] == NSLeftMouseDown
|
||||
|| [e type] == NSRightMouseDown
|
||||
|| [e type] == NSOtherMouseDown)
|
||||
if (isInputAttempt)
|
||||
{
|
||||
if (! [NSApp isActive])
|
||||
[NSApp activateIgnoringOtherApps: YES];
|
||||
|
|
@ -271031,7 +271114,7 @@ bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
|
|||
inMode: NSDefaultRunLoopMode
|
||||
dequeue: YES];
|
||||
|
||||
if (! isEventBlockedByModalComps (e))
|
||||
if (e != 0 && ! isEventBlockedByModalComps (e))
|
||||
[NSApp sendEvent: e];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3561,12 +3561,14 @@ public:
|
|||
if (indexToChange < numUsed)
|
||||
{
|
||||
if (deleteOldElement)
|
||||
{
|
||||
toDelete = this->elements [indexToChange];
|
||||
|
||||
if (toDelete == newObject)
|
||||
toDelete = 0;
|
||||
else
|
||||
this->elements [indexToChange] = const_cast <ObjectClass*> (newObject);
|
||||
if (toDelete == newObject)
|
||||
toDelete = 0;
|
||||
}
|
||||
|
||||
this->elements [indexToChange] = const_cast <ObjectClass*> (newObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -20934,6 +20936,8 @@ public:
|
|||
*/
|
||||
static bool isValidPeer (const ComponentPeer* const peer) throw();
|
||||
|
||||
static void bringModalComponentToFront();
|
||||
|
||||
juce_UseDebuggingNewOperator
|
||||
|
||||
protected:
|
||||
|
|
@ -22963,6 +22967,7 @@ private:
|
|||
static void giveAwayFocus();
|
||||
void sendEnablementChangeMessage();
|
||||
static void* runModalLoopCallback (void*);
|
||||
static void bringModalComponentToFront();
|
||||
void subtractObscuredRegions (RectangleList& result,
|
||||
const int deltaX, const int deltaY,
|
||||
const Rectangle& clipRect,
|
||||
|
|
|
|||
|
|
@ -1515,6 +1515,8 @@ void Component::exitModalState (const int returnValue)
|
|||
modalComponentStack.removeValue (this);
|
||||
|
||||
flags.currentlyModalFlag = false;
|
||||
|
||||
bringModalComponentToFront();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1551,6 +1553,34 @@ Component* JUCE_CALLTYPE Component::getCurrentlyModalComponent (int index) throw
|
|||
return c->isValidComponent() ? c : 0;
|
||||
}
|
||||
|
||||
void Component::bringModalComponentToFront()
|
||||
{
|
||||
ComponentPeer* lastOne = 0;
|
||||
|
||||
for (int i = 0; i < getNumCurrentlyModalComponents(); ++i)
|
||||
{
|
||||
Component* const c = getCurrentlyModalComponent (i);
|
||||
|
||||
if (c == 0)
|
||||
break;
|
||||
|
||||
ComponentPeer* peer = c->getPeer();
|
||||
|
||||
if (peer != 0 && peer != lastOne)
|
||||
{
|
||||
if (lastOne == 0)
|
||||
{
|
||||
peer->toFront (true);
|
||||
peer->grabFocus();
|
||||
}
|
||||
else
|
||||
peer->toBehind (lastOne);
|
||||
|
||||
lastOne = peer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void Component::setBroughtToFrontOnMouseClick (const bool shouldBeBroughtToFront) throw()
|
||||
{
|
||||
|
|
@ -2157,8 +2187,7 @@ void Component::removeComponentListener (ComponentListener* const listenerToRemo
|
|||
//==============================================================================
|
||||
void Component::inputAttemptWhenModal()
|
||||
{
|
||||
getTopLevelComponent()->toFront (true);
|
||||
|
||||
bringModalComponentToFront();
|
||||
getLookAndFeel().playAlertSound();
|
||||
}
|
||||
|
||||
|
|
@ -3085,9 +3114,7 @@ void Component::internalBroughtToFront()
|
|||
Component* const cm = getCurrentlyModalComponent();
|
||||
|
||||
if (cm != 0 && cm->getTopLevelComponent() != getTopLevelComponent())
|
||||
{
|
||||
cm->getTopLevelComponent()->toFront (true);
|
||||
}
|
||||
bringModalComponentToFront();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2085,6 +2085,7 @@ private:
|
|||
static void giveAwayFocus();
|
||||
void sendEnablementChangeMessage();
|
||||
static void* runModalLoopCallback (void*);
|
||||
static void bringModalComponentToFront();
|
||||
void subtractObscuredRegions (RectangleList& result,
|
||||
const int deltaX, const int deltaY,
|
||||
const Rectangle& clipRect,
|
||||
|
|
|
|||
|
|
@ -475,7 +475,7 @@ AlertWindow* LookAndFeel::createAlertWindow (const String& title,
|
|||
int numButtons,
|
||||
Component* associatedComponent)
|
||||
{
|
||||
AlertWindow* aw = new AlertWindow (title, message, iconType);
|
||||
AlertWindow* aw = new AlertWindow (title, message, iconType, associatedComponent);
|
||||
|
||||
if (numButtons == 1)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -604,16 +604,9 @@ void ComponentPeer::handleFocusGain()
|
|||
else
|
||||
{
|
||||
if (! component->isCurrentlyBlockedByAnotherModalComponent())
|
||||
{
|
||||
component->grabKeyboardFocus();
|
||||
}
|
||||
else
|
||||
{
|
||||
Component* const currentModalComp = Component::getCurrentlyModalComponent();
|
||||
|
||||
if (currentModalComp != 0)
|
||||
currentModalComp->toFront (! currentModalComp->hasKeyboardFocus (true));
|
||||
}
|
||||
Component::bringModalComponentToFront();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -772,6 +765,12 @@ void ComponentPeer::handleUserClosingWindow()
|
|||
component->userTriedToCloseWindow();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void ComponentPeer::bringModalComponentToFront()
|
||||
{
|
||||
Component::bringModalComponentToFront();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void ComponentPeer::clearMaskedRegion() throw()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -356,6 +356,9 @@ public:
|
|||
*/
|
||||
static bool isValidPeer (const ComponentPeer* const peer) throw();
|
||||
|
||||
//==============================================================================
|
||||
static void bringModalComponentToFront();
|
||||
|
||||
//==============================================================================
|
||||
juce_UseDebuggingNewOperator
|
||||
|
||||
|
|
|
|||
|
|
@ -355,12 +355,14 @@ public:
|
|||
if (indexToChange < numUsed)
|
||||
{
|
||||
if (deleteOldElement)
|
||||
{
|
||||
toDelete = this->elements [indexToChange];
|
||||
|
||||
if (toDelete == newObject)
|
||||
toDelete = 0;
|
||||
else
|
||||
this->elements [indexToChange] = const_cast <ObjectClass*> (newObject);
|
||||
if (toDelete == newObject)
|
||||
toDelete = 0;
|
||||
}
|
||||
|
||||
this->elements [indexToChange] = const_cast <ObjectClass*> (newObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue