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 // Init the keys decriptions array
175 if( m_keysList == NULL )
177 m_keysList = new string[vlc_num_keys];
178 for( size_t i = 0; i < vlc_num_keys; ++i )
180 m_keysList[i] = vlc_keys[i].psz_key_string;
184 label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
185 WS_CHILD | WS_VISIBLE | SS_LEFT, 5, *py_pos, 200, 15,
186 parent, NULL, hInst, NULL );
190 alt = CreateWindow( _T("BUTTON"), _T("Alt"),
191 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
192 20, *py_pos, 15, 15, parent, NULL, hInst, NULL );
193 Button_SetCheck( alt, p_item->i_type & KEY_MODIFIER_ALT ? BST_CHECKED :
196 alt_label = CreateWindow( _T("STATIC"), _T("Alt"),
197 WS_CHILD | WS_VISIBLE | SS_LEFT, 20 + 15 + 5, *py_pos, 30, 15,
198 parent, NULL, hInst, NULL );
200 ctrl = CreateWindow( _T("BUTTON"), _T("Ctrl"),
201 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
202 20 + 15 + 5 + 30 + 5, *py_pos, 15, 15,
203 parent, NULL, hInst, NULL );
204 Button_SetCheck( ctrl, p_item->i_type & KEY_MODIFIER_CTRL ? BST_CHECKED :
207 ctrl_label = CreateWindow( _T("STATIC"), _T("Ctrl"),
208 WS_CHILD | WS_VISIBLE | SS_LEFT,
209 20 + 15 + 5 + 30 + 5 + 15 + 5, *py_pos, 30, 15,
210 parent, NULL, hInst, NULL );
212 shift = CreateWindow( _T("BUTTON"), _T("Shift"),
213 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
214 20 + 15 + 5 + 2*(30 + 5) + 15 + 5, *py_pos, 15, 15,
215 parent, NULL, hInst, NULL );
216 Button_SetCheck( shift, p_item->i_type & KEY_MODIFIER_SHIFT ?
217 BST_CHECKED : BST_UNCHECKED );
219 shift_label = CreateWindow( _T("STATIC"), _T("Shift"),
220 WS_CHILD | WS_VISIBLE | SS_LEFT,
221 20 + 15 + 5 + 2*(30 + 5) + 2*(15 + 5), *py_pos, 30, 15,
222 parent, NULL, hInst, NULL );
226 combo = CreateWindow( _T("COMBOBOX"), _T(""),
227 WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_DROPDOWNLIST |
228 CBS_SORT | WS_VSCROLL, 20, *py_pos, 130, 5*15 + 6,
229 parent, NULL, hInst, NULL );
233 for( size_t i = 0; i < vlc_num_keys ; ++i )
235 ComboBox_AddString( combo, _FROMMB(m_keysList[i].c_str()) );
236 ComboBox_SetItemData( combo, i, (void*)vlc_keys[i].i_key_code );
237 if( (unsigned int)vlc_keys[i].i_key_code ==
238 ( ((unsigned int)p_item->i_type) & ~KEY_MODIFIER ) )
240 ComboBox_SetCurSel( combo, i );
241 ComboBox_SetText( combo, _FROMMB(m_keysList[i].c_str()) );
246 KeyConfigControl::~KeyConfigControl()
255 int KeyConfigControl::GetIntValue()
258 if( Button_GetCheck( alt ) )
260 result |= KEY_MODIFIER_ALT;
262 if( Button_GetCheck( ctrl ) )
264 result |= KEY_MODIFIER_CTRL;
266 if( Button_GetCheck( shift ) )
268 result |= KEY_MODIFIER_SHIFT;
270 int selected = ComboBox_GetCurSel( combo );
273 result |= (int)ComboBox_GetItemData( combo, selected );
278 /*****************************************************************************
279 * ModuleConfigControl implementation
280 *****************************************************************************/
281 ModuleConfigControl::ModuleConfigControl( vlc_object_t *p_this,
282 module_config_t *p_item,
283 HWND parent, HINSTANCE hInst,
285 : ConfigControl( p_this, p_item, parent, hInst )
290 label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
291 WS_CHILD | WS_VISIBLE | SS_LEFT,
293 parent, NULL, hInst, NULL );
297 combo = CreateWindow( _T("COMBOBOX"), _T(""),
298 WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL |
299 CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL,
300 20, *py_pos, 180, 5*15 + 6,
301 parent, NULL, hInst, NULL);
305 /* build a list of available modules */
306 p_list = module_list_get( NULL );
307 ComboBox_AddString( combo, _T("Default") );
308 ComboBox_SetItemData( combo, 0, (void *)NULL );
309 ComboBox_SetCurSel( combo, 0 );
310 //ComboBox_SetText( combo, _T("Default") );
312 for( size_t i_index = 0; p_list[i_index]; i_index++ )
314 p_parser = p_list[i_index];
316 if( module_provides( p_parser, p_item->psz_type ) )
318 ComboBox_AddString( combo, _FROMMB(module_GetLongName( p_parser ) ));
319 ComboBox_SetItemData( combo, i_index,
320 (void *) module_get_object( p_parser ) );
321 if( p_item->value.psz && !strcmp( p_item->value.psz,
322 module_get_object( p_parser )) )
324 ComboBox_SetCurSel( combo, i_index );
325 //ComboBox_SetText( combo, _FROMMB( module_GetLongName(p_parser)) );
329 module_list_free( p_list );
332 ModuleConfigControl::~ModuleConfigControl()
337 char *ModuleConfigControl::GetPszValue()
339 int selected = ComboBox_GetCurSel( combo );
341 return (char *)ComboBox_GetItemData( combo, selected );
345 /*****************************************************************************
346 * StringConfigControl implementation
347 *****************************************************************************/
348 StringConfigControl::StringConfigControl( vlc_object_t *p_this,
349 module_config_t *p_item,
350 HWND parent, HINSTANCE hInst,
352 : ConfigControl( p_this, p_item, parent, hInst )
354 label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
355 WS_CHILD | WS_VISIBLE | SS_LEFT,
357 parent, NULL, hInst, NULL );
361 textctrl = CreateWindow( _T("EDIT"), p_item->psz_type ?
362 _FROMMB(p_item->psz_type) : _T(""),
363 WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT |
364 ES_AUTOHSCROLL, 20, *py_pos - 3, 180, 15 + 3,
365 parent, NULL, hInst, NULL );
370 StringConfigControl::~StringConfigControl()
375 char *StringConfigControl::GetPszValue()
381 i_size = Edit_GetTextLength( textctrl );
382 psz_string = (TCHAR *)malloc( (i_size + 1) * sizeof(TCHAR) );
383 Edit_GetText( textctrl, psz_string, i_size + 1 );
384 psz_result = strdup( _TOMB(psz_string) );
390 /*****************************************************************************
391 * StringListConfigControl implementation
392 *****************************************************************************/
393 StringListConfigControl::StringListConfigControl( vlc_object_t *p_this,
394 module_config_t *p_item,
395 HWND parent, HINSTANCE hInst,
397 : ConfigControl( p_this, p_item, parent, hInst )
399 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
400 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
401 combo = new wxComboBox( this, -1, wxT(""),
402 wxDefaultPosition, wxDefaultSize,
403 0, NULL, wxCB_READONLY );
404 UpdateCombo( p_item );
406 combo->SetToolTip( wxU(p_item->psz_longtext) );
407 sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
409 for( int i = 0; i < p_item->i_action; i++ )
412 new wxButton( this, wxID_HIGHEST+i,
413 wxU(p_item->ppsz_action_text[i]) );
414 sizer->Add( button, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
418 this->SetSizerAndFit( sizer );
421 StringListConfigControl::~StringListConfigControl()
425 void StringListConfigControl::UpdateCombo( module_config_t *p_item )
427 /* build a list of available options */
428 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
430 combo->Append( ( p_item->ppsz_list_text &&
431 p_item->ppsz_list_text[i_index] ) ?
432 wxU(p_item->ppsz_list_text[i_index]) :
433 wxL2U(p_item->ppsz_list[i_index]) );
434 combo->SetClientData( i_index, (void *)p_item->ppsz_list[i_index] );
435 if( ( p_item->psz_value &&
436 !strcmp( p_item->psz_value, p_item->ppsz_list[i_index] ) ) ||
437 ( !p_item->psz_value && !*p_item->ppsz_list[i_index] ) )
439 combo->SetSelection( i_index );
440 combo->SetValue( ( p_item->ppsz_list_text &&
441 p_item->ppsz_list_text[i_index] ) ?
442 wxU(p_item->ppsz_list_text[i_index]) :
443 wxL2U(p_item->ppsz_list[i_index]) );
448 BEGIN_EVENT_TABLE(StringListConfigControl, wxPanel)
450 EVT_BUTTON(-1, StringListConfigControl::OnAction)
453 EVT__T(-1, StringListConfigControl::OnUpdate)
456 void StringListConfigControl::OnAction( wxCommandEvent& event )
458 int i_action = event.GetId() - wxID_HIGHEST;
460 module_config_t *p_item = config_FindConfig( p_this, GetName().mb_str() );
461 if( !p_item ) return;
463 if( i_action < 0 || i_action >= p_item->i_action ) return;
466 wxString value = GetPszValue();
467 (const char *)val.psz_string = value.mb_str();
468 p_item->ppf_action[i_action]( p_this, GetName().mb_str(), val, val, 0 );
470 if( p_item->b_dirty )
473 UpdateCombo( p_item );
474 p_item->b_dirty = false;
478 wxString StringListConfigControl::GetPszValue()
480 int selected = combo->GetSelection();
483 return wxL2U((char *)combo->GetClientData( selected ));
488 /*****************************************************************************
489 * FileConfigControl implementation
490 *****************************************************************************/
491 FileConfigControl::FileConfigControl( vlc_object_t *p_this,
492 module_config_t *p_item,
493 HWND parent, HINSTANCE hInst,
495 : ConfigControl( p_this, p_item, parent, hInst )
497 directory = p_item->i_type == CONFIG_ITEM_DIRECTORY;
498 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
499 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
500 textctrl = new wxTextCtrl( this, -1,
501 wxL2U(p_item->psz_value),
505 textctrl->SetToolTip( wxU(p_item->psz_longtext) );
506 sizer->Add( textctrl, 1, wxALL, 5 );
507 browse = new wxButton( this, wxID_HIGHEST, wxU(_("Browse...")) );
508 sizer->Add( browse, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
510 this->SetSizerAndFit( sizer );
513 BEGIN_EVENT_TABLE(FileConfigControl, wxPanel)
515 EVT_BUTTON(wxID_HIGHEST, FileConfigControl::OnBrowse)
518 void FileConfigControl::OnBrowse( wxCommandEvent& event )
522 wxDirDialog dialog( this, wxU(_("Choose directory")) );
524 if( dialog.ShowModal() == wxID_OK )
526 textctrl->SetValue( dialog.GetPath() );
531 wxFileDialog dialog( this, wxU(_("Choose file")),
532 wxT(""), wxT(""), wxT("*.*"),
533 #if defined( __WXMSW__ )
539 if( dialog.ShowModal() == wxID_OK )
541 textctrl->SetValue( dialog.GetPath() );
546 FileConfigControl::~FileConfigControl()
551 wxString FileConfigControl::GetPszValue()
553 return textctrl->GetValue();
556 /*****************************************************************************
557 * IntegerConfigControl implementation
558 *****************************************************************************/
559 IntegerConfigControl::IntegerConfigControl( vlc_object_t *p_this,
560 module_config_t *p_item,
561 HWND parent, HINSTANCE hInst,
563 : ConfigControl( p_this, p_item, parent, hInst )
565 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
566 spin = new wxSpinCtrl( this, -1,
567 wxString::Format(wxT("%d"),
569 wxDefaultPosition, wxDefaultSize,
571 -10000000, 10000000, p_item->i_value);
572 spin->SetToolTip( wxU(p_item->psz_longtext) );
573 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
574 sizer->Add( spin, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
576 this->SetSizerAndFit( sizer );
579 IntegerConfigControl::~IntegerConfigControl()
584 int IntegerConfigControl::GetIntValue()
586 return spin->GetValue();
589 /*****************************************************************************
590 * IntegerListConfigControl implementation
591 *****************************************************************************/
592 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *p_this,
593 module_config_t *p_item,
597 : ConfigControl( p_this, p_item, parent, hInst )
599 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
600 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
601 combo = new wxComboBox( this, -1, wxT(""),
602 wxDefaultPosition, wxDefaultSize,
603 0, NULL, wxCB_READONLY );
605 UpdateCombo( p_item );
607 combo->SetToolTip( wxU(p_item->psz_longtext) );
608 sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
611 this->SetSizerAndFit( sizer );
614 IntegerListConfigControl::~IntegerListConfigControl()
618 void IntegerListConfigControl::UpdateCombo( module_config_t *p_item )
620 /* build a list of available options */
621 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
623 if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
625 combo->Append( wxU(p_item->ppsz_list_text[i_index]) );
629 combo->Append( wxString::Format(wxT("%i"),
630 p_item->pi_list[i_index]) );
632 combo->SetClientData( i_index, (void *)p_item->pi_list[i_index] );
633 if( p_item->i_value == p_item->pi_list[i_index] )
635 combo->SetSelection( i_index );
636 if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
638 combo->SetValue( wxU(p_item->ppsz_list_text[i_index]) );
642 combo->SetValue( wxString::Format(wxT("%i"),
643 p_item->pi_list[i_index]) );
649 BEGIN_EVENT_TABLE(IntegerListConfigControl, wxPanel)
651 EVT_BUTTON(-1, IntegerListConfigControl::OnAction)
654 void IntegerListConfigControl::OnAction( wxCommandEvent& event )
656 int i_action = event.GetId() - wxID_HIGHEST;
658 module_config_t *p_item;
659 p_item = config_FindConfig( p_this, GetName().mb_str() );
660 if( !p_item ) return;
662 if( i_action < 0 || i_action >= p_item->i_action ) return;
665 val.i_int = GetIntValue();
666 p_item->ppf_action[i_action]( p_this, GetName().mb_str(), val, val, 0 );
668 if( p_item->b_dirty )
671 UpdateCombo( p_item );
672 p_item->b_dirty = false;
676 int IntegerListConfigControl::GetIntValue()
678 int selected = combo->GetSelection();
681 return (int)combo->GetClientData( selected );
686 /*****************************************************************************
687 * RangedIntConfigControl implementation
688 *****************************************************************************/
689 RangedIntConfigControl::RangedIntConfigControl( vlc_object_t *p_this,
690 module_config_t *p_item,
691 HWND parent, HINSTANCE hInst,
693 : ConfigControl( p_this, p_item, parent, hInst )
695 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
696 slider = new wxSlider( this, -1, p_item->i_value, p_item->i_min,
697 p_item->i_max, wxDefaultPosition, wxDefaultSize,
698 wxSL_LABELS | wxSL_HORIZONTAL );
699 slider->SetToolTip( wxU(p_item->psz_longtext) );
700 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
701 sizer->Add( slider, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
703 this->SetSizerAndFit( sizer );
706 RangedIntConfigControl::~RangedIntConfigControl()
711 int RangedIntConfigControl::GetIntValue()
713 return slider->GetValue();
717 /*****************************************************************************
718 * FloatConfigControl implementation
719 *****************************************************************************/
720 FloatConfigControl::FloatConfigControl( vlc_object_t *p_this,
721 module_config_t *p_item,
722 HWND parent, HINSTANCE hInst,
724 : ConfigControl( p_this, p_item, parent, hInst )
726 label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
727 WS_CHILD | WS_VISIBLE | SS_LEFT,
729 parent, NULL, hInst, NULL );
733 TCHAR psz_string[100];
734 _stprintf( psz_string, _T("%d"), p_item->i_type );
735 textctrl = CreateWindow( _T("EDIT"), psz_string,
736 WS_CHILD | WS_VISIBLE | WS_BORDER | SS_RIGHT | ES_AUTOHSCROLL,
737 20, *py_pos - 3, 70, 15 + 3, parent, NULL, hInst, NULL );
742 FloatConfigControl::~FloatConfigControl()
747 float FloatConfigControl::GetFloatValue()
751 int i_size = Edit_GetTextLength( textctrl );
752 TCHAR *psz_string = (TCHAR *)malloc( (i_size + 1) * sizeof(TCHAR) );
753 Edit_GetText( textctrl, psz_string, i_size + 1 );
755 if( _tscanf( psz_string, _T("%f"), &f_value ) == 1 )
765 /*****************************************************************************
766 * BoolConfigControl implementation
767 *****************************************************************************/
768 BoolConfigControl::BoolConfigControl( vlc_object_t *p_this,
769 module_config_t *p_item, HWND parent,
770 HINSTANCE hInst, int * py_pos )
771 : ConfigControl( p_this, p_item, parent, hInst )
773 checkbox = CreateWindow( _T("BUTTON"), _T(""),
774 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
776 parent, NULL, hInst, NULL );
777 Button_SetCheck( checkbox, config_GetInt(p_this, p_item->psz_name) ? BST_CHECKED : BST_UNCHECKED );
779 checkbox_label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
780 WS_CHILD | WS_VISIBLE | SS_LEFT,
781 5 + 15 + 5, *py_pos, 180, 15,
782 parent, NULL, hInst, NULL );
787 BoolConfigControl::~BoolConfigControl()
792 int BoolConfigControl::GetIntValue()
794 if( Button_GetCheck( checkbox ) ) return 1;