]> git.sesse.net Git - vlc/blob - modules/gui/beos/PreferencesWindow.cpp
configuration.[ch]: Handling of deprecated options in the command line. Add a new...
[vlc] / modules / gui / beos / PreferencesWindow.cpp
1 /*****************************************************************************
2  * PreferencesWindow.cpp: beos interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000, 2001 VideoLAN
5  * $Id$
6  *
7  * Authors: Eric Petit <titer@m0k.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 #include <stdlib.h> /* atoi(), strtod() */
25
26 #include <String.h>
27
28 #include <vlc/vlc.h>
29 #include <vlc/intf.h>
30 #include <vlc_keys.h>
31 #include <vlc_config_cat.h>
32
33 #include "PreferencesWindow.h"
34
35 #define TYPE_CATEGORY 0
36 #define TYPE_SUBCATEGORY 2
37 #define TYPE_MODULE 3
38
39 /*****************************************************************************
40  * PreferencesWindow::PreferencesWindow
41  *****************************************************************************/
42 PreferencesWindow::PreferencesWindow( intf_thread_t * _p_intf,
43                                       BRect frame, const char * name )
44     : BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
45                B_NOT_ZOOMABLE )
46 {
47     p_intf   = _p_intf;
48     fCurrent = NULL;
49
50     BRect rect;
51
52     SetSizeLimits( PREFS_WINDOW_WIDTH, 2000, PREFS_WINDOW_HEIGHT, 2000 );
53
54     /* The "background" view */
55     fPrefsView = new BView( Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW );
56     fPrefsView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
57     AddChild( fPrefsView );
58
59     /* Create a scrollable outline view for the preferences tree */
60     rect = Bounds();
61     rect.InsetBy( 10, 10 );
62     rect.right = rect.left + 150;
63     fOutline = new BOutlineListView( rect, "preferences tree",
64                                      B_SINGLE_SELECTION_LIST,
65                                      B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM );
66     BScrollView * scrollview =
67         new BScrollView( "scrollview", fOutline,
68                          B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM,
69                          0, false, true );
70     fPrefsView->AddChild( scrollview );
71
72     /* We need to be informed if the user selects an item */
73     fOutline->SetSelectionMessage( new BMessage( PREFS_ITEM_SELECTED ) );
74
75     /* Create a dummy, empty view so we can correctly place the real
76        config views later */
77     rect.bottom -= 40;
78     rect.left = rect.right + 15 + B_V_SCROLL_BAR_WIDTH;
79     rect.right = Bounds().right - 15;
80     fDummyView = new BView( rect, "", B_FOLLOW_ALL_SIDES, B_WILL_DRAW );
81     fDummyView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
82     fPrefsView->AddChild( fDummyView );
83
84     /* Fill the tree */
85     vlc_list_t * p_list;
86     p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
87     if( !p_list )
88     {
89         msg_Warn( p_intf, "couldn't find any module !" );
90         return;
91     }
92
93     /* Find the main module */
94     module_t * p_module = NULL;
95     module_config_t * p_item = NULL;
96     for( int i = 0; i < p_list->i_count; i++ )
97     {
98         p_module = (module_t*) p_list->p_values[i].p_object;
99
100         if( !strcmp( p_module->psz_object_name, "main" ) &&
101             ( p_item = p_module->p_config ) )
102             break;
103         else
104             p_module = NULL;
105     }
106
107     ConfigItem * catItem = NULL, * subcatItem, * otherItem;
108
109     if( p_module )
110     {
111         /* We found the main module, build the category tree */
112         for( ; p_item->i_type != CONFIG_HINT_END; p_item++ )
113         {
114             switch( p_item->i_type )
115             {
116                 case CONFIG_CATEGORY:
117                     catItem = new ConfigItem( p_intf,
118                         config_CategoryNameGet( p_item->i_value ),
119                         false,
120                         p_item->i_value,
121                         TYPE_CATEGORY,
122                         config_CategoryHelpGet( p_item->i_value ) );
123                     fOutline->AddItem( catItem );
124                     break;
125
126                 case CONFIG_SUBCATEGORY:
127                     if( catItem )
128                     {
129                         subcatItem = new ConfigItem( p_intf,
130                             config_CategoryNameGet( p_item->i_value ),
131                             false,
132                             p_item->i_value,
133                             TYPE_SUBCATEGORY,
134                             config_CategoryHelpGet( p_item->i_value ) );
135                         fOutline->AddUnder( subcatItem, catItem );
136                     }
137                     else
138                     {
139                         msg_Warn( p_intf, "subcategory without a category" );
140                     }
141                     break;
142             }
143         }
144     }
145
146     /* Now parse all others modules */
147
148     int category, subcategory, options;
149
150     for( int i = 0; i < p_list->i_count; i++ )
151     {
152         category    = -1;
153         subcategory = -1;
154         options     = 0;
155
156         p_module = (module_t*) p_list->p_values[i].p_object;
157
158         if( !strcmp( p_module->psz_object_name, "main" ) )
159             continue;
160
161         if( p_module->b_submodule ||
162             !( p_item = p_module->p_config ) )
163             continue;
164
165         for( ; p_item->i_type != CONFIG_HINT_END; p_item++ )
166         {
167             switch( p_item->i_type )
168             {
169                 case CONFIG_CATEGORY:
170                     category = p_item->i_value;
171                     break;
172                 case CONFIG_SUBCATEGORY:
173                     subcategory = p_item->i_value;
174                     break;
175                 default:
176                     if( p_item->i_type & CONFIG_ITEM )
177                         options++;
178             }
179             if( options > 0 && category >= 0 && subcategory >= 0 )
180             {
181                 break;
182             }
183         }
184
185         if( options < 1 || category < 0 || subcategory < 0 )
186             continue;
187
188 #if 0
189         fprintf( stderr, "cat %d, sub %d, %s\n", category, subcategory,
190                  p_module->psz_shortname ? p_module->psz_shortname :
191                  p_module->psz_object_name );
192 #endif
193
194         catItem = NULL;
195         for( int j = 0; j < fOutline->CountItemsUnder( NULL, true ); j++ )
196         {
197             catItem = (ConfigItem*)
198                 fOutline->ItemUnderAt( NULL, true, j );
199             if( catItem->ObjectId() == category )
200                 break;
201             else
202                 catItem = NULL;
203         }
204
205         if( !catItem )
206             continue;
207
208         subcatItem = NULL;
209         for( int j = 0; j < fOutline->CountItemsUnder( catItem, true ); j++ )
210         {
211             subcatItem = (ConfigItem*)
212                 fOutline->ItemUnderAt( catItem, true, j );
213             if( subcatItem->ObjectId() == subcategory )
214                 break;
215             else
216                 subcatItem = NULL;
217         }
218
219         if( !subcatItem )
220             subcatItem = catItem;
221
222         otherItem = new ConfigItem( p_intf,
223             p_module->psz_shortname ?
224               p_module->psz_shortname : p_module->psz_object_name,
225             p_module->b_submodule,
226             p_module->b_submodule ?
227               ((module_t *)p_module->p_parent)->i_object_id :
228               p_module->i_object_id,
229             TYPE_MODULE,
230             NULL );
231         fOutline->AddUnder( otherItem, subcatItem );
232     }
233
234     vlc_list_release( p_list );
235
236     for( int i = 0; i < fOutline->FullListCountItems(); i++ )
237     {
238         otherItem = (ConfigItem *)
239             fOutline->FullListItemAt( i );
240         if( fOutline->Superitem( otherItem ) )
241         {
242             fOutline->Collapse( otherItem );
243         }
244     }
245
246     /* Set the correct values */
247     ApplyChanges( false );
248
249     /* Select the first item */
250     fOutline->Select( 0 );
251
252     /* Add the buttons */
253     BButton * button;
254     rect = Bounds();
255     rect.InsetBy( 10, 10 );
256     rect.left = rect.right - 80;
257     rect.top = rect.bottom - 25;
258     button = new BButton( rect, "", _("Apply"), new BMessage( PREFS_APPLY ),
259                           B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM );
260     button->MakeDefault( true );
261     fPrefsView->AddChild( button );
262     rect.OffsetBy( -90, 0 );
263     button = new BButton( rect, "", _("Save"), new BMessage( PREFS_SAVE ),
264                           B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM );
265     fPrefsView->AddChild( button );
266     rect.OffsetBy( -90, 0 );
267     button = new BButton( rect, "", _("Defaults"),
268                           new BMessage( PREFS_DEFAULTS ),
269                           B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM );
270     fPrefsView->AddChild( button );
271
272     Hide();
273     Show();
274 }
275
276 /*****************************************************************************
277  * PreferencesWindow::~PreferencesWindow
278  *****************************************************************************/
279 PreferencesWindow::~PreferencesWindow()
280 {
281 }
282
283 /*****************************************************************************
284  * PreferencesWindow::QuitRequested
285  *****************************************************************************/
286 bool PreferencesWindow::QuitRequested()
287 {
288     if( !IsHidden() )
289     {
290         Hide();
291     }
292     return false;
293 }
294
295 /*****************************************************************************
296  * PreferencesWindow::MessageReceived
297  *****************************************************************************/
298 void PreferencesWindow::MessageReceived( BMessage * message )
299 {
300     switch( message->what )
301     {
302         case PREFS_ITEM_SELECTED:
303             Update();
304             break;
305
306         case PREFS_DEFAULTS:
307             config_ResetAll( p_intf );
308             ApplyChanges( false );
309             break;
310
311         case PREFS_APPLY:
312             ApplyChanges( true );
313             break;
314
315         case PREFS_SAVE:
316             SaveChanges();
317             break;
318
319         default:
320             BWindow::MessageReceived( message );
321     }
322 }
323
324 /*****************************************************************************
325  * PreferencesWindow::FrameResized
326  *****************************************************************************/
327 void PreferencesWindow::FrameResized( float width, float height )
328 {
329     BWindow::FrameResized( width, height );
330     fCurrent->UpdateScrollBar();
331 }
332
333 /*****************************************************************************
334  * PreferencesWindow::Update
335  *****************************************************************************/
336 void PreferencesWindow::Update()
337 {
338     /* Get the selected item, if any */
339     if( fOutline->CurrentSelection() < 0 )
340         return;
341
342     /* Detach the old box if any */
343     if( fCurrent )
344     {
345         fCurrent->ResetScroll();
346         fDummyView->RemoveChild( fCurrent->Box() );
347     }
348
349     /* Add the new one... */
350     fCurrent = (ConfigItem *)
351         fOutline->ItemAt( fOutline->CurrentSelection() );
352     fDummyView->AddChild( fCurrent->Box() );
353
354     /* ...then resize it (we must resize it after it's attached or the
355        children don't get adjusted) */
356     fCurrent->Box()->ResizeTo( fDummyView->Bounds().Width(),
357                                fDummyView->Bounds().Height() );
358     fCurrent->UpdateScrollBar();
359 }
360
361 /*****************************************************************************
362  * PreferencesWindow::ApplyChanges
363  * Apply changes if doIt is true, revert them otherwise
364  *****************************************************************************/
365 void PreferencesWindow::ApplyChanges( bool doIt )
366 {
367     ConfigItem * item;
368
369     for( int i = 0; i < fOutline->CountItems(); i++ )
370     {
371         item = (ConfigItem*) fOutline->ItemAt( i );
372         item->Apply( doIt );
373     }
374 }
375
376 /*****************************************************************************
377  * PreferencesWindow::SaveChanges
378  *****************************************************************************/
379 void PreferencesWindow::SaveChanges()
380 {
381     ApplyChanges( true );
382     config_SaveConfigFile( p_intf, NULL );
383 }
384
385 /*****************************************************************************
386  * PreferencesWindow::ReallyQuit
387  *****************************************************************************/
388 void PreferencesWindow::ReallyQuit()
389 {
390     Lock();
391     Hide();
392     Quit();
393 }
394
395 /***********************************************************************
396  * ConfigItem::ConfigItem
397  ***********************************************************************
398  *
399  **********************************************************************/
400 ConfigItem::ConfigItem( intf_thread_t * _p_intf, char * name,
401                         bool subModule, int objectId,
402                         int type, char * help )
403     : BStringItem( name )
404 {
405     p_intf     = _p_intf;
406     fSubModule = subModule;
407     fObjectId  = objectId;
408     fType      = type;
409     fHelp      = strdup( help );
410
411     BRect r;
412     r = BRect( 0, 0, 100, 100 );
413     fBox = new BBox( r, NULL, B_FOLLOW_ALL );
414     fBox->SetLabel( name );
415
416     fTextView = NULL;
417     fScroll   = NULL;
418     fView     = NULL;
419
420     if( fType == TYPE_CATEGORY )
421     {
422         /* Category: we just show the help text */
423         r = fBox->Bounds();
424         r.InsetBy( 10, 10 );
425         r.top += 5;
426
427         fTextView = new VTextView( r, NULL, B_FOLLOW_ALL, B_WILL_DRAW);
428         fTextView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
429         fTextView->MakeEditable( false );
430         fTextView->MakeSelectable( false );
431         fTextView->Insert( fHelp );
432         fBox->AddChild( fTextView );
433
434         return;
435     }
436
437     vlc_list_t * p_list = NULL;
438     module_t * p_module = NULL;
439     if( fType == TYPE_MODULE )
440     {
441         p_module = (module_t *) vlc_object_get( p_intf, fObjectId );
442     }
443     else
444     {
445         if( !( p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE,
446                                        FIND_ANYWHERE ) ) )
447         {
448             return;
449         }
450         for( int i = 0; i < p_list->i_count; i++ )
451         {
452             p_module = (module_t*) p_list->p_values[i].p_object;
453
454             if( !strcmp( p_module->psz_object_name, "main" ) )
455                 break;
456             else
457                 p_module = NULL;
458         }
459     }
460
461     if( !p_module || p_module->i_object_type != VLC_OBJECT_MODULE )
462     {
463         /* Shouldn't happen */
464         return;
465     }
466
467     module_config_t * p_item;
468     p_item = fSubModule ? ((module_t *)p_module->p_parent)->p_config :
469                p_module->p_config;
470
471     if( fType == TYPE_SUBCATEGORY )
472     {
473         for( ; p_item->i_type != CONFIG_HINT_END; p_item++ )
474         {
475             if( p_item->i_type == CONFIG_SUBCATEGORY &&
476                 p_item->i_value == fObjectId )
477             {
478                 break;
479             }
480         }
481     }
482
483     r = fBox->Bounds();
484     r = BRect( 10,20,fBox->Bounds().right-B_V_SCROLL_BAR_WIDTH-10,
485                fBox->Bounds().bottom-10 );
486     fView = new BView( r, NULL, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP,
487                        B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE );
488     fView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
489
490     r = fView->Bounds();
491     r.InsetBy( 10,10 );
492
493     ConfigWidget * widget;
494     for( ; p_item->i_type != CONFIG_HINT_END; p_item++ )
495     {
496         if( ( p_item->i_type == CONFIG_CATEGORY ||
497               p_item->i_type == CONFIG_SUBCATEGORY ) &&
498             fType == TYPE_SUBCATEGORY &&
499             p_item->i_value != fObjectId )
500         {
501             break;
502         }
503
504         widget = new ConfigWidget( p_intf, r, p_item );
505         if( !widget->InitCheck() )
506         {
507             delete widget;
508             continue;
509         }
510         fView->AddChild( widget );
511         r.top += widget->Bounds().Height();
512     }
513
514     if( fType == TYPE_MODULE )
515     {
516         vlc_object_release( p_module );
517     }
518     else
519     {
520         vlc_list_release( p_list );
521     }
522
523     /* Create a scroll view around our fView */
524     fScroll = new BScrollView( NULL, fView, B_FOLLOW_ALL, 0, false,
525                                true, B_FANCY_BORDER );
526     fScroll->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
527     fBox->AddChild( fScroll );
528
529     /* Adjust fView's height to the size it actually needs (we do this
530        only now so the BScrollView fits the BBox) */
531     fView->ResizeTo( fView->Bounds().Width(), r.top + 10 );
532 }
533
534 /***********************************************************************
535  * ConfigItem::~ConfigItem
536  ***********************************************************************
537  *
538  **********************************************************************/
539 ConfigItem::~ConfigItem()
540 {
541     if( fHelp )
542     {
543         free( fHelp );
544     }
545 }
546
547 /*****************************************************************************
548  * ConfigItem::UpdateScrollBar
549  *****************************************************************************/
550 void ConfigItem::UpdateScrollBar()
551 {
552     /* We have to fix the scrollbar manually because it doesn't handle
553        correctly simple BViews */
554
555     if( !fScroll )
556     {
557         return;
558     }
559
560     /* Get the available BRect for display */
561     BRect display = fScroll->Bounds();
562     display.right -= B_V_SCROLL_BAR_WIDTH;
563
564     /* Fix the scrollbar */
565     BScrollBar * scrollBar;
566     BRect visible = display & fView->Bounds();
567     BRect total   = display | fView->Bounds();
568     scrollBar = fScroll->ScrollBar( B_VERTICAL );
569     long max = (long)( fView->Bounds().Height() - visible.Height() );
570     if( max < 0 ) max = 0;
571     scrollBar->SetRange( 0, max );
572     scrollBar->SetProportion( visible.Height() / total.Height() );
573     scrollBar->SetSteps( 10, 100 );
574
575     /* We have to force redraw to avoid visual bugs when resizing
576        (BeOS bug?) */
577     fScroll->Invalidate();
578     fView->Invalidate();
579 }
580
581 /*****************************************************************************
582  * ConfigItem::ResetScroll
583  *****************************************************************************/
584 void ConfigItem::ResetScroll()
585 {
586     if( !fScroll )
587     {
588         return;
589     }
590
591     fView->ScrollTo( 0, 0 );
592 }
593
594 /***********************************************************************
595  * ConfigItem::Apply
596  ***********************************************************************
597  *
598  **********************************************************************/
599 void ConfigItem::Apply( bool doIt )
600 {
601     ConfigWidget * widget;
602
603     return;
604
605     if( !fView )
606     {
607         /* This is a category */
608         return;
609     }
610
611     /* Call ConfigWidget::Apply for every child of your fView */
612     for( int i = 0; i < fView->CountChildren(); i++ )
613     {
614         widget = (ConfigWidget*) fView->ChildAt( i );
615         widget->Apply( doIt );
616     }
617 }
618
619 /***********************************************************************
620  * ConfigWidget::ConfigWidget
621  ***********************************************************************
622  * Builds a view with the right controls for the given config variable.
623  *  rect: the BRect where we place ourselves. All we care is its width
624  *    and its top coordinate, since we adapt our height to take only
625  *    the place we need
626  **********************************************************************/
627 ConfigWidget::ConfigWidget( intf_thread_t * _p_intf, BRect rect,
628                             module_config_t * p_item )
629     : BView( rect, NULL, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP,
630              B_WILL_DRAW )
631 {
632     p_intf = _p_intf;
633
634     fInitOK = true;
635     SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
636
637     BRect r;
638     BMenuItem * menuItem;
639     /* Skip deprecated options */
640     if( p_item->psz_current )
641     {
642         return;
643     }
644
645     switch( p_item->i_type )
646     {
647         case CONFIG_ITEM_MODULE:
648         case CONFIG_ITEM_MODULE_CAT:
649         case CONFIG_ITEM_MODULE_LIST_CAT:
650         case CONFIG_ITEM_STRING:
651         case CONFIG_ITEM_FILE:
652         case CONFIG_ITEM_DIRECTORY:
653         case CONFIG_ITEM_INTEGER:
654         case CONFIG_ITEM_FLOAT:
655             ResizeTo( Bounds().Width(), 25 );
656             fTextControl = new VTextControl( Bounds(), NULL,
657                 p_item->psz_text, NULL, new BMessage(),
658                 B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP );
659             AddChild( fTextControl );
660             break;
661         case CONFIG_ITEM_KEY:
662             ResizeTo( Bounds().Width(), 25 );
663             r = Bounds();
664             r.left = r.right - 100;
665             fPopUpMenu = new BPopUpMenu( "" );
666             fMenuField = new BMenuField( r, NULL, NULL, fPopUpMenu,
667                 B_FOLLOW_RIGHT | B_FOLLOW_TOP );
668             for( unsigned i = 0;
669                  i < sizeof( vlc_keys ) / sizeof( key_descriptor_t );
670                  i++ )
671             {
672                 menuItem = new BMenuItem( vlc_keys[i].psz_key_string, NULL );
673                 fPopUpMenu->AddItem( menuItem );
674             }
675             r.right = r.left - 10; r.left = r.left - 60;
676             fShiftCheck = new BCheckBox( r, NULL, "Shift",
677                 new BMessage(), B_FOLLOW_RIGHT | B_FOLLOW_TOP );
678             r.right = r.left - 10; r.left = r.left - 60;
679             fCtrlCheck = new BCheckBox( r, NULL, "Ctrl",
680                 new BMessage(), B_FOLLOW_RIGHT | B_FOLLOW_TOP );
681             r.right = r.left - 10; r.left = r.left - 60;
682             fAltCheck = new BCheckBox( r, NULL, "Alt",
683                 new BMessage(), B_FOLLOW_RIGHT | B_FOLLOW_TOP );
684             r.right = r.left - 10; r.left = 0; r.bottom -= 10;
685             fStringView = new BStringView( r, NULL, p_item->psz_text,
686                 B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP );
687             AddChild( fStringView );
688             AddChild( fAltCheck );
689             AddChild( fCtrlCheck );
690             AddChild( fShiftCheck );
691             AddChild( fMenuField );
692             break;
693         case CONFIG_ITEM_BOOL:
694             ResizeTo( Bounds().Width(), 25 );
695             fCheckBox = new BCheckBox( Bounds(), NULL, p_item->psz_text,
696                 new BMessage(), B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP );
697             AddChild( fCheckBox );
698             break;
699         case CONFIG_SECTION:
700             fInitOK = false;
701             break;
702         default:
703             fInitOK = false;
704     }
705 }
706
707 /***********************************************************************
708  * ConfigWidget::Apply
709  ***********************************************************************
710  *
711  **********************************************************************/
712 void ConfigWidget::Apply( bool doIt )
713 {
714 #if 0
715     switch( fType )
716     {
717         case CONFIG_ITEM_STRING:
718         case CONFIG_ITEM_FILE:
719         case CONFIG_ITEM_MODULE:
720         case CONFIG_ITEM_DIRECTORY:
721             if( doIt )
722             {
723                 config_PutPsz( p_intf, fConfigName, fTextControl->Text() );
724             }
725             else
726             {
727                 fTextControl->SetText( config_GetPsz( p_intf, fConfigName ) );
728             }
729             break;
730
731         case CONFIG_ITEM_INTEGER:
732             if( doIt )
733             {
734                 config_PutInt( p_intf, fConfigName,
735                                atoi( fTextControl->Text() ) );
736             }
737             else
738             {
739                 memset( string, 0, 1024 );
740                 snprintf( string, 1023, "%d",
741                           config_GetInt( p_intf, fConfigName ) );
742                 fTextControl->SetText( string );
743             }
744             break;
745
746         case CONFIG_ITEM_FLOAT:
747             if( doIt )
748             {
749                 config_PutFloat( p_intf, fConfigName,
750                                  strtod( fTextControl->Text(), NULL ) );
751             }
752             else
753             {
754                 memset( string, 0, 1024 );
755                 snprintf( string, 1023, "%f",
756                           config_GetFloat( p_intf, fConfigName ) );
757                 fTextControl->SetText( string );
758             }
759             break;
760
761         case CONFIG_ITEM_BOOL:
762             if( doIt )
763             {
764                 config_PutInt( p_intf, fConfigName, fCheckBox->Value() );
765             }
766             else
767             {
768                 fCheckBox->SetValue( config_GetInt( p_intf, fConfigName ) );
769             }
770             break;
771
772         case CONFIG_ITEM_KEY:
773             if( doIt )
774             {
775                 menuItem = fPopUpMenu->FindMarked();
776                 if( menuItem )
777                 {
778                     int value = vlc_keys[fPopUpMenu->IndexOf( menuItem )].i_key_code;
779                     if( fAltCheck->Value() )
780                     {
781                         value |= KEY_MODIFIER_ALT;
782                     }
783                     if( fCtrlCheck->Value() )
784                     {
785                         value |= KEY_MODIFIER_CTRL;
786                     }
787                     if( fShiftCheck->Value() )
788                     {
789                         value |= KEY_MODIFIER_SHIFT;
790                     }
791                     config_PutInt( p_intf, fConfigName, value );
792                 }
793             }
794             else
795             {
796                 int value = config_GetInt( p_intf, fConfigName );
797                 fAltCheck->SetValue( value & KEY_MODIFIER_ALT );
798                 fCtrlCheck->SetValue( value & KEY_MODIFIER_CTRL );
799                 fShiftCheck->SetValue( value & KEY_MODIFIER_SHIFT );
800         
801                 for( unsigned i = 0;
802                      i < sizeof( vlc_keys ) / sizeof( key_descriptor_t ); i++ )
803                 {
804                     if( (unsigned) vlc_keys[i].i_key_code ==
805                             ( value & ~KEY_MODIFIER ) )
806                     {
807                         menuItem = fPopUpMenu->ItemAt( i );
808                         menuItem->SetMarked( true );
809                         break;
810                     }
811                 }
812             }
813
814             break;
815     }
816 #endif
817 }
818
819 VTextView::VTextView( BRect frame, const char *name,
820                       uint32 resizingMode, uint32 flags )
821     : BTextView( frame, name, BRect( 10,10,10,10 ), resizingMode, flags )
822 {
823     FrameResized( Bounds().Width(), Bounds().Height() );
824 }
825
826 void VTextView::FrameResized( float width, float height )
827 {
828     BTextView::FrameResized( width, height );
829     SetTextRect( BRect( 10,10, width-11, height-11 ) );
830 }
831
832 VTextControl::VTextControl( BRect frame, const char *name,
833                             const char *label, const char *text,
834                             BMessage * message, uint32 resizingMode )
835     : BTextControl( frame, name, label, text, message, resizingMode )
836 {
837     FrameResized( Bounds().Width(), Bounds().Height() );
838 }
839
840 void VTextControl::FrameResized( float width, float height )
841 {
842     BTextControl::FrameResized( width, height );
843     SetDivider( width / 2 );
844 }