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)
 
 ~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 191 of file listboxes.h.

Constructor & Destructor Documentation

◆ COMPONENTS_LISTBOX()

COMPONENTS_LISTBOX::COMPONENTS_LISTBOX ( CVPCB_MAINFRAME parent,
wxWindowID  id 
)

Definition at line 35 of file components_listbox.cpp.

35  :
36  ITEMS_LISTBOX_BASE( parent, id )
37 {
38 }
ITEMS_LISTBOX_BASE(CVPCB_MAINFRAME *aParent, wxWindowID aId, const wxPoint &aLocation=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, long aStyle=0)

◆ ~COMPONENTS_LISTBOX()

COMPONENTS_LISTBOX::~COMPONENTS_LISTBOX ( )

Definition at line 41 of file components_listbox.cpp.

42 {
43 }

Member Function Documentation

◆ AppendLine()

void COMPONENTS_LISTBOX::AppendLine ( const wxString &  text)

Definition at line 78 of file components_listbox.cpp.

79 {
80  m_ComponentList.Add( text );
81  int lines = m_ComponentList.Count();
82  SetItemCount( lines );
83  UpdateWidth( lines - 1 );
84 }
void UpdateWidth(int aLine=-1)
wxArrayString m_ComponentList
Definition: listboxes.h:194

References m_ComponentList, and ITEMS_LISTBOX_BASE::UpdateWidth().

Referenced by CVPCB_MAINFRAME::ReadNetListAndFpFiles().

◆ Clear()

void COMPONENTS_LISTBOX::Clear ( )

Definition at line 52 of file components_listbox.cpp.

53 {
54  m_ComponentList.Clear();
55  SetItemCount( 0 );
56 }
wxArrayString m_ComponentList
Definition: listboxes.h:194

References Clear().

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

◆ DeselectAll()

void ITEMS_LISTBOX_BASE::DeselectAll ( )
inherited

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

Definition at line 107 of file listbox_base.cpp.

108 {
109  for( int i = 0; i < GetItemCount(); i++ )
110  Select( i, false );
111 }

Referenced by CVPCB_MAINFRAME::SetSelectedComponent().

◆ GetCount()

int COMPONENTS_LISTBOX::GetCount ( )

◆ GetParent()

CVPCB_MAINFRAME * ITEMS_LISTBOX_BASE::GetParent ( void  ) const
virtualinherited

Definition at line 114 of file listbox_base.cpp.

115 {
116  return (CVPCB_MAINFRAME*) wxListView::GetParent();
117 }
The CvPcb application main window.

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

◆ GetSelection()

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 100 of file listbox_base.cpp.

101 {
102  return GetFirstSelected();
103 }

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

◆ OnChar()

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 110 of file components_listbox.cpp.

111 {
112  wxLogTrace( kicadTraceKeyEvent, "COMPONENTS_LISTBOX::OnChar %s", dump( event ) );
113 
114  int key = event.GetKeyCode();
115 
116  switch( key )
117  {
118  case WXK_HOME:
119  case WXK_END:
120  case WXK_UP:
121  case WXK_DOWN:
122  case WXK_PAGEUP:
123  case WXK_PAGEDOWN:
124  event.Skip();
125  return;
126 
127 
128  default:
129  break;
130  }
131 
132  // Search for an item name starting by the key code:
133  key = toupper( key );
134 
135  for( unsigned ii = 0; ii < m_ComponentList.GetCount(); ii++ )
136  {
137  wxString text = m_ComponentList.Item( ii );
138 
139  // Search for the start char of the footprint name. Skip the line number.
140  text.Trim( false ); // Remove leading spaces in line
141  unsigned jj = 0;
142 
143  for( ; jj < text.Len(); jj++ )
144  { // skip line number
145  if( text[jj] == ' ' )
146  break;
147  }
148 
149  for( ; jj < text.Len(); jj++ )
150  { // skip blanks
151  if( text[jj] != ' ' )
152  break;
153  }
154 
155  int start_char = toupper( text[jj] );
156 
157  if( key == start_char )
158  {
159  SetSelection( (int) ii, true ); // Ensure visible
160  break;
161  }
162  }
163 
164  event.Skip();
165 }
void SetSelection(int index, bool State=true)
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.
wxArrayString m_ComponentList
Definition: listboxes.h:194
const wxChar *const kicadTraceKeyEvent
Flag to enable wxKeyEvent debug tracing.

References dump(), kicadTraceKeyEvent, m_ComponentList, and SetSelection().

◆ OnGetItemText()

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 87 of file components_listbox.cpp.

88 {
89  return m_ComponentList.Item( item );
90 }
wxArrayString m_ComponentList
Definition: listboxes.h:194

References m_ComponentList.

◆ OnSelectComponent()

void COMPONENTS_LISTBOX::OnSelectComponent ( wxListEvent &  event)

Definition at line 168 of file components_listbox.cpp.

169 {
170  SetFocus();
171  GetParent()->OnSelectComponent( event );
172 }
void OnSelectComponent(wxListEvent &event)
Function OnSelectComponent Called when clicking on a component in component list window.
virtual CVPCB_MAINFRAME * GetParent() const

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

◆ SetSelection()

void COMPONENTS_LISTBOX::SetSelection ( int  index,
bool  State = true 
)

Definition at line 93 of file components_listbox.cpp.

94 {
95  if( index >= GetCount() )
96  index = GetCount() - 1;
97 
98  if( (index >= 0) && (GetCount() > 0) )
99  {
100  Select( index, State );
101  EnsureVisible( index );
102 
103 #ifdef __WXMAC__
104  Update();
105 #endif
106  }
107 }

References GetCount().

Referenced by CVPCB_MAINFRAME::BuildCmpListBox(), OnChar(), CVPCB_MAINFRAME::ReadNetListAndFpFiles(), and CVPCB_MAINFRAME::SetSelectedComponent().

◆ SetString()

void COMPONENTS_LISTBOX::SetString ( unsigned  linecount,
const wxString &  text 
)

Definition at line 65 of file components_listbox.cpp.

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

References m_ComponentList, and ITEMS_LISTBOX_BASE::UpdateWidth().

Referenced by CVPCB_MAINFRAME::AssociateFootprint().

◆ UpdateWidth()

void ITEMS_LISTBOX_BASE::UpdateWidth ( int  aLine = -1)
inherited

Definition at line 53 of file listbox_base.cpp.

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

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().

Member Data Documentation

◆ m_ComponentList

wxArrayString COMPONENTS_LISTBOX::m_ComponentList

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