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 <stdlib.h> /* malloc(), free() */
29 #include <string.h> /* strerror() */
41 #include "preferences_widgets.h"
43 /*****************************************************************************
44 * CreateConfigControl wrapper
45 *****************************************************************************/
46 ConfigControl *CreateConfigControl( vlc_object_t *p_this,
47 module_config_t *p_item,
48 HWND parent, HINSTANCE hInst,
51 ConfigControl *p_control = NULL;
53 if( p_item->psz_current )
57 switch( p_item->i_type )
59 case CONFIG_ITEM_MODULE:
60 p_control = new ModuleConfigControl( p_this, p_item, parent, hInst, py_pos );
63 case CONFIG_ITEM_STRING:
66 p_control = new StringConfigControl( p_this, p_item, parent, hInst, py_pos );
70 p_control = new StringListConfigControl( p_this, p_item, parent, hInst, py_pos );
74 case CONFIG_ITEM_FILE:
75 case CONFIG_ITEM_DIRECTORY:
76 p_control = new FileConfigControl( p_this, p_item, parent, hInst, py_pos );
79 case CONFIG_ITEM_INTEGER:
82 p_control = new IntegerListConfigControl( p_this, p_item, parent, hInst, py_pos );
84 else if( p_item->i_min != 0 || p_item->i_max != 0 )
86 p_control = new RangedIntConfigControl( p_this, p_item, parent, hInst, py_pos );
90 p_control = new IntegerConfigControl( p_this, p_item, parent, hInst, py_pos );
95 p_control = new KeyConfigControl( p_this, p_item, parent, hInst, py_pos );
98 case CONFIG_ITEM_FLOAT:
99 p_control = new FloatConfigControl( p_this, p_item, parent, hInst, py_pos );
102 case CONFIG_ITEM_BOOL:
103 p_control = new BoolConfigControl( p_this, p_item, parent, hInst, py_pos );
113 /*****************************************************************************
114 * ConfigControl implementation
115 *****************************************************************************/
116 ConfigControl::ConfigControl( vlc_object_t *_p_this,
117 module_config_t *p_item,
118 HWND parent, HINSTANCE hInst )
119 : p_this( _p_this ), pf_update_callback( NULL ), p_update_data( NULL ),
120 parent( parent ), name( p_item->psz_name ), i_type( p_item->i_type ),
121 b_advanced( p_item->b_advanced )
124 /*sizer = new wxBoxSizer( wxHORIZONTAL );*/
127 ConfigControl::~ConfigControl()
131 /*wxSizer *ConfigControl::Sizer()
136 char *ConfigControl::GetName()
141 int ConfigControl::GetType()
146 vlc_bool_t ConfigControl::IsAdvanced()
151 void ConfigControl::SetUpdateCallback( void (*p_callback)( void * ),
154 pf_update_callback = p_callback;
155 p_update_data = p_data;
158 void ConfigControl::OnUpdate( UINT event )
160 if( pf_update_callback )
162 pf_update_callback( p_update_data );
166 /*****************************************************************************
167 * KeyConfigControl implementation
168 *****************************************************************************/
169 string *KeyConfigControl::m_keysList = NULL;
171 KeyConfigControl::KeyConfigControl( vlc_object_t *p_this,
172 module_config_t *p_item,
173 HWND parent, HINSTANCE hInst,
175 : ConfigControl( p_this, p_item, parent, hInst )
177 // Number of keys descriptions
178 unsigned int i_keys = sizeof(vlc_keys)/sizeof(key_descriptor_t);
180 // Init the keys decriptions array
181 if( m_keysList == NULL )
183 m_keysList = new string[i_keys];
184 for( unsigned int i = 0; i < i_keys; i++ )
186 m_keysList[i] = vlc_keys[i].psz_key_string;
190 label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
191 WS_CHILD | WS_VISIBLE | SS_LEFT, 5, *py_pos, 200, 15,
192 parent, NULL, hInst, NULL );
196 alt = CreateWindow( _T("BUTTON"), _T("Alt"),
197 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
198 20, *py_pos, 15, 15, parent, NULL, hInst, NULL );
199 Button_SetCheck( alt, p_item->i_value & KEY_MODIFIER_ALT ? BST_CHECKED :
202 alt_label = CreateWindow( _T("STATIC"), _T("Alt"),
203 WS_CHILD | WS_VISIBLE | SS_LEFT, 20 + 15 + 5, *py_pos, 30, 15,
204 parent, NULL, hInst, NULL );
206 ctrl = CreateWindow( _T("BUTTON"), _T("Ctrl"),
207 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
208 20 + 15 + 5 + 30 + 5, *py_pos, 15, 15,
209 parent, NULL, hInst, NULL );
210 Button_SetCheck( ctrl, p_item->i_value & KEY_MODIFIER_CTRL ? BST_CHECKED :
213 ctrl_label = CreateWindow( _T("STATIC"), _T("Ctrl"),
214 WS_CHILD | WS_VISIBLE | SS_LEFT,
215 20 + 15 + 5 + 30 + 5 + 15 + 5, *py_pos, 30, 15,
216 parent, NULL, hInst, NULL );
218 shift = CreateWindow( _T("BUTTON"), _T("Shift"),
219 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
220 20 + 15 + 5 + 2*(30 + 5) + 15 + 5, *py_pos, 15, 15,
221 parent, NULL, hInst, NULL );
222 Button_SetCheck( shift, p_item->i_value & KEY_MODIFIER_SHIFT ?
223 BST_CHECKED : BST_UNCHECKED );
225 shift_label = CreateWindow( _T("STATIC"), _T("Shift"),
226 WS_CHILD | WS_VISIBLE | SS_LEFT,
227 20 + 15 + 5 + 2*(30 + 5) + 2*(15 + 5), *py_pos, 30, 15,
228 parent, NULL, hInst, NULL );
232 combo = CreateWindow( _T("COMBOBOX"), _T(""),
233 WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_DROPDOWNLIST |
234 CBS_SORT | WS_VSCROLL, 20, *py_pos, 130, 5*15 + 6,
235 parent, NULL, hInst, NULL );
239 for( unsigned int i = 0; i < i_keys ; i++ )
241 ComboBox_AddString( combo, _FROMMB(m_keysList[i].c_str()) );
242 ComboBox_SetItemData( combo, i, (void*)vlc_keys[i].i_key_code );
243 if( (unsigned int)vlc_keys[i].i_key_code ==
244 ( ((unsigned int)p_item->i_value) & ~KEY_MODIFIER ) )
246 ComboBox_SetCurSel( combo, i );
247 ComboBox_SetText( combo, _FROMMB(m_keysList[i].c_str()) );
252 KeyConfigControl::~KeyConfigControl()
261 int KeyConfigControl::GetIntValue()
264 if( Button_GetCheck( alt ) )
266 result |= KEY_MODIFIER_ALT;
268 if( Button_GetCheck( ctrl ) )
270 result |= KEY_MODIFIER_CTRL;
272 if( Button_GetCheck( shift ) )
274 result |= KEY_MODIFIER_SHIFT;
276 int selected = ComboBox_GetCurSel( combo );
279 result |= (int)ComboBox_GetItemData( combo, selected );
284 /*****************************************************************************
285 * ModuleConfigControl implementation
286 *****************************************************************************/
287 ModuleConfigControl::ModuleConfigControl( vlc_object_t *p_this,
288 module_config_t *p_item,
289 HWND parent, HINSTANCE hInst,
291 : ConfigControl( p_this, p_item, parent, hInst )
296 label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
297 WS_CHILD | WS_VISIBLE | SS_LEFT,
299 parent, NULL, hInst, NULL );
303 combo = CreateWindow( _T("COMBOBOX"), _T(""),
304 WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL |
305 CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL,
306 20, *py_pos, 180, 5*15 + 6,
307 parent, NULL, hInst, NULL);
311 /* build a list of available modules */
312 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
313 ComboBox_AddString( combo, _T("Default") );
314 ComboBox_SetItemData( combo, 0, (void *)NULL );
315 ComboBox_SetCurSel( combo, 0 );
316 //ComboBox_SetText( combo, _T("Default") );
317 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
319 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
321 if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
323 ComboBox_AddString( combo, _FROMMB(p_parser->psz_longname) );
324 ComboBox_SetItemData( combo, i_index,
325 (void*)p_parser->psz_object_name );
326 if( p_item->psz_value && !strcmp(p_item->psz_value,
327 p_parser->psz_object_name) )
329 ComboBox_SetCurSel( combo, i_index );
330 //ComboBox_SetText( combo, _FROMMB(p_parser->psz_longname) );
334 vlc_list_release( p_list );
337 ModuleConfigControl::~ModuleConfigControl()
342 char *ModuleConfigControl::GetPszValue()
344 int selected = ComboBox_GetCurSel( combo );
346 return (char *)ComboBox_GetItemData( combo, selected );
350 /*****************************************************************************
351 * StringConfigControl implementation
352 *****************************************************************************/
353 StringConfigControl::StringConfigControl( vlc_object_t *p_this,
354 module_config_t *p_item,
355 HWND parent, HINSTANCE hInst,
357 : ConfigControl( p_this, p_item, parent, hInst )
359 label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
360 WS_CHILD | WS_VISIBLE | SS_LEFT,
362 parent, NULL, hInst, NULL );
366 textctrl = CreateWindow( _T("EDIT"), p_item->psz_value ?
367 _FROMMB(p_item->psz_value) : _T(""),
368 WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT |
369 ES_AUTOHSCROLL, 20, *py_pos - 3, 180, 15 + 3,
370 parent, NULL, hInst, NULL );
375 StringConfigControl::~StringConfigControl()
380 char *StringConfigControl::GetPszValue()
386 i_size = Edit_GetTextLength( textctrl );
387 psz_string = (TCHAR *)malloc( (i_size + 1) * sizeof(TCHAR) );
388 Edit_GetText( textctrl, psz_string, i_size + 1 );
389 psz_result = strdup( _TOMB(psz_string) );
395 /*****************************************************************************
396 * StringListConfigControl implementation
397 *****************************************************************************/
398 StringListConfigControl::StringListConfigControl( vlc_object_t *p_this,
399 module_config_t *p_item,
400 HWND parent, HINSTANCE hInst,
402 : ConfigControl( p_this, p_item, parent, hInst )
404 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
405 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
406 combo = new wxComboBox( this, -1, wxT(""),
407 wxDefaultPosition, wxDefaultSize,
408 0, NULL, wxCB_READONLY );
409 UpdateCombo( p_item );
411 combo->SetToolTip( wxU(p_item->psz_longtext) );
412 sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
414 for( int i = 0; i < p_item->i_action; i++ )
417 new wxButton( this, wxID_HIGHEST+i,
418 wxU(p_item->ppsz_action_text[i]) );
419 sizer->Add( button, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
423 this->SetSizerAndFit( sizer );
426 StringListConfigControl::~StringListConfigControl()
430 void StringListConfigControl::UpdateCombo( module_config_t *p_item )
432 /* build a list of available options */
433 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
435 combo->Append( ( p_item->ppsz_list_text &&
436 p_item->ppsz_list_text[i_index] ) ?
437 wxU(p_item->ppsz_list_text[i_index]) :
438 wxL2U(p_item->ppsz_list[i_index]) );
439 combo->SetClientData( i_index, (void *)p_item->ppsz_list[i_index] );
440 if( ( p_item->psz_value &&
441 !strcmp( p_item->psz_value, p_item->ppsz_list[i_index] ) ) ||
442 ( !p_item->psz_value && !*p_item->ppsz_list[i_index] ) )
444 combo->SetSelection( i_index );
445 combo->SetValue( ( p_item->ppsz_list_text &&
446 p_item->ppsz_list_text[i_index] ) ?
447 wxU(p_item->ppsz_list_text[i_index]) :
448 wxL2U(p_item->ppsz_list[i_index]) );
453 BEGIN_EVENT_TABLE(StringListConfigControl, wxPanel)
455 EVT_BUTTON(-1, StringListConfigControl::OnAction)
458 EVT__T(-1, StringListConfigControl::OnUpdate)
461 void StringListConfigControl::OnAction( wxCommandEvent& event )
463 int i_action = event.GetId() - wxID_HIGHEST;
465 module_config_t *p_item = config_FindConfig( p_this, GetName().mb_str() );
466 if( !p_item ) return;
468 if( i_action < 0 || i_action >= p_item->i_action ) return;
471 wxString value = GetPszValue();
472 (const char *)val.psz_string = value.mb_str();
473 p_item->ppf_action[i_action]( p_this, GetName().mb_str(), val, val, 0 );
475 if( p_item->b_dirty )
478 UpdateCombo( p_item );
479 p_item->b_dirty = VLC_FALSE;
483 wxString StringListConfigControl::GetPszValue()
485 int selected = combo->GetSelection();
488 return wxL2U((char *)combo->GetClientData( selected ));
493 /*****************************************************************************
494 * FileConfigControl implementation
495 *****************************************************************************/
496 FileConfigControl::FileConfigControl( vlc_object_t *p_this,
497 module_config_t *p_item,
498 HWND parent, HINSTANCE hInst,
500 : ConfigControl( p_this, p_item, parent, hInst )
502 directory = p_item->i_type == CONFIG_ITEM_DIRECTORY;
503 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
504 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
505 textctrl = new wxTextCtrl( this, -1,
506 wxL2U(p_item->psz_value),
510 textctrl->SetToolTip( wxU(p_item->psz_longtext) );
511 sizer->Add( textctrl, 1, wxALL, 5 );
512 browse = new wxButton( this, wxID_HIGHEST, wxU(_("Browse...")) );
513 sizer->Add( browse, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
515 this->SetSizerAndFit( sizer );
518 BEGIN_EVENT_TABLE(FileConfigControl, wxPanel)
520 EVT_BUTTON(wxID_HIGHEST, FileConfigControl::OnBrowse)
523 void FileConfigControl::OnBrowse( wxCommandEvent& event )
527 wxDirDialog dialog( this, wxU(_("Choose directory")) );
529 if( dialog.ShowModal() == wxID_OK )
531 textctrl->SetValue( dialog.GetPath() );
536 wxFileDialog dialog( this, wxU(_("Choose file")),
537 wxT(""), wxT(""), wxT("*.*"),
538 #if defined( __WXMSW__ )
544 if( dialog.ShowModal() == wxID_OK )
546 textctrl->SetValue( dialog.GetPath() );
551 FileConfigControl::~FileConfigControl()
556 wxString FileConfigControl::GetPszValue()
558 return textctrl->GetValue();
561 /*****************************************************************************
562 * IntegerConfigControl implementation
563 *****************************************************************************/
564 IntegerConfigControl::IntegerConfigControl( vlc_object_t *p_this,
565 module_config_t *p_item,
566 HWND parent, HINSTANCE hInst,
568 : ConfigControl( p_this, p_item, parent, hInst )
570 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
571 spin = new wxSpinCtrl( this, -1,
572 wxString::Format(wxT("%d"),
574 wxDefaultPosition, wxDefaultSize,
576 -10000000, 10000000, p_item->i_value);
577 spin->SetToolTip( wxU(p_item->psz_longtext) );
578 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
579 sizer->Add( spin, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
581 this->SetSizerAndFit( sizer );
584 IntegerConfigControl::~IntegerConfigControl()
589 int IntegerConfigControl::GetIntValue()
591 return spin->GetValue();
594 /*****************************************************************************
595 * IntegerListConfigControl implementation
596 *****************************************************************************/
597 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *p_this,
598 module_config_t *p_item,
602 : ConfigControl( p_this, p_item, parent, hInst )
604 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
605 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
606 combo = new wxComboBox( this, -1, wxT(""),
607 wxDefaultPosition, wxDefaultSize,
608 0, NULL, wxCB_READONLY );
610 UpdateCombo( p_item );
612 combo->SetToolTip( wxU(p_item->psz_longtext) );
613 sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
616 this->SetSizerAndFit( sizer );
619 IntegerListConfigControl::~IntegerListConfigControl()
623 void IntegerListConfigControl::UpdateCombo( module_config_t *p_item )
625 /* build a list of available options */
626 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
628 if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
630 combo->Append( wxU(p_item->ppsz_list_text[i_index]) );
634 combo->Append( wxString::Format(wxT("%i"),
635 p_item->pi_list[i_index]) );
637 combo->SetClientData( i_index, (void *)p_item->pi_list[i_index] );
638 if( p_item->i_value == p_item->pi_list[i_index] )
640 combo->SetSelection( i_index );
641 if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
643 combo->SetValue( wxU(p_item->ppsz_list_text[i_index]) );
647 combo->SetValue( wxString::Format(wxT("%i"),
648 p_item->pi_list[i_index]) );
654 BEGIN_EVENT_TABLE(IntegerListConfigControl, wxPanel)
656 EVT_BUTTON(-1, IntegerListConfigControl::OnAction)
659 void IntegerListConfigControl::OnAction( wxCommandEvent& event )
661 int i_action = event.GetId() - wxID_HIGHEST;
663 module_config_t *p_item;
664 p_item = config_FindConfig( p_this, GetName().mb_str() );
665 if( !p_item ) return;
667 if( i_action < 0 || i_action >= p_item->i_action ) return;
670 val.i_int = GetIntValue();
671 p_item->ppf_action[i_action]( p_this, GetName().mb_str(), val, val, 0 );
673 if( p_item->b_dirty )
676 UpdateCombo( p_item );
677 p_item->b_dirty = VLC_FALSE;
681 int IntegerListConfigControl::GetIntValue()
683 int selected = combo->GetSelection();
686 return (int)combo->GetClientData( selected );
691 /*****************************************************************************
692 * RangedIntConfigControl implementation
693 *****************************************************************************/
694 RangedIntConfigControl::RangedIntConfigControl( vlc_object_t *p_this,
695 module_config_t *p_item,
696 HWND parent, HINSTANCE hInst,
698 : ConfigControl( p_this, p_item, parent, hInst )
700 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
701 slider = new wxSlider( this, -1, p_item->i_value, p_item->i_min,
702 p_item->i_max, wxDefaultPosition, wxDefaultSize,
703 wxSL_LABELS | wxSL_HORIZONTAL );
704 slider->SetToolTip( wxU(p_item->psz_longtext) );
705 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
706 sizer->Add( slider, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
708 this->SetSizerAndFit( sizer );
711 RangedIntConfigControl::~RangedIntConfigControl()
716 int RangedIntConfigControl::GetIntValue()
718 return slider->GetValue();
722 /*****************************************************************************
723 * FloatConfigControl implementation
724 *****************************************************************************/
725 FloatConfigControl::FloatConfigControl( vlc_object_t *p_this,
726 module_config_t *p_item,
727 HWND parent, HINSTANCE hInst,
729 : ConfigControl( p_this, p_item, parent, hInst )
731 label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
732 WS_CHILD | WS_VISIBLE | SS_LEFT,
734 parent, NULL, hInst, NULL );
738 TCHAR psz_string[100];
739 _stprintf( psz_string, _T("%f"), p_item->f_value );
740 textctrl = CreateWindow( _T("EDIT"), psz_string,
741 WS_CHILD | WS_VISIBLE | WS_BORDER | SS_RIGHT | ES_AUTOHSCROLL,
742 20, *py_pos - 3, 70, 15 + 3, parent, NULL, hInst, NULL );
747 FloatConfigControl::~FloatConfigControl()
752 float FloatConfigControl::GetFloatValue()
756 int i_size = Edit_GetTextLength( textctrl );
757 TCHAR *psz_string = (TCHAR *)malloc( (i_size + 1) * sizeof(TCHAR) );
758 Edit_GetText( textctrl, psz_string, i_size + 1 );
760 if( _tscanf( psz_string, _T("%f"), &f_value ) == 1 )
770 /*****************************************************************************
771 * BoolConfigControl implementation
772 *****************************************************************************/
773 BoolConfigControl::BoolConfigControl( vlc_object_t *p_this,
774 module_config_t *p_item, HWND parent,
775 HINSTANCE hInst, int * py_pos )
776 : ConfigControl( p_this, p_item, parent, hInst )
778 checkbox = CreateWindow( _T("BUTTON"), _T(""),
779 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
781 parent, NULL, hInst, NULL );
782 Button_SetCheck( checkbox, p_item->i_value ? BST_CHECKED : BST_UNCHECKED );
784 checkbox_label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
785 WS_CHILD | WS_VISIBLE | SS_LEFT,
786 5 + 15 + 5, *py_pos, 180, 15,
787 parent, NULL, hInst, NULL );
792 BoolConfigControl::~BoolConfigControl()
797 int BoolConfigControl::GetIntValue()
799 if( Button_GetCheck( checkbox ) ) return 1;