From 5d7622ade599e04ae71ae0064afe92a317c840b3 Mon Sep 17 00:00:00 2001 From: jules Date: Sun, 30 Sep 2012 13:39:50 +0100 Subject: [PATCH] Added methods TreeViewItem::sortSubItems() and PopupMenu::MenuItemIterator::addItemTo(). --- .../juce_gui_basics/menus/juce_PopupMenu.cpp | 8 +++++++ .../juce_gui_basics/menus/juce_PopupMenu.h | 3 +++ .../juce_gui_basics/mouse/juce_MouseEvent.h | 4 +++- .../juce_gui_basics/widgets/juce_TreeView.cpp | 2 +- .../juce_gui_basics/widgets/juce_TreeView.h | 21 +++++++++++++++++++ 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/modules/juce_gui_basics/menus/juce_PopupMenu.cpp b/modules/juce_gui_basics/menus/juce_PopupMenu.cpp index ec7b898ba3..792aef9cc3 100644 --- a/modules/juce_gui_basics/menus/juce_PopupMenu.cpp +++ b/modules/juce_gui_basics/menus/juce_PopupMenu.cpp @@ -1681,3 +1681,11 @@ bool PopupMenu::MenuItemIterator::next() return true; } + +void PopupMenu::MenuItemIterator::addItemTo (PopupMenu& targetMenu) +{ + targetMenu.items.add (new Item (itemId, itemName, isEnabled, isTicked, customImage, + customColour != nullptr ? *customColour : Colours::black, customColour != nullptr, + nullptr, + subMenu, commandManager)); +} diff --git a/modules/juce_gui_basics/menus/juce_PopupMenu.h b/modules/juce_gui_basics/menus/juce_PopupMenu.h index 54ffa478b1..0b55c8fc90 100644 --- a/modules/juce_gui_basics/menus/juce_PopupMenu.h +++ b/modules/juce_gui_basics/menus/juce_PopupMenu.h @@ -397,6 +397,9 @@ public: */ bool next(); + /** Adds an item to the target menu which has all the properties of this item. */ + void addItemTo (PopupMenu& targetMenu); + //============================================================================== String itemName; const PopupMenu* subMenu; diff --git a/modules/juce_gui_basics/mouse/juce_MouseEvent.h b/modules/juce_gui_basics/mouse/juce_MouseEvent.h index 4162c9f80d..1e829b6669 100644 --- a/modules/juce_gui_basics/mouse/juce_MouseEvent.h +++ b/modules/juce_gui_basics/mouse/juce_MouseEvent.h @@ -127,6 +127,9 @@ public: /** The time that this mouse-event occurred. */ const Time eventTime; + /** The time that the corresponding mouse-down event occurred. */ + const Time mouseDownTime; + /** The source device that generated this event. */ MouseInputSource& source; @@ -312,7 +315,6 @@ public: private: //============================================================================== const Point mouseDownPos; - const Time mouseDownTime; const uint8 numberOfClicks, wasMovedSinceMouseDown; MouseEvent& operator= (const MouseEvent&); diff --git a/modules/juce_gui_basics/widgets/juce_TreeView.cpp b/modules/juce_gui_basics/widgets/juce_TreeView.cpp index ca9b3daeb4..ba8d40e430 100644 --- a/modules/juce_gui_basics/widgets/juce_TreeView.cpp +++ b/modules/juce_gui_basics/widgets/juce_TreeView.cpp @@ -242,7 +242,7 @@ public: String getTooltip() { Rectangle pos; - if (TreeViewItem* const item = findItemAt (getMouseXYRelative().getY(), pos)) + if (TreeViewItem* const item = findItemAt (getMouseXYRelative().y, pos)) return item->getTooltip(); return owner.getTooltip(); diff --git a/modules/juce_gui_basics/widgets/juce_TreeView.h b/modules/juce_gui_basics/widgets/juce_TreeView.h index 905ceb20ce..9243339f31 100644 --- a/modules/juce_gui_basics/widgets/juce_TreeView.h +++ b/modules/juce_gui_basics/widgets/juce_TreeView.h @@ -94,6 +94,27 @@ public: */ void removeSubItem (int index, bool deleteItem = true); + /** Sorts the list of sub-items using a standard array comparator. + + This will use a comparator object to sort the elements into order. The comparator + object must have a method of the form: + @code + int compareElements (TreeViewItem* first, TreeViewItem* second); + @endcode + + ..and this method must return: + - a value of < 0 if the first comes before the second + - a value of 0 if the two objects are equivalent + - a value of > 0 if the second comes before the first + + To improve performance, the compareElements() method can be declared as static or const. + */ + template + void sortSubItems (ElementComparator& comparator) + { + subItems.sort (comparator); + } + //============================================================================== /** Returns the TreeView to which this item belongs. */ TreeView* getOwnerView() const noexcept { return ownerView; }