Break widget save/restore out to reusable class

The CONFIG_SAVE_RESTORE_WINDOW class does not need to be tied
to the array dialog, put it in common/widgets.

Also do a refactor and tidy-up of the the class, use a union for (slightly)
better type-safety and syntax (a variant would be better but that's C++17).

Also enable integral field save/restore from text boxes.
This commit is contained in:
John Beard 2019-01-28 21:37:36 +00:00 committed by Seth Hillbrand
parent 24ac9b7055
commit f85f10930a
5 changed files with 434 additions and 213 deletions

View File

@ -225,6 +225,7 @@ set( COMMON_WIDGET_SRCS
widgets/two_column_tree_list.cpp widgets/two_column_tree_list.cpp
widgets/ui_common.cpp widgets/ui_common.cpp
widgets/unit_binder.cpp widgets/unit_binder.cpp
widgets/widget_save_restore.cpp
widgets/widget_hotkey_list.cpp widgets/widget_hotkey_list.cpp
widgets/wx_grid.cpp widgets/wx_grid.cpp
) )

View File

@ -0,0 +1,169 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2019 KiCad Developers, see CHANGELOG.TXT for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <widgets/widget_save_restore.h>
#include <wx/checkbox.h>
#include <wx/choice.h>
#include <wx/notebook.h>
#include <wx/radiobox.h>
#include <wx/textctrl.h>
#include <widgets/unit_binder.h>
void WIDGET_SAVE_RESTORE::Add( wxRadioBox& ctrl, long& dest )
{
m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::RADIOBOX, ctrl, dest );
}
void WIDGET_SAVE_RESTORE::Add( wxCheckBox& ctrl, bool& dest )
{
m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::CHECKBOX, ctrl, dest );
}
void WIDGET_SAVE_RESTORE::Add( wxTextCtrl& ctrl, wxString& dest )
{
m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::TEXT, ctrl, dest );
}
void WIDGET_SAVE_RESTORE::Add( wxTextCtrl& ctrl, long& dest )
{
m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::TEXT_INTEGER, ctrl, dest );
}
void WIDGET_SAVE_RESTORE::Add( wxTextCtrl& ctrl, double& dest )
{
m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::TEXT_DOUBLE, ctrl, dest );
}
void WIDGET_SAVE_RESTORE::Add( UNIT_BINDER& ctrl, long& dest )
{
m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::UNIT_BINDER, ctrl, dest );
}
void WIDGET_SAVE_RESTORE::Add( wxChoice& ctrl, long& dest )
{
m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::CHOICE, ctrl, dest );
}
void WIDGET_SAVE_RESTORE::Add( wxNotebook& ctrl, long& dest )
{
m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::TAB, ctrl, dest );
}
void WIDGET_SAVE_RESTORE::ReadConfigFromControls()
{
for( auto& ctrl : m_ctrls )
{
switch( ctrl.m_type )
{
case WIDGET_CTRL_TYPE_T::CHECKBOX:
*ctrl.m_dest.m_bool = ctrl.m_control.m_checkbox->GetValue();
break;
case WIDGET_CTRL_TYPE_T::TEXT:
*ctrl.m_dest.m_str = ctrl.m_control.m_textctrl->GetValue();
break;
case WIDGET_CTRL_TYPE_T::TEXT_INTEGER:
ctrl.m_control.m_textctrl->GetValue().ToLong( ctrl.m_dest.m_long );
break;
case WIDGET_CTRL_TYPE_T::TEXT_DOUBLE:
ctrl.m_control.m_textctrl->GetValue().ToDouble( ctrl.m_dest.m_double );
break;
case WIDGET_CTRL_TYPE_T::UNIT_BINDER:
*ctrl.m_dest.m_long = ctrl.m_control.m_unit_binder->GetValue();
break;
case WIDGET_CTRL_TYPE_T::CHOICE:
*ctrl.m_dest.m_long = ctrl.m_control.m_choice->GetSelection();
break;
case WIDGET_CTRL_TYPE_T::RADIOBOX:
*ctrl.m_dest.m_long = ctrl.m_control.m_radiobox->GetSelection();
break;
case WIDGET_CTRL_TYPE_T::TAB:
*ctrl.m_dest.m_long = ctrl.m_control.m_notebook->GetSelection();
break;
}
}
m_valid = true;
}
void WIDGET_SAVE_RESTORE::RestoreConfigToControls()
{
if( !m_valid )
return;
for( auto& ctrl : m_ctrls )
{
switch( ctrl.m_type )
{
case WIDGET_CTRL_TYPE_T::CHECKBOX:
ctrl.m_control.m_checkbox->SetValue( *ctrl.m_dest.m_bool );
break;
case WIDGET_CTRL_TYPE_T::TEXT:
ctrl.m_control.m_textctrl->SetValue( *ctrl.m_dest.m_str );
break;
case WIDGET_CTRL_TYPE_T::TEXT_INTEGER:
ctrl.m_control.m_textctrl->SetValue( wxString::Format( "%ld", *ctrl.m_dest.m_long ) );
break;
case WIDGET_CTRL_TYPE_T::TEXT_DOUBLE:
ctrl.m_control.m_textctrl->SetValue( wxString::Format( "%f", *ctrl.m_dest.m_double ) );
break;
case WIDGET_CTRL_TYPE_T::UNIT_BINDER:
ctrl.m_control.m_unit_binder->SetValue( *ctrl.m_dest.m_long );
break;
case WIDGET_CTRL_TYPE_T::CHOICE:
ctrl.m_control.m_choice->SetSelection( *ctrl.m_dest.m_long );
break;
case WIDGET_CTRL_TYPE_T::RADIOBOX:
ctrl.m_control.m_radiobox->SetSelection( *ctrl.m_dest.m_long );
break;
case WIDGET_CTRL_TYPE_T::TAB:
ctrl.m_control.m_notebook->SetSelection( *ctrl.m_dest.m_long );
break;
}
}
}

View File

@ -0,0 +1,194 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2019 KiCad Developers, see CHANGELOG.TXT for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef WIDGETS_WIDGET_SAVE_RESTORE__H
#define WIDGETS_WIDGET_SAVE_RESTORE__H
#include <vector>
class wxCheckBox;
class wxChoice;
class wxNotebook;
class wxRadioBox;
class wxString;
class wxTextCtrl;
class UNIT_BINDER;
class WIDGET_SAVE_RESTORE
{
public:
WIDGET_SAVE_RESTORE( bool& aValidFlag ) : m_valid( aValidFlag )
{
}
/**
* Bind a radiobox to a choice.
*/
void Add( wxRadioBox& ctrl, long& dest );
/**
* Bind a check box to a binary choice
*/
void Add( wxCheckBox& ctrl, bool& dest );
/**
* Bind a text ctrl to a string: the control value is stored directly
* into the string
*/
void Add( wxTextCtrl& ctrl, wxString& dest );
/**
* Bind a text ctrl to a integer: the control value is converted to and
* from integer on save/restore.
*/
void Add( wxTextCtrl& ctrl, long& dest );
/**
* Bind a text ctrl to a double: the control value is converted to and
* from double on save/restore.
*/
void Add( wxTextCtrl& ctrl, double& dest );
/**
* Bind a control managed by a #UNIT_BINDER into a integer
*/
void Add( UNIT_BINDER& ctrl, long& dest );
/**
* Bind a choice control into a choice (agnostic to the actual
* meaning of the choice)
*/
void Add( wxChoice& ctrl, long& dest );
/**
* Bind a notebook tab choice to an integer
*/
void Add( wxNotebook& ctrl, long& dest );
/**
* Read values of all bound controls into the internally-stored
* references to the underlying data.
*/
void ReadConfigFromControls();
/**
* Restore the values from the internally-stored references to the underlying
* data to each bound control.
*/
void RestoreConfigToControls();
private:
/**
* Recognised parameters types (encodes an implicit widget type,
* data type and appropriate conversion).
*/
enum class WIDGET_CTRL_TYPE_T
{
TEXT,
TEXT_INTEGER,
TEXT_DOUBLE,
UNIT_BINDER,
CHECKBOX,
RADIOBOX,
CHOICE,
TAB
};
union CONTROL {
CONTROL( wxCheckBox* aCtrl ) : m_checkbox( aCtrl )
{
}
CONTROL( wxChoice* aCtrl ) : m_choice( aCtrl )
{
}
CONTROL( wxNotebook* aCtrl ) : m_notebook( aCtrl )
{
}
CONTROL( wxRadioBox* aCtrl ) : m_radiobox( aCtrl )
{
}
CONTROL( wxTextCtrl* aCtrl ) : m_textctrl( aCtrl )
{
}
CONTROL( UNIT_BINDER* aCtrl ) : m_unit_binder( aCtrl )
{
}
wxCheckBox* m_checkbox;
wxChoice* m_choice;
wxNotebook* m_notebook;
wxRadioBox* m_radiobox;
wxTextCtrl* m_textctrl;
UNIT_BINDER* m_unit_binder;
};
union DATA {
DATA( long* aDest ) : m_long( aDest )
{
}
DATA( bool* aDest ) : m_bool( aDest )
{
}
DATA( wxString* aDest ) : m_str( aDest )
{
}
DATA( double* aDest ) : m_double( aDest )
{
}
long* m_long;
bool* m_bool;
wxString* m_str;
double* m_double;
};
/**
* Struct that represents a single bound control
*/
struct WIDGET_CTRL_T
{
template <typename CTRL_T, typename DEST_T>
WIDGET_CTRL_T( WIDGET_CTRL_TYPE_T aType, CTRL_T& aCtrl, DEST_T& aDest )
: m_type( aType ), m_control( &aCtrl ), m_dest( &aDest )
{
}
WIDGET_CTRL_TYPE_T m_type;
CONTROL m_control;
DATA m_dest;
};
std::vector<WIDGET_CTRL_T> m_ctrls;
bool& m_valid;
};
#endif // WIDGETS_WIDGET_SAVE_RESTORE__H

View File

@ -42,13 +42,13 @@ struct CREATE_ARRAY_DIALOG_ENTRIES
*/ */
CREATE_ARRAY_DIALOG_ENTRIES() CREATE_ARRAY_DIALOG_ENTRIES()
: m_optionsSet( true ), : m_optionsSet( true ),
m_gridNx( "5" ), m_gridNx( 5 ),
m_gridNy( "5" ), m_gridNy( 5 ),
m_gridDx( Millimeter2iu( 2.54 ) ), m_gridDx( Millimeter2iu( 2.54 ) ),
m_gridDy( Millimeter2iu( 2.54 ) ), m_gridDy( Millimeter2iu( 2.54 ) ),
m_gridOffsetX( 0 ), m_gridOffsetX( 0 ),
m_gridOffsetY( 0 ), m_gridOffsetY( 0 ),
m_gridStagger( "1" ), m_gridStagger( 1 ),
m_gridStaggerType( 0 ), // rows m_gridStaggerType( 0 ), // rows
m_gridNumberingAxis( 0 ), // h then v m_gridNumberingAxis( 0 ), // h then v
m_gridNumberingReverseAlternate( false ), m_gridNumberingReverseAlternate( false ),
@ -60,8 +60,8 @@ struct CREATE_ARRAY_DIALOG_ENTRIES
m_gridSecNumberingOffset( "1" ), // numeric m_gridSecNumberingOffset( "1" ), // numeric
m_circCentreX( 0 ), m_circCentreX( 0 ),
m_circCentreY( 0 ), m_circCentreY( 0 ),
m_circAngle( "0" ), m_circAngle( 0.0 ),
m_circCount( "4" ), m_circCount( 4 ),
m_circNumberingStartSet( 1 ), // use specified start m_circNumberingStartSet( 1 ), // use specified start
m_circNumberingOffset( "1" ), m_circNumberingOffset( "1" ),
m_circRotate( false ), m_circRotate( false ),
@ -71,34 +71,34 @@ struct CREATE_ARRAY_DIALOG_ENTRIES
bool m_optionsSet; bool m_optionsSet;
wxString m_gridNx, m_gridNy; long m_gridNx, m_gridNy;
int m_gridDx, m_gridDy; long m_gridDx, m_gridDy;
int m_gridOffsetX, m_gridOffsetY; long m_gridOffsetX, m_gridOffsetY;
wxString m_gridStagger; long m_gridStagger;
int m_gridStaggerType, m_gridNumberingAxis; long m_gridStaggerType, m_gridNumberingAxis;
bool m_gridNumberingReverseAlternate; bool m_gridNumberingReverseAlternate;
int m_gridNumberingStartSet; long m_gridNumberingStartSet;
int m_grid2dArrayNumbering; long m_grid2dArrayNumbering;
int m_gridPriAxisNumScheme, m_gridSecAxisNumScheme; long m_gridPriAxisNumScheme, m_gridSecAxisNumScheme;
wxString m_gridPriNumberingOffset, m_gridSecNumberingOffset; wxString m_gridPriNumberingOffset, m_gridSecNumberingOffset;
int m_circCentreX, m_circCentreY; long m_circCentreX, m_circCentreY;
wxString m_circAngle, m_circCount; long m_circAngle;
int m_circNumberingStartSet; long m_circCount;
long m_circNumberingStartSet;
wxString m_circNumberingOffset; wxString m_circNumberingOffset;
bool m_circRotate; bool m_circRotate;
int m_arrayTypeTab; long m_arrayTypeTab;
}; };
// Persistent options settings // Persistent options settings
static CREATE_ARRAY_DIALOG_ENTRIES saved_array_options; static CREATE_ARRAY_DIALOG_ENTRIES saved_array_options;
DIALOG_CREATE_ARRAY::DIALOG_CREATE_ARRAY( PCB_BASE_FRAME* aParent, bool enableNumbering, DIALOG_CREATE_ARRAY::DIALOG_CREATE_ARRAY(
wxPoint aOrigPos ) : PCB_BASE_FRAME* aParent, bool enableNumbering, wxPoint aOrigPos )
DIALOG_CREATE_ARRAY_BASE( aParent ), : DIALOG_CREATE_ARRAY_BASE( aParent ),
CONFIG_SAVE_RESTORE_WINDOW( saved_array_options.m_optionsSet ),
m_settings( NULL ), m_settings( NULL ),
m_hSpacing( aParent, m_labelDx, m_entryDx, m_unitLabelDx ), m_hSpacing( aParent, m_labelDx, m_entryDx, m_unitLabelDx ),
m_vSpacing( aParent, m_labelDy, m_entryDy, m_unitLabelDy ), m_vSpacing( aParent, m_labelDy, m_entryDy, m_unitLabelDy ),
@ -107,6 +107,8 @@ DIALOG_CREATE_ARRAY::DIALOG_CREATE_ARRAY( PCB_BASE_FRAME* aParent, bool enableNu
m_hCentre( aParent, m_labelCentreX, m_entryCentreX, m_unitLabelCentreX ), m_hCentre( aParent, m_labelCentreX, m_entryCentreX, m_unitLabelCentreX ),
m_vCentre( aParent, m_labelCentreY, m_entryCentreY, m_unitLabelCentreY ), m_vCentre( aParent, m_labelCentreY, m_entryCentreY, m_unitLabelCentreY ),
m_circRadius( aParent, m_labelCircRadius, m_valueCircRadius, m_unitLabelCircRadius ), m_circRadius( aParent, m_labelCircRadius, m_valueCircRadius, m_unitLabelCircRadius ),
m_circAngle( aParent, m_labelCircAngle, m_entryCircAngle, m_unitLabelCircAngle ),
m_cfg_persister( saved_array_options.m_optionsSet ),
m_originalItemPosition( aOrigPos ), m_originalItemPosition( aOrigPos ),
m_numberingEnabled( enableNumbering ) m_numberingEnabled( enableNumbering )
{ {
@ -127,43 +129,48 @@ DIALOG_CREATE_ARRAY::DIALOG_CREATE_ARRAY( PCB_BASE_FRAME* aParent, bool enableNu
m_choicePriAxisNumbering->SetSelection( 0 ); m_choicePriAxisNumbering->SetSelection( 0 );
m_choiceSecAxisNumbering->SetSelection( 0 ); m_choiceSecAxisNumbering->SetSelection( 0 );
m_circAngle.SetUnits( EDA_UNITS_T::DEGREES );
// bind grid options to persister // bind grid options to persister
Add( m_entryNx, saved_array_options.m_gridNx ); m_cfg_persister.Add( *m_entryNx, saved_array_options.m_gridNx );
Add( m_entryNy, saved_array_options.m_gridNy ); m_cfg_persister.Add( *m_entryNy, saved_array_options.m_gridNy );
Add( m_hSpacing, saved_array_options.m_gridDx ); m_cfg_persister.Add( m_hSpacing, saved_array_options.m_gridDx );
Add( m_vSpacing, saved_array_options.m_gridDy ); m_cfg_persister.Add( m_vSpacing, saved_array_options.m_gridDy );
Add( m_hOffset, saved_array_options.m_gridOffsetX ); m_cfg_persister.Add( m_hOffset, saved_array_options.m_gridOffsetX );
Add( m_vOffset, saved_array_options.m_gridOffsetY ); m_cfg_persister.Add( m_vOffset, saved_array_options.m_gridOffsetY );
Add( m_entryStagger, saved_array_options.m_gridStagger ); m_cfg_persister.Add( *m_entryStagger, saved_array_options.m_gridStagger );
Add( m_radioBoxGridStaggerType, saved_array_options.m_gridStaggerType ); m_cfg_persister.Add( *m_radioBoxGridStaggerType, saved_array_options.m_gridStaggerType );
Add( m_radioBoxGridNumberingAxis, saved_array_options.m_gridNumberingAxis ); m_cfg_persister.Add( *m_radioBoxGridNumberingAxis, saved_array_options.m_gridNumberingAxis );
Add( m_checkBoxGridReverseNumbering, saved_array_options.m_gridNumberingReverseAlternate ); m_cfg_persister.Add(
*m_checkBoxGridReverseNumbering, saved_array_options.m_gridNumberingReverseAlternate );
Add( m_rbGridStartNumberingOpt, saved_array_options.m_gridNumberingStartSet ); m_cfg_persister.Add( *m_rbGridStartNumberingOpt, saved_array_options.m_gridNumberingStartSet );
Add( m_radioBoxGridNumberingScheme, saved_array_options.m_grid2dArrayNumbering ); m_cfg_persister.Add(
Add( m_choicePriAxisNumbering, saved_array_options.m_gridPriAxisNumScheme ); *m_radioBoxGridNumberingScheme, saved_array_options.m_grid2dArrayNumbering );
Add( m_choiceSecAxisNumbering, saved_array_options.m_gridSecAxisNumScheme ); m_cfg_persister.Add( *m_choicePriAxisNumbering, saved_array_options.m_gridPriAxisNumScheme );
m_cfg_persister.Add( *m_choiceSecAxisNumbering, saved_array_options.m_gridSecAxisNumScheme );
Add( m_entryGridPriNumberingOffset, saved_array_options.m_gridPriNumberingOffset ); m_cfg_persister.Add(
Add( m_entryGridSecNumberingOffset, saved_array_options.m_gridSecNumberingOffset ); *m_entryGridPriNumberingOffset, saved_array_options.m_gridPriNumberingOffset );
m_cfg_persister.Add(
*m_entryGridSecNumberingOffset, saved_array_options.m_gridSecNumberingOffset );
// bind circular options to persister // bind circular options to persister
Add( m_hCentre, saved_array_options.m_circCentreX ); m_cfg_persister.Add( m_hCentre, saved_array_options.m_circCentreX );
Add( m_vCentre, saved_array_options.m_circCentreY ); m_cfg_persister.Add( m_vCentre, saved_array_options.m_circCentreY );
Add( m_entryCircAngle, saved_array_options.m_circAngle ); m_cfg_persister.Add( m_circAngle, saved_array_options.m_circAngle );
Add( m_entryCircCount, saved_array_options.m_circCount ); m_cfg_persister.Add( *m_entryCircCount, saved_array_options.m_circCount );
Add( m_entryRotateItemsCb, saved_array_options.m_circRotate ); m_cfg_persister.Add( *m_entryRotateItemsCb, saved_array_options.m_circRotate );
Add( m_rbCircStartNumberingOpt, saved_array_options.m_circNumberingStartSet ); m_cfg_persister.Add( *m_rbCircStartNumberingOpt, saved_array_options.m_circNumberingStartSet );
Add( m_entryCircNumberingStart, saved_array_options.m_circNumberingOffset ); m_cfg_persister.Add( *m_entryCircNumberingStart, saved_array_options.m_circNumberingOffset );
Add( m_gridTypeNotebook, saved_array_options.m_arrayTypeTab ); m_cfg_persister.Add( *m_gridTypeNotebook, saved_array_options.m_arrayTypeTab );
m_cfg_persister.RestoreConfigToControls();
RestoreConfigToControls();
// Run the callbacks once to process the dialog contents // Run the callbacks once to process the dialog contents
setControlEnablement(); setControlEnablement();
@ -360,7 +367,7 @@ bool DIALOG_CREATE_ARRAY::TransferDataFromWindow()
// assign pointer and ownership here // assign pointer and ownership here
m_settings = newSettings; m_settings = newSettings;
ReadConfigFromControls(); m_cfg_persister.ReadConfigFromControls();
return true; return true;
} }

View File

@ -34,163 +34,10 @@
#include <boost/bimap.hpp> #include <boost/bimap.hpp>
#include <widgets/unit_binder.h> #include <widgets/unit_binder.h>
#include <widgets/widget_save_restore.h>
class CONFIG_SAVE_RESTORE_WINDOW
{
private:
enum CONFIG_CTRL_TYPE_T
{
CFG_CTRL_TEXT,
CFG_CTRL_UNIT_BINDER,
CFG_CTRL_CHECKBOX,
CFG_CTRL_RADIOBOX,
CFG_CTRL_CHOICE,
CFG_CTRL_TAB
};
struct CONFIG_CTRL_T
{
void* control;
CONFIG_CTRL_TYPE_T type;
void* dest;
};
std::vector<CONFIG_CTRL_T> ctrls;
bool& valid;
protected:
CONFIG_SAVE_RESTORE_WINDOW( bool& validFlag ) :
valid( validFlag )
{}
void Add( wxRadioBox* ctrl, int& dest )
{
CONFIG_CTRL_T ctrlInfo = { ctrl, CFG_CTRL_RADIOBOX, (void*) &dest };
ctrls.push_back( ctrlInfo );
}
void Add( wxCheckBox* ctrl, bool& dest )
{
CONFIG_CTRL_T ctrlInfo = { ctrl, CFG_CTRL_CHECKBOX, (void*) &dest };
ctrls.push_back( ctrlInfo );
}
void Add( wxTextCtrl* ctrl, wxString& dest )
{
CONFIG_CTRL_T ctrlInfo = { ctrl, CFG_CTRL_TEXT, (void*) &dest };
ctrls.push_back( ctrlInfo );
}
void Add( UNIT_BINDER& ctrl, int& dest )
{
CONFIG_CTRL_T ctrlInfo = { &ctrl, CFG_CTRL_UNIT_BINDER, (void*) &dest };
ctrls.push_back( ctrlInfo );
}
void Add( wxChoice* ctrl, int& dest ) class DIALOG_CREATE_ARRAY : public DIALOG_CREATE_ARRAY_BASE
{
CONFIG_CTRL_T ctrlInfo = { ctrl, CFG_CTRL_CHOICE, (void*) &dest };
ctrls.push_back( ctrlInfo );
}
void Add( wxNotebook* ctrl, int& dest )
{
CONFIG_CTRL_T ctrlInfo = { ctrl, CFG_CTRL_TAB, (void*) &dest };
ctrls.push_back( ctrlInfo );
}
void ReadConfigFromControls()
{
for( std::vector<CONFIG_CTRL_T>::const_iterator iter = ctrls.begin(), iend = ctrls.end();
iter != iend; ++iter )
{
switch( iter->type )
{
case CFG_CTRL_CHECKBOX:
*(bool*) iter->dest = static_cast<wxCheckBox*>( iter->control )->GetValue();
break;
case CFG_CTRL_TEXT:
*(wxString*) iter->dest = static_cast<wxTextCtrl*>( iter->control )->GetValue();
break;
case CFG_CTRL_UNIT_BINDER:
*(int*) iter->dest = static_cast<UNIT_BINDER*>( iter->control )->GetValue();
break;
case CFG_CTRL_CHOICE:
*(int*) iter->dest = static_cast<wxChoice*>( iter->control )->GetSelection();
break;
case CFG_CTRL_RADIOBOX:
*(int*) iter->dest = static_cast<wxRadioBox*>( iter->control )->GetSelection();
break;
case CFG_CTRL_TAB:
*(int*) iter->dest = static_cast<wxNotebook*>( iter->control )->GetSelection();
break;
default:
wxASSERT_MSG( false, wxString(
"Unhandled control type for config store: " ) << iter->type );
}
}
valid = true;
}
void RestoreConfigToControls()
{
if( !valid )
return;
for( std::vector<CONFIG_CTRL_T>::const_iterator iter = ctrls.begin(), iend = ctrls.end();
iter != iend; ++iter )
{
switch( iter->type )
{
case CFG_CTRL_CHECKBOX:
static_cast<wxCheckBox*>( iter->control )->SetValue( *(bool*) iter->dest );
break;
case CFG_CTRL_TEXT:
static_cast<wxTextCtrl*>( iter->control )->SetValue( *(wxString*) iter->dest );
break;
case CFG_CTRL_UNIT_BINDER:
static_cast<UNIT_BINDER*>( iter->control )->SetValue( *(int*) iter->dest );
break;
case CFG_CTRL_CHOICE:
static_cast<wxChoice*>( iter->control )->SetSelection( *(int*) iter->dest );
break;
case CFG_CTRL_RADIOBOX:
static_cast<wxRadioBox*>( iter->control )->SetSelection( *(int*) iter->dest );
break;
case CFG_CTRL_TAB:
static_cast<wxNotebook*>( iter->control )->SetSelection( *(int*) iter->dest );
break;
default:
wxASSERT_MSG( false, wxString(
"Unhandled control type for config restore: " ) << iter->type );
}
}
}
};
class DIALOG_CREATE_ARRAY : public DIALOG_CREATE_ARRAY_BASE,
public CONFIG_SAVE_RESTORE_WINDOW
{ {
public: public:
@ -223,6 +70,9 @@ private:
UNIT_BINDER m_hOffset, m_vOffset; UNIT_BINDER m_hOffset, m_vOffset;
UNIT_BINDER m_hCentre, m_vCentre; UNIT_BINDER m_hCentre, m_vCentre;
UNIT_BINDER m_circRadius; UNIT_BINDER m_circRadius;
UNIT_BINDER m_circAngle;
WIDGET_SAVE_RESTORE m_cfg_persister;
/* /*
* The position of the original item(s), used for finding radius, etc * The position of the original item(s), used for finding radius, etc