1 /*****************************************************************************
\r
2 * preferences.cpp: the "Preferences" dialog box
\r
3 *****************************************************************************
\r
4 * Copyright (C) 2002-2003 VideoLAN
\r
6 * Authors: Olivier Teuliere <ipkiss@via.ecp.fr>
\r
7 * Boris Dores <babal@via.ecp.fr>
\r
9 * This program is free software; you can redistribute it and/or modify
\r
10 * it under the terms of the GNU General Public License as published by
\r
11 * the Free Software Foundation; either version 2 of the License, or
\r
12 * (at your option) any later version.
\r
14 * This program is distributed in the hope that it will be useful,
\r
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
17 * GNU General Public License for more details.
\r
19 * You should have received a copy of the GNU General Public License
\r
20 * along with this program; if not, write to the Free Software
\r
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
\r
22 *****************************************************************************/
\r
27 #include <stdlib.h> /* malloc(), free() */
\r
28 #include <string.h> /* strcmp */
\r
30 #include <vlc/vlc.h>
\r
31 #include <vlc/intf.h>
\r
33 #include "preferences.h"
\r
34 #include "win32_common.h"
\r
36 //---------------------------------------------------------------------------
\r
37 //#pragma package(smart_init)
\r
38 #pragma link "CSPIN"
\r
39 #pragma resource "*.dfm"
\r
41 /****************************************************************************
\r
42 * A THintWindow with a limited width
\r
43 ****************************************************************************/
\r
44 void __fastcall TNarrowHintWindow::ActivateHint( const Windows::TRect &Rect,
\r
45 const System::AnsiString AHint )
\r
47 TRect NarrowRect = CalcHintRect( 300, AHint, NULL );
\r
48 NarrowRect.Left = Rect.Left;
\r
49 NarrowRect.Top = Rect.Top;
\r
50 NarrowRect.Right += Rect.Left;
\r
51 NarrowRect.Bottom += Rect.Top;
\r
52 THintWindow::ActivateHint( NarrowRect, AHint );
\r
56 /****************************************************************************
\r
57 * Just a wrapper to embed an AnsiString into a TObject
\r
58 ****************************************************************************/
\r
59 __fastcall TObjectString::TObjectString( char * String )
\r
61 FString = AnsiString( String );
\r
63 //---------------------------------------------------------------------------
\r
64 AnsiString __fastcall TObjectString::String()
\r
70 /****************************************************************************
\r
71 * A TCheckListBox that automatically disposes any TObject
\r
72 * associated with the string items
\r
73 ****************************************************************************/
\r
74 __fastcall TCleanCheckListBox::~TCleanCheckListBox()
\r
76 for( int i = 0 ; i < Items->Count ; i++ )
\r
78 if( Items->Objects[i] != NULL )
\r
79 delete Items->Objects[i];
\r
84 /****************************************************************************
\r
85 * Functions to help components creation
\r
86 ****************************************************************************/
\r
87 __fastcall TPanelPref::TPanelPref( TComponent* Owner,
\r
88 module_config_t *_p_config, intf_thread_t *_p_intf ) : TPanel( Owner )
\r
91 p_config = _p_config;
\r
92 BevelInner = bvNone;
\r
93 BevelOuter = bvNone;
\r
94 BorderStyle = bsNone;
\r
96 //---------------------------------------------------------------------------
\r
97 TCleanCheckListBox * __fastcall TPanelPref::CreateCleanCheckListBox(
\r
98 TWinControl *Parent, int Left, int Width, int Top, int Height )
\r
100 TCleanCheckListBox *CleanCheckListBox = new TCleanCheckListBox( Parent );
\r
101 CleanCheckListBox->Parent = Parent;
\r
102 CleanCheckListBox->Left = Left;
\r
103 CleanCheckListBox->Width = Width;
\r
104 CleanCheckListBox->Top = Top;
\r
105 CleanCheckListBox->Height = Height;
\r
106 return CleanCheckListBox;
\r
108 //---------------------------------------------------------------------------
\r
109 TButton * __fastcall TPanelPref::CreateButton( TWinControl *Parent,
\r
110 int Left, int Width, int Top, int Height, AnsiString Caption )
\r
112 TButton *Button = new TButton( Parent );
\r
113 Button->Parent = Parent;
\r
114 Button->Left = Left;
\r
115 Button->Width = Width;
\r
117 Button->Height = Height;
\r
118 Button->Caption = Caption;
\r
121 //---------------------------------------------------------------------------
\r
122 TCheckBox * __fastcall TPanelPref::CreateCheckBox( TWinControl *Parent,
\r
123 int Left, int Width, int Top, int Height, AnsiString Caption )
\r
125 TCheckBox *CheckBox = new TCheckBox( Parent );
\r
126 CheckBox->Parent = Parent;
\r
127 CheckBox->Left = Left;
\r
128 CheckBox->Width = Width;
\r
129 CheckBox->Top = Top;
\r
130 CheckBox->Height = Height;
\r
131 CheckBox->Caption = Caption;
\r
134 //---------------------------------------------------------------------------
\r
135 TLabel * __fastcall TPanelPref::CreateLabel( TWinControl *Parent,
\r
136 int Left, int Width, int Top, int Height, AnsiString Caption,
\r
139 TLabel *Label = new TLabel( Parent );
\r
140 Label->Parent = Parent;
\r
141 Label->Caption = Caption;
\r
142 Label->Left = Left;
\r
143 Label->Width = Width;
\r
145 Label->Height = Height;
\r
146 Label->WordWrap = WordWrap;
\r
149 //---------------------------------------------------------------------------
\r
150 TEdit * __fastcall TPanelPref::CreateEdit( TWinControl *Parent,
\r
151 int Left, int Width, int Top, int Height, AnsiString Text )
\r
153 TEdit *Edit = new TEdit( Parent );
\r
154 Edit->Parent = Parent;
\r
156 Edit->Width = Width;
\r
158 Edit->Height = Height;
\r
162 //---------------------------------------------------------------------------
\r
163 TCSpinEdit * __fastcall TPanelPref::CreateSpinEdit( TWinControl *Parent,
\r
164 int Left, int Width, int Top, int Height,
\r
165 long Min, long Max, long Value )
\r
167 TCSpinEdit *SpinEdit = new TCSpinEdit( Parent );
\r
168 SpinEdit->Parent = Parent;
\r
169 SpinEdit->Left = Left;
\r
170 SpinEdit->Width = Width;
\r
171 SpinEdit->Top = Top;
\r
172 SpinEdit->Height = Height;
\r
173 SpinEdit->MinValue = Min;
\r
174 SpinEdit->MaxValue = Max;
\r
175 SpinEdit->Value = Value;
\r
178 //---------------------------------------------------------------------------
\r
180 #define LIBWIN32_PREFSIZE_VPAD 4
\r
181 #define LIBWIN32_PREFSIZE_HPAD 4
\r
182 #define LIBWIN32_PREFSIZE_LEFT 16
\r
183 #define LIBWIN32_PREFSIZE_EDIT_LEFT (LIBWIN32_PREFSIZE_LEFT+32)
\r
184 #define LIBWIN32_PREFSIZE_WIDTH 375
\r
185 #define LIBWIN32_PREFSIZE_EDIT_WIDTH (LIBWIN32_PREFSIZE_WIDTH-32)
\r
186 #define LIBWIN32_PREFSIZE_BUTTON_WIDTH 150
\r
187 #define LIBWIN32_PREFSIZE_SPINEDIT_WIDTH 100
\r
188 #define LIBWIN32_PREFSIZE_RIGHT (LIBWIN32_PREFSIZE_LEFT+LIBWIN32_PREFSIZE_WIDTH)
\r
189 #define LIBWIN32_PREFSIZE_BUTTON_HEIGHT 25
\r
190 #define LIBWIN32_PREFSIZE_LABEL_HEIGHT 26
\r
191 #define LIBWIN32_PREFSIZE_CHECKLISTBOX_HEIGHT 120
\r
192 #define LIBWIN32_PREFSIZE_EDIT_HEIGHT 21
\r
193 #define LIBWIN32_PREFSIZE_CHECKBOX_HEIGHT 17
\r
194 #define LIBWIN32_PREFSIZE_SPINEDIT_HEIGHT 21
\r
196 /****************************************************************************
\r
197 * Panel for module management
\r
198 ****************************************************************************/
\r
199 __fastcall TPanelPlugin::TPanelPlugin( TComponent* Owner,
\r
200 module_config_t *p_config, intf_thread_t *_p_intf,
\r
201 bool b_multi_plugins ) : TPanelPref( Owner, p_config, _p_intf )
\r
203 this->b_multi_plugins = b_multi_plugins;
\r
205 /* init configure button */
\r
206 ButtonConfig = CreateButton( this,
\r
207 LIBWIN32_PREFSIZE_RIGHT - LIBWIN32_PREFSIZE_BUTTON_WIDTH,
\r
208 LIBWIN32_PREFSIZE_BUTTON_WIDTH,
\r
209 LIBWIN32_PREFSIZE_VPAD,
\r
210 LIBWIN32_PREFSIZE_BUTTON_HEIGHT,
\r
212 ButtonConfig->Enabled = false;
\r
213 ButtonConfig->OnClick = ButtonConfigClick;
\r
216 AnsiString Text = AnsiString( p_config->psz_text ) + ":";
\r
217 Label = CreateLabel( this,
\r
218 LIBWIN32_PREFSIZE_LEFT,
\r
219 LIBWIN32_PREFSIZE_RIGHT - LIBWIN32_PREFSIZE_BUTTON_WIDTH
\r
220 - LIBWIN32_PREFSIZE_HPAD,
\r
221 LIBWIN32_PREFSIZE_VPAD,
\r
222 LIBWIN32_PREFSIZE_LABEL_HEIGHT,
\r
223 Text.c_str(), true );
\r
225 /* vertical alignement */
\r
226 if ( ButtonConfig->Height > Label->Height )
\r
227 Label->Top += ( ButtonConfig->Height - Label->Height ) / 2;
\r
229 ButtonConfig->Top += ( Label->Height - ButtonConfig->Height ) / 2;
\r
231 /* init checklistbox */
\r
232 CleanCheckListBox = CreateCleanCheckListBox( this,
\r
233 LIBWIN32_PREFSIZE_EDIT_LEFT,
\r
234 LIBWIN32_PREFSIZE_EDIT_WIDTH,
\r
235 max( Label->Top + Label->Height , ButtonConfig->Top
\r
236 + ButtonConfig->Height ) + LIBWIN32_PREFSIZE_VPAD,
\r
237 LIBWIN32_PREFSIZE_CHECKLISTBOX_HEIGHT );
\r
238 CleanCheckListBox->OnClick = CheckListBoxClick;
\r
239 CleanCheckListBox->OnClickCheck = CheckListBoxClickCheck;
\r
240 CleanCheckListBox->Hint = p_config->psz_longtext;
\r
241 CleanCheckListBox->ShowHint = true;
\r
243 /* init up and down buttons */
\r
244 if ( b_multi_plugins )
\r
246 ButtonUp = CreateButton ( this, LIBWIN32_PREFSIZE_LEFT,
\r
247 CleanCheckListBox->Left - LIBWIN32_PREFSIZE_HPAD
\r
248 - LIBWIN32_PREFSIZE_LEFT,
\r
249 CleanCheckListBox->Top + ( CleanCheckListBox->Height
\r
250 - 2*LIBWIN32_PREFSIZE_BUTTON_HEIGHT ) / 3,
\r
251 LIBWIN32_PREFSIZE_BUTTON_HEIGHT,
\r
253 ButtonUp->Enabled = false;
\r
254 ButtonUp->OnClick = ButtonUpClick;
\r
255 ButtonUp->Hint = "Raise the plugin priority";
\r
256 ButtonUp->ShowHint = true;
\r
258 ButtonDown = CreateButton ( this, LIBWIN32_PREFSIZE_LEFT,
\r
259 CleanCheckListBox->Left - LIBWIN32_PREFSIZE_HPAD
\r
260 - LIBWIN32_PREFSIZE_LEFT,
\r
261 CleanCheckListBox->Top + ( CleanCheckListBox->Height
\r
262 - 2*LIBWIN32_PREFSIZE_BUTTON_HEIGHT ) * 2 / 3
\r
263 + LIBWIN32_PREFSIZE_BUTTON_HEIGHT,
\r
264 LIBWIN32_PREFSIZE_BUTTON_HEIGHT,
\r
266 ButtonDown->Enabled = false;
\r
267 ButtonDown->OnClick = ButtonDownClick;
\r
268 ButtonDown->Hint = "Decrease the plugin priority";
\r
269 ButtonDown->ShowHint = true;
\r
278 Height = CleanCheckListBox->Top + CleanCheckListBox->Height
\r
279 + LIBWIN32_PREFSIZE_VPAD;
\r
281 //---------------------------------------------------------------------------
\r
282 void __fastcall TPanelPlugin::CheckListBoxClick( TObject *Sender )
\r
284 module_t *p_parser;
\r
288 /* check that the click is valid (we are on an item, and the click
\r
289 * started on an item */
\r
290 if( CleanCheckListBox->ItemIndex == -1 )
\r
292 if ( ButtonUp != NULL ) ButtonUp->Enabled = false;
\r
293 if ( ButtonDown != NULL ) ButtonDown->Enabled = false;
\r
297 AnsiString Name = ((TObjectString*)CleanCheckListBox->Items->
\r
298 Objects[CleanCheckListBox->ItemIndex])->String().c_str();
\r
302 /* enable up and down buttons */
\r
303 if ( b_multi_plugins && ButtonUp != NULL && ButtonDown != NULL )
\r
305 if ( CleanCheckListBox->ItemIndex == 0 )
\r
306 ButtonUp->Enabled = false; else ButtonUp->Enabled = true;
\r
307 if ( CleanCheckListBox->ItemIndex
\r
308 == CleanCheckListBox->Items->Count - 1 )
\r
309 ButtonDown->Enabled = false; else ButtonDown->Enabled = true;
\r
312 /* look for module 'Name' */
\r
313 list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
\r
315 for( i_index = 0; i_index < list.i_count; i_index++ )
\r
317 p_parser = (module_t *)list.p_values[i_index].p_object ;
\r
319 if( strcmp( p_parser->psz_object_name, Name.c_str() ) == 0 )
\r
321 ModuleSelected = p_parser;
\r
322 ButtonConfig->Enabled =
\r
323 p_parser->i_config_items ? true : false;
\r
329 //---------------------------------------------------------------------------
\r
330 void __fastcall TPanelPlugin::CheckListBoxClickCheck( TObject *Sender )
\r
332 if ( ! b_multi_plugins )
\r
334 /* one item maximum must be checked */
\r
335 if( CleanCheckListBox->Checked[CleanCheckListBox->ItemIndex] )
\r
337 for( int item = 0; item < CleanCheckListBox->Items->Count; item++ )
\r
339 if( item != CleanCheckListBox->ItemIndex )
\r
341 CleanCheckListBox->Checked[item] = false;
\r
347 //---------------------------------------------------------------------------
\r
348 void __fastcall TPanelPlugin::ButtonConfigClick( TObject *Sender )
\r
350 p_intf->p_sys->p_window->
\r
351 CreatePreferences( ModuleSelected->psz_object_name );
\r
353 //---------------------------------------------------------------------------
\r
354 void __fastcall TPanelPlugin::ButtonUpClick( TObject *Sender )
\r
356 if( CleanCheckListBox->ItemIndex != -1 && CleanCheckListBox->ItemIndex > 0 )
\r
358 int Pos = CleanCheckListBox->ItemIndex;
\r
359 CleanCheckListBox->Items->Move ( Pos , Pos - 1 );
\r
360 CleanCheckListBox->ItemIndex = Pos - 1;
\r
361 CheckListBoxClick ( Sender );
\r
364 //---------------------------------------------------------------------------
\r
365 void __fastcall TPanelPlugin::ButtonDownClick( TObject *Sender )
\r
367 if( CleanCheckListBox->ItemIndex != -1
\r
368 && CleanCheckListBox->ItemIndex < CleanCheckListBox->Items->Count - 1 )
\r
370 int Pos = CleanCheckListBox->ItemIndex;
\r
371 CleanCheckListBox->Items->Move ( Pos , Pos + 1 );
\r
372 CleanCheckListBox->ItemIndex = Pos + 1;
\r
373 CheckListBoxClick ( Sender );
\r
376 //---------------------------------------------------------------------------
\r
377 void __fastcall TPanelPlugin::SetValue ( AnsiString Values )
\r
379 int TopChecked = 0;
\r
380 while ( Values.Length() != 0 )
\r
384 int NextValue = Values.Pos ( "," );
\r
385 if ( NextValue == 0 )
\r
387 Value = Values.Trim();
\r
392 Value = Values.SubString(1,NextValue-1).Trim();
\r
393 Values = Values.SubString ( NextValue + 1
\r
394 , Values.Length() - NextValue );
\r
397 if ( Value.Length() > 0 )
\r
399 for ( int i = TopChecked; i < CleanCheckListBox->Items->Count; i++ )
\r
401 if ( ((TObjectString*)CleanCheckListBox->Items->Objects[i])
\r
402 ->String() == Value )
\r
404 CleanCheckListBox->Checked[i] = true;
\r
405 CleanCheckListBox->Items->Move ( i , TopChecked );
\r
412 //---------------------------------------------------------------------------
\r
413 void __fastcall TPanelPlugin::UpdateChanges()
\r
415 AnsiString Name = "";
\r
417 /* find the selected plugin (if any) */
\r
418 for( int item = 0; item < CleanCheckListBox->Items->Count; item++ )
\r
420 if( CleanCheckListBox->Checked[item] )
\r
422 if ( Name.Length() == 0 )
\r
424 Name = ((TObjectString*)CleanCheckListBox->Items->Objects[item])
\r
430 + ((TObjectString*)CleanCheckListBox->Items->Objects[item])
\r
436 config_PutPsz( p_intf, p_config->psz_name,
\r
437 Name.Length() ? Name.c_str() : NULL );
\r
441 /****************************************************************************
\r
442 * Panel for string management
\r
443 ****************************************************************************/
\r
444 __fastcall TPanelString::TPanelString( TComponent* Owner,
\r
445 module_config_t *p_config, intf_thread_t *_p_intf )
\r
446 : TPanelPref( Owner, p_config, _p_intf )
\r
448 /* init description label */
\r
449 AnsiString Text = AnsiString ( p_config->psz_text ) + ":";
\r
450 Label = CreateLabel( this,
\r
451 LIBWIN32_PREFSIZE_LEFT,
\r
452 LIBWIN32_PREFSIZE_WIDTH,
\r
453 LIBWIN32_PREFSIZE_VPAD,
\r
454 LIBWIN32_PREFSIZE_LABEL_HEIGHT,
\r
455 Text.c_str(), true );
\r
458 Edit = CreateEdit( this,
\r
459 LIBWIN32_PREFSIZE_EDIT_LEFT,
\r
460 LIBWIN32_PREFSIZE_EDIT_WIDTH,
\r
461 LIBWIN32_PREFSIZE_VPAD + Label->Height + LIBWIN32_PREFSIZE_VPAD,
\r
462 LIBWIN32_PREFSIZE_EDIT_HEIGHT, "" );
\r
463 vlc_mutex_lock( p_config->p_lock );
\r
464 Edit->Text = p_config->psz_value ? p_config->psz_value : "";
\r
465 vlc_mutex_unlock( p_config->p_lock );
\r
466 Edit->Hint = p_config->psz_longtext;
\r
467 Edit->ShowHint = true;
\r
470 Height = LIBWIN32_PREFSIZE_VPAD + Label->Height + LIBWIN32_PREFSIZE_VPAD
\r
471 + Edit->Height + LIBWIN32_PREFSIZE_VPAD;
\r
473 //---------------------------------------------------------------------------
\r
474 void __fastcall TPanelString::UpdateChanges()
\r
476 config_PutPsz( p_intf, p_config->psz_name,
\r
477 Edit->Text.Length() ? Edit->Text.c_str() : NULL );
\r
481 /****************************************************************************
\r
482 * Panel for integer management
\r
483 ****************************************************************************/
\r
484 __fastcall TPanelInteger::TPanelInteger( TComponent* Owner,
\r
485 module_config_t *p_config, intf_thread_t *_p_intf )
\r
486 : TPanelPref( Owner, p_config, _p_intf )
\r
488 /* init description label */
\r
489 AnsiString Text = AnsiString ( p_config->psz_text ) + ":";
\r
490 Label = CreateLabel( this,
\r
491 LIBWIN32_PREFSIZE_LEFT,
\r
492 LIBWIN32_PREFSIZE_WIDTH - LIBWIN32_PREFSIZE_SPINEDIT_WIDTH
\r
493 - LIBWIN32_PREFSIZE_HPAD,
\r
494 LIBWIN32_PREFSIZE_VPAD,
\r
495 LIBWIN32_PREFSIZE_LABEL_HEIGHT, Text.c_str(), true );
\r
497 /* init spinedit */
\r
498 SpinEdit = CreateSpinEdit( this,
\r
499 LIBWIN32_PREFSIZE_RIGHT - LIBWIN32_PREFSIZE_SPINEDIT_WIDTH,
\r
500 LIBWIN32_PREFSIZE_SPINEDIT_WIDTH,
\r
501 LIBWIN32_PREFSIZE_VPAD,
\r
502 LIBWIN32_PREFSIZE_SPINEDIT_HEIGHT,
\r
503 -1, 100000, p_config->i_value );
\r
504 SpinEdit->Hint = p_config->psz_longtext;
\r
505 SpinEdit->ShowHint = true;
\r
507 /* vertical alignement and panel height */
\r
508 if ( SpinEdit->Height > Label->Height )
\r
510 Label->Top += ( SpinEdit->Height - Label->Height ) / 2;
\r
511 Height = SpinEdit->Top + SpinEdit->Height + LIBWIN32_PREFSIZE_VPAD;
\r
515 SpinEdit->Top += ( Label->Height - SpinEdit->Height ) / 2;
\r
516 Height = Label->Top + Label->Height + LIBWIN32_PREFSIZE_VPAD;
\r
519 //---------------------------------------------------------------------------
\r
520 void __fastcall TPanelInteger::UpdateChanges()
\r
522 /* Warning: we're casting from long to int */
\r
523 config_PutInt( p_intf, p_config->psz_name, (int)SpinEdit->Value );
\r
527 /****************************************************************************
\r
528 * Panel for float management
\r
529 ****************************************************************************/
\r
530 __fastcall TPanelFloat::TPanelFloat( TComponent* Owner,
\r
531 module_config_t *p_config, intf_thread_t *_p_intf )
\r
532 : TPanelPref( Owner, p_config, _p_intf )
\r
534 #define MAX_FLOAT_CHARS 20
\r
535 /* init description label */
\r
536 AnsiString Text = AnsiString( p_config->psz_text ) + ":";
\r
537 Label = CreateLabel( this,
\r
538 LIBWIN32_PREFSIZE_LEFT,
\r
539 LIBWIN32_PREFSIZE_WIDTH,
\r
540 LIBWIN32_PREFSIZE_VPAD,
\r
541 LIBWIN32_PREFSIZE_LABEL_HEIGHT,
\r
542 Text.c_str(), true );
\r
545 char *psz_value = (char *)malloc( MAX_FLOAT_CHARS );
\r
546 snprintf( psz_value, MAX_FLOAT_CHARS, "%f", p_config->f_value );
\r
547 /* we use the spinedit size, to be similar with the integers */
\r
548 Edit = CreateEdit( this,
\r
549 LIBWIN32_PREFSIZE_RIGHT - LIBWIN32_PREFSIZE_SPINEDIT_WIDTH,
\r
550 LIBWIN32_PREFSIZE_SPINEDIT_WIDTH,
\r
551 LIBWIN32_PREFSIZE_VPAD,
\r
552 LIBWIN32_PREFSIZE_SPINEDIT_HEIGHT,
\r
555 Edit->Hint = p_config->psz_longtext;
\r
556 Edit->ShowHint = true;
\r
558 /* vertical alignement and panel height */
\r
559 if ( Edit->Height > Label->Height )
\r
561 Label->Top += ( Edit->Height - Label->Height ) / 2;
\r
562 Height = Edit->Top + Edit->Height + LIBWIN32_PREFSIZE_VPAD;
\r
566 Edit->Top += ( Label->Height - Edit->Height ) / 2;
\r
567 Height = Label->Top + Label->Height + LIBWIN32_PREFSIZE_VPAD;
\r
570 #undef MAX_FLOAT_CHARS
\r
572 //---------------------------------------------------------------------------
\r
573 void __fastcall TPanelFloat::UpdateChanges()
\r
575 /* Warning: we're casting from double to float */
\r
576 config_PutFloat( p_intf, p_config->psz_name, atof( Edit->Text.c_str() ) );
\r
580 /****************************************************************************
\r
581 * Panel for boolean management
\r
582 ****************************************************************************/
\r
583 __fastcall TPanelBool::TPanelBool( TComponent* Owner,
\r
584 module_config_t *p_config, intf_thread_t *_p_intf )
\r
585 : TPanelPref( Owner, p_config, _p_intf )
\r
587 /* init checkbox */
\r
588 CheckBox = CreateCheckBox( this,
\r
589 LIBWIN32_PREFSIZE_LEFT,
\r
590 LIBWIN32_PREFSIZE_WIDTH,
\r
591 LIBWIN32_PREFSIZE_VPAD,
\r
592 LIBWIN32_PREFSIZE_CHECKBOX_HEIGHT, p_config->psz_text );
\r
593 CheckBox->Checked = p_config->i_value;
\r
594 CheckBox->Hint = p_config->psz_longtext;
\r
595 CheckBox->ShowHint = true;
\r
598 Height = LIBWIN32_PREFSIZE_VPAD + CheckBox->Height + LIBWIN32_PREFSIZE_VPAD;
\r
600 //---------------------------------------------------------------------------
\r
601 void __fastcall TPanelBool::UpdateChanges()
\r
603 config_PutInt( p_intf, p_config->psz_name, CheckBox->Checked ? 1 : 0 );
\r
607 /****************************************************************************
\r
608 * Callbacks for the dialog
\r
609 ****************************************************************************/
\r
610 __fastcall TPreferencesDlg::TPreferencesDlg( TComponent* Owner,
\r
611 intf_thread_t *_p_intf ) : TForm( Owner )
\r
614 Icon = p_intf->p_sys->p_window->Icon;
\r
615 Application->HintHidePause = 0x1000000;
\r
616 HintWindowClass = __classid ( TNarrowHintWindow );
\r
617 /* prevent the form from being resized horizontally */
\r
618 Constraints->MinWidth = Width;
\r
619 Constraints->MaxWidth = Width;
\r
621 //---------------------------------------------------------------------------
\r
622 void __fastcall TPreferencesDlg::FormClose( TObject *Sender,
\r
623 TCloseAction &Action )
\r
629 /****************************************************************************
\r
630 * CreateConfigDialog: dynamically creates the configuration dialog
\r
631 * box from all the configuration data provided by the selected module.
\r
632 ****************************************************************************/
\r
633 #define ADD_PANEL \
\r
635 Panel = new TPanel( this ); \
\r
636 Panel->Parent = ScrollBox; \
\r
637 Panel->Caption = ""; \
\r
638 Panel->BevelOuter = bvNone; \
\r
639 Panel->Height = 12; \
\r
642 void __fastcall TPreferencesDlg::CreateConfigDialog( char *psz_module_name )
\r
644 module_t *p_parser;
\r
648 module_config_t *p_item;
\r
649 int i_pages, i_ctrl;
\r
651 TTabSheet *TabSheet;
\r
652 TScrollBox *ScrollBox = NULL;
\r
654 TPanelPlugin *PanelPlugin;
\r
655 TPanelString *PanelString;
\r
656 TPanelInteger *PanelInteger;
\r
657 TPanelFloat *PanelFloat;
\r
658 TPanelBool *PanelBool;
\r
660 /* Look for the selected module */
\r
661 list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
\r
663 for( i_index = 0; i_index < list.i_count; i_index++ )
\r
665 p_parser = (module_t *)list.p_values[i_index].p_object ;
\r
667 if( psz_module_name
\r
668 && !strcmp( psz_module_name, p_parser->psz_object_name ) )
\r
673 if( !p_parser || i_index == list.i_count )
\r
675 vlc_list_release( &list );
\r
680 * We found it, now we can start building its configuration interface
\r
683 /* Enumerate config options and add corresponding config boxes */
\r
684 p_item = p_parser->p_config;
\r
687 switch( p_item->i_type )
\r
689 case CONFIG_HINT_CATEGORY:
\r
691 /* create a new tabsheet. */
\r
692 TabSheet = new TTabSheet( this );
\r
693 TabSheet->PageControl = PageControlPref;
\r
694 TabSheet->Caption = p_item->psz_text;
\r
695 TabSheet->Visible = true;
\r
697 /* pack a scrollbox into the tabsheet */
\r
698 ScrollBox = new TScrollBox( this );
\r
699 ScrollBox->Parent = TabSheet;
\r
700 ScrollBox->Align = alClient;
\r
701 ScrollBox->BorderStyle = bsNone;
\r
702 ScrollBox->HorzScrollBar->Tracking = true;
\r
703 ScrollBox->VertScrollBar->Tracking = true;
\r
705 /* add a panel as top margin */
\r
710 case CONFIG_ITEM_MODULE:
\r
712 /* add new panel for the config option */
\r
713 PanelPlugin = new TPanelPlugin( this, p_item, p_intf, true );
\r
714 PanelPlugin->Parent = ScrollBox;
\r
716 /* Look for valid modules */
\r
717 for( i_index = 0; i_index < list.i_count; i_index++ )
\r
719 p_parser = (module_t *)list.p_values[i_index].p_object ;
\r
721 if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
\r
723 AnsiString ModuleDesc;
\r
724 if ( p_parser->psz_longname != NULL ) {
\r
725 ModuleDesc = AnsiString( p_parser->psz_longname ) +
\r
726 " (" + AnsiString( p_parser->psz_object_name ) +
\r
730 ModuleDesc = AnsiString( p_parser->psz_object_name );
\r
732 PanelPlugin->CleanCheckListBox->Items->AddObject(
\r
733 ModuleDesc.c_str(),
\r
734 new TObjectString( p_parser->psz_object_name ) );
\r
738 /* check relevant boxes */
\r
739 PanelPlugin->SetValue ( AnsiString ( p_item->psz_value ) );
\r
743 case CONFIG_ITEM_FILE:
\r
745 case CONFIG_ITEM_STRING:
\r
747 /* add new panel for the config option */
\r
748 PanelString = new TPanelString( this, p_item, p_intf );
\r
749 PanelString->Parent = ScrollBox;
\r
753 case CONFIG_ITEM_INTEGER:
\r
755 /* add new panel for the config option */
\r
756 PanelInteger = new TPanelInteger( this, p_item, p_intf );
\r
757 PanelInteger->Parent = ScrollBox;
\r
761 case CONFIG_ITEM_FLOAT:
\r
763 /* add new panel for the config option */
\r
764 PanelFloat = new TPanelFloat( this, p_item, p_intf );
\r
765 PanelFloat->Parent = ScrollBox;
\r
769 case CONFIG_ITEM_BOOL:
\r
771 /* add new panel for the config option */
\r
772 PanelBool = new TPanelBool( this, p_item, p_intf );
\r
773 PanelBool->Parent = ScrollBox;
\r
777 msg_Warn( p_intf, "unknown config type: %i", p_item->i_type );
\r
783 while( p_item->i_type != CONFIG_HINT_END );
\r
785 /* Reorder panels inside the tabsheets */
\r
786 for( i_pages = 0; i_pages < PageControlPref->PageCount; i_pages++ )
\r
788 /* get scrollbox from the tabsheet */
\r
789 ScrollBox = (TScrollBox *)PageControlPref->Pages[i_pages]->Controls[0];
\r
791 /* add a panel as bottom margin */
\r
794 for( i_ctrl = ScrollBox->ControlCount - 1; i_ctrl >= 0 ; i_ctrl-- )
\r
796 ScrollBox->Controls[i_ctrl]->Align = alTop;
\r
800 vlc_list_release( &list );
\r
802 /* set active tabsheet
\r
803 * FIXME: i don't know why, but both lines are necessary */
\r
804 PageControlPref->ActivePageIndex = 1;
\r
805 PageControlPref->ActivePageIndex = 0;
\r
808 //---------------------------------------------------------------------------
\r
809 void __fastcall TPreferencesDlg::ButtonOkClick( TObject *Sender )
\r
811 ButtonApplyClick( Sender );
\r
814 //---------------------------------------------------------------------------
\r
815 void __fastcall TPreferencesDlg::ButtonApplyClick( TObject *Sender )
\r
817 TScrollBox *ScrollBox;
\r
821 for( i = 0; i < PageControlPref->PageCount; i++ )
\r
823 /* get scrollbox from the tabsheet */
\r
824 ScrollBox = (TScrollBox *)PageControlPref->Pages[i]->Controls[0];
\r
826 for( j = 0; j < ScrollBox->ControlCount ; j++ )
\r
828 /* skip the panels */
\r
829 if( ScrollBox->Controls[j]->InheritsFrom( __classid( TPanelPref ) ) )
\r
831 Panel = (TPanelPref *)ScrollBox->Controls[j];
\r
832 Panel->UpdateChanges();
\r
837 //---------------------------------------------------------------------------
\r
838 void __fastcall TPreferencesDlg::ButtonSaveClick( TObject *Sender )
\r
840 ButtonApplyClick( Sender );
\r
841 config_SaveConfigFile( p_intf, NULL );
\r
843 //---------------------------------------------------------------------------
\r
844 void __fastcall TPreferencesDlg::ButtonCancelClick( TObject *Sender )
\r
848 //---------------------------------------------------------------------------
\r