KiCad PCB EDA Suite
LIBRARY_LISTBOX Class Reference

#include <listboxes.h>

Inheritance diagram for LIBRARY_LISTBOX:
ITEMS_LISTBOX_BASE

Public Member Functions

 LIBRARY_LISTBOX (CVPCB_MAINFRAME *parent, wxWindowID id)
 
 ~LIBRARY_LISTBOX ()
 
int GetCount ()
 
void SetSelection (int index, bool State=true)
 
void SetString (unsigned linecount, const wxString &text)
 
void AppendLine (const wxString &text)
 
void SetLibraryList (const wxArrayString &aList)
 
wxString GetSelectedLibrary ()
 
wxString OnGetItemText (long item, long column) const override
 
void OnLeftClick (wxListEvent &event)
 
void OnSelectLibrary (wxListEvent &event)
 
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 footprint that the name starts by the letter. More...
 
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)
 

Private Attributes

wxArrayString m_libraryList
 

Detailed Description

Definition at line 148 of file listboxes.h.

Constructor & Destructor Documentation

◆ LIBRARY_LISTBOX()

LIBRARY_LISTBOX::LIBRARY_LISTBOX ( CVPCB_MAINFRAME parent,
wxWindowID  id 
)

Definition at line 40 of file library_listbox.cpp.

40  :
41  ITEMS_LISTBOX_BASE( parent, id, wxDefaultPosition, wxDefaultSize, wxLC_SINGLE_SEL )
42 {
43 }
ITEMS_LISTBOX_BASE(CVPCB_MAINFRAME *aParent, wxWindowID aId, const wxPoint &aLocation=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, long aStyle=0)

◆ ~LIBRARY_LISTBOX()

LIBRARY_LISTBOX::~LIBRARY_LISTBOX ( )

Definition at line 46 of file library_listbox.cpp.

47 {
48 }

Member Function Documentation

◆ AppendLine()

void LIBRARY_LISTBOX::AppendLine ( const wxString &  text)

Definition at line 84 of file library_listbox.cpp.

85 {
86  m_libraryList.Add( text );
87  int lines = m_libraryList.Count();
88  SetItemCount( lines );
89  UpdateWidth( lines - 1 );
90 }
void UpdateWidth(int aLine=-1)
wxArrayString m_libraryList
Definition: listboxes.h:150

References m_libraryList, and ITEMS_LISTBOX_BASE::UpdateWidth().

◆ 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 LIBRARY_LISTBOX::GetCount ( )

Definition at line 51 of file library_listbox.cpp.

52 {
53  return m_libraryList.Count();
54 }
wxArrayString m_libraryList
Definition: listboxes.h:150

References m_libraryList.

Referenced by SetLibraryList(), and SetSelection().

◆ 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(), COMPONENTS_LISTBOX::OnSelectComponent(), and OnSelectLibrary().

◆ GetSelectedLibrary()

wxString LIBRARY_LISTBOX::GetSelectedLibrary ( )

Definition at line 70 of file library_listbox.cpp.

71 {
72  wxString libraryName;
73  int ii = GetFirstSelected();
74 
75  if( ii >= 0 )
76  {
77  libraryName = m_libraryList[ii];
78  }
79 
80  return libraryName;
81 }
wxArrayString m_libraryList
Definition: listboxes.h:150

References m_libraryList.

Referenced by CVPCB_MAINFRAME::DisplayStatus(), and CVPCB_MAINFRAME::OnSelectComponent().

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

◆ OnChar()

void LIBRARY_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 footprint that the name starts by the letter.

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

Definition at line 142 of file library_listbox.cpp.

143 {
144  wxLogTrace( kicadTraceKeyEvent, "LIBRARY_LISTBOX::OnChar %s", dump( event ) );
145 
146  int key = event.GetKeyCode();
147 
148  switch( key )
149  {
150  case WXK_HOME:
151  case WXK_END:
152  case WXK_UP:
153  case WXK_DOWN:
154  case WXK_PAGEUP:
155  case WXK_PAGEDOWN:
156  event.Skip();
157  return;
158 
159  default:
160  break;
161  }
162 
163  // Search for an item name starting by the key code:
164  key = toupper(key);
165 
166  for( unsigned ii = 0; ii < m_libraryList.GetCount(); ii++ )
167  {
168  wxString text = m_libraryList.Item( ii );
169 
170  // Search for the start char of the footprint name. Skip the line number.
171  text.Trim( false ); // Remove leading spaces in line
172  unsigned jj = 0;
173 
174  for( ; jj < text.Len(); jj++ )
175  {
176  // skip line number
177  if( text[jj] == ' ' )
178  break;
179  }
180 
181  for( ; jj < text.Len(); jj++ )
182  { // skip blanks
183  if( text[jj] != ' ' )
184  break;
185  }
186 
187  int start_char = toupper( text[jj] );
188 
189  if( key == start_char )
190  {
191  SetSelection( ii, true ); // Ensure visible
192  break;
193  }
194  }
195 
196  event.Skip();
197 }
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.
wxArrayString m_libraryList
Definition: listboxes.h:150
void SetSelection(int index, bool State=true)
const wxChar *const kicadTraceKeyEvent
Flag to enable wxKeyEvent debug tracing.

References dump(), and kicadTraceKeyEvent.

◆ OnGetItemText()

wxString LIBRARY_LISTBOX::OnGetItemText ( long  item,
long  column 
) const
override

Definition at line 93 of file library_listbox.cpp.

94 {
95  return m_libraryList.Item( item );
96 }
wxArrayString m_libraryList
Definition: listboxes.h:150

References m_libraryList.

◆ OnLeftClick()

void LIBRARY_LISTBOX::OnLeftClick ( wxListEvent &  event)

◆ OnSelectLibrary()

void LIBRARY_LISTBOX::OnSelectLibrary ( wxListEvent &  event)

Definition at line 200 of file library_listbox.cpp.

201 {
202  // Apply the filter
205 
206  SetFocus();
207  GetParent()->OnSelectComponent( event );
208 }
void OnSelectComponent(wxListEvent &event)
Function OnSelectComponent Called when clicking on a component in component list window.
void SetFootprintFilter(FOOTPRINTS_LISTBOX::FP_FILTER_T aFilter, CVPCB_MAINFRAME::CVPCB_FILTER_ACTION aAction)
Function SetFootprintFilter Set a filter criteria to either on/off or toggle the criteria.
virtual CVPCB_MAINFRAME * GetParent() const

References CVPCB_MAINFRAME::FILTER_ENABLE, FOOTPRINTS_LISTBOX::FILTERING_BY_LIBRARY, ITEMS_LISTBOX_BASE::GetParent(), CVPCB_MAINFRAME::OnSelectComponent(), and CVPCB_MAINFRAME::SetFootprintFilter().

◆ SetLibraryList()

void LIBRARY_LISTBOX::SetLibraryList ( const wxArrayString &  aList)

Definition at line 117 of file library_listbox.cpp.

118 {
119  int oldSelection = GetSelection();
120 
121  m_libraryList = aList;
122 
123  SetItemCount( m_libraryList.GetCount() );
124 
125  if( GetCount() == 0 || oldSelection < 0 || oldSelection >= GetCount() )
126  SetSelection( 0, true );
127 
128  if( m_libraryList.Count() )
129  {
130  RefreshItems( 0L, m_libraryList.Count()-1 );
131  UpdateWidth();
132  }
133 }
void UpdateWidth(int aLine=-1)
wxArrayString m_libraryList
Definition: listboxes.h:150
void SetSelection(int index, bool State=true)

References GetCount(), ITEMS_LISTBOX_BASE::GetSelection(), m_libraryList, SetSelection(), and ITEMS_LISTBOX_BASE::UpdateWidth().

Referenced by CVPCB_MAINFRAME::BuildLIBRARY_LISTBOX().

◆ SetSelection()

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

Definition at line 99 of file library_listbox.cpp.

100 {
101  if( index >= GetCount() )
102  index = GetCount() - 1;
103 
104  if( (index >= 0) && (GetCount() > 0) )
105  {
106 #ifndef __WXMAC__
107  Select( index, State );
108 #endif
109  EnsureVisible( index );
110 #ifdef __WXMAC__
111  Refresh();
112 #endif
113  }
114 }
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...

References GetCount(), and Refresh().

Referenced by SetLibraryList().

◆ SetString()

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

Definition at line 57 of file library_listbox.cpp.

58 {
59  unsigned count = m_libraryList.Count();
60  if( count > 0 )
61  {
62  if( linecount >= count )
63  linecount = count - 1;
64  m_libraryList[linecount] = text;
65  UpdateWidth( linecount );
66  }
67 }
void UpdateWidth(int aLine=-1)
wxArrayString m_libraryList
Definition: listboxes.h:150

References m_libraryList, and ITEMS_LISTBOX_BASE::UpdateWidth().

◆ 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(), AppendLine(), COMPONENTS_LISTBOX::AppendLine(), CVPCB_MAINFRAME::BuildCmpListBox(), FOOTPRINTS_LISTBOX::SetFootprints(), SetLibraryList(), FOOTPRINTS_LISTBOX::SetString(), SetString(), and COMPONENTS_LISTBOX::SetString().

Member Data Documentation

◆ m_libraryList

wxArrayString LIBRARY_LISTBOX::m_libraryList
private

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