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 *****************************************************************************/
29 #include <vlc_interface.h>
38 #include "preferences_widgets.h"
40 /*****************************************************************************
41 * CreateConfigControl wrapper
42 *****************************************************************************/
43 ConfigControl *CreateConfigControl( vlc_object_t *p_this,
44 module_config_t *p_item,
45 HWND parent, HINSTANCE hInst,
48 ConfigControl *p_control = NULL;
50 switch( p_item->i_type )
52 case CONFIG_ITEM_MODULE:
53 p_control = new ModuleConfigControl( p_this, p_item, parent, hInst, py_pos );
56 case CONFIG_ITEM_STRING:
59 p_control = new StringConfigControl( p_this, p_item, parent, hInst, py_pos );
63 p_control = new StringListConfigControl( p_this, p_item, parent, hInst, py_pos );
67 case CONFIG_ITEM_FILE:
68 case CONFIG_ITEM_DIRECTORY:
69 p_control = new FileConfigControl( p_this, p_item, parent, hInst, py_pos );
72 case CONFIG_ITEM_INTEGER:
75 p_control = new IntegerListConfigControl( p_this, p_item, parent, hInst, py_pos );
77 else if( p_item->i_min != 0 || p_item->i_max != 0 )
79 p_control = new RangedIntConfigControl( p_this, p_item, parent, hInst, py_pos );
83 p_control = new IntegerConfigControl( p_this, p_item, parent, hInst, py_pos );
88 p_control = new KeyConfigControl( p_this, p_item, parent, hInst, py_pos );
91 case CONFIG_ITEM_FLOAT:
92 p_control = new FloatConfigControl( p_this, p_item, parent, hInst, py_pos );
95 case CONFIG_ITEM_BOOL:
96 p_control = new BoolConfigControl( p_this, p_item, parent, hInst, py_pos );
106 /*****************************************************************************
107 * ConfigControl implementation
108 *****************************************************************************/
109 ConfigControl::ConfigControl( vlc_object_t *_p_this,
110 module_config_t *p_item,
111 HWND parent, HINSTANCE hInst )
112 : p_this( _p_this ), pf_update_callback( NULL ), p_update_data( NULL ),
113 parent( parent ), name( p_item->psz_name ), i_type( p_item->i_type ),
114 b_advanced( p_item->b_advanced )
117 /*sizer = new wxBoxSizer( wxHORIZONTAL );*/
120 ConfigControl::~ConfigControl()
124 /*wxSizer *ConfigControl::Sizer()
129 char *ConfigControl::GetName()
134 int ConfigControl::GetType()
139 vlc_bool_t ConfigControl::IsAdvanced()
144 void ConfigControl::SetUpdateCallback( void (*p_callback)( void * ),
147 pf_update_callback = p_callback;
148 p_update_data = p_data;
151 void ConfigControl::OnUpdate( UINT event )
153 if( pf_update_callback )
155 pf_update_callback( p_update_data );
159 /*****************************************************************************
160 * KeyConfigControl implementation
161 *****************************************************************************/
162 string *KeyConfigControl::m_keysList = NULL;
164 KeyConfigControl::KeyConfigControl( vlc_object_t *p_this,
165 module_config_t *p_item,
166 HWND parent, HINSTANCE hInst,
168 : ConfigControl( p_this, p_item, parent, hInst )
170 // Number of keys descriptions
171 unsigned int i_keys = sizeof(vlc_keys)/sizeof(key_descriptor_t);
173 // Init the keys decriptions array
174 if( m_keysList == NULL )
176 m_keysList = new string[i_keys];
177 for( unsigned int i = 0; i < i_keys; i++ )
179 m_keysList[i] = vlc_keys[i].psz_key_string;
183 label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
184 WS_CHILD | WS_VISIBLE | SS_LEFT, 5, *py_pos, 200, 15,
185 parent, NULL, hInst, NULL );
189 alt = CreateWindow( _T("BUTTON"), _T("Alt"),
190 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
191 20, *py_pos, 15, 15, parent, NULL, hInst, NULL );
192 Button_SetCheck( alt, p_item->i_value & KEY_MODIFIER_ALT ? BST_CHECKED :
195 alt_label = CreateWindow( _T("STATIC"), _T("Alt"),
196 WS_CHILD | WS_VISIBLE | SS_LEFT, 20 + 15 + 5, *py_pos, 30, 15,
197 parent, NULL, hInst, NULL );
199 ctrl = CreateWindow( _T("BUTTON"), _T("Ctrl"),
200 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
201 20 + 15 + 5 + 30 + 5, *py_pos, 15, 15,
202 parent, NULL, hInst, NULL );
203 Button_SetCheck( ctrl, p_item->i_value & KEY_MODIFIER_CTRL ? BST_CHECKED :
206 ctrl_label = CreateWindow( _T("STATIC"), _T("Ctrl"),
207 WS_CHILD | WS_VISIBLE | SS_LEFT,
208 20 + 15 + 5 + 30 + 5 + 15 + 5, *py_pos, 30, 15,
209 parent, NULL, hInst, NULL );
211 shift = CreateWindow( _T("BUTTON"), _T("Shift"),
212 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
213 20 + 15 + 5 + 2*(30 + 5) + 15 + 5, *py_pos, 15, 15,
214 parent, NULL, hInst, NULL );
215 Button_SetCheck( shift, p_item->i_value & KEY_MODIFIER_SHIFT ?
216 BST_CHECKED : BST_UNCHECKED );
218 shift_label = CreateWindow( _T("STATIC"), _T("Shift"),
219 WS_CHILD | WS_VISIBLE | SS_LEFT,
220 20 + 15 + 5 + 2*(30 + 5) + 2*(15 + 5), *py_pos, 30, 15,
221 parent, NULL, hInst, NULL );
225 combo = CreateWindow( _T("COMBOBOX"), _T(""),
226 WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_DROPDOWNLIST |
227 CBS_SORT | WS_VSCROLL, 20, *py_pos, 130, 5*15 + 6,
228 parent, NULL, hInst, NULL );
232 for( unsigned int i = 0; i < i_keys ; i++ )
234 ComboBox_AddString( combo, _FROMMB(m_keysList[i].c_str()) );
235 ComboBox_SetItemData( combo, i, (void*)vlc_keys[i].i_key_code );
236 if( (unsigned int)vlc_keys[i].i_key_code ==
237 ( ((unsigned int)p_item->i_value) & ~KEY_MODIFIER ) )
239 ComboBox_SetCurSel( combo, i );
240 ComboBox_SetText( combo, _FROMMB(m_keysList[i].c_str()) );
245 KeyConfigControl::~KeyConfigControl()
254 int KeyConfigControl::GetIntValue()
257 if( Button_GetCheck( alt ) )
259 result |= KEY_MODIFIER_ALT;
261 if( Button_GetCheck( ctrl ) )
263 result |= KEY_MODIFIER_CTRL;
265 if( Button_GetCheck( shift ) )
267 result |= KEY_MODIFIER_SHIFT;
269 int selected = ComboBox_GetCurSel( combo );
272 result |= (int)ComboBox_GetItemData( combo, selected );
277 /*****************************************************************************
278 * ModuleConfigControl implementation
279 *****************************************************************************/
280 ModuleConfigControl::ModuleConfigControl( vlc_object_t *p_this,
281 module_config_t *p_item,
282 HWND parent, HINSTANCE hInst,
284 : ConfigControl( p_this, p_item, parent, hInst )
289 label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
290 WS_CHILD | WS_VISIBLE | SS_LEFT,
292 parent, NULL, hInst, NULL );
296 combo = CreateWindow( _T("COMBOBOX"), _T(""),
297 WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL |
298 CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL,
299 20, *py_pos, 180, 5*15 + 6,
300 parent, NULL, hInst, NULL);
304 /* build a list of available modules */
305 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
306 ComboBox_AddString( combo, _T("Default") );
307 ComboBox_SetItemData( combo, 0, (void *)NULL );
308 ComboBox_SetCurSel( combo, 0 );
309 //ComboBox_SetText( combo, _T("Default") );
310 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
312 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
314 if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
316 ComboBox_AddString( combo, _FROMMB(p_parser->psz_longname) );
317 ComboBox_SetItemData( combo, i_index,
318 (void*)p_parser->psz_object_name );
319 if( p_item->psz_value && !strcmp(p_item->psz_value,
320 p_parser->psz_object_name) )
322 ComboBox_SetCurSel( combo, i_index );
323 //ComboBox_SetText( combo, _FROMMB(p_parser->psz_longname) );
327 vlc_list_release( p_list );
330 ModuleConfigControl::~ModuleConfigControl()
335 char *ModuleConfigControl::GetPszValue()
337 int selected = ComboBox_GetCurSel( combo );
339 return (char *)ComboBox_GetItemData( combo, selected );
343 /*****************************************************************************
344 * StringConfigControl implementation
345 *****************************************************************************/
346 StringConfigControl::StringConfigControl( vlc_object_t *p_this,
347 module_config_t *p_item,
348 HWND parent, HINSTANCE hInst,
350 : ConfigControl( p_this, p_item, parent, hInst )
352 label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
353 WS_CHILD | WS_VISIBLE | SS_LEFT,
355 parent, NULL, hInst, NULL );
359 textctrl = CreateWindow( _T("EDIT"), p_item->psz_value ?
360 _FROMMB(p_item->psz_value) : _T(""),
361 WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT |
362 ES_AUTOHSCROLL, 20, *py_pos - 3, 180, 15 + 3,
363 parent, NULL, hInst, NULL );
368 StringConfigControl::~StringConfigControl()
373 char *StringConfigControl::GetPszValue()
379 i_size = Edit_GetTextLength( textctrl );
380 psz_string = (TCHAR *)malloc( (i_size + 1) * sizeof(TCHAR) );
381 Edit_GetText( textctrl, psz_string, i_size + 1 );
382 psz_result = strdup( _TOMB(psz_string) );
388 /*****************************************************************************
389 * StringListConfigControl implementation
390 *****************************************************************************/
391 StringListConfigControl::StringListConfigControl( vlc_object_t *p_this,
392 module_config_t *p_item,
393 HWND parent, HINSTANCE hInst,
395 : ConfigControl( p_this, p_item, parent, hInst )
397 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
398 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
399 combo = new wxComboBox( this, -1, wxT(""),
400 wxDefaultPosition, wxDefaultSize,
401 0, NULL, wxCB_READONLY );
402 UpdateCombo( p_item );
404 combo->SetToolTip( wxU(p_item->psz_longtext) );
405 sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
407 for( int i = 0; i < p_item->i_action; i++ )
410 new wxButton( this, wxID_HIGHEST+i,
411 wxU(p_item->ppsz_action_text[i]) );
412 sizer->Add( button, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
416 this->SetSizerAndFit( sizer );
419 StringListConfigControl::~StringListConfigControl()
423 void StringListConfigControl::UpdateCombo( module_config_t *p_item )
425 /* build a list of available options */
426 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
428 combo->Append( ( p_item->ppsz_list_text &&
429 p_item->ppsz_list_text[i_index] ) ?
430 wxU(p_item->ppsz_list_text[i_index]) :
431 wxL2U(p_item->ppsz_list[i_index]) );
432 combo->SetClientData( i_index, (void *)p_item->ppsz_list[i_index] );
433 if( ( p_item->psz_value &&
434 !strcmp( p_item->psz_value, p_item->ppsz_list[i_index] ) ) ||
435 ( !p_item->psz_value && !*p_item->ppsz_list[i_index] ) )
437 combo->SetSelection( i_index );
438 combo->SetValue( ( p_item->ppsz_list_text &&
439 p_item->ppsz_list_text[i_index] ) ?
440 wxU(p_item->ppsz_list_text[i_index]) :
441 wxL2U(p_item->ppsz_list[i_index]) );
446 BEGIN_EVENT_TABLE(StringListConfigControl, wxPanel)
448 EVT_BUTTON(-1, StringListConfigControl::OnAction)
451 EVT__T(-1, StringListConfigControl::OnUpdate)
454 void StringListConfigControl::OnAction( wxCommandEvent& event )
456 int i_action = event.GetId() - wxID_HIGHEST;
458 module_config_t *p_item = config_FindConfig( p_this, GetName().mb_str() );
459 if( !p_item ) return;
461 if( i_action < 0 || i_action >= p_item->i_action ) return;
464 wxString value = GetPszValue();
465 (const char *)val.psz_string = value.mb_str();
466 p_item->ppf_action[i_action]( p_this, GetName().mb_str(), val, val, 0 );
468 if( p_item->b_dirty )
471 UpdateCombo( p_item );
472 p_item->b_dirty = VLC_FALSE;
476 wxString StringListConfigControl::GetPszValue()
478 int selected = combo->GetSelection();
481 return wxL2U((char *)combo->GetClientData( selected ));
486 /*****************************************************************************
487 * FileConfigControl implementation
488 *****************************************************************************/
489 FileConfigControl::FileConfigControl( vlc_object_t *p_this,
490 module_config_t *p_item,
491 HWND parent, HINSTANCE hInst,
493 : ConfigControl( p_this, p_item, parent, hInst )
495 directory = p_item->i_type == CONFIG_ITEM_DIRECTORY;
496 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
497 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
498 textctrl = new wxTextCtrl( this, -1,
499 wxL2U(p_item->psz_value),
503 textctrl->SetToolTip( wxU(p_item->psz_longtext) );
504 sizer->Add( textctrl, 1, wxALL, 5 );
505 browse = new wxButton( this, wxID_HIGHEST, wxU(_("Browse...")) );
506 sizer->Add( browse, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
508 this->SetSizerAndFit( sizer );
511 BEGIN_EVENT_TABLE(FileConfigControl, wxPanel)
513 EVT_BUTTON(wxID_HIGHEST, FileConfigControl::OnBrowse)
516 void FileConfigControl::OnBrowse( wxCommandEvent& event )
520 wxDirDialog dialog( this, wxU(_("Choose directory")) );
522 if( dialog.ShowModal() == wxID_OK )
524 textctrl->SetValue( dialog.GetPath() );
529 wxFileDialog dialog( this, wxU(_("Choose file")),
530 wxT(""), wxT(""), wxT("*.*"),
531 #if defined( __WXMSW__ )
537 if( dialog.ShowModal() == wxID_OK )
539 textctrl->SetValue( dialog.GetPath() );
544 FileConfigControl::~FileConfigControl()
549 wxString FileConfigControl::GetPszValue()
551 return textctrl->GetValue();
554 /*****************************************************************************
555 * IntegerConfigControl implementation
556 *****************************************************************************/
557 IntegerConfigControl::IntegerConfigControl( vlc_object_t *p_this,
558 module_config_t *p_item,
559 HWND parent, HINSTANCE hInst,
561 : ConfigControl( p_this, p_item, parent, hInst )
563 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
564 spin = new wxSpinCtrl( this, -1,
565 wxString::Format(wxT("%d"),
567 wxDefaultPosition, wxDefaultSize,
569 -10000000, 10000000, p_item->i_value);
570 spin->SetToolTip( wxU(p_item->psz_longtext) );
571 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
572 sizer->Add( spin, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
574 this->SetSizerAndFit( sizer );
577 IntegerConfigControl::~IntegerConfigControl()
582 int IntegerConfigControl::GetIntValue()
584 return spin->GetValue();
587 /*****************************************************************************
588 * IntegerListConfigControl implementation
589 *****************************************************************************/
590 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *p_this,
591 module_config_t *p_item,
595 : ConfigControl( p_this, p_item, parent, hInst )
597 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
598 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
599 combo = new wxComboBox( this, -1, wxT(""),
600 wxDefaultPosition, wxDefaultSize,
601 0, NULL, wxCB_READONLY );
603 UpdateCombo( p_item );
605 combo->SetToolTip( wxU(p_item->psz_longtext) );
606 sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
609 this->SetSizerAndFit( sizer );
612 IntegerListConfigControl::~IntegerListConfigControl()
616 void IntegerListConfigControl::UpdateCombo( module_config_t *p_item )
618 /* build a list of available options */
619 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
621 if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
623 combo->Append( wxU(p_item->ppsz_list_text[i_index]) );
627 combo->Append( wxString::Format(wxT("%i"),
628 p_item->pi_list[i_index]) );
630 combo->SetClientData( i_index, (void *)p_item->pi_list[i_index] );
631 if( p_item->i_value == p_item->pi_list[i_index] )
633 combo->SetSelection( i_index );
634 if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
636 combo->SetValue( wxU(p_item->ppsz_list_text[i_index]) );
640 combo->SetValue( wxString::Format(wxT("%i"),
641 p_item->pi_list[i_index]) );
647 BEGIN_EVENT_TABLE(IntegerListConfigControl, wxPanel)
649 EVT_BUTTON(-1, IntegerListConfigControl::OnAction)
652 void IntegerListConfigControl::OnAction( wxCommandEvent& event )
654 int i_action = event.GetId() - wxID_HIGHEST;
656 module_config_t *p_item;
657 p_item = config_FindConfig( p_this, GetName().mb_str() );
658 if( !p_item ) return;
660 if( i_action < 0 || i_action >= p_item->i_action ) return;
663 val.i_int = GetIntValue();
664 p_item->ppf_action[i_action]( p_this, GetName().mb_str(), val, val, 0 );
666 if( p_item->b_dirty )
669 UpdateCombo( p_item );
670 p_item->b_dirty = VLC_FALSE;
674 int IntegerListConfigControl::GetIntValue()
676 int selected = combo->GetSelection();
679 return (int)combo->GetClientData( selected );
684 /*****************************************************************************
685 * RangedIntConfigControl implementation
686 *****************************************************************************/
687 RangedIntConfigControl::RangedIntConfigControl( vlc_object_t *p_this,
688 module_config_t *p_item,
689 HWND parent, HINSTANCE hInst,
691 : ConfigControl( p_this, p_item, parent, hInst )
693 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
694 slider = new wxSlider( this, -1, p_item->i_value, p_item->i_min,
695 p_item->i_max, wxDefaultPosition, wxDefaultSize,
696 wxSL_LABELS | wxSL_HORIZONTAL );
697 slider->SetToolTip( wxU(p_item->psz_longtext) );
698 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
699 sizer->Add( slider, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
701 this->SetSizerAndFit( sizer );
704 RangedIntConfigControl::~RangedIntConfigControl()
709 int RangedIntConfigControl::GetIntValue()
711 return slider->GetValue();
715 /*****************************************************************************
716 * FloatConfigControl implementation
717 *****************************************************************************/
718 FloatConfigControl::FloatConfigControl( vlc_object_t *p_this,
719 module_config_t *p_item,
720 HWND parent, HINSTANCE hInst,
722 : ConfigControl( p_this, p_item, parent, hInst )
724 label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
725 WS_CHILD | WS_VISIBLE | SS_LEFT,
727 parent, NULL, hInst, NULL );
731 TCHAR psz_string[100];
732 _stprintf( psz_string, _T("%f"), p_item->f_value );
733 textctrl = CreateWindow( _T("EDIT"), psz_string,
734 WS_CHILD | WS_VISIBLE | WS_BORDER | SS_RIGHT | ES_AUTOHSCROLL,
735 20, *py_pos - 3, 70, 15 + 3, parent, NULL, hInst, NULL );
740 FloatConfigControl::~FloatConfigControl()
745 float FloatConfigControl::GetFloatValue()
749 int i_size = Edit_GetTextLength( textctrl );
750 TCHAR *psz_string = (TCHAR *)malloc( (i_size + 1) * sizeof(TCHAR) );
751 Edit_GetText( textctrl, psz_string, i_size + 1 );
753 if( _tscanf( psz_string, _T("%f"), &f_value ) == 1 )
763 /*****************************************************************************
764 * BoolConfigControl implementation
765 *****************************************************************************/
766 BoolConfigControl::BoolConfigControl( vlc_object_t *p_this,
767 module_config_t *p_item, HWND parent,
768 HINSTANCE hInst, int * py_pos )
769 : ConfigControl( p_this, p_item, parent, hInst )
771 checkbox = CreateWindow( _T("BUTTON"), _T(""),
772 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
774 parent, NULL, hInst, NULL );
775 Button_SetCheck( checkbox, p_item->i_value ? BST_CHECKED : BST_UNCHECKED );
777 checkbox_label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
778 WS_CHILD | WS_VISIBLE | SS_LEFT,
779 5 + 15 + 5, *py_pos, 180, 15,
780 parent, NULL, hInst, NULL );
785 BoolConfigControl::~BoolConfigControl()
790 int BoolConfigControl::GetIntValue()
792 if( Button_GetCheck( checkbox ) ) return 1;