KiCad PCB EDA Suite
wxdataviewctrl_helpers.cpp File Reference
#include <wx/dataview.h>
#include <wxdataviewctrl_helpers.h>

Go to the source code of this file.

Functions

wxDataViewItem GetPrevItem (wxDataViewCtrl const &aView, wxDataViewItem const &aItem)
 Get the previous item in list order. More...
 
wxDataViewItem GetNextItem (wxDataViewCtrl const &aView, wxDataViewItem const &aItem)
 Get the next item in list order. More...
 
wxDataViewItem GetPrevSibling (wxDataViewCtrl const &aView, wxDataViewItem const &aItem)
 Get the previous sibling of an item. More...
 
wxDataViewItem GetNextSibling (wxDataViewCtrl const &aView, wxDataViewItem const &aItem)
 Get the next sibling of an item. More...
 

Function Documentation

◆ GetNextItem()

wxDataViewItem GetNextItem ( wxDataViewCtrl const &  aView,
wxDataViewItem const &  aItem 
)

Get the next item in list order.

Parameters
aView- a wxDataViewCtrl with valid model
aItem- a valid item in the model
Returns
the item after aItem, or an invalid item if aItem is at the bottom.

Definition at line 42 of file wxdataviewctrl_helpers.cpp.

43 {
44  wxDataViewItem nextItem;
45  wxDataViewItem invalid;
46 
47  if( !aItem.IsOk() )
48  {
49  // No selection. Select the first.
50  wxDataViewItemArray children;
51  aView.GetModel()->GetChildren( aItem, children );
52 
53  if( children.size() )
54  return children[0];
55 
56  return invalid;
57  }
58 
59  if( aView.IsExpanded( aItem ) )
60  {
61  wxDataViewItemArray children;
62  aView.GetModel()->GetChildren( aItem, children );
63 
64  if( children.size() )
65  return children[0];
66 
67  return invalid;
68  }
69  else
70  {
71  // Walk up levels until we find one that has a next sibling.
72  for( wxDataViewItem walk = aItem; walk.IsOk(); walk = aView.GetModel()->GetParent( walk ) )
73  {
74  nextItem = GetNextSibling( aView, walk );
75 
76  if( nextItem.IsOk() )
77  break;
78  }
79  }
80 
81  return nextItem;
82 }
wxDataViewItem GetNextSibling(wxDataViewCtrl const &aView, wxDataViewItem const &aItem)
Get the next sibling of an item.

References GetNextSibling().

Referenced by LIB_TREE::onQueryCharHook(), and WIDGET_HOTKEY_LIST::updateFromClientData().

◆ GetNextSibling()

wxDataViewItem GetNextSibling ( wxDataViewCtrl const &  aView,
wxDataViewItem const &  aItem 
)

Get the next sibling of an item.

Parameters
aView- awxDataViewCtrl with valid model
aItem- a valid item in the model
Returns
the sibling after aItem, or an invalid item if aItem has no siblings after it.

Definition at line 108 of file wxdataviewctrl_helpers.cpp.

109 {
110  wxDataViewItemArray siblings;
111  wxDataViewItem invalid;
112  wxDataViewItem parent = aView.GetModel()->GetParent( aItem );
113 
114  aView.GetModel()->GetChildren( parent, siblings );
115 
116  for( size_t i = 0; i < siblings.size(); ++i )
117  {
118  if( siblings[i] == aItem )
119  {
120  if( i == siblings.size() - 1 )
121  return invalid;
122  else
123  return siblings[i + 1];
124  }
125  }
126 
127  return invalid;
128 }

Referenced by GetNextItem().

◆ GetPrevItem()

wxDataViewItem GetPrevItem ( wxDataViewCtrl const &  aView,
wxDataViewItem const &  aItem 
)

Get the previous item in list order.

Parameters
aView- a wxDataViewCtrl with valid model
aItem- a valid item in the model
Returns
the item before aItem, or an invalid item if aItem is at the top.

Definition at line 23 of file wxdataviewctrl_helpers.cpp.

24 {
25  auto prevItem = GetPrevSibling( aView, aItem );
26 
27  if( !prevItem.IsOk() )
28  {
29  prevItem = aView.GetModel()->GetParent( aItem );
30  }
31  else if( aView.IsExpanded( prevItem ) )
32  {
33  wxDataViewItemArray children;
34  aView.GetModel()->GetChildren( prevItem, children );
35  prevItem = children[children.size() - 1];
36  }
37 
38  return prevItem;
39 }
wxDataViewItem GetPrevSibling(wxDataViewCtrl const &aView, wxDataViewItem const &aItem)
Get the previous sibling of an item.

References GetPrevSibling().

Referenced by LIB_TREE::onQueryCharHook().

◆ GetPrevSibling()

wxDataViewItem GetPrevSibling ( wxDataViewCtrl const &  aView,
wxDataViewItem const &  aItem 
)

Get the previous sibling of an item.

Parameters
aView- awxDataViewCtrl with valid model
aItem- a valid item in the model
Returns
the sibling before aItem, or an invalid item if aItem has no siblings before it.

Definition at line 85 of file wxdataviewctrl_helpers.cpp.

86 {
87  wxDataViewItemArray siblings;
88  wxDataViewItem invalid;
89  wxDataViewItem parent = aView.GetModel()->GetParent( aItem );
90 
91  aView.GetModel()->GetChildren( parent, siblings );
92 
93  for( size_t i = 0; i < siblings.size(); ++i )
94  {
95  if( siblings[i] == aItem )
96  {
97  if( i == 0 )
98  return invalid;
99  else
100  return siblings[i - 1];
101  }
102  }
103 
104  return invalid;
105 }

Referenced by GetPrevItem().