From 152d91fa9e139553300fb1cf5090d37c18588cda Mon Sep 17 00:00:00 2001 From: jules Date: Mon, 18 Mar 2013 21:13:07 +0000 Subject: [PATCH] Prevented TreeViews from responding to mouse clicks when they're disabled. --- .../juce_gui_basics/widgets/juce_TreeView.cpp | 72 ++++++++++--------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/modules/juce_gui_basics/widgets/juce_TreeView.cpp b/modules/juce_gui_basics/widgets/juce_TreeView.cpp index 8c5a5cdd8b..5aaf52ad2d 100644 --- a/modules/juce_gui_basics/widgets/juce_TreeView.cpp +++ b/modules/juce_gui_basics/widgets/juce_TreeView.cpp @@ -28,8 +28,8 @@ class TreeView::ContentComponent : public Component, public AsyncUpdater { public: - ContentComponent (TreeView& owner_) - : owner (owner_), + ContentComponent (TreeView& tree) + : owner (tree), buttonUnderMouse (nullptr), isDragging (false) { @@ -45,27 +45,30 @@ public: if (TreeViewItem* const item = findItemAt (e.y, pos)) { - // (if the open/close buttons are hidden, we'll treat clicks to the left of the item - // as selection clicks) - if (e.x < pos.getX() && owner.openCloseButtonsVisible) + if (isEnabled()) { - if (e.x >= pos.getX() - owner.getIndentSize()) - item->setOpen (! item->isOpen()); + // (if the open/close buttons are hidden, we'll treat clicks to the left of the item + // as selection clicks) + if (e.x < pos.getX() && owner.openCloseButtonsVisible) + { + if (e.x >= pos.getX() - owner.getIndentSize()) + item->setOpen (! item->isOpen()); - // (clicks to the left of an open/close button are ignored) - } - else - { - // mouse-down inside the body of the item.. - if (! owner.isMultiSelectEnabled()) - item->setSelected (true, true); - else if (item->isSelected()) - needSelectionOnMouseUp = ! e.mods.isPopupMenu(); + // (clicks to the left of an open/close button are ignored) + } else - selectBasedOnModifiers (item, e.mods); + { + // mouse-down inside the body of the item.. + if (! owner.isMultiSelectEnabled()) + item->setSelected (true, true); + else if (item->isSelected()) + needSelectionOnMouseUp = ! e.mods.isPopupMenu(); + else + selectBasedOnModifiers (item, e.mods); - if (e.x >= pos.getX()) - item->itemClicked (e.withNewPosition (e.getPosition() - pos.getPosition())); + if (e.x >= pos.getX()) + item->itemClicked (e.withNewPosition (e.getPosition() - pos.getPosition())); + } } } } @@ -74,7 +77,7 @@ public: { updateButtonUnderMouse (e); - if (needSelectionOnMouseUp && e.mouseWasClicked()) + if (needSelectionOnMouseUp && e.mouseWasClicked() && isEnabled()) { Rectangle pos; if (TreeViewItem* const item = findItemAt (e.y, pos)) @@ -84,7 +87,7 @@ public: void mouseDoubleClick (const MouseEvent& e) { - if (e.getNumberOfClicks() != 3) // ignore triple clicks + if (e.getNumberOfClicks() != 3 && isEnabled()) // ignore triple clicks { Rectangle pos; if (TreeViewItem* const item = findItemAt (e.y, pos)) @@ -149,20 +152,21 @@ public: TreeViewItem* findItemAt (int y, Rectangle& itemPosition) const { - if (owner.rootItem == nullptr) - return nullptr; - - owner.recalculateIfNeeded(); - - if (! owner.rootItemVisible) - y += owner.rootItem->itemHeight; + if (owner.rootItem != nullptr) + { + owner.recalculateIfNeeded(); - TreeViewItem* const ti = owner.rootItem->findItemRecursively (y); + if (! owner.rootItemVisible) + y += owner.rootItem->itemHeight; - if (ti != nullptr) - itemPosition = ti->getItemPosition (false); + if (TreeViewItem* const ti = owner.rootItem->findItemRecursively (y)) + { + itemPosition = ti->getItemPosition (false); + return ti; + } + } - return ti; + return nullptr; } void updateComponents() @@ -254,8 +258,8 @@ private: struct RowItem { - RowItem (TreeViewItem* const item_, Component* const component_, const int itemUID) - : component (component_), item (item_), uid (itemUID), shouldKeep (true) + RowItem (TreeViewItem* const it, Component* const c, const int itemUID) + : component (c), item (it), uid (itemUID), shouldKeep (true) { }