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 (C) 1992-2021 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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
29#include <cvpcb_mainframe.h>
30#include <listboxes.h>
31#include <wx/dcclient.h>
32
33
35 const wxPoint& aLocation, const wxSize& aSize,
36 long aStyle ) :
37 wxListView( aParent, aId, aLocation, aSize, LISTBOX_STYLE | aStyle ),
38 columnWidth( 0 )
39{
40 InsertColumn( 0, wxEmptyString );
41}
42
43
45{
46}
47
48
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}
71
72
73void ITEMS_LISTBOX_BASE::UpdateLineWidth( unsigned aLine, wxClientDC& dc )
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}
96
97
99{
100 return GetFirstSelected();
101}
102
103
105{
106 for( int i = GetFirstSelected(); i >= 0; i = GetNextSelected(i))
107 {
108 Select( i, false );
109 }
110}
111
112
114{
115 return (CVPCB_MAINFRAME*) wxListView::GetParent();
116}
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:36