Browse Source

Fixed some toolbar customiser drag+drop problems.

tags/2021-05-28
jules 12 years ago
parent
commit
7590e3f1fe
11 changed files with 72 additions and 100 deletions
  1. +4
    -16
      modules/juce_gui_basics/drawables/juce_DrawableComposite.cpp
  2. +5
    -5
      modules/juce_gui_basics/filebrowser/juce_FileChooserDialogBox.h
  3. +1
    -1
      modules/juce_gui_basics/juce_gui_basics.cpp
  4. +8
    -10
      modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp
  5. +1
    -1
      modules/juce_gui_basics/mouse/juce_DragAndDropContainer.h
  6. +38
    -44
      modules/juce_gui_basics/widgets/juce_Toolbar.cpp
  7. +2
    -7
      modules/juce_gui_basics/widgets/juce_ToolbarItemComponent.cpp
  8. +0
    -1
      modules/juce_gui_basics/widgets/juce_ToolbarItemComponent.h
  9. +8
    -10
      modules/juce_gui_basics/widgets/juce_ToolbarItemPalette.cpp
  10. +4
    -4
      modules/juce_gui_basics/widgets/juce_ToolbarItemPalette.h
  11. +1
    -1
      modules/juce_gui_basics/windows/juce_DialogWindow.cpp

+ 4
- 16
modules/juce_gui_basics/drawables/juce_DrawableComposite.cpp View File

@@ -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 <const Drawable*> (other.getChildComponent(i));
if (d != nullptr)
if (const Drawable* const d = dynamic_cast <const Drawable*> (other.getChildComponent(i)))
addAndMakeVisible (d->createCopy());
}
}
DrawableComposite::~DrawableComposite()
@@ -64,13 +60,9 @@ Rectangle<float> DrawableComposite::getDrawableBounds() const
Rectangle<float> r;
for (int i = getNumChildComponents(); --i >= 0;)
{
const Drawable* const d = dynamic_cast <const Drawable*> (getChildComponent(i));
if (d != nullptr)
r = r.getUnion (d->isTransformed() ? d->getDrawableBounds().transformed (d->getTransform())
if (const Drawable* const d = dynamic_cast <const Drawable*> (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);


+ 5
- 5
modules/juce_gui_basics/filebrowser/juce_FileChooserDialogBox.h View File

@@ -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();


+ 1
- 1
modules/juce_gui_basics/juce_gui_basics.cpp View File

@@ -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"


+ 8
- 10
modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp View File

@@ -310,15 +310,13 @@ DragAndDropContainer::~DragAndDropContainer()
void DragAndDropContainer::startDragging (const var& sourceDescription,
Component* sourceComponent,
const Image& dragImage_,
Image dragImage,
const bool allowDraggingToExternalWindows,
const Point<int>* 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<int> lastMouseDown (Desktop::getLastMouseDownPosition());
const Point<int> lastMouseDown (draggingSource->getLastMouseDownPosition());
Point<int> imageOffset;
if (dragImage.isNull())
@@ -389,15 +387,15 @@ void DragAndDropContainer::startDragging (const var& sourceDescription,
}
else
{
Component* const thisComp = dynamic_cast <Component*> (this);
if (thisComp == nullptr)
if (Component* const thisComp = dynamic_cast <Component*> (this))
{
thisComp->addChildComponent (dragImageComponent);
}
else
{
jassertfalse; // Your DragAndDropContainer needs to be a Component!
return;
}
thisComp->addChildComponent (dragImageComponent);
}
static_cast <DragImageComponent*> (dragImageComponent.get())->updateLocation (false, lastMouseDown);


+ 1
- 1
modules/juce_gui_basics/mouse/juce_DragAndDropContainer.h View File

@@ -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<int>* imageOffsetFromMouse = nullptr);


+ 38
- 44
modules/juce_gui_basics/widgets/juce_Toolbar.cpp View File

@@ -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 <Spacer*> (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<ToolbarItemPalette>())
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<int> current (Desktop::getInstance().getAnimator()
.getComponentDestination (getChildComponent (newIndex)));
const Rectangle<int> current (animator.getComponentDestination (getChildComponent (newIndex)));
if (ToolbarItemComponent* const prev = getNextActiveComponent (newIndex, -1))
{
const Rectangle<int> previousPos (Desktop::getInstance().getAnimator().getComponentDestination (prev));
const Rectangle<int> 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<int> nextPos (Desktop::getInstance().getAnimator().getComponentDestination (next));
const Rectangle<int> 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 <const ToolbarItemComponent::ItemDragAndDropOverlayComponent*> (comp) != nullptr;
}
void positionNearBar()
{
const Rectangle<int> screenSize (toolbar->getParentMonitorArea());
const int tbx = toolbar->getScreenX();
const int tby = toolbar->getScreenY();
const Rectangle<int> 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);
}

+ 2
- 7
modules/juce_gui_basics/widgets/juce_ToolbarItemComponent.cpp View File

@@ -22,13 +22,8 @@
==============================================================================
*/
ToolbarItemFactory::ToolbarItemFactory()
{
}
ToolbarItemFactory::~ToolbarItemFactory()
{
}
ToolbarItemFactory::ToolbarItemFactory() {}
ToolbarItemFactory::~ToolbarItemFactory() {}
//==============================================================================
class ToolbarItemComponent::ItemDragAndDropOverlayComponent : public Component


+ 0
- 1
modules/juce_gui_basics/widgets/juce_ToolbarItemComponent.h View File

@@ -28,7 +28,6 @@
#include "../buttons/juce_Button.h"
#include "../drawables/juce_Drawable.h"
#include "juce_Toolbar.h"
class ItemDragAndDropOverlayComponent;
//==============================================================================


+ 8
- 10
modules/juce_gui_basics/widgets/juce_ToolbarItemPalette.cpp View File

@@ -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;


+ 4
- 4
modules/juce_gui_basics/widgets/juce_ToolbarItemPalette.h View File

@@ -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 <ToolbarItemComponent> 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)


+ 1
- 1
modules/juce_gui_basics/windows/juce_DialogWindow.cpp View File

@@ -80,7 +80,7 @@ public:
setResizable (options.resizable, options.useBottomRightCornerResizer);
}
void closeButtonPressed()
void closeButtonPressed() override
{
setVisible (false);
}


Loading…
Cancel
Save