| @@ -28,8 +28,8 @@ class TreeView::ContentComponent : public Component, | |||||
| public AsyncUpdater | public AsyncUpdater | ||||
| { | { | ||||
| public: | public: | ||||
| ContentComponent (TreeView& owner_) | |||||
| : owner (owner_), | |||||
| ContentComponent (TreeView& tree) | |||||
| : owner (tree), | |||||
| buttonUnderMouse (nullptr), | buttonUnderMouse (nullptr), | ||||
| isDragging (false) | isDragging (false) | ||||
| { | { | ||||
| @@ -45,27 +45,30 @@ public: | |||||
| if (TreeViewItem* const item = findItemAt (e.y, pos)) | 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 | 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); | updateButtonUnderMouse (e); | ||||
| if (needSelectionOnMouseUp && e.mouseWasClicked()) | |||||
| if (needSelectionOnMouseUp && e.mouseWasClicked() && isEnabled()) | |||||
| { | { | ||||
| Rectangle<int> pos; | Rectangle<int> pos; | ||||
| if (TreeViewItem* const item = findItemAt (e.y, pos)) | if (TreeViewItem* const item = findItemAt (e.y, pos)) | ||||
| @@ -84,7 +87,7 @@ public: | |||||
| void mouseDoubleClick (const MouseEvent& e) | void mouseDoubleClick (const MouseEvent& e) | ||||
| { | { | ||||
| if (e.getNumberOfClicks() != 3) // ignore triple clicks | |||||
| if (e.getNumberOfClicks() != 3 && isEnabled()) // ignore triple clicks | |||||
| { | { | ||||
| Rectangle<int> pos; | Rectangle<int> pos; | ||||
| if (TreeViewItem* const item = findItemAt (e.y, pos)) | if (TreeViewItem* const item = findItemAt (e.y, pos)) | ||||
| @@ -149,20 +152,21 @@ public: | |||||
| TreeViewItem* findItemAt (int y, Rectangle<int>& itemPosition) const | TreeViewItem* findItemAt (int y, Rectangle<int>& 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() | void updateComponents() | ||||
| @@ -254,8 +258,8 @@ private: | |||||
| struct RowItem | 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) | |||||
| { | { | ||||
| } | } | ||||