More updates by Michael Berg <[email protected]>
Time is almost complete. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8400 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,6 +1,16 @@
|
|||||||
|
/*
|
||||||
|
AnalogClock.cpp
|
||||||
|
by Mike Berg (inseculous)
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
TOffscreen borrows heavily from the clock source.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
#include <Debug.h>
|
#include <Debug.h>
|
||||||
|
#include <Dragger.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
#include "AnalogClock.h"
|
#include "AnalogClock.h"
|
||||||
@@ -11,6 +21,10 @@ const BRect kClockRect(0, 0, kClockFaceWidth -1, kClockFaceHeight -1);
|
|||||||
const BRect kCenterRect(0, 0, kCenterWidth -1, kCenterHeight -1);
|
const BRect kCenterRect(0, 0, kCenterWidth -1, kCenterHeight -1);
|
||||||
const BRect kCapRect(0, 0, kCapWidth -1, kCapHeight -1);
|
const BRect kCapRect(0, 0, kCapWidth -1, kCapHeight -1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
TOffscreen
|
||||||
|
Analog Clock face rendering view.
|
||||||
|
*/
|
||||||
|
|
||||||
TOffscreen::TOffscreen(BRect frame, const char *name)
|
TOffscreen::TOffscreen(BRect frame, const char *name)
|
||||||
: BView(frame, name, B_NOT_RESIZABLE, B_WILL_DRAW)
|
: BView(frame, name, B_NOT_RESIZABLE, B_WILL_DRAW)
|
||||||
@@ -69,6 +83,8 @@ TOffscreen::TOffscreen(BRect frame, const char *name)
|
|||||||
TOffscreen::~TOffscreen()
|
TOffscreen::~TOffscreen()
|
||||||
{
|
{
|
||||||
delete f_bitmap;
|
delete f_bitmap;
|
||||||
|
delete f_centerbmp;
|
||||||
|
delete f_capbmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -110,7 +126,10 @@ TOffscreen::DrawX()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*=====> TAnalogClock <=====*/
|
/*
|
||||||
|
TAnalogClock
|
||||||
|
BView to display clock face of current time.
|
||||||
|
*/
|
||||||
|
|
||||||
TAnalogClock::TAnalogClock(BRect frame, const char *name, uint32 resizingmode, uint32 flags)
|
TAnalogClock::TAnalogClock(BRect frame, const char *name, uint32 resizingmode, uint32 flags)
|
||||||
: BView(frame, name, resizingmode, flags|B_DRAW_ON_CHILDREN)
|
: BView(frame, name, resizingmode, flags|B_DRAW_ON_CHILDREN)
|
||||||
@@ -122,6 +141,7 @@ TAnalogClock::TAnalogClock(BRect frame, const char *name, uint32 resizingmode, u
|
|||||||
TAnalogClock::~TAnalogClock()
|
TAnalogClock::~TAnalogClock()
|
||||||
{
|
{
|
||||||
delete f_bitmap;
|
delete f_bitmap;
|
||||||
|
delete f_offscreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -162,7 +182,7 @@ TAnalogClock::MessageReceived(BMessage *message)
|
|||||||
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 H_TM_CHANGED:
|
||||||
{
|
{
|
||||||
int32 hour = 0;
|
int32 hour = 0;
|
||||||
int32 minute = 0;
|
int32 minute = 0;
|
||||||
|
|||||||
@@ -1,13 +1,20 @@
|
|||||||
|
/*
|
||||||
|
BaseView.cpp
|
||||||
|
by Mike Berg (inseculous)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Alert.h>
|
||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "BaseView.h"
|
#include "BaseView.h"
|
||||||
|
#include "TimeMessages.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);
|
InitView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -16,6 +23,14 @@ TTimeBaseView::~TTimeBaseView()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TTimeBaseView::InitView()
|
||||||
|
{
|
||||||
|
f_message = new BMessage(H_TIME_UPDATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TTimeBaseView::Pulse()
|
TTimeBaseView::Pulse()
|
||||||
{
|
{
|
||||||
@@ -59,7 +74,7 @@ TTimeBaseView::DispatchMessage()
|
|||||||
f_message->AddInt32("minute", minute);
|
f_message->AddInt32("minute", minute);
|
||||||
f_message->AddInt32("second", second);
|
f_message->AddInt32("second", second);
|
||||||
|
|
||||||
SendNotices(OB_TM_CHANGED, f_message);
|
SendNotices(H_TM_CHANGED, f_message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -73,6 +88,7 @@ TTimeBaseView::ChangeTime(BMessage *message)
|
|||||||
time_t atime;
|
time_t atime;
|
||||||
struct tm *_tm;
|
struct tm *_tm;
|
||||||
|
|
||||||
|
|
||||||
atime = time(0);
|
atime = time(0);
|
||||||
_tm = localtime(&atime);
|
_tm = localtime(&atime);
|
||||||
|
|
||||||
@@ -82,6 +98,7 @@ TTimeBaseView::ChangeTime(BMessage *message)
|
|||||||
int32 month = 0;
|
int32 month = 0;
|
||||||
int32 day = 0;
|
int32 day = 0;
|
||||||
int32 year = 0;
|
int32 year = 0;
|
||||||
|
bool isam = false;
|
||||||
if (istime) {
|
if (istime) {
|
||||||
if (message->FindInt32("hour", &hour) == B_OK)
|
if (message->FindInt32("hour", &hour) == B_OK)
|
||||||
_tm->tm_hour = hour;
|
_tm->tm_hour = hour;
|
||||||
@@ -89,6 +106,10 @@ TTimeBaseView::ChangeTime(BMessage *message)
|
|||||||
_tm->tm_min = minute;
|
_tm->tm_min = minute;
|
||||||
if (message->FindInt32("second", &second) == B_OK)
|
if (message->FindInt32("second", &second) == B_OK)
|
||||||
_tm->tm_sec = second;
|
_tm->tm_sec = second;
|
||||||
|
if (message->FindBool("isam", &isam) == B_OK) {
|
||||||
|
if (!isam)
|
||||||
|
_tm->tm_hour += 12;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (message->FindInt32("month", &month) == B_OK)
|
if (message->FindInt32("month", &month) == B_OK)
|
||||||
_tm->tm_mon = month;
|
_tm->tm_mon = month;
|
||||||
@@ -102,3 +123,4 @@ TTimeBaseView::ChangeTime(BMessage *message)
|
|||||||
set_real_time_clock(atime2);
|
set_real_time_clock(atime2);
|
||||||
DispatchMessage();
|
DispatchMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
#include "TimeMessages.h"
|
|
||||||
|
|
||||||
class TTimeBaseView: public BView {
|
class TTimeBaseView: public BView {
|
||||||
public:
|
public:
|
||||||
@@ -13,9 +12,10 @@ class TTimeBaseView: public BView {
|
|||||||
|
|
||||||
virtual void Pulse();
|
virtual void Pulse();
|
||||||
|
|
||||||
void ChangeTime(BMessage *message);
|
void ChangeTime(BMessage *);
|
||||||
void SetGMTime(bool);
|
void SetGMTime(bool);
|
||||||
protected:
|
protected:
|
||||||
|
virtual void InitView();
|
||||||
virtual void DispatchMessage();
|
virtual void DispatchMessage();
|
||||||
private:
|
private:
|
||||||
BMessage *f_message;
|
BMessage *f_message;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "DateUtils.h"
|
#include "DateUtils.h"
|
||||||
#include "TimeMessages.h"
|
#include "TimeMessages.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#define SEGMENT_CHANGE 'ostd'
|
#define SEGMENT_CHANGE 'ostd'
|
||||||
|
|
||||||
@@ -46,6 +47,14 @@ TDay::MouseDown(BPoint where)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TDay::KeyDown(const char *bytes, int32 numbytes)
|
||||||
|
{
|
||||||
|
BControl::KeyDown(bytes, numbytes);
|
||||||
|
Parent()->KeyDown(bytes, numbytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TDay::MakeFocus(bool focused)
|
TDay::MakeFocus(bool focused)
|
||||||
{
|
{
|
||||||
@@ -189,15 +198,25 @@ TCalendarView::TCalendarView(BRect frame, const char *name,
|
|||||||
InitView();
|
InitView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TCalendarView::~TCalendarView()
|
TCalendarView::~TCalendarView()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TCalendarView::AttachedToWindow()
|
||||||
|
{
|
||||||
|
if (Parent())
|
||||||
|
SetViewColor(Parent()->ViewColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TCalendarView::MessageReceived(BMessage *message)
|
TCalendarView::MessageReceived(BMessage *message)
|
||||||
{
|
{
|
||||||
switch(message->what) {
|
switch(message->what) {
|
||||||
case OB_DAY_CHANGED:
|
case H_DAY_CHANGED:
|
||||||
{
|
{
|
||||||
TDay *day;
|
TDay *day;
|
||||||
message->FindPointer("source", (void **)&day);
|
message->FindPointer("source", (void **)&day);
|
||||||
@@ -217,15 +236,86 @@ TCalendarView::MessageReceived(BMessage *message)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TCalendarView::AttachedToWindow()
|
TCalendarView::KeyDown(const char *bytes, int32 numbytes)
|
||||||
{
|
{
|
||||||
if (Parent())
|
if (f_focused == NULL)
|
||||||
SetViewColor(Parent()->ViewColor());
|
f_focused = f_cday;
|
||||||
|
|
||||||
|
switch(bytes[0]) {
|
||||||
|
case B_LEFT_ARROW: {
|
||||||
|
TDay *newfocus = dynamic_cast<TDay *>(f_focused->PreviousSibling());
|
||||||
|
if (newfocus == NULL || newfocus->Day() == 0)
|
||||||
|
break;
|
||||||
|
f_focused->MakeFocus(false);
|
||||||
|
f_focused = newfocus;
|
||||||
|
f_focused->MakeFocus(true);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case B_RIGHT_ARROW: {
|
||||||
|
TDay *newfocus = dynamic_cast<TDay *>(f_focused->NextSibling());
|
||||||
|
if (newfocus == NULL || newfocus->Day() == 0)
|
||||||
|
break;
|
||||||
|
f_focused->MakeFocus(false);
|
||||||
|
f_focused = newfocus;
|
||||||
|
f_focused->MakeFocus(true);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case B_UP_ARROW: {
|
||||||
|
int32 idx = IndexOf(f_focused) -7;
|
||||||
|
if (idx> f_daybound.x -1 ) {
|
||||||
|
f_focused->MakeFocus(false);
|
||||||
|
f_focused = dynamic_cast<TDay *>(ChildAt(idx));
|
||||||
|
f_focused->MakeFocus(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case B_DOWN_ARROW: {
|
||||||
|
int32 idx = IndexOf(f_focused) +7;
|
||||||
|
if (idx < f_daybound.y +1) {
|
||||||
|
f_focused->MakeFocus(false);
|
||||||
|
f_focused = dynamic_cast<TDay *>(ChildAt(idx));
|
||||||
|
f_focused->MakeFocus(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int32
|
||||||
|
TCalendarView::IndexOf(BView *child) const
|
||||||
|
{
|
||||||
|
BView *test;
|
||||||
|
for (int32 idx = 0; idx < CountChildren(); idx++) {
|
||||||
|
test = ChildAt(idx);
|
||||||
|
if (test == child)
|
||||||
|
return idx;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static const char days[7] = { 'S', 'M', 'T', 'W', 'T', 'F', 'S' };
|
static const char days[7] = { 'S', 'M', 'T', 'W', 'T', 'F', 'S' };
|
||||||
|
|
||||||
|
static float
|
||||||
|
FontHeight(BView* target, bool full)
|
||||||
|
{
|
||||||
|
font_height finfo;
|
||||||
|
target->GetFontHeight(&finfo);
|
||||||
|
float h = ceil(finfo.ascent) + ceil(finfo.descent);
|
||||||
|
|
||||||
|
if (full)
|
||||||
|
h += ceil(finfo.leading);
|
||||||
|
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TCalendarView::Draw(BRect updaterect)
|
TCalendarView::Draw(BRect updaterect)
|
||||||
{
|
{
|
||||||
@@ -237,11 +327,14 @@ TCalendarView::Draw(BRect updaterect)
|
|||||||
BString day;
|
BString day;
|
||||||
SetLowColor(ViewColor());
|
SetLowColor(ViewColor());
|
||||||
SetHighColor(0, 0, 0);
|
SetHighColor(0, 0, 0);
|
||||||
|
|
||||||
|
float offset = FontHeight(this, true);
|
||||||
|
|
||||||
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);
|
||||||
drawpt.y = bounds.bottom;
|
drawpt.y = bounds.bottom -offset/2.0;
|
||||||
DrawString(day.String(), drawpt);
|
DrawString(day.String(), drawpt);
|
||||||
bounds.OffsetBy(bounds.Width() +1, 0);
|
bounds.OffsetBy(bounds.Width() +1, 0);
|
||||||
}
|
}
|
||||||
@@ -298,11 +391,15 @@ TCalendarView::InitDates()
|
|||||||
day->SetTo(label, cday);
|
day->SetTo(label, cday);
|
||||||
|
|
||||||
if (label> 0) {
|
if (label> 0) {
|
||||||
BMessage *message = new BMessage(OB_DAY_CHANGED);
|
BMessage *message = new BMessage(H_DAY_CHANGED);
|
||||||
message->AddInt32("Day", label);
|
message->AddInt32("Day", label);
|
||||||
|
|
||||||
day->SetTarget(this);
|
day->SetTarget(this);
|
||||||
day->SetMessage(message);
|
day->SetMessage(message);
|
||||||
|
if (label == 1)
|
||||||
|
f_daybound.x = row *7 +col;
|
||||||
|
if (label == daycnt)
|
||||||
|
f_daybound.y = row *7 +col;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cday) {
|
if (cday) {
|
||||||
@@ -311,6 +408,8 @@ TCalendarView::InitDates()
|
|||||||
cday = false;
|
cday = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (f_focused == NULL)
|
||||||
|
f_focused = f_cday;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -337,7 +436,7 @@ void
|
|||||||
TCalendarView::DispatchMessage()
|
TCalendarView::DispatchMessage()
|
||||||
{
|
{
|
||||||
// send message to update timedate
|
// send message to update timedate
|
||||||
BMessage *msg = new BMessage(OB_USER_CHANGE);
|
BMessage *msg = new BMessage(H_USER_CHANGE);
|
||||||
msg->AddBool("time", false);
|
msg->AddBool("time", false);
|
||||||
msg->AddInt32("month", f_month);
|
msg->AddInt32("month", f_month);
|
||||||
if (f_cday != NULL)
|
if (f_cday != NULL)
|
||||||
|
|||||||
@@ -8,11 +8,12 @@ class TDay: public BControl {
|
|||||||
public:
|
public:
|
||||||
TDay(BRect frame, int day);
|
TDay(BRect frame, int day);
|
||||||
virtual ~TDay();
|
virtual ~TDay();
|
||||||
virtual void Draw(BRect updaterect);
|
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
|
virtual void Draw(BRect updaterect);
|
||||||
|
virtual void KeyDown(const char *bytes, int32 numbytes);
|
||||||
|
virtual void MakeFocus(bool focused);
|
||||||
virtual void MouseDown(BPoint where);
|
virtual void MouseDown(BPoint where);
|
||||||
virtual void SetValue(int32 value);
|
virtual void SetValue(int32 value);
|
||||||
virtual void MakeFocus(bool focused);
|
|
||||||
|
|
||||||
void SetTo(BRect frame, int day);
|
void SetTo(BRect frame, int day);
|
||||||
void SetTo(int day, bool selected = false);
|
void SetTo(int day, bool selected = false);
|
||||||
@@ -31,6 +32,7 @@ class TCalendarView: public BView {
|
|||||||
virtual ~TCalendarView();
|
virtual ~TCalendarView();
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
virtual void Draw(BRect bounds);
|
virtual void Draw(BRect bounds);
|
||||||
|
void KeyDown(const char *bytes, int32 numbytes);
|
||||||
virtual void MessageReceived(BMessage *message);
|
virtual void MessageReceived(BMessage *message);
|
||||||
|
|
||||||
void SetTo(int32, int32, int32);
|
void SetTo(int32, int32, int32);
|
||||||
@@ -40,9 +42,13 @@ class TCalendarView: public BView {
|
|||||||
private:
|
private:
|
||||||
void InitDates();
|
void InitDates();
|
||||||
void CalcFlags();
|
void CalcFlags();
|
||||||
|
int32 IndexOf(BView *) const;
|
||||||
|
|
||||||
TDay *f_cday;
|
TDay *f_cday;
|
||||||
|
TDay *f_focused;
|
||||||
BRect f_dayrect;
|
BRect f_dayrect;
|
||||||
|
// x = index of first day; y = index of last;
|
||||||
|
BPoint f_daybound;
|
||||||
int f_firstday;
|
int f_firstday;
|
||||||
int f_month;
|
int f_month;
|
||||||
int f_day;
|
int f_day;
|
||||||
|
|||||||
+505
-628
File diff suppressed because it is too large
Load Diff
@@ -1,101 +1,70 @@
|
|||||||
#ifndef DATETIME_EDIT_H
|
#ifndef DATETIME_H
|
||||||
#define DATETIME_EDIT_H
|
#define DATETIME_H
|
||||||
|
|
||||||
#include <Control.h>
|
#include "SectionEdit.h"
|
||||||
#include <Message.h>
|
|
||||||
|
|
||||||
#define OB_UP_PRESS 'obUP'
|
// TSection descendent to hold uint32 value
|
||||||
#define OB_DOWN_PRESS 'obDN'
|
class TDateTimeSection: public TSection {
|
||||||
|
|
||||||
enum FieldFocus {
|
|
||||||
FOCUS_NONE = 0,
|
|
||||||
FOCUS_MONTH,
|
|
||||||
FOCUS_DAY,
|
|
||||||
FOCUS_YEAR,
|
|
||||||
FOCUS_HOUR,
|
|
||||||
FOCUS_MINUTE,
|
|
||||||
FOCUS_SECOND,
|
|
||||||
FOCUS_AMPM
|
|
||||||
};
|
|
||||||
|
|
||||||
class TDateTimeEdit: public BControl {
|
|
||||||
public:
|
public:
|
||||||
TDateTimeEdit(BRect frame, const char *name);
|
TDateTimeSection(BRect frame, uint32 data = 0);
|
||||||
virtual ~TDateTimeEdit();
|
~TDateTimeSection();
|
||||||
|
|
||||||
virtual void AttachedToWindow();
|
uint32 Data() const;
|
||||||
virtual void Draw(BRect updaterect);
|
void SetData(uint32 data);
|
||||||
virtual void MouseDown(BPoint where);
|
|
||||||
virtual void MessageReceived(BMessage *message);
|
|
||||||
|
|
||||||
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_down;
|
|
||||||
BRect f_uprect;
|
|
||||||
BRect f_downrect;
|
|
||||||
|
|
||||||
FieldFocus f_focus;
|
|
||||||
int f_holdvalue;
|
|
||||||
};
|
|
||||||
|
|
||||||
class TTimeEdit: public TDateTimeEdit {
|
|
||||||
public:
|
|
||||||
TTimeEdit(BRect frame, const char *name);
|
|
||||||
virtual ~TTimeEdit();
|
|
||||||
|
|
||||||
virtual void Draw(BRect updaterect);
|
|
||||||
virtual void MouseDown(BPoint where);
|
|
||||||
virtual void KeyDown(const char *bytes, int32 numbytes);
|
|
||||||
virtual void UpPress();
|
|
||||||
virtual void DownPress();
|
|
||||||
|
|
||||||
virtual void SetTo(int32, int32, int32);
|
|
||||||
private:
|
private:
|
||||||
void BuildDispatch(BMessage *message);
|
uint32 f_data;
|
||||||
void SetFocus(bool forward);
|
|
||||||
void UpdateFocus();
|
|
||||||
|
|
||||||
BRect f_hourrect;
|
|
||||||
BRect f_minrect;
|
|
||||||
BRect f_secrect;
|
|
||||||
BRect f_aprect;
|
|
||||||
|
|
||||||
int f_hour;
|
|
||||||
int f_minute;
|
|
||||||
int f_second;
|
|
||||||
bool f_isam;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class TDateEdit: public TDateTimeEdit {
|
// TSectionEdit descendent to edit time
|
||||||
|
class TTimeEdit: public TSectionEdit {
|
||||||
public:
|
public:
|
||||||
TDateEdit(BRect frame, const char *name);
|
TTimeEdit(BRect frame, const char *name, uint32 sections);
|
||||||
virtual ~TDateEdit();
|
~TTimeEdit();
|
||||||
|
|
||||||
virtual void Draw(BRect updaterect);
|
virtual void InitView();
|
||||||
virtual void MouseDown(BPoint where);
|
virtual void DrawSection(uint32 index, bool isfocus);
|
||||||
virtual void KeyDown(const char *bytes, int32 numbytes);
|
virtual void DrawSeperator(uint32 index);
|
||||||
virtual void UpPress();
|
|
||||||
virtual void DownPress();
|
|
||||||
|
|
||||||
virtual void SetTo(int32, int32, int32);
|
virtual void SetSections(BRect area);
|
||||||
private:
|
virtual void SectionFocus(uint32 index);
|
||||||
void BuildDispatch(BMessage *message);
|
virtual void GetSeperatorWidth(uint32 *width);
|
||||||
void SetFocus(bool forward);
|
|
||||||
void UpdateFocus(bool = false);
|
|
||||||
|
|
||||||
BRect f_monthrect;
|
void CheckRange();
|
||||||
BRect f_dayrect;
|
|
||||||
BRect f_yearrect;
|
virtual void DoUpPress();
|
||||||
int f_month;
|
virtual void DoDownPress();
|
||||||
int f_day;
|
|
||||||
int f_year;
|
virtual void BuildDispatch(BMessage *message);
|
||||||
|
|
||||||
|
void SetTo(uint32 hour, uint32 minute, uint32 second);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //DATETIME_EDIT_H
|
|
||||||
|
/* DATE TSECTIONEDIT */
|
||||||
|
|
||||||
|
// TSectionEdit descendent to edit Date
|
||||||
|
class TDateEdit: public TSectionEdit {
|
||||||
|
public:
|
||||||
|
TDateEdit(BRect frame, const char *name, uint32 sections);
|
||||||
|
~TDateEdit();
|
||||||
|
|
||||||
|
virtual void InitView();
|
||||||
|
virtual void DrawSection(uint32 index, bool isfocus);
|
||||||
|
virtual void DrawSeperator(uint32 index);
|
||||||
|
|
||||||
|
virtual void SetSections(BRect area);
|
||||||
|
virtual void SectionFocus(uint32 index);
|
||||||
|
virtual void GetSeperatorWidth(uint32 *width);
|
||||||
|
|
||||||
|
void CheckRange();
|
||||||
|
|
||||||
|
virtual void DoUpPress();
|
||||||
|
virtual void DoDownPress();
|
||||||
|
|
||||||
|
virtual void BuildDispatch(BMessage *message);
|
||||||
|
|
||||||
|
void SetTo(uint32 hour, uint32 minute, uint32 second);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //DATETIME_H
|
||||||
|
|||||||
@@ -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 DateUtils.cpp TZDisplay.cpp ;
|
Preference Time : AnalogClock.cpp BaseView.cpp Bitmaps.cpp CalendarView.cpp DateTimeEdit.cpp DateUtils.cpp SectionEdit.cpp SettingsView.cpp Time.cpp TimeSettings.cpp TimeView.cpp TimeWindow.cpp TZDisplay.cpp ZoneView.cpp ;
|
||||||
|
|
||||||
LinkSharedOSLibs Time : be root ;
|
LinkSharedOSLibs Time : be root ;
|
||||||
|
|||||||
@@ -0,0 +1,303 @@
|
|||||||
|
#include <Bitmap.h>
|
||||||
|
#include <Window.h>
|
||||||
|
|
||||||
|
#include "Bitmaps.h"
|
||||||
|
#include "SectionEdit.h"
|
||||||
|
#include "TimeMessages.h"
|
||||||
|
|
||||||
|
const uint32 kArrowAreaWidth = 16;
|
||||||
|
const uint32 kSeperatorWidth = 8;
|
||||||
|
|
||||||
|
|
||||||
|
TSection::TSection(BRect frame)
|
||||||
|
: f_frame(frame)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TSection::SetBounds(BRect frame)
|
||||||
|
{
|
||||||
|
f_frame = frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BRect
|
||||||
|
TSection::Bounds() const
|
||||||
|
{
|
||||||
|
BRect bounds(f_frame);
|
||||||
|
return bounds.OffsetByCopy(B_ORIGIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BRect
|
||||||
|
TSection::Frame() const
|
||||||
|
{
|
||||||
|
return f_frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TSectionEdit::TSectionEdit(BRect frame, const char *name, uint32 sections)
|
||||||
|
: BControl(frame, name, NULL, NULL, B_FOLLOW_NONE, B_NAVIGABLE|B_WILL_DRAW)
|
||||||
|
, f_focus(-1)
|
||||||
|
{
|
||||||
|
f_sectioncount = sections;
|
||||||
|
InitView();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TSectionEdit::~TSectionEdit()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TSectionEdit::AttachedToWindow()
|
||||||
|
{
|
||||||
|
if (Parent()) {
|
||||||
|
SetViewColor(Parent()->ViewColor());
|
||||||
|
ReplaceTransparentColor(f_up, ViewColor());
|
||||||
|
ReplaceTransparentColor(f_down, ViewColor());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TSectionEdit::Draw(BRect updaterect)
|
||||||
|
{
|
||||||
|
DrawBorder();
|
||||||
|
for (uint32 idx = 0; idx < f_sectioncount; idx++)
|
||||||
|
{
|
||||||
|
DrawSection(idx, ((uint32)f_focus == idx) && IsFocus());
|
||||||
|
if (idx <f_sectioncount -1)
|
||||||
|
DrawSeperator(idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TSectionEdit::MouseDown(BPoint where)
|
||||||
|
{
|
||||||
|
MakeFocus(true);
|
||||||
|
if (f_uprect.Contains(where))
|
||||||
|
DoUpPress();
|
||||||
|
else if (f_downrect.Contains(where))
|
||||||
|
DoDownPress();
|
||||||
|
else if (f_sections->CountItems()> 0) {
|
||||||
|
TSection *section;
|
||||||
|
for (uint32 idx = 0; idx < f_sectioncount; idx++) {
|
||||||
|
section = (TSection *)f_sections->ItemAt(idx);
|
||||||
|
if (section->Frame().Contains(where)) {
|
||||||
|
SectionFocus(idx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TSectionEdit::KeyDown(const char *bytes, int32 numbytes)
|
||||||
|
{
|
||||||
|
if (f_focus == -1)
|
||||||
|
SectionFocus(0);
|
||||||
|
|
||||||
|
switch (bytes[0]) {
|
||||||
|
case B_LEFT_ARROW:
|
||||||
|
f_focus -= 1;
|
||||||
|
if (f_focus < 0)
|
||||||
|
f_focus = f_sectioncount -1;
|
||||||
|
SectionFocus(f_focus);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case B_RIGHT_ARROW:
|
||||||
|
f_focus += 1;
|
||||||
|
if ((uint32)f_focus >= f_sectioncount)
|
||||||
|
f_focus = 0;
|
||||||
|
SectionFocus(f_focus);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case B_UP_ARROW:
|
||||||
|
DoUpPress();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case B_DOWN_ARROW:
|
||||||
|
DoDownPress();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
BControl::KeyDown(bytes, numbytes);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Draw(Bounds());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TSectionEdit::DispatchMessage()
|
||||||
|
{
|
||||||
|
BMessage *msg = new BMessage(H_USER_CHANGE);
|
||||||
|
BuildDispatch(msg);
|
||||||
|
Window()->PostMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint32
|
||||||
|
TSectionEdit::CountSections() const
|
||||||
|
{
|
||||||
|
return f_sections->CountItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32
|
||||||
|
TSectionEdit::FocusIndex() const
|
||||||
|
{
|
||||||
|
return f_focus;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TSectionEdit::InitView()
|
||||||
|
{
|
||||||
|
// create arrow bitmaps
|
||||||
|
|
||||||
|
f_up = new BBitmap(BRect(0, 0, kUpArrowWidth -1, kUpArrowHeight -1), kUpArrowColorSpace);
|
||||||
|
f_up->SetBits(kUpArrowBits, (kUpArrowWidth) *(kUpArrowHeight+1), 0, kUpArrowColorSpace);
|
||||||
|
|
||||||
|
f_down = new BBitmap(BRect(0, 0, kDownArrowWidth -1, kDownArrowHeight -2), kDownArrowColorSpace);
|
||||||
|
f_down->SetBits(kDownArrowBits, (kDownArrowWidth) *(kDownArrowHeight), 0, kDownArrowColorSpace);
|
||||||
|
|
||||||
|
|
||||||
|
// setup sections
|
||||||
|
f_sections = new BList(f_sectioncount);
|
||||||
|
f_sectionsarea = Bounds().InsetByCopy(2, 2);
|
||||||
|
f_sectionsarea.right -= (kArrowAreaWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TSectionEdit::Draw3DFrame(BRect frame, bool inset)
|
||||||
|
{
|
||||||
|
rgb_color color1, color2;
|
||||||
|
|
||||||
|
if (inset) {
|
||||||
|
color1 = HighColor();
|
||||||
|
color2 = LowColor();
|
||||||
|
} else {
|
||||||
|
color1 = LowColor();
|
||||||
|
color2 = HighColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
BeginLineArray(4);
|
||||||
|
// left side
|
||||||
|
AddLine(frame.LeftBottom(), frame.LeftTop(), color2);
|
||||||
|
// right side
|
||||||
|
AddLine(frame.RightTop(), frame.RightBottom(), color1);
|
||||||
|
// bottom side
|
||||||
|
AddLine(frame.RightBottom(), frame.LeftBottom(), color1);
|
||||||
|
// top side
|
||||||
|
AddLine(frame.LeftTop(), frame.RightTop(), color2);
|
||||||
|
EndLineArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TSectionEdit::DrawBorder()
|
||||||
|
{
|
||||||
|
rgb_color bgcolor = ViewColor();
|
||||||
|
rgb_color light = tint_color(bgcolor, B_LIGHTEN_MAX_TINT);
|
||||||
|
rgb_color dark = tint_color(bgcolor, B_DARKEN_1_TINT);
|
||||||
|
rgb_color darker = tint_color(bgcolor, B_DARKEN_3_TINT);
|
||||||
|
|
||||||
|
BRect bounds(Bounds());
|
||||||
|
SetHighColor(light);
|
||||||
|
SetLowColor(dark);
|
||||||
|
Draw3DFrame(bounds, true);
|
||||||
|
StrokeLine(bounds.LeftBottom(), bounds.LeftBottom(), B_SOLID_LOW);
|
||||||
|
|
||||||
|
bounds.InsetBy(1, 1);
|
||||||
|
bounds.right -= kArrowAreaWidth;
|
||||||
|
|
||||||
|
f_showfocus = (IsFocus() && Window() && Window()->IsActive());
|
||||||
|
if (f_showfocus) {
|
||||||
|
rgb_color navcolor = keyboard_navigation_color();
|
||||||
|
|
||||||
|
SetHighColor(navcolor);
|
||||||
|
StrokeRect(bounds);
|
||||||
|
} else {
|
||||||
|
// draw border thickening (erase focus)
|
||||||
|
SetHighColor(darker);
|
||||||
|
SetLowColor(bgcolor);
|
||||||
|
Draw3DFrame(bounds, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// draw up/down control
|
||||||
|
SetHighColor(light);
|
||||||
|
bounds.left = bounds.right +1;// -kArrowAreaWidth;
|
||||||
|
bounds.right = Bounds().right -1;
|
||||||
|
f_uprect.Set(bounds.left +3, bounds.top +2, bounds.right, bounds.bottom /2.0);
|
||||||
|
f_downrect = f_uprect.OffsetByCopy(0, f_uprect.Height()+2);
|
||||||
|
|
||||||
|
DrawBitmap(f_up, f_uprect.LeftTop());
|
||||||
|
DrawBitmap(f_down, f_downrect.LeftTop());
|
||||||
|
|
||||||
|
Draw3DFrame(bounds, false);
|
||||||
|
SetHighColor(dark);
|
||||||
|
StrokeLine(bounds.LeftBottom(), bounds.RightBottom());
|
||||||
|
StrokeLine(bounds.RightBottom(), bounds.RightTop());
|
||||||
|
SetHighColor(light);
|
||||||
|
StrokeLine(bounds.RightTop(), bounds.RightTop());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TSectionEdit::SetSections(BRect)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TSectionEdit::GetSeperatorWidth(uint32 *width)
|
||||||
|
{
|
||||||
|
*width = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TSectionEdit::DrawSection(uint32 index, bool isfocus)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TSectionEdit::DrawSeperator(uint32 index)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TSectionEdit::SectionFocus(uint32 index)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TSectionEdit::SectionChange(uint32 section, uint32 value)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TSectionEdit::DoUpPress()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TSectionEdit::DoDownPress()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//---//
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
#ifndef SECTIONEDIT_H
|
||||||
|
#define SECTIONEDIT_H
|
||||||
|
|
||||||
|
#include <Control.h>
|
||||||
|
#include <List.h>
|
||||||
|
|
||||||
|
class TSection {
|
||||||
|
public:
|
||||||
|
TSection(BRect frame);
|
||||||
|
|
||||||
|
void SetBounds(BRect frame);
|
||||||
|
|
||||||
|
BRect Bounds() const;
|
||||||
|
BRect Frame() const;
|
||||||
|
private:
|
||||||
|
BRect f_frame;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class TSectionEdit: public BControl {
|
||||||
|
public:
|
||||||
|
TSectionEdit(BRect frame, const char *name, uint32 sections);
|
||||||
|
~TSectionEdit();
|
||||||
|
|
||||||
|
virtual void AttachedToWindow();
|
||||||
|
virtual void Draw(BRect);
|
||||||
|
virtual void MouseDown(BPoint);
|
||||||
|
virtual void KeyDown(const char *bytes, int32 numbytes);
|
||||||
|
|
||||||
|
uint32 CountSections() const;
|
||||||
|
int32 FocusIndex() const;
|
||||||
|
BRect SectionArea() const;
|
||||||
|
protected:
|
||||||
|
virtual void InitView();
|
||||||
|
//hooks
|
||||||
|
virtual void DrawBorder();
|
||||||
|
virtual void DrawSection(uint32 index, bool isfocus);
|
||||||
|
virtual void DrawSeperator(uint32 index);
|
||||||
|
virtual void Draw3DFrame(BRect frame, bool inset);
|
||||||
|
|
||||||
|
virtual void SectionFocus(uint32 index);
|
||||||
|
virtual void SectionChange(uint32 index, uint32 value);
|
||||||
|
virtual void SetSections(BRect area);
|
||||||
|
virtual void GetSeperatorWidth(uint32 *width);
|
||||||
|
|
||||||
|
virtual void DoUpPress();
|
||||||
|
virtual void DoDownPress();
|
||||||
|
|
||||||
|
virtual void DispatchMessage();
|
||||||
|
virtual void BuildDispatch(BMessage *) = 0;
|
||||||
|
|
||||||
|
BBitmap *f_up;
|
||||||
|
BBitmap *f_down;
|
||||||
|
BList *f_sections;
|
||||||
|
|
||||||
|
BRect f_uprect;
|
||||||
|
BRect f_downrect;
|
||||||
|
BRect f_sectionsarea;
|
||||||
|
|
||||||
|
int32 f_focus;
|
||||||
|
uint32 f_sectioncount;
|
||||||
|
uint32 f_holdvalue;
|
||||||
|
|
||||||
|
bool f_showfocus;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -45,7 +45,7 @@ TSettingsView::MessageReceived(BMessage *message)
|
|||||||
message->FindInt32(B_OBSERVE_WHAT_CHANGE, &change);
|
message->FindInt32(B_OBSERVE_WHAT_CHANGE, &change);
|
||||||
switch(change)
|
switch(change)
|
||||||
{
|
{
|
||||||
case OB_TM_CHANGED:
|
case H_TM_CHANGED:
|
||||||
UpdateDateTime(message);
|
UpdateDateTime(message);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ TSettingsView::InitView()
|
|||||||
// left side
|
// left side
|
||||||
frame.InsetBy(6, 6);
|
frame.InsetBy(6, 6);
|
||||||
frame.bottom = frame.top +text_height +6;
|
frame.bottom = frame.top +text_height +6;
|
||||||
f_dateedit = new TDateEdit(frame, "date_edit");
|
f_dateedit = new TDateEdit(frame, "date_edit", 3);
|
||||||
|
|
||||||
frame.top = f_dateedit->Frame().bottom;
|
frame.top = f_dateedit->Frame().bottom;
|
||||||
frame.bottom = bounds.bottom;
|
frame.bottom = bounds.bottom;
|
||||||
@@ -97,13 +97,14 @@ TSettingsView::InitView()
|
|||||||
frame.InsetBy(26, 6);
|
frame.InsetBy(26, 6);
|
||||||
frame.bottom = frame.top +text_height +6;
|
frame.bottom = frame.top +text_height +6;
|
||||||
frame.right += 4;
|
frame.right += 4;
|
||||||
f_timeedit = new TTimeEdit(frame, "time_edit");
|
f_timeedit = new TTimeEdit(frame, "time_edit", 4);
|
||||||
|
|
||||||
frame.top = f_timeedit->Frame().bottom;
|
frame.top = f_timeedit->Frame().bottom;
|
||||||
frame.bottom = bounds.bottom -(text_height *3);
|
frame.bottom = bounds.bottom -(text_height *3);
|
||||||
frame.InsetBy(10, 10);
|
frame.InsetBy(10, 10);
|
||||||
f_clock = new TAnalogClock(frame, "analog clock",
|
f_clock = new TAnalogClock(frame, "analog clock",
|
||||||
B_FOLLOW_NONE, B_WILL_DRAW);
|
B_FOLLOW_NONE, B_WILL_DRAW);
|
||||||
|
AddChild(f_timeedit);
|
||||||
|
|
||||||
// clock radio buttons
|
// clock radio buttons
|
||||||
frame = bounds.InsetByCopy(6, 10);
|
frame = bounds.InsetByCopy(6, 10);
|
||||||
@@ -117,15 +118,14 @@ 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", new BMessage(OB_RTC_CHANGE));
|
f_local = new BRadioButton(frame, "local", "Local time", new BMessage(H_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", new BMessage(OB_RTC_CHANGE));
|
f_gmt = new BRadioButton(frame, "gmt", "GMT", new BMessage(H_RTC_CHANGE));
|
||||||
AddChild(f_gmt);
|
AddChild(f_gmt);
|
||||||
|
|
||||||
AddChild(text);
|
AddChild(text);
|
||||||
AddChild(f_timeedit);
|
|
||||||
AddChild(f_clock);
|
AddChild(f_clock);
|
||||||
|
|
||||||
if (f_islocal)
|
if (f_islocal)
|
||||||
|
|||||||
@@ -11,14 +11,14 @@
|
|||||||
TTZDisplay::TTZDisplay(BRect frame, const char *name,
|
TTZDisplay::TTZDisplay(BRect frame, const char *name,
|
||||||
uint32 resizingmode, uint32 flags,
|
uint32 resizingmode, uint32 flags,
|
||||||
const char *label, const char *text,
|
const char *label, const char *text,
|
||||||
int32 hour, int32 minute, int32 second)
|
int32 hour, int32 minute)
|
||||||
: BView(frame, name, resizingmode, flags)
|
: BView(frame, name, resizingmode, flags)
|
||||||
{
|
{
|
||||||
f_label = new BString(label);
|
f_label = new BString(label);
|
||||||
f_text = new BString(text);
|
f_text = new BString(text);
|
||||||
f_time = new BString();
|
f_time = new BString();
|
||||||
|
|
||||||
SetTo(hour, minute, second);
|
SetTo(hour, minute);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ TTZDisplay::SetText(const char *text)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TTZDisplay::SetTo(int32 hour, int32 minute, int32 second)
|
TTZDisplay::SetTo(int32 hour, int32 minute)
|
||||||
{
|
{
|
||||||
// format time into f_time
|
// format time into f_time
|
||||||
if (f_time == NULL)
|
if (f_time == NULL)
|
||||||
@@ -115,10 +115,10 @@ TTZDisplay::SetTo(int32 hour, int32 minute, int32 second)
|
|||||||
ahour = 12;
|
ahour = 12;
|
||||||
|
|
||||||
char *ap;
|
char *ap;
|
||||||
if (hour> 12)
|
if (hour> 11)
|
||||||
ap = "pm";
|
ap = "PM";
|
||||||
else
|
else
|
||||||
ap = "am";
|
ap = "AM";
|
||||||
|
|
||||||
char *time = f_time->LockBuffer(8);
|
char *time = f_time->LockBuffer(8);
|
||||||
sprintf(time, "%02lu:%02lu %s", ahour, minute, ap);
|
sprintf(time, "%02lu:%02lu %s", ahour, minute, ap);
|
||||||
@@ -126,3 +126,24 @@ TTZDisplay::SetTo(int32 hour, int32 minute, int32 second)
|
|||||||
|
|
||||||
Draw(Bounds());
|
Draw(Bounds());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
TTZDisplay::Text() const
|
||||||
|
{
|
||||||
|
return f_text->String();
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
TTZDisplay::Label() const
|
||||||
|
{
|
||||||
|
return f_label->String();
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
TTZDisplay::Time() const
|
||||||
|
{
|
||||||
|
return f_time->String();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class TTZDisplay: public BView
|
|||||||
TTZDisplay(BRect frame, const char *name, uint32 resizing, uint32 flags,
|
TTZDisplay(BRect frame, const char *name, uint32 resizing, uint32 flags,
|
||||||
const char *label = B_EMPTY_STRING,
|
const char *label = B_EMPTY_STRING,
|
||||||
const char *name = B_EMPTY_STRING,
|
const char *name = B_EMPTY_STRING,
|
||||||
int32 hour = 0, int32 minute = 0, int32 second = 0);
|
int32 hour = 0, int32 minute = 0);
|
||||||
~TTZDisplay();
|
~TTZDisplay();
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
virtual void MessageReceived(BMessage *message);
|
virtual void MessageReceived(BMessage *message);
|
||||||
@@ -19,7 +19,11 @@ class TTZDisplay: public BView
|
|||||||
|
|
||||||
virtual void SetLabel(const char *label);
|
virtual void SetLabel(const char *label);
|
||||||
virtual void SetText(const char *text);
|
virtual void SetText(const char *text);
|
||||||
virtual void SetTo(int32 hour, int32 minute, int32 second);
|
virtual void SetTo(int32 hour, int32 minute);
|
||||||
|
|
||||||
|
virtual const char *Label() const;
|
||||||
|
virtual const char *Text() const;
|
||||||
|
virtual const char *Time() const;
|
||||||
private:
|
private:
|
||||||
BString *f_label;
|
BString *f_label;
|
||||||
BString *f_text;
|
BString *f_text;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ int main()
|
|||||||
|
|
||||||
|
|
||||||
TimeApplication::TimeApplication()
|
TimeApplication::TimeApplication()
|
||||||
:BApplication(OBOS_APP_SIGNATURE)
|
:BApplication(HAIKU_APP_SIGNATURE)
|
||||||
{
|
{
|
||||||
f_settings = new TimeSettings();
|
f_settings = new TimeSettings();
|
||||||
f_window = new TTimeWindow();
|
f_window = new TTimeWindow();
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
|
|
||||||
#include "TimeWindow.h"
|
|
||||||
#include "TimeSettings.h"
|
#include "TimeSettings.h"
|
||||||
|
#include "TimeWindow.h"
|
||||||
|
|
||||||
class TimeApplication : public BApplication {
|
class TimeApplication : public BApplication {
|
||||||
public:
|
public:
|
||||||
|
|||||||
Binary file not shown.
@@ -7,33 +7,35 @@
|
|||||||
#ifndef TIME_MESSAGES_H
|
#ifndef TIME_MESSAGES_H
|
||||||
#define TIME_MESSAGES_H
|
#define TIME_MESSAGES_H
|
||||||
|
|
||||||
#define OBOS_APP_SIGNATURE "application/x-vnd.OpenBeOS-TIME"
|
#define HAIKU_APP_SIGNATURE "application/x-vnd.Haiku-TIME"
|
||||||
|
|
||||||
const uint32 ERROR_DETECTED = 'ERor';
|
const uint32 ERROR_DETECTED = 'ERor';
|
||||||
|
|
||||||
//Timezonemessages
|
//Timezone messages
|
||||||
const uint32 REGION_CHANGED = 'REch';
|
const uint32 H_REGION_CHANGED = 'h_RC';
|
||||||
const uint32 TIME_ZONE_CHANGED = 'TZch';
|
const uint32 H_CITY_CHANGED = 'h_CC';
|
||||||
|
const uint32 H_CITY_SET = 'h_CS';
|
||||||
|
|
||||||
|
|
||||||
//SetButton
|
//SetButton
|
||||||
const uint32 SET_TIME_ZONE = 'SEti';
|
const uint32 H_SET_TIME_ZONE = 'hSTZ';
|
||||||
|
|
||||||
//local and GMT settings
|
//local and GMT settings
|
||||||
const uint32 RTC_SETTINGS = 'RTse';
|
const uint32 RTC_SETTINGS = 'RTse';
|
||||||
|
|
||||||
// clock tick message
|
// clock tick message
|
||||||
const uint32 OB_TIME_UPDATE ='obTU';
|
const uint32 H_TIME_UPDATE ='obTU';
|
||||||
|
|
||||||
// clicked on day in claendar
|
// clicked on day in claendar
|
||||||
const uint32 OB_DAY_CHANGED = 'obDC';
|
const uint32 H_DAY_CHANGED = 'obDC';
|
||||||
|
|
||||||
//notice for clock ticks
|
//notice for clock ticks
|
||||||
const uint32 OB_TM_CHANGED = 'obTC';
|
const uint32 H_TM_CHANGED = 'obTC';
|
||||||
|
|
||||||
//notice for user changes
|
//notice for user changes
|
||||||
const uint32 OB_USER_CHANGE = 'obUC';
|
const uint32 H_USER_CHANGE = 'obUC';
|
||||||
|
|
||||||
// local/gmt radiobuttons
|
// local/gmt radiobuttons
|
||||||
const uint32 OB_RTC_CHANGE = 'obRC';
|
const uint32 H_RTC_CHANGE = 'obRC';
|
||||||
|
|
||||||
#endif //TIME_MESSAGES_H
|
#endif //TIME_MESSAGES_H
|
||||||
|
|||||||
@@ -46,28 +46,19 @@ void
|
|||||||
TTimeWindow::MessageReceived(BMessage *message)
|
TTimeWindow::MessageReceived(BMessage *message)
|
||||||
{
|
{
|
||||||
switch(message->what) {
|
switch(message->what) {
|
||||||
case OB_USER_CHANGE:
|
case H_USER_CHANGE:
|
||||||
{
|
{
|
||||||
bool istime;
|
bool istime;
|
||||||
if (message->FindBool("time", &istime) == B_OK)
|
if (message->FindBool("time", &istime) == B_OK)
|
||||||
f_BaseView->ChangeTime(message);
|
f_BaseView->ChangeTime(message);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case OB_RTC_CHANGE:
|
case H_RTC_CHANGE:
|
||||||
{
|
{
|
||||||
f_BaseView->SetGMTime(f_TimeSettings->GMTime());
|
f_BaseView->SetGMTime(f_TimeSettings->GMTime());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case REGION_CHANGED:
|
|
||||||
f_TimeZones->ChangeRegion(message);
|
|
||||||
break;
|
|
||||||
case SET_TIME_ZONE:
|
|
||||||
f_TimeZones->SetTimeZone();
|
|
||||||
break;
|
|
||||||
case TIME_ZONE_CHANGED:
|
|
||||||
f_TimeZones->NewTimeZone();
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
BWindow::MessageReceived(message);
|
BWindow::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -3,11 +3,10 @@
|
|||||||
|
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
/////////////////////////////////
|
#include "BaseView.h"
|
||||||
#include "SettingsView.h"
|
#include "SettingsView.h"
|
||||||
#include "TimeSettings.h"
|
#include "TimeSettings.h"
|
||||||
#include "ZoneView.h"
|
#include "ZoneView.h"
|
||||||
#include "BaseView.h"
|
|
||||||
|
|
||||||
class TTimeWindow : public BWindow {
|
class TTimeWindow : public BWindow {
|
||||||
public:
|
public:
|
||||||
|
|||||||
+283
-126
@@ -1,8 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
TZoneView.cpp
|
ZoneView.cpp
|
||||||
|
by Mike Berg (inseculous)
|
||||||
|
|
||||||
|
Status: mimics original Time Zone tab of Time Pref App
|
||||||
|
Exceptions: doesn't calc "Time in" time.
|
||||||
|
Issues: After experimenting with both Time Prefs, it seems the original doesn't
|
||||||
|
use the link file in the users settings file to get the current Timezone.
|
||||||
|
Need to find the call it uses to get its inital info so I can get exact duplication.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
|
|
||||||
#include <Directory.h>
|
#include <Directory.h>
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <FindDirectory.h>
|
#include <FindDirectory.h>
|
||||||
@@ -10,47 +18,53 @@
|
|||||||
#include <MenuField.h>
|
#include <MenuField.h>
|
||||||
#include <MenuItem.h>
|
#include <MenuItem.h>
|
||||||
#include <MenuBar.h>
|
#include <MenuBar.h>
|
||||||
#include <Path.h>
|
|
||||||
#include <PopUpMenu.h>
|
#include <PopUpMenu.h>
|
||||||
#include <ScrollView.h>
|
#include <ScrollView.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <StorageDefs.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
#include <Window.h>
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "TimeMessages.h"
|
#include "TimeMessages.h"
|
||||||
#include "ZoneView.h"
|
#include "ZoneView.h"
|
||||||
|
|
||||||
|
|
||||||
/*=====> TZoneItem <=====*/
|
/*=====> TZoneItem <=====*/
|
||||||
|
TZoneItem::TZoneItem(const char *text, const char *zone)
|
||||||
TZoneItem::TZoneItem(const char *text, const char *zonedata)
|
|
||||||
: BStringItem(text)
|
: BStringItem(text)
|
||||||
{
|
{
|
||||||
f_zonedata = new BPath(zonedata);
|
f_zone = new BPath(zone);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TZoneItem::~TZoneItem()
|
TZoneItem::~TZoneItem()
|
||||||
{
|
{
|
||||||
delete f_zonedata;
|
delete f_zone;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
TZoneItem::Zone() const
|
||||||
|
{
|
||||||
|
return f_zone->Leaf();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
TZoneItem::GetZone() const
|
TZoneItem::Path() const
|
||||||
{
|
{
|
||||||
return f_zonedata->Leaf();
|
return f_zone->Path();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*=====> TZoneView <=====*/
|
/*=====> TZoneView <=====*/
|
||||||
|
|
||||||
TZoneView::TZoneView(BRect frame)
|
TZoneView::TZoneView(BRect frame)
|
||||||
: BView(frame, "", B_FOLLOW_ALL,
|
: BView(frame, B_EMPTY_STRING, B_FOLLOW_ALL, B_WILL_DRAW|B_NAVIGABLE_JUMP)
|
||||||
B_WILL_DRAW|B_FRAME_EVENTS|B_NAVIGABLE_JUMP|B_PULSE_NEEDED)
|
, f_first(true)
|
||||||
, f_citylist(NULL)
|
|
||||||
{
|
{
|
||||||
|
ReadTimeZoneLink();
|
||||||
InitView();
|
InitView();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,11 +74,45 @@ TZoneView::~TZoneView()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TZoneView::AllAttached()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TZoneView::AttachedToWindow()
|
TZoneView::AttachedToWindow()
|
||||||
{
|
{
|
||||||
if (Parent())
|
if (Parent())
|
||||||
SetViewColor(Parent()->ViewColor());
|
SetViewColor(Parent()->ViewColor());
|
||||||
|
|
||||||
|
if (f_first) // stupid hack
|
||||||
|
{
|
||||||
|
f_regionpopup->SetTargetForItems(this);
|
||||||
|
f_setzone->SetTarget(this);
|
||||||
|
f_citylist->SetTarget(this);
|
||||||
|
// update displays
|
||||||
|
BPath parent;
|
||||||
|
f_currentzone.GetParent(&parent);
|
||||||
|
int czone = FillCityList(parent.Path());
|
||||||
|
if (czone> -1) {
|
||||||
|
f_citylist->Select(czone);
|
||||||
|
f_current->SetText( ((TZoneItem *)f_citylist->ItemAt(czone))->Text() );
|
||||||
|
}
|
||||||
|
f_first = false;
|
||||||
|
}
|
||||||
|
f_citylist->ScrollToSelection();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TZoneView::Draw(BRect updaterect)
|
||||||
|
{
|
||||||
|
f_current->Draw(updaterect);
|
||||||
|
f_preview->Draw(updaterect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -76,7 +124,7 @@ TZoneView::MessageReceived(BMessage *message)
|
|||||||
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 H_TM_CHANGED:
|
||||||
UpdateDateTime(message);
|
UpdateDateTime(message);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -85,34 +133,43 @@ TZoneView::MessageReceived(BMessage *message)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case H_REGION_CHANGED:
|
||||||
|
ChangeRegion(message);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case H_SET_TIME_ZONE:
|
||||||
|
SetTimeZone();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case H_CITY_CHANGED:
|
||||||
|
SetPreview();
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BView::MessageReceived(message);
|
BView::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
TZoneView::Draw(BRect updaterect)
|
|
||||||
{
|
|
||||||
f_currentzone->Draw(updaterect);
|
|
||||||
f_timeinzone->Draw(updaterect);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TZoneView::UpdateDateTime(BMessage *message)
|
TZoneView::UpdateDateTime(BMessage *message)
|
||||||
{
|
{
|
||||||
int32 hour, minute, second;
|
// only need hour and minute
|
||||||
|
int32 hour, minute;
|
||||||
|
|
||||||
if (message->FindInt32("hour", &hour) == B_OK
|
if (message->FindInt32("hour", &hour) == B_OK
|
||||||
&& message->FindInt32("minute", &minute) == B_OK
|
&& message->FindInt32("minute", &minute) == B_OK) {
|
||||||
&& message->FindInt32("second", &second) == B_OK)
|
if (f_hour != hour || f_minute != minute) {
|
||||||
{
|
f_hour = hour;
|
||||||
f_currentzone->SetTo(hour, minute, second);
|
f_minute = minute;
|
||||||
|
f_current->SetTo(hour, minute);
|
||||||
|
|
||||||
// do calc to get other zone time
|
if (f_citylist->CurrentSelection()> -1) {
|
||||||
f_timeinzone->SetTo(hour, minute, second);
|
// do calc to get other zone time
|
||||||
|
SetPreview();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,22 +181,20 @@ TZoneView:: InitView()
|
|||||||
be_plain_font->GetHeight(&finfo);
|
be_plain_font->GetHeight(&finfo);
|
||||||
float text_height = finfo.ascent +finfo.descent +finfo.leading;
|
float text_height = finfo.ascent +finfo.descent +finfo.leading;
|
||||||
|
|
||||||
GetCurrentRegion();
|
|
||||||
|
|
||||||
BRect bounds(Bounds().InsetByCopy(4, 2));
|
BRect bounds(Bounds().InsetByCopy(4, 2));
|
||||||
BRect frame(bounds);
|
BRect frame(bounds);
|
||||||
|
|
||||||
// Zone menu
|
// Zone menu
|
||||||
f_zonepopup = new BPopUpMenu("", true, true, B_ITEMS_IN_COLUMN);
|
f_regionpopup = new BPopUpMenu(B_EMPTY_STRING, true, true, B_ITEMS_IN_COLUMN);
|
||||||
|
|
||||||
float widest = 0;
|
float widest = 0;
|
||||||
CreateZoneMenu(&widest);
|
BuildRegionMenu(&widest);
|
||||||
|
|
||||||
frame.right = frame.left +widest +25;
|
frame.right = frame.left +widest +25;
|
||||||
frame.bottom = frame.top +text_height -1;
|
frame.bottom = frame.top +text_height -1;
|
||||||
|
|
||||||
BMenuField *mField;
|
BMenuField *mField;
|
||||||
mField= new BMenuField(frame, "mfield", NULL, f_zonepopup, true);
|
mField= new BMenuField(frame, "regions", NULL, f_regionpopup, true);
|
||||||
mField->MenuBar()->SetBorder(B_BORDER_CONTENTS);
|
mField->MenuBar()->SetBorder(B_BORDER_CONTENTS);
|
||||||
mField->MenuBar()->ResizeToPreferred();
|
mField->MenuBar()->ResizeToPreferred();
|
||||||
AddChild(mField);
|
AddChild(mField);
|
||||||
@@ -158,9 +213,12 @@ TZoneView:: InitView()
|
|||||||
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(H_CITY_CHANGED);
|
||||||
f_citylist->SetSelectionMessage(citychange);
|
f_citylist->SetSelectionMessage(citychange);
|
||||||
|
|
||||||
|
BMessage *cityinvoke = new BMessage(H_SET_TIME_ZONE);
|
||||||
|
f_citylist->SetInvocationMessage(cityinvoke);
|
||||||
|
|
||||||
BScrollView *scrollList;
|
BScrollView *scrollList;
|
||||||
scrollList = new BScrollView("scroll_list", f_citylist,
|
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);
|
||||||
@@ -172,41 +230,33 @@ TZoneView:: InitView()
|
|||||||
frame.OffsetBy(scrollList->Bounds().Width() +9, 3);
|
frame.OffsetBy(scrollList->Bounds().Width() +9, 3);
|
||||||
frame.bottom = frame.top +text_height *2;
|
frame.bottom = frame.top +text_height *2;
|
||||||
frame.right = bounds.right -6;
|
frame.right = bounds.right -6;
|
||||||
f_currentzone = new TTZDisplay(frame, "current",
|
f_current = new TTZDisplay(frame, "current",
|
||||||
B_FOLLOW_LEFT|B_FOLLOW_TOP, 0,
|
B_FOLLOW_LEFT|B_FOLLOW_TOP, 0,
|
||||||
"Current time zone:", B_EMPTY_STRING);
|
"Current time zone:", B_EMPTY_STRING);
|
||||||
f_currentzone->ResizeToPreferred();
|
f_current->ResizeToPreferred();
|
||||||
|
|
||||||
frame.OffsetBy(0, (text_height *3) +2);
|
frame.OffsetBy(0, (text_height *3) +2);
|
||||||
f_timeinzone = new TTZDisplay(frame, "timein",
|
f_preview = new TTZDisplay(frame, "timein",
|
||||||
B_FOLLOW_LEFT|B_FOLLOW_TOP, 0,
|
B_FOLLOW_LEFT|B_FOLLOW_TOP, 0,
|
||||||
"Time in: ", B_EMPTY_STRING);
|
"Time in: ", B_EMPTY_STRING);
|
||||||
f_timeinzone->ResizeToPreferred();
|
f_preview->ResizeToPreferred();
|
||||||
|
|
||||||
AddChild(f_currentzone);
|
|
||||||
AddChild(f_timeinzone);
|
|
||||||
|
|
||||||
|
AddChild(f_current);
|
||||||
|
AddChild(f_preview);
|
||||||
|
|
||||||
// set button
|
// set button
|
||||||
|
|
||||||
frame.Set(bounds.right -75, bounds.bottom -24,
|
frame.Set(bounds.right -75, bounds.bottom -24,
|
||||||
bounds.right, bounds.bottom);
|
bounds.right, bounds.bottom);
|
||||||
frame.OffsetBy(-2, -2);
|
frame.OffsetBy(-2, -2);
|
||||||
f_settimezone = new BButton(frame, "set", "Set", new BMessage(SET_TIME_ZONE));
|
f_setzone = new BButton(frame, "set", "Set", new BMessage(H_SET_TIME_ZONE));
|
||||||
f_settimezone->SetEnabled(false);
|
f_setzone->SetEnabled(false);
|
||||||
AddChild(f_settimezone);
|
AddChild(f_setzone);
|
||||||
|
|
||||||
// update displays
|
|
||||||
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() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TZoneView::CreateZoneMenu(float *widest)
|
TZoneView::BuildRegionMenu(float *widest)
|
||||||
{
|
{
|
||||||
BPath path;
|
BPath path;
|
||||||
// return if /etc directory is not found
|
// return if /etc directory is not found
|
||||||
@@ -215,138 +265,195 @@ TZoneView::CreateZoneMenu(float *widest)
|
|||||||
|
|
||||||
path.Append("timezones");
|
path.Append("timezones");
|
||||||
|
|
||||||
|
// get current region
|
||||||
|
BPath region;
|
||||||
|
f_currentzone.GetParent(®ion);
|
||||||
|
|
||||||
float width = 0;
|
float width = 0;
|
||||||
bool markitem;
|
bool markit;
|
||||||
BEntry entry;
|
BEntry entry;
|
||||||
BMenuItem *zoneItem;
|
BMenuItem *item;
|
||||||
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();
|
||||||
|
|
||||||
|
// skip Etc directory
|
||||||
if (itemtext.Compare("Etc", 3) == 0)
|
if (itemtext.Compare("Etc", 3) == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
markit = itemtext.Compare(region.Leaf()) == 0;
|
||||||
|
|
||||||
// add Ocean to oceans :)
|
// add Ocean to oceans :)
|
||||||
if ((itemtext.Compare("Atlantic", 8) == 0)
|
if (itemtext.Compare("Atlantic", 8) == 0
|
||||||
||(itemtext.Compare("Pacific", 7) == 0)
|
||itemtext.Compare("Pacific", 7) == 0
|
||||||
||(itemtext.Compare("Indian", 6) == 0))
|
||itemtext.Compare("Indian", 6) == 0)
|
||||||
itemtext.Append(" Ocean");
|
itemtext.Append(" Ocean");
|
||||||
|
|
||||||
markitem = itemtext.Compare(f_RegionStr.Leaf()) == 0;
|
itemtext = itemtext.ReplaceAll('_', ' '); // underscores are spaces
|
||||||
itemtext = itemtext.ReplaceAll('_', ' ');
|
|
||||||
|
|
||||||
width = be_plain_font->StringWidth(itemtext.String());
|
width = be_plain_font->StringWidth(itemtext.String());
|
||||||
if (width> *widest) *widest = width;
|
if (width> *widest) *widest = width;
|
||||||
|
|
||||||
BMessage *zoneMessage = new BMessage(REGION_CHANGED);
|
BMessage *msg = new BMessage(H_REGION_CHANGED);
|
||||||
zoneMessage->AddString("region", path.Leaf());
|
msg->AddString("region", path.Path());
|
||||||
|
|
||||||
zoneItem = new BMenuItem(itemtext.String(), zoneMessage);
|
item = new BMenuItem(itemtext.String(), msg);
|
||||||
zoneItem->SetMarked(markitem);
|
item->SetMarked(markit);
|
||||||
f_zonepopup->AddItem(zoneItem);
|
f_regionpopup->AddItem(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
TZoneView::ChangeRegion(BMessage *message)
|
|
||||||
{
|
|
||||||
const char *area;
|
|
||||||
message->FindString("region", &area);
|
|
||||||
|
|
||||||
FillZoneList(area);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
TZoneView::FillZoneList(const char *area)
|
TZoneView::FillCityList(const char *area)
|
||||||
{
|
{
|
||||||
//clear listview from previous items
|
// clear list
|
||||||
f_citylist->MakeEmpty();
|
|
||||||
|
// MakeEmpty() doesn't free items so...
|
||||||
|
int32 idx = f_citylist->CountItems();
|
||||||
|
if (idx>= 1)
|
||||||
|
for (; idx>= 0; idx--)
|
||||||
|
delete f_citylist->RemoveItem(idx);
|
||||||
|
|
||||||
//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
|
||||||
|
|
||||||
BPath path;
|
BPath path;
|
||||||
|
|
||||||
// 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 0;
|
return 0;
|
||||||
|
|
||||||
path.Append("timezones");
|
path.Append("timezones");
|
||||||
|
|
||||||
|
BPath Area(area);
|
||||||
BDirectory zoneDir(path.Path());
|
BDirectory zoneDir(path.Path());
|
||||||
BDirectory cityDir;
|
BDirectory cityDir;
|
||||||
BStringItem *city;
|
BStringItem *city;
|
||||||
BString city_name;
|
BString city_name;
|
||||||
entry_ref ref;
|
BEntry entry;
|
||||||
|
int index = -1;
|
||||||
int index = 0; // index of current setting
|
|
||||||
//locate subdirectory:
|
//locate subdirectory:
|
||||||
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) {
|
|
||||||
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)
|
if ( zoneDir.Contains(Area.Leaf(), B_DIRECTORY_NODE)) {
|
||||||
index = f_citylist->IndexOf(city);
|
cityDir.SetTo(&zoneDir, Area.Leaf());
|
||||||
|
//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.GetNextEntry(&entry) == B_NO_ERROR) {
|
||||||
|
if (!entry.IsDirectory()) {
|
||||||
|
BPath zone(&entry);
|
||||||
|
city_name = zone.Leaf();
|
||||||
|
city_name.ReplaceAll("_IN", ", Indiana");
|
||||||
|
city_name.ReplaceAll("__Calif", ", Calif");
|
||||||
|
city_name.ReplaceAll("__", ", ");
|
||||||
|
city_name.ReplaceAll("_", " ");
|
||||||
|
city = new TZoneItem(city_name.String(), zone.Path());
|
||||||
|
f_citylist->AddItem(city);
|
||||||
|
if (strcmp(f_currentzone.Leaf(), zone.Leaf()) == 0)
|
||||||
|
index = f_citylist->IndexOf(city);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("%d\n", index);
|
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TZoneView::GetCurrentTZ()
|
TZoneView::ChangeRegion(BMessage *message)
|
||||||
{
|
{
|
||||||
|
BString area;
|
||||||
|
message->FindString("region", &area);
|
||||||
|
|
||||||
|
FillCityList(area.String());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TZoneView::ReadTimeZoneLink()
|
||||||
|
{
|
||||||
|
/* reads the timezone symlink from B_USER_SETTINGS_DIRECTORY
|
||||||
|
currently this sets f_currentzone to the symlink value.
|
||||||
|
this is wrong. the original can get users timezone without
|
||||||
|
a timezone symlink present.
|
||||||
|
|
||||||
|
defaults are set to different values to clue in on what error was returned
|
||||||
|
GMT is set when the link is invalid
|
||||||
|
EST is set when the settings dir can't be found **should never happen**
|
||||||
|
*/
|
||||||
|
|
||||||
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() != B_OK) {// link is broken
|
||||||
|
tzLink.SetTo("/boot/beos/etc/timezones/Pacific/fiji");
|
||||||
// do something like set to a default GMT???
|
// do something like set to a default GMT???
|
||||||
// return;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// set tzlink to default
|
// set tzlink to a default
|
||||||
|
tzLink.SetTo("/boot/beos/etc/timezones/EST");
|
||||||
}
|
}
|
||||||
|
|
||||||
// we need something in the current zone
|
// we need something in the current zone
|
||||||
f_ZoneStr.SetTo(&tzLink);
|
f_currentzone.SetTo(&tzLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TZoneView::GetCurrentRegion()
|
TZoneView::SetPreview()
|
||||||
{
|
{
|
||||||
GetCurrentTZ();
|
// calc and display time based on users selection in city list
|
||||||
|
|
||||||
f_ZoneStr.GetParent(&f_RegionStr);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
TZoneView::NewTimeZone()
|
|
||||||
{
|
|
||||||
BString text;
|
|
||||||
int32 selection = f_citylist->CurrentSelection();
|
int32 selection = f_citylist->CurrentSelection();
|
||||||
text = ((TZoneItem *)f_citylist->ItemAt(selection))->Text();
|
if (selection>= 0) {
|
||||||
f_timeinzone->SetText(text.String());
|
TZoneItem *item = (TZoneItem *)f_citylist->ItemAt(selection);
|
||||||
f_settimezone->SetEnabled(true);
|
|
||||||
|
BString text;
|
||||||
|
text = item->Text();
|
||||||
|
|
||||||
|
time_t current;
|
||||||
|
struct tm *ltime;
|
||||||
|
|
||||||
|
// calc time to display and update
|
||||||
|
SetTimeZone(item->Path());
|
||||||
|
current = time(0);
|
||||||
|
ltime = localtime(¤t);
|
||||||
|
SetTimeZone(f_currentzone.Path());
|
||||||
|
|
||||||
|
f_preview->SetTo(ltime->tm_hour, ltime->tm_min);
|
||||||
|
f_preview->SetText(text.String());
|
||||||
|
|
||||||
|
f_setzone->SetEnabled((strcmp(f_current->Text(), text.String()) != 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TZoneView::SetCurrent(const char *text)
|
||||||
|
{
|
||||||
|
time_t current;
|
||||||
|
struct tm *ltime;
|
||||||
|
SetTimeZone(f_currentzone.Path());
|
||||||
|
current = time(0);
|
||||||
|
ltime = localtime(¤t);
|
||||||
|
|
||||||
|
f_current->SetTo(ltime->tm_hour, ltime->tm_min);
|
||||||
|
f_current->SetText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -355,9 +462,15 @@ TZoneView::SetTimeZone()
|
|||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
set time based on supplied timezone. How to do this?
|
set time based on supplied timezone. How to do this?
|
||||||
replace symlink, "timezone", in B_USER_SETTINGS_DIR with a link to the new timezone
|
1) replace symlink, "timezone", in B_USER_SETTINGS_DIR with a link to the new timezone
|
||||||
|
2) set TZ environment var
|
||||||
|
3) call settz()
|
||||||
|
4) call set_timezone from OS.h passing path to timezone file
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// update/create timezone symlink in B_USER_SETTINGS_DIRECTORY
|
||||||
|
|
||||||
// get path to current link
|
// get path to current link
|
||||||
BPath path;
|
BPath path;
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
||||||
@@ -365,26 +478,70 @@ TZoneView::SetTimeZone()
|
|||||||
|
|
||||||
path.Append("timezone");
|
path.Append("timezone");
|
||||||
|
|
||||||
// build target from selection
|
|
||||||
BPath target;
|
// build target for new link
|
||||||
target.SetTo(f_RegionStr.Path());
|
|
||||||
|
|
||||||
int32 selection = f_citylist->CurrentSelection();
|
int32 selection = f_citylist->CurrentSelection();
|
||||||
target.Append(((TZoneItem *)f_citylist->ItemAt(selection))->GetZone());
|
if (selection < 0)
|
||||||
|
// nothing selected??
|
||||||
|
return;
|
||||||
|
|
||||||
// create dir object to create link and remove old
|
BPath target( ((TZoneItem *)f_citylist->ItemAt(selection))->Path());
|
||||||
BDirectory dir(target.Path());
|
|
||||||
|
// remove old
|
||||||
BEntry entry(path.Path());
|
BEntry entry(path.Path());
|
||||||
if (entry.Exists())
|
if (entry.Exists())
|
||||||
entry.Remove();
|
entry.Remove();
|
||||||
|
|
||||||
|
// create new
|
||||||
|
BDirectory dir(target.Path());
|
||||||
if (dir.CreateSymLink(path.Path(), target.Path(), NULL) != B_OK)
|
if (dir.CreateSymLink(path.Path(), target.Path(), NULL) != B_OK)
|
||||||
printf("timezone not linked\n");
|
printf("timezone not linked\n");
|
||||||
|
|
||||||
// disable button
|
// update environment
|
||||||
f_settimezone -> SetEnabled(false);
|
|
||||||
|
|
||||||
/*
|
char tz[B_PATH_NAME_LENGTH];
|
||||||
Still doesn't change runtime timezone setting.
|
sprintf(tz, "TZ=%s", target.Path());
|
||||||
*/
|
|
||||||
|
putenv( tz);
|
||||||
|
tzset();
|
||||||
|
|
||||||
|
// update display
|
||||||
|
time_t current = time(0);
|
||||||
|
struct tm *ltime = localtime(¤t);
|
||||||
|
|
||||||
|
|
||||||
|
char tza[B_PATH_NAME_LENGTH];
|
||||||
|
sprintf(tza, "%s", target.Path());
|
||||||
|
set_timezone(tza);
|
||||||
|
|
||||||
|
// disable button
|
||||||
|
f_setzone -> SetEnabled(false);
|
||||||
|
|
||||||
|
time_t newtime = mktime(ltime);
|
||||||
|
ltime = localtime(&newtime);
|
||||||
|
stime(&newtime);
|
||||||
|
|
||||||
|
f_hour = ltime->tm_hour;
|
||||||
|
f_minute = ltime->tm_min;
|
||||||
|
f_currentzone.SetTo(target.Path());
|
||||||
|
SetCurrent(((TZoneItem *)f_citylist->ItemAt(selection))->Text());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TZoneView::SetTimeZone(const char *zone)
|
||||||
|
{
|
||||||
|
BString tz;
|
||||||
|
|
||||||
|
tz << "TZ=" << zone;
|
||||||
|
|
||||||
|
putenv(tz.String());
|
||||||
|
tzset();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//---//
|
||||||
|
|||||||
+40
-32
@@ -1,61 +1,69 @@
|
|||||||
/*
|
/*
|
||||||
|
ZoneView.h
|
||||||
TZoneView.h
|
Header file for the base class of the Time Zone tab in Time Pref App.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef ZONE_VIEW_H
|
#ifndef ZONE_VIEW_H
|
||||||
#define ZONE_VIEW_H
|
#define ZONE_VIEW_H
|
||||||
|
|
||||||
#include <Path.h>
|
|
||||||
#include <String.h>
|
|
||||||
#include <ListItem.h>
|
#include <ListItem.h>
|
||||||
|
#include <Path.h>
|
||||||
|
#include <View.h>
|
||||||
|
|
||||||
#include "TZDisplay.h"
|
#include "TZDisplay.h"
|
||||||
|
|
||||||
class TZoneItem: public BStringItem {
|
class TZoneItem: public BStringItem {
|
||||||
public:
|
public:
|
||||||
TZoneItem(const char *text, const char *zonedata);
|
TZoneItem(const char *text, const char *zone);
|
||||||
virtual ~TZoneItem();
|
virtual ~TZoneItem();
|
||||||
|
|
||||||
const char *GetZone() const;
|
const char *Zone() const;
|
||||||
|
const char *Path() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BPath *f_zonedata;
|
BPath *f_zone;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TZoneView : public BView {
|
|
||||||
|
|
||||||
|
class TZoneView: public BView{
|
||||||
public:
|
public:
|
||||||
TZoneView(BRect frame);
|
TZoneView(BRect frame);
|
||||||
~TZoneView();
|
virtual ~TZoneView();
|
||||||
|
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
virtual void MessageReceived(BMessage *message);
|
virtual void AllAttached();
|
||||||
virtual void Draw(BRect);
|
virtual void Draw(BRect);
|
||||||
|
virtual void MessageReceived(BMessage *message);
|
||||||
void ChangeRegion(BMessage *region);
|
|
||||||
void SetTimeZone();
|
|
||||||
void NewTimeZone();
|
|
||||||
protected:
|
protected:
|
||||||
virtual void UpdateDateTime(BMessage *message);
|
void UpdateDateTime(BMessage *message);
|
||||||
|
void ChangeRegion(BMessage *);
|
||||||
|
void SetTimeZone();
|
||||||
|
void SetTimeZone(const char *zone);
|
||||||
|
void SetPreview();
|
||||||
|
void SetCurrent(const char *text);
|
||||||
private:
|
private:
|
||||||
void InitView();
|
virtual void InitView();
|
||||||
void GetCurrentTZ();
|
void ReadTimeZoneLink();
|
||||||
void GetCurrentRegion();
|
|
||||||
|
|
||||||
int FillZoneList(const char *area);
|
// set widest to font width of longest item
|
||||||
void CreateZoneMenu(float *widest);
|
void BuildRegionMenu(float *widest);
|
||||||
|
|
||||||
private:
|
// returns index of current zone
|
||||||
BPopUpMenu *f_zonepopup;
|
int FillCityList(const char *area);
|
||||||
|
|
||||||
|
BPopUpMenu *f_regionpopup;
|
||||||
BListView *f_citylist;
|
BListView *f_citylist;
|
||||||
BButton *f_settimezone;
|
BButton *f_setzone;
|
||||||
TTZDisplay *f_currentzone;
|
TTZDisplay *f_current;
|
||||||
TTZDisplay *f_timeinzone;
|
TTZDisplay *f_preview;
|
||||||
private:
|
|
||||||
BPath f_ZoneStr;
|
|
||||||
BPath f_RegionStr;
|
|
||||||
|
|
||||||
int f_hour;
|
BPath f_currentzone;
|
||||||
int f_minutes;
|
int32 f_hour;
|
||||||
char f_TimeStr[10];
|
int32 f_minute;
|
||||||
|
int32 f_diff;
|
||||||
|
bool f_first;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif //Zone_View_H
|
||||||
|
|||||||
Reference in New Issue
Block a user