diff --git a/modules/juce_gui_basics/drawables/juce_DrawableComposite.cpp b/modules/juce_gui_basics/drawables/juce_DrawableComposite.cpp index 8fc71a9786..688507fd55 100644 --- a/modules/juce_gui_basics/drawables/juce_DrawableComposite.cpp +++ b/modules/juce_gui_basics/drawables/juce_DrawableComposite.cpp @@ -40,12 +40,8 @@ DrawableComposite::DrawableComposite (const DrawableComposite& other) updateBoundsReentrant (false) { for (int i = 0; i < other.getNumChildComponents(); ++i) - { - const Drawable* const d = dynamic_cast (other.getChildComponent(i)); - - if (d != nullptr) + if (const Drawable* const d = dynamic_cast (other.getChildComponent(i))) addAndMakeVisible (d->createCopy()); - } } DrawableComposite::~DrawableComposite() @@ -64,13 +60,9 @@ Rectangle DrawableComposite::getDrawableBounds() const Rectangle r; for (int i = getNumChildComponents(); --i >= 0;) - { - const Drawable* const d = dynamic_cast (getChildComponent(i)); - - if (d != nullptr) - r = r.getUnion (d->isTransformed() ? d->getDrawableBounds().transformed (d->getTransform()) + if (const Drawable* const d = dynamic_cast (getChildComponent(i))) + r = r.getUnion (d->isTransformed() ? d->getDrawableBounds().transformedBy (d->getTransform()) : d->getDrawableBounds()); - } return r; } @@ -199,12 +191,8 @@ void DrawableComposite::updateBoundsToFitChildren() originRelativeToComponent -= delta; for (int i = getNumChildComponents(); --i >= 0;) - { - Component* const c = getChildComponent(i); - - if (c != nullptr) + if (Component* const c = getChildComponent(i)) c->setBounds (c->getBounds() - delta); - } } setBounds (childArea); diff --git a/modules/juce_gui_basics/filebrowser/juce_FileChooserDialogBox.h b/modules/juce_gui_basics/filebrowser/juce_FileChooserDialogBox.h index 018f6a7c84..738c3d4445 100644 --- a/modules/juce_gui_basics/filebrowser/juce_FileChooserDialogBox.h +++ b/modules/juce_gui_basics/filebrowser/juce_FileChooserDialogBox.h @@ -140,12 +140,12 @@ private: ContentComponent* content; const bool warnAboutOverwritingExistingFiles; - void buttonClicked (Button*); + void buttonClicked (Button*) override; void closeButtonPressed(); - void selectionChanged(); - void fileClicked (const File&, const MouseEvent&); - void fileDoubleClicked (const File&); - void browserRootChanged (const File&); + void selectionChanged() override; + void fileClicked (const File&, const MouseEvent&) override; + void fileDoubleClicked (const File&) override; + void browserRootChanged (const File&) override; void okButtonPressed(); void createNewFolder(); diff --git a/modules/juce_gui_basics/juce_gui_basics.cpp b/modules/juce_gui_basics/juce_gui_basics.cpp index bd0a32f9e6..96536b0d4f 100644 --- a/modules/juce_gui_basics/juce_gui_basics.cpp +++ b/modules/juce_gui_basics/juce_gui_basics.cpp @@ -228,8 +228,8 @@ namespace juce #include "widgets/juce_TableHeaderComponent.cpp" #include "widgets/juce_TableListBox.cpp" #include "widgets/juce_TextEditor.cpp" -#include "widgets/juce_Toolbar.cpp" #include "widgets/juce_ToolbarItemComponent.cpp" +#include "widgets/juce_Toolbar.cpp" #include "widgets/juce_ToolbarItemPalette.cpp" #include "widgets/juce_TreeView.cpp" #include "windows/juce_AlertWindow.cpp" diff --git a/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp b/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp index b13e249774..ff2c49a6cd 100644 --- a/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp +++ b/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp @@ -310,15 +310,13 @@ DragAndDropContainer::~DragAndDropContainer() void DragAndDropContainer::startDragging (const var& sourceDescription, Component* sourceComponent, - const Image& dragImage_, + Image dragImage, const bool allowDraggingToExternalWindows, const Point* imageOffsetFromMouse) { - Image dragImage (dragImage_); - if (dragImageComponent == nullptr) { - MouseInputSource* draggingSource = Desktop::getInstance().getDraggingMouseSource (0); + MouseInputSource* const draggingSource = Desktop::getInstance().getDraggingMouseSource (0); if (draggingSource == nullptr || ! draggingSource->isDragging()) { @@ -326,7 +324,7 @@ void DragAndDropContainer::startDragging (const var& sourceDescription, return; } - const Point lastMouseDown (Desktop::getLastMouseDownPosition()); + const Point lastMouseDown (draggingSource->getLastMouseDownPosition()); Point imageOffset; if (dragImage.isNull()) @@ -389,15 +387,15 @@ void DragAndDropContainer::startDragging (const var& sourceDescription, } else { - Component* const thisComp = dynamic_cast (this); - - if (thisComp == nullptr) + if (Component* const thisComp = dynamic_cast (this)) + { + thisComp->addChildComponent (dragImageComponent); + } + else { jassertfalse; // Your DragAndDropContainer needs to be a Component! return; } - - thisComp->addChildComponent (dragImageComponent); } static_cast (dragImageComponent.get())->updateLocation (false, lastMouseDown); diff --git a/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.h b/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.h index b376e7cc7c..78ebf9f4bb 100644 --- a/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.h +++ b/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.h @@ -88,7 +88,7 @@ public: */ void startDragging (const var& sourceDescription, Component* sourceComponent, - const Image& dragImage = Image::null, + Image dragImage = Image::null, bool allowDraggingToOtherJuceWindows = false, const Point* imageOffsetFromMouse = nullptr); diff --git a/modules/juce_gui_basics/widgets/juce_Toolbar.cpp b/modules/juce_gui_basics/widgets/juce_Toolbar.cpp index c79e3063e7..81cde9dfff 100644 --- a/modules/juce_gui_basics/widgets/juce_Toolbar.cpp +++ b/modules/juce_gui_basics/widgets/juce_Toolbar.cpp @@ -149,14 +149,14 @@ private: class Toolbar::MissingItemsComponent : public PopupMenu::CustomComponent { public: - MissingItemsComponent (Toolbar& owner_, const int height_) + MissingItemsComponent (Toolbar& bar, const int h) : PopupMenu::CustomComponent (true), - owner (&owner_), - height (height_) + owner (&bar), + height (h) { - for (int i = owner_.items.size(); --i >= 0;) + for (int i = bar.items.size(); --i >= 0;) { - ToolbarItemComponent* const tc = owner_.items.getUnchecked(i); + ToolbarItemComponent* const tc = bar.items.getUnchecked(i); if (dynamic_cast (tc) == nullptr && ! tc->isVisible()) { @@ -501,13 +501,15 @@ void Toolbar::updateAllItemPositions (const bool animate) else newBounds.setBounds (pos, 0, size, getHeight()); + ComponentAnimator& animator = Desktop::getInstance().getAnimator(); + if (animate) { - Desktop::getInstance().getAnimator().animateComponent (tc, newBounds, 1.0f, 200, false, 3.0, 0.0); + animator.animateComponent (tc, newBounds, 1.0f, 200, false, 3.0, 0.0); } else { - Desktop::getInstance().getAnimator().cancelAnimation (tc, false); + animator.cancelAnimation (tc, false); tc->setBounds (newBounds); } @@ -548,7 +550,7 @@ void Toolbar::itemDragMove (const SourceDetails& dragSourceDetails) if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette) { if (ToolbarItemPalette* const palette = tc->findParentComponentOfClass()) - palette->replaceComponent (tc); + palette->replaceComponent (*tc); } else { @@ -560,6 +562,8 @@ void Toolbar::itemDragMove (const SourceDetails& dragSourceDetails) updateAllItemPositions (true); } + ComponentAnimator& animator = Desktop::getInstance().getAnimator(); + for (int i = getNumItems(); --i >= 0;) { const int currentIndex = items.indexOf (tc); @@ -569,12 +573,11 @@ void Toolbar::itemDragMove (const SourceDetails& dragSourceDetails) : (dragSourceDetails.localPosition.getX() - tc->dragOffsetX); const int dragObjectRight = dragObjectLeft + (vertical ? tc->getHeight() : tc->getWidth()); - const Rectangle current (Desktop::getInstance().getAnimator() - .getComponentDestination (getChildComponent (newIndex))); + const Rectangle current (animator.getComponentDestination (getChildComponent (newIndex))); if (ToolbarItemComponent* const prev = getNextActiveComponent (newIndex, -1)) { - const Rectangle previousPos (Desktop::getInstance().getAnimator().getComponentDestination (prev)); + const Rectangle previousPos (animator.getComponentDestination (prev)); if (abs (dragObjectLeft - (vertical ? previousPos.getY() : previousPos.getX()) < abs (dragObjectRight - (vertical ? current.getBottom() : current.getRight())))) @@ -585,7 +588,7 @@ void Toolbar::itemDragMove (const SourceDetails& dragSourceDetails) if (ToolbarItemComponent* const next = getNextActiveComponent (newIndex, 1)) { - const Rectangle nextPos (Desktop::getInstance().getAnimator().getComponentDestination (next)); + const Rectangle nextPos (animator.getComponentDestination (next)); if (abs (dragObjectLeft - (vertical ? current.getY() : current.getX()) > abs (dragObjectRight - (vertical ? nextPos.getBottom() : nextPos.getRight())))) @@ -625,21 +628,15 @@ void Toolbar::itemDropped (const SourceDetails& dragSourceDetails) tc->setState (Button::buttonNormal); } - -//============================================================================== -void Toolbar::mouseDown (const MouseEvent&) -{ -} +void Toolbar::mouseDown (const MouseEvent&) {} //============================================================================== class Toolbar::CustomisationDialog : public DialogWindow { public: - CustomisationDialog (ToolbarItemFactory& factory, - Toolbar* const toolbar_, - const int optionFlags) + CustomisationDialog (ToolbarItemFactory& factory, Toolbar& bar, int optionFlags) : DialogWindow (TRANS("Add/remove items from toolbar"), Colours::white, true, true), - toolbar (toolbar_) + toolbar (bar) { setContentOwned (new CustomiserPanel (factory, toolbar, optionFlags), true); setResizable (true, true); @@ -649,7 +646,7 @@ public: ~CustomisationDialog() { - toolbar->setEditingActive (false); + toolbar.setEditingActive (false); } void closeButtonPressed() override @@ -659,54 +656,51 @@ public: bool canModalEventBeSentToComponent (const Component* comp) override { - return toolbar->isParentOf (comp); + return toolbar.isParentOf (comp) + || dynamic_cast (comp) != nullptr; } void positionNearBar() { - const Rectangle screenSize (toolbar->getParentMonitorArea()); - const int tbx = toolbar->getScreenX(); - const int tby = toolbar->getScreenY(); + const Rectangle screenSize (toolbar.getParentMonitorArea()); + const int tbx = toolbar.getScreenX(); + const int tby = toolbar.getScreenY(); const int gap = 8; int x, y; - if (toolbar->isVertical()) + if (toolbar.isVertical()) { y = tby; if (tbx > screenSize.getCentreX()) x = tbx - getWidth() - gap; else - x = tbx + toolbar->getWidth() + gap; + x = tbx + toolbar.getWidth() + gap; } else { - x = tbx + (toolbar->getWidth() - getWidth()) / 2; + x = tbx + (toolbar.getWidth() - getWidth()) / 2; if (tby > screenSize.getCentreY()) y = tby - getHeight() - gap; else - y = tby + toolbar->getHeight() + gap; + y = tby + toolbar.getHeight() + gap; } setTopLeftPosition (x, y); } private: - Toolbar* const toolbar; + Toolbar& toolbar; class CustomiserPanel : public Component, private ComboBoxListener, // (can't use ComboBox::Listener due to idiotic VC2005 bug) private ButtonListener { public: - CustomiserPanel (ToolbarItemFactory& factory_, - Toolbar* const toolbar_, - const int optionFlags) - : factory (factory_), - toolbar (toolbar_), - palette (factory_, toolbar_), + CustomiserPanel (ToolbarItemFactory& tbf, Toolbar& bar, int optionFlags) + : factory (tbf), toolbar (bar), palette (tbf, bar), instructions (String::empty, TRANS ("You can drag the items above and drop them onto a toolbar to add them.") + "\n\n" + TRANS ("Items on the toolbar can also be dragged around to change their order, or dragged off the edge to delete them.")), @@ -726,7 +720,7 @@ private: if ((optionFlags & Toolbar::allowTextOnlyChoice) != 0) styleBox.addItem (TRANS("Show descriptions only"), 3); int selectedStyle = 0; - switch (toolbar_->getStyle()) + switch (bar.getStyle()) { case Toolbar::iconsOnly: selectedStyle = 1; break; case Toolbar::iconsWithText: selectedStyle = 2; break; @@ -754,9 +748,9 @@ private: { switch (styleBox.getSelectedId()) { - case 1: toolbar->setStyle (Toolbar::iconsOnly); break; - case 2: toolbar->setStyle (Toolbar::iconsWithText); break; - case 3: toolbar->setStyle (Toolbar::textOnly); break; + case 1: toolbar.setStyle (Toolbar::iconsOnly); break; + case 2: toolbar.setStyle (Toolbar::iconsWithText); break; + case 3: toolbar.setStyle (Toolbar::textOnly); break; } palette.resized(); // to make it update the styles @@ -764,7 +758,7 @@ private: void buttonClicked (Button*) override { - toolbar->addDefaultItems (factory); + toolbar.addDefaultItems (factory); } void paint (Graphics& g) override @@ -791,7 +785,7 @@ private: private: ToolbarItemFactory& factory; - Toolbar* const toolbar; + Toolbar& toolbar; ToolbarItemPalette palette; Label instructions; @@ -804,6 +798,6 @@ void Toolbar::showCustomisationDialog (ToolbarItemFactory& factory, const int op { setEditingActive (true); - (new CustomisationDialog (factory, this, optionFlags)) + (new CustomisationDialog (factory, *this, optionFlags)) ->enterModalState (true, nullptr, true); } diff --git a/modules/juce_gui_basics/widgets/juce_ToolbarItemComponent.cpp b/modules/juce_gui_basics/widgets/juce_ToolbarItemComponent.cpp index 9c4b1ea740..b51b19c6b6 100644 --- a/modules/juce_gui_basics/widgets/juce_ToolbarItemComponent.cpp +++ b/modules/juce_gui_basics/widgets/juce_ToolbarItemComponent.cpp @@ -22,13 +22,8 @@ ============================================================================== */ -ToolbarItemFactory::ToolbarItemFactory() -{ -} - -ToolbarItemFactory::~ToolbarItemFactory() -{ -} +ToolbarItemFactory::ToolbarItemFactory() {} +ToolbarItemFactory::~ToolbarItemFactory() {} //============================================================================== class ToolbarItemComponent::ItemDragAndDropOverlayComponent : public Component diff --git a/modules/juce_gui_basics/widgets/juce_ToolbarItemComponent.h b/modules/juce_gui_basics/widgets/juce_ToolbarItemComponent.h index cc6ed73d75..404c1bf2f4 100644 --- a/modules/juce_gui_basics/widgets/juce_ToolbarItemComponent.h +++ b/modules/juce_gui_basics/widgets/juce_ToolbarItemComponent.h @@ -28,7 +28,6 @@ #include "../buttons/juce_Button.h" #include "../drawables/juce_Drawable.h" #include "juce_Toolbar.h" -class ItemDragAndDropOverlayComponent; //============================================================================== diff --git a/modules/juce_gui_basics/widgets/juce_ToolbarItemPalette.cpp b/modules/juce_gui_basics/widgets/juce_ToolbarItemPalette.cpp index b5c08cb94f..8f3bb5db4c 100644 --- a/modules/juce_gui_basics/widgets/juce_ToolbarItemPalette.cpp +++ b/modules/juce_gui_basics/widgets/juce_ToolbarItemPalette.cpp @@ -22,10 +22,8 @@ ============================================================================== */ -ToolbarItemPalette::ToolbarItemPalette (ToolbarItemFactory& factory_, - Toolbar* const toolbar_) - : factory (factory_), - toolbar (toolbar_) +ToolbarItemPalette::ToolbarItemPalette (ToolbarItemFactory& tbf, Toolbar& bar) + : factory (tbf), toolbar (bar) { Component* const itemHolder = new Component(); viewport.setViewedComponent (itemHolder); @@ -58,13 +56,13 @@ void ToolbarItemPalette::addComponent (const int itemId, const int index) } } -void ToolbarItemPalette::replaceComponent (ToolbarItemComponent* const comp) +void ToolbarItemPalette::replaceComponent (ToolbarItemComponent& comp) { - const int index = items.indexOf (comp); + const int index = items.indexOf (&comp); jassert (index >= 0); - items.removeObject (comp, false); + items.removeObject (&comp, false); - addComponent (comp->getItemId(), index); + addComponent (comp.getItemId(), index); resized(); } @@ -76,7 +74,7 @@ void ToolbarItemPalette::resized() const int indent = 8; const int preferredWidth = viewport.getWidth() - viewport.getScrollBarThickness() - indent; - const int height = toolbar->getThickness(); + const int height = toolbar.getThickness(); int x = indent; int y = indent; int maxX = 0; @@ -85,7 +83,7 @@ void ToolbarItemPalette::resized() { ToolbarItemComponent* const tc = items.getUnchecked(i); - tc->setStyle (toolbar->getStyle()); + tc->setStyle (toolbar.getStyle()); int preferredSize = 1, minSize = 1, maxSize = 1; diff --git a/modules/juce_gui_basics/widgets/juce_ToolbarItemPalette.h b/modules/juce_gui_basics/widgets/juce_ToolbarItemPalette.h index 1be3c548f7..7c6b29fe79 100644 --- a/modules/juce_gui_basics/widgets/juce_ToolbarItemPalette.h +++ b/modules/juce_gui_basics/widgets/juce_ToolbarItemPalette.h @@ -53,23 +53,23 @@ public: The toolbar and factory must not be deleted while this object exists. */ ToolbarItemPalette (ToolbarItemFactory& factory, - Toolbar* toolbar); + Toolbar& toolbar); /** Destructor. */ ~ToolbarItemPalette(); //============================================================================== /** @internal */ - void resized(); + void resized() override; private: ToolbarItemFactory& factory; - Toolbar* toolbar; + Toolbar& toolbar; Viewport viewport; OwnedArray items; friend class Toolbar; - void replaceComponent (ToolbarItemComponent* comp); + void replaceComponent (ToolbarItemComponent&); void addComponent (int itemId, int index); JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ToolbarItemPalette) diff --git a/modules/juce_gui_basics/windows/juce_DialogWindow.cpp b/modules/juce_gui_basics/windows/juce_DialogWindow.cpp index 186ebfd173..bcb37234c5 100644 --- a/modules/juce_gui_basics/windows/juce_DialogWindow.cpp +++ b/modules/juce_gui_basics/windows/juce_DialogWindow.cpp @@ -80,7 +80,7 @@ public: setResizable (options.resizable, options.useBottomRightCornerResizer); } - void closeButtonPressed() + void closeButtonPressed() override { setVisible (false); }