Commit 3173b30a authored by Gildas Bazin's avatar Gildas Bazin

* modules/gui/wxwindows/preferences*: added GetName(), GetType() and...

* modules/gui/wxwindows/preferences*: added GetName(), GetType() and IsAdvanced() to ConfigControl and got rid of ConfigData for even more simplifications.
parent de1be1c1
......@@ -2,7 +2,7 @@
* preferences.cpp : wxWindows plugin for vlc
*****************************************************************************
* Copyright (C) 2000-2001 VideoLAN
* $Id: preferences.cpp,v 1.37 2003/10/20 00:09:27 gbazin Exp $
* $Id: preferences.cpp,v 1.38 2003/10/20 12:25:22 gbazin Exp $
*
* Authors: Gildas Bazin <gbazin@netcourrier.com>
*
......@@ -89,22 +89,7 @@ private:
wxTreeItemId plugins_item;
};
struct ConfigData
{
ConfigData( int _i_conf_type, vlc_bool_t _b_advanced, char *psz_name )
{ control = NULL; b_advanced = _b_advanced; b_config_list = VLC_FALSE;
i_config_type = _i_conf_type; option_name = wxU(psz_name); }
vlc_bool_t b_advanced;
int i_config_type;
vlc_bool_t b_config_list;
ConfigControl *control;
wxString option_name;
};
WX_DEFINE_ARRAY(ConfigData *, ArrayOfConfigData);
WX_DEFINE_ARRAY(ConfigControl *, ArrayOfConfigControls);
class PrefsPanel : public wxPanel
{
......@@ -127,7 +112,7 @@ private:
wxBoxSizer *config_sizer;
wxScrolledWindow *config_window;
ArrayOfConfigData config_array;
ArrayOfConfigControls config_array;
};
class ConfigTreeData : public wxTreeItemData
......@@ -832,65 +817,17 @@ PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,
strcmp( psz_section, p_item->psz_text ) )
break;
ConfigData *config_data =
new ConfigData( p_item->i_type, p_item->b_advanced,
p_item->psz_name );
switch( p_item->i_type )
{
case CONFIG_ITEM_MODULE:
config_data->control = new ModuleConfigControl( p_intf, p_item, config_window );
break;
case CONFIG_ITEM_STRING:
if( !p_item->ppsz_list )
{
config_data->control = new StringConfigControl( p_item, config_window );
}
else
{
config_data->control = new StringListConfigControl( p_item, config_window );
}
break;
case CONFIG_ITEM_FILE:
case CONFIG_ITEM_DIRECTORY:
config_data->control = new FileConfigControl( p_item, config_window );
break;
case CONFIG_ITEM_INTEGER:
if( p_item->i_min != 0 || p_item->i_max != 0 )
{
config_data->control = new RangedIntConfigControl( p_item, config_window );
}
else
{
config_data->control = new IntegerConfigControl( p_item, config_window );
}
break;
case CONFIG_ITEM_KEY:
config_data->control = new KeyConfigControl( p_item, config_window );
break;
case CONFIG_ITEM_FLOAT:
config_data->control = new FloatConfigControl( p_item, config_window );
break;
case CONFIG_ITEM_BOOL:
config_data->control = new BoolConfigControl( p_item, config_window );
break;
default:
break;
}
ConfigControl *control =
CreateConfigControl( VLC_OBJECT(p_intf),
p_item, config_window );
/* Don't add items that were not recognized */
if( config_data->control == NULL ) continue;
if( control == NULL ) continue;
/* Add the config data to our array so we can keep a trace of it */
config_array.Add( config_data );
config_array.Add( control );
config_sizer->Add( config_data->control, 0, wxEXPAND | wxALL, 2 );
config_sizer->Add( control, 0, wxEXPAND | wxALL, 2 );
}
while( p_item->i_type != CONFIG_HINT_END && p_item++ );
......@@ -919,26 +856,26 @@ void PrefsPanel::ApplyChanges()
{
for( size_t i = 0; i < config_array.GetCount(); i++ )
{
ConfigData *config_data = config_array.Item(i);
ConfigControl *control = config_array.Item(i);
switch( config_data->i_config_type )
switch( control->GetType() )
{
case CONFIG_ITEM_STRING:
case CONFIG_ITEM_FILE:
case CONFIG_ITEM_DIRECTORY:
case CONFIG_ITEM_MODULE:
config_PutPsz( p_intf, config_data->option_name.mb_str(),
config_data->control->GetPszValue().mb_str() );
config_PutPsz( p_intf, control->GetName().mb_str(),
control->GetPszValue().mb_str() );
break;
case CONFIG_ITEM_INTEGER:
case CONFIG_ITEM_KEY:
case CONFIG_ITEM_BOOL:
config_PutInt( p_intf, config_data->option_name.mb_str(),
config_data->control->GetIntValue() );
config_PutInt( p_intf, control->GetName().mb_str(),
control->GetIntValue() );
break;
case CONFIG_ITEM_FLOAT:
config_PutFloat( p_intf, config_data->option_name.mb_str(),
config_data->control->GetFloatValue() );
config_PutFloat( p_intf, control->GetName().mb_str(),
control->GetFloatValue() );
break;
}
}
......@@ -954,11 +891,11 @@ void PrefsPanel::SwitchAdvanced( vlc_bool_t b_new_advanced )
for( size_t i = 0; i < config_array.GetCount(); i++ )
{
ConfigData *config_data = config_array.Item(i);
if( config_data->b_advanced )
ConfigControl *control = config_array.Item(i);
if( control->IsAdvanced() )
{
config_data->control->Show( b_advanced );
config_sizer->Show( config_data->control, b_advanced );
control->Show( b_advanced );
config_sizer->Show( control, b_advanced );
}
}
......
......@@ -2,7 +2,7 @@
* preferences_widgets.cpp : wxWindows plugin for vlc
*****************************************************************************
* Copyright (C) 2000-2001 VideoLAN
* $Id: preferences_widgets.cpp,v 1.3 2003/10/20 00:09:27 gbazin Exp $
* $Id: preferences_widgets.cpp,v 1.4 2003/10/20 12:25:22 gbazin Exp $
*
* Authors: Gildas Bazin <gbazin@netcourrier.com>
* Sigmund Augdal <sigmunau@idi.ntnu.no>
......@@ -38,20 +38,78 @@
#include "wxwindows.h"
#include "preferences_widgets.h"
/*****************************************************************************
* CreateConfigControl wrapper
*****************************************************************************/
ConfigControl *CreateConfigControl( vlc_object_t *p_this,
module_config_t *p_item, wxWindow *parent )
{
ConfigControl *p_control = NULL;
switch( p_item->i_type )
{
case CONFIG_ITEM_MODULE:
p_control = new ModuleConfigControl( p_this, p_item, parent );
break;
case CONFIG_ITEM_STRING:
if( !p_item->ppsz_list )
{
p_control = new StringConfigControl( p_item, parent );
}
else
{
p_control = new StringListConfigControl( p_item, parent );
}
break;
case CONFIG_ITEM_FILE:
case CONFIG_ITEM_DIRECTORY:
p_control = new FileConfigControl( p_item, parent );
break;
case CONFIG_ITEM_INTEGER:
if( p_item->i_min != 0 || p_item->i_max != 0 )
{
p_control = new RangedIntConfigControl( p_item, parent );
}
else
{
p_control = new IntegerConfigControl( p_item, parent );
}
break;
case CONFIG_ITEM_KEY:
p_control = new KeyConfigControl( p_item, parent );
break;
case CONFIG_ITEM_FLOAT:
p_control = new FloatConfigControl( p_item, parent );
break;
case CONFIG_ITEM_BOOL:
p_control = new BoolConfigControl( p_item, parent );
break;
default:
break;
}
return p_control;
}
/*****************************************************************************
* ConfigControl implementation
*****************************************************************************/
ConfigControl::ConfigControl( wxWindow *parent ): wxPanel( parent )
ConfigControl::ConfigControl( module_config_t *p_item, wxWindow *parent )
: wxPanel( parent ), name( wxU(p_item->psz_name) ),
i_type( p_item->i_type ), b_advanced( p_item->b_advanced )
{
sizer = new wxBoxSizer( wxHORIZONTAL );
i_value = 0;
f_value = 0;
psz_value = NULL;
}
ConfigControl::~ConfigControl()
{
if( psz_value ) free( psz_value );
}
wxSizer *ConfigControl::Sizer()
......@@ -59,26 +117,26 @@ wxSizer *ConfigControl::Sizer()
return sizer;
}
int ConfigControl::GetIntValue()
wxString ConfigControl::GetName()
{
return i_value;
return name;
}
float ConfigControl::GetFloatValue()
int ConfigControl::GetType()
{
return f_value;
return i_type;
}
wxString ConfigControl::GetPszValue()
vlc_bool_t ConfigControl::IsAdvanced()
{
return wxString(psz_value ? wxU(psz_value) : wxT(""));
return b_advanced;
}
/*****************************************************************************
* KeyConfigControl implementation
*****************************************************************************/
KeyConfigControl::KeyConfigControl( module_config_t *p_item, wxWindow *parent )
: ConfigControl( parent )
: ConfigControl( p_item, parent )
{
label = new wxStaticText(this, -1, wxU(p_item->psz_text));
alt = new wxCheckBox( this, -1, wxU(_("Alt")) );
......@@ -140,27 +198,27 @@ int KeyConfigControl::GetIntValue()
/*****************************************************************************
* ModuleConfigControl implementation
*****************************************************************************/
ModuleConfigControl::ModuleConfigControl( intf_thread_t *p_intf,
ModuleConfigControl::ModuleConfigControl( vlc_object_t *p_this,
module_config_t *p_item,
wxWindow *parent )
: ConfigControl( parent )
: ConfigControl( p_item, parent )
{
vlc_list_t *p_list;
module_t *p_parser;
label = new wxStaticText(this, -1, wxU(p_item->psz_text));
combo = new wxComboBox( this, -1, wxU(p_item->psz_value),
wxDefaultPosition, wxDefaultSize,
0, NULL, wxCB_READONLY | wxCB_SORT );
/* build a list of available modules */
p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
combo->Append( wxU(_("Default")), (void *)NULL );
combo->SetSelection( 0 );
for( int i_index = 0; i_index < p_list->i_count; i_index++ )
{
p_parser = (module_t *)p_list->p_values[i_index].p_object ;
if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
{
combo->Append( wxU(p_parser->psz_longname),
......@@ -171,7 +229,7 @@ ModuleConfigControl::ModuleConfigControl( intf_thread_t *p_intf,
}
}
vlc_list_release( p_list );
combo->SetToolTip( wxU(p_item->psz_longtext) );
sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
......@@ -194,7 +252,7 @@ wxString ModuleConfigControl::GetPszValue()
*****************************************************************************/
StringConfigControl::StringConfigControl( module_config_t *p_item,
wxWindow *parent )
: ConfigControl( parent )
: ConfigControl( p_item, parent )
{
label = new wxStaticText(this, -1, wxU(p_item->psz_text));
sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
......@@ -224,14 +282,14 @@ wxString StringConfigControl::GetPszValue()
*****************************************************************************/
StringListConfigControl::StringListConfigControl( module_config_t *p_item,
wxWindow *parent )
: ConfigControl( parent )
: ConfigControl( p_item, parent )
{
label = new wxStaticText(this, -1, wxU(p_item->psz_text));
sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
combo = new wxComboBox( this, -1, wxU(p_item->psz_value),
wxDefaultPosition, wxDefaultSize,
0, NULL, wxCB_READONLY|wxCB_SORT );
/* build a list of available options */
for( int i_index = 0; p_item->ppsz_list[i_index];
i_index++ )
......@@ -241,7 +299,7 @@ StringListConfigControl::StringListConfigControl( module_config_t *p_item,
p_item->ppsz_list[i_index] ) )
combo->SetSelection( i_index );
}
if( p_item->psz_value )
combo->SetValue( wxU(p_item->psz_value) );
combo->SetToolTip( wxU(p_item->psz_longtext) );
......@@ -265,7 +323,7 @@ wxString StringListConfigControl::GetPszValue()
*****************************************************************************/
FileConfigControl::FileConfigControl( module_config_t *p_item,
wxWindow *parent )
: ConfigControl( parent )
: ConfigControl( p_item, parent )
{
directory = p_item->i_type == CONFIG_ITEM_DIRECTORY;
label = new wxStaticText(this, -1, wxU(p_item->psz_text));
......@@ -327,7 +385,7 @@ wxString FileConfigControl::GetPszValue()
*****************************************************************************/
IntegerConfigControl::IntegerConfigControl( module_config_t *p_item,
wxWindow *parent )
: ConfigControl( parent )
: ConfigControl( p_item, parent )
{
label = new wxStaticText(this, -1, wxU(p_item->psz_text));
spin = new wxSpinCtrl( this, -1,
......@@ -358,7 +416,7 @@ int IntegerConfigControl::GetIntValue()
*****************************************************************************/
RangedIntConfigControl::RangedIntConfigControl( module_config_t *p_item,
wxWindow *parent )
: ConfigControl( parent )
: ConfigControl( p_item, parent )
{
label = new wxStaticText(this, -1, wxU(p_item->psz_text));
slider = new wxSlider( this, -1, p_item->i_value, p_item->i_min,
......@@ -385,7 +443,7 @@ int RangedIntConfigControl::GetIntValue()
*****************************************************************************/
FloatConfigControl::FloatConfigControl( module_config_t *p_item,
wxWindow *parent )
: ConfigControl( parent )
: ConfigControl( p_item, parent )
{
label = new wxStaticText(this, -1, wxU(p_item->psz_text));
textctrl = new wxTextCtrl( this, -1,
......@@ -418,7 +476,7 @@ float FloatConfigControl::GetFloatValue()
*****************************************************************************/
BoolConfigControl::BoolConfigControl( module_config_t *p_item,
wxWindow *parent )
: ConfigControl( parent )
: ConfigControl( p_item, parent )
{
checkbox = new wxCheckBox( this, -1, wxU(p_item->psz_text) );
if( p_item->i_value ) checkbox->SetValue(TRUE);
......
......@@ -2,7 +2,7 @@
* preferences_widgets.h : wxWindows plugin for vlc
*****************************************************************************
* Copyright (C) 2000-2003 VideoLAN
* $Id: preferences_widgets.h,v 1.2 2003/10/20 00:09:27 gbazin Exp $
* $Id: preferences_widgets.h,v 1.3 2003/10/20 12:25:22 gbazin Exp $
*
* Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
*
......@@ -24,21 +24,31 @@
class ConfigControl: public wxPanel
{
public:
ConfigControl( wxWindow *parent );
ConfigControl( module_config_t *, wxWindow *parent );
~ConfigControl();
wxSizer *Sizer();
virtual int GetIntValue();
virtual float GetFloatValue();
virtual wxString GetPszValue();
virtual int GetIntValue() {return 0;}
virtual float GetFloatValue() {return 0;}
virtual wxString GetPszValue() {return wxString();}
wxString GetName();
int GetType();
vlc_bool_t IsAdvanced();
protected:
wxBoxSizer *sizer;
wxStaticText *label;
private:
int i_value;
float f_value;
char *psz_value;
wxString name;
int i_type;
vlc_bool_t b_advanced;
};
ConfigControl *CreateConfigControl( vlc_object_t *,
module_config_t *, wxWindow * );
class KeyConfigControl: public ConfigControl
{
public:
......@@ -55,8 +65,8 @@ private:
class ModuleConfigControl: public ConfigControl
{
public:
ModuleConfigControl( intf_thread_t *p_intf, module_config_t *p_item,
wxWindow *parent );
ModuleConfigControl( vlc_object_t *p_this, module_config_t *p_item,
wxWindow *parent );
~ModuleConfigControl();
virtual wxString GetPszValue();
private:
......@@ -136,4 +146,3 @@ public:
private:
wxCheckBox *checkbox;
};
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