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