KiCad PCB EDA Suite
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  // 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 }
68 
69 
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 }
86 
87 
89 {
90  return GetFirstSelected();
91 }
92 
93 
95 {
96  for( int i = 0; i < GetItemCount(); i++ )
97  Select( i, false );
98 }
99 
100 
102 {
103  return (CVPCB_MAINFRAME*) wxListView::GetParent();
104 }
void DeselectAll()
Remove all selection in lists which can have more than one item selected.
void UpdateWidth(int aLine=-1)
Update the width of the column based on its contents.
void UpdateLineWidth(unsigned aLine)
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)
#define LISTBOX_STYLE
Definition: listboxes.h:35
The CvPcb application main window.
virtual CVPCB_MAINFRAME * GetParent() const