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