Browse Source

Added methods TreeViewItem::sortSubItems() and PopupMenu::MenuItemIterator::addItemTo().

tags/2021-05-28
jules 13 years ago
parent
commit
5d7622ade5
5 changed files with 36 additions and 2 deletions
  1. +8
    -0
      modules/juce_gui_basics/menus/juce_PopupMenu.cpp
  2. +3
    -0
      modules/juce_gui_basics/menus/juce_PopupMenu.h
  3. +3
    -1
      modules/juce_gui_basics/mouse/juce_MouseEvent.h
  4. +1
    -1
      modules/juce_gui_basics/widgets/juce_TreeView.cpp
  5. +21
    -0
      modules/juce_gui_basics/widgets/juce_TreeView.h

+ 8
- 0
modules/juce_gui_basics/menus/juce_PopupMenu.cpp View File

@@ -1681,3 +1681,11 @@ bool PopupMenu::MenuItemIterator::next()
return true; 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));
}

+ 3
- 0
modules/juce_gui_basics/menus/juce_PopupMenu.h View File

@@ -397,6 +397,9 @@ public:
*/ */
bool next(); bool next();
/** Adds an item to the target menu which has all the properties of this item. */
void addItemTo (PopupMenu& targetMenu);
//============================================================================== //==============================================================================
String itemName; String itemName;
const PopupMenu* subMenu; const PopupMenu* subMenu;


+ 3
- 1
modules/juce_gui_basics/mouse/juce_MouseEvent.h View File

@@ -127,6 +127,9 @@ public:
/** The time that this mouse-event occurred. */ /** The time that this mouse-event occurred. */
const Time eventTime; const Time eventTime;
/** The time that the corresponding mouse-down event occurred. */
const Time mouseDownTime;
/** The source device that generated this event. */ /** The source device that generated this event. */
MouseInputSource& source; MouseInputSource& source;
@@ -312,7 +315,6 @@ public:
private: private:
//============================================================================== //==============================================================================
const Point<int> mouseDownPos; const Point<int> mouseDownPos;
const Time mouseDownTime;
const uint8 numberOfClicks, wasMovedSinceMouseDown; const uint8 numberOfClicks, wasMovedSinceMouseDown;
MouseEvent& operator= (const MouseEvent&); MouseEvent& operator= (const MouseEvent&);


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

@@ -242,7 +242,7 @@ public:
String getTooltip() String getTooltip()
{ {
Rectangle<int> pos; Rectangle<int> pos;
if (TreeViewItem* const item = findItemAt (getMouseXYRelative().getY(), pos))
if (TreeViewItem* const item = findItemAt (getMouseXYRelative().y, pos))
return item->getTooltip(); return item->getTooltip();
return owner.getTooltip(); return owner.getTooltip();


+ 21
- 0
modules/juce_gui_basics/widgets/juce_TreeView.h View File

@@ -94,6 +94,27 @@ public:
*/ */
void removeSubItem (int index, bool deleteItem = true); 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 <class ElementComparator>
void sortSubItems (ElementComparator& comparator)
{
subItems.sort (comparator);
}
//============================================================================== //==============================================================================
/** Returns the TreeView to which this item belongs. */ /** Returns the TreeView to which this item belongs. */
TreeView* getOwnerView() const noexcept { return ownerView; } TreeView* getOwnerView() const noexcept { return ownerView; }


Loading…
Cancel
Save