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:
Stephan Aßmus
2007-10-02 14:54:15 +00:00
parent 4d1c422802
commit 0064e64138
6 changed files with 264 additions and 360 deletions
+113 -134
View File
@@ -1,75 +1,65 @@
/* /*
* Copyright 1999, Be Incorporated. All Rights Reserved.
cl_view.cpp * This file may be used under the terms of the Be Sample Code License.
*
*/ */
/* #include "clock.h"
Copyright 1999, Be Incorporated. All Rights Reserved. #include "cl_view.h"
This file may be used under the terms of the Be Sample Code License.
*/
#define DEBUG 1
#include <float.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <Alert.h> #include <Alert.h>
#include <Application.h> #include <Bitmap.h>
#include <Debug.h> #include <Debug.h>
#include <Dragger.h> #include <Dragger.h>
#include <Entry.h> #include <Entry.h>
#include <Resources.h> #include <Resources.h>
#include <Roster.h> #include <Roster.h>
#include "clock.h"
#include "cl_view.h" #include <time.h>
/* ---------------------------------------------------------------- */
TOffscreenView::TOffscreenView(BRect frame, char *name, short mRadius, TOffscreenView::TOffscreenView(BRect frame, char *name, short mRadius,
short hRadius, short offset, long face, bool show) short hRadius, short offset, long face, bool show)
:BView(frame, name, B_NOT_RESIZABLE, B_WILL_DRAW) : 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; status_t error;
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;
#ifdef __HAIKU__ #ifdef __HAIKU__
BResources rsrcs; BResources rsrcs;
error = rsrcs.SetToImage(&&dummy_label); error = rsrcs.SetToImage(&&dummy_label);
dummy_label: dummy_label:
if (error == B_OK) { if (error == B_OK) {
{ {
#else // !__HAIKU__ #else
// Note: Since we can be run as replicant, we get our resources this way, // Note: Since we can be run as replicant, we get our
// not via be_app->AppResources(). // resources this way, not via be_app->AppResources().
error = be_roster->FindApp(app_signature, &ref); entry_ref ref;
printf("be_roster->FindApp() returned %s\n", strerror(error)); error = be_roster->FindApp(kAppSignature, &ref);
if (error == B_NO_ERROR) { if (error == B_NO_ERROR) {
BFile file(&ref, O_RDONLY); BFile file(&ref, O_RDONLY);
error = file.InitCheck(); error = file.InitCheck();
if (error == B_NO_ERROR) { if (error == B_NO_ERROR) {
BResources rsrcs(&file); BResources rsrcs(&file);
#endif // !__HAIKU__ #endif
for (short i = 0; i <= 8; i++)
for (loop = 0; loop <= 8; loop++) { fClockFace[i] = NULL;
if ((picH = rsrcs.FindResource('PICT', loop+4, &len))) {
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] = new BBitmap(theRect, B_CMAP8);
fClockFace[loop]->SetBits(picH,len,0, B_CMAP8); fClockFace[loop]->SetBits(picH, len, 0, B_CMAP8);
free(picH); free(picH);
} }
} }
@@ -77,33 +67,25 @@ dummy_label:
theRect.Set(0,0,15,15); theRect.Set(0,0,15,15);
if ((picH = rsrcs.FindResource('MICN', "center", &len))) { if ((picH = rsrcs.FindResource('MICN', "center", &len))) {
fCenter = new BBitmap(theRect, B_CMAP8); fCenter = new BBitmap(theRect, B_CMAP8);
fCenter->SetBits(picH,len,0, B_CMAP8); fCenter->SetBits(picH, len, 0, B_CMAP8);
free(picH); free(picH);
} }
theRect.Set(0,0,2,2); theRect.Set(0,0,2,2);
if ((picH = rsrcs.FindResource('PICT', 13, &len))) { if ((picH = rsrcs.FindResource('PICT', 13, &len))) {
fInner = new BBitmap(theRect, B_CMAP8); fInner = new BBitmap(theRect, B_CMAP8);
fInner->SetBits(picH,len,0, B_CMAP8); fInner->SetBits(picH, len, 0, B_CMAP8);
free(picH); free(picH);
} }
} }
} }
fMinutesRadius = mRadius; float x, y;
fHoursRadius = hRadius; float counter;
fOffset = offset; short index = 0;
fHours = 0;
fMinutes = 0;
fSeconds = 0;
fShowSeconds = show;
index = 0;
//
// Generate minutes points array // 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 = mRadius * cos(((360 - counter)/180.0) * 3.1415);
x += 41; x += 41;
y = mRadius * sin(((360 - counter)/180.0) * 3.1415); y = mRadius * sin(((360 - counter)/180.0) * 3.1415);
@@ -115,6 +97,7 @@ dummy_label:
y += 41; y += 41;
fHourPoints[index].Set(x,y); fHourPoints[index].Set(x,y);
} }
for (counter = 354; counter > 90; counter -= 6,index++) { for (counter = 354; counter > 90; counter -= 6,index++) {
x = mRadius * cos(((360 - counter)/180.0) * 3.1415); x = mRadius * cos(((360 - counter)/180.0) * 3.1415);
x += 41; x += 41;
@@ -139,14 +122,6 @@ TOffscreenView::NextFace()
}; };
void
TOffscreenView::AttachedToWindow()
{
SetFontSize(18);
SetFont(be_plain_font);
}
void void
TOffscreenView::DrawX() TOffscreenView::DrawX()
{ {
@@ -190,22 +165,22 @@ TOffscreenView::~TOffscreenView()
}; };
/* // #pragma mark -
* Onscreen view object
*/
TOnscreenView::TOnscreenView(BRect rect, char *title, TOnscreenView::TOnscreenView(BRect rect, char *title, short mRadius,
short mRadius, short hRadius, short offset) short hRadius, short offset)
:BView(rect, title, B_NOT_RESIZABLE, : BView(rect, title, B_FOLLOW_NONE,
B_WILL_DRAW | B_PULSE_NEEDED | B_DRAW_ON_CHILDREN) B_WILL_DRAW | B_PULSE_NEEDED | B_DRAW_ON_CHILDREN),
fOffscreen(NULL),
fOffscreenView(NULL)
{ {
InitObject(rect, mRadius, hRadius, offset, 1, TRUE); InitObject(rect, mRadius, hRadius, offset, 1, TRUE);
BRect r = rect; rect.OffsetTo(B_ORIGIN);
r.OffsetTo(B_ORIGIN); rect.top = rect.bottom - 7;
r.top = r.bottom - 7; rect.left = rect.right - 7;
r.left = r.right - 7; BDragger *dw = new BDragger(rect, this);
BDragger *dw = new BDragger(r, this, 0);
AddChild(dw); AddChild(dw);
} }
@@ -214,14 +189,7 @@ void
TOnscreenView::InitObject(BRect rect, short mRadius, short hRadius, TOnscreenView::InitObject(BRect rect, short mRadius, short hRadius,
short offset, long face, bool show) short offset, long face, bool show)
{ {
fmRadius = mRadius; fOffscreenView = new TOffscreenView(rect, "freqd", mRadius, hRadius, offset, face, show);
fhRadius = hRadius;
fOffset = offset;
fRect = rect;
fOffscreenView = NULL;
fOffscreen = NULL;
fOffscreenView = new TOffscreenView(rect, "freqd",mRadius,hRadius, offset, face, show);
fOffscreen = new BBitmap(rect, B_CMAP8, true); fOffscreen = new BBitmap(rect, B_CMAP8, true);
if (fOffscreen != NULL && fOffscreen->Lock()) { if (fOffscreen != NULL && fOffscreen->Lock()) {
fOffscreen->AddChild(fOffscreenView); fOffscreen->AddChild(fOffscreenView);
@@ -239,7 +207,9 @@ TOnscreenView::~TOnscreenView()
TOnscreenView::TOnscreenView(BMessage *data) TOnscreenView::TOnscreenView(BMessage *data)
: BView(data) : BView(data),
fOffscreen(NULL),
fOffscreenView(NULL)
{ {
InitObject(data->FindRect("bounds"), data->FindInt32("mRadius"), InitObject(data->FindRect("bounds"), data->FindInt32("mRadius"),
data->FindInt32("hRadius"), data->FindInt32("offset"), data->FindInt32("hRadius"), data->FindInt32("offset"),
@@ -250,17 +220,29 @@ TOnscreenView::TOnscreenView(BMessage *data)
status_t status_t
TOnscreenView::Archive(BMessage *data, bool deep) const TOnscreenView::Archive(BMessage *data, bool deep) const
{ {
inherited::Archive(data, deep); status_t status = BView::Archive(data, deep);
data->AddString("add_on", app_signature); if (status == B_OK)
//+ data->AddString("add_on_path", "/boot/apps/Clock"); status = data->AddString("add_on", kAppSignature);
data->AddRect("bounds", Bounds()); if (status == B_OK)
data->AddInt32("mRadius", fOffscreenView->fMinutesRadius); status = data->AddRect("bounds", Bounds());
data->AddInt32("hRadius", fOffscreenView->fHoursRadius);
data->AddInt32("offset", fOffscreenView->fOffset); if (status == B_OK)
data->AddBool("seconds", fOffscreenView->fShowSeconds); status = data->AddInt32("mRadius", fOffscreenView->fMinutesRadius);
data->AddInt32("face", fOffscreenView->fFace);
return 0; 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 void
TOnscreenView::Pulse() TOnscreenView::Pulse()
{ {
short hours,minutes,seconds;
struct tm *loctime;
time_t current;
ASSERT(fOffscreen); ASSERT(fOffscreen);
ASSERT(fOffscreenView); ASSERT(fOffscreenView);
current = time(0);
loctime = localtime(&current); time_t current = time(0);
hours = loctime->tm_hour; struct tm *loctime = localtime(&current);
minutes = loctime->tm_min;
seconds = loctime->tm_sec;
if ((fOffscreenView->fShowSeconds && (seconds != fOffscreenView->fSeconds)) || short hours = loctime->tm_hour;
(minutes != fOffscreenView->fMinutes)) { short minutes = loctime->tm_min;
short seconds = loctime->tm_sec;
if ((fOffscreenView->fShowSeconds && (seconds != fOffscreenView->fSeconds))
|| (minutes != fOffscreenView->fMinutes)) {
fOffscreenView->fHours = hours; fOffscreenView->fHours = hours;
fOffscreenView->fMinutes = minutes; fOffscreenView->fMinutes = minutes;
fOffscreenView->fSeconds = seconds; fOffscreenView->fSeconds = seconds;
BRect b = Bounds(); BRect b = Bounds();
b.InsetBy(12,12); b.InsetBy(12,12);
Draw(b); Draw(b);
} }
@@ -309,36 +281,36 @@ TOnscreenView::Pulse()
void void
TOnscreenView::UseFace( short face ) TOnscreenView::UseFace(short face)
{ {
fOffscreenView->fFace = face; fOffscreenView->fFace = face;
BRect b = Bounds(); BRect b = Bounds();
b.InsetBy(12,12); b.InsetBy(12,12);
Draw(b); Draw(b);
} }
void void
TOnscreenView::ShowSecs( bool secs ) TOnscreenView::ShowSecs(bool secs)
{ {
fOffscreenView->fShowSeconds = secs; fOffscreenView->fShowSeconds = secs;
BRect b = Bounds(); BRect b = Bounds();
b.InsetBy(12,12); b.InsetBy(12,12);
Invalidate(b); Invalidate(b);
} }
short short
TOnscreenView::ReturnFace( void ) TOnscreenView::ReturnFace()
{ {
return(fOffscreenView->fFace); return fOffscreenView->fFace;
} }
short short
TOnscreenView::ReturnSeconds( void ) TOnscreenView::ReturnSeconds()
{ {
return(fOffscreenView->fShowSeconds); return fOffscreenView->fShowSeconds;
} }
@@ -349,7 +321,8 @@ TOnscreenView::Draw(BRect rect)
ASSERT(fOffscreenView); ASSERT(fOffscreenView);
if (fOffscreen->Lock()) { if (fOffscreen->Lock()) {
fOffscreenView->DrawX(); // Composite the clock offscreen... // Composite the clock offscreen...
fOffscreenView->DrawX();
DrawBitmap(fOffscreen, rect, rect); DrawBitmap(fOffscreen, rect, rect);
fOffscreen->Unlock(); fOffscreen->Unlock();
} }
@@ -366,7 +339,6 @@ TOnscreenView::MouseDown( BPoint point )
GetMouse(&cursor,&buttons); GetMouse(&cursor,&buttons);
if (buttons & B_SECONDARY_MOUSE_BUTTON) { if (buttons & B_SECONDARY_MOUSE_BUTTON) {
fOffscreenView->fShowSeconds = !fOffscreenView->fShowSeconds; fOffscreenView->fShowSeconds = !fOffscreenView->fShowSeconds;
be_app->PostMessage(SHOW_SECONDS);
bounds.InsetBy(12,12); bounds.InsetBy(12,12);
Invalidate(bounds); Invalidate(bounds);
} else { } else {
@@ -384,9 +356,16 @@ TOnscreenView::MessageReceived(BMessage *msg)
{ {
switch(msg->what) { switch(msg->what) {
case B_ABOUT_REQUESTED: 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: default:
inherited::MessageReceived(msg); BView::MessageReceived(msg);
} }
} }
+54 -62
View File
@@ -1,83 +1,75 @@
/* /*
* Copyright 1999, Be Incorporated. All Rights Reserved.
cl_view.h * 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_ #ifndef _CL_VIEW_H_
#define _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 { class TOffscreenView : public BView {
public:
public: TOffscreenView(BRect frame, char *name, short mRadius,
TOffscreenView(BRect frame, char *name, short mRadius,
short hRadius, short offset, long face, bool show); short hRadius, short offset, long face, bool show);
virtual ~TOffscreenView(); virtual ~TOffscreenView();
virtual void AttachedToWindow();
virtual void DrawX(); void DrawX();
void NextFace(); void NextFace();
BBitmap *fClockFace[9]; short fHours;
BBitmap *fCenter; short fMinutes;
BBitmap *fInner; short fSeconds;
short fFace;
BPoint fMinutePoints[60]; short fOffset;
BPoint fHourPoints[60]; short fHoursRadius;
short fMinutesRadius; short fMinutesRadius;
short fHoursRadius;
short fOffset; short fFace;
short fHours; bool fShowSeconds;
short fMinutes;
short fSeconds; private:
bool fShowSeconds; 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: static BArchivable *Instantiate(BMessage *data);
TOnscreenView(BRect frame, char *name, short mRadius, virtual status_t Archive(BMessage *data, bool deep = true) const;
short hRadius, short offset); void InitObject(BRect frame, short mRadius, short hRadius,
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,
short offset, long face, bool show); short offset, long face, bool show);
//+virtual void AllAttached(); virtual void Pulse();
virtual void AttachedToWindow(); virtual void Draw(BRect updateRect);
virtual void Draw(BRect updateRect); virtual void MouseDown(BPoint point);
virtual void MouseDown( BPoint point); virtual void MessageReceived(BMessage *msg);
virtual void MessageReceived(BMessage *msg);
virtual void Pulse();
void UseFace( short face );
void ShowSecs( bool secs );
short ReturnFace( void );
short ReturnSeconds( void );
short ReturnFace();
void UseFace(short face);
private: short ReturnSeconds();
void ShowSecs(bool secs);
typedef BView inherited; private:
BBitmap *fOffscreen;
BBitmap *fOffscreen; TOffscreenView *fOffscreenView;
TOffscreenView *fOffscreenView;
short fmRadius;
short fhRadius;
short fOffset;
BRect fRect;
}; };
#endif #endif
+27 -28
View File
@@ -1,15 +1,11 @@
/* /*
* Copyright 1999, Be Incorporated. All Rights Reserved.
cl_wind.cpp * 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 "cl_wind.h"
#include <Application.h>
#include <FindDirectory.h> #include <FindDirectory.h>
#include <Path.h> #include <Path.h>
#include <string.h> #include <string.h>
@@ -19,37 +15,40 @@
#include <Debug.h> #include <Debug.h>
TClockWindow::TClockWindow(BRect r, const char* t) #include "cl_view.h"
:BWindow(r, t, B_TITLED_WINDOW,
B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AVOID_FRONT,
B_ALL_WORKSPACES) 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) { if (find_directory (B_USER_SETTINGS_DIRECTORY, &path, true) == B_OK) {
path.Append("Clock_settings"); path.Append("Clock_settings");
ref = creat(path.Path(), 0777); int ref = creat(path.Path(), 0777);
if (ref >= 0) { if (ref >= 0) {
lefttop = Frame().LeftTop(); BPoint lefttop = Frame().LeftTop();
write(ref, (char *)&lefttop, sizeof(BPoint)); write(ref, (char *)&lefttop, sizeof(BPoint));
face = theOnscreenView->ReturnFace(); short face = theOnscreenView->ReturnFace();
write(ref, (char *)&face, sizeof(short)); write(ref, (char *)&face, sizeof(short));
seconds = theOnscreenView->ReturnSeconds(); bool seconds = theOnscreenView->ReturnSeconds();
write(ref, (char *)&seconds, sizeof(bool)); write(ref, (char *)&seconds, sizeof(bool));
close(ref); close(ref);
} }
} }
be_app->PostMessage(B_QUIT_REQUESTED); be_app->PostMessage(B_QUIT_REQUESTED);
return(TRUE); return true;
} }
+21 -17
View File
@@ -1,26 +1,30 @@
/* /*
* Copyright 1999, Be Incorporated. All Rights Reserved.
cl_wind.h * 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> #include <Window.h>
#endif
#ifndef _CL_VIEW_H_
#include "cl_view.h" class TOnscreenView;
#endif
class TClockWindow : public BWindow { class TClockWindow : public BWindow {
public:
TClockWindow(BRect rect, const char* name);
virtual ~TClockWindow();
public: virtual bool QuitRequested();
TClockWindow(BRect, const char*);
virtual bool QuitRequested( void );
TOnscreenView *theOnscreenView; private:
void _InitWindow();
private:
TOnscreenView *theOnscreenView;
}; };
#endif // _CLOCK_WINDOW_H
+30 -99
View File
@@ -1,114 +1,45 @@
/* /*
* Copyright 1999, Be Incorporated. All Rights Reserved.
Clock.cpp * This file may be used under the terms of the Be Sample Code License.
*
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>
#include "clock.h" #include "clock.h"
#include <fcntl.h> #include "cl_wind.h"
#include <unistd.h>
#include <string.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[]) const char *kAppSignature = "application/x-vnd.Haiku-Clock";
{
THelloApplication *myApplication;
myApplication = new THelloApplication();
myApplication->Run();
delete myApplication;
return 0;
}
const char *app_signature = "application/x-vnd.Haiku-Clock";
THelloApplication::THelloApplication() THelloApplication::THelloApplication()
:BApplication(app_signature) :BApplication(kAppSignature)
{ {
BRect windowRect, viewRect; BRect windowRect(100, 100, 182, 182);
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);
myWindow = new TClockWindow(windowRect, "Clock"); 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->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()); void
//+//+ myView->ShowSecs(item->IsMarked()); THelloApplication::MessageReceived(BMessage *msg)
//+ myWindow->Unlock(); {
//+ } BApplication::MessageReceived(msg);
} else { }
BApplication::MessageReceived(msg);
}
// #pragma mark -
int
main(int argc, char* argv[])
{
THelloApplication app;
app.Run();
return 0;
} }
+19 -20
View File
@@ -1,32 +1,31 @@
/* /*
* Copyright 1999, Be Incorporated. All Rights Reserved.
clock.h * 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> #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 { class THelloApplication : public BApplication {
public:
public:
THelloApplication(); THelloApplication();
virtual void MessageReceived(BMessage *msg); virtual ~THelloApplication();
private: virtual void MessageReceived(BMessage *msg);
TClockWindow* myWindow;
TOnscreenView *myView; private:
TClockWindow *myWindow;
}; };
extern const char *kAppSignature;
#endif // _CLOCK_APPLICATION_H