diff --git a/examples/Demo/Source/Demos/LookAndFeelDemo.cpp b/examples/Demo/Source/Demos/LookAndFeelDemo.cpp index d12dc870d8..10438295b0 100644 --- a/examples/Demo/Source/Demos/LookAndFeelDemo.cpp +++ b/examples/Demo/Source/Demos/LookAndFeelDemo.cpp @@ -596,9 +596,8 @@ private: void setAllLookAndFeels (LookAndFeel* laf) { - for (int i = 0; i < demoComp.getNumChildComponents(); ++i) - if (Component* c = demoComp.getChildComponent (i)) - c->setLookAndFeel (laf); + for (auto* child : demoComp.getChildren()) + child->setLookAndFeel (laf); } void comboBoxChanged (ComboBox* comboBoxThatHasChanged) override diff --git a/examples/audio plugin host/Source/GraphEditorPanel.cpp b/examples/audio plugin host/Source/GraphEditorPanel.cpp index b13813d95f..18cdf6efb0 100644 --- a/examples/audio plugin host/Source/GraphEditorPanel.cpp +++ b/examples/audio plugin host/Source/GraphEditorPanel.cpp @@ -411,8 +411,8 @@ struct FilterComponent : public Component bool hitTest (int x, int y) override { - for (int i = getNumChildComponents(); --i >= 0;) - if (getChildComponent(i)->getBounds().contains (x, y)) + for (auto* child : getChildren()) + if (child->getBounds().contains (x, y)) return true; return x >= 3 && x < getWidth() - 6 && y >= pinSize && y < getHeight() - pinSize; @@ -440,9 +440,9 @@ struct FilterComponent : public Component { if (auto* processor = f->getProcessor()) { - for (int i = 0; i < getNumChildComponents(); ++i) + for (auto* child : getChildren()) { - if (auto* pin = dynamic_cast (getChildComponent(i))) + if (auto* pin = dynamic_cast (child)) { const bool isInput = pin->isInput; int busIdx = 0; @@ -465,8 +465,8 @@ struct FilterComponent : public Component Point getPinPos (int index, bool isInput) const { - for (int i = 0; i < getNumChildComponents(); ++i) - if (auto* pin = dynamic_cast (getChildComponent(i))) + for (auto* child : getChildren()) + if (auto* pin = dynamic_cast (child)) if (pin->index == index && isInput == pin->isInput) return getPosition().toFloat() + pin->getBounds().getCentre().toFloat(); @@ -804,21 +804,19 @@ void GraphEditorPanel::createNewPlugin (const PluginDescription& desc, Point= 0;) - { - if (auto* fc = dynamic_cast (getChildComponent (i))) + for (auto* child : getChildren()) + if (auto* fc = dynamic_cast (child)) if (fc->pluginID == filterID) return fc; - } return nullptr; } ConnectorComponent* GraphEditorPanel::getComponentForConnection (const AudioProcessorGraph::Connection& conn) const { - for (int i = getNumChildComponents(); --i >= 0;) + for (auto* child : getChildren()) { - if (auto* c = dynamic_cast (getChildComponent (i))) + if (auto* c = dynamic_cast (child)) if (c->sourceFilterID == conn.sourceNodeId && c->destFilterID == conn.destNodeId && c->sourceFilterChannel == conn.sourceChannelIndex @@ -831,8 +829,8 @@ ConnectorComponent* GraphEditorPanel::getComponentForConnection (const AudioProc PinComponent* GraphEditorPanel::findPinAt (Point pos) const { - for (int i = getNumChildComponents(); --i >= 0;) - if (auto* fc = dynamic_cast (getChildComponent (i))) + for (auto* child : getChildren()) + if (auto* fc = dynamic_cast (child)) if (auto* pin = dynamic_cast (fc->getComponentAt (pos.toInt() - fc->getPosition()))) return pin; @@ -851,11 +849,9 @@ void GraphEditorPanel::changeListenerCallback (ChangeBroadcaster*) void GraphEditorPanel::updateComponents() { - for (int i = getNumChildComponents(); --i >= 0;) - { - if (auto* fc = dynamic_cast (getChildComponent (i))) + for (auto* child : getChildren()) + if (auto* fc = dynamic_cast (child)) fc->update(); - } for (int i = getNumChildComponents(); --i >= 0;) { diff --git a/modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp b/modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp index 6bb1bc19bb..526d2bf52d 100644 --- a/modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp +++ b/modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp @@ -563,8 +563,8 @@ private: { int y = 0; - for (int i = getNumChildComponents(); --i >= 0;) - y = jmax (y, getChildComponent (i)->getBottom()); + for (auto* c : getChildren()) + y = jmax (y, c->getBottom()); return y; } diff --git a/modules/juce_gui_basics/buttons/juce_Button.cpp b/modules/juce_gui_basics/buttons/juce_Button.cpp index f93576df33..e8b7a28e36 100644 --- a/modules/juce_gui_basics/buttons/juce_Button.cpp +++ b/modules/juce_gui_basics/buttons/juce_Button.cpp @@ -242,19 +242,17 @@ void Button::setRadioGroupId (const int newGroupId, NotificationType notificatio void Button::turnOffOtherButtonsInGroup (const NotificationType notification) { - if (Component* const p = getParentComponent()) + if (auto* p = getParentComponent()) { if (radioGroupId != 0) { WeakReference deletionWatcher (this); - for (int i = p->getNumChildComponents(); --i >= 0;) + for (auto* c : p->getChildren()) { - Component* const c = p->getChildComponent (i); - if (c != this) { - if (Button* const b = dynamic_cast (c)) + if (auto b = dynamic_cast (c)) { if (b->getRadioGroupId() == radioGroupId) { diff --git a/modules/juce_gui_basics/components/juce_Component.cpp b/modules/juce_gui_basics/components/juce_Component.cpp index fc3622084e..67f292461a 100644 --- a/modules/juce_gui_basics/components/juce_Component.cpp +++ b/modules/juce_gui_basics/components/juce_Component.cpp @@ -406,7 +406,7 @@ struct Component::ComponentHelpers for (int i = comp.childComponentList.size(); --i >= 0;) { - const Component& child = *comp.childComponentList.getUnchecked(i); + auto& child = *comp.childComponentList.getUnchecked(i); if (child.isVisible() && ! child.isTransformed()) { @@ -421,7 +421,8 @@ struct Component::ComponentHelpers } else { - const Point childPos (child.getPosition()); + auto childPos = child.getPosition(); + if (clipObscuredRegions (child, g, newClip - childPos, childPos + delta)) wasClipped = true; } @@ -434,7 +435,7 @@ struct Component::ComponentHelpers static Rectangle getParentOrMainMonitorBounds (const Component& comp) { - if (Component* p = comp.getParentComponent()) + if (auto* p = comp.getParentComponent()) return p->getLocalBounds(); return Desktop::getInstance().getDisplays().getMainDisplay().userArea; @@ -442,31 +443,22 @@ struct Component::ComponentHelpers static void releaseAllCachedImageResources (Component& c) { - if (CachedComponentImage* cached = c.getCachedComponentImage()) + if (auto* cached = c.getCachedComponentImage()) cached->releaseResources(); - for (int i = c.getNumChildComponents(); --i >= 0;) - releaseAllCachedImageResources (*c.getChildComponent (i)); + for (auto* child : c.childComponentList) + releaseAllCachedImageResources (*child); } }; //============================================================================== Component::Component() noexcept - : parentComponent (nullptr), - lookAndFeel (nullptr), - effect (nullptr), - componentFlags (0), - componentTransparency (0) + : componentFlags (0) { } Component::Component (const String& name) noexcept - : componentName (name), - parentComponent (nullptr), - lookAndFeel (nullptr), - effect (nullptr), - componentFlags (0), - componentTransparency (0) + : componentName (name), componentFlags (0) { } @@ -895,11 +887,11 @@ void Component::toFront (const bool setAsForeground) } else if (parentComponent != nullptr) { - const Array& childList = parentComponent->childComponentList; + auto& childList = parentComponent->childComponentList; if (childList.getLast() != this) { - const int index = childList.indexOf (this); + auto index = childList.indexOf (this); if (index >= 0) { @@ -936,8 +928,8 @@ void Component::toBehind (Component* const other) if (parentComponent != nullptr) { - const Array& childList = parentComponent->childComponentList; - const int index = childList.indexOf (this); + auto& childList = parentComponent->childComponentList; + auto index = childList.indexOf (this); if (index >= 0 && childList [index + 1] != other) { @@ -977,11 +969,11 @@ void Component::toBack() } else if (parentComponent != nullptr) { - const Array& childList = parentComponent->childComponentList; + auto& childList = parentComponent->childComponentList; if (childList.getFirst() != this) { - const int index = childList.indexOf (this); + auto index = childList.indexOf (this); if (index > 0) { @@ -1380,7 +1372,7 @@ bool Component::hitTest (int x, int y) { for (int i = childComponentList.size(); --i >= 0;) { - Component& child = *childComponentList.getUnchecked (i); + auto& child = *childComponentList.getUnchecked (i); if (child.isVisible() && ComponentHelpers::hitTest (child, ComponentHelpers::convertFromParentSpace (child, Point (x, y)))) @@ -1437,7 +1429,8 @@ Component* Component::getComponentAt (Point position) { for (int i = childComponentList.size(); --i >= 0;) { - Component* child = childComponentList.getUnchecked(i); + auto* child = childComponentList.getUnchecked(i); + child = child->getComponentAt (ComponentHelpers::convertFromParentSpace (*child, position)); if (child != nullptr) @@ -1607,7 +1600,7 @@ int Component::getNumChildComponents() const noexcept Component* Component::getChildComponent (const int index) const noexcept { - return childComponentList [index]; + return childComponentList[index]; } int Component::getIndexOfChildComponent (const Component* const child) const noexcept @@ -1617,12 +1610,9 @@ int Component::getIndexOfChildComponent (const Component* const child) const noe Component* Component::findChildWithID (StringRef targetID) const noexcept { - for (int i = childComponentList.size(); --i >= 0;) - { - auto* c = childComponentList.getUnchecked(i); + for (auto* c : childComponentList) if (c->componentID == targetID) return c; - } return nullptr; } @@ -1979,7 +1969,7 @@ void Component::paintComponentAndChildren (Graphics& g) for (int i = 0; i < childComponentList.size(); ++i) { - Component& child = *childComponentList.getUnchecked (i); + auto& child = *childComponentList.getUnchecked (i); if (child.isVisible()) { @@ -2007,7 +1997,7 @@ void Component::paintComponentAndChildren (Graphics& g) for (int j = i + 1; j < childComponentList.size(); ++j) { - const Component& sibling = *childComponentList.getUnchecked (j); + auto& sibling = *childComponentList.getUnchecked (j); if (sibling.flags.opaqueFlag && sibling.isVisible() && sibling.affineTransform == nullptr) { diff --git a/modules/juce_gui_basics/components/juce_Component.h b/modules/juce_gui_basics/components/juce_Component.h index 6abe04d389..d482a0e69a 100644 --- a/modules/juce_gui_basics/components/juce_Component.h +++ b/modules/juce_gui_basics/components/juce_Component.h @@ -613,7 +613,7 @@ public: //============================================================================== /** Returns the number of child components that this component contains. - @see getChildComponent, getIndexOfChildComponent + @see getChildren, getChildComponent, getIndexOfChildComponent */ int getNumChildComponents() const noexcept; @@ -624,7 +624,7 @@ public: If the index is out-of-range, this will return a null pointer. - @see getNumChildComponents, getIndexOfChildComponent + @see getChildren, getNumChildComponents, getIndexOfChildComponent */ Component* getChildComponent (int index) const noexcept; @@ -635,10 +635,15 @@ public: Returns -1 if the component passed-in is not a child of this component. - @see getNumChildComponents, getChildComponent, addChildComponent, toFront, toBack, toBehind + @see getChildren, getNumChildComponents, getChildComponent, addChildComponent, toFront, toBack, toBehind */ int getIndexOfChildComponent (const Component* child) const noexcept; + /** Provides access to the underlying array of child components. + The most likely reason you may want to use this is for iteration in a range-based for loop. + */ + const Array& getChildren() const noexcept { return childComponentList; } + /** Looks for a child component with the specified ID. @see setComponentID, getComponentID */ @@ -2251,14 +2256,14 @@ private: //============================================================================== String componentName, componentID; - Component* parentComponent; + Component* parentComponent = nullptr; Rectangle boundsRelativeToParent; ScopedPointer positioner; ScopedPointer affineTransform; Array childComponentList; - LookAndFeel* lookAndFeel; + LookAndFeel* lookAndFeel = nullptr; MouseCursor cursor; - ImageEffectFilter* effect; + ImageEffectFilter* effect = nullptr; ScopedPointer cachedImage; class MouseListenerList; @@ -2304,7 +2309,7 @@ private: ComponentFlags flags; }; - uint8 componentTransparency; + uint8 componentTransparency = 0; //============================================================================== void internalMouseEnter (MouseInputSource, Point, Time); diff --git a/modules/juce_gui_basics/drawables/juce_Drawable.cpp b/modules/juce_gui_basics/drawables/juce_Drawable.cpp index fcec458993..3bd5833e44 100644 --- a/modules/juce_gui_basics/drawables/juce_Drawable.cpp +++ b/modules/juce_gui_basics/drawables/juce_Drawable.cpp @@ -140,8 +140,8 @@ bool Drawable::replaceColour (Colour original, Colour replacement) { bool changed = false; - for (int i = getNumChildComponents(); --i >= 0;) - if (auto* d = dynamic_cast (getChildComponent(i))) + for (auto* c : getChildren()) + if (auto* d = dynamic_cast (c)) changed = d->replaceColour (original, replacement) || changed; return changed; diff --git a/modules/juce_gui_basics/drawables/juce_DrawableComposite.cpp b/modules/juce_gui_basics/drawables/juce_DrawableComposite.cpp index 2dfa0fec22..b406400af8 100644 --- a/modules/juce_gui_basics/drawables/juce_DrawableComposite.cpp +++ b/modules/juce_gui_basics/drawables/juce_DrawableComposite.cpp @@ -25,8 +25,7 @@ */ DrawableComposite::DrawableComposite() - : bounds (Point(), Point (100.0f, 0.0f), Point (0.0f, 100.0f)), - updateBoundsReentrant (false) + : bounds (Point(), Point (100.0f, 0.0f), Point (0.0f, 100.0f)) { setContentArea (RelativeRectangle (Rectangle (0.0f, 0.0f, 100.0f, 100.0f))); } @@ -35,11 +34,10 @@ DrawableComposite::DrawableComposite (const DrawableComposite& other) : Drawable (other), bounds (other.bounds), markersX (other.markersX), - markersY (other.markersY), - updateBoundsReentrant (false) + markersY (other.markersY) { - for (int i = 0; i < other.getNumChildComponents(); ++i) - if (const Drawable* const d = dynamic_cast (other.getChildComponent(i))) + for (auto* c : other.getChildren()) + if (auto* d = dynamic_cast (c)) addAndMakeVisible (d->createCopy()); } @@ -58,8 +56,8 @@ Rectangle DrawableComposite::getDrawableBounds() const { Rectangle r; - for (int i = getNumChildComponents(); --i >= 0;) - if (const Drawable* const d = dynamic_cast (getChildComponent(i))) + for (auto* c : getChildren()) + if (auto* d = dynamic_cast (c)) r = r.getUnion (d->isTransformed() ? d->getDrawableBounds().transformedBy (d->getTransform()) : d->getDrawableBounds()); @@ -96,7 +94,7 @@ void DrawableComposite::setBoundingBox (const RelativeParallelogram& newBounds) if (bounds.isDynamic()) { - Drawable::Positioner* const p = new Drawable::Positioner (*this); + auto p = new Drawable::Positioner (*this); setPositioner (p); p->apply(); } @@ -135,11 +133,11 @@ void DrawableComposite::recalculateCoordinates (Expression::Scope* scope) Point resolved[3]; bounds.resolveThreePoints (resolved, scope); - const Rectangle content (getContentArea().resolve (scope)); + auto content = getContentArea().resolve (scope); - AffineTransform t (AffineTransform::fromTargetPoints (content.getX(), content.getY(), resolved[0].x, resolved[0].y, - content.getRight(), content.getY(), resolved[1].x, resolved[1].y, - content.getX(), content.getBottom(), resolved[2].x, resolved[2].y)); + auto t = AffineTransform::fromTargetPoints (content.getX(), content.getY(), resolved[0].x, resolved[0].y, + content.getRight(), content.getY(), resolved[1].x, resolved[1].y, + content.getX(), content.getBottom(), resolved[2].x, resolved[2].y); if (t.isSingularity()) t = AffineTransform(); @@ -149,8 +147,7 @@ void DrawableComposite::recalculateCoordinates (Expression::Scope* scope) void DrawableComposite::parentHierarchyChanged() { - DrawableComposite* parent = getParent(); - if (parent != nullptr) + if (auto* parent = getParent()) originRelativeToComponent = parent->originRelativeToComponent - getPosition(); } @@ -172,10 +169,10 @@ void DrawableComposite::updateBoundsToFitChildren() Rectangle childArea; - for (int i = getNumChildComponents(); --i >= 0;) - childArea = childArea.getUnion (getChildComponent(i)->getBoundsInParent()); + for (auto* c : getChildren()) + childArea = childArea.getUnion (c->getBoundsInParent()); - const Point delta (childArea.getPosition()); + auto delta = childArea.getPosition(); childArea += getPosition(); if (childArea != getBounds()) @@ -184,9 +181,8 @@ void DrawableComposite::updateBoundsToFitChildren() { originRelativeToComponent -= delta; - for (int i = getNumChildComponents(); --i >= 0;) - if (Component* const c = getChildComponent(i)) - c->setBounds (c->getBounds() - delta); + for (auto* c : getChildren()) + c->setBounds (c->getBounds() - delta); } setBounds (childArea); @@ -306,9 +302,9 @@ ValueTree DrawableComposite::createValueTree (ComponentBuilder::ImageProvider* i ValueTree childList (v.getChildListCreating (nullptr)); - for (int i = 0; i < getNumChildComponents(); ++i) + for (auto* c : getChildren()) { - const Drawable* const d = dynamic_cast (getChildComponent(i)); + auto* d = dynamic_cast (c); jassert (d != nullptr); // You can't save a mix of Drawables and normal components! childList.addChild (d->createValueTree (imageProvider), -1, nullptr); @@ -324,11 +320,10 @@ Path DrawableComposite::getOutlineAsPath() const { Path p; - for (int i = 0; i < getNumChildComponents(); ++i) - if (auto* childDrawable = dynamic_cast (getChildComponent (i))) - p.addPath (childDrawable->getOutlineAsPath()); + for (auto* c : getChildren()) + if (auto* d = dynamic_cast (c)) + p.addPath (d->getOutlineAsPath()); p.applyTransform (getTransform()); - return p; } diff --git a/modules/juce_gui_basics/drawables/juce_DrawableComposite.h b/modules/juce_gui_basics/drawables/juce_DrawableComposite.h index a11ae87777..00217e4f9c 100644 --- a/modules/juce_gui_basics/drawables/juce_DrawableComposite.h +++ b/modules/juce_gui_basics/drawables/juce_DrawableComposite.h @@ -148,7 +148,7 @@ private: //============================================================================== RelativeParallelogram bounds; MarkerList markersX, markersY; - bool updateBoundsReentrant; + bool updateBoundsReentrant = false; friend class Drawable::Positioner; bool registerCoordinates (RelativeCoordinatePositionerBase&); diff --git a/modules/juce_gui_basics/keyboard/juce_KeyboardFocusTraverser.cpp b/modules/juce_gui_basics/keyboard/juce_KeyboardFocusTraverser.cpp index 48927c83c9..13afbd4027 100644 --- a/modules/juce_gui_basics/keyboard/juce_KeyboardFocusTraverser.cpp +++ b/modules/juce_gui_basics/keyboard/juce_KeyboardFocusTraverser.cpp @@ -30,46 +30,40 @@ namespace KeyboardFocusHelpers // left-to-right and then top-to-bottom. struct ScreenPositionComparator { - static int compareElements (const Component* const first, const Component* const second) + static int compareElements (const Component* first, const Component* second) { - const int explicitOrder1 = getOrder (first); - const int explicitOrder2 = getOrder (second); + auto explicitOrder1 = getOrder (first); + auto explicitOrder2 = getOrder (second); if (explicitOrder1 != explicitOrder2) return explicitOrder1 - explicitOrder2; - const int yDiff = first->getY() - second->getY(); + auto yDiff = first->getY() - second->getY(); return yDiff == 0 ? first->getX() - second->getX() : yDiff; } - static int getOrder (const Component* const c) + static int getOrder (const Component* c) { - const int order = c->getExplicitFocusOrder(); + auto order = c->getExplicitFocusOrder(); return order > 0 ? order : (std::numeric_limits::max() / 2); } }; - static void findAllFocusableComponents (Component* const parent, Array & comps) + static void findAllFocusableComponents (Component* parent, Array& comps) { - if (parent->getNumChildComponents() > 0) + if (parent->getNumChildComponents() != 0) { - Array localComps; + Array localComps; ScreenPositionComparator comparator; - for (int i = parent->getNumChildComponents(); --i >= 0;) - { - Component* const c = parent->getChildComponent (i); - + for (auto* c : parent->getChildren()) if (c->isVisible() && c->isEnabled()) localComps.addSorted (comparator, c); - } - for (int i = 0; i < localComps.size(); ++i) + for (auto* c : localComps) { - Component* const c = localComps.getUnchecked (i); - if (c->getWantsKeyboardFocus()) comps.add (c); @@ -90,18 +84,16 @@ namespace KeyboardFocusHelpers return c; } - static Component* getIncrementedComponent (Component* const current, const int delta) + static Component* getIncrementedComponent (Component* current, int delta) { - Component* focusContainer = findFocusContainer (current); - - if (focusContainer != nullptr) + if (auto* focusContainer = findFocusContainer (current)) { - Array comps; + Array comps; KeyboardFocusHelpers::findAllFocusableComponents (focusContainer, comps); - if (comps.size() > 0) + if (! comps.isEmpty()) { - const int index = comps.indexOf (current); + auto index = comps.indexOf (current); return comps [(index + comps.size() + delta) % comps.size()]; } } @@ -128,7 +120,7 @@ Component* KeyboardFocusTraverser::getPreviousComponent (Component* current) Component* KeyboardFocusTraverser::getDefaultComponent (Component* parentComponent) { - Array comps; + Array comps; if (parentComponent != nullptr) KeyboardFocusHelpers::findAllFocusableComponents (parentComponent, comps); diff --git a/modules/juce_gui_basics/layout/juce_ComponentBuilder.cpp b/modules/juce_gui_basics/layout/juce_ComponentBuilder.cpp index 99764e99f4..bd5b6c52db 100644 --- a/modules/juce_gui_basics/layout/juce_ComponentBuilder.cpp +++ b/modules/juce_gui_basics/layout/juce_ComponentBuilder.cpp @@ -52,9 +52,9 @@ namespace ComponentBuilderHelpers if (c.getComponentID() == compId) return &c; - for (int i = c.getNumChildComponents(); --i >= 0;) - if (Component* const child = findComponentWithID (*c.getChildComponent (i), compId)) - return child; + for (auto* child : c.getChildren()) + if (auto* found = findComponentWithID (*child, compId)) + return found; return nullptr; } @@ -238,7 +238,7 @@ void ComponentBuilder::updateChildComponents (Component& parent, const ValueTree { using namespace ComponentBuilderHelpers; - const int numExistingChildComps = parent.getNumChildComponents(); + auto numExistingChildComps = parent.getNumChildComponents(); Array componentsInOrder; componentsInOrder.ensureStorageAllocated (numExistingChildComps); @@ -250,15 +250,16 @@ void ComponentBuilder::updateChildComponents (Component& parent, const ValueTree for (int i = 0; i < numExistingChildComps; ++i) existingComponents.add (parent.getChildComponent (i)); - const int newNumChildren = children.getNumChildren(); + auto newNumChildren = children.getNumChildren(); + for (int i = 0; i < newNumChildren; ++i) { - const ValueTree childState (children.getChild (i)); - Component* c = removeComponentWithID (existingComponents, getStateId (childState)); + auto childState = children.getChild (i); + auto* c = removeComponentWithID (existingComponents, getStateId (childState)); if (c == nullptr) { - if (TypeHandler* const type = getHandlerForState (childState)) + if (auto* type = getHandlerForState (childState)) c = ComponentBuilderHelpers::createNewComponent (*type, childState, &parent); else jassertfalse; diff --git a/modules/juce_gui_basics/layout/juce_MultiDocumentPanel.cpp b/modules/juce_gui_basics/layout/juce_MultiDocumentPanel.cpp index 57f607c10d..65c7454200 100644 --- a/modules/juce_gui_basics/layout/juce_MultiDocumentPanel.cpp +++ b/modules/juce_gui_basics/layout/juce_MultiDocumentPanel.cpp @@ -143,7 +143,7 @@ void MultiDocumentPanel::addWindow (Component* component) int x = 4; - if (Component* const topComp = getChildComponent (getNumChildComponents() - 1)) + if (auto* topComp = getChildren().getLast()) if (topComp->getX() == x && topComp->getY() == x) x += 16; @@ -200,7 +200,7 @@ bool MultiDocumentPanel::addDocument (Component* const component, { addAndMakeVisible (tabComponent = new TabbedComponentInternal()); - Array temp (components); + Array temp (components); for (int i = 0; i < temp.size(); ++i) tabComponent->addTab (temp[i]->getName(), docColour, temp[i], false); @@ -239,9 +239,9 @@ bool MultiDocumentPanel::closeDocument (Component* component, if (mode == FloatingWindows) { - for (int i = getNumChildComponents(); --i >= 0;) + for (auto* child : getChildren()) { - if (MultiDocumentPanelWindow* const dw = dynamic_cast (getChildComponent (i))) + if (auto* dw = dynamic_cast (child)) { if (dw->getContentComponent() == component) { @@ -326,8 +326,8 @@ Component* MultiDocumentPanel::getActiveDocument() const noexcept { if (mode == FloatingWindows) { - for (int i = getNumChildComponents(); --i >= 0;) - if (MultiDocumentPanelWindow* const dw = dynamic_cast (getChildComponent (i))) + for (auto* child : getChildren()) + if (auto* dw = dynamic_cast (child)) if (dw->isActiveWindow()) return dw->getContentComponent(); } @@ -411,7 +411,7 @@ void MultiDocumentPanel::setLayoutMode (const LayoutMode newLayoutMode) resized(); - const Array tempComps (components); + const Array tempComps (components); components.clear(); for (int i = 0; i < tempComps.size(); ++i) @@ -445,8 +445,8 @@ void MultiDocumentPanel::resized() { if (mode == MaximisedWindowsWithTabs || components.size() == numDocsBeforeTabsUsed) { - for (int i = getNumChildComponents(); --i >= 0;) - getChildComponent (i)->setBounds (getLocalBounds()); + for (auto* child : getChildren()) + child->setBounds (getLocalBounds()); } setWantsKeyboardFocus (components.size() == 0); @@ -456,8 +456,8 @@ Component* MultiDocumentPanel::getContainerComp (Component* c) const { if (mode == FloatingWindows) { - for (int i = 0; i < getNumChildComponents(); ++i) - if (MultiDocumentPanelWindow* const dw = dynamic_cast (getChildComponent (i))) + for (auto* child : getChildren()) + if (auto* dw = dynamic_cast (child)) if (dw->getContentComponent() == c) return dw; } @@ -469,8 +469,8 @@ void MultiDocumentPanel::componentNameChanged (Component&) { if (mode == FloatingWindows) { - for (int i = 0; i < getNumChildComponents(); ++i) - if (MultiDocumentPanelWindow* const dw = dynamic_cast (getChildComponent (i))) + for (auto* child : getChildren()) + if (auto* dw = dynamic_cast (child)) dw->setName (dw->getContentComponent()->getName()); } else if (tabComponent != nullptr) @@ -482,21 +482,21 @@ void MultiDocumentPanel::componentNameChanged (Component&) void MultiDocumentPanel::updateOrder() { - const Array oldList (components); + auto oldList = components; if (mode == FloatingWindows) { components.clear(); - for (int i = 0; i < getNumChildComponents(); ++i) - if (MultiDocumentPanelWindow* const dw = dynamic_cast (getChildComponent (i))) + for (auto* child : getChildren()) + if (auto* dw = dynamic_cast (child)) components.add (dw->getContentComponent()); } else { if (tabComponent != nullptr) { - if (Component* const current = tabComponent->getCurrentContentComponent()) + if (auto* current = tabComponent->getCurrentContentComponent()) { components.removeFirstMatchingValue (current); components.add (current); diff --git a/modules/juce_gui_basics/layout/juce_TabbedButtonBar.cpp b/modules/juce_gui_basics/layout/juce_TabbedButtonBar.cpp index d6a2b857aa..3f9b05752a 100644 --- a/modules/juce_gui_basics/layout/juce_TabbedButtonBar.cpp +++ b/modules/juce_gui_basics/layout/juce_TabbedButtonBar.cpp @@ -221,8 +221,8 @@ void TabbedButtonBar::setOrientation (const Orientation newOrientation) { orientation = newOrientation; - for (int i = getNumChildComponents(); --i >= 0;) - getChildComponent (i)->resized(); + for (auto* child : getChildren()) + child->resized(); resized(); } diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V4.cpp b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V4.cpp index 7c6bba5c27..71fe70988d 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V4.cpp +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V4.cpp @@ -378,9 +378,9 @@ AlertWindow* LookAndFeel_V4::createAlertWindow (const String& title, const Strin bounds = bounds.withSizeKeepingCentre (bounds.getWidth() + boundsOffset, bounds.getHeight() + boundsOffset); aw->setBounds (bounds); - for (int i = 0, maxI = aw->getNumChildComponents(); i < maxI; ++i) - if (auto button = dynamic_cast (aw->getChildComponent(i))) - button->setBounds (button->getBounds().withPosition (button->getX() + 25, button->getY() + 40)); + for (auto* child : aw->getChildren()) + if (auto button = dynamic_cast (child)) + button->setBounds (button->getBounds() + Point (25, 40)); return aw; } diff --git a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm index a8c426d66b..492bea9b1a 100644 --- a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm @@ -61,7 +61,7 @@ static NSRect flippedScreenRect (NSRect r) noexcept } #if JUCE_MODULE_AVAILABLE_juce_opengl -void componentPeerAboutToChange (ComponentPeer&, bool); +void componentPeerAboutToChange (Component&, bool); #endif //============================================================================== @@ -672,7 +672,7 @@ public: { #if JUCE_MODULE_AVAILABLE_juce_opengl if ([view window] == window) - componentPeerAboutToChange (*this, (newWindow == nullptr)); + componentPeerAboutToChange (getComponent(), newWindow == nullptr); #else ignoreUnused (newWindow); #endif diff --git a/modules/juce_gui_basics/widgets/juce_Toolbar.cpp b/modules/juce_gui_basics/widgets/juce_Toolbar.cpp index 6aaa4c383a..a2bab5484b 100644 --- a/modules/juce_gui_basics/widgets/juce_Toolbar.cpp +++ b/modules/juce_gui_basics/widgets/juce_Toolbar.cpp @@ -177,7 +177,7 @@ public: { for (int i = 0; i < getNumChildComponents(); ++i) { - if (ToolbarItemComponent* const tc = dynamic_cast (getChildComponent (i))) + if (auto* tc = dynamic_cast (getChildComponent (i))) { tc->setVisible (false); const int index = oldIndexes.removeAndReturn (i); @@ -197,9 +197,9 @@ public: int y = indent; int maxX = 0; - for (int i = 0; i < getNumChildComponents(); ++i) + for (auto* c : getChildren()) { - if (ToolbarItemComponent* const tc = dynamic_cast (getChildComponent (i))) + if (auto* tc = dynamic_cast (c)) { int preferredSize = 1, minSize = 1, maxSize = 1; diff --git a/modules/juce_gui_extra/misc/juce_KeyMappingEditorComponent.cpp b/modules/juce_gui_extra/misc/juce_KeyMappingEditorComponent.cpp index ef5b2fb683..88ee4a8e36 100644 --- a/modules/juce_gui_extra/misc/juce_KeyMappingEditorComponent.cpp +++ b/modules/juce_gui_extra/misc/juce_KeyMappingEditorComponent.cpp @@ -101,8 +101,8 @@ public: addButton (TRANS("Cancel"), 0); // (avoid return + escape keys getting processed by the buttons..) - for (int i = getNumChildComponents(); --i >= 0;) - getChildComponent (i)->setWantsKeyboardFocus (false); + for (auto* child : getChildren()) + child->setWantsKeyboardFocus (false); setWantsKeyboardFocus (true); grabKeyboardFocus(); @@ -113,7 +113,7 @@ public: lastPress = key; String message (TRANS("Key") + ": " + owner.getDescriptionForKeyPress (key)); - const CommandID previousCommand = owner.getMappings().findCommandForKeyPress (key); + auto previousCommand = owner.getMappings().findCommandForKeyPress (key); if (previousCommand != 0) message << "\n\n(" @@ -148,7 +148,7 @@ public: { if (newKey.isValid()) { - const CommandID previousCommand = owner.getMappings().findCommandForKeyPress (newKey); + auto previousCommand = owner.getMappings().findCommandForKeyPress (newKey); if (previousCommand == 0 || dontAskUser) { @@ -209,14 +209,14 @@ private: class KeyMappingEditorComponent::ItemComponent : public Component { public: - ItemComponent (KeyMappingEditorComponent& kec, const CommandID command) + ItemComponent (KeyMappingEditorComponent& kec, CommandID command) : owner (kec), commandID (command) { setInterceptsMouseClicks (false, true); const bool isReadOnly = owner.isCommandReadOnly (commandID); - const Array keyPresses (owner.getMappings().getKeyPressesAssignedToCommand (commandID)); + auto keyPresses = owner.getMappings().getKeyPressesAssignedToCommand (commandID); for (int i = 0; i < jmin ((int) maxNumAssignments, keyPresses.size()); ++i) addKeyPressButton (owner.getDescriptionForKeyPress (keyPresses.getReference (i)), i, isReadOnly); @@ -226,7 +226,7 @@ public: void addKeyPressButton (const String& desc, const int index, const bool isReadOnly) { - ChangeKeyButton* const b = new ChangeKeyButton (owner, commandID, desc, index); + auto* b = new ChangeKeyButton (owner, commandID, desc, index); keyChangeButtons.add (b); b->setEnabled (! isReadOnly); @@ -250,7 +250,7 @@ public: for (int i = keyChangeButtons.size(); --i >= 0;) { - ChangeKeyButton* const b = keyChangeButtons.getUnchecked(i); + auto* b = keyChangeButtons.getUnchecked(i); b->fitToContent (getHeight() - 2); b->setTopRightPosition (x, 1); @@ -272,7 +272,7 @@ private: class KeyMappingEditorComponent::MappingItem : public TreeViewItem { public: - MappingItem (KeyMappingEditorComponent& kec, const CommandID command) + MappingItem (KeyMappingEditorComponent& kec, CommandID command) : owner (kec), commandID (command) {} @@ -314,13 +314,9 @@ public: if (isNowOpen) { if (getNumSubItems() == 0) - { - const Array commands (owner.getCommandManager().getCommandsInCategory (categoryName)); - - for (int i = 0; i < commands.size(); ++i) - if (owner.shouldCommandBeIncluded (commands.getUnchecked(i))) - addSubItem (new MappingItem (owner, commands.getUnchecked(i))); - } + for (auto command : owner.getCommandManager().getCommandsInCategory (categoryName)) + if (owner.shouldCommandBeIncluded (command)) + addSubItem (new MappingItem (owner, command)); } else { @@ -360,19 +356,16 @@ public: const OpennessRestorer opennessRestorer (*this); clearSubItems(); - const StringArray categories (owner.getCommandManager().getCommandCategories()); - - for (int i = 0; i < categories.size(); ++i) + for (auto category : owner.getCommandManager().getCommandCategories()) { - const Array commands (owner.getCommandManager().getCommandsInCategory (categories[i])); int count = 0; - for (int j = 0; j < commands.size(); ++j) - if (owner.shouldCommandBeIncluded (commands.getUnchecked(j))) + for (auto command : owner.getCommandManager().getCommandsInCategory (category)) + if (owner.shouldCommandBeIncluded (command)) ++count; if (count > 0) - addSubItem (new CategoryItem (owner, categories[i])); + addSubItem (new CategoryItem (owner, category)); } } @@ -459,14 +452,14 @@ void KeyMappingEditorComponent::resized() //============================================================================== bool KeyMappingEditorComponent::shouldCommandBeIncluded (const CommandID commandID) { - const ApplicationCommandInfo* const ci = mappings.getCommandManager().getCommandForID (commandID); + auto* ci = mappings.getCommandManager().getCommandForID (commandID); return ci != nullptr && (ci->flags & ApplicationCommandInfo::hiddenFromKeyEditor) == 0; } bool KeyMappingEditorComponent::isCommandReadOnly (const CommandID commandID) { - const ApplicationCommandInfo* const ci = mappings.getCommandManager().getCommandForID (commandID); + auto* ci = mappings.getCommandManager().getCommandForID (commandID); return ci != nullptr && (ci->flags & ApplicationCommandInfo::readOnlyInKeyEditor) != 0; } diff --git a/modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp b/modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp index f0fda61407..e87c817d98 100644 --- a/modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp +++ b/modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp @@ -53,13 +53,13 @@ private: Array alreadyDone; for (int i = TopLevelWindow::getNumTopLevelWindows(); --i >= 0;) - if (Component* c = TopLevelWindow::getTopLevelWindow(i)) + if (auto* c = TopLevelWindow::getTopLevelWindow(i)) repaintAndResizeAllComps (c, alreadyDone); - Desktop& desktop = Desktop::getInstance(); + auto& desktop = Desktop::getInstance(); for (int i = desktop.getNumComponents(); --i >= 0;) - if (Component* c = desktop.getComponent(i)) + if (auto* c = desktop.getComponent(i)) repaintAndResizeAllComps (c, alreadyDone); } @@ -73,7 +73,7 @@ private: for (int i = c->getNumChildComponents(); --i >= 0;) { - if (Component* child = c->getChildComponent(i)) + if (auto* child = c->getChildComponent(i)) { repaintAndResizeAllComps (child, alreadyDone); alreadyDone.add (child); @@ -124,7 +124,7 @@ LiveValueBase::~LiveValueBase() //============================================================================== LivePropertyEditorBase::LivePropertyEditorBase (LiveValueBase& v, CodeDocument& d) - : value (v), resetButton ("reset"), document (d), sourceEditor (document, &tokeniser), wasHex (false) + : value (v), document (d), sourceEditor (document, &tokeniser) { setSize (600, 100); @@ -155,11 +155,11 @@ void LivePropertyEditorBase::paint (Graphics& g) void LivePropertyEditorBase::resized() { - Rectangle r (getLocalBounds().reduced (0, 3).withTrimmedBottom (1)); + auto r = getLocalBounds().reduced (0, 3).withTrimmedBottom (1); - Rectangle left (r.removeFromLeft (jmax (200, r.getWidth() / 3))); + auto left = r.removeFromLeft (jmax (200, r.getWidth() / 3)); - Rectangle top (left.removeFromTop (25)); + auto top = left.removeFromTop (25); resetButton.setBounds (top.removeFromRight (35).reduced (0, 3)); name.setBounds (top); @@ -208,8 +208,8 @@ void LivePropertyEditorBase::selectOriginalValue() void LivePropertyEditorBase::findOriginalValueInCode() { CodeDocument::Position pos (document, value.sourceLine, 0); - String line (pos.getLineText()); - String::CharPointerType p (line.getCharPointer()); + auto line = pos.getLineText(); + auto p = line.getCharPointer(); p = CharacterFunctions::find (p, CharPointer_ASCII ("JUCE_LIVE_CONSTANT")); @@ -233,13 +233,13 @@ void LivePropertyEditorBase::findOriginalValueInCode() if (p.getAndAdvance() == '(') { - String::CharPointerType start (p), end (p); + auto start = p, end = p; int depth = 1; while (! end.isEmpty()) { - const juce_wchar c = end.getAndAdvance(); + auto c = end.getAndAdvance(); if (c == '(') ++depth; if (c == ')') --depth; @@ -328,11 +328,11 @@ public: void updateItems (ValueList& list) { - if (ValueListHolderComponent* l = dynamic_cast (viewport.getViewedComponent())) + if (auto* l = dynamic_cast (viewport.getViewedComponent())) { while (l->getNumChildComponents() < list.values.size()) { - if (LiveValueBase* v = list.values [l->getNumChildComponents()]) + if (auto* v = list.values [l->getNumChildComponents()]) l->addItem (viewport.getMaximumVisibleWidth(), *v, list.getDocument (v->sourceFile)); else break; @@ -346,7 +346,7 @@ public: { DocumentWindow::resized(); - if (ValueListHolderComponent* l = dynamic_cast (viewport.getViewedComponent())) + if (auto* l = dynamic_cast (viewport.getViewedComponent())) l->layout (viewport.getMaximumVisibleWidth()); } @@ -379,7 +379,7 @@ CodeDocument& ValueList::getDocument (const File& file) if (index >= 0) return *documents.getUnchecked (index); - CodeDocument* doc = documents.add (new CodeDocument()); + auto* doc = documents.add (new CodeDocument()); documentFiles.add (file); doc->replaceAllContent (file.loadFileAsString()); doc->clearUndoHistory(); @@ -409,7 +409,7 @@ struct ColourEditorComp : public Component, void mouseDown (const MouseEvent&) override { - ColourSelector* colourSelector = new ColourSelector(); + auto* colourSelector = new ColourSelector(); colourSelector->setName ("Colour"); colourSelector->setCurrentColour (getColour()); colourSelector->addChangeListener (this); @@ -421,7 +421,7 @@ struct ColourEditorComp : public Component, void changeListenerCallback (ChangeBroadcaster* source) override { - if (ColourSelector* cs = dynamic_cast (source)) + if (auto* cs = dynamic_cast (source)) editor.applyNewValue (getAsString (cs->getCurrentColour(), true)); repaint(); @@ -493,9 +493,9 @@ struct BoolSliderComp : public SliderComp void sliderValueChanged (Slider*) override { editor.applyNewValue (slider.getValue() > 0.5 ? "true" : "false"); } }; -Component* createIntegerSlider (LivePropertyEditorBase& editor) { return new SliderComp (editor, false); } -Component* createFloatSlider (LivePropertyEditorBase& editor) { return new SliderComp (editor, true); } -Component* createBoolSlider (LivePropertyEditorBase& editor) { return new BoolSliderComp (editor); } +Component* createIntegerSlider (LivePropertyEditorBase& editor) { return new SliderComp (editor, false); } +Component* createFloatSlider (LivePropertyEditorBase& editor) { return new SliderComp (editor, true); } +Component* createBoolSlider (LivePropertyEditorBase& editor) { return new BoolSliderComp (editor); } } diff --git a/modules/juce_gui_extra/misc/juce_LiveConstantEditor.h b/modules/juce_gui_extra/misc/juce_LiveConstantEditor.h index 10be7df96c..c4281b5b07 100644 --- a/modules/juce_gui_extra/misc/juce_LiveConstantEditor.h +++ b/modules/juce_gui_extra/misc/juce_LiveConstantEditor.h @@ -123,13 +123,13 @@ namespace LiveConstantEditor LiveValueBase& value; Label name; TextEditor valueEditor; - TextButton resetButton; + TextButton resetButton { "reset" }; CodeDocument& document; CPlusPlusCodeTokeniser tokeniser; CodeEditorComponent sourceEditor; CodeDocument::Position valueStart, valueEnd; ScopedPointer customComp; - bool wasHex; + bool wasHex = false; JUCE_DECLARE_NON_COPYABLE (LivePropertyEditorBase) }; diff --git a/modules/juce_opengl/native/juce_OpenGL_osx.h b/modules/juce_opengl/native/juce_OpenGL_osx.h index dbbcbc0ea2..706486ebe5 100644 --- a/modules/juce_opengl/native/juce_OpenGL_osx.h +++ b/modules/juce_opengl/native/juce_OpenGL_osx.h @@ -247,21 +247,11 @@ bool OpenGLHelpers::isContextActive() } //============================================================================== -void componentPeerAboutToChange (ComponentPeer& peer, bool shouldSuspend) +void componentPeerAboutToChange (Component& comp, bool shouldSuspend) { - Array stack; - stack.add (&peer.getComponent()); + if (auto* context = OpenGLContext::getContextAttachedTo (comp)) + context->overrideCanBeAttached (shouldSuspend); - while (stack.size() != 0) - { - Component& comp = *stack.removeAndReturn (0); - - const int n = comp.getNumChildComponents(); - for (int i = 0; i < n; ++i) - if (Component* child = comp.getChildComponent (i)) - stack.add (child); - - if (OpenGLContext* context = OpenGLContext::getContextAttachedTo (comp)) - context->overrideCanBeAttached (shouldSuspend); - } + for (auto* child : comp.getChildren()) + componentPeerAboutToChange (*child, shouldSuspend); } diff --git a/modules/juce_opengl/opengl/juce_OpenGLContext.h b/modules/juce_opengl/opengl/juce_OpenGLContext.h index 7c444d1398..fe6627d35e 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLContext.h +++ b/modules/juce_opengl/opengl/juce_OpenGLContext.h @@ -322,14 +322,14 @@ private: struct AsyncWorkerFunctor : AsyncWorker { AsyncWorkerFunctor (T functorToUse) : functor (functorToUse) {} - void operator() (OpenGLContext& callerContext) override { functor (callerContext); } + void operator() (OpenGLContext& callerContext) override { functor (callerContext); } T functor; - JUCE_DECLARE_NON_COPYABLE(AsyncWorkerFunctor) + JUCE_DECLARE_NON_COPYABLE (AsyncWorkerFunctor) }; //============================================================================== - friend void componentPeerAboutToChange (ComponentPeer&, bool); + friend void componentPeerAboutToChange (Component&, bool); void overrideCanBeAttached (bool); //==============================================================================