Many updates by "Michael Berg" <mike@agamemnon.homelinux.net>
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8143 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
825849ba91
commit
1388993922
@ -4,39 +4,37 @@
|
||||
#include <Message.h>
|
||||
#include <View.h>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
class TOffscreen: public BView
|
||||
{
|
||||
class TOffscreen: public BView {
|
||||
public:
|
||||
TOffscreen(BRect frame, char *name);
|
||||
TOffscreen(BRect frame, const char *name);
|
||||
virtual ~TOffscreen();
|
||||
virtual void AttachedToWindow();
|
||||
virtual void DrawX();
|
||||
|
||||
virtual void DrawX();
|
||||
BPoint Position();
|
||||
|
||||
BPoint f_MinutePoints[60];
|
||||
BPoint f_HourPoints[60];
|
||||
short f_Hours;
|
||||
BPoint f_MinutePoints[60];
|
||||
BPoint f_HourPoints[60];
|
||||
short f_Hours;
|
||||
short f_Minutes;
|
||||
short f_Seconds;
|
||||
private:
|
||||
BBitmap *f_bitmap;
|
||||
BBitmap *f_centerbmp;
|
||||
BBitmap *f_capbmp;
|
||||
BPoint f_center;
|
||||
BPoint f_offset;
|
||||
float f_Offset;
|
||||
};
|
||||
|
||||
class TAnalogClock: public BView
|
||||
{
|
||||
class TAnalogClock: public BView {
|
||||
public:
|
||||
TAnalogClock(BRect frame, const char *name, uint32 resizingmode, uint32 flags);
|
||||
virtual ~TAnalogClock();
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
virtual void Draw(BRect updaterect);
|
||||
virtual void MessageReceived(BMessage *);
|
||||
|
||||
void Update(tm *atm);
|
||||
void InitView(BRect frame);
|
||||
void SetTo(int32, int32, int32);
|
||||
private:
|
||||
BPoint f_drawpt;
|
||||
BBitmap *f_bitmap;
|
||||
|
@ -1,30 +1,104 @@
|
||||
#include <Alert.h>
|
||||
#include <OS.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "BaseView.h"
|
||||
|
||||
|
||||
TTimeBaseView::TTimeBaseView(BRect frame, const char *name)
|
||||
: 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()
|
||||
{ }
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TTimeBaseView::Pulse()
|
||||
{
|
||||
if (IsWatched())
|
||||
DispatchMessage();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TTimeBaseView::SetGMTime(bool gmt)
|
||||
{
|
||||
f_gmtime = gmt;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TTimeBaseView::DispatchMessage()
|
||||
{
|
||||
time_t current;
|
||||
struct tm *ltime;
|
||||
|
||||
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->AddPointer("_tm_", ltime);
|
||||
if (IsWatched())
|
||||
{
|
||||
SendNotices(OB_TIME_UPDATE, f_message);
|
||||
}
|
||||
f_message->AddInt32("month", month);
|
||||
f_message->AddInt32("day", day);
|
||||
f_message->AddInt32("year", year);
|
||||
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"
|
||||
|
||||
class TTimeBaseView: public BView
|
||||
{
|
||||
class TTimeBaseView: public BView {
|
||||
public:
|
||||
TTimeBaseView(BRect frmae, const char *name);
|
||||
virtual ~TTimeBaseView();
|
||||
|
||||
virtual void Pulse();
|
||||
|
||||
void ChangeTime(BMessage *message);
|
||||
void SetGMTime(bool);
|
||||
protected:
|
||||
virtual void DispatchMessage();
|
||||
private:
|
||||
BMessage *f_message;
|
||||
bool f_gmtime;
|
||||
};
|
||||
|
||||
#endif //TIMEBASE_H
|
||||
|
@ -1,12 +1,13 @@
|
||||
#include <Screen.h>
|
||||
#include <Bitmap.h>
|
||||
#include <Debug.h>
|
||||
#include <Screen.h>
|
||||
|
||||
#include "Bitmaps.h"
|
||||
|
||||
void
|
||||
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);
|
||||
uint32 withIndex = screen.IndexForColor(with);
|
||||
|
@ -1,7 +1,7 @@
|
||||
void ReplaceTransparentColor(BBitmap *bitmap, rgb_color with);
|
||||
|
||||
const int32 kClockFaceWidth = 85;
|
||||
const int32 kClockFaceHeight = 86;
|
||||
const int32 kClockFaceHeight = 85;
|
||||
const color_space kClockFaceColorSpace = B_CMAP8;
|
||||
|
||||
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,
|
||||
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,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,
|
||||
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,
|
||||
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,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,
|
||||
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,
|
||||
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,
|
||||
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,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,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,
|
||||
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,
|
||||
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,
|
||||
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,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,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,
|
||||
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,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,
|
||||
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,
|
||||
@ -480,6 +480,31 @@ const unsigned char kClockFaceBits [] = {
|
||||
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 kUpArrowHeight = 7;
|
||||
const color_space kUpArrowColorSpace = B_CMAP8;
|
||||
|
@ -1,28 +1,25 @@
|
||||
#include <Debug.h>
|
||||
#include <Message.h>
|
||||
#include <String.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include "CalendarView.h"
|
||||
#include "DateUtils.h"
|
||||
#include "TimeMessages.h"
|
||||
|
||||
|
||||
#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)
|
||||
: 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_isselected(false)
|
||||
{ }
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TDay::~TDay()
|
||||
{ }
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TDay::AttachedToWindow()
|
||||
@ -31,29 +28,45 @@ TDay::AttachedToWindow()
|
||||
SetViewColor(Parent()->ViewColor());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TDay::MouseDown(BPoint where)
|
||||
{
|
||||
if (f_day> 0)
|
||||
{
|
||||
f_isselected = !f_isselected;
|
||||
if (f_day> 0) {
|
||||
// only allow if not currently selected
|
||||
if (Value() == B_CONTROL_ON)
|
||||
return;
|
||||
|
||||
SetValue(B_CONTROL_ON);
|
||||
Invoke();
|
||||
|
||||
//update display
|
||||
Draw(Bounds());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TDay::MakeFocus(bool focused)
|
||||
{
|
||||
if (focused != IsFocus()) {
|
||||
BView::MakeFocus(focused);
|
||||
Draw(Bounds());
|
||||
Flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TDay::Stroke3dFrame(BRect frame, rgb_color light, rgb_color dark, bool inset)
|
||||
{
|
||||
rgb_color color1;
|
||||
rgb_color color2;
|
||||
|
||||
if (inset)
|
||||
{
|
||||
if (inset) {
|
||||
color1 = dark;
|
||||
color2 = light;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
color1 = light;
|
||||
color2 = dark;
|
||||
}
|
||||
@ -81,12 +94,9 @@ TDay::Draw(BRect updaterect)
|
||||
|
||||
BString text;
|
||||
|
||||
if (f_isselected)
|
||||
{
|
||||
if (Value() == 1) {
|
||||
bgcolor = tint_color(ViewColor(), B_DARKEN_2_TINT);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
bgcolor = tint_color(ViewColor(), B_DARKEN_1_TINT);
|
||||
}
|
||||
text << f_day;
|
||||
@ -97,12 +107,8 @@ TDay::Draw(BRect updaterect)
|
||||
SetHighColor(bgcolor);
|
||||
FillRect(bounds);
|
||||
|
||||
if (f_isselected)
|
||||
Stroke3dFrame(bounds, light, dark, true);
|
||||
|
||||
if (f_day> 0)
|
||||
{
|
||||
if (!f_isselected)
|
||||
if (f_day> 0) {
|
||||
if (!(Value() == 1))
|
||||
SetHighColor(0, 0, 0, 255);
|
||||
else
|
||||
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);
|
||||
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
|
||||
TDay::SetTo(BRect frame, int day)
|
||||
{
|
||||
@ -128,19 +161,30 @@ TDay::SetTo(BRect frame, int day)
|
||||
Draw(Bounds());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TDay::SetDay(int day, bool selected = false)
|
||||
TDay::SetTo(int day, bool selected = false)
|
||||
{
|
||||
f_day = day;
|
||||
f_isselected = selected;
|
||||
SetValue(selected);
|
||||
if (Value() == 1) {
|
||||
SetFlags(Flags()|B_NAVIGABLE);
|
||||
} else {
|
||||
SetFlags(Flags() & ~B_NAVIGABLE);
|
||||
}
|
||||
Draw(Bounds());
|
||||
}
|
||||
|
||||
|
||||
/*=====> 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)
|
||||
, f_firstday(0)
|
||||
, f_month(0)
|
||||
, f_day(0)
|
||||
,f_year(0)
|
||||
{
|
||||
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
|
||||
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
|
||||
TCalendarView::Draw(BRect updaterect)
|
||||
@ -170,8 +237,7 @@ TCalendarView::Draw(BRect updaterect)
|
||||
BString day;
|
||||
SetLowColor(ViewColor());
|
||||
SetHighColor(0, 0, 0);
|
||||
for (int i = 0; i < 7; i++)
|
||||
{
|
||||
for (int i = 0; i < 7; i++) {
|
||||
day = days[i];
|
||||
width = be_plain_font->StringWidth(day.String());
|
||||
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
|
||||
TCalendarView::InitView()
|
||||
@ -268,14 +260,10 @@ TCalendarView::InitView()
|
||||
float height = ((bounds.Height() -(text_height +4)) -6)/6;
|
||||
f_dayrect.Set(0.0, text_height +6, width, text_height +6 +height);
|
||||
|
||||
__printrect(f_dayrect);
|
||||
|
||||
BRect dayrect(f_dayrect);
|
||||
TDay *day;
|
||||
for (int row = 0; row < 6; row++)
|
||||
{
|
||||
for (int col = 0; col < 7; col++)
|
||||
{
|
||||
for (int row = 0; row < 6; row++) {
|
||||
for (int col = 0; col < 7; col++) {
|
||||
day = new TDay(dayrect.InsetByCopy(1, 1), 0);
|
||||
AddChild(day);
|
||||
dayrect.OffsetBy(width +1, 0);
|
||||
@ -283,6 +271,8 @@ TCalendarView::InitView()
|
||||
dayrect.OffsetBy(0, height +1);
|
||||
dayrect.OffsetTo(0, dayrect.top);
|
||||
}
|
||||
|
||||
f_cday = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
@ -290,41 +280,69 @@ TCalendarView::InitDates()
|
||||
{
|
||||
TDay *day;
|
||||
|
||||
int label = 0;
|
||||
int32 label = 0;
|
||||
int idx = 0;
|
||||
int first = GetFirstDay(f_month+1, f_year);
|
||||
int daycnt = GetDaysInMonth(f_month, f_year);
|
||||
printf("%d, %d\n", first, daycnt);
|
||||
for (int row = 0; row < 6; row++)
|
||||
{
|
||||
for (int col = 0; col < 7; col++)
|
||||
{
|
||||
f_firstday = getFirstDay(f_month+1, f_year);
|
||||
int daycnt = getDaysInMonth(f_month, f_year);
|
||||
bool cday = false;
|
||||
for (int row = 0; row < 6; row++) {
|
||||
for (int col = 0; col < 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;
|
||||
else
|
||||
label = idx -(first +1);
|
||||
label = idx -(f_firstday +1);
|
||||
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
|
||||
TCalendarView::Update(tm *atm)
|
||||
TCalendarView::SetTo(int32 year, int32 month, int32 day)
|
||||
{
|
||||
if (f_month != atm->tm_mon
|
||||
||f_day != atm->tm_mday
|
||||
||f_year != atm->tm_year)
|
||||
{
|
||||
f_month = atm->tm_mon;
|
||||
f_day = atm->tm_mday;
|
||||
f_wday = atm->tm_wday;
|
||||
f_year = atm->tm_year;
|
||||
if (f_month != month||f_year != year) {
|
||||
f_month = month;
|
||||
f_day = day;
|
||||
f_year = year;
|
||||
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
|
||||
#define CALENDAR_VIEW_H
|
||||
|
||||
#include <Control.h>
|
||||
#include <View.h>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
class TDay: public BView
|
||||
{
|
||||
class TDay: public BControl {
|
||||
public:
|
||||
TDay(BRect frame, int day);
|
||||
virtual ~TDay();
|
||||
virtual void Draw(BRect updaterect);
|
||||
virtual void AttachedToWindow();
|
||||
virtual void MouseDown(BPoint where);
|
||||
virtual void SetValue(int32 value);
|
||||
virtual void MakeFocus(bool focused);
|
||||
|
||||
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:
|
||||
virtual void Stroke3dFrame(BRect frame, rgb_color light, rgb_color dark, bool inset);
|
||||
private:
|
||||
int f_day;
|
||||
bool f_isselected;
|
||||
};
|
||||
|
||||
class TCalendarView: public BView
|
||||
{
|
||||
class TCalendarView: public BView {
|
||||
public:
|
||||
TCalendarView(BRect frame, const char *name, uint32 resizingmode, uint32 flags);
|
||||
virtual ~TCalendarView();
|
||||
virtual void AttachedToWindow();
|
||||
virtual void Draw(BRect bounds);
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
|
||||
void Update(tm *atm);
|
||||
void SetTo(int32, int32, int32);
|
||||
protected:
|
||||
virtual void InitView();
|
||||
virtual void DispatchMessage();
|
||||
private:
|
||||
void InitDates();
|
||||
void ClearDays();
|
||||
void CalcFlags();
|
||||
|
||||
BRect f_dayrect;
|
||||
int f_month;
|
||||
int f_day;
|
||||
int f_year;
|
||||
int f_wday;
|
||||
TDay *f_cday;
|
||||
BRect f_dayrect;
|
||||
int f_firstday;
|
||||
int f_month;
|
||||
int f_day;
|
||||
int f_year;
|
||||
};
|
||||
|
||||
#endif // CALENDAR_VIEW_H
|
||||
|
@ -1,64 +1,69 @@
|
||||
#include <Bitmap.h>
|
||||
#include <String.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include "DateTimeEdit.h"
|
||||
#include "Bitmaps.h"
|
||||
#include "DateTimeEdit.h"
|
||||
#include "DateUtils.h"
|
||||
#include "TimeMessages.h"
|
||||
|
||||
const int32 kArrowAreaWidth = 16;
|
||||
|
||||
// number of years after 1900 to loop should be system setting
|
||||
#define YEAR_DELTA 110
|
||||
|
||||
/*=====> TDateTimeEdit <=====*/
|
||||
|
||||
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->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->SetBits(kDownArrowBits, (kDownArrowWidth) *(kDownArrowHeight), 0, kDownArrowColorSpace);
|
||||
ReplaceTransparentColor(f_down, ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
|
||||
}
|
||||
|
||||
|
||||
TDateTimeEdit::~TDateTimeEdit()
|
||||
{ }
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TDateTimeEdit::AttachedToWindow()
|
||||
{
|
||||
if (Parent())
|
||||
if (Parent()) {
|
||||
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
|
||||
TDateTimeEdit::MouseDown(BPoint where)
|
||||
{
|
||||
MakeFocus(true);
|
||||
if (f_uprect.Contains(where))
|
||||
UpPress();
|
||||
else
|
||||
if (f_downrect.Contains(where))
|
||||
else if (f_downrect.Contains(where))
|
||||
DownPress();
|
||||
}
|
||||
|
||||
void
|
||||
TDateTimeEdit::UpPress()
|
||||
{ }
|
||||
|
||||
void
|
||||
TDateTimeEdit::DownPress()
|
||||
{ }
|
||||
|
||||
void
|
||||
TDateTimeEdit::MakeFocus(bool focused)
|
||||
{
|
||||
if (focused != IsFocus())
|
||||
{
|
||||
BView::MakeFocus(focused);
|
||||
Draw(Bounds());
|
||||
Flush();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TDateTimeEdit::Draw(BRect updaterect)
|
||||
@ -77,15 +82,13 @@ TDateTimeEdit::Draw(BRect updaterect)
|
||||
|
||||
bounds.InsetBy(1, 1);
|
||||
bounds.right -= kArrowAreaWidth;
|
||||
if (IsFocus())
|
||||
{
|
||||
|
||||
if ( (IsFocus() && Window() && Window()->IsActive())) {
|
||||
rgb_color navcolor = keyboard_navigation_color();
|
||||
|
||||
SetHighColor(navcolor);
|
||||
StrokeRect(bounds);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// draw border thickening (erase focus)
|
||||
SetHighColor(darker);
|
||||
SetLowColor(bgcolor);
|
||||
@ -110,23 +113,21 @@ TDateTimeEdit::Draw(BRect updaterect)
|
||||
StrokeLine(bounds.RightTop(), bounds.RightTop());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TDateTimeEdit::Draw3dFrame(BRect frame, bool inset)
|
||||
{
|
||||
rgb_color color1, color2;
|
||||
|
||||
if (inset)
|
||||
{
|
||||
if (inset) {
|
||||
color1 = HighColor();
|
||||
color2 = LowColor();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
color1 = LowColor();
|
||||
color2 = HighColor();
|
||||
}
|
||||
|
||||
BeginLineArray(6);
|
||||
BeginLineArray(4);
|
||||
// left side
|
||||
AddLine(frame.LeftBottom(), frame.LeftTop(), color2);
|
||||
// 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(BRect frame, const char *name)
|
||||
@ -147,13 +158,12 @@ TTimeEdit::TTimeEdit(BRect frame, const char *name)
|
||||
BRect bounds(Bounds().InsetByCopy(1, 2));
|
||||
|
||||
// all areas same width :)
|
||||
float width = be_plain_font->StringWidth("00") +7;
|
||||
float width = be_plain_font->StringWidth("00") +6;
|
||||
|
||||
// AM/PM rect
|
||||
bounds.right = Bounds().right -(kArrowAreaWidth +3);
|
||||
bounds.left = bounds.right -(width +4);
|
||||
bounds.left = bounds.right -(width +5);
|
||||
f_aprect = bounds;
|
||||
|
||||
|
||||
// seconds rect
|
||||
bounds.right = bounds.left;
|
||||
@ -173,8 +183,11 @@ TTimeEdit::TTimeEdit(BRect frame, const char *name)
|
||||
f_hourrect = bounds;
|
||||
}
|
||||
|
||||
|
||||
TTimeEdit::~TTimeEdit()
|
||||
{ }
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TTimeEdit::Draw(BRect updaterect)
|
||||
@ -183,11 +196,11 @@ TTimeEdit::Draw(BRect updaterect)
|
||||
|
||||
SetHighColor(0, 0, 0, 255);
|
||||
|
||||
BRect bounds(Bounds());
|
||||
BString text;
|
||||
BPoint drawpt;
|
||||
BPoint offset(0, f_hourrect.Height()/2.0 -6);
|
||||
|
||||
int value;
|
||||
|
||||
// seperator
|
||||
BString septext(":");
|
||||
|
||||
@ -195,50 +208,52 @@ TTimeEdit::Draw(BRect updaterect)
|
||||
rgb_color dark = tint_color(ViewColor(), B_DARKEN_1_TINT);
|
||||
|
||||
//draw hour
|
||||
if (updaterect.Contains(f_hourrect))
|
||||
{
|
||||
if (f_hour> 12)
|
||||
{
|
||||
if (f_hour < 22) text << "0";
|
||||
text << f_hour -12;
|
||||
if (updaterect.Contains(f_hourrect)) {
|
||||
|
||||
if (f_focus == FOCUS_HOUR && IsFocus()) {
|
||||
SetLowColor(dark);
|
||||
value = f_holdvalue;
|
||||
} else {
|
||||
SetLowColor(ViewColor());
|
||||
value = f_hour;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (f_hour < 10) text << "0";
|
||||
text << f_hour;
|
||||
|
||||
if (value> 12) {
|
||||
if (value < 22) text << "0";
|
||||
text << value -12;
|
||||
} else {
|
||||
if (value < 10) text << "0";
|
||||
text << value;
|
||||
}
|
||||
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;
|
||||
|
||||
if (f_focus == FOCUS_HOUR)
|
||||
SetLowColor(dark);
|
||||
else
|
||||
SetLowColor(ViewColor());
|
||||
|
||||
FillRect(f_hourrect, B_SOLID_LOW);
|
||||
DrawString(text.String(), drawpt);
|
||||
|
||||
offset.x = -3;
|
||||
SetLowColor(ViewColor());
|
||||
DrawString(septext.String(), f_hourrect.RightBottom() -offset);
|
||||
}
|
||||
|
||||
//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 = "";
|
||||
if (f_minute < 10) text << "0";
|
||||
text << f_minute;
|
||||
if (value < 10) text << "0";
|
||||
text << value;
|
||||
|
||||
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;
|
||||
|
||||
if (f_focus == FOCUS_MINUTE)
|
||||
SetLowColor(dark);
|
||||
else
|
||||
SetLowColor(ViewColor());
|
||||
|
||||
FillRect(f_minrect, B_SOLID_LOW);
|
||||
DrawString(text.String(), drawpt);
|
||||
|
||||
@ -248,27 +263,29 @@ TTimeEdit::Draw(BRect updaterect)
|
||||
}
|
||||
|
||||
//draw sec
|
||||
if (updaterect.Contains(f_secrect))
|
||||
{
|
||||
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)
|
||||
if (updaterect.Contains(f_secrect)) {
|
||||
if (f_focus == FOCUS_SECOND && IsFocus()) {
|
||||
SetLowColor(dark);
|
||||
else
|
||||
value = f_holdvalue;
|
||||
} else {
|
||||
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);
|
||||
DrawString(text.String(), drawpt);
|
||||
}
|
||||
|
||||
//draw AM/PM
|
||||
if (updaterect.Contains(f_aprect))
|
||||
{
|
||||
if (updaterect.Contains(f_aprect)) {
|
||||
text = "";
|
||||
if (f_isam)
|
||||
text << "AM";
|
||||
@ -276,10 +293,10 @@ TTimeEdit::Draw(BRect updaterect)
|
||||
text << "PM";
|
||||
|
||||
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;
|
||||
|
||||
if (f_focus == FOCUS_AMPM)
|
||||
if (f_focus == FOCUS_AMPM && IsFocus())
|
||||
SetLowColor(dark);
|
||||
else
|
||||
SetLowColor(ViewColor());
|
||||
@ -289,116 +306,167 @@ TTimeEdit::Draw(BRect updaterect)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TTimeEdit::MouseDown(BPoint where)
|
||||
{
|
||||
TDateTimeEdit::MouseDown(where);
|
||||
|
||||
if (f_hourrect.Contains(where))
|
||||
{
|
||||
if (f_hourrect.Contains(where)) {
|
||||
f_focus = FOCUS_HOUR;
|
||||
}
|
||||
else
|
||||
if (f_minrect.Contains(where))
|
||||
{
|
||||
f_holdvalue = f_hour;
|
||||
} else if (f_minrect.Contains(where)) {
|
||||
f_focus = FOCUS_MINUTE;
|
||||
}
|
||||
else
|
||||
if (f_secrect.Contains(where))
|
||||
{
|
||||
f_holdvalue = f_minute;
|
||||
} else if (f_secrect.Contains(where)) {
|
||||
f_focus = FOCUS_SECOND;
|
||||
}
|
||||
else
|
||||
if (f_aprect.Contains(where))
|
||||
{
|
||||
f_holdvalue = f_second;
|
||||
} else if (f_aprect.Contains(where)) {
|
||||
f_focus = FOCUS_AMPM;
|
||||
}
|
||||
else
|
||||
f_focus = FOCUS_NONE;
|
||||
|
||||
}
|
||||
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
|
||||
TTimeEdit::UpPress()
|
||||
{
|
||||
switch(f_focus)
|
||||
{
|
||||
case FOCUS_HOUR:
|
||||
f_hour += 1;
|
||||
Draw(f_hourrect);
|
||||
break;
|
||||
case FOCUS_MINUTE:
|
||||
f_minute += 1;
|
||||
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;
|
||||
}
|
||||
f_holdvalue += 1;
|
||||
if (f_focus == FOCUS_AMPM)
|
||||
f_isam = !f_isam;
|
||||
|
||||
UpdateFocus();
|
||||
|
||||
// notify of change
|
||||
DispatchMessage();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TTimeEdit::DownPress()
|
||||
{
|
||||
switch(f_focus)
|
||||
{
|
||||
case FOCUS_HOUR:
|
||||
f_hour -= 1;
|
||||
Draw(f_hourrect);
|
||||
break;
|
||||
case FOCUS_MINUTE:
|
||||
f_minute -= 1;
|
||||
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;
|
||||
f_holdvalue -= 1;
|
||||
|
||||
if (f_focus == FOCUS_AMPM)
|
||||
f_isam = !f_isam;
|
||||
|
||||
UpdateFocus();
|
||||
|
||||
// notify of change
|
||||
DispatchMessage();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TTimeEdit::SetTo(int32 hour, int32 minute, int32 second)
|
||||
{
|
||||
if (f_hour != hour
|
||||
||f_minute != minute
|
||||
||f_second != second) {
|
||||
f_hour = hour;
|
||||
f_minute = minute;
|
||||
f_second = second;
|
||||
f_isam = f_hour <= 12;
|
||||
Draw(Bounds());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TTimeEdit::SetTo(int hour, int minute, int second)
|
||||
TTimeEdit::BuildDispatch(BMessage *message)
|
||||
{
|
||||
f_hour = hour;
|
||||
f_minute = minute;
|
||||
f_second = second;
|
||||
f_isam = f_hour <= 12;
|
||||
Draw(Bounds());
|
||||
message->AddBool("time", true);
|
||||
message->AddInt32("hour", f_hour);
|
||||
message->AddInt32("minute", f_minute);
|
||||
message->AddInt32("second", f_second);
|
||||
}
|
||||
|
||||
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 <=====*/
|
||||
|
||||
const char *months[] =
|
||||
{ "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)
|
||||
: TDateTimeEdit(frame, name)
|
||||
@ -407,58 +475,52 @@ TDateEdit::TDateEdit(BRect frame, const char *name)
|
||||
float width;
|
||||
|
||||
// year rect
|
||||
width = be_plain_font->StringWidth("0000") +8;
|
||||
width = be_plain_font->StringWidth("0000") +6;
|
||||
bounds.right = Bounds().right -(kArrowAreaWidth +2);
|
||||
bounds.left = bounds.right -width;
|
||||
f_yearrect = bounds;
|
||||
|
||||
// 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 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.left = bounds.right -width;
|
||||
f_dayrect = bounds;
|
||||
|
||||
//get september width (longest)
|
||||
bounds.right = bounds.left -sep_width;
|
||||
bounds.left = Bounds().left +2;
|
||||
|
||||
f_monthrect = bounds;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
TDateEdit::~TDateEdit()
|
||||
{ }
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TDateEdit::MouseDown(BPoint where)
|
||||
{
|
||||
TDateTimeEdit::MouseDown(where);
|
||||
|
||||
if (f_monthrect.Contains(where))
|
||||
{
|
||||
if (f_monthrect.Contains(where)) {
|
||||
f_focus = FOCUS_MONTH;
|
||||
}
|
||||
else
|
||||
if (f_dayrect.Contains(where))
|
||||
{
|
||||
f_holdvalue = f_month;
|
||||
} else if (f_dayrect.Contains(where)) {
|
||||
f_focus = FOCUS_DAY;
|
||||
}
|
||||
else
|
||||
if (f_yearrect.Contains(where))
|
||||
{
|
||||
f_holdvalue = f_day;
|
||||
} else if (f_yearrect.Contains(where)) {
|
||||
f_focus = FOCUS_YEAR;
|
||||
f_holdvalue = f_year;
|
||||
}
|
||||
else
|
||||
f_focus = FOCUS_NONE;
|
||||
|
||||
Draw(Bounds());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TDateEdit::Draw(BRect updaterect)
|
||||
{
|
||||
@ -466,11 +528,11 @@ TDateEdit::Draw(BRect updaterect)
|
||||
|
||||
SetHighColor(0, 0, 0, 255);
|
||||
|
||||
BRect bounds(Bounds());
|
||||
BString text;
|
||||
BPoint drawpt;
|
||||
BPoint offset(0, f_monthrect.Height()/2.0 -6);
|
||||
|
||||
int value;
|
||||
|
||||
// seperator
|
||||
BString septext("/");
|
||||
|
||||
@ -478,130 +540,219 @@ TDateEdit::Draw(BRect updaterect)
|
||||
rgb_color dark = tint_color(ViewColor(), B_DARKEN_1_TINT);
|
||||
|
||||
//draw month
|
||||
if (updaterect.Contains(f_monthrect))
|
||||
{
|
||||
text << months[f_month];
|
||||
if (updaterect.Contains(f_monthrect)) {
|
||||
if (f_focus == FOCUS_MONTH && IsFocus()) {
|
||||
SetLowColor(dark);
|
||||
value = f_holdvalue;
|
||||
} else {
|
||||
SetLowColor(ViewColor());
|
||||
value = f_month;
|
||||
}
|
||||
|
||||
text << months[value];
|
||||
width = be_plain_font->StringWidth(text.String());
|
||||
offset.x = width +4;
|
||||
offset.x = width +3;
|
||||
drawpt = f_monthrect.RightBottom() -offset;
|
||||
|
||||
if (f_focus == FOCUS_MONTH)
|
||||
SetLowColor(dark);
|
||||
else
|
||||
SetLowColor(ViewColor());
|
||||
|
||||
FillRect(f_monthrect, B_SOLID_LOW);
|
||||
DrawString(text.String(), drawpt);
|
||||
|
||||
offset.x = -2;
|
||||
offset.x = -3;
|
||||
SetLowColor(ViewColor());
|
||||
DrawString(septext.String(), f_monthrect.RightBottom() -offset);
|
||||
}
|
||||
|
||||
//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 << f_day;
|
||||
text << value;
|
||||
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;
|
||||
if (f_focus == FOCUS_DAY)
|
||||
SetLowColor(dark);
|
||||
else
|
||||
SetLowColor(ViewColor());
|
||||
|
||||
FillRect(f_dayrect, B_SOLID_LOW);
|
||||
DrawString(text.String(), drawpt);
|
||||
|
||||
offset.x = -2;
|
||||
offset.x = -3;
|
||||
SetLowColor(ViewColor());
|
||||
DrawString(septext.String(), f_dayrect.RightBottom() -offset);
|
||||
}
|
||||
|
||||
//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 << f_year +1900;
|
||||
text << value +1900;
|
||||
width = be_plain_font->StringWidth(text.String());
|
||||
offset.x = -(f_yearrect.Width()/2.0 -width/2.0);
|
||||
drawpt = f_yearrect.LeftBottom() -offset;
|
||||
|
||||
if (f_focus == FOCUS_YEAR)
|
||||
SetLowColor(dark);
|
||||
else
|
||||
SetLowColor(ViewColor());
|
||||
|
||||
FillRect(f_yearrect, B_SOLID_LOW);
|
||||
DrawString(text.String(), drawpt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TDateEdit::UpPress()
|
||||
TDateEdit::SetFocus(bool forward)
|
||||
{
|
||||
switch(f_focus)
|
||||
{
|
||||
switch(f_focus) {
|
||||
case FOCUS_MONTH:
|
||||
f_month += 1;
|
||||
Draw(f_monthrect);
|
||||
(forward)?f_focus = FOCUS_DAY: f_focus = FOCUS_YEAR;
|
||||
break;
|
||||
case FOCUS_DAY:
|
||||
f_day += 1;
|
||||
Draw(f_dayrect);
|
||||
(forward)?f_focus = FOCUS_YEAR: f_focus = FOCUS_MONTH;
|
||||
break;
|
||||
case FOCUS_YEAR:
|
||||
f_year += 1;
|
||||
Draw(f_yearrect);
|
||||
(forward)?f_focus = FOCUS_MONTH: f_focus = FOCUS_DAY;
|
||||
break;
|
||||
default:
|
||||
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
|
||||
TDateEdit::DownPress()
|
||||
{
|
||||
switch(f_focus)
|
||||
{
|
||||
case FOCUS_MONTH:
|
||||
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;
|
||||
}
|
||||
f_holdvalue -= 1;
|
||||
UpdateFocus();
|
||||
DispatchMessage();
|
||||
}
|
||||
|
||||
void
|
||||
TDateEdit::SetTo(int month, int day, int year)
|
||||
{
|
||||
f_month = month;
|
||||
f_day = day;
|
||||
f_year = year;
|
||||
Draw(Bounds());
|
||||
}
|
||||
|
||||
void
|
||||
TDateEdit::Update(tm *_tm)
|
||||
TDateEdit::SetTo(int32 year, int32 month, int32 day)
|
||||
{
|
||||
if (f_month != _tm->tm_mon
|
||||
|| f_day != _tm->tm_mday
|
||||
|| f_year != _tm->tm_year)
|
||||
if (f_month != month
|
||||
|| f_day != day
|
||||
|| f_year != year)
|
||||
{
|
||||
f_month = _tm->tm_mon;
|
||||
f_day = _tm->tm_mday;
|
||||
f_year = _tm->tm_year;
|
||||
f_month = month;
|
||||
f_day = day;
|
||||
f_year = year;
|
||||
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
|
||||
#define DATETIME_EDIT_H
|
||||
|
||||
#include <View.h>
|
||||
#include <Control.h>
|
||||
#include <Message.h>
|
||||
|
||||
#define OB_UP_PRESS 'obUP'
|
||||
#define OB_DOWN_PRESS 'obDN'
|
||||
|
||||
enum FieldFocus
|
||||
{
|
||||
FOCUS_NONE,
|
||||
enum FieldFocus {
|
||||
FOCUS_NONE = 0,
|
||||
FOCUS_MONTH,
|
||||
FOCUS_DAY,
|
||||
FOCUS_YEAR,
|
||||
@ -18,45 +18,50 @@ enum FieldFocus
|
||||
FOCUS_AMPM
|
||||
};
|
||||
|
||||
class TDateTimeEdit: public BView
|
||||
{
|
||||
class TDateTimeEdit: public BControl {
|
||||
public:
|
||||
TDateTimeEdit(BRect frame, const char *name);
|
||||
virtual ~TDateTimeEdit();
|
||||
|
||||
virtual void Draw(BRect updaterect);
|
||||
virtual void AttachedToWindow();
|
||||
virtual void Draw(BRect updaterect);
|
||||
virtual void MouseDown(BPoint where);
|
||||
virtual void MakeFocus(bool focused);
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
|
||||
virtual void UpPress();
|
||||
virtual void DownPress();
|
||||
virtual void UpPress()=0;
|
||||
virtual void DownPress()=0;
|
||||
protected:
|
||||
virtual void DispatchMessage();
|
||||
virtual void BuildDispatch(BMessage *message)=0;
|
||||
|
||||
virtual void Draw3dFrame(BRect frame, bool inset);
|
||||
|
||||
BBitmap *f_up;
|
||||
BBitmap *f_up;
|
||||
BBitmap *f_down;
|
||||
BRect f_uprect;
|
||||
BRect f_downrect;
|
||||
|
||||
FieldFocus f_focus;
|
||||
int f_holdvalue;
|
||||
};
|
||||
|
||||
class TTimeEdit: public TDateTimeEdit
|
||||
{
|
||||
class TTimeEdit: public TDateTimeEdit {
|
||||
public:
|
||||
TTimeEdit(BRect frame, const char *name);
|
||||
virtual ~TTimeEdit();
|
||||
|
||||
virtual void Draw(BRect updaterect);
|
||||
virtual void Update(tm *_tm);
|
||||
virtual void MouseDown(BPoint where);
|
||||
|
||||
virtual void KeyDown(const char *bytes, int32 numbytes);
|
||||
virtual void UpPress();
|
||||
virtual void DownPress();
|
||||
|
||||
void SetTo(int hour, int minute, int second);
|
||||
virtual void SetTo(int32, int32, int32);
|
||||
private:
|
||||
void BuildDispatch(BMessage *message);
|
||||
void SetFocus(bool forward);
|
||||
void UpdateFocus();
|
||||
|
||||
BRect f_hourrect;
|
||||
BRect f_minrect;
|
||||
BRect f_secrect;
|
||||
@ -68,21 +73,23 @@ class TTimeEdit: public TDateTimeEdit
|
||||
bool f_isam;
|
||||
};
|
||||
|
||||
class TDateEdit: public TDateTimeEdit
|
||||
{
|
||||
class TDateEdit: public TDateTimeEdit {
|
||||
public:
|
||||
TDateEdit(BRect frame, const char *name);
|
||||
virtual ~TDateEdit();
|
||||
|
||||
virtual void Draw(BRect updaterect);
|
||||
virtual void MouseDown(BPoint where);
|
||||
virtual void Update(tm *_tm);
|
||||
|
||||
virtual void KeyDown(const char *bytes, int32 numbytes);
|
||||
virtual void UpPress();
|
||||
virtual void DownPress();
|
||||
|
||||
void SetTo(int month, int day, int year);
|
||||
virtual void SetTo(int32, int32, int32);
|
||||
private:
|
||||
void BuildDispatch(BMessage *message);
|
||||
void SetFocus(bool forward);
|
||||
void UpdateFocus(bool = false);
|
||||
|
||||
BRect f_monthrect;
|
||||
BRect f_dayrect;
|
||||
BRect f_yearrect;
|
||||
|
53
src/prefs/time/DateUtils.cpp
Normal file
53
src/prefs/time/DateUtils.cpp
Normal file
@ -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;
|
||||
}
|
8
src/prefs/time/DateUtils.h
Normal file
8
src/prefs/time/DateUtils.h
Normal file
@ -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 ;
|
||||
|
||||
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 ;
|
||||
|
@ -1,32 +1,33 @@
|
||||
/*
|
||||
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 <File.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <Path.h>
|
||||
#include <RadioButton.h>
|
||||
#include <String.h>
|
||||
#include <StringView.h>
|
||||
|
||||
#include "SettingsView.h"
|
||||
#include "AnalogClock.h"
|
||||
#include "CalendarView.h"
|
||||
#include "TimeMessages.h"
|
||||
|
||||
TSettingsView::TSettingsView(BRect frame):
|
||||
BView(frame,"Settings", B_FOLLOW_ALL,
|
||||
B_WILL_DRAW|B_FRAME_EVENTS|B_NAVIGABLE_JUMP|B_PULSE_NEEDED)
|
||||
|
||||
/*=====> TSettingsView <=====*/
|
||||
|
||||
TSettingsView::TSettingsView(BRect frame)
|
||||
: BView(frame,"Settings", B_FOLLOW_ALL,
|
||||
B_WILL_DRAW|B_FRAME_EVENTS|B_NAVIGABLE_JUMP)
|
||||
{
|
||||
InitView();
|
||||
} //SettingsView::SettingsView()
|
||||
}
|
||||
|
||||
|
||||
TSettingsView::~TSettingsView()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TSettingsView::AttachedToWindow()
|
||||
{
|
||||
@ -34,24 +35,23 @@ TSettingsView::AttachedToWindow()
|
||||
SetViewColor(Parent()->ViewColor());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TSettingsView::MessageReceived(BMessage *message)
|
||||
{
|
||||
int32 change;
|
||||
switch(message->what)
|
||||
{
|
||||
switch(message->what) {
|
||||
case B_OBSERVER_NOTICE_CHANGE:
|
||||
message->FindInt32(B_OBSERVE_WHAT_CHANGE, &change);
|
||||
switch (change)
|
||||
switch(change)
|
||||
{
|
||||
case OB_TIME_UPDATE:
|
||||
{
|
||||
case OB_TM_CHANGED:
|
||||
UpdateDateTime(message);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
BView::MessageReceived(message);
|
||||
break;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -61,6 +61,7 @@ TSettingsView::MessageReceived(BMessage *message)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TSettingsView::InitView()
|
||||
{
|
||||
@ -116,27 +117,26 @@ TSettingsView::InitView()
|
||||
frame.OffsetBy(frame.Width() +9, -1);
|
||||
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);
|
||||
|
||||
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(text);
|
||||
AddChild(f_timeedit);
|
||||
AddChild(f_clock);
|
||||
|
||||
f_clock->SetViewColor(200, 20, 200);
|
||||
if (f_islocal)
|
||||
f_local->SetValue(1);
|
||||
else
|
||||
f_gmt->SetValue(1);
|
||||
|
||||
}//SettingsView::buildView()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TSettingsView::Draw(BRect frame)
|
||||
TSettingsView::Draw(BRect updaterect)
|
||||
{
|
||||
//draw a separator line
|
||||
BRect bounds(Bounds());
|
||||
@ -154,20 +154,42 @@ TSettingsView::Draw(BRect frame)
|
||||
end.x++;
|
||||
AddLine(start, end, light);
|
||||
EndLineArray();
|
||||
}//SettingsView::Draw(BRect frame)
|
||||
|
||||
f_timeedit->Draw(bounds);
|
||||
f_dateedit->Draw(bounds);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TSettingsView::GMTime()
|
||||
{
|
||||
return f_gmt->Value() == 1;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TSettingsView::UpdateDateTime(BMessage *message)
|
||||
{
|
||||
struct tm *ltime;
|
||||
message->FindPointer("_tm_", (void **)<ime);
|
||||
f_timeedit->Update(ltime);
|
||||
f_clock->Update(ltime);
|
||||
int32 month, day, year, hour, minute, second;
|
||||
|
||||
f_dateedit->Update(ltime);
|
||||
f_calendar->Update(ltime);
|
||||
if (message->FindInt32("month", &month) == B_OK
|
||||
&& 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
|
||||
TSettingsView::ReadFiles()
|
||||
{
|
||||
@ -176,8 +198,7 @@ TSettingsView::ReadFiles()
|
||||
// read RTC_time_settings
|
||||
|
||||
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!!!
|
||||
}
|
||||
path.Append("RTC_time_settings");
|
||||
@ -185,13 +206,11 @@ TSettingsView::ReadFiles()
|
||||
BEntry entry(path.Path());
|
||||
BFile file;
|
||||
|
||||
if (entry.Exists())
|
||||
{
|
||||
if (entry.Exists()) {
|
||||
//read file
|
||||
file.SetTo(&entry, B_READ_ONLY);
|
||||
status_t err = file.InitCheck();
|
||||
if (err == B_OK)
|
||||
{
|
||||
if (err == B_OK) {
|
||||
char buff[6];
|
||||
file.Read(buff, 6);
|
||||
BString text;
|
||||
@ -200,11 +219,8 @@ TSettingsView::ReadFiles()
|
||||
f_islocal = true;
|
||||
else
|
||||
f_islocal = false;
|
||||
printf("f_islocal >> (BS)%s, (BF)%s\n", text.String(), buff);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// create set to local
|
||||
f_islocal = true;
|
||||
file.SetTo(&entry, B_CREATE_FILE|B_READ_WRITE);
|
||||
|
@ -6,36 +6,37 @@
|
||||
#ifndef SETTINGS_VIEW_H
|
||||
#define SETTINGS_VIEW_H
|
||||
|
||||
#ifndef _VIEW_H
|
||||
#include <View.h>
|
||||
#endif
|
||||
|
||||
#include "CalendarView.h"
|
||||
#include "AnalogClock.h"
|
||||
#include "CalendarView.h"
|
||||
#include "DateTimeEdit.h"
|
||||
|
||||
class TSettingsView:public BView
|
||||
{
|
||||
class TSettingsView:public BView {
|
||||
public:
|
||||
TSettingsView(BRect frame);
|
||||
virtual ~TSettingsView();
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
virtual void Draw(BRect frame);
|
||||
virtual void Draw(BRect updaterect);
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
|
||||
void ChangeRTCSetting();
|
||||
|
||||
bool GMTime();
|
||||
private:
|
||||
void InitView();
|
||||
void ReadFiles(); // reads RTC_time_settings
|
||||
void UpdateDateTime(BMessage *message);
|
||||
|
||||
BRect f_temp;
|
||||
BRadioButton *f_local;
|
||||
BRadioButton *f_gmt;
|
||||
TDateEdit *f_dateedit;
|
||||
TTimeEdit *f_timeedit;
|
||||
TCalendarView *f_calendar;
|
||||
TAnalogClock *f_clock;
|
||||
bool f_islocal; // local or gmt?
|
||||
BRadioButton *f_local;
|
||||
BRadioButton *f_gmt;
|
||||
TDateEdit *f_dateedit;
|
||||
TTimeEdit *f_timeedit;
|
||||
TCalendarView *f_calendar;
|
||||
TAnalogClock *f_clock;
|
||||
bool f_islocal; // local or gmt?
|
||||
};
|
||||
|
||||
#endif
|
||||
|
128
src/prefs/time/TZDisplay.cpp
Normal file
128
src/prefs/time/TZDisplay.cpp
Normal file
@ -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());
|
||||
}
|
30
src/prefs/time/TZDisplay.h
Normal file
30
src/prefs/time/TZDisplay.h
Normal file
@ -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 <Screen.h>
|
||||
|
||||
#include "Time.h"
|
||||
#include "TimeSettings.h"
|
||||
#include "TimeMessages.h"
|
||||
|
||||
#define OBOS_APP_SIGNATURE "application/x-vnd.OpenBeOS-TIME"
|
||||
|
||||
int main()
|
||||
{
|
||||
@ -23,6 +21,7 @@ int main()
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
TimeApplication::TimeApplication()
|
||||
:BApplication(OBOS_APP_SIGNATURE)
|
||||
{
|
||||
@ -30,19 +29,20 @@ TimeApplication::TimeApplication()
|
||||
f_window = new TTimeWindow();
|
||||
}
|
||||
|
||||
|
||||
TimeApplication::~TimeApplication()
|
||||
{
|
||||
delete f_settings;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TimeApplication::MessageReceived(BMessage *message)
|
||||
{
|
||||
switch(message->what) {
|
||||
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);
|
||||
errorAlert->Go();
|
||||
(new BAlert("Error", "Something has gone wrong!","OK",NULL,NULL,B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_WARNING_ALERT))->Go();
|
||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||
}
|
||||
break;
|
||||
@ -52,18 +52,21 @@ TimeApplication::MessageReceived(BMessage *message)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TimeApplication::ReadyToRun(void)
|
||||
{
|
||||
f_window->Show();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TimeApplication::AboutRequested(void)
|
||||
{
|
||||
(new BAlert("about", "...by Andrew Edward McCall\n...Mike Berg too", "Big Deal"))->Go();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TimeApplication::SetWindowCorner(BPoint corner)
|
||||
{
|
||||
|
@ -6,22 +6,22 @@
|
||||
#include "TimeWindow.h"
|
||||
#include "TimeSettings.h"
|
||||
|
||||
class TimeApplication : public BApplication
|
||||
{
|
||||
public:
|
||||
TimeApplication();
|
||||
virtual ~TimeApplication();
|
||||
class TimeApplication : public BApplication {
|
||||
public:
|
||||
TimeApplication();
|
||||
virtual ~TimeApplication();
|
||||
|
||||
void MessageReceived(BMessage *message);
|
||||
|
||||
void MessageReceived(BMessage *message);
|
||||
|
||||
void ReadyToRun(void);
|
||||
void AboutRequested(void);
|
||||
|
||||
void SetWindowCorner(BPoint corner);
|
||||
BPoint WindowCorner() const { return f_settings->WindowCorner(); }
|
||||
private:
|
||||
TimeSettings* f_settings;
|
||||
TTimeWindow* f_window;
|
||||
void ReadyToRun(void);
|
||||
void AboutRequested(void);
|
||||
|
||||
void SetWindowCorner(BPoint corner);
|
||||
BPoint WindowCorner() const
|
||||
{ return f_settings->WindowCorner(); }
|
||||
private:
|
||||
TimeSettings *f_settings;
|
||||
TTimeWindow *f_window;
|
||||
};
|
||||
|
||||
#endif //TIME_H
|
||||
|
Binary file not shown.
@ -7,23 +7,33 @@
|
||||
#ifndef TIME_MESSAGES_H
|
||||
#define TIME_MESSAGES_H
|
||||
|
||||
const uint32 BUTTON_DEFAULTS = 'BTde';
|
||||
const uint32 BUTTON_REVERT = 'BTre';
|
||||
const uint32 SLIDER_REPEAT_RATE = 'SLrr';
|
||||
const uint32 SLIDER_DELAY_RATE = 'SLdr';
|
||||
#define OBOS_APP_SIGNATURE "application/x-vnd.OpenBeOS-TIME"
|
||||
|
||||
const uint32 ERROR_DETECTED = 'ERor';
|
||||
const uint32 ERROR_DETECTED = 'ERor';
|
||||
|
||||
//Timezonemessages
|
||||
const uint32 REGION_CHANGED ='REch';
|
||||
const uint32 TIME_ZONE_CHANGED ='TZch';
|
||||
const uint32 REGION_CHANGED = 'REch';
|
||||
const uint32 TIME_ZONE_CHANGED = 'TZch';
|
||||
|
||||
//SetButton
|
||||
const uint32 SET_TIME_ZONE ='SEti';
|
||||
const uint32 SET_TIME_ZONE = 'SEti';
|
||||
|
||||
//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
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
const char TimeSettings::kTimeSettingsFile[] = "Time_settings";
|
||||
|
||||
|
||||
TimeSettings::TimeSettings()
|
||||
{
|
||||
BPath path;
|
||||
@ -29,16 +30,15 @@ TimeSettings::TimeSettings()
|
||||
fCorner.x=50;
|
||||
fCorner.y=50;
|
||||
};
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
fCorner.x=50;
|
||||
fCorner.y=50;
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
be_app->PostMessage(ERROR_DETECTED);
|
||||
}
|
||||
|
||||
|
||||
TimeSettings::~TimeSettings()
|
||||
{
|
||||
BPath path;
|
||||
@ -56,6 +56,7 @@ TimeSettings::~TimeSettings()
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TimeSettings::SetWindowCorner(BPoint corner)
|
||||
{
|
||||
|
@ -3,17 +3,16 @@
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
class TimeSettings{
|
||||
public :
|
||||
TimeSettings();
|
||||
~TimeSettings();
|
||||
class TimeSettings {
|
||||
public :
|
||||
TimeSettings();
|
||||
~TimeSettings();
|
||||
|
||||
BPoint WindowCorner() const { return fCorner; }
|
||||
void SetWindowCorner(BPoint corner);
|
||||
|
||||
private:
|
||||
static const char kTimeSettingsFile[];
|
||||
BPoint fCorner;
|
||||
BPoint WindowCorner() const { return fCorner; }
|
||||
void SetWindowCorner(BPoint corner);
|
||||
private:
|
||||
static const char kTimeSettingsFile[];
|
||||
BPoint fCorner;
|
||||
|
||||
};
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "TimeView.h"
|
||||
#include "TimeMessages.h"
|
||||
|
||||
|
||||
TimeView::TimeView(BRect rect)
|
||||
: BBox(rect, "time_view",
|
||||
B_FOLLOW_ALL, B_FRAME_EVENTS | B_NAVIGABLE_JUMP,
|
||||
@ -31,7 +32,7 @@ TimeView::TimeView(BRect rect)
|
||||
// Settings Tab...
|
||||
fTab = new BTab();
|
||||
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));
|
||||
fTabView->AddTab(fView,fTab);
|
||||
fTab->SetLabel("Settings");
|
||||
@ -39,7 +40,7 @@ TimeView::TimeView(BRect rect)
|
||||
// Time Zone Tab...
|
||||
fTab = new BTab();
|
||||
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));
|
||||
fTabView->AddTab(fView,fTab);
|
||||
fTab->SetLabel("Time Zone");
|
||||
@ -49,6 +50,7 @@ TimeView::TimeView(BRect rect)
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TimeView::Draw(BRect updateFrame)
|
||||
{
|
||||
inherited::Draw(updateFrame);
|
||||
|
@ -7,17 +7,15 @@
|
||||
#ifndef TIME_VIEW_H
|
||||
#define TIME_VIEW_H
|
||||
|
||||
|
||||
#include <Box.h>
|
||||
|
||||
class TimeView : public BBox
|
||||
{
|
||||
public:
|
||||
public:
|
||||
typedef BBox inherited;
|
||||
|
||||
TimeView(BRect frame);
|
||||
virtual void Draw(BRect frame);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -8,20 +8,21 @@
|
||||
#include <Message.h>
|
||||
#include <Screen.h>
|
||||
#include <TabView.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "TimeMessages.h"
|
||||
#include "TimeWindow.h"
|
||||
#include "TimeView.h"
|
||||
#include "Time.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_BOTTOM 227 //208
|
||||
|
||||
|
||||
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;
|
||||
|
||||
@ -35,42 +36,59 @@ TTimeWindow::TTimeWindow()
|
||||
SetPulseRate(500000);
|
||||
}
|
||||
|
||||
|
||||
TTimeWindow::~TTimeWindow()
|
||||
{ /* empty */ }
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TTimeWindow::MessageReceived(BMessage *message)
|
||||
{
|
||||
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:
|
||||
fTimeZones->ChangeRegion(message);
|
||||
f_TimeZones->ChangeRegion(message);
|
||||
break;
|
||||
case SET_TIME_ZONE:
|
||||
fTimeZones->SetTimeZone();
|
||||
f_TimeZones->SetTimeZone();
|
||||
break;
|
||||
case TIME_ZONE_CHANGED:
|
||||
fTimeZones->NewTimeZone();
|
||||
f_TimeZones->NewTimeZone();
|
||||
break;
|
||||
default:
|
||||
BWindow::MessageReceived(message);
|
||||
break;
|
||||
}
|
||||
|
||||
}//TTimeWindow::MessageReceived(BMessage *message)
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TTimeWindow::QuitRequested()
|
||||
{
|
||||
dynamic_cast<TimeApplication *>(be_app)->SetWindowCorner(BPoint(Frame().left,Frame().top));
|
||||
|
||||
f_BaseView->StopWatchingAll(fTimeSettings);
|
||||
f_BaseView->StopWatchingAll(fTimeZones);
|
||||
f_BaseView->StopWatchingAll(f_TimeSettings);
|
||||
f_BaseView->StopWatchingAll(f_TimeZones);
|
||||
|
||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||
|
||||
return(true);
|
||||
|
||||
} //TTimeWindow::QuitRequested()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TTimeWindow::InitWindow()
|
||||
@ -88,26 +106,24 @@ TTimeWindow::InitWindow()
|
||||
bounds.InsetBy(4, 6);
|
||||
bounds.bottom -= tabview->TabHeight();
|
||||
|
||||
fTimeSettings = new TSettingsView(bounds);
|
||||
if (f_BaseView->StartWatchingAll(fTimeSettings) != B_OK)
|
||||
f_TimeSettings = new TSettingsView(bounds);
|
||||
if (f_BaseView->StartWatchingAll(f_TimeSettings) != B_OK)
|
||||
printf("StartWatchingAll(TimeSettings) failed!!!");
|
||||
|
||||
fTimeZones = new TZoneView(bounds);
|
||||
if (f_BaseView->StartWatchingAll(fTimeZones) != B_OK)
|
||||
printf("TimeZones->StartWatchingAll(TimeZone) failed!!!");
|
||||
|
||||
|
||||
f_TimeZones = new TZoneView(bounds);
|
||||
if (f_BaseView->StartWatchingAll(f_TimeZones) != B_OK)
|
||||
printf("TimeZones->StartWatchingAll(TimeZone) failed!!!");
|
||||
// add tabs
|
||||
BTab *tab;
|
||||
tab = new BTab();
|
||||
tabview->AddTab(fTimeSettings, tab);
|
||||
tabview->AddTab(f_TimeSettings, tab);
|
||||
tab->SetLabel("Settings");
|
||||
|
||||
tab = new BTab();
|
||||
tabview->AddTab(fTimeZones, tab);
|
||||
tabview->AddTab(f_TimeZones, tab);
|
||||
tab->SetLabel("Time Zone");
|
||||
|
||||
f_BaseView->AddChild(tabview);
|
||||
f_BaseView->Pulse();
|
||||
|
||||
}//TTimeWindow::BuildViews()
|
||||
}
|
||||
|
@ -9,22 +9,19 @@
|
||||
#include "ZoneView.h"
|
||||
#include "BaseView.h"
|
||||
|
||||
class TTimeWindow : public BWindow
|
||||
{
|
||||
class TTimeWindow : public BWindow {
|
||||
public:
|
||||
TTimeWindow();
|
||||
~TTimeWindow();
|
||||
|
||||
bool QuitRequested();
|
||||
void MessageReceived(BMessage *message);
|
||||
|
||||
private:
|
||||
void InitWindow();
|
||||
|
||||
private:
|
||||
TTimeBaseView *f_BaseView;
|
||||
TSettingsView *fTimeSettings;
|
||||
TZoneView *fTimeZones;
|
||||
TTimeBaseView *f_BaseView;
|
||||
TSettingsView *f_TimeSettings;
|
||||
TZoneView *f_TimeZones;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -2,13 +2,10 @@
|
||||
TZoneView.cpp
|
||||
*/
|
||||
|
||||
#include <AppDefs.h>
|
||||
#include <Button.h>
|
||||
#include <Directory.h>
|
||||
#include <Entry.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <Handler.h>
|
||||
#include <ListItem.h>
|
||||
#include <ListView.h>
|
||||
#include <MenuField.h>
|
||||
#include <MenuItem.h>
|
||||
@ -17,11 +14,9 @@
|
||||
#include <PopUpMenu.h>
|
||||
#include <ScrollView.h>
|
||||
#include <String.h>
|
||||
#include <StringView.h>
|
||||
#include <View.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "TimeMessages.h"
|
||||
#include "ZoneView.h"
|
||||
@ -45,19 +40,24 @@ TZoneItem::~TZoneItem()
|
||||
const char *
|
||||
TZoneItem::GetZone() const
|
||||
{
|
||||
return f_zonedata->Path();
|
||||
return f_zonedata->Leaf();
|
||||
}
|
||||
|
||||
|
||||
/*=====> TZoneView <=====*/
|
||||
|
||||
TZoneView::TZoneView(BRect frame)
|
||||
: BView(frame,"",B_FOLLOW_ALL,
|
||||
B_WILL_DRAW|B_FRAME_EVENTS|B_NAVIGABLE_JUMP)
|
||||
: BView(frame, "", B_FOLLOW_ALL,
|
||||
B_WILL_DRAW|B_FRAME_EVENTS|B_NAVIGABLE_JUMP|B_PULSE_NEEDED)
|
||||
, f_citylist(NULL)
|
||||
{
|
||||
InitView();
|
||||
} //TZoneView::TZoneView()
|
||||
}
|
||||
|
||||
|
||||
TZoneView::~TZoneView()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
@ -72,23 +72,19 @@ void
|
||||
TZoneView::MessageReceived(BMessage *message)
|
||||
{
|
||||
int32 change;
|
||||
switch(message->what)
|
||||
{
|
||||
switch(message->what) {
|
||||
case B_OBSERVER_NOTICE_CHANGE:
|
||||
message->FindInt32(B_OBSERVE_WHAT_CHANGE, &change);
|
||||
switch (change)
|
||||
{
|
||||
case OB_TIME_UPDATE:
|
||||
{
|
||||
switch(change) {
|
||||
case OB_TM_CHANGED:
|
||||
UpdateDateTime(message);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
BView::MessageReceived(message);
|
||||
break;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
BView::MessageReceived(message);
|
||||
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
|
||||
TZoneView:: InitView()
|
||||
{
|
||||
@ -115,7 +136,7 @@ TZoneView:: InitView()
|
||||
CreateZoneMenu(&widest);
|
||||
|
||||
frame.right = frame.left +widest +25;
|
||||
frame.bottom = frame.top +text_height;
|
||||
frame.bottom = frame.top +text_height -1;
|
||||
|
||||
BMenuField *mField;
|
||||
mField= new BMenuField(frame, "mfield", NULL, f_zonepopup, true);
|
||||
@ -134,59 +155,36 @@ TZoneView:: InitView()
|
||||
frame.InsetBy(3, 5);
|
||||
|
||||
f_citylist = new BListView(frame, "cities", B_SINGLE_SELECTION_LIST,
|
||||
B_FOLLOW_LEFT|B_FOLLOW_TOP,
|
||||
B_WILL_DRAW|B_NAVIGABLE|B_FRAME_EVENTS);
|
||||
B_FOLLOW_LEFT|B_FOLLOW_TOP,
|
||||
B_WILL_DRAW|B_NAVIGABLE|B_FRAME_EVENTS);
|
||||
|
||||
BMessage *citychange = new BMessage(TIME_ZONE_CHANGED);
|
||||
f_citylist->SetSelectionMessage(citychange);
|
||||
|
||||
BScrollView *scrollList;
|
||||
scrollList = new BScrollView("scroll_list", f_citylist,
|
||||
B_FOLLOW_LEFT|B_FOLLOW_TOP,
|
||||
0, false, true);
|
||||
B_FOLLOW_LEFT|B_FOLLOW_TOP, 0, false, true);
|
||||
AddChild(scrollList);
|
||||
|
||||
|
||||
// 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);
|
||||
// Time Displays
|
||||
|
||||
float oldleft = frame.left;
|
||||
float width = be_plain_font->StringWidth("00:00 PM") +8;
|
||||
frame.OffsetBy(scrollList->Bounds().Width() +9, 3);
|
||||
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.right = bounds.right -(width +4);
|
||||
f_curtext = new BStringView(frame, "currenttext", "Current time display");
|
||||
|
||||
frame.right = bounds.right;
|
||||
frame.left = frame.right -width;
|
||||
frame.OffsetBy(0, (text_height *3) +2);
|
||||
f_timeinzone = new TTZDisplay(frame, "timein",
|
||||
B_FOLLOW_LEFT|B_FOLLOW_TOP, 0,
|
||||
"Time in: ", B_EMPTY_STRING);
|
||||
f_timeinzone->ResizeToPreferred();
|
||||
|
||||
f_curtime = new BStringView(frame, "currenttime", "cTIME");
|
||||
f_curtime->SetAlignment(B_ALIGN_RIGHT);
|
||||
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);
|
||||
AddChild(f_currentzone);
|
||||
AddChild(f_timeinzone);
|
||||
|
||||
|
||||
// set button
|
||||
@ -198,11 +196,12 @@ TZoneView:: InitView()
|
||||
f_settimezone->SetEnabled(false);
|
||||
AddChild(f_settimezone);
|
||||
|
||||
|
||||
// update displays
|
||||
|
||||
FillZoneList(f_RegionStr.Leaf());
|
||||
UpdateTimeDisplay(OB_CURRENT_TIME);
|
||||
int currentzone = FillZoneList(f_RegionStr.Leaf());
|
||||
f_citylist->Select(currentzone);
|
||||
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
|
||||
if (!(find_directory(B_BEOS_ETC_DIRECTORY, &path) == B_OK))
|
||||
return;
|
||||
|
||||
|
||||
path.Append("timezones");
|
||||
|
||||
|
||||
float width = 0;
|
||||
bool markitem;
|
||||
BEntry entry;
|
||||
BMenuItem *zoneItem;
|
||||
BDirectory dir(path.Path());
|
||||
|
||||
|
||||
dir.Rewind();
|
||||
// walk timezones dir and add entries to menu
|
||||
BString itemtext;
|
||||
while (dir.GetNextEntry(&entry) == B_NO_ERROR)
|
||||
{
|
||||
if (entry.IsDirectory())
|
||||
{
|
||||
while (dir.GetNextEntry(&entry) == B_NO_ERROR) {
|
||||
if (entry.IsDirectory()) {
|
||||
path.SetTo(&entry);
|
||||
itemtext = path.Leaf();
|
||||
if (itemtext.Compare("Etc", 3) == 0)
|
||||
continue;
|
||||
|
||||
// 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;
|
||||
itemtext = itemtext.ReplaceAll('_', ' ');
|
||||
|
||||
@ -263,7 +264,7 @@ TZoneView::ChangeRegion(BMessage *message)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
int
|
||||
TZoneView::FillZoneList(const char *area)
|
||||
{
|
||||
//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 subdirectory and count the items. For each item, add a StringItem to f_CityList
|
||||
//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;
|
||||
BStringItem *city;
|
||||
BString city_name;
|
||||
entry_ref ref;
|
||||
|
||||
|
||||
int index = 0; // index of current setting
|
||||
//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!!
|
||||
//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.ReplaceAll("__", ", ");
|
||||
city_name.ReplaceAll("_", " ");
|
||||
city = new TZoneItem(city_name.String(), ref.name);
|
||||
f_citylist->AddItem(city);
|
||||
|
||||
if (strcmp(f_ZoneStr.Leaf(), ref.name) == 0)
|
||||
index = f_citylist->IndexOf(city);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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());
|
||||
printf("%d\n", index);
|
||||
return index;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TZoneView::GetCurrentTZ()
|
||||
{
|
||||
|
||||
BPath path;
|
||||
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");
|
||||
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???
|
||||
// return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// set tzlink to default
|
||||
}
|
||||
|
||||
// we need something in the current zone
|
||||
f_ZoneStr.SetTo(&tzLink);
|
||||
|
||||
}//TZoneView::getCurrentTz()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
@ -372,8 +342,12 @@ TZoneView::GetCurrentRegion()
|
||||
void
|
||||
TZoneView::NewTimeZone()
|
||||
{
|
||||
UpdateTimeDisplay(OB_SELECTION_TIME);
|
||||
}//TZoneView::newTimeZone()
|
||||
BString text;
|
||||
int32 selection = f_citylist->CurrentSelection();
|
||||
text = ((TZoneItem *)f_citylist->ItemAt(selection))->Text();
|
||||
f_timeinzone->SetText(text.String());
|
||||
f_settimezone->SetEnabled(true);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
@ -384,32 +358,33 @@ TZoneView::SetTimeZone()
|
||||
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);
|
||||
} //TZoneView::setTimeZone()
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Still doesn't change runtime timezone setting.
|
||||
*/
|
||||
}
|
||||
|
@ -10,14 +10,9 @@
|
||||
#include <String.h>
|
||||
#include <ListItem.h>
|
||||
|
||||
enum OB_TIME_TARGET
|
||||
{
|
||||
OB_CURRENT_TIME,
|
||||
OB_SELECTION_TIME
|
||||
};
|
||||
#include "TZDisplay.h"
|
||||
|
||||
class TZoneItem: public BStringItem
|
||||
{
|
||||
class TZoneItem: public BStringItem {
|
||||
public:
|
||||
TZoneItem(const char *text, const char *zonedata);
|
||||
virtual ~TZoneItem();
|
||||
@ -27,44 +22,40 @@ class TZoneItem: public BStringItem
|
||||
BPath *f_zonedata;
|
||||
};
|
||||
|
||||
class TZoneView : public BView
|
||||
{
|
||||
class TZoneView : public BView {
|
||||
public:
|
||||
TZoneView(BRect frame);
|
||||
~TZoneView();
|
||||
virtual void AttachedToWindow();
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
virtual void Draw(BRect);
|
||||
|
||||
void ChangeRegion(BMessage *region);
|
||||
void SetTimeZone();
|
||||
void NewTimeZone();
|
||||
protected:
|
||||
virtual void UpdateDateTime(BMessage *message);
|
||||
private:
|
||||
void InitView();
|
||||
void GetCurrentTZ();
|
||||
void GetCurrentRegion();
|
||||
|
||||
void FillZoneList(const char *area);
|
||||
int FillZoneList(const char *area);
|
||||
void CreateZoneMenu(float *widest);
|
||||
|
||||
void Update();
|
||||
|
||||
void UpdateTimeDisplay(OB_TIME_TARGET target);
|
||||
void UpdateDateTime(BMessage *message);
|
||||
private:
|
||||
BPopUpMenu *f_zonepopup;
|
||||
BListView *f_citylist;
|
||||
BButton *f_settimezone;
|
||||
BStringView *f_seltext;
|
||||
BStringView *f_seltime;
|
||||
BStringView *f_curtext;
|
||||
BStringView *f_curtime;
|
||||
BPopUpMenu *f_zonepopup;
|
||||
BListView *f_citylist;
|
||||
BButton *f_settimezone;
|
||||
TTZDisplay *f_currentzone;
|
||||
TTZDisplay *f_timeinzone;
|
||||
private:
|
||||
BString f_CurrentTime;
|
||||
BPath f_ZoneStr;
|
||||
BPath f_RegionStr;
|
||||
BPath f_ZoneStr;
|
||||
BPath f_RegionStr;
|
||||
|
||||
int f_hour;
|
||||
int f_minutes;
|
||||
char f_TimeStr[10];
|
||||
};
|
||||
int f_hour;
|
||||
int f_minutes;
|
||||
char f_TimeStr[10];
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user