patch by Julun:
* fixed ticket #1500 * big cleanup and removal of unused code git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22411 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+113
-134
@@ -1,75 +1,65 @@
|
||||
/*
|
||||
|
||||
cl_view.cpp
|
||||
|
||||
*/
|
||||
* Copyright 1999, Be Incorporated. All Rights Reserved.
|
||||
* This file may be used under the terms of the Be Sample Code License.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 1999, Be Incorporated. All Rights Reserved.
|
||||
This file may be used under the terms of the Be Sample Code License.
|
||||
*/
|
||||
#include "clock.h"
|
||||
#include "cl_view.h"
|
||||
|
||||
#define DEBUG 1
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <Alert.h>
|
||||
#include <Application.h>
|
||||
#include <Bitmap.h>
|
||||
#include <Debug.h>
|
||||
#include <Dragger.h>
|
||||
#include <Entry.h>
|
||||
#include <Resources.h>
|
||||
#include <Roster.h>
|
||||
|
||||
#include "clock.h"
|
||||
#include "cl_view.h"
|
||||
/* ---------------------------------------------------------------- */
|
||||
|
||||
#include <time.h>
|
||||
|
||||
|
||||
TOffscreenView::TOffscreenView(BRect frame, char *name, short mRadius,
|
||||
short hRadius, short offset, long face, bool show)
|
||||
:BView(frame, name, B_NOT_RESIZABLE, B_WILL_DRAW)
|
||||
short hRadius, short offset, long face, bool show)
|
||||
: BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW),
|
||||
fHours(0),
|
||||
fMinutes(0),
|
||||
fSeconds(0),
|
||||
fOffset(offset),
|
||||
fHoursRadius(hRadius),
|
||||
fMinutesRadius(mRadius),
|
||||
fFace(face),
|
||||
fShowSeconds(show)
|
||||
{
|
||||
BRect theRect;
|
||||
short loop;
|
||||
void *picH;
|
||||
size_t len;
|
||||
float counter;
|
||||
short index;
|
||||
float x,y;
|
||||
entry_ref ref;
|
||||
long error;
|
||||
|
||||
fFace = face;
|
||||
theRect.Set(0,0,82,82);
|
||||
|
||||
for (index = 0; index <= 8; index++)
|
||||
fClockFace[index] = NULL;
|
||||
|
||||
status_t error;
|
||||
#ifdef __HAIKU__
|
||||
BResources rsrcs;
|
||||
error = rsrcs.SetToImage(&&dummy_label);
|
||||
dummy_label:
|
||||
if (error == B_OK) {
|
||||
{
|
||||
#else // !__HAIKU__
|
||||
// Note: Since we can be run as replicant, we get our resources this way,
|
||||
// not via be_app->AppResources().
|
||||
error = be_roster->FindApp(app_signature, &ref);
|
||||
printf("be_roster->FindApp() returned %s\n", strerror(error));
|
||||
#else
|
||||
// Note: Since we can be run as replicant, we get our
|
||||
// resources this way, not via be_app->AppResources().
|
||||
entry_ref ref;
|
||||
error = be_roster->FindApp(kAppSignature, &ref);
|
||||
if (error == B_NO_ERROR) {
|
||||
BFile file(&ref, O_RDONLY);
|
||||
error = file.InitCheck();
|
||||
if (error == B_NO_ERROR) {
|
||||
BResources rsrcs(&file);
|
||||
#endif // !__HAIKU__
|
||||
|
||||
for (loop = 0; loop <= 8; loop++) {
|
||||
if ((picH = rsrcs.FindResource('PICT', loop+4, &len))) {
|
||||
#endif
|
||||
for (short i = 0; i <= 8; i++)
|
||||
fClockFace[i] = NULL;
|
||||
|
||||
size_t len;
|
||||
void *picH;
|
||||
BRect theRect(0, 0, 82, 82);
|
||||
for (short loop = 0; loop <= 8; loop++) {
|
||||
if ((picH = rsrcs.FindResource('PICT', loop + 4, &len))) {
|
||||
fClockFace[loop] = new BBitmap(theRect, B_CMAP8);
|
||||
fClockFace[loop]->SetBits(picH,len,0, B_CMAP8);
|
||||
fClockFace[loop]->SetBits(picH, len, 0, B_CMAP8);
|
||||
free(picH);
|
||||
}
|
||||
}
|
||||
@@ -77,33 +67,25 @@ dummy_label:
|
||||
theRect.Set(0,0,15,15);
|
||||
if ((picH = rsrcs.FindResource('MICN', "center", &len))) {
|
||||
fCenter = new BBitmap(theRect, B_CMAP8);
|
||||
fCenter->SetBits(picH,len,0, B_CMAP8);
|
||||
fCenter->SetBits(picH, len, 0, B_CMAP8);
|
||||
free(picH);
|
||||
}
|
||||
|
||||
theRect.Set(0,0,2,2);
|
||||
if ((picH = rsrcs.FindResource('PICT', 13, &len))) {
|
||||
fInner = new BBitmap(theRect, B_CMAP8);
|
||||
fInner->SetBits(picH,len,0, B_CMAP8);
|
||||
fInner->SetBits(picH, len, 0, B_CMAP8);
|
||||
free(picH);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fMinutesRadius = mRadius;
|
||||
fHoursRadius = hRadius;
|
||||
fOffset = offset;
|
||||
fHours = 0;
|
||||
fMinutes = 0;
|
||||
fSeconds = 0;
|
||||
fShowSeconds = show;
|
||||
|
||||
index = 0;
|
||||
|
||||
//
|
||||
float x, y;
|
||||
float counter;
|
||||
short index = 0;
|
||||
|
||||
// Generate minutes points array
|
||||
//
|
||||
for (counter = 90; counter >= 0; counter -= 6,index++) {
|
||||
for (counter = 90; counter >= 0; counter -= 6, index++) {
|
||||
x = mRadius * cos(((360 - counter)/180.0) * 3.1415);
|
||||
x += 41;
|
||||
y = mRadius * sin(((360 - counter)/180.0) * 3.1415);
|
||||
@@ -115,6 +97,7 @@ dummy_label:
|
||||
y += 41;
|
||||
fHourPoints[index].Set(x,y);
|
||||
}
|
||||
|
||||
for (counter = 354; counter > 90; counter -= 6,index++) {
|
||||
x = mRadius * cos(((360 - counter)/180.0) * 3.1415);
|
||||
x += 41;
|
||||
@@ -139,14 +122,6 @@ TOffscreenView::NextFace()
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
TOffscreenView::AttachedToWindow()
|
||||
{
|
||||
SetFontSize(18);
|
||||
SetFont(be_plain_font);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TOffscreenView::DrawX()
|
||||
{
|
||||
@@ -190,22 +165,22 @@ TOffscreenView::~TOffscreenView()
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Onscreen view object
|
||||
*/
|
||||
TOnscreenView::TOnscreenView(BRect rect, char *title,
|
||||
short mRadius, short hRadius, short offset)
|
||||
:BView(rect, title, B_NOT_RESIZABLE,
|
||||
B_WILL_DRAW | B_PULSE_NEEDED | B_DRAW_ON_CHILDREN)
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
TOnscreenView::TOnscreenView(BRect rect, char *title, short mRadius,
|
||||
short hRadius, short offset)
|
||||
: BView(rect, title, B_FOLLOW_NONE,
|
||||
B_WILL_DRAW | B_PULSE_NEEDED | B_DRAW_ON_CHILDREN),
|
||||
fOffscreen(NULL),
|
||||
fOffscreenView(NULL)
|
||||
{
|
||||
InitObject(rect, mRadius, hRadius, offset, 1, TRUE);
|
||||
|
||||
BRect r = rect;
|
||||
r.OffsetTo(B_ORIGIN);
|
||||
r.top = r.bottom - 7;
|
||||
r.left = r.right - 7;
|
||||
|
||||
BDragger *dw = new BDragger(r, this, 0);
|
||||
rect.OffsetTo(B_ORIGIN);
|
||||
rect.top = rect.bottom - 7;
|
||||
rect.left = rect.right - 7;
|
||||
BDragger *dw = new BDragger(rect, this);
|
||||
AddChild(dw);
|
||||
}
|
||||
|
||||
@@ -214,14 +189,7 @@ void
|
||||
TOnscreenView::InitObject(BRect rect, short mRadius, short hRadius,
|
||||
short offset, long face, bool show)
|
||||
{
|
||||
fmRadius = mRadius;
|
||||
fhRadius = hRadius;
|
||||
fOffset = offset;
|
||||
fRect = rect;
|
||||
fOffscreenView = NULL;
|
||||
fOffscreen = NULL;
|
||||
|
||||
fOffscreenView = new TOffscreenView(rect, "freqd",mRadius,hRadius, offset, face, show);
|
||||
fOffscreenView = new TOffscreenView(rect, "freqd", mRadius, hRadius, offset, face, show);
|
||||
fOffscreen = new BBitmap(rect, B_CMAP8, true);
|
||||
if (fOffscreen != NULL && fOffscreen->Lock()) {
|
||||
fOffscreen->AddChild(fOffscreenView);
|
||||
@@ -239,7 +207,9 @@ TOnscreenView::~TOnscreenView()
|
||||
|
||||
|
||||
TOnscreenView::TOnscreenView(BMessage *data)
|
||||
: BView(data)
|
||||
: BView(data),
|
||||
fOffscreen(NULL),
|
||||
fOffscreenView(NULL)
|
||||
{
|
||||
InitObject(data->FindRect("bounds"), data->FindInt32("mRadius"),
|
||||
data->FindInt32("hRadius"), data->FindInt32("offset"),
|
||||
@@ -250,17 +220,29 @@ TOnscreenView::TOnscreenView(BMessage *data)
|
||||
status_t
|
||||
TOnscreenView::Archive(BMessage *data, bool deep) const
|
||||
{
|
||||
inherited::Archive(data, deep);
|
||||
data->AddString("add_on", app_signature);
|
||||
//+ data->AddString("add_on_path", "/boot/apps/Clock");
|
||||
status_t status = BView::Archive(data, deep);
|
||||
if (status == B_OK)
|
||||
status = data->AddString("add_on", kAppSignature);
|
||||
|
||||
data->AddRect("bounds", Bounds());
|
||||
data->AddInt32("mRadius", fOffscreenView->fMinutesRadius);
|
||||
data->AddInt32("hRadius", fOffscreenView->fHoursRadius);
|
||||
data->AddInt32("offset", fOffscreenView->fOffset);
|
||||
data->AddBool("seconds", fOffscreenView->fShowSeconds);
|
||||
data->AddInt32("face", fOffscreenView->fFace);
|
||||
return 0;
|
||||
if (status == B_OK)
|
||||
status = data->AddRect("bounds", Bounds());
|
||||
|
||||
if (status == B_OK)
|
||||
status = data->AddInt32("mRadius", fOffscreenView->fMinutesRadius);
|
||||
|
||||
if (status == B_OK)
|
||||
status = data->AddInt32("hRadius", fOffscreenView->fHoursRadius);
|
||||
|
||||
if (status == B_OK)
|
||||
status = data->AddInt32("offset", fOffscreenView->fOffset);
|
||||
|
||||
if (status == B_OK)
|
||||
status = data->AddBool("seconds", fOffscreenView->fShowSeconds);
|
||||
|
||||
if (status == B_OK)
|
||||
status = data->AddInt32("face", fOffscreenView->fFace);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@@ -273,35 +255,25 @@ TOnscreenView::Instantiate(BMessage *data)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TOnscreenView::AttachedToWindow()
|
||||
{
|
||||
//+ PRINT(("InitData m=%d, h=%d, offset=%d\n", fmRadius, fhRadius, fOffset));
|
||||
//+ PRINT_OBJECT(fRect);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TOnscreenView::Pulse()
|
||||
{
|
||||
short hours,minutes,seconds;
|
||||
struct tm *loctime;
|
||||
time_t current;
|
||||
|
||||
ASSERT(fOffscreen);
|
||||
ASSERT(fOffscreenView);
|
||||
current = time(0);
|
||||
loctime = localtime(¤t);
|
||||
hours = loctime->tm_hour;
|
||||
minutes = loctime->tm_min;
|
||||
seconds = loctime->tm_sec;
|
||||
|
||||
time_t current = time(0);
|
||||
struct tm *loctime = localtime(¤t);
|
||||
|
||||
if ((fOffscreenView->fShowSeconds && (seconds != fOffscreenView->fSeconds)) ||
|
||||
(minutes != fOffscreenView->fMinutes)) {
|
||||
short hours = loctime->tm_hour;
|
||||
short minutes = loctime->tm_min;
|
||||
short seconds = loctime->tm_sec;
|
||||
|
||||
if ((fOffscreenView->fShowSeconds && (seconds != fOffscreenView->fSeconds))
|
||||
|| (minutes != fOffscreenView->fMinutes)) {
|
||||
fOffscreenView->fHours = hours;
|
||||
fOffscreenView->fMinutes = minutes;
|
||||
fOffscreenView->fSeconds = seconds;
|
||||
BRect b = Bounds();
|
||||
BRect b = Bounds();
|
||||
b.InsetBy(12,12);
|
||||
Draw(b);
|
||||
}
|
||||
@@ -309,36 +281,36 @@ TOnscreenView::Pulse()
|
||||
|
||||
|
||||
void
|
||||
TOnscreenView::UseFace( short face )
|
||||
TOnscreenView::UseFace(short face)
|
||||
{
|
||||
fOffscreenView->fFace = face;
|
||||
BRect b = Bounds();
|
||||
BRect b = Bounds();
|
||||
b.InsetBy(12,12);
|
||||
Draw(b);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TOnscreenView::ShowSecs( bool secs )
|
||||
TOnscreenView::ShowSecs(bool secs)
|
||||
{
|
||||
fOffscreenView->fShowSeconds = secs;
|
||||
BRect b = Bounds();
|
||||
BRect b = Bounds();
|
||||
b.InsetBy(12,12);
|
||||
Invalidate(b);
|
||||
}
|
||||
|
||||
|
||||
short
|
||||
TOnscreenView::ReturnFace( void )
|
||||
TOnscreenView::ReturnFace()
|
||||
{
|
||||
return(fOffscreenView->fFace);
|
||||
return fOffscreenView->fFace;
|
||||
}
|
||||
|
||||
|
||||
short
|
||||
TOnscreenView::ReturnSeconds( void )
|
||||
TOnscreenView::ReturnSeconds()
|
||||
{
|
||||
return(fOffscreenView->fShowSeconds);
|
||||
return fOffscreenView->fShowSeconds;
|
||||
}
|
||||
|
||||
|
||||
@@ -349,7 +321,8 @@ TOnscreenView::Draw(BRect rect)
|
||||
ASSERT(fOffscreenView);
|
||||
|
||||
if (fOffscreen->Lock()) {
|
||||
fOffscreenView->DrawX(); // Composite the clock offscreen...
|
||||
// Composite the clock offscreen...
|
||||
fOffscreenView->DrawX();
|
||||
DrawBitmap(fOffscreen, rect, rect);
|
||||
fOffscreen->Unlock();
|
||||
}
|
||||
@@ -366,7 +339,6 @@ TOnscreenView::MouseDown( BPoint point )
|
||||
GetMouse(&cursor,&buttons);
|
||||
if (buttons & B_SECONDARY_MOUSE_BUTTON) {
|
||||
fOffscreenView->fShowSeconds = !fOffscreenView->fShowSeconds;
|
||||
be_app->PostMessage(SHOW_SECONDS);
|
||||
bounds.InsetBy(12,12);
|
||||
Invalidate(bounds);
|
||||
} else {
|
||||
@@ -384,9 +356,16 @@ TOnscreenView::MessageReceived(BMessage *msg)
|
||||
{
|
||||
switch(msg->what) {
|
||||
case B_ABOUT_REQUESTED:
|
||||
(new BAlert("About Clock", "Clock (The Replicant version)\n\n(C)2002 OpenBeOS\n\nOriginally coded by the folks at Be.\n Copyright Be Inc., 1991-1998","OK"))->Go();
|
||||
break;
|
||||
{
|
||||
BAlert *alert = new BAlert("About Clock",
|
||||
"Clock (The Replicant version)\n\n(C)2002, 2003 OpenBeOS,\n"
|
||||
"2004 - 2007, Haiku, Inc.\n\nOriginally coded by the folks "
|
||||
"at Be.\n Copyright Be Inc., 1991 - 1998", "OK");
|
||||
|
||||
alert->Go();
|
||||
} break;
|
||||
|
||||
default:
|
||||
inherited::MessageReceived(msg);
|
||||
BView::MessageReceived(msg);
|
||||
}
|
||||
}
|
||||
|
||||
+54
-62
@@ -1,83 +1,75 @@
|
||||
/*
|
||||
|
||||
cl_view.h
|
||||
|
||||
*/
|
||||
/*
|
||||
Copyright 1999, Be Incorporated. All Rights Reserved.
|
||||
This file may be used under the terms of the Be Sample Code License.
|
||||
*/
|
||||
|
||||
* Copyright 1999, Be Incorporated. All Rights Reserved.
|
||||
* This file may be used under the terms of the Be Sample Code License.
|
||||
*
|
||||
*/
|
||||
#ifndef _CL_VIEW_H_
|
||||
#define _CL_VIEW_H_
|
||||
|
||||
#include <Application.h>
|
||||
#include <Bitmap.h>
|
||||
#include <View.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include <time.h>
|
||||
#include <View.h>
|
||||
|
||||
|
||||
class BBitmap;
|
||||
class BMessage;
|
||||
|
||||
|
||||
class TOffscreenView : public BView {
|
||||
|
||||
public:
|
||||
TOffscreenView(BRect frame, char *name, short mRadius,
|
||||
public:
|
||||
TOffscreenView(BRect frame, char *name, short mRadius,
|
||||
short hRadius, short offset, long face, bool show);
|
||||
virtual ~TOffscreenView();
|
||||
virtual void AttachedToWindow();
|
||||
virtual void DrawX();
|
||||
void NextFace();
|
||||
virtual ~TOffscreenView();
|
||||
|
||||
void DrawX();
|
||||
void NextFace();
|
||||
|
||||
BBitmap *fClockFace[9];
|
||||
BBitmap *fCenter;
|
||||
BBitmap *fInner;
|
||||
short fFace;
|
||||
BPoint fMinutePoints[60];
|
||||
BPoint fHourPoints[60];
|
||||
short fMinutesRadius;
|
||||
short fHoursRadius;
|
||||
short fOffset;
|
||||
short fHours;
|
||||
short fMinutes;
|
||||
short fSeconds;
|
||||
bool fShowSeconds;
|
||||
short fHours;
|
||||
short fMinutes;
|
||||
short fSeconds;
|
||||
|
||||
short fOffset;
|
||||
short fHoursRadius;
|
||||
short fMinutesRadius;
|
||||
|
||||
short fFace;
|
||||
bool fShowSeconds;
|
||||
|
||||
private:
|
||||
BBitmap *fInner;
|
||||
BBitmap *fCenter;
|
||||
BBitmap *fClockFace[9];
|
||||
|
||||
BPoint fHourPoints[60];
|
||||
BPoint fMinutePoints[60];
|
||||
};
|
||||
|
||||
|
||||
class _EXPORT TOnscreenView : public BView {
|
||||
class TOnscreenView : public BView {
|
||||
public:
|
||||
TOnscreenView(BRect frame, char *name,
|
||||
short mRadius, short hRadius, short offset);
|
||||
TOnscreenView(BMessage *data);
|
||||
virtual ~TOnscreenView();
|
||||
|
||||
public:
|
||||
TOnscreenView(BRect frame, char *name, short mRadius,
|
||||
short hRadius, short offset);
|
||||
virtual ~TOnscreenView();
|
||||
TOnscreenView(BMessage *data);
|
||||
static BArchivable *Instantiate(BMessage *data);
|
||||
virtual status_t Archive(BMessage *data, bool deep = true) const;
|
||||
void InitObject(BRect frame, short mRadius, short hRadius,
|
||||
static BArchivable *Instantiate(BMessage *data);
|
||||
virtual status_t Archive(BMessage *data, bool deep = true) const;
|
||||
void InitObject(BRect frame, short mRadius, short hRadius,
|
||||
short offset, long face, bool show);
|
||||
|
||||
//+virtual void AllAttached();
|
||||
virtual void AttachedToWindow();
|
||||
virtual void Draw(BRect updateRect);
|
||||
virtual void MouseDown( BPoint point);
|
||||
virtual void MessageReceived(BMessage *msg);
|
||||
virtual void Pulse();
|
||||
void UseFace( short face );
|
||||
void ShowSecs( bool secs );
|
||||
short ReturnFace( void );
|
||||
short ReturnSeconds( void );
|
||||
virtual void Pulse();
|
||||
virtual void Draw(BRect updateRect);
|
||||
virtual void MouseDown(BPoint point);
|
||||
virtual void MessageReceived(BMessage *msg);
|
||||
|
||||
short ReturnFace();
|
||||
void UseFace(short face);
|
||||
|
||||
private:
|
||||
short ReturnSeconds();
|
||||
void ShowSecs(bool secs);
|
||||
|
||||
typedef BView inherited;
|
||||
|
||||
BBitmap *fOffscreen;
|
||||
TOffscreenView *fOffscreenView;
|
||||
short fmRadius;
|
||||
short fhRadius;
|
||||
short fOffset;
|
||||
BRect fRect;
|
||||
private:
|
||||
BBitmap *fOffscreen;
|
||||
TOffscreenView *fOffscreenView;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+27
-28
@@ -1,15 +1,11 @@
|
||||
/*
|
||||
|
||||
cl_wind.cpp
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 1999, Be Incorporated. All Rights Reserved.
|
||||
This file may be used under the terms of the Be Sample Code License.
|
||||
*/
|
||||
* Copyright 1999, Be Incorporated. All Rights Reserved.
|
||||
* This file may be used under the terms of the Be Sample Code License.
|
||||
*/
|
||||
|
||||
#include "cl_wind.h"
|
||||
|
||||
#include <Application.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <Path.h>
|
||||
#include <string.h>
|
||||
@@ -19,37 +15,40 @@
|
||||
|
||||
#include <Debug.h>
|
||||
|
||||
TClockWindow::TClockWindow(BRect r, const char* t)
|
||||
:BWindow(r, t, B_TITLED_WINDOW,
|
||||
B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AVOID_FRONT,
|
||||
B_ALL_WORKSPACES)
|
||||
#include "cl_view.h"
|
||||
|
||||
|
||||
TClockWindow::TClockWindow(BRect frame, const char* title)
|
||||
: BWindow(frame, title, B_TITLED_WINDOW,
|
||||
B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AVOID_FRONT, B_ALL_WORKSPACES)
|
||||
{
|
||||
SetPulseRate(500000); // half second pulse rate
|
||||
SetPulseRate(500000);
|
||||
// half second pulse rate
|
||||
}
|
||||
|
||||
bool TClockWindow::QuitRequested( void )
|
||||
{
|
||||
int ref;
|
||||
BPoint lefttop;
|
||||
short face;
|
||||
bool seconds;
|
||||
BPath path;
|
||||
// int len;
|
||||
|
||||
|
||||
TClockWindow::~TClockWindow()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TClockWindow::QuitRequested()
|
||||
{
|
||||
BPath path;
|
||||
if (find_directory (B_USER_SETTINGS_DIRECTORY, &path, true) == B_OK) {
|
||||
path.Append("Clock_settings");
|
||||
ref = creat(path.Path(), 0777);
|
||||
int ref = creat(path.Path(), 0777);
|
||||
if (ref >= 0) {
|
||||
lefttop = Frame().LeftTop();
|
||||
BPoint lefttop = Frame().LeftTop();
|
||||
write(ref, (char *)&lefttop, sizeof(BPoint));
|
||||
face = theOnscreenView->ReturnFace();
|
||||
short face = theOnscreenView->ReturnFace();
|
||||
write(ref, (char *)&face, sizeof(short));
|
||||
seconds = theOnscreenView->ReturnSeconds();
|
||||
bool seconds = theOnscreenView->ReturnSeconds();
|
||||
write(ref, (char *)&seconds, sizeof(bool));
|
||||
close(ref);
|
||||
}
|
||||
}
|
||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||
return(TRUE);
|
||||
return true;
|
||||
}
|
||||
|
||||
+21
-17
@@ -1,26 +1,30 @@
|
||||
/*
|
||||
|
||||
cl_wind.h
|
||||
|
||||
*/
|
||||
* Copyright 1999, Be Incorporated. All Rights Reserved.
|
||||
* This file may be used under the terms of the Be Sample Code License.
|
||||
*
|
||||
*/
|
||||
#ifndef _CLOCK_WINDOW_H
|
||||
#define _CLOCK_WINDOW_H
|
||||
|
||||
/*
|
||||
Copyright 1999, Be Incorporated. All Rights Reserved.
|
||||
This file may be used under the terms of the Be Sample Code License.
|
||||
*/
|
||||
|
||||
#ifndef _WINDOW_H
|
||||
#include <Window.h>
|
||||
#endif
|
||||
#ifndef _CL_VIEW_H_
|
||||
#include "cl_view.h"
|
||||
#endif
|
||||
|
||||
|
||||
class TOnscreenView;
|
||||
|
||||
|
||||
class TClockWindow : public BWindow {
|
||||
public:
|
||||
TClockWindow(BRect rect, const char* name);
|
||||
virtual ~TClockWindow();
|
||||
|
||||
public:
|
||||
TClockWindow(BRect, const char*);
|
||||
virtual bool QuitRequested( void );
|
||||
virtual bool QuitRequested();
|
||||
|
||||
TOnscreenView *theOnscreenView;
|
||||
private:
|
||||
void _InitWindow();
|
||||
|
||||
private:
|
||||
TOnscreenView *theOnscreenView;
|
||||
};
|
||||
|
||||
#endif // _CLOCK_WINDOW_H
|
||||
|
||||
+30
-99
@@ -1,114 +1,45 @@
|
||||
/*
|
||||
|
||||
Clock.cpp
|
||||
|
||||
13 apr 94 elr new today
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 1999, Be Incorporated. All Rights Reserved.
|
||||
This file may be used under the terms of the Be Sample Code License.
|
||||
*/
|
||||
|
||||
#include <Debug.h>
|
||||
* Copyright 1999, Be Incorporated. All Rights Reserved.
|
||||
* This file may be used under the terms of the Be Sample Code License.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "clock.h"
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include "cl_wind.h"
|
||||
|
||||
#include <MenuItem.h>
|
||||
#include <PopUpMenu.h>
|
||||
#include <Path.h>
|
||||
#include <Screen.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <Dragger.h>
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
THelloApplication *myApplication;
|
||||
const char *kAppSignature = "application/x-vnd.Haiku-Clock";
|
||||
|
||||
myApplication = new THelloApplication();
|
||||
myApplication->Run();
|
||||
|
||||
delete myApplication;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *app_signature = "application/x-vnd.Haiku-Clock";
|
||||
|
||||
THelloApplication::THelloApplication()
|
||||
:BApplication(app_signature)
|
||||
:BApplication(kAppSignature)
|
||||
{
|
||||
BRect windowRect, viewRect;
|
||||
BPoint wind_loc;
|
||||
int ref;
|
||||
short face;
|
||||
bool secs;
|
||||
BPath path;
|
||||
|
||||
viewRect.Set(0, 0, 82, 82);
|
||||
myView = new TOnscreenView(viewRect, "Clock",22,15,41);
|
||||
windowRect.Set(100, 100, 182, 182);
|
||||
BRect windowRect(100, 100, 182, 182);
|
||||
myWindow = new TClockWindow(windowRect, "Clock");
|
||||
face = 1;
|
||||
if (find_directory (B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
|
||||
path.Append("Clock_settings");
|
||||
ref = open(path.Path(), O_RDONLY);
|
||||
if (ref >= 0) {
|
||||
read(ref, (char *)&wind_loc, sizeof(wind_loc));
|
||||
read(ref, (char *)&face, sizeof(short));
|
||||
read(ref, (char *)&secs, sizeof(bool));
|
||||
close(ref);
|
||||
myWindow->MoveTo(wind_loc);
|
||||
|
||||
BRect frame = myWindow->Frame();
|
||||
frame.InsetBy(-4, -4);
|
||||
if (!frame.Intersects(BScreen(myWindow).Frame())) {
|
||||
// it's not visible so reposition. I'm not going to get
|
||||
// fancy here, just place in the default location
|
||||
myWindow->MoveTo(100, 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//+ BPopUpMenu *menu = MainMenu();
|
||||
//+ BMenuItem *item = new BMenuItem("Show Seconds", new BMessage(SHOW_SECONDS));
|
||||
//+ item->SetTarget(this);
|
||||
//+ item->SetMarked(secs);
|
||||
//+
|
||||
//+ menu->AddItem(new BSeparatorItem(), 1);
|
||||
//+ menu->AddItem(item, 2);
|
||||
//+ menu->AddItem(new BSeparatorItem(), 3);
|
||||
|
||||
myWindow->Lock();
|
||||
myWindow->AddChild(myView);
|
||||
myWindow->theOnscreenView = myView;
|
||||
|
||||
//+ BRect r = myView->Frame();
|
||||
//+ r.top = r.bottom - 7;
|
||||
//+ r.left = r.right - 7;
|
||||
//+ BDragger *dw = new BDragger(r, myView, 0);
|
||||
//+ myWindow->AddChild(dw);
|
||||
|
||||
myView->UseFace( face );
|
||||
myView->ShowSecs( secs );
|
||||
myView->Pulse(); // Force update
|
||||
myWindow->Show();
|
||||
myWindow->Unlock();
|
||||
}
|
||||
|
||||
void THelloApplication::MessageReceived(BMessage *msg)
|
||||
|
||||
THelloApplication::~THelloApplication()
|
||||
{
|
||||
if (msg->what == SHOW_SECONDS) {
|
||||
//+ if (myWindow->Lock()) {
|
||||
//+ BMenuItem *item = MainMenu()->FindItem(SHOW_SECONDS);
|
||||
//+ item->SetMarked(!item->IsMarked());
|
||||
//+//+ myView->ShowSecs(item->IsMarked());
|
||||
//+ myWindow->Unlock();
|
||||
//+ }
|
||||
} else {
|
||||
BApplication::MessageReceived(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
THelloApplication::MessageReceived(BMessage *msg)
|
||||
{
|
||||
BApplication::MessageReceived(msg);
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
THelloApplication app;
|
||||
app.Run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+19
-20
@@ -1,32 +1,31 @@
|
||||
/*
|
||||
|
||||
clock.h
|
||||
|
||||
*/
|
||||
* Copyright 1999, Be Incorporated. All Rights Reserved.
|
||||
* This file may be used under the terms of the Be Sample Code License.
|
||||
*
|
||||
*/
|
||||
#ifndef _CLOCK_APPLICATION_H
|
||||
#define _CLOCK_APPLICATION_H
|
||||
|
||||
/*
|
||||
Copyright 1999, Be Incorporated. All Rights Reserved.
|
||||
This file may be used under the terms of the Be Sample Code License.
|
||||
*/
|
||||
|
||||
#ifndef _APPLICATION_H
|
||||
#include <Application.h>
|
||||
#endif
|
||||
|
||||
#include "cl_view.h"
|
||||
#include "cl_wind.h"
|
||||
|
||||
#define SHOW_SECONDS 'ssec'
|
||||
class TClockWindow;
|
||||
|
||||
extern const char *app_signature;
|
||||
|
||||
class THelloApplication : public BApplication {
|
||||
|
||||
public:
|
||||
public:
|
||||
THelloApplication();
|
||||
virtual void MessageReceived(BMessage *msg);
|
||||
virtual ~THelloApplication();
|
||||
|
||||
private:
|
||||
TClockWindow* myWindow;
|
||||
TOnscreenView *myView;
|
||||
virtual void MessageReceived(BMessage *msg);
|
||||
|
||||
private:
|
||||
TClockWindow *myWindow;
|
||||
};
|
||||
|
||||
|
||||
extern const char *kAppSignature;
|
||||
|
||||
|
||||
#endif // _CLOCK_APPLICATION_H
|
||||
|
||||
Reference in New Issue
Block a user