KiCad PCB EDA Suite
class_DCodeSelectionbox.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 KiCad Developers, see CHANGELOG.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 <fctsys.h>
26 #include <pgm_base.h>
27 #include <wxstruct.h>
28 #include <dcode.h>
29 
31 
32 /*******************************************/
33 /* Helper class for displaying DCodes list */
34 /*******************************************/
35 
36 DCODE_SELECTION_BOX::DCODE_SELECTION_BOX( wxAuiToolBar* aParent, wxWindowID aId,
37  const wxPoint& aLocation, const wxSize& aSize,
38  const wxArrayString* aChoices ) :
39  wxComboBox( aParent, aId, wxEmptyString, aLocation, aSize, 0, NULL, wxCB_READONLY )
40 {
41  if( aChoices )
42  // Append aChoices here is by far faster than use aChoices inside
43  // the wxComboBox constructor
44  Append( *aChoices );
45 }
46 
47 
49 {
50 }
51 
52 
54 {
55  int ii = GetSelection();
56 
57  if( ii > 0 )
58  {
59  // in strings displayed by the combo box, the dcode number
60  // is the second word. get it:
61  wxString msg = GetString( ii ).AfterFirst( ' ' ).BeforeFirst( ' ' );
62  long id;
63 
64  if( msg.ToLong(&id) )
65  return id;
66  }
67 
68  return 0;
69 }
70 
71 
72 /* SetDCodeSelection
73  * aDCodeId = the DCode Id to select or <= 0 to select "no selection"
74  */
76 {
77  wxString msg;
78 
79  for( unsigned index = 1; index < GetCount(); ++index )
80  {
81  msg = GetString( index ).AfterFirst( ' ' ).BeforeFirst( ' ' );
82  long id;
83 
84  if( msg.ToLong(&id) && id == aDCodeId )
85  {
86  SetSelection( index );
87  return;
88  }
89  }
90 
91  SetSelection( 0 );
92 }
93 
94 
95 void DCODE_SELECTION_BOX::AppendDCodeList( const wxArrayString& aChoices )
96 {
97  Append( aChoices );
98 }
void SetDCodeSelection(int aDCodeId)
Function SetDCodeSelection.
DCODE_SELECTION_BOX(wxAuiToolBar *aParent, wxWindowID aId, const wxPoint &aLocation, const wxSize &aSize, const wxArrayString *aChoices=NULL)
Base window classes and related definitions.
int GetSelectedDCodeId()
Function GetSelectedDCodeId.
void AppendDCodeList(const wxArrayString &aChoices)
Function AppendDCodeList.
see class PGM_BASE