]> git.sesse.net Git - vlc/blob - modules/gui/beos/PreferencesWindow.cpp
6cf03c181e4b8fbe3dc01a39ba7b74804717bfcb
[vlc] / modules / gui / beos / PreferencesWindow.cpp
1 /*****************************************************************************
2  * PreferencesWindow.cpp: beos interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000, 2001 VideoLAN (Centrale Réseaux) and its contributors
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         catItem = NULL;
189         for( int j = 0; j < fOutline->CountItemsUnder( NULL, true ); j++ )
190         {
191             catItem = (ConfigItem*)
192                 fOutline->ItemUnderAt( NULL, true, j );
193             if( catItem->ObjectId() == category )
194                 break;
195             else
196                 catItem = NULL;
197         }
198
199         if( !catItem )
200             continue;
201
202         subcatItem = NULL;
203         for( int j = 0; j < fOutline->CountItemsUnder( catItem, true ); j++ )
204         {
205             subcatItem = (ConfigItem*)
206                 fOutline->ItemUnderAt( catItem, true, j );
207             if( subcatItem->ObjectId() == subcategory )
208                 break;
209             else
210                 subcatItem = NULL;
211         }
212
213         if( !subcatItem )
214             subcatItem = catItem;
215
216         otherItem = new ConfigItem( p_intf,
217             p_module->psz_shortname ?
218               p_module->psz_shortname : p_module->psz_object_name,
219             p_module->b_submodule,
220             p_module->b_submodule ?
221               ((module_t *)p_module->p_parent)->i_object_id :
222               p_module->i_object_id,
223             TYPE_MODULE,
224             NULL );
225         fOutline->AddUnder( otherItem, subcatItem );
226     }
227
228     vlc_list_release( p_list );
229
230     /* Collapse the whole tree */
231     for( int i = 0; i < fOutline->FullListCountItems(); i++ )
232     {
233         otherItem = (ConfigItem *) fOutline->FullListItemAt( i );
234         fOutline->Collapse( otherItem );
235     }
236
237     /* Set the correct values */
238     Apply( false );
239
240     /* Select the first item */
241     fOutline->Select( 0 );
242
243     /* Add the buttons */
244     BButton * button;
245     rect = Bounds();
246     rect.InsetBy( 10, 10 );
247     rect.left = rect.right - 80;
248     rect.top = rect.bottom - 25;
249     button = new BButton( rect, "", _("Apply"), new BMessage( PREFS_APPLY ),
250                           B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM );
251     button->MakeDefault( true );
252     fPrefsView->AddChild( button );
253     rect.OffsetBy( -90, 0 );
254     button = new BButton( rect, "", _("Save"), new BMessage( PREFS_SAVE ),
255                           B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM );
256     fPrefsView->AddChild( button );
257     rect.OffsetBy( -90, 0 );
258     button = new BButton( rect, "", _("Defaults"),
259                           new BMessage( PREFS_DEFAULTS ),
260                           B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM );
261     fPrefsView->AddChild( button );
262
263     Hide();
264     Show();
265 }
266
267 /*****************************************************************************
268  * PreferencesWindow::~PreferencesWindow
269  *****************************************************************************/
270 PreferencesWindow::~PreferencesWindow()
271 {
272 }
273
274 /*****************************************************************************
275  * PreferencesWindow::QuitRequested
276  *****************************************************************************/
277 bool PreferencesWindow::QuitRequested()
278 {
279     if( !IsHidden() )
280     {
281         Hide();
282     }
283     return false;
284 }
285
286 /*****************************************************************************
287  * PreferencesWindow::MessageReceived
288  *****************************************************************************/
289 void PreferencesWindow::MessageReceived( BMessage * message )
290 {
291     switch( message->what )
292     {
293         case PREFS_ITEM_SELECTED:
294             Update();
295             break;
296
297         case PREFS_DEFAULTS:
298             config_ResetAll( p_intf );
299             config_SaveConfigFile( p_intf, NULL );
300             Apply( false );
301             break;
302
303         case PREFS_APPLY:
304             Apply( true );
305             break;
306
307         case PREFS_SAVE:
308             Apply( true );
309             config_SaveConfigFile( p_intf, NULL );
310             break;
311
312         default:
313             BWindow::MessageReceived( message );
314     }
315 }
316
317 /*****************************************************************************
318  * PreferencesWindow::FrameResized
319  *****************************************************************************/
320 void PreferencesWindow::FrameResized( float width, float height )
321 {
322     BWindow::FrameResized( width, height );
323     fCurrent->UpdateScrollBar();
324 }
325
326 /*****************************************************************************
327  * PreferencesWindow::Update
328  *****************************************************************************/
329 void PreferencesWindow::Update()
330 {
331     /* Get the selected item, if any */
332     if( fOutline->CurrentSelection() < 0 )
333         return;
334
335     /* Detach the old box if any */
336     if( fCurrent )
337     {
338         fCurrent->ResetScroll();
339         fDummyView->RemoveChild( fCurrent->Box() );
340     }
341
342     /* Add the new one... */
343     fCurrent = (ConfigItem *)
344         fOutline->ItemAt( fOutline->CurrentSelection() );
345     fDummyView->AddChild( fCurrent->Box() );
346
347     /* ...then resize it (we must resize it after it's attached or the
348        children don't get adjusted) */
349     fCurrent->Box()->ResizeTo( fDummyView->Bounds().Width(),
350                                fDummyView->Bounds().Height() );
351     fCurrent->UpdateScrollBar();
352 }
353
354 /*****************************************************************************
355  * PreferencesWindow::Apply
356  * Apply changes if doIt is true, revert them otherwise
357  *****************************************************************************/
358 void PreferencesWindow::Apply( bool doIt )
359 {
360     ConfigItem * item;
361
362     for( int i = 0; i < fOutline->FullListCountItems(); i++ )
363     {
364         item = (ConfigItem*) fOutline->FullListItemAt( i );
365         item->Apply( doIt );
366     }
367 }
368
369 /*****************************************************************************
370  * PreferencesWindow::ReallyQuit
371  *****************************************************************************/
372 void PreferencesWindow::ReallyQuit()
373 {
374     Lock();
375     Hide();
376     Quit();
377 }
378
379 /***********************************************************************
380  * ConfigItem::ConfigItem
381  ***********************************************************************
382  *
383  **********************************************************************/
384 ConfigItem::ConfigItem( intf_thread_t * _p_intf, char * name,
385                         bool subModule, int objectId,
386                         int type, char * help )
387     : BStringItem( name )
388 {
389     p_intf     = _p_intf;
390     fSubModule = subModule;
391     fObjectId  = objectId;
392     fType      = type;
393     fHelp      = strdup( help );
394
395     BRect r;
396     r = BRect( 0, 0, 100, 100 );
397     fBox = new BBox( r, NULL, B_FOLLOW_ALL );
398     fBox->SetLabel( name );
399
400     fTextView = NULL;
401     fScroll   = NULL;
402     fView     = NULL;
403
404     if( fType == TYPE_CATEGORY )
405     {
406         /* Category: we just show the help text */
407         r = fBox->Bounds();
408         r.InsetBy( 10, 10 );
409         r.top += 5;
410
411         fTextView = new VTextView( r, NULL, B_FOLLOW_ALL, B_WILL_DRAW);
412         fTextView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
413         fTextView->MakeEditable( false );
414         fTextView->MakeSelectable( false );
415         fTextView->Insert( fHelp );
416         fBox->AddChild( fTextView );
417
418         return;
419     }
420
421     vlc_list_t * p_list = NULL;
422     module_t * p_module = NULL;
423     if( fType == TYPE_MODULE )
424     {
425         p_module = (module_t *) vlc_object_get( p_intf, fObjectId );
426     }
427     else
428     {
429         if( !( p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE,
430                                        FIND_ANYWHERE ) ) )
431         {
432             return;
433         }
434         for( int i = 0; i < p_list->i_count; i++ )
435         {
436             p_module = (module_t*) p_list->p_values[i].p_object;
437
438             if( !strcmp( p_module->psz_object_name, "main" ) )
439                 break;
440             else
441                 p_module = NULL;
442         }
443     }
444
445     if( !p_module || p_module->i_object_type != VLC_OBJECT_MODULE )
446     {
447         /* Shouldn't happen */
448         return;
449     }
450
451     module_config_t * p_item;
452     p_item = fSubModule ? ((module_t *)p_module->p_parent)->p_config :
453                p_module->p_config;
454
455     if( fType == TYPE_SUBCATEGORY )
456     {
457         for( ; p_item->i_type != CONFIG_HINT_END; p_item++ )
458         {
459             if( p_item->i_type == CONFIG_SUBCATEGORY &&
460                 p_item->i_value == fObjectId )
461             {
462                 break;
463             }
464         }
465     }
466
467     r = fBox->Bounds();
468     r = BRect( 10,20,fBox->Bounds().right-B_V_SCROLL_BAR_WIDTH-10,
469                fBox->Bounds().bottom-10 );
470     fView = new BView( r, NULL, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP,
471                        B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE );
472     fView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
473
474     r = fView->Bounds();
475     r.InsetBy( 10,10 );
476
477     ConfigWidget * widget;
478     for( ; p_item->i_type != CONFIG_HINT_END; p_item++ )
479     {
480         if( ( p_item->i_type == CONFIG_CATEGORY ||
481               p_item->i_type == CONFIG_SUBCATEGORY ) &&
482             fType == TYPE_SUBCATEGORY &&
483             p_item->i_value != fObjectId )
484         {
485             break;
486         }
487
488         widget = new ConfigWidget( p_intf, r, p_item );
489         if( !widget->InitCheck() )
490         {
491             delete widget;
492             continue;
493         }
494         fView->AddChild( widget );
495         r.top += widget->Bounds().Height();
496     }
497
498     if( fType == TYPE_MODULE )
499     {
500         vlc_object_release( p_module );
501     }
502     else
503     {
504         vlc_list_release( p_list );
505     }
506
507     /* Create a scroll view around our fView */
508     fScroll = new BScrollView( NULL, fView, B_FOLLOW_ALL, 0, false,
509                                true, B_FANCY_BORDER );
510     fScroll->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
511     fBox->AddChild( fScroll );
512
513     /* Adjust fView's height to the size it actually needs (we do this
514        only now so the BScrollView fits the BBox) */
515     fView->ResizeTo( fView->Bounds().Width(), r.top + 10 );
516 }
517
518 /***********************************************************************
519  * ConfigItem::~ConfigItem
520  ***********************************************************************
521  *
522  **********************************************************************/
523 ConfigItem::~ConfigItem()
524 {
525     if( fHelp )
526     {
527         free( fHelp );
528     }
529 }
530
531 /*****************************************************************************
532  * ConfigItem::UpdateScrollBar
533  *****************************************************************************/
534 void ConfigItem::UpdateScrollBar()
535 {
536     /* We have to fix the scrollbar manually because it doesn't handle
537        correctly simple BViews */
538
539     if( !fScroll )
540     {
541         return;
542     }
543
544     /* Get the available BRect for display */
545     BRect display = fScroll->Bounds();
546     display.right -= B_V_SCROLL_BAR_WIDTH;
547
548     /* Fix the scrollbar */
549     BScrollBar * scrollBar;
550     BRect visible = display & fView->Bounds();
551     BRect total   = display | fView->Bounds();
552     scrollBar = fScroll->ScrollBar( B_VERTICAL );
553     long max = (long)( fView->Bounds().Height() - visible.Height() );
554     if( max < 0 ) max = 0;
555     scrollBar->SetRange( 0, max );
556     scrollBar->SetProportion( visible.Height() / total.Height() );
557     scrollBar->SetSteps( 10, 100 );
558
559     /* We have to force redraw to avoid visual bugs when resizing
560        (BeOS bug?) */
561     fScroll->Invalidate();
562     fView->Invalidate();
563 }
564
565 /*****************************************************************************
566  * ConfigItem::ResetScroll
567  *****************************************************************************/
568 void ConfigItem::ResetScroll()
569 {
570     if( !fScroll )
571     {
572         return;
573     }
574
575     fView->ScrollTo( 0, 0 );
576 }
577
578 /***********************************************************************
579  * ConfigItem::Apply
580  ***********************************************************************
581  *
582  **********************************************************************/
583 void ConfigItem::Apply( bool doIt )
584 {
585     if( !fScroll )
586     {
587         return;
588     }
589
590     /* Call ConfigWidget::Apply for every child of your fView */
591     ConfigWidget * widget;
592     for( int i = 0; i < fView->CountChildren(); i++ )
593     {
594         widget = (ConfigWidget*) fView->ChildAt( i );
595         widget->Apply( doIt );
596     }
597 }
598
599 /***********************************************************************
600  * ConfigWidget::ConfigWidget
601  ***********************************************************************
602  * Builds a view with the right controls for the given config variable.
603  *  rect: the BRect where we place ourselves. All we care is its width
604  *    and its top coordinate, since we adapt our height to take only
605  *    the place we need
606  **********************************************************************/
607 ConfigWidget::ConfigWidget( intf_thread_t * _p_intf, BRect rect,
608                             module_config_t * p_item )
609     : BView( rect, NULL, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP,
610              B_WILL_DRAW )
611 {
612     p_intf = _p_intf;
613
614     SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
615
616     BRect r;
617     BMenuItem * menuItem;
618     /* Skip deprecated options */
619     if( p_item->psz_current )
620     {
621         fInitOK = false;
622         return;
623     }
624
625     fInitOK = true;
626
627     fType = p_item->i_type;
628     fName = strdup( p_item->psz_name );
629
630     switch( fType )
631     {
632         case CONFIG_ITEM_MODULE:
633         case CONFIG_ITEM_MODULE_CAT:
634         case CONFIG_ITEM_MODULE_LIST_CAT:
635         case CONFIG_ITEM_STRING:
636         case CONFIG_ITEM_FILE:
637         case CONFIG_ITEM_DIRECTORY:
638         case CONFIG_ITEM_INTEGER:
639         case CONFIG_ITEM_FLOAT:
640             ResizeTo( Bounds().Width(), 25 );
641             fTextControl = new VTextControl( Bounds(), NULL,
642                 p_item->psz_text, NULL, new BMessage(),
643                 B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP );
644             AddChild( fTextControl );
645             break;
646         case CONFIG_ITEM_KEY:
647             ResizeTo( Bounds().Width(), 25 );
648             r = Bounds();
649             r.left = r.right - 100;
650             fPopUpMenu = new BPopUpMenu( "" );
651             fMenuField = new BMenuField( r, NULL, NULL, fPopUpMenu,
652                 B_FOLLOW_RIGHT | B_FOLLOW_TOP );
653             for( unsigned i = 0;
654                  i < sizeof( vlc_keys ) / sizeof( key_descriptor_t );
655                  i++ )
656             {
657                 menuItem = new BMenuItem( vlc_keys[i].psz_key_string, NULL );
658                 fPopUpMenu->AddItem( menuItem );
659             }
660             r.right = r.left - 10; r.left = r.left - 60;
661             fShiftCheck = new BCheckBox( r, NULL, "Shift",
662                 new BMessage(), B_FOLLOW_RIGHT | B_FOLLOW_TOP );
663             r.right = r.left - 10; r.left = r.left - 60;
664             fCtrlCheck = new BCheckBox( r, NULL, "Ctrl",
665                 new BMessage(), B_FOLLOW_RIGHT | B_FOLLOW_TOP );
666             r.right = r.left - 10; r.left = r.left - 60;
667             fAltCheck = new BCheckBox( r, NULL, "Alt",
668                 new BMessage(), B_FOLLOW_RIGHT | B_FOLLOW_TOP );
669             r.right = r.left - 10; r.left = 0; r.bottom -= 10;
670             fStringView = new BStringView( r, NULL, p_item->psz_text,
671                 B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP );
672             AddChild( fStringView );
673             AddChild( fAltCheck );
674             AddChild( fCtrlCheck );
675             AddChild( fShiftCheck );
676             AddChild( fMenuField );
677             break;
678         case CONFIG_ITEM_BOOL:
679             ResizeTo( Bounds().Width(), 25 );
680             fCheckBox = new BCheckBox( Bounds(), NULL, p_item->psz_text,
681                 new BMessage(), B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP );
682             AddChild( fCheckBox );
683             break;
684         case CONFIG_SECTION:
685             fInitOK = false;
686             break;
687         default:
688             fInitOK = false;
689     }
690 }
691
692 ConfigWidget::~ConfigWidget()
693 {
694     free( fName );
695 }
696
697 /***********************************************************************
698  * ConfigWidget::Apply
699  ***********************************************************************
700  *
701  **********************************************************************/
702 void ConfigWidget::Apply( bool doIt )
703 {
704     BMenuItem * menuItem;
705     char string[256];
706     vlc_value_t val;
707
708     switch( fType )
709     {
710         case CONFIG_ITEM_STRING:
711         case CONFIG_ITEM_FILE:
712         case CONFIG_ITEM_MODULE:
713         case CONFIG_ITEM_MODULE_CAT:
714         case CONFIG_ITEM_MODULE_LIST_CAT:
715         case CONFIG_ITEM_DIRECTORY:
716             if( doIt )
717             {
718                 config_PutPsz( p_intf, fName, fTextControl->Text() );
719             }
720             else
721             {
722                 fTextControl->SetText( config_GetPsz( p_intf, fName ) );
723             }
724             break;
725
726         case CONFIG_ITEM_INTEGER:
727             if( doIt )
728             {
729                 config_PutInt( p_intf, fName, atoi( fTextControl->Text() ) );
730             }
731             else
732             {
733                 snprintf( string, 256, "%d", config_GetInt( p_intf, fName ) );
734                 fTextControl->SetText( string );
735             }
736             break;
737
738         case CONFIG_ITEM_FLOAT:
739             if( doIt )
740             {
741                 config_PutFloat( p_intf, fName, atof( fTextControl->Text() ) );
742             }
743             else
744             {
745                 snprintf( string, 256, "%f", config_GetFloat( p_intf, fName ) );
746                 fTextControl->SetText( string );
747             }
748             break;
749
750         case CONFIG_ITEM_KEY:
751             if( doIt )
752             {
753                 menuItem = fPopUpMenu->FindMarked();
754                 if( menuItem )
755                 {
756                     val.i_int = vlc_keys[fPopUpMenu->IndexOf( menuItem )].i_key_code;
757                     if( fAltCheck->Value() )
758                     {
759                         val.i_int |= KEY_MODIFIER_ALT;
760                     }
761                     if( fCtrlCheck->Value() )
762                     {
763                         val.i_int |= KEY_MODIFIER_CTRL;
764                     }
765                     if( fShiftCheck->Value() )
766                     {
767                         val.i_int |= KEY_MODIFIER_SHIFT;
768                     }
769                     var_Set( p_intf->p_vlc, fName, val );
770                 }
771             }
772             else
773             {
774                 val.i_int = config_GetInt( p_intf, fName );
775                 fAltCheck->SetValue( val.i_int & KEY_MODIFIER_ALT );
776                 fCtrlCheck->SetValue( val.i_int & KEY_MODIFIER_CTRL );
777                 fShiftCheck->SetValue( val.i_int & KEY_MODIFIER_SHIFT );
778         
779                 for( unsigned i = 0;
780                      i < sizeof( vlc_keys ) / sizeof( key_descriptor_t ); i++ )
781                 {
782                     if( (unsigned) vlc_keys[i].i_key_code ==
783                             ( val.i_int & ~KEY_MODIFIER ) )
784                     {
785                         menuItem = fPopUpMenu->ItemAt( i );
786                         menuItem->SetMarked( true );
787                         break;
788                     }
789                 }
790             }
791             break;
792
793         case CONFIG_ITEM_BOOL:
794             if( doIt )
795             {
796                 config_PutInt( p_intf, fName, fCheckBox->Value() );
797             }
798             else
799             {
800                 fCheckBox->SetValue( config_GetInt( p_intf, fName ) );
801             }
802             break;
803
804         default:
805             break;
806     }
807 }
808
809 VTextView::VTextView( BRect frame, const char *name,
810                       uint32 resizingMode, uint32 flags )
811     : BTextView( frame, name, BRect( 10,10,10,10 ), resizingMode, flags )
812 {
813     FrameResized( Bounds().Width(), Bounds().Height() );
814 }
815
816 void VTextView::FrameResized( float width, float height )
817 {
818     BTextView::FrameResized( width, height );
819     SetTextRect( BRect( 10,10, width-11, height-11 ) );
820 }
821
822 VTextControl::VTextControl( BRect frame, const char *name,
823                             const char *label, const char *text,
824                             BMessage * message, uint32 resizingMode )
825     : BTextControl( frame, name, label, text, message, resizingMode )
826 {
827     FrameResized( Bounds().Width(), Bounds().Height() );
828 }
829
830 void VTextControl::FrameResized( float width, float height )
831 {
832     BTextControl::FrameResized( width, height );
833     SetDivider( width / 2 );
834 }