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 ) : m_valid( aValidFlag )
42  {
43  }
44 
48  void Add( wxRadioBox& ctrl, long& dest );
49 
53  void Add( wxCheckBox& ctrl, bool& dest );
54 
59  void Add( wxTextCtrl& ctrl, wxString& dest );
60 
65  void Add( wxTextCtrl& ctrl, long& dest );
66 
71  void Add( wxTextCtrl& ctrl, double& dest );
72 
76  void Add( UNIT_BINDER& ctrl, long& dest );
77 
82  void Add( wxChoice& ctrl, long& dest );
83 
87  void Add( wxNotebook& ctrl, long& dest );
88 
94 
100 
101 private:
107  {
108  TEXT,
109  TEXT_INTEGER,
110  TEXT_DOUBLE,
111  UNIT_BINDER,
112  CHECKBOX,
113  RADIOBOX,
114  CHOICE,
115  TAB
116  };
117 
118  union CONTROL {
119  CONTROL( wxCheckBox* aCtrl ) : m_checkbox( aCtrl )
120  {
121  }
122 
123  CONTROL( wxChoice* aCtrl ) : m_choice( aCtrl )
124  {
125  }
126 
127  CONTROL( wxNotebook* aCtrl ) : m_notebook( aCtrl )
128  {
129  }
130 
131  CONTROL( wxRadioBox* aCtrl ) : m_radiobox( aCtrl )
132  {
133  }
134 
135  CONTROL( wxTextCtrl* aCtrl ) : m_textctrl( aCtrl )
136  {
137  }
138 
139  CONTROL( UNIT_BINDER* aCtrl ) : m_unit_binder( aCtrl )
140  {
141  }
142 
143  wxCheckBox* m_checkbox;
144  wxChoice* m_choice;
145  wxNotebook* m_notebook;
146  wxRadioBox* m_radiobox;
147  wxTextCtrl* m_textctrl;
149  };
150 
151  union DATA {
152  DATA( long* aDest ) : m_long( aDest )
153  {
154  }
155 
156  DATA( bool* aDest ) : m_bool( aDest )
157  {
158  }
159 
160  DATA( wxString* aDest ) : m_str( aDest )
161  {
162  }
163 
164  DATA( double* aDest ) : m_double( aDest )
165  {
166  }
167 
168  long* m_long;
169  bool* m_bool;
170  wxString* m_str;
171  double* m_double;
172  };
173 
178  {
179  template <typename CTRL_T, typename DEST_T>
180  WIDGET_CTRL_T( WIDGET_CTRL_TYPE_T aType, CTRL_T& aCtrl, DEST_T& aDest )
181  : m_type( aType ), m_control( &aCtrl ), m_dest( &aDest )
182  {
183  }
184 
188  };
189 
190  std::vector<WIDGET_CTRL_T> m_ctrls;
191  bool& m_valid;
192 };
193 
194 #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)