KiCad PCB EDA Suite
LIBRARY_LISTBOX Class Reference

#include <listview_classes.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 listview_classes.h.

Constructor & Destructor Documentation

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

Definition at line 43 of file class_library_listbox.cpp.

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

Definition at line 50 of file class_library_listbox.cpp.

51 {
52 }

Member Function Documentation

void LIBRARY_LISTBOX::AppendLine ( const wxString &  text)

Definition at line 88 of file class_library_listbox.cpp.

References m_libraryList, and ITEMS_LISTBOX_BASE::UpdateWidth().

89 {
90  m_libraryList.Add( text );
91  int lines = m_libraryList.Count();
92  SetItemCount( lines );
93  UpdateWidth( lines - 1 );
94 }
void UpdateWidth(int aLine=-1)
Definition: listboxes.cpp:58
wxArrayString m_libraryList
void ITEMS_LISTBOX_BASE::DeselectAll ( )
inherited

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

Definition at line 112 of file listboxes.cpp.

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

113 {
114  for( int i = 0; i < GetItemCount(); i++ )
115  Select( i, false );
116 }
int LIBRARY_LISTBOX::GetCount ( )

Definition at line 55 of file class_library_listbox.cpp.

References m_libraryList.

Referenced by SetLibraryList(), and SetSelection().

56 {
57  return m_libraryList.Count();
58 }
wxArrayString m_libraryList
CVPCB_MAINFRAME * ITEMS_LISTBOX_BASE::GetParent ( ) const
virtualinherited

Definition at line 119 of file listboxes.cpp.

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

120 {
121  return (CVPCB_MAINFRAME*) wxListView::GetParent();
122 }
The CvPcb application main window.
wxString LIBRARY_LISTBOX::GetSelectedLibrary ( )

Definition at line 74 of file class_library_listbox.cpp.

References m_libraryList.

Referenced by CVPCB_MAINFRAME::OnSelectComponent().

75 {
76  wxString libraryName;
77  int ii = GetFirstSelected();
78 
79  if( ii >= 0 )
80  {
81  libraryName = m_libraryList[ii];
82  }
83 
84  return libraryName;
85 }
wxArrayString m_libraryList
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 105 of file listboxes.cpp.

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

106 {
107  return GetFirstSelected();
108 }
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 146 of file class_library_listbox.cpp.

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

Definition at line 97 of file class_library_listbox.cpp.

References m_libraryList.

98 {
99  return m_libraryList.Item( item );
100 }
wxArrayString m_libraryList
void LIBRARY_LISTBOX::OnLeftClick ( wxListEvent &  event)
void LIBRARY_LISTBOX::OnSelectLibrary ( wxListEvent &  event)

Definition at line 213 of file class_library_listbox.cpp.

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

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

Definition at line 121 of file class_library_listbox.cpp.

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

Referenced by CVPCB_MAINFRAME::BuildLIBRARY_LISTBOX().

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

Definition at line 103 of file class_library_listbox.cpp.

References GetCount(), and Refresh().

Referenced by SetLibraryList().

104 {
105  if( index >= GetCount() )
106  index = GetCount() - 1;
107 
108  if( (index >= 0) && (GetCount() > 0) )
109  {
110 #ifndef __WXMAC__
111  Select( index, State );
112 #endif
113  EnsureVisible( index );
114 #ifdef __WXMAC__
115  Refresh();
116 #endif
117  }
118 }
void Refresh()
void LIBRARY_LISTBOX::SetString ( unsigned  linecount,
const wxString &  text 
)

Definition at line 61 of file class_library_listbox.cpp.

References m_libraryList, and ITEMS_LISTBOX_BASE::UpdateWidth().

62 {
63  unsigned count = m_libraryList.Count();
64  if( count > 0 )
65  {
66  if( linecount >= count )
67  linecount = count - 1;
68  m_libraryList[linecount] = text;
69  UpdateWidth( linecount );
70  }
71 }
void UpdateWidth(int aLine=-1)
Definition: listboxes.cpp:58
wxArrayString m_libraryList
void ITEMS_LISTBOX_BASE::UpdateWidth ( int  aLine = -1)
inherited

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

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

Member Data Documentation

wxArrayString LIBRARY_LISTBOX::m_libraryList
private

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