KiCad PCB EDA Suite
Loading...
Searching...
No Matches
wx_dataviewctrl.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
21#include <wx/dataview.h>
22
23wxDataViewItem WX_DATAVIEWCTRL::GetPrevItem( wxDataViewItem const& aItem )
24{
25 wxDataViewItem prevItem = GetPrevSibling( aItem );
26
27 if( !prevItem.IsOk() )
28 {
29 prevItem = GetModel()->GetParent( aItem );
30 }
31 else if( IsExpanded( prevItem ) )
32 {
33 wxDataViewItemArray children;
34 GetModel()->GetChildren( prevItem, children );
35
36 if( children.size() )
37 prevItem = children[children.size() - 1];
38 }
39
40 return prevItem;
41}
42
43
44wxDataViewItem WX_DATAVIEWCTRL::GetNextItem( wxDataViewItem const& aItem )
45{
46 wxDataViewItem nextItem;
47 wxDataViewItem invalid;
48
49 if( !aItem.IsOk() )
50 {
51 // No selection. Select the first.
52 wxDataViewItemArray children;
53 GetModel()->GetChildren( aItem, children );
54
55 if( children.size() )
56 return children[0];
57
58 return invalid;
59 }
60
61 if( IsExpanded( aItem ) )
62 {
63 wxDataViewItemArray children;
64 GetModel()->GetChildren( aItem, children );
65
66 if( children.size() )
67 return children[0];
68
69 return invalid;
70 }
71 else
72 {
73 // Walk up levels until we find one that has a next sibling.
74 for( wxDataViewItem walk = aItem; walk.IsOk(); walk = GetModel()->GetParent( walk ) )
75 {
76 nextItem = GetNextSibling( walk );
77
78 if( nextItem.IsOk() )
79 break;
80 }
81 }
82
83 return nextItem;
84}
85
86
87wxDataViewItem WX_DATAVIEWCTRL::GetPrevSibling( wxDataViewItem const& aItem )
88{
89 wxDataViewItemArray siblings;
90 wxDataViewItem invalid;
91 wxDataViewItem parent = GetModel()->GetParent( aItem );
92
93 GetModel()->GetChildren( parent, siblings );
94
95 for( size_t i = 0; i < siblings.size(); ++i )
96 {
97 if( siblings[i] == aItem )
98 {
99 if( i == 0 )
100 return invalid;
101 else
102 return siblings[i - 1];
103 }
104 }
105
106 return invalid;
107}
108
109
110wxDataViewItem WX_DATAVIEWCTRL::GetNextSibling( wxDataViewItem const& aItem )
111{
112 wxDataViewItemArray siblings;
113 wxDataViewItem invalid;
114 wxDataViewItem parent = GetModel()->GetParent( aItem );
115
116 GetModel()->GetChildren( parent, siblings );
117
118 for( size_t i = 0; i < siblings.size(); ++i )
119 {
120 if( siblings[i] == aItem )
121 {
122 if( i == siblings.size() - 1 )
123 return invalid;
124 else
125 return siblings[i + 1];
126 }
127 }
128
129 return invalid;
130}
131
132
133void recursiveDescent( WX_DATAVIEWCTRL* aCtrl, wxDataViewItem aItem, bool aExpand )
134{
135 wxDataViewItemArray children;
136
137 aCtrl->GetModel()->GetChildren( aItem, children );
138
139 for( size_t i = 0; i < children.size(); ++i )
140 recursiveDescent( aCtrl, children[i], aExpand );
141
142 if( aItem )
143 {
144 if( aExpand )
145 aCtrl->Expand( aItem );
146 else
147 aCtrl->Collapse( aItem );
148 }
149}
150
151
153{
154 recursiveDescent( this, wxDataViewItem(), true );
155}
156
157
159{
160 recursiveDescent( this, wxDataViewItem(), false );
161}
Extension of the wxDataViewCtrl to include some helper functions for working with items.
wxDataViewItem GetPrevSibling(wxDataViewItem const &aItem)
Get the previous sibling of an item.
wxDataViewItem GetNextSibling(wxDataViewItem const &aItem)
Get the next sibling of an item.
wxDataViewItem GetNextItem(wxDataViewItem const &aItem)
Get the next item in list order.
wxDataViewItem GetPrevItem(wxDataViewItem const &aItem)
Get the previous item in list order.
static void recursiveDescent(wxSizer *aSizer, std::map< int, wxString > &aLabels)
void recursiveDescent(WX_DATAVIEWCTRL *aCtrl, wxDataViewItem aItem, bool aExpand)