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 ),
42  columnWidth( 0 )
43 {
44  InsertColumn( 0, wxEmptyString );
45 }
46 
47 
49 {
50 }
51 
52 
54 {
55  // Less than zero: recalculate width of all items.
56  if( aLine < 0 )
57  {
58  columnWidth = 0;
59  for( int ii = 0; ii < GetItemCount(); ii++ )
60  {
61  UpdateLineWidth( (unsigned)ii );
62  }
63  }
64 
65  // Zero or above: update from a single line.
66  else
67  {
68  if( aLine < GetItemCount() )
69  UpdateLineWidth( (unsigned)aLine );
70  }
71 }
72 
73 
74 /*
75  * Calculate the width of the given line, and increase the column width
76  * if needed. This is effectively the wxListCtrl code for autosizing.
77  * NB. it relies on the caller checking the given line number is valid.
78  */
80 {
81  wxClientDC dc( this );
82  wxCoord w;
83  int newWidth = 10; // Value of AUTOSIZE_COL_MARGIN from wxWidgets source.
84 
85  dc.SetFont( GetFont() );
86  dc.GetTextExtent( GetItemText( aLine, 0 ) + " ", &w, NULL );
87  newWidth += w;
88 
89  if( newWidth > columnWidth )
90  {
91  columnWidth = newWidth;
92  SetColumnWidth( 0, columnWidth );
93  }
94 }
95 
96 
97 /*
98  * Return an index for the selected item
99  */
101 {
102  return GetFirstSelected();
103 }
104 
105 /* Removes all selection in list
106 */
108 {
109  for( int i = 0; i < GetItemCount(); i++ )
110  Select( i, false );
111 }
112 
113 
115 {
116  return (CVPCB_MAINFRAME*) wxListView::GetParent();
117 }
void DeselectAll()
Removes all selection in lists which can have more than one item selected.
#define NULL
void UpdateWidth(int aLine=-1)
void UpdateLineWidth(unsigned aLine)
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