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