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 152 of file listboxes.h.

Constructor & Destructor Documentation

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

Definition at line 42 of file library_listbox.cpp.

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

Definition at line 49 of file library_listbox.cpp.

50 {
51 }

Member Function Documentation

void LIBRARY_LISTBOX::AppendLine ( const wxString &  text)

Definition at line 87 of file library_listbox.cpp.

References m_libraryList, and ITEMS_LISTBOX_BASE::UpdateWidth().

88 {
89  m_libraryList.Add( text );
90  int lines = m_libraryList.Count();
91  SetItemCount( lines );
92  UpdateWidth( lines - 1 );
93 }
void UpdateWidth(int aLine=-1)
wxArrayString m_libraryList
Definition: listboxes.h:154
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 LIBRARY_LISTBOX::GetCount ( )

Definition at line 54 of file library_listbox.cpp.

References m_libraryList.

Referenced by SetLibraryList(), and SetSelection().

55 {
56  return m_libraryList.Count();
57 }
wxArrayString m_libraryList
Definition: listboxes.h:154
CVPCB_MAINFRAME * ITEMS_LISTBOX_BASE::GetParent ( ) const
virtualinherited
wxString LIBRARY_LISTBOX::GetSelectedLibrary ( )

Definition at line 73 of file library_listbox.cpp.

References m_libraryList.

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

74 {
75  wxString libraryName;
76  int ii = GetFirstSelected();
77 
78  if( ii >= 0 )
79  {
80  libraryName = m_libraryList[ii];
81  }
82 
83  return libraryName;
84 }
wxArrayString m_libraryList
Definition: listboxes.h:154
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::refreshAfterComponentSearch(), CVPCB_MAINFRAME::SendMessageToEESCHEMA(), FOOTPRINTS_LISTBOX::SetFootprints(), and SetLibraryList().

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

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

Referenced by SetLibraryList().

146 {
147  int key = event.GetKeyCode();
148 
149  switch( key )
150  {
151  case WXK_TAB:
152  case WXK_RIGHT:
153  case WXK_NUMPAD_RIGHT:
154  GetParent()->ChangeFocus( true );
155  return;
156 
157  case WXK_LEFT:
158  case WXK_NUMPAD_LEFT:
159  GetParent()->ChangeFocus( false );
160  return;
161 
162  case WXK_HOME:
163  case WXK_END:
164  case WXK_UP:
165  case WXK_DOWN:
166  case WXK_PAGEUP:
167  case WXK_PAGEDOWN:
168  event.Skip();
169  return;
170 
171  default:
172  break;
173  }
174 
175  // Search for an item name starting by the key code:
176  key = toupper(key);
177 
178  for( unsigned ii = 0; ii < m_libraryList.GetCount(); ii++ )
179  {
180  wxString text = m_libraryList.Item( ii );
181 
182  // Search for the start char of the footprint name. Skip the line number.
183  text.Trim( false ); // Remove leading spaces in line
184  unsigned jj = 0;
185 
186  for( ; jj < text.Len(); jj++ )
187  {
188  // skip line number
189  if( text[jj] == ' ' )
190  break;
191  }
192 
193  for( ; jj < text.Len(); jj++ )
194  { // skip blanks
195  if( text[jj] != ' ' )
196  break;
197  }
198 
199  int start_char = toupper( text[jj] );
200 
201  if( key == start_char )
202  {
203  SetSelection( ii, true ); // Ensure visible
204  break;
205  }
206  }
207 
208  event.Skip();
209 }
void ChangeFocus(bool aMoveRight)
wxArrayString m_libraryList
Definition: listboxes.h:154
void SetSelection(int index, bool State=true)
virtual CVPCB_MAINFRAME * GetParent() const
wxString LIBRARY_LISTBOX::OnGetItemText ( long  item,
long  column 
) const
override

Definition at line 96 of file library_listbox.cpp.

References m_libraryList.

97 {
98  return m_libraryList.Item( item );
99 }
wxArrayString m_libraryList
Definition: listboxes.h:154
void LIBRARY_LISTBOX::OnLeftClick ( wxListEvent &  event)
void LIBRARY_LISTBOX::OnSelectLibrary ( wxListEvent &  event)

Definition at line 212 of file library_listbox.cpp.

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

Referenced by SetLibraryList().

213 {
214  SetFocus();
215  GetParent()->OnSelectComponent( event );
216 }
void OnSelectComponent(wxListEvent &event)
Function OnSelectComponent Called when clicking on a component in component list window.
virtual CVPCB_MAINFRAME * GetParent() const
void LIBRARY_LISTBOX::SetLibraryList ( const wxArrayString &  aList)

Definition at line 120 of file library_listbox.cpp.

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

Referenced by CVPCB_MAINFRAME::BuildLIBRARY_LISTBOX().

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

Definition at line 102 of file library_listbox.cpp.

References GetCount(), and Refresh().

Referenced by OnChar(), and SetLibraryList().

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

Definition at line 60 of file library_listbox.cpp.

References m_libraryList, and ITEMS_LISTBOX_BASE::UpdateWidth().

61 {
62  unsigned count = m_libraryList.Count();
63  if( count > 0 )
64  {
65  if( linecount >= count )
66  linecount = count - 1;
67  m_libraryList[linecount] = text;
68  UpdateWidth( linecount );
69  }
70 }
void UpdateWidth(int aLine=-1)
wxArrayString m_libraryList
Definition: listboxes.h:154
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(), AppendLine(), COMPONENTS_LISTBOX::AppendLine(), CVPCB_MAINFRAME::BuildCmpListBox(), FOOTPRINTS_LISTBOX::SetFootprints(), SetLibraryList(), FOOTPRINTS_LISTBOX::SetString(), SetString(), and COMPONENTS_LISTBOX::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 LIBRARY_LISTBOX::m_libraryList
private

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