KiCad PCB EDA Suite
widget_save_restore.h
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) 2019 KiCad Developers, see CHANGELOG.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 
24 #ifndef WIDGETS_WIDGET_SAVE_RESTORE__H
25 #define WIDGETS_WIDGET_SAVE_RESTORE__H
26 
27 #include <vector>
28 
29 class wxCheckBox;
30 class wxChoice;
31 class wxNotebook;
32 class wxRadioBox;
33 class wxString;
34 class wxTextCtrl;
35 
36 class UNIT_BINDER;
37 
39 {
40 public:
41  WIDGET_SAVE_RESTORE( bool& aValidFlag ) :
42  m_valid( aValidFlag )
43  {
44  }
45 
49  void Add( wxRadioBox& ctrl, long& dest );
50 
54  void Add( wxCheckBox& ctrl, bool& dest );
55 
60  void Add( wxTextCtrl& ctrl, wxString& dest );
61 
66  void Add( wxTextCtrl& ctrl, long& dest );
67 
72  void Add( wxTextCtrl& ctrl, double& dest );
73 
77  void Add( UNIT_BINDER& ctrl, long& dest );
78 
83  void Add( wxChoice& ctrl, long& dest );
84 
88  void Add( wxNotebook& ctrl, long& dest );
89 
95 
101 
102 private:
108  {
109  TEXT,
110  TEXT_INTEGER,
111  TEXT_DOUBLE,
112  UNIT_BINDER,
113  CHECKBOX,
114  RADIOBOX,
115  CHOICE,
116  TAB
117  };
118 
119  union CONTROL {
120  CONTROL( wxCheckBox* aCtrl ) :
121  m_checkbox( aCtrl )
122  {
123  }
124 
125  CONTROL( wxChoice* aCtrl ) :
126  m_choice( aCtrl )
127  {
128  }
129 
130  CONTROL( wxNotebook* aCtrl ) :
131  m_notebook( aCtrl )
132  {
133  }
134 
135  CONTROL( wxRadioBox* aCtrl ) :
136  m_radiobox( aCtrl )
137  {
138  }
139 
140  CONTROL( wxTextCtrl* aCtrl ) :
141  m_textctrl( aCtrl )
142  {
143  }
144 
145  CONTROL( UNIT_BINDER* aCtrl ) :
146  m_unit_binder( aCtrl )
147  {
148  }
149 
150  wxCheckBox* m_checkbox;
151  wxChoice* m_choice;
152  wxNotebook* m_notebook;
153  wxRadioBox* m_radiobox;
154  wxTextCtrl* m_textctrl;
156  };
157 
158  union DATA {
159  DATA( long* aDest ) :
160  m_long( aDest )
161  {
162  }
163 
164  DATA( bool* aDest ) :
165  m_bool( aDest )
166  {
167  }
168 
169  DATA( wxString* aDest ) :
170  m_str( aDest )
171  {
172  }
173 
174  DATA( double* aDest ) :
175  m_double( aDest )
176  {
177  }
178 
179  long* m_long;
180  bool* m_bool;
181  wxString* m_str;
182  double* m_double;
183  };
184 
189  {
190  template <typename CTRL_T, typename DEST_T>
191  WIDGET_CTRL_T( WIDGET_CTRL_TYPE_T aType, CTRL_T& aCtrl, DEST_T& aDest ) :
192  m_type( aType ),
193  m_control( &aCtrl ),
194  m_dest( &aDest )
195  {
196  }
197 
201  };
202 
203  std::vector<WIDGET_CTRL_T> m_ctrls;
204  bool& m_valid;
205 };
206 
207 #endif // WIDGETS_WIDGET_SAVE_RESTORE__H
Struct that represents a single bound control.
std::vector< WIDGET_CTRL_T > m_ctrls
WIDGET_SAVE_RESTORE(bool &aValidFlag)
void RestoreConfigToControls()
Restore the values from the internally-stored references to the underlying data to each bound control...
WIDGET_CTRL_TYPE_T
Recognised parameters types (encodes an implicit widget type, data type and appropriate conversion).
void ReadConfigFromControls()
Read values of all bound controls into the internally-stored references to the underlying data.
void Add(wxRadioBox &ctrl, long &dest)
Bind a radiobox to a choice.
WIDGET_CTRL_T(WIDGET_CTRL_TYPE_T aType, CTRL_T &aCtrl, DEST_T &aDest)