From 2676bb02f26e759ff351efdb9a2e5f4c3bb30c74 Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Sun, 7 Mar 2010 17:45:10 +0000 Subject: [PATCH] Added ListenerList class and changed some components to use it for their listener dispatching. Sorted out bug in popup menus and win32 mouse wheel. --- build/macosx/Juce.xcodeproj/project.pbxproj | 4 + build/win32/vc8/JUCE.vcproj | 4 + juce_amalgamated.cpp | 1343 +++++++---------- juce_amalgamated.h | 486 ++++-- .../juce_ApplicationCommandManager.cpp | 20 +- .../juce_ApplicationCommandManager.h | 4 +- src/containers/juce_Value.cpp | 14 +- src/containers/juce_Value.h | 3 +- src/containers/juce_ValueTree.cpp | 38 +- src/containers/juce_ValueTree.h | 7 +- src/core/juce_StandardHeader.h | 312 ++-- src/events/juce_ListenerList.h | 315 ++++ src/gui/components/buttons/juce_Button.cpp | 53 +- src/gui/components/buttons/juce_Button.h | 4 +- src/gui/components/controls/juce_ComboBox.cpp | 13 +- src/gui/components/controls/juce_ComboBox.h | 2 +- src/gui/components/controls/juce_Label.cpp | 25 +- src/gui/components/controls/juce_Label.h | 2 +- src/gui/components/controls/juce_Slider.cpp | 27 +- src/gui/components/controls/juce_Slider.h | 3 +- .../components/controls/juce_TextEditor.cpp | 56 +- src/gui/components/controls/juce_TextEditor.h | 2 +- ...juce_DirectoryContentsDisplayComponent.cpp | 46 +- .../juce_DirectoryContentsDisplayComponent.h | 2 +- .../filebrowser/juce_FileBrowserComponent.cpp | 47 +- .../filebrowser/juce_FileBrowserComponent.h | 2 +- .../filebrowser/juce_FilenameComponent.cpp | 14 +- .../filebrowser/juce_FilenameComponent.h | 2 +- src/gui/components/juce_Component.cpp | 563 +++---- src/gui/components/juce_Component.h | 37 +- src/gui/components/juce_ComponentListener.cpp | 2 +- src/gui/components/juce_Desktop.cpp | 82 +- src/gui/components/juce_Desktop.h | 50 +- src/gui/components/layout/juce_ScrollBar.cpp | 14 +- src/gui/components/layout/juce_ScrollBar.h | 2 +- .../components/menus/juce_MenuBarModel.cpp | 22 +- src/gui/components/menus/juce_MenuBarModel.h | 2 +- src/gui/components/menus/juce_PopupMenu.cpp | 14 +- src/juce_app_includes.h | 6 + src/native/juce_linux_NativeCode.cpp | 1 + src/native/juce_win32_NativeCode.cpp | 1 + src/native/windows/juce_win32_Windowing.cpp | 2 +- 42 files changed, 1798 insertions(+), 1850 deletions(-) create mode 100644 src/events/juce_ListenerList.h diff --git a/build/macosx/Juce.xcodeproj/project.pbxproj b/build/macosx/Juce.xcodeproj/project.pbxproj index cfca23e227..f9889071ec 100644 --- a/build/macosx/Juce.xcodeproj/project.pbxproj +++ b/build/macosx/Juce.xcodeproj/project.pbxproj @@ -30,6 +30,7 @@ 844BB95D10C5579B00DF5536 /* juce_FillType.h in Headers */ = {isa = PBXBuildFile; fileRef = 84F29A9E10C2EFA5005014DF /* juce_FillType.h */; }; 844BB95E10C557A600DF5536 /* juce_mac_CoreGraphicsContext.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84D0F00B109B1546007F73A3 /* juce_mac_CoreGraphicsContext.mm */; }; 844BB95F10C557A800DF5536 /* juce_Config.h in Headers */ = {isa = PBXBuildFile; fileRef = 8456EC6508A2A6C80087C412 /* juce_Config.h */; }; + 8458B536113ECFCF0044DA09 /* juce_ListenerList.h in Headers */ = {isa = PBXBuildFile; fileRef = 8458B535113ECFCF0044DA09 /* juce_ListenerList.h */; }; 8473E64A11249FD800D74E02 /* juce_TextInputTarget.h in Headers */ = {isa = PBXBuildFile; fileRef = 8473E64911249FD800D74E02 /* juce_TextInputTarget.h */; }; 8473E64B11249FD800D74E02 /* juce_TextInputTarget.h in Headers */ = {isa = PBXBuildFile; fileRef = 8473E64911249FD800D74E02 /* juce_TextInputTarget.h */; }; 8473E6531125974600D74E02 /* juce_Range.h in Headers */ = {isa = PBXBuildFile; fileRef = 8473E6521125974600D74E02 /* juce_Range.h */; }; @@ -1245,6 +1246,7 @@ 843D4A3A10D3C54500624BA6 /* juce_ValueTree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = juce_ValueTree.h; sourceTree = ""; }; 8456EC6508A2A6C80087C412 /* juce_Config.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; lineEnding = 2; name = juce_Config.h; path = ../../juce_Config.h; sourceTree = SOURCE_ROOT; }; 8456EC6908A2A6F00087C412 /* JUCE changelist.txt */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; name = "JUCE changelist.txt"; path = "../../docs/JUCE changelist.txt"; sourceTree = SOURCE_ROOT; }; + 8458B535113ECFCF0044DA09 /* juce_ListenerList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = juce_ListenerList.h; sourceTree = ""; }; 8473E64911249FD800D74E02 /* juce_TextInputTarget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = juce_TextInputTarget.h; sourceTree = ""; }; 8473E6521125974600D74E02 /* juce_Range.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = juce_Range.h; sourceTree = ""; }; 84751E591132EE9E00640F9A /* juce_MouseInputSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = juce_MouseInputSource.cpp; sourceTree = ""; }; @@ -2313,6 +2315,7 @@ 84F1E958104036B3006A1807 /* juce_InterprocessConnection.h */, 84F1E959104036B3006A1807 /* juce_InterprocessConnectionServer.cpp */, 84F1E95A104036B3006A1807 /* juce_InterprocessConnectionServer.h */, + 8458B535113ECFCF0044DA09 /* juce_ListenerList.h */, 84F1E95B104036B3006A1807 /* juce_Message.cpp */, 84F1E95C104036B3006A1807 /* juce_Message.h */, 84F1E95D104036B3006A1807 /* juce_MessageListener.cpp */, @@ -3594,6 +3597,7 @@ 8473E64A11249FD800D74E02 /* juce_TextInputTarget.h in Headers */, 8473E6531125974600D74E02 /* juce_Range.h in Headers */, 84751E5C1132EE9E00640F9A /* juce_MouseInputSource.h in Headers */, + 8458B536113ECFCF0044DA09 /* juce_ListenerList.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/build/win32/vc8/JUCE.vcproj b/build/win32/vc8/JUCE.vcproj index 81e77f96a1..eae5510abb 100644 --- a/build/win32/vc8/JUCE.vcproj +++ b/build/win32/vc8/JUCE.vcproj @@ -1285,6 +1285,10 @@ RelativePath="..\..\..\src\events\juce_InterprocessConnectionServer.h" > + + diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index 097b49a7df..b4086a9105 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -1807,20 +1807,15 @@ const String Time::toString (const bool includeDate, if (includeTime) { + const int mins = getMinutes(); + + result << (use24HourClock ? getHours() : getHoursInAmPmFormat()) + << (mins < 10 ? ":0" : ":") << mins; + if (includeSeconds) { - result += String::formatted (T("%d:%02d:%02d "), - (use24HourClock) ? getHours() - : getHoursInAmPmFormat(), - getMinutes(), - getSeconds()); - } - else - { - result += String::formatted (T("%d.%02d"), - (use24HourClock) ? getHours() - : getHoursInAmPmFormat(), - getMinutes()); + const int secs = getSeconds(); + result << (secs < 10 ? ":0" : ":") << secs; } if (! use24HourClock) @@ -2842,10 +2837,7 @@ const String BitArray::toString (const int base, const int minimumNumCharacters) return String::empty; } - const int length = s.length(); - - if (length < minimumNumCharacters) - s = String::repeatedString (T("0"), minimumNumCharacters - length) + s; + s = s.paddedLeft ('0', minimumNumCharacters); return isNegative() ? T("-") + s : s; } @@ -11483,7 +11475,7 @@ void String::vprintf (const tchar* const pf, va_list& args) throw() } const String String::repeatedString (const tchar* const stringToRepeat, - int numberOfTimesToRepeat) throw() + int numberOfTimesToRepeat) { const int len = CharacterFunctions::length (stringToRepeat); String result ((int) (len * numberOfTimesToRepeat + 1), (int) 0); @@ -11500,6 +11492,48 @@ const String String::repeatedString (const tchar* const stringToRepeat, return result; } +const String String::paddedLeft (const juce_wchar padCharacter, int minimumLength) const +{ + if (padCharacter == 0) + { + jassertfalse; + return *this; + } + + const int len = length(); + + if (len >= minimumLength) + return *this; + + String result ((int) minimumLength + 1, (int) 0); + + tchar* n = result.text->text; + + minimumLength -= len; + while (--minimumLength >= 0) + *n++ = padCharacter; + + *n = 0; + CharacterFunctions::append (n, text->text); + + return result; +} + +const String String::paddedRight (const juce_wchar padCharacter, int minimumLength) const +{ + if (padCharacter == 0) + { + jassertfalse; + return *this; + } + + const int paddingNeeded = minimumLength - length(); + if (paddingNeeded <= 0) + return *this; + + return *this + String::empty.paddedLeft (padCharacter, paddingNeeded); +} + const String String::replaceSection (int index, int numCharsToReplace, const tchar* const stringToInsert) const throw() @@ -16139,23 +16173,13 @@ ValueTree::SharedObject::~SharedObject() } } -void ValueTree::deliverPropertyChangeMessage (ValueTree& tree, const var::identifier& property) -{ - for (int i = listeners.size(); --i >= 0;) - { - ValueTree::Listener* const l = listeners[i]; - if (l != 0) - l->valueTreePropertyChanged (tree, property); - } -} - void ValueTree::SharedObject::sendPropertyChangeMessage (ValueTree& tree, const var::identifier& property) { for (int i = valueTreesWithListeners.size(); --i >= 0;) { ValueTree* const v = valueTreesWithListeners[i]; if (v != 0) - v->deliverPropertyChangeMessage (tree, property); + v->listeners.call (&ValueTree::Listener::valueTreePropertyChanged, tree, property); } } @@ -16171,23 +16195,13 @@ void ValueTree::SharedObject::sendPropertyChangeMessage (const var::identifier& } } -void ValueTree::deliverChildChangeMessage (ValueTree& tree) -{ - for (int i = listeners.size(); --i >= 0;) - { - ValueTree::Listener* const l = listeners[i]; - if (l != 0) - l->valueTreeChildrenChanged (tree); - } -} - void ValueTree::SharedObject::sendChildChangeMessage (ValueTree& tree) { for (int i = valueTreesWithListeners.size(); --i >= 0;) { ValueTree* const v = valueTreesWithListeners[i]; if (v != 0) - v->deliverChildChangeMessage (tree); + v->listeners.call (&ValueTree::Listener::valueTreeChildrenChanged, tree); } } @@ -16203,16 +16217,6 @@ void ValueTree::SharedObject::sendChildChangeMessage() } } -void ValueTree::deliverParentChangeMessage (ValueTree& tree) -{ - for (int i = listeners.size(); --i >= 0;) - { - ValueTree::Listener* const l = listeners[i]; - if (l != 0) - l->valueTreeParentChanged (tree); - } -} - void ValueTree::SharedObject::sendParentChangeMessage() { ValueTree tree (this); @@ -16229,7 +16233,7 @@ void ValueTree::SharedObject::sendParentChangeMessage() { ValueTree* const v = valueTreesWithListeners[i]; if (v != 0) - v->deliverParentChangeMessage (tree); + v->listeners.call (&ValueTree::Listener::valueTreeParentChanged, tree); } } @@ -16622,7 +16626,7 @@ void ValueTree::addListener (Listener* listener) void ValueTree::removeListener (Listener* listener) { - listeners.removeValue (listener); + listeners.remove (listener); if (listeners.size() == 0 && object != 0) object->valueTreesWithListeners.removeValue (this); @@ -16900,7 +16904,7 @@ void Value::addListener (Listener* const listener) void Value::removeListener (Listener* const listener) { - listeners.removeValue (listener); + listeners.remove (listener); if (listeners.size() == 0) value->valuesWithListeners.removeValue (this); @@ -16908,15 +16912,8 @@ void Value::removeListener (Listener* const listener) void Value::callListeners() { - Value valueCopy (*this); // Use a copy in case this object gets deleted by a callback - - for (int i = listeners.size(); --i >= 0;) - { - Listener* const l = listeners[i]; - - if (l != 0) - l->valueChanged (valueCopy); - } + Value v (*this); // (create a copy in case this gets deleted by a callback) + listeners.call (&Listener::valueChanged, v); } END_JUCE_NAMESPACE @@ -17560,32 +17557,22 @@ ApplicationCommandTarget* ApplicationCommandManager::findDefaultComponentTarget( void ApplicationCommandManager::addListener (ApplicationCommandManagerListener* const listener) throw() { - jassert (listener != 0); - if (listener != 0) - listeners.add (listener); + listeners.add (listener); } void ApplicationCommandManager::removeListener (ApplicationCommandManagerListener* const listener) throw() { - listeners.removeValue (listener); + listeners.remove (listener); } -void ApplicationCommandManager::sendListenerInvokeCallback (const ApplicationCommandTarget::InvocationInfo& info) const +void ApplicationCommandManager::sendListenerInvokeCallback (const ApplicationCommandTarget::InvocationInfo& info) { - for (int i = listeners.size(); --i >= 0;) - { - ((ApplicationCommandManagerListener*) listeners.getUnchecked (i))->applicationCommandInvoked (info); - i = jmin (i, listeners.size()); - } + listeners.call (&ApplicationCommandManagerListener::applicationCommandInvoked, info); } void ApplicationCommandManager::handleAsyncUpdate() { - for (int i = listeners.size(); --i >= 0;) - { - ((ApplicationCommandManagerListener*) listeners.getUnchecked (i))->applicationCommandListChanged(); - i = jmin (i, listeners.size()); - } + listeners.call (&ApplicationCommandManagerListener::applicationCommandListChanged); } void ApplicationCommandManager::globalFocusChanged (Component*) @@ -38497,8 +38484,11 @@ Component* Component::currentlyFocusedComponent = 0; static Array modalComponentStack, modalComponentReturnValueKeys; static Array modalReturnValues; -static const int customCommandMessage = 0x7fff0001; -static const int exitModalStateMessage = 0x7fff0002; +enum ComponentMessageNumbers +{ + customCommandMessage = 0x7fff0001, + exitModalStateMessage = 0x7fff0002 +}; #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager()); @@ -38513,7 +38503,6 @@ Component::Component() throw() bufferedImage_ (0), mouseListeners_ (0), keyListeners_ (0), - componentListeners_ (0), componentFlags_ (0) { } @@ -38528,23 +38517,13 @@ Component::Component (const String& name) throw() bufferedImage_ (0), mouseListeners_ (0), keyListeners_ (0), - componentListeners_ (0), componentFlags_ (0) { } Component::~Component() { - if (componentListeners_ != 0) - { - for (int i = componentListeners_->size(); --i >= 0;) - { - ((ComponentListener*) componentListeners_->getUnchecked (i)) - ->componentBeingDeleted (*this); - - i = jmin (i, componentListeners_->size()); - } - } + componentListeners.call (&ComponentListener::componentBeingDeleted, *this); if (parentComponent_ != 0) { @@ -38567,7 +38546,6 @@ Component::~Component() delete bufferedImage_; delete mouseListeners_; delete keyListeners_; - delete componentListeners_; } void Component::setName (const String& name) @@ -38589,22 +38567,8 @@ void Component::setName (const String& name) peer->setTitle (name); } - if (componentListeners_ != 0) - { - SafePointer safePointer (this); - - for (int i = componentListeners_->size(); --i >= 0;) - { - ((ComponentListener*) componentListeners_->getUnchecked (i)) - ->componentNameChanged (*this); - - if (safePointer == 0) - return; - - i = jmin (i, componentListeners_->size()); - } - } - + BailOutChecker checker (this); + componentListeners.callChecked (checker, &ComponentListener::componentNameChanged, *this); } } @@ -38658,23 +38622,12 @@ void Component::visibilityChanged() void Component::sendVisibilityChangeMessage() { - SafePointer safePointer (this); + BailOutChecker checker (this); visibilityChanged(); - if (safePointer != 0 && componentListeners_ != 0) - { - for (int i = componentListeners_->size(); --i >= 0;) - { - ((ComponentListener*) componentListeners_->getUnchecked (i)) - ->componentVisibilityChanged (*this); - - if (safePointer == 0) - return; - - i = jmin (i, componentListeners_->size()); - } - } + if (! checker.shouldBailOut()) + componentListeners.callChecked (checker, &ComponentListener::componentVisibilityChanged, *this); } bool Component::isShowing() const throw() @@ -39336,24 +39289,14 @@ void Component::sendMovedResizedMessages (const bool wasMoved, const bool wasRes } } + BailOutChecker checker (this); + if (parentComponent_ != 0) parentComponent_->childBoundsChanged (this); - if (componentListeners_ != 0) - { - SafePointer safePointer (this); - - for (int i = componentListeners_->size(); --i >= 0;) - { - ((ComponentListener*) componentListeners_->getUnchecked (i)) - ->componentMovedOrResized (*this, wasMoved, wasResized); - - if (safePointer == 0) - return; - - i = jmin (i, componentListeners_->size()); - } - } + if (! checker.shouldBailOut()) + componentListeners.callChecked (checker, &ComponentListener::componentMovedOrResized, + *this, wasMoved, wasResized); } JUCE_CATCH_EXCEPTION } @@ -39717,7 +39660,13 @@ Component* Component::getTopLevelComponent() const throw() bool Component::isParentOf (const Component* possibleChild) const throw() { - while (possibleChild->isValidComponent()) + if (! possibleChild->isValidComponent()) + { + jassert (possibleChild == 0); + return false; + } + + while (possibleChild != 0) { possibleChild = possibleChild->parentComponent_; @@ -39738,58 +39687,46 @@ void Component::childrenChanged() void Component::internalChildrenChanged() { - SafePointer safePointer (this); - const bool hasListeners = componentListeners_ != 0; - - childrenChanged(); - - if (hasListeners) + if (componentListeners.isEmpty()) { - if (safePointer == 0) - return; - - for (int i = componentListeners_->size(); --i >= 0;) - { - ((ComponentListener*) componentListeners_->getUnchecked (i)) - ->componentChildrenChanged (*this); + childrenChanged(); + } + else + { + BailOutChecker checker (this); - if (safePointer == 0) - return; + childrenChanged(); - i = jmin (i, componentListeners_->size()); - } + if (! checker.shouldBailOut()) + componentListeners.callChecked (checker, &ComponentListener::componentChildrenChanged, *this); } } void Component::internalHierarchyChanged() { - parentHierarchyChanged(); + BailOutChecker checker (this); - SafePointer safePointer (this); + parentHierarchyChanged(); - if (componentListeners_ != 0) - { - for (int i = componentListeners_->size(); --i >= 0;) - { - ((ComponentListener*) componentListeners_->getUnchecked (i)) - ->componentParentHierarchyChanged (*this); + if (checker.shouldBailOut()) + return; - if (safePointer == 0) - return; + componentListeners.callChecked (checker, &ComponentListener::componentParentHierarchyChanged, *this); - i = jmin (i, componentListeners_->size()); - } - } + if (checker.shouldBailOut()) + return; for (int i = childComponentList_.size(); --i >= 0;) { childComponentList_.getUnchecked (i)->internalHierarchyChanged(); - // you really shouldn't delete the parent component during a callback telling you - // that it's changed.. - jassert (safePointer != 0); - if (safePointer == 0) + if (checker.shouldBailOut()) + { + // you really shouldn't delete the parent component during a callback telling you + // that it's changed.. + jassertfalse; return; + } i = jmin (i, childComponentList_.size()); } @@ -40493,18 +40430,14 @@ void Component::parentSizeChanged() void Component::addComponentListener (ComponentListener* const newListener) throw() { - if (componentListeners_ == 0) - componentListeners_ = new VoidArray(); - - componentListeners_->addIfNotAlreadyThere (newListener); + componentListeners.add (newListener); } void Component::removeComponentListener (ComponentListener* const listenerToRemove) throw() { jassert (isValidComponent()); - if (componentListeners_ != 0) - componentListeners_->removeValue (listenerToRemove); + componentListeners.remove (listenerToRemove); } void Component::inputAttemptWhenModal() @@ -40613,13 +40546,13 @@ void Component::internalMouseEnter (MouseInputSource& source, const Point& return; } - if (isValidComponent() && ! flags.mouseInsideFlag) + if (! flags.mouseInsideFlag) { flags.mouseInsideFlag = true; flags.mouseOverFlag = true; flags.draggingFlag = false; - SafePointer safePointer (this); + BailOutChecker checker (this); if (flags.repaintOnMouseActivityFlag) repaint(); @@ -40630,20 +40563,14 @@ void Component::internalMouseEnter (MouseInputSource& source, const Point& mouseEnter (me); - if (safePointer == 0) + if (checker.shouldBailOut()) return; Desktop::getInstance().resetTimer(); + Desktop::getInstance().mouseListeners.callChecked (checker, &MouseListener::mouseEnter, me); - for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;) - { - ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseEnter (me); - - if (safePointer == 0) - return; - - i = jmin (i, Desktop::getInstance().mouseListeners.size()); - } + if (checker.shouldBailOut()) + return; if (mouseListeners_ != 0) { @@ -40651,7 +40578,7 @@ void Component::internalMouseEnter (MouseInputSource& source, const Point& { ((MouseListener*) mouseListeners_->getUnchecked(i))->mouseEnter (me); - if (safePointer == 0) + if (checker.shouldBailOut()) return; i = jmin (i, mouseListeners_->size()); @@ -40662,16 +40589,19 @@ void Component::internalMouseEnter (MouseInputSource& source, const Point& while (p != 0) { - SafePointer parentPointer (p); - - for (int i = p->numDeepMouseListeners; --i >= 0;) + if (p->numDeepMouseListeners > 0) { - ((MouseListener*) (p->mouseListeners_->getUnchecked(i)))->mouseEnter (me); + BailOutChecker checker (this, p); - if (safePointer == 0 || parentPointer == 0) - return; + for (int i = p->numDeepMouseListeners; --i >= 0;) + { + ((MouseListener*) (p->mouseListeners_->getUnchecked(i)))->mouseEnter (me); - i = jmin (i, p->numDeepMouseListeners); + if (checker.shouldBailOut()) + return; + + i = jmin (i, p->numDeepMouseListeners); + } } p = p->parentComponent_; @@ -40681,13 +40611,13 @@ void Component::internalMouseEnter (MouseInputSource& source, const Point& void Component::internalMouseExit (MouseInputSource& source, const Point& relativePos, const Time& time) { - SafePointer safePointer (this); + BailOutChecker checker (this); if (flags.draggingFlag) { internalMouseUp (source, relativePos, time, source.getCurrentModifiers().getRawFlags()); - if (safePointer == 0) + if (checker.shouldBailOut()) return; } @@ -40705,20 +40635,14 @@ void Component::internalMouseExit (MouseInputSource& source, const Point& r time, 0, false); mouseExit (me); - if (safePointer == 0) + if (checker.shouldBailOut()) return; Desktop::getInstance().resetTimer(); + Desktop::getInstance().mouseListeners.callChecked (checker, &MouseListener::mouseExit, me); - for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;) - { - ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseExit (me); - - if (safePointer == 0) - return; - - i = jmin (i, Desktop::getInstance().mouseListeners.size()); - } + if (checker.shouldBailOut()) + return; if (mouseListeners_ != 0) { @@ -40726,7 +40650,7 @@ void Component::internalMouseExit (MouseInputSource& source, const Point& r { ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseExit (me); - if (safePointer == 0) + if (checker.shouldBailOut()) return; i = jmin (i, mouseListeners_->size()); @@ -40737,16 +40661,19 @@ void Component::internalMouseExit (MouseInputSource& source, const Point& r while (p != 0) { - SafePointer parentPointer (p); - - for (int i = p->numDeepMouseListeners; --i >= 0;) + if (p->numDeepMouseListeners > 0) { - ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseExit (me); + BailOutChecker checker (this, p); - if (safePointer == 0 || parentPointer == 0) - return; + for (int i = p->numDeepMouseListeners; --i >= 0;) + { + ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseExit (me); - i = jmin (i, p->numDeepMouseListeners); + if (checker.shouldBailOut()) + return; + + i = jmin (i, p->numDeepMouseListeners); + } } p = p->parentComponent_; @@ -40812,13 +40739,13 @@ void Component::internalMouseDown (MouseInputSource& source, const Point& r { Desktop& desktop = Desktop::getInstance(); - SafePointer safePointer (this); + BailOutChecker checker (this); if (isCurrentlyBlockedByAnotherModalComponent()) { internalModalInputAttempt(); - if (safePointer == 0) + if (checker.shouldBailOut()) return; // If processing the input attempt has exited the modal loop, we'll allow the event @@ -40831,17 +40758,7 @@ void Component::internalMouseDown (MouseInputSource& source, const Point& r source.getNumberOfMultipleClicks(), false); desktop.resetTimer(); - - for (int i = desktop.mouseListeners.size(); --i >= 0;) - { - ((MouseListener*) desktop.mouseListeners[i])->mouseDown (me); - - if (safePointer == 0) - return; - - i = jmin (i, desktop.mouseListeners.size()); - } - + desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDown, me); return; } } @@ -40855,7 +40772,7 @@ void Component::internalMouseDown (MouseInputSource& source, const Point& r { c->toFront (true); - if (safePointer == 0) + if (checker.shouldBailOut()) return; } @@ -40867,7 +40784,7 @@ void Component::internalMouseDown (MouseInputSource& source, const Point& r { grabFocusInternal (focusChangedByMouseClick); - if (safePointer == 0) + if (checker.shouldBailOut()) return; } @@ -40882,20 +40799,14 @@ void Component::internalMouseDown (MouseInputSource& source, const Point& r source.getNumberOfMultipleClicks(), false); mouseDown (me); - if (safePointer == 0) + if (checker.shouldBailOut()) return; desktop.resetTimer(); + desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDown, me); - for (int i = desktop.mouseListeners.size(); --i >= 0;) - { - ((MouseListener*) desktop.mouseListeners[i])->mouseDown (me); - - if (safePointer == 0) - return; - - i = jmin (i, desktop.mouseListeners.size()); - } + if (checker.shouldBailOut()) + return; if (mouseListeners_ != 0) { @@ -40903,7 +40814,7 @@ void Component::internalMouseDown (MouseInputSource& source, const Point& r { ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDown (me); - if (safePointer == 0) + if (checker.shouldBailOut()) return; i = jmin (i, mouseListeners_->size()); @@ -40914,16 +40825,19 @@ void Component::internalMouseDown (MouseInputSource& source, const Point& r while (p != 0) { - SafePointer parentPointer (p); - - for (int i = p->numDeepMouseListeners; --i >= 0;) + if (p->numDeepMouseListeners > 0) { - ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDown (me); + BailOutChecker checker (this, p); - if (safePointer == 0 || parentPointer == 0) - return; + for (int i = p->numDeepMouseListeners; --i >= 0;) + { + ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDown (me); - i = jmin (i, p->numDeepMouseListeners); + if (checker.shouldBailOut()) + return; + + i = jmin (i, p->numDeepMouseListeners); + } } p = p->parentComponent_; @@ -40932,13 +40846,13 @@ void Component::internalMouseDown (MouseInputSource& source, const Point& r void Component::internalMouseUp (MouseInputSource& source, const Point& relativePos, const Time& time, const ModifierKeys& oldModifiers) { - if (isValidComponent() && flags.draggingFlag) + if (flags.draggingFlag) { Desktop& desktop = Desktop::getInstance(); flags.draggingFlag = false; - SafePointer safePointer (this); + BailOutChecker checker (this); if (flags.repaintOnMouseActivityFlag) repaint(); @@ -40952,20 +40866,14 @@ void Component::internalMouseUp (MouseInputSource& source, const Point& rel mouseUp (me); - if (safePointer == 0) + if (checker.shouldBailOut()) return; desktop.resetTimer(); + desktop.mouseListeners.callChecked (checker, &MouseListener::mouseUp, me); - for (int i = desktop.mouseListeners.size(); --i >= 0;) - { - ((MouseListener*) desktop.mouseListeners[i])->mouseUp (me); - - if (safePointer == 0) - return; - - i = jmin (i, desktop.mouseListeners.size()); - } + if (checker.shouldBailOut()) + return; if (mouseListeners_ != 0) { @@ -40973,7 +40881,7 @@ void Component::internalMouseUp (MouseInputSource& source, const Point& rel { ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseUp (me); - if (safePointer == 0) + if (checker.shouldBailOut()) return; i = jmin (i, mouseListeners_->size()); @@ -40985,16 +40893,19 @@ void Component::internalMouseUp (MouseInputSource& source, const Point& rel while (p != 0) { - SafePointer parentPointer (p); - - for (int i = p->numDeepMouseListeners; --i >= 0;) + if (p->numDeepMouseListeners > 0) { - ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseUp (me); + BailOutChecker checker (this, p); - if (safePointer == 0 || parentPointer == 0) - return; + for (int i = p->numDeepMouseListeners; --i >= 0;) + { + ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseUp (me); - i = jmin (i, p->numDeepMouseListeners); + if (checker.shouldBailOut()) + return; + + i = jmin (i, p->numDeepMouseListeners); + } } p = p->parentComponent_; @@ -41008,20 +40919,17 @@ void Component::internalMouseUp (MouseInputSource& source, const Point& rel mouseDoubleClick (me); - int i; - for (i = desktop.mouseListeners.size(); --i >= 0;) - { - ((MouseListener*) desktop.mouseListeners[i])->mouseDoubleClick (me); - - if (safePointer == 0) - return; + desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDoubleClick, me); - i = jmin (i, desktop.mouseListeners.size()); - } + if (checker.shouldBailOut()) + return; - for (i = numListeners; --i >= 0;) + for (int i = numListeners; --i >= 0;) { - if (safePointer == 0 || mouseListeners_ == 0) + if (checker.shouldBailOut()) + return; + + if (mouseListeners_ == 0) return; MouseListener* const ml = (MouseListener*)((*mouseListeners_)[i]); @@ -41029,23 +40937,26 @@ void Component::internalMouseUp (MouseInputSource& source, const Point& rel ml->mouseDoubleClick (me); } - if (safePointer == 0) + if (checker.shouldBailOut()) return; Component* p = parentComponent_; while (p != 0) { - SafePointer parentPointer (p); - - for (i = p->numDeepMouseListeners; --i >= 0;) + if (p->numDeepMouseListeners > 0) { - ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDoubleClick (me); + BailOutChecker checker (this, p); - if (safePointer == 0 || parentPointer == 0) - return; + for (int i = p->numDeepMouseListeners; --i >= 0;) + { + ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDoubleClick (me); - i = jmin (i, p->numDeepMouseListeners); + if (checker.shouldBailOut()) + return; + + i = jmin (i, p->numDeepMouseListeners); + } } p = p->parentComponent_; @@ -41056,13 +40967,13 @@ void Component::internalMouseUp (MouseInputSource& source, const Point& rel void Component::internalMouseDrag (MouseInputSource& source, const Point& relativePos, const Time& time) { - if (isValidComponent() && flags.draggingFlag) + if (flags.draggingFlag) { Desktop& desktop = Desktop::getInstance(); flags.mouseOverFlag = reallyContains (relativePos.getX(), relativePos.getY(), false); - SafePointer safePointer (this); + BailOutChecker checker (this); const MouseEvent me (source, relativePos, source.getCurrentModifiers(), this, time, @@ -41073,20 +40984,14 @@ void Component::internalMouseDrag (MouseInputSource& source, const Point& r mouseDrag (me); - if (safePointer == 0) + if (checker.shouldBailOut()) return; desktop.resetTimer(); + desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDrag, me); - for (int i = desktop.mouseListeners.size(); --i >= 0;) - { - ((MouseListener*) desktop.mouseListeners[i])->mouseDrag (me); - - if (safePointer == 0) - return; - - i = jmin (i, desktop.mouseListeners.size()); - } + if (checker.shouldBailOut()) + return; if (mouseListeners_ != 0) { @@ -41094,7 +40999,7 @@ void Component::internalMouseDrag (MouseInputSource& source, const Point& r { ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDrag (me); - if (safePointer == 0) + if (checker.shouldBailOut()) return; i = jmin (i, mouseListeners_->size()); @@ -41105,16 +41010,19 @@ void Component::internalMouseDrag (MouseInputSource& source, const Point& r while (p != 0) { - SafePointer parentPointer (p); - - for (int i = p->numDeepMouseListeners; --i >= 0;) + if (p->numDeepMouseListeners > 0) { - ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDrag (me); + BailOutChecker checker (this, p); - if (safePointer == 0 || parentPointer == 0) - return; + for (int i = p->numDeepMouseListeners; --i >= 0;) + { + ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDrag (me); - i = jmin (i, p->numDeepMouseListeners); + if (checker.shouldBailOut()) + return; + + i = jmin (i, p->numDeepMouseListeners); + } } p = p->parentComponent_; @@ -41124,73 +41032,66 @@ void Component::internalMouseDrag (MouseInputSource& source, const Point& r void Component::internalMouseMove (MouseInputSource& source, const Point& relativePos, const Time& time) { - SafePointer safePointer (this); + Desktop& desktop = Desktop::getInstance(); + BailOutChecker checker (this); - if (isValidComponent()) - { - Desktop& desktop = Desktop::getInstance(); + const MouseEvent me (source, relativePos, source.getCurrentModifiers(), + this, time, relativePos, + time, 0, false); - const MouseEvent me (source, relativePos, source.getCurrentModifiers(), - this, time, relativePos, - time, 0, false); + if (isCurrentlyBlockedByAnotherModalComponent()) + { + // allow blocked mouse-events to go to global listeners.. + desktop.sendMouseMove(); + } + else + { + flags.mouseOverFlag = true; - if (isCurrentlyBlockedByAnotherModalComponent()) - { - // allow blocked mouse-events to go to global listeners.. - desktop.sendMouseMove(); - } - else - { - flags.mouseOverFlag = true; + mouseMove (me); - mouseMove (me); + if (checker.shouldBailOut()) + return; - if (safePointer == 0) - return; + desktop.resetTimer(); + desktop.mouseListeners.callChecked (checker, &MouseListener::mouseMove, me); - desktop.resetTimer(); + if (checker.shouldBailOut()) + return; - for (int i = desktop.mouseListeners.size(); --i >= 0;) + if (mouseListeners_ != 0) + { + for (int i = mouseListeners_->size(); --i >= 0;) { - ((MouseListener*) desktop.mouseListeners[i])->mouseMove (me); + ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseMove (me); - if (safePointer == 0) + if (checker.shouldBailOut()) return; - i = jmin (i, desktop.mouseListeners.size()); - } - - if (mouseListeners_ != 0) - { - for (int i = mouseListeners_->size(); --i >= 0;) - { - ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseMove (me); - - if (safePointer == 0) - return; - - i = jmin (i, mouseListeners_->size()); - } + i = jmin (i, mouseListeners_->size()); } + } - Component* p = parentComponent_; + Component* p = parentComponent_; - while (p != 0) + while (p != 0) + { + if (p->numDeepMouseListeners > 0) { - SafePointer parentPointer (p); + BailOutChecker checker (this, p); for (int i = p->numDeepMouseListeners; --i >= 0;) { ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseMove (me); - if (safePointer == 0 || parentPointer == 0) + if (checker.shouldBailOut()) return; i = jmin (i, p->numDeepMouseListeners); } - - p = p->parentComponent_; } + + p = p->parentComponent_; } } } @@ -41199,7 +41100,7 @@ void Component::internalMouseWheel (MouseInputSource& source, const Point& const Time& time, const float amountX, const float amountY) { Desktop& desktop = Desktop::getInstance(); - SafePointer safePointer (this); + BailOutChecker checker (this); const float wheelIncrementX = amountX * (1.0f / 256.0f); const float wheelIncrementY = amountY * (1.0f / 256.0f); @@ -41210,32 +41111,19 @@ void Component::internalMouseWheel (MouseInputSource& source, const Point& if (isCurrentlyBlockedByAnotherModalComponent()) { // allow blocked mouse-events to go to global listeners.. - for (int i = desktop.mouseListeners.size(); --i >= 0;) - { - ((MouseListener*) desktop.mouseListeners[i])->mouseWheelMove (me, wheelIncrementX, wheelIncrementY); - - if (safePointer == 0) - return; - - i = jmin (i, desktop.mouseListeners.size()); - } + desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheelIncrementX, wheelIncrementY); } else { mouseWheelMove (me, wheelIncrementX, wheelIncrementY); - if (safePointer == 0) + if (checker.shouldBailOut()) return; - for (int i = desktop.mouseListeners.size(); --i >= 0;) - { - ((MouseListener*) desktop.mouseListeners[i])->mouseWheelMove (me, wheelIncrementX, wheelIncrementY); - - if (safePointer == 0) - return; + desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheelIncrementX, wheelIncrementY); - i = jmin (i, desktop.mouseListeners.size()); - } + if (checker.shouldBailOut()) + return; if (mouseListeners_ != 0) { @@ -41243,7 +41131,7 @@ void Component::internalMouseWheel (MouseInputSource& source, const Point& { ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY); - if (safePointer == 0) + if (checker.shouldBailOut()) return; i = jmin (i, mouseListeners_->size()); @@ -41254,16 +41142,19 @@ void Component::internalMouseWheel (MouseInputSource& source, const Point& while (p != 0) { - SafePointer parentPointer (p); - - for (int i = p->numDeepMouseListeners; --i >= 0;) + if (p->numDeepMouseListeners > 0) { - ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY); + BailOutChecker checker (this, p); - if (safePointer == 0 || parentPointer == 0) - return; + for (int i = p->numDeepMouseListeners; --i >= 0;) + { + ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY); - i = jmin (i, p->numDeepMouseListeners); + if (checker.shouldBailOut()) + return; + + i = jmin (i, p->numDeepMouseListeners); + } } p = p->parentComponent_; @@ -41282,39 +41173,29 @@ void Component::broughtToFront() void Component::internalBroughtToFront() { - if (isValidComponent()) - { - if (flags.hasHeavyweightPeerFlag) - Desktop::getInstance().componentBroughtToFront (this); - - SafePointer safePointer (this); - broughtToFront(); + if (! isValidComponent()) + return; - if (safePointer == 0) - return; + if (flags.hasHeavyweightPeerFlag) + Desktop::getInstance().componentBroughtToFront (this); - if (componentListeners_ != 0) - { - for (int i = componentListeners_->size(); --i >= 0;) - { - ((ComponentListener*) componentListeners_->getUnchecked (i)) - ->componentBroughtToFront (*this); + BailOutChecker checker (this); + broughtToFront(); - if (safePointer == 0) - return; + if (checker.shouldBailOut()) + return; - i = jmin (i, componentListeners_->size()); - } - } + componentListeners.callChecked (checker, &ComponentListener::componentBroughtToFront, *this); - // when brought to the front and there's a modal component blocking this one, - // we need to bring the modal one to the front instead.. + if (checker.shouldBailOut()) + return; - Component* const cm = getCurrentlyModalComponent(); + // When brought to the front and there's a modal component blocking this one, + // we need to bring the modal one to the front instead.. + Component* const cm = getCurrentlyModalComponent(); - if (cm != 0 && cm->getTopLevelComponent() != getTopLevelComponent()) - bringModalComponentToFront(); - } + if (cm != 0 && cm->getTopLevelComponent() != getTopLevelComponent()) + bringModalComponentToFront(); } void Component::focusGained (FocusChangeType) @@ -41710,6 +41591,17 @@ ComponentPeer* Component::getPeer() const throw() return 0; } +Component::BailOutChecker::BailOutChecker (Component* const component1, Component* const component2_) + : safePointer1 (component1), safePointer2 (component2_), component2 (component2_) +{ + jassert (component1 != 0); +} + +bool Component::BailOutChecker::shouldBailOut() const throw() +{ + return safePointer1 == 0 || safePointer2 != component2; +} + ComponentDeletionWatcher::ComponentDeletionWatcher (const Component* const componentToWatch_) throw() : componentToWatch (componentToWatch_), componentUID (componentToWatch_->getComponentUID()) @@ -41745,7 +41637,7 @@ void ComponentListener::componentVisibilityChanged (Component&) {} void ComponentListener::componentChildrenChanged (Component&) {} void ComponentListener::componentParentHierarchyChanged (Component&) {} void ComponentListener::componentNameChanged (Component&) {} -void ComponentListener::componentBeingDeleted (Component& component) {} +void ComponentListener::componentBeingDeleted (Component&) {} END_JUCE_NAMESPACE /*** End of inlined file: juce_ComponentListener.cpp ***/ @@ -41754,7 +41646,7 @@ END_JUCE_NAMESPACE /*** Start of inlined file: juce_Desktop.cpp ***/ BEGIN_JUCE_NAMESPACE -Desktop::Desktop() throw() +Desktop::Desktop() : mouseClickCounter (0), kioskModeComponent (0) { @@ -41762,7 +41654,7 @@ Desktop::Desktop() throw() refreshMonitorSizes(); } -Desktop::~Desktop() throw() +Desktop::~Desktop() { jassert (instance == this); instance = 0; @@ -41772,7 +41664,7 @@ Desktop::~Desktop() throw() jassert (desktopComponents.size() == 0); } -Desktop& JUCE_CALLTYPE Desktop::getInstance() throw() +Desktop& JUCE_CALLTYPE Desktop::getInstance() { if (instance == 0) instance = new Desktop(); @@ -41785,7 +41677,7 @@ Desktop* Desktop::instance = 0; extern void juce_updateMultiMonitorInfo (Array >& monitorCoords, const bool clipToWorkArea); -void Desktop::refreshMonitorSizes() throw() +void Desktop::refreshMonitorSizes() { const Array > oldClipped (monitorCoordsClipped); const Array > oldUnclipped (monitorCoordsUnclipped); @@ -41835,7 +41727,7 @@ const Rectangle Desktop::getMainMonitorArea (const bool clippedToWorkArea) return getDisplayMonitorCoordinates (0, clippedToWorkArea); } -const Rectangle Desktop::getMonitorAreaContaining (const Point& position, const bool clippedToWorkArea) const throw() +const Rectangle Desktop::getMonitorAreaContaining (const Point& position, const bool clippedToWorkArea) const { Rectangle best (getMainMonitorArea (clippedToWorkArea)); double bestDistance = 1.0e10; @@ -41883,19 +41775,19 @@ Component* Desktop::findComponentAt (const Point& screenPosition) const return 0; } -void Desktop::addDesktopComponent (Component* const c) throw() +void Desktop::addDesktopComponent (Component* const c) { jassert (c != 0); jassert (! desktopComponents.contains (c)); desktopComponents.addIfNotAlreadyThere (c); } -void Desktop::removeDesktopComponent (Component* const c) throw() +void Desktop::removeDesktopComponent (Component* const c) { desktopComponents.removeValue (c); } -void Desktop::componentBroughtToFront (Component* const c) throw() +void Desktop::componentBroughtToFront (Component* const c) { const int index = desktopComponents.indexOf (c); jassert (index >= 0); @@ -41962,48 +41854,37 @@ MouseInputSource* Desktop::getDraggingMouseSource (int index) const throw() return 0; } -void Desktop::addGlobalMouseListener (MouseListener* const listener) throw() +void Desktop::addFocusChangeListener (FocusChangeListener* const listener) { - jassert (listener != 0); - - if (listener != 0) - { - mouseListeners.add (listener); - resetTimer(); - } + focusListeners.add (listener); } -void Desktop::removeGlobalMouseListener (MouseListener* const listener) throw() +void Desktop::removeFocusChangeListener (FocusChangeListener* const listener) { - mouseListeners.removeValue (listener); - resetTimer(); + focusListeners.remove (listener); } -void Desktop::addFocusChangeListener (FocusChangeListener* const listener) throw() +void Desktop::triggerFocusCallback() { - jassert (listener != 0); - - if (listener != 0) - focusListeners.add (listener); + triggerAsyncUpdate(); } -void Desktop::removeFocusChangeListener (FocusChangeListener* const listener) throw() +void Desktop::handleAsyncUpdate() { - focusListeners.removeValue (listener); + Component* currentFocus = Component::getCurrentlyFocusedComponent(); + focusListeners.call (&FocusChangeListener::globalFocusChanged, currentFocus); } -void Desktop::triggerFocusCallback() throw() +void Desktop::addGlobalMouseListener (MouseListener* const listener) { - triggerAsyncUpdate(); + mouseListeners.add (listener); + resetTimer(); } -void Desktop::handleAsyncUpdate() +void Desktop::removeGlobalMouseListener (MouseListener* const listener) { - for (int i = focusListeners.size(); --i >= 0;) - { - ((FocusChangeListener*) focusListeners.getUnchecked (i))->globalFocusChanged (Component::getCurrentlyFocusedComponent()); - i = jmin (i, focusListeners.size()); - } + mouseListeners.remove (listener); + resetTimer(); } void Desktop::timerCallback() @@ -42014,7 +41895,7 @@ void Desktop::timerCallback() void Desktop::sendMouseMove() { - if (mouseListeners.size() > 0) + if (! mouseListeners.isEmpty()) { startTimer (20); @@ -42024,30 +41905,22 @@ void Desktop::sendMouseMove() if (target != 0) { - Component::SafePointer deletionChecker (target); + Component::BailOutChecker checker (target); const Point pos (target->globalPositionToRelative (lastFakeMouseMove)); const Time now (Time::getCurrentTime()); const MouseEvent me (getMainMouseSource(), pos, ModifierKeys::getCurrentModifiers(), target, now, pos, now, 0, false); - for (int i = mouseListeners.size(); --i >= 0;) - { - if (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()) - ((MouseListener*) mouseListeners[i])->mouseDrag (me); - else - ((MouseListener*) mouseListeners[i])->mouseMove (me); - - if (deletionChecker == 0) - return; - - i = jmin (i, mouseListeners.size()); - } + if (me.mods.isAnyMouseButtonDown()) + mouseListeners.callChecked (checker, &MouseListener::mouseDrag, me); + else + mouseListeners.callChecked (checker, &MouseListener::mouseMove, me); } } } -void Desktop::resetTimer() throw() +void Desktop::resetTimer() { if (mouseListeners.size() == 0) stopTimer(); @@ -42164,7 +42037,6 @@ private: Button::Button (const String& name) : Component (name), - keySource (0), text (name), buttonPressTime (0), lastTimeCallbackTime (0), @@ -42459,23 +42331,17 @@ void Button::handleCommandMessage (int commandId) void Button::addButtonListener (ButtonListener* const newListener) { - jassert (newListener != 0); - jassert (! buttonListeners.contains (newListener)); // trying to add a listener to the list twice! - - if (newListener != 0) - buttonListeners.add (newListener); + buttonListeners.add (newListener); } void Button::removeButtonListener (ButtonListener* const listener) { - jassert (buttonListeners.contains (listener)); // trying to remove a listener that isn't on the list! - - buttonListeners.removeValue (listener); + buttonListeners.remove (listener); } void Button::sendClickMessage (const ModifierKeys& modifiers) { - Component::SafePointer deletionWatcher (this); + Component::BailOutChecker checker (this); if (commandManagerToUse != 0 && commandID != 0) { @@ -42488,44 +42354,18 @@ void Button::sendClickMessage (const ModifierKeys& modifiers) clicked (modifiers); - if (deletionWatcher != 0) - { - for (int i = buttonListeners.size(); --i >= 0;) - { - ButtonListener* const bl = (ButtonListener*) buttonListeners[i]; - - if (bl != 0) - { - bl->buttonClicked (this); - - if (deletionWatcher == 0) - return; - } - } - } + if (! checker.shouldBailOut()) + buttonListeners.callChecked (checker, &ButtonListener::buttonClicked, this); } void Button::sendStateMessage() { - Component::SafePointer deletionWatcher (this); + Component::BailOutChecker checker (this); buttonStateChanged(); - if (deletionWatcher == 0) - return; - - for (int i = buttonListeners.size(); --i >= 0;) - { - ButtonListener* const bl = (ButtonListener*) buttonListeners[i]; - - if (bl != 0) - { - bl->buttonStateChanged (this); - - if (deletionWatcher == 0) - return; - } - } + if (! checker.shouldBailOut()) + buttonListeners.callChecked (checker, &ButtonListener::buttonStateChanged, this); } void Button::paint (Graphics& g) @@ -42616,12 +42456,12 @@ void Button::parentHierarchyChanged() if (newKeySource != keySource) { - if (keySource->isValidComponent()) + if (keySource != 0) keySource->removeKeyListener (this); keySource = newKeySource; - if (keySource->isValidComponent()) + if (keySource != 0) keySource->addKeyListener (this); } } @@ -46836,23 +46676,18 @@ void ComboBox::mouseUp (const MouseEvent& e2) void ComboBox::addListener (ComboBoxListener* const listener) throw() { - jassert (listener != 0); - if (listener != 0) - listeners.add (listener); + listeners.add (listener); } void ComboBox::removeListener (ComboBoxListener* const listener) throw() { - listeners.removeValue (listener); + listeners.remove (listener); } void ComboBox::handleAsyncUpdate() { - for (int i = listeners.size(); --i >= 0;) - { - ((ComboBoxListener*) listeners.getUnchecked (i))->comboBoxChanged (this); - i = jmin (i, listeners.size()); - } + Component::BailOutChecker checker (this); + listeners.callChecked (checker, &ComboBoxListener::comboBoxChanged, this); } END_JUCE_NAMESPACE @@ -46966,7 +46801,7 @@ void Label::setBorderSize (int h, int v) Component* Label::getAttachedComponent() const { - return const_cast (static_cast (ownerComponent)); + return static_cast (ownerComponent); } void Label::attachToComponent (Component* owner, @@ -47082,6 +46917,8 @@ void Label::hideEditor (const bool discardCurrentEditorContents) { if (editor != 0) { + Component::SafePointer deletionChecker (this); + editorAboutToBeHidden (editor); const bool changed = (! discardCurrentEditorContents) @@ -47093,9 +46930,10 @@ void Label::hideEditor (const bool discardCurrentEditorContents) if (changed) textWasEdited(); - exitModalState (0); + if (deletionChecker != 0) + exitModalState (0); - if (changed && isValidComponent()) + if (changed && deletionChecker != 0) callChangeListeners(); } } @@ -47217,23 +47055,18 @@ KeyboardFocusTraverser* Label::createFocusTraverser() void Label::addListener (LabelListener* const listener) throw() { - jassert (listener != 0); - if (listener != 0) - listeners.add (listener); + listeners.add (listener); } void Label::removeListener (LabelListener* const listener) throw() { - listeners.removeValue (listener); + listeners.remove (listener); } void Label::callChangeListeners() { - for (int i = listeners.size(); --i >= 0;) - { - ((LabelListener*) listeners.getUnchecked (i))->labelTextChanged (this); - i = jmin (i, listeners.size()); - } + Component::BailOutChecker checker (this); + listeners.callChecked (checker, &LabelListener::labelTextChanged, this); } void Label::textEditorTextChanged (TextEditor& ed) @@ -47264,9 +47097,10 @@ void Label::textEditorReturnKeyPressed (TextEditor& ed) if (changed) { + Component::SafePointer deletionChecker (this); textWasEdited(); - if (isValidComponent()) + if (deletionChecker != 0) callChangeListeners(); } } @@ -48463,22 +48297,16 @@ void Slider::handleAsyncUpdate() { cancelPendingUpdate(); - for (int i = listeners.size(); --i >= 0;) - { - ((SliderListener*) listeners.getUnchecked (i))->sliderValueChanged (this); - i = jmin (i, listeners.size()); - } + Component::BailOutChecker checker (this); + listeners.callChecked (checker, &SliderListener::sliderValueChanged, this); } void Slider::sendDragStart() { startedDragging(); - for (int i = listeners.size(); --i >= 0;) - { - ((SliderListener*) listeners.getUnchecked (i))->sliderDragStarted (this); - i = jmin (i, listeners.size()); - } + Component::BailOutChecker checker (this); + listeners.callChecked (checker, &SliderListener::sliderDragStarted, this); } void Slider::sendDragEnd() @@ -48487,23 +48315,18 @@ void Slider::sendDragEnd() sliderBeingDragged = -1; - for (int i = listeners.size(); --i >= 0;) - { - ((SliderListener*) listeners.getUnchecked (i))->sliderDragEnded (this); - i = jmin (i, listeners.size()); - } + Component::BailOutChecker checker (this); + listeners.callChecked (checker, &SliderListener::sliderDragEnded, this); } void Slider::addListener (SliderListener* const listener) { - jassert (listener != 0); - if (listener != 0) - listeners.add (listener); + listeners.add (listener); } void Slider::removeListener (SliderListener* const listener) { - listeners.removeValue (listener); + listeners.remove (listener); } void Slider::setSliderStyle (const SliderStyle newStyle) @@ -52365,15 +52188,12 @@ void TextEditor::escapePressed() void TextEditor::addListener (TextEditorListener* const newListener) { - jassert (newListener != 0) - - if (newListener != 0) - listeners.add (newListener); + listeners.add (newListener); } void TextEditor::removeListener (TextEditorListener* const listenerToRemove) { - listeners.removeValue (listenerToRemove); + listeners.remove (listenerToRemove); } void TextEditor::timerCallbackInt() @@ -53263,47 +53083,36 @@ void TextEditor::resized() void TextEditor::handleCommandMessage (const int commandId) { - Component::SafePointer deletionChecker (this); + Component::BailOutChecker checker (this); - for (int i = listeners.size(); --i >= 0;) + switch (commandId) { - TextEditorListener* const tl = (TextEditorListener*) listeners [i]; - - if (tl != 0) - { - switch (commandId) - { - case TextEditorDefs::textChangeMessageId: - tl->textEditorTextChanged (*this); - break; - - case TextEditorDefs::returnKeyMessageId: - tl->textEditorReturnKeyPressed (*this); - break; + case TextEditorDefs::textChangeMessageId: + listeners.callChecked (checker, &TextEditorListener::textEditorTextChanged, (TextEditor&) *this); + break; - case TextEditorDefs::escapeKeyMessageId: - tl->textEditorEscapeKeyPressed (*this); - break; + case TextEditorDefs::returnKeyMessageId: + listeners.callChecked (checker, &TextEditorListener::textEditorReturnKeyPressed, (TextEditor&) *this); + break; - case TextEditorDefs::focusLossMessageId: - tl->textEditorFocusLost (*this); - break; + case TextEditorDefs::escapeKeyMessageId: + listeners.callChecked (checker, &TextEditorListener::textEditorEscapeKeyPressed, (TextEditor&) *this); + break; - default: - jassertfalse - break; - } + case TextEditorDefs::focusLossMessageId: + listeners.callChecked (checker, &TextEditorListener::textEditorFocusLost, (TextEditor&) *this); + break; - if (deletionChecker == 0) - return; - } + default: + jassertfalse + break; } } void TextEditor::enablementChanged() { - setMouseCursor (MouseCursor (isReadOnly() ? MouseCursor::NormalCursor - : MouseCursor::IBeamCursor)); + setMouseCursor (isReadOnly() ? MouseCursor::NormalCursor + : MouseCursor::IBeamCursor); repaint(); } @@ -56676,47 +56485,26 @@ FileBrowserListener::~FileBrowserListener() void DirectoryContentsDisplayComponent::addListener (FileBrowserListener* const listener) throw() { - jassert (listener != 0); - - if (listener != 0) - listeners.add (listener); + listeners.add (listener); } void DirectoryContentsDisplayComponent::removeListener (FileBrowserListener* const listener) throw() { - listeners.removeValue (listener); + listeners.remove (listener); } void DirectoryContentsDisplayComponent::sendSelectionChangeMessage() { - Component::SafePointer deletionWatcher (dynamic_cast (this)); - - for (int i = listeners.size(); --i >= 0;) - { - ((FileBrowserListener*) listeners.getUnchecked (i))->selectionChanged(); - - if (deletionWatcher == 0) - return; - - i = jmin (i, listeners.size() - 1); - } + Component::BailOutChecker checker (dynamic_cast (this)); + listeners.callChecked (checker, &FileBrowserListener::selectionChanged); } void DirectoryContentsDisplayComponent::sendMouseClickMessage (const File& file, const MouseEvent& e) { if (fileList.getDirectory().exists()) { - Component::SafePointer deletionWatcher (dynamic_cast (this)); - - for (int i = listeners.size(); --i >= 0;) - { - ((FileBrowserListener*) listeners.getUnchecked (i))->fileClicked (file, e); - - if (deletionWatcher == 0) - return; - - i = jmin (i, listeners.size() - 1); - } + Component::BailOutChecker checker (dynamic_cast (this)); + listeners.callChecked (checker, &FileBrowserListener::fileClicked, file, e); } } @@ -56724,17 +56512,8 @@ void DirectoryContentsDisplayComponent::sendDoubleClickMessage (const File& file { if (fileList.getDirectory().exists()) { - Component::SafePointer deletionWatcher (dynamic_cast (this)); - - for (int i = listeners.size(); --i >= 0;) - { - ((FileBrowserListener*) listeners.getUnchecked (i))->fileDoubleClicked (file); - - if (deletionWatcher == 0) - return; - - i = jmin (i, listeners.size() - 1); - } + Component::BailOutChecker checker (dynamic_cast (this)); + listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, file); } } @@ -57130,15 +56909,12 @@ FileBrowserComponent::~FileBrowserComponent() void FileBrowserComponent::addListener (FileBrowserListener* const newListener) throw() { - jassert (newListener != 0) - - if (newListener != 0) - listeners.add (newListener); + listeners.add (newListener); } void FileBrowserComponent::removeListener (FileBrowserListener* const listener) throw() { - listeners.removeValue (listener); + listeners.remove (listener); } bool FileBrowserComponent::isSaveMode() const throw() @@ -57275,23 +57051,15 @@ void FileBrowserComponent::resized() void FileBrowserComponent::sendListenerChangeMessage() { - Component::SafePointer deletionWatcher (this); + Component::BailOutChecker checker (this); if (previewComp != 0) previewComp->selectedFileChanged (getSelectedFile (0)); // You shouldn't delete the browser when the file gets changed! - jassert (deletionWatcher != 0); - - for (int i = listeners.size(); --i >= 0;) - { - ((FileBrowserListener*) listeners.getUnchecked (i))->selectionChanged(); + jassert (! checker.shouldBailOut()); - if (deletionWatcher == 0) - return; - - i = jmin (i, listeners.size() - 1); - } + listeners.callChecked (checker, &FileBrowserListener::selectionChanged); } void FileBrowserComponent::selectionChanged() @@ -57324,17 +57092,8 @@ void FileBrowserComponent::selectionChanged() void FileBrowserComponent::fileClicked (const File& f, const MouseEvent& e) { - Component::SafePointer deletionWatcher (this); - - for (int i = listeners.size(); --i >= 0;) - { - ((FileBrowserListener*) listeners.getUnchecked (i))->fileClicked (f, e); - - if (deletionWatcher == 0) - return; - - i = jmin (i, listeners.size() - 1); - } + Component::BailOutChecker checker (this); + listeners.callChecked (checker, &FileBrowserListener::fileClicked, f, e); } void FileBrowserComponent::fileDoubleClicked (const File& f) @@ -57345,17 +57104,8 @@ void FileBrowserComponent::fileDoubleClicked (const File& f) } else { - Component::SafePointer deletionWatcher (this); - - for (int i = listeners.size(); --i >= 0;) - { - ((FileBrowserListener*) listeners.getUnchecked (i))->fileDoubleClicked (f); - - if (deletionWatcher == 0) - return; - - i = jmin (i, listeners.size() - 1); - } + Component::BailOutChecker checker (this); + listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, f); } } @@ -58295,24 +58045,18 @@ void FilenameComponent::addRecentlyUsedFile (const File& file) void FilenameComponent::addListener (FilenameComponentListener* const listener) throw() { - jassert (listener != 0); - - if (listener != 0) - listeners.add (listener); + listeners.add (listener); } void FilenameComponent::removeListener (FilenameComponentListener* const listener) throw() { - listeners.removeValue (listener); + listeners.remove (listener); } void FilenameComponent::handleAsyncUpdate() { - for (int i = listeners.size(); --i >= 0;) - { - ((FilenameComponentListener*) listeners.getUnchecked (i))->filenameComponentChanged (this); - i = jmin (i, listeners.size()); - } + Component::BailOutChecker checker (this); + listeners.callChecked (checker, &FilenameComponentListener::filenameComponentChanged, this); } END_JUCE_NAMESPACE @@ -61449,10 +61193,13 @@ END_JUCE_NAMESPACE /*** Start of inlined file: juce_ResizableBorderComponent.cpp ***/ BEGIN_JUCE_NAMESPACE -const int zoneL = 1; -const int zoneR = 2; -const int zoneT = 4; -const int zoneB = 8; +enum ResizableBorderComponentZones +{ + zoneL = 1, + zoneR = 2, + zoneT = 4, + zoneB = 8 +}; ResizableBorderComponent::ResizableBorderComponent (Component* const componentToResize, ComponentBoundsConstrainer* const constrainer_) @@ -61484,67 +61231,50 @@ void ResizableBorderComponent::mouseMove (const MouseEvent& e) void ResizableBorderComponent::mouseDown (const MouseEvent& e) { - if (component->isValidComponent()) + if (component == 0) { - updateMouseZone (e); + jassertfalse // You've deleted the component that this resizer was supposed to be using! + return; + } - originalX = component->getX(); - originalY = component->getY(); - originalW = component->getWidth(); - originalH = component->getHeight(); + updateMouseZone (e); - if (constrainer != 0) - constrainer->resizeStart(); - } - else - { - jassertfalse - } + originalBounds = component->getBounds(); + + if (constrainer != 0) + constrainer->resizeStart(); } void ResizableBorderComponent::mouseDrag (const MouseEvent& e) { - if (! component->isValidComponent()) + if (component == 0) { - jassertfalse + jassertfalse // You've deleted the component that this resizer was supposed to be using! return; } - int x = originalX; - int y = originalY; - int w = originalW; - int h = originalH; - - const int dx = e.getDistanceFromDragStartX(); - const int dy = e.getDistanceFromDragStartY(); + Rectangle bounds (originalBounds); if ((mouseZone & zoneL) != 0) - { - x += dx; - w -= dx; - } + bounds.setLeft (bounds.getX() + e.getDistanceFromDragStartX()); if ((mouseZone & zoneT) != 0) - { - y += dy; - h -= dy; - } + bounds.setTop (bounds.getY() + e.getDistanceFromDragStartY()); if ((mouseZone & zoneR) != 0) - w += dx; + bounds.setWidth (bounds.getWidth() + e.getDistanceFromDragStartX()); if ((mouseZone & zoneB) != 0) - h += dy; + bounds.setHeight (bounds.getHeight() + e.getDistanceFromDragStartY()); if (constrainer != 0) - constrainer->setBoundsForComponent (component, - Rectangle (x, y, w, h), + constrainer->setBoundsForComponent (component, bounds, (mouseZone & zoneT) != 0, (mouseZone & zoneL) != 0, (mouseZone & zoneB) != 0, (mouseZone & zoneR) != 0); else - component->setBounds (x, y, w, h); + component->setBounds (bounds); } void ResizableBorderComponent::mouseUp (const MouseEvent&) @@ -61561,7 +61291,7 @@ bool ResizableBorderComponent::hitTest (int x, int y) || y >= getHeight() - borderSize.getBottom(); } -void ResizableBorderComponent::setBorderThickness (const BorderSize& newBorderSize) throw() +void ResizableBorderComponent::setBorderThickness (const BorderSize& newBorderSize) { if (borderSize != newBorderSize) { @@ -61570,12 +61300,12 @@ void ResizableBorderComponent::setBorderThickness (const BorderSize& newBorderSi } } -const BorderSize ResizableBorderComponent::getBorderThickness() const throw() +const BorderSize ResizableBorderComponent::getBorderThickness() const { return borderSize; } -void ResizableBorderComponent::updateMouseZone (const MouseEvent& e) throw() +void ResizableBorderComponent::updateMouseZone (const MouseEvent& e) { int newZone = 0; @@ -61608,40 +61338,15 @@ void ResizableBorderComponent::updateMouseZone (const MouseEvent& e) throw() switch (newZone) { - case (zoneL | zoneT): - mc = MouseCursor::TopLeftCornerResizeCursor; - break; - - case zoneT: - mc = MouseCursor::TopEdgeResizeCursor; - break; - - case (zoneR | zoneT): - mc = MouseCursor::TopRightCornerResizeCursor; - break; - - case zoneL: - mc = MouseCursor::LeftEdgeResizeCursor; - break; - - case zoneR: - mc = MouseCursor::RightEdgeResizeCursor; - break; - - case (zoneL | zoneB): - mc = MouseCursor::BottomLeftCornerResizeCursor; - break; - - case zoneB: - mc = MouseCursor::BottomEdgeResizeCursor; - break; - - case (zoneR | zoneB): - mc = MouseCursor::BottomRightCornerResizeCursor; - break; - - default: - break; + case (zoneL | zoneT): mc = MouseCursor::TopLeftCornerResizeCursor; break; + case zoneT: mc = MouseCursor::TopEdgeResizeCursor; break; + case (zoneR | zoneT): mc = MouseCursor::TopRightCornerResizeCursor; break; + case zoneL: mc = MouseCursor::LeftEdgeResizeCursor; break; + case zoneR: mc = MouseCursor::RightEdgeResizeCursor; break; + case (zoneL | zoneB): mc = MouseCursor::BottomLeftCornerResizeCursor; break; + case zoneB: mc = MouseCursor::BottomEdgeResizeCursor; break; + case (zoneR | zoneB): mc = MouseCursor::BottomRightCornerResizeCursor; break; + default: break; } setMouseCursor (mc); @@ -61678,40 +61383,33 @@ void ResizableCornerComponent::paint (Graphics& g) void ResizableCornerComponent::mouseDown (const MouseEvent&) { - if (component->isValidComponent()) - { - originalX = component->getX(); - originalY = component->getY(); - originalW = component->getWidth(); - originalH = component->getHeight(); - - if (constrainer != 0) - constrainer->resizeStart(); - } - else + if (component == 0) { - jassertfalse + jassertfalse; // You've deleted the component that this resizer is supposed to be controlling! + return; } + + originalBounds = component->getBounds(); + + if (constrainer != 0) + constrainer->resizeStart(); } void ResizableCornerComponent::mouseDrag (const MouseEvent& e) { - if (! component->isValidComponent()) + if (component == 0) { - jassertfalse + jassertfalse; // You've deleted the component that this resizer is supposed to be controlling! return; } - int x = originalX; - int y = originalY; - int w = originalW + e.getDistanceFromDragStartX(); - int h = originalH + e.getDistanceFromDragStartY(); + Rectangle r (originalBounds.withSize (originalBounds.getWidth() + e.getDistanceFromDragStartX(), + originalBounds.getHeight() + e.getDistanceFromDragStartY())); if (constrainer != 0) - constrainer->setBoundsForComponent (component, Rectangle (x, y, w, h), - false, false, true, true); + constrainer->setBoundsForComponent (component, r, false, false, true, true); else - component->setBounds (x, y, w, h); + component->setBounds (r); } void ResizableCornerComponent::mouseUp (const MouseEvent&) @@ -61888,25 +61586,17 @@ void ScrollBar::setButtonRepeatSpeed (const int initialDelayInMillisecs_, void ScrollBar::addListener (ScrollBarListener* const listener) throw() { - jassert (listener != 0); - if (listener != 0) - listeners.add (listener); + listeners.add (listener); } void ScrollBar::removeListener (ScrollBarListener* const listener) throw() { - listeners.removeValue (listener); + listeners.remove (listener); } void ScrollBar::handleAsyncUpdate() { - const double value = getCurrentRangeStart(); - - for (int i = listeners.size(); --i >= 0;) - { - ((ScrollBarListener*) listeners.getUnchecked (i))->scrollBarMoved (this, value); - i = jmin (i, listeners.size()); - } + listeners.call (&ScrollBarListener::scrollBarMoved, this, rangeStart); } void ScrollBar::updateThumbPosition() throw() @@ -63527,11 +63217,9 @@ void Viewport::setViewedComponent (Component* const newViewedComponent) { if (contentComp != newViewedComponent) { - if (contentComp->isValidComponent()) { - Component* const oldComp = contentComp; + ScopedPointer oldCompDeleter (contentComp); contentComp = 0; - delete oldComp; } contentComp = newViewedComponent; @@ -67789,11 +67477,7 @@ void MenuBarModel::setApplicationCommandManagerToWatch (ApplicationCommandManage void MenuBarModel::addListener (MenuBarModelListener* const newListener) throw() { - jassert (newListener != 0); - jassert (! listeners.contains (newListener)); // trying to add a listener to the list twice! - - if (newListener != 0) - listeners.add (newListener); + listeners.add (newListener); } void MenuBarModel::removeListener (MenuBarModelListener* const listenerToRemove) throw() @@ -67803,25 +67487,17 @@ void MenuBarModel::removeListener (MenuBarModelListener* const listenerToRemove) // deleted this menu model while it's still being used by something (e.g. by a MenuBarComponent) jassert (listeners.contains (listenerToRemove)); - listeners.removeValue (listenerToRemove); + listeners.remove (listenerToRemove); } void MenuBarModel::handleAsyncUpdate() { - for (int i = listeners.size(); --i >= 0;) - { - ((MenuBarModelListener*) listeners.getUnchecked (i))->menuBarItemsChanged (this); - i = jmin (i, listeners.size()); - } + listeners.call (&MenuBarModelListener::menuBarItemsChanged, this); } void MenuBarModel::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info) { - for (int i = listeners.size(); --i >= 0;) - { - ((MenuBarModelListener*) listeners.getUnchecked (i))->menuCommandInvoked (this, info); - i = jmin (i, listeners.size()); - } + listeners.call (&MenuBarModelListener::menuCommandInvoked, this, info); } void MenuBarModel::applicationCommandListChanged() @@ -68140,6 +67816,7 @@ public: mw->menuBarComponent = menuBarComponent; mw->managerOfChosenCommand = managerOfChosenCommand; mw->componentAttachedTo = componentAttachedTo; + mw->componentAttachedToOriginal = componentAttachedTo; mw->calculateWindowPos (minX, maxX, minY, maxY, alignToRectangle); mw->setTopLeftPosition (mw->windowPos.getX(), @@ -68287,16 +67964,14 @@ public: } else if (key.isKeyCode (KeyPress::leftKey)) { - Window* parentWindow = owner; - - if (parentWindow != 0) + if (owner != 0) { - PopupMenu::ItemComponent* currentChildOfParent - = (parentWindow != 0) ? parentWindow->currentChild : 0; + Component::SafePointer parentWindow (owner); + PopupMenu::ItemComponent* currentChildOfParent = parentWindow->currentChild; hide (0); - if (parentWindow->isValidComponent()) + if (parentWindow != 0) parentWindow->setCurrentlyHighlightedChild (currentChildOfParent); disableTimerUntilMouseMoves(); @@ -68378,7 +68053,7 @@ public: if (! isVisible()) return; - if (componentAttachedTo == 0) + if (componentAttachedTo != componentAttachedToOriginal) { dismissMenu (0); return; @@ -68531,6 +68206,7 @@ private: Component* menuBarComponent; ApplicationCommandManager** managerOfChosenCommand; Component::SafePointer componentAttachedTo; + Component* componentAttachedToOriginal; Rectangle windowPos; Point lastMouse; int minimumWidth, maximumNumColumns, standardItemHeight; @@ -69581,7 +69257,7 @@ void ComponentDragger::startDraggingComponent (Component* const componentToDrag, { jassert (componentToDrag->isValidComponent()); - if (componentToDrag->isValidComponent()) + if (componentToDrag != 0) { constrainer = constrainer_; originalPos = componentToDrag->relativePositionToGlobal (Point()); @@ -69593,24 +69269,20 @@ void ComponentDragger::dragComponent (Component* const componentToDrag, const Mo jassert (componentToDrag->isValidComponent()); jassert (e.mods.isAnyMouseButtonDown()); // (the event has to be a drag event..) - if (componentToDrag->isValidComponent()) + if (componentToDrag != 0) { - Point pos (originalPos); - int w = componentToDrag->getWidth(); - int h = componentToDrag->getHeight(); + Rectangle bounds (componentToDrag->getBounds().withPosition (originalPos)); const Component* const parentComp = componentToDrag->getParentComponent(); if (parentComp != 0) - pos = parentComp->globalPositionToRelative (pos); + bounds.setPosition (parentComp->globalPositionToRelative (originalPos)); - pos += Point (e.getDistanceFromDragStartX(), - e.getDistanceFromDragStartY()); + bounds.setPosition (bounds.getPosition() + e.getOffsetFromDragStart()); if (constrainer != 0) - constrainer->setBoundsForComponent (componentToDrag, Rectangle (pos.getX(), pos.getY(), w, h), - false, false, false, false); + constrainer->setBoundsForComponent (componentToDrag, bounds, false, false, false, false); else - componentToDrag->setBounds (pos.getX(), pos.getY(), w, h); + componentToDrag->setBounds (bounds); } } @@ -70264,6 +69936,11 @@ int MouseEvent::getDistanceFromDragStart() const throw() return mouseDownPos.getDistanceFrom (getPosition()); } +const Point MouseEvent::getOffsetFromDragStart() const throw() +{ + return getPosition() - mouseDownPos; +} + int MouseEvent::getLengthOfMousePress() const throw() { if (mouseDownTime.toMilliseconds() > 0) @@ -70348,7 +70025,7 @@ public: Component* getComponentUnderMouse() const { - return const_cast (static_cast (componentUnderMouse)); + return static_cast (componentUnderMouse); } const ModifierKeys getCurrentModifiers() const @@ -73184,6 +72861,11 @@ BEGIN_JUCE_NAMESPACE static const int swatchesPerRow = 8; static const int swatchHeight = 22; +static const String colourComponentToHexString (int value) +{ + return String::toHexString (value).toUpperCase().paddedLeft ('0', 2); +} + class ColourComponentSlider : public Slider { public: @@ -73199,7 +72881,7 @@ public: const String getTextFromValue (double value) { - return String::formatted (T("%02X"), (int) value); + return colourComponentToHexString ((int) value); } double getValueFromText (const String& text) @@ -73634,15 +73316,13 @@ void ColourSelector::paint (Graphics& g) g.setColour (Colours::white.overlaidWith (colour).contrasting()); g.setFont (14.0f, true); g.drawText (((flags & showAlphaChannel) != 0) - ? String::formatted (T("#%02X%02X%02X%02X"), - (int) colour.getAlpha(), - (int) colour.getRed(), - (int) colour.getGreen(), - (int) colour.getBlue()) - : String::formatted (T("#%02X%02X%02X"), - (int) colour.getRed(), - (int) colour.getGreen(), - (int) colour.getBlue()), + ? colourComponentToHexString ((int) colour.getAlpha()) + + colourComponentToHexString ((int) colour.getRed()) + + colourComponentToHexString ((int) colour.getGreen()) + + colourComponentToHexString ((int) colour.getBlue()) + : colourComponentToHexString ((int) colour.getRed()) + + colourComponentToHexString ((int) colour.getGreen()) + + colourComponentToHexString ((int) colour.getBlue()), 0, edgeGap, getWidth(), topSpace - edgeGap * 2, Justification::centred, false); } @@ -76259,7 +75939,7 @@ struct AlertWindowInfo String title, message, button1, button2, button3; AlertWindow::AlertIconType iconType; int numButtons; - Component* associatedComponent; + Component::SafePointer associatedComponent; int run() const { @@ -76270,10 +75950,8 @@ struct AlertWindowInfo private: int show() const { - jassert (associatedComponent == 0 || associatedComponent->isValidComponent()); // has your comp been deleted? - - LookAndFeel& lf = associatedComponent->isValidComponent() ? associatedComponent->getLookAndFeel() - : LookAndFeel::getDefaultLookAndFeel(); + LookAndFeel& lf = associatedComponent != 0 ? associatedComponent->getLookAndFeel() + : LookAndFeel::getDefaultLookAndFeel(); ScopedPointer alertBox (lf.createAlertWindow (title, message, button1, button2, button3, iconType, numButtons, associatedComponent)); @@ -76460,8 +76138,8 @@ bool ComponentPeer::handleKeyPress (const int keyCode, { updateCurrentModifiers(); - Component* target = Component::currentlyFocusedComponent->isValidComponent() - ? Component::currentlyFocusedComponent + Component* target = Component::getCurrentlyFocusedComponent() != 0 + ? Component::getCurrentlyFocusedComponent() : component; if (target->isCurrentlyBlockedByAnotherModalComponent()) @@ -76519,8 +76197,8 @@ bool ComponentPeer::handleKeyUpOrDown (const bool isKeyDown) { updateCurrentModifiers(); - Component* target = Component::currentlyFocusedComponent->isValidComponent() - ? Component::currentlyFocusedComponent + Component* target = Component::getCurrentlyFocusedComponent() != 0 + ? Component::getCurrentlyFocusedComponent() : component; if (target->isCurrentlyBlockedByAnotherModalComponent()) @@ -76573,7 +76251,7 @@ void ComponentPeer::handleModifierKeysChange() if (target == 0) target = component; - if (target->isValidComponent()) + if (target != 0) target->internalModifierKeysChanged(); } @@ -76722,7 +76400,7 @@ void ComponentPeer::handleFileDragMove (const StringArray& files, const Point (dynamic_cast (static_cast (dragAndDropTargetComponent))); + = dynamic_cast (static_cast (dragAndDropTargetComponent)); FileDragAndDropTarget* newTarget = 0; @@ -76777,7 +76455,7 @@ void ComponentPeer::handleFileDragDrop (const StringArray& files, const Point (dynamic_cast (static_cast (dragAndDropTargetComponent))); + = dynamic_cast (static_cast (dragAndDropTargetComponent)); dragAndDropTargetComponent = 0; lastDragAndDropCompUnderMouse = 0; @@ -78041,7 +77719,7 @@ void TooltipWindow::showFor (const String& tip) const String TooltipWindow::getTipFor (Component* const c) { - if (c->isValidComponent() + if (c != 0 && Process::isForegroundProcess() && ! Component::isMouseButtonDownAnywhere()) { @@ -215587,7 +215265,7 @@ private: { updateKeyModifiers(); - const float amount = jlimit (-1000.0f, 1000.0f, 0.75f * HIWORD (wParam)); + const float amount = jlimit (-1000.0f, 1000.0f, 0.75f * (short) HIWORD (wParam)); handleMouseWheel (0, position, getMouseEventTime(), isVertical ? 0.0f : amount, @@ -246519,10 +246197,7 @@ BOOL NSViewComponentPeer::sendDragCallback (int type, id sender bool NSViewComponentPeer::isOpaque() { - if (! getComponent()->isValidComponent()) - return true; - - return getComponent()->isOpaque(); + return component == 0 || component->isOpaque(); } void NSViewComponentPeer::drawRect (NSRect r) @@ -247956,7 +247631,7 @@ END_JUCE_NAMESPACE NSEvent* e = [NSApp currentEvent]; if ([e type] == NSKeyDown || [e type] == NSKeyUp) { - if (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->isValidComponent()) + if (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent() != 0) { JUCE_NAMESPACE::NSViewComponentPeer* peer = dynamic_cast (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->getPeer()); diff --git a/juce_amalgamated.h b/juce_amalgamated.h index cd5058ec35..60bd21c6b9 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -43,7 +43,7 @@ #define JUCE_MAJOR_VERSION 1 #define JUCE_MINOR_VERSION 51 -#define JUCE_BUILDNUMBER 6 +#define JUCE_BUILDNUMBER 7 #define JUCE_VERSION ((JUCE_MAJOR_VERSION << 16) + (JUCE_MINOR_VERSION << 8) + JUCE_BUILDNUMBER) @@ -1278,7 +1278,11 @@ public: void vprintf (const tchar* const format, va_list& args) throw(); static const String repeatedString (const tchar* const stringToRepeat, - int numberOfTimesToRepeat) throw(); + int numberOfTimesToRepeat); + + const String paddedLeft (const juce_wchar padCharacter, int minimumLength) const; + + const String paddedRight (const juce_wchar padCharacter, int minimumLength) const; static const String createStringFromData (const void* const data, const int size) throw(); @@ -6013,6 +6017,211 @@ private: #endif // __JUCE_ASYNCUPDATER_JUCEHEADER__ /*** End of inlined file: juce_AsyncUpdater.h ***/ + +/*** Start of inlined file: juce_ListenerList.h ***/ +#ifndef __JUCE_LISTENERLIST_JUCEHEADER__ +#define __JUCE_LISTENERLIST_JUCEHEADER__ + +template > +class ListenerList +{ +public: + + ListenerList() + { + } + + ~ListenerList() + { + } + + void add (ListenerClass* const listenerToAdd) + { + // Listeners can't be null pointers! + jassert (listenerToAdd != 0); + + if (listenerToAdd != 0) + listeners.add (listenerToAdd); + } + + void remove (ListenerClass* const listenerToRemove) + { + // Listeners can't be null pointers! + jassert (listenerToRemove != 0); + + listeners.removeValue (listenerToRemove); + } + + int size() const throw() + { + return listeners.size(); + } + + bool isEmpty() const throw() + { + return listeners.size() == 0; + } + + bool contains (ListenerClass* const listener) const throw() + { + return listeners.contains (listener); + } + + void call (void (ListenerClass::*callbackFunction) ()) + { + callChecked (DummyBailOutChecker(), callbackFunction); + } + + template + void callChecked (const BailOutCheckerType& bailOutChecker, + void (ListenerClass::*callbackFunction) ()) + { + for (Iterator iter (*this, bailOutChecker); iter.next();) + (iter.getListener()->*callbackFunction) (); + } + + template + void call (void (ListenerClass::*callbackFunction) (P1), + P2& param1) + { + for (Iterator iter (*this, DummyBailOutChecker()); iter.next();) + (iter.getListener()->*callbackFunction) (param1); + } + + template + void callChecked (const BailOutCheckerType& bailOutChecker, + void (ListenerClass::*callbackFunction) (P1), + P2& param1) + { + for (Iterator iter (*this, bailOutChecker); iter.next();) + (iter.getListener()->*callbackFunction) (param1); + } + + template + void call (void (ListenerClass::*callbackFunction) (P1, P2), + P3& param1, P4& param2) + { + for (Iterator iter (*this, DummyBailOutChecker()); iter.next();) + (iter.getListener()->*callbackFunction) (param1, param2); + } + + template + void callChecked (const BailOutCheckerType& bailOutChecker, + void (ListenerClass::*callbackFunction) (P1, P2), + P3& param1, P4& param2) + { + for (Iterator iter (*this, bailOutChecker); iter.next();) + (iter.getListener()->*callbackFunction) (param1, param2); + } + + template + void call (void (ListenerClass::*callbackFunction) (P1, P2, P3), + P4& param1, P5& param2, P6& param3) + { + for (Iterator iter (*this, DummyBailOutChecker()); iter.next();) + (iter.getListener()->*callbackFunction) (param1, param2, param3); + } + + template + void callChecked (const BailOutCheckerType& bailOutChecker, + void (ListenerClass::*callbackFunction) (P1, P2, P3), + P4& param1, P5& param2, P6& param3) + { + for (Iterator iter (*this, bailOutChecker); iter.next();) + (iter.getListener()->*callbackFunction) (param1, param2, param3); + } + + template + void call (void (ListenerClass::*callbackFunction) (P1, P2, P3, P4), + P5& param1, P6& param2, P7& param3, P8& param4) + { + for (Iterator iter (*this, DummyBailOutChecker()); iter.next();) + (iter.getListener()->*callbackFunction) (param1, param2, param3, param4); + } + + template + void callChecked (const BailOutCheckerType& bailOutChecker, + void (ListenerClass::*callbackFunction) (P1, P2, P3, P4), + P5& param1, P6& param2, P7& param3, P8& param4) + { + for (Iterator iter (*this, bailOutChecker); iter.next();) + (iter.getListener()->*callbackFunction) (param1, param2, param3, param4); + } + + template + void call (void (ListenerClass::*callbackFunction) (P1, P2, P3, P4, P5), + P6& param1, P7& param2, P8& param3, P9& param4, P10& param5) + { + for (Iterator iter (*this, DummyBailOutChecker()); iter.next();) + (iter.getListener()->*callbackFunction) (param1, param2, param3, param4, param5); + } + + template + void callChecked (const BailOutCheckerType& bailOutChecker, + void (ListenerClass::*callbackFunction) (P1, P2, P3, P4, P5), + P6& param1, P7& param2, P8& param3, P9& param4, P10& param5) + { + for (Iterator iter (*this, bailOutChecker); iter.next();) + (iter.getListener()->*callbackFunction) (param1, param2, param3, param4, param5); + } + + class DummyBailOutChecker + { + public: + inline bool shouldBailOut() const throw() { return false; } + }; + + template + class Iterator + { + public: + + Iterator (const ListenerList& list_, const BailOutCheckerType& bailOutChecker_) + : list (list_), bailOutChecker (bailOutChecker_), index (list_.size()) + {} + + ~Iterator() {} + + bool next() + { + if (index <= 0 || bailOutChecker.shouldBailOut()) + return false; + + const int listSize = list.size(); + + if (--index < listSize) + return true; + + index = listSize - 1; + return index >= 0; + } + + ListenerClass* getListener() const throw() + { + return list.listeners.getUnchecked (index); + } + + private: + const ListenerList& list; + const BailOutCheckerType& bailOutChecker; + int index; + + Iterator (const Iterator&); + Iterator& operator= (const Iterator&); + }; + +private: + + ArrayType listeners; + + ListenerList (const ListenerList&); + ListenerList& operator= (const ListenerList&); +}; + +#endif // __JUCE_LISTENERLIST_JUCEHEADER__ +/*** End of inlined file: juce_ListenerList.h ***/ + class JUCE_API Value { public: @@ -6088,7 +6297,7 @@ public: private: friend class ValueSource; ReferenceCountedObjectPtr value; - SortedSet listeners; + ListenerList listeners; void callListeners(); @@ -6490,11 +6699,7 @@ private: typedef ReferenceCountedObjectPtr SharedObjectPtr; ReferenceCountedObjectPtr object; - SortedSet listeners; - - void deliverPropertyChangeMessage (ValueTree& tree, const var::identifier& property); - void deliverChildChangeMessage (ValueTree& tree); - void deliverParentChangeMessage (ValueTree& tree); + ListenerList listeners; ValueTree (SharedObject* const object_); }; @@ -9261,6 +9466,8 @@ public: int getDistanceFromDragStartY() const throw(); + const Point getOffsetFromDragStart() const throw(); + bool mouseWasClicked() const throw(); int getNumberOfClicks() const throw() { return numberOfClicks; } @@ -12379,9 +12586,7 @@ public: return *this; } - operator ComponentType*() throw() { return comp; } - - operator const ComponentType*() const throw() { return comp; } + operator ComponentType*() const throw() { return comp; } /** Returns the component that this pointer refers to, or null if the component no longer exists. */ ComponentType* operator->() throw() { jassert (comp != 0); return comp; } @@ -12399,6 +12604,22 @@ public: void componentBeingDeleted (Component&) { comp = 0; } }; + class BailOutChecker + { + public: + BailOutChecker (Component* const component1, + Component* const component2 = 0); + + bool shouldBailOut() const throw(); + + private: + Component::SafePointer safePointer1, safePointer2; + Component* const component2; + + BailOutChecker (const BailOutChecker&); + BailOutChecker& operator= (const BailOutChecker&); + }; + juce_UseDebuggingNewOperator private: @@ -12422,7 +12643,7 @@ private: Image* bufferedImage_; VoidArray* mouseListeners_; VoidArray* keyListeners_; - VoidArray* componentListeners_; + ListenerList componentListeners; NamedValueSet properties; struct ComponentFlags @@ -12876,13 +13097,13 @@ class JUCE_API Desktop : private DeletedAtShutdown, { public: - static Desktop& JUCE_CALLTYPE getInstance() throw(); + static Desktop& JUCE_CALLTYPE getInstance(); const RectangleList getAllMonitorDisplayAreas (const bool clippedToWorkArea = true) const throw(); const Rectangle getMainMonitorArea (const bool clippedToWorkArea = true) const throw(); - const Rectangle getMonitorAreaContaining (const Point& position, const bool clippedToWorkArea = true) const throw(); + const Rectangle getMonitorAreaContaining (const Point& position, const bool clippedToWorkArea = true) const; static const Point getMousePosition(); @@ -12896,18 +13117,18 @@ public: static bool isScreenSaverEnabled() throw(); - void addGlobalMouseListener (MouseListener* const listener) throw(); + void addGlobalMouseListener (MouseListener* const listener); - void removeGlobalMouseListener (MouseListener* const listener) throw(); + void removeGlobalMouseListener (MouseListener* const listener); - void addFocusChangeListener (FocusChangeListener* const listener) throw(); + void addFocusChangeListener (FocusChangeListener* const listener); - void removeFocusChangeListener (FocusChangeListener* const listener) throw(); + void removeFocusChangeListener (FocusChangeListener* const listener); void setKioskModeComponent (Component* componentToUse, const bool allowMenusAndBars = true); - Component* getKioskModeComponent() const { return kioskModeComponent; } + Component* getKioskModeComponent() const throw() { return kioskModeComponent; } int getNumComponents() const throw(); @@ -12927,7 +13148,7 @@ public: juce_UseDebuggingNewOperator - void refreshMonitorSizes() throw(); + void refreshMonitorSizes(); static bool canUseSemiTransparentWindows() throw(); @@ -12939,42 +13160,43 @@ private: friend class ComponentPeer; friend class MouseInputSource; friend class MouseInputSourceInternal; - SortedSet mouseListeners, focusListeners; - Array desktopComponents; - friend class DeletedAtShutdown; friend class TopLevelWindowManager; - Desktop() throw(); - ~Desktop() throw(); - - Array > monitorCoordsClipped, monitorCoordsUnclipped; OwnedArray mouseSources; + void createMouseInputSources(); + + ListenerList mouseListeners; + ListenerList focusListeners; + + Array desktopComponents; + Array > monitorCoordsClipped, monitorCoordsUnclipped; Point lastFakeMouseMove; - int mouseClickCounter; + void sendMouseMove(); + int mouseClickCounter; void incrementMouseClickCounter() throw(); Component* kioskModeComponent; Rectangle kioskComponentOriginalBounds; - void createMouseInputSources(); - void timerCallback(); - void sendMouseMove(); - void resetTimer() throw(); + void resetTimer(); int getNumDisplayMonitors() const throw(); const Rectangle getDisplayMonitorCoordinates (const int index, const bool clippedToWorkArea) const throw(); - void addDesktopComponent (Component* const c) throw(); - void removeDesktopComponent (Component* const c) throw(); - void componentBroughtToFront (Component* const c) throw(); + void addDesktopComponent (Component* const c); + void removeDesktopComponent (Component* const c); + void componentBroughtToFront (Component* const c); - void triggerFocusCallback() throw(); + void triggerFocusCallback(); void handleAsyncUpdate(); + Desktop(); + ~Desktop(); + Desktop (const Desktop&); Desktop& operator= (const Desktop&); }; @@ -13046,11 +13268,11 @@ public: private: OwnedArray commands; - SortedSet listeners; + ListenerList listeners; ScopedPointer keyMappings; ApplicationCommandTarget* firstTarget; - void sendListenerInvokeCallback (const ApplicationCommandTarget::InvocationInfo& info) const; + void sendListenerInvokeCallback (const ApplicationCommandTarget::InvocationInfo& info); void handleAsyncUpdate(); void globalFocusChanged (Component*); @@ -15708,9 +15930,9 @@ protected: private: Array shortcuts; - Component* keySource; + Component::SafePointer keySource; String text; - SortedSet buttonListeners; + ListenerList buttonListeners; class RepeatTimer; friend class RepeatTimer; @@ -15843,7 +16065,7 @@ private: bool vertical, isDraggingThumb, alwaysVisible; Button* upButton; Button* downButton; - SortedSet listeners; + ListenerList listeners; void updateThumbPosition() throw(); void timerCallback(); @@ -15921,7 +16143,7 @@ public: bool useMouseWheelMoveIfNeeded (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY); private: - Component* contentComp; + Component::SafePointer contentComp; int lastVX, lastVY, lastVW, lastVH; int scrollBarThickness; int singleStepX, singleStepY; @@ -16385,7 +16607,7 @@ private: } dragType; String allowedCharacters; - SortedSet listeners; + ListenerList listeners; friend class TextEditorInsertAction; friend class TextEditorRemoveAction; @@ -16562,7 +16784,7 @@ private: Font font; Justification justification; ScopedPointer editor; - SortedSet listeners; + ListenerList listeners; Component::SafePointer ownerComponent; int horizontalBorderSize, verticalBorderSize; float minimumHorizontalScale; @@ -16710,7 +16932,7 @@ private: Value currentId; int lastCurrentId; bool isButtonDown, separatorPending, menuActive, textIsCustom; - SortedSet listeners; + ListenerList listeners; ScopedPointer