diff --git a/examples/GUI/GraphicsDemo.h b/examples/GUI/GraphicsDemo.h index 75733d4519..d5fecd464f 100644 --- a/examples/GUI/GraphicsDemo.h +++ b/examples/GUI/GraphicsDemo.h @@ -496,18 +496,20 @@ public: if (svgFileStream.get() != nullptr) { - svgDrawable.reset (dynamic_cast (Drawable::createFromImageDataStream (*svgFileStream))); + svgDrawable = Drawable::createFromImageDataStream (*svgFileStream); - if (svgDrawable.get() != nullptr) + if (svgDrawable != nullptr) { // to make our icon the right size, we'll set its bounding box to the size and position that we want. - svgDrawable->setBoundingBox ({ -100.0f, -100.0f, 200.0f, 200.0f }); + + if (auto comp = dynamic_cast (svgDrawable.get())) + comp->setBoundingBox ({ -100.0f, -100.0f, 200.0f, 200.0f }); } } } Time lastSVGLoadTime; - std::unique_ptr svgDrawable; + std::unique_ptr svgDrawable; }; //============================================================================== diff --git a/examples/GUI/WidgetsDemo.h b/examples/GUI/WidgetsDemo.h index fb7ea8074a..4af6321b89 100644 --- a/examples/GUI/WidgetsDemo.h +++ b/examples/GUI/WidgetsDemo.h @@ -632,12 +632,14 @@ private: case edit_copy: return createButtonFromZipFileSVG (itemId, "copy", "edit-copy.svg"); case edit_cut: return createButtonFromZipFileSVG (itemId, "cut", "edit-cut.svg"); case edit_paste: return createButtonFromZipFileSVG (itemId, "paste", "edit-paste.svg"); + case juceLogoButton: { - auto* drawable = new DrawableImage(); + auto drawable = std::make_unique(); drawable->setImage (getImageFromAssets ("juce_icon.png")); - return new ToolbarButton (itemId, "juce!", drawable, nullptr); + return new ToolbarButton (itemId, "juce!", std::move (drawable), {}); } + case customComboBox: return new CustomToolbarComboBox (itemId); default: break; } @@ -670,8 +672,8 @@ private: } } - auto* image = iconsFromZipFile[iconNames.indexOf (filename)]->createCopy(); - return new ToolbarButton (itemId, text, image, nullptr); + auto* image = iconsFromZipFile[iconNames.indexOf (filename)]; + return new ToolbarButton (itemId, text, image->createCopy(), {}); } // Demonstrates how to put a custom component into a toolbar - this one contains diff --git a/extras/Projucer/Source/Application/jucer_AutoUpdater.cpp b/extras/Projucer/Source/Application/jucer_AutoUpdater.cpp index 2fe10e8e37..a54b52736a 100644 --- a/extras/Projucer/Source/Application/jucer_AutoUpdater.cpp +++ b/extras/Projucer/Source/Application/jucer_AutoUpdater.cpp @@ -210,8 +210,8 @@ public: dontAskAgainButton.setToggleState (getGlobalProperties().getValue (Ids::dontQueryForUpdate, {}).isNotEmpty(), dontSendNotification); addAndMakeVisible (dontAskAgainButton); - juceIcon.reset (Drawable::createFromImageData (BinaryData::juce_icon_png, BinaryData::juce_icon_pngSize)); - + juceIcon = Drawable::createFromImageData (BinaryData::juce_icon_png, + BinaryData::juce_icon_pngSize); lookAndFeelChanged(); setSize (500, 280); diff --git a/extras/Projucer/Source/CodeEditor/jucer_ItemPreviewComponent.h b/extras/Projucer/Source/CodeEditor/jucer_ItemPreviewComponent.h index e2133316be..669c74e7d0 100644 --- a/extras/Projucer/Source/CodeEditor/jucer_ItemPreviewComponent.h +++ b/extras/Projucer/Source/CodeEditor/jucer_ItemPreviewComponent.h @@ -109,7 +109,7 @@ private: if (drawable == nullptr) if (auto svg = parseXML (file)) - drawable.reset (Drawable::createFromSVG (*svg)); + drawable = Drawable::createFromSVG (*svg); facts.removeEmptyStrings (true); } diff --git a/extras/Projucer/Source/ComponentEditor/jucer_BinaryResources.cpp b/extras/Projucer/Source/ComponentEditor/jucer_BinaryResources.cpp index 1192e1e6dc..f0439f0660 100644 --- a/extras/Projucer/Source/ComponentEditor/jucer_BinaryResources.cpp +++ b/extras/Projucer/Source/ComponentEditor/jucer_BinaryResources.cpp @@ -188,8 +188,8 @@ const Drawable* BinaryResources::getDrawable (const String& name) const if (auto* res = const_cast (getResource (name))) { if (res->drawable == nullptr && res->data.getSize() > 0) - res->drawable.reset (Drawable::createFromImageData (res->data.getData(), - res->data.getSize())); + res->drawable = Drawable::createFromImageData (res->data.getData(), + res->data.getSize()); return res->drawable.get(); } diff --git a/extras/Projucer/Source/Project/UI/jucer_ProjectContentComponent.cpp b/extras/Projucer/Source/Project/UI/jucer_ProjectContentComponent.cpp index e9fb6807fd..52d52045b6 100644 --- a/extras/Projucer/Source/Project/UI/jucer_ProjectContentComponent.cpp +++ b/extras/Projucer/Source/Project/UI/jucer_ProjectContentComponent.cpp @@ -40,7 +40,7 @@ struct LogoComponent : public Component LogoComponent() { if (auto svg = parseXML (BinaryData::background_logo_svg)) - logo.reset (Drawable::createFromSVG (*svg)); + logo = Drawable::createFromSVG (*svg); else jassertfalse; } diff --git a/extras/Projucer/Source/Wizards/jucer_TemplateThumbnailsComponent.h b/extras/Projucer/Source/Wizards/jucer_TemplateThumbnailsComponent.h index 3ae5142dd1..914ae8cd6f 100644 --- a/extras/Projucer/Source/Wizards/jucer_TemplateThumbnailsComponent.h +++ b/extras/Projucer/Source/Wizards/jucer_TemplateThumbnailsComponent.h @@ -41,12 +41,12 @@ public: // svg for thumbnail icon auto svg = parseXML (thumbSvg); jassert (svg != nullptr); - thumb.reset (Drawable::createFromSVG (*svg)); + thumb = Drawable::createFromSVG (*svg); // svg for thumbnail background highlight auto backSvg = parseXML (BinaryData::wizard_Highlight_svg); jassert (backSvg != nullptr); - hoverBackground.reset (Drawable::createFromSVG (*backSvg)); + hoverBackground = Drawable::createFromSVG (*backSvg); name = buttonName; diff --git a/modules/juce_core/containers/juce_ReferenceCountedArray.cpp b/modules/juce_core/containers/juce_ReferenceCountedArray.cpp index 4ce5c1d5ee..75d6c8d84c 100644 --- a/modules/juce_core/containers/juce_ReferenceCountedArray.cpp +++ b/modules/juce_core/containers/juce_ReferenceCountedArray.cpp @@ -84,12 +84,7 @@ public: expectEquals (derivedObject->getReferenceCount(), 1); baseArray.add (baseObjectPtr); - - #if JUCE_STRICT_REFCOUNTEDPOINTER - baseArray.add (derivedObjectPtr); - #else baseArray.add (derivedObjectPtr.get()); - #endif for (auto o : baseArray) expectEquals (o->getReferenceCount(), 2); diff --git a/modules/juce_gui_basics/buttons/juce_DrawableButton.cpp b/modules/juce_gui_basics/buttons/juce_DrawableButton.cpp index b1bdf973a1..66146752e7 100644 --- a/modules/juce_gui_basics/buttons/juce_DrawableButton.cpp +++ b/modules/juce_gui_basics/buttons/juce_DrawableButton.cpp @@ -37,9 +37,12 @@ DrawableButton::~DrawableButton() } //============================================================================== -static Drawable* copyDrawableIfNotNull (const Drawable* const d) +static std::unique_ptr copyDrawableIfNotNull (const Drawable* const d) { - return d != nullptr ? d->createCopy() : nullptr; + if (d != nullptr) + return d->createCopy(); + + return {}; } void DrawableButton::setImages (const Drawable* normal, @@ -53,14 +56,14 @@ void DrawableButton::setImages (const Drawable* normal, { jassert (normal != nullptr); // you really need to give it at least a normal image.. - normalImage .reset (copyDrawableIfNotNull (normal)); - overImage .reset (copyDrawableIfNotNull (over)); - downImage .reset (copyDrawableIfNotNull (down)); - disabledImage .reset (copyDrawableIfNotNull (disabled)); - normalImageOn .reset (copyDrawableIfNotNull (normalOn)); - overImageOn .reset (copyDrawableIfNotNull (overOn)); - downImageOn .reset (copyDrawableIfNotNull (downOn)); - disabledImageOn .reset (copyDrawableIfNotNull (disabledOn)); + normalImage = copyDrawableIfNotNull (normal); + overImage = copyDrawableIfNotNull (over); + downImage = copyDrawableIfNotNull (down); + disabledImage = copyDrawableIfNotNull (disabled); + normalImageOn = copyDrawableIfNotNull (normalOn); + overImageOn = copyDrawableIfNotNull (overOn); + downImageOn = copyDrawableIfNotNull (downOn); + disabledImageOn = copyDrawableIfNotNull (disabledOn); currentImage = nullptr; diff --git a/modules/juce_gui_basics/buttons/juce_DrawableButton.h b/modules/juce_gui_basics/buttons/juce_DrawableButton.h index 9758a94a9f..1602130e76 100644 --- a/modules/juce_gui_basics/buttons/juce_DrawableButton.h +++ b/modules/juce_gui_basics/buttons/juce_DrawableButton.h @@ -183,7 +183,7 @@ private: //============================================================================== ButtonStyle style; std::unique_ptr normalImage, overImage, downImage, disabledImage, - normalImageOn, overImageOn, downImageOn, disabledImageOn; + normalImageOn, overImageOn, downImageOn, disabledImageOn; Drawable* currentImage = nullptr; int edgeIndent = 3; diff --git a/modules/juce_gui_basics/buttons/juce_ToolbarButton.cpp b/modules/juce_gui_basics/buttons/juce_ToolbarButton.cpp index 172c5194f3..c5e3765dd4 100644 --- a/modules/juce_gui_basics/buttons/juce_ToolbarButton.cpp +++ b/modules/juce_gui_basics/buttons/juce_ToolbarButton.cpp @@ -28,11 +28,11 @@ namespace juce { ToolbarButton::ToolbarButton (const int iid, const String& buttonText, - Drawable* const normalIm, Drawable* const toggledOnIm) + std::unique_ptr normalIm, + std::unique_ptr toggledOnIm) : ToolbarItemComponent (iid, buttonText, true), - normalImage (normalIm), - toggledOnImage (toggledOnIm), - currentImage (nullptr) + normalImage (std::move (normalIm)), + toggledOnImage (std::move (toggledOnIm)) { jassert (normalImage != nullptr); } diff --git a/modules/juce_gui_basics/buttons/juce_ToolbarButton.h b/modules/juce_gui_basics/buttons/juce_ToolbarButton.h index a875e500b4..f527811bee 100644 --- a/modules/juce_gui_basics/buttons/juce_ToolbarButton.h +++ b/modules/juce_gui_basics/buttons/juce_ToolbarButton.h @@ -62,8 +62,8 @@ public: */ ToolbarButton (int itemId, const String& labelText, - Drawable* normalImage, - Drawable* toggledOnImage); + std::unique_ptr normalImage, + std::unique_ptr toggledOnImage); /** Destructor. */ ~ToolbarButton() override; @@ -87,7 +87,7 @@ public: private: //============================================================================== std::unique_ptr normalImage, toggledOnImage; - Drawable* currentImage; + Drawable* currentImage = nullptr; void updateDrawable(); Drawable* getImageToUse() const; diff --git a/modules/juce_gui_basics/drawables/juce_Drawable.cpp b/modules/juce_gui_basics/drawables/juce_Drawable.cpp index 382fef0115..e1f1f81c8b 100644 --- a/modules/juce_gui_basics/drawables/juce_Drawable.cpp +++ b/modules/juce_gui_basics/drawables/juce_Drawable.cpp @@ -110,11 +110,11 @@ DrawableComposite* Drawable::getParent() const return dynamic_cast (getParentComponent()); } -void Drawable::setClipPath (Drawable* clipPath) +void Drawable::setClipPath (std::unique_ptr clipPath) { - if (drawableClipPath.get() != clipPath) + if (drawableClipPath != clipPath) { - drawableClipPath.reset (clipPath); + drawableClipPath = std::move (clipPath); repaint(); } } @@ -166,9 +166,9 @@ void Drawable::setTransformToFit (const Rectangle& area, RectanglePlaceme } //============================================================================== -Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes) +std::unique_ptr Drawable::createFromImageData (const void* data, const size_t numBytes) { - Drawable* result = nullptr; + std::unique_ptr result; auto image = ImageFileFormat::loadFrom (data, numBytes); @@ -176,7 +176,7 @@ Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes { auto* di = new DrawableImage(); di->setImage (image); - result = di; + result.reset (di); } else { @@ -186,18 +186,14 @@ Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes std::unique_ptr outer (doc.getDocumentElement (true)); if (outer != nullptr && outer->hasTagName ("svg")) - { - std::unique_ptr svg (doc.getDocumentElement()); - - if (svg != nullptr) + if (auto svg = doc.getDocumentElement()) result = Drawable::createFromSVG (*svg); - } } return result; } -Drawable* Drawable::createFromImageDataStream (InputStream& dataSource) +std::unique_ptr Drawable::createFromImageDataStream (InputStream& dataSource) { MemoryOutputStream mo; mo << dataSource; @@ -205,11 +201,14 @@ Drawable* Drawable::createFromImageDataStream (InputStream& dataSource) return createFromImageData (mo.getData(), mo.getDataSize()); } -Drawable* Drawable::createFromImageFile (const File& file) +std::unique_ptr Drawable::createFromImageFile (const File& file) { FileInputStream fin (file); - return fin.openedOk() ? createFromImageDataStream (fin) : nullptr; + if (fin.openedOk()) + return createFromImageDataStream (fin); + + return {}; } } // namespace juce diff --git a/modules/juce_gui_basics/drawables/juce_Drawable.h b/modules/juce_gui_basics/drawables/juce_Drawable.h index 671450807d..e743b2de6d 100644 --- a/modules/juce_gui_basics/drawables/juce_Drawable.h +++ b/modules/juce_gui_basics/drawables/juce_Drawable.h @@ -54,7 +54,7 @@ public: Use this to create a new copy of this and any sub-objects in the tree. */ - virtual Drawable* createCopy() const = 0; + virtual std::unique_ptr createCopy() const = 0; /** Creates a path that describes the outline of this drawable. */ virtual Path getOutlineAsPath() const = 0; @@ -123,9 +123,9 @@ public: DrawableComposite* getParent() const; /** Sets a the clipping region of this drawable using another drawable. - The drawbale passed in ill be deleted when no longer needed. + The drawbale passed in will be deleted when no longer needed. */ - void setClipPath (Drawable* drawableClipPath); + void setClipPath (std::unique_ptr drawableClipPath); //============================================================================== /** Tries to turn some kind of image file into a drawable. @@ -133,21 +133,21 @@ public: The data could be an image that the ImageFileFormat class understands, or it could be SVG. */ - static Drawable* createFromImageData (const void* data, size_t numBytes); + static std::unique_ptr createFromImageData (const void* data, size_t numBytes); /** Tries to turn a stream containing some kind of image data into a drawable. The data could be an image that the ImageFileFormat class understands, or it could be SVG. */ - static Drawable* createFromImageDataStream (InputStream& dataSource); + static std::unique_ptr createFromImageDataStream (InputStream& dataSource); /** Tries to turn a file containing some kind of image data into a drawable. The data could be an image that the ImageFileFormat class understands, or it could be SVG. */ - static Drawable* createFromImageFile (const File& file); + static std::unique_ptr createFromImageFile (const File& file); /** Attempts to parse an SVG (Scalable Vector Graphics) document, and to turn this into a Drawable tree. @@ -158,7 +158,7 @@ public: SVG is a pretty large and complex spec, and this doesn't aim to be a full implementation, but it can return the basic vector objects. */ - static Drawable* createFromSVG (const XmlElement& svgDocument); + static std::unique_ptr createFromSVG (const XmlElement& svgDocument); /** Attempts to parse an SVG (Scalable Vector Graphics) document from a file, and to turn this into a Drawable tree. @@ -172,7 +172,7 @@ public: Any references to references to external image files will be relative to the parent directory of the file passed. */ - static Drawable* createFromSVGFile (const File& svgFile); + static std::unique_ptr createFromSVGFile (const File& svgFile); /** Parses an SVG path string and returns it. */ static Path parseSVGPath (const String& svgPath); diff --git a/modules/juce_gui_basics/drawables/juce_DrawableComposite.cpp b/modules/juce_gui_basics/drawables/juce_DrawableComposite.cpp index 6bdbed27b4..8cddf73dfa 100644 --- a/modules/juce_gui_basics/drawables/juce_DrawableComposite.cpp +++ b/modules/juce_gui_basics/drawables/juce_DrawableComposite.cpp @@ -40,7 +40,7 @@ DrawableComposite::DrawableComposite (const DrawableComposite& other) { for (auto* c : other.getChildren()) if (auto* d = dynamic_cast (c)) - addAndMakeVisible (d->createCopy()); + addAndMakeVisible (d->createCopy().release()); } DrawableComposite::~DrawableComposite() @@ -48,9 +48,9 @@ DrawableComposite::~DrawableComposite() deleteAllChildren(); } -Drawable* DrawableComposite::createCopy() const +std::unique_ptr DrawableComposite::createCopy() const { - return new DrawableComposite (*this); + return std::make_unique (*this); } //============================================================================== diff --git a/modules/juce_gui_basics/drawables/juce_DrawableComposite.h b/modules/juce_gui_basics/drawables/juce_DrawableComposite.h index 593a7dbaa5..b80ee9eced 100644 --- a/modules/juce_gui_basics/drawables/juce_DrawableComposite.h +++ b/modules/juce_gui_basics/drawables/juce_DrawableComposite.h @@ -91,7 +91,7 @@ public: //============================================================================== /** @internal */ - Drawable* createCopy() const override; + std::unique_ptr createCopy() const override; /** @internal */ Rectangle getDrawableBounds() const override; /** @internal */ diff --git a/modules/juce_gui_basics/drawables/juce_DrawableImage.cpp b/modules/juce_gui_basics/drawables/juce_DrawableImage.cpp index 0e5d2e99a5..95df711133 100644 --- a/modules/juce_gui_basics/drawables/juce_DrawableImage.cpp +++ b/modules/juce_gui_basics/drawables/juce_DrawableImage.cpp @@ -45,9 +45,9 @@ DrawableImage::~DrawableImage() { } -Drawable* DrawableImage::createCopy() const +std::unique_ptr DrawableImage::createCopy() const { - return new DrawableImage (*this); + return std::make_unique (*this); } //============================================================================== diff --git a/modules/juce_gui_basics/drawables/juce_DrawableImage.h b/modules/juce_gui_basics/drawables/juce_DrawableImage.h index b6e7a23c5e..0f146ac543 100644 --- a/modules/juce_gui_basics/drawables/juce_DrawableImage.h +++ b/modules/juce_gui_basics/drawables/juce_DrawableImage.h @@ -90,7 +90,7 @@ public: /** @internal */ bool hitTest (int x, int y) override; /** @internal */ - Drawable* createCopy() const override; + std::unique_ptr createCopy() const override; /** @internal */ Rectangle getDrawableBounds() const override; /** @internal */ diff --git a/modules/juce_gui_basics/drawables/juce_DrawablePath.cpp b/modules/juce_gui_basics/drawables/juce_DrawablePath.cpp index 6905717dad..eadadc3af4 100644 --- a/modules/juce_gui_basics/drawables/juce_DrawablePath.cpp +++ b/modules/juce_gui_basics/drawables/juce_DrawablePath.cpp @@ -35,9 +35,9 @@ DrawablePath::DrawablePath (const DrawablePath& other) : DrawableShape (other) setPath (other.path); } -Drawable* DrawablePath::createCopy() const +std::unique_ptr DrawablePath::createCopy() const { - return new DrawablePath (*this); + return std::make_unique (*this); } void DrawablePath::setPath (const Path& newPath) diff --git a/modules/juce_gui_basics/drawables/juce_DrawablePath.h b/modules/juce_gui_basics/drawables/juce_DrawablePath.h index 38499d3b1a..14b80f5eba 100644 --- a/modules/juce_gui_basics/drawables/juce_DrawablePath.h +++ b/modules/juce_gui_basics/drawables/juce_DrawablePath.h @@ -67,7 +67,7 @@ public: //============================================================================== /** @internal */ - Drawable* createCopy() const override; + std::unique_ptr createCopy() const override; private: //============================================================================== diff --git a/modules/juce_gui_basics/drawables/juce_DrawableRectangle.cpp b/modules/juce_gui_basics/drawables/juce_DrawableRectangle.cpp index be093deb41..04773e1fcd 100644 --- a/modules/juce_gui_basics/drawables/juce_DrawableRectangle.cpp +++ b/modules/juce_gui_basics/drawables/juce_DrawableRectangle.cpp @@ -38,9 +38,9 @@ DrawableRectangle::DrawableRectangle (const DrawableRectangle& other) rebuildPath(); } -Drawable* DrawableRectangle::createCopy() const +std::unique_ptr DrawableRectangle::createCopy() const { - return new DrawableRectangle (*this); + return std::make_unique (*this); } //============================================================================== diff --git a/modules/juce_gui_basics/drawables/juce_DrawableRectangle.h b/modules/juce_gui_basics/drawables/juce_DrawableRectangle.h index 43076a2c99..198572e6c8 100644 --- a/modules/juce_gui_basics/drawables/juce_DrawableRectangle.h +++ b/modules/juce_gui_basics/drawables/juce_DrawableRectangle.h @@ -62,7 +62,7 @@ public: //============================================================================== /** @internal */ - Drawable* createCopy() const override; + std::unique_ptr createCopy() const override; private: Parallelogram bounds; diff --git a/modules/juce_gui_basics/drawables/juce_DrawableText.cpp b/modules/juce_gui_basics/drawables/juce_DrawableText.cpp index 7edab45619..e33fbdeec8 100644 --- a/modules/juce_gui_basics/drawables/juce_DrawableText.cpp +++ b/modules/juce_gui_basics/drawables/juce_DrawableText.cpp @@ -52,9 +52,9 @@ DrawableText::~DrawableText() { } -Drawable* DrawableText::createCopy() const +std::unique_ptr DrawableText::createCopy() const { - return new DrawableText (*this); + return std::make_unique (*this); } //============================================================================== diff --git a/modules/juce_gui_basics/drawables/juce_DrawableText.h b/modules/juce_gui_basics/drawables/juce_DrawableText.h index 13ab956d7f..bb83573381 100644 --- a/modules/juce_gui_basics/drawables/juce_DrawableText.h +++ b/modules/juce_gui_basics/drawables/juce_DrawableText.h @@ -92,7 +92,7 @@ public: /** @internal */ void paint (Graphics&) override; /** @internal */ - Drawable* createCopy() const override; + std::unique_ptr createCopy() const override; /** @internal */ Rectangle getDrawableBounds() const override; /** @internal */ diff --git a/modules/juce_gui_basics/drawables/juce_SVGParser.cpp b/modules/juce_gui_basics/drawables/juce_SVGParser.cpp index 657bd12cb6..2049668dbb 100644 --- a/modules/juce_gui_basics/drawables/juce_SVGParser.cpp +++ b/modules/juce_gui_basics/drawables/juce_SVGParser.cpp @@ -809,7 +809,7 @@ private: if (drawableClipPath->getNumChildComponents() > 0) { setCommonAttributes (*drawableClipPath, xmlPath); - target.setClipPath (drawableClipPath.release()); + target.setClipPath (std::move (drawableClipPath)); return true; } } @@ -1696,32 +1696,32 @@ private: //============================================================================== -Drawable* Drawable::createFromSVG (const XmlElement& svgDocument) +std::unique_ptr Drawable::createFromSVG (const XmlElement& svgDocument) { if (! svgDocument.hasTagNameIgnoringNamespace ("svg")) - return nullptr; + return {}; SVGState state (&svgDocument); - return state.parseSVGElement (SVGState::XmlPath (&svgDocument, nullptr)); + return std::unique_ptr (state.parseSVGElement (SVGState::XmlPath (&svgDocument, nullptr))); } -Drawable* Drawable::createFromSVGFile (const File& svgFile) +std::unique_ptr Drawable::createFromSVGFile (const File& svgFile) { XmlDocument doc (svgFile); - std::unique_ptr outer (doc.getDocumentElement (true)); - if (outer != nullptr && outer->hasTagName ("svg")) + if (auto outer = doc.getDocumentElement (true)) { - std::unique_ptr svgDocument (doc.getDocumentElement()); - - if (svgDocument != nullptr) + if (outer->hasTagName ("svg")) { - SVGState state (svgDocument.get(), svgFile); - return state.parseSVGElement (SVGState::XmlPath (svgDocument.get(), nullptr)); + if (auto svgDocument = doc.getDocumentElement()) + { + SVGState state (svgDocument.get(), svgFile); + return std::unique_ptr (state.parseSVGElement (SVGState::XmlPath (svgDocument.get(), nullptr))); + } } } - return nullptr; + return {}; } Path Drawable::parseSVGPath (const String& svgPath) diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp index 7f38d0ad8f..b357db1717 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp @@ -2315,14 +2315,14 @@ Button* LookAndFeel_V2::createTabBarExtrasButton() dp.setFill (Colour (0x59000000)); DrawableComposite normalImage; - normalImage.addAndMakeVisible (ellipse.createCopy()); - normalImage.addAndMakeVisible (dp.createCopy()); + normalImage.addAndMakeVisible (ellipse.createCopy().release()); + normalImage.addAndMakeVisible (dp.createCopy().release()); dp.setFill (Colour (0xcc000000)); DrawableComposite overImage; - overImage.addAndMakeVisible (ellipse.createCopy()); - overImage.addAndMakeVisible (dp.createCopy()); + overImage.addAndMakeVisible (ellipse.createCopy().release()); + overImage.addAndMakeVisible (dp.createCopy().release()); auto db = new DrawableButton ("tabs", DrawableButton::ImageFitted); db->setImages (&normalImage, &overImage, nullptr); @@ -2653,7 +2653,7 @@ void LookAndFeel_V2::layoutFileBrowserComponent (FileBrowserComponent& browserCo } //============================================================================== -static Drawable* createDrawableFromSVG (const char* data) +static std::unique_ptr createDrawableFromSVG (const char* data) { auto xml = parseXML (data); jassert (xml != nullptr); @@ -2663,7 +2663,7 @@ static Drawable* createDrawableFromSVG (const char* data) const Drawable* LookAndFeel_V2::getDefaultFolderImage() { if (folderImage == nullptr) - folderImage.reset (createDrawableFromSVG (R"svgdata( + folderImage = createDrawableFromSVG (R"svgdata( @@ -2678,7 +2678,7 @@ const Drawable* LookAndFeel_V2::getDefaultFolderImage() -)svgdata")); +)svgdata"); return folderImage.get(); } @@ -2686,12 +2686,12 @@ const Drawable* LookAndFeel_V2::getDefaultFolderImage() const Drawable* LookAndFeel_V2::getDefaultDocumentFileImage() { if (documentImage == nullptr) - documentImage.reset (createDrawableFromSVG (R"svgdata( + documentImage = createDrawableFromSVG (R"svgdata( -)svgdata")); +)svgdata"); return documentImage.get(); } diff --git a/modules/juce_gui_basics/menus/juce_PopupMenu.cpp b/modules/juce_gui_basics/menus/juce_PopupMenu.cpp index c4af0d037a..490acb3ff6 100644 --- a/modules/juce_gui_basics/menus/juce_PopupMenu.cpp +++ b/modules/juce_gui_basics/menus/juce_PopupMenu.cpp @@ -1331,7 +1331,7 @@ PopupMenu::Item& PopupMenu::Item::operator= (const Item& other) text = other.text; itemID = other.itemID; subMenu.reset (createCopyIfNotNull (other.subMenu.get())); - image.reset (other.image != nullptr ? other.image->createCopy() : nullptr); + image = other.image != nullptr ? other.image->createCopy() : std::unique_ptr(); customComponent = other.customComponent; customCallback = other.customCallback; commandManager = other.commandManager; @@ -1365,16 +1365,16 @@ void PopupMenu::addItem (int itemResultID, const String& itemText, bool isActive addItem (i); } -static Drawable* createDrawableFromImage (const Image& im) +static std::unique_ptr createDrawableFromImage (const Image& im) { if (im.isValid()) { auto d = new DrawableImage(); d->setImage (im); - return d; + return std::unique_ptr (d); } - return nullptr; + return {}; } void PopupMenu::addItem (int itemResultID, const String& itemText, bool isActive, bool isTicked, const Image& iconToUse) @@ -1382,21 +1382,22 @@ void PopupMenu::addItem (int itemResultID, const String& itemText, bool isActive addItem (itemResultID, itemText, isActive, isTicked, createDrawableFromImage (iconToUse)); } -void PopupMenu::addItem (int itemResultID, const String& itemText, bool isActive, bool isTicked, Drawable* iconToUse) +void PopupMenu::addItem (int itemResultID, const String& itemText, bool isActive, + bool isTicked, std::unique_ptr iconToUse) { Item i; i.text = itemText; i.itemID = itemResultID; i.isEnabled = isActive; i.isTicked = isTicked; - i.image.reset (iconToUse); + i.image = std::move (iconToUse); addItem (i); } void PopupMenu::addCommandItem (ApplicationCommandManager* commandManager, const CommandID commandID, const String& displayName, - Drawable* iconToUse) + std::unique_ptr iconToUse) { jassert (commandManager != nullptr && commandID != 0); @@ -1411,13 +1412,13 @@ void PopupMenu::addCommandItem (ApplicationCommandManager* commandManager, i.commandManager = commandManager; i.isEnabled = target != nullptr && (info.flags & ApplicationCommandInfo::isDisabled) == 0; i.isTicked = (info.flags & ApplicationCommandInfo::isTicked) != 0; - i.image.reset (iconToUse); + i.image = std::move (iconToUse); addItem (i); } } void PopupMenu::addColouredItem (int itemResultID, const String& itemText, Colour itemTextColour, - bool isActive, bool isTicked, Drawable* iconToUse) + bool isActive, bool isTicked, std::unique_ptr iconToUse) { Item i; i.text = itemText; @@ -1425,7 +1426,7 @@ void PopupMenu::addColouredItem (int itemResultID, const String& itemText, Colou i.colour = itemTextColour; i.isEnabled = isActive; i.isTicked = isTicked; - i.image.reset (iconToUse); + i.image = std::move (iconToUse); addItem (i); } @@ -1438,7 +1439,7 @@ void PopupMenu::addColouredItem (int itemResultID, const String& itemText, Colou i.colour = itemTextColour; i.isEnabled = isActive; i.isTicked = isTicked; - i.image.reset (createDrawableFromImage (iconToUse)); + i.image = createDrawableFromImage (iconToUse); addItem (i); } @@ -1472,7 +1473,7 @@ void PopupMenu::addSubMenu (const String& subMenuName, const PopupMenu& subMenu, } void PopupMenu::addSubMenu (const String& subMenuName, const PopupMenu& subMenu, bool isActive, - Drawable* iconToUse, bool isTicked, int itemResultID) + std::unique_ptr iconToUse, bool isTicked, int itemResultID) { Item i; i.text = subMenuName; @@ -1480,7 +1481,7 @@ void PopupMenu::addSubMenu (const String& subMenuName, const PopupMenu& subMenu, i.subMenu.reset (new PopupMenu (subMenu)); i.isEnabled = isActive && (itemResultID != 0 || subMenu.getNumItems() > 0); i.isTicked = isTicked; - i.image.reset (iconToUse); + i.image = std::move (iconToUse); addItem (i); } diff --git a/modules/juce_gui_basics/menus/juce_PopupMenu.h b/modules/juce_gui_basics/menus/juce_PopupMenu.h index 7f07e67652..8ea675197f 100644 --- a/modules/juce_gui_basics/menus/juce_PopupMenu.h +++ b/modules/juce_gui_basics/menus/juce_PopupMenu.h @@ -231,7 +231,7 @@ public: const String& itemText, bool isEnabled, bool isTicked, - Drawable* iconToUse); + std::unique_ptr iconToUse); /** Adds an item that represents one of the commands in a command manager object. @@ -247,7 +247,7 @@ public: void addCommandItem (ApplicationCommandManager* commandManager, CommandID commandID, const String& displayName = String(), - Drawable* iconToUse = nullptr); + std::unique_ptr iconToUse = {}); /** Appends a text item with a special colour. @@ -273,7 +273,7 @@ public: Colour itemTextColour, bool isEnabled, bool isTicked, - Drawable* iconToUse); + std::unique_ptr iconToUse); /** Appends a custom menu item. @@ -344,7 +344,7 @@ public: void addSubMenu (const String& subMenuName, const PopupMenu& subMenu, bool isEnabled, - Drawable* iconToUse, + std::unique_ptr iconToUse, bool isTicked = false, int itemResultID = 0);