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, const wxPoint &loc, const wxSize &size)
 
 ~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 153 of file listboxes.h.

Constructor & Destructor Documentation

◆ LIBRARY_LISTBOX()

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

Definition at line 40 of file library_listbox.cpp.

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

◆ ~LIBRARY_LISTBOX()

LIBRARY_LISTBOX::~LIBRARY_LISTBOX ( )

Definition at line 47 of file library_listbox.cpp.

48 {
49 }

Member Function Documentation

◆ AppendLine()

void LIBRARY_LISTBOX::AppendLine ( const wxString &  text)

Definition at line 85 of file library_listbox.cpp.

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

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

107 {
108  for( int i = 0; i < GetItemCount(); i++ )
109  Select( i, false );
110 }
size_t i
Definition: json11.cpp:649

References i.

Referenced by CVPCB_MAINFRAME::SetSelectedComponent().

◆ GetCount()

int LIBRARY_LISTBOX::GetCount ( )

Definition at line 52 of file library_listbox.cpp.

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

References m_libraryList.

Referenced by SetLibraryList(), and SetSelection().

◆ GetParent()

CVPCB_MAINFRAME * ITEMS_LISTBOX_BASE::GetParent ( ) const
virtualinherited

Definition at line 113 of file listbox_base.cpp.

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

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

◆ GetSelectedLibrary()

wxString LIBRARY_LISTBOX::GetSelectedLibrary ( )

Definition at line 71 of file library_listbox.cpp.

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

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

100 {
101  return GetFirstSelected();
102 }

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 143 of file library_listbox.cpp.

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

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

References m_libraryList.

◆ OnLeftClick()

void LIBRARY_LISTBOX::OnLeftClick ( wxListEvent &  event)

◆ OnSelectLibrary()

void LIBRARY_LISTBOX::OnSelectLibrary ( wxListEvent &  event)

Definition at line 201 of file library_listbox.cpp.

202 {
203  // Apply the filter
206 
207  SetFocus();
208  GetParent()->OnSelectComponent( event );
209 }
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 118 of file library_listbox.cpp.

119 {
120  int oldSelection = GetSelection();
121 
122  m_libraryList = aList;
123 
124  SetItemCount( m_libraryList.GetCount() );
125 
126  if( GetCount() == 0 || oldSelection < 0 || oldSelection >= GetCount() )
127  SetSelection( 0, true );
128 
129  if( m_libraryList.Count() )
130  {
131  RefreshItems( 0L, m_libraryList.Count()-1 );
132  UpdateWidth();
133  }
134 }
void UpdateWidth(int aLine=-1)
wxArrayString m_libraryList
Definition: listboxes.h:155
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 100 of file library_listbox.cpp.

101 {
102  if( index >= GetCount() )
103  index = GetCount() - 1;
104 
105  if( (index >= 0) && (GetCount() > 0) )
106  {
107 #ifndef __WXMAC__
108  Select( index, State );
109 #endif
110  EnsureVisible( index );
111 #ifdef __WXMAC__
112  Refresh();
113 #endif
114  }
115 }
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 58 of file library_listbox.cpp.

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

References m_libraryList, and ITEMS_LISTBOX_BASE::UpdateWidth().

◆ UpdateWidth()

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

Definition at line 52 of file listbox_base.cpp.

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