preferences.cpp 24.6 KB
Newer Older
1 2 3 4 5 6
/*****************************************************************************
 * preferences.cpp: the "Preferences" dialog box
 *****************************************************************************
 * Copyright (C) 2002 VideoLAN
 *
 * Authors: Olivier Teuliere <ipkiss@via.ecp.fr>
7
 *          Boris Dores <babal@via.ecp.fr>
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

#include <vcl.h>
#pragma hdrstop

#include <stdlib.h>                                      /* malloc(), free() */
#include <string.h>                                                /* strcmp */

#include <vlc/vlc.h>
#include <vlc/intf.h>

#include "preferences.h"
#include "win32_common.h"

//---------------------------------------------------------------------------
//#pragma package(smart_init)
#pragma link "CSPIN"
#pragma resource "*.dfm"

41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
/****************************************************************************
 * A THintWindow with a limited width
 ****************************************************************************/
void __fastcall TNarrowHintWindow::ActivateHint(const Windows::TRect &Rect,
    const System::AnsiString AHint)
{
    TRect NarrowRect = CalcHintRect ( 300 , AHint , NULL );
    NarrowRect.Left = Rect.Left;
    NarrowRect.Top = Rect.Top;
    NarrowRect.Right += Rect.Left;
    NarrowRect.Bottom += Rect.Top;
    THintWindow::ActivateHint ( NarrowRect , AHint );
}


/****************************************************************************
 * Just a wrapper to embed an AnsiString into a TObject
 ****************************************************************************/
__fastcall TObjectString::TObjectString(char * String)
{
    FString = AnsiString(String);
}
//---------------------------------------------------------------------------
AnsiString __fastcall TObjectString::String()
{
    return FString;
}


/****************************************************************************
 * A TCheckListBox that automatically disposes any TObject
 * associated with the string items
 ****************************************************************************/
__fastcall TCleanCheckListBox::~TCleanCheckListBox()
{
    for ( int i = 0 ; i < Items->Count ; i++ )
    {
        if ( Items->Objects[i] != NULL ) delete Items->Objects[i];
    }
}

82 83 84 85

/****************************************************************************
 * Functions to help components creation
 ****************************************************************************/
86 87
__fastcall TPanelPref::TPanelPref( TComponent* Owner,
            module_config_t *p_config_arg ) : TPanel( Owner )
88 89
{
    p_config = p_config_arg;
90 91 92
    BevelInner = bvNone;
    BevelOuter = bvNone;
    BorderStyle = bsNone;
93 94
}
//---------------------------------------------------------------------------
95
TCleanCheckListBox * __fastcall TPanelPref::CreateCleanCheckListBox(
96
    TWinControl *Parent, int Left, int Width, int Top, int Height )
97
{
98 99 100 101 102 103 104
    TCleanCheckListBox *CleanCheckListBox = new TCleanCheckListBox( Parent );
    CleanCheckListBox->Parent = Parent;
    CleanCheckListBox->Left = Left;
    CleanCheckListBox->Width = Width;
    CleanCheckListBox->Top = Top;
    CleanCheckListBox->Height = Height;
    return CleanCheckListBox;
105 106
}
//---------------------------------------------------------------------------
107
TButton * __fastcall TPanelPref::CreateButton( TWinControl *Parent,
108 109 110 111 112 113 114 115 116 117 118 119
            int Left, int Width, int Top, int Height, AnsiString Caption )
{
    TButton *Button = new TButton( Parent );
    Button->Parent = Parent;
    Button->Left = Left;
    Button->Width = Width;
    Button->Top = Top;
    Button->Height = Height;
    Button->Caption = Caption;
    return Button;
}
//---------------------------------------------------------------------------
120
TCheckBox * __fastcall TPanelPref::CreateCheckBox( TWinControl *Parent,
121 122 123 124 125 126 127 128 129 130 131 132
            int Left, int Width, int Top, int Height, AnsiString Caption )
{
    TCheckBox *CheckBox = new TCheckBox( Parent );
    CheckBox->Parent = Parent;
    CheckBox->Left = Left;
    CheckBox->Width = Width;
    CheckBox->Top = Top;
    CheckBox->Height = Height;
    CheckBox->Caption = Caption;
    return CheckBox;
}
//---------------------------------------------------------------------------
133
TLabel * __fastcall TPanelPref::CreateLabel( TWinControl *Parent,
134 135 136 137 138 139 140 141 142 143 144 145 146 147
            int Left, int Width, int Top, int Height, AnsiString Caption,
            bool WordWrap )
{
    TLabel *Label = new TLabel( Parent );
    Label->Parent = Parent;
    Label->Caption = Caption;
    Label->Left = Left;
    Label->Width = Width;
    Label->Top = Top;
    Label->Height = Height;
    Label->WordWrap = WordWrap;
    return Label;
}
//---------------------------------------------------------------------------
148
TEdit * __fastcall TPanelPref::CreateEdit( TWinControl *Parent,
149 150 151 152 153 154 155 156 157 158 159 160
            int Left, int Width, int Top, int Height, AnsiString Text )
{
    TEdit *Edit = new TEdit( Parent );
    Edit->Parent = Parent;
    Edit->Left = Left;
    Edit->Width = Width;
    Edit->Top = Top;
    Edit->Height = Height;
    Edit->Text = Text;
    return Edit;
}
//---------------------------------------------------------------------------
161
TCSpinEdit * __fastcall TPanelPref::CreateSpinEdit( TWinControl *Parent,
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
            int Left, int Width, int Top, int Height,
            long Min, long Max, long Value )
{
    TCSpinEdit *SpinEdit = new TCSpinEdit( Parent );
    SpinEdit->Parent = Parent;
    SpinEdit->Left = Left;
    SpinEdit->Width = Width;
    SpinEdit->Top = Top;
    SpinEdit->Height = Height;
    SpinEdit->MinValue = Min;
    SpinEdit->MaxValue = Max;
    SpinEdit->Value = Value;
    return SpinEdit;
}
//---------------------------------------------------------------------------
177
void __fastcall TPanelPref::UpdateChanges()
178 179 180
{
}

181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
#define LIBWIN32_PREFSIZE_VPAD                4
#define LIBWIN32_PREFSIZE_HPAD                4
#define LIBWIN32_PREFSIZE_LEFT                16
#define LIBWIN32_PREFSIZE_EDIT_LEFT           (LIBWIN32_PREFSIZE_LEFT+32)
#define LIBWIN32_PREFSIZE_WIDTH               375
#define LIBWIN32_PREFSIZE_EDIT_WIDTH          (LIBWIN32_PREFSIZE_WIDTH-32)
#define LIBWIN32_PREFSIZE_BUTTON_WIDTH        150
#define LIBWIN32_PREFSIZE_SPINEDIT_WIDTH      100
#define LIBWIN32_PREFSIZE_RIGHT               (LIBWIN32_PREFSIZE_LEFT+LIBWIN32_PREFSIZE_WIDTH)
#define LIBWIN32_PREFSIZE_BUTTON_HEIGHT       25
#define LIBWIN32_PREFSIZE_LABEL_HEIGHT        26
#define LIBWIN32_PREFSIZE_CHECKLISTBOX_HEIGHT 120
#define LIBWIN32_PREFSIZE_EDIT_HEIGHT         21
#define LIBWIN32_PREFSIZE_CHECKBOX_HEIGHT     17
#define LIBWIN32_PREFSIZE_SPINEDIT_HEIGHT     21
196 197

/****************************************************************************
198
 * Panel for module management
199
 ****************************************************************************/
200
__fastcall TPanelPlugin::TPanelPlugin( TComponent* Owner,
201 202
    module_config_t *p_config, intf_thread_t *_p_intf )
    : TPanelPref( Owner, p_config )
203
{
204 205
    p_intf = _p_intf;

206
    /* init configure button */
207 208 209 210 211 212
    ButtonConfig = CreateButton( this,
            LIBWIN32_PREFSIZE_RIGHT - LIBWIN32_PREFSIZE_BUTTON_WIDTH,
            LIBWIN32_PREFSIZE_BUTTON_WIDTH,
            LIBWIN32_PREFSIZE_VPAD,
            LIBWIN32_PREFSIZE_BUTTON_HEIGHT,
            "Configure..." );
213 214 215
    ButtonConfig->Enabled = false;
    ButtonConfig->OnClick = ButtonConfigClick;

216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
    /* init label */
    AnsiString Text = AnsiString(p_config->psz_text) + ":";
    Label = CreateLabel( this,
            LIBWIN32_PREFSIZE_LEFT,
            LIBWIN32_PREFSIZE_RIGHT - LIBWIN32_PREFSIZE_BUTTON_WIDTH
             - LIBWIN32_PREFSIZE_HPAD,
            LIBWIN32_PREFSIZE_VPAD,
            LIBWIN32_PREFSIZE_LABEL_HEIGHT,
            Text.c_str(), true );

    /* vertical alignement */
    if ( ButtonConfig->Height > Label->Height )
        Label->Top += ( ButtonConfig->Height - Label->Height ) / 2;
    else
        ButtonConfig->Top += ( Label->Height - ButtonConfig->Height ) / 2;

    /* init checklistbox */
    CleanCheckListBox = CreateCleanCheckListBox( this,
            LIBWIN32_PREFSIZE_EDIT_LEFT,
            LIBWIN32_PREFSIZE_EDIT_WIDTH,
            max ( Label->Top + Label->Height , ButtonConfig->Top
             + ButtonConfig->Height ) + LIBWIN32_PREFSIZE_VPAD,
            LIBWIN32_PREFSIZE_CHECKLISTBOX_HEIGHT );
    CleanCheckListBox->OnClick = CheckListBoxClick;
    CleanCheckListBox->OnClickCheck = CheckListBoxClickCheck;
    CleanCheckListBox->Hint = p_config->psz_longtext;
    CleanCheckListBox->ShowHint = true;

    /* panel height */
    Height = CleanCheckListBox->Top + CleanCheckListBox->Height
            + LIBWIN32_PREFSIZE_VPAD;
247 248
};
//---------------------------------------------------------------------------
249
void __fastcall TPanelPlugin::CheckListBoxClick( TObject *Sender )
250
{
251 252
    module_t **pp_parser;
    vlc_list_t *p_list;
253

254 255
    /* check that the click is valid (we are on an item, and the click
     * started on an item */
256
    if( CleanCheckListBox->ItemIndex == -1 )
257 258
        return;

259 260
    AnsiString Name = ((TObjectString*)CleanCheckListBox->Items->
        Objects[CleanCheckListBox->ItemIndex])->String().c_str();
261 262 263 264
    if( Name == "" )
        return;

    /* look for module 'Name' */
265
    p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
266

267 268 269 270 271
    for( pp_parser = (module_t **)p_list->pp_objects ;
         *pp_parser ;
         pp_parser++ )
    {
        if( strcmp( (*pp_parser)->psz_object_name, Name.c_str() ) == 0 )
272
        {
273
            ModuleSelected = (*pp_parser);
274 275
            ButtonConfig->Enabled =
                (*pp_parser)->i_config_items ? true : false;
276

277
            break;
278 279 280 281
        }
    }
}
//---------------------------------------------------------------------------
282
void __fastcall TPanelPlugin::CheckListBoxClickCheck( TObject *Sender )
283
{
284
    /* one item maximum must be checked */
285
    if( CleanCheckListBox->Checked[CleanCheckListBox->ItemIndex] )
286
    {
287
        for( int item = 0; item < CleanCheckListBox->Items->Count; item++ )
288
        {
289
            if( item != CleanCheckListBox->ItemIndex )
290
            {
291
                CleanCheckListBox->Checked[item] = false;
292 293 294
            }
        }
    }
295 296
}
//---------------------------------------------------------------------------
297
void __fastcall TPanelPlugin::ButtonConfigClick( TObject *Sender )
298
{
299
    p_intf->p_sys->p_window->
300 301 302
                        CreatePreferences( ModuleSelected->psz_object_name );
}
//---------------------------------------------------------------------------
303
void __fastcall TPanelPlugin::UpdateChanges()
304
{
305 306 307
    AnsiString Name = "";

    /* find the selected plugin (if any) */
308
    for( int item = 0; item < CleanCheckListBox->Items->Count; item++ )
309
    {
310
        if( CleanCheckListBox->Checked[item] )
311
        {
312 313
            Name = ((TObjectString*)CleanCheckListBox->Items->Objects[item])
                   ->String().c_str();
314 315 316 317
            break;
        }
    }

318 319
    /* XXX: Necessary, since c_str() returns only a temporary pointer... */
    free( p_config->psz_value );
320 321
    p_config->psz_value = (char *)malloc( Name.Length() + 1 );
    strcpy( p_config->psz_value, Name.c_str() );
322 323 324 325
}


/****************************************************************************
326
 * Panel for string management
327
 ****************************************************************************/
328 329
__fastcall TPanelString::TPanelString( TComponent* Owner,
            module_config_t *p_config ) : TPanelPref( Owner, p_config )
330 331
{
    /* init description label */
332 333 334 335 336 337 338
    AnsiString Text = AnsiString ( p_config->psz_text ) + ":";
    Label = CreateLabel( this,
            LIBWIN32_PREFSIZE_LEFT,
            LIBWIN32_PREFSIZE_WIDTH,
            LIBWIN32_PREFSIZE_VPAD,
            LIBWIN32_PREFSIZE_LABEL_HEIGHT,
            Text.c_str(), true );
339 340

    /* init edit */
341 342 343 344 345
    Edit = CreateEdit( this,
            LIBWIN32_PREFSIZE_EDIT_LEFT,
            LIBWIN32_PREFSIZE_EDIT_WIDTH,
            LIBWIN32_PREFSIZE_VPAD + Label->Height + LIBWIN32_PREFSIZE_VPAD,
            LIBWIN32_PREFSIZE_EDIT_HEIGHT, "" );
346 347 348
    vlc_mutex_lock( p_config->p_lock );
    Edit->Text = p_config->psz_value ? p_config->psz_value : "";
    vlc_mutex_unlock( p_config->p_lock );
349 350
    Edit->Hint = p_config->psz_longtext;
    Edit->ShowHint = true;
351

352 353 354
    /* panel height */
    Height = LIBWIN32_PREFSIZE_VPAD + Label->Height + LIBWIN32_PREFSIZE_VPAD
            + Edit->Height + LIBWIN32_PREFSIZE_VPAD;
355 356
};
//---------------------------------------------------------------------------
357
void __fastcall TPanelString::UpdateChanges()
358 359 360 361 362 363 364 365 366
{
    /* XXX: Necessary, since c_str() returns only a temporary pointer... */
    free( p_config->psz_value );
    p_config->psz_value = (char *)malloc( Edit->Text.Length() + 1 );
    strcpy( p_config->psz_value, Edit->Text.c_str() );
}


/****************************************************************************
367
 * Panel for integer management
368
 ****************************************************************************/
369 370
__fastcall TPanelInteger::TPanelInteger( TComponent* Owner,
            module_config_t *p_config ) : TPanelPref( Owner, p_config )
371 372
{
    /* init description label */
373 374 375 376 377 378 379
    AnsiString Text = AnsiString ( p_config->psz_text ) + ":";
    Label = CreateLabel( this,
            LIBWIN32_PREFSIZE_LEFT,
            LIBWIN32_PREFSIZE_WIDTH - LIBWIN32_PREFSIZE_SPINEDIT_WIDTH
             - LIBWIN32_PREFSIZE_HPAD,
            LIBWIN32_PREFSIZE_VPAD,
            LIBWIN32_PREFSIZE_LABEL_HEIGHT, Text.c_str(), true );
380 381

    /* init spinedit */
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
    SpinEdit = CreateSpinEdit( this,
            LIBWIN32_PREFSIZE_RIGHT - LIBWIN32_PREFSIZE_SPINEDIT_WIDTH,
            LIBWIN32_PREFSIZE_SPINEDIT_WIDTH,
            LIBWIN32_PREFSIZE_VPAD,
            LIBWIN32_PREFSIZE_SPINEDIT_HEIGHT,
            -1, 100000, p_config->i_value );
    SpinEdit->Hint = p_config->psz_longtext;
    SpinEdit->ShowHint = true;

    /* vertical alignement and panel height */
    if ( SpinEdit->Height > Label->Height )
    {
        Label->Top += ( SpinEdit->Height - Label->Height ) / 2;
        Height = SpinEdit->Top + SpinEdit->Height + LIBWIN32_PREFSIZE_VPAD;
    }
    else
    {
        SpinEdit->Top += ( Label->Height - SpinEdit->Height ) / 2;
        Height = Label->Top + Label->Height + LIBWIN32_PREFSIZE_VPAD;
    }
402 403
};
//---------------------------------------------------------------------------
404
void __fastcall TPanelInteger::UpdateChanges()
405 406 407 408 409 410 411
{
    /* Warning: we're casting from long to int */
    p_config->i_value = (int)SpinEdit->Value;
}


/****************************************************************************
412
 * Panel for boolean management
413
 ****************************************************************************/
414 415
__fastcall TPanelBool::TPanelBool( TComponent* Owner,
            module_config_t *p_config ) : TPanelPref( Owner, p_config )
416 417
{
    /* init checkbox */
418 419 420 421 422
    CheckBox = CreateCheckBox( this,
            LIBWIN32_PREFSIZE_LEFT,
            LIBWIN32_PREFSIZE_WIDTH,
            LIBWIN32_PREFSIZE_VPAD,
            LIBWIN32_PREFSIZE_CHECKBOX_HEIGHT, p_config->psz_text );
423
    CheckBox->Checked = p_config->i_value;
424 425
    CheckBox->Hint = p_config->psz_longtext;
    CheckBox->ShowHint = true;
426

427 428
    /* panel height */
    Height = LIBWIN32_PREFSIZE_VPAD + CheckBox->Height + LIBWIN32_PREFSIZE_VPAD;
429 430
};
//---------------------------------------------------------------------------
431
void __fastcall TPanelBool::UpdateChanges()
432 433 434 435 436 437 438 439
{
    p_config->i_value = CheckBox->Checked ? 1 : 0;
}


/****************************************************************************
 * Callbacks for the dialog
 ****************************************************************************/
440 441
__fastcall TPreferencesDlg::TPreferencesDlg( TComponent* Owner,
    intf_thread_t *_p_intf ) : TForm( Owner )
442
{
443 444
    p_intf = _p_intf;
    Icon = p_intf->p_sys->p_window->Icon;
445 446 447 448 449
    Application->HintHidePause = 0x1000000;
    HintWindowClass = __classid ( TNarrowHintWindow );
    /* prevent the form from being resized horizontally */
    Constraints->MinWidth = Width;
    Constraints->MaxWidth = Width;
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473
}
//---------------------------------------------------------------------------
void __fastcall TPreferencesDlg::FormClose( TObject *Sender,
      TCloseAction &Action )
{
    Action = caHide;
}


/****************************************************************************
 * CreateConfigDialog: dynamically creates the configuration dialog
 * box from all the configuration data provided by the selected module.
 ****************************************************************************/
#define ADD_PANEL                               \
{                                               \
            Panel = new TPanel( this );         \
            Panel->Parent = ScrollBox;          \
            Panel->Caption = "";                \
            Panel->BevelOuter = bvNone;         \
            Panel->Height = 12;                 \
}

void __fastcall TPreferencesDlg::CreateConfigDialog( char *psz_module_name )
{
474 475 476
    module_t          **pp_parser;
    vlc_list_t         *p_list;

477 478
    module_config_t    *p_item;
    int                 i_pages, i_ctrl;
479

480 481 482
    TTabSheet          *TabSheet;
    TScrollBox         *ScrollBox;
    TPanel             *Panel;
483 484 485 486
    TPanelPlugin       *PanelPlugin;
    TPanelString       *PanelString;
    TPanelInteger      *PanelInteger;
    TPanelBool         *PanelBool;
487 488

    /* Look for the selected module */
489
    p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
490 491 492 493

    for( pp_parser = (module_t **)p_list->pp_objects ;
         *pp_parser ;
         pp_parser++ )
494 495
    {
        if( psz_module_name
496
             && !strcmp( psz_module_name, (*pp_parser)->psz_object_name ) )
497 498 499 500
        {
            break;
        }
    }
501 502 503 504 505
    if( !(*pp_parser) )
    {
        vlc_list_release( p_list );
        return;
    }
506 507 508 509 510 511

    /*
     * We found it, now we can start building its configuration interface
     */

    /* Enumerate config options and add corresponding config boxes */
512
    p_item = (*pp_parser)->p_config;
513
    if( p_item ) do
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
    {
        switch( p_item->i_type )
        {
        case CONFIG_HINT_CATEGORY:

            /* create a new tabsheet. */
            TabSheet = new TTabSheet( this );
            TabSheet->PageControl = PageControlPref;
            TabSheet->Caption = p_item->psz_text;
            TabSheet->Visible = true;

            /* pack a scrollbox into the tabsheet */
            ScrollBox = new TScrollBox( this );
            ScrollBox->Parent = TabSheet;
            ScrollBox->Align = alClient;
            ScrollBox->BorderStyle = bsNone;
            ScrollBox->HorzScrollBar->Tracking = true;
            ScrollBox->VertScrollBar->Tracking = true;

533 534 535
            /* add a panel as top margin */
            ADD_PANEL;

536 537 538 539
            break;

        case CONFIG_ITEM_MODULE:

540
            /* add new panel for the config option */
541
            PanelPlugin = new TPanelPlugin( this, p_item, p_intf );
542
            PanelPlugin->Parent = ScrollBox;
543

544 545 546 547
            /* Look for valid modules */
            pp_parser = (module_t **)p_list->pp_objects;

            for( ; *pp_parser ; pp_parser++ )
548
            {
549
                if( !strcmp( (*pp_parser)->psz_capability, p_item->psz_type ) )
550
                {
551 552 553 554 555 556 557 558 559 560 561 562
                    AnsiString ModuleDesc;
                    if ( (*pp_parser)->psz_longname != NULL ) {
                        ModuleDesc = AnsiString((*pp_parser)->psz_longname) +
                            " (" + AnsiString((*pp_parser)->psz_object_name) +
                            ")";
                    }
                    else
                        ModuleDesc = AnsiString((*pp_parser)->psz_object_name);

                    int item = PanelPlugin->CleanCheckListBox->Items->AddObject(
                        ModuleDesc.c_str(),
                        new TObjectString((*pp_parser)->psz_object_name) );
563 564 565 566 567 568

                    /* check the box if it's the default module */
                    AnsiString Name = p_item->psz_value ?
                        p_item->psz_value : "";
                    if( !strcmp( (*pp_parser)->psz_object_name, Name.c_str()) )
                    {
569
                        PanelPlugin->CleanCheckListBox->Checked[item] = true;
570
                    }
571 572
                }
            }
573

574 575 576 577 578 579
            break;

        case CONFIG_ITEM_FILE:

        case CONFIG_ITEM_STRING:

580 581 582
            /* add new panel for the config option */
            PanelString = new TPanelString( this, p_item );
            PanelString->Parent = ScrollBox;
583 584 585 586 587

            break;

        case CONFIG_ITEM_INTEGER:

588 589 590
            /* add new panel for the config option */
            PanelInteger = new TPanelInteger( this, p_item );
            PanelInteger->Parent = ScrollBox;
591 592 593 594 595

            break;

        case CONFIG_ITEM_BOOL:

596 597 598
            /* add new panel for the config option */
            PanelBool = new TPanelBool( this, p_item );
            PanelBool->Parent = ScrollBox;
599 600 601

            break;
        }
602

603 604 605 606
        p_item++;
    }
    while( p_item->i_type != CONFIG_HINT_END );

607
    /* Reorder panels inside the tabsheets */
608 609 610 611 612
    for( i_pages = 0; i_pages < PageControlPref->PageCount; i_pages++ )
    {
        /* get scrollbox from the tabsheet */
        ScrollBox = (TScrollBox *)PageControlPref->Pages[i_pages]->Controls[0];

613 614 615
        /* add a panel as bottom margin */
        ADD_PANEL;

616 617 618 619 620 621
        for( i_ctrl = ScrollBox->ControlCount - 1; i_ctrl >= 0 ; i_ctrl-- )
        {
            ScrollBox->Controls[i_ctrl]->Align = alTop;
        }
    }

622 623
    vlc_list_release( p_list );

624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639
    /* set active tabsheet
     * FIXME: i don't know why, but both lines are necessary */
    PageControlPref->ActivePageIndex = 1;
    PageControlPref->ActivePageIndex = 0;
}
#undef ADD_PANEL
//---------------------------------------------------------------------------
void __fastcall TPreferencesDlg::ButtonOkClick( TObject *Sender )
{
    ButtonApplyClick( Sender );
    Hide();
}
//---------------------------------------------------------------------------
void __fastcall TPreferencesDlg::ButtonApplyClick( TObject *Sender )
{
    TScrollBox *ScrollBox;
640
    TPanelPref *Panel;
641 642 643 644 645 646 647 648 649 650
    int i, j;

    for( i = 0; i < PageControlPref->PageCount; i++ )
    {
        /* get scrollbox from the tabsheet */
        ScrollBox = (TScrollBox *)PageControlPref->Pages[i]->Controls[0];

        for( j = 0; j < ScrollBox->ControlCount ; j++ )
        {
            /* skip the panels */
651
            if( ScrollBox->Controls[j]->InheritsFrom( __classid( TPanelPref ) ) )
652
            {
653 654 655
                Panel = (TPanelPref *)ScrollBox->Controls[j];
                Panel->UpdateChanges();
                SaveValue( Panel->p_config );
656 657 658 659 660 661 662 663
            }
        }
    }
}
//---------------------------------------------------------------------------
void __fastcall TPreferencesDlg::ButtonSaveClick( TObject *Sender )
{
    ButtonApplyClick( Sender );
664
    config_SaveConfigFile( p_intf, NULL );
665 666 667 668 669 670 671 672 673 674 675 676 677 678
}
//---------------------------------------------------------------------------
void __fastcall TPreferencesDlg::ButtonCancelClick( TObject *Sender )
{
    Hide();
}
//---------------------------------------------------------------------------
void __fastcall TPreferencesDlg::SaveValue( module_config_t *p_config )
{
    switch( p_config->i_type )
    {
        case CONFIG_ITEM_STRING:
        case CONFIG_ITEM_FILE:
        case CONFIG_ITEM_MODULE:
679
            config_PutPsz( p_intf, p_config->psz_name,
680 681 682 683
                           *p_config->psz_value ? p_config->psz_value : NULL );
            break;
        case CONFIG_ITEM_INTEGER:
        case CONFIG_ITEM_BOOL:
684
            config_PutInt( p_intf, p_config->psz_name,
685 686 687 688 689 690
                           p_config->i_value );
            break;
    }
}
//---------------------------------------------------------------------------