* implemented Time, Date, DateTime classes to be used in CalendarView

* implemented new Calendarview, capable to show/hide week numbers and day names
   weekstart sunday/monday and getting the current selected date etc...

* updated mail addresses
* make use of the new calendar view in time prefs
* changed required classes to use the new date, time classes
* gmt/ local time change implementation is missing atm, will come next

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22554 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Karsten Heimrich
2007-10-14 13:53:53 +00:00
parent 1b8f7f13a3
commit 00826781d4
30 changed files with 2339 additions and 963 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Mike Berg (inseculous) * Mike Berg <mike@berg-net.us>
* Julun <[email protected]> * Julun <[email protected]>
* Stephan Aßmus <[email protected]> * Stephan Aßmus <[email protected]>
*/ */
+1 -1
View File
@@ -3,7 +3,7 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Mike Berg (inseculous) * Mike Berg <mike@berg-net.us>
* Julun <[email protected]> * Julun <[email protected]>
*/ */
#ifndef ANALOG_CLOCK_H #ifndef ANALOG_CLOCK_H
+44 -54
View File
@@ -3,21 +3,20 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Mike Berg (inseculous) * Mike Berg <mike@berg-net.us>
* Julun <[email protected]> * Julun <[email protected]>
*/ */
#include "BaseView.h" #include "BaseView.h"
#include "DateTime.h"
#include "TimeMessages.h" #include "TimeMessages.h"
#include <Message.h>
#include <OS.h> #include <OS.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),
fIsGMT(false),
fMessage(H_TIME_UPDATE) fMessage(H_TIME_UPDATE)
{ {
} }
@@ -32,7 +31,7 @@ void
TTimeBaseView::Pulse() TTimeBaseView::Pulse()
{ {
if (IsWatched()) if (IsWatched())
DispatchMessage(); _SendNotices();
} }
@@ -43,13 +42,6 @@ TTimeBaseView::AttachedToWindow()
} }
void
TTimeBaseView::SetGMTime(bool gmt)
{
fIsGMT = gmt;
}
void void
TTimeBaseView::ChangeTime(BMessage *message) TTimeBaseView::ChangeTime(BMessage *message)
{ {
@@ -57,64 +49,62 @@ TTimeBaseView::ChangeTime(BMessage *message)
if (message->FindBool("time", &isTime) != B_OK) if (message->FindBool("time", &isTime) != B_OK)
return; return;
time_t tmp = time(NULL); BDateTime dateTime = BDateTime::CurrentDateTime(B_LOCAL_TIME);
struct tm *tm_struct = localtime(&tmp);
if (isTime) { if (isTime) {
int32 hour = 0; BTime time = dateTime.Time();
if (message->FindInt32("hour", &hour) == B_OK) int32 hour;
tm_struct->tm_hour = hour; if (message->FindInt32("hour", &hour) != B_OK)
hour = time.Hour();
int32 minute = 0; int32 minute;
if (message->FindInt32("minute", &minute) == B_OK) if (message->FindInt32("minute", &minute) != B_OK)
tm_struct->tm_min = minute; minute = time.Minute();
int32 second = 0; int32 second;
if (message->FindInt32("second", &second) == B_OK) if (message->FindInt32("second", &second) != B_OK)
tm_struct->tm_sec = second; second = time.Second();
bool isAM = false; time.SetTime(hour, minute, second);
if (message->FindBool("isam", &isAM) == B_OK) { dateTime.SetTime(time);
if (!isAM)
tm_struct->tm_hour += 12;
}
} else { } else {
int32 month = 0; BDate date = dateTime.Date();
if (message->FindInt32("month", &month) == B_OK) int32 day;
tm_struct->tm_mon = month; if (message->FindInt32("day", &day) != B_OK)
day = date.Day();
int32 day = 0; int32 year;
if (message->FindInt32("day", &day) == B_OK) if (message->FindInt32("year", &year) != B_OK)
tm_struct->tm_mday = day; year = date.Year();
int32 year = 0; int32 month;
if (message->FindInt32("year", &year) == B_OK) if (message->FindInt32("month", &month) != B_OK)
tm_struct->tm_year = year; month = date.Month();
if (year >= 1970 && year <= 2037) {
date.SetDate(year, month, day);
dateTime.SetDate(date);
}
} }
tmp = mktime(tm_struct); set_real_time_clock(dateTime.Time_t());
set_real_time_clock(tmp);
} }
void void
TTimeBaseView::DispatchMessage() TTimeBaseView::_SendNotices()
{ {
time_t tmp = time(NULL);
struct tm *tm_struct = localtime(&tmp);
if (fIsGMT)
tm_struct = gmtime(&tmp);
fMessage.MakeEmpty(); fMessage.MakeEmpty();
BDate date = BDate::CurrentDate(B_LOCAL_TIME);
fMessage.AddInt32("day", date.Day());
fMessage.AddInt32("year", date.Year());
fMessage.AddInt32("month", date.Month());
fMessage.AddInt32("month", tm_struct->tm_mon); BTime time = BTime::CurrentTime(B_LOCAL_TIME);
fMessage.AddInt32("day", tm_struct->tm_mday); fMessage.AddInt32("hour", time.Hour());
fMessage.AddInt32("year", tm_struct->tm_year); fMessage.AddInt32("minute", time.Minute());
fMessage.AddInt32("second", time.Second());
fMessage.AddInt32("hour", tm_struct->tm_hour);
fMessage.AddInt32("minute", tm_struct->tm_min);
fMessage.AddInt32("second", tm_struct->tm_sec);
SendNotices(H_TM_CHANGED, &fMessage); SendNotices(H_TM_CHANGED, &fMessage);
} }
+4 -6
View File
@@ -3,15 +3,15 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Mike Berg (inseculous) * Mike Berg <mike@berg-net.us>
* Julun <[email protected]> * Julun <[email protected]>
*/ */
#ifndef TIMEBASE_H #ifndef TIMEBASE_H
#define TIMEBASE_H #define TIMEBASE_H
#include <View.h>
#include <Message.h> #include <Message.h>
#include <View.h>
class TTimeBaseView: public BView { class TTimeBaseView: public BView {
@@ -22,14 +22,12 @@ class TTimeBaseView: public BView {
virtual void Pulse(); virtual void Pulse();
virtual void AttachedToWindow(); virtual void AttachedToWindow();
void SetGMTime(bool gmtTime);
void ChangeTime(BMessage *message); void ChangeTime(BMessage *message);
protected: private:
virtual void DispatchMessage(); void _SendNotices();
private: private:
bool fIsGMT;
BMessage fMessage; BMessage fMessage;
}; };
+3 -2
View File
@@ -3,9 +3,10 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* probably Mike Berg <[email protected]> * Andrew McCall <mccall@@digitalparadise.co.uk>
* and/or Andrew McCall <mccall@@digitalparadise.co.uk> * Mike Berg <mike@berg-net.us>
* Julun <[email protected]> * Julun <[email protected]>
*
*/ */
#include "Bitmaps.h" #include "Bitmaps.h"
+3 -2
View File
@@ -3,9 +3,10 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* probably Mike Berg <[email protected]> * Andrew McCall <mccall@@digitalparadise.co.uk>
* and/or Andrew McCall <mccall@@digitalparadise.co.uk> * Mike Berg <mike@berg-net.us>
* Julun <[email protected]> * Julun <[email protected]>
*
*/ */
#ifndef ANALOG_CLOCK_H #ifndef ANALOG_CLOCK_H
#define ANALOG_CLOCK_H #define ANALOG_CLOCK_H
File diff suppressed because it is too large Load Diff
+162 -51
View File
@@ -1,68 +1,179 @@
/* /*
* Copyright 2004-2007, Haiku, Inc. All Rights Reserved. * Copyright 2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*
* Authors:
* probably Mike Berg <[email protected]>
* and/or Andrew McCall <mccall@@digitalparadise.co.uk>
*/ */
#ifndef CALENDAR_VIEW_H #ifndef _CALENDAR_VIEW_H_
#define CALENDAR_VIEW_H #define _CALENDAR_VIEW_H_
#include <Control.h> #include "DateTime.h"
#include <Invoker.h>
#include <List.h>
#include <String.h>
#include <View.h> #include <View.h>
class TDay: public BControl { class BMessage;
public:
TDay(BRect frame, int day);
virtual ~TDay();
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 SetValue(int32 value);
void SetTo(BRect frame, int day);
void SetTo(int day, bool selected = false);
int Day()
{ return f_day; } enum week_start {
protected: B_WEEK_START_MONDAY,
virtual void Stroke3dFrame(BRect frame, rgb_color light, rgb_color dark, bool inset); B_WEEK_START_SUNDAY
private:
int f_day;
}; };
class TCalendarView: public BView {
class BCalendarView : public BView, public BInvoker {
public: public:
TCalendarView(BRect frame, const char *name, uint32 resizingmode, uint32 flags); BCalendarView(BRect frame, const char *name,
virtual ~TCalendarView(); uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP,
virtual void AttachedToWindow(); uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE);
virtual void Draw(BRect bounds);
void KeyDown(const char *bytes, int32 numbytes); BCalendarView(BRect frame, const char *name, week_start start,
virtual void MessageReceived(BMessage *message); uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP,
uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE);
virtual ~BCalendarView();
BCalendarView(BMessage *archive);
static BArchivable* Instantiate(BMessage *archive);
virtual status_t Archive(BMessage *archive, bool deep = true) const;
virtual void AttachedToWindow();
virtual void DetachedFromWindow();
virtual void AllAttached();
virtual void AllDetached();
virtual void FrameMoved(BPoint newPosition);
virtual void FrameResized(float width, float height);
virtual void Draw(BRect updateRect);
void SetTo(int32, int32, int32); virtual void DrawDay(BView *owner, BRect frame, const char *text,
protected: bool isSelected = false, bool isEnabled = true,
virtual void InitView(); bool focus = false);
virtual void DispatchMessage(); virtual void DrawDayName(BView *owner, BRect frame, const char *text);
virtual void DrawWeekNumber(BView *owner, BRect frame, const char *text);
virtual void MessageReceived(BMessage *message);
uint32 SelectionCommand() const;
BMessage* SelectionMessage() const;
virtual void SetSelectionMessage(BMessage *message);
uint32 InvocationCommand() const;
BMessage* InvocationMessage() const;
virtual void SetInvocationMessage(BMessage *message);
virtual void WindowActivated(bool state);
virtual void MakeFocus(bool state = true);
virtual status_t Invoke(BMessage* message = NULL);
virtual void MouseUp(BPoint point);
virtual void MouseDown(BPoint where);
virtual void MouseMoved(BPoint point, uint32 code,
const BMessage *dragMessage);
virtual void KeyDown(const char *bytes, int32 numBytes);
virtual BHandler* ResolveSpecifier(BMessage *message, int32 index,
BMessage *specifier, int32 form, const char *property);
virtual status_t GetSupportedSuites(BMessage *data);
virtual status_t Perform(perform_code code, void* arg);
virtual void ResizeToPreferred();
virtual void GetPreferredSize(float *width, float *height);
int32 Day() const;
int32 Year() const;
int32 Month() const;
BDate Date() const;
bool SetDate(const BDate &date);
bool SetDate(int32 year, int32 month, int32 day);
week_start WeekStart() const;
void SetWeekStart(week_start start);
bool IsDayNameHeaderVisible() const;
void SetDayNameHeaderVisible(bool visible);
bool IsWeekNumberHeaderVisible() const;
void SetWeekNumberHeaderVisible(bool visible);
private: private:
void InitDates(); void _InitObject();
void CalcFlags();
int32 IndexOf(BView *) const;
TDay *f_cday; void _SetToDay();
TDay *f_focused; void _GetYearMonth(int32 *year, int32 *month) const;
BRect f_dayrect; void _GetPreferredSize(float *width, float *height);
// x = index of first day; y = index of last;
BPoint f_daybound; void _SetupDayNames();
int f_firstday; void _SetupDayNumbers();
int f_month; void _SetupWeekNumbers();
int f_day;
int f_year; void _DrawDays();
void _DrawFocusRect();
void _DrawDayHeader();
void _DrawWeekHeader();
void _DrawDay(int32 curRow, int32 curColumn,
int32 row, int32 column, int32 counter,
BRect frame, const char *text, bool focus = false);
void _DrawItem(BView *owner, BRect frame, const char *text,
bool isSelected = false, bool isEnabled = true,
bool focus = false);
void _UpdateSelection();
BRect _FirstCalendarItemFrame() const;
BRect _SetNewSelectedDay(const BPoint &where);
BCalendarView& operator=(const BCalendarView &view);
private:
struct Selection {
Selection()
: row(0), column(0) { }
void SetTo(int32 _row, int32 _column)
{ row = _row; column = _column; }
int32 row;
int32 column;
Selection& operator=(const Selection &s)
{ row = s.row; column = s.column; return *this; }
bool operator==(const Selection &s) const
{ return row == s.row && column == s.column; }
bool operator!=(const Selection &s) const
{ return row != s.row || column != s.column; }
};
BRect _RectOfDay(const Selection &selection) const;
BMessage *fSelectionMessage;
int32 fDay;
int32 fYear;
int32 fMonth;
Selection fFocusedDay;
bool fFocusChanged;
Selection fNewFocusedDay;
Selection fSelectedDay;
Selection fNewSelectedDay;
bool fSelectionChanged;
week_start fWeekStart;
bool fDayNameHeaderVisible;
bool fWeekNumberHeaderVisible;
BString fDayNames[7];
BString fWeekNumbers[6];
BString fDayNumbers[6][7];
}; };
#endif // CALENDAR_VIEW_H #endif // _CALENDAR_VIEW_H_
+483
View File
@@ -0,0 +1,483 @@
/*
* Copyright 2004-2006, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Julun <[email protected]>
* Stephan Aßmus <[email protected]>
*/
#include "DateTime.h"
#include <time.h>
BTime::BTime()
: fHour(-1),
fMinute(-1),
fSecond(-1)
{
}
BTime::BTime(int32 hour, int32 minute, int32 second)
: fHour(hour),
fMinute(minute),
fSecond(second)
{
}
BTime::~BTime()
{
}
bool
BTime::IsValid() const
{
if (fHour < 0 || fHour >= 24)
return false;
if (fMinute < 0 || fMinute >= 60)
return false;
if (fSecond < 0 || fSecond >= 60)
return false;
return true;
}
BTime
BTime::CurrentTime(time_type type)
{
time_t timer;
struct tm result;
struct tm* timeinfo;
time(&timer);
if (type == B_GMT_TIME)
timeinfo = gmtime_r(&timer, &result);
else
timeinfo = localtime_r(&timer, &result);
int32 sec = timeinfo->tm_sec;
return BTime(timeinfo->tm_hour, timeinfo->tm_min, (sec > 59) ? 59 : sec);
}
bool
BTime::SetTime(int32 hour, int32 minute, int32 second)
{
fHour = hour;
fMinute = minute;
fSecond = second;
return IsValid();
}
int32
BTime::Hour() const
{
return fHour;
}
int32
BTime::Minute() const
{
return fMinute;
}
int32
BTime::Second() const
{
return fSecond;
}
// #pragma mark -
BDate::BDate()
: fDay(-1),
fYear(-1),
fMonth(-1)
{
}
BDate::BDate(int32 year, int32 month, int32 day)
: fDay(day),
fYear(year),
fMonth(month)
{
}
BDate::~BDate()
{
}
bool
BDate::IsValid() const
{
// fail if the year goes less 1583
// 10/15/1582 start of Gregorian calendar
if (fYear < 1583)
return false;
if (fMonth < 1 || fMonth > 12)
return false;
if (fDay < 1 || fDay > DaysInMonth())
return false;
return true;
}
BDate
BDate::CurrentDate(time_type type)
{
time_t timer;
struct tm result;
struct tm* timeinfo;
time(&timer);
if (type == B_GMT_TIME)
timeinfo = gmtime_r(&timer, &result);
else
timeinfo = localtime_r(&timer, &result);
return BDate(timeinfo->tm_year + 1900, timeinfo->tm_mon +1, timeinfo->tm_mday);
}
bool
BDate::SetDate(int32 year, int32 month, int32 day)
{
fDay = day;
fYear = year;
fMonth = month;
return IsValid();
}
int32
BDate::Day() const
{
return fDay;
}
int32
BDate::Year() const
{
return fYear;
}
int32
BDate::Month() const
{
return fMonth;
}
int32
BDate::WeekNumber() const
{
/*
This algorithm is taken from:
Frequently Asked Questions about Calendars
Version 2.8 Claus Tøndering 15 December 2005
Note: it will work only within the Gregorian Calendar
*/
if (!IsValid())
return 0;
int32 a;
int32 b;
int32 s;
int32 e;
int32 f;
if (fMonth > 0 && fMonth < 3) {
a = fYear - 1;
b = (a / 4) - (a / 100) + (a / 400);
int32 c = ((a - 1) / 4) - ((a - 1) / 100) + ((a -1) / 400);
s = b - c;
e = 0;
f = fDay - 1 + 31 * (fMonth - 1);
} else if (fMonth >= 3 && fMonth <= 12) {
a = fYear;
b = (a / 4) - (a / 100) + (a / 400);
int32 c = ((a - 1) / 4) - ((a - 1) / 100) + ((a -1) / 400);
s = b - c;
e = s + 1;
f = fDay + ((153 * (fMonth - 3) + 2) / 5) + 58 + s;
} else
return 0;
int32 g = (a + b) % 7;
int32 d = (f + g - e) % 7;
int32 n = f + 3 - d;
int32 weekNumber;
if (n < 0)
weekNumber = 53 - (g -s) / 5;
else if (n > 364 + s)
weekNumber = 1;
else
weekNumber = n / 7 + 1;
return weekNumber;
}
int32
BDate::DayOfWeek() const
{
/*
This algorithm is taken from:
Frequently Asked Questions about Calendars
Version 2.8 Claus Tøndering 15 December 2005
Note: it will work only within the Gregorian Calendar
*/
if (!IsValid())
return -1;
int32 a = (14 - fMonth) / 12;
int32 y = fYear - a;
int32 m = fMonth + 12 * a - 2;
int32 d = (fDay + y + (y / 4) - (y / 100) + (y / 400) + ((31 * m) / 12)) % 7;
return d;
}
int32
BDate::DayOfYear() const
{
/*
Note: this function might fail for 1582...
http://en.wikipedia.org/wiki/Gregorian_calendar:
The last day of the Julian calendar was Thursday October 4, 1582
and this was followed by the first day of the Gregorian calendar,
Friday October 15, 1582 (the cycle of weekdays was not affected).
*/
if (!IsValid())
return -1;
const int kFirstDayOfMonth[2][12] = {
{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 },
{ 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 }
};
if (IsLeapYear(fYear))
return kFirstDayOfMonth[1][fMonth -1] + fDay;
return kFirstDayOfMonth[0][fMonth -1] + fDay;
}
bool
BDate::IsLeapYear(int32 year) const
{
return year % 400 == 0 || year % 4 == 0 && year % 100 != 0;
}
int32
BDate::DaysInYear() const
{
if (!IsValid())
return 0;
return IsLeapYear(fYear) ? 366 : 365;
}
int32
BDate::DaysInMonth() const
{
if (fMonth == 2 && IsLeapYear(fYear))
return 29;
const int32 daysInMonth[12] =
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
return daysInMonth[fMonth -1];
}
BString
BDate::ShortDayName(int32 day) const
{
if (day < 1 || day > 7)
return BString();
tm tm_struct;
memset(&tm_struct, 0, sizeof(tm));
tm_struct.tm_wday = day == 7 ? 0 : day;
char buffer[256];
strftime(buffer, sizeof(buffer), "%a", &tm_struct);
return BString(buffer);
}
BString
BDate::ShortMonthName(int32 month) const
{
if (month < 1 || month > 12)
return BString();
tm tm_struct;
memset(&tm_struct, 0, sizeof(tm));
tm_struct.tm_mon = month -1;
char buffer[256];
strftime(buffer, sizeof(buffer), "%b", &tm_struct);
return BString(buffer);
}
BString
BDate::LongDayName(int32 day) const
{
if (day < 1 || day > 7)
return BString();
tm tm_struct;
memset(&tm_struct, 0, sizeof(tm));
tm_struct.tm_wday = day == 7 ? 0 : day;
char buffer[256];
strftime(buffer, sizeof(buffer), "%A", &tm_struct);
return BString(buffer);
}
BString
BDate::LongMonthName(int32 month) const
{
if (month < 1 || month > 12)
return BString();
tm tm_struct;
memset(&tm_struct, 0, sizeof(tm));
tm_struct.tm_mon = month -1;
char buffer[256];
strftime(buffer, sizeof(buffer), "%B", &tm_struct);
return BString(buffer);
}
// #pragma mark -
BDateTime::BDateTime(const BDate &date, const BTime &time)
: fDate(date),
fTime(time)
{
}
BDateTime::~BDateTime()
{
}
bool
BDateTime::IsValid() const
{
return fDate.IsValid() && fTime.IsValid();
}
BDateTime
BDateTime::CurrentDateTime(time_type type)
{
BDate date = BDate::CurrentDate(type);
BTime time = BTime::CurrentTime(type);
return BDateTime(date, time);
}
void
BDateTime::SetDateTime(const BDate &date, const BTime &time)
{
fDate = date;
fTime = time;
}
BDate
BDateTime::Date() const
{
return fDate;
}
void
BDateTime::SetDate(const BDate &date)
{
fDate = date;
}
BTime
BDateTime::Time() const
{
return fTime;
}
void
BDateTime::SetTime(const BTime &time)
{
fTime = time;
}
uint32
BDateTime::Time_t() const
{
tm tm_struct;
tm_struct.tm_hour = fTime.Hour();
tm_struct.tm_min = fTime.Minute();
tm_struct.tm_sec = fTime.Second();
tm_struct.tm_year = fDate.Year() - 1900;
tm_struct.tm_mon = fDate.Month() - 1;
tm_struct.tm_mday = fDate.Day();
// set less 0 as we wan't use it
tm_struct.tm_isdst = -1;
// return secs_since_jan1_1970 or -1 on error
return uint32(mktime(&tm_struct));
}
+100
View File
@@ -0,0 +1,100 @@
/*
* Copyright 2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _DATE_TIME_H_
#define _DATE_TIME_H_
#include <String.h>
enum time_type {
B_GMT_TIME,
B_LOCAL_TIME
};
class BTime {
public:
BTime();
BTime(int32 hour, int32 minute, int32 second);
~BTime();
bool IsValid() const;
static BTime CurrentTime(time_type type);
bool SetTime(int32 hour, int32 minute, int32 second);
int32 Hour() const;
int32 Minute() const;
int32 Second() const;
private:
int32 fHour;
int32 fMinute;
int32 fSecond;
};
class BDate {
public:
BDate();
BDate(int32 year, int32 month, int32 day);
~BDate();
bool IsValid() const;
static BDate CurrentDate(time_type type);
bool SetDate(int32 year, int32 month, int32 day);
int32 Day() const;
int32 Year() const;
int32 Month() const;
int32 DayOfWeek() const;
int32 DayOfYear() const;
int32 WeekNumber() const;
bool IsLeapYear(int32 year) const;
int32 DaysInYear() const;
int32 DaysInMonth() const;
BString ShortDayName(int32 day) const;
BString ShortMonthName(int32 month) const;
BString LongDayName(int32 day) const;
BString LongMonthName(int32 month) const;
private:
int32 fDay;
int32 fYear;
int32 fMonth;
};
class BDateTime {
public:
BDateTime(const BDate &date, const BTime &time);
~BDateTime();
bool IsValid() const;
static BDateTime CurrentDateTime(time_type type);
void SetDateTime(const BDate &date, const BTime &time);
BDate Date() const;
void SetDate(const BDate &date);
BTime Time() const;
void SetTime(const BTime &time);
uint32 Time_t() const;
private:
BDate fDate;
BTime fTime;
};
#endif // _DATE_TIME_H_
+198 -232
View File
@@ -3,45 +3,24 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* probably Mike Berg <[email protected]> * McCall <mccall@@digitalparadise.co.uk>
* and/or Andrew McCall <mccall@@digitalparadise.co.uk> * Mike Berg <mike@berg-net.us>
* Julun <[email protected]> * Julun <[email protected]>
* *
*/ */
#include "DateTimeEdit.h" #include "DateTimeEdit.h"
#include "DateUtils.h"
#include <List.h> #include <List.h>
#include <String.h> #include <String.h>
#define YEAR_DELTA_MAX 110
#define YEAR_DELTA_MIN 64
class TDateTimeSection : public TSection {
public:
TDateTimeSection(BRect frame, uint32 data = 0)
: TSection(frame), fData(data) { }
~TDateTimeSection();
uint32 Data() const { return fData; }
void SetData(uint32 data) { fData = data; }
private:
uint32 fData;
};
// #pragma mark -
TTimeEdit::TTimeEdit(BRect frame, const char *name, uint32 sections) TTimeEdit::TTimeEdit(BRect frame, const char *name, uint32 sections)
: TSectionEdit(frame, name, sections) : TSectionEdit(frame, name, sections)
{ {
InitView(); InitView();
fTime = BTime::CurrentTime(B_LOCAL_TIME);
} }
@@ -64,27 +43,25 @@ void
TTimeEdit::DrawSection(uint32 index, bool hasFocus) TTimeEdit::DrawSection(uint32 index, bool hasFocus)
{ {
// user defined section drawing // user defined section drawing
TDateTimeSection *section; TSection *section = NULL;
section = (TDateTimeSection *)fSectionList->ItemAt(index); section = static_cast<TSection*> (fSectionList->ItemAt(index));
if (!section)
return;
BRect bounds = section->Frame(); BRect bounds = section->Frame();
uint32 value = _SectionValue(index);
// format value to display SetLowColor(ViewColor());
uint32 value;
if (hasFocus) { if (hasFocus) {
SetLowColor(tint_color(ViewColor(), B_DARKEN_1_TINT)); SetLowColor(tint_color(ViewColor(), B_DARKEN_1_TINT));
value = fHoldValue; value = fHoldValue;
} else {
SetLowColor(ViewColor());
value = section->Data();
} }
BString text; BString text;
// format value (new method?)
switch (index) { switch (index) {
case 0: // hour case 0:
{ // hour
if (value > 12) { if (value > 12) {
if (value < 22) if (value < 22)
text << "0"; text << "0";
@@ -96,53 +73,55 @@ TTimeEdit::DrawSection(uint32 index, bool hasFocus)
text << "0"; text << "0";
text << value; text << value;
} }
break; } break;
case 1: // minute case 1:
case 2: // second case 2:
{ // minute
// second
if (value < 10) if (value < 10)
text << "0"; text << "0";
text << value; text << value;
break; } break;
case 3: // am/pm case 3:
value = ((TDateTimeSection *)fSectionList->ItemAt(0))->Data(); { // am/pm
value = fTime.Hour();
if (value >= 12) if (value >= 12)
text << "PM"; text << "PM";
else else
text << "AM"; text << "AM";
break; } break;
default: default:
return; return;
break; break;
} }
// calc and center text in section rect // calc and center text in section rect
float width = be_plain_font->StringWidth(text.String()); float width = be_plain_font->StringWidth(text.String());
BPoint offset(-(bounds.Width() / 2.0 -width / 2.0) -1.0, bounds.Height() / 2.0 -6.0); BPoint offset(-((bounds.Width()- width) / 2.0) -1.0
, bounds.Height() / 2.0 -6.0);
BPoint drawpt(bounds.LeftBottom() -offset);
SetHighColor(0, 0, 0, 255); SetHighColor(0, 0, 0, 255);
FillRect(bounds, B_SOLID_LOW); FillRect(bounds, B_SOLID_LOW);
DrawString(text.String(), drawpt); DrawString(text.String(), bounds.LeftBottom() - offset);
} }
/*
DrawSeperator(uint32 index) user drawn seperator. Section is the
index of the section in fSectionList or the section to the seps left
*/
void void
TTimeEdit::DrawSeperator(uint32 index) TTimeEdit::DrawSeperator(uint32 index)
{ {
if (index == 3) if (index == 3)
return; return;
TDateTimeSection *section = (TDateTimeSection *)fSectionList->ItemAt(index); TSection *section = NULL;
section = static_cast<TSection*> (fSectionList->ItemAt(index));
if (!section)
return;
BRect bounds = section->Frame(); BRect bounds = section->Frame();
float sepWidth = SeperatorWidth(); float sepWidth = SeperatorWidth();
@@ -151,20 +130,17 @@ TTimeEdit::DrawSeperator(uint32 index)
sep = "-"; sep = "-";
float width = be_plain_font->StringWidth(sep); float width = be_plain_font->StringWidth(sep);
BPoint offset(-((sepWidth - width) / 2.0) -1.0
BPoint offset(-(sepWidth / 2.0 - width / 2.0) -1.0, bounds.Height() / 2.0 -6.0); , bounds.Height() / 2.0 -6.0);
BPoint drawpt(bounds.RightBottom() -offset); DrawString(sep, bounds.RightBottom() - offset);
DrawString(sep, drawpt);
} }
void void
TTimeEdit::SetSections(BRect area) TTimeEdit::SetSections(BRect area)
{ {
// by default divie up the sections evenly // by default divide up the sections evenly
BRect bounds(area); BRect bounds(area);
// no comp for sep width
float sepWidth = SeperatorWidth(); float sepWidth = SeperatorWidth();
@@ -173,13 +149,13 @@ TTimeEdit::SetSections(BRect area)
bounds.right = bounds.left + (width -sepWidth / fSectionCount); bounds.right = bounds.left + (width -sepWidth / fSectionCount);
for (uint32 idx = 0; idx < fSectionCount; idx++) { for (uint32 idx = 0; idx < fSectionCount; idx++) {
fSectionList->AddItem(new TDateTimeSection(bounds)); fSectionList->AddItem(new TSection(bounds));
bounds.left = bounds.right + sepWidth; bounds.left = bounds.right + sepWidth;
if (idx == fSectionCount -2) if (idx == fSectionCount -2)
bounds.right = area.right -1; bounds.right = area.right -1;
else else
bounds.right = bounds.left + (width -sep_2); bounds.right = bounds.left + (width - sep_2);
} }
} }
@@ -187,7 +163,7 @@ TTimeEdit::SetSections(BRect area)
float float
TTimeEdit::SeperatorWidth() const TTimeEdit::SeperatorWidth() const
{ {
return 8.0f; return 10.0f;
} }
@@ -195,42 +171,20 @@ void
TTimeEdit::SectionFocus(uint32 index) TTimeEdit::SectionFocus(uint32 index)
{ {
fFocus = index; fFocus = index;
fHoldValue = _SectionValue(index);
// update hold value
fHoldValue = ((TDateTimeSection *)fSectionList->ItemAt(fFocus))->Data();
Draw(Bounds()); Draw(Bounds());
} }
void void
TTimeEdit::SetTime(uint32 hour, uint32 minute, uint32 second) TTimeEdit::SetTime(int32 hour, int32 minute, int32 second)
{ {
if (fSectionList->CountItems()> 0) if (fTime.Hour() == hour && fTime.Minute() == minute
{ && fTime.Second() == second)
bool update = false; return;
TDateTimeSection *section = (TDateTimeSection *)fSectionList->ItemAt(0); fTime.SetTime(hour, minute, second);
if (section->Data() != hour) { Invalidate(Bounds());
section->SetData(hour);
update = true;
}
section = (TDateTimeSection *)fSectionList->ItemAt(1);
if (section->Data() != minute) {
section->SetData(minute);
update = true;
}
section = (TDateTimeSection *)fSectionList->ItemAt(2);
if (section->Data() != second) {
section->SetData(second);
update = true;
}
if (update)
Draw(Bounds());
}
} }
@@ -243,7 +197,7 @@ TTimeEdit::DoUpPress()
// update displayed value // update displayed value
fHoldValue += 1; fHoldValue += 1;
CheckRange(); _CheckRange();
// send message to change time // send message to change time
DispatchMessage(); DispatchMessage();
@@ -259,7 +213,7 @@ TTimeEdit::DoDownPress()
// update display value // update display value
fHoldValue -= 1; fHoldValue -= 1;
CheckRange(); _CheckRange();
// send message to change time // send message to change time
DispatchMessage(); DispatchMessage();
@@ -269,74 +223,105 @@ TTimeEdit::DoDownPress()
void void
TTimeEdit::BuildDispatch(BMessage *message) TTimeEdit::BuildDispatch(BMessage *message)
{ {
const char *fields[4] = {"hour", "minute", "second", "isam"}; const char *fields[3] = { "hour", "minute", "second" };
message->AddBool("time", true); message->AddBool("time", true);
for (int32 idx = 0; idx < fSectionList->CountItems() -1; idx++) { for (int32 index = 0; index < fSectionList->CountItems() -1; ++index) {
uint32 data = ((TDateTimeSection *)fSectionList->ItemAt(idx))->Data(); uint32 data = _SectionValue(index);
if (fFocus == idx) if (fFocus == index)
data = fHoldValue; data = fHoldValue;
if (idx == 3) // isam message->AddInt32(fields[index], data);
message->AddBool(fields[idx], data == 1);
else
message->AddInt32(fields[idx], data);
} }
} }
void void
TTimeEdit::CheckRange() TTimeEdit::_CheckRange()
{ {
int32 value = fHoldValue; int32 value = fHoldValue;
switch (fFocus) { switch (fFocus) {
case 0: // hour case 0:
if (value> 23) { // hour
if (value > 23)
value = 0; value = 0;
else if (value < 0) else if (value < 0)
value = 23; value = 23;
break;
case 1: // minute fTime.SetTime(value, fTime.Minute(), fTime.Second());
} break;
case 1:
{ // minute
if (value> 59) if (value> 59)
value = 0; value = 0;
else if (value < 0) else if (value < 0)
value = 59; value = 59;
break;
case 2: // second fTime.SetTime(fTime.Hour(), value, fTime.Second());
} break;
case 2:
{ // second
if (value > 59) if (value > 59)
value = 0; value = 0;
else if (value < 0) else if (value < 0)
value = 59; value = 59;
break; fTime.SetTime(fTime.Hour(), fTime.Minute(), value);
} break;
case 3: case 3:
// modify hour value to reflect change in am/pm {
value = ((TDateTimeSection *)fSectionList->ItemAt(0))->Data(); value = fTime.Hour();
if (value < 13) if (value < 13)
value += 12; value += 12;
else else
value -= 12; value -= 12;
if (value == 24) if (value == 24)
value = 0; value = 0;
((TDateTimeSection *)fSectionList->ItemAt(0))->SetData(value);
break; // modify hour value to reflect change in am/ pm
fTime.SetTime(value, fTime.Minute(), fTime.Second());
} break;
default: default:
return; return;
} }
((TDateTimeSection *)fSectionList->ItemAt(fFocus))->SetData(value);
fHoldValue = value; fHoldValue = value;
Invalidate(Bounds()); Invalidate(Bounds());
} }
int32
TTimeEdit::_SectionValue(int32 index) const
{
int32 value;
switch (index) {
case 0:
value = fTime.Hour();
break;
case 1:
value = fTime.Minute();
break;
case 2:
value = fTime.Second();
break;
default:
value = 0;
break;
}
return value;
}
// #pragma mark - // #pragma mark -
@@ -344,6 +329,7 @@ TDateEdit::TDateEdit(BRect frame, const char *name, uint32 sections)
: TSectionEdit(frame, name, sections) : TSectionEdit(frame, name, sections)
{ {
InitView(); InitView();
fDate = BDate::CurrentDate(B_LOCAL_TIME);
} }
@@ -366,54 +352,32 @@ void
TDateEdit::DrawSection(uint32 index, bool hasFocus) TDateEdit::DrawSection(uint32 index, bool hasFocus)
{ {
// user defined section drawing // user defined section drawing
TDateTimeSection *section; TSection *section = NULL;
section = (TDateTimeSection *)fSectionList->ItemAt(index); section = static_cast<TSection*> (fSectionList->ItemAt(index));
if (!section)
return;
BRect bounds = section->Frame(); BRect bounds = section->Frame();
uint32 value = _SectionValue(index);
// format value to display SetLowColor(ViewColor());
uint32 value;
if (hasFocus) { if (hasFocus) {
SetLowColor(tint_color(ViewColor(), B_DARKEN_1_TINT)); SetLowColor(tint_color(ViewColor(), B_DARKEN_1_TINT));
value = fHoldValue; value = fHoldValue;
} else {
SetLowColor(ViewColor());
value = section->Data();
} }
BString text; BString text;
switch (index) { if (index != 0) {
case 0: if (value < 10) text << "0";
{ // month text << value;
struct tm tm; } else
tm.tm_mon = value; text.SetTo(fDate.LongMonthName(value));
char buffer[64];
memset(buffer, 0, sizeof(buffer));
strftime(buffer, sizeof(buffer), "%B", &tm);
text.SetTo(buffer);
} break;
case 1: // day
text << value;
break;
case 2: // year
text << (value + 1900);
break;
default:
return;
}
// calc and center text in section rect // calc and center text in section rect
float width = StringWidth(text.String()); float width = StringWidth(text.String());
BPoint offset(-(bounds.Width() - width) / 2.0 - 1.0, (bounds.Height() / 2.0 - 6.0)); BPoint offset(-(bounds.Width() - width) / 2.0 - 1.0
, (bounds.Height() / 2.0 - 6.0));
if (index == 0)
offset.x = -(bounds.Width() - width) ;
SetHighColor(0, 0, 0, 255); SetHighColor(0, 0, 0, 255);
FillRect(bounds, B_SOLID_LOW); FillRect(bounds, B_SOLID_LOW);
@@ -421,26 +385,24 @@ TDateEdit::DrawSection(uint32 index, bool hasFocus)
} }
/*
DrawSeperator(uint32 index) user drawn seperator. Section is the
index of the section in fSectionList or the section to the seps left
*/
void void
TDateEdit::DrawSeperator(uint32 index) TDateEdit::DrawSeperator(uint32 index)
{ {
if (index == 3) if (index == 3)
return; return;
TDateTimeSection *section = (TDateTimeSection *)fSectionList->ItemAt(index); TSection *section = NULL;
section = static_cast<TSection*> (fSectionList->ItemAt(index));
BRect bounds = section->Frame(); BRect bounds = section->Frame();
float sepWidth = SeperatorWidth(); float sepWidth = SeperatorWidth();
float width = be_plain_font->StringWidth("/"); float width = be_plain_font->StringWidth("/");
BPoint offset(-(sepWidth / 2.0 - width / 2.0) -1.0, bounds.Height() / 2.0 -6.0); BPoint offset(-(sepWidth / 2.0 - width / 2.0) -1.0
BPoint drawpt(bounds.RightBottom() - offset); , bounds.Height() / 2.0 -6.0);
DrawString("/", drawpt); SetHighColor(0, 0, 0, 255);
DrawString("/", bounds.RightBottom() - offset);
} }
@@ -449,35 +411,38 @@ TDateEdit::SetSections(BRect area)
{ {
// create sections // create sections
for (uint32 idx = 0; idx < fSectionCount; idx++) for (uint32 idx = 0; idx < fSectionCount; idx++)
fSectionList->AddItem(new TDateTimeSection(area)); fSectionList->AddItem(new TSection(area));
BRect bounds(area); BRect bounds(area);
float sepWidth = SeperatorWidth();
// year // year
TSection *section = NULL;
float width = be_plain_font->StringWidth("0000") +6; float width = be_plain_font->StringWidth("0000") +6;
bounds.right = area.right; bounds.right = area.right;
bounds.left = bounds.right -width; bounds.left = bounds.right -width;
((TDateTimeSection *)fSectionList->ItemAt(2))->SetFrame(bounds); section = static_cast<TSection*> (fSectionList->ItemAt(2));
section->SetFrame(bounds);
float sepWidth = SeperatorWidth();
// day // day
width = be_plain_font->StringWidth("00") +6; width = be_plain_font->StringWidth("00") +6;
bounds.right = bounds.left -sepWidth; bounds.right = bounds.left -sepWidth;
bounds.left = bounds.right -width; bounds.left = bounds.right -width;
((TDateTimeSection *)fSectionList->ItemAt(1))->SetFrame(bounds); section = static_cast<TSection*> (fSectionList->ItemAt(1));
section->SetFrame(bounds);
// month // month
bounds.right = bounds.left - sepWidth; bounds.right = bounds.left - sepWidth;
bounds.left = area.left; bounds.left = area.left;
((TDateTimeSection *)fSectionList->ItemAt(0))->SetFrame(bounds); section = static_cast<TSection*> (fSectionList->ItemAt(0));
section->SetFrame(bounds);
} }
float float
TDateEdit::SeperatorWidth() const TDateEdit::SeperatorWidth() const
{ {
return 8.0f; return 10.0f;
} }
@@ -485,41 +450,19 @@ void
TDateEdit::SectionFocus(uint32 index) TDateEdit::SectionFocus(uint32 index)
{ {
fFocus = index; fFocus = index;
fHoldValue = _SectionValue(index);
// update hold value
fHoldValue = ((TDateTimeSection *)fSectionList->ItemAt(fFocus))->Data();
Draw(Bounds()); Draw(Bounds());
} }
void void
TDateEdit::SetDate(uint32 year, uint32 month, uint32 day) TDateEdit::SetDate(int32 year, int32 month, int32 day)
{ {
if (fSectionList->CountItems() > 0) { if (year == fDate.Year() && month == fDate.Month() && day == fDate.Day())
bool update = false; return;
TDateTimeSection *section = (TDateTimeSection *)fSectionList->ItemAt(0); fDate.SetDate(year, month, day);
if (section->Data() != month) { Invalidate(Bounds());
section->SetData(month);
update = true;
}
section = (TDateTimeSection *)fSectionList->ItemAt(1);
if (section->Data() != day) {
section->SetData(day);
update = true;
}
section = (TDateTimeSection *)fSectionList->ItemAt(2);
if (section->Data() != year) {
section->SetData(year);
update = true;
}
if (update)
Invalidate(Bounds());
}
} }
@@ -532,7 +475,7 @@ TDateEdit::DoUpPress()
// update displayed value // update displayed value
fHoldValue += 1; fHoldValue += 1;
CheckRange(); _CheckRange();
// send message to change Date // send message to change Date
DispatchMessage(); DispatchMessage();
@@ -548,7 +491,7 @@ TDateEdit::DoDownPress()
// update display value // update display value
fHoldValue -= 1; fHoldValue -= 1;
CheckRange(); _CheckRange();
// send message to change Date // send message to change Date
DispatchMessage(); DispatchMessage();
@@ -558,65 +501,88 @@ TDateEdit::DoDownPress()
void void
TDateEdit::BuildDispatch(BMessage *message) TDateEdit::BuildDispatch(BMessage *message)
{ {
const char *fields[3] = {"month", "day", "year"}; const char *fields[3] = { "month", "day", "year" };
message->AddBool("time", false); message->AddBool("time", false);
for (int32 idx = 0; idx < fSectionList->CountItems(); idx++) { int32 value;
uint32 data = ((TDateTimeSection *)fSectionList->ItemAt(idx))->Data(); for (int32 index = 0; index < fSectionList->CountItems(); ++index) {
value = _SectionValue(index);
if (fFocus == idx) if (index == fFocus)
data = fHoldValue; value = fHoldValue;
message->AddInt32(fields[idx], data); message->AddInt32(fields[index], value);
} }
} }
void void
TDateEdit::CheckRange() TDateEdit::_CheckRange()
{ {
int32 value = fHoldValue; int32 value = fHoldValue;
switch (fFocus) { switch (fFocus) {
case 0: // month case 0:
{ {
if (value > 11) // month
value = 0; if (value > 12)
else if (value < 0)
value = 11;
break;
}
case 1: //day
{
uint32 month = ((TDateTimeSection *)fSectionList->ItemAt(0))->Data();
uint32 year = ((TDateTimeSection *)fSectionList->ItemAt(2))->Data();
int daycnt = getDaysInMonth(month, year);
if (value > daycnt)
value = 1; value = 1;
else if (value < 1) else if (value < 1)
value = daycnt; value = 12;
break;
}
case 2: //year fDate.SetDate(fDate.Year(), value, fDate.Day());
} break;
case 1:
{ {
if (value > YEAR_DELTA_MAX) //day
value = YEAR_DELTA_MIN; int32 days = fDate.DaysInMonth();
else if (value < YEAR_DELTA_MIN) if (value > days)
value = YEAR_DELTA_MAX; value = 1;
break; else if (value < 1)
} value = days;
fDate.SetDate(fDate.Year(), fDate.Month(), value);
} break;
case 2:
{
//year
if (value > 2037)
value = 2037;
else if (value < 1970)
value = 1970;
fDate.SetDate(value, fDate.Month(), fDate.Day());
} break;
default: default:
return; return;
} }
((TDateTimeSection *)fSectionList->ItemAt(fFocus))->SetData(value);
fHoldValue = value; fHoldValue = value;
Draw(Bounds()); Draw(Bounds());
} }
int32
TDateEdit::_SectionValue(int32 index) const
{
int32 value = 0;
switch (index) {
case 0:
value = fDate.Month();
break;
case 1:
value = fDate.Day();
break;
default:
value = fDate.Year();
break;
}
return value;
}
+19 -8
View File
@@ -3,8 +3,8 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* probably Mike Berg <[email protected]> * McCall <mccall@@digitalparadise.co.uk>
* and/or Andrew McCall <mccall@@digitalparadise.co.uk> * Mike Berg <mike@berg-net.us>
* Julun <[email protected]> * Julun <[email protected]>
* *
*/ */
@@ -12,6 +12,7 @@
#define DATETIME_H #define DATETIME_H
#include "DateTime.h"
#include "SectionEdit.h" #include "SectionEdit.h"
@@ -28,14 +29,19 @@ class TTimeEdit : public TSectionEdit {
virtual void SectionFocus(uint32 index); virtual void SectionFocus(uint32 index);
virtual float SeperatorWidth() const; virtual float SeperatorWidth() const;
void CheckRange();
virtual void DoUpPress(); virtual void DoUpPress();
virtual void DoDownPress(); virtual void DoDownPress();
virtual void BuildDispatch(BMessage *message); virtual void BuildDispatch(BMessage *message);
void SetTime(uint32 hour, uint32 minute, uint32 second); void SetTime(int32 hour, int32 minute, int32 second);
private:
void _CheckRange();
int32 _SectionValue(int32 index) const;
private:
BTime fTime;
}; };
@@ -52,14 +58,19 @@ class TDateEdit : public TSectionEdit {
virtual void SectionFocus(uint32 index); virtual void SectionFocus(uint32 index);
virtual float SeperatorWidth() const; virtual float SeperatorWidth() const;
void CheckRange();
virtual void DoUpPress(); virtual void DoUpPress();
virtual void DoDownPress(); virtual void DoDownPress();
virtual void BuildDispatch(BMessage *message); virtual void BuildDispatch(BMessage *message);
void SetDate(uint32 year, uint32 month, uint32 day); void SetDate(int32 year, int32 month, int32 day);
private:
void _CheckRange();
int32 _SectionValue(int32 index) const;
private:
BDate fDate;
}; };
#endif // DATETIME_H #endif // DATETIME_H
-54
View File
@@ -1,54 +0,0 @@
/*
* Copyright 2004-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* probably Mike Berg <[email protected]>
* and/or Andrew McCall <mccall@@digitalparadise.co.uk>
*/
#include "DateUtils.h"
#include "math.h"
#include <time.h>
bool
isLeapYear(const int year)
{
int realYear = year + 1900;
return ((realYear % 400 == 0) || (realYear % 4 == 0 && realYear % 100 != 0));
}
int
getDaysInMonth(const int month, const int year)
{
if (month == 1 && 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)
{
struct tm tm;
time_t currentTime = time(NULL);
localtime_r(&currentTime, &tm);
// TODO: review this.
// We rely on the fact that tm.tm_wday is calculated
// starting from the following parameters
tm.tm_mon = month;
tm.tm_year = year;
tm.tm_mday = 1;
currentTime = mktime(&tm);
localtime_r(&currentTime, &tm);
return tm.tm_wday;
}
-20
View File
@@ -1,20 +0,0 @@
/*
* Copyright 2004-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* probably Mike Berg <[email protected]>
* and/or Andrew McCall <mccall@@digitalparadise.co.uk>
*
*/
#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
+1 -1
View File
@@ -9,7 +9,6 @@ Preference Time :
Bitmaps.cpp Bitmaps.cpp
CalendarView.cpp CalendarView.cpp
DateTimeEdit.cpp DateTimeEdit.cpp
DateUtils.cpp
SectionEdit.cpp SectionEdit.cpp
SettingsView.cpp SettingsView.cpp
Time.cpp Time.cpp
@@ -17,6 +16,7 @@ Preference Time :
TimeWindow.cpp TimeWindow.cpp
TZDisplay.cpp TZDisplay.cpp
ZoneView.cpp ZoneView.cpp
DateTime.cpp
: be : be
: Time.rdef : Time.rdef
; ;
+31 -15
View File
@@ -3,7 +3,7 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* probably Mike Berg <mike@agamemnon.homelinux.net> * Mike Berg <mike@berg-net.us>
* Julun <[email protected]> * Julun <[email protected]>
* *
*/ */
@@ -19,7 +19,6 @@
const uint32 kArrowAreaWidth = 16; const uint32 kArrowAreaWidth = 16;
const uint32 kSeperatorWidth = 8;
TSectionEdit::TSectionEdit(BRect frame, const char *name, uint32 sections) TSectionEdit::TSectionEdit(BRect frame, const char *name, uint32 sections)
@@ -60,13 +59,12 @@ TSectionEdit::AttachedToWindow()
void void
TSectionEdit::Draw(BRect updaterect) TSectionEdit::Draw(BRect updateRect)
{ {
DrawBorder(); DrawBorder();
for (uint32 idx = 0; idx < fSectionCount; idx++) for (uint32 idx = 0; idx < fSectionCount; idx++) {
{
DrawSection(idx, ((uint32)fFocus == idx) && IsFocus()); DrawSection(idx, ((uint32)fFocus == idx) && IsFocus());
if (idx <fSectionCount -1) if (idx < fSectionCount -1)
DrawSeperator(idx); DrawSeperator(idx);
} }
} }
@@ -76,6 +74,7 @@ void
TSectionEdit::MouseDown(BPoint where) TSectionEdit::MouseDown(BPoint where)
{ {
MakeFocus(true); MakeFocus(true);
if (fUpRect.Contains(where)) if (fUpRect.Contains(where))
DoUpPress(); DoUpPress();
else if (fDownRect.Contains(where)) else if (fDownRect.Contains(where))
@@ -93,6 +92,21 @@ TSectionEdit::MouseDown(BPoint where)
} }
void
TSectionEdit::MakeFocus(bool focused)
{
if (focused == IsFocus())
return;
BControl::MakeFocus(focused);
if (fFocus == -1)
SectionFocus(0);
else
SectionFocus(fFocus);
}
void void
TSectionEdit::KeyDown(const char *bytes, int32 numbytes) TSectionEdit::KeyDown(const char *bytes, int32 numbytes)
{ {
@@ -133,9 +147,9 @@ TSectionEdit::KeyDown(const char *bytes, int32 numbytes)
void void
TSectionEdit::DispatchMessage() TSectionEdit::DispatchMessage()
{ {
BMessage *msg = new BMessage(H_USER_CHANGE); BMessage message(H_USER_CHANGE);
BuildDispatch(msg); BuildDispatch(&message);
Window()->PostMessage(msg); Window()->PostMessage(&message);
} }
@@ -157,13 +171,15 @@ void
TSectionEdit::InitView() TSectionEdit::InitView()
{ {
// create arrow bitmaps // create arrow bitmaps
BRect rect(0, 0, kUpArrowWidth -1, kUpArrowHeight -1);
fUpArrow = new BBitmap(rect, kUpArrowColorSpace);
fUpArrow->SetBits(kUpArrowBits, (kUpArrowWidth) *(kUpArrowHeight+1), 0
, kUpArrowColorSpace);
fUpArrow = new BBitmap(BRect(0, 0, kUpArrowWidth -1, kUpArrowHeight -1), kUpArrowColorSpace); rect = BRect(0, 0, kDownArrowWidth -1, kDownArrowHeight -2);
fUpArrow->SetBits(kUpArrowBits, (kUpArrowWidth) *(kUpArrowHeight+1), 0, kUpArrowColorSpace); fDownArrow = new BBitmap(rect, kDownArrowColorSpace);
fDownArrow->SetBits(kDownArrowBits, (kDownArrowWidth) *(kDownArrowHeight)
fDownArrow = new BBitmap(BRect(0, 0, kDownArrowWidth -1, kDownArrowHeight -2), kDownArrowColorSpace); , 0, kDownArrowColorSpace);
fDownArrow->SetBits(kDownArrowBits, (kDownArrowWidth) *(kDownArrowHeight), 0, kDownArrowColorSpace);
// setup sections // setup sections
fSectionList = new BList(fSectionCount); fSectionList = new BList(fSectionCount);
+2 -1
View File
@@ -3,7 +3,7 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* probably Mike Berg <mike@agamemnon.homelinux.net> * Mike Berg <mike@berg-net.us>
* Julun <[email protected]> * Julun <[email protected]>
* *
*/ */
@@ -48,6 +48,7 @@ class TSectionEdit: public BControl {
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual void Draw(BRect updateRect); virtual void Draw(BRect updateRect);
virtual void MouseDown(BPoint point); virtual void MouseDown(BPoint point);
virtual void MakeFocus(bool focused = true);
virtual void KeyDown(const char *bytes, int32 numBytes); virtual void KeyDown(const char *bytes, int32 numBytes);
uint32 CountSections() const; uint32 CountSections() const;
+96 -88
View File
@@ -3,8 +3,8 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* probably Mike Berg <[email protected]> * Andrew McCall <mccall@@digitalparadise.co.uk>
* and/or Andrew McCall <mccall@@digitalparadise.co.uk> * Mike Berg <mike@berg-net.us>
* Julun <[email protected]> * Julun <[email protected]>
*/ */
@@ -15,29 +15,31 @@
#include "TimeMessages.h" #include "TimeMessages.h"
#include <CheckBox.h>
#include <Entry.h> #include <Entry.h>
#include <File.h> #include <File.h>
#include <FindDirectory.h> #include <FindDirectory.h>
#include <Message.h>
#include <Path.h> #include <Path.h>
#include <RadioButton.h> #include <RadioButton.h>
#include <String.h> #include <String.h>
#include <StringView.h> #include <StringView.h>
#include <Window.h>
#include <stdio.h>
#include <stdlib.h>
TSettingsView::TSettingsView(BRect frame) TSettingsView::TSettingsView(BRect frame)
: BView(frame,"Settings", B_FOLLOW_ALL, : BView(frame,"Settings", B_FOLLOW_ALL,
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP), B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP),
fGmtTime(NULL) fGmtTime(NULL),
fInitialized(false)
{ {
InitView(); _ReadRTCSettings();
} }
TSettingsView::~TSettingsView() TSettingsView::~TSettingsView()
{ {
WriteRTCSettings(); _WriteRTCSettings();
} }
@@ -46,6 +48,35 @@ TSettingsView::AttachedToWindow()
{ {
if (Parent()) if (Parent())
SetViewColor(Parent()->ViewColor()); SetViewColor(Parent()->ViewColor());
if (!fInitialized) {
_InitView();
fInitialized = true;
}
}
void
TSettingsView::Draw(BRect /*updateRect*/)
{
rgb_color viewcolor = ViewColor();
rgb_color dark = tint_color(viewcolor, B_DARKEN_4_TINT);
rgb_color light = tint_color(viewcolor, B_LIGHTEN_MAX_TINT);
//draw a separator line
BRect bounds(Bounds());
BPoint start(bounds.Width() / 2.0f + 2.0f, bounds.top + 2.0f);
BPoint end(bounds.Width() / 2.0 + 2.0f, bounds.bottom - 2.0f);
BeginLineArray(2);
AddLine(start, end, dark);
start.x++;
end.x++;
AddLine(start, end, light);
EndLineArray();
fTimeEdit->Draw(bounds);
fDateEdit->Draw(bounds);
} }
@@ -56,10 +87,9 @@ TSettingsView::MessageReceived(BMessage *message)
switch(message->what) { switch(message->what) {
case B_OBSERVER_NOTICE_CHANGE: case B_OBSERVER_NOTICE_CHANGE:
message->FindInt32(B_OBSERVE_WHAT_CHANGE, &change); message->FindInt32(B_OBSERVE_WHAT_CHANGE, &change);
switch(change) switch(change) {
{
case H_TM_CHANGED: case H_TM_CHANGED:
UpdateDateTime(message); _UpdateDateTime(message);
break; break;
default: default:
@@ -68,6 +98,14 @@ TSettingsView::MessageReceived(BMessage *message)
} }
break; break;
case kDayChanged:
{
BMessage msg(*message);
msg.what = H_USER_CHANGE;
msg.AddBool("time", false);
Window()->PostMessage(&msg);
} break;
default: default:
BView::MessageReceived(message); BView::MessageReceived(message);
break; break;
@@ -79,10 +117,10 @@ void
TSettingsView::GetPreferredSize(float *width, float *height) TSettingsView::GetPreferredSize(float *width, float *height)
{ {
// hardcode in TimeWindow ... // hardcode in TimeWindow ...
*width = 361.0f; *width = 470.0f;
*height = 227.0f; *height = 227.0f;
if (fGmtTime) { if (fInitialized) {
// we are initialized // we are initialized
*width = Bounds().Width(); *width = Bounds().Width();
*height = fGmtTime->Frame().bottom; *height = fGmtTime->Frame().bottom;
@@ -91,19 +129,17 @@ TSettingsView::GetPreferredSize(float *width, float *height)
void void
TSettingsView::InitView() TSettingsView::_InitView()
{ {
ReadRTCSettings();
font_height fontHeight; font_height fontHeight;
be_plain_font->GetHeight(&fontHeight); be_plain_font->GetHeight(&fontHeight);
float textHeight = fontHeight.descent + fontHeight.ascent + fontHeight.leading; float textHeight = fontHeight.descent + fontHeight.ascent + fontHeight.leading;
// left side // left side
BRect frameLeft(Bounds()); BRect frameLeft(Bounds());
frameLeft.right = frameLeft.Width() / 2; frameLeft.right = frameLeft.Width() / 2.0;
frameLeft.InsetBy(10.0f, 10.0f); frameLeft.InsetBy(10.0f, 10.0f);
frameLeft.bottom = frameLeft.top + textHeight +6; frameLeft.bottom = frameLeft.top + textHeight + 6.0;
fDateEdit = new TDateEdit(frameLeft, "date_edit", 3); fDateEdit = new TDateEdit(frameLeft, "date_edit", 3);
AddChild(fDateEdit); AddChild(fDateEdit);
@@ -111,24 +147,28 @@ TSettingsView::InitView()
frameLeft.top = fDateEdit->Frame().bottom + 10; frameLeft.top = fDateEdit->Frame().bottom + 10;
frameLeft.bottom = Bounds().bottom - 10; frameLeft.bottom = Bounds().bottom - 10;
fCalendar = new TCalendarView(frameLeft, "calendar", B_FOLLOW_NONE, B_WILL_DRAW); fCalendarView = new BCalendarView(frameLeft, "calendar");
AddChild(fCalendar); fCalendarView->SetWeekNumberHeaderVisible(false);
AddChild(fCalendarView);
fCalendarView->SetSelectionMessage(new BMessage(kDayChanged));
fCalendarView->SetInvocationMessage(new BMessage(kDayChanged));
fCalendarView->SetTarget(this);
// right side // right side
BRect frameRight(Bounds()); BRect frameRight(Bounds());
frameRight.left = frameRight.Width() / 2; frameRight.left = frameRight.Width() / 2.0;
frameRight.InsetBy(10.0f, 10.0f); frameRight.InsetBy(10.0f, 10.0f);
frameRight.bottom = frameRight.top + textHeight +6; frameRight.bottom = frameRight.top + textHeight + 6.0;
fTimeEdit = new TTimeEdit(frameRight, "time_edit", 4); fTimeEdit = new TTimeEdit(frameRight, "time_edit", 4);
AddChild(fTimeEdit); AddChild(fTimeEdit);
frameRight.top = fTimeEdit->Frame().bottom + 10; frameRight.top = fTimeEdit->Frame().bottom + 10.0;
frameRight.bottom = Bounds().bottom - 10; frameRight.bottom = Bounds().bottom - 10.0;
float left = fTimeEdit->Frame().left; float left = fTimeEdit->Frame().left;
float tmp = MIN(frameRight.Width(), frameRight.Height()); float tmp = MIN(frameRight.Width(), frameRight.Height());
frameRight.left = left + (fTimeEdit->Bounds().Width() - tmp) /2; frameRight.left = left + (fTimeEdit->Bounds().Width() - tmp) / 2.0;
frameRight.bottom = frameRight.top + tmp; frameRight.bottom = frameRight.top + tmp;
frameRight.right = frameRight.left + tmp; frameRight.right = frameRight.left + tmp;
@@ -137,13 +177,13 @@ TSettingsView::InitView()
// clock radio buttons // clock radio buttons
frameRight.left = left; frameRight.left = left;
frameRight.top = fClock->Frame().bottom + 10; frameRight.top = fClock->Frame().bottom + 10.0;
BStringView *text = new BStringView(frameRight, "clockis", "Clock set to:"); BStringView *text = new BStringView(frameRight, "clockis", "Clock set to:");
AddChild(text); AddChild(text);
text->ResizeToPreferred(); text->ResizeToPreferred();
frameRight.left += 10.0f; frameRight.left += 10.0f;
frameRight.top = text->Frame().bottom + 5; frameRight.top = text->Frame().bottom + 5.0;
fLocalTime = new BRadioButton(frameRight, "local", "Local time", fLocalTime = new BRadioButton(frameRight, "local", "Local time",
new BMessage(H_RTC_CHANGE)); new BMessage(H_RTC_CHANGE));
@@ -164,66 +204,7 @@ TSettingsView::InitView()
void void
TSettingsView::Draw(BRect /*updateRect*/) TSettingsView::_ReadRTCSettings()
{
//draw a separator line
BRect bounds(Bounds());
rgb_color viewcolor = ViewColor();
rgb_color dark = tint_color(viewcolor, B_DARKEN_4_TINT);
rgb_color light = tint_color(viewcolor, B_LIGHTEN_MAX_TINT);
BPoint start(bounds.Width() / 2.0f +2.0f, bounds.top +1.0f);
BPoint end(bounds.Width() / 2.0 +2.0f, bounds.bottom -1.0f);
BeginLineArray(2);
AddLine(start, end, dark);
start.x++;
end.x++;
AddLine(start, end, light);
EndLineArray();
fTimeEdit->Draw(bounds);
fDateEdit->Draw(bounds);
}
bool
TSettingsView::GMTime()
{
return fGmtTime->Value() == B_CONTROL_ON;
}
void
TSettingsView::UpdateDateTime(BMessage *message)
{
int32 day;
int32 month;
int32 year;
if (message->FindInt32("month", &month) == B_OK
&& message->FindInt32("day", &day) == B_OK
&& message->FindInt32("year", &year) == B_OK)
{
fDateEdit->SetDate(year, month, day);
fCalendar->SetTo(year, month, day);
}
int32 hour;
int32 minute;
int32 second;
if (message->FindInt32("hour", &hour) == B_OK
&& message->FindInt32("minute", &minute) == B_OK
&& message->FindInt32("second", &second) == B_OK)
{
fTimeEdit->SetTime(hour, minute, second);
fClock->SetTime(hour, minute, second);
}
}
void
TSettingsView::ReadRTCSettings()
{ {
BPath path; BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
@@ -254,7 +235,7 @@ TSettingsView::ReadRTCSettings()
void void
TSettingsView::WriteRTCSettings() TSettingsView::_WriteRTCSettings()
{ {
BPath path; BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
@@ -270,3 +251,30 @@ TSettingsView::WriteRTCSettings()
file.Write("gmt", 3); file.Write("gmt", 3);
} }
} }
void
TSettingsView::_UpdateDateTime(BMessage *message)
{
int32 day;
int32 month;
int32 year;
if (message->FindInt32("month", &month) == B_OK
&& message->FindInt32("day", &day) == B_OK
&& message->FindInt32("year", &year) == B_OK)
{
fDateEdit->SetDate(year, month, day);
fCalendarView->SetDate(year, month, day);
}
int32 hour;
int32 minute;
int32 second;
if (message->FindInt32("hour", &hour) == B_OK
&& message->FindInt32("minute", &minute) == B_OK
&& message->FindInt32("second", &second) == B_OK)
{
fTimeEdit->SetTime(hour, minute, second);
fClock->SetTime(hour, minute, second);
}
}
+12 -11
View File
@@ -3,8 +3,8 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* probably Mike Berg <[email protected]> * Andrew McCall <mccall@@digitalparadise.co.uk>
* and/or Andrew McCall <mccall@@digitalparadise.co.uk> * Mike Berg <mike@berg-net.us>
* Julun <[email protected]> * Julun <[email protected]>
*/ */
#ifndef SETTINGS_VIEW_H #ifndef SETTINGS_VIEW_H
@@ -16,9 +16,9 @@
class TDateEdit; class TDateEdit;
class TTimeEdit; class TTimeEdit;
class TCalendarView; class BCalendarView;
class TAnalogClock;
class BRadioButton; class BRadioButton;
class TAnalogClock;
class TSettingsView : public BView { class TSettingsView : public BView {
@@ -31,21 +31,22 @@ class TSettingsView : public BView {
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage *message);
virtual void GetPreferredSize(float *width, float *height); virtual void GetPreferredSize(float *width, float *height);
bool GMTime(); private:
void _InitView();
void _ReadRTCSettings();
void _WriteRTCSettings();
void _UpdateDateTime(BMessage *message);
private: private:
void InitView();
void ReadRTCSettings();
void WriteRTCSettings();
void UpdateDateTime(BMessage *message);
BRadioButton *fLocalTime; BRadioButton *fLocalTime;
BRadioButton *fGmtTime; BRadioButton *fGmtTime;
TDateEdit *fDateEdit; TDateEdit *fDateEdit;
TTimeEdit *fTimeEdit; TTimeEdit *fTimeEdit;
TCalendarView *fCalendar; BCalendarView *fCalendarView;
TAnalogClock *fClock; TAnalogClock *fClock;
bool fIsLocalTime; bool fIsLocalTime;
bool fInitialized;
}; };
#endif // SETTINGS_VIEW_H #endif // SETTINGS_VIEW_H
+2 -2
View File
@@ -3,8 +3,8 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* probably Mike Berg <[email protected]> * Andrew McCall <mccall@@digitalparadise.co.uk>
* and/or Andrew McCall <mccall@@digitalparadise.co.uk> * Mike Berg <mike@berg-net.us>
* Julun <[email protected]> * Julun <[email protected]>
* *
*/ */
+2 -2
View File
@@ -3,8 +3,8 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* probably Mike Berg <[email protected]> * Andrew McCall <mccall@@digitalparadise.co.uk>
* and/or Andrew McCall <mccall@@digitalparadise.co.uk> * Mike Berg <mike@berg-net.us>
* Julun <[email protected]> * Julun <[email protected]>
* *
*/ */
+1 -1
View File
@@ -4,7 +4,7 @@
* *
* Authors: * Authors:
* Andrew McCall <[email protected]> * Andrew McCall <[email protected]>
* Mike Berg <mike@agamemnon.homelinux.net> * Mike Berg <mike@berg-net.us>
* Julun <[email protected]> * Julun <[email protected]>
*/ */
+1 -1
View File
@@ -4,7 +4,7 @@
* *
* Authors: * Authors:
* Andrew McCall, [email protected] * Andrew McCall, [email protected]
* Mike Berg <mike@agamemnon.homelinux.net> * Mike Berg <mike@berg-net.us>
* Julun <[email protected]> * Julun <[email protected]>
*/ */
#ifndef TIME_H #ifndef TIME_H
+6 -6
View File
@@ -4,7 +4,7 @@
* *
* Authors: * Authors:
* Andrew McCall, [email protected] * Andrew McCall, [email protected]
* Mike Berg <mike@agamemnon.homelinux.net> * Mike Berg <mike@berg-net.us>
* Julun <[email protected]> * Julun <[email protected]>
*/ */
#ifndef TIME_MESSAGES_H #ifndef TIME_MESSAGES_H
@@ -29,20 +29,20 @@ const uint32 RTC_SETTINGS = 'RTse';
// clock tick message // clock tick message
const uint32 H_TIME_UPDATE ='obTU'; const uint32 H_TIME_UPDATE ='obTU';
// clicked on day in claendar
const uint32 H_DAY_CHANGED = 'obDC';
//notice for clock ticks //notice for clock ticks
const uint32 H_TM_CHANGED = 'obTC'; const uint32 H_TM_CHANGED = 'obTC';
//notice for user changes //notice for user changes
const uint32 H_USER_CHANGE = 'obUC'; const uint32 H_USER_CHANGE = 'obUC';
// local/gmt radiobuttons // local/ gmt radiobuttons
const uint32 H_RTC_CHANGE = 'obRC'; const uint32 H_RTC_CHANGE = 'obRC';
// sunday/monday radio button // sunday/ monday radio button
const uint32 kWeekStart = '_kws'; const uint32 kWeekStart = '_kws';
// clicked on day in calendar
const uint32 kDayChanged = '_kdc';
#endif //TIME_MESSAGES_H #endif //TIME_MESSAGES_H
+2 -1
View File
@@ -4,8 +4,9 @@
* *
* Authors: * Authors:
* Andrew McCall, [email protected] * Andrew McCall, [email protected]
* Mike Berg <mike@agamemnon.homelinux.net> * Mike Berg <mike@berg-net.us>
* Julun <[email protected]> * Julun <[email protected]>
*
*/ */
#include "TimeSettings.h" #include "TimeSettings.h"
+1 -1
View File
@@ -4,7 +4,7 @@
* *
* Authors: * Authors:
* Andrew McCall, [email protected] * Andrew McCall, [email protected]
* Mike Berg <mike@agamemnon.homelinux.net> * Mike Berg <mike@berg-net.us>
* Julun <[email protected]> * Julun <[email protected]>
*/ */
#ifndef TIME_SETTINGS_H #ifndef TIME_SETTINGS_H
+5 -12
View File
@@ -5,6 +5,7 @@
* Authors: * Authors:
* Andrew McCall <mccall@@digitalparadise.co.uk> * Andrew McCall <mccall@@digitalparadise.co.uk>
* Julun <[email protected]> * Julun <[email protected]>
*
*/ */
#include "TimeWindow.h" #include "TimeWindow.h"
@@ -20,7 +21,7 @@
#include <TabView.h> #include <TabView.h>
#define WINDOW_RIGHT 400 #define WINDOW_RIGHT 470
#define WINDOW_BOTTOM 227 #define WINDOW_BOTTOM 227
@@ -46,17 +47,9 @@ TTimeWindow::MessageReceived(BMessage *message)
{ {
switch(message->what) { switch(message->what) {
case H_USER_CHANGE: case H_USER_CHANGE:
{ fBaseView->ChangeTime(message);
bool isTime;
if (message->FindBool("time", &isTime) == B_OK)
fBaseView->ChangeTime(message);
break; break;
}
case H_RTC_CHANGE:
fBaseView->SetGMTime(fTimeSettings->GMTime());
break;
default: default:
BWindow::MessageReceived(message); BWindow::MessageReceived(message);
break; break;
@@ -114,8 +107,8 @@ TTimeWindow::_InitWindow()
float width; float width;
float height; float height;
fTimeSettings->GetPreferredSize(&width, &height);
// width/ height from settingsview + all InsetBy etc.. // width/ height from settingsview + all InsetBy etc..
ResizeTo(width +5, height + tabview->TabHeight() +25); fTimeSettings->GetPreferredSize(&width, &height);
ResizeTo(width +10, height + tabview->TabHeight() +25);
} }
+1
View File
@@ -5,6 +5,7 @@
* Authors: * Authors:
* Andrew McCall <mccall@@digitalparadise.co.uk> * Andrew McCall <mccall@@digitalparadise.co.uk>
* Julun <[email protected]> * Julun <[email protected]>
*
*/ */
#ifndef TIME_WINDOW_H #ifndef TIME_WINDOW_H
#define TIME_WINDOW_H #define TIME_WINDOW_H
+1 -1
View File
@@ -3,7 +3,7 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Mike Berg <mike@agamemnon.homelinux.net> * Mike Berg <mike@berg-net.us>
* Julun <[email protected]> * Julun <[email protected]>
*/ */
+1 -1
View File
@@ -3,7 +3,7 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Mike Berg <mike@agamemnon.homelinux.net> * Mike Berg <mike@berg-net.us>
* Julun <[email protected]> * Julun <[email protected]>
*/ */
#ifndef ZONE_VIEW_H #ifndef ZONE_VIEW_H