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 *****************************************************************************/
30 #include <vlc_interface.h>
39 #include "preferences_widgets.h"
41 /*****************************************************************************
42 * CreateConfigControl wrapper
43 *****************************************************************************/
44 ConfigControl *CreateConfigControl( vlc_object_t *p_this,
45 module_config_t *p_item,
46 HWND parent, HINSTANCE hInst,
49 ConfigControl *p_control = NULL;
51 if( p_item->psz_current )
55 switch( p_item->i_type )
57 case CONFIG_ITEM_MODULE:
58 p_control = new ModuleConfigControl( p_this, p_item, parent, hInst, py_pos );
61 case CONFIG_ITEM_STRING:
64 p_control = new StringConfigControl( p_this, p_item, parent, hInst, py_pos );
68 p_control = new StringListConfigControl( p_this, p_item, parent, hInst, py_pos );
72 case CONFIG_ITEM_FILE:
73 case CONFIG_ITEM_DIRECTORY:
74 p_control = new FileConfigControl( p_this, p_item, parent, hInst, py_pos );
77 case CONFIG_ITEM_INTEGER:
80 p_control = new IntegerListConfigControl( p_this, p_item, parent, hInst, py_pos );
82 else if( p_item->i_min != 0 || p_item->i_max != 0 )
84 p_control = new RangedIntConfigControl( p_this, p_item, parent, hInst, py_pos );
88 p_control = new IntegerConfigControl( p_this, p_item, parent, hInst, py_pos );
93 p_control = new KeyConfigControl( p_this, p_item, parent, hInst, py_pos );
96 case CONFIG_ITEM_FLOAT:
97 p_control = new FloatConfigControl( p_this, p_item, parent, hInst, py_pos );
100 case CONFIG_ITEM_BOOL:
101 p_control = new BoolConfigControl( p_this, p_item, parent, hInst, py_pos );
111 /*****************************************************************************
112 * ConfigControl implementation
113 *****************************************************************************/
114 ConfigControl::ConfigControl( vlc_object_t *_p_this,
115 module_config_t *p_item,
116 HWND parent, HINSTANCE hInst )
117 : p_this( _p_this ), pf_update_callback( NULL ), p_update_data( NULL ),
118 parent( parent ), name( p_item->psz_name ), i_type( p_item->i_type ),
119 b_advanced( p_item->b_advanced )
122 /*sizer = new wxBoxSizer( wxHORIZONTAL );*/
125 ConfigControl::~ConfigControl()
129 /*wxSizer *ConfigControl::Sizer()
134 char *ConfigControl::GetName()
139 int ConfigControl::GetType()
144 vlc_bool_t ConfigControl::IsAdvanced()
149 void ConfigControl::SetUpdateCallback( void (*p_callback)( void * ),
152 pf_update_callback = p_callback;
153 p_update_data = p_data;
156 void ConfigControl::OnUpdate( UINT event )
158 if( pf_update_callback )
160 pf_update_callback( p_update_data );
164 /*****************************************************************************
165 * KeyConfigControl implementation
166 *****************************************************************************/
167 string *KeyConfigControl::m_keysList = NULL;
169 KeyConfigControl::KeyConfigControl( vlc_object_t *p_this,
170 module_config_t *p_item,
171 HWND parent, HINSTANCE hInst,
173 : ConfigControl( p_this, p_item, parent, hInst )
175 // Number of keys descriptions
176 unsigned int i_keys = sizeof(vlc_keys)/sizeof(key_descriptor_t);
178 // Init the keys decriptions array
179 if( m_keysList == NULL )
181 m_keysList = new string[i_keys];
182 for( unsigned int i = 0; i < i_keys; i++ )
184 m_keysList[i] = vlc_keys[i].psz_key_string;
188 label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
189 WS_CHILD | WS_VISIBLE | SS_LEFT, 5, *py_pos, 200, 15,
190 parent, NULL, hInst, NULL );
194 alt = CreateWindow( _T("BUTTON"), _T("Alt"),
195 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
196 20, *py_pos, 15, 15, parent, NULL, hInst, NULL );
197 Button_SetCheck( alt, p_item->i_value & KEY_MODIFIER_ALT ? BST_CHECKED :
200 alt_label = CreateWindow( _T("STATIC"), _T("Alt"),
201 WS_CHILD | WS_VISIBLE | SS_LEFT, 20 + 15 + 5, *py_pos, 30, 15,
202 parent, NULL, hInst, NULL );
204 ctrl = CreateWindow( _T("BUTTON"), _T("Ctrl"),
205 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
206 20 + 15 + 5 + 30 + 5, *py_pos, 15, 15,
207 parent, NULL, hInst, NULL );
208 Button_SetCheck( ctrl, p_item->i_value & KEY_MODIFIER_CTRL ? BST_CHECKED :
211 ctrl_label = CreateWindow( _T("STATIC"), _T("Ctrl"),
212 WS_CHILD | WS_VISIBLE | SS_LEFT,
213 20 + 15 + 5 + 30 + 5 + 15 + 5, *py_pos, 30, 15,
214 parent, NULL, hInst, NULL );
216 shift = CreateWindow( _T("BUTTON"), _T("Shift"),
217 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
218 20 + 15 + 5 + 2*(30 + 5) + 15 + 5, *py_pos, 15, 15,
219 parent, NULL, hInst, NULL );
220 Button_SetCheck( shift, p_item->i_value & KEY_MODIFIER_SHIFT ?
221 BST_CHECKED : BST_UNCHECKED );
223 shift_label = CreateWindow( _T("STATIC"), _T("Shift"),
224 WS_CHILD | WS_VISIBLE | SS_LEFT,
225 20 + 15 + 5 + 2*(30 + 5) + 2*(15 + 5), *py_pos, 30, 15,
226 parent, NULL, hInst, NULL );
230 combo = CreateWindow( _T("COMBOBOX"), _T(""),
231 WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_DROPDOWNLIST |
232 CBS_SORT | WS_VSCROLL, 20, *py_pos, 130, 5*15 + 6,
233 parent, NULL, hInst, NULL );
237 for( unsigned int i = 0; i < i_keys ; i++ )
239 ComboBox_AddString( combo, _FROMMB(m_keysList[i].c_str()) );
240 ComboBox_SetItemData( combo, i, (void*)vlc_keys[i].i_key_code );
241 if( (unsigned int)vlc_keys[i].i_key_code ==
242 ( ((unsigned int)p_item->i_value) & ~KEY_MODIFIER ) )
244 ComboBox_SetCurSel( combo, i );
245 ComboBox_SetText( combo, _FROMMB(m_keysList[i].c_str()) );
250 KeyConfigControl::~KeyConfigControl()
259 int KeyConfigControl::GetIntValue()
262 if( Button_GetCheck( alt ) )
264 result |= KEY_MODIFIER_ALT;
266 if( Button_GetCheck( ctrl ) )
268 result |= KEY_MODIFIER_CTRL;
270 if( Button_GetCheck( shift ) )
272 result |= KEY_MODIFIER_SHIFT;
274 int selected = ComboBox_GetCurSel( combo );
277 result |= (int)ComboBox_GetItemData( combo, selected );
282 /*****************************************************************************
283 * ModuleConfigControl implementation
284 *****************************************************************************/
285 ModuleConfigControl::ModuleConfigControl( vlc_object_t *p_this,
286 module_config_t *p_item,
287 HWND parent, HINSTANCE hInst,
289 : ConfigControl( p_this, p_item, parent, hInst )
294 label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
295 WS_CHILD | WS_VISIBLE | SS_LEFT,
297 parent, NULL, hInst, NULL );
301 combo = CreateWindow( _T("COMBOBOX"), _T(""),
302 WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL |
303 CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL,
304 20, *py_pos, 180, 5*15 + 6,
305 parent, NULL, hInst, NULL);
309 /* build a list of available modules */
310 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
311 ComboBox_AddString( combo, _T("Default") );
312 ComboBox_SetItemData( combo, 0, (void *)NULL );
313 ComboBox_SetCurSel( combo, 0 );
314 //ComboBox_SetText( combo, _T("Default") );
315 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
317 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
319 if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
321 ComboBox_AddString( combo, _FROMMB(p_parser->psz_longname) );
322 ComboBox_SetItemData( combo, i_index,
323 (void*)p_parser->psz_object_name );
324 if( p_item->psz_value && !strcmp(p_item->psz_value,
325 p_parser->psz_object_name) )
327 ComboBox_SetCurSel( combo, i_index );
328 //ComboBox_SetText( combo, _FROMMB(p_parser->psz_longname) );
332 vlc_list_release( 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_value ?
365 _FROMMB(p_item->psz_value) : _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 = VLC_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 = VLC_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("%f"), p_item->f_value );
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, p_item->i_value ? 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;