Many updates by "Michael Berg" <[email protected]>
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8143 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -4,39 +4,37 @@
|
|||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
#include <time.h>
|
class TOffscreen: public BView {
|
||||||
|
|
||||||
class TOffscreen: public BView
|
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
TOffscreen(BRect frame, char *name);
|
TOffscreen(BRect frame, const char *name);
|
||||||
virtual ~TOffscreen();
|
virtual ~TOffscreen();
|
||||||
virtual void AttachedToWindow();
|
|
||||||
virtual void DrawX();
|
|
||||||
|
|
||||||
|
virtual void DrawX();
|
||||||
BPoint Position();
|
BPoint Position();
|
||||||
|
|
||||||
BPoint f_MinutePoints[60];
|
BPoint f_MinutePoints[60];
|
||||||
BPoint f_HourPoints[60];
|
BPoint f_HourPoints[60];
|
||||||
short f_Hours;
|
short f_Hours;
|
||||||
short f_Minutes;
|
short f_Minutes;
|
||||||
short f_Seconds;
|
short f_Seconds;
|
||||||
private:
|
private:
|
||||||
BBitmap *f_bitmap;
|
BBitmap *f_bitmap;
|
||||||
|
BBitmap *f_centerbmp;
|
||||||
|
BBitmap *f_capbmp;
|
||||||
BPoint f_center;
|
BPoint f_center;
|
||||||
BPoint f_offset;
|
|
||||||
float f_Offset;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class TAnalogClock: public BView
|
class TAnalogClock: public BView {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
TAnalogClock(BRect frame, const char *name, uint32 resizingmode, uint32 flags);
|
TAnalogClock(BRect frame, const char *name, uint32 resizingmode, uint32 flags);
|
||||||
virtual ~TAnalogClock();
|
virtual ~TAnalogClock();
|
||||||
|
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
virtual void Draw(BRect updaterect);
|
virtual void Draw(BRect updaterect);
|
||||||
|
virtual void MessageReceived(BMessage *);
|
||||||
|
|
||||||
void Update(tm *atm);
|
void InitView(BRect frame);
|
||||||
|
void SetTo(int32, int32, int32);
|
||||||
private:
|
private:
|
||||||
BPoint f_drawpt;
|
BPoint f_drawpt;
|
||||||
BBitmap *f_bitmap;
|
BBitmap *f_bitmap;
|
||||||
|
|||||||
+84
-10
@@ -1,30 +1,104 @@
|
|||||||
#include <Alert.h>
|
#include <OS.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "BaseView.h"
|
#include "BaseView.h"
|
||||||
|
|
||||||
|
|
||||||
TTimeBaseView::TTimeBaseView(BRect frame, const char *name)
|
TTimeBaseView::TTimeBaseView(BRect frame, const char *name)
|
||||||
: BView(frame, name, B_FOLLOW_ALL_SIDES, B_PULSE_NEEDED)
|
: BView(frame, name, B_FOLLOW_ALL_SIDES, B_PULSE_NEEDED)
|
||||||
{
|
{
|
||||||
f_message = new BMessage(OB_TIME_UPDATE);
|
f_message = new BMessage(OB_TIME_UPDATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TTimeBaseView::~TTimeBaseView()
|
TTimeBaseView::~TTimeBaseView()
|
||||||
{ }
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TTimeBaseView::Pulse()
|
TTimeBaseView::Pulse()
|
||||||
|
{
|
||||||
|
if (IsWatched())
|
||||||
|
DispatchMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TTimeBaseView::SetGMTime(bool gmt)
|
||||||
|
{
|
||||||
|
f_gmtime = gmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TTimeBaseView::DispatchMessage()
|
||||||
{
|
{
|
||||||
time_t current;
|
time_t current;
|
||||||
struct tm *ltime;
|
struct tm *ltime;
|
||||||
|
|
||||||
current = time(0);
|
current = time(0);
|
||||||
ltime = localtime(¤t);
|
|
||||||
|
if (f_gmtime)
|
||||||
|
ltime = gmtime(¤t);
|
||||||
|
else
|
||||||
|
ltime = localtime(¤t);
|
||||||
|
|
||||||
|
int32 month = ltime->tm_mon;
|
||||||
|
int32 day = ltime->tm_mday;
|
||||||
|
int32 year = ltime->tm_year;
|
||||||
|
int32 hour = ltime->tm_hour;
|
||||||
|
int32 minute = ltime->tm_min;
|
||||||
|
int32 second = ltime->tm_sec;
|
||||||
|
|
||||||
f_message->MakeEmpty();
|
f_message->MakeEmpty();
|
||||||
f_message->AddPointer("_tm_", ltime);
|
f_message->AddInt32("month", month);
|
||||||
if (IsWatched())
|
f_message->AddInt32("day", day);
|
||||||
{
|
f_message->AddInt32("year", year);
|
||||||
SendNotices(OB_TIME_UPDATE, f_message);
|
f_message->AddInt32("hour", hour);
|
||||||
}
|
f_message->AddInt32("minute", minute);
|
||||||
|
f_message->AddInt32("second", second);
|
||||||
|
|
||||||
|
SendNotices(OB_TM_CHANGED, f_message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TTimeBaseView::ChangeTime(BMessage *message)
|
||||||
|
{
|
||||||
|
bool istime;
|
||||||
|
if (!(message->FindBool("time", &istime) == B_OK))
|
||||||
|
return;
|
||||||
|
|
||||||
|
time_t atime;
|
||||||
|
struct tm *_tm;
|
||||||
|
|
||||||
|
atime = time(0);
|
||||||
|
_tm = localtime(&atime);
|
||||||
|
|
||||||
|
int32 hour = 0;
|
||||||
|
int32 minute = 0;
|
||||||
|
int32 second = 0;
|
||||||
|
int32 month = 0;
|
||||||
|
int32 day = 0;
|
||||||
|
int32 year = 0;
|
||||||
|
if (istime) {
|
||||||
|
if (message->FindInt32("hour", &hour) == B_OK)
|
||||||
|
_tm->tm_hour = hour;
|
||||||
|
if (message->FindInt32("minute", &minute) == B_OK)
|
||||||
|
_tm->tm_min = minute;
|
||||||
|
if (message->FindInt32("second", &second) == B_OK)
|
||||||
|
_tm->tm_sec = second;
|
||||||
|
} else {
|
||||||
|
if (message->FindInt32("month", &month) == B_OK)
|
||||||
|
_tm->tm_mon = month;
|
||||||
|
if (message->FindInt32("day", &day) == B_OK)
|
||||||
|
_tm->tm_mday = day;
|
||||||
|
if (message->FindInt32("year", &year) == B_OK)
|
||||||
|
_tm->tm_year = year;
|
||||||
|
}
|
||||||
|
|
||||||
|
time_t atime2 = mktime(_tm);
|
||||||
|
set_real_time_clock(atime2);
|
||||||
|
DispatchMessage();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,14 +6,20 @@
|
|||||||
|
|
||||||
#include "TimeMessages.h"
|
#include "TimeMessages.h"
|
||||||
|
|
||||||
class TTimeBaseView: public BView
|
class TTimeBaseView: public BView {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
TTimeBaseView(BRect frmae, const char *name);
|
TTimeBaseView(BRect frmae, const char *name);
|
||||||
virtual ~TTimeBaseView();
|
virtual ~TTimeBaseView();
|
||||||
|
|
||||||
virtual void Pulse();
|
virtual void Pulse();
|
||||||
|
|
||||||
|
void ChangeTime(BMessage *message);
|
||||||
|
void SetGMTime(bool);
|
||||||
|
protected:
|
||||||
|
virtual void DispatchMessage();
|
||||||
private:
|
private:
|
||||||
BMessage *f_message;
|
BMessage *f_message;
|
||||||
|
bool f_gmtime;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //TIMEBASE_H
|
#endif //TIMEBASE_H
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
#include <Screen.h>
|
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
|
#include <Debug.h>
|
||||||
|
#include <Screen.h>
|
||||||
|
|
||||||
#include "Bitmaps.h"
|
#include "Bitmaps.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
ReplaceTransparentColor(BBitmap *bitmap, rgb_color with)
|
ReplaceTransparentColor(BBitmap *bitmap, rgb_color with)
|
||||||
{
|
{
|
||||||
// ASSERT(bitmap->ColorSpace() == B_COLOR_8_BIT); // other color spaces not implemented yet
|
ASSERT(bitmap->ColorSpace() == B_COLOR_8_BIT); // other color spaces not implemented yet
|
||||||
|
|
||||||
BScreen screen(B_MAIN_SCREEN_ID);
|
BScreen screen(B_MAIN_SCREEN_ID);
|
||||||
uint32 withIndex = screen.IndexForColor(with);
|
uint32 withIndex = screen.IndexForColor(with);
|
||||||
|
|||||||
+35
-10
@@ -1,7 +1,7 @@
|
|||||||
void ReplaceTransparentColor(BBitmap *bitmap, rgb_color with);
|
void ReplaceTransparentColor(BBitmap *bitmap, rgb_color with);
|
||||||
|
|
||||||
const int32 kClockFaceWidth = 85;
|
const int32 kClockFaceWidth = 85;
|
||||||
const int32 kClockFaceHeight = 86;
|
const int32 kClockFaceHeight = 85;
|
||||||
const color_space kClockFaceColorSpace = B_CMAP8;
|
const color_space kClockFaceColorSpace = B_CMAP8;
|
||||||
|
|
||||||
const unsigned char kClockFaceBits [] = {
|
const unsigned char kClockFaceBits [] = {
|
||||||
@@ -222,40 +222,40 @@ const unsigned char kClockFaceBits [] = {
|
|||||||
0x10,0x10,0x0e,0x06,0xff,0x3f,0x3f,0x3f,0xff,0x11,0x10,0x10,0x10,0x04,0x19,0x3f,
|
0x10,0x10,0x0e,0x06,0xff,0x3f,0x3f,0x3f,0xff,0x11,0x10,0x10,0x10,0x04,0x19,0x3f,
|
||||||
0x3f,0x3f,0x3f,0xda,0x2b,0x2b,0xda,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
0x3f,0x3f,0x3f,0xda,0x2b,0x2b,0xda,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
||||||
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
||||||
0x3f,0x0a,0x0a,0x0a,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
||||||
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0xda,0x2b,
|
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0xda,0x2b,
|
||||||
0x2b,0xda,0x3f,0x3f,0x3f,0x3f,0x1d,0x10,0x10,0x10,0x0f,0x05,0xff,0x3f,0x3f,0x3f,
|
0x2b,0xda,0x3f,0x3f,0x3f,0x3f,0x1d,0x10,0x10,0x10,0x0f,0x05,0xff,0x3f,0x3f,0x3f,
|
||||||
0xff,0x10,0x10,0x10,0x10,0x03,0x1c,0x3f,0x3f,0x3f,0x3f,0x2b,0x3f,0x3f,0x2b,0x3f,
|
0xff,0x10,0x10,0x10,0x10,0x03,0x1c,0x3f,0x3f,0x3f,0x3f,0x2b,0x3f,0x3f,0x2b,0x3f,
|
||||||
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
||||||
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x0a,0x15,0x15,0x15,0x0a,0x3f,0x3f,0x3f,
|
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
||||||
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
||||||
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x2b,0x3f,0x3f,0x2b,0x3f,0x3f,0x3f,0x3f,0x1e,0x10,
|
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x2b,0x3f,0x3f,0x2b,0x3f,0x3f,0x3f,0x3f,0x1e,0x10,
|
||||||
0x10,0x10,0x0f,0x03,0xff,0x3f,0x3f,0x3f,0xff,0x10,0x10,0x10,0x10,0x03,0x1e,0x3f,
|
0x10,0x10,0x0f,0x03,0xff,0x3f,0x3f,0x3f,0xff,0x10,0x10,0x10,0x10,0x03,0x1e,0x3f,
|
||||||
0x3f,0x3f,0x3f,0x2b,0x3f,0x3f,0x2b,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
0x3f,0x3f,0x3f,0x2b,0x3f,0x3f,0x2b,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
||||||
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x0a,
|
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
||||||
0x15,0x0a,0x0a,0x0a,0x15,0x0a,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
||||||
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
||||||
0x3f,0x2b,0x3f,0x3f,0x3f,0x3f,0x3f,0x10,0x10,0x10,0x10,0x03,0xff,0x3f,0x3f,0x3f,
|
0x3f,0x2b,0x3f,0x3f,0x3f,0x3f,0x3f,0x10,0x10,0x10,0x10,0x03,0xff,0x3f,0x3f,0x3f,
|
||||||
0xff,0x10,0x10,0x10,0x10,0x03,0x3f,0x3f,0x3f,0x3f,0x3f,0xda,0x2b,0x2b,0x2b,0x3f,
|
0xff,0x10,0x10,0x10,0x10,0x03,0x3f,0x3f,0x3f,0x3f,0x3f,0xda,0x2b,0x2b,0x2b,0x3f,
|
||||||
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
||||||
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x0a,0x15,0x0a,0x00,0x0a,0x15,0x0a,0x3f,0x3f,
|
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
||||||
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
||||||
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x2b,0x2b,0xda,0x3f,0x3f,0x3f,0x3f,0x3f,0x10,
|
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x2b,0x2b,0xda,0x3f,0x3f,0x3f,0x3f,0x3f,0x10,
|
||||||
0x10,0x10,0x0f,0x03,0xff,0x3f,0x3f,0x3f,0xff,0x10,0x10,0x10,0x10,0x04,0x1e,0x3f,
|
0x10,0x10,0x0f,0x03,0xff,0x3f,0x3f,0x3f,0xff,0x10,0x10,0x10,0x10,0x04,0x1e,0x3f,
|
||||||
0x3f,0x3f,0x3f,0x3f,0x3f,0xda,0x2b,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
0x3f,0x3f,0x3f,0x3f,0x3f,0xda,0x2b,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
||||||
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x0a,
|
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
||||||
0x15,0x0a,0x0a,0x0a,0x15,0x0a,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
||||||
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
||||||
0x3f,0x2b,0x3f,0x3f,0x3f,0x3f,0x3f,0x10,0x10,0x10,0x0f,0x03,0xff,0x3f,0x3f,0x3f,
|
0x3f,0x2b,0x3f,0x3f,0x3f,0x3f,0x3f,0x10,0x10,0x10,0x0f,0x03,0xff,0x3f,0x3f,0x3f,
|
||||||
0xff,0x10,0x10,0x10,0x10,0x05,0x1c,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x2b,0xda,0x3f,
|
0xff,0x10,0x10,0x10,0x10,0x05,0x1c,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x2b,0xda,0x3f,
|
||||||
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
||||||
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x0a,0x15,0x15,0x15,0x0a,0x3f,0x3f,0x3f,
|
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
||||||
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
||||||
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x2b,0x3f,0x3f,0x2b,0x3f,0x3f,0x3f,0x3f,0x1e,0x10,
|
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x2b,0x3f,0x3f,0x2b,0x3f,0x3f,0x3f,0x3f,0x1e,0x10,
|
||||||
0x10,0x10,0x0e,0x03,0xff,0x3f,0x3f,0x3f,0xff,0x11,0x10,0x10,0x10,0x06,0x19,0x3f,
|
0x10,0x10,0x0e,0x03,0xff,0x3f,0x3f,0x3f,0xff,0x11,0x10,0x10,0x10,0x06,0x19,0x3f,
|
||||||
0x3f,0x3f,0x3f,0x3f,0x2b,0xda,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
0x3f,0x3f,0x3f,0x3f,0x2b,0xda,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
||||||
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
||||||
0x3f,0x0a,0x0a,0x0a,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
||||||
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0xda,0x2b,
|
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0xda,0x2b,
|
||||||
0x2b,0xda,0x3f,0x3f,0x3f,0x3f,0x1d,0x10,0x10,0x10,0x0d,0x05,0xff,0x3f,0x3f,0x3f,
|
0x2b,0xda,0x3f,0x3f,0x3f,0x3f,0x1d,0x10,0x10,0x10,0x0d,0x05,0xff,0x3f,0x3f,0x3f,
|
||||||
0xff,0x12,0x10,0x10,0x10,0x07,0x15,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
0xff,0x12,0x10,0x10,0x10,0x07,0x15,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
|
||||||
@@ -480,6 +480,31 @@ const unsigned char kClockFaceBits [] = {
|
|||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x3f,0x3f,0x3f
|
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x3f,0x3f,0x3f
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const int32 kCenterWidth = 7;
|
||||||
|
const int32 kCenterHeight = 7;
|
||||||
|
const color_space kCenterColorSpace = B_CMAP8;
|
||||||
|
|
||||||
|
const unsigned char kCenterBits [] = {
|
||||||
|
0x3f,0x3f,0x0a,0x0a,0x0a,0x3f,0x3f,0x3f,
|
||||||
|
0x3f,0x0a,0x15,0x15,0x15,0x0a,0x3f,0x0a,
|
||||||
|
0x0a,0x15,0x0a,0x0a,0x0a,0x15,0x0a,0x0a,
|
||||||
|
0x0a,0x15,0x0a,0x00,0x0a,0x15,0x0a,0x0a,
|
||||||
|
0x0a,0x15,0x0a,0x0a,0x0a,0x15,0x0a,0x0a,
|
||||||
|
0x3f,0x0a,0x15,0x15,0x15,0x0a,0x3f,0x3f,
|
||||||
|
0x3f,0x3f,0x0a,0x0a,0x0a,0x3f,0x3f};
|
||||||
|
|
||||||
|
const int32 kCapWidth = 5;
|
||||||
|
const int32 kCapHeight = 5;
|
||||||
|
const color_space kCapColorSpace = B_CMAP8;
|
||||||
|
|
||||||
|
const unsigned char kCapBits [] = {
|
||||||
|
0x0a, 0x15, 0x15, 0x15, 0x0a, 0x00, 0x00, 0x00,
|
||||||
|
0x15, 0x0a, 0x0a, 0x0a, 0x15, 0x00, 0x00, 0x00,
|
||||||
|
0x15, 0x0a, 0x00, 0x0a, 0x15, 0x00, 0x00, 0x00,
|
||||||
|
0x15, 0x0a, 0x0a, 0x0a, 0x15, 0x00, 0x00, 0x00,
|
||||||
|
0x0a, 0x15, 0x15, 0x15, 0x0a, 0x00, 0x00, 0x00
|
||||||
|
};
|
||||||
|
|
||||||
const int32 kUpArrowWidth = 16;
|
const int32 kUpArrowWidth = 16;
|
||||||
const int32 kUpArrowHeight = 7;
|
const int32 kUpArrowHeight = 7;
|
||||||
const color_space kUpArrowColorSpace = B_CMAP8;
|
const color_space kUpArrowColorSpace = B_CMAP8;
|
||||||
|
|||||||
+159
-141
@@ -1,28 +1,25 @@
|
|||||||
#include <Debug.h>
|
|
||||||
#include <Message.h>
|
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
#include <Window.h>
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "CalendarView.h"
|
#include "CalendarView.h"
|
||||||
|
#include "DateUtils.h"
|
||||||
|
#include "TimeMessages.h"
|
||||||
|
|
||||||
|
|
||||||
#define SEGMENT_CHANGE 'ostd'
|
#define SEGMENT_CHANGE 'ostd'
|
||||||
|
|
||||||
void
|
|
||||||
|
|
||||||
__printrect(BRect rect)
|
|
||||||
{
|
|
||||||
printf("%f, %f, %f, %f\n", rect.left, rect.top, rect.right, rect.bottom);
|
|
||||||
}
|
|
||||||
|
|
||||||
TDay::TDay(BRect frame, int day)
|
TDay::TDay(BRect frame, int day)
|
||||||
: BView(frame, B_EMPTY_STRING, B_FOLLOW_NONE, B_WILL_DRAW)
|
: BControl(frame, B_EMPTY_STRING, NULL, NULL, B_FOLLOW_NONE, B_WILL_DRAW)
|
||||||
, f_day(day)
|
, f_day(day)
|
||||||
, f_isselected(false)
|
{
|
||||||
{ }
|
}
|
||||||
|
|
||||||
|
|
||||||
TDay::~TDay()
|
TDay::~TDay()
|
||||||
{ }
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TDay::AttachedToWindow()
|
TDay::AttachedToWindow()
|
||||||
@@ -31,29 +28,45 @@ TDay::AttachedToWindow()
|
|||||||
SetViewColor(Parent()->ViewColor());
|
SetViewColor(Parent()->ViewColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TDay::MouseDown(BPoint where)
|
TDay::MouseDown(BPoint where)
|
||||||
{
|
{
|
||||||
if (f_day> 0)
|
if (f_day> 0) {
|
||||||
{
|
// only allow if not currently selected
|
||||||
f_isselected = !f_isselected;
|
if (Value() == B_CONTROL_ON)
|
||||||
|
return;
|
||||||
|
|
||||||
|
SetValue(B_CONTROL_ON);
|
||||||
|
Invoke();
|
||||||
|
|
||||||
|
//update display
|
||||||
Draw(Bounds());
|
Draw(Bounds());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TDay::MakeFocus(bool focused)
|
||||||
|
{
|
||||||
|
if (focused != IsFocus()) {
|
||||||
|
BView::MakeFocus(focused);
|
||||||
|
Draw(Bounds());
|
||||||
|
Flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TDay::Stroke3dFrame(BRect frame, rgb_color light, rgb_color dark, bool inset)
|
TDay::Stroke3dFrame(BRect frame, rgb_color light, rgb_color dark, bool inset)
|
||||||
{
|
{
|
||||||
rgb_color color1;
|
rgb_color color1;
|
||||||
rgb_color color2;
|
rgb_color color2;
|
||||||
|
|
||||||
if (inset)
|
if (inset) {
|
||||||
{
|
|
||||||
color1 = dark;
|
color1 = dark;
|
||||||
color2 = light;
|
color2 = light;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
color1 = light;
|
color1 = light;
|
||||||
color2 = dark;
|
color2 = dark;
|
||||||
}
|
}
|
||||||
@@ -81,12 +94,9 @@ TDay::Draw(BRect updaterect)
|
|||||||
|
|
||||||
BString text;
|
BString text;
|
||||||
|
|
||||||
if (f_isselected)
|
if (Value() == 1) {
|
||||||
{
|
|
||||||
bgcolor = tint_color(ViewColor(), B_DARKEN_2_TINT);
|
bgcolor = tint_color(ViewColor(), B_DARKEN_2_TINT);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
bgcolor = tint_color(ViewColor(), B_DARKEN_1_TINT);
|
bgcolor = tint_color(ViewColor(), B_DARKEN_1_TINT);
|
||||||
}
|
}
|
||||||
text << f_day;
|
text << f_day;
|
||||||
@@ -97,12 +107,8 @@ TDay::Draw(BRect updaterect)
|
|||||||
SetHighColor(bgcolor);
|
SetHighColor(bgcolor);
|
||||||
FillRect(bounds);
|
FillRect(bounds);
|
||||||
|
|
||||||
if (f_isselected)
|
if (f_day> 0) {
|
||||||
Stroke3dFrame(bounds, light, dark, true);
|
if (!(Value() == 1))
|
||||||
|
|
||||||
if (f_day> 0)
|
|
||||||
{
|
|
||||||
if (!f_isselected)
|
|
||||||
SetHighColor(0, 0, 0, 255);
|
SetHighColor(0, 0, 0, 255);
|
||||||
else
|
else
|
||||||
SetHighColor(255, 255, 255, 255);
|
SetHighColor(255, 255, 255, 255);
|
||||||
@@ -118,8 +124,35 @@ TDay::Draw(BRect updaterect)
|
|||||||
BPoint drawpt((bounds.Width()/2.0) -(width/2.0) +1, (bounds.Height()/2.0) +(height/2.0) -2);
|
BPoint drawpt((bounds.Width()/2.0) -(width/2.0) +1, (bounds.Height()/2.0) +(height/2.0) -2);
|
||||||
DrawString(text.String(), drawpt);
|
DrawString(text.String(), drawpt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (IsFocus()) {
|
||||||
|
rgb_color nav_color = keyboard_navigation_color();
|
||||||
|
SetHighColor(nav_color);
|
||||||
|
StrokeRect(bounds);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
SetHighColor(bgcolor);
|
||||||
|
StrokeRect(bounds);
|
||||||
|
if (Value() == 1)
|
||||||
|
Stroke3dFrame(bounds, light, dark, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TDay::SetValue(int32 value)
|
||||||
|
{
|
||||||
|
BControl::SetValue(value);
|
||||||
|
|
||||||
|
if (Value() == 1) {
|
||||||
|
SetFlags(Flags() & ~B_NAVIGABLE);
|
||||||
|
} else {
|
||||||
|
SetFlags(Flags()|B_NAVIGABLE);
|
||||||
|
}
|
||||||
|
Draw(Bounds());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TDay::SetTo(BRect frame, int day)
|
TDay::SetTo(BRect frame, int day)
|
||||||
{
|
{
|
||||||
@@ -128,19 +161,30 @@ TDay::SetTo(BRect frame, int day)
|
|||||||
Draw(Bounds());
|
Draw(Bounds());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TDay::SetDay(int day, bool selected = false)
|
TDay::SetTo(int day, bool selected = false)
|
||||||
{
|
{
|
||||||
f_day = day;
|
f_day = day;
|
||||||
f_isselected = selected;
|
SetValue(selected);
|
||||||
|
if (Value() == 1) {
|
||||||
|
SetFlags(Flags()|B_NAVIGABLE);
|
||||||
|
} else {
|
||||||
|
SetFlags(Flags() & ~B_NAVIGABLE);
|
||||||
|
}
|
||||||
Draw(Bounds());
|
Draw(Bounds());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*=====> TCalendarView <=====*/
|
/*=====> TCalendarView <=====*/
|
||||||
|
|
||||||
TCalendarView::TCalendarView(BRect frame, const char *name, uint32 resizingmode, uint32 flags)
|
TCalendarView::TCalendarView(BRect frame, const char *name,
|
||||||
|
uint32 resizingmode, uint32 flags)
|
||||||
: BView(frame, name, resizingmode, flags)
|
: BView(frame, name, resizingmode, flags)
|
||||||
|
, f_firstday(0)
|
||||||
|
, f_month(0)
|
||||||
|
, f_day(0)
|
||||||
|
,f_year(0)
|
||||||
{
|
{
|
||||||
InitView();
|
InitView();
|
||||||
}
|
}
|
||||||
@@ -149,6 +193,29 @@ TCalendarView::~TCalendarView()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TCalendarView::MessageReceived(BMessage *message)
|
||||||
|
{
|
||||||
|
switch(message->what) {
|
||||||
|
case OB_DAY_CHANGED:
|
||||||
|
{
|
||||||
|
TDay *day;
|
||||||
|
message->FindPointer("source", (void **)&day);
|
||||||
|
if (f_cday != NULL)
|
||||||
|
f_cday->SetValue(B_CONTROL_OFF);
|
||||||
|
f_cday = day;
|
||||||
|
|
||||||
|
DispatchMessage();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
BView::MessageReceived(message);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TCalendarView::AttachedToWindow()
|
TCalendarView::AttachedToWindow()
|
||||||
{
|
{
|
||||||
@@ -157,7 +224,7 @@ TCalendarView::AttachedToWindow()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char days[7] = { 'S', 'M', 'T', 'W', 'T', 'F', 'S' };
|
static const char days[7] = { 'S', 'M', 'T', 'W', 'T', 'F', 'S' };
|
||||||
|
|
||||||
void
|
void
|
||||||
TCalendarView::Draw(BRect updaterect)
|
TCalendarView::Draw(BRect updaterect)
|
||||||
@@ -170,8 +237,7 @@ TCalendarView::Draw(BRect updaterect)
|
|||||||
BString day;
|
BString day;
|
||||||
SetLowColor(ViewColor());
|
SetLowColor(ViewColor());
|
||||||
SetHighColor(0, 0, 0);
|
SetHighColor(0, 0, 0);
|
||||||
for (int i = 0; i < 7; i++)
|
for (int i = 0; i < 7; i++) {
|
||||||
{
|
|
||||||
day = days[i];
|
day = days[i];
|
||||||
width = be_plain_font->StringWidth(day.String());
|
width = be_plain_font->StringWidth(day.String());
|
||||||
drawpt.x = bounds.left +(x -width/2.0 +2);
|
drawpt.x = bounds.left +(x -width/2.0 +2);
|
||||||
@@ -181,80 +247,6 @@ TCalendarView::Draw(BRect updaterect)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
TCalendarView::ClearDays()
|
|
||||||
{
|
|
||||||
BView *child;
|
|
||||||
if (CountChildren()> 0)
|
|
||||||
{
|
|
||||||
if ((child = ChildAt(0)) != NULL)
|
|
||||||
{
|
|
||||||
while (child)
|
|
||||||
{
|
|
||||||
RemoveChild(child);
|
|
||||||
child = child->NextSibling();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
TCalendarView::CalcFlags()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
isLeapYear(const int year)
|
|
||||||
{
|
|
||||||
if ((year % 400 == 0)||(year % 4 == 0 && year % 100 == 0))
|
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
GetDaysInMonth(const int month, const int year)
|
|
||||||
{
|
|
||||||
if (month == 2 && isLeapYear(year))
|
|
||||||
{
|
|
||||||
return 29;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const int DaysinMonth[12] =
|
|
||||||
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
|
||||||
|
|
||||||
return DaysinMonth[month];
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
GetFirstDay(const int month, const int year)
|
|
||||||
{
|
|
||||||
int l_century = year/100;
|
|
||||||
int l_decade = year%100;
|
|
||||||
int l_month = (month +10)%12;
|
|
||||||
int l_day = 1;
|
|
||||||
|
|
||||||
if (l_month == 1 || l_month == 2)
|
|
||||||
{
|
|
||||||
if (l_decade == 0)
|
|
||||||
{
|
|
||||||
l_decade = 99;
|
|
||||||
l_century -= 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
l_decade-= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
float tmp = (l_day +(floor(((13 *l_month) -1)/5))
|
|
||||||
+l_decade +(floor(l_decade /4))
|
|
||||||
+(floor(l_century/4)) -(2 *l_century));
|
|
||||||
int result = static_cast<int>(tmp)%7;
|
|
||||||
|
|
||||||
if (result < 0)
|
|
||||||
result += 7;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TCalendarView::InitView()
|
TCalendarView::InitView()
|
||||||
@@ -268,14 +260,10 @@ TCalendarView::InitView()
|
|||||||
float height = ((bounds.Height() -(text_height +4)) -6)/6;
|
float height = ((bounds.Height() -(text_height +4)) -6)/6;
|
||||||
f_dayrect.Set(0.0, text_height +6, width, text_height +6 +height);
|
f_dayrect.Set(0.0, text_height +6, width, text_height +6 +height);
|
||||||
|
|
||||||
__printrect(f_dayrect);
|
|
||||||
|
|
||||||
BRect dayrect(f_dayrect);
|
BRect dayrect(f_dayrect);
|
||||||
TDay *day;
|
TDay *day;
|
||||||
for (int row = 0; row < 6; row++)
|
for (int row = 0; row < 6; row++) {
|
||||||
{
|
for (int col = 0; col < 7; col++) {
|
||||||
for (int col = 0; col < 7; col++)
|
|
||||||
{
|
|
||||||
day = new TDay(dayrect.InsetByCopy(1, 1), 0);
|
day = new TDay(dayrect.InsetByCopy(1, 1), 0);
|
||||||
AddChild(day);
|
AddChild(day);
|
||||||
dayrect.OffsetBy(width +1, 0);
|
dayrect.OffsetBy(width +1, 0);
|
||||||
@@ -283,6 +271,8 @@ TCalendarView::InitView()
|
|||||||
dayrect.OffsetBy(0, height +1);
|
dayrect.OffsetBy(0, height +1);
|
||||||
dayrect.OffsetTo(0, dayrect.top);
|
dayrect.OffsetTo(0, dayrect.top);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
f_cday = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -290,41 +280,69 @@ TCalendarView::InitDates()
|
|||||||
{
|
{
|
||||||
TDay *day;
|
TDay *day;
|
||||||
|
|
||||||
int label = 0;
|
int32 label = 0;
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
int first = GetFirstDay(f_month+1, f_year);
|
f_firstday = getFirstDay(f_month+1, f_year);
|
||||||
int daycnt = GetDaysInMonth(f_month, f_year);
|
int daycnt = getDaysInMonth(f_month, f_year);
|
||||||
printf("%d, %d\n", first, daycnt);
|
bool cday = false;
|
||||||
for (int row = 0; row < 6; row++)
|
for (int row = 0; row < 6; row++) {
|
||||||
{
|
for (int col = 0; col < 7; col++) {
|
||||||
for (int col = 0; col < 7; col++)
|
|
||||||
{
|
|
||||||
day = dynamic_cast<TDay *>(ChildAt((row *7) +col));
|
day = dynamic_cast<TDay *>(ChildAt((row *7) +col));
|
||||||
|
|
||||||
if (idx < first || idx > daycnt +first +1)
|
if (idx < f_firstday || idx > daycnt +f_firstday +1)
|
||||||
label = 0;
|
label = 0;
|
||||||
else
|
else
|
||||||
label = idx -(first +1);
|
label = idx -(f_firstday +1);
|
||||||
idx++;
|
idx++;
|
||||||
day->SetDay(label, (label == f_day));
|
cday = label == f_day;
|
||||||
|
day->SetTo(label, cday);
|
||||||
|
|
||||||
|
if (label> 0) {
|
||||||
|
BMessage *message = new BMessage(OB_DAY_CHANGED);
|
||||||
|
message->AddInt32("Day", label);
|
||||||
|
|
||||||
|
day->SetTarget(this);
|
||||||
|
day->SetMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cday) {
|
||||||
|
f_cday = day;
|
||||||
|
}
|
||||||
|
cday = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TCalendarView::Update(tm *atm)
|
TCalendarView::SetTo(int32 year, int32 month, int32 day)
|
||||||
{
|
{
|
||||||
if (f_month != atm->tm_mon
|
if (f_month != month||f_year != year) {
|
||||||
||f_day != atm->tm_mday
|
f_month = month;
|
||||||
||f_year != atm->tm_year)
|
f_day = day;
|
||||||
{
|
f_year = year;
|
||||||
f_month = atm->tm_mon;
|
|
||||||
f_day = atm->tm_mday;
|
|
||||||
f_wday = atm->tm_wday;
|
|
||||||
f_year = atm->tm_year;
|
|
||||||
InitDates();
|
InitDates();
|
||||||
|
} else if (f_day != day) {
|
||||||
|
f_day = day;
|
||||||
|
int idx = ((f_day/7)*7) + (f_day%7 +f_firstday +1);
|
||||||
|
TDay *day = dynamic_cast<TDay *>(ChildAt(idx));
|
||||||
|
f_cday->SetValue(B_CONTROL_OFF);
|
||||||
|
f_cday = day;
|
||||||
|
day->SetValue(B_CONTROL_ON);
|
||||||
}
|
}
|
||||||
printf("M: %d %d D: %d %d Y: %d %d\n",
|
}
|
||||||
f_month, atm->tm_mon, f_day, atm->tm_mday, f_year, atm->tm_year);
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TCalendarView::DispatchMessage()
|
||||||
|
{
|
||||||
|
// send message to update timedate
|
||||||
|
BMessage *msg = new BMessage(OB_USER_CHANGE);
|
||||||
|
msg->AddBool("time", false);
|
||||||
|
msg->AddInt32("month", f_month);
|
||||||
|
if (f_cday != NULL)
|
||||||
|
msg->AddInt32("day", f_cday->Day());
|
||||||
|
msg->AddInt32("year", f_year);
|
||||||
|
|
||||||
|
Window()->PostMessage(msg);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,48 +1,52 @@
|
|||||||
#ifndef CALENDAR_VIEW_H
|
#ifndef CALENDAR_VIEW_H
|
||||||
#define CALENDAR_VIEW_H
|
#define CALENDAR_VIEW_H
|
||||||
|
|
||||||
|
#include <Control.h>
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
#include <time.h>
|
class TDay: public BControl {
|
||||||
|
|
||||||
class TDay: public BView
|
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
TDay(BRect frame, int day);
|
TDay(BRect frame, int day);
|
||||||
virtual ~TDay();
|
virtual ~TDay();
|
||||||
virtual void Draw(BRect updaterect);
|
virtual void Draw(BRect updaterect);
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
virtual void MouseDown(BPoint where);
|
virtual void MouseDown(BPoint where);
|
||||||
|
virtual void SetValue(int32 value);
|
||||||
|
virtual void MakeFocus(bool focused);
|
||||||
|
|
||||||
void SetTo(BRect frame, int day);
|
void SetTo(BRect frame, int day);
|
||||||
void SetDay(int day, bool selected = false);
|
void SetTo(int day, bool selected = false);
|
||||||
|
|
||||||
|
int Day()
|
||||||
|
{ return f_day; }
|
||||||
protected:
|
protected:
|
||||||
virtual void Stroke3dFrame(BRect frame, rgb_color light, rgb_color dark, bool inset);
|
virtual void Stroke3dFrame(BRect frame, rgb_color light, rgb_color dark, bool inset);
|
||||||
private:
|
private:
|
||||||
int f_day;
|
int f_day;
|
||||||
bool f_isselected;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class TCalendarView: public BView
|
class TCalendarView: public BView {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
TCalendarView(BRect frame, const char *name, uint32 resizingmode, uint32 flags);
|
TCalendarView(BRect frame, const char *name, uint32 resizingmode, uint32 flags);
|
||||||
virtual ~TCalendarView();
|
virtual ~TCalendarView();
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
virtual void Draw(BRect bounds);
|
virtual void Draw(BRect bounds);
|
||||||
|
virtual void MessageReceived(BMessage *message);
|
||||||
|
|
||||||
void Update(tm *atm);
|
void SetTo(int32, int32, int32);
|
||||||
protected:
|
protected:
|
||||||
virtual void InitView();
|
virtual void InitView();
|
||||||
|
virtual void DispatchMessage();
|
||||||
private:
|
private:
|
||||||
void InitDates();
|
void InitDates();
|
||||||
void ClearDays();
|
|
||||||
void CalcFlags();
|
void CalcFlags();
|
||||||
|
|
||||||
BRect f_dayrect;
|
TDay *f_cday;
|
||||||
int f_month;
|
BRect f_dayrect;
|
||||||
int f_day;
|
int f_firstday;
|
||||||
int f_year;
|
int f_month;
|
||||||
int f_wday;
|
int f_day;
|
||||||
|
int f_year;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CALENDAR_VIEW_H
|
#endif // CALENDAR_VIEW_H
|
||||||
|
|||||||
+403
-252
@@ -1,64 +1,69 @@
|
|||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
#include <Window.h>
|
||||||
|
|
||||||
#include "DateTimeEdit.h"
|
|
||||||
#include "Bitmaps.h"
|
#include "Bitmaps.h"
|
||||||
|
#include "DateTimeEdit.h"
|
||||||
|
#include "DateUtils.h"
|
||||||
|
#include "TimeMessages.h"
|
||||||
|
|
||||||
const int32 kArrowAreaWidth = 16;
|
const int32 kArrowAreaWidth = 16;
|
||||||
|
|
||||||
|
// number of years after 1900 to loop should be system setting
|
||||||
|
#define YEAR_DELTA 110
|
||||||
|
|
||||||
/*=====> TDateTimeEdit <=====*/
|
/*=====> TDateTimeEdit <=====*/
|
||||||
|
|
||||||
TDateTimeEdit::TDateTimeEdit(BRect frame, const char *name)
|
TDateTimeEdit::TDateTimeEdit(BRect frame, const char *name)
|
||||||
: BView(frame, name, B_FOLLOW_NONE, B_NAVIGABLE|B_WILL_DRAW)
|
: BControl(frame, name, NULL, NULL, B_FOLLOW_NONE, B_NAVIGABLE|B_WILL_DRAW)
|
||||||
|
, f_holdvalue(0)
|
||||||
{
|
{
|
||||||
f_up = new BBitmap(BRect(0, 0, kUpArrowWidth -1, kUpArrowHeight -1), kUpArrowColorSpace);
|
f_up = new BBitmap(BRect(0, 0, kUpArrowWidth -1, kUpArrowHeight -1), kUpArrowColorSpace);
|
||||||
f_up->SetBits(kUpArrowBits, (kUpArrowWidth) *(kUpArrowHeight+1), 0, kUpArrowColorSpace);
|
f_up->SetBits(kUpArrowBits, (kUpArrowWidth) *(kUpArrowHeight+1), 0, kUpArrowColorSpace);
|
||||||
ReplaceTransparentColor(f_up, ui_color(B_PANEL_BACKGROUND_COLOR)); // should be set to parents back color
|
|
||||||
|
|
||||||
f_down = new BBitmap(BRect(0, 0, kDownArrowWidth -1, kDownArrowHeight -2), kDownArrowColorSpace);
|
f_down = new BBitmap(BRect(0, 0, kDownArrowWidth -1, kDownArrowHeight -2), kDownArrowColorSpace);
|
||||||
f_down->SetBits(kDownArrowBits, (kDownArrowWidth) *(kDownArrowHeight), 0, kDownArrowColorSpace);
|
f_down->SetBits(kDownArrowBits, (kDownArrowWidth) *(kDownArrowHeight), 0, kDownArrowColorSpace);
|
||||||
ReplaceTransparentColor(f_down, ui_color(B_PANEL_BACKGROUND_COLOR));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TDateTimeEdit::~TDateTimeEdit()
|
TDateTimeEdit::~TDateTimeEdit()
|
||||||
{ }
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TDateTimeEdit::AttachedToWindow()
|
TDateTimeEdit::AttachedToWindow()
|
||||||
{
|
{
|
||||||
if (Parent())
|
if (Parent()) {
|
||||||
SetViewColor(Parent()->ViewColor());
|
SetViewColor(Parent()->ViewColor());
|
||||||
|
ReplaceTransparentColor(f_up, ViewColor());
|
||||||
|
ReplaceTransparentColor(f_down, ViewColor());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TDateTimeEdit::MessageReceived(BMessage *message)
|
||||||
|
{
|
||||||
|
switch(message->what) {
|
||||||
|
default:
|
||||||
|
BView::MessageReceived(message);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TDateTimeEdit::MouseDown(BPoint where)
|
TDateTimeEdit::MouseDown(BPoint where)
|
||||||
{
|
{
|
||||||
MakeFocus(true);
|
MakeFocus(true);
|
||||||
if (f_uprect.Contains(where))
|
if (f_uprect.Contains(where))
|
||||||
UpPress();
|
UpPress();
|
||||||
else
|
else if (f_downrect.Contains(where))
|
||||||
if (f_downrect.Contains(where))
|
|
||||||
DownPress();
|
DownPress();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
TDateTimeEdit::UpPress()
|
|
||||||
{ }
|
|
||||||
|
|
||||||
void
|
|
||||||
TDateTimeEdit::DownPress()
|
|
||||||
{ }
|
|
||||||
|
|
||||||
void
|
|
||||||
TDateTimeEdit::MakeFocus(bool focused)
|
|
||||||
{
|
|
||||||
if (focused != IsFocus())
|
|
||||||
{
|
|
||||||
BView::MakeFocus(focused);
|
|
||||||
Draw(Bounds());
|
|
||||||
Flush();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TDateTimeEdit::Draw(BRect updaterect)
|
TDateTimeEdit::Draw(BRect updaterect)
|
||||||
@@ -77,15 +82,13 @@ TDateTimeEdit::Draw(BRect updaterect)
|
|||||||
|
|
||||||
bounds.InsetBy(1, 1);
|
bounds.InsetBy(1, 1);
|
||||||
bounds.right -= kArrowAreaWidth;
|
bounds.right -= kArrowAreaWidth;
|
||||||
if (IsFocus())
|
|
||||||
{
|
if ( (IsFocus() && Window() && Window()->IsActive())) {
|
||||||
rgb_color navcolor = keyboard_navigation_color();
|
rgb_color navcolor = keyboard_navigation_color();
|
||||||
|
|
||||||
SetHighColor(navcolor);
|
SetHighColor(navcolor);
|
||||||
StrokeRect(bounds);
|
StrokeRect(bounds);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// draw border thickening (erase focus)
|
// draw border thickening (erase focus)
|
||||||
SetHighColor(darker);
|
SetHighColor(darker);
|
||||||
SetLowColor(bgcolor);
|
SetLowColor(bgcolor);
|
||||||
@@ -110,23 +113,21 @@ TDateTimeEdit::Draw(BRect updaterect)
|
|||||||
StrokeLine(bounds.RightTop(), bounds.RightTop());
|
StrokeLine(bounds.RightTop(), bounds.RightTop());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TDateTimeEdit::Draw3dFrame(BRect frame, bool inset)
|
TDateTimeEdit::Draw3dFrame(BRect frame, bool inset)
|
||||||
{
|
{
|
||||||
rgb_color color1, color2;
|
rgb_color color1, color2;
|
||||||
|
|
||||||
if (inset)
|
if (inset) {
|
||||||
{
|
|
||||||
color1 = HighColor();
|
color1 = HighColor();
|
||||||
color2 = LowColor();
|
color2 = LowColor();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
color1 = LowColor();
|
color1 = LowColor();
|
||||||
color2 = HighColor();
|
color2 = HighColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
BeginLineArray(6);
|
BeginLineArray(4);
|
||||||
// left side
|
// left side
|
||||||
AddLine(frame.LeftBottom(), frame.LeftTop(), color2);
|
AddLine(frame.LeftBottom(), frame.LeftTop(), color2);
|
||||||
// right side
|
// right side
|
||||||
@@ -139,6 +140,16 @@ TDateTimeEdit::Draw3dFrame(BRect frame, bool inset)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TDateTimeEdit::DispatchMessage()
|
||||||
|
{
|
||||||
|
// send message to update timedate
|
||||||
|
BMessage *msg = new BMessage(OB_USER_CHANGE);
|
||||||
|
BuildDispatch(msg);
|
||||||
|
Window()->PostMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*=====> TTimeEdit <=====*/
|
/*=====> TTimeEdit <=====*/
|
||||||
|
|
||||||
TTimeEdit::TTimeEdit(BRect frame, const char *name)
|
TTimeEdit::TTimeEdit(BRect frame, const char *name)
|
||||||
@@ -147,13 +158,12 @@ TTimeEdit::TTimeEdit(BRect frame, const char *name)
|
|||||||
BRect bounds(Bounds().InsetByCopy(1, 2));
|
BRect bounds(Bounds().InsetByCopy(1, 2));
|
||||||
|
|
||||||
// all areas same width :)
|
// all areas same width :)
|
||||||
float width = be_plain_font->StringWidth("00") +7;
|
float width = be_plain_font->StringWidth("00") +6;
|
||||||
|
|
||||||
// AM/PM rect
|
// AM/PM rect
|
||||||
bounds.right = Bounds().right -(kArrowAreaWidth +3);
|
bounds.right = Bounds().right -(kArrowAreaWidth +3);
|
||||||
bounds.left = bounds.right -(width +4);
|
bounds.left = bounds.right -(width +5);
|
||||||
f_aprect = bounds;
|
f_aprect = bounds;
|
||||||
|
|
||||||
|
|
||||||
// seconds rect
|
// seconds rect
|
||||||
bounds.right = bounds.left;
|
bounds.right = bounds.left;
|
||||||
@@ -173,8 +183,11 @@ TTimeEdit::TTimeEdit(BRect frame, const char *name)
|
|||||||
f_hourrect = bounds;
|
f_hourrect = bounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TTimeEdit::~TTimeEdit()
|
TTimeEdit::~TTimeEdit()
|
||||||
{ }
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TTimeEdit::Draw(BRect updaterect)
|
TTimeEdit::Draw(BRect updaterect)
|
||||||
@@ -183,11 +196,11 @@ TTimeEdit::Draw(BRect updaterect)
|
|||||||
|
|
||||||
SetHighColor(0, 0, 0, 255);
|
SetHighColor(0, 0, 0, 255);
|
||||||
|
|
||||||
BRect bounds(Bounds());
|
|
||||||
BString text;
|
BString text;
|
||||||
BPoint drawpt;
|
BPoint drawpt;
|
||||||
BPoint offset(0, f_hourrect.Height()/2.0 -6);
|
BPoint offset(0, f_hourrect.Height()/2.0 -6);
|
||||||
|
int value;
|
||||||
|
|
||||||
// seperator
|
// seperator
|
||||||
BString septext(":");
|
BString septext(":");
|
||||||
|
|
||||||
@@ -195,50 +208,52 @@ TTimeEdit::Draw(BRect updaterect)
|
|||||||
rgb_color dark = tint_color(ViewColor(), B_DARKEN_1_TINT);
|
rgb_color dark = tint_color(ViewColor(), B_DARKEN_1_TINT);
|
||||||
|
|
||||||
//draw hour
|
//draw hour
|
||||||
if (updaterect.Contains(f_hourrect))
|
if (updaterect.Contains(f_hourrect)) {
|
||||||
{
|
|
||||||
if (f_hour> 12)
|
if (f_focus == FOCUS_HOUR && IsFocus()) {
|
||||||
{
|
SetLowColor(dark);
|
||||||
if (f_hour < 22) text << "0";
|
value = f_holdvalue;
|
||||||
text << f_hour -12;
|
} else {
|
||||||
|
SetLowColor(ViewColor());
|
||||||
|
value = f_hour;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
if (value> 12) {
|
||||||
if (f_hour < 10) text << "0";
|
if (value < 22) text << "0";
|
||||||
text << f_hour;
|
text << value -12;
|
||||||
|
} else {
|
||||||
|
if (value < 10) text << "0";
|
||||||
|
text << value;
|
||||||
}
|
}
|
||||||
width = be_plain_font->StringWidth(text.String());
|
width = be_plain_font->StringWidth(text.String());
|
||||||
offset.x = -(f_hourrect.Width()/2.0 -width/2.0);
|
offset.x = -(f_hourrect.Width()/2.0 -width/2.0) -1;
|
||||||
drawpt = f_hourrect.LeftBottom() -offset;
|
drawpt = f_hourrect.LeftBottom() -offset;
|
||||||
|
|
||||||
if (f_focus == FOCUS_HOUR)
|
|
||||||
SetLowColor(dark);
|
|
||||||
else
|
|
||||||
SetLowColor(ViewColor());
|
|
||||||
|
|
||||||
FillRect(f_hourrect, B_SOLID_LOW);
|
FillRect(f_hourrect, B_SOLID_LOW);
|
||||||
DrawString(text.String(), drawpt);
|
DrawString(text.String(), drawpt);
|
||||||
|
|
||||||
offset.x = -3;
|
|
||||||
SetLowColor(ViewColor());
|
SetLowColor(ViewColor());
|
||||||
DrawString(septext.String(), f_hourrect.RightBottom() -offset);
|
DrawString(septext.String(), f_hourrect.RightBottom() -offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
//draw min
|
//draw min
|
||||||
if (updaterect.Contains(f_minrect))
|
if (updaterect.Contains(f_minrect)) {
|
||||||
{
|
if (f_focus == FOCUS_MINUTE && IsFocus()) {
|
||||||
|
SetLowColor(dark);
|
||||||
|
value = f_holdvalue;
|
||||||
|
} else {
|
||||||
|
SetLowColor(ViewColor());
|
||||||
|
value = f_minute;
|
||||||
|
}
|
||||||
|
|
||||||
text = "";
|
text = "";
|
||||||
if (f_minute < 10) text << "0";
|
if (value < 10) text << "0";
|
||||||
text << f_minute;
|
text << value;
|
||||||
|
|
||||||
width = be_plain_font->StringWidth(text.String());
|
width = be_plain_font->StringWidth(text.String());
|
||||||
offset.x = -(f_minrect.Width()/2.0 -width/2.0);
|
offset.x = -(f_minrect.Width()/2.0 -width/2.0) -1;
|
||||||
drawpt = f_minrect.LeftBottom() -offset;
|
drawpt = f_minrect.LeftBottom() -offset;
|
||||||
|
|
||||||
if (f_focus == FOCUS_MINUTE)
|
|
||||||
SetLowColor(dark);
|
|
||||||
else
|
|
||||||
SetLowColor(ViewColor());
|
|
||||||
|
|
||||||
FillRect(f_minrect, B_SOLID_LOW);
|
FillRect(f_minrect, B_SOLID_LOW);
|
||||||
DrawString(text.String(), drawpt);
|
DrawString(text.String(), drawpt);
|
||||||
|
|
||||||
@@ -248,27 +263,29 @@ TTimeEdit::Draw(BRect updaterect)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//draw sec
|
//draw sec
|
||||||
if (updaterect.Contains(f_secrect))
|
if (updaterect.Contains(f_secrect)) {
|
||||||
{
|
if (f_focus == FOCUS_SECOND && IsFocus()) {
|
||||||
text = "";
|
|
||||||
if (f_second < 10) text << "0";
|
|
||||||
text << f_second;
|
|
||||||
width = be_plain_font->StringWidth(text.String());
|
|
||||||
offset.x = -(f_secrect.Width()/2.0 -width/2.0);
|
|
||||||
drawpt = f_secrect.LeftBottom() -offset;
|
|
||||||
|
|
||||||
if (f_focus == FOCUS_SECOND)
|
|
||||||
SetLowColor(dark);
|
SetLowColor(dark);
|
||||||
else
|
value = f_holdvalue;
|
||||||
|
} else {
|
||||||
SetLowColor(ViewColor());
|
SetLowColor(ViewColor());
|
||||||
|
value = f_second;
|
||||||
|
}
|
||||||
|
|
||||||
|
text = "";
|
||||||
|
if (value < 10) text << "0";
|
||||||
|
text << value;
|
||||||
|
|
||||||
|
width = be_plain_font->StringWidth(text.String());
|
||||||
|
offset.x = -(f_secrect.Width()/2.0 -width/2.0) -1;
|
||||||
|
drawpt = f_secrect.LeftBottom() -offset;
|
||||||
|
|
||||||
FillRect(f_secrect, B_SOLID_LOW);
|
FillRect(f_secrect, B_SOLID_LOW);
|
||||||
DrawString(text.String(), drawpt);
|
DrawString(text.String(), drawpt);
|
||||||
}
|
}
|
||||||
|
|
||||||
//draw AM/PM
|
//draw AM/PM
|
||||||
if (updaterect.Contains(f_aprect))
|
if (updaterect.Contains(f_aprect)) {
|
||||||
{
|
|
||||||
text = "";
|
text = "";
|
||||||
if (f_isam)
|
if (f_isam)
|
||||||
text << "AM";
|
text << "AM";
|
||||||
@@ -276,10 +293,10 @@ TTimeEdit::Draw(BRect updaterect)
|
|||||||
text << "PM";
|
text << "PM";
|
||||||
|
|
||||||
width = be_plain_font->StringWidth(text.String());
|
width = be_plain_font->StringWidth(text.String());
|
||||||
offset.x = -(f_aprect.Width()/2.0 -width/2.0);
|
offset.x = -(f_aprect.Width()/2.0 -width/2.0) -1;
|
||||||
drawpt = f_aprect.LeftBottom() -offset;
|
drawpt = f_aprect.LeftBottom() -offset;
|
||||||
|
|
||||||
if (f_focus == FOCUS_AMPM)
|
if (f_focus == FOCUS_AMPM && IsFocus())
|
||||||
SetLowColor(dark);
|
SetLowColor(dark);
|
||||||
else
|
else
|
||||||
SetLowColor(ViewColor());
|
SetLowColor(ViewColor());
|
||||||
@@ -289,116 +306,167 @@ TTimeEdit::Draw(BRect updaterect)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TTimeEdit::MouseDown(BPoint where)
|
TTimeEdit::MouseDown(BPoint where)
|
||||||
{
|
{
|
||||||
TDateTimeEdit::MouseDown(where);
|
TDateTimeEdit::MouseDown(where);
|
||||||
|
|
||||||
if (f_hourrect.Contains(where))
|
if (f_hourrect.Contains(where)) {
|
||||||
{
|
|
||||||
f_focus = FOCUS_HOUR;
|
f_focus = FOCUS_HOUR;
|
||||||
}
|
f_holdvalue = f_hour;
|
||||||
else
|
} else if (f_minrect.Contains(where)) {
|
||||||
if (f_minrect.Contains(where))
|
|
||||||
{
|
|
||||||
f_focus = FOCUS_MINUTE;
|
f_focus = FOCUS_MINUTE;
|
||||||
}
|
f_holdvalue = f_minute;
|
||||||
else
|
} else if (f_secrect.Contains(where)) {
|
||||||
if (f_secrect.Contains(where))
|
|
||||||
{
|
|
||||||
f_focus = FOCUS_SECOND;
|
f_focus = FOCUS_SECOND;
|
||||||
}
|
f_holdvalue = f_second;
|
||||||
else
|
} else if (f_aprect.Contains(where)) {
|
||||||
if (f_aprect.Contains(where))
|
|
||||||
{
|
|
||||||
f_focus = FOCUS_AMPM;
|
f_focus = FOCUS_AMPM;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
f_focus = FOCUS_NONE;
|
|
||||||
|
|
||||||
Draw(Bounds());
|
Draw(Bounds());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TTimeEdit::SetFocus(bool forward)
|
||||||
|
{
|
||||||
|
switch(f_focus) {
|
||||||
|
case FOCUS_HOUR:
|
||||||
|
(forward)?f_focus = FOCUS_MINUTE: f_focus = FOCUS_AMPM;
|
||||||
|
break;
|
||||||
|
case FOCUS_MINUTE:
|
||||||
|
(forward)?f_focus = FOCUS_SECOND: f_focus = FOCUS_HOUR;
|
||||||
|
break;
|
||||||
|
case FOCUS_SECOND:
|
||||||
|
(forward)?f_focus = FOCUS_AMPM: f_focus = FOCUS_MINUTE;
|
||||||
|
break;
|
||||||
|
case FOCUS_AMPM:
|
||||||
|
(forward)?f_focus = FOCUS_HOUR: f_focus = FOCUS_SECOND;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TTimeEdit::UpdateFocus()
|
||||||
|
{
|
||||||
|
switch(f_focus) {
|
||||||
|
case FOCUS_HOUR:
|
||||||
|
f_hour = f_holdvalue;
|
||||||
|
Draw(f_hourrect);
|
||||||
|
break;
|
||||||
|
case FOCUS_MINUTE:
|
||||||
|
f_minute = f_holdvalue;
|
||||||
|
Draw(f_minrect);
|
||||||
|
break;
|
||||||
|
case FOCUS_SECOND:
|
||||||
|
f_second = f_holdvalue;
|
||||||
|
Draw(f_secrect);
|
||||||
|
break;
|
||||||
|
case FOCUS_AMPM:
|
||||||
|
f_isam = !f_isam;
|
||||||
|
Draw(f_aprect);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TTimeEdit::KeyDown(const char *bytes, int32 numbytes)
|
||||||
|
{
|
||||||
|
switch(bytes[0]) {
|
||||||
|
case B_LEFT_ARROW:
|
||||||
|
SetFocus(false);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case B_RIGHT_ARROW:
|
||||||
|
SetFocus(true);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case B_UP_ARROW:
|
||||||
|
UpPress();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case B_DOWN_ARROW:
|
||||||
|
DownPress();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
BView::KeyDown(bytes, numbytes);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TTimeEdit::UpPress()
|
TTimeEdit::UpPress()
|
||||||
{
|
{
|
||||||
switch(f_focus)
|
f_holdvalue += 1;
|
||||||
{
|
if (f_focus == FOCUS_AMPM)
|
||||||
case FOCUS_HOUR:
|
f_isam = !f_isam;
|
||||||
f_hour += 1;
|
|
||||||
Draw(f_hourrect);
|
UpdateFocus();
|
||||||
break;
|
|
||||||
case FOCUS_MINUTE:
|
// notify of change
|
||||||
f_minute += 1;
|
DispatchMessage();
|
||||||
Draw(f_minrect);
|
|
||||||
break;
|
|
||||||
case FOCUS_SECOND:
|
|
||||||
f_second += 1;
|
|
||||||
Draw(f_secrect);
|
|
||||||
break;
|
|
||||||
case FOCUS_AMPM:
|
|
||||||
f_isam = !f_isam;
|
|
||||||
Draw(f_aprect);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TTimeEdit::DownPress()
|
TTimeEdit::DownPress()
|
||||||
{
|
{
|
||||||
switch(f_focus)
|
f_holdvalue -= 1;
|
||||||
{
|
|
||||||
case FOCUS_HOUR:
|
if (f_focus == FOCUS_AMPM)
|
||||||
f_hour -= 1;
|
f_isam = !f_isam;
|
||||||
Draw(f_hourrect);
|
|
||||||
break;
|
UpdateFocus();
|
||||||
case FOCUS_MINUTE:
|
|
||||||
f_minute -= 1;
|
// notify of change
|
||||||
Draw(f_minrect);
|
DispatchMessage();
|
||||||
break;
|
}
|
||||||
case FOCUS_SECOND:
|
|
||||||
f_second -= 1;
|
|
||||||
Draw(f_secrect);
|
void
|
||||||
break;
|
TTimeEdit::SetTo(int32 hour, int32 minute, int32 second)
|
||||||
case FOCUS_AMPM:
|
{
|
||||||
f_isam = !f_isam;
|
if (f_hour != hour
|
||||||
Draw(f_aprect);
|
||f_minute != minute
|
||||||
break;
|
||f_second != second) {
|
||||||
default:
|
f_hour = hour;
|
||||||
break;
|
f_minute = minute;
|
||||||
|
f_second = second;
|
||||||
|
f_isam = f_hour <= 12;
|
||||||
|
Draw(Bounds());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TTimeEdit::SetTo(int hour, int minute, int second)
|
TTimeEdit::BuildDispatch(BMessage *message)
|
||||||
{
|
{
|
||||||
f_hour = hour;
|
message->AddBool("time", true);
|
||||||
f_minute = minute;
|
message->AddInt32("hour", f_hour);
|
||||||
f_second = second;
|
message->AddInt32("minute", f_minute);
|
||||||
f_isam = f_hour <= 12;
|
message->AddInt32("second", f_second);
|
||||||
Draw(Bounds());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
TTimeEdit::Update(tm *_tm)
|
|
||||||
{
|
|
||||||
if (f_hour != _tm->tm_hour
|
|
||||||
||f_minute != _tm->tm_min
|
|
||||||
||f_second != _tm->tm_sec)
|
|
||||||
{
|
|
||||||
SetTo(_tm->tm_hour, _tm->tm_min, _tm->tm_sec);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*=====> TDateEdit <=====*/
|
/*=====> TDateEdit <=====*/
|
||||||
|
|
||||||
const char *months[] =
|
const char *months[] =
|
||||||
{ "January", "Febuary", "March", "April", "May", "June",
|
{ "January", "Febuary", "March", "April", "May", "June",
|
||||||
"July", "August", "September", "October", "November", "December" };
|
"July", "August", "September", "October", "November", "December"
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
TDateEdit::TDateEdit(BRect frame, const char *name)
|
TDateEdit::TDateEdit(BRect frame, const char *name)
|
||||||
: TDateTimeEdit(frame, name)
|
: TDateTimeEdit(frame, name)
|
||||||
@@ -407,58 +475,52 @@ TDateEdit::TDateEdit(BRect frame, const char *name)
|
|||||||
float width;
|
float width;
|
||||||
|
|
||||||
// year rect
|
// year rect
|
||||||
width = be_plain_font->StringWidth("0000") +8;
|
width = be_plain_font->StringWidth("0000") +6;
|
||||||
bounds.right = Bounds().right -(kArrowAreaWidth +2);
|
bounds.right = Bounds().right -(kArrowAreaWidth +2);
|
||||||
bounds.left = bounds.right -width;
|
bounds.left = bounds.right -width;
|
||||||
f_yearrect = bounds;
|
f_yearrect = bounds;
|
||||||
|
|
||||||
// don't know how to determine system date sep char
|
// don't know how to determine system date sep char
|
||||||
float sep_width = be_plain_font->StringWidth("/") +4;
|
float sep_width = be_plain_font->StringWidth("/") +6;
|
||||||
|
|
||||||
// day rect
|
// day rect
|
||||||
//day is 2 digits 0 usually widest
|
//day is 2 digits 0 usually widest
|
||||||
width = be_plain_font->StringWidth("00") +4;
|
width = be_plain_font->StringWidth("00") +6;
|
||||||
bounds.right = bounds.left -sep_width;
|
bounds.right = bounds.left -sep_width;
|
||||||
bounds.left = bounds.right -width;
|
bounds.left = bounds.right -width;
|
||||||
f_dayrect = bounds;
|
f_dayrect = bounds;
|
||||||
|
|
||||||
//get september width (longest)
|
|
||||||
bounds.right = bounds.left -sep_width;
|
bounds.right = bounds.left -sep_width;
|
||||||
bounds.left = Bounds().left +2;
|
bounds.left = Bounds().left +2;
|
||||||
|
|
||||||
f_monthrect = bounds;
|
f_monthrect = bounds;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TDateEdit::~TDateEdit()
|
TDateEdit::~TDateEdit()
|
||||||
{ }
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TDateEdit::MouseDown(BPoint where)
|
TDateEdit::MouseDown(BPoint where)
|
||||||
{
|
{
|
||||||
TDateTimeEdit::MouseDown(where);
|
TDateTimeEdit::MouseDown(where);
|
||||||
|
|
||||||
if (f_monthrect.Contains(where))
|
if (f_monthrect.Contains(where)) {
|
||||||
{
|
|
||||||
f_focus = FOCUS_MONTH;
|
f_focus = FOCUS_MONTH;
|
||||||
}
|
f_holdvalue = f_month;
|
||||||
else
|
} else if (f_dayrect.Contains(where)) {
|
||||||
if (f_dayrect.Contains(where))
|
|
||||||
{
|
|
||||||
f_focus = FOCUS_DAY;
|
f_focus = FOCUS_DAY;
|
||||||
}
|
f_holdvalue = f_day;
|
||||||
else
|
} else if (f_yearrect.Contains(where)) {
|
||||||
if (f_yearrect.Contains(where))
|
|
||||||
{
|
|
||||||
f_focus = FOCUS_YEAR;
|
f_focus = FOCUS_YEAR;
|
||||||
|
f_holdvalue = f_year;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
f_focus = FOCUS_NONE;
|
|
||||||
|
|
||||||
Draw(Bounds());
|
Draw(Bounds());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TDateEdit::Draw(BRect updaterect)
|
TDateEdit::Draw(BRect updaterect)
|
||||||
{
|
{
|
||||||
@@ -466,11 +528,11 @@ TDateEdit::Draw(BRect updaterect)
|
|||||||
|
|
||||||
SetHighColor(0, 0, 0, 255);
|
SetHighColor(0, 0, 0, 255);
|
||||||
|
|
||||||
BRect bounds(Bounds());
|
|
||||||
BString text;
|
BString text;
|
||||||
BPoint drawpt;
|
BPoint drawpt;
|
||||||
BPoint offset(0, f_monthrect.Height()/2.0 -6);
|
BPoint offset(0, f_monthrect.Height()/2.0 -6);
|
||||||
|
int value;
|
||||||
|
|
||||||
// seperator
|
// seperator
|
||||||
BString septext("/");
|
BString septext("/");
|
||||||
|
|
||||||
@@ -478,130 +540,219 @@ TDateEdit::Draw(BRect updaterect)
|
|||||||
rgb_color dark = tint_color(ViewColor(), B_DARKEN_1_TINT);
|
rgb_color dark = tint_color(ViewColor(), B_DARKEN_1_TINT);
|
||||||
|
|
||||||
//draw month
|
//draw month
|
||||||
if (updaterect.Contains(f_monthrect))
|
if (updaterect.Contains(f_monthrect)) {
|
||||||
{
|
if (f_focus == FOCUS_MONTH && IsFocus()) {
|
||||||
text << months[f_month];
|
SetLowColor(dark);
|
||||||
|
value = f_holdvalue;
|
||||||
|
} else {
|
||||||
|
SetLowColor(ViewColor());
|
||||||
|
value = f_month;
|
||||||
|
}
|
||||||
|
|
||||||
|
text << months[value];
|
||||||
width = be_plain_font->StringWidth(text.String());
|
width = be_plain_font->StringWidth(text.String());
|
||||||
offset.x = width +4;
|
offset.x = width +3;
|
||||||
drawpt = f_monthrect.RightBottom() -offset;
|
drawpt = f_monthrect.RightBottom() -offset;
|
||||||
|
|
||||||
if (f_focus == FOCUS_MONTH)
|
|
||||||
SetLowColor(dark);
|
|
||||||
else
|
|
||||||
SetLowColor(ViewColor());
|
|
||||||
|
|
||||||
FillRect(f_monthrect, B_SOLID_LOW);
|
FillRect(f_monthrect, B_SOLID_LOW);
|
||||||
DrawString(text.String(), drawpt);
|
DrawString(text.String(), drawpt);
|
||||||
|
|
||||||
offset.x = -2;
|
offset.x = -3;
|
||||||
SetLowColor(ViewColor());
|
SetLowColor(ViewColor());
|
||||||
DrawString(septext.String(), f_monthrect.RightBottom() -offset);
|
DrawString(septext.String(), f_monthrect.RightBottom() -offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
//draw day
|
//draw day
|
||||||
if (updaterect.Contains(f_dayrect))
|
if (updaterect.Contains(f_dayrect)) {
|
||||||
{
|
if (f_focus == FOCUS_DAY && IsFocus()) {
|
||||||
|
SetLowColor(dark);
|
||||||
|
value = f_holdvalue;
|
||||||
|
} else {
|
||||||
|
SetLowColor(ViewColor());
|
||||||
|
value = f_day;
|
||||||
|
}
|
||||||
|
|
||||||
text = "";
|
text = "";
|
||||||
text << f_day;
|
text << value;
|
||||||
width = be_plain_font->StringWidth(text.String());
|
width = be_plain_font->StringWidth(text.String());
|
||||||
offset.x = -(f_dayrect.Width()/2.0 -width/2.0);
|
offset.x = -(f_dayrect.Width()/2.0 -width/2.0) -1;
|
||||||
|
|
||||||
drawpt = f_dayrect.LeftBottom() -offset;
|
drawpt = f_dayrect.LeftBottom() -offset;
|
||||||
if (f_focus == FOCUS_DAY)
|
|
||||||
SetLowColor(dark);
|
|
||||||
else
|
|
||||||
SetLowColor(ViewColor());
|
|
||||||
|
|
||||||
FillRect(f_dayrect, B_SOLID_LOW);
|
FillRect(f_dayrect, B_SOLID_LOW);
|
||||||
DrawString(text.String(), drawpt);
|
DrawString(text.String(), drawpt);
|
||||||
|
|
||||||
offset.x = -2;
|
offset.x = -3;
|
||||||
SetLowColor(ViewColor());
|
SetLowColor(ViewColor());
|
||||||
DrawString(septext.String(), f_dayrect.RightBottom() -offset);
|
DrawString(septext.String(), f_dayrect.RightBottom() -offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
//draw year
|
//draw year
|
||||||
if (updaterect.Contains(f_yearrect))
|
if (updaterect.Contains(f_yearrect)) {
|
||||||
{
|
if (f_focus == FOCUS_YEAR && IsFocus()) {
|
||||||
|
SetLowColor(dark);
|
||||||
|
value = f_holdvalue;
|
||||||
|
} else {
|
||||||
|
SetLowColor(ViewColor());
|
||||||
|
value = f_year;
|
||||||
|
}
|
||||||
|
|
||||||
text = "";
|
text = "";
|
||||||
text << f_year +1900;
|
text << value +1900;
|
||||||
width = be_plain_font->StringWidth(text.String());
|
width = be_plain_font->StringWidth(text.String());
|
||||||
offset.x = -(f_yearrect.Width()/2.0 -width/2.0);
|
offset.x = -(f_yearrect.Width()/2.0 -width/2.0);
|
||||||
drawpt = f_yearrect.LeftBottom() -offset;
|
drawpt = f_yearrect.LeftBottom() -offset;
|
||||||
|
|
||||||
if (f_focus == FOCUS_YEAR)
|
|
||||||
SetLowColor(dark);
|
|
||||||
else
|
|
||||||
SetLowColor(ViewColor());
|
|
||||||
|
|
||||||
FillRect(f_yearrect, B_SOLID_LOW);
|
FillRect(f_yearrect, B_SOLID_LOW);
|
||||||
DrawString(text.String(), drawpt);
|
DrawString(text.String(), drawpt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TDateEdit::UpPress()
|
TDateEdit::SetFocus(bool forward)
|
||||||
{
|
{
|
||||||
switch(f_focus)
|
switch(f_focus) {
|
||||||
{
|
|
||||||
case FOCUS_MONTH:
|
case FOCUS_MONTH:
|
||||||
f_month += 1;
|
(forward)?f_focus = FOCUS_DAY: f_focus = FOCUS_YEAR;
|
||||||
Draw(f_monthrect);
|
|
||||||
break;
|
break;
|
||||||
case FOCUS_DAY:
|
case FOCUS_DAY:
|
||||||
f_day += 1;
|
(forward)?f_focus = FOCUS_YEAR: f_focus = FOCUS_MONTH;
|
||||||
Draw(f_dayrect);
|
|
||||||
break;
|
break;
|
||||||
case FOCUS_YEAR:
|
case FOCUS_YEAR:
|
||||||
f_year += 1;
|
(forward)?f_focus = FOCUS_MONTH: f_focus = FOCUS_DAY;
|
||||||
Draw(f_yearrect);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TDateEdit::UpdateFocus(bool sethold = false)
|
||||||
|
{
|
||||||
|
switch(f_focus) {
|
||||||
|
case FOCUS_MONTH:
|
||||||
|
{
|
||||||
|
if (sethold)
|
||||||
|
f_holdvalue = f_month;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (f_holdvalue> 11)
|
||||||
|
f_holdvalue = 0;
|
||||||
|
else
|
||||||
|
if (f_holdvalue < 0)
|
||||||
|
f_holdvalue = 11;
|
||||||
|
|
||||||
|
f_month = f_holdvalue;
|
||||||
|
}
|
||||||
|
Draw(f_monthrect);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case FOCUS_DAY:
|
||||||
|
{
|
||||||
|
if (sethold)
|
||||||
|
f_holdvalue = f_day;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int daycnt = getDaysInMonth(f_month, f_year);
|
||||||
|
if (f_holdvalue> daycnt)
|
||||||
|
f_holdvalue = 1;
|
||||||
|
else
|
||||||
|
if (f_holdvalue < 0)
|
||||||
|
f_holdvalue = daycnt;
|
||||||
|
f_day = f_holdvalue;
|
||||||
|
}
|
||||||
|
Draw(f_dayrect);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case FOCUS_YEAR:
|
||||||
|
{
|
||||||
|
if (sethold)
|
||||||
|
f_holdvalue = f_year;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (f_holdvalue> YEAR_DELTA)
|
||||||
|
f_holdvalue = 65;
|
||||||
|
else
|
||||||
|
if (f_holdvalue < 65)
|
||||||
|
f_holdvalue = YEAR_DELTA;
|
||||||
|
f_year = f_holdvalue;
|
||||||
|
}
|
||||||
|
Draw(f_yearrect);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TDateEdit::KeyDown(const char *bytes, int32 numbytes)
|
||||||
|
{
|
||||||
|
switch(bytes[0]) {
|
||||||
|
case B_LEFT_ARROW:
|
||||||
|
SetFocus(false);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case B_RIGHT_ARROW:
|
||||||
|
SetFocus(true);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case B_UP_ARROW:
|
||||||
|
UpPress();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case B_DOWN_ARROW:
|
||||||
|
DownPress();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
BView::KeyDown(bytes, numbytes);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TDateEdit::UpPress()
|
||||||
|
{
|
||||||
|
f_holdvalue += 1;
|
||||||
|
UpdateFocus();
|
||||||
|
DispatchMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TDateEdit::DownPress()
|
TDateEdit::DownPress()
|
||||||
{
|
{
|
||||||
switch(f_focus)
|
f_holdvalue -= 1;
|
||||||
{
|
UpdateFocus();
|
||||||
case FOCUS_MONTH:
|
DispatchMessage();
|
||||||
f_month -= 1;
|
|
||||||
Draw(f_monthrect);
|
|
||||||
break;
|
|
||||||
case FOCUS_DAY:
|
|
||||||
f_day -= 1;
|
|
||||||
Draw(f_dayrect);
|
|
||||||
break;
|
|
||||||
case FOCUS_YEAR:
|
|
||||||
f_year -= 1;
|
|
||||||
Draw(f_yearrect);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
TDateEdit::SetTo(int month, int day, int year)
|
|
||||||
{
|
|
||||||
f_month = month;
|
|
||||||
f_day = day;
|
|
||||||
f_year = year;
|
|
||||||
Draw(Bounds());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TDateEdit::Update(tm *_tm)
|
TDateEdit::SetTo(int32 year, int32 month, int32 day)
|
||||||
{
|
{
|
||||||
if (f_month != _tm->tm_mon
|
if (f_month != month
|
||||||
|| f_day != _tm->tm_mday
|
|| f_day != day
|
||||||
|| f_year != _tm->tm_year)
|
|| f_year != year)
|
||||||
{
|
{
|
||||||
f_month = _tm->tm_mon;
|
f_month = month;
|
||||||
f_day = _tm->tm_mday;
|
f_day = day;
|
||||||
f_year = _tm->tm_year;
|
f_year = year;
|
||||||
Draw(Bounds());
|
Draw(Bounds());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TDateEdit::BuildDispatch(BMessage *message)
|
||||||
|
{
|
||||||
|
message->AddBool("time", false);
|
||||||
|
message->AddInt32("month", f_month);
|
||||||
|
message->AddInt32("day", f_day);
|
||||||
|
message->AddInt32("year", f_year);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
#ifndef DATETIME_EDIT_H
|
#ifndef DATETIME_EDIT_H
|
||||||
#define DATETIME_EDIT_H
|
#define DATETIME_EDIT_H
|
||||||
|
|
||||||
#include <View.h>
|
#include <Control.h>
|
||||||
|
#include <Message.h>
|
||||||
|
|
||||||
#define OB_UP_PRESS 'obUP'
|
#define OB_UP_PRESS 'obUP'
|
||||||
#define OB_DOWN_PRESS 'obDN'
|
#define OB_DOWN_PRESS 'obDN'
|
||||||
|
|
||||||
enum FieldFocus
|
enum FieldFocus {
|
||||||
{
|
FOCUS_NONE = 0,
|
||||||
FOCUS_NONE,
|
|
||||||
FOCUS_MONTH,
|
FOCUS_MONTH,
|
||||||
FOCUS_DAY,
|
FOCUS_DAY,
|
||||||
FOCUS_YEAR,
|
FOCUS_YEAR,
|
||||||
@@ -18,45 +18,50 @@ enum FieldFocus
|
|||||||
FOCUS_AMPM
|
FOCUS_AMPM
|
||||||
};
|
};
|
||||||
|
|
||||||
class TDateTimeEdit: public BView
|
class TDateTimeEdit: public BControl {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
TDateTimeEdit(BRect frame, const char *name);
|
TDateTimeEdit(BRect frame, const char *name);
|
||||||
virtual ~TDateTimeEdit();
|
virtual ~TDateTimeEdit();
|
||||||
|
|
||||||
virtual void Draw(BRect updaterect);
|
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
|
virtual void Draw(BRect updaterect);
|
||||||
virtual void MouseDown(BPoint where);
|
virtual void MouseDown(BPoint where);
|
||||||
virtual void MakeFocus(bool focused);
|
virtual void MessageReceived(BMessage *message);
|
||||||
|
|
||||||
virtual void UpPress();
|
virtual void UpPress()=0;
|
||||||
virtual void DownPress();
|
virtual void DownPress()=0;
|
||||||
protected:
|
protected:
|
||||||
|
virtual void DispatchMessage();
|
||||||
|
virtual void BuildDispatch(BMessage *message)=0;
|
||||||
|
|
||||||
virtual void Draw3dFrame(BRect frame, bool inset);
|
virtual void Draw3dFrame(BRect frame, bool inset);
|
||||||
|
|
||||||
BBitmap *f_up;
|
BBitmap *f_up;
|
||||||
BBitmap *f_down;
|
BBitmap *f_down;
|
||||||
BRect f_uprect;
|
BRect f_uprect;
|
||||||
BRect f_downrect;
|
BRect f_downrect;
|
||||||
|
|
||||||
FieldFocus f_focus;
|
FieldFocus f_focus;
|
||||||
|
int f_holdvalue;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TTimeEdit: public TDateTimeEdit
|
class TTimeEdit: public TDateTimeEdit {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
TTimeEdit(BRect frame, const char *name);
|
TTimeEdit(BRect frame, const char *name);
|
||||||
virtual ~TTimeEdit();
|
virtual ~TTimeEdit();
|
||||||
|
|
||||||
virtual void Draw(BRect updaterect);
|
virtual void Draw(BRect updaterect);
|
||||||
virtual void Update(tm *_tm);
|
|
||||||
virtual void MouseDown(BPoint where);
|
virtual void MouseDown(BPoint where);
|
||||||
|
virtual void KeyDown(const char *bytes, int32 numbytes);
|
||||||
virtual void UpPress();
|
virtual void UpPress();
|
||||||
virtual void DownPress();
|
virtual void DownPress();
|
||||||
|
|
||||||
void SetTo(int hour, int minute, int second);
|
virtual void SetTo(int32, int32, int32);
|
||||||
private:
|
private:
|
||||||
|
void BuildDispatch(BMessage *message);
|
||||||
|
void SetFocus(bool forward);
|
||||||
|
void UpdateFocus();
|
||||||
|
|
||||||
BRect f_hourrect;
|
BRect f_hourrect;
|
||||||
BRect f_minrect;
|
BRect f_minrect;
|
||||||
BRect f_secrect;
|
BRect f_secrect;
|
||||||
@@ -68,21 +73,23 @@ class TTimeEdit: public TDateTimeEdit
|
|||||||
bool f_isam;
|
bool f_isam;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TDateEdit: public TDateTimeEdit
|
class TDateEdit: public TDateTimeEdit {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
TDateEdit(BRect frame, const char *name);
|
TDateEdit(BRect frame, const char *name);
|
||||||
virtual ~TDateEdit();
|
virtual ~TDateEdit();
|
||||||
|
|
||||||
virtual void Draw(BRect updaterect);
|
virtual void Draw(BRect updaterect);
|
||||||
virtual void MouseDown(BPoint where);
|
virtual void MouseDown(BPoint where);
|
||||||
virtual void Update(tm *_tm);
|
virtual void KeyDown(const char *bytes, int32 numbytes);
|
||||||
|
|
||||||
virtual void UpPress();
|
virtual void UpPress();
|
||||||
virtual void DownPress();
|
virtual void DownPress();
|
||||||
|
|
||||||
void SetTo(int month, int day, int year);
|
virtual void SetTo(int32, int32, int32);
|
||||||
private:
|
private:
|
||||||
|
void BuildDispatch(BMessage *message);
|
||||||
|
void SetFocus(bool forward);
|
||||||
|
void UpdateFocus(bool = false);
|
||||||
|
|
||||||
BRect f_monthrect;
|
BRect f_monthrect;
|
||||||
BRect f_dayrect;
|
BRect f_dayrect;
|
||||||
BRect f_yearrect;
|
BRect f_yearrect;
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
#include "DateUtils.h"
|
||||||
|
#include "math.h"
|
||||||
|
|
||||||
|
bool
|
||||||
|
isLeapYear(const int year)
|
||||||
|
{
|
||||||
|
if ((year % 400 == 0)||(year % 4 == 0 && year % 100 == 0))
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
getDaysInMonth(const int month, const int year)
|
||||||
|
{
|
||||||
|
if (month == 2 && isLeapYear(year)) {
|
||||||
|
return 29;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const int DaysinMonth[12] =
|
||||||
|
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||||
|
|
||||||
|
return DaysinMonth[month];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
getFirstDay(const int month, const int year)
|
||||||
|
{
|
||||||
|
int l_century = year/100;
|
||||||
|
int l_decade = year%100;
|
||||||
|
int l_month = (month +10)%12;
|
||||||
|
int l_day = 1;
|
||||||
|
|
||||||
|
if (l_month == 1 || l_month == 2) {
|
||||||
|
if (l_decade == 0) {
|
||||||
|
l_decade = 99;
|
||||||
|
l_century -= 1;
|
||||||
|
} else
|
||||||
|
l_decade-= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
float tmp = (l_day +(floor(((13 *l_month) -1)/5))
|
||||||
|
+l_decade +(floor(l_decade /4))
|
||||||
|
+(floor(l_century/4)) -(2 *l_century));
|
||||||
|
int result = static_cast<int>(tmp)%7;
|
||||||
|
|
||||||
|
if (result < 0)
|
||||||
|
result += 7;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef CAL_HELPERS
|
||||||
|
#define CAL_HELPERS
|
||||||
|
|
||||||
|
bool isLeapYear(const int year);
|
||||||
|
int getDaysInMonth(const int month, const int year);
|
||||||
|
int getFirstDay(const int month, const int year);
|
||||||
|
|
||||||
|
#endif //CAL_HELPERS
|
||||||
@@ -2,6 +2,6 @@ SubDir OBOS_TOP src prefs time ;
|
|||||||
|
|
||||||
AddResources Time : Time.rsrc ;
|
AddResources Time : Time.rsrc ;
|
||||||
|
|
||||||
Preference Time : Bitmaps.cpp BaseView.cpp DateTimeEdit.cpp CalendarView.cpp AnalogClock.cpp SettingsView.cpp Time.cpp TimeSettings.cpp TimeView.cpp TimeWindow.cpp ZoneView.cpp ;
|
Preference Time : Bitmaps.cpp BaseView.cpp DateTimeEdit.cpp CalendarView.cpp AnalogClock.cpp SettingsView.cpp Time.cpp TimeSettings.cpp TimeView.cpp TimeWindow.cpp ZoneView.cpp DateUtils.cpp TZDisplay.cpp ;
|
||||||
|
|
||||||
LinkSharedOSLibs Time : be root ;
|
LinkSharedOSLibs Time : be root ;
|
||||||
|
|||||||
@@ -1,32 +1,33 @@
|
|||||||
/*
|
/*
|
||||||
SettingsView.cpp
|
SettingsView.cpp
|
||||||
*/
|
*/
|
||||||
#include <RadioButton.h>
|
|
||||||
#include <StringView.h>
|
|
||||||
#include <View.h>
|
|
||||||
#include <Box.h>
|
|
||||||
#include <String.h>
|
|
||||||
#include <RadioButton.h>
|
|
||||||
#include <AppDefs.h>
|
|
||||||
#include <Handler.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <Path.h>
|
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <FindDirectory.h>
|
#include <FindDirectory.h>
|
||||||
|
#include <Path.h>
|
||||||
|
#include <RadioButton.h>
|
||||||
|
#include <String.h>
|
||||||
|
#include <StringView.h>
|
||||||
|
|
||||||
#include "SettingsView.h"
|
#include "SettingsView.h"
|
||||||
#include "AnalogClock.h"
|
|
||||||
#include "CalendarView.h"
|
|
||||||
#include "TimeMessages.h"
|
#include "TimeMessages.h"
|
||||||
|
|
||||||
TSettingsView::TSettingsView(BRect frame):
|
|
||||||
BView(frame,"Settings", B_FOLLOW_ALL,
|
/*=====> TSettingsView <=====*/
|
||||||
B_WILL_DRAW|B_FRAME_EVENTS|B_NAVIGABLE_JUMP|B_PULSE_NEEDED)
|
|
||||||
|
TSettingsView::TSettingsView(BRect frame)
|
||||||
|
: BView(frame,"Settings", B_FOLLOW_ALL,
|
||||||
|
B_WILL_DRAW|B_FRAME_EVENTS|B_NAVIGABLE_JUMP)
|
||||||
{
|
{
|
||||||
InitView();
|
InitView();
|
||||||
} //SettingsView::SettingsView()
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TSettingsView::~TSettingsView()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TSettingsView::AttachedToWindow()
|
TSettingsView::AttachedToWindow()
|
||||||
{
|
{
|
||||||
@@ -34,24 +35,23 @@ TSettingsView::AttachedToWindow()
|
|||||||
SetViewColor(Parent()->ViewColor());
|
SetViewColor(Parent()->ViewColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TSettingsView::MessageReceived(BMessage *message)
|
TSettingsView::MessageReceived(BMessage *message)
|
||||||
{
|
{
|
||||||
int32 change;
|
int32 change;
|
||||||
switch(message->what)
|
switch(message->what) {
|
||||||
{
|
|
||||||
case B_OBSERVER_NOTICE_CHANGE:
|
case B_OBSERVER_NOTICE_CHANGE:
|
||||||
message->FindInt32(B_OBSERVE_WHAT_CHANGE, &change);
|
message->FindInt32(B_OBSERVE_WHAT_CHANGE, &change);
|
||||||
switch (change)
|
switch(change)
|
||||||
{
|
{
|
||||||
case OB_TIME_UPDATE:
|
case OB_TM_CHANGED:
|
||||||
{
|
|
||||||
UpdateDateTime(message);
|
UpdateDateTime(message);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
BView::MessageReceived(message);
|
BView::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -61,6 +61,7 @@ TSettingsView::MessageReceived(BMessage *message)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TSettingsView::InitView()
|
TSettingsView::InitView()
|
||||||
{
|
{
|
||||||
@@ -116,27 +117,26 @@ TSettingsView::InitView()
|
|||||||
frame.OffsetBy(frame.Width() +9, -1);
|
frame.OffsetBy(frame.Width() +9, -1);
|
||||||
frame.right = bounds.right-2;
|
frame.right = bounds.right-2;
|
||||||
|
|
||||||
f_local = new BRadioButton(frame, "local", "Local time", NULL);
|
f_local = new BRadioButton(frame, "local", "Local time", new BMessage(OB_RTC_CHANGE));
|
||||||
AddChild(f_local);
|
AddChild(f_local);
|
||||||
|
|
||||||
frame.OffsetBy(0, text_height +4);
|
frame.OffsetBy(0, text_height +4);
|
||||||
f_gmt = new BRadioButton(frame, "gmt", "GMT", NULL);
|
f_gmt = new BRadioButton(frame, "gmt", "GMT", new BMessage(OB_RTC_CHANGE));
|
||||||
AddChild(f_gmt);
|
AddChild(f_gmt);
|
||||||
|
|
||||||
AddChild(text);
|
AddChild(text);
|
||||||
AddChild(f_timeedit);
|
AddChild(f_timeedit);
|
||||||
AddChild(f_clock);
|
AddChild(f_clock);
|
||||||
|
|
||||||
f_clock->SetViewColor(200, 20, 200);
|
|
||||||
if (f_islocal)
|
if (f_islocal)
|
||||||
f_local->SetValue(1);
|
f_local->SetValue(1);
|
||||||
else
|
else
|
||||||
f_gmt->SetValue(1);
|
f_gmt->SetValue(1);
|
||||||
|
}
|
||||||
}//SettingsView::buildView()
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TSettingsView::Draw(BRect frame)
|
TSettingsView::Draw(BRect updaterect)
|
||||||
{
|
{
|
||||||
//draw a separator line
|
//draw a separator line
|
||||||
BRect bounds(Bounds());
|
BRect bounds(Bounds());
|
||||||
@@ -154,20 +154,42 @@ TSettingsView::Draw(BRect frame)
|
|||||||
end.x++;
|
end.x++;
|
||||||
AddLine(start, end, light);
|
AddLine(start, end, light);
|
||||||
EndLineArray();
|
EndLineArray();
|
||||||
}//SettingsView::Draw(BRect frame)
|
|
||||||
|
f_timeedit->Draw(bounds);
|
||||||
|
f_dateedit->Draw(bounds);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
TSettingsView::GMTime()
|
||||||
|
{
|
||||||
|
return f_gmt->Value() == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TSettingsView::UpdateDateTime(BMessage *message)
|
TSettingsView::UpdateDateTime(BMessage *message)
|
||||||
{
|
{
|
||||||
struct tm *ltime;
|
int32 month, day, year, hour, minute, second;
|
||||||
message->FindPointer("_tm_", (void **)<ime);
|
|
||||||
f_timeedit->Update(ltime);
|
|
||||||
f_clock->Update(ltime);
|
|
||||||
|
|
||||||
f_dateedit->Update(ltime);
|
if (message->FindInt32("month", &month) == B_OK
|
||||||
f_calendar->Update(ltime);
|
&& message->FindInt32("day", &day) == B_OK
|
||||||
|
&& message->FindInt32("year", &year) == B_OK)
|
||||||
|
{
|
||||||
|
f_dateedit->SetTo(year, month, day);
|
||||||
|
f_calendar->SetTo(year, month, day);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message->FindInt32("hour", &hour) == B_OK
|
||||||
|
&& message->FindInt32("minute", &minute) == B_OK
|
||||||
|
&& message->FindInt32("second", &second) == B_OK)
|
||||||
|
{
|
||||||
|
f_timeedit->SetTo(hour, minute, second);
|
||||||
|
f_clock->SetTo(hour, minute, second);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TSettingsView::ReadFiles()
|
TSettingsView::ReadFiles()
|
||||||
{
|
{
|
||||||
@@ -176,8 +198,7 @@ TSettingsView::ReadFiles()
|
|||||||
// read RTC_time_settings
|
// read RTC_time_settings
|
||||||
|
|
||||||
BPath path;
|
BPath path;
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) {
|
||||||
{
|
|
||||||
return; // NO USER SETTINGS DIRECTORY!!!
|
return; // NO USER SETTINGS DIRECTORY!!!
|
||||||
}
|
}
|
||||||
path.Append("RTC_time_settings");
|
path.Append("RTC_time_settings");
|
||||||
@@ -185,13 +206,11 @@ TSettingsView::ReadFiles()
|
|||||||
BEntry entry(path.Path());
|
BEntry entry(path.Path());
|
||||||
BFile file;
|
BFile file;
|
||||||
|
|
||||||
if (entry.Exists())
|
if (entry.Exists()) {
|
||||||
{
|
|
||||||
//read file
|
//read file
|
||||||
file.SetTo(&entry, B_READ_ONLY);
|
file.SetTo(&entry, B_READ_ONLY);
|
||||||
status_t err = file.InitCheck();
|
status_t err = file.InitCheck();
|
||||||
if (err == B_OK)
|
if (err == B_OK) {
|
||||||
{
|
|
||||||
char buff[6];
|
char buff[6];
|
||||||
file.Read(buff, 6);
|
file.Read(buff, 6);
|
||||||
BString text;
|
BString text;
|
||||||
@@ -200,11 +219,8 @@ TSettingsView::ReadFiles()
|
|||||||
f_islocal = true;
|
f_islocal = true;
|
||||||
else
|
else
|
||||||
f_islocal = false;
|
f_islocal = false;
|
||||||
printf("f_islocal >> (BS)%s, (BF)%s\n", text.String(), buff);
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// create set to local
|
// create set to local
|
||||||
f_islocal = true;
|
f_islocal = true;
|
||||||
file.SetTo(&entry, B_CREATE_FILE|B_READ_WRITE);
|
file.SetTo(&entry, B_CREATE_FILE|B_READ_WRITE);
|
||||||
|
|||||||
@@ -6,36 +6,37 @@
|
|||||||
#ifndef SETTINGS_VIEW_H
|
#ifndef SETTINGS_VIEW_H
|
||||||
#define SETTINGS_VIEW_H
|
#define SETTINGS_VIEW_H
|
||||||
|
|
||||||
#ifndef _VIEW_H
|
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "CalendarView.h"
|
|
||||||
#include "AnalogClock.h"
|
#include "AnalogClock.h"
|
||||||
|
#include "CalendarView.h"
|
||||||
#include "DateTimeEdit.h"
|
#include "DateTimeEdit.h"
|
||||||
|
|
||||||
class TSettingsView:public BView
|
class TSettingsView:public BView {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
TSettingsView(BRect frame);
|
TSettingsView(BRect frame);
|
||||||
|
virtual ~TSettingsView();
|
||||||
|
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
virtual void Draw(BRect frame);
|
virtual void Draw(BRect updaterect);
|
||||||
virtual void MessageReceived(BMessage *message);
|
virtual void MessageReceived(BMessage *message);
|
||||||
|
|
||||||
void ChangeRTCSetting();
|
void ChangeRTCSetting();
|
||||||
|
|
||||||
|
bool GMTime();
|
||||||
private:
|
private:
|
||||||
void InitView();
|
void InitView();
|
||||||
void ReadFiles(); // reads RTC_time_settings
|
void ReadFiles(); // reads RTC_time_settings
|
||||||
void UpdateDateTime(BMessage *message);
|
void UpdateDateTime(BMessage *message);
|
||||||
|
|
||||||
BRect f_temp;
|
BRect f_temp;
|
||||||
BRadioButton *f_local;
|
BRadioButton *f_local;
|
||||||
BRadioButton *f_gmt;
|
BRadioButton *f_gmt;
|
||||||
TDateEdit *f_dateedit;
|
TDateEdit *f_dateedit;
|
||||||
TTimeEdit *f_timeedit;
|
TTimeEdit *f_timeedit;
|
||||||
TCalendarView *f_calendar;
|
TCalendarView *f_calendar;
|
||||||
TAnalogClock *f_clock;
|
TAnalogClock *f_clock;
|
||||||
bool f_islocal; // local or gmt?
|
bool f_islocal; // local or gmt?
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,128 @@
|
|||||||
|
#include<Message.h>
|
||||||
|
#include <String.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "TimeMessages.h"
|
||||||
|
#include "TZDisplay.h"
|
||||||
|
|
||||||
|
|
||||||
|
TTZDisplay::TTZDisplay(BRect frame, const char *name,
|
||||||
|
uint32 resizingmode, uint32 flags,
|
||||||
|
const char *label, const char *text,
|
||||||
|
int32 hour, int32 minute, int32 second)
|
||||||
|
: BView(frame, name, resizingmode, flags)
|
||||||
|
{
|
||||||
|
f_label = new BString(label);
|
||||||
|
f_text = new BString(text);
|
||||||
|
f_time = new BString();
|
||||||
|
|
||||||
|
SetTo(hour, minute, second);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TTZDisplay::~TTZDisplay()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TTZDisplay::AttachedToWindow()
|
||||||
|
{
|
||||||
|
if (Parent())
|
||||||
|
SetViewColor(Parent()->ViewColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TTZDisplay::MessageReceived(BMessage *message)
|
||||||
|
{
|
||||||
|
switch(message->what) {
|
||||||
|
default:
|
||||||
|
BView::MessageReceived(message);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static float
|
||||||
|
fontheight()
|
||||||
|
{
|
||||||
|
font_height finfo;
|
||||||
|
be_plain_font->GetHeight(&finfo);
|
||||||
|
float height = ceil(finfo.descent) +ceil(finfo.ascent) +ceil(finfo.leading);
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TTZDisplay::ResizeToPreferred()
|
||||||
|
{
|
||||||
|
float height = fontheight();
|
||||||
|
ResizeTo(Bounds().Width(), height *2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TTZDisplay::Draw(BRect updaterect)
|
||||||
|
{
|
||||||
|
BRect bounds(Bounds());
|
||||||
|
SetLowColor(ViewColor());
|
||||||
|
FillRect(bounds, B_SOLID_LOW);
|
||||||
|
|
||||||
|
float height = fontheight();
|
||||||
|
|
||||||
|
BPoint drawpt(bounds.left +2, height/2.0 +1);
|
||||||
|
DrawString(f_label->String(), drawpt);
|
||||||
|
|
||||||
|
drawpt.y += fontheight() +2;
|
||||||
|
DrawString(f_text->String(), drawpt);
|
||||||
|
|
||||||
|
drawpt.x = bounds.right -be_plain_font->StringWidth(f_time->String()) +2;
|
||||||
|
DrawString(f_time->String(), drawpt);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TTZDisplay::SetLabel(const char *label)
|
||||||
|
{
|
||||||
|
f_label->SetTo(label);
|
||||||
|
Draw(Bounds());
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TTZDisplay::SetText(const char *text)
|
||||||
|
{
|
||||||
|
f_text->SetTo(text);
|
||||||
|
Draw(Bounds());
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TTZDisplay::SetTo(int32 hour, int32 minute, int32 second)
|
||||||
|
{
|
||||||
|
// format time into f_time
|
||||||
|
if (f_time == NULL)
|
||||||
|
f_time = new BString();
|
||||||
|
else
|
||||||
|
f_time->SetTo("");
|
||||||
|
|
||||||
|
int32 ahour = hour;
|
||||||
|
if (hour> 12)
|
||||||
|
ahour = hour -12;
|
||||||
|
|
||||||
|
if (ahour == 0)
|
||||||
|
ahour = 12;
|
||||||
|
|
||||||
|
char *ap;
|
||||||
|
if (hour> 12)
|
||||||
|
ap = "pm";
|
||||||
|
else
|
||||||
|
ap = "am";
|
||||||
|
|
||||||
|
char *time = f_time->LockBuffer(8);
|
||||||
|
sprintf(time, "%02lu:%02lu %s", ahour, minute, ap);
|
||||||
|
f_time->UnlockBuffer(8);
|
||||||
|
|
||||||
|
Draw(Bounds());
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
#ifndef TTZDISPLAY_H
|
||||||
|
#define TTZDISPLAY_H
|
||||||
|
|
||||||
|
#include <View.h>
|
||||||
|
|
||||||
|
class TTZDisplay: public BView
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TTZDisplay(BRect frame, const char *name, uint32 resizing, uint32 flags,
|
||||||
|
const char *label = B_EMPTY_STRING,
|
||||||
|
const char *name = B_EMPTY_STRING,
|
||||||
|
int32 hour = 0, int32 minute = 0, int32 second = 0);
|
||||||
|
~TTZDisplay();
|
||||||
|
virtual void AttachedToWindow();
|
||||||
|
virtual void MessageReceived(BMessage *message);
|
||||||
|
virtual void ResizeToPreferred();
|
||||||
|
|
||||||
|
virtual void Draw(BRect);
|
||||||
|
|
||||||
|
virtual void SetLabel(const char *label);
|
||||||
|
virtual void SetText(const char *text);
|
||||||
|
virtual void SetTo(int32 hour, int32 minute, int32 second);
|
||||||
|
private:
|
||||||
|
BString *f_label;
|
||||||
|
BString *f_text;
|
||||||
|
BString *f_time;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //TTZDISPLAY_H
|
||||||
@@ -5,13 +5,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
#include <Screen.h>
|
|
||||||
|
|
||||||
#include "Time.h"
|
#include "Time.h"
|
||||||
#include "TimeSettings.h"
|
#include "TimeSettings.h"
|
||||||
#include "TimeMessages.h"
|
#include "TimeMessages.h"
|
||||||
|
|
||||||
#define OBOS_APP_SIGNATURE "application/x-vnd.OpenBeOS-TIME"
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
@@ -23,6 +21,7 @@ int main()
|
|||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TimeApplication::TimeApplication()
|
TimeApplication::TimeApplication()
|
||||||
:BApplication(OBOS_APP_SIGNATURE)
|
:BApplication(OBOS_APP_SIGNATURE)
|
||||||
{
|
{
|
||||||
@@ -30,19 +29,20 @@ TimeApplication::TimeApplication()
|
|||||||
f_window = new TTimeWindow();
|
f_window = new TTimeWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TimeApplication::~TimeApplication()
|
TimeApplication::~TimeApplication()
|
||||||
{
|
{
|
||||||
delete f_settings;
|
delete f_settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TimeApplication::MessageReceived(BMessage *message)
|
TimeApplication::MessageReceived(BMessage *message)
|
||||||
{
|
{
|
||||||
switch(message->what) {
|
switch(message->what) {
|
||||||
case ERROR_DETECTED:
|
case ERROR_DETECTED:
|
||||||
{
|
{
|
||||||
BAlert *errorAlert = new BAlert("Error", "Something has gone wrong!","OK",NULL,NULL,B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_WARNING_ALERT);
|
(new BAlert("Error", "Something has gone wrong!","OK",NULL,NULL,B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_WARNING_ALERT))->Go();
|
||||||
errorAlert->Go();
|
|
||||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -52,18 +52,21 @@ TimeApplication::MessageReceived(BMessage *message)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TimeApplication::ReadyToRun(void)
|
TimeApplication::ReadyToRun(void)
|
||||||
{
|
{
|
||||||
f_window->Show();
|
f_window->Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TimeApplication::AboutRequested(void)
|
TimeApplication::AboutRequested(void)
|
||||||
{
|
{
|
||||||
(new BAlert("about", "...by Andrew Edward McCall\n...Mike Berg too", "Big Deal"))->Go();
|
(new BAlert("about", "...by Andrew Edward McCall\n...Mike Berg too", "Big Deal"))->Go();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TimeApplication::SetWindowCorner(BPoint corner)
|
TimeApplication::SetWindowCorner(BPoint corner)
|
||||||
{
|
{
|
||||||
|
|||||||
+15
-15
@@ -6,22 +6,22 @@
|
|||||||
#include "TimeWindow.h"
|
#include "TimeWindow.h"
|
||||||
#include "TimeSettings.h"
|
#include "TimeSettings.h"
|
||||||
|
|
||||||
class TimeApplication : public BApplication
|
class TimeApplication : public BApplication {
|
||||||
{
|
public:
|
||||||
public:
|
TimeApplication();
|
||||||
TimeApplication();
|
virtual ~TimeApplication();
|
||||||
virtual ~TimeApplication();
|
|
||||||
|
void MessageReceived(BMessage *message);
|
||||||
|
|
||||||
void MessageReceived(BMessage *message);
|
void ReadyToRun(void);
|
||||||
|
void AboutRequested(void);
|
||||||
void ReadyToRun(void);
|
|
||||||
void AboutRequested(void);
|
void SetWindowCorner(BPoint corner);
|
||||||
|
BPoint WindowCorner() const
|
||||||
void SetWindowCorner(BPoint corner);
|
{ return f_settings->WindowCorner(); }
|
||||||
BPoint WindowCorner() const { return f_settings->WindowCorner(); }
|
private:
|
||||||
private:
|
TimeSettings *f_settings;
|
||||||
TimeSettings* f_settings;
|
TTimeWindow *f_window;
|
||||||
TTimeWindow* f_window;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //TIME_H
|
#endif //TIME_H
|
||||||
|
|||||||
Binary file not shown.
@@ -7,23 +7,33 @@
|
|||||||
#ifndef TIME_MESSAGES_H
|
#ifndef TIME_MESSAGES_H
|
||||||
#define TIME_MESSAGES_H
|
#define TIME_MESSAGES_H
|
||||||
|
|
||||||
const uint32 BUTTON_DEFAULTS = 'BTde';
|
#define OBOS_APP_SIGNATURE "application/x-vnd.OpenBeOS-TIME"
|
||||||
const uint32 BUTTON_REVERT = 'BTre';
|
|
||||||
const uint32 SLIDER_REPEAT_RATE = 'SLrr';
|
|
||||||
const uint32 SLIDER_DELAY_RATE = 'SLdr';
|
|
||||||
|
|
||||||
const uint32 ERROR_DETECTED = 'ERor';
|
const uint32 ERROR_DETECTED = 'ERor';
|
||||||
|
|
||||||
//Timezonemessages
|
//Timezonemessages
|
||||||
const uint32 REGION_CHANGED ='REch';
|
const uint32 REGION_CHANGED = 'REch';
|
||||||
const uint32 TIME_ZONE_CHANGED ='TZch';
|
const uint32 TIME_ZONE_CHANGED = 'TZch';
|
||||||
|
|
||||||
//SetButton
|
//SetButton
|
||||||
const uint32 SET_TIME_ZONE ='SEti';
|
const uint32 SET_TIME_ZONE = 'SEti';
|
||||||
|
|
||||||
//local and GMT settings
|
//local and GMT settings
|
||||||
const uint32 RTC_SETTINGS ='RTse';
|
const uint32 RTC_SETTINGS = 'RTse';
|
||||||
|
|
||||||
const uint32 OB_TIME_UPDATE ='obTU';
|
// clock tick message
|
||||||
|
const uint32 OB_TIME_UPDATE ='obTU';
|
||||||
|
|
||||||
|
// clicked on day in claendar
|
||||||
|
const uint32 OB_DAY_CHANGED = 'obDC';
|
||||||
|
|
||||||
|
//notice for clock ticks
|
||||||
|
const uint32 OB_TM_CHANGED = 'obTC';
|
||||||
|
|
||||||
|
//notice for user changes
|
||||||
|
const uint32 OB_USER_CHANGE = 'obUC';
|
||||||
|
|
||||||
|
// local/gmt radiobuttons
|
||||||
|
const uint32 OB_RTC_CHANGE = 'obRC';
|
||||||
|
|
||||||
#endif //TIME_MESSAGES_H
|
#endif //TIME_MESSAGES_H
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
const char TimeSettings::kTimeSettingsFile[] = "Time_settings";
|
const char TimeSettings::kTimeSettingsFile[] = "Time_settings";
|
||||||
|
|
||||||
|
|
||||||
TimeSettings::TimeSettings()
|
TimeSettings::TimeSettings()
|
||||||
{
|
{
|
||||||
BPath path;
|
BPath path;
|
||||||
@@ -29,16 +30,15 @@ TimeSettings::TimeSettings()
|
|||||||
fCorner.x=50;
|
fCorner.x=50;
|
||||||
fCorner.y=50;
|
fCorner.y=50;
|
||||||
};
|
};
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
fCorner.x=50;
|
fCorner.x=50;
|
||||||
fCorner.y=50;
|
fCorner.y=50;
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
be_app->PostMessage(ERROR_DETECTED);
|
be_app->PostMessage(ERROR_DETECTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TimeSettings::~TimeSettings()
|
TimeSettings::~TimeSettings()
|
||||||
{
|
{
|
||||||
BPath path;
|
BPath path;
|
||||||
@@ -56,6 +56,7 @@ TimeSettings::~TimeSettings()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TimeSettings::SetWindowCorner(BPoint corner)
|
TimeSettings::SetWindowCorner(BPoint corner)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,17 +3,16 @@
|
|||||||
|
|
||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
class TimeSettings{
|
class TimeSettings {
|
||||||
public :
|
public :
|
||||||
TimeSettings();
|
TimeSettings();
|
||||||
~TimeSettings();
|
~TimeSettings();
|
||||||
|
|
||||||
BPoint WindowCorner() const { return fCorner; }
|
BPoint WindowCorner() const { return fCorner; }
|
||||||
void SetWindowCorner(BPoint corner);
|
void SetWindowCorner(BPoint corner);
|
||||||
|
private:
|
||||||
private:
|
static const char kTimeSettingsFile[];
|
||||||
static const char kTimeSettingsFile[];
|
BPoint fCorner;
|
||||||
BPoint fCorner;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include "TimeView.h"
|
#include "TimeView.h"
|
||||||
#include "TimeMessages.h"
|
#include "TimeMessages.h"
|
||||||
|
|
||||||
|
|
||||||
TimeView::TimeView(BRect rect)
|
TimeView::TimeView(BRect rect)
|
||||||
: BBox(rect, "time_view",
|
: BBox(rect, "time_view",
|
||||||
B_FOLLOW_ALL, B_FRAME_EVENTS | B_NAVIGABLE_JUMP,
|
B_FOLLOW_ALL, B_FRAME_EVENTS | B_NAVIGABLE_JUMP,
|
||||||
@@ -31,7 +32,7 @@ TimeView::TimeView(BRect rect)
|
|||||||
// Settings Tab...
|
// Settings Tab...
|
||||||
fTab = new BTab();
|
fTab = new BTab();
|
||||||
fView = new BView(BRect(fTabView->Bounds().InsetByCopy(10, 10)),"settings_view",B_FOLLOW_ALL,
|
fView = new BView(BRect(fTabView->Bounds().InsetByCopy(10, 10)),"settings_view",B_FOLLOW_ALL,
|
||||||
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP);
|
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP);
|
||||||
fView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
fView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
fTabView->AddTab(fView,fTab);
|
fTabView->AddTab(fView,fTab);
|
||||||
fTab->SetLabel("Settings");
|
fTab->SetLabel("Settings");
|
||||||
@@ -39,7 +40,7 @@ TimeView::TimeView(BRect rect)
|
|||||||
// Time Zone Tab...
|
// Time Zone Tab...
|
||||||
fTab = new BTab();
|
fTab = new BTab();
|
||||||
fView = new BView(BRect(fTabView->Bounds().InsetByCopy(10, 10)),"time_zone_view",B_FOLLOW_ALL,
|
fView = new BView(BRect(fTabView->Bounds().InsetByCopy(10, 10)),"time_zone_view",B_FOLLOW_ALL,
|
||||||
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP);
|
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP);
|
||||||
fView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
fView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
fTabView->AddTab(fView,fTab);
|
fTabView->AddTab(fView,fTab);
|
||||||
fTab->SetLabel("Time Zone");
|
fTab->SetLabel("Time Zone");
|
||||||
@@ -49,6 +50,7 @@ TimeView::TimeView(BRect rect)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TimeView::Draw(BRect updateFrame)
|
void TimeView::Draw(BRect updateFrame)
|
||||||
{
|
{
|
||||||
inherited::Draw(updateFrame);
|
inherited::Draw(updateFrame);
|
||||||
|
|||||||
@@ -7,17 +7,15 @@
|
|||||||
#ifndef TIME_VIEW_H
|
#ifndef TIME_VIEW_H
|
||||||
#define TIME_VIEW_H
|
#define TIME_VIEW_H
|
||||||
|
|
||||||
|
|
||||||
#include <Box.h>
|
#include <Box.h>
|
||||||
|
|
||||||
class TimeView : public BBox
|
class TimeView : public BBox
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef BBox inherited;
|
typedef BBox inherited;
|
||||||
|
|
||||||
TimeView(BRect frame);
|
TimeView(BRect frame);
|
||||||
virtual void Draw(BRect frame);
|
virtual void Draw(BRect frame);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -8,20 +8,21 @@
|
|||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <Screen.h>
|
#include <Screen.h>
|
||||||
#include <TabView.h>
|
#include <TabView.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "TimeMessages.h"
|
|
||||||
#include "TimeWindow.h"
|
|
||||||
#include "TimeView.h"
|
|
||||||
#include "Time.h"
|
|
||||||
#include "BaseView.h"
|
#include "BaseView.h"
|
||||||
|
#include "Time.h"
|
||||||
|
#include "TimeMessages.h"
|
||||||
|
#include "TimeView.h"
|
||||||
|
#include "TimeWindow.h"
|
||||||
|
|
||||||
#define TIME_WINDOW_RIGHT 361 //332
|
#define TIME_WINDOW_RIGHT 361 //332
|
||||||
#define TIME_WINDOW_BOTTOM 227 //208
|
#define TIME_WINDOW_BOTTOM 227 //208
|
||||||
|
|
||||||
|
|
||||||
TTimeWindow::TTimeWindow()
|
TTimeWindow::TTimeWindow()
|
||||||
: BWindow(BRect(0,0,TIME_WINDOW_RIGHT,TIME_WINDOW_BOTTOM), "Time & Date", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE )
|
: BWindow(BRect(0,0,TIME_WINDOW_RIGHT,TIME_WINDOW_BOTTOM),
|
||||||
|
"Time & Date", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE )
|
||||||
{
|
{
|
||||||
BScreen screen;
|
BScreen screen;
|
||||||
|
|
||||||
@@ -35,42 +36,59 @@ TTimeWindow::TTimeWindow()
|
|||||||
SetPulseRate(500000);
|
SetPulseRate(500000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TTimeWindow::~TTimeWindow()
|
TTimeWindow::~TTimeWindow()
|
||||||
{ /* empty */ }
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TTimeWindow::MessageReceived(BMessage *message)
|
TTimeWindow::MessageReceived(BMessage *message)
|
||||||
{
|
{
|
||||||
switch(message->what) {
|
switch(message->what) {
|
||||||
|
case OB_USER_CHANGE:
|
||||||
|
{
|
||||||
|
bool istime;
|
||||||
|
if (message->FindBool("time", &istime) == B_OK)
|
||||||
|
f_BaseView->ChangeTime(message);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case OB_RTC_CHANGE:
|
||||||
|
{
|
||||||
|
f_BaseView->SetGMTime(f_TimeSettings->GMTime());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case REGION_CHANGED:
|
case REGION_CHANGED:
|
||||||
fTimeZones->ChangeRegion(message);
|
f_TimeZones->ChangeRegion(message);
|
||||||
break;
|
break;
|
||||||
case SET_TIME_ZONE:
|
case SET_TIME_ZONE:
|
||||||
fTimeZones->SetTimeZone();
|
f_TimeZones->SetTimeZone();
|
||||||
break;
|
break;
|
||||||
case TIME_ZONE_CHANGED:
|
case TIME_ZONE_CHANGED:
|
||||||
fTimeZones->NewTimeZone();
|
f_TimeZones->NewTimeZone();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
BWindow::MessageReceived(message);
|
BWindow::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}//TTimeWindow::MessageReceived(BMessage *message)
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
TTimeWindow::QuitRequested()
|
TTimeWindow::QuitRequested()
|
||||||
{
|
{
|
||||||
dynamic_cast<TimeApplication *>(be_app)->SetWindowCorner(BPoint(Frame().left,Frame().top));
|
dynamic_cast<TimeApplication *>(be_app)->SetWindowCorner(BPoint(Frame().left,Frame().top));
|
||||||
|
|
||||||
f_BaseView->StopWatchingAll(fTimeSettings);
|
f_BaseView->StopWatchingAll(f_TimeSettings);
|
||||||
f_BaseView->StopWatchingAll(fTimeZones);
|
f_BaseView->StopWatchingAll(f_TimeZones);
|
||||||
|
|
||||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
|
|
||||||
} //TTimeWindow::QuitRequested()
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TTimeWindow::InitWindow()
|
TTimeWindow::InitWindow()
|
||||||
@@ -88,26 +106,24 @@ TTimeWindow::InitWindow()
|
|||||||
bounds.InsetBy(4, 6);
|
bounds.InsetBy(4, 6);
|
||||||
bounds.bottom -= tabview->TabHeight();
|
bounds.bottom -= tabview->TabHeight();
|
||||||
|
|
||||||
fTimeSettings = new TSettingsView(bounds);
|
f_TimeSettings = new TSettingsView(bounds);
|
||||||
if (f_BaseView->StartWatchingAll(fTimeSettings) != B_OK)
|
if (f_BaseView->StartWatchingAll(f_TimeSettings) != B_OK)
|
||||||
printf("StartWatchingAll(TimeSettings) failed!!!");
|
printf("StartWatchingAll(TimeSettings) failed!!!");
|
||||||
|
|
||||||
fTimeZones = new TZoneView(bounds);
|
f_TimeZones = new TZoneView(bounds);
|
||||||
if (f_BaseView->StartWatchingAll(fTimeZones) != B_OK)
|
if (f_BaseView->StartWatchingAll(f_TimeZones) != B_OK)
|
||||||
printf("TimeZones->StartWatchingAll(TimeZone) failed!!!");
|
printf("TimeZones->StartWatchingAll(TimeZone) failed!!!");
|
||||||
|
|
||||||
|
|
||||||
// add tabs
|
// add tabs
|
||||||
BTab *tab;
|
BTab *tab;
|
||||||
tab = new BTab();
|
tab = new BTab();
|
||||||
tabview->AddTab(fTimeSettings, tab);
|
tabview->AddTab(f_TimeSettings, tab);
|
||||||
tab->SetLabel("Settings");
|
tab->SetLabel("Settings");
|
||||||
|
|
||||||
tab = new BTab();
|
tab = new BTab();
|
||||||
tabview->AddTab(fTimeZones, tab);
|
tabview->AddTab(f_TimeZones, tab);
|
||||||
tab->SetLabel("Time Zone");
|
tab->SetLabel("Time Zone");
|
||||||
|
|
||||||
f_BaseView->AddChild(tabview);
|
f_BaseView->AddChild(tabview);
|
||||||
f_BaseView->Pulse();
|
f_BaseView->Pulse();
|
||||||
|
|
||||||
}//TTimeWindow::BuildViews()
|
}
|
||||||
|
|||||||
@@ -9,22 +9,19 @@
|
|||||||
#include "ZoneView.h"
|
#include "ZoneView.h"
|
||||||
#include "BaseView.h"
|
#include "BaseView.h"
|
||||||
|
|
||||||
class TTimeWindow : public BWindow
|
class TTimeWindow : public BWindow {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
TTimeWindow();
|
TTimeWindow();
|
||||||
~TTimeWindow();
|
~TTimeWindow();
|
||||||
|
|
||||||
bool QuitRequested();
|
bool QuitRequested();
|
||||||
void MessageReceived(BMessage *message);
|
void MessageReceived(BMessage *message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void InitWindow();
|
void InitWindow();
|
||||||
|
|
||||||
private:
|
TTimeBaseView *f_BaseView;
|
||||||
TTimeBaseView *f_BaseView;
|
TSettingsView *f_TimeSettings;
|
||||||
TSettingsView *fTimeSettings;
|
TZoneView *f_TimeZones;
|
||||||
TZoneView *fTimeZones;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+131
-156
@@ -2,13 +2,10 @@
|
|||||||
TZoneView.cpp
|
TZoneView.cpp
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AppDefs.h>
|
|
||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
#include <Directory.h>
|
#include <Directory.h>
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <FindDirectory.h>
|
#include <FindDirectory.h>
|
||||||
#include <Handler.h>
|
|
||||||
#include <ListItem.h>
|
|
||||||
#include <ListView.h>
|
#include <ListView.h>
|
||||||
#include <MenuField.h>
|
#include <MenuField.h>
|
||||||
#include <MenuItem.h>
|
#include <MenuItem.h>
|
||||||
@@ -17,11 +14,9 @@
|
|||||||
#include <PopUpMenu.h>
|
#include <PopUpMenu.h>
|
||||||
#include <ScrollView.h>
|
#include <ScrollView.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <StringView.h>
|
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#include "TimeMessages.h"
|
#include "TimeMessages.h"
|
||||||
#include "ZoneView.h"
|
#include "ZoneView.h"
|
||||||
@@ -45,19 +40,24 @@ TZoneItem::~TZoneItem()
|
|||||||
const char *
|
const char *
|
||||||
TZoneItem::GetZone() const
|
TZoneItem::GetZone() const
|
||||||
{
|
{
|
||||||
return f_zonedata->Path();
|
return f_zonedata->Leaf();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*=====> TZoneView <=====*/
|
/*=====> TZoneView <=====*/
|
||||||
|
|
||||||
TZoneView::TZoneView(BRect frame)
|
TZoneView::TZoneView(BRect frame)
|
||||||
: BView(frame,"",B_FOLLOW_ALL,
|
: BView(frame, "", B_FOLLOW_ALL,
|
||||||
B_WILL_DRAW|B_FRAME_EVENTS|B_NAVIGABLE_JUMP)
|
B_WILL_DRAW|B_FRAME_EVENTS|B_NAVIGABLE_JUMP|B_PULSE_NEEDED)
|
||||||
, f_citylist(NULL)
|
, f_citylist(NULL)
|
||||||
{
|
{
|
||||||
InitView();
|
InitView();
|
||||||
} //TZoneView::TZoneView()
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TZoneView::~TZoneView()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -72,23 +72,19 @@ void
|
|||||||
TZoneView::MessageReceived(BMessage *message)
|
TZoneView::MessageReceived(BMessage *message)
|
||||||
{
|
{
|
||||||
int32 change;
|
int32 change;
|
||||||
switch(message->what)
|
switch(message->what) {
|
||||||
{
|
|
||||||
case B_OBSERVER_NOTICE_CHANGE:
|
case B_OBSERVER_NOTICE_CHANGE:
|
||||||
message->FindInt32(B_OBSERVE_WHAT_CHANGE, &change);
|
message->FindInt32(B_OBSERVE_WHAT_CHANGE, &change);
|
||||||
switch (change)
|
switch(change) {
|
||||||
{
|
case OB_TM_CHANGED:
|
||||||
case OB_TIME_UPDATE:
|
|
||||||
{
|
|
||||||
UpdateDateTime(message);
|
UpdateDateTime(message);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
BView::MessageReceived(message);
|
BView::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BView::MessageReceived(message);
|
BView::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
@@ -96,6 +92,31 @@ TZoneView::MessageReceived(BMessage *message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TZoneView::Draw(BRect updaterect)
|
||||||
|
{
|
||||||
|
f_currentzone->Draw(updaterect);
|
||||||
|
f_timeinzone->Draw(updaterect);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TZoneView::UpdateDateTime(BMessage *message)
|
||||||
|
{
|
||||||
|
int32 hour, minute, second;
|
||||||
|
|
||||||
|
if (message->FindInt32("hour", &hour) == B_OK
|
||||||
|
&& message->FindInt32("minute", &minute) == B_OK
|
||||||
|
&& message->FindInt32("second", &second) == B_OK)
|
||||||
|
{
|
||||||
|
f_currentzone->SetTo(hour, minute, second);
|
||||||
|
|
||||||
|
// do calc to get other zone time
|
||||||
|
f_timeinzone->SetTo(hour, minute, second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TZoneView:: InitView()
|
TZoneView:: InitView()
|
||||||
{
|
{
|
||||||
@@ -115,7 +136,7 @@ TZoneView:: InitView()
|
|||||||
CreateZoneMenu(&widest);
|
CreateZoneMenu(&widest);
|
||||||
|
|
||||||
frame.right = frame.left +widest +25;
|
frame.right = frame.left +widest +25;
|
||||||
frame.bottom = frame.top +text_height;
|
frame.bottom = frame.top +text_height -1;
|
||||||
|
|
||||||
BMenuField *mField;
|
BMenuField *mField;
|
||||||
mField= new BMenuField(frame, "mfield", NULL, f_zonepopup, true);
|
mField= new BMenuField(frame, "mfield", NULL, f_zonepopup, true);
|
||||||
@@ -134,59 +155,36 @@ TZoneView:: InitView()
|
|||||||
frame.InsetBy(3, 5);
|
frame.InsetBy(3, 5);
|
||||||
|
|
||||||
f_citylist = new BListView(frame, "cities", B_SINGLE_SELECTION_LIST,
|
f_citylist = new BListView(frame, "cities", B_SINGLE_SELECTION_LIST,
|
||||||
B_FOLLOW_LEFT|B_FOLLOW_TOP,
|
B_FOLLOW_LEFT|B_FOLLOW_TOP,
|
||||||
B_WILL_DRAW|B_NAVIGABLE|B_FRAME_EVENTS);
|
B_WILL_DRAW|B_NAVIGABLE|B_FRAME_EVENTS);
|
||||||
|
|
||||||
BMessage *citychange = new BMessage(TIME_ZONE_CHANGED);
|
BMessage *citychange = new BMessage(TIME_ZONE_CHANGED);
|
||||||
f_citylist->SetSelectionMessage(citychange);
|
f_citylist->SetSelectionMessage(citychange);
|
||||||
|
|
||||||
BScrollView *scrollList;
|
BScrollView *scrollList;
|
||||||
scrollList = new BScrollView("scroll_list", f_citylist,
|
scrollList = new BScrollView("scroll_list", f_citylist,
|
||||||
B_FOLLOW_LEFT|B_FOLLOW_TOP,
|
B_FOLLOW_LEFT|B_FOLLOW_TOP, 0, false, true);
|
||||||
0, false, true);
|
|
||||||
AddChild(scrollList);
|
AddChild(scrollList);
|
||||||
|
|
||||||
|
|
||||||
// Time displays
|
// Time Displays
|
||||||
BStringView *displaytext;
|
|
||||||
|
|
||||||
BString labels = "Current time zone:";
|
|
||||||
frame.OffsetBy(scrollList->Bounds().Width() +9, 2);
|
|
||||||
frame.bottom = frame.top +text_height;
|
|
||||||
displaytext = new BStringView(frame, "current", labels.String());
|
|
||||||
AddChild(displaytext);
|
|
||||||
|
|
||||||
float oldleft = frame.left;
|
frame.OffsetBy(scrollList->Bounds().Width() +9, 3);
|
||||||
float width = be_plain_font->StringWidth("00:00 PM") +8;
|
frame.bottom = frame.top +text_height *2;
|
||||||
|
frame.right = bounds.right -6;
|
||||||
|
f_currentzone = new TTZDisplay(frame, "current",
|
||||||
|
B_FOLLOW_LEFT|B_FOLLOW_TOP, 0,
|
||||||
|
"Current time zone:", B_EMPTY_STRING);
|
||||||
|
f_currentzone->ResizeToPreferred();
|
||||||
|
|
||||||
frame.OffsetBy(0, text_height +2);
|
frame.OffsetBy(0, (text_height *3) +2);
|
||||||
frame.right = bounds.right -(width +4);
|
f_timeinzone = new TTZDisplay(frame, "timein",
|
||||||
f_curtext = new BStringView(frame, "currenttext", "Current time display");
|
B_FOLLOW_LEFT|B_FOLLOW_TOP, 0,
|
||||||
|
"Time in: ", B_EMPTY_STRING);
|
||||||
frame.right = bounds.right;
|
f_timeinzone->ResizeToPreferred();
|
||||||
frame.left = frame.right -width;
|
|
||||||
|
|
||||||
f_curtime = new BStringView(frame, "currenttime", "cTIME");
|
AddChild(f_currentzone);
|
||||||
f_curtime->SetAlignment(B_ALIGN_RIGHT);
|
AddChild(f_timeinzone);
|
||||||
AddChild(f_curtext);
|
|
||||||
AddChild(f_curtime);
|
|
||||||
|
|
||||||
labels = "Time in:";
|
|
||||||
frame.OffsetTo(oldleft, frame.top +text_height *2);
|
|
||||||
displaytext = new BStringView(frame, "timein", labels.String());
|
|
||||||
AddChild(displaytext);
|
|
||||||
|
|
||||||
frame.OffsetBy(0, text_height +2);
|
|
||||||
frame.right = bounds.right - (width -2);
|
|
||||||
frame.bottom = frame.top +text_height;
|
|
||||||
f_seltext = new BStringView(frame, "selectedtext", "Selected time display");
|
|
||||||
|
|
||||||
frame.right = bounds.right;
|
|
||||||
frame.left = bounds.right -width;
|
|
||||||
f_seltime = new BStringView(frame, "selectedtime", "sTIME");
|
|
||||||
f_seltime->SetAlignment(B_ALIGN_RIGHT);
|
|
||||||
AddChild(f_seltext);
|
|
||||||
AddChild(f_seltime);
|
|
||||||
|
|
||||||
|
|
||||||
// set button
|
// set button
|
||||||
@@ -198,11 +196,12 @@ TZoneView:: InitView()
|
|||||||
f_settimezone->SetEnabled(false);
|
f_settimezone->SetEnabled(false);
|
||||||
AddChild(f_settimezone);
|
AddChild(f_settimezone);
|
||||||
|
|
||||||
|
|
||||||
// update displays
|
// update displays
|
||||||
|
int currentzone = FillZoneList(f_RegionStr.Leaf());
|
||||||
FillZoneList(f_RegionStr.Leaf());
|
f_citylist->Select(currentzone);
|
||||||
UpdateTimeDisplay(OB_CURRENT_TIME);
|
f_citylist->ScrollToSelection();
|
||||||
|
f_citylist->Invalidate();
|
||||||
|
f_currentzone->SetText( ((TZoneItem *)f_citylist->ItemAt(currentzone))->Text() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -213,29 +212,31 @@ TZoneView::CreateZoneMenu(float *widest)
|
|||||||
// return if /etc directory is not found
|
// return if /etc directory is not found
|
||||||
if (!(find_directory(B_BEOS_ETC_DIRECTORY, &path) == B_OK))
|
if (!(find_directory(B_BEOS_ETC_DIRECTORY, &path) == B_OK))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
path.Append("timezones");
|
path.Append("timezones");
|
||||||
|
|
||||||
float width = 0;
|
float width = 0;
|
||||||
bool markitem;
|
bool markitem;
|
||||||
BEntry entry;
|
BEntry entry;
|
||||||
BMenuItem *zoneItem;
|
BMenuItem *zoneItem;
|
||||||
BDirectory dir(path.Path());
|
BDirectory dir(path.Path());
|
||||||
|
|
||||||
dir.Rewind();
|
dir.Rewind();
|
||||||
// walk timezones dir and add entries to menu
|
// walk timezones dir and add entries to menu
|
||||||
BString itemtext;
|
BString itemtext;
|
||||||
while (dir.GetNextEntry(&entry) == B_NO_ERROR)
|
while (dir.GetNextEntry(&entry) == B_NO_ERROR) {
|
||||||
{
|
if (entry.IsDirectory()) {
|
||||||
if (entry.IsDirectory())
|
|
||||||
{
|
|
||||||
path.SetTo(&entry);
|
path.SetTo(&entry);
|
||||||
itemtext = path.Leaf();
|
itemtext = path.Leaf();
|
||||||
if (itemtext.Compare("Etc", 3) == 0)
|
if (itemtext.Compare("Etc", 3) == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// add Ocean to oceans :)
|
// add Ocean to oceans :)
|
||||||
|
if ((itemtext.Compare("Atlantic", 8) == 0)
|
||||||
|
||(itemtext.Compare("Pacific", 7) == 0)
|
||||||
|
||(itemtext.Compare("Indian", 6) == 0))
|
||||||
|
itemtext.Append(" Ocean");
|
||||||
|
|
||||||
markitem = itemtext.Compare(f_RegionStr.Leaf()) == 0;
|
markitem = itemtext.Compare(f_RegionStr.Leaf()) == 0;
|
||||||
itemtext = itemtext.ReplaceAll('_', ' ');
|
itemtext = itemtext.ReplaceAll('_', ' ');
|
||||||
|
|
||||||
@@ -263,7 +264,7 @@ TZoneView::ChangeRegion(BMessage *message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
int
|
||||||
TZoneView::FillZoneList(const char *area)
|
TZoneView::FillZoneList(const char *area)
|
||||||
{
|
{
|
||||||
//clear listview from previous items
|
//clear listview from previous items
|
||||||
@@ -272,92 +273,61 @@ TZoneView::FillZoneList(const char *area)
|
|||||||
//Enter time zones directory. Find subdir with name that matches string stored in area.
|
//Enter time zones directory. Find subdir with name that matches string stored in area.
|
||||||
//Enter subdirectory and count the items. For each item, add a StringItem to f_CityList
|
//Enter subdirectory and count the items. For each item, add a StringItem to f_CityList
|
||||||
//Time zones directory
|
//Time zones directory
|
||||||
BDirectory zoneDir("/boot/beos/etc/timezones/");
|
|
||||||
|
BPath path;
|
||||||
|
// return if /etc directory is not found
|
||||||
|
if (!(find_directory(B_BEOS_ETC_DIRECTORY, &path) == B_OK))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
path.Append("timezones");
|
||||||
|
|
||||||
|
BDirectory zoneDir(path.Path());
|
||||||
BDirectory cityDir;
|
BDirectory cityDir;
|
||||||
BStringItem *city;
|
BStringItem *city;
|
||||||
BString city_name;
|
BString city_name;
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
|
|
||||||
|
int index = 0; // index of current setting
|
||||||
//locate subdirectory:
|
//locate subdirectory:
|
||||||
if ( zoneDir.Contains(area, B_DIRECTORY_NODE) )
|
if ( zoneDir.Contains(area, B_DIRECTORY_NODE)) {
|
||||||
{
|
|
||||||
cityDir.SetTo(&zoneDir, area); //There is a subdir with a name that matches 'area'. That's the one!!
|
cityDir.SetTo(&zoneDir, area); //There is a subdir with a name that matches 'area'. That's the one!!
|
||||||
//iterate over the items in the subdir and fill the listview with TZoneItems:
|
//iterate over the items in the subdir and fill the listview with TZoneItems:
|
||||||
while(cityDir.GetNextRef(&ref) == B_NO_ERROR)
|
while(cityDir.GetNextRef(&ref) == B_NO_ERROR) {
|
||||||
{
|
|
||||||
city_name = ref.name;
|
city_name = ref.name;
|
||||||
city_name.ReplaceAll("__", ", ");
|
city_name.ReplaceAll("__", ", ");
|
||||||
city_name.ReplaceAll("_", " ");
|
city_name.ReplaceAll("_", " ");
|
||||||
city = new TZoneItem(city_name.String(), ref.name);
|
city = new TZoneItem(city_name.String(), ref.name);
|
||||||
f_citylist->AddItem(city);
|
f_citylist->AddItem(city);
|
||||||
|
|
||||||
|
if (strcmp(f_ZoneStr.Leaf(), ref.name) == 0)
|
||||||
|
index = f_citylist->IndexOf(city);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
printf("%d\n", index);
|
||||||
|
return index;
|
||||||
|
|
||||||
void
|
|
||||||
TZoneView::UpdateDateTime(BMessage *message)
|
|
||||||
{
|
|
||||||
struct tm *ltime;
|
|
||||||
if (message->FindPointer("_tm_", (void **)<ime) == B_OK)
|
|
||||||
{
|
|
||||||
if (f_hour != ltime->tm_hour || f_minutes != ltime->tm_min)
|
|
||||||
{
|
|
||||||
f_hour = ltime->tm_hour;
|
|
||||||
f_minutes = ltime->tm_min;
|
|
||||||
Update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
TZoneView::Update()
|
|
||||||
{
|
|
||||||
BString text;
|
|
||||||
if (f_hour -12 < 10)
|
|
||||||
text << "0";
|
|
||||||
text << f_hour-12 << ":";
|
|
||||||
|
|
||||||
if (f_minutes < 10)
|
|
||||||
text << "0";
|
|
||||||
text << f_minutes << " ";
|
|
||||||
|
|
||||||
if (f_hour> 12)
|
|
||||||
text << "PM";
|
|
||||||
else
|
|
||||||
text << "AM";
|
|
||||||
f_curtime->SetText(text.String());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TZoneView::GetCurrentTZ()
|
TZoneView::GetCurrentTZ()
|
||||||
{
|
{
|
||||||
|
|
||||||
BPath path;
|
BPath path;
|
||||||
BEntry tzLink;
|
BEntry tzLink;
|
||||||
|
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK)
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
|
||||||
{
|
|
||||||
path.Append("timezone");
|
path.Append("timezone");
|
||||||
tzLink.SetTo(path.Path(), true);
|
tzLink.SetTo(path.Path(), true);
|
||||||
if (!tzLink.InitCheck()) // link is broken
|
if (!tzLink.InitCheck()) {// link is broken
|
||||||
{
|
|
||||||
// do something like set to a default GMT???
|
// do something like set to a default GMT???
|
||||||
// return;
|
// return;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// set tzlink to default
|
// set tzlink to default
|
||||||
}
|
}
|
||||||
|
|
||||||
// we need something in the current zone
|
// we need something in the current zone
|
||||||
f_ZoneStr.SetTo(&tzLink);
|
f_ZoneStr.SetTo(&tzLink);
|
||||||
|
}
|
||||||
}//TZoneView::getCurrentTz()
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -372,8 +342,12 @@ TZoneView::GetCurrentRegion()
|
|||||||
void
|
void
|
||||||
TZoneView::NewTimeZone()
|
TZoneView::NewTimeZone()
|
||||||
{
|
{
|
||||||
UpdateTimeDisplay(OB_SELECTION_TIME);
|
BString text;
|
||||||
}//TZoneView::newTimeZone()
|
int32 selection = f_citylist->CurrentSelection();
|
||||||
|
text = ((TZoneItem *)f_citylist->ItemAt(selection))->Text();
|
||||||
|
f_timeinzone->SetText(text.String());
|
||||||
|
f_settimezone->SetEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -384,32 +358,33 @@ TZoneView::SetTimeZone()
|
|||||||
replace symlink, "timezone", in B_USER_SETTINGS_DIR with a link to the new timezone
|
replace symlink, "timezone", in B_USER_SETTINGS_DIR with a link to the new timezone
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// get path to current link
|
||||||
|
BPath path;
|
||||||
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
path.Append("timezone");
|
||||||
|
|
||||||
|
// build target from selection
|
||||||
|
BPath target;
|
||||||
|
target.SetTo(f_RegionStr.Path());
|
||||||
|
|
||||||
|
int32 selection = f_citylist->CurrentSelection();
|
||||||
|
target.Append(((TZoneItem *)f_citylist->ItemAt(selection))->GetZone());
|
||||||
|
|
||||||
|
// create dir object to create link and remove old
|
||||||
|
BDirectory dir(target.Path());
|
||||||
|
BEntry entry(path.Path());
|
||||||
|
if (entry.Exists())
|
||||||
|
entry.Remove();
|
||||||
|
|
||||||
|
if (dir.CreateSymLink(path.Path(), target.Path(), NULL) != B_OK)
|
||||||
|
printf("timezone not linked\n");
|
||||||
|
|
||||||
|
// disable button
|
||||||
f_settimezone -> SetEnabled(false);
|
f_settimezone -> SetEnabled(false);
|
||||||
} //TZoneView::setTimeZone()
|
|
||||||
|
/*
|
||||||
|
Still doesn't change runtime timezone setting.
|
||||||
void
|
*/
|
||||||
TZoneView::UpdateTimeDisplay(OB_TIME_TARGET target)
|
}
|
||||||
{
|
|
||||||
switch (target)
|
|
||||||
{
|
|
||||||
case OB_CURRENT_TIME:
|
|
||||||
{
|
|
||||||
BString text(f_ZoneStr.Leaf());
|
|
||||||
text.ReplaceAll("_", " ");
|
|
||||||
f_curtext->SetText(text.String());
|
|
||||||
Draw(Bounds());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case OB_SELECTION_TIME:
|
|
||||||
{
|
|
||||||
BString text;
|
|
||||||
int32 selection = f_citylist->CurrentSelection();
|
|
||||||
text = ((TZoneItem *)f_citylist->ItemAt(selection))->Text();
|
|
||||||
f_seltext->SetText(text.String());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+19
-28
@@ -10,14 +10,9 @@
|
|||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <ListItem.h>
|
#include <ListItem.h>
|
||||||
|
|
||||||
enum OB_TIME_TARGET
|
#include "TZDisplay.h"
|
||||||
{
|
|
||||||
OB_CURRENT_TIME,
|
|
||||||
OB_SELECTION_TIME
|
|
||||||
};
|
|
||||||
|
|
||||||
class TZoneItem: public BStringItem
|
class TZoneItem: public BStringItem {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
TZoneItem(const char *text, const char *zonedata);
|
TZoneItem(const char *text, const char *zonedata);
|
||||||
virtual ~TZoneItem();
|
virtual ~TZoneItem();
|
||||||
@@ -27,44 +22,40 @@ class TZoneItem: public BStringItem
|
|||||||
BPath *f_zonedata;
|
BPath *f_zonedata;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TZoneView : public BView
|
class TZoneView : public BView {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
TZoneView(BRect frame);
|
TZoneView(BRect frame);
|
||||||
|
~TZoneView();
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
virtual void MessageReceived(BMessage *message);
|
virtual void MessageReceived(BMessage *message);
|
||||||
|
virtual void Draw(BRect);
|
||||||
|
|
||||||
void ChangeRegion(BMessage *region);
|
void ChangeRegion(BMessage *region);
|
||||||
void SetTimeZone();
|
void SetTimeZone();
|
||||||
void NewTimeZone();
|
void NewTimeZone();
|
||||||
|
protected:
|
||||||
|
virtual void UpdateDateTime(BMessage *message);
|
||||||
private:
|
private:
|
||||||
void InitView();
|
void InitView();
|
||||||
void GetCurrentTZ();
|
void GetCurrentTZ();
|
||||||
void GetCurrentRegion();
|
void GetCurrentRegion();
|
||||||
|
|
||||||
void FillZoneList(const char *area);
|
int FillZoneList(const char *area);
|
||||||
void CreateZoneMenu(float *widest);
|
void CreateZoneMenu(float *widest);
|
||||||
|
|
||||||
void Update();
|
|
||||||
|
|
||||||
void UpdateTimeDisplay(OB_TIME_TARGET target);
|
|
||||||
void UpdateDateTime(BMessage *message);
|
|
||||||
private:
|
private:
|
||||||
BPopUpMenu *f_zonepopup;
|
BPopUpMenu *f_zonepopup;
|
||||||
BListView *f_citylist;
|
BListView *f_citylist;
|
||||||
BButton *f_settimezone;
|
BButton *f_settimezone;
|
||||||
BStringView *f_seltext;
|
TTZDisplay *f_currentzone;
|
||||||
BStringView *f_seltime;
|
TTZDisplay *f_timeinzone;
|
||||||
BStringView *f_curtext;
|
|
||||||
BStringView *f_curtime;
|
|
||||||
private:
|
private:
|
||||||
BString f_CurrentTime;
|
BPath f_ZoneStr;
|
||||||
BPath f_ZoneStr;
|
BPath f_RegionStr;
|
||||||
BPath f_RegionStr;
|
|
||||||
|
|
||||||
int f_hour;
|
int f_hour;
|
||||||
int f_minutes;
|
int f_minutes;
|
||||||
char f_TimeStr[10];
|
char f_TimeStr[10];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user