1 /*****************************************************************************
2 * preferences_widgets.cpp : WinCE gui plugin for VLC
3 *****************************************************************************
4 * Copyright (C) 2000-2004 the VideoLAN team
7 * Authors: Marodon Cedric <cedric_marodon@yahoo.fr>
8 * Gildas Bazin <gbazin@videolan.org>
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <string.h> /* strerror() */
31 #include <vlc_interface.h>
40 #include "preferences_widgets.h"
42 /*****************************************************************************
43 * CreateConfigControl wrapper
44 *****************************************************************************/
45 ConfigControl *CreateConfigControl( vlc_object_t *p_this,
46 module_config_t *p_item,
47 HWND parent, HINSTANCE hInst,
50 ConfigControl *p_control = NULL;
52 if( p_item->psz_current )
56 switch( p_item->i_type )
58 case CONFIG_ITEM_MODULE:
59 p_control = new ModuleConfigControl( p_this, p_item, parent, hInst, py_pos );
62 case CONFIG_ITEM_STRING:
65 p_control = new StringConfigControl( p_this, p_item, parent, hInst, py_pos );
69 p_control = new StringListConfigControl( p_this, p_item, parent, hInst, py_pos );
73 case CONFIG_ITEM_FILE:
74 case CONFIG_ITEM_DIRECTORY:
75 p_control = new FileConfigControl( p_this, p_item, parent, hInst, py_pos );
78 case CONFIG_ITEM_INTEGER:
81 p_control = new IntegerListConfigControl( p_this, p_item, parent, hInst, py_pos );
83 else if( p_item->i_min != 0 || p_item->i_max != 0 )
85 p_control = new RangedIntConfigControl( p_this, p_item, parent, hInst, py_pos );
89 p_control = new IntegerConfigControl( p_this, p_item, parent, hInst, py_pos );
94 p_control = new KeyConfigControl( p_this, p_item, parent, hInst, py_pos );
97 case CONFIG_ITEM_FLOAT:
98 p_control = new FloatConfigControl( p_this, p_item, parent, hInst, py_pos );
101 case CONFIG_ITEM_BOOL:
102 p_control = new BoolConfigControl( p_this, p_item, parent, hInst, py_pos );
112 /*****************************************************************************
113 * ConfigControl implementation
114 *****************************************************************************/
115 ConfigControl::ConfigControl( vlc_object_t *_p_this,
116 module_config_t *p_item,
117 HWND parent, HINSTANCE hInst )
118 : p_this( _p_this ), pf_update_callback( NULL ), p_update_data( NULL ),
119 parent( parent ), name( p_item->psz_name ), i_type( p_item->i_type ),
120 b_advanced( p_item->b_advanced )
123 /*sizer = new wxBoxSizer( wxHORIZONTAL );*/
126 ConfigControl::~ConfigControl()
130 /*wxSizer *ConfigControl::Sizer()
135 char *ConfigControl::GetName()
140 int ConfigControl::GetType()
145 vlc_bool_t ConfigControl::IsAdvanced()
150 void ConfigControl::SetUpdateCallback( void (*p_callback)( void * ),
153 pf_update_callback = p_callback;
154 p_update_data = p_data;
157 void ConfigControl::OnUpdate( UINT event )
159 if( pf_update_callback )
161 pf_update_callback( p_update_data );
165 /*****************************************************************************
166 * KeyConfigControl implementation
167 *****************************************************************************/
168 string *KeyConfigControl::m_keysList = NULL;
170 KeyConfigControl::KeyConfigControl( vlc_object_t *p_this,
171 module_config_t *p_item,
172 HWND parent, HINSTANCE hInst,
174 : ConfigControl( p_this, p_item, parent, hInst )
176 // Number of keys descriptions
177 unsigned int i_keys = sizeof(vlc_keys)/sizeof(key_descriptor_t);
179 // Init the keys decriptions array
180 if( m_keysList == NULL )
182 m_keysList = new string[i_keys];
183 for( unsigned int i = 0; i < i_keys; i++ )
185 m_keysList[i] = vlc_keys[i].psz_key_string;
189 label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
190 WS_CHILD | WS_VISIBLE | SS_LEFT, 5, *py_pos, 200, 15,
191 parent, NULL, hInst, NULL );
195 alt = CreateWindow( _T("BUTTON"), _T("Alt"),
196 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
197 20, *py_pos, 15, 15, parent, NULL, hInst, NULL );
198 Button_SetCheck( alt, p_item->i_value & KEY_MODIFIER_ALT ? BST_CHECKED :
201 alt_label = CreateWindow( _T("STATIC"), _T("Alt"),
202 WS_CHILD | WS_VISIBLE | SS_LEFT, 20 + 15 + 5, *py_pos, 30, 15,
203 parent, NULL, hInst, NULL );
205 ctrl = CreateWindow( _T("BUTTON"), _T("Ctrl"),
206 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
207 20 + 15 + 5 + 30 + 5, *py_pos, 15, 15,
208 parent, NULL, hInst, NULL );
209 Button_SetCheck( ctrl, p_item->i_value & KEY_MODIFIER_CTRL ? BST_CHECKED :
212 ctrl_label = CreateWindow( _T("STATIC"), _T("Ctrl"),
213 WS_CHILD | WS_VISIBLE | SS_LEFT,
214 20 + 15 + 5 + 30 + 5 + 15 + 5, *py_pos, 30, 15,
215 parent, NULL, hInst, NULL );
217 shift = CreateWindow( _T("BUTTON"), _T("Shift"),
218 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
219 20 + 15 + 5 + 2*(30 + 5) + 15 + 5, *py_pos, 15, 15,
220 parent, NULL, hInst, NULL );
221 Button_SetCheck( shift, p_item->i_value & KEY_MODIFIER_SHIFT ?
222 BST_CHECKED : BST_UNCHECKED );
224 shift_label = CreateWindow( _T("STATIC"), _T("Shift"),
225 WS_CHILD | WS_VISIBLE | SS_LEFT,
226 20 + 15 + 5 + 2*(30 + 5) + 2*(15 + 5), *py_pos, 30, 15,
227 parent, NULL, hInst, NULL );
231 combo = CreateWindow( _T("COMBOBOX"), _T(""),
232 WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_DROPDOWNLIST |
233 CBS_SORT | WS_VSCROLL, 20, *py_pos, 130, 5*15 + 6,
234 parent, NULL, hInst, NULL );
238 for( unsigned int i = 0; i < i_keys ; i++ )
240 ComboBox_AddString( combo, _FROMMB(m_keysList[i].c_str()) );
241 ComboBox_SetItemData( combo, i, (void*)vlc_keys[i].i_key_code );
242 if( (unsigned int)vlc_keys[i].i_key_code ==
243 ( ((unsigned int)p_item->i_value) & ~KEY_MODIFIER ) )
245 ComboBox_SetCurSel( combo, i );
246 ComboBox_SetText( combo, _FROMMB(m_keysList[i].c_str()) );
251 KeyConfigControl::~KeyConfigControl()
260 int KeyConfigControl::GetIntValue()
263 if( Button_GetCheck( alt ) )
265 result |= KEY_MODIFIER_ALT;
267 if( Button_GetCheck( ctrl ) )
269 result |= KEY_MODIFIER_CTRL;
271 if( Button_GetCheck( shift ) )
273 result |= KEY_MODIFIER_SHIFT;
275 int selected = ComboBox_GetCurSel( combo );
278 result |= (int)ComboBox_GetItemData( combo, selected );
283 /*****************************************************************************
284 * ModuleConfigControl implementation
285 *****************************************************************************/
286 ModuleConfigControl::ModuleConfigControl( vlc_object_t *p_this,
287 module_config_t *p_item,
288 HWND parent, HINSTANCE hInst,
290 : ConfigControl( p_this, p_item, parent, hInst )
295 label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
296 WS_CHILD | WS_VISIBLE | SS_LEFT,
298 parent, NULL, hInst, NULL );
302 combo = CreateWindow( _T("COMBOBOX"), _T(""),
303 WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL |
304 CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL,
305 20, *py_pos, 180, 5*15 + 6,
306 parent, NULL, hInst, NULL);
310 /* build a list of available modules */
311 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
312 ComboBox_AddString( combo, _T("Default") );
313 ComboBox_SetItemData( combo, 0, (void *)NULL );
314 ComboBox_SetCurSel( combo, 0 );
315 //ComboBox_SetText( combo, _T("Default") );
316 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
318 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
320 if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
322 ComboBox_AddString( combo, _FROMMB(p_parser->psz_longname) );
323 ComboBox_SetItemData( combo, i_index,
324 (void*)p_parser->psz_object_name );
325 if( p_item->psz_value && !strcmp(p_item->psz_value,
326 p_parser->psz_object_name) )
328 ComboBox_SetCurSel( combo, i_index );
329 //ComboBox_SetText( combo, _FROMMB(p_parser->psz_longname) );
333 vlc_list_release( p_list );
336 ModuleConfigControl::~ModuleConfigControl()
341 char *ModuleConfigControl::GetPszValue()
343 int selected = ComboBox_GetCurSel( combo );
345 return (char *)ComboBox_GetItemData( combo, selected );
349 /*****************************************************************************
350 * StringConfigControl implementation
351 *****************************************************************************/
352 StringConfigControl::StringConfigControl( vlc_object_t *p_this,
353 module_config_t *p_item,
354 HWND parent, HINSTANCE hInst,
356 : ConfigControl( p_this, p_item, parent, hInst )
358 label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
359 WS_CHILD | WS_VISIBLE | SS_LEFT,
361 parent, NULL, hInst, NULL );
365 textctrl = CreateWindow( _T("EDIT"), p_item->psz_value ?
366 _FROMMB(p_item->psz_value) : _T(""),
367 WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT |
368 ES_AUTOHSCROLL, 20, *py_pos - 3, 180, 15 + 3,
369 parent, NULL, hInst, NULL );
374 StringConfigControl::~StringConfigControl()
379 char *StringConfigControl::GetPszValue()
385 i_size = Edit_GetTextLength( textctrl );
386 psz_string = (TCHAR *)malloc( (i_size + 1) * sizeof(TCHAR) );
387 Edit_GetText( textctrl, psz_string, i_size + 1 );
388 psz_result = strdup( _TOMB(psz_string) );
394 /*****************************************************************************
395 * StringListConfigControl implementation
396 *****************************************************************************/
397 StringListConfigControl::StringListConfigControl( vlc_object_t *p_this,
398 module_config_t *p_item,
399 HWND parent, HINSTANCE hInst,
401 : ConfigControl( p_this, p_item, parent, hInst )
403 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
404 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
405 combo = new wxComboBox( this, -1, wxT(""),
406 wxDefaultPosition, wxDefaultSize,
407 0, NULL, wxCB_READONLY );
408 UpdateCombo( p_item );
410 combo->SetToolTip( wxU(p_item->psz_longtext) );
411 sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
413 for( int i = 0; i < p_item->i_action; i++ )
416 new wxButton( this, wxID_HIGHEST+i,
417 wxU(p_item->ppsz_action_text[i]) );
418 sizer->Add( button, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
422 this->SetSizerAndFit( sizer );
425 StringListConfigControl::~StringListConfigControl()
429 void StringListConfigControl::UpdateCombo( module_config_t *p_item )
431 /* build a list of available options */
432 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
434 combo->Append( ( p_item->ppsz_list_text &&
435 p_item->ppsz_list_text[i_index] ) ?
436 wxU(p_item->ppsz_list_text[i_index]) :
437 wxL2U(p_item->ppsz_list[i_index]) );
438 combo->SetClientData( i_index, (void *)p_item->ppsz_list[i_index] );
439 if( ( p_item->psz_value &&
440 !strcmp( p_item->psz_value, p_item->ppsz_list[i_index] ) ) ||
441 ( !p_item->psz_value && !*p_item->ppsz_list[i_index] ) )
443 combo->SetSelection( i_index );
444 combo->SetValue( ( p_item->ppsz_list_text &&
445 p_item->ppsz_list_text[i_index] ) ?
446 wxU(p_item->ppsz_list_text[i_index]) :
447 wxL2U(p_item->ppsz_list[i_index]) );
452 BEGIN_EVENT_TABLE(StringListConfigControl, wxPanel)
454 EVT_BUTTON(-1, StringListConfigControl::OnAction)
457 EVT__T(-1, StringListConfigControl::OnUpdate)
460 void StringListConfigControl::OnAction( wxCommandEvent& event )
462 int i_action = event.GetId() - wxID_HIGHEST;
464 module_config_t *p_item = config_FindConfig( p_this, GetName().mb_str() );
465 if( !p_item ) return;
467 if( i_action < 0 || i_action >= p_item->i_action ) return;
470 wxString value = GetPszValue();
471 (const char *)val.psz_string = value.mb_str();
472 p_item->ppf_action[i_action]( p_this, GetName().mb_str(), val, val, 0 );
474 if( p_item->b_dirty )
477 UpdateCombo( p_item );
478 p_item->b_dirty = VLC_FALSE;
482 wxString StringListConfigControl::GetPszValue()
484 int selected = combo->GetSelection();
487 return wxL2U((char *)combo->GetClientData( selected ));
492 /*****************************************************************************
493 * FileConfigControl implementation
494 *****************************************************************************/
495 FileConfigControl::FileConfigControl( vlc_object_t *p_this,
496 module_config_t *p_item,
497 HWND parent, HINSTANCE hInst,
499 : ConfigControl( p_this, p_item, parent, hInst )
501 directory = p_item->i_type == CONFIG_ITEM_DIRECTORY;
502 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
503 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
504 textctrl = new wxTextCtrl( this, -1,
505 wxL2U(p_item->psz_value),
509 textctrl->SetToolTip( wxU(p_item->psz_longtext) );
510 sizer->Add( textctrl, 1, wxALL, 5 );
511 browse = new wxButton( this, wxID_HIGHEST, wxU(_("Browse...")) );
512 sizer->Add( browse, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
514 this->SetSizerAndFit( sizer );
517 BEGIN_EVENT_TABLE(FileConfigControl, wxPanel)
519 EVT_BUTTON(wxID_HIGHEST, FileConfigControl::OnBrowse)
522 void FileConfigControl::OnBrowse( wxCommandEvent& event )
526 wxDirDialog dialog( this, wxU(_("Choose directory")) );
528 if( dialog.ShowModal() == wxID_OK )
530 textctrl->SetValue( dialog.GetPath() );
535 wxFileDialog dialog( this, wxU(_("Choose file")),
536 wxT(""), wxT(""), wxT("*.*"),
537 #if defined( __WXMSW__ )
543 if( dialog.ShowModal() == wxID_OK )
545 textctrl->SetValue( dialog.GetPath() );
550 FileConfigControl::~FileConfigControl()
555 wxString FileConfigControl::GetPszValue()
557 return textctrl->GetValue();
560 /*****************************************************************************
561 * IntegerConfigControl implementation
562 *****************************************************************************/
563 IntegerConfigControl::IntegerConfigControl( vlc_object_t *p_this,
564 module_config_t *p_item,
565 HWND parent, HINSTANCE hInst,
567 : ConfigControl( p_this, p_item, parent, hInst )
569 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
570 spin = new wxSpinCtrl( this, -1,
571 wxString::Format(wxT("%d"),
573 wxDefaultPosition, wxDefaultSize,
575 -10000000, 10000000, p_item->i_value);
576 spin->SetToolTip( wxU(p_item->psz_longtext) );
577 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
578 sizer->Add( spin, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
580 this->SetSizerAndFit( sizer );
583 IntegerConfigControl::~IntegerConfigControl()
588 int IntegerConfigControl::GetIntValue()
590 return spin->GetValue();
593 /*****************************************************************************
594 * IntegerListConfigControl implementation
595 *****************************************************************************/
596 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *p_this,
597 module_config_t *p_item,
601 : ConfigControl( p_this, p_item, parent, hInst )
603 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
604 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
605 combo = new wxComboBox( this, -1, wxT(""),
606 wxDefaultPosition, wxDefaultSize,
607 0, NULL, wxCB_READONLY );
609 UpdateCombo( p_item );
611 combo->SetToolTip( wxU(p_item->psz_longtext) );
612 sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
615 this->SetSizerAndFit( sizer );
618 IntegerListConfigControl::~IntegerListConfigControl()
622 void IntegerListConfigControl::UpdateCombo( module_config_t *p_item )
624 /* build a list of available options */
625 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
627 if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
629 combo->Append( wxU(p_item->ppsz_list_text[i_index]) );
633 combo->Append( wxString::Format(wxT("%i"),
634 p_item->pi_list[i_index]) );
636 combo->SetClientData( i_index, (void *)p_item->pi_list[i_index] );
637 if( p_item->i_value == p_item->pi_list[i_index] )
639 combo->SetSelection( i_index );
640 if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
642 combo->SetValue( wxU(p_item->ppsz_list_text[i_index]) );
646 combo->SetValue( wxString::Format(wxT("%i"),
647 p_item->pi_list[i_index]) );
653 BEGIN_EVENT_TABLE(IntegerListConfigControl, wxPanel)
655 EVT_BUTTON(-1, IntegerListConfigControl::OnAction)
658 void IntegerListConfigControl::OnAction( wxCommandEvent& event )
660 int i_action = event.GetId() - wxID_HIGHEST;
662 module_config_t *p_item;
663 p_item = config_FindConfig( p_this, GetName().mb_str() );
664 if( !p_item ) return;
666 if( i_action < 0 || i_action >= p_item->i_action ) return;
669 val.i_int = GetIntValue();
670 p_item->ppf_action[i_action]( p_this, GetName().mb_str(), val, val, 0 );
672 if( p_item->b_dirty )
675 UpdateCombo( p_item );
676 p_item->b_dirty = VLC_FALSE;
680 int IntegerListConfigControl::GetIntValue()
682 int selected = combo->GetSelection();
685 return (int)combo->GetClientData( selected );
690 /*****************************************************************************
691 * RangedIntConfigControl implementation
692 *****************************************************************************/
693 RangedIntConfigControl::RangedIntConfigControl( vlc_object_t *p_this,
694 module_config_t *p_item,
695 HWND parent, HINSTANCE hInst,
697 : ConfigControl( p_this, p_item, parent, hInst )
699 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
700 slider = new wxSlider( this, -1, p_item->i_value, p_item->i_min,
701 p_item->i_max, wxDefaultPosition, wxDefaultSize,
702 wxSL_LABELS | wxSL_HORIZONTAL );
703 slider->SetToolTip( wxU(p_item->psz_longtext) );
704 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
705 sizer->Add( slider, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
707 this->SetSizerAndFit( sizer );
710 RangedIntConfigControl::~RangedIntConfigControl()
715 int RangedIntConfigControl::GetIntValue()
717 return slider->GetValue();
721 /*****************************************************************************
722 * FloatConfigControl implementation
723 *****************************************************************************/
724 FloatConfigControl::FloatConfigControl( vlc_object_t *p_this,
725 module_config_t *p_item,
726 HWND parent, HINSTANCE hInst,
728 : ConfigControl( p_this, p_item, parent, hInst )
730 label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
731 WS_CHILD | WS_VISIBLE | SS_LEFT,
733 parent, NULL, hInst, NULL );
737 TCHAR psz_string[100];
738 _stprintf( psz_string, _T("%f"), p_item->f_value );
739 textctrl = CreateWindow( _T("EDIT"), psz_string,
740 WS_CHILD | WS_VISIBLE | WS_BORDER | SS_RIGHT | ES_AUTOHSCROLL,
741 20, *py_pos - 3, 70, 15 + 3, parent, NULL, hInst, NULL );
746 FloatConfigControl::~FloatConfigControl()
751 float FloatConfigControl::GetFloatValue()
755 int i_size = Edit_GetTextLength( textctrl );
756 TCHAR *psz_string = (TCHAR *)malloc( (i_size + 1) * sizeof(TCHAR) );
757 Edit_GetText( textctrl, psz_string, i_size + 1 );
759 if( _tscanf( psz_string, _T("%f"), &f_value ) == 1 )
769 /*****************************************************************************
770 * BoolConfigControl implementation
771 *****************************************************************************/
772 BoolConfigControl::BoolConfigControl( vlc_object_t *p_this,
773 module_config_t *p_item, HWND parent,
774 HINSTANCE hInst, int * py_pos )
775 : ConfigControl( p_this, p_item, parent, hInst )
777 checkbox = CreateWindow( _T("BUTTON"), _T(""),
778 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
780 parent, NULL, hInst, NULL );
781 Button_SetCheck( checkbox, p_item->i_value ? BST_CHECKED : BST_UNCHECKED );
783 checkbox_label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
784 WS_CHILD | WS_VISIBLE | SS_LEFT,
785 5 + 15 + 5, *py_pos, 180, 15,
786 parent, NULL, hInst, NULL );
791 BoolConfigControl::~BoolConfigControl()
796 int BoolConfigControl::GetIntValue()
798 if( Button_GetCheck( checkbox ) ) return 1;