]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/preferences_widgets.cpp
Fix warnings
[vlc] / modules / gui / wxwindows / preferences_widgets.cpp
1 /*****************************************************************************
2  * preferences_widgets.cpp : wxWindows plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2004 VideoLAN
5  * $Id$
6  *
7  * Authors: Gildas Bazin <gbazin@videolan.org>
8  *          Sigmund Augdal <sigmunau@idi.ntnu.no>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <stdlib.h>                                      /* malloc(), free() */
29 #include <errno.h>                                                 /* ENOMEM */
30 #include <string.h>                                            /* strerror() */
31 #include <stdio.h>
32
33 #include <vlc/vlc.h>
34 #include <vlc/intf.h>
35
36 #include <vlc_config_cat.h>
37
38 #include "wxwindows.h"
39 #include "preferences_widgets.h"
40
41 #include <wx/statline.h>
42
43 /*****************************************************************************
44  * CreateConfigControl wrapper
45  *****************************************************************************/
46 ConfigControl *CreateConfigControl( vlc_object_t *p_this,
47                                     module_config_t *p_item, wxWindow *parent )
48 {
49     ConfigControl *p_control = NULL;
50
51     switch( p_item->i_type )
52     {
53     case CONFIG_ITEM_MODULE:
54         p_control = new ModuleConfigControl( p_this, p_item, parent );
55         break;
56     case CONFIG_ITEM_MODULE_LIST_CAT:
57         p_control = new ModuleListCatConfigControl( p_this, p_item, parent );
58         break;
59
60     case CONFIG_ITEM_STRING:
61         if( !p_item->i_list )
62         {
63             p_control = new StringConfigControl( p_this, p_item, parent );
64         }
65         else
66         {
67             p_control = new StringListConfigControl( p_this, p_item, parent );
68         }
69         break;
70
71     case CONFIG_ITEM_FILE:
72     case CONFIG_ITEM_DIRECTORY:
73         p_control = new FileConfigControl( p_this, p_item, parent );
74         break;
75
76     case CONFIG_ITEM_INTEGER:
77         if( p_item->i_list )
78         {
79             p_control = new IntegerListConfigControl( p_this, p_item, parent );
80         }
81         else if( p_item->i_min != 0 || p_item->i_max != 0 )
82         {
83             p_control = new RangedIntConfigControl( p_this, p_item, parent );
84         }
85         else
86         {
87             p_control = new IntegerConfigControl( p_this, p_item, parent );
88         }
89         break;
90
91     case CONFIG_ITEM_KEY:
92         p_control = new KeyConfigControl( p_this, p_item, parent );
93         break;
94
95     case CONFIG_ITEM_FLOAT:
96         p_control = new FloatConfigControl( p_this, p_item, parent );
97         break;
98
99     case CONFIG_ITEM_BOOL:
100         p_control = new BoolConfigControl( p_this, p_item, parent );
101         break;
102
103     case CONFIG_SECTION:
104         p_control = new SectionConfigControl( p_this, p_item, parent );
105         break;
106
107     default:
108         break;
109     }
110
111     return p_control;
112 }
113
114 /*****************************************************************************
115  * ConfigControl implementation
116  *****************************************************************************/
117 ConfigControl::ConfigControl( vlc_object_t *_p_this,
118                               module_config_t *p_item, wxWindow *parent )
119   : wxPanel( parent ), p_this( _p_this ),
120     pf_update_callback( NULL ), p_update_data( NULL ),
121     name( wxU(p_item->psz_name) ), i_type( p_item->i_type ),
122     b_advanced( p_item->b_advanced )
123
124 {
125     sizer = new wxBoxSizer( wxHORIZONTAL );
126 }
127
128 ConfigControl::~ConfigControl()
129 {
130 }
131
132 wxSizer *ConfigControl::Sizer()
133 {
134     return sizer;
135 }
136
137 wxString ConfigControl::GetName()
138 {
139     return name;
140 }
141
142 int ConfigControl::GetType()
143 {
144     return i_type;
145 }
146
147 vlc_bool_t ConfigControl::IsAdvanced()
148 {
149     return b_advanced;
150 }
151
152 void ConfigControl::SetUpdateCallback( void (*p_callback)( void * ),
153                                              void *p_data )
154 {
155     pf_update_callback = p_callback;
156     p_update_data = p_data;
157 }
158
159 void ConfigControl::OnUpdate( wxCommandEvent& WXUNUSED(event) )
160 {
161     if( pf_update_callback )
162     {
163         pf_update_callback( p_update_data );
164     }
165 }
166
167 /*****************************************************************************
168  * KeyConfigControl implementation
169  *****************************************************************************/
170 wxString *KeyConfigControl::m_keysList = NULL;
171
172 KeyConfigControl::KeyConfigControl( vlc_object_t *p_this,
173                                     module_config_t *p_item, wxWindow *parent )
174   : ConfigControl( p_this, p_item, parent )
175 {
176     // Number of keys descriptions
177     unsigned int i_keys = sizeof(vlc_keys)/sizeof(key_descriptor_t);
178
179     // Init the keys decriptions array
180     if( m_keysList == NULL )
181     {
182         m_keysList = new wxString[i_keys];
183         for( unsigned int i = 0; i < i_keys; i++ )
184         {
185             m_keysList[i] = wxU(vlc_keys[i].psz_key_string);
186         }
187     }
188
189     label = new wxStaticText(this, -1, wxU(p_item->psz_text));
190     alt = new wxCheckBox( this, -1, wxU(_("Alt")) );
191     alt->SetValue( p_item->i_value & KEY_MODIFIER_ALT );
192     ctrl = new wxCheckBox( this, -1, wxU(_("Ctrl")) );
193     ctrl->SetValue( p_item->i_value & KEY_MODIFIER_CTRL );
194     shift = new wxCheckBox( this, -1, wxU(_("Shift")) );
195     shift->SetValue( p_item->i_value & KEY_MODIFIER_SHIFT );
196     combo = new wxComboBox( this, -1, wxT(""), wxDefaultPosition,
197                             wxDefaultSize, i_keys, m_keysList,
198                             wxCB_READONLY );
199     for( unsigned int i = 0; i < i_keys; i++ )
200     {
201         combo->SetClientData( i, (void*)vlc_keys[i].i_key_code );
202         if( (unsigned int)vlc_keys[i].i_key_code ==
203             ( ((unsigned int)p_item->i_value) & ~KEY_MODIFIER ) )
204         {
205             combo->SetSelection( i );
206             combo->SetValue( wxU(_(vlc_keys[i].psz_key_string)) );
207         }
208     }
209
210     sizer->Add( label, 2, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
211     sizer->Add( alt,   1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
212     sizer->Add( ctrl,  1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
213     sizer->Add( shift, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
214     sizer->Add( combo, 2, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
215     sizer->Layout();
216     this->SetSizerAndFit( sizer );
217 }
218
219 KeyConfigControl::~KeyConfigControl()
220 {
221     if( m_keysList )
222     {
223         delete[] m_keysList;
224         m_keysList = NULL;
225     }
226 }
227
228 int KeyConfigControl::GetIntValue()
229 {
230     int result = 0;
231     if( alt->IsChecked() )
232     {
233         result |= KEY_MODIFIER_ALT;
234     }
235     if( ctrl->IsChecked() )
236     {
237         result |= KEY_MODIFIER_CTRL;
238     }
239     if( shift->IsChecked() )
240     {
241         result |= KEY_MODIFIER_SHIFT;
242     }
243     int selected = combo->GetSelection();
244     if( selected != -1 )
245     {
246         result |= (int)combo->GetClientData( selected );
247     }
248     return result;
249 }
250
251 /*****************************************************************************
252  * ModuleConfigControl implementation
253  *****************************************************************************/
254 ModuleConfigControl::ModuleConfigControl( vlc_object_t *p_this,
255                                           module_config_t *p_item,
256                                           wxWindow *parent )
257   : ConfigControl( p_this, p_item, parent )
258 {
259     vlc_list_t *p_list;
260     module_t *p_parser;
261
262     label = new wxStaticText(this, -1, wxU(p_item->psz_text));
263     combo = new wxComboBox( this, -1, wxL2U(p_item->psz_value),
264                             wxDefaultPosition, wxDefaultSize,
265                             0, NULL, wxCB_READONLY | wxCB_SORT );
266
267     /* build a list of available modules */
268     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
269     combo->Append( wxU(_("Default")), (void *)NULL );
270     combo->SetSelection( 0 );
271     for( int i_index = 0; i_index < p_list->i_count; i_index++ )
272     {
273         p_parser = (module_t *)p_list->p_values[i_index].p_object ;
274
275         if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
276         {
277             combo->Append( wxU(p_parser->psz_longname),
278                            p_parser->psz_object_name );
279             if( p_item->psz_value && !strcmp(p_item->psz_value,
280                                              p_parser->psz_object_name) )
281                 combo->SetValue( wxU(p_parser->psz_longname) );
282         }
283     }
284     vlc_list_release( p_list );
285
286     combo->SetToolTip( wxU(p_item->psz_longtext) );
287     sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
288     sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
289     sizer->Layout();
290     this->SetSizerAndFit( sizer );
291 }
292
293 ModuleConfigControl::~ModuleConfigControl()
294 {
295     ;
296 }
297
298 wxString ModuleConfigControl::GetPszValue()
299 {
300     return wxU( (char *)combo->GetClientData( combo->GetSelection() ));
301 }
302
303 /*****************************************************************************
304  * ModuleListCatonfigControl implementation
305  *****************************************************************************/
306 BEGIN_EVENT_TABLE(ModuleListCatConfigControl, wxPanel)
307     EVT_CHECKBOX( wxID_HIGHEST , ModuleListCatConfigControl::OnUpdate )
308 END_EVENT_TABLE()
309
310
311 ModuleListCatConfigControl::ModuleListCatConfigControl( vlc_object_t *p_this,
312                                                      module_config_t *p_item,
313                                                      wxWindow *parent )
314   : ConfigControl( p_this, p_item, parent )
315 {
316     vlc_list_t *p_list;
317     module_t *p_parser;
318
319     delete sizer;
320     sizer = new wxBoxSizer( wxVERTICAL );
321     label = new wxStaticText(this, -1, wxU(p_item->psz_text));
322     sizer->Add( label );
323
324     text = new wxTextCtrl( this, -1, wxU(p_item->psz_value),
325                            wxDefaultPosition,wxSize( 300, 20 ) );
326
327
328     /* build a list of available modules */
329     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
330     for(  int i_index = 0; i_index < p_list->i_count; i_index++ )
331     {
332         p_parser = (module_t *)p_list->p_values[i_index].p_object ;
333
334         if( !strcmp( p_parser->psz_object_name, "main" ) )
335               continue;
336
337         module_config_t *p_config = p_parser->p_config;
338         if( p_config ) do
339         {
340             /* Hack: required subcategory is stored in i_min */
341             if( p_config->i_type == CONFIG_SUBCATEGORY &&
342                 p_config->i_value == p_item->i_min )
343             {
344                 moduleCheckBox *mc = new moduleCheckBox;
345                 mc->checkbox = new wxCheckBox( this, wxID_HIGHEST,
346                                                wxU(p_parser->psz_longname));
347                 mc->psz_module = strdup( p_parser->psz_object_name );
348                 pp_checkboxes.push_back( mc );
349
350                 if( p_item->psz_value &&
351                     strstr( p_item->psz_value, p_parser->psz_object_name ) )
352                 {
353                     mc->checkbox->SetValue( true );
354                 }
355                 sizer->Add( mc->checkbox );
356             }
357         } while( p_config->i_type != CONFIG_HINT_END && p_config++ );
358     }
359     vlc_list_release( p_list );
360
361     text->SetToolTip( wxU(p_item->psz_longtext) );
362     sizer->Add(text, wxEXPAND );
363
364     sizer->Add (new wxStaticText( this, -1, wxU( vlc_wraptext( _("Select modules that you want. To get more advanced control, you can also modify the resulting chain by yourself") , 72, ISUTF8 ) ) ) );
365
366     sizer->Layout();
367     this->SetSizerAndFit( sizer );
368 }
369
370 ModuleListCatConfigControl::~ModuleListCatConfigControl()
371 {
372     ;
373 }
374
375 wxString ModuleListCatConfigControl::GetPszValue()
376 {
377     return wxU( text->GetValue().c_str() ) ;
378 }
379
380 void  ModuleListCatConfigControl::OnUpdate( wxCommandEvent &event )
381 {
382     wxString newtext = wxU("");
383     for( unsigned int i = 0 ; i< pp_checkboxes.size() ; i++ )
384     {
385         if( pp_checkboxes[i]->checkbox->IsChecked() )
386         {
387             if( newtext.Len() == 0 )
388             {
389                 newtext = newtext + wxU( pp_checkboxes[i]->psz_module );
390             }
391             else
392             {
393                 newtext += wxU( "," );
394                 newtext += wxU(pp_checkboxes[i]->psz_module);
395             }
396         }
397     }
398     text->SetValue( newtext );
399 }
400
401 /*****************************************************************************
402  * StringConfigControl implementation
403  *****************************************************************************/
404 StringConfigControl::StringConfigControl( vlc_object_t *p_this,
405                                           module_config_t *p_item,
406                                           wxWindow *parent )
407   : ConfigControl( p_this, p_item, parent )
408 {
409     label = new wxStaticText(this, -1, wxU(p_item->psz_text));
410     sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
411     textctrl = new wxTextCtrl( this, -1,
412                                wxL2U(p_item->psz_value),
413                                wxDefaultPosition,
414                                wxDefaultSize,
415                                wxTE_PROCESS_ENTER);
416     textctrl->SetToolTip( wxU(p_item->psz_longtext) );
417     sizer->Add( textctrl, 1, wxALL, 5 );
418     sizer->Layout();
419     this->SetSizerAndFit( sizer );
420 }
421
422 StringConfigControl::~StringConfigControl()
423 {
424     ;
425 }
426
427 wxString StringConfigControl::GetPszValue()
428 {
429     return textctrl->GetValue();
430 }
431
432 BEGIN_EVENT_TABLE(StringConfigControl, wxPanel)
433     /* Text events */
434     EVT_TEXT(-1, StringConfigControl::OnUpdate)
435 END_EVENT_TABLE()
436
437 /*****************************************************************************
438  * StringListConfigControl implementation
439  *****************************************************************************/
440 StringListConfigControl::StringListConfigControl( vlc_object_t *p_this,
441                                                   module_config_t *p_item,
442                                                   wxWindow *parent )
443   : ConfigControl( p_this, p_item, parent )
444 {
445     psz_default_value = p_item->psz_value;
446     if( psz_default_value ) psz_default_value = strdup( psz_default_value );
447
448     label = new wxStaticText(this, -1, wxU(p_item->psz_text));
449     sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
450     combo = new wxComboBox( this, -1, wxT(""),
451                             wxDefaultPosition, wxDefaultSize,
452                             0, NULL, wxCB_READONLY );
453     UpdateCombo( p_item );
454
455     combo->SetToolTip( wxU(p_item->psz_longtext) );
456     sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
457
458     for( int i = 0; i < p_item->i_action; i++ )
459     {
460         wxButton *button =
461             new wxButton( this, wxID_HIGHEST+i,
462                           wxU(p_item->ppsz_action_text[i]) );
463         sizer->Add( button, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
464     }
465
466     sizer->Layout();
467     this->SetSizerAndFit( sizer );
468 }
469
470 StringListConfigControl::~StringListConfigControl()
471 {
472     if( psz_default_value ) free( psz_default_value );
473 }
474
475 void StringListConfigControl::UpdateCombo( module_config_t *p_item )
476 {
477     vlc_bool_t b_found = VLC_FALSE;
478     int i_index;
479
480     /* build a list of available options */
481     for( i_index = 0; i_index < p_item->i_list; i_index++ )
482     {
483         combo->Append( ( p_item->ppsz_list_text &&
484                          p_item->ppsz_list_text[i_index] ) ?
485                        wxU(p_item->ppsz_list_text[i_index]) :
486                        wxL2U(p_item->ppsz_list[i_index]) );
487         combo->SetClientData( i_index, (void *)p_item->ppsz_list[i_index] );
488         if( ( p_item->psz_value &&
489               !strcmp( p_item->psz_value, p_item->ppsz_list[i_index] ) ) ||
490              ( !p_item->psz_value && !*p_item->ppsz_list[i_index] ) )
491         {
492             combo->SetSelection( i_index );
493             combo->SetValue( ( p_item->ppsz_list_text &&
494                                p_item->ppsz_list_text[i_index] ) ?
495                              wxU(p_item->ppsz_list_text[i_index]) :
496                              wxL2U(p_item->ppsz_list[i_index]) );
497             b_found = VLC_TRUE;
498         }
499     }
500
501     if( p_item->psz_value && !b_found )
502     {
503         /* Add custom entry to list */
504         combo->Append( wxL2U(p_item->psz_value) );
505         combo->SetClientData( i_index, (void *)psz_default_value );
506         combo->SetSelection( i_index );
507         combo->SetValue( wxL2U(p_item->psz_value) );
508     }
509 }
510
511 BEGIN_EVENT_TABLE(StringListConfigControl, wxPanel)
512     /* Button events */
513     EVT_BUTTON(-1, StringListConfigControl::OnAction)
514
515     /* Text events */
516     EVT_TEXT(-1, StringListConfigControl::OnUpdate)
517 END_EVENT_TABLE()
518
519 void StringListConfigControl::OnAction( wxCommandEvent& event )
520 {
521     int i_action = event.GetId() - wxID_HIGHEST;
522
523     module_config_t *p_item = config_FindConfig( p_this, GetName().mb_str() );
524     if( !p_item ) return;
525
526     if( i_action < 0 || i_action >= p_item->i_action ) return;
527
528     vlc_value_t val;
529     wxString value = GetPszValue();
530     *((const char **)&val.psz_string) = value.mb_str();
531     p_item->ppf_action[i_action]( p_this, GetName().mb_str(), val, val, 0 );
532
533     if( p_item->b_dirty )
534     {
535         combo->Clear();
536         UpdateCombo( p_item );
537         p_item->b_dirty = VLC_FALSE;
538     }
539 }
540
541 wxString StringListConfigControl::GetPszValue()
542 {
543     int selected = combo->GetSelection();
544     if( selected != -1 )
545     {
546         return wxL2U((char *)combo->GetClientData( selected ));
547     }
548     return wxString();
549 }
550
551 /*****************************************************************************
552  * FileConfigControl implementation
553  *****************************************************************************/
554 FileConfigControl::FileConfigControl( vlc_object_t *p_this,
555                                       module_config_t *p_item,
556                                       wxWindow *parent )
557   : ConfigControl( p_this, p_item, parent )
558 {
559     directory = p_item->i_type == CONFIG_ITEM_DIRECTORY;
560     label = new wxStaticText(this, -1, wxU(p_item->psz_text));
561     sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
562     textctrl = new wxTextCtrl( this, -1,
563                                wxL2U(p_item->psz_value),
564                                wxDefaultPosition,
565                                wxDefaultSize,
566                                wxTE_PROCESS_ENTER);
567     textctrl->SetToolTip( wxU(p_item->psz_longtext) );
568     sizer->Add( textctrl, 1, wxALL, 5 );
569     browse = new wxButton( this, wxID_HIGHEST, wxU(_("Browse...")) );
570     sizer->Add( browse, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
571     sizer->Layout();
572     this->SetSizerAndFit( sizer );
573 }
574
575 BEGIN_EVENT_TABLE(FileConfigControl, wxPanel)
576     /* Button events */
577     EVT_BUTTON(wxID_HIGHEST, FileConfigControl::OnBrowse)
578 END_EVENT_TABLE()
579
580 void FileConfigControl::OnBrowse( wxCommandEvent& event )
581 {
582     if( directory )
583     {
584         wxDirDialog dialog( this, wxU(_("Choose directory")) );
585
586         if( dialog.ShowModal() == wxID_OK )
587         {
588             textctrl->SetValue( dialog.GetPath() );
589         }
590     }
591     else
592     {
593         wxFileDialog dialog( this, wxU(_("Choose file")),
594                              wxT(""), wxT(""), wxT("*.*"),
595 #if defined( __WXMSW__ )
596                              wxOPEN
597 #else
598                              wxOPEN | wxSAVE
599 #endif
600                            );
601         if( dialog.ShowModal() == wxID_OK )
602         {
603             textctrl->SetValue( dialog.GetPath() );
604         }
605     }
606 }
607
608 FileConfigControl::~FileConfigControl()
609 {
610     ;
611 }
612
613 wxString FileConfigControl::GetPszValue()
614 {
615     return textctrl->GetValue();
616 }
617
618 /*****************************************************************************
619  * IntegerConfigControl implementation
620  *****************************************************************************/
621 BEGIN_EVENT_TABLE(IntegerConfigControl, wxPanel)
622     EVT_TEXT(-1, IntegerConfigControl::OnUpdate)
623     EVT_COMMAND_SCROLL(-1, IntegerConfigControl::OnUpdate)
624 END_EVENT_TABLE()
625
626 IntegerConfigControl::IntegerConfigControl( vlc_object_t *p_this,
627                                             module_config_t *p_item,
628                                             wxWindow *parent )
629   : ConfigControl( p_this, p_item, parent )
630 {
631     label = new wxStaticText(this, -1, wxU(p_item->psz_text));
632     spin = new wxSpinCtrl( this, -1,
633                            wxString::Format(wxT("%d"),
634                                             p_item->i_value),
635                            wxDefaultPosition, wxDefaultSize,
636                            wxSP_ARROW_KEYS,
637                            -100000000, 100000000, p_item->i_value);
638     spin->SetToolTip( wxU(p_item->psz_longtext) );
639     sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
640     sizer->Add( spin, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
641     sizer->Layout();
642     this->SetSizerAndFit( sizer );
643     i_value = p_item->i_value;
644 }
645
646 IntegerConfigControl::~IntegerConfigControl()
647 {
648     ;
649 }
650
651 int IntegerConfigControl::GetIntValue()
652 {
653     /* We avoid using GetValue because of a recursion bug with wxSpinCtrl with
654      * wxGTK. */
655     return i_value; //spin->GetValue();
656 }
657
658 void IntegerConfigControl::OnUpdate( wxCommandEvent &event )
659 {
660     i_value = event.GetInt();
661     ConfigControl::OnUpdate( event );
662 }
663
664 /*****************************************************************************
665  * IntegerListConfigControl implementation
666  *****************************************************************************/
667 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *p_this,
668                                                     module_config_t *p_item,
669                                                     wxWindow *parent )
670   : ConfigControl( p_this, p_item, parent )
671 {
672     label = new wxStaticText(this, -1, wxU(p_item->psz_text));
673     sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
674     combo = new wxComboBox( this, -1, wxT(""),
675                             wxDefaultPosition, wxDefaultSize,
676                             0, NULL, wxCB_READONLY );
677
678     UpdateCombo( p_item );
679
680     combo->SetToolTip( wxU(p_item->psz_longtext) );
681     sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
682
683     sizer->Layout();
684     this->SetSizerAndFit( sizer );
685 }
686
687 IntegerListConfigControl::~IntegerListConfigControl()
688 {
689 }
690
691 void IntegerListConfigControl::UpdateCombo( module_config_t *p_item )
692 {
693     /* build a list of available options */
694     for( int i_index = 0; i_index < p_item->i_list; i_index++ )
695     {
696         if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
697         {
698             combo->Append( wxU(p_item->ppsz_list_text[i_index]) );
699         }
700         else
701         {
702             combo->Append( wxString::Format(wxT("%i"),
703                                             p_item->pi_list[i_index]) );
704         }
705         combo->SetClientData( i_index, (void *)p_item->pi_list[i_index] );
706         if( p_item->i_value == p_item->pi_list[i_index] )
707         {
708             combo->SetSelection( i_index );
709             if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
710             {
711                 combo->SetValue( wxU(p_item->ppsz_list_text[i_index]) );
712             }
713             else
714             {
715                 combo->SetValue( wxString::Format(wxT("%i"),
716                                                   p_item->pi_list[i_index]) );
717             }
718         }
719     }
720 }
721
722 BEGIN_EVENT_TABLE(IntegerListConfigControl, wxPanel)
723     /* Button events */
724     EVT_BUTTON(-1, IntegerListConfigControl::OnAction)
725 END_EVENT_TABLE()
726
727 void IntegerListConfigControl::OnAction( wxCommandEvent& event )
728 {
729     int i_action = event.GetId() - wxID_HIGHEST;
730
731     module_config_t *p_item;
732     p_item = config_FindConfig( p_this, GetName().mb_str() );
733     if( !p_item ) return;
734
735     if( i_action < 0 || i_action >= p_item->i_action ) return;
736
737     vlc_value_t val;
738     val.i_int = GetIntValue();
739     p_item->ppf_action[i_action]( p_this, GetName().mb_str(), val, val, 0 );
740
741     if( p_item->b_dirty )
742     {
743         combo->Clear();
744         UpdateCombo( p_item );
745         p_item->b_dirty = VLC_FALSE;
746     }
747 }
748
749 int IntegerListConfigControl::GetIntValue()
750 {
751     int selected = combo->GetSelection();
752     if( selected != -1 )
753     {
754         return (int)combo->GetClientData( selected );
755     }
756     return -1;
757 }
758
759 /*****************************************************************************
760  * RangedIntConfigControl implementation
761  *****************************************************************************/
762 BEGIN_EVENT_TABLE(RangedIntConfigControl, wxPanel)
763     EVT_COMMAND_SCROLL(-1, RangedIntConfigControl::OnUpdate)
764 END_EVENT_TABLE()
765
766 RangedIntConfigControl::RangedIntConfigControl( vlc_object_t *p_this,
767                                                 module_config_t *p_item,
768                                                 wxWindow *parent )
769   : ConfigControl( p_this, p_item, parent )
770 {
771     label = new wxStaticText(this, -1, wxU(p_item->psz_text));
772     slider = new wxSlider( this, -1, p_item->i_value, p_item->i_min,
773                            p_item->i_max, wxDefaultPosition, wxDefaultSize,
774                            wxSL_LABELS | wxSL_HORIZONTAL );
775     slider->SetToolTip( wxU(p_item->psz_longtext) );
776     sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
777     sizer->Add( slider, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
778     sizer->Layout();
779     this->SetSizerAndFit( sizer );
780 }
781
782 RangedIntConfigControl::~RangedIntConfigControl()
783 {
784     ;
785 }
786
787 int RangedIntConfigControl::GetIntValue()
788 {
789     return slider->GetValue();
790 }
791
792 /*****************************************************************************
793  * FloatConfigControl implementation
794  *****************************************************************************/
795 BEGIN_EVENT_TABLE(FloatConfigControl, wxPanel)
796     EVT_TEXT(-1, FloatConfigControl::OnUpdate)
797 END_EVENT_TABLE()
798
799 FloatConfigControl::FloatConfigControl( vlc_object_t *p_this,
800                                         module_config_t *p_item,
801                                         wxWindow *parent )
802   : ConfigControl( p_this, p_item, parent )
803 {
804     label = new wxStaticText(this, -1, wxU(p_item->psz_text));
805     textctrl = new wxTextCtrl( this, -1,
806                                wxString::Format(wxT("%f"),
807                                                 p_item->f_value),
808                                wxDefaultPosition, wxDefaultSize,
809                                wxTE_PROCESS_ENTER );
810     textctrl->SetToolTip( wxU(p_item->psz_longtext) );
811     sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
812     sizer->Add( textctrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
813     sizer->Layout();
814     this->SetSizerAndFit( sizer );
815 }
816
817 FloatConfigControl::~FloatConfigControl()
818 {
819     ;
820 }
821
822 float FloatConfigControl::GetFloatValue()
823 {
824     float f_value;
825     if( (wxSscanf(textctrl->GetValue(), wxT("%f"), &f_value) == 1) )
826         return f_value;
827     else return 0.0;
828 }
829
830 /*****************************************************************************
831  * BoolConfigControl implementation
832  *****************************************************************************/
833 BEGIN_EVENT_TABLE(BoolConfigControl, wxPanel)
834     EVT_CHECKBOX(-1, BoolConfigControl::OnUpdate)
835 END_EVENT_TABLE()
836
837 BoolConfigControl::BoolConfigControl( vlc_object_t *p_this,
838                                       module_config_t *p_item,
839                                       wxWindow *parent )
840   : ConfigControl( p_this, p_item, parent )
841 {
842     checkbox = new wxCheckBox( this, -1, wxU(p_item->psz_text) );
843     if( p_item->i_value ) checkbox->SetValue(TRUE);
844     checkbox->SetToolTip( wxU(p_item->psz_longtext) );
845     sizer->Add( checkbox, 0, wxALL, 5 );
846     sizer->Layout();
847     this->SetSizerAndFit( sizer );
848 }
849
850 BoolConfigControl::~BoolConfigControl()
851 {
852     ;
853 }
854
855 int BoolConfigControl::GetIntValue()
856 {
857     if( checkbox->IsChecked() ) return 1;
858     else return 0;
859 }
860
861 /*****************************************************************************
862  * SectionConfigControl implementation
863  *****************************************************************************/
864 SectionConfigControl::SectionConfigControl( vlc_object_t *p_this,
865                                             module_config_t *p_item,
866                                             wxWindow *parent )
867   : ConfigControl( p_this, p_item, parent )
868 {
869     delete sizer;
870     sizer = new wxBoxSizer( wxVERTICAL );
871     sizer->Add( new wxStaticText( this, -1, wxU( p_item->psz_text ) ) );
872     sizer->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND, 5 );
873     sizer->Layout();
874     this->SetSizerAndFit( sizer );
875 }
876
877 SectionConfigControl::~SectionConfigControl()
878 {
879     ;
880 }