2002-07-09 12:24:59 +00:00
|
|
|
/*
|
2007-10-02 14:54:15 +00:00
|
|
|
* Copyright 1999, Be Incorporated. All Rights Reserved.
|
|
|
|
|
* This file may be used under the terms of the Be Sample Code License.
|
|
|
|
|
*/
|
2002-07-09 12:24:59 +00:00
|
|
|
|
|
|
|
|
#include "cl_wind.h"
|
2007-10-14 23:10:53 +00:00
|
|
|
#include "cl_view.h"
|
2007-10-02 14:54:15 +00:00
|
|
|
|
|
|
|
|
#include <Application.h>
|
2002-07-09 12:24:59 +00:00
|
|
|
#include <FindDirectory.h>
|
|
|
|
|
#include <Path.h>
|
2007-10-14 23:10:53 +00:00
|
|
|
#include <Screen.h>
|
2002-07-09 12:24:59 +00:00
|
|
|
|
|
|
|
|
|
2007-10-14 23:10:53 +00:00
|
|
|
#include <fcntl.h>
|
2007-10-21 15:52:56 +00:00
|
|
|
#include <unistd.h>
|
2007-10-14 23:10:53 +00:00
|
|
|
#include <sys/stat.h>
|
2007-10-02 14:54:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
TClockWindow::TClockWindow(BRect frame, const char* title)
|
|
|
|
|
: BWindow(frame, title, B_TITLED_WINDOW,
|
2007-10-14 23:10:53 +00:00
|
|
|
B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AVOID_FRONT, B_ALL_WORKSPACES),
|
|
|
|
|
fOnScreenView(NULL)
|
2002-07-09 12:24:59 +00:00
|
|
|
{
|
2007-10-14 23:10:53 +00:00
|
|
|
_InitWindow();
|
2002-07-09 12:24:59 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-02 14:54:15 +00:00
|
|
|
|
|
|
|
|
TClockWindow::~TClockWindow()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
TClockWindow::QuitRequested()
|
2002-07-09 12:24:59 +00:00
|
|
|
{
|
2007-10-02 14:54:15 +00:00
|
|
|
BPath path;
|
2002-07-09 12:24:59 +00:00
|
|
|
if (find_directory (B_USER_SETTINGS_DIRECTORY, &path, true) == B_OK) {
|
|
|
|
|
path.Append("Clock_settings");
|
2007-10-02 14:54:15 +00:00
|
|
|
int ref = creat(path.Path(), 0777);
|
2002-07-09 12:24:59 +00:00
|
|
|
if (ref >= 0) {
|
2007-10-02 14:54:15 +00:00
|
|
|
BPoint lefttop = Frame().LeftTop();
|
2002-07-09 12:24:59 +00:00
|
|
|
write(ref, (char *)&lefttop, sizeof(BPoint));
|
2007-10-14 23:10:53 +00:00
|
|
|
short face = fOnScreenView->ReturnFace();
|
2002-07-09 12:24:59 +00:00
|
|
|
write(ref, (char *)&face, sizeof(short));
|
2007-10-14 23:10:53 +00:00
|
|
|
bool seconds = fOnScreenView->ReturnSeconds();
|
2002-07-09 12:24:59 +00:00
|
|
|
write(ref, (char *)&seconds, sizeof(bool));
|
|
|
|
|
close(ref);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
be_app->PostMessage(B_QUIT_REQUESTED);
|
2007-10-02 14:54:15 +00:00
|
|
|
return true;
|
2002-07-09 12:24:59 +00:00
|
|
|
}
|
2007-10-14 23:10:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
TClockWindow::_InitWindow()
|
|
|
|
|
{
|
|
|
|
|
// half second pulse rate
|
|
|
|
|
SetPulseRate(500000);
|
|
|
|
|
|
|
|
|
|
fOnScreenView = new TOnscreenView(BRect(0, 0, 82, 82), "Clock", 22, 15, 41);
|
|
|
|
|
AddChild(fOnScreenView);
|
|
|
|
|
|
|
|
|
|
int ref;
|
|
|
|
|
BPath path;
|
|
|
|
|
if (find_directory (B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
|
|
|
|
|
path.Append("Clock_settings");
|
|
|
|
|
ref = open(path.Path(), O_RDONLY);
|
|
|
|
|
if (ref >= 0) {
|
|
|
|
|
BPoint leftTop;
|
|
|
|
|
read(ref, (char*)&leftTop, sizeof(leftTop));
|
|
|
|
|
|
|
|
|
|
short face;
|
|
|
|
|
read(ref, (char *)&face, sizeof(short));
|
|
|
|
|
fOnScreenView->UseFace(face);
|
|
|
|
|
|
|
|
|
|
bool secs;
|
|
|
|
|
read(ref, (char *)&secs, sizeof(bool));
|
|
|
|
|
fOnScreenView->ShowSecs(secs);
|
|
|
|
|
|
|
|
|
|
close(ref);
|
|
|
|
|
|
|
|
|
|
MoveTo(leftTop);
|
|
|
|
|
|
|
|
|
|
BRect frame = Frame();
|
|
|
|
|
frame.InsetBy(-4, -4);
|
|
|
|
|
// it's not visible so reposition. I'm not going to get
|
|
|
|
|
// fancy here, just place in the default location
|
|
|
|
|
if (!frame.Intersects(BScreen(this).Frame()))
|
|
|
|
|
MoveTo(100, 100);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|