From 9b38f912265e126066d6c7d0329d590df417b9e0 Mon Sep 17 00:00:00 2001 From: jules Date: Thu, 29 Sep 2011 21:25:00 +0100 Subject: [PATCH] Fixed a compile problem in VSTs. Minor clean-ups. --- extras/JuceDemo/Source/demos/OpenGLDemo.cpp | 2 +- .../RTAS/juce_RTAS_Wrapper.cpp | 2 +- .../VST/juce_VST_Wrapper.cpp | 2 +- .../keyboard/juce_KeyPress.cpp | 42 +++++-- .../keyboard/juce_KeyboardFocusTraverser.cpp | 74 ++++++------ .../keyboard/juce_ModifierKeys.cpp | 5 + .../keyboard/juce_ModifierKeys.h | 5 +- .../juce_gui_basics/mouse/juce_MouseEvent.cpp | 105 ++++-------------- .../juce_gui_basics/mouse/juce_MouseEvent.h | 23 ++-- .../mouse/juce_SelectedItemSet.h | 10 +- .../juce_gui_basics/widgets/juce_Label.cpp | 23 +--- 11 files changed, 118 insertions(+), 175 deletions(-) diff --git a/extras/JuceDemo/Source/demos/OpenGLDemo.cpp b/extras/JuceDemo/Source/demos/OpenGLDemo.cpp index 4d8bc3a75e..6ced372a24 100644 --- a/extras/JuceDemo/Source/demos/OpenGLDemo.cpp +++ b/extras/JuceDemo/Source/demos/OpenGLDemo.cpp @@ -172,7 +172,7 @@ private: for (int i = 10; --i >= 0;) { Path pp; - pp.addStar (Point (r.nextFloat() * w, r.nextFloat() * h, r.nextFloat() * 8 + 3, 10.0f, 20.0f, 0.0f); + pp.addStar (Point (r.nextFloat() * w, r.nextFloat() * h), r.nextFloat() * 8 + 3, 10.0f, 20.0f, 0.0f); g.setColour (Colours::pink.withAlpha (0.4f)); g.fillPath (pp); } diff --git a/modules/juce_audio_plugin_client/RTAS/juce_RTAS_Wrapper.cpp b/modules/juce_audio_plugin_client/RTAS/juce_RTAS_Wrapper.cpp index 9cd2251397..1de0cdde99 100644 --- a/modules/juce_audio_plugin_client/RTAS/juce_RTAS_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/RTAS/juce_RTAS_Wrapper.cpp @@ -617,7 +617,7 @@ protected: { //jassert (midiEventPosition >= 0 && midiEventPosition < (int) numSamples); } - #else + #elif JUCE_DEBUG || JUCE_LOG_ASSERTIONS // if your plugin creates midi messages, you'll need to set // the JucePlugin_ProducesMidiOutput macro to 1 in your // JucePluginCharacteristics.h file diff --git a/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp b/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp index fbeb7a5e1f..4d298d8217 100644 --- a/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp @@ -573,7 +573,7 @@ public: } sendVstEventsToHost (outgoingEvents.events); - #else + #elif JUCE_DEBUG /* This assertion is caused when you've added some events to the midiMessages array in your processBlock() method, which usually means that you're trying to send them somewhere. But in this case they're diff --git a/modules/juce_gui_basics/keyboard/juce_KeyPress.cpp b/modules/juce_gui_basics/keyboard/juce_KeyPress.cpp index 080eb75d20..c10306fb79 100644 --- a/modules/juce_gui_basics/keyboard/juce_KeyPress.cpp +++ b/modules/juce_gui_basics/keyboard/juce_KeyPress.cpp @@ -28,7 +28,6 @@ BEGIN_JUCE_NAMESPACE //============================================================================== KeyPress::KeyPress() noexcept : keyCode (0), - mods (0), textCharacter (0) { } @@ -170,6 +169,29 @@ namespace KeyPressHelpers return 0; } + + #if JUCE_MAC + struct OSXSymbolReplacement + { + const char* text; + juce_wchar symbol; + }; + + const OSXSymbolReplacement osxSymbols[] = + { + { "shift + ", 0x21e7 }, + { "command + ", 0x2318 }, + { "option + ", 0x2325 }, + { "ctrl + ", 0x2303 }, + { "return", 0x23ce }, + { "cursor left", 0x2190 }, + { "cursor right", 0x2192 }, + { "cursor up", 0x2191 }, + { "cursor down", 0x2193 }, + { "backspace", 0x232b }, + { "delete", 0x2326 } + }; + #endif } //============================================================================== @@ -273,17 +295,13 @@ String KeyPress::getTextDescription() const String KeyPress::getTextDescriptionWithIcons() const { #if JUCE_MAC - return getTextDescription().replace ("shift + ", String::charToString (0x21e7)) - .replace ("command + ", String::charToString (0x2318)) - .replace ("option + ", String::charToString (0x2325)) - .replace ("ctrl + ", String::charToString (0x2303)) - .replace ("return", String::charToString (0x23ce)) - .replace ("cursor left", String::charToString (0x2190)) - .replace ("cursor right", String::charToString (0x2192)) - .replace ("cursor up", String::charToString (0x2191)) - .replace ("cursor down", String::charToString (0x2193)) - .replace ("backspace", String::charToString (0x232b)) - .replace ("delete", String::charToString (0x2326)); + String s (getTextDescription()); + + for (int i = 0; i < numElementsInArray (KeyPressHelpers::osxSymbols); ++i) + s = s.replace (KeyPressHelpers::osxSymbols[i].text, + String::charToString (KeyPressHelpers::osxSymbols[i].symbol)); + + return s; #else return getTextDescription(); #endif diff --git a/modules/juce_gui_basics/keyboard/juce_KeyboardFocusTraverser.cpp b/modules/juce_gui_basics/keyboard/juce_KeyboardFocusTraverser.cpp index 3cd35013e0..7ce72cde0b 100644 --- a/modules/juce_gui_basics/keyboard/juce_KeyboardFocusTraverser.cpp +++ b/modules/juce_gui_basics/keyboard/juce_KeyboardFocusTraverser.cpp @@ -25,42 +25,30 @@ BEGIN_JUCE_NAMESPACE -//============================================================================== -KeyboardFocusTraverser::KeyboardFocusTraverser() -{ -} - -KeyboardFocusTraverser::~KeyboardFocusTraverser() -{ -} - -//============================================================================== namespace KeyboardFocusHelpers { // This will sort a set of components, so that they are ordered in terms of // left-to-right and then top-to-bottom. - class ScreenPositionComparator + struct ScreenPositionComparator { - public: - ScreenPositionComparator() {} - static int compareElements (const Component* const first, const Component* const second) { - int explicitOrder1 = first->getExplicitFocusOrder(); - if (explicitOrder1 <= 0) - explicitOrder1 = std::numeric_limits::max() / 2; - - int explicitOrder2 = second->getExplicitFocusOrder(); - if (explicitOrder2 <= 0) - explicitOrder2 = std::numeric_limits::max() / 2; + const int explicitOrder1 = getOrder (first); + const int explicitOrder2 = getOrder (second); if (explicitOrder1 != explicitOrder2) return explicitOrder1 - explicitOrder2; - const int diff = first->getY() - second->getY(); + const int yDiff = first->getY() - second->getY(); - return (diff == 0) ? first->getX() - second->getX() - : diff; + return yDiff == 0 ? first->getX() - second->getX() + : yDiff; + } + + static int getOrder (const Component* const c) + { + const int order = c->getExplicitFocusOrder(); + return order > 0 ? order : (std::numeric_limits::max() / 2); } }; @@ -92,29 +80,31 @@ namespace KeyboardFocusHelpers } } } -} -namespace KeyboardFocusHelpers -{ + Component* findFocusContainer (Component* c) + { + c = c->getParentComponent(); + + if (c != nullptr) + while (c->getParentComponent() != nullptr && ! c->isFocusContainer()) + c = c->getParentComponent(); + + return c; + } + Component* getIncrementedComponent (Component* const current, const int delta) { - Component* focusContainer = current->getParentComponent(); + Component* focusContainer = findFocusContainer (current); if (focusContainer != nullptr) { - while (focusContainer->getParentComponent() != nullptr && ! focusContainer->isFocusContainer()) - focusContainer = focusContainer->getParentComponent(); + Array comps; + KeyboardFocusHelpers::findAllFocusableComponents (focusContainer, comps); - if (focusContainer != nullptr) + if (comps.size() > 0) { - Array comps; - KeyboardFocusHelpers::findAllFocusableComponents (focusContainer, comps); - - if (comps.size() > 0) - { - const int index = comps.indexOf (current); - return comps [(index + comps.size() + delta) % comps.size()]; - } + const int index = comps.indexOf (current); + return comps [(index + comps.size() + delta) % comps.size()]; } } @@ -122,13 +112,19 @@ namespace KeyboardFocusHelpers } } +//============================================================================== +KeyboardFocusTraverser::KeyboardFocusTraverser() {} +KeyboardFocusTraverser::~KeyboardFocusTraverser() {} + Component* KeyboardFocusTraverser::getNextComponent (Component* current) { + jassert (current != nullptr); return KeyboardFocusHelpers::getIncrementedComponent (current, 1); } Component* KeyboardFocusTraverser::getPreviousComponent (Component* current) { + jassert (current != nullptr); return KeyboardFocusHelpers::getIncrementedComponent (current, -1); } diff --git a/modules/juce_gui_basics/keyboard/juce_ModifierKeys.cpp b/modules/juce_gui_basics/keyboard/juce_ModifierKeys.cpp index 9b38556788..7f2a989cd5 100644 --- a/modules/juce_gui_basics/keyboard/juce_ModifierKeys.cpp +++ b/modules/juce_gui_basics/keyboard/juce_ModifierKeys.cpp @@ -26,6 +26,11 @@ BEGIN_JUCE_NAMESPACE //============================================================================== +ModifierKeys::ModifierKeys() noexcept + : flags (0) +{ +} + ModifierKeys::ModifierKeys (const int flags_) noexcept : flags (flags_) { diff --git a/modules/juce_gui_basics/keyboard/juce_ModifierKeys.h b/modules/juce_gui_basics/keyboard/juce_ModifierKeys.h index 9893b7dc91..2b35ceb722 100644 --- a/modules/juce_gui_basics/keyboard/juce_ModifierKeys.h +++ b/modules/juce_gui_basics/keyboard/juce_ModifierKeys.h @@ -40,13 +40,16 @@ class JUCE_API ModifierKeys { public: //============================================================================== + /** Creates a ModifierKeys object with no flags set. */ + ModifierKeys() noexcept; + /** Creates a ModifierKeys object from a raw set of flags. @param flags to represent the keys that are down @see shiftModifier, ctrlModifier, altModifier, leftButtonModifier, rightButtonModifier, commandModifier, popupMenuClickModifier */ - ModifierKeys (int flags = 0) noexcept; + ModifierKeys (int flags) noexcept; /** Creates a copy of another object. */ ModifierKeys (const ModifierKeys& other) noexcept; diff --git a/modules/juce_gui_basics/mouse/juce_MouseEvent.cpp b/modules/juce_gui_basics/mouse/juce_MouseEvent.cpp index 6efa89562f..6ed8a618a4 100644 --- a/modules/juce_gui_basics/mouse/juce_MouseEvent.cpp +++ b/modules/juce_gui_basics/mouse/juce_MouseEvent.cpp @@ -45,8 +45,8 @@ MouseEvent::MouseEvent (MouseInputSource& source_, source (source_), mouseDownPos (mouseDownPos_), mouseDownTime (mouseDownTime_), - numberOfClicks (numberOfClicks_), - wasMovedSinceMouseDown (mouseWasDragged) + numberOfClicks ((uint8) numberOfClicks_), + wasMovedSinceMouseDown ((uint8) (mouseWasDragged ? 1 : 0)) { } @@ -57,64 +57,25 @@ MouseEvent::~MouseEvent() noexcept //============================================================================== MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) const noexcept { - if (otherComponent == nullptr) - { - jassertfalse; - return *this; - } + jassert (otherComponent != nullptr); return MouseEvent (source, otherComponent->getLocalPoint (eventComponent, getPosition()), mods, otherComponent, originalComponent, eventTime, otherComponent->getLocalPoint (eventComponent, mouseDownPos), - mouseDownTime, numberOfClicks, wasMovedSinceMouseDown); + mouseDownTime, numberOfClicks, wasMovedSinceMouseDown != 0); } MouseEvent MouseEvent::withNewPosition (const Point& newPosition) const noexcept { return MouseEvent (source, newPosition, mods, eventComponent, originalComponent, eventTime, mouseDownPos, mouseDownTime, - numberOfClicks, wasMovedSinceMouseDown); + numberOfClicks, wasMovedSinceMouseDown != 0); } //============================================================================== bool MouseEvent::mouseWasClicked() const noexcept { - return ! wasMovedSinceMouseDown; -} - -int MouseEvent::getMouseDownX() const noexcept -{ - return mouseDownPos.getX(); -} - -int MouseEvent::getMouseDownY() const noexcept -{ - return mouseDownPos.getY(); -} - -const Point MouseEvent::getMouseDownPosition() const noexcept -{ - return mouseDownPos; -} - -int MouseEvent::getDistanceFromDragStartX() const noexcept -{ - return x - mouseDownPos.getX(); -} - -int MouseEvent::getDistanceFromDragStartY() const noexcept -{ - return y - mouseDownPos.getY(); -} - -int MouseEvent::getDistanceFromDragStart() const noexcept -{ - return mouseDownPos.getDistanceFrom (getPosition()); -} - -const Point MouseEvent::getOffsetFromDragStart() const noexcept -{ - return getPosition() - mouseDownPos; + return wasMovedSinceMouseDown == 0; } int MouseEvent::getLengthOfMousePress() const noexcept @@ -126,52 +87,32 @@ int MouseEvent::getLengthOfMousePress() const noexcept } //============================================================================== -const Point MouseEvent::getPosition() const noexcept -{ - return Point (x, y); -} +Point MouseEvent::getPosition() const noexcept { return Point (x, y); } +Point MouseEvent::getScreenPosition() const { return eventComponent->localPointToGlobal (getPosition()); } -int MouseEvent::getScreenX() const -{ - return getScreenPosition().getX(); -} +Point MouseEvent::getMouseDownPosition() const noexcept { return mouseDownPos; } +Point MouseEvent::getMouseDownScreenPosition() const { return eventComponent->localPointToGlobal (mouseDownPos); } -int MouseEvent::getScreenY() const -{ - return getScreenPosition().getY(); -} +Point MouseEvent::getOffsetFromDragStart() const noexcept { return getPosition() - mouseDownPos; } +int MouseEvent::getDistanceFromDragStart() const noexcept { return mouseDownPos.getDistanceFrom (getPosition()); } -const Point MouseEvent::getScreenPosition() const -{ - return eventComponent->localPointToGlobal (Point (x, y)); -} +int MouseEvent::getMouseDownX() const noexcept { return mouseDownPos.getX(); } +int MouseEvent::getMouseDownY() const noexcept { return mouseDownPos.getY(); } -int MouseEvent::getMouseDownScreenX() const -{ - return getMouseDownScreenPosition().getX(); -} +int MouseEvent::getDistanceFromDragStartX() const noexcept { return x - mouseDownPos.getX(); } +int MouseEvent::getDistanceFromDragStartY() const noexcept { return y - mouseDownPos.getY(); } -int MouseEvent::getMouseDownScreenY() const -{ - return getMouseDownScreenPosition().getY(); -} +int MouseEvent::getScreenX() const { return getScreenPosition().getX(); } +int MouseEvent::getScreenY() const { return getScreenPosition().getY(); } -const Point MouseEvent::getMouseDownScreenPosition() const -{ - return eventComponent->localPointToGlobal (mouseDownPos); -} +int MouseEvent::getMouseDownScreenX() const { return getMouseDownScreenPosition().getX(); } +int MouseEvent::getMouseDownScreenY() const { return getMouseDownScreenPosition().getY(); } //============================================================================== -int MouseEvent::doubleClickTimeOutMs = 400; +static int doubleClickTimeOutMs = 400; -void MouseEvent::setDoubleClickTimeout (const int newTime) noexcept -{ - doubleClickTimeOutMs = newTime; -} +int MouseEvent::getDoubleClickTimeout() noexcept { return doubleClickTimeOutMs; } +void MouseEvent::setDoubleClickTimeout (const int newTime) noexcept { doubleClickTimeOutMs = newTime; } -int MouseEvent::getDoubleClickTimeout() noexcept -{ - return doubleClickTimeOutMs; -} END_JUCE_NAMESPACE diff --git a/modules/juce_gui_basics/mouse/juce_MouseEvent.h b/modules/juce_gui_basics/mouse/juce_MouseEvent.h index 64a0aa7123..3d26d0220a 100644 --- a/modules/juce_gui_basics/mouse/juce_MouseEvent.h +++ b/modules/juce_gui_basics/mouse/juce_MouseEvent.h @@ -124,12 +124,10 @@ public: */ Component* const originalComponent; - /** The time that this mouse-event occurred. - */ + /** The time that this mouse-event occurred. */ const Time eventTime; - /** The source device that generated this event. - */ + /** The source device that generated this event. */ MouseInputSource& source; //============================================================================== @@ -155,7 +153,7 @@ public: @see getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasClicked */ - const Point getMouseDownPosition() const noexcept; + Point getMouseDownPosition() const noexcept; /** Returns the straight-line distance between where the mouse is now and where it was the last time the button was pressed. @@ -186,7 +184,7 @@ public: @see getDistanceFromDragStart */ - const Point getOffsetFromDragStart() const noexcept; + Point getOffsetFromDragStart() const noexcept; /** Returns true if the mouse has just been clicked. @@ -226,7 +224,7 @@ public: This position is relative to the top-left of the component to which the event applies (as indicated by the MouseEvent::eventComponent field). */ - const Point getPosition() const noexcept; + Point getPosition() const noexcept; /** Returns the mouse x position of this event, in global screen co-ordinates. @@ -250,7 +248,7 @@ public: @see getMouseDownScreenPosition */ - const Point getScreenPosition() const; + Point getScreenPosition() const; /** Returns the x co-ordinate at which the mouse button was last pressed. @@ -274,15 +272,16 @@ public: @see getScreenPosition */ - const Point getMouseDownScreenPosition() const; + Point getMouseDownScreenPosition() const; //============================================================================== /** Creates a version of this event that is relative to a different component. The x and y positions of the event that is returned will have been adjusted to be relative to the new component. + The component pointer that is passed-in must not be null. */ - MouseEvent getEventRelativeTo (Component* otherComponent) const noexcept; + MouseEvent getEventRelativeTo (Component* newComponent) const noexcept; /** Creates a copy of this event with a different position. All other members of the event object are the same, but the x and y are @@ -314,9 +313,7 @@ private: //============================================================================== const Point mouseDownPos; const Time mouseDownTime; - const int numberOfClicks; - const bool wasMovedSinceMouseDown; - static int doubleClickTimeOutMs; + const uint8 numberOfClicks, wasMovedSinceMouseDown; MouseEvent& operator= (const MouseEvent&); }; diff --git a/modules/juce_gui_basics/mouse/juce_SelectedItemSet.h b/modules/juce_gui_basics/mouse/juce_SelectedItemSet.h index 6badd9e955..f6303f73f7 100644 --- a/modules/juce_gui_basics/mouse/juce_SelectedItemSet.h +++ b/modules/juce_gui_basics/mouse/juce_SelectedItemSet.h @@ -190,14 +190,10 @@ public: const ModifierKeys& modifiers) { if (isSelected (item)) - { return ! modifiers.isPopupMenu(); - } - else - { - addToSelectionBasedOnModifiers (item, modifiers); - return false; - } + + addToSelectionBasedOnModifiers (item, modifiers); + return false; } /** Selects or deselects items that can also be dragged, based on a mouse-up event. diff --git a/modules/juce_gui_basics/widgets/juce_Label.cpp b/modules/juce_gui_basics/widgets/juce_Label.cpp index 787fdf67f6..5995b97b37 100644 --- a/modules/juce_gui_basics/widgets/juce_Label.cpp +++ b/modules/juce_gui_basics/widgets/juce_Label.cpp @@ -144,8 +144,7 @@ Component* Label::getAttachedComponent() const return static_cast (ownerComponent); } -void Label::attachToComponent (Component* owner, - const bool onLeft) +void Label::attachToComponent (Component* owner, const bool onLeft) { if (ownerComponent != nullptr) ownerComponent->removeComponentListener (this); @@ -193,13 +192,10 @@ void Label::componentVisibilityChanged (Component& component) } //============================================================================== -void Label::textWasEdited() -{ -} - -void Label::textWasChanged() -{ -} +void Label::textWasEdited() {} +void Label::textWasChanged() {} +void Label::editorShown (TextEditor*) {} +void Label::editorAboutToBeHidden (TextEditor*) {} void Label::showEditor() { @@ -210,7 +206,6 @@ void Label::showEditor() editor->addListener (this); editor->grabKeyboardFocus(); editor->setHighlightedRegion (Range (0, textValue.toString().length())); - editor->addListener (this); resized(); repaint(); @@ -222,14 +217,6 @@ void Label::showEditor() } } -void Label::editorShown (TextEditor*) -{ -} - -void Label::editorAboutToBeHidden (TextEditor*) -{ -} - bool Label::updateFromTextEditorContents (TextEditor& ed) { const String newText (ed.getText());