/
TreeView.h
110 lines (82 loc) · 3.07 KB
/
TreeView.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#pragma once
#include <memory>
#include <wx/dataview.h>
#include <wx/windowptr.h>
#include "TreeModel.h"
namespace wxutil
{
/**
* greebo: Extension of the regular wxDataViewCtrl to add
* a few needed improvements, like automatic column sizing
* for treeviews (a thing that seems to be problematic in the
* pure wxDataViewCtrl) and type-ahead searching.
*
* Use the named constructors Create*() to instantiate a new TreeView.
*/
class TreeView :
public wxDataViewCtrl
{
protected:
class Search;
std::unique_ptr<Search> _search;
class SearchPopupWindow;
std::vector<TreeModel::Column> _colsToSearch;
bool _collapseRecursively;
bool _searchPopupEnabled;
TreeView(wxWindow* parent, wxDataViewModel* model, long style);
public:
typedef wxWindowPtr<TreeView> Ptr;
// Create a TreeView without model (single-selection mode)
static TreeView* Create(wxWindow* parent, long style = wxDV_SINGLE);
/**
* \brief
* Construct a TreeView with an associated model
*
* \param parent
* The parent window of the tree view widget
*
* \param model
* Data model to supply data for the tree view. May be null.
*/
static TreeView* CreateWithModel(wxWindow* parent, wxDataViewModel* model,
long style = wxDV_SINGLE);
virtual ~TreeView();
// override wxDataViewCtrl to make it more robust
virtual bool AssociateModel(wxDataViewModel* model) override;
// Enable the automatic recalculation of column widths
void EnableAutoColumnWidthFix(bool enable = true);
// Trigger an ItemChanged event on all the children of the given node
// Call this if your text columns get squashed and are not sized correctly
void TriggerColumnSizeEvent(const wxDataViewItem& item = wxDataViewItem());
// Expands the first level of all the top-level items
void ExpandTopLevelItems();
// When enabled, collapsing a single item will automatically collapse all child items too
void EnableRecursiveCollapse(bool enabled);
// Removes any sort keys
void ResetSortingOnAllColumns();
// Adds a column to search when the user starts typing
void AddSearchColumn(const TreeModel::Column& column);
// Returns true if the treeview search popup is currently visible
bool HasActiveSearchPopup();
// Enable/Disable the search popup (which is enabled by default)
void EnableSearchPopup(bool enabled);
#if !defined(__linux__)
// Triggers a rebuild of the tree (done by calling ItemDeleted+ItemAdded for each
// of the root's immediate children.
void Rebuild();
#endif
// Stops any ongoing inline-editing in any column
void CancelEditing();
protected:
// Synthesises a selection change event to notify any handlers
void SendSelectionChangeEvent(const wxDataViewItem& item);
void JumpToSearchMatch(const wxDataViewItem& item);
private:
void CollapseChildren(const wxDataViewItem& item);
void CloseSearch();
void _onItemCollapsing(wxDataViewEvent& ev);
void _onItemExpanded(wxDataViewEvent& ev);
void _onChar(wxKeyEvent& ev);
void _onItemActivated(wxDataViewEvent& ev);
};
} // namespace