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 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_interface.h>
42 #include "preferences_widgets.h"
44 /*****************************************************************************
45 * CreateConfigControl wrapper
46 *****************************************************************************/
47 ConfigControl *CreateConfigControl( vlc_object_t *p_this,
48 module_config_t *p_item,
49 HWND parent, HINSTANCE hInst,
52 ConfigControl *p_control = NULL;
54 switch( p_item->i_type )
56 case CONFIG_ITEM_MODULE:
57 p_control = new ModuleConfigControl( p_this, p_item, parent, hInst, py_pos );
60 case CONFIG_ITEM_STRING:
63 p_control = new StringConfigControl( p_this, p_item, parent, hInst, py_pos );
67 p_control = new StringListConfigControl( p_this, p_item, parent, hInst, py_pos );
71 case CONFIG_ITEM_FILE:
72 case CONFIG_ITEM_DIRECTORY:
73 p_control = new FileConfigControl( p_this, p_item, parent, hInst, py_pos );
76 case CONFIG_ITEM_INTEGER:
79 p_control = new IntegerListConfigControl( p_this, p_item, parent, hInst, py_pos );
81 else if( p_item->i_min != 0 || p_item->i_max != 0 )
83 p_control = new RangedIntConfigControl( p_this, p_item, parent, hInst, py_pos );
87 p_control = new IntegerConfigControl( p_this, p_item, parent, hInst, py_pos );
92 p_control = new KeyConfigControl( p_this, p_item, parent, hInst, py_pos );
95 case CONFIG_ITEM_FLOAT:
96 p_control = new FloatConfigControl( p_this, p_item, parent, hInst, py_pos );
99 case CONFIG_ITEM_BOOL:
100 p_control = new BoolConfigControl( p_this, p_item, parent, hInst, py_pos );
110 /*****************************************************************************
111 * ConfigControl implementation
112 *****************************************************************************/
113 ConfigControl::ConfigControl( vlc_object_t *_p_this,
114 module_config_t *p_item,
115 HWND parent, HINSTANCE hInst )
116 : p_this( _p_this ), pf_update_callback( NULL ), p_update_data( NULL ),
117 parent( parent ), name( p_item->psz_name ), i_type( p_item->i_type ),
118 b_advanced( p_item->b_advanced )
121 /*sizer = new wxBoxSizer( wxHORIZONTAL );*/
124 ConfigControl::~ConfigControl()
128 /*wxSizer *ConfigControl::Sizer()
133 char *ConfigControl::GetName()
138 int ConfigControl::GetType()
143 bool ConfigControl::IsAdvanced()
148 void ConfigControl::SetUpdateCallback( void (*p_callback)( void * ),
151 pf_update_callback = p_callback;
152 p_update_data = p_data;
155 void ConfigControl::OnUpdate( UINT event )
157 if( pf_update_callback )
159 pf_update_callback( p_update_data );
163 /*****************************************************************************
164 * KeyConfigControl implementation
165 *****************************************************************************/
166 string *KeyConfigControl::m_keysList = NULL;
168 KeyConfigControl::KeyConfigControl( vlc_object_t *p_this,
169 module_config_t *p_item,
170 HWND parent, HINSTANCE hInst,
172 : ConfigControl( p_this, p_item, parent, hInst )
174 // Number of keys descriptions
175 unsigned int i_keys = sizeof(vlc_keys)/sizeof(key_descriptor_t);
177 // Init the keys decriptions array
178 if( m_keysList == NULL )
180 m_keysList = new string[i_keys];
181 for( unsigned int i = 0; i < i_keys; i++ )
183 m_keysList[i] = vlc_keys[i].psz_key_string;
187 label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
188 WS_CHILD | WS_VISIBLE | SS_LEFT, 5, *py_pos, 200, 15,
189 parent, NULL, hInst, NULL );
193 alt = CreateWindow( _T("BUTTON"), _T("Alt"),
194 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
195 20, *py_pos, 15, 15, parent, NULL, hInst, NULL );
196 Button_SetCheck( alt, p_item->i_value & KEY_MODIFIER_ALT ? BST_CHECKED :
199 alt_label = CreateWindow( _T("STATIC"), _T("Alt"),
200 WS_CHILD | WS_VISIBLE | SS_LEFT, 20 + 15 + 5, *py_pos, 30, 15,
201 parent, NULL, hInst, NULL );
203 ctrl = CreateWindow( _T("BUTTON"), _T("Ctrl"),
204 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
205 20 + 15 + 5 + 30 + 5, *py_pos, 15, 15,
206 parent, NULL, hInst, NULL );
207 Button_SetCheck( ctrl, p_item->i_value & KEY_MODIFIER_CTRL ? BST_CHECKED :
210 ctrl_label = CreateWindow( _T("STATIC"), _T("Ctrl"),
211 WS_CHILD | WS_VISIBLE | SS_LEFT,
212 20 + 15 + 5 + 30 + 5 + 15 + 5, *py_pos, 30, 15,
213 parent, NULL, hInst, NULL );
215 shift = CreateWindow( _T("BUTTON"), _T("Shift"),
216 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
217 20 + 15 + 5 + 2*(30 + 5) + 15 + 5, *py_pos, 15, 15,
218 parent, NULL, hInst, NULL );
219 Button_SetCheck( shift, p_item->i_value & KEY_MODIFIER_SHIFT ?
220 BST_CHECKED : BST_UNCHECKED );
222 shift_label = CreateWindow( _T("STATIC"), _T("Shift"),
223 WS_CHILD | WS_VISIBLE | SS_LEFT,
224 20 + 15 + 5 + 2*(30 + 5) + 2*(15 + 5), *py_pos, 30, 15,
225 parent, NULL, hInst, NULL );
229 combo = CreateWindow( _T("COMBOBOX"), _T(""),
230 WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_DROPDOWNLIST |
231 CBS_SORT | WS_VSCROLL, 20, *py_pos, 130, 5*15 + 6,
232 parent, NULL, hInst, NULL );
236 for( unsigned int i = 0; i < i_keys ; i++ )
238 ComboBox_AddString( combo, _FROMMB(m_keysList[i].c_str()) );
239 ComboBox_SetItemData( combo, i, (void*)vlc_keys[i].i_key_code );
240 if( (unsigned int)vlc_keys[i].i_key_code ==
241 ( ((unsigned int)p_item->i_value) & ~KEY_MODIFIER ) )
243 ComboBox_SetCurSel( combo, i );
244 ComboBox_SetText( combo, _FROMMB(m_keysList[i].c_str()) );
249 KeyConfigControl::~KeyConfigControl()
258 int KeyConfigControl::GetIntValue()
261 if( Button_GetCheck( alt ) )
263 result |= KEY_MODIFIER_ALT;
265 if( Button_GetCheck( ctrl ) )
267 result |= KEY_MODIFIER_CTRL;
269 if( Button_GetCheck( shift ) )
271 result |= KEY_MODIFIER_SHIFT;
273 int selected = ComboBox_GetCurSel( combo );
276 result |= (int)ComboBox_GetItemData( combo, selected );
281 /*****************************************************************************
282 * ModuleConfigControl implementation
283 *****************************************************************************/
284 ModuleConfigControl::ModuleConfigControl( vlc_object_t *p_this,
285 module_config_t *p_item,
286 HWND parent, HINSTANCE hInst,
288 : ConfigControl( p_this, p_item, parent, hInst )
293 label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
294 WS_CHILD | WS_VISIBLE | SS_LEFT,
296 parent, NULL, hInst, NULL );
300 combo = CreateWindow( _T("COMBOBOX"), _T(""),
301 WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL |
302 CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL,
303 20, *py_pos, 180, 5*15 + 6,
304 parent, NULL, hInst, NULL);
308 /* build a list of available modules */
309 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
310 ComboBox_AddString( combo, _T("Default") );
311 ComboBox_SetItemData( combo, 0, (void *)NULL );
312 ComboBox_SetCurSel( combo, 0 );
313 //ComboBox_SetText( combo, _T("Default") );
314 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
316 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
318 if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
320 ComboBox_AddString( combo, _FROMMB(p_parser->psz_longname) );
321 ComboBox_SetItemData( combo, i_index,
322 (void*)p_parser->psz_object_name );
323 if( p_item->psz_value && !strcmp(p_item->psz_value,
324 p_parser->psz_object_name) )
326 ComboBox_SetCurSel( combo, i_index );
327 //ComboBox_SetText( combo, _FROMMB(p_parser->psz_longname) );
331 vlc_list_release( p_list );
334 ModuleConfigControl::~ModuleConfigControl()
339 char *ModuleConfigControl::GetPszValue()
341 int selected = ComboBox_GetCurSel( combo );
343 return (char *)ComboBox_GetItemData( combo, selected );
347 /*****************************************************************************
348 * StringConfigControl implementation
349 *****************************************************************************/
350 StringConfigControl::StringConfigControl( vlc_object_t *p_this,
351 module_config_t *p_item,
352 HWND parent, HINSTANCE hInst,
354 : ConfigControl( p_this, p_item, parent, hInst )
356 label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
357 WS_CHILD | WS_VISIBLE | SS_LEFT,
359 parent, NULL, hInst, NULL );
363 textctrl = CreateWindow( _T("EDIT"), p_item->psz_value ?
364 _FROMMB(p_item->psz_value) : _T(""),
365 WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT |
366 ES_AUTOHSCROLL, 20, *py_pos - 3, 180, 15 + 3,
367 parent, NULL, hInst, NULL );
372 StringConfigControl::~StringConfigControl()
377 char *StringConfigControl::GetPszValue()
383 i_size = Edit_GetTextLength( textctrl );
384 psz_string = (TCHAR *)malloc( (i_size + 1) * sizeof(TCHAR) );
385 Edit_GetText( textctrl, psz_string, i_size + 1 );
386 psz_result = strdup( _TOMB(psz_string) );
392 /*****************************************************************************
393 * StringListConfigControl implementation
394 *****************************************************************************/
395 StringListConfigControl::StringListConfigControl( vlc_object_t *p_this,
396 module_config_t *p_item,
397 HWND parent, HINSTANCE hInst,
399 : ConfigControl( p_this, p_item, parent, hInst )
401 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
402 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
403 combo = new wxComboBox( this, -1, wxT(""),
404 wxDefaultPosition, wxDefaultSize,
405 0, NULL, wxCB_READONLY );
406 UpdateCombo( p_item );
408 combo->SetToolTip( wxU(p_item->psz_longtext) );
409 sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
411 for( int i = 0; i < p_item->i_action; i++ )
414 new wxButton( this, wxID_HIGHEST+i,
415 wxU(p_item->ppsz_action_text[i]) );
416 sizer->Add( button, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
420 this->SetSizerAndFit( sizer );
423 StringListConfigControl::~StringListConfigControl()
427 void StringListConfigControl::UpdateCombo( module_config_t *p_item )
429 /* build a list of available options */
430 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
432 combo->Append( ( p_item->ppsz_list_text &&
433 p_item->ppsz_list_text[i_index] ) ?
434 wxU(p_item->ppsz_list_text[i_index]) :
435 wxL2U(p_item->ppsz_list[i_index]) );
436 combo->SetClientData( i_index, (void *)p_item->ppsz_list[i_index] );
437 if( ( p_item->psz_value &&
438 !strcmp( p_item->psz_value, p_item->ppsz_list[i_index] ) ) ||
439 ( !p_item->psz_value && !*p_item->ppsz_list[i_index] ) )
441 combo->SetSelection( i_index );
442 combo->SetValue( ( p_item->ppsz_list_text &&
443 p_item->ppsz_list_text[i_index] ) ?
444 wxU(p_item->ppsz_list_text[i_index]) :
445 wxL2U(p_item->ppsz_list[i_index]) );
450 BEGIN_EVENT_TABLE(StringListConfigControl, wxPanel)
452 EVT_BUTTON(-1, StringListConfigControl::OnAction)
455 EVT__T(-1, StringListConfigControl::OnUpdate)
458 void StringListConfigControl::OnAction( wxCommandEvent& event )
460 int i_action = event.GetId() - wxID_HIGHEST;
462 module_config_t *p_item = config_FindConfig( p_this, GetName().mb_str() );
463 if( !p_item ) return;
465 if( i_action < 0 || i_action >= p_item->i_action ) return;
468 wxString value = GetPszValue();
469 (const char *)val.psz_string = value.mb_str();
470 p_item->ppf_action[i_action]( p_this, GetName().mb_str(), val, val, 0 );
472 if( p_item->b_dirty )
475 UpdateCombo( p_item );
476 p_item->b_dirty = false;
480 wxString StringListConfigControl::GetPszValue()
482 int selected = combo->GetSelection();
485 return wxL2U((char *)combo->GetClientData( selected ));
490 /*****************************************************************************
491 * FileConfigControl implementation
492 *****************************************************************************/
493 FileConfigControl::FileConfigControl( vlc_object_t *p_this,
494 module_config_t *p_item,
495 HWND parent, HINSTANCE hInst,
497 : ConfigControl( p_this, p_item, parent, hInst )
499 directory = p_item->i_type == CONFIG_ITEM_DIRECTORY;
500 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
501 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
502 textctrl = new wxTextCtrl( this, -1,
503 wxL2U(p_item->psz_value),
507 textctrl->SetToolTip( wxU(p_item->psz_longtext) );
508 sizer->Add( textctrl, 1, wxALL, 5 );
509 browse = new wxButton( this, wxID_HIGHEST, wxU(_("Browse...")) );
510 sizer->Add( browse, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
512 this->SetSizerAndFit( sizer );
515 BEGIN_EVENT_TABLE(FileConfigControl, wxPanel)
517 EVT_BUTTON(wxID_HIGHEST, FileConfigControl::OnBrowse)
520 void FileConfigControl::OnBrowse( wxCommandEvent& event )
524 wxDirDialog dialog( this, wxU(_("Choose directory")) );
526 if( dialog.ShowModal() == wxID_OK )
528 textctrl->SetValue( dialog.GetPath() );
533 wxFileDialog dialog( this, wxU(_("Choose file")),
534 wxT(""), wxT(""), wxT("*.*"),
535 #if defined( __WXMSW__ )
541 if( dialog.ShowModal() == wxID_OK )
543 textctrl->SetValue( dialog.GetPath() );
548 FileConfigControl::~FileConfigControl()
553 wxString FileConfigControl::GetPszValue()
555 return textctrl->GetValue();
558 /*****************************************************************************
559 * IntegerConfigControl implementation
560 *****************************************************************************/
561 IntegerConfigControl::IntegerConfigControl( vlc_object_t *p_this,
562 module_config_t *p_item,
563 HWND parent, HINSTANCE hInst,
565 : ConfigControl( p_this, p_item, parent, hInst )
567 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
568 spin = new wxSpinCtrl( this, -1,
569 wxString::Format(wxT("%d"),
571 wxDefaultPosition, wxDefaultSize,
573 -10000000, 10000000, p_item->i_value);
574 spin->SetToolTip( wxU(p_item->psz_longtext) );
575 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
576 sizer->Add( spin, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
578 this->SetSizerAndFit( sizer );
581 IntegerConfigControl::~IntegerConfigControl()
586 int IntegerConfigControl::GetIntValue()
588 return spin->GetValue();
591 /*****************************************************************************
592 * IntegerListConfigControl implementation
593 *****************************************************************************/
594 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *p_this,
595 module_config_t *p_item,
599 : ConfigControl( p_this, p_item, parent, hInst )
601 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
602 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
603 combo = new wxComboBox( this, -1, wxT(""),
604 wxDefaultPosition, wxDefaultSize,
605 0, NULL, wxCB_READONLY );
607 UpdateCombo( p_item );
609 combo->SetToolTip( wxU(p_item->psz_longtext) );
610 sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
613 this->SetSizerAndFit( sizer );
616 IntegerListConfigControl::~IntegerListConfigControl()
620 void IntegerListConfigControl::UpdateCombo( module_config_t *p_item )
622 /* build a list of available options */
623 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
625 if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
627 combo->Append( wxU(p_item->ppsz_list_text[i_index]) );
631 combo->Append( wxString::Format(wxT("%i"),
632 p_item->pi_list[i_index]) );
634 combo->SetClientData( i_index, (void *)p_item->pi_list[i_index] );
635 if( p_item->i_value == p_item->pi_list[i_index] )
637 combo->SetSelection( i_index );
638 if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
640 combo->SetValue( wxU(p_item->ppsz_list_text[i_index]) );
644 combo->SetValue( wxString::Format(wxT("%i"),
645 p_item->pi_list[i_index]) );
651 BEGIN_EVENT_TABLE(IntegerListConfigControl, wxPanel)
653 EVT_BUTTON(-1, IntegerListConfigControl::OnAction)
656 void IntegerListConfigControl::OnAction( wxCommandEvent& event )
658 int i_action = event.GetId() - wxID_HIGHEST;
660 module_config_t *p_item;
661 p_item = config_FindConfig( p_this, GetName().mb_str() );
662 if( !p_item ) return;
664 if( i_action < 0 || i_action >= p_item->i_action ) return;
667 val.i_int = GetIntValue();
668 p_item->ppf_action[i_action]( p_this, GetName().mb_str(), val, val, 0 );
670 if( p_item->b_dirty )
673 UpdateCombo( p_item );
674 p_item->b_dirty = false;
678 int IntegerListConfigControl::GetIntValue()
680 int selected = combo->GetSelection();
683 return (int)combo->GetClientData( selected );
688 /*****************************************************************************
689 * RangedIntConfigControl implementation
690 *****************************************************************************/
691 RangedIntConfigControl::RangedIntConfigControl( vlc_object_t *p_this,
692 module_config_t *p_item,
693 HWND parent, HINSTANCE hInst,
695 : ConfigControl( p_this, p_item, parent, hInst )
697 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
698 slider = new wxSlider( this, -1, p_item->i_value, p_item->i_min,
699 p_item->i_max, wxDefaultPosition, wxDefaultSize,
700 wxSL_LABELS | wxSL_HORIZONTAL );
701 slider->SetToolTip( wxU(p_item->psz_longtext) );
702 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
703 sizer->Add( slider, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
705 this->SetSizerAndFit( sizer );
708 RangedIntConfigControl::~RangedIntConfigControl()
713 int RangedIntConfigControl::GetIntValue()
715 return slider->GetValue();
719 /*****************************************************************************
720 * FloatConfigControl implementation
721 *****************************************************************************/
722 FloatConfigControl::FloatConfigControl( vlc_object_t *p_this,
723 module_config_t *p_item,
724 HWND parent, HINSTANCE hInst,
726 : ConfigControl( p_this, p_item, parent, hInst )
728 label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
729 WS_CHILD | WS_VISIBLE | SS_LEFT,
731 parent, NULL, hInst, NULL );
735 TCHAR psz_string[100];
736 _stprintf( psz_string, _T("%f"), p_item->f_value );
737 textctrl = CreateWindow( _T("EDIT"), psz_string,
738 WS_CHILD | WS_VISIBLE | WS_BORDER | SS_RIGHT | ES_AUTOHSCROLL,
739 20, *py_pos - 3, 70, 15 + 3, parent, NULL, hInst, NULL );
744 FloatConfigControl::~FloatConfigControl()
749 float FloatConfigControl::GetFloatValue()
753 int i_size = Edit_GetTextLength( textctrl );
754 TCHAR *psz_string = (TCHAR *)malloc( (i_size + 1) * sizeof(TCHAR) );
755 Edit_GetText( textctrl, psz_string, i_size + 1 );
757 if( _tscanf( psz_string, _T("%f"), &f_value ) == 1 )
767 /*****************************************************************************
768 * BoolConfigControl implementation
769 *****************************************************************************/
770 BoolConfigControl::BoolConfigControl( vlc_object_t *p_this,
771 module_config_t *p_item, HWND parent,
772 HINSTANCE hInst, int * py_pos )
773 : ConfigControl( p_this, p_item, parent, hInst )
775 checkbox = CreateWindow( _T("BUTTON"), _T(""),
776 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
778 parent, NULL, hInst, NULL );
779 Button_SetCheck( checkbox, p_item->i_value ? BST_CHECKED : BST_UNCHECKED );
781 checkbox_label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
782 WS_CHILD | WS_VISIBLE | SS_LEFT,
783 5 + 15 + 5, *py_pos, 180, 15,
784 parent, NULL, hInst, NULL );
789 BoolConfigControl::~BoolConfigControl()
794 int BoolConfigControl::GetIntValue()
796 if( Button_GetCheck( checkbox ) ) return 1;