Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

PreferencesWindow.cpp

00001 /*****************************************************************************
00002  * PreferencesWindow.cpp: beos interface
00003  *****************************************************************************
00004  * Copyright (C) 1999, 2000, 2001 the VideoLAN team
00005  * $Id: PreferencesWindow.cpp 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Eric Petit <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 #include <stdlib.h> /* atoi(), strtod() */
00025 
00026 #include <String.h>
00027 
00028 #include <vlc/vlc.h>
00029 #include <vlc/intf.h>
00030 #include <vlc_keys.h>
00031 #include <vlc_config_cat.h>
00032 
00033 #include "PreferencesWindow.h"
00034 
00035 #define TYPE_CATEGORY 0
00036 #define TYPE_SUBCATEGORY 2
00037 #define TYPE_MODULE 3
00038 
00039 /*****************************************************************************
00040  * PreferencesWindow::PreferencesWindow
00041  *****************************************************************************/
00042 PreferencesWindow::PreferencesWindow( intf_thread_t * _p_intf,
00043                                       BRect frame, const char * name )
00044     : BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
00045                B_NOT_ZOOMABLE )
00046 {
00047     p_intf   = _p_intf;
00048     fCurrent = NULL;
00049 
00050     BRect rect;
00051 
00052     SetSizeLimits( PREFS_WINDOW_WIDTH, 2000, PREFS_WINDOW_HEIGHT, 2000 );
00053 
00054     /* The "background" view */
00055     fPrefsView = new BView( Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW );
00056     fPrefsView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
00057     AddChild( fPrefsView );
00058 
00059     /* Create a scrollable outline view for the preferences tree */
00060     rect = Bounds();
00061     rect.InsetBy( 10, 10 );
00062     rect.right = rect.left + 150;
00063     fOutline = new BOutlineListView( rect, "preferences tree",
00064                                      B_SINGLE_SELECTION_LIST,
00065                                      B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM );
00066     BScrollView * scrollview =
00067         new BScrollView( "scrollview", fOutline,
00068                          B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM,
00069                          0, false, true );
00070     fPrefsView->AddChild( scrollview );
00071 
00072     /* We need to be informed if the user selects an item */
00073     fOutline->SetSelectionMessage( new BMessage( PREFS_ITEM_SELECTED ) );
00074 
00075     /* Create a dummy, empty view so we can correctly place the real
00076        config views later */
00077     rect.bottom -= 40;
00078     rect.left = rect.right + 15 + B_V_SCROLL_BAR_WIDTH;
00079     rect.right = Bounds().right - 15;
00080     fDummyView = new BView( rect, "", B_FOLLOW_ALL_SIDES, B_WILL_DRAW );
00081     fDummyView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
00082     fPrefsView->AddChild( fDummyView );
00083 
00084     /* Fill the tree */
00085     vlc_list_t * p_list;
00086     p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
00087     if( !p_list )
00088     {
00089         msg_Warn( p_intf, "couldn't find any module !" );
00090         return;
00091     }
00092 
00093     /* Find the main module */
00094     module_t * p_module = NULL;
00095     module_config_t * p_item = NULL;
00096     for( int i = 0; i < p_list->i_count; i++ )
00097     {
00098         p_module = (module_t*) p_list->p_values[i].p_object;
00099 
00100         if( !strcmp( p_module->psz_object_name, "main" ) &&
00101             ( p_item = p_module->p_config ) )
00102             break;
00103         else
00104             p_module = NULL;
00105     }
00106 
00107     ConfigItem * catItem = NULL, * subcatItem, * otherItem;
00108 
00109     if( p_module )
00110     {
00111         /* We found the main module, build the category tree */
00112         for( ; p_item->i_type != CONFIG_HINT_END; p_item++ )
00113         {
00114             switch( p_item->i_type )
00115             {
00116                 case CONFIG_CATEGORY:
00117                     catItem = new ConfigItem( p_intf,
00118                         config_CategoryNameGet( p_item->i_value ),
00119                         false,
00120                         p_item->i_value,
00121                         TYPE_CATEGORY,
00122                         config_CategoryHelpGet( p_item->i_value ) );
00123                     fOutline->AddItem( catItem );
00124                     break;
00125 
00126                 case CONFIG_SUBCATEGORY:
00127                     if( catItem )
00128                     {
00129                         subcatItem = new ConfigItem( p_intf,
00130                             config_CategoryNameGet( p_item->i_value ),
00131                             false,
00132                             p_item->i_value,
00133                             TYPE_SUBCATEGORY,
00134                             config_CategoryHelpGet( p_item->i_value ) );
00135                         fOutline->AddUnder( subcatItem, catItem );
00136                     }
00137                     else
00138                     {
00139                         msg_Warn( p_intf, "subcategory without a category" );
00140                     }
00141                     break;
00142             }
00143         }
00144     }
00145 
00146     /* Now parse all others modules */
00147 
00148     int category, subcategory, options;
00149 
00150     for( int i = 0; i < p_list->i_count; i++ )
00151     {
00152         category    = -1;
00153         subcategory = -1;
00154         options     = 0;
00155 
00156         p_module = (module_t*) p_list->p_values[i].p_object;
00157 
00158         if( !strcmp( p_module->psz_object_name, "main" ) )
00159             continue;
00160 
00161         if( p_module->b_submodule ||
00162             !( p_item = p_module->p_config ) )
00163             continue;
00164 
00165         for( ; p_item->i_type != CONFIG_HINT_END; p_item++ )
00166         {
00167             switch( p_item->i_type )
00168             {
00169                 case CONFIG_CATEGORY:
00170                     category = p_item->i_value;
00171                     break;
00172                 case CONFIG_SUBCATEGORY:
00173                     subcategory = p_item->i_value;
00174                     break;
00175                 default:
00176                     if( p_item->i_type & CONFIG_ITEM )
00177                         options++;
00178             }
00179             if( options > 0 && category >= 0 && subcategory >= 0 )
00180             {
00181                 break;
00182             }
00183         }
00184 
00185         if( options < 1 || category < 0 || subcategory < 0 )
00186             continue;
00187 
00188         catItem = NULL;
00189         for( int j = 0; j < fOutline->CountItemsUnder( NULL, true ); j++ )
00190         {
00191             catItem = (ConfigItem*)
00192                 fOutline->ItemUnderAt( NULL, true, j );
00193             if( catItem->ObjectId() == category )
00194                 break;
00195             else
00196                 catItem = NULL;
00197         }
00198 
00199         if( !catItem )
00200             continue;
00201 
00202         subcatItem = NULL;
00203         for( int j = 0; j < fOutline->CountItemsUnder( catItem, true ); j++ )
00204         {
00205             subcatItem = (ConfigItem*)
00206                 fOutline->ItemUnderAt( catItem, true, j );
00207             if( subcatItem->ObjectId() == subcategory )
00208                 break;
00209             else
00210                 subcatItem = NULL;
00211         }
00212 
00213         if( !subcatItem )
00214             subcatItem = catItem;
00215 
00216         otherItem = new ConfigItem( p_intf,
00217             p_module->psz_shortname ?
00218               p_module->psz_shortname : p_module->psz_object_name,
00219             p_module->b_submodule,
00220             p_module->b_submodule ?
00221               ((module_t *)p_module->p_parent)->i_object_id :
00222               p_module->i_object_id,
00223             TYPE_MODULE,
00224             NULL );
00225         fOutline->AddUnder( otherItem, subcatItem );
00226     }
00227 
00228     vlc_list_release( p_list );
00229 
00230     /* Collapse the whole tree */
00231     for( int i = 0; i < fOutline->FullListCountItems(); i++ )
00232     {
00233         otherItem = (ConfigItem *) fOutline->FullListItemAt( i );
00234         fOutline->Collapse( otherItem );
00235     }
00236 
00237     /* Set the correct values */
00238     Apply( false );
00239 
00240     /* Select the first item */
00241     fOutline->Select( 0 );
00242 
00243     /* Add the buttons */
00244     BButton * button;
00245     rect = Bounds();
00246     rect.InsetBy( 10, 10 );
00247     rect.left = rect.right - 80;
00248     rect.top = rect.bottom - 25;
00249     button = new BButton( rect, "", _("Apply"), new BMessage( PREFS_APPLY ),
00250                           B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM );
00251     button->MakeDefault( true );
00252     fPrefsView->AddChild( button );
00253     rect.OffsetBy( -90, 0 );
00254     button = new BButton( rect, "", _("Save"), new BMessage( PREFS_SAVE ),
00255                           B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM );
00256     fPrefsView->AddChild( button );
00257     rect.OffsetBy( -90, 0 );
00258     button = new BButton( rect, "", _("Defaults"),
00259                           new BMessage( PREFS_DEFAULTS ),
00260                           B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM );
00261     fPrefsView->AddChild( button );
00262 
00263     Hide();
00264     Show();
00265 }
00266 
00267 /*****************************************************************************
00268  * PreferencesWindow::~PreferencesWindow
00269  *****************************************************************************/
00270 PreferencesWindow::~PreferencesWindow()
00271 {
00272 }
00273 
00274 /*****************************************************************************
00275  * PreferencesWindow::QuitRequested
00276  *****************************************************************************/
00277 bool PreferencesWindow::QuitRequested()
00278 {
00279     if( !IsHidden() )
00280     {
00281         Hide();
00282     }
00283     return false;
00284 }
00285 
00286 /*****************************************************************************
00287  * PreferencesWindow::MessageReceived
00288  *****************************************************************************/
00289 void PreferencesWindow::MessageReceived( BMessage * message )
00290 {
00291     switch( message->what )
00292     {
00293         case PREFS_ITEM_SELECTED:
00294             Update();
00295             break;
00296 
00297         case PREFS_DEFAULTS:
00298             config_ResetAll( p_intf );
00299             config_SaveConfigFile( p_intf, NULL );
00300             Apply( false );
00301             break;
00302 
00303         case PREFS_APPLY:
00304             Apply( true );
00305             break;
00306 
00307         case PREFS_SAVE:
00308             Apply( true );
00309             config_SaveConfigFile( p_intf, NULL );
00310             break;
00311 
00312         default:
00313             BWindow::MessageReceived( message );
00314     }
00315 }
00316 
00317 /*****************************************************************************
00318  * PreferencesWindow::FrameResized
00319  *****************************************************************************/
00320 void PreferencesWindow::FrameResized( float width, float height )
00321 {
00322     BWindow::FrameResized( width, height );
00323     fCurrent->UpdateScrollBar();
00324 }
00325 
00326 /*****************************************************************************
00327  * PreferencesWindow::Update
00328  *****************************************************************************/
00329 void PreferencesWindow::Update()
00330 {
00331     /* Get the selected item, if any */
00332     if( fOutline->CurrentSelection() < 0 )
00333         return;
00334 
00335     /* Detach the old box if any */
00336     if( fCurrent )
00337     {
00338         fCurrent->ResetScroll();
00339         fDummyView->RemoveChild( fCurrent->Box() );
00340     }
00341 
00342     /* Add the new one... */
00343     fCurrent = (ConfigItem *)
00344         fOutline->ItemAt( fOutline->CurrentSelection() );
00345     fDummyView->AddChild( fCurrent->Box() );
00346 
00347     /* ...then resize it (we must resize it after it's attached or the
00348        children don't get adjusted) */
00349     fCurrent->Box()->ResizeTo( fDummyView->Bounds().Width(),
00350                                fDummyView->Bounds().Height() );
00351     fCurrent->UpdateScrollBar();
00352 }
00353 
00354 /*****************************************************************************
00355  * PreferencesWindow::Apply
00356  * Apply changes if doIt is true, revert them otherwise
00357  *****************************************************************************/
00358 void PreferencesWindow::Apply( bool doIt )
00359 {
00360     ConfigItem * item;
00361 
00362     for( int i = 0; i < fOutline->FullListCountItems(); i++ )
00363     {
00364         item = (ConfigItem*) fOutline->FullListItemAt( i );
00365         item->Apply( doIt );
00366     }
00367 }
00368 
00369 /*****************************************************************************
00370  * PreferencesWindow::ReallyQuit
00371  *****************************************************************************/
00372 void PreferencesWindow::ReallyQuit()
00373 {
00374     Lock();
00375     Hide();
00376     Quit();
00377 }
00378 
00379 /***********************************************************************
00380  * ConfigItem::ConfigItem
00381  ***********************************************************************
00382  *
00383  **********************************************************************/
00384 ConfigItem::ConfigItem( intf_thread_t * _p_intf, char * name,
00385                         bool subModule, int objectId,
00386                         int type, char * help )
00387     : BStringItem( name )
00388 {
00389     p_intf     = _p_intf;
00390     fSubModule = subModule;
00391     fObjectId  = objectId;
00392     fType      = type;
00393     fHelp      = strdup( help );
00394 
00395     BRect r;
00396     r = BRect( 0, 0, 100, 100 );
00397     fBox = new BBox( r, NULL, B_FOLLOW_ALL );
00398     fBox->SetLabel( name );
00399 
00400     fTextView = NULL;
00401     fScroll   = NULL;
00402     fView     = NULL;
00403 
00404     if( fType == TYPE_CATEGORY )
00405     {
00406         /* Category: we just show the help text */
00407         r = fBox->Bounds();
00408         r.InsetBy( 10, 10 );
00409         r.top += 5;
00410 
00411         fTextView = new VTextView( r, NULL, B_FOLLOW_ALL, B_WILL_DRAW);
00412         fTextView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
00413         fTextView->MakeEditable( false );
00414         fTextView->MakeSelectable( false );
00415         fTextView->Insert( fHelp );
00416         fBox->AddChild( fTextView );
00417 
00418         return;
00419     }
00420 
00421     vlc_list_t * p_list = NULL;
00422     module_t * p_module = NULL;
00423     if( fType == TYPE_MODULE )
00424     {
00425         p_module = (module_t *) vlc_object_get( p_intf, fObjectId );
00426     }
00427     else
00428     {
00429         if( !( p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE,
00430                                        FIND_ANYWHERE ) ) )
00431         {
00432             return;
00433         }
00434         for( int i = 0; i < p_list->i_count; i++ )
00435         {
00436             p_module = (module_t*) p_list->p_values[i].p_object;
00437 
00438             if( !strcmp( p_module->psz_object_name, "main" ) )
00439                 break;
00440             else
00441                 p_module = NULL;
00442         }
00443     }
00444 
00445     if( !p_module || p_module->i_object_type != VLC_OBJECT_MODULE )
00446     {
00447         /* Shouldn't happen */
00448         return;
00449     }
00450 
00451     module_config_t * p_item;
00452     p_item = fSubModule ? ((module_t *)p_module->p_parent)->p_config :
00453                p_module->p_config;
00454 
00455     if( fType == TYPE_SUBCATEGORY )
00456     {
00457         for( ; p_item->i_type != CONFIG_HINT_END; p_item++ )
00458         {
00459             if( p_item->i_type == CONFIG_SUBCATEGORY &&
00460                 p_item->i_value == fObjectId )
00461             {
00462                 break;
00463             }
00464         }
00465     }
00466 
00467     r = fBox->Bounds();
00468     r = BRect( 10,20,fBox->Bounds().right-B_V_SCROLL_BAR_WIDTH-10,
00469                fBox->Bounds().bottom-10 );
00470     fView = new BView( r, NULL, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP,
00471                        B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE );
00472     fView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
00473 
00474     r = fView->Bounds();
00475     r.InsetBy( 10,10 );
00476 
00477     ConfigWidget * widget;
00478     for( ; p_item->i_type != CONFIG_HINT_END; p_item++ )
00479     {
00480         if( ( p_item->i_type == CONFIG_CATEGORY ||
00481               p_item->i_type == CONFIG_SUBCATEGORY ) &&
00482             fType == TYPE_SUBCATEGORY &&
00483             p_item->i_value != fObjectId )
00484         {
00485             break;
00486         }
00487 
00488         widget = new ConfigWidget( p_intf, r, p_item );
00489         if( !widget->InitCheck() )
00490         {
00491             delete widget;
00492             continue;
00493         }
00494         fView->AddChild( widget );
00495         r.top += widget->Bounds().Height();
00496     }
00497 
00498     if( fType == TYPE_MODULE )
00499     {
00500         vlc_object_release( p_module );
00501     }
00502     else
00503     {
00504         vlc_list_release( p_list );
00505     }
00506 
00507     /* Create a scroll view around our fView */
00508     fScroll = new BScrollView( NULL, fView, B_FOLLOW_ALL, 0, false,
00509                                true, B_FANCY_BORDER );
00510     fScroll->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
00511     fBox->AddChild( fScroll );
00512 
00513     /* Adjust fView's height to the size it actually needs (we do this
00514        only now so the BScrollView fits the BBox) */
00515     fView->ResizeTo( fView->Bounds().Width(), r.top + 10 );
00516 }
00517 
00518 /***********************************************************************
00519  * ConfigItem::~ConfigItem
00520  ***********************************************************************
00521  *
00522  **********************************************************************/
00523 ConfigItem::~ConfigItem()
00524 {
00525     if( fHelp )
00526     {
00527         free( fHelp );
00528     }
00529 }
00530 
00531 /*****************************************************************************
00532  * ConfigItem::UpdateScrollBar
00533  *****************************************************************************/
00534 void ConfigItem::UpdateScrollBar()
00535 {
00536     /* We have to fix the scrollbar manually because it doesn't handle
00537        correctly simple BViews */
00538 
00539     if( !fScroll )
00540     {
00541         return;
00542     }
00543 
00544     /* Get the available BRect for display */
00545     BRect display = fScroll->Bounds();
00546     display.right -= B_V_SCROLL_BAR_WIDTH;
00547 
00548     /* Fix the scrollbar */
00549     BScrollBar * scrollBar;
00550     BRect visible = display & fView->Bounds();
00551     BRect total   = display | fView->Bounds();
00552     scrollBar = fScroll->ScrollBar( B_VERTICAL );
00553     long max = (long)( fView->Bounds().Height() - visible.Height() );
00554     if( max < 0 ) max = 0;
00555     scrollBar->SetRange( 0, max );
00556     scrollBar->SetProportion( visible.Height() / total.Height() );
00557     scrollBar->SetSteps( 10, 100 );
00558 
00559     /* We have to force redraw to avoid visual bugs when resizing
00560        (BeOS bug?) */
00561     fScroll->Invalidate();
00562     fView->Invalidate();
00563 }
00564 
00565 /*****************************************************************************
00566  * ConfigItem::ResetScroll
00567  *****************************************************************************/
00568 void ConfigItem::ResetScroll()
00569 {
00570     if( !fScroll )
00571     {
00572         return;
00573     }
00574 
00575     fView->ScrollTo( 0, 0 );
00576 }
00577 
00578 /***********************************************************************
00579  * ConfigItem::Apply
00580  ***********************************************************************
00581  *
00582  **********************************************************************/
00583 void ConfigItem::Apply( bool doIt )
00584 {
00585     if( !fScroll )
00586     {
00587         return;
00588     }
00589 
00590     /* Call ConfigWidget::Apply for every child of your fView */
00591     ConfigWidget * widget;
00592     for( int i = 0; i < fView->CountChildren(); i++ )
00593     {
00594         widget = (ConfigWidget*) fView->ChildAt( i );
00595         widget->Apply( doIt );
00596     }
00597 }
00598 
00599 /***********************************************************************
00600  * ConfigWidget::ConfigWidget
00601  ***********************************************************************
00602  * Builds a view with the right controls for the given config variable.
00603  *  rect: the BRect where we place ourselves. All we care is its width
00604  *    and its top coordinate, since we adapt our height to take only
00605  *    the place we need
00606  **********************************************************************/
00607 ConfigWidget::ConfigWidget( intf_thread_t * _p_intf, BRect rect,
00608                             module_config_t * p_item )
00609     : BView( rect, NULL, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP,
00610              B_WILL_DRAW )
00611 {
00612     p_intf = _p_intf;
00613 
00614     SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
00615 
00616     BRect r;
00617     BMenuItem * menuItem;
00618     /* Skip deprecated options */
00619     if( p_item->psz_current )
00620     {
00621         fInitOK = false;
00622         return;
00623     }
00624 
00625     fInitOK = true;
00626 
00627     fType = p_item->i_type;
00628     fName = strdup( p_item->psz_name );
00629 
00630     switch( fType )
00631     {
00632         case CONFIG_ITEM_MODULE:
00633         case CONFIG_ITEM_MODULE_CAT:
00634         case CONFIG_ITEM_MODULE_LIST_CAT:
00635         case CONFIG_ITEM_STRING:
00636         case CONFIG_ITEM_FILE:
00637         case CONFIG_ITEM_DIRECTORY:
00638         case CONFIG_ITEM_INTEGER:
00639         case CONFIG_ITEM_FLOAT:
00640             ResizeTo( Bounds().Width(), 25 );
00641             fTextControl = new VTextControl( Bounds(), NULL,
00642                 p_item->psz_text, NULL, new BMessage(),
00643                 B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP );
00644             AddChild( fTextControl );
00645             break;
00646         case CONFIG_ITEM_KEY:
00647             ResizeTo( Bounds().Width(), 25 );
00648             r = Bounds();
00649             r.left = r.right - 100;
00650             fPopUpMenu = new BPopUpMenu( "" );
00651             fMenuField = new BMenuField( r, NULL, NULL, fPopUpMenu,
00652                 B_FOLLOW_RIGHT | B_FOLLOW_TOP );
00653             for( unsigned i = 0;
00654                  i < sizeof( vlc_keys ) / sizeof( key_descriptor_t );
00655                  i++ )
00656             {
00657                 menuItem = new BMenuItem( vlc_keys[i].psz_key_string, NULL );
00658                 fPopUpMenu->AddItem( menuItem );
00659             }
00660             r.right = r.left - 10; r.left = r.left - 60;
00661             fShiftCheck = new BCheckBox( r, NULL, "Shift",
00662                 new BMessage(), B_FOLLOW_RIGHT | B_FOLLOW_TOP );
00663             r.right = r.left - 10; r.left = r.left - 60;
00664             fCtrlCheck = new BCheckBox( r, NULL, "Ctrl",
00665                 new BMessage(), B_FOLLOW_RIGHT | B_FOLLOW_TOP );
00666             r.right = r.left - 10; r.left = r.left - 60;
00667             fAltCheck = new BCheckBox( r, NULL, "Alt",
00668                 new BMessage(), B_FOLLOW_RIGHT | B_FOLLOW_TOP );
00669             r.right = r.left - 10; r.left = 0; r.bottom -= 10;
00670             fStringView = new BStringView( r, NULL, p_item->psz_text,
00671                 B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP );
00672             AddChild( fStringView );
00673             AddChild( fAltCheck );
00674             AddChild( fCtrlCheck );
00675             AddChild( fShiftCheck );
00676             AddChild( fMenuField );
00677             break;
00678         case CONFIG_ITEM_BOOL:
00679             ResizeTo( Bounds().Width(), 25 );
00680             fCheckBox = new BCheckBox( Bounds(), NULL, p_item->psz_text,
00681                 new BMessage(), B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP );
00682             AddChild( fCheckBox );
00683             break;
00684         case CONFIG_SECTION:
00685             fInitOK = false;
00686             break;
00687         default:
00688             fInitOK = false;
00689     }
00690 }
00691 
00692 ConfigWidget::~ConfigWidget()
00693 {
00694     free( fName );
00695 }
00696 
00697 /***********************************************************************
00698  * ConfigWidget::Apply
00699  ***********************************************************************
00700  *
00701  **********************************************************************/
00702 void ConfigWidget::Apply( bool doIt )
00703 {
00704     BMenuItem * menuItem;
00705     char string[256];
00706     vlc_value_t val;
00707 
00708     switch( fType )
00709     {
00710         case CONFIG_ITEM_STRING:
00711         case CONFIG_ITEM_FILE:
00712         case CONFIG_ITEM_MODULE:
00713         case CONFIG_ITEM_MODULE_CAT:
00714         case CONFIG_ITEM_MODULE_LIST_CAT:
00715         case CONFIG_ITEM_DIRECTORY:
00716             if( doIt )
00717             {
00718                 config_PutPsz( p_intf, fName, fTextControl->Text() );
00719             }
00720             else
00721             {
00722                 fTextControl->SetText( config_GetPsz( p_intf, fName ) );
00723             }
00724             break;
00725 
00726         case CONFIG_ITEM_INTEGER:
00727             if( doIt )
00728             {
00729                 config_PutInt( p_intf, fName, atoi( fTextControl->Text() ) );
00730             }
00731             else
00732             {
00733                 snprintf( string, 256, "%d", config_GetInt( p_intf, fName ) );
00734                 fTextControl->SetText( string );
00735             }
00736             break;
00737 
00738         case CONFIG_ITEM_FLOAT:
00739             if( doIt )
00740             {
00741                 config_PutFloat( p_intf, fName, atof( fTextControl->Text() ) );
00742             }
00743             else
00744             {
00745                 snprintf( string, 256, "%f", config_GetFloat( p_intf, fName ) );
00746                 fTextControl->SetText( string );
00747             }
00748             break;
00749 
00750         case CONFIG_ITEM_KEY:
00751             if( doIt )
00752             {
00753                 menuItem = fPopUpMenu->FindMarked();
00754                 if( menuItem )
00755                 {
00756                     val.i_int = vlc_keys[fPopUpMenu->IndexOf( menuItem )].i_key_code;
00757                     if( fAltCheck->Value() )
00758                     {
00759                         val.i_int |= KEY_MODIFIER_ALT;
00760                     }
00761                     if( fCtrlCheck->Value() )
00762                     {
00763                         val.i_int |= KEY_MODIFIER_CTRL;
00764                     }
00765                     if( fShiftCheck->Value() )
00766                     {
00767                         val.i_int |= KEY_MODIFIER_SHIFT;
00768                     }
00769                     var_Set( p_intf->p_vlc, fName, val );
00770                 }
00771             }
00772             else
00773             {
00774                 val.i_int = config_GetInt( p_intf, fName );
00775                 fAltCheck->SetValue( val.i_int & KEY_MODIFIER_ALT );
00776                 fCtrlCheck->SetValue( val.i_int & KEY_MODIFIER_CTRL );
00777                 fShiftCheck->SetValue( val.i_int & KEY_MODIFIER_SHIFT );
00778         
00779                 for( unsigned i = 0;
00780                      i < sizeof( vlc_keys ) / sizeof( key_descriptor_t ); i++ )
00781                 {
00782                     if( (unsigned) vlc_keys[i].i_key_code ==
00783                             ( val.i_int & ~KEY_MODIFIER ) )
00784                     {
00785                         menuItem = fPopUpMenu->ItemAt( i );
00786                         menuItem->SetMarked( true );
00787                         break;
00788                     }
00789                 }
00790             }
00791             break;
00792 
00793         case CONFIG_ITEM_BOOL:
00794             if( doIt )
00795             {
00796                 config_PutInt( p_intf, fName, fCheckBox->Value() );
00797             }
00798             else
00799             {
00800                 fCheckBox->SetValue( config_GetInt( p_intf, fName ) );
00801             }
00802             break;
00803 
00804         default:
00805             break;
00806     }
00807 }
00808 
00809 VTextView::VTextView( BRect frame, const char *name,
00810                       uint32 resizingMode, uint32 flags )
00811     : BTextView( frame, name, BRect( 10,10,10,10 ), resizingMode, flags )
00812 {
00813     FrameResized( Bounds().Width(), Bounds().Height() );
00814 }
00815 
00816 void VTextView::FrameResized( float width, float height )
00817 {
00818     BTextView::FrameResized( width, height );
00819     SetTextRect( BRect( 10,10, width-11, height-11 ) );
00820 }
00821 
00822 VTextControl::VTextControl( BRect frame, const char *name,
00823                             const char *label, const char *text,
00824                             BMessage * message, uint32 resizingMode )
00825     : BTextControl( frame, name, label, text, message, resizingMode )
00826 {
00827     FrameResized( Bounds().Width(), Bounds().Height() );
00828 }
00829 
00830 void VTextControl::FrameResized( float width, float height )
00831 {
00832     BTextControl::FrameResized( width, height );
00833     SetDivider( width / 2 );
00834 }

Generated on Tue Dec 20 10:14:37 2005 for vlc-0.8.4a by  doxygen 1.4.2