KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dcode_selection_box.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) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.TXT for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include <wx/aui/aui.h>
26#include <dcode.h>
27
28#include "dcode_selection_box.h"
29
30
31DCODE_SELECTION_BOX::DCODE_SELECTION_BOX( wxAuiToolBar* aParent, wxWindowID aId,
32 const wxPoint& aLocation, const wxSize& aSize,
33 const wxArrayString* aChoices ) :
34 wxComboBox( aParent, aId, wxEmptyString, aLocation, aSize, 0, nullptr, wxCB_READONLY )
35{
36 if( aChoices )
37 // Append aChoices here is by far faster than use aChoices inside
38 // the wxComboBox constructor
39 Append( *aChoices );
40}
41
42
44{
45}
46
47
49{
50 int ii = GetSelection();
51
52 if( ii > 0 )
53 {
54 // in strings displayed by the combo box, the dcode number
55 // is the second word. get it:
56 wxString msg = GetString( ii ).AfterFirst( ' ' ).BeforeFirst( ' ' );
57 long id;
58
59 if( msg.ToLong( &id ) )
60 return id;
61 }
62
63 return 0;
64}
65
66
68{
69 wxString msg;
70
71 for( unsigned index = 1; index < GetCount(); ++index )
72 {
73 msg = GetString( index ).AfterFirst( ' ' ).BeforeFirst( ' ' );
74 long id;
75
76 if( msg.ToLong(&id) && id == aDCodeId )
77 {
78 SetSelection( index );
79 return;
80 }
81 }
82
83 SetSelection( 0 );
84}
85
86
87void DCODE_SELECTION_BOX::AppendDCodeList( const wxArrayString& aChoices )
88{
89 Append( aChoices );
90}
void SetDCodeSelection(int aDCodeId)
void AppendDCodeList(const wxArrayString &aChoices)
DCODE_SELECTION_BOX(wxAuiToolBar *aParent, wxWindowID aId, const wxPoint &aLocation, const wxSize &aSize, const wxArrayString *aChoices=nullptr)