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-2012 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 
32 
33 /******************************************************************************
34 * Basic class (from wxListView) to display component and footprint lists
35 * Not directly used: the 2 list boxes actually used are derived from it
36 ******************************************************************************/
37 
39  const wxPoint& aLocation, const wxSize& aSize,
40  long aStyle) :
41  wxListView( aParent, aId, aLocation, aSize, LISTBOX_STYLE | aStyle ), columnWidth(0)
42 {
43  InsertColumn( 0, wxEmptyString );
44 }
45 
46 
48 {
49 }
50 
51 
53 {
54  // Less than zero: recalculate width of all items.
55  if( aLine < 0 )
56  {
57  columnWidth = 0;
58  for( int ii = 0; ii < GetItemCount(); ii++ )
59  {
60  UpdateLineWidth( (unsigned)ii );
61  }
62  }
63 
64  // Zero or above: update from a single line.
65  else
66  {
67  if( aLine < GetItemCount() )
68  UpdateLineWidth( (unsigned)aLine );
69  }
70 }
71 
72 
73 /*
74  * Calculate the width of the given line, and increase the column width
75  * if needed. This is effectively the wxListCtrl code for autosizing.
76  * NB. it relies on the caller checking the given line number is valid.
77  */
79 {
80  wxClientDC dc( this );
81  wxCoord w;
82  int newWidth = 10; // Value of AUTOSIZE_COL_MARGIN from wxWidgets source.
83 
84  dc.SetFont( GetFont() );
85  dc.GetTextExtent( GetItemText( aLine, 0 ) + " ", &w, NULL );
86  newWidth += w;
87 
88  if( newWidth > columnWidth )
89  {
90  columnWidth = newWidth;
91  SetColumnWidth( 0, columnWidth );
92  }
93 }
94 
95 
96 /*
97  * Return an index for the selected item
98  */
100 {
101  return GetFirstSelected();
102 }
103 
104 /* Removes all selection in list
105 */
107 {
108  for( int i = 0; i < GetItemCount(); i++ )
109  Select( i, false );
110 }
111 
112 
114 {
115  return (CVPCB_MAINFRAME*) wxListView::GetParent();
116 }
ITEMS_LISTBOX_BASE(CVPCB_MAINFRAME *aParent, wxWindowID aId, const wxPoint &aLocation, const wxSize &aSize, long aStyle=0)
void DeselectAll()
Removes all selection in lists which can have more than one item selected.
void UpdateWidth(int aLine=-1)
void UpdateLineWidth(unsigned aLine)
size_t i
Definition: json11.cpp:597
#define LISTBOX_STYLE
Definition: listboxes.h:39
The CvPcb application main window.
virtual CVPCB_MAINFRAME * GetParent() const