From c6b81ebf51738623e8ce278c85872bb4a21c6917 Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Tue, 25 Jan 2011 19:09:44 +0000 Subject: [PATCH] Added a setHeader() method to TableListBox. New utility class TreeView::OpennessRestorer. --- .../Project/jucer_ProjectTreeViewBase.cpp | 6 +-- juce_amalgamated.cpp | 48 ++++++++++++------- juce_amalgamated.h | 40 ++++++++++++++++ .../components/controls/juce_TableListBox.cpp | 24 +++++++--- .../components/controls/juce_TableListBox.h | 6 +++ src/gui/components/controls/juce_TreeView.cpp | 14 ++++++ src/gui/components/controls/juce_TreeView.h | 35 ++++++++++++++ .../juce_KeyMappingEditorComponent.cpp | 6 +-- .../juce_LowLevelGraphicsSoftwareRenderer.cpp | 4 -- .../drawables/juce_DrawableComposite.cpp | 2 +- 10 files changed, 148 insertions(+), 37 deletions(-) diff --git a/extras/Jucer (experimental)/Source/Project/jucer_ProjectTreeViewBase.cpp b/extras/Jucer (experimental)/Source/Project/jucer_ProjectTreeViewBase.cpp index 2ffb154cb6..3e42f655a9 100644 --- a/extras/Jucer (experimental)/Source/Project/jucer_ProjectTreeViewBase.cpp +++ b/extras/Jucer (experimental)/Source/Project/jucer_ProjectTreeViewBase.cpp @@ -416,13 +416,9 @@ void ProjectTreeViewBase::addSubItems() void ProjectTreeViewBase::refreshSubItems() { - ScopedPointer oldOpenness (getOpennessState()); - + OpennessRestorer openness (*this); clearSubItems(); addSubItems(); - - if (oldOpenness != 0) - restoreOpennessState (*oldOpenness); } void ProjectTreeViewBase::showMultiSelectionPopupMenu() diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index 2b11a63ffd..2e4b2562b9 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -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 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 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 (getChildComponent(i)); jassert (d != 0); // You can't save a mix of Drawables and normal components! diff --git a/juce_amalgamated.h b/juce_amalgamated.h index 6294973680..9c43b7c6e1 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -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 oldOpenness; + + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpennessRestorer); + }; + private: TreeView* ownerView; diff --git a/src/gui/components/controls/juce_TableListBox.cpp b/src/gui/components/controls/juce_TableListBox.cpp index e22bd4ef4c..81dfebed6f 100644 --- a/src/gui/components/controls/juce_TableListBox.cpp +++ b/src/gui/components/controls/juce_TableListBox.cpp @@ -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 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(); diff --git a/src/gui/components/controls/juce_TableListBox.h b/src/gui/components/controls/juce_TableListBox.h index 9fd316b584..fa4b32fc92 100644 --- a/src/gui/components/controls/juce_TableListBox.h +++ b/src/gui/components/controls/juce_TableListBox.h @@ -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 */ diff --git a/src/gui/components/controls/juce_TreeView.cpp b/src/gui/components/controls/juce_TreeView.cpp index 203d23735c..787b03977b 100644 --- a/src/gui/components/controls/juce_TreeView.cpp +++ b/src/gui/components/controls/juce_TreeView.cpp @@ -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 diff --git a/src/gui/components/controls/juce_TreeView.h b/src/gui/components/controls/juce_TreeView.h index fbd1fa8b9b..486aed714e 100644 --- a/src/gui/components/controls/juce_TreeView.h +++ b/src/gui/components/controls/juce_TreeView.h @@ -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 oldOpenness; + + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpennessRestorer); + }; + private: //============================================================================== TreeView* ownerView; diff --git a/src/gui/components/keyboard/juce_KeyMappingEditorComponent.cpp b/src/gui/components/keyboard/juce_KeyMappingEditorComponent.cpp index cc57ada9b0..6f8d703b80 100644 --- a/src/gui/components/keyboard/juce_KeyMappingEditorComponent.cpp +++ b/src/gui/components/keyboard/juce_KeyMappingEditorComponent.cpp @@ -353,8 +353,7 @@ public: void changeListenerCallback (ChangeBroadcaster*) { - const ScopedPointer 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*) diff --git a/src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp b/src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp index b3b1f03e82..0e2ce33ae0 100644 --- a/src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp +++ b/src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp @@ -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 diff --git a/src/gui/graphics/drawables/juce_DrawableComposite.cpp b/src/gui/graphics/drawables/juce_DrawableComposite.cpp index 873074d62d..99d75d42c7 100644 --- a/src/gui/graphics/drawables/juce_DrawableComposite.cpp +++ b/src/gui/graphics/drawables/juce_DrawableComposite.cpp @@ -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 (getChildComponent(i)); jassert (d != 0); // You can't save a mix of Drawables and normal components!