Browse Source

Added a setHeader() method to TableListBox. New utility class TreeView::OpennessRestorer.

tags/2021-05-28
Julian Storer 14 years ago
parent
commit
c6b81ebf51
10 changed files with 148 additions and 37 deletions
  1. +1
    -5
      extras/Jucer (experimental)/Source/Project/jucer_ProjectTreeViewBase.cpp
  2. +32
    -16
      juce_amalgamated.cpp
  3. +40
    -0
      juce_amalgamated.h
  4. +18
    -6
      src/gui/components/controls/juce_TableListBox.cpp
  5. +6
    -0
      src/gui/components/controls/juce_TableListBox.h
  6. +14
    -0
      src/gui/components/controls/juce_TreeView.cpp
  7. +35
    -0
      src/gui/components/controls/juce_TreeView.h
  8. +1
    -5
      src/gui/components/keyboard/juce_KeyMappingEditorComponent.cpp
  9. +0
    -4
      src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp
  10. +1
    -1
      src/gui/graphics/drawables/juce_DrawableComposite.cpp

+ 1
- 5
extras/Jucer (experimental)/Source/Project/jucer_ProjectTreeViewBase.cpp View File

@@ -416,13 +416,9 @@ void ProjectTreeViewBase::addSubItems()
void ProjectTreeViewBase::refreshSubItems()
{
ScopedPointer <XmlElement> oldOpenness (getOpennessState());
OpennessRestorer openness (*this);
clearSubItems();
addSubItems();
if (oldOpenness != 0)
restoreOpennessState (*oldOpenness);
}
void ProjectTreeViewBase::showMultiSelectionPopupMenu()


+ 32
- 16
juce_amalgamated.cpp View File

@@ -52220,16 +52220,12 @@ private:

TableListBox::TableListBox (const String& name, TableListBoxModel* const model_)
: ListBox (name, 0),
model (model_),
header (0), model (model_),
autoSizeOptionsShown (true)
{
ListBox::model = this;

header = new TableListBoxHeader (*this);
header->setSize (100, 28);
header->addListener (this);

setHeaderComponent (header);
setHeader (new TableListBoxHeader (*this));
}

TableListBox::~TableListBox()
@@ -52246,6 +52242,22 @@ void TableListBox::setModel (TableListBoxModel* const newModel)
}
}

void TableListBox::setHeader (TableHeaderComponent* newHeader)
{
jassert (newHeader != 0); // you need to supply a real header for a table!

Rectangle<int> newBounds (0, 0, 100, 28);
if (header != 0)
newBounds = header->getBounds();

header = newHeader;
header->setBounds (newBounds);

setHeaderComponent (header);

header->addListener (this);
}

int TableListBox::getHeaderHeight() const
{
return header->getHeight();
@@ -57873,6 +57885,18 @@ XmlElement* TreeViewItem::getOpennessState() const throw()
return 0;
}

TreeViewItem::OpennessRestorer::OpennessRestorer (TreeViewItem& treeViewItem_)
: treeViewItem (treeViewItem_),
oldOpenness (treeViewItem_.getOpennessState())
{
}

TreeViewItem::OpennessRestorer::~OpennessRestorer()
{
if (oldOpenness != 0)
treeViewItem.restoreOpennessState (*oldOpenness);
}

END_JUCE_NAMESPACE
/*** End of inlined file: juce_TreeView.cpp ***/

@@ -60574,8 +60598,7 @@ public:

void changeListenerCallback (ChangeBroadcaster*)
{
const ScopedPointer <XmlElement> oldOpenness (owner.tree.getOpennessState (true));

const OpennessRestorer openness (*this);
clearSubItems();

const StringArray categories (owner.getMappings().getCommandManager()->getCommandCategories());
@@ -60592,9 +60615,6 @@ public:
if (count > 0)
addSubItem (new CategoryItem (owner, categories[i]));
}

if (oldOpenness != 0)
owner.tree.restoreOpennessState (*oldOpenness);
}

void buttonClicked (Button*)
@@ -83782,10 +83802,6 @@ END_JUCE_NAMESPACE
/*** Start of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
BEGIN_JUCE_NAMESPACE

#if (JUCE_WINDOWS || JUCE_LINUX) && ! JUCE_64BIT
#define JUCE_USE_SSE_INSTRUCTIONS 1
#endif

#if JUCE_MSVC
#pragma warning (push)
#pragma warning (disable: 4127) // "expression is constant" warning
@@ -87291,7 +87307,7 @@ const ValueTree DrawableComposite::createValueTree (ComponentBuilder::ImageProvi

ValueTree childList (v.getChildListCreating (0));

for (int i = getNumChildComponents(); --i >= 0;)
for (int i = 0; i < getNumChildComponents(); ++i)
{
const Drawable* const d = dynamic_cast <const Drawable*> (getChildComponent(i));
jassert (d != 0); // You can't save a mix of Drawables and normal components!


+ 40
- 0
juce_amalgamated.h View File

@@ -50025,6 +50025,12 @@ public:
/** Returns the header component being used in this table. */
TableHeaderComponent& getHeader() const { return *header; }

/** Sets the header component to use for the table.
The table will take ownership of the component that you pass in, and will delete it
when it's no longer needed.
*/
void setHeader (TableHeaderComponent* newHeader);

/** Changes the height of the table header component.
@see getHeaderHeight
*/
@@ -50781,6 +50787,40 @@ public:
*/
const String getItemIdentifierString() const;

/**
This handy class takes a copy of a TreeViewItem's openness when you create it,
and restores that openness state when its destructor is called.

This can very handy when you're refreshing sub-items - e.g.
@code
void MyTreeViewItem::updateChildItems()
{
OpennessRestorer openness (*this); // saves the openness state here..

clearSubItems();

// add a bunch of sub-items here which may or may not be the same as the ones that
// were previously there
addSubItem (...

// ..and at this point, the old openness is restored, so any items that haven't
// changed will have their old openness retained.
}
@endcode
*/
class OpennessRestorer
{
public:
OpennessRestorer (TreeViewItem& treeViewItem);
~OpennessRestorer();

private:
TreeViewItem& treeViewItem;
ScopedPointer <XmlElement> oldOpenness;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpennessRestorer);
};

private:

TreeView* ownerView;


+ 18
- 6
src/gui/components/controls/juce_TableListBox.cpp View File

@@ -268,16 +268,12 @@ private:
//==============================================================================
TableListBox::TableListBox (const String& name, TableListBoxModel* const model_)
: ListBox (name, 0),
model (model_),
header (0), model (model_),
autoSizeOptionsShown (true)
{
ListBox::model = this;
header = new TableListBoxHeader (*this);
header->setSize (100, 28);
header->addListener (this);
setHeaderComponent (header);
setHeader (new TableListBoxHeader (*this));
}
TableListBox::~TableListBox()
@@ -294,6 +290,22 @@ void TableListBox::setModel (TableListBoxModel* const newModel)
}
}
void TableListBox::setHeader (TableHeaderComponent* newHeader)
{
jassert (newHeader != 0); // you need to supply a real header for a table!
Rectangle<int> newBounds (0, 0, 100, 28);
if (header != 0)
newBounds = header->getBounds();
header = newHeader;
header->setBounds (newBounds);
setHeaderComponent (header);
header->addListener (this);
}
int TableListBox::getHeaderHeight() const
{
return header->getHeight();


+ 6
- 0
src/gui/components/controls/juce_TableListBox.h View File

@@ -226,6 +226,12 @@ public:
/** Returns the header component being used in this table. */
TableHeaderComponent& getHeader() const { return *header; }
/** Sets the header component to use for the table.
The table will take ownership of the component that you pass in, and will delete it
when it's no longer needed.
*/
void setHeader (TableHeaderComponent* newHeader);
/** Changes the height of the table header component.
@see getHeaderHeight
*/


+ 14
- 0
src/gui/components/controls/juce_TreeView.cpp View File

@@ -1800,4 +1800,18 @@ XmlElement* TreeViewItem::getOpennessState() const throw()
return 0;
}
//==============================================================================
TreeViewItem::OpennessRestorer::OpennessRestorer (TreeViewItem& treeViewItem_)
: treeViewItem (treeViewItem_),
oldOpenness (treeViewItem_.getOpennessState())
{
}
TreeViewItem::OpennessRestorer::~OpennessRestorer()
{
if (oldOpenness != 0)
treeViewItem.restoreOpennessState (*oldOpenness);
}
END_JUCE_NAMESPACE

+ 35
- 0
src/gui/components/controls/juce_TreeView.h View File

@@ -457,6 +457,41 @@ public:
*/
const String getItemIdentifierString() const;
//==============================================================================
/**
This handy class takes a copy of a TreeViewItem's openness when you create it,
and restores that openness state when its destructor is called.
This can very handy when you're refreshing sub-items - e.g.
@code
void MyTreeViewItem::updateChildItems()
{
OpennessRestorer openness (*this); // saves the openness state here..
clearSubItems();
// add a bunch of sub-items here which may or may not be the same as the ones that
// were previously there
addSubItem (...
// ..and at this point, the old openness is restored, so any items that haven't
// changed will have their old openness retained.
}
@endcode
*/
class OpennessRestorer
{
public:
OpennessRestorer (TreeViewItem& treeViewItem);
~OpennessRestorer();
private:
TreeViewItem& treeViewItem;
ScopedPointer <XmlElement> oldOpenness;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpennessRestorer);
};
private:
//==============================================================================
TreeView* ownerView;


+ 1
- 5
src/gui/components/keyboard/juce_KeyMappingEditorComponent.cpp View File

@@ -353,8 +353,7 @@ public:
void changeListenerCallback (ChangeBroadcaster*)
{
const ScopedPointer <XmlElement> oldOpenness (owner.tree.getOpennessState (true));
const OpennessRestorer openness (*this);
clearSubItems();
const StringArray categories (owner.getMappings().getCommandManager()->getCommandCategories());
@@ -371,9 +370,6 @@ public:
if (count > 0)
addSubItem (new CategoryItem (owner, categories[i]));
}
if (oldOpenness != 0)
owner.tree.restoreOpennessState (*oldOpenness);
}
void buttonClicked (Button*)


+ 0
- 4
src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp View File

@@ -37,10 +37,6 @@ BEGIN_JUCE_NAMESPACE
#include "../../../core/juce_Singleton.h"
#include "../../../utilities/juce_DeletedAtShutdown.h"
#if (JUCE_WINDOWS || JUCE_LINUX) && ! JUCE_64BIT
#define JUCE_USE_SSE_INSTRUCTIONS 1
#endif
#if JUCE_MSVC
#pragma warning (push)
#pragma warning (disable: 4127) // "expression is constant" warning


+ 1
- 1
src/gui/graphics/drawables/juce_DrawableComposite.cpp View File

@@ -333,7 +333,7 @@ const ValueTree DrawableComposite::createValueTree (ComponentBuilder::ImageProvi
ValueTree childList (v.getChildListCreating (0));
for (int i = getNumChildComponents(); --i >= 0;)
for (int i = 0; i < getNumChildComponents(); ++i)
{
const Drawable* const d = dynamic_cast <const Drawable*> (getChildComponent(i));
jassert (d != 0); // You can't save a mix of Drawables and normal components!


Loading…
Cancel
Save