diff --git a/modules/juce_core/containers/juce_Variant.cpp b/modules/juce_core/containers/juce_Variant.cpp index da0ada9291..6ecc85144a 100644 --- a/modules/juce_core/containers/juce_Variant.cpp +++ b/modules/juce_core/containers/juce_Variant.cpp @@ -454,8 +454,10 @@ bool operator!= (const var& v1, const char* const v2) { return v1.toString //============================================================================== var var::operator[] (const Identifier& propertyName) const { - DynamicObject* const o = getDynamicObject(); - return o != nullptr ? o->getProperty (propertyName) : var::null; + if (DynamicObject* const o = getDynamicObject()) + return o->getProperty (propertyName); + + return var::null; } var var::operator[] (const char* const propertyName) const @@ -465,14 +467,18 @@ var var::operator[] (const char* const propertyName) const var var::getProperty (const Identifier& propertyName, const var& defaultReturnValue) const { - DynamicObject* const o = getDynamicObject(); - return o != nullptr ? o->getProperties().getWithDefault (propertyName, defaultReturnValue) : defaultReturnValue; + if (DynamicObject* const o = getDynamicObject()) + return o->getProperties().getWithDefault (propertyName, defaultReturnValue); + + return defaultReturnValue; } var var::invoke (const Identifier& method, const var* arguments, int numArguments) const { - DynamicObject* const o = getDynamicObject(); - return o != nullptr ? o->invokeMethod (method, arguments, numArguments) : var::null; + if (DynamicObject* const o = getDynamicObject()) + return o->invokeMethod (method, arguments, numArguments); + + return var::null; } var var::invokeMethod (DynamicObject* const target, const var* const arguments, const int numArguments) const @@ -522,8 +528,10 @@ var var::call (const Identifier& method, const var& arg1, const var& arg2, const //============================================================================== int var::size() const { - const Array* const array = getArray(); - return array != nullptr ? array->size() : 0; + if (const Array* const array = getArray()) + return array->size(); + + return 0; } const var& var::operator[] (int arrayIndex) const @@ -574,9 +582,7 @@ void var::append (const var& n) void var::remove (const int index) { - Array* const array = getArray(); - - if (array != nullptr) + if (Array* const array = getArray()) array->remove (index); } @@ -592,8 +598,10 @@ void var::resize (const int numArrayElementsWanted) int var::indexOf (const var& n) const { - const Array* const array = getArray(); - return array != nullptr ? array->indexOf (n) : -1; + if (const Array* const array = getArray()) + return array->indexOf (n); + + return -1; } //============================================================================== diff --git a/modules/juce_data_structures/values/juce_ValueTree.cpp b/modules/juce_data_structures/values/juce_ValueTree.cpp index e10bb556cc..35a7f7e095 100644 --- a/modules/juce_data_structures/values/juce_ValueTree.cpp +++ b/modules/juce_data_structures/values/juce_ValueTree.cpp @@ -482,13 +482,10 @@ public: { if (! (isAddingNewProperty || isDeletingProperty)) { - SetPropertyAction* const next = dynamic_cast (nextAction); - - if (next != nullptr && next->target == target && next->name == name - && ! (next->isAddingNewProperty || next->isDeletingProperty)) - { - return new SetPropertyAction (target, name, next->newValue, oldValue, false, false); - } + if (SetPropertyAction* const next = dynamic_cast (nextAction)) + if (next->target == target && next->name == name + && ! (next->isAddingNewProperty || next->isDeletingProperty)) + return new SetPropertyAction (target, name, next->newValue, oldValue, false, false); } return nullptr; diff --git a/modules/juce_graphics/fonts/juce_TextLayout.cpp b/modules/juce_graphics/fonts/juce_TextLayout.cpp index e4e08000db..2cef4c5a20 100644 --- a/modules/juce_graphics/fonts/juce_TextLayout.cpp +++ b/modules/juce_graphics/fonts/juce_TextLayout.cpp @@ -521,8 +521,8 @@ namespace TextLayoutHelpers if (attr.range.contains (i)) { - if (attr.getFont() != nullptr) newFontAndColour.font = attr.getFont(); - if (attr.getColour() != nullptr) newFontAndColour.colour = *attr.getColour(); + if (const Font* f = attr.getFont()) newFontAndColour.font = f; + if (const Colour* c = attr.getColour()) newFontAndColour.colour = *c; } } diff --git a/modules/juce_gui_basics/drawables/juce_SVGParser.cpp b/modules/juce_gui_basics/drawables/juce_SVGParser.cpp index 3ff396993e..99a2e31e43 100644 --- a/modules/juce_gui_basics/drawables/juce_SVGParser.cpp +++ b/modules/juce_gui_basics/drawables/juce_SVGParser.cpp @@ -146,9 +146,7 @@ private: DrawableComposite* parseSwitch (const XmlElement& xml) { - const XmlElement* const group = xml.getChildByName ("g"); - - if (group != nullptr) + if (const XmlElement* const group = xml.getChildByName ("g")) return parseGroupElement (*group); return nullptr; @@ -572,142 +570,141 @@ private: void addGradientStopsIn (ColourGradient& cg, const XmlElement* const fillXml) const { - if (fillXml == 0) - return; - - forEachXmlChildElementWithTagName (*fillXml, e, "stop") + if (fillXml != nullptr) { - int index = 0; - Colour col (parseColour (getStyleAttribute (e, "stop-color"), index, Colours::black)); + forEachXmlChildElementWithTagName (*fillXml, e, "stop") + { + int index = 0; + Colour col (parseColour (getStyleAttribute (e, "stop-color"), index, Colours::black)); - const String opacity (getStyleAttribute (e, "stop-opacity", "1")); - col = col.withMultipliedAlpha (jlimit (0.0f, 1.0f, opacity.getFloatValue())); + const String opacity (getStyleAttribute (e, "stop-opacity", "1")); + col = col.withMultipliedAlpha (jlimit (0.0f, 1.0f, opacity.getFloatValue())); - double offset = e->getDoubleAttribute ("offset"); + double offset = e->getDoubleAttribute ("offset"); - if (e->getStringAttribute ("offset").containsChar ('%')) - offset *= 0.01; + if (e->getStringAttribute ("offset").containsChar ('%')) + offset *= 0.01; - cg.addColour (jlimit (0.0, 1.0, offset), col); + cg.addColour (jlimit (0.0, 1.0, offset), col); + } } } - FillType getPathFillType (const Path& path, - const String& fill, - const String& fillOpacity, - const String& overallOpacity, - const Colour& defaultColour) const + FillType getGradientFillType (const XmlElement* fillXml, + const Path& path, + const float opacity) const { - float opacity = 1.0f; + ColourGradient gradient; - if (overallOpacity.isNotEmpty()) - opacity = jlimit (0.0f, 1.0f, overallOpacity.getFloatValue()); + addGradientStopsIn (gradient, findLinkedElement (fillXml)); + addGradientStopsIn (gradient, fillXml); - if (fillOpacity.isNotEmpty()) - opacity *= (jlimit (0.0f, 1.0f, fillOpacity.getFloatValue())); - - if (fill.startsWithIgnoreCase ("url")) + if (gradient.getNumColours() > 0) { - const String id (fill.fromFirstOccurrenceOf ("#", false, false) - .upToLastOccurrenceOf (")", false, false).trim()); + gradient.addColour (0.0, gradient.getColour (0)); + gradient.addColour (1.0, gradient.getColour (gradient.getNumColours() - 1)); + } + else + { + gradient.addColour (0.0, Colours::black); + gradient.addColour (1.0, Colours::black); + } - const XmlElement* const fillXml = findElementForId (topLevelXml, id); + if (opacity < 1.0f) + gradient.multiplyOpacity (opacity); - if (fillXml != nullptr - && (fillXml->hasTagName ("linearGradient") - || fillXml->hasTagName ("radialGradient"))) - { - const XmlElement* inheritedFrom = findLinkedElement (fillXml); + jassert (gradient.getNumColours() > 0); - ColourGradient gradient; + gradient.isRadial = fillXml->hasTagName ("radialGradient"); - addGradientStopsIn (gradient, inheritedFrom); - addGradientStopsIn (gradient, fillXml); + float gradientWidth = viewBoxW; + float gradientHeight = viewBoxH; + float dx = 0.0f; + float dy = 0.0f; - if (gradient.getNumColours() > 0) - { - gradient.addColour (0.0, gradient.getColour (0)); - gradient.addColour (1.0, gradient.getColour (gradient.getNumColours() - 1)); - } - else - { - gradient.addColour (0.0, Colours::black); - gradient.addColour (1.0, Colours::black); - } + const bool userSpace = fillXml->getStringAttribute ("gradientUnits").equalsIgnoreCase ("userSpaceOnUse"); - if (overallOpacity.isNotEmpty()) - gradient.multiplyOpacity (overallOpacity.getFloatValue()); + if (! userSpace) + { + const Rectangle bounds (path.getBounds()); + dx = bounds.getX(); + dy = bounds.getY(); + gradientWidth = bounds.getWidth(); + gradientHeight = bounds.getHeight(); + } - jassert (gradient.getNumColours() > 0); + if (gradient.isRadial) + { + if (userSpace) + gradient.point1.setXY (dx + getCoordLength (fillXml->getStringAttribute ("cx", "50%"), gradientWidth), + dy + getCoordLength (fillXml->getStringAttribute ("cy", "50%"), gradientHeight)); + else + gradient.point1.setXY (dx + gradientWidth * getCoordLength (fillXml->getStringAttribute ("cx", "50%"), 1.0f), + dy + gradientHeight * getCoordLength (fillXml->getStringAttribute ("cy", "50%"), 1.0f)); - gradient.isRadial = fillXml->hasTagName ("radialGradient"); + const float radius = getCoordLength (fillXml->getStringAttribute ("r", "50%"), gradientWidth); + gradient.point2 = gradient.point1 + Point (radius, 0.0f); - float gradientWidth = viewBoxW; - float gradientHeight = viewBoxH; - float dx = 0.0f; - float dy = 0.0f; + //xxx (the fx, fy focal point isn't handled properly here..) + } + else + { + if (userSpace) + { + gradient.point1.setXY (dx + getCoordLength (fillXml->getStringAttribute ("x1", "0%"), gradientWidth), + dy + getCoordLength (fillXml->getStringAttribute ("y1", "0%"), gradientHeight)); - const bool userSpace = fillXml->getStringAttribute ("gradientUnits").equalsIgnoreCase ("userSpaceOnUse"); + gradient.point2.setXY (dx + getCoordLength (fillXml->getStringAttribute ("x2", "100%"), gradientWidth), + dy + getCoordLength (fillXml->getStringAttribute ("y2", "0%"), gradientHeight)); + } + else + { + gradient.point1.setXY (dx + gradientWidth * getCoordLength (fillXml->getStringAttribute ("x1", "0%"), 1.0f), + dy + gradientHeight * getCoordLength (fillXml->getStringAttribute ("y1", "0%"), 1.0f)); - if (! userSpace) - { - const Rectangle bounds (path.getBounds()); - dx = bounds.getX(); - dy = bounds.getY(); - gradientWidth = bounds.getWidth(); - gradientHeight = bounds.getHeight(); - } + gradient.point2.setXY (dx + gradientWidth * getCoordLength (fillXml->getStringAttribute ("x2", "100%"), 1.0f), + dy + gradientHeight * getCoordLength (fillXml->getStringAttribute ("y2", "0%"), 1.0f)); + } - if (gradient.isRadial) - { - if (userSpace) - gradient.point1.setXY (dx + getCoordLength (fillXml->getStringAttribute ("cx", "50%"), gradientWidth), - dy + getCoordLength (fillXml->getStringAttribute ("cy", "50%"), gradientHeight)); - else - gradient.point1.setXY (dx + gradientWidth * getCoordLength (fillXml->getStringAttribute ("cx", "50%"), 1.0f), - dy + gradientHeight * getCoordLength (fillXml->getStringAttribute ("cy", "50%"), 1.0f)); + if (gradient.point1 == gradient.point2) + return Colour (gradient.getColour (gradient.getNumColours() - 1)); + } - const float radius = getCoordLength (fillXml->getStringAttribute ("r", "50%"), gradientWidth); - gradient.point2 = gradient.point1 + Point (radius, 0.0f); + FillType type (gradient); + type.transform = parseTransform (fillXml->getStringAttribute ("gradientTransform")) + .followedBy (transform); + return type; + } - //xxx (the fx, fy focal point isn't handled properly here..) - } - else - { - if (userSpace) - { - gradient.point1.setXY (dx + getCoordLength (fillXml->getStringAttribute ("x1", "0%"), gradientWidth), - dy + getCoordLength (fillXml->getStringAttribute ("y1", "0%"), gradientHeight)); + FillType getPathFillType (const Path& path, + const String& fill, + const String& fillOpacity, + const String& overallOpacity, + const Colour& defaultColour) const + { + float opacity = 1.0f; - gradient.point2.setXY (dx + getCoordLength (fillXml->getStringAttribute ("x2", "100%"), gradientWidth), - dy + getCoordLength (fillXml->getStringAttribute ("y2", "0%"), gradientHeight)); - } - else - { - gradient.point1.setXY (dx + gradientWidth * getCoordLength (fillXml->getStringAttribute ("x1", "0%"), 1.0f), - dy + gradientHeight * getCoordLength (fillXml->getStringAttribute ("y1", "0%"), 1.0f)); + if (overallOpacity.isNotEmpty()) + opacity = jlimit (0.0f, 1.0f, overallOpacity.getFloatValue()); - gradient.point2.setXY (dx + gradientWidth * getCoordLength (fillXml->getStringAttribute ("x2", "100%"), 1.0f), - dy + gradientHeight * getCoordLength (fillXml->getStringAttribute ("y2", "0%"), 1.0f)); - } + if (fillOpacity.isNotEmpty()) + opacity *= (jlimit (0.0f, 1.0f, fillOpacity.getFloatValue())); - if (gradient.point1 == gradient.point2) - return Colour (gradient.getColour (gradient.getNumColours() - 1)); - } + if (fill.startsWithIgnoreCase ("url")) + { + const String id (fill.fromFirstOccurrenceOf ("#", false, false) + .upToLastOccurrenceOf (")", false, false).trim()); - FillType type (gradient); - type.transform = parseTransform (fillXml->getStringAttribute ("gradientTransform")) - .followedBy (transform); - return type; - } + if (const XmlElement* const fillXml = findElementForId (topLevelXml, id)) + if (fillXml->hasTagName ("linearGradient") || fillXml->hasTagName ("radialGradient")) + return getGradientFillType (fillXml, path, opacity); } if (fill.equalsIgnoreCase ("none")) return Colours::transparentBlack; int i = 0; - const Colour colour (parseColour (fill, i, defaultColour)); - return colour.withMultipliedAlpha (opacity); + return parseColour (fill, i, defaultColour).withMultipliedAlpha (opacity); } PathStrokeType getStrokeFor (const XmlElement* const xml) const @@ -1216,9 +1213,7 @@ private: if (e->compareAttribute ("id", id)) return e; - const XmlElement* const found = findElementForId (e, id); - - if (found != nullptr) + if (const XmlElement* const found = findElementForId (e, id)) return found; } diff --git a/modules/juce_gui_basics/layout/juce_ScrollBar.h b/modules/juce_gui_basics/layout/juce_ScrollBar.h index d76052a815..8c3fab1b3b 100644 --- a/modules/juce_gui_basics/layout/juce_ScrollBar.h +++ b/modules/juce_gui_basics/layout/juce_ScrollBar.h @@ -153,16 +153,14 @@ public: This sets both the position and size of the thumb - to just set the position without changing the size, you can use setCurrentRangeStart(). - If this method call actually changes the scrollbar's position, it will trigger an - asynchronous call to ScrollBar::Listener::scrollBarMoved() for all the listeners that - are registered. - @param newStart the top (or left) of the thumb, in the range getMinimumRangeLimit() <= newStart <= getMaximumRangeLimit(). If the value is beyond these limits, it will be clipped. @param newSize the size of the thumb, such that getMinimumRangeLimit() <= newStart + newSize <= getMaximumRangeLimit(). If the size is beyond these limits, it will be clipped. + @param notification specifies if and how a callback should be made to any listeners + if the range actually changes @see setCurrentRangeStart, getCurrentRangeStart, getCurrentRangeSize */ void setCurrentRange (double newStart, double newSize, diff --git a/modules/juce_gui_basics/widgets/juce_TableListBox.cpp b/modules/juce_gui_basics/widgets/juce_TableListBox.cpp index 9a71358b5d..cfb55b4fe0 100644 --- a/modules/juce_gui_basics/widgets/juce_TableListBox.cpp +++ b/modules/juce_gui_basics/widgets/juce_TableListBox.cpp @@ -132,8 +132,9 @@ public: const int columnId = owner.getHeader().getColumnIdAtX (e.x); - if (columnId != 0 && owner.getModel() != nullptr) - owner.getModel()->cellClicked (row, columnId, e); + if (columnId != 0) + if (TableListBoxModel* model = owner.getModel()) + model->cellClicked (row, columnId, e); } else { @@ -169,8 +170,9 @@ public: const int columnId = owner.getHeader().getColumnIdAtX (e.x); - if (columnId != 0 && owner.getModel() != nullptr) - owner.getModel()->cellClicked (row, columnId, e); + if (columnId != 0) + if (TableListBoxModel* model = owner.getModel()) + model->cellClicked (row, columnId, e); } } @@ -178,16 +180,18 @@ public: { const int columnId = owner.getHeader().getColumnIdAtX (e.x); - if (columnId != 0 && owner.getModel() != nullptr) - owner.getModel()->cellDoubleClicked (row, columnId, e); + if (columnId != 0) + if (TableListBoxModel* model = owner.getModel()) + model->cellDoubleClicked (row, columnId, e); } String getTooltip() { const int columnId = owner.getHeader().getColumnIdAtX (getMouseXYRelative().getX()); - if (columnId != 0 && owner.getModel() != nullptr) - return owner.getModel()->getCellTooltip (row, columnId); + if (columnId != 0) + if (TableListBoxModel* model = owner.getModel()) + return model->getCellTooltip (row, columnId); return String::empty; } @@ -334,15 +338,15 @@ Rectangle TableListBox::getCellPosition (const int columnId, const int rowN Component* TableListBox::getCellComponent (int columnId, int rowNumber) const { - RowComp* const rowComp = dynamic_cast (getComponentForRowNumber (rowNumber)); - return rowComp != nullptr ? rowComp->findChildComponentForColumn (columnId) : 0; + if (RowComp* const rowComp = dynamic_cast (getComponentForRowNumber (rowNumber))) + return rowComp->findChildComponentForColumn (columnId); + + return nullptr; } void TableListBox::scrollToEnsureColumnIsOnscreen (const int columnId) { - ScrollBar* const scrollbar = getHorizontalScrollBar(); - - if (scrollbar != nullptr) + if (ScrollBar* const scrollbar = getHorizontalScrollBar()) { const Rectangle pos (header->getColumnPosition (header->getIndexOfColumnId (columnId, true))); @@ -447,12 +451,8 @@ void TableListBox::updateColumnComponents() const const int firstRow = getRowContainingPosition (0, 0); for (int i = firstRow + getNumRowsOnScreen() + 2; --i >= firstRow;) - { - RowComp* const rowComp = dynamic_cast (getComponentForRowNumber (i)); - - if (rowComp != nullptr) + if (RowComp* const rowComp = dynamic_cast (getComponentForRowNumber (i))) rowComp->resized(); - } } //============================================================================== diff --git a/modules/juce_gui_basics/widgets/juce_TreeView.cpp b/modules/juce_gui_basics/widgets/juce_TreeView.cpp index c699563380..7831e0b90f 100644 --- a/modules/juce_gui_basics/widgets/juce_TreeView.cpp +++ b/modules/juce_gui_basics/widgets/juce_TreeView.cpp @@ -363,9 +363,11 @@ private: static bool isMouseDraggingInChildCompOf (Component* const comp) { - for (int i = Desktop::getInstance().getNumMouseSources(); --i >= 0;) + Desktop& desktop = Desktop::getInstance(); + + for (int i = desktop.getNumMouseSources(); --i >= 0;) { - MouseInputSource* const source = Desktop::getInstance().getMouseSource(i); + MouseInputSource* const source = desktop.getMouseSource(i); if (source->isDragging()) if (Component* const underMouse = source->getComponentUnderMouse())