KiCad PCB EDA Suite
Loading...
Searching...
No Matches
listbox_base.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
24
25#include <cvpcb_mainframe.h>
26#include <listboxes.h>
27#include <wx/dcclient.h>
28
29
31 const wxPoint& aLocation, const wxSize& aSize,
32 long aStyle ) :
33 wxListView( aParent, aId, aLocation, aSize, LISTBOX_STYLE | aStyle ),
34 m_isClosing( false ),
35 m_columnWidth( 0 )
36{
37 InsertColumn( 0, wxEmptyString );
38}
39
40
42{
43 wxClientDC dc( this );
44 int itemCount = GetItemCount();
45
46 // Less than zero: recalculate width of all items.
47 if( aLine < 0 )
48 {
49 m_columnWidth = 0;
50
51 for( int ii = 0; ii < itemCount; ii++ )
52 UpdateLineWidth( (unsigned)ii, dc );
53 }
54 // Zero or above: update from a single line.
55 else
56 {
57 if( aLine < itemCount )
58 UpdateLineWidth( (unsigned)aLine, dc );
59 }
60}
61
62
63void ITEMS_LISTBOX_BASE::UpdateLineWidth( unsigned aLine, wxClientDC& dc )
64{
65 wxCoord w;
66 int newWidth = 10; // Value of AUTOSIZE_COL_MARGIN from wxWidgets source.
67 wxString str;
68
69 dc.SetFont( GetFont() );
70
71 if( IsVirtual() )
72 str = OnGetItemText( aLine, 0 );
73 else
74 str = GetItemText( aLine, 0 );
75 str += wxS( " " );
76
77 dc.GetTextExtent( str, &w, nullptr );
78 newWidth += w;
79
80 if( newWidth > m_columnWidth )
81 {
82 m_columnWidth = newWidth;
83 SetColumnWidth( 0, m_columnWidth );
84 }
85}
86
87
89{
90 return GetFirstSelected();
91}
92
93
95{
96 for( int i = GetFirstSelected(); i >= 0; i = GetNextSelected( i ) )
97 {
98 Select( i, false );
99 }
100}
101
102
104{
105 return (CVPCB_MAINFRAME*) wxListView::GetParent();
106}
The CvPcb application main window.
void UpdateWidth(int aLine=-1)
Update the width of the column based on its contents.
void DeselectAll()
Remove all selection in lists which can have more than one item selected.
void UpdateLineWidth(unsigned aLine, wxClientDC &dc)
Calculate the width of the given line, and increase the column width if needed.
ITEMS_LISTBOX_BASE(CVPCB_MAINFRAME *aParent, wxWindowID aId, const wxPoint &aLocation=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, long aStyle=0)
virtual CVPCB_MAINFRAME * GetParent() const
#define LISTBOX_STYLE
Definition listboxes.h:32