KiCad PCB EDA Suite
COMPONENTS_LISTBOX Class Reference

#include <listview_classes.h>

Inheritance diagram for COMPONENTS_LISTBOX:
ITEMS_LISTBOX_BASE

Public Member Functions

 COMPONENTS_LISTBOX (CVPCB_MAINFRAME *parent, wxWindowID id, const wxPoint &loc, const wxSize &size)
 
 ~COMPONENTS_LISTBOX ()
 
void Clear ()
 
int GetCount ()
 
wxString OnGetItemText (long item, long column) const override
 Function OnGetItemText this overloaded function MUST be provided for the wxLC_VIRTUAL mode because real data is not handled by ITEMS_LISTBOX_BASE. More...
 
void SetSelection (int index, bool State=true)
 
void SetString (unsigned linecount, const wxString &text)
 
void AppendLine (const wxString &text)
 
void OnChar (wxKeyEvent &event)
 Function OnChar called on a key pressed Call default handler for some special keys, and for "ascii" keys, select the first component that the name starts by the letter. More...
 
void OnSelectComponent (wxListEvent &event)
 
int GetSelection ()
 
void DeselectAll ()
 Removes all selection in lists which can have more than one item selected. More...
 
virtual CVPCB_MAINFRAMEGetParent () const
 
void UpdateWidth (int aLine=-1)
 

Public Attributes

wxArrayString m_ComponentList
 

Detailed Description

Definition at line 196 of file listview_classes.h.

Constructor & Destructor Documentation

COMPONENTS_LISTBOX::COMPONENTS_LISTBOX ( CVPCB_MAINFRAME parent,
wxWindowID  id,
const wxPoint loc,
const wxSize &  size 
)

Definition at line 37 of file class_components_listbox.cpp.

38  :
39  ITEMS_LISTBOX_BASE( parent, id, loc, size, 0 )
40 {
41 }
ITEMS_LISTBOX_BASE(CVPCB_MAINFRAME *aParent, wxWindowID aId, const wxPoint &aLocation, const wxSize &aSize, long aStyle=0)
Definition: listboxes.cpp:44
COMPONENTS_LISTBOX::~COMPONENTS_LISTBOX ( )

Definition at line 44 of file class_components_listbox.cpp.

45 {
46 }

Member Function Documentation

void COMPONENTS_LISTBOX::AppendLine ( const wxString &  text)

Definition at line 81 of file class_components_listbox.cpp.

References m_ComponentList, and ITEMS_LISTBOX_BASE::UpdateWidth().

Referenced by CVPCB_MAINFRAME::ReadNetListAndFpFiles().

82 {
83  m_ComponentList.Add( text );
84  int lines = m_ComponentList.Count();
85  SetItemCount( lines );
86  UpdateWidth( lines - 1 );
87 }
void UpdateWidth(int aLine=-1)
Definition: listboxes.cpp:58
wxArrayString m_ComponentList
void COMPONENTS_LISTBOX::Clear ( )

Definition at line 55 of file class_components_listbox.cpp.

References Clear().

Referenced by Clear(), and CVPCB_MAINFRAME::ReadNetListAndFpFiles().

56 {
57  m_ComponentList.Clear();
58  SetItemCount( 0 );
59 }
wxArrayString m_ComponentList
void ITEMS_LISTBOX_BASE::DeselectAll ( )
inherited

Removes all selection in lists which can have more than one item selected.

Definition at line 112 of file listboxes.cpp.

Referenced by CVPCB_MAINFRAME::DelAssociations(), CVPCB_MAINFRAME::ToFirstNA(), and CVPCB_MAINFRAME::ToPreviousNA().

113 {
114  for( int i = 0; i < GetItemCount(); i++ )
115  Select( i, false );
116 }
int COMPONENTS_LISTBOX::GetCount ( )
CVPCB_MAINFRAME * ITEMS_LISTBOX_BASE::GetParent ( ) const
virtualinherited

Definition at line 119 of file listboxes.cpp.

Referenced by FOOTPRINTS_LISTBOX::OnChar(), OnChar(), FOOTPRINTS_LISTBOX::OnLeftDClick(), OnSelectComponent(), and LIBRARY_LISTBOX::OnSelectLibrary().

120 {
121  return (CVPCB_MAINFRAME*) wxListView::GetParent();
122 }
The CvPcb application main window.
int ITEMS_LISTBOX_BASE::GetSelection ( )
inherited
Returns
the index of the selected item in lists allowing only one item selected and the index of the first selected item in lists allowing many selection

Definition at line 105 of file listboxes.cpp.

Referenced by CVPCB_MAINFRAME::GetSelectedComponent(), CVPCB_MAINFRAME::refreshAfterComponentSearch(), CVPCB_MAINFRAME::SendMessageToEESCHEMA(), FOOTPRINTS_LISTBOX::SetFootprints(), and LIBRARY_LISTBOX::SetLibraryList().

106 {
107  return GetFirstSelected();
108 }
void COMPONENTS_LISTBOX::OnChar ( wxKeyEvent &  event)

Function OnChar called on a key pressed Call default handler for some special keys, and for "ascii" keys, select the first component that the name starts by the letter.

This is the default behavior of a listbox, but because we use virtual lists, the listbox does not know anything to what is displayed, we must handle this behavior here. Furthermore the reference of components is not at the beginning of displayed lines (the first word is the line number)

Definition at line 113 of file class_components_listbox.cpp.

References CVPCB_MAINFRAME::ChangeFocus(), ITEMS_LISTBOX_BASE::GetParent(), m_ComponentList, and SetSelection().

114 {
115  int key = event.GetKeyCode();
116 
117  switch( key )
118  {
119  case WXK_TAB:
120  case WXK_RIGHT:
121  case WXK_NUMPAD_RIGHT:
122  GetParent()->ChangeFocus( true );
123  return;
124 
125  case WXK_LEFT:
126  case WXK_NUMPAD_LEFT:
127  GetParent()->ChangeFocus( false );
128  return;
129 
130  case WXK_HOME:
131  case WXK_END:
132  case WXK_UP:
133  case WXK_DOWN:
134  case WXK_PAGEUP:
135  case WXK_PAGEDOWN:
136  event.Skip();
137  return;
138 
139 
140  default:
141  break;
142  }
143 
144  // Search for an item name starting by the key code:
145  key = toupper( key );
146 
147  for( unsigned ii = 0; ii < m_ComponentList.GetCount(); ii++ )
148  {
149  wxString text = m_ComponentList.Item( ii );
150 
151  // Search for the start char of the footprint name. Skip the line number.
152  text.Trim( false ); // Remove leading spaces in line
153  unsigned jj = 0;
154 
155  for( ; jj < text.Len(); jj++ )
156  { // skip line number
157  if( text[jj] == ' ' )
158  break;
159  }
160 
161  for( ; jj < text.Len(); jj++ )
162  { // skip blanks
163  if( text[jj] != ' ' )
164  break;
165  }
166 
167  int start_char = toupper( text[jj] );
168 
169  if( key == start_char )
170  {
171  SetSelection( (int) ii, true ); // Ensure visible
172  break;
173  }
174  }
175 
176  event.Skip();
177 }
void SetSelection(int index, bool State=true)
void ChangeFocus(bool aMoveRight)
wxArrayString m_ComponentList
virtual CVPCB_MAINFRAME * GetParent() const
Definition: listboxes.cpp:119
wxString COMPONENTS_LISTBOX::OnGetItemText ( long  item,
long  column 
) const
override

Function OnGetItemText this overloaded function MUST be provided for the wxLC_VIRTUAL mode because real data is not handled by ITEMS_LISTBOX_BASE.

Definition at line 90 of file class_components_listbox.cpp.

References m_ComponentList.

91 {
92  return m_ComponentList.Item( item );
93 }
wxArrayString m_ComponentList
void COMPONENTS_LISTBOX::OnSelectComponent ( wxListEvent &  event)

Definition at line 180 of file class_components_listbox.cpp.

References ITEMS_LISTBOX_BASE::GetParent(), and CVPCB_MAINFRAME::OnSelectComponent().

181 {
182  SetFocus();
183  GetParent()->OnSelectComponent( event );
184 }
void OnSelectComponent(wxListEvent &event)
Function OnSelectComponent Called when clicking on a component in component list window.
virtual CVPCB_MAINFRAME * GetParent() const
Definition: listboxes.cpp:119
void COMPONENTS_LISTBOX::SetSelection ( int  index,
bool  State = true 
)

Definition at line 96 of file class_components_listbox.cpp.

References GetCount().

Referenced by CVPCB_MAINFRAME::BuildCmpListBox(), CVPCB_MAINFRAME::DelAssociations(), OnChar(), CVPCB_MAINFRAME::ReadNetListAndFpFiles(), CVPCB_MAINFRAME::SetNewPkg(), CVPCB_MAINFRAME::ToFirstNA(), and CVPCB_MAINFRAME::ToPreviousNA().

97 {
98  if( index >= GetCount() )
99  index = GetCount() - 1;
100 
101  if( (index >= 0) && (GetCount() > 0) )
102  {
103  Select( index, State );
104  EnsureVisible( index );
105 
106 #ifdef __WXMAC__
107  Update();
108 #endif
109  }
110 }
void COMPONENTS_LISTBOX::SetString ( unsigned  linecount,
const wxString &  text 
)

Definition at line 68 of file class_components_listbox.cpp.

References m_ComponentList, and ITEMS_LISTBOX_BASE::UpdateWidth().

Referenced by CVPCB_MAINFRAME::SetNewPkg().

69 {
70  if( linecount >= m_ComponentList.Count() )
71  linecount = m_ComponentList.Count() - 1;
72 
73  if( m_ComponentList.Count() > 0 )
74  {
75  m_ComponentList[linecount] = text;
76  UpdateWidth( linecount );
77  }
78 }
void UpdateWidth(int aLine=-1)
Definition: listboxes.cpp:58
wxArrayString m_ComponentList
void ITEMS_LISTBOX_BASE::UpdateWidth ( int  aLine = -1)
inherited

Definition at line 58 of file listboxes.cpp.

References ITEMS_LISTBOX_BASE::columnWidth, and ITEMS_LISTBOX_BASE::UpdateLineWidth().

Referenced by FOOTPRINTS_LISTBOX::AppendLine(), LIBRARY_LISTBOX::AppendLine(), AppendLine(), CVPCB_MAINFRAME::BuildCmpListBox(), FOOTPRINTS_LISTBOX::SetFootprints(), LIBRARY_LISTBOX::SetLibraryList(), FOOTPRINTS_LISTBOX::SetString(), LIBRARY_LISTBOX::SetString(), and SetString().

59 {
60  // Less than zero: recalculate width of all items.
61  if( aLine < 0 )
62  {
63  columnWidth = 0;
64  for( int ii = 0; ii < GetItemCount(); ii++ )
65  {
66  UpdateLineWidth( (unsigned)ii );
67  }
68  }
69 
70  // Zero or above: update from a single line.
71  else
72  {
73  if( aLine < GetItemCount() )
74  UpdateLineWidth( (unsigned)aLine );
75  }
76 }
void UpdateLineWidth(unsigned aLine)
Definition: listboxes.cpp:84

Member Data Documentation

wxArrayString COMPONENTS_LISTBOX::m_ComponentList

The documentation for this class was generated from the following files: