Ocean
Loading...
Searching...
No Matches
TreeView.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_PLATFORM_APPLE_MACOS_TREE_VIEW_H
9#define META_OCEAN_PLATFORM_APPLE_MACOS_TREE_VIEW_H
10
12
13#ifndef __OBJC__
14 #error Platform::Apple::MacOS::TreeView.h needs to be included from an ObjectiveC++ file
15#endif
16
18
19#include <memory>
20#include <unordered_map>
21
22#include <AppKit/AppKit.h>
23
24namespace Ocean
25{
26
27namespace Platform
28{
29
30namespace Apple
31{
32
33namespace MacOS
34{
35
36/**
37 * This class implements tree view control for MacOS platforms.
38 * @ingroup platformapplemacos
39 */
41{
42 public:
43
44 /**
45 * Definition of a vector holding strings.
46 */
47 typedef std::vector<std::string> Strings;
48
49 /**
50 * Definition of a unique tree item id.
51 */
52 typedef uint64_t TreeItemId;
53
54 /**
55 * Definition of a vector holding unique tree item ids.
56 */
57 typedef std::vector<TreeItemId> TreeItemIds;
58
59 /**
60 * Definition of an (unordered) map mapping item ids to item ids.
61 */
62 typedef std::unordered_map<TreeItemId, TreeItemId> TreeItemResortingMap;
63
64 /**
65 * Definition of an invalid tree item id.
66 */
68
69 /**
70 * Definition of an invalid icon index.
71 */
72 static const unsigned int invalidIconIndex = (unsigned int)(-1);
73
74 /**
75 * This class implements a tree item.
76 */
78 {
79 friend class TreeView;
80
81 public:
82
83 /**
84 * Destructs a tree item.
85 */
86 virtual ~TreeItem();
87
88 /**
89 * Returns the unique id of this tree item (unique for the owning tree view).
90 * @return The item's unique id
91 */
92 inline TreeItemId id() const;
93
94 /**
95 * Returns the texts of this item.
96 * @return The item's texts, one for each column
97 */
98 inline const Strings& texts() const;
99
100 /**
101 * Returns the id of the parent item.
102 * @return THe parent's item id, an invalid id if this item is currently not shown in the tree view.
103 */
104 inline TreeItemId parentId() const;
105
106 /**
107 * Returns all children of this item.
108 * @return The ids of all children of this item
109 */
110 inline const TreeItemIds& children() const;
111
112 /**
113 * Returns all children of this item recursively.
114 * @return The ids of all children and of the children's children a.s.o.
115 */
117
118 /**
119 * Returns the index of the icon of this item.
120 * @return The item's icon index, an invalid index if the item has no icon
121 */
122 inline unsigned int iconIndex() const;
123
124 /**
125 * Returns whether this item has a specific child item.
126 * @param childId The id of the child to check
127 * @return True, if so
128 */
129 bool hasChild(const TreeItemId childId) const;
130
131 /**
132 * Removes a child from this item.
133 * @param childId The id of the child to remove, must be a valid child
134 * @return True, if succeeded
135 * @see hasChild().
136 */
137 bool removeChild(const TreeItemId childId);
138
139 /**
140 * Sets the texts of this item.
141 * @param texts The texts to set, one for each column
142 */
143 void setTexts(const Strings& texts);
144
145 /**
146 * Sets or changes the index of the icon of this item.
147 * @param index The index of the icon to set
148 */
149 void setIconIndex(const unsigned int index);
150
151 /**
152 * Sets or changes the parent item of this item.
153 * @param parentId The id of the new parent item
154 * @param followingId Optional id of the (already existing) child item of the new parent item which will become the next sibling item, an invalid id to add this item as last child item
155 * @param refreshView True, to refresh the view afterwards; False, to skip refreshing the view
156 * @return True, if succeeded
157 */
158 bool setParent(const TreeItemId parentId, const TreeItemId followingId = invalidTreeItemId, const bool refreshView = true);
159
160 /**
161 * Expands this item.
162 * @param allChildItems True, to expand also all child items
163 */
164 void expand(const bool allChildItems = false) const;
165
166 protected:
167
168 /**
169 * Creates a new tree item object.
170 * @param owner The owner of the item
171 * @param texts The texts of the item, one for each column
172 * @param id The unique id of the item, any unique id which does not exist already, or and invalid id to automatically create an unique id
173 * @param iconIndex The item's icon index, an invalid index if the item has no icon
174 */
175 explicit TreeItem(TreeView& owner, const Strings& texts, const TreeItemId id = invalidTreeItemId, const unsigned int iconIndex = invalidIconIndex);
176
177 /**
178 * Creates a new tree item object.
179 * @param owner The owner of the item
180 * @param texts The texts of the item, one for each column, will be moved
181 * @param id The unique id of the item, any unique id which does not exist already, or and invalid id to automatically create an unique id
182 * @param iconIndex The item's icon index, an invalid index if the item has no icon
183 */
184 explicit TreeItem(TreeView& owner, Strings&& texts, const TreeItemId id = invalidTreeItemId, const unsigned int iconIndex = invalidIconIndex);
185
186 protected:
187
188 /// The owner of this item.
190
191 /// The id of the parent item, an invalid id if this item is currently not registered in the tree view.
193
194 /// The ids of all child items.
196
197 /// The unique id of this item.
199
200 /// The text of this item.
202
203 /// The index of the item's icon defined for the image list of the owner.
204 unsigned int iconIndex_ = (unsigned int)(-1);
205 };
206
207 /**
208 * Definition of an (not thread safe) object reference holding a tree item.
209 */
210 typedef std::shared_ptr<TreeItem> TreeItemRef;
211
212 protected:
213
214 /**
215 * Definition of a map mapping tree item ids to tree items.
216 */
217 typedef std::map<TreeItemId, TreeItemRef> TreeItemMap;
218
219 public:
220
221 /**
222 * Creates an invalid tree view object.
223 */
225
226 /**
227 * Creates a new view object with specified size and dimension.
228 * @param rect The rect defining the size and dimension
229 * @param columnNames The names of the columns the tree view will have, at least one (optional empty) string
230 */
231 explicit TreeView(const NSRect& rect, const Strings& columnNames = Strings(1, std::string()));
232
233 /**
234 * Creates a new tree view object with specified size and dimension.
235 * @param left The horizontal start position of the control, with range (-infinity, infinity)
236 * @param top The vertical start position of the control in pixel, with range (-infinity, infinity)
237 * @param width The width of the control in pixel, with range [0, infinity)
238 * @param height The height of the control in pixel, with range [0, infinity)
239 * @param columnNames The names of the columns the tree view will have, at least one (optional empty) string
240 */
241 TreeView(const double left, const double top, const double width, const double height, const Strings& columnNames = Strings(1, std::string()));
242
243 /**
244 * Move constructor.
245 * @param treeView Tree view object to be moved
246 */
247 TreeView(TreeView&& treeView) noexcept;
248
249 /**
250 * Disabled copy constructor.
251 * @param treeView Tree view object to be moved
252 */
253 TreeView(const TreeView& treeView) = delete;
254
255 /**
256 * Destructs a tree view object.
257 */
258 virtual ~TreeView();
259
260 /**
261 * Returns the number of columns this view has.
262 * @return The views number of columns, with range [1, infinity)
263 */
264 inline size_t columns() const;
265
266 /**
267 * Enables or disables multi row selection.
268 * @param enable True, to enabled multi row selection; False, to disable multi row selection
269 */
270 inline void enableMultiRowSelection(const bool enable);
271
272 /**
273 * Returns the id of the invisible root item of this tree view.
274 * @return The tree view's root item id, which is -1
275 */
276 inline TreeItemId rootItemId() const;
277
278 /**
279 * Returns the invisible root item of this tree view.
280 * @return The tree view's root item, with item id -1
281 */
282 inline const TreeItem& rootItem() const;
283
284 /**
285 * Returns whether this tree view holds a specified item.
286 * @param itemId The id of the item to check
287 * @return True, if so
288 */
289 bool hasItem(const TreeItemId itemId) const;
290
291 /**
292 * Returns a specific item of this tree view.
293 * @param itemId The id of the requested item
294 * @return The requested item, an invalid object if the item does not exist
295 */
296 TreeItemRef item(const TreeItemId itemId) const;
297
298 /**
299 * Creates a new item for this tree view and registeres it.
300 * @param text The text of the first column of the item to be created
301 * @param parentId Optional id of the parent item, and invalid id so that the item will not directly show up in the tree view
302 * @param itemId Optional the unique id of the item, any unique id which does not exist already, or and invalid id to automatically create an unique id, while the root item has item id -1
303 * @param refreshView True, to refresh the view afterwards; False, to skip refreshing the view
304 */
305 virtual TreeItemRef createItem(const std::string& text, const TreeItemId parentId = invalidTreeItemId, const TreeItemId itemId = invalidTreeItemId, const bool refreshView = true);
306
307 /**
308 * Creates a new item for this tree view and registeres it.
309 * @param texts The texts of the item to be created, one text for each column
310 * @param parentId Optional id of the parent item, and invalid id so that the item will not directly show up in the tree view
311 * @param itemId Optional the unique id of the item, any unique id which does not exist already, or and invalid id to automatically create an unique id, while the root item has item id -1
312 * @param refreshView True, to refresh the view afterwards; False, to skip refreshing the view
313 */
314 virtual TreeItemRef createItem(const Strings& texts, const TreeItemId parentId = invalidTreeItemId, const TreeItemId itemId = invalidTreeItemId, const bool refreshView = true);
315
316 /**
317 * Creates a new item for this tree view and registeres it.
318 * @param texts The texts of the item to be created, one text for each column, will be moved
319 * @param parentId Optional id of the parent item, and invalid id so that the item will not directly show up in the tree view
320 * @param itemId Optional the unique id of the item, any unique id which does not exist already, or and invalid id to automatically create an unique id, while the root item has item id -1
321 * @param refreshView True, to refresh the view afterwards; False, to skip refreshing the view
322 */
323 virtual TreeItemRef createItem(Strings&& texts, const TreeItemId parentId = invalidTreeItemId, const TreeItemId itemId = invalidTreeItemId, const bool refreshView = true);
324
325 /**
326 * Removes an item from this tree view.
327 * @param itemId The id of the item to remove
328 * @return True, if succeeded
329 */
330 virtual bool removeItem(const TreeItemId itemId);
331
332 /**
333 * Removes all items from this tree view.
334 */
335 virtual void removeItems();
336
337 /**
338 * Selects an item of this tree view.
339 * @param itemId The id of the item to select
340 * @param extendSelection True, to leave currently selected item unchanged; False, to select the defined item only
341 * @return True, if the item could be selected
342 */
343 virtual bool selectItem(const TreeItemId itemId, const bool extendSelection = false);
344
345 /**
346 * Selects items of this tree view.
347 * @param itemIds The ids of the item to select
348 * @param extendSelection True, to leave currently selected item unchanged; False, to select the defined items only
349 * @return True, if all items could be selected; False, if some items could not be selected
350 */
351 virtual bool selectItems(const TreeItemIds& itemIds, const bool extendSelection = false);
352
353 /**
354 * Unselects all items.
355 */
356 virtual void unselectItems();
357
358 /**
359 * Returns the id of the currently (first) selected item.
360 * @return The id of the first item which is currently selected, an invalid id if no item is selected
361 */
363
364 /**
365 * Returns the ids of all items that are currently selected.
366 * @return Ids of all selected items
367 */
369
370 /**
371 * Sets the image list for this tree view object (by moving the object).
372 * @param imageList The image list object to be moved
373 */
375
376 /**
377 * Returns the image list object of this tree view.
378 * @return The image list object
379 */
380 inline ImageList& imageList();
381
382 /**
383 * Sets the width of a column.
384 * @param columnIndex The index of the column to be set, with range [0, columns())
385 * @param width The width of the column, with range [0, infinity)
386 */
387 void setColumnWidth(const unsigned int columnIndex, const double width);
388
389 /**
390 * Fits the width of the all columns or of one specific column so that the width of the column(s) match with the content.
391 * @param columnIndex The index of the column to be adjusted, -1 to adjust all columns
392 */
393 void fitColumnSize(const unsigned int columnIndex = (unsigned int)(-1));
394
395 /**
396 * Returns the MacOS specific object of this tree view.
397 * @return The view object
398 */
399 inline NSView* nsView();
400
401 /**
402 * Returns whether this object is enabled.
403 * @return True, if so
404 */
405 inline bool isEnabled() const;
406
407 /**
408 * Returns whether this object is valid and wrapps a valid MacOS object.
409 * @return True, if so
410 */
411 inline bool isValid() const;
412
413 /**
414 * Forces the panel to be repainted.
415 */
416 void repaint();
417
418 /**
419 * View resize event.
420 * @param x The horizontal start location of this view, with range (-infinity, infinity)
421 * @param y The vertical start location of this view, with range (-infinity, infinity)
422 * @param width The width of this view, with range [0, infinity)
423 * @param height The height of this view, with range [0, infinity)
424 */
425 virtual void onResize(const double x, const double y, const double width, const double height);
426
427 /**
428 * The item selected event function.
429 * @param itemId The id of the item which has been selected, an invalid id if an item has been unselected
430 */
431 virtual void onItemSelected(const TreeItemId itemId);
432
433 /**
434 * The function for left mouse button down events.
435 */
436 virtual void onMouseDownLeft();
437
438 /**
439 * The function for left mouse button up events.
440 */
441 virtual void onMouseUpLeft();
442
443 /**
444 * The function for right mouse button down events.
445 */
446 virtual void onMouseDownRight();
447
448 /**
449 * The function for right mouse button up events.
450 */
451 virtual void onMouseUpRight();
452
453 /**
454 * The function for header click events.
455 * @param columnIndex The index of the header column that has been clicked
456 */
457 virtual void onMouseDownInHeader(const unsigned int columnIndex);
458
459 /**
460 * The function for background draw events.
461 */
462 virtual void onDrawBackground();
463
464 /**
465 * The function for post-foreground draw events.
466 */
467 virtual void onDrawForeground();
468
469 /**
470 * Translates an unsorted item (a tree view entry) to a sorted item.
471 * @param unsortedItem The unsorted item to be translated
472 * @return The sorted item
473 */
474 TreeItemRef unsortedItem2sortedItem(id unsortedItem) const;
475
476 /**
477 * Move operator.
478 * @param treeView Tree view object to be moved
479 * @return Reference to this object
480 */
481 TreeView& operator=(TreeView&& treeView) noexcept;
482
483 /**
484 * Disabled copy operator.
485 * @param treeView Tree view object to be copied
486 * @return Reference to this object
487 */
488 TreeView& operator=(const TreeView& treeView) = delete;
489
490 /**
491 * Returns whether this object is valid and wraps a valid MacOS object.
492 * @return True, if so
493 */
494 explicit inline operator bool() const;
495
496 protected:
497
498 /**
499 * Creates (mainly registers) an item for this tree view.
500 * @param itemObject The already existing but not registered tree item which must not be released by the caller, must be valid
501 * @param parentId Optional id of the parent item, and invalid id so that the item will not directly show up in the tree view
502 * @param refreshView True, to refresh the view afterwards; False, to skip refreshing the view
503 */
504 virtual TreeItemRef createItem(TreeItem* itemObject, const TreeItemId parentId = invalidTreeItemId, const bool refreshView = true);
505
506 /**
507 * Returns a unique tree item id for the current state of the tree view.
508 * @return The unique item id
509 */
511
512 /**
513 * Refreshes (repaints) a specified item.
514 * @param itemId The id of the item which has to be refreshed (repainted).
515 */
516 void refreshItem(const TreeItemId itemId);
517
518 /**
519 * Refreshes (repaints) all items.
520 */
522
523 /**
524 * Sets the sorting map for all items.
525 * @param unsorted2SortedItemMap The map mapping unsorted item ids to sorted item ids, will be moved
526 */
527 void setItemSortMap(TreeItemResortingMap&& unsorted2SortedItemMap);
528
529 /**
530 * Translates an unsorted item id to a sorted item id.
531 * @param unsortedItemId The id of the unsorted item to be translated
532 * @return The sorted item id
533 */
534 inline TreeItemId unsortedItemId2sortedItemId(const TreeItemId unsortedItemId) const;
535
536 /**
537 * Translates a sorted item id to an unsorted item id.
538 * @param sortedItemId The id of the sorted item to be translated
539 * @return The unsorted item id
540 */
541 inline TreeItemId sortedItemId2unsortedItemId(const TreeItemId sortedItemId) const;
542
543 protected:
544
545 /// The MacOS specific object providing scroll functionality.
546 NSScrollView* scrollView_ = nullptr;
547
548 /// The MacOS specific object providing the tree functionality.
549 NSOutlineView* outlineView_ = nullptr;
550
551 /// The MacOS specific data source for the outline view.
553
554 /// The invisible root item of this tree view.
556
557 /// The map mapping tree item ids to tree items.
559
560 /// The counter for unique tree item ids.
562
563 /// The image list of this tree view.
565
566 /// The names of the columns of this tree.
568
569 private:
570
571 /// Optional map mapping unsorted item ids to sorted item ids.
573
574 /// Optional map mapping sorted item ids to unsorted item ids.
576};
577
579{
580 return id_;
581}
582
584{
585 return texts_;
586}
587
589{
590 return parentId_;
591}
592
594{
595 return childItemIds_;
596}
597
598inline unsigned int TreeView::TreeItem::iconIndex() const
599{
600 return iconIndex_;
601}
602
603inline size_t TreeView::columns() const
604{
605 return columnNames_.size();
606}
607
608inline void TreeView::enableMultiRowSelection(const bool enable)
609{
610 [outlineView_ setAllowsMultipleSelection:enable];
611}
612
614{
615 return TreeItemId(-1);
616}
617
619{
620 ocean_assert(rootItem_);
621 return *rootItem_;
622}
623
625{
626 return viewImageList_;
627}
628
629inline NSView* TreeView::nsView()
630{
631 ocean_assert(scrollView_);
632 return scrollView_;
633}
634
635inline bool TreeView::isEnabled() const
636{
637 return [outlineView_ isEnabled];
638}
639
640inline bool TreeView::isValid() const
641{
642 ocean_assert((scrollView_ != nullptr && outlineView_ != nullptr && outlineViewDataSource_ != nullptr)
643 || (scrollView_ == nullptr && outlineView_ == nullptr && outlineViewDataSource_ == nullptr));
644
645 return scrollView_ != nullptr;
646}
647
648inline TreeView::operator bool() const
649{
650 return isValid();
651}
652
654{
655 ocean_assert(unsorted2SortedItemMap_.size() == sorted2UnsortedItemMap_.size());
656
657 if (unsorted2SortedItemMap_.empty())
658 {
659 return unsortedItemId;
660 }
661 else
662 {
663 const TreeItemResortingMap::const_iterator i = unsorted2SortedItemMap_.find(unsortedItemId);
664 ocean_assert(i != unsorted2SortedItemMap_.end());
665
666 return i->second;
667 }
668}
669
671{
672 ocean_assert(unsorted2SortedItemMap_.size() == sorted2UnsortedItemMap_.size());
673
674 if (sorted2UnsortedItemMap_.empty())
675 {
676 return sortedItemId;
677 }
678 else
679 {
680 const TreeItemResortingMap::const_iterator i = sorted2UnsortedItemMap_.find(sortedItemId);
681 ocean_assert(i != sorted2UnsortedItemMap_.end());
682
683 return i->second;
684 }
685}
686
687}
688
689}
690
691}
692
693}
694
695#endif // META_OCEAN_PLATFORM_APPLE_MACOS_TREE_VIEW_H
This class implements an image list.
Definition apple/macos/ImageList.h:37
This class implements a tree item.
Definition TreeView.h:78
virtual ~TreeItem()
Destructs a tree item.
TreeItemIds recursiveChildren() const
Returns all children of this item recursively.
TreeItemIds childItemIds_
The ids of all child items.
Definition TreeView.h:195
const TreeItemIds & children() const
Returns all children of this item.
Definition TreeView.h:593
unsigned int iconIndex_
The index of the item's icon defined for the image list of the owner.
Definition TreeView.h:204
TreeItemId id() const
Returns the unique id of this tree item (unique for the owning tree view).
Definition TreeView.h:578
bool hasChild(const TreeItemId childId) const
Returns whether this item has a specific child item.
void expand(const bool allChildItems=false) const
Expands this item.
Strings texts_
The text of this item.
Definition TreeView.h:201
TreeItemId parentId() const
Returns the id of the parent item.
Definition TreeView.h:588
void setIconIndex(const unsigned int index)
Sets or changes the index of the icon of this item.
bool setParent(const TreeItemId parentId, const TreeItemId followingId=invalidTreeItemId, const bool refreshView=true)
Sets or changes the parent item of this item.
TreeItem(TreeView &owner, Strings &&texts, const TreeItemId id=invalidTreeItemId, const unsigned int iconIndex=invalidIconIndex)
Creates a new tree item object.
TreeItemId id_
The unique id of this item.
Definition TreeView.h:198
TreeItem(TreeView &owner, const Strings &texts, const TreeItemId id=invalidTreeItemId, const unsigned int iconIndex=invalidIconIndex)
Creates a new tree item object.
bool removeChild(const TreeItemId childId)
Removes a child from this item.
const Strings & texts() const
Returns the texts of this item.
Definition TreeView.h:583
void setTexts(const Strings &texts)
Sets the texts of this item.
TreeView & owner_
The owner of this item.
Definition TreeView.h:189
unsigned int iconIndex() const
Returns the index of the icon of this item.
Definition TreeView.h:598
TreeItemId parentId_
The id of the parent item, an invalid id if this item is currently not registered in the tree view.
Definition TreeView.h:192
This class implements tree view control for MacOS platforms.
Definition TreeView.h:41
virtual void onItemSelected(const TreeItemId itemId)
The item selected event function.
TreeItemRef rootItem_
The invisible root item of this tree view.
Definition TreeView.h:555
void repaint()
Forces the panel to be repainted.
size_t columns() const
Returns the number of columns this view has.
Definition TreeView.h:603
ImageList viewImageList_
The image list of this tree view.
Definition TreeView.h:564
static const TreeItemId invalidTreeItemId
Definition of an invalid tree item id.
Definition TreeView.h:67
NSOutlineView * outlineView_
The MacOS specific object providing the tree functionality.
Definition TreeView.h:549
virtual void onDrawBackground()
The function for background draw events.
std::unordered_map< TreeItemId, TreeItemId > TreeItemResortingMap
Definition of an (unordered) map mapping item ids to item ids.
Definition TreeView.h:62
void refreshItems()
Refreshes (repaints) all items.
virtual TreeItemRef createItem(const std::string &text, const TreeItemId parentId=invalidTreeItemId, const TreeItemId itemId=invalidTreeItemId, const bool refreshView=true)
Creates a new item for this tree view and registeres it.
TreeItemId unsortedItemId2sortedItemId(const TreeItemId unsortedItemId) const
Translates an unsorted item id to a sorted item id.
Definition TreeView.h:653
virtual void onMouseUpRight()
The function for right mouse button up events.
virtual bool removeItem(const TreeItemId itemId)
Removes an item from this tree view.
virtual void removeItems()
Removes all items from this tree view.
bool isEnabled() const
Returns whether this object is enabled.
Definition TreeView.h:635
virtual void onMouseDownInHeader(const unsigned int columnIndex)
The function for header click events.
void fitColumnSize(const unsigned int columnIndex=(unsigned int)(-1))
Fits the width of the all columns or of one specific column so that the width of the column(s) match ...
void setImageList(ImageList &&imageList)
Sets the image list for this tree view object (by moving the object).
TreeItemIds selectedItemIds() const
Returns the ids of all items that are currently selected.
TreeView(const TreeView &treeView)=delete
Disabled copy constructor.
TreeItemId treeItemIdCounter_
The counter for unique tree item ids.
Definition TreeView.h:561
virtual TreeItemRef createItem(const Strings &texts, const TreeItemId parentId=invalidTreeItemId, const TreeItemId itemId=invalidTreeItemId, const bool refreshView=true)
Creates a new item for this tree view and registeres it.
TreeItemId uniqueItemId()
Returns a unique tree item id for the current state of the tree view.
bool isValid() const
Returns whether this object is valid and wrapps a valid MacOS object.
Definition TreeView.h:640
virtual bool selectItems(const TreeItemIds &itemIds, const bool extendSelection=false)
Selects items of this tree view.
virtual bool selectItem(const TreeItemId itemId, const bool extendSelection=false)
Selects an item of this tree view.
NSObject< NSOutlineViewDataSource > * outlineViewDataSource_
The MacOS specific data source for the outline view.
Definition TreeView.h:552
TreeItemResortingMap unsorted2SortedItemMap_
Optional map mapping unsorted item ids to sorted item ids.
Definition TreeView.h:572
TreeView(TreeView &&treeView) noexcept
Move constructor.
std::shared_ptr< TreeItem > TreeItemRef
Definition of an (not thread safe) object reference holding a tree item.
Definition TreeView.h:210
TreeItemId selectedItemId() const
Returns the id of the currently (first) selected item.
TreeItemRef unsortedItem2sortedItem(id unsortedItem) const
Translates an unsorted item (a tree view entry) to a sorted item.
TreeView(const NSRect &rect, const Strings &columnNames=Strings(1, std::string()))
Creates a new view object with specified size and dimension.
void setColumnWidth(const unsigned int columnIndex, const double width)
Sets the width of a column.
uint64_t TreeItemId
Definition of a unique tree item id.
Definition TreeView.h:52
virtual TreeItemRef createItem(TreeItem *itemObject, const TreeItemId parentId=invalidTreeItemId, const bool refreshView=true)
Creates (mainly registers) an item for this tree view.
virtual void onResize(const double x, const double y, const double width, const double height)
View resize event.
bool hasItem(const TreeItemId itemId) const
Returns whether this tree view holds a specified item.
TreeView(const double left, const double top, const double width, const double height, const Strings &columnNames=Strings(1, std::string()))
Creates a new tree view object with specified size and dimension.
const TreeItem & rootItem() const
Returns the invisible root item of this tree view.
Definition TreeView.h:618
TreeView()
Creates an invalid tree view object.
virtual void onMouseDownLeft()
The function for left mouse button down events.
TreeView & operator=(const TreeView &treeView)=delete
Disabled copy operator.
TreeItemMap treeItemMap_
The map mapping tree item ids to tree items.
Definition TreeView.h:558
TreeItemRef item(const TreeItemId itemId) const
Returns a specific item of this tree view.
Strings columnNames_
The names of the columns of this tree.
Definition TreeView.h:567
virtual void onMouseUpLeft()
The function for left mouse button up events.
void refreshItem(const TreeItemId itemId)
Refreshes (repaints) a specified item.
TreeItemResortingMap sorted2UnsortedItemMap_
Optional map mapping sorted item ids to unsorted item ids.
Definition TreeView.h:575
std::map< TreeItemId, TreeItemRef > TreeItemMap
Definition of a map mapping tree item ids to tree items.
Definition TreeView.h:217
ImageList & imageList()
Returns the image list object of this tree view.
Definition TreeView.h:624
std::vector< std::string > Strings
Definition of a vector holding strings.
Definition TreeView.h:47
std::vector< TreeItemId > TreeItemIds
Definition of a vector holding unique tree item ids.
Definition TreeView.h:57
void enableMultiRowSelection(const bool enable)
Enables or disables multi row selection.
Definition TreeView.h:608
TreeView & operator=(TreeView &&treeView) noexcept
Move operator.
virtual void unselectItems()
Unselects all items.
static const unsigned int invalidIconIndex
Definition of an invalid icon index.
Definition TreeView.h:72
TreeItemId rootItemId() const
Returns the id of the invisible root item of this tree view.
Definition TreeView.h:613
virtual void onDrawForeground()
The function for post-foreground draw events.
virtual ~TreeView()
Destructs a tree view object.
virtual TreeItemRef createItem(Strings &&texts, const TreeItemId parentId=invalidTreeItemId, const TreeItemId itemId=invalidTreeItemId, const bool refreshView=true)
Creates a new item for this tree view and registeres it.
void setItemSortMap(TreeItemResortingMap &&unsorted2SortedItemMap)
Sets the sorting map for all items.
NSScrollView * scrollView_
The MacOS specific object providing scroll functionality.
Definition TreeView.h:546
virtual void onMouseDownRight()
The function for right mouse button down events.
TreeItemId sortedItemId2unsortedItemId(const TreeItemId sortedItemId) const
Translates a sorted item id to an unsorted item id.
Definition TreeView.h:670
NSView * nsView()
Returns the MacOS specific object of this tree view.
Definition TreeView.h:629
The namespace covering the entire Ocean framework.
Definition Accessor.h:15