Browse Source

tags/2021-05-28
jules 17 years ago
parent
commit
e92eb30e0f
3 changed files with 44 additions and 44 deletions
  1. +40
    -43
      src/juce_appframework/gui/components/controls/juce_Toolbar.cpp
  2. +3
    -0
      src/juce_appframework/gui/components/controls/juce_Toolbar.h
  3. +1
    -1
      src/juce_appframework/gui/components/juce_Component.cpp

+ 40
- 43
src/juce_appframework/gui/components/controls/juce_Toolbar.cpp View File

@@ -185,11 +185,11 @@ public:
owner (owner_), owner (owner_),
height (height_) height (height_)
{ {
for (int i = owner_.getNumChildComponents(); --i >= 0;)
for (int i = owner_.items.size(); --i >= 0;)
{ {
ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (owner_.getChildComponent (i));
ToolbarItemComponent* const tc = owner_.items.getUnchecked(i);
if (tc != 0 && dynamic_cast <ToolbarSpacerComp*> (tc) == 0 && ! tc->isVisible())
if (dynamic_cast <ToolbarSpacerComp*> (tc) == 0 && ! tc->isVisible())
{ {
oldIndexes.insert (0, i); oldIndexes.insert (0, i);
addAndMakeVisible (tc, 0); addAndMakeVisible (tc, 0);
@@ -211,7 +211,9 @@ public:
if (tc != 0) if (tc != 0)
{ {
tc->setVisible (false); tc->setVisible (false);
owner.addChildComponent (tc, oldIndexes.remove (i));
const int index = oldIndexes.remove (i);
owner.items.insert (index, tc);
owner.addChildComponent (tc, index);
--i; --i;
} }
} }
@@ -300,11 +302,11 @@ void Toolbar::setVertical (const bool shouldBeVertical)
void Toolbar::clear() void Toolbar::clear()
{ {
for (int i = getNumChildComponents(); --i >= 0;)
for (int i = items.size(); --i >= 0;)
{ {
ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
if (tc != 0)
delete tc;
ToolbarItemComponent* const tc = items.getUnchecked(i);
items.remove (i);
delete tc;
} }
resized(); resized();
@@ -342,6 +344,7 @@ void Toolbar::addItemInternal (ToolbarItemFactory& factory,
jassert (allowedIds.contains (itemId)); jassert (allowedIds.contains (itemId));
#endif #endif
items.insert (insertIndex, tc);
addAndMakeVisible (tc, insertIndex); addAndMakeVisible (tc, insertIndex);
} }
} }
@@ -373,6 +376,7 @@ void Toolbar::removeToolbarItem (const int itemIndex)
if (tc != 0) if (tc != 0)
{ {
items.removeValue (tc);
delete tc; delete tc;
resized(); resized();
} }
@@ -380,7 +384,7 @@ void Toolbar::removeToolbarItem (const int itemIndex)
int Toolbar::getNumItems() const throw() int Toolbar::getNumItems() const throw()
{ {
return getNumChildComponents() - 1;
return items.size();
} }
int Toolbar::getItemId (const int itemIndex) const throw() int Toolbar::getItemId (const int itemIndex) const throw()
@@ -391,10 +395,7 @@ int Toolbar::getItemId (const int itemIndex) const throw()
ToolbarItemComponent* Toolbar::getItemComponent (const int itemIndex) const throw() ToolbarItemComponent* Toolbar::getItemComponent (const int itemIndex) const throw()
{ {
if (itemIndex < getNumItems())
return dynamic_cast <ToolbarItemComponent*> (getChildComponent (itemIndex));
return 0;
return items [itemIndex];
} }
ToolbarItemComponent* Toolbar::getNextActiveComponent (int index, const int delta) const ToolbarItemComponent* Toolbar::getNextActiveComponent (int index, const int delta) const
@@ -487,40 +488,31 @@ void Toolbar::updateAllItemPositions (const bool animate)
{ {
StretchableObjectResizer resizer; StretchableObjectResizer resizer;
const int numComponents = getNumChildComponents();
Array <ToolbarItemComponent*> activeComps;
int i; int i;
for (i = 0; i < numComponents; ++i)
for (i = 0; i < items.size(); ++i)
{ {
ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
ToolbarItemComponent* const tc = items.getUnchecked(i);
// have you added a component directly to the toolbar? That's not advisable! Only use addCustomToolbarItem()!
jassert (tc != 0 || getChildComponent(i) == missingItemsButton);
tc->setEditingMode (isEditingActive ? ToolbarItemComponent::editableOnToolbar
: ToolbarItemComponent::normalMode);
if (tc != 0)
{
tc->setEditingMode (isEditingActive ? ToolbarItemComponent::editableOnToolbar
: ToolbarItemComponent::normalMode);
tc->setStyle (toolbarStyle);
tc->setStyle (toolbarStyle);
ToolbarSpacerComp* const spacer = dynamic_cast <ToolbarSpacerComp*> (tc);
ToolbarSpacerComp* const spacer = dynamic_cast <ToolbarSpacerComp*> (tc);
int preferredSize = 1, minSize = 1, maxSize = 1;
int preferredSize = 1, minSize = 1, maxSize = 1;
if (tc->getToolbarItemSizes (getThickness(), isVertical(),
preferredSize, minSize, maxSize))
{
tc->isActive = true;
resizer.addItem (preferredSize, minSize, maxSize,
spacer != 0 ? spacer->getResizeOrder() : 2);
}
else
{
tc->isActive = false;
tc->setVisible (false);
}
if (tc->getToolbarItemSizes (getThickness(), isVertical(),
preferredSize, minSize, maxSize))
{
tc->isActive = true;
resizer.addItem (preferredSize, minSize, maxSize,
spacer != 0 ? spacer->getResizeOrder() : 2);
}
else
{
tc->isActive = false;
tc->setVisible (false);
} }
} }
@@ -550,11 +542,11 @@ void Toolbar::updateAllItemPositions (const bool animate)
: getLength(); : getLength();
int pos = 0, activeIndex = 0; int pos = 0, activeIndex = 0;
for (i = 0; i < getNumChildComponents(); ++i)
for (i = 0; i < items.size(); ++i)
{ {
ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
ToolbarItemComponent* const tc = items.getUnchecked(i);
if (tc != 0 && tc->isActive)
if (tc->isActive)
{ {
const int size = (int) resizer.getItemSize (activeIndex++); const int size = (int) resizer.getItemSize (activeIndex++);
@@ -623,6 +615,7 @@ void Toolbar::itemDragMove (const String&, Component* sourceComponent, int x, in
jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar); jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
} }
items.add (tc);
addChildComponent (tc); addChildComponent (tc);
updateAllItemPositions (false); updateAllItemPositions (false);
} }
@@ -646,6 +639,7 @@ void Toolbar::itemDragMove (const String&, Component* sourceComponent, int x, in
jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar); jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
} }
items.add (tc);
addChildComponent (tc); addChildComponent (tc);
currentIndex = getIndexOfChildComponent (tc); currentIndex = getIndexOfChildComponent (tc);
updateAllItemPositions (true); updateAllItemPositions (true);
@@ -684,8 +678,10 @@ void Toolbar::itemDragMove (const String&, Component* sourceComponent, int x, in
if (newIndex != currentIndex) if (newIndex != currentIndex)
{ {
items.removeValue (tc);
removeChildComponent (tc); removeChildComponent (tc);
addChildComponent (tc, newIndex); addChildComponent (tc, newIndex);
items.insert (newIndex, tc);
updateAllItemPositions (true); updateAllItemPositions (true);
} }
else else
@@ -705,6 +701,7 @@ void Toolbar::itemDragExit (const String&, Component* sourceComponent)
{ {
if (isParentOf (tc)) if (isParentOf (tc))
{ {
items.removeValue (tc);
removeChildComponent (tc); removeChildComponent (tc);
updateAllItemPositions (true); updateAllItemPositions (true);
} }


+ 3
- 0
src/juce_appframework/gui/components/controls/juce_Toolbar.h View File

@@ -37,6 +37,7 @@
#include "../buttons/juce_Button.h" #include "../buttons/juce_Button.h"
class ToolbarItemComponent; class ToolbarItemComponent;
class ToolbarItemFactory; class ToolbarItemFactory;
class MissingItemsComponent;
//============================================================================== //==============================================================================
@@ -304,6 +305,8 @@ private:
bool vertical, isEditingActive; bool vertical, isEditingActive;
ToolbarItemStyle toolbarStyle; ToolbarItemStyle toolbarStyle;
ComponentAnimator animator; ComponentAnimator animator;
friend class MissingItemsComponent;
Array <ToolbarItemComponent*> items;
friend class ItemDragAndDropOverlayComponent; friend class ItemDragAndDropOverlayComponent;
static const tchar* const toolbarDragDescriptor; static const tchar* const toolbarDragDescriptor;


+ 1
- 1
src/juce_appframework/gui/components/juce_Component.cpp View File

@@ -1195,7 +1195,7 @@ void Component::addChildComponent (Component* const child, int zOrder)
if (! child->isAlwaysOnTop()) if (! child->isAlwaysOnTop())
{ {
if (zOrder < 0)
if (zOrder < 0 || zOrder > childComponentList_.size())
zOrder = childComponentList_.size(); zOrder = childComponentList_.size();
while (zOrder > 0) while (zOrder > 0)


Loading…
Cancel
Save