Commit f43c76d4 authored by Olivier Teulière's avatar Olivier Teulière

* ./modules/gui/win32: fixed a bug in the preferences (closes #60)

parent 920f7a10
/***************************************************************************** /*****************************************************************************
* preferences.cpp: the "Preferences" dialog box * preferences.cpp: the "Preferences" dialog box
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002-2003 VideoLAN
* *
* Authors: Olivier Teuliere <ipkiss@via.ecp.fr> * Authors: Olivier Teuliere <ipkiss@via.ecp.fr>
* Boris Dores <babal@via.ecp.fr> * Boris Dores <babal@via.ecp.fr>
...@@ -85,9 +85,10 @@ __fastcall TCleanCheckListBox::~TCleanCheckListBox() ...@@ -85,9 +85,10 @@ __fastcall TCleanCheckListBox::~TCleanCheckListBox()
* Functions to help components creation * Functions to help components creation
****************************************************************************/ ****************************************************************************/
__fastcall TPanelPref::TPanelPref( TComponent* Owner, __fastcall TPanelPref::TPanelPref( TComponent* Owner,
module_config_t *p_config_arg ) : TPanel( Owner ) module_config_t *_p_config, intf_thread_t *_p_intf ) : TPanel( Owner )
{ {
p_config = p_config_arg; p_intf = _p_intf;
p_config = _p_config;
BevelInner = bvNone; BevelInner = bvNone;
BevelOuter = bvNone; BevelOuter = bvNone;
BorderStyle = bsNone; BorderStyle = bsNone;
...@@ -175,9 +176,6 @@ TCSpinEdit * __fastcall TPanelPref::CreateSpinEdit( TWinControl *Parent, ...@@ -175,9 +176,6 @@ TCSpinEdit * __fastcall TPanelPref::CreateSpinEdit( TWinControl *Parent,
return SpinEdit; return SpinEdit;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void __fastcall TPanelPref::UpdateChanges()
{
}
#define LIBWIN32_PREFSIZE_VPAD 4 #define LIBWIN32_PREFSIZE_VPAD 4
#define LIBWIN32_PREFSIZE_HPAD 4 #define LIBWIN32_PREFSIZE_HPAD 4
...@@ -199,11 +197,9 @@ void __fastcall TPanelPref::UpdateChanges() ...@@ -199,11 +197,9 @@ void __fastcall TPanelPref::UpdateChanges()
* Panel for module management * Panel for module management
****************************************************************************/ ****************************************************************************/
__fastcall TPanelPlugin::TPanelPlugin( TComponent* Owner, __fastcall TPanelPlugin::TPanelPlugin( TComponent* Owner,
module_config_t *p_config, intf_thread_t *_p_intf ) module_config_t *p_config, intf_thread_t *_p_intf )
: TPanelPref( Owner, p_config ) : TPanelPref( Owner, p_config, _p_intf )
{ {
p_intf = _p_intf;
/* init configure button */ /* init configure button */
ButtonConfig = CreateButton( this, ButtonConfig = CreateButton( this,
LIBWIN32_PREFSIZE_RIGHT - LIBWIN32_PREFSIZE_BUTTON_WIDTH, LIBWIN32_PREFSIZE_RIGHT - LIBWIN32_PREFSIZE_BUTTON_WIDTH,
...@@ -312,15 +308,13 @@ void __fastcall TPanelPlugin::UpdateChanges() ...@@ -312,15 +308,13 @@ void __fastcall TPanelPlugin::UpdateChanges()
if( CleanCheckListBox->Checked[item] ) if( CleanCheckListBox->Checked[item] )
{ {
Name = ((TObjectString*)CleanCheckListBox->Items->Objects[item]) Name = ((TObjectString*)CleanCheckListBox->Items->Objects[item])
->String().c_str(); ->String();
break; break;
} }
} }
/* XXX: Necessary, since c_str() returns only a temporary pointer... */ config_PutPsz( p_intf, p_config->psz_name,
free( p_config->psz_value ); Name.Length() ? Name.c_str() : NULL );
p_config->psz_value = (char *)malloc( Name.Length() + 1 );
strcpy( p_config->psz_value, Name.c_str() );
} }
...@@ -328,7 +322,8 @@ void __fastcall TPanelPlugin::UpdateChanges() ...@@ -328,7 +322,8 @@ void __fastcall TPanelPlugin::UpdateChanges()
* Panel for string management * Panel for string management
****************************************************************************/ ****************************************************************************/
__fastcall TPanelString::TPanelString( TComponent* Owner, __fastcall TPanelString::TPanelString( TComponent* Owner,
module_config_t *p_config ) : TPanelPref( Owner, p_config ) module_config_t *p_config, intf_thread_t *_p_intf )
: TPanelPref( Owner, p_config, _p_intf )
{ {
/* init description label */ /* init description label */
AnsiString Text = AnsiString ( p_config->psz_text ) + ":"; AnsiString Text = AnsiString ( p_config->psz_text ) + ":";
...@@ -358,10 +353,8 @@ __fastcall TPanelString::TPanelString( TComponent* Owner, ...@@ -358,10 +353,8 @@ __fastcall TPanelString::TPanelString( TComponent* Owner,
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void __fastcall TPanelString::UpdateChanges() void __fastcall TPanelString::UpdateChanges()
{ {
/* XXX: Necessary, since c_str() returns only a temporary pointer... */ config_PutPsz( p_intf, p_config->psz_name,
free( p_config->psz_value ); Edit->Text.Length() ? Edit->Text.c_str() : NULL );
p_config->psz_value = (char *)malloc( Edit->Text.Length() + 1 );
strcpy( p_config->psz_value, Edit->Text.c_str() );
} }
...@@ -369,7 +362,8 @@ void __fastcall TPanelString::UpdateChanges() ...@@ -369,7 +362,8 @@ void __fastcall TPanelString::UpdateChanges()
* Panel for integer management * Panel for integer management
****************************************************************************/ ****************************************************************************/
__fastcall TPanelInteger::TPanelInteger( TComponent* Owner, __fastcall TPanelInteger::TPanelInteger( TComponent* Owner,
module_config_t *p_config ) : TPanelPref( Owner, p_config ) module_config_t *p_config, intf_thread_t *_p_intf )
: TPanelPref( Owner, p_config, _p_intf )
{ {
/* init description label */ /* init description label */
AnsiString Text = AnsiString ( p_config->psz_text ) + ":"; AnsiString Text = AnsiString ( p_config->psz_text ) + ":";
...@@ -406,7 +400,7 @@ __fastcall TPanelInteger::TPanelInteger( TComponent* Owner, ...@@ -406,7 +400,7 @@ __fastcall TPanelInteger::TPanelInteger( TComponent* Owner,
void __fastcall TPanelInteger::UpdateChanges() void __fastcall TPanelInteger::UpdateChanges()
{ {
/* Warning: we're casting from long to int */ /* Warning: we're casting from long to int */
p_config->i_value = (int)SpinEdit->Value; config_PutInt( p_intf, p_config->psz_name, (int)SpinEdit->Value );
} }
...@@ -414,7 +408,8 @@ void __fastcall TPanelInteger::UpdateChanges() ...@@ -414,7 +408,8 @@ void __fastcall TPanelInteger::UpdateChanges()
* Panel for float management * Panel for float management
****************************************************************************/ ****************************************************************************/
__fastcall TPanelFloat::TPanelFloat( TComponent* Owner, __fastcall TPanelFloat::TPanelFloat( TComponent* Owner,
module_config_t *p_config ) : TPanelPref( Owner, p_config ) module_config_t *p_config, intf_thread_t *_p_intf )
: TPanelPref( Owner, p_config, _p_intf )
{ {
#define MAX_FLOAT_CHARS 20 #define MAX_FLOAT_CHARS 20
/* init description label */ /* init description label */
...@@ -458,7 +453,7 @@ __fastcall TPanelFloat::TPanelFloat( TComponent* Owner, ...@@ -458,7 +453,7 @@ __fastcall TPanelFloat::TPanelFloat( TComponent* Owner,
void __fastcall TPanelFloat::UpdateChanges() void __fastcall TPanelFloat::UpdateChanges()
{ {
/* Warning: we're casting from double to float */ /* Warning: we're casting from double to float */
p_config->f_value = atof( Edit->Text.c_str() ); config_PutFloat( p_intf, p_config->psz_name, atof( Edit->Text.c_str() ) );
} }
...@@ -466,7 +461,8 @@ void __fastcall TPanelFloat::UpdateChanges() ...@@ -466,7 +461,8 @@ void __fastcall TPanelFloat::UpdateChanges()
* Panel for boolean management * Panel for boolean management
****************************************************************************/ ****************************************************************************/
__fastcall TPanelBool::TPanelBool( TComponent* Owner, __fastcall TPanelBool::TPanelBool( TComponent* Owner,
module_config_t *p_config ) : TPanelPref( Owner, p_config ) module_config_t *p_config, intf_thread_t *_p_intf )
: TPanelPref( Owner, p_config, _p_intf )
{ {
/* init checkbox */ /* init checkbox */
CheckBox = CreateCheckBox( this, CheckBox = CreateCheckBox( this,
...@@ -484,7 +480,7 @@ __fastcall TPanelBool::TPanelBool( TComponent* Owner, ...@@ -484,7 +480,7 @@ __fastcall TPanelBool::TPanelBool( TComponent* Owner,
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void __fastcall TPanelBool::UpdateChanges() void __fastcall TPanelBool::UpdateChanges()
{ {
p_config->i_value = CheckBox->Checked ? 1 : 0; config_PutInt( p_intf, p_config->psz_name, CheckBox->Checked ? 1 : 0 );
} }
...@@ -634,7 +630,7 @@ void __fastcall TPreferencesDlg::CreateConfigDialog( char *psz_module_name ) ...@@ -634,7 +630,7 @@ void __fastcall TPreferencesDlg::CreateConfigDialog( char *psz_module_name )
case CONFIG_ITEM_STRING: case CONFIG_ITEM_STRING:
/* add new panel for the config option */ /* add new panel for the config option */
PanelString = new TPanelString( this, p_item ); PanelString = new TPanelString( this, p_item, p_intf );
PanelString->Parent = ScrollBox; PanelString->Parent = ScrollBox;
break; break;
...@@ -642,7 +638,7 @@ void __fastcall TPreferencesDlg::CreateConfigDialog( char *psz_module_name ) ...@@ -642,7 +638,7 @@ void __fastcall TPreferencesDlg::CreateConfigDialog( char *psz_module_name )
case CONFIG_ITEM_INTEGER: case CONFIG_ITEM_INTEGER:
/* add new panel for the config option */ /* add new panel for the config option */
PanelInteger = new TPanelInteger( this, p_item ); PanelInteger = new TPanelInteger( this, p_item, p_intf );
PanelInteger->Parent = ScrollBox; PanelInteger->Parent = ScrollBox;
break; break;
...@@ -650,7 +646,7 @@ void __fastcall TPreferencesDlg::CreateConfigDialog( char *psz_module_name ) ...@@ -650,7 +646,7 @@ void __fastcall TPreferencesDlg::CreateConfigDialog( char *psz_module_name )
case CONFIG_ITEM_FLOAT: case CONFIG_ITEM_FLOAT:
/* add new panel for the config option */ /* add new panel for the config option */
PanelFloat = new TPanelFloat( this, p_item ); PanelFloat = new TPanelFloat( this, p_item, p_intf );
PanelFloat->Parent = ScrollBox; PanelFloat->Parent = ScrollBox;
break; break;
...@@ -658,7 +654,7 @@ void __fastcall TPreferencesDlg::CreateConfigDialog( char *psz_module_name ) ...@@ -658,7 +654,7 @@ void __fastcall TPreferencesDlg::CreateConfigDialog( char *psz_module_name )
case CONFIG_ITEM_BOOL: case CONFIG_ITEM_BOOL:
/* add new panel for the config option */ /* add new panel for the config option */
PanelBool = new TPanelBool( this, p_item ); PanelBool = new TPanelBool( this, p_item, p_intf );
PanelBool->Parent = ScrollBox; PanelBool->Parent = ScrollBox;
break; break;
...@@ -719,7 +715,6 @@ void __fastcall TPreferencesDlg::ButtonApplyClick( TObject *Sender ) ...@@ -719,7 +715,6 @@ void __fastcall TPreferencesDlg::ButtonApplyClick( TObject *Sender )
{ {
Panel = (TPanelPref *)ScrollBox->Controls[j]; Panel = (TPanelPref *)ScrollBox->Controls[j];
Panel->UpdateChanges(); Panel->UpdateChanges();
SaveValue( Panel->p_config );
} }
} }
} }
...@@ -736,27 +731,3 @@ void __fastcall TPreferencesDlg::ButtonCancelClick( TObject *Sender ) ...@@ -736,27 +731,3 @@ void __fastcall TPreferencesDlg::ButtonCancelClick( TObject *Sender )
Hide(); Hide();
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void __fastcall TPreferencesDlg::SaveValue( module_config_t *p_config )
{
switch( p_config->i_type )
{
case CONFIG_ITEM_STRING:
case CONFIG_ITEM_FILE:
case CONFIG_ITEM_MODULE:
config_PutPsz( p_intf, p_config->psz_name,
*p_config->psz_value ? p_config->psz_value : NULL );
break;
case CONFIG_ITEM_INTEGER:
case CONFIG_ITEM_BOOL:
config_PutInt( p_intf, p_config->psz_name, p_config->i_value );
break;
case CONFIG_ITEM_FLOAT:
config_PutFloat( p_intf, p_config->psz_name, p_config->f_value );
break;
default:
msg_Warn( p_intf, "unknown config type" );
break;
}
}
//---------------------------------------------------------------------------
/***************************************************************************** /*****************************************************************************
* preferences.h: the "Preferences" dialog box * preferences.h: the "Preferences" dialog box
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002-2003 VideoLAN
* *
* Authors: Olivier Teuliere <ipkiss@via.ecp.fr> * Authors: Olivier Teuliere <ipkiss@via.ecp.fr>
* Boris Dores <babal@via.ecp.fr> * Boris Dores <babal@via.ecp.fr>
...@@ -65,10 +65,13 @@ public: ...@@ -65,10 +65,13 @@ public:
class TPanelPref : public TPanel class TPanelPref : public TPanel
{ {
public: public:
__fastcall TPanelPref( TComponent* Owner, module_config_t *p_config_arg ); __fastcall TPanelPref( TComponent* Owner, module_config_t *_p_config,
module_config_t *p_config; intf_thread_t *_p_intf );
virtual void __fastcall UpdateChanges() = 0; virtual void __fastcall UpdateChanges() = 0;
TCleanCheckListBox * __fastcall CreateCleanCheckListBox( TWinControl *Parent, protected:
module_config_t * p_config;
intf_thread_t * p_intf;
TCleanCheckListBox * __fastcall CreateCleanCheckListBox(TWinControl *Parent,
int Left, int Width, int Top, int Height ); int Left, int Width, int Top, int Height );
TButton * __fastcall CreateButton( TWinControl *Parent, TButton * __fastcall CreateButton( TWinControl *Parent,
int Left, int Width, int Top, int Height, AnsiString Caption ); int Left, int Width, int Top, int Height, AnsiString Caption );
...@@ -88,7 +91,7 @@ class TPanelPlugin : public TPanelPref ...@@ -88,7 +91,7 @@ class TPanelPlugin : public TPanelPref
{ {
public: public:
__fastcall TPanelPlugin( TComponent* Owner, module_config_t *p_config, __fastcall TPanelPlugin( TComponent* Owner, module_config_t *p_config,
intf_thread_t *_p_intf ); intf_thread_t *_p_intf );
TCleanCheckListBox *CleanCheckListBox; TCleanCheckListBox *CleanCheckListBox;
TButton *ButtonConfig; TButton *ButtonConfig;
TLabel *Label; TLabel *Label;
...@@ -97,14 +100,13 @@ public: ...@@ -97,14 +100,13 @@ public:
void __fastcall CheckListBoxClick( TObject *Sender ); void __fastcall CheckListBoxClick( TObject *Sender );
void __fastcall CheckListBoxClickCheck( TObject *Sender ); void __fastcall CheckListBoxClickCheck( TObject *Sender );
void __fastcall ButtonConfigClick( TObject *Sender ); void __fastcall ButtonConfigClick( TObject *Sender );
private:
intf_thread_t *p_intf;
}; };
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
class TPanelString : public TPanelPref class TPanelString : public TPanelPref
{ {
public: public:
__fastcall TPanelString( TComponent* Owner, module_config_t *p_config ); __fastcall TPanelString( TComponent* Owner, module_config_t *p_config,
intf_thread_t *_p_intf );
TLabel *Label; TLabel *Label;
TEdit *Edit; TEdit *Edit;
virtual void __fastcall UpdateChanges(); virtual void __fastcall UpdateChanges();
...@@ -113,7 +115,8 @@ public: ...@@ -113,7 +115,8 @@ public:
class TPanelInteger : public TPanelPref class TPanelInteger : public TPanelPref
{ {
public: public:
__fastcall TPanelInteger( TComponent* Owner, module_config_t *p_config ); __fastcall TPanelInteger( TComponent* Owner, module_config_t *p_config,
intf_thread_t *_p_intf );
TLabel *Label; TLabel *Label;
TCSpinEdit *SpinEdit; TCSpinEdit *SpinEdit;
virtual void __fastcall UpdateChanges(); virtual void __fastcall UpdateChanges();
...@@ -122,7 +125,8 @@ public: ...@@ -122,7 +125,8 @@ public:
class TPanelFloat : public TPanelPref class TPanelFloat : public TPanelPref
{ {
public: public:
__fastcall TPanelFloat( TComponent* Owner, module_config_t *p_config ); __fastcall TPanelFloat( TComponent* Owner, module_config_t *p_config,
intf_thread_t *_p_intf );
TLabel *Label; TLabel *Label;
TEdit *Edit; TEdit *Edit;
virtual void __fastcall UpdateChanges(); virtual void __fastcall UpdateChanges();
...@@ -131,7 +135,8 @@ public: ...@@ -131,7 +135,8 @@ public:
class TPanelBool : public TPanelPref class TPanelBool : public TPanelPref
{ {
public: public:
__fastcall TPanelBool( TComponent* Owner, module_config_t *p_config ); __fastcall TPanelBool( TComponent* Owner, module_config_t *p_config,
intf_thread_t *_p_intf );
TCheckBox *CheckBox; TCheckBox *CheckBox;
virtual void __fastcall UpdateChanges(); virtual void __fastcall UpdateChanges();
}; };
...@@ -154,7 +159,6 @@ private: // User declarations ...@@ -154,7 +159,6 @@ private: // User declarations
public: // User declarations public: // User declarations
__fastcall TPreferencesDlg( TComponent* Owner, intf_thread_t *_p_intf ); __fastcall TPreferencesDlg( TComponent* Owner, intf_thread_t *_p_intf );
void __fastcall CreateConfigDialog( char *psz_module_name ); void __fastcall CreateConfigDialog( char *psz_module_name );
void __fastcall SaveValue( module_config_t *p_config );
}; };
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment