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_type & 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_type & 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_type & 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_type) & ~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 = module_list_get( NULL );
310 ComboBox_AddString( combo, _T("Default") );
311 ComboBox_SetItemData( combo, 0, (void *)NULL );
312 ComboBox_SetCurSel( combo, 0 );
313 //ComboBox_SetText( combo, _T("Default") );
315 for( size_t i_index = 0; p_list[i_index]; i_index++ )
317 p_parser = p_list[i_index];
319 if( module_provides( p_parser, p_item->psz_type ) )
321 ComboBox_AddString( combo, _FROMMB(module_GetLongName( p_parser ) ));
322 ComboBox_SetItemData( combo, i_index,
323 (void *) module_get_object( p_parser ) );
324 if( p_item->value.psz && !strcmp( p_item->value.psz,
325 module_get_object( p_parser )) )
327 ComboBox_SetCurSel( combo, i_index );
328 //ComboBox_SetText( combo, _FROMMB( module_GetLongName(p_parser)) );
332 module_list_free( p_list );
335 ModuleConfigControl::~ModuleConfigControl()
340 char *ModuleConfigControl::GetPszValue()
342 int selected = ComboBox_GetCurSel( combo );
344 return (char *)ComboBox_GetItemData( combo, selected );
348 /*****************************************************************************
349 * StringConfigControl implementation
350 *****************************************************************************/
351 StringConfigControl::StringConfigControl( vlc_object_t *p_this,
352 module_config_t *p_item,
353 HWND parent, HINSTANCE hInst,
355 : ConfigControl( p_this, p_item, parent, hInst )
357 label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
358 WS_CHILD | WS_VISIBLE | SS_LEFT,
360 parent, NULL, hInst, NULL );
364 textctrl = CreateWindow( _T("EDIT"), p_item->psz_type ?
365 _FROMMB(p_item->psz_type) : _T(""),
366 WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT |
367 ES_AUTOHSCROLL, 20, *py_pos - 3, 180, 15 + 3,
368 parent, NULL, hInst, NULL );
373 StringConfigControl::~StringConfigControl()
378 char *StringConfigControl::GetPszValue()
384 i_size = Edit_GetTextLength( textctrl );
385 psz_string = (TCHAR *)malloc( (i_size + 1) * sizeof(TCHAR) );
386 Edit_GetText( textctrl, psz_string, i_size + 1 );
387 psz_result = strdup( _TOMB(psz_string) );
393 /*****************************************************************************
394 * StringListConfigControl implementation
395 *****************************************************************************/
396 StringListConfigControl::StringListConfigControl( vlc_object_t *p_this,
397 module_config_t *p_item,
398 HWND parent, HINSTANCE hInst,
400 : ConfigControl( p_this, p_item, parent, hInst )
402 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
403 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
404 combo = new wxComboBox( this, -1, wxT(""),
405 wxDefaultPosition, wxDefaultSize,
406 0, NULL, wxCB_READONLY );
407 UpdateCombo( p_item );
409 combo->SetToolTip( wxU(p_item->psz_longtext) );
410 sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
412 for( int i = 0; i < p_item->i_action; i++ )
415 new wxButton( this, wxID_HIGHEST+i,
416 wxU(p_item->ppsz_action_text[i]) );
417 sizer->Add( button, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
421 this->SetSizerAndFit( sizer );
424 StringListConfigControl::~StringListConfigControl()
428 void StringListConfigControl::UpdateCombo( module_config_t *p_item )
430 /* build a list of available options */
431 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
433 combo->Append( ( p_item->ppsz_list_text &&
434 p_item->ppsz_list_text[i_index] ) ?
435 wxU(p_item->ppsz_list_text[i_index]) :
436 wxL2U(p_item->ppsz_list[i_index]) );
437 combo->SetClientData( i_index, (void *)p_item->ppsz_list[i_index] );
438 if( ( p_item->psz_value &&
439 !strcmp( p_item->psz_value, p_item->ppsz_list[i_index] ) ) ||
440 ( !p_item->psz_value && !*p_item->ppsz_list[i_index] ) )
442 combo->SetSelection( i_index );
443 combo->SetValue( ( p_item->ppsz_list_text &&
444 p_item->ppsz_list_text[i_index] ) ?
445 wxU(p_item->ppsz_list_text[i_index]) :
446 wxL2U(p_item->ppsz_list[i_index]) );
451 BEGIN_EVENT_TABLE(StringListConfigControl, wxPanel)
453 EVT_BUTTON(-1, StringListConfigControl::OnAction)
456 EVT__T(-1, StringListConfigControl::OnUpdate)
459 void StringListConfigControl::OnAction( wxCommandEvent& event )
461 int i_action = event.GetId() - wxID_HIGHEST;
463 module_config_t *p_item = config_FindConfig( p_this, GetName().mb_str() );
464 if( !p_item ) return;
466 if( i_action < 0 || i_action >= p_item->i_action ) return;
469 wxString value = GetPszValue();
470 (const char *)val.psz_string = value.mb_str();
471 p_item->ppf_action[i_action]( p_this, GetName().mb_str(), val, val, 0 );
473 if( p_item->b_dirty )
476 UpdateCombo( p_item );
477 p_item->b_dirty = false;
481 wxString StringListConfigControl::GetPszValue()
483 int selected = combo->GetSelection();
486 return wxL2U((char *)combo->GetClientData( selected ));
491 /*****************************************************************************
492 * FileConfigControl implementation
493 *****************************************************************************/
494 FileConfigControl::FileConfigControl( vlc_object_t *p_this,
495 module_config_t *p_item,
496 HWND parent, HINSTANCE hInst,
498 : ConfigControl( p_this, p_item, parent, hInst )
500 directory = p_item->i_type == CONFIG_ITEM_DIRECTORY;
501 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
502 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
503 textctrl = new wxTextCtrl( this, -1,
504 wxL2U(p_item->psz_value),
508 textctrl->SetToolTip( wxU(p_item->psz_longtext) );
509 sizer->Add( textctrl, 1, wxALL, 5 );
510 browse = new wxButton( this, wxID_HIGHEST, wxU(_("Browse...")) );
511 sizer->Add( browse, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
513 this->SetSizerAndFit( sizer );
516 BEGIN_EVENT_TABLE(FileConfigControl, wxPanel)
518 EVT_BUTTON(wxID_HIGHEST, FileConfigControl::OnBrowse)
521 void FileConfigControl::OnBrowse( wxCommandEvent& event )
525 wxDirDialog dialog( this, wxU(_("Choose directory")) );
527 if( dialog.ShowModal() == wxID_OK )
529 textctrl->SetValue( dialog.GetPath() );
534 wxFileDialog dialog( this, wxU(_("Choose file")),
535 wxT(""), wxT(""), wxT("*.*"),
536 #if defined( __WXMSW__ )
542 if( dialog.ShowModal() == wxID_OK )
544 textctrl->SetValue( dialog.GetPath() );
549 FileConfigControl::~FileConfigControl()
554 wxString FileConfigControl::GetPszValue()
556 return textctrl->GetValue();
559 /*****************************************************************************
560 * IntegerConfigControl implementation
561 *****************************************************************************/
562 IntegerConfigControl::IntegerConfigControl( vlc_object_t *p_this,
563 module_config_t *p_item,
564 HWND parent, HINSTANCE hInst,
566 : ConfigControl( p_this, p_item, parent, hInst )
568 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
569 spin = new wxSpinCtrl( this, -1,
570 wxString::Format(wxT("%d"),
572 wxDefaultPosition, wxDefaultSize,
574 -10000000, 10000000, p_item->i_value);
575 spin->SetToolTip( wxU(p_item->psz_longtext) );
576 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
577 sizer->Add( spin, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
579 this->SetSizerAndFit( sizer );
582 IntegerConfigControl::~IntegerConfigControl()
587 int IntegerConfigControl::GetIntValue()
589 return spin->GetValue();
592 /*****************************************************************************
593 * IntegerListConfigControl implementation
594 *****************************************************************************/
595 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *p_this,
596 module_config_t *p_item,
600 : ConfigControl( p_this, p_item, parent, hInst )
602 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
603 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
604 combo = new wxComboBox( this, -1, wxT(""),
605 wxDefaultPosition, wxDefaultSize,
606 0, NULL, wxCB_READONLY );
608 UpdateCombo( p_item );
610 combo->SetToolTip( wxU(p_item->psz_longtext) );
611 sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
614 this->SetSizerAndFit( sizer );
617 IntegerListConfigControl::~IntegerListConfigControl()
621 void IntegerListConfigControl::UpdateCombo( module_config_t *p_item )
623 /* build a list of available options */
624 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
626 if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
628 combo->Append( wxU(p_item->ppsz_list_text[i_index]) );
632 combo->Append( wxString::Format(wxT("%i"),
633 p_item->pi_list[i_index]) );
635 combo->SetClientData( i_index, (void *)p_item->pi_list[i_index] );
636 if( p_item->i_value == p_item->pi_list[i_index] )
638 combo->SetSelection( i_index );
639 if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
641 combo->SetValue( wxU(p_item->ppsz_list_text[i_index]) );
645 combo->SetValue( wxString::Format(wxT("%i"),
646 p_item->pi_list[i_index]) );
652 BEGIN_EVENT_TABLE(IntegerListConfigControl, wxPanel)
654 EVT_BUTTON(-1, IntegerListConfigControl::OnAction)
657 void IntegerListConfigControl::OnAction( wxCommandEvent& event )
659 int i_action = event.GetId() - wxID_HIGHEST;
661 module_config_t *p_item;
662 p_item = config_FindConfig( p_this, GetName().mb_str() );
663 if( !p_item ) return;
665 if( i_action < 0 || i_action >= p_item->i_action ) return;
668 val.i_int = GetIntValue();
669 p_item->ppf_action[i_action]( p_this, GetName().mb_str(), val, val, 0 );
671 if( p_item->b_dirty )
674 UpdateCombo( p_item );
675 p_item->b_dirty = false;
679 int IntegerListConfigControl::GetIntValue()
681 int selected = combo->GetSelection();
684 return (int)combo->GetClientData( selected );
689 /*****************************************************************************
690 * RangedIntConfigControl implementation
691 *****************************************************************************/
692 RangedIntConfigControl::RangedIntConfigControl( vlc_object_t *p_this,
693 module_config_t *p_item,
694 HWND parent, HINSTANCE hInst,
696 : ConfigControl( p_this, p_item, parent, hInst )
698 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
699 slider = new wxSlider( this, -1, p_item->i_value, p_item->i_min,
700 p_item->i_max, wxDefaultPosition, wxDefaultSize,
701 wxSL_LABELS | wxSL_HORIZONTAL );
702 slider->SetToolTip( wxU(p_item->psz_longtext) );
703 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
704 sizer->Add( slider, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
706 this->SetSizerAndFit( sizer );
709 RangedIntConfigControl::~RangedIntConfigControl()
714 int RangedIntConfigControl::GetIntValue()
716 return slider->GetValue();
720 /*****************************************************************************
721 * FloatConfigControl implementation
722 *****************************************************************************/
723 FloatConfigControl::FloatConfigControl( vlc_object_t *p_this,
724 module_config_t *p_item,
725 HWND parent, HINSTANCE hInst,
727 : ConfigControl( p_this, p_item, parent, hInst )
729 label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
730 WS_CHILD | WS_VISIBLE | SS_LEFT,
732 parent, NULL, hInst, NULL );
736 TCHAR psz_string[100];
737 _stprintf( psz_string, _T("%d"), p_item->i_type );
738 textctrl = CreateWindow( _T("EDIT"), psz_string,
739 WS_CHILD | WS_VISIBLE | WS_BORDER | SS_RIGHT | ES_AUTOHSCROLL,
740 20, *py_pos - 3, 70, 15 + 3, parent, NULL, hInst, NULL );
745 FloatConfigControl::~FloatConfigControl()
750 float FloatConfigControl::GetFloatValue()
754 int i_size = Edit_GetTextLength( textctrl );
755 TCHAR *psz_string = (TCHAR *)malloc( (i_size + 1) * sizeof(TCHAR) );
756 Edit_GetText( textctrl, psz_string, i_size + 1 );
758 if( _tscanf( psz_string, _T("%f"), &f_value ) == 1 )
768 /*****************************************************************************
769 * BoolConfigControl implementation
770 *****************************************************************************/
771 BoolConfigControl::BoolConfigControl( vlc_object_t *p_this,
772 module_config_t *p_item, HWND parent,
773 HINSTANCE hInst, int * py_pos )
774 : ConfigControl( p_this, p_item, parent, hInst )
776 checkbox = CreateWindow( _T("BUTTON"), _T(""),
777 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
779 parent, NULL, hInst, NULL );
780 Button_SetCheck( checkbox, config_GetInt(p_this, p_item->psz_name) ? BST_CHECKED : BST_UNCHECKED );
782 checkbox_label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
783 WS_CHILD | WS_VISIBLE | SS_LEFT,
784 5 + 15 + 5, *py_pos, 180, 15,
785 parent, NULL, hInst, NULL );
790 BoolConfigControl::~BoolConfigControl()
795 int BoolConfigControl::GetIntValue()
797 if( Button_GetCheck( checkbox ) ) return 1;