KiCad PCB EDA Suite
symbols_listbox.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-2018 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
#include <
trace_helpers.h
>
29
30
#include <
cvpcb_mainframe.h
>
31
#include <
listboxes.h
>
32
#include <
cvpcb_id.h
>
33
#include <wx/log.h>
34
35
36
SYMBOLS_LISTBOX::SYMBOLS_LISTBOX
(
CVPCB_MAINFRAME
* parent, wxWindowID
id
) :
37
ITEMS_LISTBOX_BASE
( parent, id )
38
{
39
}
40
41
42
SYMBOLS_LISTBOX::~SYMBOLS_LISTBOX
()
43
{
44
}
45
46
47
BEGIN_EVENT_TABLE(
SYMBOLS_LISTBOX
,
ITEMS_LISTBOX_BASE
)
48
EVT_CHAR(
SYMBOLS_LISTBOX::OnChar
)
49
EVT_LIST_ITEM_SELECTED(
ID_CVPCB_COMPONENT_LIST
,
SYMBOLS_LISTBOX::OnSelectComponent
)
50
END_EVENT_TABLE()
51
52
53
void
SYMBOLS_LISTBOX
::Clear()
54
{
55
m_SymbolList.
Clear
();
56
SetItemCount( 0 );
57
}
58
59
60
int
SYMBOLS_LISTBOX::GetCount
()
61
{
62
return
m_SymbolList
.Count();
63
}
64
65
66
void
SYMBOLS_LISTBOX::SetString
(
unsigned
linecount,
const
wxString& text )
67
{
68
if
( linecount >=
m_SymbolList
.Count() )
69
linecount =
m_SymbolList
.Count() - 1;
70
71
if
(
m_SymbolList
.Count() > 0 )
72
{
73
m_SymbolList
[linecount] =
text
;
74
UpdateWidth
( linecount );
75
}
76
}
77
78
79
void
SYMBOLS_LISTBOX::AppendLine
(
const
wxString& text )
80
{
81
m_SymbolList
.Add(
text
);
82
int
lines =
m_SymbolList
.Count();
83
SetItemCount( lines );
84
UpdateWidth
( lines - 1 );
85
}
86
87
88
wxString
SYMBOLS_LISTBOX::OnGetItemText
(
long
item,
long
column )
const
89
{
90
return
m_SymbolList
.Item( item );
91
}
92
93
94
void
SYMBOLS_LISTBOX::SetSelection
(
int
index,
bool
State )
95
{
96
if
( index >=
GetCount
() )
97
index =
GetCount
() - 1;
98
99
if
( (index >= 0) && (
GetCount
() > 0) )
100
{
101
Select( index, State );
102
EnsureVisible( index );
103
104
#ifdef __WXMAC__
105
Update();
106
#endif
107
}
108
}
109
110
111
void
SYMBOLS_LISTBOX::OnChar
( wxKeyEvent& event )
112
{
113
wxLogTrace(
kicadTraceKeyEvent
, wxT(
"SYMBOLS_LISTBOX::OnChar %s"
),
dump
( event ) );
114
115
int
key =
event
.GetKeyCode();
116
117
switch
( key )
118
{
119
case
WXK_HOME:
120
case
WXK_END:
121
case
WXK_UP:
122
case
WXK_DOWN:
123
case
WXK_PAGEUP:
124
case
WXK_PAGEDOWN:
125
event
.Skip();
126
return
;
127
128
129
default
:
130
break
;
131
}
132
133
// Search for an item name starting by the key code:
134
key = toupper( key );
135
136
for
(
unsigned
ii = 0; ii <
m_SymbolList
.GetCount(); ii++ )
137
{
138
wxString
text
=
m_SymbolList
.Item( ii );
139
140
// Search for the start char of the footprint name. Skip the line number.
141
text
.Trim(
false
);
// Remove leading spaces in line
142
unsigned
jj = 0;
143
144
for
( ; jj <
text
.Len(); jj++ )
145
{
// skip line number
146
if
(
text
[jj] ==
' '
)
147
break
;
148
}
149
150
for
( ; jj <
text
.Len(); jj++ )
151
{
// skip blanks
152
if
(
text
[jj] !=
' '
)
153
break
;
154
}
155
156
int
start_char = toupper(
text
[jj] );
157
158
if
( key == start_char )
159
{
160
SetSelection
( (
int
) ii,
true
);
// Ensure visible
161
break
;
162
}
163
}
164
165
event
.Skip();
166
}
167
168
169
void
SYMBOLS_LISTBOX::OnSelectComponent
( wxListEvent& event )
170
{
171
SetFocus();
172
GetParent
()->
OnSelectComponent
( event );
173
}
SYMBOLS_LISTBOX::Clear
void Clear()
Definition:
symbols_listbox.cpp:53
SYMBOLS_LISTBOX::AppendLine
void AppendLine(const wxString &text)
Definition:
symbols_listbox.cpp:79
ID_CVPCB_COMPONENT_LIST
Definition:
cvpcb_id.h:42
SYMBOLS_LISTBOX::OnSelectComponent
void OnSelectComponent(wxListEvent &event)
Definition:
symbols_listbox.cpp:169
SYMBOLS_LISTBOX::SetSelection
void SetSelection(int index, bool State=true)
Definition:
symbols_listbox.cpp:94
SYMBOLS_LISTBOX::SetString
void SetString(unsigned linecount, const wxString &text)
Definition:
symbols_listbox.cpp:66
cvpcb_mainframe.h
SYMBOLS_LISTBOX::GetCount
int GetCount()
Definition:
symbols_listbox.cpp:60
ITEMS_LISTBOX_BASE
Base class to display symbol and footprint lists.
Definition:
listboxes.h:41
SYMBOLS_LISTBOX::OnGetItemText
wxString OnGetItemText(long item, long column) const override
This overloaded function MUST be provided for the wxLC_VIRTUAL mode because real data is not handled ...
Definition:
symbols_listbox.cpp:88
CVPCB_MAINFRAME::OnSelectComponent
void OnSelectComponent(wxListEvent &event)
Called when clicking on a component in component list window:
Definition:
cvpcb_mainframe.cpp:431
ITEMS_LISTBOX_BASE::UpdateWidth
void UpdateWidth(int aLine=-1)
Update the width of the column based on its contents.
Definition:
listbox_base.cpp:49
dump
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.
Definition:
trace_helpers.cpp:57
SYMBOLS_LISTBOX::m_SymbolList
wxArrayString m_SymbolList
Definition:
listboxes.h:222
BITMAPS::text
SYMBOLS_LISTBOX
Definition:
listboxes.h:179
trace_helpers.h
wxLogTrace helper definitions.
SYMBOLS_LISTBOX::SYMBOLS_LISTBOX
SYMBOLS_LISTBOX(CVPCB_MAINFRAME *parent, wxWindowID id)
Definition:
symbols_listbox.cpp:36
SYMBOLS_LISTBOX::~SYMBOLS_LISTBOX
~SYMBOLS_LISTBOX()
Definition:
symbols_listbox.cpp:42
cvpcb_id.h
SYMBOLS_LISTBOX::OnChar
void OnChar(wxKeyEvent &event)
Called on a key press.
Definition:
symbols_listbox.cpp:111
kicadTraceKeyEvent
const wxChar *const kicadTraceKeyEvent
Flag to enable wxKeyEvent debug tracing.
Definition:
trace_helpers.cpp:36
listboxes.h
CVPCB_MAINFRAME
The CvPcb application main window.
Definition:
cvpcb_mainframe.h:56
ITEMS_LISTBOX_BASE::GetParent
virtual CVPCB_MAINFRAME * GetParent() const
Definition:
listbox_base.cpp:101
cvpcb
symbols_listbox.cpp
Generated on Sat May 21 2022 04:06:33 for KiCad PCB EDA Suite by
1.8.15