* 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:
@@ -3,7 +3,7 @@
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Mike Berg (inseculous)
|
||||
* Mike Berg <mike@berg-net.us>
|
||||
* Julun <[email protected]>
|
||||
* Stephan Aßmus <[email protected]>
|
||||
*/
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Mike Berg (inseculous)
|
||||
* Mike Berg <mike@berg-net.us>
|
||||
* Julun <[email protected]>
|
||||
*/
|
||||
#ifndef ANALOG_CLOCK_H
|
||||
|
||||
@@ -3,21 +3,20 @@
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Mike Berg (inseculous)
|
||||
* Mike Berg <mike@berg-net.us>
|
||||
* Julun <[email protected]>
|
||||
*/
|
||||
|
||||
#include "BaseView.h"
|
||||
#include "DateTime.h"
|
||||
#include "TimeMessages.h"
|
||||
|
||||
|
||||
#include <Message.h>
|
||||
#include <OS.h>
|
||||
|
||||
|
||||
TTimeBaseView::TTimeBaseView(BRect frame, const char *name)
|
||||
: BView(frame, name, B_FOLLOW_ALL_SIDES, B_PULSE_NEEDED),
|
||||
fIsGMT(false),
|
||||
fMessage(H_TIME_UPDATE)
|
||||
{
|
||||
}
|
||||
@@ -32,7 +31,7 @@ void
|
||||
TTimeBaseView::Pulse()
|
||||
{
|
||||
if (IsWatched())
|
||||
DispatchMessage();
|
||||
_SendNotices();
|
||||
}
|
||||
|
||||
|
||||
@@ -43,13 +42,6 @@ TTimeBaseView::AttachedToWindow()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TTimeBaseView::SetGMTime(bool gmt)
|
||||
{
|
||||
fIsGMT = gmt;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TTimeBaseView::ChangeTime(BMessage *message)
|
||||
{
|
||||
@@ -57,64 +49,62 @@ TTimeBaseView::ChangeTime(BMessage *message)
|
||||
if (message->FindBool("time", &isTime) != B_OK)
|
||||
return;
|
||||
|
||||
time_t tmp = time(NULL);
|
||||
struct tm *tm_struct = localtime(&tmp);
|
||||
|
||||
BDateTime dateTime = BDateTime::CurrentDateTime(B_LOCAL_TIME);
|
||||
|
||||
if (isTime) {
|
||||
int32 hour = 0;
|
||||
if (message->FindInt32("hour", &hour) == B_OK)
|
||||
tm_struct->tm_hour = hour;
|
||||
BTime time = dateTime.Time();
|
||||
int32 hour;
|
||||
if (message->FindInt32("hour", &hour) != B_OK)
|
||||
hour = time.Hour();
|
||||
|
||||
int32 minute = 0;
|
||||
if (message->FindInt32("minute", &minute) == B_OK)
|
||||
tm_struct->tm_min = minute;
|
||||
int32 minute;
|
||||
if (message->FindInt32("minute", &minute) != B_OK)
|
||||
minute = time.Minute();
|
||||
|
||||
int32 second = 0;
|
||||
if (message->FindInt32("second", &second) == B_OK)
|
||||
tm_struct->tm_sec = second;
|
||||
int32 second;
|
||||
if (message->FindInt32("second", &second) != B_OK)
|
||||
second = time.Second();
|
||||
|
||||
bool isAM = false;
|
||||
if (message->FindBool("isam", &isAM) == B_OK) {
|
||||
if (!isAM)
|
||||
tm_struct->tm_hour += 12;
|
||||
}
|
||||
time.SetTime(hour, minute, second);
|
||||
dateTime.SetTime(time);
|
||||
} else {
|
||||
int32 month = 0;
|
||||
if (message->FindInt32("month", &month) == B_OK)
|
||||
tm_struct->tm_mon = month;
|
||||
BDate date = dateTime.Date();
|
||||
int32 day;
|
||||
if (message->FindInt32("day", &day) != B_OK)
|
||||
day = date.Day();
|
||||
|
||||
int32 day = 0;
|
||||
if (message->FindInt32("day", &day) == B_OK)
|
||||
tm_struct->tm_mday = day;
|
||||
int32 year;
|
||||
if (message->FindInt32("year", &year) != B_OK)
|
||||
year = date.Year();
|
||||
|
||||
int32 year = 0;
|
||||
if (message->FindInt32("year", &year) == B_OK)
|
||||
tm_struct->tm_year = year;
|
||||
int32 month;
|
||||
if (message->FindInt32("month", &month) != B_OK)
|
||||
month = date.Month();
|
||||
|
||||
if (year >= 1970 && year <= 2037) {
|
||||
date.SetDate(year, month, day);
|
||||
dateTime.SetDate(date);
|
||||
}
|
||||
}
|
||||
|
||||
tmp = mktime(tm_struct);
|
||||
set_real_time_clock(tmp);
|
||||
|
||||
set_real_time_clock(dateTime.Time_t());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TTimeBaseView::DispatchMessage()
|
||||
TTimeBaseView::_SendNotices()
|
||||
{
|
||||
time_t tmp = time(NULL);
|
||||
struct tm *tm_struct = localtime(&tmp);
|
||||
|
||||
if (fIsGMT)
|
||||
tm_struct = gmtime(&tmp);
|
||||
|
||||
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);
|
||||
fMessage.AddInt32("day", tm_struct->tm_mday);
|
||||
fMessage.AddInt32("year", tm_struct->tm_year);
|
||||
|
||||
fMessage.AddInt32("hour", tm_struct->tm_hour);
|
||||
fMessage.AddInt32("minute", tm_struct->tm_min);
|
||||
fMessage.AddInt32("second", tm_struct->tm_sec);
|
||||
BTime time = BTime::CurrentTime(B_LOCAL_TIME);
|
||||
fMessage.AddInt32("hour", time.Hour());
|
||||
fMessage.AddInt32("minute", time.Minute());
|
||||
fMessage.AddInt32("second", time.Second());
|
||||
|
||||
SendNotices(H_TM_CHANGED, &fMessage);
|
||||
}
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Mike Berg (inseculous)
|
||||
* Mike Berg <mike@berg-net.us>
|
||||
* Julun <[email protected]>
|
||||
*/
|
||||
#ifndef TIMEBASE_H
|
||||
#define TIMEBASE_H
|
||||
|
||||
|
||||
#include <View.h>
|
||||
#include <Message.h>
|
||||
#include <View.h>
|
||||
|
||||
|
||||
class TTimeBaseView: public BView {
|
||||
@@ -22,14 +22,12 @@ class TTimeBaseView: public BView {
|
||||
virtual void Pulse();
|
||||
virtual void AttachedToWindow();
|
||||
|
||||
void SetGMTime(bool gmtTime);
|
||||
void ChangeTime(BMessage *message);
|
||||
|
||||
protected:
|
||||
virtual void DispatchMessage();
|
||||
private:
|
||||
void _SendNotices();
|
||||
|
||||
private:
|
||||
bool fIsGMT;
|
||||
BMessage fMessage;
|
||||
};
|
||||
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* probably Mike Berg <[email protected]>
|
||||
* and/or Andrew McCall <mccall@@digitalparadise.co.uk>
|
||||
* Andrew McCall <mccall@@digitalparadise.co.uk>
|
||||
* Mike Berg <mike@berg-net.us>
|
||||
* Julun <[email protected]>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "Bitmaps.h"
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* probably Mike Berg <[email protected]>
|
||||
* and/or Andrew McCall <mccall@@digitalparadise.co.uk>
|
||||
* Andrew McCall <mccall@@digitalparadise.co.uk>
|
||||
* Mike Berg <mike@berg-net.us>
|
||||
* Julun <[email protected]>
|
||||
*
|
||||
*/
|
||||
#ifndef ANALOG_CLOCK_H
|
||||
#define ANALOG_CLOCK_H
|
||||
|
||||
+1156
-388
File diff suppressed because it is too large
Load Diff
@@ -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.
|
||||
*
|
||||
* Authors:
|
||||
* probably Mike Berg <mike@agamemnon.homelinux.net>
|
||||
* and/or Andrew McCall <mccall@@digitalparadise.co.uk>
|
||||
*/
|
||||
#ifndef CALENDAR_VIEW_H
|
||||
#define CALENDAR_VIEW_H
|
||||
#ifndef _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>
|
||||
|
||||
|
||||
class TDay: public BControl {
|
||||
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);
|
||||
class BMessage;
|
||||
|
||||
int Day()
|
||||
{ return f_day; }
|
||||
protected:
|
||||
virtual void Stroke3dFrame(BRect frame, rgb_color light, rgb_color dark, bool inset);
|
||||
private:
|
||||
int f_day;
|
||||
|
||||
enum week_start {
|
||||
B_WEEK_START_MONDAY,
|
||||
B_WEEK_START_SUNDAY
|
||||
};
|
||||
|
||||
class TCalendarView: public BView {
|
||||
|
||||
class BCalendarView : public BView, public BInvoker {
|
||||
public:
|
||||
TCalendarView(BRect frame, const char *name, uint32 resizingmode, uint32 flags);
|
||||
virtual ~TCalendarView();
|
||||
virtual void AttachedToWindow();
|
||||
virtual void Draw(BRect bounds);
|
||||
void KeyDown(const char *bytes, int32 numbytes);
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
BCalendarView(BRect frame, const char *name,
|
||||
uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||
uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE);
|
||||
|
||||
BCalendarView(BRect frame, const char *name, week_start start,
|
||||
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);
|
||||
protected:
|
||||
virtual void InitView();
|
||||
virtual void DispatchMessage();
|
||||
virtual void DrawDay(BView *owner, BRect frame, const char *text,
|
||||
bool isSelected = false, bool isEnabled = true,
|
||||
bool focus = false);
|
||||
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:
|
||||
void InitDates();
|
||||
void CalcFlags();
|
||||
int32 IndexOf(BView *) const;
|
||||
void _InitObject();
|
||||
|
||||
TDay *f_cday;
|
||||
TDay *f_focused;
|
||||
BRect f_dayrect;
|
||||
// x = index of first day; y = index of last;
|
||||
BPoint f_daybound;
|
||||
int f_firstday;
|
||||
int f_month;
|
||||
int f_day;
|
||||
int f_year;
|
||||
void _SetToDay();
|
||||
void _GetYearMonth(int32 *year, int32 *month) const;
|
||||
void _GetPreferredSize(float *width, float *height);
|
||||
|
||||
void _SetupDayNames();
|
||||
void _SetupDayNumbers();
|
||||
void _SetupWeekNumbers();
|
||||
|
||||
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_
|
||||
|
||||
Executable
+483
@@ -0,0 +1,483 @@
|
||||
/*
|
||||
* Copyright 2004-2006, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Julun <host.haiku@gmx.de>
|
||||
* Stephan Aßmus <superstippi@gmx.de>
|
||||
*/
|
||||
|
||||
#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));
|
||||
}
|
||||
Executable
+100
@@ -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_
|
||||
@@ -3,45 +3,24 @@
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* probably Mike Berg <mike@agamemnon.homelinux.net>
|
||||
* and/or Andrew McCall <mccall@@digitalparadise.co.uk>
|
||||
* McCall <mccall@@digitalparadise.co.uk>
|
||||
* Mike Berg <mike@berg-net.us>
|
||||
* Julun <host.haiku@gmx.de>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "DateTimeEdit.h"
|
||||
#include "DateUtils.h"
|
||||
|
||||
|
||||
#include <List.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)
|
||||
: TSectionEdit(frame, name, sections)
|
||||
{
|
||||
InitView();
|
||||
fTime = BTime::CurrentTime(B_LOCAL_TIME);
|
||||
}
|
||||
|
||||
|
||||
@@ -64,27 +43,25 @@ void
|
||||
TTimeEdit::DrawSection(uint32 index, bool hasFocus)
|
||||
{
|
||||
// user defined section drawing
|
||||
TDateTimeSection *section;
|
||||
section = (TDateTimeSection *)fSectionList->ItemAt(index);
|
||||
TSection *section = NULL;
|
||||
section = static_cast<TSection*> (fSectionList->ItemAt(index));
|
||||
|
||||
if (!section)
|
||||
return;
|
||||
|
||||
BRect bounds = section->Frame();
|
||||
uint32 value = _SectionValue(index);
|
||||
|
||||
// format value to display
|
||||
|
||||
uint32 value;
|
||||
|
||||
SetLowColor(ViewColor());
|
||||
if (hasFocus) {
|
||||
SetLowColor(tint_color(ViewColor(), B_DARKEN_1_TINT));
|
||||
value = fHoldValue;
|
||||
} else {
|
||||
SetLowColor(ViewColor());
|
||||
value = section->Data();
|
||||
}
|
||||
|
||||
BString text;
|
||||
// format value (new method?)
|
||||
switch (index) {
|
||||
case 0: // hour
|
||||
case 0:
|
||||
{ // hour
|
||||
if (value > 12) {
|
||||
if (value < 22)
|
||||
text << "0";
|
||||
@@ -96,53 +73,55 @@ TTimeEdit::DrawSection(uint32 index, bool hasFocus)
|
||||
text << "0";
|
||||
text << value;
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case 1: // minute
|
||||
case 2: // second
|
||||
case 1:
|
||||
case 2:
|
||||
{ // minute
|
||||
// second
|
||||
if (value < 10)
|
||||
text << "0";
|
||||
text << value;
|
||||
break;
|
||||
} break;
|
||||
|
||||
case 3: // am/pm
|
||||
value = ((TDateTimeSection *)fSectionList->ItemAt(0))->Data();
|
||||
case 3:
|
||||
{ // am/pm
|
||||
value = fTime.Hour();
|
||||
if (value >= 12)
|
||||
text << "PM";
|
||||
else
|
||||
text << "AM";
|
||||
break;
|
||||
} break;
|
||||
|
||||
default:
|
||||
return;
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
// calc and center text in section rect
|
||||
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 drawpt(bounds.LeftBottom() -offset);
|
||||
BPoint offset(-((bounds.Width()- width) / 2.0) -1.0
|
||||
, bounds.Height() / 2.0 -6.0);
|
||||
|
||||
SetHighColor(0, 0, 0, 255);
|
||||
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
|
||||
TTimeEdit::DrawSeperator(uint32 index)
|
||||
{
|
||||
if (index == 3)
|
||||
return;
|
||||
|
||||
TDateTimeSection *section = (TDateTimeSection *)fSectionList->ItemAt(index);
|
||||
TSection *section = NULL;
|
||||
section = static_cast<TSection*> (fSectionList->ItemAt(index));
|
||||
|
||||
if (!section)
|
||||
return;
|
||||
|
||||
BRect bounds = section->Frame();
|
||||
float sepWidth = SeperatorWidth();
|
||||
|
||||
@@ -151,20 +130,17 @@ TTimeEdit::DrawSeperator(uint32 index)
|
||||
sep = "-";
|
||||
|
||||
float width = be_plain_font->StringWidth(sep);
|
||||
|
||||
BPoint offset(-(sepWidth / 2.0 - width / 2.0) -1.0, bounds.Height() / 2.0 -6.0);
|
||||
BPoint drawpt(bounds.RightBottom() -offset);
|
||||
|
||||
DrawString(sep, drawpt);
|
||||
BPoint offset(-((sepWidth - width) / 2.0) -1.0
|
||||
, bounds.Height() / 2.0 -6.0);
|
||||
DrawString(sep, bounds.RightBottom() - offset);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TTimeEdit::SetSections(BRect area)
|
||||
{
|
||||
// by default divie up the sections evenly
|
||||
// by default divide up the sections evenly
|
||||
BRect bounds(area);
|
||||
// no comp for sep width
|
||||
|
||||
float sepWidth = SeperatorWidth();
|
||||
|
||||
@@ -173,13 +149,13 @@ TTimeEdit::SetSections(BRect area)
|
||||
bounds.right = bounds.left + (width -sepWidth / fSectionCount);
|
||||
|
||||
for (uint32 idx = 0; idx < fSectionCount; idx++) {
|
||||
fSectionList->AddItem(new TDateTimeSection(bounds));
|
||||
fSectionList->AddItem(new TSection(bounds));
|
||||
|
||||
bounds.left = bounds.right + sepWidth;
|
||||
if (idx == fSectionCount -2)
|
||||
bounds.right = area.right -1;
|
||||
else
|
||||
bounds.right = bounds.left + (width -sep_2);
|
||||
bounds.right = bounds.left + (width - sep_2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,7 +163,7 @@ TTimeEdit::SetSections(BRect area)
|
||||
float
|
||||
TTimeEdit::SeperatorWidth() const
|
||||
{
|
||||
return 8.0f;
|
||||
return 10.0f;
|
||||
}
|
||||
|
||||
|
||||
@@ -195,42 +171,20 @@ void
|
||||
TTimeEdit::SectionFocus(uint32 index)
|
||||
{
|
||||
fFocus = index;
|
||||
|
||||
// update hold value
|
||||
fHoldValue = ((TDateTimeSection *)fSectionList->ItemAt(fFocus))->Data();
|
||||
|
||||
fHoldValue = _SectionValue(index);
|
||||
Draw(Bounds());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TTimeEdit::SetTime(uint32 hour, uint32 minute, uint32 second)
|
||||
TTimeEdit::SetTime(int32 hour, int32 minute, int32 second)
|
||||
{
|
||||
if (fSectionList->CountItems()> 0)
|
||||
{
|
||||
bool update = false;
|
||||
|
||||
TDateTimeSection *section = (TDateTimeSection *)fSectionList->ItemAt(0);
|
||||
if (section->Data() != hour) {
|
||||
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());
|
||||
}
|
||||
if (fTime.Hour() == hour && fTime.Minute() == minute
|
||||
&& fTime.Second() == second)
|
||||
return;
|
||||
|
||||
fTime.SetTime(hour, minute, second);
|
||||
Invalidate(Bounds());
|
||||
}
|
||||
|
||||
|
||||
@@ -243,7 +197,7 @@ TTimeEdit::DoUpPress()
|
||||
// update displayed value
|
||||
fHoldValue += 1;
|
||||
|
||||
CheckRange();
|
||||
_CheckRange();
|
||||
|
||||
// send message to change time
|
||||
DispatchMessage();
|
||||
@@ -259,7 +213,7 @@ TTimeEdit::DoDownPress()
|
||||
// update display value
|
||||
fHoldValue -= 1;
|
||||
|
||||
CheckRange();
|
||||
_CheckRange();
|
||||
|
||||
// send message to change time
|
||||
DispatchMessage();
|
||||
@@ -269,74 +223,105 @@ TTimeEdit::DoDownPress()
|
||||
void
|
||||
TTimeEdit::BuildDispatch(BMessage *message)
|
||||
{
|
||||
const char *fields[4] = {"hour", "minute", "second", "isam"};
|
||||
const char *fields[3] = { "hour", "minute", "second" };
|
||||
|
||||
message->AddBool("time", true);
|
||||
|
||||
for (int32 idx = 0; idx < fSectionList->CountItems() -1; idx++) {
|
||||
uint32 data = ((TDateTimeSection *)fSectionList->ItemAt(idx))->Data();
|
||||
for (int32 index = 0; index < fSectionList->CountItems() -1; ++index) {
|
||||
uint32 data = _SectionValue(index);
|
||||
|
||||
if (fFocus == idx)
|
||||
if (fFocus == index)
|
||||
data = fHoldValue;
|
||||
|
||||
if (idx == 3) // isam
|
||||
message->AddBool(fields[idx], data == 1);
|
||||
else
|
||||
message->AddInt32(fields[idx], data);
|
||||
message->AddInt32(fields[index], data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TTimeEdit::CheckRange()
|
||||
TTimeEdit::_CheckRange()
|
||||
{
|
||||
int32 value = fHoldValue;
|
||||
switch (fFocus) {
|
||||
case 0: // hour
|
||||
if (value> 23)
|
||||
case 0:
|
||||
{ // hour
|
||||
if (value > 23)
|
||||
value = 0;
|
||||
else if (value < 0)
|
||||
value = 23;
|
||||
break;
|
||||
|
||||
case 1: // minute
|
||||
fTime.SetTime(value, fTime.Minute(), fTime.Second());
|
||||
} break;
|
||||
|
||||
case 1:
|
||||
{ // minute
|
||||
if (value> 59)
|
||||
value = 0;
|
||||
else if (value < 0)
|
||||
value = 59;
|
||||
break;
|
||||
|
||||
case 2: // second
|
||||
fTime.SetTime(fTime.Hour(), value, fTime.Second());
|
||||
} break;
|
||||
|
||||
case 2:
|
||||
{ // second
|
||||
if (value > 59)
|
||||
value = 0;
|
||||
else if (value < 0)
|
||||
value = 59;
|
||||
|
||||
break;
|
||||
|
||||
fTime.SetTime(fTime.Hour(), fTime.Minute(), value);
|
||||
} break;
|
||||
|
||||
case 3:
|
||||
// modify hour value to reflect change in am/pm
|
||||
value = ((TDateTimeSection *)fSectionList->ItemAt(0))->Data();
|
||||
{
|
||||
value = fTime.Hour();
|
||||
if (value < 13)
|
||||
value += 12;
|
||||
else
|
||||
value -= 12;
|
||||
if (value == 24)
|
||||
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:
|
||||
return;
|
||||
}
|
||||
|
||||
((TDateTimeSection *)fSectionList->ItemAt(fFocus))->SetData(value);
|
||||
fHoldValue = value;
|
||||
|
||||
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 -
|
||||
|
||||
|
||||
@@ -344,6 +329,7 @@ TDateEdit::TDateEdit(BRect frame, const char *name, uint32 sections)
|
||||
: TSectionEdit(frame, name, sections)
|
||||
{
|
||||
InitView();
|
||||
fDate = BDate::CurrentDate(B_LOCAL_TIME);
|
||||
}
|
||||
|
||||
|
||||
@@ -366,54 +352,32 @@ void
|
||||
TDateEdit::DrawSection(uint32 index, bool hasFocus)
|
||||
{
|
||||
// user defined section drawing
|
||||
TDateTimeSection *section;
|
||||
section = (TDateTimeSection *)fSectionList->ItemAt(index);
|
||||
TSection *section = NULL;
|
||||
section = static_cast<TSection*> (fSectionList->ItemAt(index));
|
||||
|
||||
if (!section)
|
||||
return;
|
||||
|
||||
BRect bounds = section->Frame();
|
||||
uint32 value = _SectionValue(index);
|
||||
|
||||
// format value to display
|
||||
|
||||
uint32 value;
|
||||
|
||||
SetLowColor(ViewColor());
|
||||
if (hasFocus) {
|
||||
SetLowColor(tint_color(ViewColor(), B_DARKEN_1_TINT));
|
||||
value = fHoldValue;
|
||||
} else {
|
||||
SetLowColor(ViewColor());
|
||||
value = section->Data();
|
||||
}
|
||||
|
||||
BString text;
|
||||
switch (index) {
|
||||
case 0:
|
||||
{ // month
|
||||
struct tm tm;
|
||||
tm.tm_mon = 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;
|
||||
}
|
||||
if (index != 0) {
|
||||
if (value < 10) text << "0";
|
||||
text << value;
|
||||
} else
|
||||
text.SetTo(fDate.LongMonthName(value));
|
||||
|
||||
// calc and center text in section rect
|
||||
float width = StringWidth(text.String());
|
||||
BPoint offset(-(bounds.Width() - width) / 2.0 - 1.0, (bounds.Height() / 2.0 - 6.0));
|
||||
|
||||
if (index == 0)
|
||||
offset.x = -(bounds.Width() - width) ;
|
||||
BPoint offset(-(bounds.Width() - width) / 2.0 - 1.0
|
||||
, (bounds.Height() / 2.0 - 6.0));
|
||||
|
||||
SetHighColor(0, 0, 0, 255);
|
||||
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
|
||||
TDateEdit::DrawSeperator(uint32 index)
|
||||
{
|
||||
if (index == 3)
|
||||
return;
|
||||
|
||||
TDateTimeSection *section = (TDateTimeSection *)fSectionList->ItemAt(index);
|
||||
TSection *section = NULL;
|
||||
section = static_cast<TSection*> (fSectionList->ItemAt(index));
|
||||
BRect bounds = section->Frame();
|
||||
|
||||
float sepWidth = SeperatorWidth();
|
||||
float width = be_plain_font->StringWidth("/");
|
||||
|
||||
BPoint offset(-(sepWidth / 2.0 - width / 2.0) -1.0, bounds.Height() / 2.0 -6.0);
|
||||
BPoint drawpt(bounds.RightBottom() - offset);
|
||||
BPoint offset(-(sepWidth / 2.0 - width / 2.0) -1.0
|
||||
, 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
|
||||
for (uint32 idx = 0; idx < fSectionCount; idx++)
|
||||
fSectionList->AddItem(new TDateTimeSection(area));
|
||||
fSectionList->AddItem(new TSection(area));
|
||||
|
||||
BRect bounds(area);
|
||||
float sepWidth = SeperatorWidth();
|
||||
|
||||
// year
|
||||
TSection *section = NULL;
|
||||
float width = be_plain_font->StringWidth("0000") +6;
|
||||
bounds.right = area.right;
|
||||
bounds.left = bounds.right -width;
|
||||
((TDateTimeSection *)fSectionList->ItemAt(2))->SetFrame(bounds);
|
||||
|
||||
float sepWidth = SeperatorWidth();
|
||||
section = static_cast<TSection*> (fSectionList->ItemAt(2));
|
||||
section->SetFrame(bounds);
|
||||
|
||||
// day
|
||||
width = be_plain_font->StringWidth("00") +6;
|
||||
bounds.right = bounds.left -sepWidth;
|
||||
bounds.left = bounds.right -width;
|
||||
((TDateTimeSection *)fSectionList->ItemAt(1))->SetFrame(bounds);
|
||||
section = static_cast<TSection*> (fSectionList->ItemAt(1));
|
||||
section->SetFrame(bounds);
|
||||
|
||||
// month
|
||||
bounds.right = bounds.left - sepWidth;
|
||||
bounds.left = area.left;
|
||||
((TDateTimeSection *)fSectionList->ItemAt(0))->SetFrame(bounds);
|
||||
section = static_cast<TSection*> (fSectionList->ItemAt(0));
|
||||
section->SetFrame(bounds);
|
||||
}
|
||||
|
||||
|
||||
float
|
||||
TDateEdit::SeperatorWidth() const
|
||||
{
|
||||
return 8.0f;
|
||||
return 10.0f;
|
||||
}
|
||||
|
||||
|
||||
@@ -485,41 +450,19 @@ void
|
||||
TDateEdit::SectionFocus(uint32 index)
|
||||
{
|
||||
fFocus = index;
|
||||
|
||||
// update hold value
|
||||
fHoldValue = ((TDateTimeSection *)fSectionList->ItemAt(fFocus))->Data();
|
||||
|
||||
fHoldValue = _SectionValue(index);
|
||||
Draw(Bounds());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TDateEdit::SetDate(uint32 year, uint32 month, uint32 day)
|
||||
TDateEdit::SetDate(int32 year, int32 month, int32 day)
|
||||
{
|
||||
if (fSectionList->CountItems() > 0) {
|
||||
bool update = false;
|
||||
if (year == fDate.Year() && month == fDate.Month() && day == fDate.Day())
|
||||
return;
|
||||
|
||||
TDateTimeSection *section = (TDateTimeSection *)fSectionList->ItemAt(0);
|
||||
if (section->Data() != month) {
|
||||
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());
|
||||
}
|
||||
fDate.SetDate(year, month, day);
|
||||
Invalidate(Bounds());
|
||||
}
|
||||
|
||||
|
||||
@@ -532,7 +475,7 @@ TDateEdit::DoUpPress()
|
||||
// update displayed value
|
||||
fHoldValue += 1;
|
||||
|
||||
CheckRange();
|
||||
_CheckRange();
|
||||
|
||||
// send message to change Date
|
||||
DispatchMessage();
|
||||
@@ -548,7 +491,7 @@ TDateEdit::DoDownPress()
|
||||
// update display value
|
||||
fHoldValue -= 1;
|
||||
|
||||
CheckRange();
|
||||
_CheckRange();
|
||||
|
||||
// send message to change Date
|
||||
DispatchMessage();
|
||||
@@ -558,65 +501,88 @@ TDateEdit::DoDownPress()
|
||||
void
|
||||
TDateEdit::BuildDispatch(BMessage *message)
|
||||
{
|
||||
const char *fields[3] = {"month", "day", "year"};
|
||||
const char *fields[3] = { "month", "day", "year" };
|
||||
|
||||
message->AddBool("time", false);
|
||||
|
||||
for (int32 idx = 0; idx < fSectionList->CountItems(); idx++) {
|
||||
uint32 data = ((TDateTimeSection *)fSectionList->ItemAt(idx))->Data();
|
||||
int32 value;
|
||||
for (int32 index = 0; index < fSectionList->CountItems(); ++index) {
|
||||
value = _SectionValue(index);
|
||||
|
||||
if (fFocus == idx)
|
||||
data = fHoldValue;
|
||||
if (index == fFocus)
|
||||
value = fHoldValue;
|
||||
|
||||
message->AddInt32(fields[idx], data);
|
||||
message->AddInt32(fields[index], value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TDateEdit::CheckRange()
|
||||
TDateEdit::_CheckRange()
|
||||
{
|
||||
int32 value = fHoldValue;
|
||||
|
||||
switch (fFocus) {
|
||||
case 0: // month
|
||||
case 0:
|
||||
{
|
||||
if (value > 11)
|
||||
value = 0;
|
||||
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)
|
||||
// month
|
||||
if (value > 12)
|
||||
value = 1;
|
||||
else if (value < 1)
|
||||
value = daycnt;
|
||||
break;
|
||||
}
|
||||
value = 12;
|
||||
|
||||
case 2: //year
|
||||
fDate.SetDate(fDate.Year(), value, fDate.Day());
|
||||
} break;
|
||||
|
||||
case 1:
|
||||
{
|
||||
if (value > YEAR_DELTA_MAX)
|
||||
value = YEAR_DELTA_MIN;
|
||||
else if (value < YEAR_DELTA_MIN)
|
||||
value = YEAR_DELTA_MAX;
|
||||
break;
|
||||
}
|
||||
//day
|
||||
int32 days = fDate.DaysInMonth();
|
||||
if (value > days)
|
||||
value = 1;
|
||||
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:
|
||||
return;
|
||||
}
|
||||
|
||||
((TDateTimeSection *)fSectionList->ItemAt(fFocus))->SetData(value);
|
||||
fHoldValue = value;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* probably Mike Berg <mike@agamemnon.homelinux.net>
|
||||
* and/or Andrew McCall <mccall@@digitalparadise.co.uk>
|
||||
* McCall <mccall@@digitalparadise.co.uk>
|
||||
* Mike Berg <mike@berg-net.us>
|
||||
* Julun <host.haiku@gmx.de>
|
||||
*
|
||||
*/
|
||||
@@ -12,6 +12,7 @@
|
||||
#define DATETIME_H
|
||||
|
||||
|
||||
#include "DateTime.h"
|
||||
#include "SectionEdit.h"
|
||||
|
||||
|
||||
@@ -28,14 +29,19 @@ class TTimeEdit : public TSectionEdit {
|
||||
virtual void SectionFocus(uint32 index);
|
||||
virtual float SeperatorWidth() const;
|
||||
|
||||
void CheckRange();
|
||||
|
||||
virtual void DoUpPress();
|
||||
virtual void DoDownPress();
|
||||
|
||||
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 float SeperatorWidth() const;
|
||||
|
||||
void CheckRange();
|
||||
|
||||
virtual void DoUpPress();
|
||||
virtual void DoDownPress();
|
||||
|
||||
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
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004-2007, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* probably Mike Berg <mike@agamemnon.homelinux.net>
|
||||
* 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(¤tTime, &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(¤tTime, &tm);
|
||||
|
||||
return tm.tm_wday;
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004-2007, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* probably Mike Berg <mike@agamemnon.homelinux.net>
|
||||
* 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
|
||||
|
||||
@@ -9,7 +9,6 @@ Preference Time :
|
||||
Bitmaps.cpp
|
||||
CalendarView.cpp
|
||||
DateTimeEdit.cpp
|
||||
DateUtils.cpp
|
||||
SectionEdit.cpp
|
||||
SettingsView.cpp
|
||||
Time.cpp
|
||||
@@ -17,6 +16,7 @@ Preference Time :
|
||||
TimeWindow.cpp
|
||||
TZDisplay.cpp
|
||||
ZoneView.cpp
|
||||
DateTime.cpp
|
||||
: be
|
||||
: Time.rdef
|
||||
;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* probably Mike Berg <mike@agamemnon.homelinux.net>
|
||||
* Mike Berg <mike@berg-net.us>
|
||||
* Julun <host.haiku@gmx.de>
|
||||
*
|
||||
*/
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
|
||||
const uint32 kArrowAreaWidth = 16;
|
||||
const uint32 kSeperatorWidth = 8;
|
||||
|
||||
|
||||
TSectionEdit::TSectionEdit(BRect frame, const char *name, uint32 sections)
|
||||
@@ -60,13 +59,12 @@ TSectionEdit::AttachedToWindow()
|
||||
|
||||
|
||||
void
|
||||
TSectionEdit::Draw(BRect updaterect)
|
||||
TSectionEdit::Draw(BRect updateRect)
|
||||
{
|
||||
DrawBorder();
|
||||
for (uint32 idx = 0; idx < fSectionCount; idx++)
|
||||
{
|
||||
for (uint32 idx = 0; idx < fSectionCount; idx++) {
|
||||
DrawSection(idx, ((uint32)fFocus == idx) && IsFocus());
|
||||
if (idx <fSectionCount -1)
|
||||
if (idx < fSectionCount -1)
|
||||
DrawSeperator(idx);
|
||||
}
|
||||
}
|
||||
@@ -76,6 +74,7 @@ void
|
||||
TSectionEdit::MouseDown(BPoint where)
|
||||
{
|
||||
MakeFocus(true);
|
||||
|
||||
if (fUpRect.Contains(where))
|
||||
DoUpPress();
|
||||
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
|
||||
TSectionEdit::KeyDown(const char *bytes, int32 numbytes)
|
||||
{
|
||||
@@ -133,9 +147,9 @@ TSectionEdit::KeyDown(const char *bytes, int32 numbytes)
|
||||
void
|
||||
TSectionEdit::DispatchMessage()
|
||||
{
|
||||
BMessage *msg = new BMessage(H_USER_CHANGE);
|
||||
BuildDispatch(msg);
|
||||
Window()->PostMessage(msg);
|
||||
BMessage message(H_USER_CHANGE);
|
||||
BuildDispatch(&message);
|
||||
Window()->PostMessage(&message);
|
||||
}
|
||||
|
||||
|
||||
@@ -157,13 +171,15 @@ void
|
||||
TSectionEdit::InitView()
|
||||
{
|
||||
// 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);
|
||||
fUpArrow->SetBits(kUpArrowBits, (kUpArrowWidth) *(kUpArrowHeight+1), 0, kUpArrowColorSpace);
|
||||
|
||||
fDownArrow = new BBitmap(BRect(0, 0, kDownArrowWidth -1, kDownArrowHeight -2), kDownArrowColorSpace);
|
||||
fDownArrow->SetBits(kDownArrowBits, (kDownArrowWidth) *(kDownArrowHeight), 0, kDownArrowColorSpace);
|
||||
|
||||
rect = BRect(0, 0, kDownArrowWidth -1, kDownArrowHeight -2);
|
||||
fDownArrow = new BBitmap(rect, kDownArrowColorSpace);
|
||||
fDownArrow->SetBits(kDownArrowBits, (kDownArrowWidth) *(kDownArrowHeight)
|
||||
, 0, kDownArrowColorSpace);
|
||||
|
||||
// setup sections
|
||||
fSectionList = new BList(fSectionCount);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* probably Mike Berg <mike@agamemnon.homelinux.net>
|
||||
* Mike Berg <mike@berg-net.us>
|
||||
* Julun <host.haiku@gmx.de>
|
||||
*
|
||||
*/
|
||||
@@ -48,6 +48,7 @@ class TSectionEdit: public BControl {
|
||||
virtual void AttachedToWindow();
|
||||
virtual void Draw(BRect updateRect);
|
||||
virtual void MouseDown(BPoint point);
|
||||
virtual void MakeFocus(bool focused = true);
|
||||
virtual void KeyDown(const char *bytes, int32 numBytes);
|
||||
|
||||
uint32 CountSections() const;
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* probably Mike Berg <mike@agamemnon.homelinux.net>
|
||||
* and/or Andrew McCall <mccall@@digitalparadise.co.uk>
|
||||
* Andrew McCall <mccall@@digitalparadise.co.uk>
|
||||
* Mike Berg <mike@berg-net.us>
|
||||
* Julun <host.haiku@gmx.de>
|
||||
*/
|
||||
|
||||
@@ -15,29 +15,31 @@
|
||||
#include "TimeMessages.h"
|
||||
|
||||
|
||||
#include <CheckBox.h>
|
||||
#include <Entry.h>
|
||||
#include <File.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <Message.h>
|
||||
#include <Path.h>
|
||||
#include <RadioButton.h>
|
||||
#include <String.h>
|
||||
#include <StringView.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
TSettingsView::TSettingsView(BRect frame)
|
||||
: BView(frame,"Settings", B_FOLLOW_ALL,
|
||||
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP),
|
||||
fGmtTime(NULL)
|
||||
fGmtTime(NULL),
|
||||
fInitialized(false)
|
||||
{
|
||||
InitView();
|
||||
_ReadRTCSettings();
|
||||
}
|
||||
|
||||
|
||||
TSettingsView::~TSettingsView()
|
||||
{
|
||||
WriteRTCSettings();
|
||||
_WriteRTCSettings();
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +48,35 @@ TSettingsView::AttachedToWindow()
|
||||
{
|
||||
if (Parent())
|
||||
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) {
|
||||
case B_OBSERVER_NOTICE_CHANGE:
|
||||
message->FindInt32(B_OBSERVE_WHAT_CHANGE, &change);
|
||||
switch(change)
|
||||
{
|
||||
switch(change) {
|
||||
case H_TM_CHANGED:
|
||||
UpdateDateTime(message);
|
||||
_UpdateDateTime(message);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -68,6 +98,14 @@ TSettingsView::MessageReceived(BMessage *message)
|
||||
}
|
||||
break;
|
||||
|
||||
case kDayChanged:
|
||||
{
|
||||
BMessage msg(*message);
|
||||
msg.what = H_USER_CHANGE;
|
||||
msg.AddBool("time", false);
|
||||
Window()->PostMessage(&msg);
|
||||
} break;
|
||||
|
||||
default:
|
||||
BView::MessageReceived(message);
|
||||
break;
|
||||
@@ -79,10 +117,10 @@ void
|
||||
TSettingsView::GetPreferredSize(float *width, float *height)
|
||||
{
|
||||
// hardcode in TimeWindow ...
|
||||
*width = 361.0f;
|
||||
*width = 470.0f;
|
||||
*height = 227.0f;
|
||||
|
||||
if (fGmtTime) {
|
||||
if (fInitialized) {
|
||||
// we are initialized
|
||||
*width = Bounds().Width();
|
||||
*height = fGmtTime->Frame().bottom;
|
||||
@@ -91,19 +129,17 @@ TSettingsView::GetPreferredSize(float *width, float *height)
|
||||
|
||||
|
||||
void
|
||||
TSettingsView::InitView()
|
||||
TSettingsView::_InitView()
|
||||
{
|
||||
ReadRTCSettings();
|
||||
|
||||
font_height fontHeight;
|
||||
be_plain_font->GetHeight(&fontHeight);
|
||||
float textHeight = fontHeight.descent + fontHeight.ascent + fontHeight.leading;
|
||||
|
||||
// left side
|
||||
BRect frameLeft(Bounds());
|
||||
frameLeft.right = frameLeft.Width() / 2;
|
||||
frameLeft.right = frameLeft.Width() / 2.0;
|
||||
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);
|
||||
AddChild(fDateEdit);
|
||||
@@ -111,24 +147,28 @@ TSettingsView::InitView()
|
||||
frameLeft.top = fDateEdit->Frame().bottom + 10;
|
||||
frameLeft.bottom = Bounds().bottom - 10;
|
||||
|
||||
fCalendar = new TCalendarView(frameLeft, "calendar", B_FOLLOW_NONE, B_WILL_DRAW);
|
||||
AddChild(fCalendar);
|
||||
fCalendarView = new BCalendarView(frameLeft, "calendar");
|
||||
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());
|
||||
frameRight.left = frameRight.Width() / 2;
|
||||
frameRight.left = frameRight.Width() / 2.0;
|
||||
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);
|
||||
AddChild(fTimeEdit);
|
||||
|
||||
frameRight.top = fTimeEdit->Frame().bottom + 10;
|
||||
frameRight.bottom = Bounds().bottom - 10;
|
||||
frameRight.top = fTimeEdit->Frame().bottom + 10.0;
|
||||
frameRight.bottom = Bounds().bottom - 10.0;
|
||||
|
||||
float left = fTimeEdit->Frame().left;
|
||||
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.right = frameRight.left + tmp;
|
||||
|
||||
@@ -137,13 +177,13 @@ TSettingsView::InitView()
|
||||
|
||||
// clock radio buttons
|
||||
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:");
|
||||
AddChild(text);
|
||||
text->ResizeToPreferred();
|
||||
|
||||
frameRight.left += 10.0f;
|
||||
frameRight.top = text->Frame().bottom + 5;
|
||||
frameRight.top = text->Frame().bottom + 5.0;
|
||||
|
||||
fLocalTime = new BRadioButton(frameRight, "local", "Local time",
|
||||
new BMessage(H_RTC_CHANGE));
|
||||
@@ -164,66 +204,7 @@ TSettingsView::InitView()
|
||||
|
||||
|
||||
void
|
||||
TSettingsView::Draw(BRect /*updateRect*/)
|
||||
{
|
||||
//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()
|
||||
TSettingsView::_ReadRTCSettings()
|
||||
{
|
||||
BPath path;
|
||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
||||
@@ -254,7 +235,7 @@ TSettingsView::ReadRTCSettings()
|
||||
|
||||
|
||||
void
|
||||
TSettingsView::WriteRTCSettings()
|
||||
TSettingsView::_WriteRTCSettings()
|
||||
{
|
||||
BPath path;
|
||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
||||
@@ -270,3 +251,30 @@ TSettingsView::WriteRTCSettings()
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* probably Mike Berg <mike@agamemnon.homelinux.net>
|
||||
* and/or Andrew McCall <mccall@@digitalparadise.co.uk>
|
||||
* Andrew McCall <mccall@@digitalparadise.co.uk>
|
||||
* Mike Berg <mike@berg-net.us>
|
||||
* Julun <host.haiku@gmx.de>
|
||||
*/
|
||||
#ifndef SETTINGS_VIEW_H
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
class TDateEdit;
|
||||
class TTimeEdit;
|
||||
class TCalendarView;
|
||||
class TAnalogClock;
|
||||
class BCalendarView;
|
||||
class BRadioButton;
|
||||
class TAnalogClock;
|
||||
|
||||
|
||||
class TSettingsView : public BView {
|
||||
@@ -31,21 +31,22 @@ class TSettingsView : public BView {
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
virtual void GetPreferredSize(float *width, float *height);
|
||||
|
||||
bool GMTime();
|
||||
private:
|
||||
void _InitView();
|
||||
void _ReadRTCSettings();
|
||||
void _WriteRTCSettings();
|
||||
void _UpdateDateTime(BMessage *message);
|
||||
|
||||
private:
|
||||
void InitView();
|
||||
void ReadRTCSettings();
|
||||
void WriteRTCSettings();
|
||||
void UpdateDateTime(BMessage *message);
|
||||
|
||||
BRadioButton *fLocalTime;
|
||||
BRadioButton *fGmtTime;
|
||||
TDateEdit *fDateEdit;
|
||||
TTimeEdit *fTimeEdit;
|
||||
TCalendarView *fCalendar;
|
||||
BCalendarView *fCalendarView;
|
||||
TAnalogClock *fClock;
|
||||
|
||||
bool fIsLocalTime;
|
||||
bool fInitialized;
|
||||
};
|
||||
|
||||
#endif // SETTINGS_VIEW_H
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* probably Mike Berg <mike@agamemnon.homelinux.net>
|
||||
* and/or Andrew McCall <mccall@@digitalparadise.co.uk>
|
||||
* Andrew McCall <mccall@@digitalparadise.co.uk>
|
||||
* Mike Berg <mike@berg-net.us>
|
||||
* Julun <host.haiku@gmx.de>
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* probably Mike Berg <mike@agamemnon.homelinux.net>
|
||||
* and/or Andrew McCall <mccall@@digitalparadise.co.uk>
|
||||
* Andrew McCall <mccall@@digitalparadise.co.uk>
|
||||
* Mike Berg <mike@berg-net.us>
|
||||
* Julun <host.haiku@gmx.de>
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* Authors:
|
||||
* Andrew McCall <mccall@digitalparadise.co.uk>
|
||||
* Mike Berg <mike@agamemnon.homelinux.net>
|
||||
* Mike Berg <mike@berg-net.us>
|
||||
* Julun <host.haiku@gmx.de>
|
||||
*/
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* Authors:
|
||||
* Andrew McCall, mccall@digitalparadise.co.uk
|
||||
* Mike Berg <mike@agamemnon.homelinux.net>
|
||||
* Mike Berg <mike@berg-net.us>
|
||||
* Julun <host.haiku@gmx.de>
|
||||
*/
|
||||
#ifndef TIME_H
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* Authors:
|
||||
* Andrew McCall, mccall@digitalparadise.co.uk
|
||||
* Mike Berg <mike@agamemnon.homelinux.net>
|
||||
* Mike Berg <mike@berg-net.us>
|
||||
* Julun <host.haiku@gmx.de>
|
||||
*/
|
||||
#ifndef TIME_MESSAGES_H
|
||||
@@ -29,20 +29,20 @@ const uint32 RTC_SETTINGS = 'RTse';
|
||||
// clock tick message
|
||||
const uint32 H_TIME_UPDATE ='obTU';
|
||||
|
||||
// clicked on day in claendar
|
||||
const uint32 H_DAY_CHANGED = 'obDC';
|
||||
|
||||
//notice for clock ticks
|
||||
const uint32 H_TM_CHANGED = 'obTC';
|
||||
|
||||
//notice for user changes
|
||||
const uint32 H_USER_CHANGE = 'obUC';
|
||||
|
||||
// local/gmt radiobuttons
|
||||
// local/ gmt radiobuttons
|
||||
const uint32 H_RTC_CHANGE = 'obRC';
|
||||
|
||||
// sunday/monday radio button
|
||||
// sunday/ monday radio button
|
||||
const uint32 kWeekStart = '_kws';
|
||||
|
||||
// clicked on day in calendar
|
||||
const uint32 kDayChanged = '_kdc';
|
||||
|
||||
#endif //TIME_MESSAGES_H
|
||||
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
*
|
||||
* Authors:
|
||||
* Andrew McCall, mccall@digitalparadise.co.uk
|
||||
* Mike Berg <mike@agamemnon.homelinux.net>
|
||||
* Mike Berg <mike@berg-net.us>
|
||||
* Julun <host.haiku@gmx.de>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "TimeSettings.h"
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* Authors:
|
||||
* Andrew McCall, mccall@digitalparadise.co.uk
|
||||
* Mike Berg <mike@agamemnon.homelinux.net>
|
||||
* Mike Berg <mike@berg-net.us>
|
||||
* Julun <host.haiku@gmx.de>
|
||||
*/
|
||||
#ifndef TIME_SETTINGS_H
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* Authors:
|
||||
* Andrew McCall <mccall@@digitalparadise.co.uk>
|
||||
* Julun <host.haiku@gmx.de>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "TimeWindow.h"
|
||||
@@ -20,7 +21,7 @@
|
||||
#include <TabView.h>
|
||||
|
||||
|
||||
#define WINDOW_RIGHT 400
|
||||
#define WINDOW_RIGHT 470
|
||||
#define WINDOW_BOTTOM 227
|
||||
|
||||
|
||||
@@ -46,17 +47,9 @@ TTimeWindow::MessageReceived(BMessage *message)
|
||||
{
|
||||
switch(message->what) {
|
||||
case H_USER_CHANGE:
|
||||
{
|
||||
bool isTime;
|
||||
if (message->FindBool("time", &isTime) == B_OK)
|
||||
fBaseView->ChangeTime(message);
|
||||
fBaseView->ChangeTime(message);
|
||||
break;
|
||||
}
|
||||
|
||||
case H_RTC_CHANGE:
|
||||
fBaseView->SetGMTime(fTimeSettings->GMTime());
|
||||
break;
|
||||
|
||||
default:
|
||||
BWindow::MessageReceived(message);
|
||||
break;
|
||||
@@ -114,8 +107,8 @@ TTimeWindow::_InitWindow()
|
||||
|
||||
float width;
|
||||
float height;
|
||||
fTimeSettings->GetPreferredSize(&width, &height);
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* Authors:
|
||||
* Andrew McCall <mccall@@digitalparadise.co.uk>
|
||||
* Julun <host.haiku@gmx.de>
|
||||
*
|
||||
*/
|
||||
#ifndef TIME_WINDOW_H
|
||||
#define TIME_WINDOW_H
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Mike Berg <mike@agamemnon.homelinux.net>
|
||||
* Mike Berg <mike@berg-net.us>
|
||||
* Julun <host.haiku@gmx.de>
|
||||
*/
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Mike Berg <mike@agamemnon.homelinux.net>
|
||||
* Mike Berg <mike@berg-net.us>
|
||||
* Julun <host.haiku@gmx.de>
|
||||
*/
|
||||
#ifndef ZONE_VIEW_H
|
||||
|
||||
Reference in New Issue
Block a user