]> git.sesse.net Git - vlc/blob - modules/gui/win32/preferences.cpp
- Enterely new layout for the preference window of the native win32
[vlc] / modules / gui / win32 / preferences.cpp
1 /*****************************************************************************\r
2  * preferences.cpp: the "Preferences" dialog box\r
3  *****************************************************************************\r
4  * Copyright (C) 2002 VideoLAN\r
5  *\r
6  * Authors: Olivier Teuliere <ipkiss@via.ecp.fr>\r
7  *          Boris Dores <babal@via.ecp.fr>\r
8  *\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
13  *\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
18  *\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
23 \r
24 #include <vcl.h>\r
25 #pragma hdrstop\r
26 \r
27 #include <stdlib.h>                                      /* malloc(), free() */\r
28 #include <string.h>                                                /* strcmp */\r
29 \r
30 #include <vlc/vlc.h>\r
31 #include <vlc/intf.h>\r
32 \r
33 #include "preferences.h"\r
34 #include "win32_common.h"\r
35 \r
36 //---------------------------------------------------------------------------\r
37 //#pragma package(smart_init)\r
38 #pragma link "CSPIN"\r
39 #pragma resource "*.dfm"\r
40 \r
41 extern intf_thread_t *p_intfGlobal;\r
42 \r
43 /****************************************************************************\r
44  * A THintWindow with a limited width\r
45  ****************************************************************************/\r
46 void __fastcall TNarrowHintWindow::ActivateHint(const Windows::TRect &Rect,\r
47     const System::AnsiString AHint)\r
48 {\r
49     TRect NarrowRect = CalcHintRect ( 300 , AHint , NULL );\r
50     NarrowRect.Left = Rect.Left;\r
51     NarrowRect.Top = Rect.Top;\r
52     NarrowRect.Right += Rect.Left;\r
53     NarrowRect.Bottom += Rect.Top;\r
54     THintWindow::ActivateHint ( NarrowRect , AHint );\r
55 }\r
56 \r
57 \r
58 /****************************************************************************\r
59  * Just a wrapper to embed an AnsiString into a TObject\r
60  ****************************************************************************/\r
61 __fastcall TObjectString::TObjectString(char * String)\r
62 {\r
63     FString = AnsiString(String);\r
64 }\r
65 //---------------------------------------------------------------------------\r
66 AnsiString __fastcall TObjectString::String()\r
67 {\r
68     return FString;\r
69 }\r
70 \r
71 \r
72 /****************************************************************************\r
73  * A TCheckListBox that automatically disposes any TObject\r
74  * associated with the string items\r
75  ****************************************************************************/\r
76 __fastcall TCleanCheckListBox::~TCleanCheckListBox()\r
77 {\r
78     for ( int i = 0 ; i < Items->Count ; i++ )\r
79     {\r
80         if ( Items->Objects[i] != NULL ) delete Items->Objects[i];\r
81     }\r
82 }\r
83 \r
84 \r
85 /****************************************************************************\r
86  * Functions to help components creation\r
87  ****************************************************************************/\r
88 __fastcall TPanelPref::TPanelPref( TComponent* Owner,\r
89             module_config_t *p_config_arg ) : TPanel( Owner )\r
90 {\r
91     p_config = p_config_arg;\r
92     BevelInner = bvNone;\r
93     BevelOuter = bvNone;\r
94     BorderStyle = bsNone;\r
95 }\r
96 //---------------------------------------------------------------------------\r
97 TCleanCheckListBox * __fastcall TPanelPref::CreateCleanCheckListBox(\r
98     TWinControl *Parent, int Left, int Width, int Top, int Height )\r
99 {\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
107 }\r
108 //---------------------------------------------------------------------------\r
109 TButton * __fastcall TPanelPref::CreateButton( TWinControl *Parent,\r
110             int Left, int Width, int Top, int Height, AnsiString Caption )\r
111 {\r
112     TButton *Button = new TButton( Parent );\r
113     Button->Parent = Parent;\r
114     Button->Left = Left;\r
115     Button->Width = Width;\r
116     Button->Top = Top;\r
117     Button->Height = Height;\r
118     Button->Caption = Caption;\r
119     return Button;\r
120 }\r
121 //---------------------------------------------------------------------------\r
122 TCheckBox * __fastcall TPanelPref::CreateCheckBox( TWinControl *Parent,\r
123             int Left, int Width, int Top, int Height, AnsiString Caption )\r
124 {\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
132     return CheckBox;\r
133 }\r
134 //---------------------------------------------------------------------------\r
135 TLabel * __fastcall TPanelPref::CreateLabel( TWinControl *Parent,\r
136             int Left, int Width, int Top, int Height, AnsiString Caption,\r
137             bool WordWrap )\r
138 {\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
144     Label->Top = Top;\r
145     Label->Height = Height;\r
146     Label->WordWrap = WordWrap;\r
147     return Label;\r
148 }\r
149 //---------------------------------------------------------------------------\r
150 TEdit * __fastcall TPanelPref::CreateEdit( TWinControl *Parent,\r
151             int Left, int Width, int Top, int Height, AnsiString Text )\r
152 {\r
153     TEdit *Edit = new TEdit( Parent );\r
154     Edit->Parent = Parent;\r
155     Edit->Left = Left;\r
156     Edit->Width = Width;\r
157     Edit->Top = Top;\r
158     Edit->Height = Height;\r
159     Edit->Text = Text;\r
160     return Edit;\r
161 }\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
166 {\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
176     return SpinEdit;\r
177 }\r
178 //---------------------------------------------------------------------------\r
179 void __fastcall TPanelPref::UpdateChanges()\r
180 {\r
181 }\r
182 \r
183 #define LIBWIN32_PREFSIZE_VPAD                4\r
184 #define LIBWIN32_PREFSIZE_HPAD                4\r
185 #define LIBWIN32_PREFSIZE_LEFT                16\r
186 #define LIBWIN32_PREFSIZE_EDIT_LEFT           (LIBWIN32_PREFSIZE_LEFT+32)\r
187 #define LIBWIN32_PREFSIZE_WIDTH               375\r
188 #define LIBWIN32_PREFSIZE_EDIT_WIDTH          (LIBWIN32_PREFSIZE_WIDTH-32)\r
189 #define LIBWIN32_PREFSIZE_BUTTON_WIDTH        150\r
190 #define LIBWIN32_PREFSIZE_SPINEDIT_WIDTH      100\r
191 #define LIBWIN32_PREFSIZE_RIGHT               (LIBWIN32_PREFSIZE_LEFT+LIBWIN32_PREFSIZE_WIDTH)\r
192 #define LIBWIN32_PREFSIZE_BUTTON_HEIGHT       25\r
193 #define LIBWIN32_PREFSIZE_LABEL_HEIGHT        26\r
194 #define LIBWIN32_PREFSIZE_CHECKLISTBOX_HEIGHT 120\r
195 #define LIBWIN32_PREFSIZE_EDIT_HEIGHT         21\r
196 #define LIBWIN32_PREFSIZE_CHECKBOX_HEIGHT     17\r
197 #define LIBWIN32_PREFSIZE_SPINEDIT_HEIGHT     21\r
198 \r
199 /****************************************************************************\r
200  * Panel for module management\r
201  ****************************************************************************/\r
202 __fastcall TPanelPlugin::TPanelPlugin( TComponent* Owner,\r
203             module_config_t *p_config ) : TPanelPref( Owner, p_config )\r
204 {\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
211             "Configure..." );\r
212     ButtonConfig->Enabled = false;\r
213     ButtonConfig->OnClick = ButtonConfigClick;\r
214 \r
215     /* init label */\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
224 \r
225     /* vertical alignement */\r
226     if ( ButtonConfig->Height > Label->Height )\r
227         Label->Top += ( ButtonConfig->Height - Label->Height ) / 2;\r
228     else\r
229         ButtonConfig->Top += ( Label->Height - ButtonConfig->Height ) / 2;\r
230 \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
242 \r
243     /* panel height */\r
244     Height = CleanCheckListBox->Top + CleanCheckListBox->Height\r
245             + LIBWIN32_PREFSIZE_VPAD;\r
246 };\r
247 //---------------------------------------------------------------------------\r
248 void __fastcall TPanelPlugin::CheckListBoxClick( TObject *Sender )\r
249 {\r
250     module_t **pp_parser;\r
251     vlc_list_t *p_list;\r
252 \r
253     /* check that the click is valid (we are on an item, and the click\r
254      * started on an item */\r
255     if( CleanCheckListBox->ItemIndex == -1 )\r
256         return;\r
257 \r
258     AnsiString Name = ((TObjectString*)CleanCheckListBox->Items->\r
259         Objects[CleanCheckListBox->ItemIndex])->String().c_str();\r
260     if( Name == "" )\r
261         return;\r
262 \r
263     /* look for module 'Name' */\r
264     p_list = vlc_list_find( p_intfGlobal, VLC_OBJECT_MODULE, FIND_ANYWHERE );\r
265 \r
266     for( pp_parser = (module_t **)p_list->pp_objects ;\r
267          *pp_parser ;\r
268          pp_parser++ )\r
269     {\r
270         if( strcmp( (*pp_parser)->psz_object_name, Name.c_str() ) == 0 )\r
271         {\r
272             ModuleSelected = (*pp_parser);\r
273             ButtonConfig->Enabled =\r
274                 (*pp_parser)->i_config_items ? true : false;\r
275 \r
276             break;\r
277         }\r
278     }\r
279 }\r
280 //---------------------------------------------------------------------------\r
281 void __fastcall TPanelPlugin::CheckListBoxClickCheck( TObject *Sender )\r
282 {\r
283     /* one item maximum must be checked */\r
284     if( CleanCheckListBox->Checked[CleanCheckListBox->ItemIndex] )\r
285     {\r
286         for( int item = 0; item < CleanCheckListBox->Items->Count; item++ )\r
287         {\r
288             if( item != CleanCheckListBox->ItemIndex )\r
289             {\r
290                 CleanCheckListBox->Checked[item] = false;\r
291             }\r
292         }\r
293     }\r
294 }\r
295 //---------------------------------------------------------------------------\r
296 void __fastcall TPanelPlugin::ButtonConfigClick( TObject *Sender )\r
297 {\r
298     p_intfGlobal->p_sys->p_window->\r
299                         CreatePreferences( ModuleSelected->psz_object_name );\r
300 }\r
301 //---------------------------------------------------------------------------\r
302 void __fastcall TPanelPlugin::UpdateChanges()\r
303 {\r
304     AnsiString Name = "";\r
305 \r
306     /* find the selected plugin (if any) */\r
307     for( int item = 0; item < CleanCheckListBox->Items->Count; item++ )\r
308     {\r
309         if( CleanCheckListBox->Checked[item] )\r
310         {\r
311             Name = ((TObjectString*)CleanCheckListBox->Items->Objects[item])\r
312                    ->String().c_str();\r
313             break;\r
314         }\r
315     }\r
316 \r
317     /* XXX: Necessary, since c_str() returns only a temporary pointer... */\r
318     free( p_config->psz_value );\r
319     p_config->psz_value = (char *)malloc( Name.Length() + 1 );\r
320     strcpy( p_config->psz_value, Name.c_str() );\r
321 }\r
322 \r
323 \r
324 /****************************************************************************\r
325  * Panel for string management\r
326  ****************************************************************************/\r
327 __fastcall TPanelString::TPanelString( TComponent* Owner,\r
328             module_config_t *p_config ) : TPanelPref( Owner, p_config )\r
329 {\r
330     /* init description label */\r
331     AnsiString Text = AnsiString ( p_config->psz_text ) + ":";\r
332     Label = CreateLabel( this,\r
333             LIBWIN32_PREFSIZE_LEFT,\r
334             LIBWIN32_PREFSIZE_WIDTH,\r
335             LIBWIN32_PREFSIZE_VPAD,\r
336             LIBWIN32_PREFSIZE_LABEL_HEIGHT,\r
337             Text.c_str(), true );\r
338 \r
339     /* init edit */\r
340     Edit = CreateEdit( this,\r
341             LIBWIN32_PREFSIZE_EDIT_LEFT,\r
342             LIBWIN32_PREFSIZE_EDIT_WIDTH,\r
343             LIBWIN32_PREFSIZE_VPAD + Label->Height + LIBWIN32_PREFSIZE_VPAD,\r
344             LIBWIN32_PREFSIZE_EDIT_HEIGHT, "" );\r
345     vlc_mutex_lock( p_config->p_lock );\r
346     Edit->Text = p_config->psz_value ? p_config->psz_value : "";\r
347     vlc_mutex_unlock( p_config->p_lock );\r
348     Edit->Hint = p_config->psz_longtext;\r
349     Edit->ShowHint = true;\r
350 \r
351     /* panel height */\r
352     Height = LIBWIN32_PREFSIZE_VPAD + Label->Height + LIBWIN32_PREFSIZE_VPAD\r
353             + Edit->Height + LIBWIN32_PREFSIZE_VPAD;\r
354 };\r
355 //---------------------------------------------------------------------------\r
356 void __fastcall TPanelString::UpdateChanges()\r
357 {\r
358     /* XXX: Necessary, since c_str() returns only a temporary pointer... */\r
359     free( p_config->psz_value );\r
360     p_config->psz_value = (char *)malloc( Edit->Text.Length() + 1 );\r
361     strcpy( p_config->psz_value, Edit->Text.c_str() );\r
362 }\r
363 \r
364 \r
365 /****************************************************************************\r
366  * Panel for integer management\r
367  ****************************************************************************/\r
368 __fastcall TPanelInteger::TPanelInteger( TComponent* Owner,\r
369             module_config_t *p_config ) : TPanelPref( Owner, p_config )\r
370 {\r
371     /* init description label */\r
372     AnsiString Text = AnsiString ( p_config->psz_text ) + ":";\r
373     Label = CreateLabel( this,\r
374             LIBWIN32_PREFSIZE_LEFT,\r
375             LIBWIN32_PREFSIZE_WIDTH - LIBWIN32_PREFSIZE_SPINEDIT_WIDTH\r
376              - LIBWIN32_PREFSIZE_HPAD,\r
377             LIBWIN32_PREFSIZE_VPAD,\r
378             LIBWIN32_PREFSIZE_LABEL_HEIGHT, Text.c_str(), true );\r
379 \r
380     /* init spinedit */\r
381     SpinEdit = CreateSpinEdit( this,\r
382             LIBWIN32_PREFSIZE_RIGHT - LIBWIN32_PREFSIZE_SPINEDIT_WIDTH,\r
383             LIBWIN32_PREFSIZE_SPINEDIT_WIDTH,\r
384             LIBWIN32_PREFSIZE_VPAD,\r
385             LIBWIN32_PREFSIZE_SPINEDIT_HEIGHT,\r
386             -1, 100000, p_config->i_value );\r
387     SpinEdit->Hint = p_config->psz_longtext;\r
388     SpinEdit->ShowHint = true;\r
389 \r
390     /* vertical alignement and panel height */\r
391     if ( SpinEdit->Height > Label->Height )\r
392     {\r
393         Label->Top += ( SpinEdit->Height - Label->Height ) / 2;\r
394         Height = SpinEdit->Top + SpinEdit->Height + LIBWIN32_PREFSIZE_VPAD;\r
395     }\r
396     else\r
397     {\r
398         SpinEdit->Top += ( Label->Height - SpinEdit->Height ) / 2;\r
399         Height = Label->Top + Label->Height + LIBWIN32_PREFSIZE_VPAD;\r
400     }\r
401 };\r
402 //---------------------------------------------------------------------------\r
403 void __fastcall TPanelInteger::UpdateChanges()\r
404 {\r
405     /* Warning: we're casting from long to int */\r
406     p_config->i_value = (int)SpinEdit->Value;\r
407 }\r
408 \r
409 \r
410 /****************************************************************************\r
411  * Panel for boolean management\r
412  ****************************************************************************/\r
413 __fastcall TPanelBool::TPanelBool( TComponent* Owner,\r
414             module_config_t *p_config ) : TPanelPref( Owner, p_config )\r
415 {\r
416     /* init checkbox */\r
417     CheckBox = CreateCheckBox( this,\r
418             LIBWIN32_PREFSIZE_LEFT,\r
419             LIBWIN32_PREFSIZE_WIDTH,\r
420             LIBWIN32_PREFSIZE_VPAD,\r
421             LIBWIN32_PREFSIZE_CHECKBOX_HEIGHT, p_config->psz_text );\r
422     CheckBox->Checked = p_config->i_value;\r
423     CheckBox->Hint = p_config->psz_longtext;\r
424     CheckBox->ShowHint = true;\r
425 \r
426     /* panel height */\r
427     Height = LIBWIN32_PREFSIZE_VPAD + CheckBox->Height + LIBWIN32_PREFSIZE_VPAD;\r
428 };\r
429 //---------------------------------------------------------------------------\r
430 void __fastcall TPanelBool::UpdateChanges()\r
431 {\r
432     p_config->i_value = CheckBox->Checked ? 1 : 0;\r
433 }\r
434 \r
435 \r
436 /****************************************************************************\r
437  * Callbacks for the dialog\r
438  ****************************************************************************/\r
439 __fastcall TPreferencesDlg::TPreferencesDlg( TComponent* Owner )\r
440         : TForm( Owner )\r
441 {\r
442     Icon = p_intfGlobal->p_sys->p_window->Icon;\r
443     Application->HintHidePause = 0x1000000;\r
444     HintWindowClass = __classid ( TNarrowHintWindow );\r
445     /* prevent the form from being resized horizontally */\r
446     Constraints->MinWidth = Width;\r
447     Constraints->MaxWidth = Width;\r
448 }\r
449 //---------------------------------------------------------------------------\r
450 void __fastcall TPreferencesDlg::FormClose( TObject *Sender,\r
451       TCloseAction &Action )\r
452 {\r
453     Action = caHide;\r
454 }\r
455 \r
456 \r
457 /****************************************************************************\r
458  * CreateConfigDialog: dynamically creates the configuration dialog\r
459  * box from all the configuration data provided by the selected module.\r
460  ****************************************************************************/\r
461 #define ADD_PANEL                               \\r
462 {                                               \\r
463             Panel = new TPanel( this );         \\r
464             Panel->Parent = ScrollBox;          \\r
465             Panel->Caption = "";                \\r
466             Panel->BevelOuter = bvNone;         \\r
467             Panel->Height = 12;                 \\r
468 }\r
469 \r
470 void __fastcall TPreferencesDlg::CreateConfigDialog( char *psz_module_name )\r
471 {\r
472     module_t          **pp_parser;\r
473     vlc_list_t         *p_list;\r
474 \r
475     module_config_t    *p_item;\r
476     int                 i_pages, i_ctrl;\r
477 \r
478     TTabSheet          *TabSheet;\r
479     TScrollBox         *ScrollBox;\r
480     TPanel             *Panel;\r
481     TPanelPlugin       *PanelPlugin;\r
482     TPanelString       *PanelString;\r
483     TPanelInteger      *PanelInteger;\r
484     TPanelBool         *PanelBool;\r
485 \r
486     /* Look for the selected module */\r
487     p_list = vlc_list_find( p_intfGlobal, VLC_OBJECT_MODULE, FIND_ANYWHERE );\r
488 \r
489     for( pp_parser = (module_t **)p_list->pp_objects ;\r
490          *pp_parser ;\r
491          pp_parser++ )\r
492     {\r
493         if( psz_module_name\r
494              && !strcmp( psz_module_name, (*pp_parser)->psz_object_name ) )\r
495         {\r
496             break;\r
497         }\r
498     }\r
499     if( !(*pp_parser) )\r
500     {\r
501         vlc_list_release( p_list );\r
502         return;\r
503     }\r
504 \r
505     /*\r
506      * We found it, now we can start building its configuration interface\r
507      */\r
508 \r
509     /* Enumerate config options and add corresponding config boxes */\r
510     p_item = (*pp_parser)->p_config;\r
511     if( p_item ) do\r
512     {\r
513         switch( p_item->i_type )\r
514         {\r
515         case CONFIG_HINT_CATEGORY:\r
516 \r
517             /* create a new tabsheet. */\r
518             TabSheet = new TTabSheet( this );\r
519             TabSheet->PageControl = PageControlPref;\r
520             TabSheet->Caption = p_item->psz_text;\r
521             TabSheet->Visible = true;\r
522 \r
523             /* pack a scrollbox into the tabsheet */\r
524             ScrollBox = new TScrollBox( this );\r
525             ScrollBox->Parent = TabSheet;\r
526             ScrollBox->Align = alClient;\r
527             ScrollBox->BorderStyle = bsNone;\r
528             ScrollBox->HorzScrollBar->Tracking = true;\r
529             ScrollBox->VertScrollBar->Tracking = true;\r
530 \r
531             /* add a panel as top margin */\r
532             ADD_PANEL;\r
533 \r
534             break;\r
535 \r
536         case CONFIG_ITEM_MODULE:\r
537 \r
538             /* add new panel for the config option */\r
539             PanelPlugin = new TPanelPlugin( this, p_item );\r
540             PanelPlugin->Parent = ScrollBox;\r
541 \r
542             /* Look for valid modules */\r
543             pp_parser = (module_t **)p_list->pp_objects;\r
544 \r
545             for( ; *pp_parser ; pp_parser++ )\r
546             {\r
547                 if( !strcmp( (*pp_parser)->psz_capability, p_item->psz_type ) )\r
548                 {\r
549                     AnsiString ModuleDesc;\r
550                     if ( (*pp_parser)->psz_longname != NULL ) {\r
551                         ModuleDesc = AnsiString((*pp_parser)->psz_longname) +\r
552                             " (" + AnsiString((*pp_parser)->psz_object_name) +\r
553                             ")";\r
554                     }\r
555                     else\r
556                         ModuleDesc = AnsiString((*pp_parser)->psz_object_name);\r
557 \r
558                     int item = PanelPlugin->CleanCheckListBox->Items->AddObject(\r
559                         ModuleDesc.c_str(),\r
560                         new TObjectString((*pp_parser)->psz_object_name) );\r
561 \r
562                     /* check the box if it's the default module */\r
563                     AnsiString Name = p_item->psz_value ?\r
564                         p_item->psz_value : "";\r
565                     if( !strcmp( (*pp_parser)->psz_object_name, Name.c_str()) )\r
566                     {\r
567                         PanelPlugin->CleanCheckListBox->Checked[item] = true;\r
568                     }\r
569                 }\r
570             }\r
571 \r
572             break;\r
573 \r
574         case CONFIG_ITEM_FILE:\r
575 \r
576         case CONFIG_ITEM_STRING:\r
577 \r
578             /* add new panel for the config option */\r
579             PanelString = new TPanelString( this, p_item );\r
580             PanelString->Parent = ScrollBox;\r
581 \r
582             break;\r
583 \r
584         case CONFIG_ITEM_INTEGER:\r
585 \r
586             /* add new panel for the config option */\r
587             PanelInteger = new TPanelInteger( this, p_item );\r
588             PanelInteger->Parent = ScrollBox;\r
589 \r
590             break;\r
591 \r
592         case CONFIG_ITEM_BOOL:\r
593 \r
594             /* add new panel for the config option */\r
595             PanelBool = new TPanelBool( this, p_item );\r
596             PanelBool->Parent = ScrollBox;\r
597 \r
598             break;\r
599         }\r
600 \r
601         p_item++;\r
602     }\r
603     while( p_item->i_type != CONFIG_HINT_END );\r
604 \r
605     /* Reorder panels inside the tabsheets */\r
606     for( i_pages = 0; i_pages < PageControlPref->PageCount; i_pages++ )\r
607     {\r
608         /* get scrollbox from the tabsheet */\r
609         ScrollBox = (TScrollBox *)PageControlPref->Pages[i_pages]->Controls[0];\r
610 \r
611         /* add a panel as bottom margin */\r
612         ADD_PANEL;\r
613 \r
614         for( i_ctrl = ScrollBox->ControlCount - 1; i_ctrl >= 0 ; i_ctrl-- )\r
615         {\r
616             ScrollBox->Controls[i_ctrl]->Align = alTop;\r
617         }\r
618     }\r
619 \r
620     vlc_list_release( p_list );\r
621 \r
622     /* set active tabsheet\r
623      * FIXME: i don't know why, but both lines are necessary */\r
624     PageControlPref->ActivePageIndex = 1;\r
625     PageControlPref->ActivePageIndex = 0;\r
626 }\r
627 #undef ADD_PANEL\r
628 //---------------------------------------------------------------------------\r
629 void __fastcall TPreferencesDlg::ButtonOkClick( TObject *Sender )\r
630 {\r
631     ButtonApplyClick( Sender );\r
632     Hide();\r
633 }\r
634 //---------------------------------------------------------------------------\r
635 void __fastcall TPreferencesDlg::ButtonApplyClick( TObject *Sender )\r
636 {\r
637     TScrollBox *ScrollBox;\r
638     TPanelPref *Panel;\r
639     int i, j;\r
640 \r
641     for( i = 0; i < PageControlPref->PageCount; i++ )\r
642     {\r
643         /* get scrollbox from the tabsheet */\r
644         ScrollBox = (TScrollBox *)PageControlPref->Pages[i]->Controls[0];\r
645 \r
646         for( j = 0; j < ScrollBox->ControlCount ; j++ )\r
647         {\r
648             /* skip the panels */\r
649             if( ScrollBox->Controls[j]->InheritsFrom( __classid( TPanelPref ) ) )\r
650             {\r
651                 Panel = (TPanelPref *)ScrollBox->Controls[j];\r
652                 Panel->UpdateChanges();\r
653                 SaveValue( Panel->p_config );\r
654             }\r
655         }\r
656     }\r
657 }\r
658 //---------------------------------------------------------------------------\r
659 void __fastcall TPreferencesDlg::ButtonSaveClick( TObject *Sender )\r
660 {\r
661     ButtonApplyClick( Sender );\r
662     config_SaveConfigFile( p_intfGlobal, NULL );\r
663 }\r
664 //---------------------------------------------------------------------------\r
665 void __fastcall TPreferencesDlg::ButtonCancelClick( TObject *Sender )\r
666 {\r
667     Hide();\r
668 }\r
669 //---------------------------------------------------------------------------\r
670 void __fastcall TPreferencesDlg::SaveValue( module_config_t *p_config )\r
671 {\r
672     switch( p_config->i_type )\r
673     {\r
674         case CONFIG_ITEM_STRING:\r
675         case CONFIG_ITEM_FILE:\r
676         case CONFIG_ITEM_MODULE:\r
677             config_PutPsz( p_intfGlobal, p_config->psz_name,\r
678                            *p_config->psz_value ? p_config->psz_value : NULL );\r
679             break;\r
680         case CONFIG_ITEM_INTEGER:\r
681         case CONFIG_ITEM_BOOL:\r
682             config_PutInt( p_intfGlobal, p_config->psz_name,\r
683                            p_config->i_value );\r
684             break;\r
685     }\r
686 }\r
687 //---------------------------------------------------------------------------\r
688 \r