Add remaining files
[juce-lv2.git] / juce / source / src / gui / components / controls / juce_TreeView.h
blob7ed7fcda638e2de1a8d05000cea74a3b10ff28db
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCE_TREEVIEW_JUCEHEADER__
27 #define __JUCE_TREEVIEW_JUCEHEADER__
29 #include "../layout/juce_Viewport.h"
30 #include "../../../text/juce_XmlElement.h"
31 #include "../../../events/juce_AsyncUpdater.h"
32 #include "../mouse/juce_FileDragAndDropTarget.h"
33 #include "../mouse/juce_DragAndDropTarget.h"
34 class TreeView;
37 //==============================================================================
38 /**
39 An item in a treeview.
41 A TreeViewItem can either be a leaf-node in the tree, or it can contain its
42 own sub-items.
44 To implement an item that contains sub-items, override the itemOpennessChanged()
45 method so that when it is opened, it adds the new sub-items to itself using the
46 addSubItem method. Depending on the nature of the item it might choose to only
47 do this the first time it's opened, or it might want to refresh itself each time.
48 It also has the option of deleting its sub-items when it is closed, or leaving them
49 in place.
51 class JUCE_API TreeViewItem
53 public:
54 //==============================================================================
55 /** Constructor. */
56 TreeViewItem();
58 /** Destructor. */
59 virtual ~TreeViewItem();
61 //==============================================================================
62 /** Returns the number of sub-items that have been added to this item.
64 Note that this doesn't mean much if the node isn't open.
66 @see getSubItem, mightContainSubItems, addSubItem
68 int getNumSubItems() const noexcept;
70 /** Returns one of the item's sub-items.
72 Remember that the object returned might get deleted at any time when its parent
73 item is closed or refreshed, depending on the nature of the items you're using.
75 @see getNumSubItems
77 TreeViewItem* getSubItem (int index) const noexcept;
79 /** Removes any sub-items. */
80 void clearSubItems();
82 /** Adds a sub-item.
84 @param newItem the object to add to the item's sub-item list. Once added, these can be
85 found using getSubItem(). When the items are later removed with
86 removeSubItem() (or when this item is deleted), they will be deleted.
87 @param insertPosition the index which the new item should have when it's added. If this
88 value is less than 0, the item will be added to the end of the list.
90 void addSubItem (TreeViewItem* newItem, int insertPosition = -1);
92 /** Removes one of the sub-items.
94 @param index the item to remove
95 @param deleteItem if true, the item that is removed will also be deleted.
97 void removeSubItem (int index, bool deleteItem = true);
99 //==============================================================================
100 /** Returns the TreeView to which this item belongs. */
101 TreeView* getOwnerView() const noexcept { return ownerView; }
103 /** Returns the item within which this item is contained. */
104 TreeViewItem* getParentItem() const noexcept { return parentItem; }
106 //==============================================================================
107 /** True if this item is currently open in the treeview. */
108 bool isOpen() const noexcept;
110 /** Opens or closes the item.
112 When opened or closed, the item's itemOpennessChanged() method will be called,
113 and a subclass should use this callback to create and add any sub-items that
114 it needs to.
116 @see itemOpennessChanged, mightContainSubItems
118 void setOpen (bool shouldBeOpen);
120 /** True if this item is currently selected.
122 Use this when painting the node, to decide whether to draw it as selected or not.
124 bool isSelected() const noexcept;
126 /** Selects or deselects the item.
128 This will cause a callback to itemSelectionChanged()
130 void setSelected (bool shouldBeSelected,
131 bool deselectOtherItemsFirst);
133 /** Returns the rectangle that this item occupies.
135 If relativeToTreeViewTopLeft is true, the co-ordinates are relative to the
136 top-left of the TreeView comp, so this will depend on the scroll-position of
137 the tree. If false, it is relative to the top-left of the topmost item in the
138 tree (so this would be unaffected by scrolling the view).
140 const Rectangle<int> getItemPosition (bool relativeToTreeViewTopLeft) const noexcept;
142 /** Sends a signal to the treeview to make it refresh itself.
144 Call this if your items have changed and you want the tree to update to reflect
145 this.
147 void treeHasChanged() const noexcept;
149 /** Sends a repaint message to redraw just this item.
151 Note that you should only call this if you want to repaint a superficial change. If
152 you're altering the tree's nodes, you should instead call treeHasChanged().
154 void repaintItem() const;
156 /** Returns the row number of this item in the tree.
158 The row number of an item will change according to which items are open.
160 @see TreeView::getNumRowsInTree(), TreeView::getItemOnRow()
162 int getRowNumberInTree() const noexcept;
164 /** Returns true if all the item's parent nodes are open.
166 This is useful to check whether the item might actually be visible or not.
168 bool areAllParentsOpen() const noexcept;
170 /** Changes whether lines are drawn to connect any sub-items to this item.
172 By default, line-drawing is turned on.
174 void setLinesDrawnForSubItems (bool shouldDrawLines) noexcept;
176 //==============================================================================
177 /** Tells the tree whether this item can potentially be opened.
179 If your item could contain sub-items, this should return true; if it returns
180 false then the tree will not try to open the item. This determines whether or
181 not the item will be drawn with a 'plus' button next to it.
183 virtual bool mightContainSubItems() = 0;
185 /** Returns a string to uniquely identify this item.
187 If you're planning on using the TreeView::getOpennessState() method, then
188 these strings will be used to identify which nodes are open. The string
189 should be unique amongst the item's sibling items, but it's ok for there
190 to be duplicates at other levels of the tree.
192 If you're not going to store the state, then it's ok not to bother implementing
193 this method.
195 virtual const String getUniqueName() const;
197 /** Called when an item is opened or closed.
199 When setOpen() is called and the item has specified that it might
200 have sub-items with the mightContainSubItems() method, this method
201 is called to let the item create or manage its sub-items.
203 So when this is called with isNowOpen set to true (i.e. when the item is being
204 opened), a subclass might choose to use clearSubItems() and addSubItem() to
205 refresh its sub-item list.
207 When this is called with isNowOpen set to false, the subclass might want
208 to use clearSubItems() to save on space, or it might choose to leave them,
209 depending on the nature of the tree.
211 You could also use this callback as a trigger to start a background process
212 which asynchronously creates sub-items and adds them, if that's more
213 appropriate for the task in hand.
215 @see mightContainSubItems
217 virtual void itemOpennessChanged (bool isNowOpen);
219 /** Must return the width required by this item.
221 If your item needs to have a particular width in pixels, return that value; if
222 you'd rather have it just fill whatever space is available in the treeview,
223 return -1.
225 If all your items return -1, no horizontal scrollbar will be shown, but if any
226 items have fixed widths and extend beyond the width of the treeview, a
227 scrollbar will appear.
229 Each item can be a different width, but if they change width, you should call
230 treeHasChanged() to update the tree.
232 virtual int getItemWidth() const { return -1; }
234 /** Must return the height required by this item.
236 This is the height in pixels that the item will take up. Items in the tree
237 can be different heights, but if they change height, you should call
238 treeHasChanged() to update the tree.
240 virtual int getItemHeight() const { return 20; }
242 /** You can override this method to return false if you don't want to allow the
243 user to select this item.
245 virtual bool canBeSelected() const { return true; }
247 /** Creates a component that will be used to represent this item.
249 You don't have to implement this method - if it returns 0 then no component
250 will be used for the item, and you can just draw it using the paintItem()
251 callback. But if you do return a component, it will be positioned in the
252 treeview so that it can be used to represent this item.
254 The component returned will be managed by the treeview, so always return
255 a new component, and don't keep a reference to it, as the treeview will
256 delete it later when it goes off the screen or is no longer needed. Also
257 bear in mind that if the component keeps a reference to the item that
258 created it, that item could be deleted before the component. Its position
259 and size will be completely managed by the tree, so don't attempt to move it
260 around.
262 Something you may want to do with your component is to give it a pointer to
263 the TreeView that created it. This is perfectly safe, and there's no danger
264 of it becoming a dangling pointer because the TreeView will always delete
265 the component before it is itself deleted.
267 As long as you stick to these rules you can return whatever kind of
268 component you like. It's most useful if you're doing things like drag-and-drop
269 of items, or want to use a Label component to edit item names, etc.
271 virtual Component* createItemComponent() { return nullptr; }
273 //==============================================================================
274 /** Draws the item's contents.
276 You can choose to either implement this method and draw each item, or you
277 can use createItemComponent() to create a component that will represent the
278 item.
280 If all you need in your tree is to be able to draw the items and detect when
281 the user selects or double-clicks one of them, it's probably enough to
282 use paintItem(), itemClicked() and itemDoubleClicked(). If you need more
283 complicated interactions, you may need to use createItemComponent() instead.
285 @param g the graphics context to draw into
286 @param width the width of the area available for drawing
287 @param height the height of the area available for drawing
289 virtual void paintItem (Graphics& g, int width, int height);
291 /** Draws the item's open/close button.
293 If you don't implement this method, the default behaviour is to
294 call LookAndFeel::drawTreeviewPlusMinusBox(), but you can override
295 it for custom effects.
297 virtual void paintOpenCloseButton (Graphics& g, int width, int height, bool isMouseOver);
299 /** Called when the user clicks on this item.
301 If you're using createItemComponent() to create a custom component for the
302 item, the mouse-clicks might not make it through to the treeview, but this
303 is how you find out about clicks when just drawing each item individually.
305 The associated mouse-event details are passed in, so you can find out about
306 which button, where it was, etc.
308 @see itemDoubleClicked
310 virtual void itemClicked (const MouseEvent& e);
312 /** Called when the user double-clicks on this item.
314 If you're using createItemComponent() to create a custom component for the
315 item, the mouse-clicks might not make it through to the treeview, but this
316 is how you find out about clicks when just drawing each item individually.
318 The associated mouse-event details are passed in, so you can find out about
319 which button, where it was, etc.
321 If not overridden, the base class method here will open or close the item as
322 if the 'plus' button had been clicked.
324 @see itemClicked
326 virtual void itemDoubleClicked (const MouseEvent& e);
328 /** Called when the item is selected or deselected.
330 Use this if you want to do something special when the item's selectedness
331 changes. By default it'll get repainted when this happens.
333 virtual void itemSelectionChanged (bool isNowSelected);
335 /** The item can return a tool tip string here if it wants to.
336 @see TooltipClient
338 virtual const String getTooltip();
340 //==============================================================================
341 /** To allow items from your treeview to be dragged-and-dropped, implement this method.
343 If this returns a non-null variant then when the user drags an item, the treeview will
344 try to find a DragAndDropContainer in its parent hierarchy, and will use it to trigger
345 a drag-and-drop operation, using this string as the source description, with the treeview
346 itself as the source component.
348 If you need more complex drag-and-drop behaviour, you can use custom components for
349 the items, and use those to trigger the drag.
351 To accept drag-and-drop in your tree, see isInterestedInDragSource(),
352 isInterestedInFileDrag(), etc.
354 @see DragAndDropContainer::startDragging
356 virtual const var getDragSourceDescription();
358 /** If you want your item to be able to have files drag-and-dropped onto it, implement this
359 method and return true.
361 If you return true and allow some files to be dropped, you'll also need to implement the
362 filesDropped() method to do something with them.
364 Note that this will be called often, so make your implementation very quick! There's
365 certainly no time to try opening the files and having a think about what's inside them!
367 For responding to internal drag-and-drop of other types of object, see isInterestedInDragSource().
368 @see FileDragAndDropTarget::isInterestedInFileDrag, isInterestedInDragSource
370 virtual bool isInterestedInFileDrag (const StringArray& files);
372 /** When files are dropped into this item, this callback is invoked.
374 For this to work, you'll need to have also implemented isInterestedInFileDrag().
375 The insertIndex value indicates where in the list of sub-items the files were dropped.
376 If files are dropped onto an area of the tree where there are no visible items, this
377 method is called on the root item of the tree, with an insert index of 0.
378 @see FileDragAndDropTarget::filesDropped, isInterestedInFileDrag
380 virtual void filesDropped (const StringArray& files, int insertIndex);
382 /** If you want your item to act as a DragAndDropTarget, implement this method and return true.
384 If you implement this method, you'll also need to implement itemDropped() in order to handle
385 the items when they are dropped.
386 To respond to drag-and-drop of files from external applications, see isInterestedInFileDrag().
387 @see DragAndDropTarget::isInterestedInDragSource, itemDropped
389 virtual bool isInterestedInDragSource (const DragAndDropTarget::SourceDetails& dragSourceDetails);
391 /** When a things are dropped into this item, this callback is invoked.
393 For this to work, you need to have also implemented isInterestedInDragSource().
394 The insertIndex value indicates where in the list of sub-items the new items should be placed.
395 If files are dropped onto an area of the tree where there are no visible items, this
396 method is called on the root item of the tree, with an insert index of 0.
397 @see isInterestedInDragSource, DragAndDropTarget::itemDropped
399 virtual void itemDropped (const DragAndDropTarget::SourceDetails& dragSourceDetails, int insertIndex);
401 //==============================================================================
402 /** Sets a flag to indicate that the item wants to be allowed
403 to draw all the way across to the left edge of the treeview.
405 By default this is false, which means that when the paintItem()
406 method is called, its graphics context is clipped to only allow
407 drawing within the item's rectangle. If this flag is set to true,
408 then the graphics context isn't clipped on its left side, so it
409 can draw all the way across to the left margin. Note that the
410 context will still have its origin in the same place though, so
411 the coordinates of anything to its left will be negative. It's
412 mostly useful if you want to draw a wider bar behind the
413 highlighted item.
415 void setDrawsInLeftMargin (bool canDrawInLeftMargin) noexcept;
417 //==============================================================================
418 /** Saves the current state of open/closed nodes so it can be restored later.
420 This takes a snapshot of which sub-nodes have been explicitly opened or closed,
421 and records it as XML. To identify node objects it uses the
422 TreeViewItem::getUniqueName() method to create named paths. This
423 means that the same state of open/closed nodes can be restored to a
424 completely different instance of the tree, as long as it contains nodes
425 whose unique names are the same.
427 You'd normally want to use TreeView::getOpennessState() rather than call it
428 for a specific item, but this can be handy if you need to briefly save the state
429 for a section of the tree.
431 The caller is responsible for deleting the object that is returned.
432 @see TreeView::getOpennessState, restoreOpennessState
434 XmlElement* getOpennessState() const noexcept;
436 /** Restores the openness of this item and all its sub-items from a saved state.
438 See TreeView::restoreOpennessState for more details.
440 You'd normally want to use TreeView::restoreOpennessState() rather than call it
441 for a specific item, but this can be handy if you need to briefly save the state
442 for a section of the tree.
444 @see TreeView::restoreOpennessState, getOpennessState
446 void restoreOpennessState (const XmlElement& xml) noexcept;
448 //==============================================================================
449 /** Returns the index of this item in its parent's sub-items. */
450 int getIndexInParent() const noexcept;
452 /** Returns true if this item is the last of its parent's sub-itens. */
453 bool isLastOfSiblings() const noexcept;
455 /** Creates a string that can be used to uniquely retrieve this item in the tree.
457 The string that is returned can be passed to TreeView::findItemFromIdentifierString().
458 The string takes the form of a path, constructed from the getUniqueName() of this
459 item and all its parents, so these must all be correctly implemented for it to work.
460 @see TreeView::findItemFromIdentifierString, getUniqueName
462 String getItemIdentifierString() const;
464 //==============================================================================
466 This handy class takes a copy of a TreeViewItem's openness when you create it,
467 and restores that openness state when its destructor is called.
469 This can very handy when you're refreshing sub-items - e.g.
470 @code
471 void MyTreeViewItem::updateChildItems()
473 OpennessRestorer openness (*this); // saves the openness state here..
475 clearSubItems();
477 // add a bunch of sub-items here which may or may not be the same as the ones that
478 // were previously there
479 addSubItem (...
481 // ..and at this point, the old openness is restored, so any items that haven't
482 // changed will have their old openness retained.
484 @endcode
486 class OpennessRestorer
488 public:
489 OpennessRestorer (TreeViewItem& treeViewItem);
490 ~OpennessRestorer();
492 private:
493 TreeViewItem& treeViewItem;
494 ScopedPointer <XmlElement> oldOpenness;
496 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpennessRestorer);
499 private:
500 //==============================================================================
501 TreeView* ownerView;
502 TreeViewItem* parentItem;
503 OwnedArray <TreeViewItem> subItems;
504 int y, itemHeight, totalHeight, itemWidth, totalWidth;
505 int uid;
506 bool selected : 1;
507 bool redrawNeeded : 1;
508 bool drawLinesInside : 1;
509 bool drawsInLeftMargin : 1;
510 unsigned int openness : 2;
512 friend class TreeView;
513 friend class TreeViewContentComponent;
515 void updatePositions (int newY);
516 int getIndentX() const noexcept;
517 void setOwnerView (TreeView*) noexcept;
518 void paintRecursively (Graphics&, int width);
519 TreeViewItem* getTopLevelItem() noexcept;
520 TreeViewItem* findItemRecursively (int y) noexcept;
521 TreeViewItem* getDeepestOpenParentItem() noexcept;
522 int getNumRows() const noexcept;
523 TreeViewItem* getItemOnRow (int index) noexcept;
524 void deselectAllRecursively();
525 int countSelectedItemsRecursively (int depth) const noexcept;
526 TreeViewItem* getSelectedItemWithIndex (int index) noexcept;
527 TreeViewItem* getNextVisibleItem (bool recurse) const noexcept;
528 TreeViewItem* findItemFromIdentifierString (const String&);
530 #if JUCE_CATCH_DEPRECATED_CODE_MISUSE
531 // The parameters for these methods have changed - please update your code!
532 virtual void isInterestedInDragSource (const String&, Component*) {}
533 virtual int itemDropped (const String&, Component*, int) { return 0; }
534 #endif
536 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TreeViewItem);
540 //==============================================================================
542 A tree-view component.
544 Use one of these to hold and display a structure of TreeViewItem objects.
547 class JUCE_API TreeView : public Component,
548 public SettableTooltipClient,
549 public FileDragAndDropTarget,
550 public DragAndDropTarget,
551 private AsyncUpdater
553 public:
554 //==============================================================================
555 /** Creates an empty treeview.
557 Once you've got a treeview component, you'll need to give it something to
558 display, using the setRootItem() method.
560 TreeView (const String& componentName = String::empty);
562 /** Destructor. */
563 ~TreeView();
565 //==============================================================================
566 /** Sets the item that is displayed in the treeview.
568 A tree has a single root item which contains as many sub-items as it needs. If
569 you want the tree to contain a number of root items, you should still use a single
570 root item above these, but hide it using setRootItemVisible().
572 You can pass in 0 to this method to clear the tree and remove its current root item.
574 The object passed in will not be deleted by the treeview, it's up to the caller
575 to delete it when no longer needed. BUT make absolutely sure that you don't delete
576 this item until you've removed it from the tree, either by calling setRootItem (nullptr),
577 or by deleting the tree first. You can also use deleteRootItem() as a quick way
578 to delete it.
580 void setRootItem (TreeViewItem* newRootItem);
582 /** Returns the tree's root item.
584 This will be the last object passed to setRootItem(), or 0 if none has been set.
586 TreeViewItem* getRootItem() const noexcept { return rootItem; }
588 /** This will remove and delete the current root item.
590 It's a convenient way of deleting the item and calling setRootItem (nullptr).
592 void deleteRootItem();
594 /** Changes whether the tree's root item is shown or not.
596 If the root item is hidden, only its sub-items will be shown in the treeview - this
597 lets you make the tree look as if it's got many root items. If it's hidden, this call
598 will also make sure the root item is open (otherwise the treeview would look empty).
600 void setRootItemVisible (bool shouldBeVisible);
602 /** Returns true if the root item is visible.
604 @see setRootItemVisible
606 bool isRootItemVisible() const noexcept { return rootItemVisible; }
608 /** Sets whether items are open or closed by default.
610 Normally, items are closed until the user opens them, but you can use this
611 to make them default to being open until explicitly closed.
613 @see areItemsOpenByDefault
615 void setDefaultOpenness (bool isOpenByDefault);
617 /** Returns true if the tree's items default to being open.
619 @see setDefaultOpenness
621 bool areItemsOpenByDefault() const noexcept { return defaultOpenness; }
623 /** This sets a flag to indicate that the tree can be used for multi-selection.
625 You can always select multiple items internally by calling the
626 TreeViewItem::setSelected() method, but this flag indicates whether the user
627 is allowed to multi-select by clicking on the tree.
629 By default it is disabled.
631 @see isMultiSelectEnabled
633 void setMultiSelectEnabled (bool canMultiSelect);
635 /** Returns whether multi-select has been enabled for the tree.
637 @see setMultiSelectEnabled
639 bool isMultiSelectEnabled() const noexcept { return multiSelectEnabled; }
641 /** Sets a flag to indicate whether to hide the open/close buttons.
643 @see areOpenCloseButtonsVisible
645 void setOpenCloseButtonsVisible (bool shouldBeVisible);
647 /** Returns whether open/close buttons are shown.
649 @see setOpenCloseButtonsVisible
651 bool areOpenCloseButtonsVisible() const noexcept { return openCloseButtonsVisible; }
653 //==============================================================================
654 /** Deselects any items that are currently selected. */
655 void clearSelectedItems();
657 /** Returns the number of items that are currently selected.
658 If maximumDepthToSearchTo is >= 0, it lets you specify a maximum depth to which the
659 tree will be recursed.
660 @see getSelectedItem, clearSelectedItems
662 int getNumSelectedItems (int maximumDepthToSearchTo = -1) const noexcept;
664 /** Returns one of the selected items in the tree.
666 @param index the index, 0 to (getNumSelectedItems() - 1)
668 TreeViewItem* getSelectedItem (int index) const noexcept;
670 //==============================================================================
671 /** Returns the number of rows the tree is using.
673 This will depend on which items are open.
675 @see TreeViewItem::getRowNumberInTree()
677 int getNumRowsInTree() const;
679 /** Returns the item on a particular row of the tree.
681 If the index is out of range, this will return 0.
683 @see getNumRowsInTree, TreeViewItem::getRowNumberInTree()
685 TreeViewItem* getItemOnRow (int index) const;
687 /** Returns the item that contains a given y position.
688 The y is relative to the top of the TreeView component.
690 TreeViewItem* getItemAt (int yPosition) const noexcept;
692 /** Tries to scroll the tree so that this item is on-screen somewhere. */
693 void scrollToKeepItemVisible (TreeViewItem* item);
695 /** Returns the treeview's Viewport object. */
696 Viewport* getViewport() const noexcept;
698 /** Returns the number of pixels by which each nested level of the tree is indented.
699 @see setIndentSize
701 int getIndentSize() const noexcept { return indentSize; }
703 /** Changes the distance by which each nested level of the tree is indented.
704 @see getIndentSize
706 void setIndentSize (int newIndentSize);
708 /** Searches the tree for an item with the specified identifier.
709 The identifer string must have been created by calling TreeViewItem::getItemIdentifierString().
710 If no such item exists, this will return false. If the item is found, all of its items
711 will be automatically opened.
713 TreeViewItem* findItemFromIdentifierString (const String& identifierString) const;
715 //==============================================================================
716 /** Saves the current state of open/closed nodes so it can be restored later.
718 This takes a snapshot of which nodes have been explicitly opened or closed,
719 and records it as XML. To identify node objects it uses the
720 TreeViewItem::getUniqueName() method to create named paths. This
721 means that the same state of open/closed nodes can be restored to a
722 completely different instance of the tree, as long as it contains nodes
723 whose unique names are the same.
725 The caller is responsible for deleting the object that is returned.
727 @param alsoIncludeScrollPosition if this is true, the state will also
728 include information about where the
729 tree has been scrolled to vertically,
730 so this can also be restored
731 @see restoreOpennessState
733 XmlElement* getOpennessState (bool alsoIncludeScrollPosition) const;
735 /** Restores a previously saved arrangement of open/closed nodes.
737 This will try to restore a snapshot of the tree's state that was created by
738 the getOpennessState() method. If any of the nodes named in the original
739 XML aren't present in this tree, they will be ignored.
741 If restoreStoredSelection is true, it will also try to re-select any items that
742 were selected in the stored state.
744 @see getOpennessState
746 void restoreOpennessState (const XmlElement& newState,
747 bool restoreStoredSelection);
749 //==============================================================================
750 /** A set of colour IDs to use to change the colour of various aspects of the treeview.
752 These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
753 methods.
755 @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
757 enum ColourIds
759 backgroundColourId = 0x1000500, /**< A background colour to fill the component with. */
760 linesColourId = 0x1000501, /**< The colour to draw the lines with.*/
761 dragAndDropIndicatorColourId = 0x1000502 /**< The colour to use for the drag-and-drop target position indicator. */
764 //==============================================================================
765 /** @internal */
766 void paint (Graphics& g);
767 /** @internal */
768 void resized();
769 /** @internal */
770 bool keyPressed (const KeyPress& key);
771 /** @internal */
772 void colourChanged();
773 /** @internal */
774 void enablementChanged();
775 /** @internal */
776 bool isInterestedInFileDrag (const StringArray& files);
777 /** @internal */
778 void fileDragEnter (const StringArray& files, int x, int y);
779 /** @internal */
780 void fileDragMove (const StringArray& files, int x, int y);
781 /** @internal */
782 void fileDragExit (const StringArray& files);
783 /** @internal */
784 void filesDropped (const StringArray& files, int x, int y);
785 /** @internal */
786 bool isInterestedInDragSource (const SourceDetails&);
787 /** @internal */
788 void itemDragEnter (const SourceDetails&);
789 /** @internal */
790 void itemDragMove (const SourceDetails&);
791 /** @internal */
792 void itemDragExit (const SourceDetails&);
793 /** @internal */
794 void itemDropped (const SourceDetails&);
796 private:
797 friend class TreeViewItem;
798 friend class TreeViewContentComponent;
799 class TreeViewport;
800 class InsertPointHighlight;
801 class TargetGroupHighlight;
802 friend class ScopedPointer<TreeViewport>;
803 friend class ScopedPointer<InsertPointHighlight>;
804 friend class ScopedPointer<TargetGroupHighlight>;
805 ScopedPointer<TreeViewport> viewport;
806 CriticalSection nodeAlterationLock;
807 TreeViewItem* rootItem;
808 ScopedPointer<InsertPointHighlight> dragInsertPointHighlight;
809 ScopedPointer<TargetGroupHighlight> dragTargetGroupHighlight;
810 int indentSize;
811 bool defaultOpenness : 1;
812 bool needsRecalculating : 1;
813 bool rootItemVisible : 1;
814 bool multiSelectEnabled : 1;
815 bool openCloseButtonsVisible : 1;
817 void itemsChanged() noexcept;
818 void handleAsyncUpdate();
819 void moveSelectedRow (int delta);
820 void updateButtonUnderMouse (const MouseEvent& e);
821 void showDragHighlight (TreeViewItem* item, int insertIndex, int x, int y) noexcept;
822 void hideDragHighlight() noexcept;
823 void handleDrag (const StringArray& files, const SourceDetails&);
824 void handleDrop (const StringArray& files, const SourceDetails&);
825 TreeViewItem* getInsertPosition (int& x, int& y, int& insertIndex,
826 const StringArray& files, const SourceDetails&) const noexcept;
828 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TreeView);
831 #endif // __JUCE_TREEVIEW_JUCEHEADER__