1 /*****************************************************************************
2 * preferences_widgets.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: preferences_widgets.cpp,v 1.6 2003/10/28 21:59:13 gbazin Exp $
7 * Authors: Gildas Bazin <gbazin@netcourrier.com>
8 * Sigmund Augdal <sigmunau@idi.ntnu.no>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
29 #include <errno.h> /* ENOMEM */
30 #include <string.h> /* strerror() */
38 #include "wxwindows.h"
39 #include "preferences_widgets.h"
41 /*****************************************************************************
42 * CreateConfigControl wrapper
43 *****************************************************************************/
44 ConfigControl *CreateConfigControl( vlc_object_t *p_this,
45 module_config_t *p_item, wxWindow *parent )
47 ConfigControl *p_control = NULL;
49 switch( p_item->i_type )
51 case CONFIG_ITEM_MODULE:
52 p_control = new ModuleConfigControl( p_this, p_item, parent );
55 case CONFIG_ITEM_STRING:
56 if( !p_item->ppsz_list )
58 p_control = new StringConfigControl( p_item, parent );
62 p_control = new StringListConfigControl( p_item, parent );
66 case CONFIG_ITEM_FILE:
67 case CONFIG_ITEM_DIRECTORY:
68 p_control = new FileConfigControl( p_item, parent );
71 case CONFIG_ITEM_INTEGER:
72 if( p_item->i_min != 0 || p_item->i_max != 0 )
74 p_control = new RangedIntConfigControl( p_item, parent );
78 p_control = new IntegerConfigControl( p_item, parent );
83 p_control = new KeyConfigControl( p_item, parent );
86 case CONFIG_ITEM_FLOAT:
87 p_control = new FloatConfigControl( p_item, parent );
90 case CONFIG_ITEM_BOOL:
91 p_control = new BoolConfigControl( p_item, parent );
101 /*****************************************************************************
102 * ConfigControl implementation
103 *****************************************************************************/
104 ConfigControl::ConfigControl( module_config_t *p_item, wxWindow *parent )
105 : wxPanel( parent ), name( wxU(p_item->psz_name) ),
106 i_type( p_item->i_type ), b_advanced( p_item->b_advanced )
108 sizer = new wxBoxSizer( wxHORIZONTAL );
111 ConfigControl::~ConfigControl()
115 wxSizer *ConfigControl::Sizer()
120 wxString ConfigControl::GetName()
125 int ConfigControl::GetType()
130 vlc_bool_t ConfigControl::IsAdvanced()
135 /*****************************************************************************
136 * KeyConfigControl implementation
137 *****************************************************************************/
138 KeyConfigControl::KeyConfigControl( module_config_t *p_item, wxWindow *parent )
139 : ConfigControl( p_item, parent )
141 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
142 alt = new wxCheckBox( this, -1, wxU(_("Alt")) );
143 alt->SetValue( p_item->i_value & KEY_MODIFIER_ALT );
144 ctrl = new wxCheckBox( this, -1, wxU(_("Ctrl")) );
145 ctrl->SetValue( p_item->i_value & KEY_MODIFIER_CTRL );
146 shift = new wxCheckBox( this, -1, wxU(_("Shift")) );
147 shift->SetValue( p_item->i_value & KEY_MODIFIER_SHIFT );
148 combo = new wxComboBox( this, -1, wxU("f"), wxDefaultPosition,
149 wxDefaultSize, 0, NULL,
150 wxCB_READONLY | wxCB_SORT );
151 for( unsigned int i = 0; i < sizeof(keys)/sizeof(key_descriptor_s); i++ )
153 /* HPReg says casting the int to void * is fine */
154 combo->Append( wxU(_(keys[i].psz_key_string)),
155 (void*)keys[i].i_key_code );
156 if( keys[i].i_key_code == ( ((unsigned int)p_item->i_value) & ~KEY_MODIFIER ) )
158 combo->SetSelection( i );
159 combo->SetValue( wxU(_(keys[i].psz_key_string)) );
163 sizer->Add( label, 2, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
164 sizer->Add( alt, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
165 sizer->Add( ctrl, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
166 sizer->Add( shift, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
167 sizer->Add( combo, 2, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
169 this->SetSizerAndFit( sizer );
172 KeyConfigControl::~KeyConfigControl()
177 int KeyConfigControl::GetIntValue()
180 if( alt->IsChecked() )
182 result |= KEY_MODIFIER_ALT;
184 if( ctrl->IsChecked() )
186 result |= KEY_MODIFIER_CTRL;
188 if( shift->IsChecked() )
190 result |= KEY_MODIFIER_SHIFT;
192 int selected = combo->GetSelection();
195 result |= (int)combo->GetClientData( selected );
200 /*****************************************************************************
201 * ModuleConfigControl implementation
202 *****************************************************************************/
203 ModuleConfigControl::ModuleConfigControl( vlc_object_t *p_this,
204 module_config_t *p_item,
206 : ConfigControl( p_item, parent )
211 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
212 combo = new wxComboBox( this, -1, wxU(p_item->psz_value),
213 wxDefaultPosition, wxDefaultSize,
214 0, NULL, wxCB_READONLY | wxCB_SORT );
216 /* build a list of available modules */
217 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
218 combo->Append( wxU(_("Default")), (void *)NULL );
219 combo->SetSelection( 0 );
220 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
222 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
224 if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
226 combo->Append( wxU(p_parser->psz_longname),
227 p_parser->psz_object_name );
228 if( p_item->psz_value && !strcmp(p_item->psz_value,
229 p_parser->psz_object_name) )
230 combo->SetValue( wxU(p_parser->psz_longname) );
233 vlc_list_release( p_list );
235 combo->SetToolTip( wxU(p_item->psz_longtext) );
236 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
237 sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
239 this->SetSizerAndFit( sizer );
242 ModuleConfigControl::~ModuleConfigControl()
247 wxString ModuleConfigControl::GetPszValue()
249 return wxU( (char *)combo->GetClientData( combo->GetSelection() ));
252 /*****************************************************************************
253 * StringConfigControl implementation
254 *****************************************************************************/
255 StringConfigControl::StringConfigControl( module_config_t *p_item,
257 : ConfigControl( p_item, parent )
259 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
260 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
261 textctrl = new wxTextCtrl( this, -1,
262 wxU(p_item->psz_value),
266 textctrl->SetToolTip( wxU(p_item->psz_longtext) );
267 sizer->Add( textctrl, 1, wxALL, 5 );
269 this->SetSizerAndFit( sizer );
272 StringConfigControl::~StringConfigControl()
277 wxString StringConfigControl::GetPszValue()
279 return textctrl->GetValue();
282 /*****************************************************************************
283 * StringListConfigControl implementation
284 *****************************************************************************/
285 StringListConfigControl::StringListConfigControl( module_config_t *p_item,
287 : ConfigControl( p_item, parent )
289 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
290 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
291 combo = new wxComboBox( this, -1, wxU(p_item->psz_value),
292 wxDefaultPosition, wxDefaultSize,
293 0, NULL, wxCB_READONLY|wxCB_SORT );
295 /* build a list of available options */
296 for( int i_index = 0; p_item->ppsz_list[i_index];
299 combo->Append( wxU(p_item->ppsz_list[i_index]) );
300 if( p_item->psz_value && !strcmp( p_item->psz_value,
301 p_item->ppsz_list[i_index] ) )
302 combo->SetSelection( i_index );
305 if( p_item->psz_value )
306 combo->SetValue( wxU(p_item->psz_value) );
307 combo->SetToolTip( wxU(p_item->psz_longtext) );
308 sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
310 this->SetSizerAndFit( sizer );
313 StringListConfigControl::~StringListConfigControl()
318 wxString StringListConfigControl::GetPszValue()
320 return combo->GetStringSelection();
323 /*****************************************************************************
324 * FileConfigControl implementation
325 *****************************************************************************/
326 FileConfigControl::FileConfigControl( module_config_t *p_item,
328 : ConfigControl( p_item, parent )
330 directory = p_item->i_type == CONFIG_ITEM_DIRECTORY;
331 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
332 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
333 textctrl = new wxTextCtrl( this, -1,
334 wxU(p_item->psz_value),
338 textctrl->SetToolTip( wxU(p_item->psz_longtext) );
339 sizer->Add( textctrl, 1, wxALL, 5 );
340 browse = new wxButton( this, wxID_HIGHEST, wxU(_("Browse...")) );
341 sizer->Add( browse, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
343 this->SetSizerAndFit( sizer );
346 BEGIN_EVENT_TABLE(FileConfigControl, wxPanel)
348 EVT_BUTTON(wxID_HIGHEST, FileConfigControl::OnBrowse)
351 void FileConfigControl::OnBrowse( wxCommandEvent& event )
355 wxDirDialog dialog( this, wxU(_("Choose Directory")) );
357 if( dialog.ShowModal() == wxID_OK )
359 textctrl->SetValue( dialog.GetPath() );
364 wxFileDialog dialog( this, wxU(_("Choose File")),
365 wxT(""), wxT(""), wxT("*.*"),
366 #if defined( __WXMSW__ )
375 FileConfigControl::~FileConfigControl()
380 wxString FileConfigControl::GetPszValue()
382 return textctrl->GetValue();
385 /*****************************************************************************
386 * IntegerConfigControl implementation
387 *****************************************************************************/
388 IntegerConfigControl::IntegerConfigControl( module_config_t *p_item,
390 : ConfigControl( p_item, parent )
392 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
393 spin = new wxSpinCtrl( this, -1,
394 wxString::Format(wxT("%d"),
396 wxDefaultPosition, wxDefaultSize,
398 -16000, 16000, p_item->i_value);
399 spin->SetToolTip( wxU(p_item->psz_longtext) );
400 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
401 sizer->Add( spin, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
403 this->SetSizerAndFit( sizer );
406 IntegerConfigControl::~IntegerConfigControl()
411 int IntegerConfigControl::GetIntValue()
413 return spin->GetValue();
416 /*****************************************************************************
417 * RangedIntConfigControl implementation
418 *****************************************************************************/
419 RangedIntConfigControl::RangedIntConfigControl( module_config_t *p_item,
421 : ConfigControl( p_item, parent )
423 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
424 slider = new wxSlider( this, -1, p_item->i_value, p_item->i_min,
426 slider->SetToolTip( wxU(p_item->psz_longtext) );
427 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
428 sizer->Add( slider, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
430 this->SetSizerAndFit( sizer );
433 RangedIntConfigControl::~RangedIntConfigControl()
438 int RangedIntConfigControl::GetIntValue()
440 return slider->GetValue();
443 /*****************************************************************************
444 * FloatConfigControl implementation
445 *****************************************************************************/
446 FloatConfigControl::FloatConfigControl( module_config_t *p_item,
448 : ConfigControl( p_item, parent )
450 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
451 textctrl = new wxTextCtrl( this, -1,
452 wxString::Format(wxT("%f"),
454 wxDefaultPosition, wxDefaultSize,
455 wxTE_PROCESS_ENTER );
456 textctrl->SetToolTip( wxU(p_item->psz_longtext) );
457 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
458 sizer->Add( textctrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
460 this->SetSizerAndFit( sizer );
463 FloatConfigControl::~FloatConfigControl()
468 float FloatConfigControl::GetFloatValue()
471 if( (wxSscanf(textctrl->GetValue(), wxT("%f"), &f_value) == 1) )
476 /*****************************************************************************
477 * BoolConfigControl implementation
478 *****************************************************************************/
479 BoolConfigControl::BoolConfigControl( module_config_t *p_item,
481 : ConfigControl( p_item, parent )
483 checkbox = new wxCheckBox( this, -1, wxU(p_item->psz_text) );
484 if( p_item->i_value ) checkbox->SetValue(TRUE);
485 checkbox->SetToolTip( wxU(p_item->psz_longtext) );
486 sizer->Add( checkbox, 0, wxALL, 5 );
488 this->SetSizerAndFit( sizer );
491 BoolConfigControl::~BoolConfigControl()
496 int BoolConfigControl::GetIntValue()
498 if( checkbox->IsChecked() )