Factored the code for each of the different types of config options out into

separate widgets. This makes preferences.cpp much cleaner and opens up
greater possibilities for the config item controls.
* Added "browse..." button to CONFIG_ITEM_DIRECTORY
* Added a slider to CONFIG_ITEM_INTEGER when i_min or i_max differs from 0
* Made it possible to change CONFIG_ITEM_KEY options with the preferences
dialog
parent ed1df1f7
...@@ -10,6 +10,7 @@ SOURCES_wxwindows = \ ...@@ -10,6 +10,7 @@ SOURCES_wxwindows = \
iteminfo.cpp \ iteminfo.cpp \
menus.cpp \ menus.cpp \
preferences.cpp \ preferences.cpp \
preferences_widgets.cpp \
timer.cpp \ timer.cpp \
fileinfo.cpp \ fileinfo.cpp \
subtitles.cpp \ subtitles.cpp \
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* interface.cpp : wxWindows plugin for vlc * interface.cpp : wxWindows plugin for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2000-2001 VideoLAN * Copyright (C) 2000-2001 VideoLAN
* $Id: interface.cpp,v 1.65 2003/10/14 22:41:41 gbazin Exp $ * $Id: interface.cpp,v 1.66 2003/10/19 22:41:18 sigmunau Exp $
* *
* Authors: Gildas Bazin <gbazin@netcourrier.com> * Authors: Gildas Bazin <gbazin@netcourrier.com>
* *
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "stream_control.h" #include "stream_control.h"
#include "wxwindows.h" #include "wxwindows.h"
#include <wx/url.h>
/* include the toolbar graphics */ /* include the toolbar graphics */
#include "bitmaps/file.xpm" #include "bitmaps/file.xpm"
...@@ -1244,7 +1245,7 @@ bool DragAndDrop::OnDropFiles( wxCoord, wxCoord, ...@@ -1244,7 +1245,7 @@ bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
} }
for( size_t i = 0; i < filenames.GetCount(); i++ ) for( size_t i = 0; i < filenames.GetCount(); i++ )
playlist_Add( p_playlist, (const char *)filenames[i].mb_str(), 0, 0, playlist_Add( p_playlist, (const char *)wxURL("file:///" + filenames[i]).GetPath().mb_str(), 0, 0,
PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO), PLAYLIST_END ); PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO), PLAYLIST_END );
vlc_object_release( p_playlist ); vlc_object_release( p_playlist );
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* preferences.cpp : wxWindows plugin for vlc * preferences.cpp : wxWindows plugin for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2000-2001 VideoLAN * Copyright (C) 2000-2001 VideoLAN
* $Id: preferences.cpp,v 1.35 2003/10/17 16:40:09 gbazin Exp $ * $Id: preferences.cpp,v 1.36 2003/10/19 22:41:18 sigmunau Exp $
* *
* Authors: Gildas Bazin <gbazin@netcourrier.com> * Authors: Gildas Bazin <gbazin@netcourrier.com>
* *
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <vlc_help.h> #include <vlc_help.h>
#include "wxwindows.h" #include "wxwindows.h"
#include "preferences_widgets.h"
#include <wx/notebook.h> #include <wx/notebook.h>
#include <wx/textctrl.h> #include <wx/textctrl.h>
#include <wx/combobox.h> #include <wx/combobox.h>
...@@ -90,26 +91,16 @@ private: ...@@ -90,26 +91,16 @@ private:
struct ConfigData struct ConfigData
{ {
ConfigData( wxPanel *_panel, int _i_conf_type, ConfigData( int _i_conf_type, vlc_bool_t _b_advanced, char *psz_name )
vlc_bool_t _b_advanced, char *psz_name ) { control = NULL; b_advanced = _b_advanced; b_config_list = VLC_FALSE;
{ panel = _panel; b_advanced = _b_advanced; b_config_list = VLC_FALSE;
i_config_type = _i_conf_type; option_name = wxU(psz_name); } i_config_type = _i_conf_type; option_name = wxU(psz_name); }
vlc_bool_t b_advanced; vlc_bool_t b_advanced;
int i_config_type; int i_config_type;
vlc_bool_t b_config_list; vlc_bool_t b_config_list;
union control ConfigControl *control;
{
wxComboBox *combobox;
wxRadioButton *radio;
wxSpinCtrl *spinctrl;
wxCheckBox *checkbox;
wxTextCtrl *textctrl;
} control;
wxPanel *panel;
wxString option_name; wxString option_name;
}; };
...@@ -156,22 +147,6 @@ public: ...@@ -156,22 +147,6 @@ public:
char *psz_section; char *psz_section;
}; };
class ConfigEvtHandler : public wxEvtHandler
{
public:
ConfigEvtHandler( intf_thread_t *p_intf, PrefsDialog *p_prefs_dialog );
virtual ~ConfigEvtHandler();
void ConfigEvtHandler::OnCommandEvent( wxCommandEvent& event );
private:
DECLARE_EVENT_TABLE()
intf_thread_t *p_intf;
PrefsDialog *p_prefs_dialog;
};
/***************************************************************************** /*****************************************************************************
* Event Table. * Event Table.
*****************************************************************************/ *****************************************************************************/
...@@ -208,13 +183,6 @@ BEGIN_EVENT_TABLE(PrefsTreeCtrl, wxTreeCtrl) ...@@ -208,13 +183,6 @@ BEGIN_EVENT_TABLE(PrefsTreeCtrl, wxTreeCtrl)
EVT_COMMAND(Advanced_Event, wxEVT_USER_FIRST, PrefsTreeCtrl::OnAdvanced) EVT_COMMAND(Advanced_Event, wxEVT_USER_FIRST, PrefsTreeCtrl::OnAdvanced)
END_EVENT_TABLE() END_EVENT_TABLE()
BEGIN_EVENT_TABLE(ConfigEvtHandler, wxEvtHandler)
EVT_BUTTON(-1, ConfigEvtHandler::OnCommandEvent)
EVT_TEXT(-1, ConfigEvtHandler::OnCommandEvent)
EVT_RADIOBOX(-1, ConfigEvtHandler::OnCommandEvent)
EVT_SPINCTRL(-1, ConfigEvtHandler::OnCommandEvent)
END_EVENT_TABLE()
/***************************************************************************** /*****************************************************************************
* Constructor. * Constructor.
*****************************************************************************/ *****************************************************************************/
...@@ -776,19 +744,11 @@ PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf, ...@@ -776,19 +744,11 @@ PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,
: wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize ) : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize )
{ {
module_config_t *p_item; module_config_t *p_item;
vlc_list_t *p_list;
module_t *p_parser;
wxStaticText *label; wxStaticText *label;
wxStaticText *help; wxStaticText *help;
wxComboBox *combo;
wxSpinCtrl *spin;
wxCheckBox *checkbox;
wxTextCtrl *textctrl;
wxButton *button;
wxArrayString array; wxArrayString array;
vlc_bool_t b_has_advanced = VLC_FALSE;
module_t *p_module = NULL; module_t *p_module = NULL;
/* Initializations */ /* Initializations */
...@@ -872,195 +832,65 @@ PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf, ...@@ -872,195 +832,65 @@ PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,
strcmp( psz_section, p_item->psz_text ) ) strcmp( psz_section, p_item->psz_text ) )
break; break;
/* put each config option in a separate panel so we can hide
* advanced options easily */
wxPanel *panel = new wxPanel( config_window, -1, wxDefaultPosition,
wxDefaultSize );
wxBoxSizer *panel_sizer = new wxBoxSizer( wxHORIZONTAL );
ConfigData *config_data = ConfigData *config_data =
new ConfigData( panel, p_item->i_type, new ConfigData( p_item->i_type, p_item->b_advanced,
p_item->b_advanced, p_item->psz_name ); p_item->psz_name );
switch( p_item->i_type ) switch( p_item->i_type )
{ {
case CONFIG_ITEM_MODULE: case CONFIG_ITEM_MODULE:
label = new wxStaticText(panel, -1, wxU(p_item->psz_text)); config_data->control = new ModuleConfigControl( p_intf, p_item, config_window );
combo = new wxComboBox( panel, -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 );
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),
p_parser->psz_object_name );
if( p_item->psz_value && !strcmp(p_item->psz_value,
p_parser->psz_object_name) )
combo->SetValue( wxU(p_parser->psz_longname) );
}
}
vlc_list_release( p_list );
combo->SetToolTip( wxU(p_item->psz_longtext) );
config_data->control.combobox = combo;
panel_sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL
| wxALL, 5 );
panel_sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL
| wxALL, 5 );
break; break;
case CONFIG_ITEM_STRING: case CONFIG_ITEM_STRING:
case CONFIG_ITEM_FILE:
case CONFIG_ITEM_DIRECTORY:
label = new wxStaticText(panel, -1, wxU(p_item->psz_text));
panel_sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL
| wxALL, 5 );
if( !p_item->ppsz_list ) if( !p_item->ppsz_list )
{ {
textctrl = new wxTextCtrl( panel, -1, config_data->control = new StringConfigControl( p_item, config_window );
wxU(p_item->psz_value),
wxDefaultPosition,
wxDefaultSize,
wxTE_PROCESS_ENTER);
textctrl->SetToolTip( wxU(p_item->psz_longtext) );
config_data->control.textctrl = textctrl;
panel_sizer->Add( textctrl, 1, wxALL, 5 );
} }
else else
{ {
combo = new wxComboBox( panel, -1, wxU(p_item->psz_value), config_data->control = new StringListConfigControl( p_item, config_window );
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++ )
{
combo->Append( wxU(p_item->ppsz_list[i_index]) );
if( p_item->psz_value && !strcmp( p_item->psz_value,
p_item->ppsz_list[i_index] ) )
combo->SetSelection( i_index );
} }
break;
case CONFIG_ITEM_FILE:
case CONFIG_ITEM_DIRECTORY:
config_data->control = new FileConfigControl( p_item, config_window );
break;
if( p_item->psz_value ) case CONFIG_ITEM_INTEGER:
combo->SetValue( wxU(p_item->psz_value) ); if( p_item->i_min != 0 || p_item->i_max != 0 )
combo->SetToolTip( wxU(p_item->psz_longtext) ); {
config_data->control.combobox = combo; config_data->control = new RangedIntConfigControl( p_item, config_window );
config_data->b_config_list = VLC_TRUE;
panel_sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL
|wxALL, 5 );
} }
else
if( p_item->i_type == CONFIG_ITEM_FILE )
{ {
button = new wxButton( panel, -1, wxU(_("Browse...")) ); config_data->control = new IntegerConfigControl( p_item, config_window );
panel_sizer->Add( button, 0, wxALIGN_CENTER_VERTICAL
|wxALL, 5);
button->SetClientData((void *)config_data);
} }
if( p_item->b_advanced ) b_has_advanced = VLC_TRUE;
break;
case CONFIG_ITEM_INTEGER:
label = new wxStaticText(panel, -1, wxU(p_item->psz_text));
spin = new wxSpinCtrl( panel, -1,
wxString::Format(wxT("%d"),
p_item->i_value),
wxDefaultPosition, wxDefaultSize,
wxSP_ARROW_KEYS,
-16000, 16000, p_item->i_value);
spin->SetToolTip( wxU(p_item->psz_longtext) );
config_data->control.spinctrl = spin;
panel_sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL
| wxALL, 5 );
panel_sizer->Add( spin, 0, wxALIGN_CENTER_VERTICAL
| wxALL, 5 );
spin->SetClientData((void *)config_data);
if( p_item->b_advanced ) b_has_advanced = VLC_TRUE;
break; break;
case CONFIG_ITEM_KEY: case CONFIG_ITEM_KEY:
{ config_data->control = new KeyConfigControl( p_item, config_window );
label = new wxStaticText(panel, -1, wxU(p_item->psz_text));
wxCheckBox *alt = new wxCheckBox( panel, -1, wxU(_("Alt")) );
alt->SetValue( p_item->i_value & KEY_MODIFIER_ALT );
wxCheckBox *ctrl = new wxCheckBox( panel, -1, wxU(_("Ctrl")) );
ctrl->SetValue( p_item->i_value & KEY_MODIFIER_CTRL );
wxCheckBox *shift = new wxCheckBox( panel, -1,
wxU(_("Shift")) );
shift->SetValue( p_item->i_value & KEY_MODIFIER_SHIFT );
combo = new wxComboBox( panel, -1, wxU("f"),
wxDefaultPosition, wxDefaultSize, 0
, NULL, wxCB_READONLY | wxCB_SORT );
for( int i=0; i < sizeof(keys)/sizeof(key_descriptor_s); i++ )
{
combo->Append( wxU(_(keys[i].psz_key_string)),
(void*)&keys[i].i_key_code );
}
combo->SetValue( wxU( KeyToString(
p_item->i_value&~KEY_MODIFIER )));
config_data->control.combobox = combo;
panel_sizer->Add( label, 2, wxALIGN_CENTER_VERTICAL
| wxALL | wxEXPAND, 5 );
panel_sizer->Add( alt, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
panel_sizer->Add( ctrl, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5);
panel_sizer->Add( shift, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5);
panel_sizer->Add( combo, 2, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5);
break; break;
}
case CONFIG_ITEM_FLOAT: case CONFIG_ITEM_FLOAT:
label = new wxStaticText(panel, -1, wxU(p_item->psz_text)); config_data->control = new FloatConfigControl( p_item, config_window );
textctrl = new wxTextCtrl( panel, -1,
wxString::Format(wxT("%f"),
p_item->f_value),
wxDefaultPosition, wxDefaultSize,
wxTE_PROCESS_ENTER );
textctrl->SetToolTip( wxU(p_item->psz_longtext) );
config_data->control.textctrl = textctrl;
panel_sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL
| wxALL, 5 );
panel_sizer->Add( textctrl, 0, wxALIGN_CENTER_VERTICAL
| wxALL, 5);
if( p_item->b_advanced ) b_has_advanced = VLC_TRUE;
break; break;
case CONFIG_ITEM_BOOL: case CONFIG_ITEM_BOOL:
checkbox = new wxCheckBox( panel, -1, wxU(p_item->psz_text) ); config_data->control = new BoolConfigControl( p_item, config_window );
if( p_item->i_value ) checkbox->SetValue(TRUE);
checkbox->SetToolTip( wxU(p_item->psz_longtext) );
config_data->control.checkbox = checkbox;
panel_sizer->Add( checkbox, 0, wxALL, 5 );
if( p_item->b_advanced ) b_has_advanced = VLC_TRUE;
break; break;
default: default:
delete panel; panel = NULL;
delete panel_sizer;
delete config_data;
break; break;
} }
/* Don't add items that were not recognized */ /* Don't add items that were not recognized */
if( panel == NULL ) continue; if( config_data->control == NULL ) continue;
panel_sizer->Layout();
panel->SetSizerAndFit( panel_sizer );
/* Add the config data to our array so we can keep a trace of it */ /* Add the config data to our array so we can keep a trace of it */
config_array.Add( config_data ); config_array.Add( config_data );
config_sizer->Add( panel, 0, wxEXPAND | wxALL, 2 ); config_sizer->Add( config_data->control, 0, wxEXPAND | wxALL, 2 );
} }
while( p_item->i_type != CONFIG_HINT_END && p_item++ ); while( p_item->i_type != CONFIG_HINT_END && p_item++ );
...@@ -1080,10 +910,6 @@ PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf, ...@@ -1080,10 +910,6 @@ PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,
sizer->Add( help ,0 ,wxEXPAND | wxALL, 5 ); sizer->Add( help ,0 ,wxEXPAND | wxALL, 5 );
} }
/* Intercept all menu events in our custom event handler */
config_window->PushEventHandler(
new ConfigEvtHandler( p_intf, p_prefs_dialog ) );
} }
sizer->Layout(); sizer->Layout();
SetSizer( sizer ); SetSizer( sizer );
...@@ -1097,37 +923,22 @@ void PrefsPanel::ApplyChanges() ...@@ -1097,37 +923,22 @@ void PrefsPanel::ApplyChanges()
switch( config_data->i_config_type ) switch( config_data->i_config_type )
{ {
case CONFIG_ITEM_MODULE:
config_PutPsz( p_intf, config_data->option_name.mb_str(), (char *)
config_data->control.combobox->GetClientData(
config_data->control.combobox->GetSelection() ) );
break;
case CONFIG_ITEM_STRING: case CONFIG_ITEM_STRING:
case CONFIG_ITEM_FILE: case CONFIG_ITEM_FILE:
case CONFIG_ITEM_DIRECTORY: case CONFIG_ITEM_DIRECTORY:
if( !config_data->b_config_list ) case CONFIG_ITEM_MODULE:
config_PutPsz( p_intf, config_data->option_name.mb_str(), config_PutPsz( p_intf, config_data->option_name.mb_str(), (char *)
config_data->control.textctrl->GetValue().mb_str() ); config_data->control->GetPszValue() );
else
config_PutPsz( p_intf, config_data->option_name.mb_str(),
config_data->control.combobox->GetValue().mb_str() );
break;
case CONFIG_ITEM_BOOL:
config_PutInt( p_intf, config_data->option_name.mb_str(),
config_data->control.checkbox->IsChecked() );
break; break;
case CONFIG_ITEM_INTEGER: case CONFIG_ITEM_INTEGER:
case CONFIG_ITEM_KEY:
case CONFIG_ITEM_BOOL:
config_PutInt( p_intf, config_data->option_name.mb_str(), config_PutInt( p_intf, config_data->option_name.mb_str(),
config_data->control.spinctrl->GetValue() ); config_data->control->GetIntValue() );
break; break;
case CONFIG_ITEM_FLOAT: case CONFIG_ITEM_FLOAT:
{
float f_value;
if( (wxSscanf(config_data->control.textctrl->GetValue(),
wxT("%f"), &f_value) == 1) )
config_PutFloat( p_intf, config_data->option_name.mb_str(), config_PutFloat( p_intf, config_data->option_name.mb_str(),
f_value ); config_data->control->GetFloatValue() );
}
break; break;
} }
} }
...@@ -1146,8 +957,8 @@ void PrefsPanel::SwitchAdvanced( vlc_bool_t b_new_advanced ) ...@@ -1146,8 +957,8 @@ void PrefsPanel::SwitchAdvanced( vlc_bool_t b_new_advanced )
ConfigData *config_data = config_array.Item(i); ConfigData *config_data = config_array.Item(i);
if( config_data->b_advanced ) if( config_data->b_advanced )
{ {
config_data->panel->Show( b_advanced ); config_data->control->Show( b_advanced );
config_sizer->Show( config_data->panel, b_advanced ); config_sizer->Show( config_data->control, b_advanced );
} }
} }
...@@ -1157,70 +968,3 @@ void PrefsPanel::SwitchAdvanced( vlc_bool_t b_new_advanced ) ...@@ -1157,70 +968,3 @@ void PrefsPanel::SwitchAdvanced( vlc_bool_t b_new_advanced )
} }
return; return;
} }
/*****************************************************************************
* A small helper class which intercepts all events
*****************************************************************************/
ConfigEvtHandler::ConfigEvtHandler( intf_thread_t *_p_intf,
PrefsDialog *_p_prefs_dialog )
{
/* Initializations */
p_intf = _p_intf;
p_prefs_dialog = _p_prefs_dialog;
}
ConfigEvtHandler::~ConfigEvtHandler()
{
}
void ConfigEvtHandler::OnCommandEvent( wxCommandEvent& event )
{
if( !event.GetEventObject() )
{
event.Skip();
return;
}
ConfigData *config_data = (ConfigData *)
((wxEvtHandler *)event.GetEventObject())->GetClientData();
if( !config_data )
{
event.Skip();
return;
}
if( config_data->i_config_type == CONFIG_ITEM_FILE )
{
wxFileDialog dialog( p_prefs_dialog, wxU(_("Open file")),
wxT(""), wxT(""), wxT("*.*"),
#if defined( __WXMSW__ )
wxOPEN );
#else
wxOPEN | wxSAVE );
#endif
if( dialog.ShowModal() == wxID_OK )
{
config_data->control.textctrl->SetValue( dialog.GetPath() );
}
}
switch( config_data->i_config_type )
{
case CONFIG_ITEM_MODULE:
break;
case CONFIG_ITEM_STRING:
break;
case CONFIG_ITEM_FILE:
break;
case CONFIG_ITEM_INTEGER:
break;
case CONFIG_ITEM_FLOAT:
break;
case CONFIG_ITEM_BOOL:
break;
}
event.Skip();
}
/*****************************************************************************
* preferences_widgets.cpp : wxWindows plugin for vlc
*****************************************************************************
* Copyright (C) 2000-2001 VideoLAN
* $Id: preferences_widgets.cpp,v 1.1 2003/10/19 22:41:18 sigmunau Exp $
*
* Authors: Gildas Bazin <gbazin@netcourrier.com>
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#include <stdlib.h> /* malloc(), free() */
#include <errno.h> /* ENOMEM */
#include <string.h> /* strerror() */
#include <stdio.h>
#include <vlc/vlc.h>
#include <vlc/intf.h>
#include <vlc_help.h>
#include "wxwindows.h"
#include "preferences_widgets.h"
/*****************************************************************************
* ConfigControl implementation
*****************************************************************************/
ConfigControl::ConfigControl( wxWindow *parent ): wxPanel( parent )
{
sizer = new wxBoxSizer( wxHORIZONTAL );
i_value = 0;
f_value = 0;
psz_value = NULL;
}
ConfigControl::~ConfigControl()
{
if( psz_value ) free( psz_value );
}
wxSizer *ConfigControl::Sizer()
{
return sizer;
}
int ConfigControl::GetIntValue()
{
return i_value;
}
float ConfigControl::GetFloatValue()
{
return f_value;
}
const char *ConfigControl::GetPszValue()
{
return psz_value;
}
/*****************************************************************************
* KeyConfigControl implementation
*****************************************************************************/
KeyConfigControl::KeyConfigControl( module_config_t *p_item, wxWindow *parent ): ConfigControl( parent )
{
label = new wxStaticText(this, -1, wxU(p_item->psz_text));
alt = new wxCheckBox( this, -1, wxU(_("Alt")) );
alt->SetValue( p_item->i_value & KEY_MODIFIER_ALT );
ctrl = new wxCheckBox( this, -1, wxU(_("Ctrl")) );
ctrl->SetValue( p_item->i_value & KEY_MODIFIER_CTRL );
shift = new wxCheckBox( this, -1, wxU(_("Shift")) );
shift->SetValue( p_item->i_value & KEY_MODIFIER_SHIFT );
combo = new wxComboBox( this, -1, wxU("f"), wxDefaultPosition,
wxDefaultSize, 0, NULL,
wxCB_READONLY | wxCB_SORT );
for( int i=0; i < sizeof(keys)/sizeof(key_descriptor_s); i++ )
{
/* HPReg says casting the int to void * is fine */
combo->Append( wxU(_(keys[i].psz_key_string)),
(void*)keys[i].i_key_code );
if( keys[i].i_key_code == ( p_item->i_value & ~KEY_MODIFIER ) )
{
combo->SetSelection( i );
}
}
sizer->Add( label, 2, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
sizer->Add( alt, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
sizer->Add( ctrl, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
sizer->Add( shift, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
sizer->Add( combo, 2, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
sizer->Layout();
this->SetSizerAndFit( sizer );
}
KeyConfigControl::~KeyConfigControl()
{
;
}
int KeyConfigControl::GetIntValue()
{
int result = 0;
if( alt->IsChecked() )
{
result |= KEY_MODIFIER_ALT;
}
if( ctrl->IsChecked() )
{
result |= KEY_MODIFIER_CTRL;
}
if( shift->IsChecked() )
{
result |= KEY_MODIFIER_SHIFT;
}
int selected = combo->GetSelection();
if( selected != -1 )
{
result |= (int)combo->GetClientData( selected );
}
return result;
}
/*****************************************************************************
* ModuleConfigControl implementation
*****************************************************************************/
ModuleConfigControl::ModuleConfigControl( intf_thread_t *p_intf, module_config_t *p_item, wxWindow *parent ): ConfigControl( 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 );
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),
p_parser->psz_object_name );
if( p_item->psz_value && !strcmp(p_item->psz_value,
p_parser->psz_object_name) )
combo->SetValue( wxU(p_parser->psz_longname) );
}
}
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 );
sizer->Layout();
this->SetSizerAndFit( sizer );
}
ModuleConfigControl::~ModuleConfigControl()
{
;
}
const char *ModuleConfigControl::GetPszValue()
{
return combo->GetStringSelection();
}
/*****************************************************************************
* StringConfigControl implementation
*****************************************************************************/
StringConfigControl::StringConfigControl( module_config_t *p_item, wxWindow *parent ) : ConfigControl( parent )
{
label = new wxStaticText(this, -1, wxU(p_item->psz_text));
sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
textctrl = new wxTextCtrl( this, -1,
wxU(p_item->psz_value),
wxDefaultPosition,
wxDefaultSize,
wxTE_PROCESS_ENTER);
textctrl->SetToolTip( wxU(p_item->psz_longtext) );
sizer->Add( textctrl, 1, wxALL, 5 );
sizer->Layout();
this->SetSizerAndFit( sizer );
}
StringConfigControl::~StringConfigControl()
{
;
}
const char *StringConfigControl::GetPszValue()
{
return textctrl->GetValue();
}
/*****************************************************************************
* StringListConfigControl implementation
*****************************************************************************/
StringListConfigControl::StringListConfigControl( module_config_t *p_item, wxWindow *parent ): ConfigControl( 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++ )
{
combo->Append( wxU(p_item->ppsz_list[i_index]) );
if( p_item->psz_value && !strcmp( p_item->psz_value,
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) );
sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
sizer->Layout();
this->SetSizerAndFit( sizer );
}
StringListConfigControl::~StringListConfigControl()
{
;
}
const char *StringListConfigControl::GetPszValue()
{
return combo->GetStringSelection();
}
/*****************************************************************************
* FileConfigControl implementation
*****************************************************************************/
FileConfigControl::FileConfigControl( module_config_t *p_item, wxWindow *parent ) :ConfigControl( parent )
{
directory = p_item->i_type == CONFIG_ITEM_DIRECTORY;
label = new wxStaticText(this, -1, wxU(p_item->psz_text));
sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
textctrl = new wxTextCtrl( this, -1,
wxU(p_item->psz_value),
wxDefaultPosition,
wxDefaultSize,
wxTE_PROCESS_ENTER);
textctrl->SetToolTip( wxU(p_item->psz_longtext) );
sizer->Add( textctrl, 1, wxALL, 5 );
browse = new wxButton( this, wxID_HIGHEST, wxU(_("Browse...")) );
sizer->Add( browse, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
sizer->Layout();
this->SetSizerAndFit( sizer );
}
BEGIN_EVENT_TABLE(FileConfigControl, wxPanel)
/* Button events */
EVT_BUTTON(wxID_HIGHEST, FileConfigControl::OnBrowse)
END_EVENT_TABLE()
void FileConfigControl::OnBrowse( wxCommandEvent& event )
{
if( directory )
{
wxDirDialog dialog( this, wxU(_("Choose Directory")) );
if( dialog.ShowModal() == wxID_OK )
{
textctrl->SetValue( dialog.GetPath() );
}
}
else
{
wxFileDialog dialog( this, wxU(_("Choose File")),
wxT(""), wxT(""), wxT("*.*"),
#if defined( __WXMSW__ )
wxOPEN
#else
wxOPEN | wxSAVE
#endif
);
}
}
FileConfigControl::~FileConfigControl()
{
;
}
const char *FileConfigControl::GetPszValue()
{
return textctrl->GetValue();
}
/*****************************************************************************
* IntegerConfigControl implementation
*****************************************************************************/
IntegerConfigControl::IntegerConfigControl( module_config_t *p_item, wxWindow *parent ): ConfigControl( parent )
{
label = new wxStaticText(this, -1, wxU(p_item->psz_text));
spin = new wxSpinCtrl( this, -1,
wxString::Format(wxT("%d"),
p_item->i_value),
wxDefaultPosition, wxDefaultSize,
wxSP_ARROW_KEYS,
-16000, 16000, p_item->i_value);
spin->SetToolTip( wxU(p_item->psz_longtext) );
sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
sizer->Add( spin, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
sizer->Layout();
this->SetSizerAndFit( sizer );
}
IntegerConfigControl::~IntegerConfigControl()
{
;
}
int IntegerConfigControl::GetIntValue()
{
return spin->GetValue();
}
/*****************************************************************************
* RangedIntConfigControl implementation
*****************************************************************************/
RangedIntConfigControl::RangedIntConfigControl( module_config_t *p_item, wxWindow *parent ): ConfigControl( parent )
{
label = new wxStaticText(this, -1, wxU(p_item->psz_text));
slider = new wxSlider( this, -1, p_item->i_value, p_item->i_min,
p_item->i_max );
slider->SetToolTip( wxU(p_item->psz_longtext) );
sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
sizer->Add( slider, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
sizer->Layout();
this->SetSizerAndFit( sizer );
}
RangedIntConfigControl::~RangedIntConfigControl()
{
;
}
int RangedIntConfigControl::GetIntValue()
{
return slider->GetValue();
}
/*****************************************************************************
* FloatConfigControl implementation
*****************************************************************************/
FloatConfigControl::FloatConfigControl( module_config_t *p_item, wxWindow *parent ): ConfigControl( parent )
{
label = new wxStaticText(this, -1, wxU(p_item->psz_text));
textctrl = new wxTextCtrl( this, -1,
wxString::Format(wxT("%f"),
p_item->f_value),
wxDefaultPosition, wxDefaultSize,
wxTE_PROCESS_ENTER );
textctrl->SetToolTip( wxU(p_item->psz_longtext) );
sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
sizer->Add( textctrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
sizer->Layout();
this->SetSizerAndFit( sizer );
}
FloatConfigControl::~FloatConfigControl()
{
;
}
float FloatConfigControl::GetFloatValue()
{
float f_value;
if( (wxSscanf(textctrl->GetValue(), wxT("%f"), &f_value) == 1) )
return f_value;
else return 0.0;
}
/*****************************************************************************
* BoolConfigControl implementation
*****************************************************************************/
BoolConfigControl::BoolConfigControl( module_config_t *p_item, wxWindow *parent ): ConfigControl( parent )
{
checkbox = new wxCheckBox( this, -1, wxU(p_item->psz_text) );
if( p_item->i_value ) checkbox->SetValue(TRUE);
checkbox->SetToolTip( wxU(p_item->psz_longtext) );
sizer->Add( checkbox, 0, wxALL, 5 );
sizer->Layout();
this->SetSizerAndFit( sizer );
}
BoolConfigControl::~BoolConfigControl()
{
;
}
int BoolConfigControl::GetIntValue()
{
if( checkbox->IsChecked() )
{
return 1;
}
else
{
return 0;
}
}
/*****************************************************************************
* preferences_widgets.h : wxWindows plugin for vlc
*****************************************************************************
* Copyright (C) 2000-2003 VideoLAN
* $Id: preferences_widgets.h,v 1.1 2003/10/19 22:41:18 sigmunau Exp $
*
* Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
class ConfigControl: public wxPanel
{
public:
ConfigControl( wxWindow *parent );
~ConfigControl();
wxSizer *Sizer();
virtual int GetIntValue();
virtual float GetFloatValue();
virtual const char * GetPszValue();
protected:
wxBoxSizer *sizer;
wxStaticText *label;
private:
int i_value;
float f_value;
char *psz_value;
};
class KeyConfigControl: public ConfigControl
{
public:
KeyConfigControl( module_config_t *p_item, wxWindow *parent );
~KeyConfigControl();
virtual int GetIntValue();
private:
wxCheckBox *alt;
wxCheckBox *ctrl;
wxCheckBox *shift;
wxComboBox *combo;
};
class ModuleConfigControl: public ConfigControl
{
public:
ModuleConfigControl( intf_thread_t *p_intf, module_config_t *p_item,
wxWindow *parent );
~ModuleConfigControl();
virtual const char *GetPszValue();
private:
wxComboBox *combo;
};
class StringConfigControl: public ConfigControl
{
public:
StringConfigControl( module_config_t *p_item, wxWindow *parent );
~StringConfigControl();
virtual const char *GetPszValue();
private:
wxTextCtrl *textctrl;
};
class StringListConfigControl: public ConfigControl
{
public:
StringListConfigControl( module_config_t *p_item, wxWindow *parent );
~StringListConfigControl();
virtual const char *GetPszValue();
private:
wxComboBox *combo;
};
class FileConfigControl: public ConfigControl
{
public:
FileConfigControl( module_config_t *p_item, wxWindow *parent );
~FileConfigControl();
void FileConfigControl::OnBrowse( wxCommandEvent& );
virtual const char *GetPszValue();
private:
DECLARE_EVENT_TABLE()
wxTextCtrl *textctrl;
wxButton *browse;
bool directory;
};
class IntegerConfigControl: public ConfigControl
{
public:
IntegerConfigControl( module_config_t *p_item, wxWindow *parent );
~IntegerConfigControl();
virtual int GetIntValue();
private:
wxSpinCtrl *spin;
};
class RangedIntConfigControl: public ConfigControl
{
public:
RangedIntConfigControl( module_config_t *p_item, wxWindow *parent );
~RangedIntConfigControl();
virtual int GetIntValue();
private:
wxSlider *slider;
};
class FloatConfigControl: public ConfigControl
{
public:
FloatConfigControl( module_config_t *p_item, wxWindow *parent );
~FloatConfigControl();
virtual float GetFloatValue();
private:
wxTextCtrl *textctrl;
};
class BoolConfigControl: public ConfigControl
{
public:
BoolConfigControl( module_config_t *p_item, wxWindow *parent );
~BoolConfigControl();
virtual int GetIntValue();
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