KiCad PCB EDA Suite
COMPONENTS_LISTBOX Class Reference

#include <listboxes.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 197 of file listboxes.h.

Constructor & Destructor Documentation

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

Definition at line 36 of file components_listbox.cpp.

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

Definition at line 43 of file components_listbox.cpp.

References ID_CVPCB_COMPONENT_LIST, OnChar(), and OnSelectComponent().

44 {
45 }

Member Function Documentation

void COMPONENTS_LISTBOX::AppendLine ( const wxString &  text)

Definition at line 80 of file components_listbox.cpp.

References m_ComponentList, and ITEMS_LISTBOX_BASE::UpdateWidth().

Referenced by CVPCB_MAINFRAME::ReadNetListAndFpFiles().

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

Definition at line 54 of file components_listbox.cpp.

References m_ComponentList.

Referenced by CVPCB_MAINFRAME::ReadNetListAndFpFiles().

55 {
56  m_ComponentList.Clear();
57  SetItemCount( 0 );
58 }
wxArrayString m_ComponentList
Definition: listboxes.h:200
void ITEMS_LISTBOX_BASE::DeselectAll ( )
inherited

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

Definition at line 111 of file listbox_base.cpp.

References i.

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

112 {
113  for( int i = 0; i < GetItemCount(); i++ )
114  Select( i, false );
115 }
size_t i
Definition: json11.cpp:597
int COMPONENTS_LISTBOX::GetCount ( )
CVPCB_MAINFRAME * ITEMS_LISTBOX_BASE::GetParent ( ) const
virtualinherited
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 104 of file listbox_base.cpp.

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

105 {
106  return GetFirstSelected();
107 }
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 112 of file components_listbox.cpp.

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

Referenced by ~COMPONENTS_LISTBOX().

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

References m_ComponentList.

90 {
91  return m_ComponentList.Item( item );
92 }
wxArrayString m_ComponentList
Definition: listboxes.h:200
void COMPONENTS_LISTBOX::OnSelectComponent ( wxListEvent &  event)

Definition at line 179 of file components_listbox.cpp.

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

Referenced by ~COMPONENTS_LISTBOX().

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

Definition at line 95 of file 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().

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

Definition at line 67 of file components_listbox.cpp.

References m_ComponentList, and ITEMS_LISTBOX_BASE::UpdateWidth().

Referenced by CVPCB_MAINFRAME::SetNewPkg().

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

Definition at line 57 of file listbox_base.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().

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

Member Data Documentation

wxArrayString COMPONENTS_LISTBOX::m_ComponentList

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