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, wxClientDC &dc)
 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 42 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:36

◆ ~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 104 of file listbox_base.cpp.

105{
106 for( int i = GetFirstSelected(); i >= 0; i = GetNextSelected(i))
107 {
108 Select( i, false );
109 }
110}

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

◆ GetParent()

CVPCB_MAINFRAME * ITEMS_LISTBOX_BASE::GetParent ( void  ) const
virtual

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(), 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 98 of file listbox_base.cpp.

99{
100 return GetFirstSelected();
101}

Referenced by CVPCB_MAINFRAME::GetSelectedComponent(), CVPCB_MAINFRAME::OnSelectComponent(), CVPCB_MAINFRAME::onTextFilterChangedTimer(), CVPCB_MAINFRAME::refreshAfterSymbolSearch(), CVPCB_MAINFRAME::SendComponentSelectionToSch(), and FOOTPRINTS_LISTBOX::SetFootprints().

◆ UpdateLineWidth()

void ITEMS_LISTBOX_BASE::UpdateLineWidth ( unsigned  aLine,
wxClientDC &  dc 
)
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 73 of file listbox_base.cpp.

74{
75 wxCoord w;
76 int newWidth = 10; // Value of AUTOSIZE_COL_MARGIN from wxWidgets source.
77 wxString str;
78
79 dc.SetFont( GetFont() );
80
81 if( IsVirtual() )
82 str = OnGetItemText( aLine, 0 );
83 else
84 str = GetItemText( aLine, 0 );
85 str += wxS( " " );
86
87 dc.GetTextExtent( str, &w, nullptr );
88 newWidth += w;
89
90 if( newWidth > columnWidth )
91 {
92 columnWidth = newWidth;
93 SetColumnWidth( 0, columnWidth );
94 }
95}

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

References columnWidth, and UpdateLineWidth().

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

Member Data Documentation

◆ columnWidth

int ITEMS_LISTBOX_BASE::columnWidth
private

Definition at line 81 of file listboxes.h.

Referenced by UpdateLineWidth(), and UpdateWidth().


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