1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-02 00:29:41 +02:00

WrappedType is immutable (though it points to something mutable)

This commit is contained in:
Paul Licameli 2019-02-26 13:40:42 -05:00
parent 459582ce00
commit a5e0b66d1f
4 changed files with 29 additions and 35 deletions

View File

@ -1440,7 +1440,7 @@ wxRadioButton * ShuttleGuiBase::TieRadioButton(const wxString &Prompt, WrappedTy
mpWind = pRadioButton = safenew wxRadioButton(GetParent(), miId, Prompt,
wxDefaultPosition, wxDefaultSize,
(mRadioCount==1)?wxRB_GROUP:0);
pRadioButton->SetValue(WrappedRef.ValuesMatch( mRadioValue ));
pRadioButton->SetValue(WrappedRef.ValuesMatch( *mRadioValue ));
pRadioButton->SetName(wxStripMenuCodes(Prompt));
UpdateSizers();
}
@ -1454,7 +1454,7 @@ wxRadioButton * ShuttleGuiBase::TieRadioButton(const wxString &Prompt, WrappedTy
wxASSERT( pRadioButton );
if( pRadioButton->GetValue() )
{
mRadioValue.WriteToAsWrappedType( WrappedRef );
mRadioValue->WriteToAsWrappedType( WrappedRef );
}
}
break;
@ -1470,11 +1470,11 @@ wxRadioButton * ShuttleGuiBase::TieRadioButton(const wxString &Prompt, WrappedTy
/// Versions for specific types must do that initialisation.
void ShuttleGuiBase::StartRadioButtonGroup( const wxString & SettingName )
{
wxASSERT( mRadioValue.eWrappedType != eWrappedNotSet );
wxASSERT( mRadioValue && mRadioValue->eWrappedType != eWrappedNotSet );
mSettingName = SettingName;
mRadioCount = 0;
if( mShuttleMode == eIsCreating )
DoDataShuttle( SettingName, mRadioValue );
DoDataShuttle( SettingName, *mRadioValue );
}
/// Call this after any TieRadioButton calls.
@ -1482,9 +1482,8 @@ void ShuttleGuiBase::StartRadioButtonGroup( const wxString & SettingName )
void ShuttleGuiBase::EndRadioButtonGroup()
{
if( mShuttleMode == eIsGettingFromDialog )
DoDataShuttle( mSettingName, mRadioValue );
mRadioValue.Init();// Clear it out...
mSettingName = wxT("");
DoDataShuttle( mSettingName, *mRadioValue );
mRadioValue.reset();// Clear it out...
mRadioCount = -1; // So we detect a problem.
}
@ -1984,7 +1983,7 @@ void ShuttleGuiBase::StartRadioButtonGroup( const wxString & SettingName, const
{
// Configure the generic type mechanism to use OUR integer.
mRadioValueInt = iDefaultValue;
mRadioValue.SetTo( mRadioValueInt );
mRadioValue.create( mRadioValueInt );
// Now actually start the radio button group.
StartRadioButtonGroup( SettingName );
}
@ -1995,7 +1994,7 @@ void ShuttleGuiBase::StartRadioButtonGroup( const wxString & SettingName, const
{
// Configure the generic type mechanism to use OUR string.
mRadioValueString = DefaultValue;
mRadioValue.SetTo( mRadioValueString );
mRadioValue.create( mRadioValueString );
// Now actually start the radio button group.
StartRadioButtonGroup( SettingName );
}

View File

@ -335,7 +335,7 @@ protected:
wxString mSettingName; /// The setting controlled by a group.
int mRadioCount; /// The index of this radio item. -1 for none.
WrappedType mRadioValue; /// The wrapped value associated with the active radio button.
Maybe<WrappedType> mRadioValue; /// The wrapped value associated with the active radio button.
wxString mRadioValueString; /// Unwrapped string value.
int mRadioValueInt; /// Unwrapped integer value.

View File

@ -66,15 +66,6 @@ bool WrappedType::ValuesMatch( const WrappedType & W )
return false;
}
void WrappedType::Init()
{
eWrappedType = eWrappedNotSet;
mpStr = NULL;
mpInt = NULL;
mpDouble = NULL;
mpBool = NULL;
}
void WrappedType::WriteToAsWrappedType( const WrappedType & W )
{
wxASSERT( W.eWrappedType == eWrappedType );

View File

@ -31,16 +31,21 @@ class AUDACITY_DLL_API WrappedType
{
public:
WrappedType( wxString & InStr ){ SetTo(InStr); };
WrappedType( int & InInt ){ SetTo(InInt); };
WrappedType( double & InDouble ){SetTo(InDouble);};
WrappedType( bool & InBool ){ SetTo(InBool); };
WrappedType(){ Init();}
void SetTo( wxString & InStr ){ Init();mpStr=&InStr; eWrappedType = eWrappedString;}
void SetTo( int & InInt ){ Init();mpInt=&InInt; eWrappedType = eWrappedInt;};
void SetTo( double & InDouble ){Init();mpDouble=&InDouble; eWrappedType = eWrappedDouble;};
void SetTo( bool & InBool ){ Init();mpBool=&InBool; eWrappedType = eWrappedBool;};
explicit WrappedType( wxString & InStr )
: eWrappedType{ eWrappedString }, mpStr{ &InStr }
{}
explicit WrappedType( int & InInt )
: eWrappedType{ eWrappedInt }, mpInt{ &InInt }
{}
explicit WrappedType( double & InDouble )
: eWrappedType{ eWrappedDouble }, mpDouble{ &InDouble }
{}
explicit WrappedType( bool & InBool )
: eWrappedType{ eWrappedBool }, mpBool{ &InBool }
{}
explicit WrappedType()
: eWrappedType{ eWrappedNotSet }
{}
bool IsString();
@ -58,13 +63,12 @@ public:
void WriteToAsWrappedType( const WrappedType & W );
public :
void Init();
teWrappedType eWrappedType;
wxString * mpStr;
int * mpInt;
double * mpDouble;
bool * mpBool;
const teWrappedType eWrappedType;
wxString *const mpStr {};
int *const mpInt {};
double *const mpDouble {};
bool *const mpBool {};
};