KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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
28
29
#include <
cvpcb_mainframe.h
>
30
#include <
listboxes.h
>
31
#include <wx/dcclient.h>
32
33
34
ITEMS_LISTBOX_BASE::ITEMS_LISTBOX_BASE
(
CVPCB_MAINFRAME
* aParent, wxWindowID aId,
35
const
wxPoint& aLocation,
const
wxSize& aSize,
36
long
aStyle ) :
37
wxListView( aParent, aId, aLocation, aSize,
LISTBOX_STYLE
| aStyle ),
38
m_isClosing
( false ),
39
m_columnWidth
( 0 )
40
{
41
InsertColumn( 0, wxEmptyString );
42
}
43
44
45
void
ITEMS_LISTBOX_BASE::UpdateWidth
(
int
aLine )
46
{
47
wxClientDC dc(
this
);
48
int
itemCount = GetItemCount();
49
50
// Less than zero: recalculate width of all items.
51
if
( aLine < 0 )
52
{
53
m_columnWidth
= 0;
54
55
for
(
int
ii = 0; ii < itemCount; ii++ )
56
UpdateLineWidth
( (
unsigned
)ii, dc );
57
}
58
// Zero or above: update from a single line.
59
else
60
{
61
if
( aLine < itemCount )
62
UpdateLineWidth
( (
unsigned
)aLine, dc );
63
}
64
}
65
66
67
void
ITEMS_LISTBOX_BASE::UpdateLineWidth
(
unsigned
aLine, wxClientDC& dc )
68
{
69
wxCoord w;
70
int
newWidth = 10;
// Value of AUTOSIZE_COL_MARGIN from wxWidgets source.
71
wxString str;
72
73
dc.SetFont( GetFont() );
74
75
if
( IsVirtual() )
76
str = OnGetItemText( aLine, 0 );
77
else
78
str = GetItemText( aLine, 0 );
79
str += wxS(
" "
);
80
81
dc.GetTextExtent( str, &w,
nullptr
);
82
newWidth += w;
83
84
if
( newWidth >
m_columnWidth
)
85
{
86
m_columnWidth
= newWidth;
87
SetColumnWidth( 0,
m_columnWidth
);
88
}
89
}
90
91
92
int
ITEMS_LISTBOX_BASE::GetSelection
()
93
{
94
return
GetFirstSelected();
95
}
96
97
98
void
ITEMS_LISTBOX_BASE::DeselectAll
()
99
{
100
for
(
int
i = GetFirstSelected(); i >= 0; i = GetNextSelected( i ) )
101
{
102
Select( i,
false
);
103
}
104
}
105
106
107
CVPCB_MAINFRAME
*
ITEMS_LISTBOX_BASE::GetParent
()
const
108
{
109
return
(
CVPCB_MAINFRAME
*) wxListView::GetParent();
110
}
CVPCB_MAINFRAME
The CvPcb application main window.
Definition
cvpcb_mainframe.h:56
ITEMS_LISTBOX_BASE::UpdateWidth
void UpdateWidth(int aLine=-1)
Update the width of the column based on its contents.
Definition
listbox_base.cpp:45
ITEMS_LISTBOX_BASE::GetSelection
int GetSelection()
Definition
listbox_base.cpp:92
ITEMS_LISTBOX_BASE::m_columnWidth
int m_columnWidth
Definition
listboxes.h:87
ITEMS_LISTBOX_BASE::DeselectAll
void DeselectAll()
Remove all selection in lists which can have more than one item selected.
Definition
listbox_base.cpp:98
ITEMS_LISTBOX_BASE::UpdateLineWidth
void UpdateLineWidth(unsigned aLine, wxClientDC &dc)
Calculate the width of the given line, and increase the column width if needed.
Definition
listbox_base.cpp:67
ITEMS_LISTBOX_BASE::ITEMS_LISTBOX_BASE
ITEMS_LISTBOX_BASE(CVPCB_MAINFRAME *aParent, wxWindowID aId, const wxPoint &aLocation=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, long aStyle=0)
Definition
listbox_base.cpp:34
ITEMS_LISTBOX_BASE::m_isClosing
bool m_isClosing
Definition
listboxes.h:84
ITEMS_LISTBOX_BASE::GetParent
virtual CVPCB_MAINFRAME * GetParent() const
Definition
listbox_base.cpp:107
cvpcb_mainframe.h
listboxes.h
LISTBOX_STYLE
#define LISTBOX_STYLE
Definition
listboxes.h:36
src
cvpcb
listbox_base.cpp
Generated on Sun Sep 21 2025 01:05:22 for KiCad PCB EDA Suite by
1.13.2