Commit 3dae4454 authored by Eric Petit's avatar Eric Petit

modules/gui/beos/PreferencesWindow.*:

  - use BMenuFields for string_from_list config items
  - cleaning
parent 7ba77f51
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* PreferencesWindow.cpp: beos interface * PreferencesWindow.cpp: beos interface
***************************************************************************** *****************************************************************************
* Copyright (C) 1999, 2000, 2001 VideoLAN * Copyright (C) 1999, 2000, 2001 VideoLAN
* $Id: PreferencesWindow.cpp,v 1.20 2003/05/13 11:18:25 titer Exp $ * $Id: PreferencesWindow.cpp,v 1.21 2003/05/13 14:11:33 titer Exp $
* *
* Authors: Eric Petit <titer@videolan.org> * Authors: Eric Petit <titer@videolan.org>
* *
...@@ -23,14 +23,17 @@ ...@@ -23,14 +23,17 @@
#include <stdlib.h> /* atoi(), strtod() */ #include <stdlib.h> /* atoi(), strtod() */
#include <InterfaceKit.h>
#include <SupportKit.h>
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include <vlc/intf.h> #include <vlc/intf.h>
#include "PreferencesWindow.h" #include "PreferencesWindow.h"
/* TODO:
- handle CONFIG_HINT_SUBCATEGORY
- use BSliders for integer_with_range and float_with_range
- add the needed LockLooper()s
- fix horizontal window resizing */
/* We use this function to order the items of the BOutlineView */ /* We use this function to order the items of the BOutlineView */
int compare_func( const BListItem * _first, const BListItem * _second ) int compare_func( const BListItem * _first, const BListItem * _second )
{ {
...@@ -53,25 +56,6 @@ int compare_func( const BListItem * _first, const BListItem * _second ) ...@@ -53,25 +56,6 @@ int compare_func( const BListItem * _first, const BListItem * _second )
return( strcmp( first->Text(), second->Text() ) ); return( strcmp( first->Text(), second->Text() ) );
} }
/*****************************************************************************
* StringItemWithView::StringItemWithView
*****************************************************************************/
StringItemWithView::StringItemWithView( const char * text )
: BStringItem( text )
{
/* We use the default constructor */
}
/*****************************************************************************
* ConfigView::ConfigView
*****************************************************************************/
ConfigView::ConfigView( BRect frame, const char * name,
uint32 resizingMode, uint32 flags )
: BView( frame, name, resizingMode, flags )
{
/* We use the default constructor */
}
/***************************************************************************** /*****************************************************************************
* PreferencesWindow::PreferencesWindow * PreferencesWindow::PreferencesWindow
*****************************************************************************/ *****************************************************************************/
...@@ -88,9 +72,8 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface, ...@@ -88,9 +72,8 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface,
BRect rect; BRect rect;
/* The "background" view */ /* The "background" view */
rgb_color background = ui_color( B_PANEL_BACKGROUND_COLOR );
fPrefsView = new BView( Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW ); fPrefsView = new BView( Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW );
fPrefsView->SetViewColor( background ); fPrefsView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
AddChild( fPrefsView ); AddChild( fPrefsView );
/* Create the preferences tree */ /* Create the preferences tree */
...@@ -122,13 +105,6 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface, ...@@ -122,13 +105,6 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface,
fOutline->AddItem( modulesItem ); fOutline->AddItem( modulesItem );
/* Fill the tree */ /* Fill the tree */
/* TODO:
- manage CONFIG_HINT_SUBCATEGORY
- use a pop-up for CONFIG_HINT_MODULE
- use BSliders for integer_with_range and float_with_range
- add the needed LockLooper()s
- fix horizontal window resizing
- make this intuitive ! */
vlc_list_t * p_list; vlc_list_t * p_list;
p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE ); p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
if( !p_list ) if( !p_list )
...@@ -158,22 +134,19 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface, ...@@ -158,22 +134,19 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface,
/* Build the config view for this module */ /* Build the config view for this module */
rect = fDummyView->Bounds(); rect = fDummyView->Bounds();
rect.right -= B_V_SCROLL_BAR_WIDTH; rect.right -= B_V_SCROLL_BAR_WIDTH;
ConfigView * configView; BView * configView;
configView = new ConfigView( rect, "config view", configView = new BView( rect, "config view",
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, B_WILL_DRAW ); B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, B_WILL_DRAW );
configView->SetViewColor( background ); configView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
rect = configView->Bounds(); rect = configView->Bounds();
rect.InsetBy( 10, 10 ); rect.InsetBy( 10, 10 );
rect.bottom = rect.top + TEXT_HEIGHT; rect.bottom = rect.top + TEXT_HEIGHT;
BTextControl * textControl; ConfigTextControl * textControl;
BCheckBox * checkBox; ConfigCheckBox * checkBox;
ConfigMenuField * menuField;
/* FIXME: we use the BControl name to store the VLC variable name. BPopUpMenu * popUp;
To know what variable type it is, I add one character at the beginning
of the name (see ApplyChanges()); it's not pretty, but it works. To
be cleaned later. */
char name[128];
p_item = p_module->p_config; p_item = p_module->p_config;
bool firstItem = true; bool firstItem = true;
do do
...@@ -189,12 +162,25 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface, ...@@ -189,12 +162,25 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface,
else else
firstItem = false; firstItem = false;
memset( name, 0, 128 ); if( p_item->ppsz_list && p_item->ppsz_list[0] )
sprintf( name, "s%s", p_item->psz_name ); {
textControl = new BTextControl( rect, name, p_item->psz_text, popUp = new BPopUpMenu( "" );
"", new BMessage(), menuField = new ConfigMenuField( rect, p_item->psz_text,
B_FOLLOW_NONE ); popUp, p_item->psz_name );
configView->AddChild( textControl ); BMenuItem * menuItem;
for( int i = 0; p_item->ppsz_list[i]; i++ )
{
menuItem = new BMenuItem( p_item->ppsz_list[i], new BMessage() );
popUp->AddItem( menuItem );
}
configView->AddChild( menuField );
}
else
{
textControl = new ConfigTextControl( rect, p_item->psz_text,
CONFIG_ITEM_STRING, p_item->psz_name );
configView->AddChild( textControl );
}
break; break;
case CONFIG_ITEM_INTEGER: case CONFIG_ITEM_INTEGER:
...@@ -203,11 +189,8 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface, ...@@ -203,11 +189,8 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface,
else else
firstItem = false; firstItem = false;
memset( name, 0, 128 ); textControl = new ConfigTextControl( rect, p_item->psz_text,
sprintf( name, "i%s", p_item->psz_name ); CONFIG_ITEM_INTEGER, p_item->psz_name );
textControl = new BTextControl( rect, name, p_item->psz_text,
"", new BMessage(),
B_FOLLOW_NONE );
configView->AddChild( textControl ); configView->AddChild( textControl );
break; break;
...@@ -217,11 +200,8 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface, ...@@ -217,11 +200,8 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface,
else else
firstItem = false; firstItem = false;
memset( name, 0, 128 ); textControl = new ConfigTextControl( rect, p_item->psz_text,
sprintf( name, "f%s", p_item->psz_name ); CONFIG_ITEM_FLOAT, p_item->psz_name );
textControl = new BTextControl( rect, name, p_item->psz_text,
"", new BMessage(),
B_FOLLOW_NONE );
configView->AddChild( textControl ); configView->AddChild( textControl );
break; break;
...@@ -231,10 +211,8 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface, ...@@ -231,10 +211,8 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface,
else else
firstItem = false; firstItem = false;
memset( name, 0, 128 ); checkBox = new ConfigCheckBox( rect, p_item->psz_text,
sprintf( name, "b%s", p_item->psz_name ); p_item->psz_name );
checkBox = new BCheckBox( rect, name, p_item->psz_text,
new BMessage(), B_FOLLOW_NONE );
configView->AddChild( checkBox ); configView->AddChild( checkBox );
break; break;
} }
...@@ -243,8 +221,7 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface, ...@@ -243,8 +221,7 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface,
/* Adjust the configView size */ /* Adjust the configView size */
rect.bottom += 10; rect.bottom += 10;
configView->fRealBounds = BRect( 0, 0, configView->Bounds().Width(), rect.bottom ); configView->ResizeTo( configView->Bounds().Width(), rect.bottom );
configView->ResizeTo( configView->Bounds().Width(), configView->Bounds().Height() );
/* Add the item to the tree */ /* Add the item to the tree */
StringItemWithView * stringItem; StringItemWithView * stringItem;
...@@ -345,12 +322,9 @@ void PreferencesWindow::FrameResized( float width, float height ) ...@@ -345,12 +322,9 @@ void PreferencesWindow::FrameResized( float width, float height )
{ {
BWindow::FrameResized( width, height ); BWindow::FrameResized( width, height );
/* Get the current ConfigView */ /* Get the current config BView */
ConfigView * view; BView * view;
view = (ConfigView*) fConfigScroll->ChildAt( 0 ); view = fConfigScroll->ChildAt( 0 );
view->ResizeTo( fDummyView->Bounds().Width() - B_V_SCROLL_BAR_WIDTH,
fDummyView->Bounds().Height() );
UpdateScrollBar(); UpdateScrollBar();
} }
...@@ -372,11 +346,11 @@ void PreferencesWindow::Update() ...@@ -372,11 +346,11 @@ void PreferencesWindow::Update()
if( fConfigScroll ) if( fConfigScroll )
{ {
/* If we don't do this, the ConfigView will remember a wrong position */ /* If we don't do this, the config BView will remember a wrong position */
BScrollBar * scrollBar = fConfigScroll->ScrollBar( B_VERTICAL ); BScrollBar * scrollBar = fConfigScroll->ScrollBar( B_VERTICAL );
scrollBar->SetValue( 0 ); scrollBar->SetValue( 0 );
/* Detach the current ConfigView, remove the BScrollView */ /* Detach the current config BView, remove the BScrollView */
BView * view; BView * view;
while( ( view = fConfigScroll->ChildAt( 0 ) ) ) while( ( view = fConfigScroll->ChildAt( 0 ) ) )
fConfigScroll->RemoveChild( view ); fConfigScroll->RemoveChild( view );
...@@ -384,14 +358,17 @@ void PreferencesWindow::Update() ...@@ -384,14 +358,17 @@ void PreferencesWindow::Update()
delete fConfigScroll; delete fConfigScroll;
} }
/* Create a BScrollView with the new config BView in it */
BRect oldBounds = selectedItem->fConfigView->Bounds();
selectedItem->fConfigView->ResizeTo( fDummyView->Bounds().Width() - selectedItem->fConfigView->ResizeTo( fDummyView->Bounds().Width() -
B_V_SCROLL_BAR_WIDTH, B_V_SCROLL_BAR_WIDTH,
fDummyView->Bounds().Height() ); fDummyView->Bounds().Height() );
/* Create a BScrollView with the new ConfigView in it */
fConfigScroll = new BScrollView( "", selectedItem->fConfigView, B_FOLLOW_ALL_SIDES, fConfigScroll = new BScrollView( "", selectedItem->fConfigView, B_FOLLOW_ALL_SIDES,
0, false, true, B_NO_BORDER ); 0, false, true, B_NO_BORDER );
fConfigScroll->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
fDummyView->AddChild( fConfigScroll ); fDummyView->AddChild( fConfigScroll );
selectedItem->fConfigView->ResizeTo( oldBounds.Width(),
oldBounds.Height() );
UpdateScrollBar(); UpdateScrollBar();
} }
...@@ -405,8 +382,8 @@ void PreferencesWindow::UpdateScrollBar() ...@@ -405,8 +382,8 @@ void PreferencesWindow::UpdateScrollBar()
correctly simple BViews */ correctly simple BViews */
/* Get the current config view */ /* Get the current config view */
ConfigView * view; BView * view;
view = (ConfigView*) fConfigScroll->ChildAt( 0 ); view = fConfigScroll->ChildAt( 0 );
/* Get the available BRect for display */ /* Get the available BRect for display */
BRect display = fConfigScroll->Bounds(); BRect display = fConfigScroll->Bounds();
...@@ -415,10 +392,10 @@ void PreferencesWindow::UpdateScrollBar() ...@@ -415,10 +392,10 @@ void PreferencesWindow::UpdateScrollBar()
/* Fix the scrollbar */ /* Fix the scrollbar */
BScrollBar * scrollBar; BScrollBar * scrollBar;
long max; long max;
BRect visible = display & view->fRealBounds; BRect visible = display & view->Bounds();
BRect total = display | view->fRealBounds; BRect total = display | view->Bounds();
scrollBar = fConfigScroll->ScrollBar( B_VERTICAL ); scrollBar = fConfigScroll->ScrollBar( B_VERTICAL );
max = (long)( view->fRealBounds.Height() - visible.Height() ); max = (long)( view->Bounds().Height() - visible.Height() );
if( max < 0 ) max = 0; if( max < 0 ) max = 0;
scrollBar->SetRange( 0, max ); scrollBar->SetRange( 0, max );
scrollBar->SetProportion( visible.Height() / total.Height() ); scrollBar->SetProportion( visible.Height() / total.Height() );
...@@ -432,7 +409,7 @@ void PreferencesWindow::UpdateScrollBar() ...@@ -432,7 +409,7 @@ void PreferencesWindow::UpdateScrollBar()
void PreferencesWindow::ApplyChanges( bool doIt ) void PreferencesWindow::ApplyChanges( bool doIt )
{ {
StringItemWithView * item; StringItemWithView * item;
ConfigView * view; BView * view;
BView * child; BView * child;
const char * name; const char * name;
BString string; BString string;
...@@ -444,46 +421,83 @@ void PreferencesWindow::ApplyChanges( bool doIt ) ...@@ -444,46 +421,83 @@ void PreferencesWindow::ApplyChanges( bool doIt )
if( !view ) if( !view )
/* This must be the "Modules" item */ /* This must be the "Modules" item */
continue; continue;
for( int j = 0; j < view->CountChildren(); j++ ) for( int j = 0; j < view->CountChildren(); j++ )
{ {
child = view->ChildAt( j ); child = view->ChildAt( j );
name = child->Name(); name = child->Name();
switch( *name ) if( !strcmp( name, "ConfigTextControl" ) )
{ {
case 's': /* BTextControl, string variable */ ConfigTextControl * textControl;
if( doIt ) textControl = (ConfigTextControl*) child;
config_PutPsz( p_intf, name + 1, ((BTextControl*)child)->Text() ); switch( textControl->fConfigType )
else {
((BTextControl*)child)->SetText( config_GetPsz( p_intf, name + 1 ) ); case CONFIG_ITEM_STRING:
break; if( doIt )
case 'i': /* BTextControl, int variable */ config_PutPsz( p_intf, textControl->fConfigName, textControl->Text() );
if( doIt ) else
config_PutInt( p_intf, name + 1, atoi( ((BTextControl*)child)->Text() ) ); textControl->SetText( config_GetPsz( p_intf, textControl->fConfigName ) );
else break;
{ case CONFIG_ITEM_INTEGER:
string = ""; if( doIt )
string << config_GetInt( p_intf, name + 1 ); config_PutInt( p_intf, textControl->fConfigName, atoi( textControl->Text() ) );
((BTextControl*)child)->SetText( string.String() ); else
} {
break; string = "";
case 'f': /* BTextControl, float variable */ string << config_GetInt( p_intf, textControl->fConfigName );
if( doIt ) textControl->SetText( string.String() );
config_PutFloat( p_intf, name + 1, }
strtod( ((BTextControl*)child)->Text(), NULL ) ); break;
else case CONFIG_ITEM_FLOAT:
if( doIt )
config_PutFloat( p_intf, textControl->fConfigName,
strtod( textControl->Text(), NULL ) );
else
{
string = "";
string << config_GetFloat( p_intf, textControl->fConfigName );
textControl->SetText( string.String() );
}
break;
}
}
else if( !strcmp( name, "ConfigCheckBox" ) )
{
ConfigCheckBox * checkBox;
checkBox = (ConfigCheckBox*) child;
if( doIt )
config_PutInt( p_intf, checkBox->fConfigName, checkBox->Value() );
else
checkBox->SetValue( config_GetInt( p_intf, checkBox->fConfigName ) );
}
else if( !strcmp( name, "ConfigMenuField" ) )
{
ConfigMenuField * menuField;
menuField = (ConfigMenuField*) child;
BMenu * menu;
BMenuItem * menuItem;
menu = menuField->Menu();
if( doIt )
{
menuItem = menu->FindMarked();
if( menuItem )
config_PutPsz( p_intf, menuField->fConfigName, menuItem->Label() );
}
else
{
char * value;
value = config_GetPsz( p_intf, menuField->fConfigName );
if( !value ) value = "";
for( int k = 0; k < menu->CountItems(); k++ )
{ {
string = ""; menuItem = menu->ItemAt( k );
string << config_GetFloat( p_intf, name + 1 ); if( !strcmp( value, menuItem->Label() ) )
((BTextControl*)child)->SetText( string.String() ); {
menuItem->SetMarked( true );
break;
}
} }
break; }
case 'b': /* BCheckBox, bool variable */
if( doIt )
config_PutInt( p_intf, name + 1, ((BCheckBox*)child)->Value() );
else
((BCheckBox*)child)->SetValue( config_GetInt( p_intf, name + 1 ) );
break;
} }
} }
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* PreferencesWindow.h * PreferencesWindow.h
***************************************************************************** *****************************************************************************
* Copyright (C) 1999, 2000, 2001 VideoLAN * Copyright (C) 1999, 2000, 2001 VideoLAN
* $Id: PreferencesWindow.h,v 1.13 2003/05/13 11:18:25 titer Exp $ * $Id: PreferencesWindow.h,v 1.14 2003/05/13 14:11:33 titer Exp $
* *
* Authors: Eric Petit <titer@videolan.org> * Authors: Eric Petit <titer@videolan.org>
* *
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#ifndef BEOS_PREFERENCES_WINDOW_H #ifndef BEOS_PREFERENCES_WINDOW_H
#define BEOS_PREFERENCES_WINDOW_H #define BEOS_PREFERENCES_WINDOW_H
#include <Window.h> #include <InterfaceKit.h>
#define PREFS_WINDOW_WIDTH 600 #define PREFS_WINDOW_WIDTH 600
#define PREFS_WINDOW_HEIGHT 400 #define PREFS_WINDOW_HEIGHT 400
...@@ -34,25 +34,58 @@ ...@@ -34,25 +34,58 @@
#define PREFS_SAVE 'prsa' #define PREFS_SAVE 'prsa'
#define TEXT_HEIGHT 16 #define TEXT_HEIGHT 16
class ConfigView : public BView class StringItemWithView : public BStringItem
{ {
public: public:
ConfigView( BRect frame, const char * name, StringItemWithView( const char * text )
uint32 resizingMode, uint32 flags ); : BStringItem( text ) {}
/* When we create the view, we have to give it an arbitrary size because /* Here we store the config BView associated to this module */
it will be the size of the BScrollView. That's why we keep the real size BView * fConfigView;
in fRealBounds so we can have a correct BScrollBar later */
BRect fRealBounds;
}; };
class StringItemWithView : public BStringItem class ConfigTextControl : public BTextControl
{ {
public: public:
StringItemWithView( const char * text ); ConfigTextControl( BRect rect, char * label,
int type, char * configName )
: BTextControl( rect, "ConfigTextControl", label,
"", new BMessage() )
{
fConfigType = type;
fConfigName = strdup( configName );
}
int fConfigType;
char * fConfigName;
};
class ConfigCheckBox : public BCheckBox
{
public:
ConfigCheckBox( BRect rect, char * label,
char * configName )
: BCheckBox( rect, "ConfigCheckBox", label,
new BMessage() )
{
fConfigName = strdup( configName );
}
char * fConfigName;
};
class ConfigMenuField : public BMenuField
{
public:
ConfigMenuField( BRect rect, char * label,
BPopUpMenu * popUp, char * configName )
: BMenuField( rect, "ConfigMenuField", label,
popUp, new BMessage() )
{
fConfigName = strdup( configName );
}
/* Here we store the ConfigView associated to this module */ char * fConfigName;
ConfigView * fConfigView;
}; };
class PreferencesWindow : public BWindow class PreferencesWindow : public BWindow
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment