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

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.

References GetNextSibling().

Referenced by WIDGET_HOTKEY_LIST::CheckKeyConflicts(), DIALOG_CHOOSE_COMPONENT::OnQueryCharHook(), TWO_COLUMN_TREE_LIST::OnSize(), WIDGET_HOTKEY_LIST::TransferDataFromControl(), WIDGET_HOTKEY_LIST::TransferDefaultsToControl(), and WIDGET_HOTKEY_LIST::UpdateFromClientData().

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

Referenced by GetNextItem().

100 {
101  wxDataViewItemArray siblings;
102  wxDataViewItem invalid;
103  wxDataViewItem parent = aView.GetModel()->GetParent( aItem );
104 
105  aView.GetModel()->GetChildren( parent, siblings );
106 
107  for( size_t i = 0; i < siblings.size(); ++i )
108  {
109  if( siblings[i] == aItem )
110  {
111  if( i == siblings.size() - 1 )
112  return invalid;
113  else
114  return siblings[i + 1];
115  }
116  }
117 
118  return invalid;
119 }
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.

References GetPrevSibling().

Referenced by DIALOG_CHOOSE_COMPONENT::OnQueryCharHook().

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.
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 76 of file wxdataviewctrl_helpers.cpp.

Referenced by GetPrevItem().

77 {
78  wxDataViewItemArray siblings;
79  wxDataViewItem invalid;
80  wxDataViewItem parent = aView.GetModel()->GetParent( aItem );
81 
82  aView.GetModel()->GetChildren( parent, siblings );
83 
84  for( size_t i = 0; i < siblings.size(); ++i )
85  {
86  if( siblings[i] == aItem )
87  {
88  if( i == 0 )
89  return invalid;
90  else
91  return siblings[i - 1];
92  }
93  }
94 
95  return invalid;
96 }