KiCad PCB EDA Suite
ITEMS_LISTBOX_BASE Class Reference

Base class to display symbol and footprint lists. More...

#include <listboxes.h>

Inheritance diagram for ITEMS_LISTBOX_BASE:
FOOTPRINTS_LISTBOX LIBRARY_LISTBOX SYMBOLS_LISTBOX

Public Member Functions

 ITEMS_LISTBOX_BASE (CVPCB_MAINFRAME *aParent, wxWindowID aId, const wxPoint &aLocation=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, long aStyle=0)
 
 ~ITEMS_LISTBOX_BASE ()
 
int GetSelection ()
 
void DeselectAll ()
 Remove all selection in lists which can have more than one item selected. More...
 
virtual CVPCB_MAINFRAMEGetParent () const
 
void UpdateWidth (int aLine=-1)
 Update the width of the column based on its contents. More...
 

Private Member Functions

void UpdateLineWidth (unsigned aLine)
 Calculate the width of the given line, and increase the column width if needed. More...
 

Private Attributes

int columnWidth
 

Detailed Description

Base class to display symbol and footprint lists.

Definition at line 41 of file listboxes.h.

Constructor & Destructor Documentation

◆ ITEMS_LISTBOX_BASE()

ITEMS_LISTBOX_BASE::ITEMS_LISTBOX_BASE ( CVPCB_MAINFRAME aParent,
wxWindowID  aId,
const wxPoint &  aLocation = wxDefaultPosition,
const wxSize &  aSize = wxDefaultSize,
long  aStyle = 0 
)

Definition at line 34 of file listbox_base.cpp.

36  :
37  wxListView( aParent, aId, aLocation, aSize, LISTBOX_STYLE | aStyle ),
38  columnWidth( 0 )
39 {
40  InsertColumn( 0, wxEmptyString );
41 }
#define LISTBOX_STYLE
Definition: listboxes.h:35

◆ ~ITEMS_LISTBOX_BASE()

ITEMS_LISTBOX_BASE::~ITEMS_LISTBOX_BASE ( )

Definition at line 44 of file listbox_base.cpp.

45 {
46 }

Member Function Documentation

◆ DeselectAll()

void ITEMS_LISTBOX_BASE::DeselectAll ( )

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

Definition at line 94 of file listbox_base.cpp.

95 {
96  for( int i = 0; i < GetItemCount(); i++ )
97  Select( i, false );
98 }

Referenced by FOOTPRINTS_LISTBOX::SetFootprints(), and CVPCB_MAINFRAME::SetSelectedComponent().

◆ GetParent()

CVPCB_MAINFRAME * ITEMS_LISTBOX_BASE::GetParent ( void  ) const
virtual

Definition at line 101 of file listbox_base.cpp.

102 {
103  return (CVPCB_MAINFRAME*) wxListView::GetParent();
104 }
The CvPcb application main window.

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

◆ GetSelection()

int ITEMS_LISTBOX_BASE::GetSelection ( )
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 88 of file listbox_base.cpp.

89 {
90  return GetFirstSelected();
91 }

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

◆ UpdateLineWidth()

void ITEMS_LISTBOX_BASE::UpdateLineWidth ( unsigned  aLine)
private

Calculate the width of the given line, and increase the column width if needed.

This is effectively the wxListCtrl code for autosizing. NB. it relies on the caller checking the given line number is valid.

Definition at line 70 of file listbox_base.cpp.

71 {
72  wxClientDC dc( this );
73  wxCoord w;
74  int newWidth = 10; // Value of AUTOSIZE_COL_MARGIN from wxWidgets source.
75 
76  dc.SetFont( GetFont() );
77  dc.GetTextExtent( GetItemText( aLine, 0 ) + " ", &w, nullptr );
78  newWidth += w;
79 
80  if( newWidth > columnWidth )
81  {
82  columnWidth = newWidth;
83  SetColumnWidth( 0, columnWidth );
84  }
85 }

References columnWidth.

Referenced by UpdateWidth().

◆ UpdateWidth()

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

Update the width of the column based on its contents.

Parameters
aLineis the line to calculate the width from. If positive, the width will only be increased if needed. If negative, we start from scratch and all lines are considered, i.e., the column may be shrunk.

Definition at line 49 of file listbox_base.cpp.

50 {
51  // Less than zero: recalculate width of all items.
52  if( aLine < 0 )
53  {
54  columnWidth = 0;
55  for( int ii = 0; ii < GetItemCount(); ii++ )
56  {
57  UpdateLineWidth( (unsigned)ii );
58  }
59  }
60 
61  // Zero or above: update from a single line.
62  else
63  {
64  if( aLine < GetItemCount() )
65  UpdateLineWidth( (unsigned)aLine );
66  }
67 }
void UpdateLineWidth(unsigned aLine)
Calculate the width of the given line, and increase the column width if needed.

References columnWidth, and UpdateLineWidth().

Referenced by FOOTPRINTS_LISTBOX::AppendLine(), LIBRARY_LISTBOX::AppendLine(), SYMBOLS_LISTBOX::AppendLine(), CVPCB_MAINFRAME::BuildSymbolsListBox(), FOOTPRINTS_LISTBOX::SetFootprints(), LIBRARY_LISTBOX::SetLibraryList(), FOOTPRINTS_LISTBOX::SetString(), LIBRARY_LISTBOX::SetString(), and SYMBOLS_LISTBOX::SetString().

Member Data Documentation

◆ columnWidth

int ITEMS_LISTBOX_BASE::columnWidth
private

Definition at line 80 of file listboxes.h.

Referenced by UpdateLineWidth(), and UpdateWidth().


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