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