Commit 6a46b2e3 authored by Eric Petit's avatar Eric Petit

beos/*: first pass at fixing the BeOS prefs

parent 41c5188d
...@@ -50,6 +50,7 @@ vlc_module_begin(); ...@@ -50,6 +50,7 @@ vlc_module_begin();
set_category( CAT_INTERFACE ); set_category( CAT_INTERFACE );
set_subcategory( SUBCAT_INTERFACE_GENERAL ); set_subcategory( SUBCAT_INTERFACE_GENERAL );
add_bool( "beos-dvdmenus", 0, NULL, _("Use DVD Menus"), "", VLC_TRUE ); add_bool( "beos-dvdmenus", 0, NULL, _("Use DVD Menus"), "", VLC_TRUE );
set_shortname( "BeOS" );
set_description( _("BeOS standard API interface") ); set_description( _("BeOS standard API interface") );
set_capability( "interface", 100 ); set_capability( "interface", 100 );
set_callbacks( E_(OpenIntf), E_(CloseIntf) ); set_callbacks( E_(OpenIntf), E_(CloseIntf) );
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* Copyright (C) 1999, 2000, 2001 VideoLAN * Copyright (C) 1999, 2000, 2001 VideoLAN
* $Id$ * $Id$
* *
* Authors: Eric Petit <titer@videolan.org> * Authors: Eric Petit <titer@m0k.org>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -28,29 +28,13 @@ ...@@ -28,29 +28,13 @@
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include <vlc/intf.h> #include <vlc/intf.h>
#include <vlc_keys.h> #include <vlc_keys.h>
#include <vlc_config_cat.h>
#include "PreferencesWindow.h" #include "PreferencesWindow.h"
/* TODO: #define TYPE_CATEGORY 0
- add the needed LockLooper()s #define TYPE_SUBCATEGORY 2
- fix window resizing */ #define TYPE_MODULE 3
/* We use this function to order the items of the BOutlineView */
static int compare_func( const BListItem * _first,
const BListItem * _second )
{
StringItemWithView * first = (StringItemWithView*) _first;
StringItemWithView * second = (StringItemWithView*) _second;
/* The Modules tree at last */
if( !strcmp( first->Text(), _( "Modules" ) ) )
return 1;
if( !strcmp( second->Text(), _( "Modules" ) ) )
return -1;
/* alphabetic order */
return( strcmp( first->Text(), second->Text() ) );
}
/***************************************************************************** /*****************************************************************************
* PreferencesWindow::PreferencesWindow * PreferencesWindow::PreferencesWindow
...@@ -58,13 +42,10 @@ static int compare_func( const BListItem * _first, ...@@ -58,13 +42,10 @@ static int compare_func( const BListItem * _first,
PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface, PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface,
BRect frame, const char * name ) BRect frame, const char * name )
: BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, : BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
B_NOT_ZOOMABLE | B_NOT_RESIZABLE ), B_NOT_ZOOMABLE ),
fConfigScroll( NULL ), fConfigScroll( NULL ),
p_intf( p_interface ) p_intf( p_interface )
{ {
SetSizeLimits( PREFS_WINDOW_WIDTH, PREFS_WINDOW_WIDTH,
200, 2000 );
BRect rect; BRect rect;
/* The "background" view */ /* The "background" view */
...@@ -72,7 +53,7 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface, ...@@ -72,7 +53,7 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface,
fPrefsView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) ); fPrefsView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
AddChild( fPrefsView ); AddChild( fPrefsView );
/* Create the preferences tree */ /* Create a scrollable outline view for the preferences tree */
rect = Bounds(); rect = Bounds();
rect.InsetBy( 10, 10 ); rect.InsetBy( 10, 10 );
rect.right = rect.left + 150; rect.right = rect.left + 150;
...@@ -88,8 +69,8 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface, ...@@ -88,8 +69,8 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface,
/* We need to be informed if the user selects an item */ /* We need to be informed if the user selects an item */
fOutline->SetSelectionMessage( new BMessage( PREFS_ITEM_SELECTED ) ); fOutline->SetSelectionMessage( new BMessage( PREFS_ITEM_SELECTED ) );
/* Create a dummy view so we can correctly place the real config /* Create a dummy, empty view so we can correctly place the real
views later */ config views later */
rect.bottom -= 40; rect.bottom -= 40;
rect.left = rect.right + 15 + B_V_SCROLL_BAR_WIDTH; rect.left = rect.right + 15 + B_V_SCROLL_BAR_WIDTH;
rect.right = Bounds().right - 15; rect.right = Bounds().right - 15;
...@@ -97,11 +78,6 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface, ...@@ -97,11 +78,6 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface,
fDummyView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) ); fDummyView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
fPrefsView->AddChild( fDummyView ); fPrefsView->AddChild( fDummyView );
/* Add a category for modules configuration */
StringItemWithView * modulesItem;
modulesItem = new StringItemWithView( _("Modules") );
fOutline->AddItem( modulesItem );
/* Fill the tree */ /* Fill the tree */
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 );
...@@ -111,9 +87,9 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface, ...@@ -111,9 +87,9 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface,
return; return;
} }
/* First, handle the main module */ /* Find the main module */
module_t * p_module = NULL; module_t * p_module = NULL;
module_config_t * p_item; module_config_t * p_item = NULL;
for( int i = 0; i < p_list->i_count; i++ ) for( int i = 0; i < p_list->i_count; i++ )
{ {
p_module = (module_t*) p_list->p_values[i].p_object; p_module = (module_t*) p_list->p_values[i].p_object;
...@@ -125,102 +101,146 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface, ...@@ -125,102 +101,146 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface,
p_module = NULL; p_module = NULL;
} }
ConfigItem * catItem = NULL, * subcatItem, * otherItem;
if( p_module ) if( p_module )
{ {
/* We found the main module */ /* We found the main module, build the category tree */
while( p_item->i_type == CONFIG_HINT_CATEGORY ) for( ; p_item->i_type != CONFIG_HINT_END; p_item++ )
{ {
StringItemWithView * stringItem; switch( p_item->i_type )
stringItem = new StringItemWithView( p_item->psz_text ); {
p_item++; case CONFIG_CATEGORY:
BuildConfigView( stringItem, &p_item, true ); catItem = new ConfigItem( p_intf,
fOutline->AddItem( stringItem ); config_CategoryNameGet( p_item->i_value ),
false,
p_item->i_value,
TYPE_CATEGORY,
config_CategoryHelpGet( p_item->i_value ) );
fOutline->AddItem( catItem );
break;
case CONFIG_SUBCATEGORY:
if( catItem )
{
subcatItem = new ConfigItem( p_intf,
config_CategoryNameGet( p_item->i_value ),
false,
p_item->i_value,
TYPE_SUBCATEGORY,
config_CategoryHelpGet( p_item->i_value ) );
fOutline->AddUnder( subcatItem, catItem );
}
else
{
msg_Warn( p_intf, "subcategory without a category" );
}
break;
}
} }
} }
/* Now parse all others modules */
int category, subcategory, options;
for( int i = 0; i < p_list->i_count; i++ ) for( int i = 0; i < p_list->i_count; i++ )
{ {
category = -1;
subcategory = -1;
options = 0;
p_module = (module_t*) p_list->p_values[i].p_object; p_module = (module_t*) p_list->p_values[i].p_object;
if( !strcmp( p_module->psz_object_name, "main" ) ) if( !strcmp( p_module->psz_object_name, "main" ) )
continue; continue;
/* If the module has no config option, ignore it */ if( p_module->b_submodule ||
p_item = p_module->p_config; !( p_item = p_module->p_config ) )
if( !p_item )
{
continue; continue;
}
do for( ; p_item->i_type != CONFIG_HINT_END; p_item++ )
{ {
if( p_item->i_type & CONFIG_ITEM ) switch( p_item->i_type )
{
case CONFIG_CATEGORY:
category = p_item->i_value;
break;
case CONFIG_SUBCATEGORY:
subcategory = p_item->i_value;
break;
default:
if( p_item->i_type & CONFIG_ITEM )
options++;
}
if( options > 0 && category >= 0 && subcategory >= 0 )
{ {
break; break;
} }
} while( p_item->i_type != CONFIG_HINT_END && p_item++ ); }
if( p_item->i_type == CONFIG_HINT_END ) if( options < 1 || category < 0 || subcategory < 0 )
{
continue; continue;
}
/* Create the capability tree if it doesn't already exist */ fprintf( stderr, "cat %d, sub %d, %s\n", category, subcategory,
char * psz_capability; p_module->psz_shortname ? p_module->psz_shortname :
psz_capability = p_module->psz_capability; p_module->psz_object_name );
if( !psz_capability || !*psz_capability )
{
/* Empty capability ? Let's look at the submodules */
module_t * p_submodule;
for( int j = 0; j < p_module->i_children; j++ )
{
p_submodule = (module_t*)p_module->pp_children[ j ];
if( p_submodule->psz_capability &&
*p_submodule->psz_capability )
{
psz_capability = p_submodule->psz_capability;
break;
}
}
}
StringItemWithView * capabilityItem; catItem = NULL;
capabilityItem = NULL; for( int j = 0; j < fOutline->CountItemsUnder( NULL, true ); j++ )
for( int j = 0;
j < fOutline->CountItemsUnder( modulesItem, true ); j++ )
{ {
if( !strcmp( ((StringItemWithView*) catItem = (ConfigItem*)
fOutline->ItemUnderAt( modulesItem, true, j ))->Text(), fOutline->ItemUnderAt( NULL, true, j );
psz_capability ) ) if( catItem->ObjectId() == category )
{
capabilityItem = (StringItemWithView*)
fOutline->ItemUnderAt( modulesItem, true, j );
break; break;
} else
catItem = NULL;
} }
if( !capabilityItem )
if( !catItem )
continue;
subcatItem = NULL;
for( int j = 0; j < fOutline->CountItemsUnder( catItem, true ); j++ )
{ {
capabilityItem = new StringItemWithView( psz_capability ); subcatItem = (ConfigItem*)
fOutline->AddUnder( capabilityItem, modulesItem ); fOutline->ItemUnderAt( catItem, true, j );
if( subcatItem->ObjectId() == subcategory )
break;
else
subcatItem = NULL;
} }
/* Now add the item ! */ if( !subcatItem )
StringItemWithView * stringItem; subcatItem = catItem;
stringItem = new StringItemWithView( p_module->psz_object_name );
BuildConfigView( stringItem, &p_item, false ); otherItem = new ConfigItem( p_intf,
fOutline->AddUnder( stringItem, capabilityItem ); p_module->psz_shortname ?
p_module->psz_shortname : p_module->psz_object_name,
p_module->b_submodule,
p_module->b_submodule ?
((module_t *)p_module->p_parent)->i_object_id :
p_module->i_object_id,
TYPE_MODULE,
NULL );
fOutline->AddUnder( otherItem, subcatItem );
} }
vlc_list_release( p_list ); vlc_list_release( p_list );
for( int i = 0; i < fOutline->FullListCountItems(); i++ )
{
otherItem = (ConfigItem *)
fOutline->FullListItemAt( i );
if( fOutline->Superitem( otherItem ) )
{
fOutline->Collapse( otherItem );
}
}
/* Set the correct values */ /* Set the correct values */
ApplyChanges( false ); ApplyChanges( false );
/* Sort items, collapse the tree */
fOutline->FullListSortItems( compare_func );
fOutline->Collapse( modulesItem );
for( int i = 0; i < fOutline->CountItemsUnder( modulesItem, true ); i++ )
fOutline->Collapse( fOutline->ItemUnderAt( modulesItem, true, i ) );
/* Select the first item */ /* Select the first item */
fOutline->Select( 0 ); fOutline->Select( 0 );
...@@ -264,7 +284,7 @@ bool PreferencesWindow::QuitRequested() ...@@ -264,7 +284,7 @@ bool PreferencesWindow::QuitRequested()
{ {
Hide(); Hide();
} }
return false; return false;
} }
/***************************************************************************** /*****************************************************************************
...@@ -314,22 +334,22 @@ void PreferencesWindow::Update() ...@@ -314,22 +334,22 @@ void PreferencesWindow::Update()
/* Get the selected item, if any */ /* Get the selected item, if any */
if( fOutline->CurrentSelection() < 0 ) if( fOutline->CurrentSelection() < 0 )
return; return;
fCurrent = (StringItemWithView*) fCurrent = (ConfigItem*)
fOutline->ItemAt( fOutline->CurrentSelection() ); fOutline->ItemAt( fOutline->CurrentSelection() );
if( !fCurrent->fConfigBox ) /* Detach the old box if any */
/* This is a category */
return;
/* Detach the old item */
if( fDummyView->CountChildren() > 0 ) if( fDummyView->CountChildren() > 0 )
fDummyView->RemoveChild( fDummyView->ChildAt( 0 ) ); fDummyView->RemoveChild( fDummyView->ChildAt( 0 ) );
/* Resize and show the new config box */ /* Add the new one... */
fCurrent->fConfigBox->ResizeTo( fDummyView->Bounds().Width(), fDummyView->AddChild( fCurrent->Box() );
fDummyView->Bounds().Height() );
fDummyView->AddChild( fCurrent->fConfigBox );
/* ...then resize it (we must resize it after it's attached or the
children don't get adjusted) */
fCurrent->Box()->ResizeTo( fDummyView->Bounds().Width(),
fDummyView->Bounds().Height() );
#if 0
/* Force redrawing of its children */ /* Force redrawing of its children */
BRect rect = fCurrent->fConfigBox->Bounds(); BRect rect = fCurrent->fConfigBox->Bounds();
rect.InsetBy( 10,10 ); rect.InsetBy( 10,10 );
...@@ -338,6 +358,7 @@ void PreferencesWindow::Update() ...@@ -338,6 +358,7 @@ void PreferencesWindow::Update()
fCurrent->fConfigScroll->Draw( fCurrent->fConfigScroll->Bounds() ); fCurrent->fConfigScroll->Draw( fCurrent->fConfigScroll->Bounds() );
UpdateScrollBar(); UpdateScrollBar();
#endif
} }
...@@ -349,6 +370,7 @@ void PreferencesWindow::UpdateScrollBar() ...@@ -349,6 +370,7 @@ void PreferencesWindow::UpdateScrollBar()
/* We have to fix the scrollbar manually because it doesn't handle /* We have to fix the scrollbar manually because it doesn't handle
correctly simple BViews */ correctly simple BViews */
#if 0
if( !fCurrent ) if( !fCurrent )
{ {
return; return;
...@@ -369,6 +391,7 @@ void PreferencesWindow::UpdateScrollBar() ...@@ -369,6 +391,7 @@ void PreferencesWindow::UpdateScrollBar()
scrollBar->SetRange( 0, max ); scrollBar->SetRange( 0, max );
scrollBar->SetProportion( visible.Height() / total.Height() ); scrollBar->SetProportion( visible.Height() / total.Height() );
scrollBar->SetSteps( 10, 100 ); scrollBar->SetSteps( 10, 100 );
#endif
} }
/***************************************************************************** /*****************************************************************************
...@@ -377,27 +400,12 @@ void PreferencesWindow::UpdateScrollBar() ...@@ -377,27 +400,12 @@ void PreferencesWindow::UpdateScrollBar()
*****************************************************************************/ *****************************************************************************/
void PreferencesWindow::ApplyChanges( bool doIt ) void PreferencesWindow::ApplyChanges( bool doIt )
{ {
StringItemWithView * item; ConfigItem * item;
BView * view;
ConfigWidget * child;
BString string;
for( int i = 0; i < fOutline->CountItems(); i++ ) for( int i = 0; i < fOutline->CountItems(); i++ )
{ {
item = (StringItemWithView*) fOutline->ItemAt( i ); item = (ConfigItem*) fOutline->ItemAt( i );
view = item->fConfigView; item->Apply( doIt );
if( !view )
{
/* This is a category */
continue;
}
for( int j = 0; j < view->CountChildren(); j++ )
{
child = (ConfigWidget*) view->ChildAt( j );
child->Apply( p_intf, doIt );
}
} }
} }
...@@ -420,161 +428,161 @@ void PreferencesWindow::ReallyQuit() ...@@ -420,161 +428,161 @@ void PreferencesWindow::ReallyQuit()
Quit(); Quit();
} }
/***************************************************************************** /***********************************************************************
* PreferencesWindow::BuildConfigView * ConfigItem::ConfigItem
*****************************************************************************/ ***********************************************************************
void PreferencesWindow::BuildConfigView( StringItemWithView * stringItem, *
module_config_t ** pp_item, **********************************************************************/
bool stop_after_category ) ConfigItem::ConfigItem( intf_thread_t * _p_intf, char * name,
bool subModule, int objectId,
int type, char * help )
: BStringItem( name )
{ {
/* Build the BBox */ p_intf = _p_intf;
BRect rect = fDummyView->Bounds(); fSubModule = subModule;
stringItem->fConfigBox = new BBox( rect, "config box", B_FOLLOW_ALL ); fObjectId = objectId;
stringItem->fConfigBox->SetLabel( stringItem->fText ); fType = type;
fHelp = strdup( help );
/* Build the BView */ fTextView = NULL;
rect = stringItem->fConfigBox->Bounds();
rect.InsetBy( 10,10 );
rect.top += 10;
rect.right -= B_V_SCROLL_BAR_WIDTH + 5;
stringItem->fConfigView = new BView( rect, "config view",
B_FOLLOW_NONE, B_WILL_DRAW );
stringItem->fConfigView->SetViewColor(
ui_color( B_PANEL_BACKGROUND_COLOR ) );
/* Add all the settings options */
rect = stringItem->fConfigView->Bounds();
rect.InsetBy( 10, 10 );
ConfigTextControl * textControl; BRect r;
ConfigCheckBox * checkBox; r = BRect( 0, 0, 100, 100 );
ConfigMenuField * menuField; fBox = new BBox( r, NULL, B_FOLLOW_ALL );
ConfigSlider * slider; fBox->SetLabel( name );
ConfigKey * keyConfig;
for( ; (*pp_item)->i_type != CONFIG_HINT_END; (*pp_item)++ ) if( fType == TYPE_CATEGORY )
{ {
if( stop_after_category && r = fBox->Bounds();
(*pp_item)->i_type == CONFIG_HINT_CATEGORY ) r.InsetBy( 10, 10 );
{ r.top += 5;
break;
} fTextView = new VTextView( r, NULL, B_FOLLOW_ALL, B_WILL_DRAW);
fTextView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
switch( (*pp_item)->i_type ) fTextView->MakeEditable( false );
{ fTextView->MakeSelectable( false );
case CONFIG_ITEM_STRING: fTextView->Insert( fHelp );
case CONFIG_ITEM_FILE: fBox->AddChild( fTextView );
case CONFIG_ITEM_MODULE: }
case CONFIG_ITEM_DIRECTORY: }
if( (*pp_item)->ppsz_list && (*pp_item)->ppsz_list[0] )
{
menuField = new ConfigMenuField( rect,
(*pp_item)->i_type, (*pp_item)->psz_text,
(*pp_item)->psz_name, (*pp_item)->ppsz_list );
stringItem->fConfigView->AddChild( menuField );
rect.top += menuField->Bounds().Height();
}
else
{
textControl = new ConfigTextControl( rect,
(*pp_item)->i_type, (*pp_item)->psz_text,
(*pp_item)->psz_name );
stringItem->fConfigView->AddChild( textControl );
rect.top += textControl->Bounds().Height();
}
break;
case CONFIG_ITEM_INTEGER: /***********************************************************************
if( (*pp_item)->i_min == (*pp_item)->i_max ) * ConfigItem::~ConfigItem
{ ***********************************************************************
textControl = new ConfigTextControl( rect, *
CONFIG_ITEM_INTEGER, (*pp_item)->psz_text, **********************************************************************/
(*pp_item)->psz_name ); ConfigItem::~ConfigItem()
stringItem->fConfigView->AddChild( textControl ); {
rect.top += textControl->Bounds().Height(); if( fHelp )
} {
else free( fHelp );
{ }
slider = new ConfigSlider( rect, CONFIG_ITEM_INTEGER, }
(*pp_item)->psz_text, (*pp_item)->psz_name,
(*pp_item)->i_min, (*pp_item)->i_max );
stringItem->fConfigView->AddChild( slider );
rect.top += slider->Bounds().Height();
}
break;
case CONFIG_ITEM_FLOAT: /***********************************************************************
if( (*pp_item)->f_min == (*pp_item)->f_max ) * ConfigItem::Apply
{ ***********************************************************************
textControl = new ConfigTextControl( rect, *
CONFIG_ITEM_FLOAT, (*pp_item)->psz_text, **********************************************************************/
(*pp_item)->psz_name ); void ConfigItem::Apply( bool doIt )
stringItem->fConfigView->AddChild( textControl ); {
rect.top += textControl->Bounds().Height(); ConfigWidget * widget;
}
else
{
slider = new ConfigSlider( rect, CONFIG_ITEM_FLOAT,
(*pp_item)->psz_text, (*pp_item)->psz_name,
100 * (*pp_item)->f_min, 100 * (*pp_item)->f_max );
stringItem->fConfigView->AddChild( slider );
rect.top += slider->Bounds().Height();
}
break;
case CONFIG_ITEM_BOOL: return;
checkBox = new ConfigCheckBox( rect,
CONFIG_ITEM_BOOL, (*pp_item)->psz_text,
(*pp_item)->psz_name );
stringItem->fConfigView->AddChild( checkBox );
rect.top += checkBox->Bounds().Height();
break;
case CONFIG_ITEM_KEY: if( !fView )
keyConfig = new ConfigKey( rect, CONFIG_ITEM_KEY, {
(*pp_item)->psz_text, (*pp_item)->psz_name ); /* This is a category */
stringItem->fConfigView->AddChild( keyConfig ); return;
rect.top += keyConfig->Bounds().Height();
}
} }
/* Put the BView into a BScrollView */ /* Call ConfigWidget::Apply for every child of your fView */
stringItem->fConfigScroll = for( int i = 0; i < fView->CountChildren(); i++ )
new BScrollView( "config scroll", stringItem->fConfigView, {
B_FOLLOW_ALL, 0, false, true, B_FANCY_BORDER ); widget = (ConfigWidget*) fView->ChildAt( i );
stringItem->fConfigScroll->SetViewColor( widget->Apply( doIt );
ui_color( B_PANEL_BACKGROUND_COLOR ) ); }
stringItem->fConfigBox->AddChild( stringItem->fConfigScroll );
/* Adjust the configView size */
stringItem->fConfigView->ResizeTo(
stringItem->fConfigView->Bounds().Width(), rect.top );
} }
ConfigWidget::ConfigWidget( BRect rect, int type, char * configName ) /***********************************************************************
* ConfigWidget::ConfigWidget
***********************************************************************
* Builds a view with the right controls for the given config variable.
* rect: the BRect where we place ourselves. All we care is its width
* and its top coordinate, since we adapt our height to take only
* the place we need
**********************************************************************/
ConfigWidget::ConfigWidget( intf_thread_t * _p_intf, BRect rect,
module_config_t * p_item )
: BView( rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW ) : BView( rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW )
{ {
fConfigType = type; #if 0
fConfigName = strdup( configName ); fType = type;
SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
}
ConfigTextControl::ConfigTextControl( BRect rect, int type, char * label, switch( fType )
char * configName ) {
: ConfigWidget( BRect( rect.left, rect.top, case CONFIG_ITEM_STRING:
rect.right, rect.top + 25 ), case CONFIG_ITEM_FILE:
type, configName ) case CONFIG_ITEM_MODULE:
{ case CONFIG_ITEM_DIRECTORY:
fTextControl = new BTextControl( Bounds(), NULL, label, NULL, case CONFIG_ITEM_INTEGER:
case CONFIG_ITEM_FLOAT:
ResizeTo( Bounds().Width(), 25 );
fTextControl = new BTextControl( Bounds(), NULL, label, NULL,
new BMessage() ); new BMessage() );
AddChild( fTextControl ); AddChild( fTextControl );
break;
case CONFIG_ITEM_BOOL:
ResizeTo( Bounds().Width(), 25 );
fCheckBox = new BCheckBox( Bounds(), NULL, label, new BMessage() );
AddChild( fCheckBox );
break;
case CONFIG_ITEM_KEY:
ResizeTo( Bounds().Width(), 25 );
r.left = r.right - 60;
fPopUpMenu = new BPopUpMenu( "" );
fMenuField = new BMenuField( r, NULL, NULL, fPopUpMenu );
for( unsigned i = 0;
i < sizeof( vlc_keys ) / sizeof( key_descriptor_t ); i++ )
{
menuItem = new BMenuItem( vlc_keys[i].psz_key_string, NULL );
fPopUpMenu->AddItem( menuItem );
}
r.right = r.left - 10; r.left = r.left - 60;
fShiftCheck = new BCheckBox( r, NULL, "Shift", new BMessage );
r.right = r.left - 10; r.left = r.left - 60;
fCtrlCheck = new BCheckBox( r, NULL, "Ctrl", new BMessage );
r.right = r.left - 10; r.left = r.left - 60;
fAltCheck = new BCheckBox( r, NULL, "Alt", new BMessage );
/* Can someone tell me how we're supposed to get GUI items aligned ? */
r.right = r.left - 10; r.left = 0;
r.bottom -= 10;
fStringView = new BStringView( r, NULL, label );
AddChild( fStringView );
AddChild( fAltCheck );
AddChild( fCtrlCheck );
AddChild( fShiftCheck );
AddChild( fMenuField );
break;
#endif
} }
void ConfigTextControl::Apply( intf_thread_t * p_intf, bool doIt ) /***********************************************************************
* ConfigWidget::Apply
***********************************************************************
*
**********************************************************************/
void ConfigWidget::Apply( bool doIt )
{ {
char string[1024]; #if 0
switch( fType )
switch( fConfigType )
{ {
case CONFIG_ITEM_STRING: case CONFIG_ITEM_STRING:
case CONFIG_ITEM_FILE: case CONFIG_ITEM_FILE:
...@@ -589,6 +597,7 @@ void ConfigTextControl::Apply( intf_thread_t * p_intf, bool doIt ) ...@@ -589,6 +597,7 @@ void ConfigTextControl::Apply( intf_thread_t * p_intf, bool doIt )
fTextControl->SetText( config_GetPsz( p_intf, fConfigName ) ); fTextControl->SetText( config_GetPsz( p_intf, fConfigName ) );
} }
break; break;
case CONFIG_ITEM_INTEGER: case CONFIG_ITEM_INTEGER:
if( doIt ) if( doIt )
{ {
...@@ -603,6 +612,7 @@ void ConfigTextControl::Apply( intf_thread_t * p_intf, bool doIt ) ...@@ -603,6 +612,7 @@ void ConfigTextControl::Apply( intf_thread_t * p_intf, bool doIt )
fTextControl->SetText( string ); fTextControl->SetText( string );
} }
break; break;
case CONFIG_ITEM_FLOAT: case CONFIG_ITEM_FLOAT:
if( doIt ) if( doIt )
{ {
...@@ -617,207 +627,74 @@ void ConfigTextControl::Apply( intf_thread_t * p_intf, bool doIt ) ...@@ -617,207 +627,74 @@ void ConfigTextControl::Apply( intf_thread_t * p_intf, bool doIt )
fTextControl->SetText( string ); fTextControl->SetText( string );
} }
break; break;
}
}
ConfigCheckBox::ConfigCheckBox( BRect rect, int type, char * label,
char * configName )
: ConfigWidget( BRect( rect.left, rect.top,
rect.right, rect.top + 25 ),
type, configName )
{
fCheckBox = new BCheckBox( Bounds(), NULL, label, new BMessage() );
AddChild( fCheckBox );
}
void ConfigCheckBox::Apply( intf_thread_t * p_intf, bool doIt ) case CONFIG_ITEM_BOOL:
{
if( doIt )
{
config_PutInt( p_intf, fConfigName, fCheckBox->Value() );
}
else
{
fCheckBox->SetValue( config_GetInt( p_intf, fConfigName ) );
}
}
ConfigMenuField::ConfigMenuField( BRect rect, int type, char * label,
char * configName, char ** list )
: ConfigWidget( BRect( rect.left, rect.top,
rect.right, rect.top + 25 ),
type, configName )
{
BMenuItem * menuItem;
fPopUpMenu = new BPopUpMenu( "" );
fMenuField = new BMenuField( Bounds(), NULL, label, fPopUpMenu );
for( int i = 0; list[i]; i++ )
{
menuItem = new BMenuItem( list[i], new BMessage() );
fPopUpMenu->AddItem( menuItem );
}
AddChild( fMenuField );
}
void ConfigMenuField::Apply( intf_thread_t * p_intf, bool doIt )
{
BMenuItem * menuItem;
if( doIt )
{
menuItem = fPopUpMenu->FindMarked();
if( menuItem )
{
config_PutPsz( p_intf, fConfigName, menuItem->Label() );
}
}
else
{
char * value = config_GetPsz( p_intf, fConfigName );
if( !value )
{
value = "";
}
for( int i = 0; i < fPopUpMenu->CountItems(); i++ )
{
menuItem = fPopUpMenu->ItemAt( i );
if( !strcmp( value, menuItem->Label() ) )
{
menuItem->SetMarked( true );
break;
}
}
}
}
ConfigSlider::ConfigSlider( BRect rect, int type, char * label,
char * configName, int min, int max )
: ConfigWidget( BRect( rect.left, rect.top,
rect.right, rect.top + 40 ),
type, configName )
{
fSlider = new BSlider( Bounds(), NULL, label, new BMessage(),
min, max, B_TRIANGLE_THUMB );
AddChild( fSlider );
}
void ConfigSlider::Apply( intf_thread_t * p_intf, bool doIt )
{
switch( fConfigType )
{
case CONFIG_ITEM_INTEGER:
if( doIt ) if( doIt )
{ {
config_PutInt( p_intf, fConfigName, fSlider->Value() ); config_PutInt( p_intf, fConfigName, fCheckBox->Value() );
} }
else else
{ {
fSlider->SetValue( config_GetInt( p_intf, fConfigName ) ); fCheckBox->SetValue( config_GetInt( p_intf, fConfigName ) );
} }
break; break;
case CONFIG_ITEM_FLOAT: case CONFIG_ITEM_KEY:
if( doIt ) if( doIt )
{ {
config_PutFloat( p_intf, fConfigName, menuItem = fPopUpMenu->FindMarked();
(float) fSlider->Value() / 100.0 ); if( menuItem )
{
int value = vlc_keys[fPopUpMenu->IndexOf( menuItem )].i_key_code;
if( fAltCheck->Value() )
{
value |= KEY_MODIFIER_ALT;
}
if( fCtrlCheck->Value() )
{
value |= KEY_MODIFIER_CTRL;
}
if( fShiftCheck->Value() )
{
value |= KEY_MODIFIER_SHIFT;
}
config_PutInt( p_intf, fConfigName, value );
}
} }
else else
{ {
fSlider->SetValue( 100 * int value = config_GetInt( p_intf, fConfigName );
config_GetFloat( p_intf, fConfigName ) ); fAltCheck->SetValue( value & KEY_MODIFIER_ALT );
fCtrlCheck->SetValue( value & KEY_MODIFIER_CTRL );
fShiftCheck->SetValue( value & KEY_MODIFIER_SHIFT );
for( unsigned i = 0;
i < sizeof( vlc_keys ) / sizeof( key_descriptor_t ); i++ )
{
if( (unsigned) vlc_keys[i].i_key_code ==
( value & ~KEY_MODIFIER ) )
{
menuItem = fPopUpMenu->ItemAt( i );
menuItem->SetMarked( true );
break;
}
}
} }
break; break;
} }
#endif
} }
ConfigKey::ConfigKey( BRect rect, int type, char * label, VTextView::VTextView( BRect frame, const char *name,
char * configName ) uint32 resizingMode, uint32 flags )
: ConfigWidget( BRect( rect.left, rect.top, : BTextView( frame, name, BRect( 10,10,10,10 ), resizingMode, flags )
rect.right, rect.top + 25 ),
type, configName )
{ {
BRect r = Bounds(); FrameResized( Bounds().Width(), Bounds().Height() );
BMenuItem * menuItem;
r.left = r.right - 60;
fPopUpMenu = new BPopUpMenu( "" );
fMenuField = new BMenuField( r, NULL, NULL, fPopUpMenu );
for( unsigned i = 0;
i < sizeof( vlc_keys ) / sizeof( key_descriptor_t ); i++ )
{
menuItem = new BMenuItem( vlc_keys[i].psz_key_string, NULL );
fPopUpMenu->AddItem( menuItem );
}
r.right = r.left - 10; r.left = r.left - 60;
fShiftCheck = new BCheckBox( r, NULL, "Shift", new BMessage );
r.right = r.left - 10; r.left = r.left - 60;
fCtrlCheck = new BCheckBox( r, NULL, "Ctrl", new BMessage );
r.right = r.left - 10; r.left = r.left - 60;
fAltCheck = new BCheckBox( r, NULL, "Alt", new BMessage );
/* Can someone tell me how we're supposed to get GUI items aligned ? */
r.right = r.left - 10; r.left = 0;
r.bottom -= 10;
fStringView = new BStringView( r, NULL, label );
AddChild( fStringView );
AddChild( fAltCheck );
AddChild( fCtrlCheck );
AddChild( fShiftCheck );
AddChild( fMenuField );
} }
void ConfigKey::Apply( intf_thread_t * p_intf, bool doIt ) void VTextView::FrameResized( float width, float height )
{ {
BMenuItem * menuItem; BTextView::FrameResized( width, height );
SetTextRect( BRect( 10,10, width-11, height-11 ) );
if( doIt )
{
menuItem = fPopUpMenu->FindMarked();
if( menuItem )
{
int value = vlc_keys[fPopUpMenu->IndexOf( menuItem )].i_key_code;
if( fAltCheck->Value() )
{
value |= KEY_MODIFIER_ALT;
}
if( fCtrlCheck->Value() )
{
value |= KEY_MODIFIER_CTRL;
}
if( fShiftCheck->Value() )
{
value |= KEY_MODIFIER_SHIFT;
}
config_PutInt( p_intf, fConfigName, value );
}
}
else
{
int value = config_GetInt( p_intf, fConfigName );
fAltCheck->SetValue( value & KEY_MODIFIER_ALT );
fCtrlCheck->SetValue( value & KEY_MODIFIER_CTRL );
fShiftCheck->SetValue( value & KEY_MODIFIER_SHIFT );
for( unsigned i = 0;
i < sizeof( vlc_keys ) / sizeof( key_descriptor_t ); i++ )
{
if( (unsigned) vlc_keys[i].i_key_code ==
( value & ~KEY_MODIFIER ) )
{
menuItem = fPopUpMenu->ItemAt( i );
menuItem->SetMarked( true );
break;
}
}
}
} }
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* Copyright (C) 1999, 2000, 2001 VideoLAN * Copyright (C) 1999, 2000, 2001 VideoLAN
* $Id$ * $Id$
* *
* Authors: Eric Petit <titer@videolan.org> * Authors: Eric Petit <titer@m0k.org>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -27,101 +27,67 @@ ...@@ -27,101 +27,67 @@
#include <InterfaceKit.h> #include <InterfaceKit.h>
#define PREFS_WINDOW_WIDTH 700 #define PREFS_WINDOW_WIDTH 700
#define PREFS_WINDOW_HEIGHT 400 #define PREFS_WINDOW_HEIGHT 600
#define PREFS_ITEM_SELECTED 'pris' #define PREFS_ITEM_SELECTED 'pris'
#define PREFS_DEFAULTS 'prde' #define PREFS_DEFAULTS 'prde'
#define PREFS_APPLY 'prap' #define PREFS_APPLY 'prap'
#define PREFS_SAVE 'prsa' #define PREFS_SAVE 'prsa'
class StringItemWithView : public BStringItem class VTextView : public BTextView
{
public:
StringItemWithView( const char * text )
: BStringItem( text )
{
fConfigBox = NULL;
fConfigScroll = NULL;
fConfigView = NULL;
fText = strdup( text );
}
/* Here we store the config BBox associated to this module */
BBox * fConfigBox;
BScrollView * fConfigScroll;
BView * fConfigView;
char * fText;
};
class ConfigWidget : public BView
{
public:
ConfigWidget( BRect rect, int type, char * configName );
virtual void Apply( intf_thread_t * p_intf, bool doIt ) = 0;
protected:
int fConfigType;
char * fConfigName;
};
class ConfigTextControl : public ConfigWidget
{
public:
ConfigTextControl( BRect rect, int type, char * label,
char * configName );
void Apply( intf_thread_t * p_intf, bool doIt );
private:
BTextControl * fTextControl;
};
class ConfigCheckBox : public ConfigWidget
{ {
public: public:
ConfigCheckBox( BRect rect, int type, char * label, VTextView( BRect frame, const char *name,
char * configName ); uint32 resizingMode, uint32 flags );
void Apply( intf_thread_t * p_intf, bool doIt ); void FrameResized( float width, float height );
private:
BCheckBox * fCheckBox;
}; };
class ConfigMenuField : public ConfigWidget class ConfigWidget : public BView
{ {
public: public:
ConfigMenuField( BRect rect, int type, char * label, ConfigWidget( intf_thread_t * p_intf, BRect rect,
char * configName, char ** list ); module_config_t * p_item );
void Apply( intf_thread_t * p_intf, bool doIt ); void Apply( bool doIt );
private: private:
BPopUpMenu * fPopUpMenu; intf_thread_t * p_intf;
BMenuField * fMenuField;
int fType;
BTextControl * fTextControl;
BCheckBox * fCheckBox;
BPopUpMenu * fPopUpMenu;
BMenuField * fMenuField;
BSlider * fSlider;
BStringView * fStringView;
BCheckBox * fAltCheck;
BCheckBox * fCtrlCheck;
BCheckBox * fShiftCheck;
}; };
class ConfigSlider : public ConfigWidget class ConfigItem : public BStringItem
{ {
public: public:
ConfigSlider( BRect rect, int type, char * label, ConfigItem( intf_thread_t * p_intf,
char * configName, int min, int max ); char * name, bool subModule,
void Apply( intf_thread_t * p_intf, bool doIt ); int objectId, int type, char * help );
~ConfigItem();
int ObjectId() { return fObjectId; }
BBox * Box() { return fBox; }
void Apply( bool doIt );
void Pulse();
private: private:
BSlider * fSlider; intf_thread_t * p_intf;
};
class ConfigKey : public ConfigWidget bool fSubModule;
{ int fObjectId;
public: int fType;
ConfigKey( BRect rect, int type, char * label, char * fHelp;
char * configName );
void Apply( intf_thread_t * p_intf, bool doIt );
private: BBox * fBox;
BStringView * fStringView; BScrollView * fScroll;
BCheckBox * fAltCheck; BView * fView;
BCheckBox * fCtrlCheck; VTextView * fTextView;
BCheckBox * fShiftCheck;
BPopUpMenu * fPopUpMenu;
BMenuField * fMenuField;
}; };
class PreferencesWindow : public BWindow class PreferencesWindow : public BWindow
...@@ -144,7 +110,7 @@ class PreferencesWindow : public BWindow ...@@ -144,7 +110,7 @@ class PreferencesWindow : public BWindow
void ReallyQuit(); void ReallyQuit();
private: private:
void BuildConfigView( StringItemWithView * stringItem, void BuildConfigView( ConfigItem * stringItem,
module_config_t ** pp_item, module_config_t ** pp_item,
bool stop_after_category ); bool stop_after_category );
...@@ -152,7 +118,7 @@ class PreferencesWindow : public BWindow ...@@ -152,7 +118,7 @@ class PreferencesWindow : public BWindow
BOutlineListView * fOutline; BOutlineListView * fOutline;
BView * fDummyView; BView * fDummyView;
BScrollView * fConfigScroll; BScrollView * fConfigScroll;
StringItemWithView * fCurrent; ConfigItem * fCurrent;
intf_thread_t * p_intf; intf_thread_t * p_intf;
}; };
......
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