Major changes. File name changes, much work with code sharing to get

screensaver preview and module settings information correct. Mostly complete.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7127 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Phipps 2004-03-31 00:35:20 +00:00
parent 711c2f0843
commit f7f8f8fdd9
12 changed files with 685 additions and 357 deletions

View File

@ -10,6 +10,7 @@ static const char *times[]={"30 seconds", "1 minute", "1 minute 30 s
"50 minutes", "1 hour", "1 hour 30 minutes",
"2 hours", "2 hours 30 minutes", "3 hours",
"4 hours", "5 hours"};
static const int timeInSeconds[]={ 30, 60, 90,
120, 150, 180,
240, 300, 360,

View File

@ -3,19 +3,19 @@ SubDir OBOS_TOP src prefs screensaver ;
AddResources ScreenSaver : ScreenSaver.rsrc ;
local sources =
OBOSScreenSaverPreferences.cpp
ScreenSaver.cpp
pwWindow.cpp
ScreenSaverPrefsApp.cpp
ScreenSaverWindow.cpp
passwordWindow.cpp
PreviewView.cpp
MouseAreaView.cpp
;
Preference ScreenSaver : $(sources) ;
LinkSharedOSLibs ScreenSaver : screensaver be stdc++.r4 ;
LinkSharedOSLibs ScreenSaver : libscreensaver.so be stdc++.r4 ;
# Ugly hack: Prepend the dir containing Be's ScreenSaver.h to the list of
# include search dirs. Otherwise it won't be found.
# It is certainly a good idea to rename the local files.
PrependObjectHdrs $(sources) : /boot/develop/headers/be/add-ons/screen_saver ;
# PrependObjectHdrs $(sources) : /boot/develop/headers/be/add-ons/screen_saver ;

View File

@ -5,13 +5,11 @@
#include <Shape.h>
#include <stdio.h>
inline BPoint scaleDirect(float x, float y,BRect area)
{
inline BPoint scaleDirect(float x, float y,BRect area) {
return BPoint(area.Width()*x+area.left,area.Height()*y+area.top);
}
inline BRect scaleDirect (float x1,float x2,float y1,float y2,BRect area)
{
inline BRect scaleDirect (float x1,float x2,float y1,float y2,BRect area) {
return BRect(area.Width()*x1+area.left,area.Height()*y1+area.top, area.Width()*x2+area.left,area.Height()*y2+area.top);
}
@ -21,17 +19,16 @@ float positionalY[]= {0,.1,.7,.8,.9,1.0};
inline BPoint scale(int x, int y,BRect area) { return scaleDirect(positionalX[x],positionalY[y],area); }
inline BRect scale(int x1, int x2, int y1, int y2,BRect area) { return scaleDirect(positionalX[x1],positionalX[x2],positionalY[y1],positionalY[y2],area); }
int secondsToSlider(int val)
{
int secondsToSlider(int val) {
int count=sizeof(timeInSeconds)/sizeof(int);
int t;
for (t=0;t<sizeof(timeInSeconds)/sizeof(int);t++)
for (t=0;t<count;t++)
if (timeInSeconds[t]==val)
return t;
return -1;
}
void MouseAreaView::Draw(BRect update)
{
void MouseAreaView::Draw(BRect update) {
SetViewColor(216,216,216);
// Top of monitor
SetHighColor(grey);
@ -59,8 +56,9 @@ void MouseAreaView::Draw(BRect update)
float arrowX[]= {0,.25,.5,.66667,.90,.9};
float arrowY[]= {0,.15,.25,.3333333,.6666667,1.0};
inline BPoint scale3(int x, int y,BRect area,bool invertX,bool invertY)
{ return scaleDirect(((invertX)?1-arrowX[x]:arrowX[x]),((invertY)?1-arrowY[y]:arrowY[y]),area); }
inline BPoint scale3(int x, int y,BRect area,bool invertX,bool invertY) {
return scaleDirect(((invertX)?1-arrowX[x]:arrowX[x]),((invertY)?1-arrowY[y]:arrowY[y]),area); }
BRect getArrowSize(BRect area,bool isCentered)
{
@ -75,10 +73,8 @@ BRect getArrowSize(BRect area,bool isCentered)
return (foo);
}
void MouseAreaView::DrawArrow(void)
{
if (currentDirection!=NONE)
{
void MouseAreaView::DrawArrow(void) {
if (currentDirection!=NONE) {
BRect area(getArrowSize(screenArea,false));
bool invertX=(currentDirection==UPRIGHT||currentDirection==DOWNRIGHT);
bool invertY=(currentDirection==UPRIGHT||currentDirection==UPLEFT);
@ -98,27 +94,23 @@ void MouseAreaView::DrawArrow(void)
SetHighColor(black);
FillShape(&arrow,B_SOLID_HIGH);
}
else
{
PushState();
else {
// PushState();
BRect area(getArrowSize(screenArea,true));
SetHighColor(red);
SetPenSize(2);
StrokeEllipse(area);
StrokeLine(BPoint(area.right,area.top),BPoint(area.left,area.bottom));
PopState();
// PopState();
}
}
void MouseAreaView::MouseUp(BPoint point)
{
if (screenArea.Contains(point))
{
void MouseAreaView::MouseUp(BPoint point) {
if (screenArea.Contains(point)) {
if (getArrowSize(screenArea,true).Contains(point))
currentDirection=NONE;
else
{
else {
float centerX=screenArea.left+(screenArea.Width()/2);
float centerY=screenArea.top+(screenArea.Height()/2);
if (point.x<centerX)

View File

@ -1,6 +1,5 @@
#include <View.h>
enum arrowDirection {UPLEFT,UPRIGHT,DOWNLEFT,DOWNRIGHT,NONE};
#include "ScreenSaverPrefs.h"
class MouseAreaView : public BView
{
@ -12,8 +11,8 @@ class MouseAreaView : public BView
virtual void Draw(BRect update);
virtual void MouseUp(BPoint point);
void DrawArrow(void);
inline int getDirection(void) {return ((int)currentDirection);}
void setDirection(int direction) {currentDirection=(arrowDirection)direction;Draw(BRect (0,0,100,100));}
inline arrowDirection getDirection(void) {return currentDirection;}
void setDirection(arrowDirection direction) {currentDirection=direction;Draw(BRect (0,0,100,100));}
private:
BRect screenArea;
arrowDirection currentDirection;

View File

@ -7,321 +7,70 @@
#include <ScreenSaver.h>
#include <Errors.h>
#include <Screen.h>
#include <String.h>
struct
{
int32 previewThreadId;
BView* previewArea;
BScreenSaver* saver;
bool stopMe;
} previewData;
// viewer thread
int32 previewThread(void* data)
{
int cycleNumber = 0;
if (previewData.saver == 0)
{
std::cout << "saver not there!\n";
return 0;
}
int32 loopOnCount = previewData.saver->LoopOnCount();
int32 loopOnCounter = 0;
int32 loopOffCount = previewData.saver->LoopOffCount();
int32 loopOffCounter = 0;
if (loopOnCount == 0 && loopOffCount == 0)
{
// TODO: fill in setup for "normal" loop counting here?
}
snooze( previewData.saver->TickSize() );
while (!previewData.stopMe)
{
if (previewData.previewArea->Window()->Lock())
{
if (!previewData.previewArea->IsHidden())
{
previewData.saver->Draw( previewData.previewArea, cycleNumber );
}
previewData.previewArea->Window()->Unlock();
// previewData.previewArea->Flush();
}
snooze( previewData.saver->TickSize() );
++cycleNumber;
}
} // end previewThread()
inline BPoint scaleDirect(float x, float y,BRect area)
{
inline BPoint scaleDirect(float x, float y,BRect area) {
return BPoint(area.Width()*x+area.left,area.Height()*y+area.top);
}
inline BRect scaleDirect (float x1,float x2,float y1,float y2,BRect area)
{
inline BRect scaleDirect (float x1,float x2,float y1,float y2,BRect area) {
return BRect(area.Width()*x1+area.left,area.Height()*y1+area.top, area.Width()*x2+area.left,area.Height()*y2+area.top);
}
float sampleX[]= {0,.025,.25,.6,.625,.7,.725,.75,.975,1.0};
float sampleY[]= {0,.05,.8,.9,.933,.966,1.0};
float sampleX[]= {0,.05,.15,.7,.725,.8,.825,.85,.950,1.0};
float sampleY[]= {0,.05,.90,.95,.966,.975,1.0};
inline BPoint scale2(int x, int y,BRect area) { return scaleDirect(sampleX[x],sampleY[y],area); }
inline BRect scale2(int x1, int x2, int y1, int y2,BRect area) { return scaleDirect(sampleX[x1],sampleX[x2],sampleY[y1],sampleY[y2],area); }
PreviewView::PreviewView(BRect frame, const char *name)
PreviewView::PreviewView(BRect frame, const char *name,ScreenSaverPrefs *prefp)
: BView (frame,name,B_FOLLOW_NONE,B_WILL_DRAW),
addonImage (0),
saver (0),
settingsBoxPtr (0),
configView (0),
stopSaver (false),
stopConfigView (false),
removeConfigView (false),
deleteSaver (false),
removePreviewArea (false),
unloadAddon (false),
noPreview (false)
{
SetViewColor(216,216,216);
AddChild(previewArea=new BView (scale2(1,8,1,2,Bounds()),"sampleScreen",B_FOLLOW_NONE,B_WILL_DRAW));
previewArea->SetViewColor(0,0,0);
previewData.previewArea = previewArea;
previewData.previewThreadId = 0;
previewData.saver = 0;
previewData.stopMe = false;
} // end PreviewView::PreviewView()
PreviewView::~PreviewView()
{
if (previewData.previewThreadId != 0)
{
previewData.stopMe = true;
snooze( saver->TickSize() );
kill_thread( previewData.previewThreadId );
previewData.stopMe = false;
}
if (stopSaver)
{
saver->StopSaver();
stopSaver = false;
}
if (stopConfigView)
{
saver->StopConfig();
stopConfigView = false;
}
if (deleteSaver)
{
delete saver;
saver = 0;
deleteSaver = false;
}
if (removeConfigView)
{
settingsBoxPtr->RemoveChild(configView);
delete configView;
settingsBoxPtr->Draw(settingsBoxPtr->Bounds());
removeConfigView = false;
}
if (removePreviewArea)
{
previewArea->RemoveSelf();
delete previewArea;
}
} // end PreviewView::~PreviewView()
void PreviewView::Draw(BRect update)
{
saver (NULL),configView(NULL),sst(NULL),threadID(0),prefPtr(prefp) {
SetViewColor(216,216,216);
SetHighColor(grey);
FillRoundRect(scale2(0,9,0,3,Bounds()),4,4);
SetHighColor(black);
StrokeRoundRect(scale2(0,9,0,3,Bounds()),4,4);
FillRoundRect(scale2(1,8,1,2,Bounds()),4,4);
SetHighColor(grey);
FillRoundRect(scale2(2,7,3,6,Bounds()),4,4);
SetHighColor(black);
StrokeLine(scale2(2,3,Bounds()),scale2(2,6,Bounds()));
StrokeLine(scale2(2,6,Bounds()),scale2(7,6,Bounds()));
StrokeLine(scale2(7,6,Bounds()),scale2(7,3,Bounds()));
SetHighColor(lightGreen);
FillRect(scale2(3,4,4,5,Bounds()));
SetHighColor(darkGrey);
FillRect(scale2(5,6,4,5,Bounds()));
}
PreviewView::~PreviewView() {
}
void PreviewView::SetScreenSaver(BString name) {
if (threadID)
kill_thread(threadID);
if (sst)
delete sst;
if (configView) {
RemoveChild(configView);
delete configView;
}
configView=new BView(scale2(1,8,1,2,Bounds()),"previewArea",B_FOLLOW_NONE,B_WILL_DRAW);
configView->SetViewColor(0,0,0);
AddChild(configView);
sst=new ScreenSaverThread(Window(),configView,prefPtr);
saver=sst->LoadAddOn();
threadID=spawn_thread(threadFunc,"ScreenSaverRenderer",0,sst);
resume_thread(threadID);
}
void PreviewView::LoadNewAddon(const char* addOnFilename, BMessage* settingsMsg)
{
if (previewData.previewThreadId != 0)
{
std::cout << "Ending old thread id=" << previewData.previewThreadId << '\n';
previewData.stopMe = true;
// replace :
//snooze( saver->TickSize() );
//kill_thread( previewData.previewThreadId );
// with :
suspend_thread( previewData.previewThreadId );
resume_thread( previewData.previewThreadId );
// end replace
previewData.stopMe = false;
previewData.previewThreadId = 0;
}
status_t lastOpStatus;
//screen saver's exported instantiation function
BScreenSaver *(*instantiate)(BMessage *, image_id );
if (stopSaver)
{
std::cout << "stopping old saver\n";
saver->StopSaver();
stopSaver = false;
}
if (stopConfigView)
{
std::cout << "stopping config view\n";
saver->StopConfig();
stopConfigView = false;
}
if (deleteSaver)
{
std::cout << "deleting old saver\n";
delete saver;
saver = 0;
deleteSaver = false;
}
if (removeConfigView)
{
std::cout << "removing old config view\n";
settingsBoxPtr->RemoveChild(configView);
delete configView;
settingsBoxPtr->Draw(settingsBoxPtr->Bounds());
removeConfigView = false;
}
if (noPreview)
{
std::cout << "no preview\n";
noPreviewView->RemoveSelf();
delete noPreviewView;
}
if (removePreviewArea)
{
std::cout << "removing preview area\n";
previewArea->RemoveSelf();
delete previewArea;
previewArea=new BView (scale2(1,8,1,2,Bounds()),"sampleScreen",B_FOLLOW_NONE,B_WILL_DRAW);
previewArea->SetViewColor( 0,0,0 );
AddChild(previewArea);
previewData.previewArea = previewArea;
removePreviewArea = false;
}
if (unloadAddon)
{
std::cout << "unloading add-on\n";
unload_add_on(addonImage);
addonImage = 0;
unloadAddon = false;
}
void PreviewView::Draw(BRect update) {
SetViewColor(216,216,216);
addonImage = load_add_on(addOnFilename);
if (addonImage < 0 )
{
std::cout << "Unable to open the add-on " << addOnFilename << "\n"
"load_add_on returned " << std::hex << addonImage << std::dec << "!\n";
return;
}
unloadAddon = true;
SetHighColor(184,184,184);
FillRoundRect(scale2(0,9,0,3,Bounds()),4,4);// Outer shape
FillRoundRect(scale2(2,7,3,6,Bounds()),2,2);// control console outline
std::cout << "Add-on loaded\n";
lastOpStatus = get_image_symbol(addonImage, "instantiate_screen_saver", B_SYMBOL_TYPE_TEXT,(void **) &instantiate);
if (lastOpStatus != B_OK)
{
// add-on does not have proper function exported!
std::cout << "Add-on does not export instantiation function, "
"get_image_symbol() returned " << lastOpStatus << '\n';
return;
}
std::cout << "symbol imported\n";
saver = instantiate(settingsMsg, addonImage);
if (saver == 0)
{
std::cout << "Saver not instantiated.\n";
return;
}
std::cout << "saver instantiated\n";
deleteSaver = true;
previewData.saver = saver;
lastOpStatus = saver->InitCheck();
if ( lastOpStatus != B_OK )
{
std::cout << "InitCheck() said no go, returned " << lastOpStatus << '\n';
return;
}
std::cout << "InitCheck() says we're a go!\n";
lastOpStatus = saver->StartSaver(previewArea, true);
if ( lastOpStatus != B_OK )
{
std::cout << "StartSaver() said no go, returned " << lastOpStatus << '\n';
noPreview = true;
}
else
{
std::cout << "Saver started\n";
stopSaver = true;
noPreview = false;
}
// make config view
BRect configViewBounds = settingsBoxPtr->Bounds();
configViewBounds.InsetBy( 4, 16 );
configView = new BView(configViewBounds, "settings", B_FOLLOW_ALL_SIDES, 0);
configView->SetViewColor(216,216,216);
settingsBoxPtr->AddChild( configView );
saver->StartConfig( configView );
stopConfigView = true;
removeConfigView = true;
std::cout << "Config view made\n";
if ( noPreview )
{
noPreviewView = new BStringView(previewArea->Bounds(), "no_preview", "NO PREVIEW AVAILABLE");
rgb_color white = { 255, 255, 255, 0};
noPreviewView->SetHighColor(white);
noPreviewView->SetAlignment(B_ALIGN_CENTER);
noPreviewView->Draw(previewArea->Bounds());
previewArea->AddChild(noPreviewView);
std::cout << "no preview\n";
}
else
{
previewData.previewThreadId = spawn_thread( previewThread, "preview_thread", 50, NULL );
resume_thread( previewData.previewThreadId );
removePreviewArea = true;
std::cout << "Preview thread started\n";
}
} // end PreviewView::LoadNewAddon()
SetHighColor(96,96,96);
StrokeRoundRect(scale2(2,7,3,6,Bounds()),2,2);// control console outline
StrokeRoundRect(scale2(0,9,0,3,Bounds()),4,4); // Outline outer shape
SetHighColor(black);
// FillRoundRect(scale2(1,8,1,2,Bounds()),4,4);// Screen itself
SetHighColor(184,184,184);
BRect outerShape=scale2(2,7,2,6,Bounds());
outerShape.InsetBy(1,1);
FillRoundRect(outerShape,4,4);// Outer shape
SetHighColor(0,255,0);
FillRect(scale2(3,4,4,5,Bounds()));
SetHighColor(96,96,96);
FillRect(scale2(5,6,4,5,Bounds()));
}

View File

@ -1,38 +1,24 @@
#include <View.h>
#include <Box.h>
#include <MessageRunner.h>
#include <Bitmap.h>
#include <StringView.h>
#include <ScreenSaverThread.h>
#include <ScreenSaverPrefs.h>
class BScreenSaver;
class PreviewView : public BView
{
public:
PreviewView(BRect frame, const char *name);
PreviewView(BRect frame, const char *name,ScreenSaverPrefs *prefp);
~PreviewView();
void Draw(BRect update);
void LoadNewAddon(const char* addOnFilename, BMessage* settingsMsg);
void SetSettingsBoxPtr( BBox* settingsBox )
{ settingsBoxPtr = settingsBox; }
void SetScreenSaver(BString name);
BScreenSaver *ScreenSaver(void) {return saver;}
private:
BView *previewArea;
BBox *settingsBoxPtr;
BView *configView;
image_id addonImage;
BScreenSaver* saver;
// to keep track of what to tear down
bool stopSaver;
bool stopConfigView;
bool removeConfigView;
bool deleteSaver;
bool removePreviewArea;
bool unloadAddon;
bool noPreview;
BStringView *noPreviewView;
BView *configView;
ScreenSaverThread *sst;
thread_id threadID;
ScreenSaverPrefs *prefPtr;
}; // end class PreviewView

View File

@ -0,0 +1,29 @@
#include <Application.h>
#include "ScreenSaverPrefsApp.h"
const char *APP_SIG = "application/x-vnd.OBOS.ScreenSaver";
ScreenSaverPrefsApp::~ScreenSaverPrefsApp(void) {
}
ScreenSaverPrefsApp::ScreenSaverPrefsApp(void) : BApplication(APP_SIG) {
m_MainForm = new ScreenSaverWin();
m_MainForm->Show();
}
void ScreenSaverPrefsApp::MessageReceived(BMessage *message) {
switch(message->what) {
case B_READY_TO_RUN:
break;
default: {
BApplication::MessageReceived(message);
}
}
}
int main(void) {
ScreenSaverPrefsApp app;
app.Run();
return 0;
}

View File

@ -0,0 +1,17 @@
#ifndef _ScreenSaverPrefsApp_H
#define _ScreenSaverPrefsApp_H
#include "ScreenSaverWindow.h"
extern const char *APP_SIG;
class ScreenSaverPrefsApp: public BApplication {
private:
ScreenSaverWin *m_MainForm;
public:
ScreenSaverPrefsApp(void);
virtual ~ScreenSaverPrefsApp(void);
virtual void MessageReceived(BMessage *);
};
#endif // _ScreenSaverPrefsApp_H

View File

@ -0,0 +1,349 @@
#include "ScreenSaverWindow.h"
#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>
#include "MouseAreaView.h"
#include "PreviewView.h"
#include <stdio.h>
void drawPositionalMonitor(BView *view,BRect areaToDrawIn,int state);
BView *drawSampleMonitor(BView *view, BRect area);
struct SSListItem {
BString fileName;
BString displayName;
};
void ScreenSaverWin::MessageReceived(BMessage *msg) {
SSListItem* listItem;
switch(msg->what) {
case PWBUTTON:
pwMessenger->SendMessage(SHOW);
break;
case B_QUIT_REQUESTED:
be_app->PostMessage(B_QUIT_REQUESTED);
break;
case SAVER_SEL:
if (previewDisplay->ScreenSaver())
previewDisplay->ScreenSaver()->StopConfig();
listItem = reinterpret_cast<SSListItem*>(AddonList->ItemAt(ListView1->CurrentSelection()));
BString settingsMsgName(listItem->fileName);
previewDisplay->SetScreenSaver(settingsMsgName);
if (settingsArea) {
ModuleSettingsBox->RemoveChild(settingsArea);
delete settingsArea;
}
BRect bnds=ModuleSettingsBox->Bounds();
bnds.InsetBy(5,10);
settingsArea=new BView(bnds,"settingsArea",B_FOLLOW_NONE,B_WILL_DRAW);
settingsArea->SetViewColor(216,216,216);
ModuleSettingsBox->AddChild(settingsArea);
if (previewDisplay->ScreenSaver())
previewDisplay->ScreenSaver()->StartConfig(settingsArea);
break;
}
updateStatus(); // This could get called sometimes when it doesn't need to. Shouldn't hurt
BWindow::MessageReceived(msg);
}
bool ScreenSaverWin::QuitRequested() {
updateStatus();
be_app->PostMessage(B_QUIT_REQUESTED);
return(true);
}
void ScreenSaverWin::updateStatus(void) {
DisableUpdates();
// Policy - enable and disable controls as per checkboxes, etc
PasswordCheckbox->SetEnabled(EnableCheckbox->Value());
TurnOffScreenCheckBox->SetEnabled(EnableCheckbox->Value());
RunSlider->SetEnabled(EnableCheckbox->Value());
TurnOffSlider->SetEnabled(EnableCheckbox->Value() && TurnOffScreenCheckBox->Value());
TurnOffSlider->SetEnabled(false); // This never seems to turn on in the R5 version
TurnOffScreenCheckBox->SetEnabled(false);
PasswordSlider->SetEnabled(EnableCheckbox->Value() && PasswordCheckbox->Value());
PasswordButton->SetEnabled(EnableCheckbox->Value() && PasswordCheckbox->Value());
// Set the labels for the sliders
RunSlider->SetLabel(times[RunSlider->Value()]);
TurnOffSlider->SetLabel(times[TurnOffSlider->Value()]);
PasswordSlider->SetLabel(times[PasswordSlider->Value()]);
EnableUpdates();
// Update the saved preferences
prefs.SetWindowFrame(Frame());
prefs.SetWindowTab(tabView->Selection());
prefs.SetTimeFlags(EnableCheckbox->Value());
prefs.SetBlankTime(timeInSeconds[RunSlider->Value()]);
prefs.SetOffTime(timeInSeconds[TurnOffSlider->Value()]);
prefs.SetSuspendTime(timeInSeconds[TurnOffSlider->Value()]);
prefs.SetStandbyTime(timeInSeconds[TurnOffSlider->Value()]);
prefs.SetBlankCorner(fadeNow->getDirection());
prefs.SetNeverBlankCorner(fadeNever->getDirection());
prefs.SetLockEnable(PasswordCheckbox->Value());
prefs.SetPasswordTime(timeInSeconds[PasswordSlider->Value()]);
int selection=ListView1->CurrentSelection(0);
//const BStringItem **ptr = (const BStringItem **)(ListView1->Items());
if (selection>=0)
prefs.SetModuleName(((BStringItem *)(ListView1->ItemAt(selection)))->Text());
// TODO - Tell the password window to update its stuff
prefs.SaveSettings();
};
void ScreenSaverWin::SetupForm(void) {
BRect r;
BView *background;
BTab *tab;
r = Bounds();
// Create a background view
background=new BView(r,"background",B_FOLLOW_NONE,0);
background->SetViewColor(216,216,216,0);
AddChild(background);
// Add the tab view to the background
r.InsetBy(0,3);
tabView = new BTabView(r, "tab_view");
tabView->SetViewColor(216,216,216,0);
r = tabView->Bounds();
r.InsetBy(0,4);
r.bottom -= tabView->TabHeight();
tab = new BTab();
tabView->AddTab(tab2=new BView(r,"Fade",B_FOLLOW_NONE,0), tab);
tab->SetLabel("Fade");
tab = new BTab();
tabView->AddTab(tab1=new BView(r,"Modules",B_FOLLOW_NONE,0), tab);
tab->SetLabel("Modules");
background->AddChild(tabView);
// Create the controls inside the tabs
setupTab2();
setupTab1();
// Create the password editing window
pwWin=new pwWindow;
pwMessenger=new BMessenger (NULL,pwWin);
pwWin->Run();
// Time to load the settings into a message and implement them...
prefs.LoadSettings();
prefs.WindowFrame().PrintToStream();
MoveTo(prefs.WindowFrame().left,prefs.WindowFrame().top);
ResizeTo(prefs.WindowFrame().right-prefs.WindowFrame().left,prefs.WindowFrame().bottom-prefs.WindowFrame().top);
tabView->Select(prefs.WindowTab());
EnableCheckbox->SetValue(prefs.TimeFlags());
RunSlider->SetValue(secondsToSlider(prefs.BlankTime()));
TurnOffSlider->SetValue(secondsToSlider(prefs.OffTime()));
fadeNow->setDirection(prefs.GetBlankCorner());
fadeNever->setDirection(prefs.GetNeverBlankCorner());
PasswordCheckbox->SetValue(prefs.LockEnable());
PasswordSlider->SetValue(secondsToSlider(prefs.PasswordTime()));
const BStringItem **ptr = (const BStringItem **)(ListView1->Items());
long count=ListView1->CountItems();
if (prefs.Password() && ptr)
for ( long i = 0; i < count; i++ ) {
if (BString(prefs.Password())==((*ptr++)->Text()))
ListView1->Select(count=i); // Clever bit here - intentional assignment.
}
updateStatus();
}
// Set the common Look and Feel stuff for a given control
void commonLookAndFeel(BView *widget,bool isSlider,bool isControl) {
{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);
}
{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);
}
}
// Iterate over a directory, adding the directories files to the list
void addScreenSaversToList (directory_which dir, BList *list) {
BPath path;
find_directory(dir,&path);
path.Append("Screen Savers",true);
const char* pathName = path.Path();
BDirectory ssDir(pathName);
BEntry thisSS;
char thisName[B_FILE_NAME_LENGTH];
while (B_OK==ssDir.GetNextEntry(&thisSS,true)) {
thisSS.GetName(thisName);
SSListItem* tempListItem = new SSListItem;
tempListItem->fileName = pathName;
tempListItem->fileName += "/";
tempListItem->fileName += thisName;
tempListItem->displayName = thisName;
list->AddItem(tempListItem);
}
}
// sorting function for SSListItems
int compareSSListItems(const void* left, const void* right) {
SSListItem* leftItem = *(SSListItem **)left;
SSListItem* rightItem = *(SSListItem **)right;
return leftItem->displayName.Compare(rightItem->displayName);
}
// Add the strings in the BList to a BListView
void displayScreenSaversList(BList* list, BListView* view) {
list->SortItems(compareSSListItems);
int numItems = list->CountItems();
for( int i = 0; i < numItems; ++i ) {
SSListItem* item = (SSListItem*)(list->ItemAt(i));
view->AddItem( new BStringItem(item->displayName.String()) );
}
}
// Create the controls for the first tab
void ScreenSaverWin::setupTab1(void) {
int columns[4]={15,150,180,430};
int rows[6]={15,125,135,255,263,276};
{rgb_color clr = {216,216,216,255}; tab1->SetViewColor(clr);}
tab1->AddChild( ModuleSettingsBox = new BBox(BRect(columns[2],rows[0],columns[3],rows[5]),"ModuleSettingsBox",B_FOLLOW_NONE,B_WILL_DRAW));
ModuleSettingsBox->SetLabel("Module settings");
ModuleSettingsBox->SetBorder(B_FANCY_BORDER);
ListView1 = new BListView(BRect(columns[0],rows[2],columns[1]+3,rows[3]),"ListView1",B_SINGLE_SELECTION_LIST);
tab1->AddChild(new BScrollView("scroll_list",ListView1,B_FOLLOW_NONE,0,false,true));
commonLookAndFeel(ModuleSettingsBox,false,false);
{rgb_color clr = {255,255,255,0}; ListView1->SetViewColor(clr);}
ListView1->SetListType(B_SINGLE_SELECTION_LIST);
// selection message for screensaver list
ListView1->SetSelectionMessage( new BMessage( SAVER_SEL ) );
tab1->AddChild( TestButton = new BButton(BRect(columns[0],rows[4],91,rows[5]),"TestButton","Test", new BMessage (TAB1_CHG)));
commonLookAndFeel(TestButton,false,true);
TestButton->SetLabel("Test");
tab1->AddChild( AddButton = new BButton(BRect(97,rows[4],columns[2]-10,rows[5]),"AddButton","Add...", new BMessage (TAB1_CHG)));
commonLookAndFeel(AddButton,false,true);
AddButton->SetLabel("Add...");
tab1->AddChild(previewDisplay = new PreviewView(BRect(columns[0]+5,rows[0],columns[1],rows[1]),"preview",&prefs));
AddonList = new BList;
addScreenSaversToList( B_BEOS_ADDONS_DIRECTORY, AddonList );
addScreenSaversToList( B_USER_ADDONS_DIRECTORY, AddonList );
displayScreenSaversList( AddonList, ListView1 );
}
// Create the controls for the second tab
void ScreenSaverWin::setupTab2(void) {
font_height stdFontHt;
be_plain_font->GetHeight(&stdFontHt);
int stringHeight=(int)(stdFontHt.ascent+stdFontHt.descent),sliderHeight=30;
int topEdge;
{rgb_color clr = {216,216,216,255}; tab2->SetViewColor(clr);}
tab2->AddChild( EnableScreenSaverBox = new BBox(BRect(11,13,437,280),"EnableScreenSaverBox"));
commonLookAndFeel(EnableScreenSaverBox,false,false);
EnableCheckbox = new BCheckBox(BRect(0,0,90,stringHeight),"EnableCheckBox","Enable Screen Saver", new BMessage (TAB2_CHG));
EnableScreenSaverBox->SetLabel(EnableCheckbox);
EnableScreenSaverBox->SetBorder(B_FANCY_BORDER);
// Run Module
topEdge=26;
EnableScreenSaverBox->AddChild( StringView1 = new BStringView(BRect(21,topEdge,101,topEdge+stringHeight),"StringView1","Run module"));
commonLookAndFeel(StringView1,false,false);
StringView1->SetText("Run module");
StringView1->SetAlignment(B_ALIGN_LEFT);
EnableScreenSaverBox->AddChild( RunSlider = new BSlider(BRect(132,topEdge,415,topEdge+sliderHeight),"RunSlider","minutes", new BMessage(TAB2_CHG), 0, 25));
RunSlider->SetModificationMessage(new BMessage(TAB2_CHG));
commonLookAndFeel(RunSlider,true,true);
float w,h;
RunSlider->GetPreferredSize(&w,&h);
sliderHeight=(int)h;
// Turn Off
topEdge+=sliderHeight;
EnableScreenSaverBox->AddChild( TurnOffScreenCheckBox = new BCheckBox(BRect(9,topEdge,107,topEdge+stringHeight),"TurnOffScreenCheckBox","Turn off screen", new BMessage (TAB2_CHG)));
commonLookAndFeel(TurnOffScreenCheckBox,false,true);
TurnOffScreenCheckBox->SetLabel("Turn off screen");
TurnOffScreenCheckBox->SetResizingMode(B_FOLLOW_NONE);
EnableScreenSaverBox->AddChild( TurnOffSlider = new BSlider(BRect(132,topEdge,415,topEdge+sliderHeight),"TurnOffSlider","", new BMessage(TAB2_CHG), 0, 25));
TurnOffSlider->SetModificationMessage(new BMessage(TAB2_CHG));
commonLookAndFeel(TurnOffSlider,true,true);
// Password
topEdge+=sliderHeight;
EnableScreenSaverBox->AddChild( PasswordCheckbox = new BCheckBox(BRect(9,topEdge,108,topEdge+stringHeight),"PasswordCheckbox","Password lock", new BMessage (TAB2_CHG)));
commonLookAndFeel(PasswordCheckbox,false,true);
PasswordCheckbox->SetLabel("Password lock");
EnableScreenSaverBox->AddChild( PasswordSlider = new BSlider(BRect(132,topEdge,415,topEdge+sliderHeight),"PasswordSlider","", new BMessage(TAB2_CHG), 0, 25));
PasswordSlider->SetModificationMessage(new BMessage(TAB2_CHG));
commonLookAndFeel(PasswordSlider,true,true);
topEdge+=sliderHeight;
EnableScreenSaverBox->AddChild( PasswordButton = new BButton(BRect(331,topEdge,405,topEdge+25),"PasswordButton","Password...", new BMessage (PWBUTTON)));
commonLookAndFeel(PasswordButton,false,true);
PasswordButton->SetLabel("Password...");
// Bottom
EnableScreenSaverBox->AddChild(fadeNow=new MouseAreaView(BRect(20,205,80,260),"fadeNow"));
EnableScreenSaverBox->AddChild(fadeNever=new MouseAreaView(BRect(220,205,280,260),"fadeNever"));
EnableScreenSaverBox->AddChild( FadeNowString = new BStringView(BRect(85,210,188,222),"FadeNowString","Fade now when"));
commonLookAndFeel(FadeNowString,false,false);
FadeNowString->SetText("Fade now when");
FadeNowString->SetAlignment(B_ALIGN_LEFT);
EnableScreenSaverBox->AddChild( FadeNowString2 = new BStringView(BRect(85,225,188,237),"FadeNowString2","mouse is here"));
commonLookAndFeel(FadeNowString2,false,false);
FadeNowString2->SetText("mouse is here");
FadeNowString2->SetAlignment(B_ALIGN_LEFT);
EnableScreenSaverBox->AddChild( DontFadeString = new BStringView(BRect(285,210,382,222),"DontFadeString","Don't fade when"));
commonLookAndFeel(DontFadeString,false,false);
DontFadeString->SetText("Don't fade when");
DontFadeString->SetAlignment(B_ALIGN_LEFT);
EnableScreenSaverBox->AddChild( DontFadeString2 = new BStringView(BRect(285,225,382,237),"DontFadeString2","mouse is here"));
commonLookAndFeel(DontFadeString2,false,false);
DontFadeString2->SetText("mouse is here");
DontFadeString2->SetAlignment(B_ALIGN_LEFT);
}

View File

@ -0,0 +1,89 @@
#ifndef _ScreenSaver_H
#define _ScreenSaver_H
#include <Picture.h>
#include "Constants.h"
#include "passwordWindow.h"
#include "ScreenSaverPrefs.h"
class MouseAreaView;
class PreviewView;
class ScreenSaverWin: public BWindow {
public:
ScreenSaverWin(void) : BWindow(BRect(50,50,500,385),"OBOS Screen Saver Preferences",B_TITLED_WINDOW,B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE) ,
fadeState(0),noFadeState(0),
sampleView(NULL),
tab1(NULL),tab2(NULL),
tabView(NULL), ModuleSettingsBox(NULL),
previewDisplay(NULL), ListView1(NULL),
AddonList(NULL), SelectedAddonFileName(NULL),
currentAddon(NULL), TestButton(NULL),
AddButton(NULL), EnableScreenSaverBox(NULL),
PasswordSlider(NULL), TurnOffSlider(NULL),
RunSlider(NULL), StringView1(NULL),
EnableCheckbox(NULL), PasswordCheckbox(NULL),
TurnOffScreenCheckBox(NULL),
TurnOffMinutes(NULL), RunMinutes(NULL),
PasswordMinutes(NULL), PasswordButton(NULL),
FadeNowString(NULL),
FadeNowString2(NULL),
DontFadeString(NULL), DontFadeString2(NULL),
fadeNow(NULL),fadeNever(NULL),
pwWin(NULL),
pwMessenger(NULL),
settingsArea(NULL) {
SetupForm();
}
virtual void MessageReceived(BMessage *message);
virtual bool QuitRequested(void);
void LoadSettings(void);
virtual ~ScreenSaverWin(void) {};
private:
void SetupForm(void);
void setupTab1(void);
void setupTab2(void);
void updateStatus(void);
ScreenSaverPrefs prefs;
int fadeState,noFadeState;
BView *sampleView;
BView *tab1,*tab2;
BTabView *tabView;
BBox *ModuleSettingsBox;
PreviewView *previewDisplay;
BListView *ListView1;
BList *AddonList;
BString SelectedAddonFileName;
image_id currentAddon;
BButton *TestButton;
BButton *AddButton;
BBox *EnableScreenSaverBox;
BSlider *PasswordSlider;
BSlider *TurnOffSlider;
BSlider *RunSlider;
BStringView *StringView1;
BCheckBox *EnableCheckbox;
BCheckBox *PasswordCheckbox;
BCheckBox *TurnOffScreenCheckBox;
BStringView *TurnOffMinutes;
BStringView *RunMinutes;
BStringView *PasswordMinutes;
BButton *PasswordButton;
BStringView *FadeNowString;
BStringView *FadeNowString2;
BStringView *DontFadeString;
BStringView *DontFadeString2;
BPicture samplePicture;
MouseAreaView *fadeNow,*fadeNever;
pwWindow *pwWin;
BMessenger *pwMessenger;
BMessage settings;
BView *settingsArea;
};
#endif // _ScreenSaver_H

View File

@ -0,0 +1,91 @@
#include "passwordWindow.h"
#include <stdio.h>
#include "RadioButton.h"
#include "Alert.h"
void pwWindow::setup(void) {
BView *owner=new BView(Bounds(),"ownerView",B_FOLLOW_NONE,B_WILL_DRAW);
owner->SetViewColor(216,216,216);
AddChild(owner);
useNetwork=new BRadioButton(BRect(15,10,160,20),"useNetwork","Use Network password",new BMessage(BUTTON_CHANGED),B_FOLLOW_NONE);
useNetwork->SetValue(1);
owner->AddChild(useNetwork);
useCustom=new BRadioButton(BRect(30,50,130,60),"useCustom","Use custom password",new BMessage(BUTTON_CHANGED),B_FOLLOW_NONE);
customBox=new BBox(BRect(10,30,270,105),"custBeBox",B_FOLLOW_NONE);
customBox->SetLabel(useCustom);
password=new BTextControl(BRect(10,20,250,35),"pwdCntrl","Password:",NULL,B_FOLLOW_NONE);
confirm=new BTextControl(BRect(10,45,250,60),"confirmCntrl","Confirm password:",NULL,B_FOLLOW_NONE);
password->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT);
password->SetDivider(90);
password->TextView()->HideTyping(true);
confirm->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT);
confirm->SetDivider(90);
confirm->TextView()->HideTyping(true);
customBox->AddChild(password);
customBox->AddChild(confirm);
owner->AddChild(customBox);
done=new BButton(BRect(200,120,275,130),"done","Done",new BMessage (DONE_CLICKED),B_FOLLOW_NONE);
cancel=new BButton(BRect(115,120,190,130),"cancel","Cancel",new BMessage (CANCEL_CLICKED),B_FOLLOW_NONE);
owner->AddChild(done);
owner->AddChild(cancel);
done->MakeDefault(true);
update();
}
void pwWindow::update(void) {
useNetPassword=(useCustom->Value()>0);
confirm->SetEnabled(useNetPassword);
password->SetEnabled(useNetPassword);
}
void pwWindow::MessageReceived(BMessage *message) {
switch(message->what) {
case DONE_CLICKED:
if (useCustom->Value())
if (strcmp(password->Text(),confirm->Text())) {
BAlert *alert=new BAlert("noMatch","Passwords don't match. Try again.","OK");
alert->Go();
}
else {
thePassword=password->Text();
Hide();
}
else {
password->SetText("");
confirm->SetText("");
Hide();
}
break;
case CANCEL_CLICKED:
password->SetText("");
confirm->SetText("");
Hide();
break;
case BUTTON_CHANGED:
update();
break;
case SHOW:
Show();
break;
case POPULATE:
message->ReplaceString("lockpassword", ((useNetPassword)?"":thePassword));
message->ReplaceString("lockmethod", (useNetPassword?"network":"custom"));
message->SendReply(message);
break;
case UTILIZE: {
BString temp;
message->FindString("lockmethod",&temp);
useNetPassword=(temp=="custom");
if (!useNetPassword) {
message->FindString("lockpassword",&temp);
thePassword=temp;
}
break;
}
default:
BWindow::MessageReceived(message);
break;
}
}

View File

@ -0,0 +1,26 @@
#include "Window.h"
#include "CheckBox.h"
#include "String.h"
#include "Box.h"
#include "TextControl.h"
#include "Button.h"
#include "Constants.h"
class pwWindow : public BWindow
{
public:
pwWindow (void) : BWindow(BRect(100,100,380,250),"",B_MODAL_WINDOW_LOOK,B_MODAL_APP_WINDOW_FEEL,B_NOT_RESIZABLE) {setup();}
void setup(void);
void update(void);
virtual void MessageReceived(BMessage *message);
private:
BRadioButton *useNetwork,*useCustom;
BBox *customBox;
BTextControl *password,*confirm;
BButton *cancel,*done;
BString thePassword;
bool useNetPassword;
};