1 /*****************************************************************************
2 * preferences_widgets.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: preferences_widgets.cpp,v 1.3 2003/10/20 00:09:27 gbazin Exp $
7 * Authors: Gildas Bazin <gbazin@netcourrier.com>
8 * Sigmund Augdal <sigmunau@idi.ntnu.no>
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
29 #include <errno.h> /* ENOMEM */
30 #include <string.h> /* strerror() */
38 #include "wxwindows.h"
39 #include "preferences_widgets.h"
41 /*****************************************************************************
42 * ConfigControl implementation
43 *****************************************************************************/
44 ConfigControl::ConfigControl( wxWindow *parent ): wxPanel( parent )
46 sizer = new wxBoxSizer( wxHORIZONTAL );
52 ConfigControl::~ConfigControl()
54 if( psz_value ) free( psz_value );
57 wxSizer *ConfigControl::Sizer()
62 int ConfigControl::GetIntValue()
67 float ConfigControl::GetFloatValue()
72 wxString ConfigControl::GetPszValue()
74 return wxString(psz_value ? wxU(psz_value) : wxT(""));
77 /*****************************************************************************
78 * KeyConfigControl implementation
79 *****************************************************************************/
80 KeyConfigControl::KeyConfigControl( module_config_t *p_item, wxWindow *parent )
81 : ConfigControl( parent )
83 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
84 alt = new wxCheckBox( this, -1, wxU(_("Alt")) );
85 alt->SetValue( p_item->i_value & KEY_MODIFIER_ALT );
86 ctrl = new wxCheckBox( this, -1, wxU(_("Ctrl")) );
87 ctrl->SetValue( p_item->i_value & KEY_MODIFIER_CTRL );
88 shift = new wxCheckBox( this, -1, wxU(_("Shift")) );
89 shift->SetValue( p_item->i_value & KEY_MODIFIER_SHIFT );
90 combo = new wxComboBox( this, -1, wxU("f"), wxDefaultPosition,
91 wxDefaultSize, 0, NULL,
92 wxCB_READONLY | wxCB_SORT );
93 for( unsigned int i = 0; i < sizeof(keys)/sizeof(key_descriptor_s); i++ )
95 /* HPReg says casting the int to void * is fine */
96 combo->Append( wxU(_(keys[i].psz_key_string)),
97 (void*)keys[i].i_key_code );
98 if( keys[i].i_key_code == ( p_item->i_value & ~KEY_MODIFIER ) )
100 combo->SetSelection( i );
103 sizer->Add( label, 2, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
104 sizer->Add( alt, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
105 sizer->Add( ctrl, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
106 sizer->Add( shift, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
107 sizer->Add( combo, 2, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
109 this->SetSizerAndFit( sizer );
112 KeyConfigControl::~KeyConfigControl()
117 int KeyConfigControl::GetIntValue()
120 if( alt->IsChecked() )
122 result |= KEY_MODIFIER_ALT;
124 if( ctrl->IsChecked() )
126 result |= KEY_MODIFIER_CTRL;
128 if( shift->IsChecked() )
130 result |= KEY_MODIFIER_SHIFT;
132 int selected = combo->GetSelection();
135 result |= (int)combo->GetClientData( selected );
140 /*****************************************************************************
141 * ModuleConfigControl implementation
142 *****************************************************************************/
143 ModuleConfigControl::ModuleConfigControl( intf_thread_t *p_intf,
144 module_config_t *p_item,
146 : ConfigControl( parent )
151 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
152 combo = new wxComboBox( this, -1, wxU(p_item->psz_value),
153 wxDefaultPosition, wxDefaultSize,
154 0, NULL, wxCB_READONLY | wxCB_SORT );
156 /* build a list of available modules */
157 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
158 combo->Append( wxU(_("Default")), (void *)NULL );
159 combo->SetSelection( 0 );
160 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
162 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
164 if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
166 combo->Append( wxU(p_parser->psz_longname),
167 p_parser->psz_object_name );
168 if( p_item->psz_value && !strcmp(p_item->psz_value,
169 p_parser->psz_object_name) )
170 combo->SetValue( wxU(p_parser->psz_longname) );
173 vlc_list_release( p_list );
175 combo->SetToolTip( wxU(p_item->psz_longtext) );
176 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
177 sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
179 this->SetSizerAndFit( sizer );
182 ModuleConfigControl::~ModuleConfigControl()
187 wxString ModuleConfigControl::GetPszValue()
189 return combo->GetStringSelection();
192 /*****************************************************************************
193 * StringConfigControl implementation
194 *****************************************************************************/
195 StringConfigControl::StringConfigControl( module_config_t *p_item,
197 : ConfigControl( parent )
199 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
200 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
201 textctrl = new wxTextCtrl( this, -1,
202 wxU(p_item->psz_value),
206 textctrl->SetToolTip( wxU(p_item->psz_longtext) );
207 sizer->Add( textctrl, 1, wxALL, 5 );
209 this->SetSizerAndFit( sizer );
212 StringConfigControl::~StringConfigControl()
217 wxString StringConfigControl::GetPszValue()
219 return textctrl->GetValue();
222 /*****************************************************************************
223 * StringListConfigControl implementation
224 *****************************************************************************/
225 StringListConfigControl::StringListConfigControl( module_config_t *p_item,
227 : ConfigControl( parent )
229 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
230 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
231 combo = new wxComboBox( this, -1, wxU(p_item->psz_value),
232 wxDefaultPosition, wxDefaultSize,
233 0, NULL, wxCB_READONLY|wxCB_SORT );
235 /* build a list of available options */
236 for( int i_index = 0; p_item->ppsz_list[i_index];
239 combo->Append( wxU(p_item->ppsz_list[i_index]) );
240 if( p_item->psz_value && !strcmp( p_item->psz_value,
241 p_item->ppsz_list[i_index] ) )
242 combo->SetSelection( i_index );
245 if( p_item->psz_value )
246 combo->SetValue( wxU(p_item->psz_value) );
247 combo->SetToolTip( wxU(p_item->psz_longtext) );
248 sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
250 this->SetSizerAndFit( sizer );
253 StringListConfigControl::~StringListConfigControl()
258 wxString StringListConfigControl::GetPszValue()
260 return combo->GetStringSelection();
263 /*****************************************************************************
264 * FileConfigControl implementation
265 *****************************************************************************/
266 FileConfigControl::FileConfigControl( module_config_t *p_item,
268 : ConfigControl( parent )
270 directory = p_item->i_type == CONFIG_ITEM_DIRECTORY;
271 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
272 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
273 textctrl = new wxTextCtrl( this, -1,
274 wxU(p_item->psz_value),
278 textctrl->SetToolTip( wxU(p_item->psz_longtext) );
279 sizer->Add( textctrl, 1, wxALL, 5 );
280 browse = new wxButton( this, wxID_HIGHEST, wxU(_("Browse...")) );
281 sizer->Add( browse, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
283 this->SetSizerAndFit( sizer );
286 BEGIN_EVENT_TABLE(FileConfigControl, wxPanel)
288 EVT_BUTTON(wxID_HIGHEST, FileConfigControl::OnBrowse)
291 void FileConfigControl::OnBrowse( wxCommandEvent& event )
295 wxDirDialog dialog( this, wxU(_("Choose Directory")) );
297 if( dialog.ShowModal() == wxID_OK )
299 textctrl->SetValue( dialog.GetPath() );
304 wxFileDialog dialog( this, wxU(_("Choose File")),
305 wxT(""), wxT(""), wxT("*.*"),
306 #if defined( __WXMSW__ )
315 FileConfigControl::~FileConfigControl()
320 wxString FileConfigControl::GetPszValue()
322 return textctrl->GetValue();
325 /*****************************************************************************
326 * IntegerConfigControl implementation
327 *****************************************************************************/
328 IntegerConfigControl::IntegerConfigControl( module_config_t *p_item,
330 : ConfigControl( parent )
332 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
333 spin = new wxSpinCtrl( this, -1,
334 wxString::Format(wxT("%d"),
336 wxDefaultPosition, wxDefaultSize,
338 -16000, 16000, p_item->i_value);
339 spin->SetToolTip( wxU(p_item->psz_longtext) );
340 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
341 sizer->Add( spin, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
343 this->SetSizerAndFit( sizer );
346 IntegerConfigControl::~IntegerConfigControl()
351 int IntegerConfigControl::GetIntValue()
353 return spin->GetValue();
356 /*****************************************************************************
357 * RangedIntConfigControl implementation
358 *****************************************************************************/
359 RangedIntConfigControl::RangedIntConfigControl( module_config_t *p_item,
361 : ConfigControl( parent )
363 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
364 slider = new wxSlider( this, -1, p_item->i_value, p_item->i_min,
366 slider->SetToolTip( wxU(p_item->psz_longtext) );
367 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
368 sizer->Add( slider, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
370 this->SetSizerAndFit( sizer );
373 RangedIntConfigControl::~RangedIntConfigControl()
378 int RangedIntConfigControl::GetIntValue()
380 return slider->GetValue();
383 /*****************************************************************************
384 * FloatConfigControl implementation
385 *****************************************************************************/
386 FloatConfigControl::FloatConfigControl( module_config_t *p_item,
388 : ConfigControl( parent )
390 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
391 textctrl = new wxTextCtrl( this, -1,
392 wxString::Format(wxT("%f"),
394 wxDefaultPosition, wxDefaultSize,
395 wxTE_PROCESS_ENTER );
396 textctrl->SetToolTip( wxU(p_item->psz_longtext) );
397 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
398 sizer->Add( textctrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
400 this->SetSizerAndFit( sizer );
403 FloatConfigControl::~FloatConfigControl()
408 float FloatConfigControl::GetFloatValue()
411 if( (wxSscanf(textctrl->GetValue(), wxT("%f"), &f_value) == 1) )
416 /*****************************************************************************
417 * BoolConfigControl implementation
418 *****************************************************************************/
419 BoolConfigControl::BoolConfigControl( module_config_t *p_item,
421 : ConfigControl( parent )
423 checkbox = new wxCheckBox( this, -1, wxU(p_item->psz_text) );
424 if( p_item->i_value ) checkbox->SetValue(TRUE);
425 checkbox->SetToolTip( wxU(p_item->psz_longtext) );
426 sizer->Add( checkbox, 0, wxALL, 5 );
428 this->SetSizerAndFit( sizer );
431 BoolConfigControl::~BoolConfigControl()
436 int BoolConfigControl::GetIntValue()
438 if( checkbox->IsChecked() )