2005-07-26 20:12:05 +04:00
/*
2005-08-24 19:13:52 +04:00
* Copyright 2003 - 2005 , Haiku .
2005-07-26 20:12:05 +04:00
* Distributed under the terms of the MIT License .
2005-08-24 19:13:52 +04:00
*
* Authors :
* Michael Phipps
* J <EFBFBD> r <EFBFBD> me Duval , jerome . duval @ free . fr
2005-07-26 20:12:05 +04:00
*/
2004-03-31 04:35:20 +04:00
# include <ListView.h>
# include <Application.h>
# include <Button.h>
# include <Box.h>
# include <Font.h>
# include <TabView.h>
# include <Directory.h>
# include <Entry.h>
# include <File.h>
# include <Path.h>
# include <ScrollView.h>
# include <FindDirectory.h>
# include <Slider.h>
# include <StringView.h>
# include <ScreenSaver.h>
2004-04-20 06:05:24 +04:00
# include <Roster.h>
2004-03-31 04:35:20 +04:00
# include <stdio.h>
2005-07-26 20:12:05 +04:00
# include "ScreenSaverWindow.h"
2005-07-29 11:41:58 +04:00
# include "ScreenSaverItem.h"
2005-07-26 20:12:05 +04:00
# include "MouseAreaView.h"
# include "PreviewView.h"
2005-07-29 11:41:58 +04:00
# include <Debug.h>
# define CALLED() PRINT(("%s\n", __PRETTY_FUNCTION__))
2005-07-26 20:12:05 +04:00
static const char * kTimes [ ] = { " 30 seconds " , " 1 minute " , " 1 minute 30 seconds " ,
" 2 minutes " , " 2 minutes 30 seconds " , " 3 minutes " ,
" 4 minutes " , " 5 minutes " , " 6 minutes " ,
" 7 minutes " , " 8 minutes " , " 9 minutes " ,
" 10 minutes " , " 15 minutes " , " 20 minutes " ,
" 25 minutes " , " 30 minutes " , " 40 minutes " ,
" 50 minutes " , " 1 hour " , " 1 hour 30 minutes " ,
" 2 hours " , " 2 hours 30 minutes " , " 3 hours " ,
" 4 hours " , " 5 hours " } ;
2005-07-29 11:41:58 +04:00
static const int32 kTimeInUnits [ ] = { 30 , 60 , 90 ,
2005-07-26 20:12:05 +04:00
120 , 150 , 180 ,
240 , 300 , 360 ,
420 , 480 , 540 ,
600 , 900 , 1200 ,
1500 , 1800 , 2400 ,
3000 , 3600 , 5400 ,
7200 , 9000 , 10800 ,
14400 , 18000 } ;
2005-07-29 11:41:58 +04:00
int32
UnitsToSlider ( bigtime_t val )
2004-05-04 02:41:30 +04:00
{
2005-07-29 11:41:58 +04:00
int count = sizeof ( kTimeInUnits ) / sizeof ( int ) ;
for ( int t = 0 ; t < count ; t + + )
if ( kTimeInUnits [ t ] * 1000000LL = = val )
return t ;
2004-05-04 02:41:30 +04:00
return - 1 ;
}
2005-08-01 16:53:23 +04:00
class ModulesTab : public BTab
{
public :
ModulesTab ( ScreenSaverWin * win , BView * view = NULL ) ;
virtual ~ ModulesTab ( ) ;
virtual void Select ( BView * view ) ;
private :
ScreenSaverWin * fWin ;
} ;
ModulesTab : : ModulesTab ( ScreenSaverWin * win , BView * view = NULL )
: BTab ( view ) ,
fWin ( win )
{
}
ModulesTab : : ~ ModulesTab ( )
{
}
void
ModulesTab : : Select ( BView * view )
{
BTab : : Select ( view ) ;
fWin - > SelectCurrentModule ( ) ;
}
2005-07-26 20:12:05 +04:00
ScreenSaverWin : : ScreenSaverWin ( )
2005-07-29 11:41:58 +04:00
: BWindow ( BRect ( 50 , 50 , 496 , 375 ) , " OBOS Screen Saver " ,
2005-07-26 20:12:05 +04:00
B_TITLED_WINDOW , B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE ) ,
fFadeState ( 0 ) , fNoFadeState ( 0 ) ,
2005-07-29 11:41:58 +04:00
fSelectedAddonFileName ( NULL ) ,
2005-07-26 20:12:05 +04:00
fCurrentAddon ( NULL ) , fTestButton ( NULL ) ,
fTurnOffMinutes ( NULL ) , fRunMinutes ( NULL ) ,
fPasswordMinutes ( NULL ) , fPasswordButton ( NULL ) ,
fFadeNowString ( NULL ) ,
fFadeNowString2 ( NULL ) ,
fDontFadeString ( NULL ) , fDontFadeString2 ( NULL ) ,
fFadeNow ( NULL ) , fFadeNever ( NULL ) ,
2005-08-23 15:29:30 +04:00
fPwMessenger ( NULL ) , fFilePanel ( NULL ) ,
2005-07-26 20:12:05 +04:00
fSettingsArea ( NULL )
{
SetupForm ( ) ;
}
ScreenSaverWin : : ~ ScreenSaverWin ( )
{
2005-08-23 15:29:30 +04:00
delete fFilePanel ;
2005-07-26 20:12:05 +04:00
}
2004-05-04 02:41:30 +04:00
void
2005-07-29 11:41:58 +04:00
ScreenSaverWin : : SaverSelected ( )
2004-05-04 02:41:30 +04:00
{
2005-07-29 11:41:58 +04:00
CALLED ( ) ;
UpdateStatus ( ) ;
2004-05-04 02:41:30 +04:00
if ( fListView1 - > CurrentSelection ( ) > = 0 ) {
if ( fPreviewDisplay - > ScreenSaver ( ) )
fPreviewDisplay - > ScreenSaver ( ) - > StopConfig ( ) ;
2005-07-29 11:41:58 +04:00
ScreenSaverItem * item = reinterpret_cast < ScreenSaverItem * > ( fListView1 - > ItemAt ( fListView1 - > CurrentSelection ( ) ) ) ;
BString settingsMsgName ( item - > Path ( ) ) ;
2004-05-04 02:41:30 +04:00
fPreviewDisplay - > SetScreenSaver ( settingsMsgName ) ;
if ( fSettingsArea ) {
fModuleSettingsBox - > RemoveChild ( fSettingsArea ) ;
delete fSettingsArea ;
}
2005-07-29 11:41:58 +04:00
BRect bnds = fModuleSettingsBox - > Bounds ( ) ;
2004-04-20 06:05:24 +04:00
bnds . InsetBy ( 5 , 10 ) ;
2005-07-29 11:41:58 +04:00
fSettingsArea = new BView ( bnds , " settingsArea " , B_FOLLOW_NONE , B_WILL_DRAW ) ;
2004-05-04 02:41:30 +04:00
fSettingsArea - > SetViewColor ( 216 , 216 , 216 ) ;
fModuleSettingsBox - > AddChild ( fSettingsArea ) ;
2004-04-20 06:05:24 +04:00
2004-05-04 02:41:30 +04:00
if ( fPreviewDisplay - > ScreenSaver ( ) )
fPreviewDisplay - > ScreenSaver ( ) - > StartConfig ( fSettingsArea ) ;
2004-04-20 06:05:24 +04:00
}
}
2004-05-04 02:41:30 +04:00
void
ScreenSaverWin : : MessageReceived ( BMessage * msg )
{
2004-03-31 04:35:20 +04:00
switch ( msg - > what ) {
2005-07-29 11:41:58 +04:00
case kRunSliderChanged :
fRunSlider - > SetLabel ( kTimes [ fRunSlider - > Value ( ) ] ) ;
if ( fRunSlider - > Value ( ) > fPasswordSlider - > Value ( ) ) {
fTurnOffSlider - > SetValue ( fRunSlider - > Value ( ) ) ;
fTurnOffSlider - > SetLabel ( kTimes [ fTurnOffSlider - > Value ( ) ] ) ;
fPasswordSlider - > SetValue ( fRunSlider - > Value ( ) ) ;
fPasswordSlider - > SetLabel ( kTimes [ fPasswordSlider - > Value ( ) ] ) ;
}
break ;
case kTurnOffSliderChanged :
fTurnOffSlider - > SetLabel ( kTimes [ fTurnOffSlider - > Value ( ) ] ) ;
break ;
case kPasswordSliderChanged :
fPasswordSlider - > SetLabel ( kTimes [ fPasswordSlider - > Value ( ) ] ) ;
if ( fPasswordSlider - > Value ( ) < fRunSlider - > Value ( ) ) {
fRunSlider - > SetValue ( fPasswordSlider - > Value ( ) ) ;
fRunSlider - > SetLabel ( kTimes [ fRunSlider - > Value ( ) ] ) ;
}
break ;
2005-07-29 22:28:06 +04:00
case kPasswordCheckbox :
case kEnableScreenSaverChanged :
UpdateStatus ( ) ;
break ;
2004-05-04 02:41:30 +04:00
case kPwbutton :
fPwMessenger - > SendMessage ( kShow ) ;
2005-07-29 11:41:58 +04:00
break ;
2004-05-04 02:41:30 +04:00
case kSaver_sel :
2004-04-20 06:05:24 +04:00
SaverSelected ( ) ;
break ;
2004-05-04 02:41:30 +04:00
case kTest_btn :
2005-07-29 11:41:58 +04:00
{
2005-07-29 16:05:22 +04:00
BMessage & settings = fPrefs . GetSettings ( ) ;
2005-08-01 16:53:23 +04:00
be_roster - > Launch ( SCREEN_BLANKER_SIG , & settings ) ;
2004-04-20 06:05:24 +04:00
break ;
2005-07-29 11:41:58 +04:00
}
2004-05-04 02:41:30 +04:00
case kAdd_btn :
fFilePanel - > Show ( ) ;
2004-04-20 06:05:24 +04:00
break ;
2004-05-04 02:41:30 +04:00
case kUpdatelist :
2005-07-26 20:12:05 +04:00
PopulateScreenSaverList ( ) ;
2004-04-20 06:05:24 +04:00
break ;
2004-03-31 04:35:20 +04:00
}
BWindow : : MessageReceived ( msg ) ;
}
2004-05-04 02:41:30 +04:00
bool
ScreenSaverWin : : QuitRequested ( )
{
2005-07-26 20:12:05 +04:00
UpdateStatus ( ) ;
2005-07-29 11:41:58 +04:00
fPrefs . SaveSettings ( ) ;
2004-03-31 04:35:20 +04:00
be_app - > PostMessage ( B_QUIT_REQUESTED ) ;
2005-08-23 15:29:30 +04:00
return true ;
2004-03-31 04:35:20 +04:00
}
2004-05-04 02:41:30 +04:00
void
2005-07-26 20:12:05 +04:00
ScreenSaverWin : : UpdateStatus ( void )
2004-05-04 02:41:30 +04:00
{
2004-03-31 04:35:20 +04:00
DisableUpdates ( ) ;
// Policy - enable and disable controls as per checkboxes, etc
2004-05-04 02:41:30 +04:00
fPasswordCheckbox - > SetEnabled ( fEnableCheckbox - > Value ( ) ) ;
fTurnOffScreenCheckBox - > SetEnabled ( fEnableCheckbox - > Value ( ) ) ;
fRunSlider - > SetEnabled ( fEnableCheckbox - > Value ( ) ) ;
fTurnOffSlider - > SetEnabled ( fEnableCheckbox - > Value ( ) & & fTurnOffScreenCheckBox - > Value ( ) ) ;
fTurnOffSlider - > SetEnabled ( false ) ; // This never seems to turn on in the R5 version
fTurnOffScreenCheckBox - > SetEnabled ( false ) ;
fPasswordSlider - > SetEnabled ( fEnableCheckbox - > Value ( ) & & fPasswordCheckbox - > Value ( ) ) ;
fPasswordButton - > SetEnabled ( fEnableCheckbox - > Value ( ) & & fPasswordCheckbox - > Value ( ) ) ;
2004-03-31 04:35:20 +04:00
// Set the labels for the sliders
2004-05-04 02:41:30 +04:00
fRunSlider - > SetLabel ( kTimes [ fRunSlider - > Value ( ) ] ) ;
fTurnOffSlider - > SetLabel ( kTimes [ fTurnOffSlider - > Value ( ) ] ) ;
fPasswordSlider - > SetLabel ( kTimes [ fPasswordSlider - > Value ( ) ] ) ;
2004-03-31 04:35:20 +04:00
EnableUpdates ( ) ;
// Update the saved preferences
2004-05-04 02:41:30 +04:00
fPrefs . SetWindowFrame ( Frame ( ) ) ;
fPrefs . SetWindowTab ( fTabView - > Selection ( ) ) ;
fPrefs . SetTimeFlags ( fEnableCheckbox - > Value ( ) ) ;
2005-07-29 11:41:58 +04:00
fPrefs . SetBlankTime ( 1000000LL * kTimeInUnits [ fRunSlider - > Value ( ) ] ) ;
fPrefs . SetOffTime ( 1000000LL * kTimeInUnits [ fTurnOffSlider - > Value ( ) ] ) ;
fPrefs . SetSuspendTime ( 1000000LL * kTimeInUnits [ fTurnOffSlider - > Value ( ) ] ) ;
fPrefs . SetStandbyTime ( 1000000LL * kTimeInUnits [ fTurnOffSlider - > Value ( ) ] ) ;
2004-05-04 02:41:30 +04:00
fPrefs . SetBlankCorner ( fFadeNow - > getDirection ( ) ) ;
fPrefs . SetNeverBlankCorner ( fFadeNever - > getDirection ( ) ) ;
fPrefs . SetLockEnable ( fPasswordCheckbox - > Value ( ) ) ;
2005-07-29 11:41:58 +04:00
fPrefs . SetPasswordTime ( 1000000LL * kTimeInUnits [ fPasswordSlider - > Value ( ) ] ) ;
int selection = fListView1 - > CurrentSelection ( ) ;
if ( selection > = 0 ) {
fPrefs . SetModuleName ( ( ( ScreenSaverItem * ) ( fListView1 - > ItemAt ( selection ) ) ) - > Text ( ) ) ;
if ( strcmp ( fPrefs . ModuleName ( ) , " Blackness " ) = = 0 )
fPrefs . SetModuleName ( " " ) ;
}
2004-03-31 04:35:20 +04:00
// TODO - Tell the password window to update its stuff
2004-04-20 06:05:24 +04:00
BMessage ssState ;
2004-05-04 02:41:30 +04:00
if ( ( fPreviewDisplay - > ScreenSaver ( ) ) & & ( fPreviewDisplay - > ScreenSaver ( ) - > SaveState ( & ssState ) = = B_OK ) )
2005-07-26 20:12:05 +04:00
fPrefs . SetState ( fPrefs . ModuleName ( ) , & ssState ) ;
2004-03-31 04:35:20 +04:00
} ;
2004-04-20 06:05:24 +04:00
2004-05-04 02:41:30 +04:00
void
2005-07-26 20:12:05 +04:00
ScreenSaverWin : : SetupForm ( )
2004-05-04 02:41:30 +04:00
{
2005-08-23 15:29:30 +04:00
fFilePanel = new BFilePanel ( ) ;
2004-04-20 06:05:24 +04:00
2005-07-26 20:12:05 +04:00
BRect r = Bounds ( ) ;
2004-03-31 04:35:20 +04:00
BTab * tab ;
2004-04-20 06:05:24 +04:00
2004-03-31 04:35:20 +04:00
// Create a background view
2005-07-26 20:12:05 +04:00
BView * background = new BView ( r , " background " , B_FOLLOW_NONE , 0 ) ;
2004-03-31 04:35:20 +04:00
background - > SetViewColor ( 216 , 216 , 216 , 0 ) ;
AddChild ( background ) ;
// Add the tab view to the background
2005-07-29 11:41:58 +04:00
r . top + = 4 ;
2004-05-04 02:41:30 +04:00
fTabView = new BTabView ( r , " tab_view " ) ;
fTabView - > SetViewColor ( 216 , 216 , 216 , 0 ) ;
r = fTabView - > Bounds ( ) ;
2004-03-31 04:35:20 +04:00
r . InsetBy ( 0 , 4 ) ;
2004-05-04 02:41:30 +04:00
r . bottom - = fTabView - > TabHeight ( ) ;
2004-03-31 04:35:20 +04:00
2004-04-20 06:05:24 +04:00
// Time to load the settings into a message and implement them...
2004-05-04 02:41:30 +04:00
fPrefs . LoadSettings ( ) ;
2004-04-20 06:05:24 +04:00
2004-03-31 04:35:20 +04:00
tab = new BTab ( ) ;
2005-07-29 11:41:58 +04:00
fTab2 = new BView ( r , " Fade " , B_FOLLOW_NONE , 0 ) ;
fTabView - > AddTab ( fTab2 , tab ) ;
2004-03-31 04:35:20 +04:00
tab - > SetLabel ( " Fade " ) ;
2005-08-01 16:53:23 +04:00
tab = new ModulesTab ( this ) ;
2005-07-29 11:41:58 +04:00
fTab1 = new BView ( r , " Modules " , B_FOLLOW_NONE , 0 ) ;
fTabView - > AddTab ( fTab1 , tab ) ;
2004-03-31 04:35:20 +04:00
tab - > SetLabel ( " Modules " ) ;
2004-05-04 02:41:30 +04:00
background - > AddChild ( fTabView ) ;
2004-03-31 04:35:20 +04:00
// Create the controls inside the tabs
2005-07-26 20:12:05 +04:00
SetupTab2 ( ) ;
SetupTab1 ( ) ;
2004-03-31 04:35:20 +04:00
// Create the password editing window
2005-07-26 20:12:05 +04:00
fPwWin = new PasswordWindow ( ) ;
fPwMessenger = new BMessenger ( NULL , fPwWin ) ;
2004-05-04 02:41:30 +04:00
fPwWin - > Run ( ) ;
MoveTo ( fPrefs . WindowFrame ( ) . left , fPrefs . WindowFrame ( ) . top ) ;
fTabView - > Select ( fPrefs . WindowTab ( ) ) ;
fEnableCheckbox - > SetValue ( fPrefs . TimeFlags ( ) ) ;
2005-07-29 11:41:58 +04:00
fRunSlider - > SetValue ( UnitsToSlider ( fPrefs . BlankTime ( ) ) ) ;
fTurnOffSlider - > SetValue ( UnitsToSlider ( fPrefs . OffTime ( ) ) ) ;
2004-05-04 02:41:30 +04:00
fFadeNow - > setDirection ( fPrefs . GetBlankCorner ( ) ) ;
fFadeNever - > setDirection ( fPrefs . GetNeverBlankCorner ( ) ) ;
fPasswordCheckbox - > SetValue ( fPrefs . LockEnable ( ) ) ;
2005-07-29 11:41:58 +04:00
fPasswordSlider - > SetValue ( UnitsToSlider ( fPrefs . PasswordTime ( ) ) ) ;
2005-08-01 16:53:23 +04:00
SelectCurrentModule ( ) ;
2005-07-26 20:12:05 +04:00
UpdateStatus ( ) ;
2004-03-31 04:35:20 +04:00
}
2004-05-04 02:41:30 +04:00
2005-08-01 16:53:23 +04:00
void
ScreenSaverWin : : SelectCurrentModule ( )
{
int32 count = fListView1 - > CountItems ( ) ;
for ( int32 i = 0 ; i < count ; i + + ) {
ScreenSaverItem * item = dynamic_cast < ScreenSaverItem * > ( fListView1 - > ItemAt ( i ) ) ;
if ( ( strcmp ( fPrefs . ModuleName ( ) , item - > Text ( ) ) = = 0 )
| | ( strcmp ( fPrefs . ModuleName ( ) , " " ) = = 0 & & strcmp ( item - > Text ( ) , " Blackness " ) = = 0 ) ) {
fListView1 - > Select ( i ) ;
SaverSelected ( ) ;
fListView1 - > ScrollToSelection ( ) ;
break ;
}
}
}
2004-03-31 04:35:20 +04:00
// Set the common Look and Feel stuff for a given control
2004-05-04 02:41:30 +04:00
void
commonLookAndFeel ( BView * widget , bool isSlider , bool isControl )
{
2004-03-31 04:35:20 +04:00
{ rgb_color clr = { 216 , 216 , 216 , 255 } ; widget - > SetViewColor ( clr ) ; }
if ( isSlider ) {
BSlider * slid = dynamic_cast < BSlider * > ( widget ) ;
{ rgb_color clr = { 160 , 160 , 160 , 0 } ; slid - > SetBarColor ( clr ) ; }
slid - > SetHashMarks ( B_HASH_MARKS_NONE ) ;
slid - > SetHashMarkCount ( 0 ) ;
slid - > SetStyle ( B_TRIANGLE_THUMB ) ;
slid - > SetLimitLabels ( " " , " " ) ;
slid - > SetLimitLabels ( NULL , NULL ) ;
slid - > SetLabel ( " 0 minutes " ) ;
slid - > SetValue ( 0 ) ;
slid - > SetEnabled ( true ) ;
2004-05-04 02:41:30 +04:00
}
2004-03-31 04:35:20 +04:00
{ rgb_color clr = { 0 , 0 , 0 , 0 } ; widget - > SetHighColor ( clr ) ; }
widget - > SetFlags ( B_WILL_DRAW | B_NAVIGABLE ) ;
widget - > SetResizingMode ( B_FOLLOW_NONE ) ;
widget - > SetFontSize ( 10 ) ;
widget - > SetFont ( be_plain_font ) ;
if ( isControl ) {
BControl * wid = dynamic_cast < BControl * > ( widget ) ;
wid - > SetEnabled ( true ) ;
}
2004-05-04 02:41:30 +04:00
}
2004-03-31 04:35:20 +04:00
// Iterate over a directory, adding the directories files to the list
2004-05-04 02:41:30 +04:00
void
2005-07-29 11:41:58 +04:00
addScreenSaversToList ( directory_which dir , BListView * list )
2004-05-04 02:41:30 +04:00
{
2004-04-20 06:05:24 +04:00
BPath path ;
find_directory ( dir , & path ) ;
path . Append ( " Screen Savers " , true ) ;
2004-03-31 04:35:20 +04:00
2005-07-29 11:41:58 +04:00
BDirectory ssDir ( path . Path ( ) ) ;
2004-04-20 06:05:24 +04:00
BEntry thisSS ;
char thisName [ B_FILE_NAME_LENGTH ] ;
while ( B_OK = = ssDir . GetNextEntry ( & thisSS , true ) ) {
thisSS . GetName ( thisName ) ;
2005-07-29 11:41:58 +04:00
BString pathname = path . Path ( ) ;
pathname + = " / " ;
pathname + = thisName ;
list - > AddItem ( new ScreenSaverItem ( thisName , pathname . String ( ) ) ) ;
2004-05-04 02:41:30 +04:00
}
2004-03-31 04:35:20 +04:00
}
2004-05-04 02:41:30 +04:00
2005-07-29 11:41:58 +04:00
// sorting function for ScreenSaverItems
2004-05-04 02:41:30 +04:00
int
2005-07-29 11:41:58 +04:00
ScreenSaverWin : : CompareScreenSaverItems ( const void * left , const void * right )
2004-05-04 02:41:30 +04:00
{
2005-07-29 11:41:58 +04:00
ScreenSaverItem * leftItem = * ( ScreenSaverItem * * ) left ;
ScreenSaverItem * rightItem = * ( ScreenSaverItem * * ) right ;
2004-03-31 04:35:20 +04:00
2005-07-29 11:41:58 +04:00
return strcmp ( leftItem - > Text ( ) , rightItem - > Text ( ) ) ;
2004-03-31 04:35:20 +04:00
}
2004-05-04 02:41:30 +04:00
void
2005-07-26 20:12:05 +04:00
ScreenSaverWin : : PopulateScreenSaverList ( void )
2004-05-04 02:41:30 +04:00
{
fListView1 - > DeselectAll ( ) ;
2005-07-29 11:41:58 +04:00
while ( void * i = fListView1 - > RemoveItem ( ( int32 ) 0 ) )
delete ( ( ScreenSaverItem * ) i ) ;
2004-04-20 06:05:24 +04:00
2005-07-29 11:41:58 +04:00
fListView1 - > AddItem ( new ScreenSaverItem ( " Blackness " , " " ) ) ;
addScreenSaversToList ( B_BEOS_ADDONS_DIRECTORY , fListView1 ) ;
addScreenSaversToList ( B_USER_ADDONS_DIRECTORY , fListView1 ) ;
fListView1 - > SortItems ( CompareScreenSaverItems ) ;
2004-03-31 04:35:20 +04:00
}
2004-05-04 02:41:30 +04:00
2004-03-31 04:35:20 +04:00
// Create the controls for the first tab
2004-05-04 02:41:30 +04:00
void
2005-07-26 20:12:05 +04:00
ScreenSaverWin : : SetupTab1 ( )
2004-05-04 02:41:30 +04:00
{
2004-04-20 06:05:24 +04:00
int columns [ 4 ] = { 15 , 150 , 180 , 430 } ;
int rows [ 6 ] = { 15 , 120 , 135 , 255 , 263 , 280 } ;
2004-05-04 02:41:30 +04:00
{ rgb_color clr = { 216 , 216 , 216 , 255 } ; fTab1 - > SetViewColor ( clr ) ; }
fTab1 - > AddChild ( fModuleSettingsBox = new BBox ( BRect ( columns [ 2 ] , rows [ 0 ] , columns [ 3 ] , rows [ 5 ] ) , " ModuleSettingsBox " , B_FOLLOW_NONE , B_WILL_DRAW ) ) ;
fModuleSettingsBox - > SetLabel ( " Module settings " ) ;
fModuleSettingsBox - > SetBorder ( B_FANCY_BORDER ) ;
2004-04-20 06:05:24 +04:00
2004-05-04 02:41:30 +04:00
fListView1 = new BListView ( BRect ( columns [ 0 ] , rows [ 2 ] , columns [ 1 ] + 3 , rows [ 3 ] ) , " ListView1 " , B_SINGLE_SELECTION_LIST ) ;
fTab1 - > AddChild ( new BScrollView ( " scroll_list " , fListView1 , B_FOLLOW_NONE , 0 , false , true ) ) ;
commonLookAndFeel ( fModuleSettingsBox , false , false ) ;
{ rgb_color clr = { 255 , 255 , 255 , 0 } ; fListView1 - > SetViewColor ( clr ) ; }
fListView1 - > SetListType ( B_SINGLE_SELECTION_LIST ) ;
2004-04-20 06:05:24 +04:00
// selection message for screensaver list
2004-05-04 02:41:30 +04:00
fListView1 - > SetSelectionMessage ( new BMessage ( kSaver_sel ) ) ;
2004-03-31 04:35:20 +04:00
2004-05-04 02:41:30 +04:00
fTab1 - > AddChild ( fTestButton = new BButton ( BRect ( columns [ 0 ] , rows [ 4 ] , 91 , rows [ 5 ] ) , " TestButton " , " Test " , new BMessage ( kTest_btn ) ) ) ;
commonLookAndFeel ( fTestButton , false , true ) ;
fTestButton - > SetLabel ( " Test " ) ;
2004-03-31 04:35:20 +04:00
2004-05-04 02:41:30 +04:00
fTab1 - > AddChild ( fAddButton = new BButton ( BRect ( 97 , rows [ 4 ] , columns [ 2 ] - 10 , rows [ 5 ] ) , " AddButton " , " Add... " , new BMessage ( kAdd_btn ) ) ) ;
commonLookAndFeel ( fAddButton , false , true ) ;
fAddButton - > SetLabel ( " Add... " ) ;
2004-03-31 04:35:20 +04:00
2004-05-04 02:41:30 +04:00
fTab1 - > AddChild ( fPreviewDisplay = new PreviewView ( BRect ( columns [ 0 ] + 5 , rows [ 0 ] , columns [ 1 ] , rows [ 1 ] ) , " preview " , & fPrefs ) ) ;
2005-07-26 20:12:05 +04:00
PopulateScreenSaverList ( ) ;
2004-03-31 04:35:20 +04:00
}
2004-05-04 02:41:30 +04:00
2004-03-31 04:35:20 +04:00
// Create the controls for the second tab
2004-05-04 02:41:30 +04:00
void
2005-07-26 20:12:05 +04:00
ScreenSaverWin : : SetupTab2 ( )
2004-05-04 02:41:30 +04:00
{
2004-04-20 06:05:24 +04:00
font_height stdFontHt ;
be_plain_font - > GetHeight ( & stdFontHt ) ;
int stringHeight = ( int ) ( stdFontHt . ascent + stdFontHt . descent ) , sliderHeight = 30 ;
int topEdge ;
2004-05-04 02:41:30 +04:00
{ rgb_color clr = { 216 , 216 , 216 , 255 } ; fTab2 - > SetViewColor ( clr ) ; }
2005-07-29 11:41:58 +04:00
fTab2 - > AddChild ( fEnableScreenSaverBox = new BBox ( BRect ( 8 , 6 , 436 , 280 ) , " EnableScreenSaverBox " ) ) ;
2004-05-04 02:41:30 +04:00
commonLookAndFeel ( fEnableScreenSaverBox , false , false ) ;
2004-04-20 06:05:24 +04:00
2005-07-29 22:28:06 +04:00
fEnableCheckbox = new BCheckBox ( BRect ( 0 , 0 , 90 , stringHeight ) , " EnableCheckBox " , " Enable Screen Saver " , new BMessage ( kEnableScreenSaverChanged ) ) ;
2004-05-04 02:41:30 +04:00
fEnableScreenSaverBox - > SetLabel ( fEnableCheckbox ) ;
fEnableScreenSaverBox - > SetBorder ( B_FANCY_BORDER ) ;
2004-04-20 06:05:24 +04:00
// Run Module
topEdge = 26 ;
2004-05-04 02:41:30 +04:00
fEnableScreenSaverBox - > AddChild ( fStringView1 = new BStringView ( BRect ( 21 , topEdge , 101 , topEdge + stringHeight ) , " StringView1 " , " Run module " ) ) ;
commonLookAndFeel ( fStringView1 , false , false ) ;
fStringView1 - > SetText ( " Run module " ) ;
fStringView1 - > SetAlignment ( B_ALIGN_LEFT ) ;
2005-07-29 11:41:58 +04:00
fEnableScreenSaverBox - > AddChild ( fRunSlider = new BSlider ( BRect ( 132 , topEdge , 415 , topEdge + sliderHeight ) , " RunSlider " , " minutes " , new BMessage ( kRunSliderChanged ) , 0 , 25 ) ) ;
fRunSlider - > SetModificationMessage ( new BMessage ( kRunSliderChanged ) ) ;
2004-05-04 02:41:30 +04:00
commonLookAndFeel ( fRunSlider , true , true ) ;
2004-04-20 06:05:24 +04:00
float w , h ;
2004-05-04 02:41:30 +04:00
fRunSlider - > GetPreferredSize ( & w , & h ) ;
2004-04-20 06:05:24 +04:00
sliderHeight = ( int ) h ;
// Turn Off
topEdge + = sliderHeight ;
2004-05-04 02:41:30 +04:00
fEnableScreenSaverBox - > AddChild ( fTurnOffScreenCheckBox = new BCheckBox ( BRect ( 9 , topEdge , 107 , topEdge + stringHeight ) , " TurnOffScreenCheckBox " , " Turn off screen " , new BMessage ( kTab2_chg ) ) ) ;
commonLookAndFeel ( fTurnOffScreenCheckBox , false , true ) ;
fTurnOffScreenCheckBox - > SetLabel ( " Turn off screen " ) ;
fTurnOffScreenCheckBox - > SetResizingMode ( B_FOLLOW_NONE ) ;
2004-04-20 06:05:24 +04:00
2005-07-29 11:41:58 +04:00
fEnableScreenSaverBox - > AddChild ( fTurnOffSlider = new BSlider ( BRect ( 132 , topEdge , 415 , topEdge + sliderHeight ) , " TurnOffSlider " , " " , new BMessage ( kTurnOffSliderChanged ) , 0 , 25 ) ) ;
fTurnOffSlider - > SetModificationMessage ( new BMessage ( kTurnOffSliderChanged ) ) ;
2004-05-04 02:41:30 +04:00
commonLookAndFeel ( fTurnOffSlider , true , true ) ;
2004-04-20 06:05:24 +04:00
// Password
topEdge + = sliderHeight ;
2005-07-29 11:41:58 +04:00
fEnableScreenSaverBox - > AddChild ( fPasswordCheckbox = new BCheckBox ( BRect ( 9 , topEdge , 108 , topEdge + stringHeight ) , " PasswordCheckbox " , " Password lock " , new BMessage ( kPasswordCheckbox ) ) ) ;
2004-05-04 02:41:30 +04:00
commonLookAndFeel ( fPasswordCheckbox , false , true ) ;
fPasswordCheckbox - > SetLabel ( " Password lock " ) ;
2004-04-20 06:05:24 +04:00
2005-07-29 11:41:58 +04:00
fEnableScreenSaverBox - > AddChild ( fPasswordSlider = new BSlider ( BRect ( 132 , topEdge , 415 , topEdge + sliderHeight ) , " PasswordSlider " , " " , new BMessage ( kPasswordSliderChanged ) , 0 , 25 ) ) ;
fPasswordSlider - > SetModificationMessage ( new BMessage ( kPasswordSliderChanged ) ) ;
2004-05-04 02:41:30 +04:00
commonLookAndFeel ( fPasswordSlider , true , true ) ;
2004-04-20 06:05:24 +04:00
topEdge + = sliderHeight ;
2004-05-04 02:41:30 +04:00
fEnableScreenSaverBox - > AddChild ( fPasswordButton = new BButton ( BRect ( 331 , topEdge , 405 , topEdge + 25 ) , " PasswordButton " , " Password... " , new BMessage ( kPwbutton ) ) ) ;
commonLookAndFeel ( fPasswordButton , false , true ) ;
fPasswordButton - > SetLabel ( " Password... " ) ;
2004-03-31 04:35:20 +04:00
// Bottom
2004-05-04 02:41:30 +04:00
fEnableScreenSaverBox - > AddChild ( fFadeNow = new MouseAreaView ( BRect ( 20 , 205 , 80 , 260 ) , " fadeNow " ) ) ;
fEnableScreenSaverBox - > AddChild ( fFadeNever = new MouseAreaView ( BRect ( 220 , 205 , 280 , 260 ) , " fadeNever " ) ) ;
2004-03-31 04:35:20 +04:00
2004-05-04 02:41:30 +04:00
fEnableScreenSaverBox - > AddChild ( fFadeNowString = new BStringView ( BRect ( 85 , 210 , 188 , 222 ) , " FadeNowString " , " Fade now when " ) ) ;
commonLookAndFeel ( fFadeNowString , false , false ) ;
fFadeNowString - > SetText ( " Fade now when " ) ;
fFadeNowString - > SetAlignment ( B_ALIGN_LEFT ) ;
2004-03-31 04:35:20 +04:00
2004-05-04 02:41:30 +04:00
fEnableScreenSaverBox - > AddChild ( fFadeNowString2 = new BStringView ( BRect ( 85 , 225 , 188 , 237 ) , " FadeNowString2 " , " mouse is here " ) ) ;
commonLookAndFeel ( fFadeNowString2 , false , false ) ;
fFadeNowString2 - > SetText ( " mouse is here " ) ;
fFadeNowString2 - > SetAlignment ( B_ALIGN_LEFT ) ;
2004-03-31 04:35:20 +04:00
2004-05-04 02:41:30 +04:00
fEnableScreenSaverBox - > AddChild ( fDontFadeString = new BStringView ( BRect ( 285 , 210 , 382 , 222 ) , " DontFadeString " , " Don't fade when " ) ) ;
commonLookAndFeel ( fDontFadeString , false , false ) ;
fDontFadeString - > SetText ( " Don't fade when " ) ;
fDontFadeString - > SetAlignment ( B_ALIGN_LEFT ) ;
2004-03-31 04:35:20 +04:00
2004-05-04 02:41:30 +04:00
fEnableScreenSaverBox - > AddChild ( fDontFadeString2 = new BStringView ( BRect ( 285 , 225 , 382 , 237 ) , " DontFadeString2 " , " mouse is here " ) ) ;
commonLookAndFeel ( fDontFadeString2 , false , false ) ;
fDontFadeString2 - > SetText ( " mouse is here " ) ;
fDontFadeString2 - > SetAlignment ( B_ALIGN_LEFT ) ;
2004-03-31 04:35:20 +04:00
}