Work on #7947 (CalendarView not respecting locale's start of week)
* support all weekdays as start of week, not only Sunday and Monday (at least Saturday is used for real, too) * introduce BWeekday as enumeration of weekdays (currently in Locale.h, may be moved somewhere else later) * change CalendarView to use BDate as its model, not individual values for day, month and year, such that no more date computation is done in CalendarView itself * some more style cleanups in CalendarView along the way * add monthwise paging to CalendarView * adjusted Deskbar and Time preflet accordingly git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42720 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -22,7 +22,7 @@ class BString;
|
||||
class BTimeZone;
|
||||
|
||||
|
||||
typedef enum {
|
||||
enum BDateElement {
|
||||
B_DATE_ELEMENT_INVALID = B_BAD_DATA,
|
||||
B_DATE_ELEMENT_YEAR = 0,
|
||||
B_DATE_ELEMENT_MONTH,
|
||||
@@ -31,14 +31,26 @@ typedef enum {
|
||||
B_DATE_ELEMENT_HOUR,
|
||||
B_DATE_ELEMENT_MINUTE,
|
||||
B_DATE_ELEMENT_SECOND
|
||||
} BDateElement;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
enum BNumberElement {
|
||||
B_NUMBER_ELEMENT_INVALID = B_BAD_DATA,
|
||||
B_NUMBER_ELEMENT_INTEGER = 0,
|
||||
B_NUMBER_ELEMENT_FRACTIONAL,
|
||||
B_NUMBER_ELEMENT_CURRENCY
|
||||
} BNumberElement;
|
||||
};
|
||||
|
||||
|
||||
// TODO: move this to BCalendar (should we ever have that) or BDate
|
||||
enum BWeekday {
|
||||
B_WEEKDAY_MONDAY = 1,
|
||||
B_WEEKDAY_TUESDAY,
|
||||
B_WEEKDAY_WEDNESDAY,
|
||||
B_WEEKDAY_THURSDAY,
|
||||
B_WEEKDAY_FRIDAY,
|
||||
B_WEEKDAY_SATURDAY,
|
||||
B_WEEKDAY_SUNDAY,
|
||||
};
|
||||
|
||||
|
||||
class BLocale {
|
||||
@@ -99,7 +111,7 @@ public:
|
||||
int& fieldCount, BDateFormatStyle style
|
||||
) const;
|
||||
|
||||
int StartOfWeek() const;
|
||||
status_t GetStartOfWeek(BWeekday* weekday) const;
|
||||
|
||||
// Time
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
#include <Invoker.h>
|
||||
#include <List.h>
|
||||
#include <Locale.h>
|
||||
#include <String.h>
|
||||
#include <View.h>
|
||||
|
||||
@@ -21,22 +22,9 @@ class BMessage;
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
enum week_start {
|
||||
B_WEEK_START_MONDAY,
|
||||
B_WEEK_START_SUNDAY
|
||||
};
|
||||
|
||||
|
||||
class BCalendarView : public BView, public BInvoker {
|
||||
public:
|
||||
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,
|
||||
public:
|
||||
BCalendarView(BRect frame, const char* name,
|
||||
uint32 resizeMask = B_FOLLOW_LEFT
|
||||
| B_FOLLOW_TOP,
|
||||
uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS
|
||||
@@ -46,170 +34,157 @@ class BCalendarView : public BView, public BInvoker {
|
||||
uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS
|
||||
| B_NAVIGABLE);
|
||||
|
||||
BCalendarView(const char* name,
|
||||
week_start start, uint32 flags = B_WILL_DRAW
|
||||
| B_FRAME_EVENTS | B_NAVIGABLE);
|
||||
virtual ~BCalendarView();
|
||||
|
||||
virtual ~BCalendarView();
|
||||
|
||||
BCalendarView(BMessage *archive);
|
||||
static BArchivable* Instantiate(BMessage *archive);
|
||||
virtual status_t Archive(BMessage *archive,
|
||||
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 AttachedToWindow();
|
||||
|
||||
virtual void AllAttached();
|
||||
virtual void AllDetached();
|
||||
virtual void FrameResized(float width, float height);
|
||||
|
||||
virtual void FrameMoved(BPoint newPosition);
|
||||
virtual void FrameResized(float width, float height);
|
||||
virtual void Draw(BRect updateRect);
|
||||
|
||||
virtual void Draw(BRect updateRect);
|
||||
|
||||
virtual void DrawDay(BView *owner, BRect frame,
|
||||
const char *text, bool isSelected = false,
|
||||
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 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 SelectionCommand() const;
|
||||
BMessage* SelectionMessage() const;
|
||||
virtual void SetSelectionMessage(BMessage *message);
|
||||
uint32 InvocationCommand() const;
|
||||
BMessage* InvocationMessage() const;
|
||||
virtual void SetInvocationMessage(BMessage* message);
|
||||
|
||||
uint32 InvocationCommand() const;
|
||||
BMessage* InvocationMessage() const;
|
||||
virtual void SetInvocationMessage(BMessage *message);
|
||||
virtual void MakeFocus(bool state = true);
|
||||
virtual status_t Invoke(BMessage* message = NULL);
|
||||
|
||||
virtual void WindowActivated(bool state);
|
||||
virtual void MakeFocus(bool state = true);
|
||||
virtual status_t Invoke(BMessage* message = NULL);
|
||||
virtual void MouseDown(BPoint where);
|
||||
|
||||
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 void KeyDown(const char *bytes, int32 numBytes);
|
||||
virtual void ResizeToPreferred();
|
||||
virtual void GetPreferredSize(float* width, float* height);
|
||||
|
||||
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 BSize MaxSize();
|
||||
virtual BSize MinSize();
|
||||
virtual BSize PreferredSize();
|
||||
|
||||
virtual void ResizeToPreferred();
|
||||
virtual void GetPreferredSize(float *width, float *height);
|
||||
int32 Day() const;
|
||||
int32 Year() const;
|
||||
int32 Month() const;
|
||||
|
||||
virtual BSize MaxSize();
|
||||
virtual BSize MinSize();
|
||||
virtual BSize PreferredSize();
|
||||
BDate Date() const;
|
||||
bool SetDate(const BDate& date);
|
||||
bool SetDate(int32 year, int32 month, int32 day);
|
||||
|
||||
int32 Day() const;
|
||||
int32 Year() const;
|
||||
int32 Month() const;
|
||||
BWeekday StartOfWeek() const;
|
||||
void SetStartOfWeek(BWeekday startOfWeek);
|
||||
|
||||
BDate Date() const;
|
||||
bool SetDate(const BDate &date);
|
||||
bool SetDate(int32 year, int32 month, int32 day);
|
||||
bool IsDayNameHeaderVisible() const;
|
||||
void SetDayNameHeaderVisible(bool visible);
|
||||
|
||||
week_start WeekStart() const;
|
||||
void SetWeekStart(week_start start);
|
||||
bool IsWeekNumberHeaderVisible() const;
|
||||
void SetWeekNumberHeaderVisible(bool visible);
|
||||
|
||||
bool IsDayNameHeaderVisible() const;
|
||||
void SetDayNameHeaderVisible(bool visible);
|
||||
|
||||
bool IsWeekNumberHeaderVisible() const;
|
||||
void SetWeekNumberHeaderVisible(bool visible);
|
||||
|
||||
private:
|
||||
void _InitObject();
|
||||
|
||||
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(const BCalendarView &view);
|
||||
BCalendarView& operator=(const BCalendarView &view);
|
||||
|
||||
private:
|
||||
struct Selection {
|
||||
private:
|
||||
struct Selection {
|
||||
Selection()
|
||||
: row(0), column(0) { }
|
||||
: row(0), column(0)
|
||||
{
|
||||
}
|
||||
|
||||
void SetTo(int32 _row, int32 _column)
|
||||
{ row = _row; column = _column; }
|
||||
void
|
||||
SetTo(int32 _row, int32 _column)
|
||||
{
|
||||
row = _row;
|
||||
column = _column;
|
||||
}
|
||||
|
||||
int32 row;
|
||||
int32 column;
|
||||
|
||||
Selection& operator=(const Selection &s)
|
||||
Selection& operator=(const Selection& s)
|
||||
{
|
||||
row = s.row;
|
||||
column = s.column;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(const Selection &s) const
|
||||
bool operator==(const Selection& s) const
|
||||
{
|
||||
return row == s.row
|
||||
&& column == s.column;
|
||||
}
|
||||
|
||||
bool operator!=(const Selection &s) const
|
||||
bool operator!=(const Selection& s) const
|
||||
{
|
||||
return row != s.row
|
||||
|| column != s.column;
|
||||
}
|
||||
};
|
||||
BRect _RectOfDay(const Selection &selection) const;
|
||||
|
||||
BMessage *fSelectionMessage;
|
||||
void _InitObject();
|
||||
|
||||
int32 fDay;
|
||||
int32 fYear;
|
||||
int32 fMonth;
|
||||
void _SetToDay();
|
||||
void _GetYearMonthForSelection(
|
||||
const Selection& selection, int32* year,
|
||||
int32* month) const;
|
||||
void _GetPreferredSize(float* width, float* height);
|
||||
|
||||
Selection fFocusedDay;
|
||||
bool fFocusChanged;
|
||||
Selection fNewFocusedDay;
|
||||
void _SetupDayNames();
|
||||
void _SetupDayNumbers();
|
||||
void _SetupWeekNumbers();
|
||||
|
||||
Selection fSelectedDay;
|
||||
Selection fNewSelectedDay;
|
||||
bool fSelectionChanged;
|
||||
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);
|
||||
|
||||
week_start fWeekStart;
|
||||
bool fDayNameHeaderVisible;
|
||||
bool fWeekNumberHeaderVisible;
|
||||
void _UpdateSelection();
|
||||
BRect _FirstCalendarItemFrame() const;
|
||||
BRect _SetNewSelectedDay(const BPoint& where);
|
||||
|
||||
BString fDayNames[7];
|
||||
BString fWeekNumbers[6];
|
||||
BString fDayNumbers[6][7];
|
||||
BRect _RectOfDay(const Selection& selection) const;
|
||||
|
||||
private:
|
||||
BMessage* fSelectionMessage;
|
||||
|
||||
BDate fDate;
|
||||
|
||||
Selection fFocusedDay;
|
||||
Selection fNewFocusedDay;
|
||||
bool fFocusChanged;
|
||||
|
||||
Selection fSelectedDay;
|
||||
Selection fNewSelectedDay;
|
||||
bool fSelectionChanged;
|
||||
|
||||
int32 fStartOfWeek;
|
||||
bool fDayNameHeaderVisible;
|
||||
bool fWeekNumberHeaderVisible;
|
||||
|
||||
BString fDayNames[7];
|
||||
BString fWeekNumbers[6];
|
||||
BString fDayNumbers[6][7];
|
||||
|
||||
// hide copy constructor & assignment
|
||||
BCalendarView(const BCalendarView& view);
|
||||
BCalendarView& operator=(const BCalendarView& view);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
|
||||
|
||||
using BPrivate::BCalendarView;
|
||||
using BPrivate::B_WEEK_START_SUNDAY;
|
||||
using BPrivate::B_WEEK_START_MONDAY;
|
||||
|
||||
|
||||
enum {
|
||||
@@ -90,17 +88,13 @@ CalendarMenuWindow::CalendarMenuWindow(BPoint where)
|
||||
{
|
||||
SetFeel(B_FLOATING_ALL_WINDOW_FEEL);
|
||||
|
||||
BPrivate::week_start startOfWeek
|
||||
= (BPrivate::week_start)BLocale::Default()->StartOfWeek();
|
||||
|
||||
RemoveShortcut('H', B_COMMAND_KEY | B_CONTROL_KEY);
|
||||
AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
|
||||
|
||||
fYearLabel = new BStringView("year", "");
|
||||
fMonthLabel = new BStringView("month", "");
|
||||
|
||||
fCalendarView = new BCalendarView(Bounds(), "calendar",
|
||||
startOfWeek, B_FOLLOW_ALL);
|
||||
fCalendarView = new BCalendarView(Bounds(), "calendar", B_FOLLOW_ALL);
|
||||
fCalendarView->SetInvocationMessage(new BMessage(kInvokationMessage));
|
||||
|
||||
BGroupLayout* layout = new BGroupLayout(B_HORIZONTAL);
|
||||
|
||||
+40
-14
@@ -30,8 +30,6 @@
|
||||
|
||||
|
||||
using BPrivate::ObjectDeleter;
|
||||
using BPrivate::B_WEEK_START_MONDAY;
|
||||
using BPrivate::B_WEEK_START_SUNDAY;
|
||||
|
||||
|
||||
BLocale::BLocale(const BLanguage* language,
|
||||
@@ -353,26 +351,54 @@ BLocale::GetDateFields(BDateElement*& fields, int& fieldCount,
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
BLocale::StartOfWeek() const
|
||||
status_t
|
||||
BLocale::GetStartOfWeek(BWeekday* startOfWeek) const
|
||||
{
|
||||
if (startOfWeek == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
BAutolock lock(fLock);
|
||||
if (!lock.IsLocked())
|
||||
return B_WOULD_BLOCK;
|
||||
|
||||
UErrorCode err = U_ZERO_ERROR;
|
||||
Calendar* c = Calendar::createInstance(
|
||||
*BFormattingConventions::Private(&fConventions).ICULocale(),
|
||||
err);
|
||||
ObjectDeleter<Calendar> calendar = Calendar::createInstance(
|
||||
*BFormattingConventions::Private(&fConventions).ICULocale(), err);
|
||||
|
||||
if (err == U_ZERO_ERROR && c->getFirstDayOfWeek(err) == UCAL_SUNDAY) {
|
||||
delete c;
|
||||
return B_WEEK_START_SUNDAY;
|
||||
} else {
|
||||
delete c;
|
||||
// Might be another day, but BeAPI will not handle it
|
||||
return B_WEEK_START_MONDAY;
|
||||
if (U_FAILURE(err))
|
||||
return B_ERROR;
|
||||
|
||||
UCalendarDaysOfWeek icuWeekStart = calendar->getFirstDayOfWeek(err);
|
||||
if (U_FAILURE(err))
|
||||
return B_ERROR;
|
||||
|
||||
switch (icuWeekStart) {
|
||||
case UCAL_SUNDAY:
|
||||
*startOfWeek = B_WEEKDAY_SUNDAY;
|
||||
break;
|
||||
case UCAL_MONDAY:
|
||||
*startOfWeek = B_WEEKDAY_MONDAY;
|
||||
break;
|
||||
case UCAL_TUESDAY:
|
||||
*startOfWeek = B_WEEKDAY_TUESDAY;
|
||||
break;
|
||||
case UCAL_WEDNESDAY:
|
||||
*startOfWeek = B_WEEKDAY_WEDNESDAY;
|
||||
break;
|
||||
case UCAL_THURSDAY:
|
||||
*startOfWeek = B_WEEKDAY_THURSDAY;
|
||||
break;
|
||||
case UCAL_FRIDAY:
|
||||
*startOfWeek = B_WEEKDAY_FRIDAY;
|
||||
break;
|
||||
case UCAL_SATURDAY:
|
||||
*startOfWeek = B_WEEKDAY_SATURDAY;
|
||||
break;
|
||||
default:
|
||||
return B_BAD_DATA;
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+173
-363
@@ -19,7 +19,7 @@ namespace BPrivate {
|
||||
|
||||
|
||||
static float
|
||||
FontHeight(const BView *view)
|
||||
FontHeight(const BView* view)
|
||||
{
|
||||
if (!view)
|
||||
return 0.0;
|
||||
@@ -35,37 +35,16 @@ FontHeight(const BView *view)
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
BCalendarView::BCalendarView(BRect frame, const char *name,
|
||||
uint32 resizeMask, uint32 flags)
|
||||
BCalendarView::BCalendarView(BRect frame, const char* name, uint32 resizeMask,
|
||||
uint32 flags)
|
||||
:
|
||||
BView(frame, name, resizeMask, flags),
|
||||
BInvoker(),
|
||||
fSelectionMessage(NULL),
|
||||
fDay(0),
|
||||
fYear(0),
|
||||
fMonth(0),
|
||||
fDate(),
|
||||
fFocusChanged(false),
|
||||
fSelectionChanged(false),
|
||||
fWeekStart(B_WEEK_START_SUNDAY),
|
||||
fDayNameHeaderVisible(true),
|
||||
fWeekNumberHeaderVisible(true)
|
||||
{
|
||||
_InitObject();
|
||||
}
|
||||
|
||||
|
||||
BCalendarView::BCalendarView(BRect frame, const char *name, week_start start,
|
||||
uint32 resizeMask, uint32 flags)
|
||||
:
|
||||
BView(frame, name, resizeMask, flags),
|
||||
BInvoker(),
|
||||
fSelectionMessage(NULL),
|
||||
fDay(0),
|
||||
fYear(0),
|
||||
fMonth(0),
|
||||
fFocusChanged(false),
|
||||
fSelectionChanged(false),
|
||||
fWeekStart(start),
|
||||
fStartOfWeek((int32)B_WEEKDAY_MONDAY),
|
||||
fDayNameHeaderVisible(true),
|
||||
fWeekNumberHeaderVisible(true)
|
||||
{
|
||||
@@ -78,31 +57,10 @@ BCalendarView::BCalendarView(const char* name, uint32 flags)
|
||||
BView(name, flags),
|
||||
BInvoker(),
|
||||
fSelectionMessage(NULL),
|
||||
fDay(0),
|
||||
fYear(0),
|
||||
fMonth(0),
|
||||
fDate(),
|
||||
fFocusChanged(false),
|
||||
fSelectionChanged(false),
|
||||
fWeekStart(B_WEEK_START_SUNDAY),
|
||||
fDayNameHeaderVisible(true),
|
||||
fWeekNumberHeaderVisible(true)
|
||||
{
|
||||
_InitObject();
|
||||
}
|
||||
|
||||
|
||||
BCalendarView::BCalendarView(const char* name, week_start start,
|
||||
uint32 flags)
|
||||
:
|
||||
BView(name, flags),
|
||||
BInvoker(),
|
||||
fSelectionMessage(NULL),
|
||||
fDay(0),
|
||||
fYear(0),
|
||||
fMonth(0),
|
||||
fFocusChanged(false),
|
||||
fSelectionChanged(false),
|
||||
fWeekStart(start),
|
||||
fStartOfWeek((int32)B_WEEKDAY_MONDAY),
|
||||
fDayNameHeaderVisible(true),
|
||||
fWeekNumberHeaderVisible(true)
|
||||
{
|
||||
@@ -116,42 +74,32 @@ BCalendarView::~BCalendarView()
|
||||
}
|
||||
|
||||
|
||||
BCalendarView::BCalendarView(BMessage *archive)
|
||||
BCalendarView::BCalendarView(BMessage* archive)
|
||||
:
|
||||
BView(archive),
|
||||
BInvoker(),
|
||||
fSelectionMessage(NULL),
|
||||
fDay(0),
|
||||
fYear(0),
|
||||
fMonth(0),
|
||||
fDate(archive),
|
||||
fFocusChanged(false),
|
||||
fSelectionChanged(false),
|
||||
fWeekStart(B_WEEK_START_SUNDAY),
|
||||
fStartOfWeek((int32)B_WEEKDAY_MONDAY),
|
||||
fDayNameHeaderVisible(true),
|
||||
fWeekNumberHeaderVisible(true)
|
||||
{
|
||||
if (archive->HasMessage("_invokeMsg")) {
|
||||
BMessage *invokationMessage = new BMessage;
|
||||
BMessage* invokationMessage = new BMessage;
|
||||
archive->FindMessage("_invokeMsg", invokationMessage);
|
||||
SetInvocationMessage(invokationMessage);
|
||||
}
|
||||
|
||||
if (archive->HasMessage("_selectMsg")) {
|
||||
BMessage *selectionMessage = new BMessage;
|
||||
BMessage* selectionMessage = new BMessage;
|
||||
archive->FindMessage("selectMsg", selectionMessage);
|
||||
SetSelectionMessage(selectionMessage);
|
||||
}
|
||||
|
||||
if (archive->FindInt32("_day", &fDay) != B_OK
|
||||
|| archive->FindInt32("_month", &fMonth) != B_OK
|
||||
|| archive->FindInt32("_year", &fYear) != B_OK) {
|
||||
BDate date = BDate::CurrentDate(B_LOCAL_TIME);
|
||||
date.GetDate(&fYear, &fMonth, &fDay);
|
||||
}
|
||||
|
||||
int32 start;
|
||||
if (archive->FindInt32("_weekStart", &start) == B_OK)
|
||||
fWeekStart = week_start(start);
|
||||
if (archive->FindInt32("_weekStart", &fStartOfWeek) != B_OK)
|
||||
fStartOfWeek = (int32)B_WEEKDAY_MONDAY;
|
||||
|
||||
if (archive->FindBool("_dayHeader", &fDayNameHeaderVisible) != B_OK)
|
||||
fDayNameHeaderVisible = true;
|
||||
@@ -166,7 +114,7 @@ BCalendarView::BCalendarView(BMessage *archive)
|
||||
|
||||
|
||||
BArchivable*
|
||||
BCalendarView::Instantiate(BMessage *archive)
|
||||
BCalendarView::Instantiate(BMessage* archive)
|
||||
{
|
||||
if (validate_instantiation(archive, "BCalendarView"))
|
||||
return new BCalendarView(archive);
|
||||
@@ -176,7 +124,7 @@ BCalendarView::Instantiate(BMessage *archive)
|
||||
|
||||
|
||||
status_t
|
||||
BCalendarView::Archive(BMessage *archive, bool deep) const
|
||||
BCalendarView::Archive(BMessage* archive, bool deep) const
|
||||
{
|
||||
status_t status = BView::Archive(archive, deep);
|
||||
|
||||
@@ -187,16 +135,10 @@ BCalendarView::Archive(BMessage *archive, bool deep) const
|
||||
status = archive->AddMessage("_selectMsg", SelectionMessage());
|
||||
|
||||
if (status == B_OK)
|
||||
status = archive->AddInt32("_day", fDay);
|
||||
status = fDate.Archive(archive);
|
||||
|
||||
if (status == B_OK)
|
||||
status = archive->AddInt32("_month", fMonth);
|
||||
|
||||
if (status == B_OK)
|
||||
status = archive->AddInt32("_year", fYear);
|
||||
|
||||
if (status == B_OK)
|
||||
status = archive->AddInt32("_weekStart", int32(fWeekStart));
|
||||
status = archive->AddInt32("_weekStart", fStartOfWeek);
|
||||
|
||||
if (status == B_OK)
|
||||
status = archive->AddBool("_dayHeader", fDayNameHeaderVisible);
|
||||
@@ -218,34 +160,6 @@ BCalendarView::AttachedToWindow()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BCalendarView::DetachedFromWindow()
|
||||
{
|
||||
BView::DetachedFromWindow();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BCalendarView::AllAttached()
|
||||
{
|
||||
BView::AllAttached();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BCalendarView::AllDetached()
|
||||
{
|
||||
BView::AllDetached();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BCalendarView::FrameMoved(BPoint newPosition)
|
||||
{
|
||||
BView::FrameMoved(newPosition);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BCalendarView::FrameResized(float width, float height)
|
||||
{
|
||||
@@ -283,7 +197,7 @@ BCalendarView::Draw(BRect updateRect)
|
||||
|
||||
|
||||
void
|
||||
BCalendarView::DrawDay(BView *owner, BRect frame, const char *text,
|
||||
BCalendarView::DrawDay(BView* owner, BRect frame, const char* text,
|
||||
bool isSelected, bool isEnabled, bool focus)
|
||||
{
|
||||
_DrawItem(owner, frame, text, isSelected, isEnabled, focus);
|
||||
@@ -291,7 +205,7 @@ BCalendarView::DrawDay(BView *owner, BRect frame, const char *text,
|
||||
|
||||
|
||||
void
|
||||
BCalendarView::DrawDayName(BView *owner, BRect frame, const char *text)
|
||||
BCalendarView::DrawDayName(BView* owner, BRect frame, const char* text)
|
||||
{
|
||||
// we get the full rect, fake this as the internal function
|
||||
// shrinks the frame to work properly when drawing a day item
|
||||
@@ -300,7 +214,7 @@ BCalendarView::DrawDayName(BView *owner, BRect frame, const char *text)
|
||||
|
||||
|
||||
void
|
||||
BCalendarView::DrawWeekNumber(BView *owner, BRect frame, const char *text)
|
||||
BCalendarView::DrawWeekNumber(BView* owner, BRect frame, const char* text)
|
||||
{
|
||||
// we get the full rect, fake this as the internal function
|
||||
// shrinks the frame to work properly when drawing a day item
|
||||
@@ -308,13 +222,6 @@ BCalendarView::DrawWeekNumber(BView *owner, BRect frame, const char *text)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BCalendarView::MessageReceived(BMessage *message)
|
||||
{
|
||||
BView::MessageReceived(message);
|
||||
}
|
||||
|
||||
|
||||
uint32
|
||||
BCalendarView::SelectionCommand() const
|
||||
{
|
||||
@@ -333,7 +240,7 @@ BCalendarView::SelectionMessage() const
|
||||
|
||||
|
||||
void
|
||||
BCalendarView::SetSelectionMessage(BMessage *message)
|
||||
BCalendarView::SetSelectionMessage(BMessage* message)
|
||||
{
|
||||
delete fSelectionMessage;
|
||||
fSelectionMessage = message;
|
||||
@@ -355,19 +262,12 @@ BCalendarView::InvocationMessage() const
|
||||
|
||||
|
||||
void
|
||||
BCalendarView::SetInvocationMessage(BMessage *message)
|
||||
BCalendarView::SetInvocationMessage(BMessage* message)
|
||||
{
|
||||
BInvoker::SetMessage(message);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BCalendarView::WindowActivated(bool state)
|
||||
{
|
||||
BView::WindowActivated(state);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BCalendarView::MakeFocus(bool state)
|
||||
{
|
||||
@@ -384,7 +284,7 @@ BCalendarView::MakeFocus(bool state)
|
||||
|
||||
|
||||
status_t
|
||||
BCalendarView::Invoke(BMessage *message)
|
||||
BCalendarView::Invoke(BMessage* message)
|
||||
{
|
||||
bool notify = false;
|
||||
uint32 kind = InvokeKind(¬ify);
|
||||
@@ -407,11 +307,11 @@ BCalendarView::Invoke(BMessage *message)
|
||||
|
||||
int32 year;
|
||||
int32 month;
|
||||
_GetYearMonth(&year, &month);
|
||||
_GetYearMonthForSelection(fSelectedDay, &year, &month);
|
||||
|
||||
clone.AddInt32("year", year);
|
||||
clone.AddInt32("month", month);
|
||||
clone.AddInt32("day", fDay);
|
||||
clone.AddInt32("year", fDate.Year());
|
||||
clone.AddInt32("month", fDate.Month());
|
||||
clone.AddInt32("day", fDate.Day());
|
||||
|
||||
if (message)
|
||||
status = BInvoker::Invoke(&clone);
|
||||
@@ -422,13 +322,6 @@ BCalendarView::Invoke(BMessage *message)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BCalendarView::MouseUp(BPoint point)
|
||||
{
|
||||
BView::MouseUp(point);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BCalendarView::MouseDown(BPoint where)
|
||||
{
|
||||
@@ -471,22 +364,14 @@ BCalendarView::MouseDown(BPoint where)
|
||||
|
||||
int32 clicks;
|
||||
// on double click invoke
|
||||
BMessage *message = Looper()->CurrentMessage();
|
||||
BMessage* message = Looper()->CurrentMessage();
|
||||
if (message->FindInt32("clicks", &clicks) == B_OK && clicks > 1)
|
||||
Invoke();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BCalendarView::MouseMoved(BPoint point, uint32 code,
|
||||
const BMessage *dragMessage)
|
||||
{
|
||||
BView::MouseMoved(point, code, dragMessage);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BCalendarView::KeyDown(const char *bytes, int32 numBytes)
|
||||
BCalendarView::KeyDown(const char* bytes, int32 numBytes)
|
||||
{
|
||||
const int32 kRows = 6;
|
||||
const int32 kColumns = 7;
|
||||
@@ -496,19 +381,17 @@ BCalendarView::KeyDown(const char *bytes, int32 numBytes)
|
||||
|
||||
switch (bytes[0]) {
|
||||
case B_LEFT_ARROW:
|
||||
{
|
||||
column -= 1;
|
||||
if (column < 0) {
|
||||
column = kColumns -1;
|
||||
column = kColumns - 1;
|
||||
row -= 1;
|
||||
if (row >= 0)
|
||||
fFocusChanged = true;
|
||||
} else
|
||||
fFocusChanged = true;
|
||||
} break;
|
||||
break;
|
||||
|
||||
case B_RIGHT_ARROW:
|
||||
{
|
||||
column += 1;
|
||||
if (column == kColumns) {
|
||||
column = 0;
|
||||
@@ -517,24 +400,43 @@ BCalendarView::KeyDown(const char *bytes, int32 numBytes)
|
||||
fFocusChanged = true;
|
||||
} else
|
||||
fFocusChanged = true;
|
||||
} break;
|
||||
break;
|
||||
|
||||
case B_UP_ARROW:
|
||||
{
|
||||
row -= 1;
|
||||
if (row >= 0)
|
||||
fFocusChanged = true;
|
||||
} break;
|
||||
break;
|
||||
|
||||
case B_DOWN_ARROW:
|
||||
{
|
||||
row += 1;
|
||||
if (row < kRows)
|
||||
fFocusChanged = true;
|
||||
} break;
|
||||
break;
|
||||
|
||||
case B_PAGE_UP:
|
||||
{
|
||||
BDate date(fDate);
|
||||
date.AddMonths(-1);
|
||||
SetDate(date);
|
||||
|
||||
Invoke();
|
||||
break;
|
||||
}
|
||||
|
||||
case B_PAGE_DOWN:
|
||||
{
|
||||
BDate date(fDate);
|
||||
date.AddMonths(1);
|
||||
SetDate(date);
|
||||
|
||||
Invoke();
|
||||
break;
|
||||
}
|
||||
|
||||
case B_RETURN:
|
||||
case B_SPACE: {
|
||||
case B_SPACE:
|
||||
{
|
||||
fSelectionChanged = true;
|
||||
BPoint pt = _RectOfDay(fFocusedDay).LeftTop();
|
||||
Draw(_SetNewSelectedDay(pt + BPoint(4.0, 4.0)));
|
||||
@@ -542,7 +444,8 @@ BCalendarView::KeyDown(const char *bytes, int32 numBytes)
|
||||
fSelectionChanged = false;
|
||||
|
||||
Invoke();
|
||||
} break;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
BView::KeyDown(bytes, numBytes);
|
||||
@@ -558,28 +461,6 @@ BCalendarView::KeyDown(const char *bytes, int32 numBytes)
|
||||
}
|
||||
|
||||
|
||||
BHandler*
|
||||
BCalendarView::ResolveSpecifier(BMessage *message, int32 index,
|
||||
BMessage *specifier, int32 form, const char *property)
|
||||
{
|
||||
return BView::ResolveSpecifier(message, index, specifier, form, property);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BCalendarView::GetSupportedSuites(BMessage *data)
|
||||
{
|
||||
return BView::GetSupportedSuites(data);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BCalendarView::Perform(perform_code code, void *arg)
|
||||
{
|
||||
return BView::Perform(code, arg);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BCalendarView::ResizeToPreferred()
|
||||
{
|
||||
@@ -592,7 +473,7 @@ BCalendarView::ResizeToPreferred()
|
||||
|
||||
|
||||
void
|
||||
BCalendarView::GetPreferredSize(float *width, float *height)
|
||||
BCalendarView::GetPreferredSize(float* width, float* height)
|
||||
{
|
||||
_GetPreferredSize(width, height);
|
||||
}
|
||||
@@ -611,23 +492,21 @@ BCalendarView::MinSize()
|
||||
{
|
||||
float width, height;
|
||||
_GetPreferredSize(&width, &height);
|
||||
return BLayoutUtils::ComposeSize(ExplicitMinSize(),
|
||||
BSize(width, height));
|
||||
return BLayoutUtils::ComposeSize(ExplicitMinSize(), BSize(width, height));
|
||||
}
|
||||
|
||||
|
||||
BSize
|
||||
BCalendarView::PreferredSize()
|
||||
{
|
||||
return BLayoutUtils::ComposeSize(ExplicitPreferredSize(),
|
||||
MinSize());
|
||||
return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), MinSize());
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
BCalendarView::Day() const
|
||||
{
|
||||
return fDay;
|
||||
return fDate.Day();
|
||||
}
|
||||
|
||||
|
||||
@@ -635,8 +514,7 @@ int32
|
||||
BCalendarView::Year() const
|
||||
{
|
||||
int32 year;
|
||||
int32 month;
|
||||
_GetYearMonth(&year, &month);
|
||||
_GetYearMonthForSelection(fSelectedDay, &year, NULL);
|
||||
|
||||
return year;
|
||||
}
|
||||
@@ -645,9 +523,8 @@ BCalendarView::Year() const
|
||||
int32
|
||||
BCalendarView::Month() const
|
||||
{
|
||||
int32 year;
|
||||
int32 month;
|
||||
_GetYearMonth(&year, &month);
|
||||
_GetYearMonthForSelection(fSelectedDay, NULL, &month);
|
||||
|
||||
return month;
|
||||
}
|
||||
@@ -658,32 +535,23 @@ BCalendarView::Date() const
|
||||
{
|
||||
int32 year;
|
||||
int32 month;
|
||||
_GetYearMonth(&year, &month);
|
||||
return BDate(year, month, fDay);
|
||||
_GetYearMonthForSelection(fSelectedDay, &year, &month);
|
||||
return BDate(year, month, fDate.Day());
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
BCalendarView::SetDate(const BDate &date)
|
||||
BCalendarView::SetDate(const BDate& date)
|
||||
{
|
||||
if (!date.IsValid())
|
||||
return false;
|
||||
|
||||
return SetDate(date.Year(), date.Month(), date.Day());
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
BCalendarView::SetDate(int32 year, int32 month, int32 day)
|
||||
{
|
||||
if (!BDate(year, month, day).IsValid())
|
||||
return false;
|
||||
|
||||
if (fYear == year && fMonth == month && fDay == day)
|
||||
if (fDate == date)
|
||||
return true;
|
||||
|
||||
fDay = day;
|
||||
if (fYear == year && fMonth == month) {
|
||||
if (fDate.Year() == date.Year() && fDate.Month() == date.Month()) {
|
||||
fDate = date;
|
||||
|
||||
_SetToDay();
|
||||
// update focus
|
||||
fFocusChanged = true;
|
||||
@@ -696,8 +564,7 @@ BCalendarView::SetDate(int32 year, int32 month, int32 day)
|
||||
Draw(_RectOfDay(fNewSelectedDay));
|
||||
fSelectionChanged = false;
|
||||
} else {
|
||||
fYear = year;
|
||||
fMonth = month;
|
||||
fDate = date;
|
||||
|
||||
_SetupDayNumbers();
|
||||
_SetupWeekNumbers();
|
||||
@@ -716,20 +583,27 @@ BCalendarView::SetDate(int32 year, int32 month, int32 day)
|
||||
}
|
||||
|
||||
|
||||
week_start
|
||||
BCalendarView::WeekStart() const
|
||||
bool
|
||||
BCalendarView::SetDate(int32 year, int32 month, int32 day)
|
||||
{
|
||||
return fWeekStart;
|
||||
return SetDate(BDate(year, month, day));
|
||||
}
|
||||
|
||||
|
||||
BWeekday
|
||||
BCalendarView::StartOfWeek() const
|
||||
{
|
||||
return BWeekday(fStartOfWeek);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BCalendarView::SetWeekStart(week_start start)
|
||||
BCalendarView::SetStartOfWeek(BWeekday startOfWeek)
|
||||
{
|
||||
if (fWeekStart == start)
|
||||
if (fStartOfWeek == (int32)startOfWeek)
|
||||
return;
|
||||
|
||||
fWeekStart = start;
|
||||
fStartOfWeek = (int32)startOfWeek;
|
||||
|
||||
_SetupDayNames();
|
||||
_SetupDayNumbers();
|
||||
@@ -778,8 +652,9 @@ BCalendarView::SetWeekNumberHeaderVisible(bool visible)
|
||||
void
|
||||
BCalendarView::_InitObject()
|
||||
{
|
||||
BDate date = BDate::CurrentDate(B_LOCAL_TIME);
|
||||
date.GetDate(&fYear, &fMonth, &fDay);
|
||||
fDate = BDate::CurrentDate(B_LOCAL_TIME);
|
||||
|
||||
BLocale::Default()->GetStartOfWeek((BWeekday*)&fStartOfWeek);
|
||||
|
||||
_SetupDayNames();
|
||||
_SetupDayNumbers();
|
||||
@@ -790,94 +665,53 @@ BCalendarView::_InitObject()
|
||||
void
|
||||
BCalendarView::_SetToDay()
|
||||
{
|
||||
BDate date(fYear, fMonth, 1);
|
||||
BDate date(fDate.Year(), fDate.Month(), 1);
|
||||
if (!date.IsValid())
|
||||
return;
|
||||
|
||||
const int32 firstDayOffset = (7 + date.DayOfWeek() - fStartOfWeek) % 7;
|
||||
|
||||
int32 day = 1 - firstDayOffset;
|
||||
for (int32 row = 0; row < 6; ++row) {
|
||||
for (int32 column = 0; column < 7; ++column) {
|
||||
if (day == fDate.Day()) {
|
||||
fNewFocusedDay.SetTo(row, column);
|
||||
fNewSelectedDay.SetTo(row, column);
|
||||
return;
|
||||
}
|
||||
day++;
|
||||
}
|
||||
}
|
||||
|
||||
fNewFocusedDay.SetTo(0, 0);
|
||||
fNewSelectedDay.SetTo(0, 0);
|
||||
|
||||
const int32 dayCountCurrent = date.DaysInMonth();
|
||||
|
||||
int32 firstDay = date.DayOfWeek();
|
||||
if (fWeekStart == B_WEEK_START_MONDAY)
|
||||
firstDay = ((firstDay - 1) < 0) ? 6 : firstDay -1;
|
||||
|
||||
int32 counter = 0;
|
||||
for (int32 row = 0; row < 6; ++row) {
|
||||
for (int32 column = 0; column < 7; ++column) {
|
||||
int32 day = counter - (firstDay - 1);
|
||||
if (counter >= firstDay
|
||||
&& counter <= dayCountCurrent + firstDay - 1) {
|
||||
if (day == fDay) {
|
||||
fNewFocusedDay.SetTo(row, column);
|
||||
fNewSelectedDay.SetTo(row, column);
|
||||
return;
|
||||
}
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BCalendarView::_GetYearMonth(int32 *year, int32 *month) const
|
||||
BCalendarView::_GetYearMonthForSelection(const Selection& selection,
|
||||
int32* year, int32* month) const
|
||||
{
|
||||
BDate date(fYear, fMonth, 1);
|
||||
BDate startOfMonth(fDate.Year(), fDate.Month(), 1);
|
||||
const int32 firstDayOffset
|
||||
= (7 + startOfMonth.DayOfWeek() - fStartOfWeek) % 7;
|
||||
const int32 daysInMonth = startOfMonth.DaysInMonth();
|
||||
|
||||
const int32 dayCountCurrent = date.DaysInMonth();
|
||||
|
||||
int32 firstDay = date.DayOfWeek();
|
||||
if (fWeekStart == B_WEEK_START_MONDAY)
|
||||
firstDay = ((firstDay - 1) < 0) ? 6 : firstDay -1;
|
||||
|
||||
// set the date to one month before
|
||||
if (date.Month() == 1)
|
||||
date.SetDate(date.Year() -1, 12, fDay);
|
||||
else
|
||||
date.SetDate(date.Year(), date.Month() - 1, fDay);
|
||||
|
||||
const int32 currRow = fSelectedDay.row;
|
||||
const int32 currColumn = fSelectedDay.column;
|
||||
|
||||
*year = fYear;
|
||||
*month = fMonth;
|
||||
|
||||
int32 counter = 0;
|
||||
for (int32 row = 0; row < 6; ++row) {
|
||||
for (int32 column = 0; column < 7; ++column) {
|
||||
if (counter < firstDay
|
||||
|| counter > dayCountCurrent + firstDay - 1) {
|
||||
if (counter - firstDay < 0) {
|
||||
if (row == currRow && column == currColumn) {
|
||||
*year = date.Year();
|
||||
*month = date.Month();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (row == currRow && column == currColumn) {
|
||||
*year = fYear;
|
||||
*month = fMonth +1;
|
||||
if (fMonth == 12) {
|
||||
*year = fYear +1;
|
||||
*month = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (row == currRow && column == currColumn)
|
||||
break;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
BDate date(fDate);
|
||||
const int32 dayOffset = selection.row * 7 + selection.column;
|
||||
if (dayOffset < firstDayOffset)
|
||||
date.AddMonths(-1);
|
||||
else if (dayOffset >= firstDayOffset + daysInMonth)
|
||||
date.AddMonths(1);
|
||||
if (year != NULL)
|
||||
*year = date.Year();
|
||||
if (month != NULL)
|
||||
*month = date.Month();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BCalendarView::_GetPreferredSize(float *_width, float *_height)
|
||||
BCalendarView::_GetPreferredSize(float* _width, float* _height)
|
||||
{
|
||||
BFont font;
|
||||
GetFont(&font);
|
||||
@@ -911,87 +745,60 @@ BCalendarView::_GetPreferredSize(float *_width, float *_height)
|
||||
void
|
||||
BCalendarView::_SetupDayNames()
|
||||
{
|
||||
const BDate date(fYear, fMonth, fDay);
|
||||
if (!date.IsValid())
|
||||
return;
|
||||
|
||||
if (fWeekStart == B_WEEK_START_MONDAY) {
|
||||
for (int32 i = 1; i <= 7; ++i) {
|
||||
fDayNames[i -1] = date.ShortDayName(i);
|
||||
}
|
||||
} else {
|
||||
fDayNames[0] = date.ShortDayName(7);
|
||||
for (int32 i = 1; i < 7; ++i) {
|
||||
fDayNames[i] = date.ShortDayName(i);
|
||||
}
|
||||
}
|
||||
for (int32 i = 0; i <= 6; ++i)
|
||||
fDayNames[i] = fDate.ShortDayName(1 + (fStartOfWeek - 1 + i) % 7);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BCalendarView::_SetupDayNumbers()
|
||||
{
|
||||
BDate date(fYear, fMonth, 1);
|
||||
if (!date.IsValid())
|
||||
BDate startOfMonth(fDate.Year(), fDate.Month(), 1);
|
||||
if (!startOfMonth.IsValid())
|
||||
return;
|
||||
|
||||
fFocusedDay.SetTo(0, 0);
|
||||
fSelectedDay.SetTo(0, 0);
|
||||
fNewFocusedDay.SetTo(0, 0);
|
||||
|
||||
const int32 dayCountCurrent = date.DaysInMonth();
|
||||
|
||||
int32 firstDay = date.DayOfWeek();
|
||||
if (fWeekStart == B_WEEK_START_MONDAY)
|
||||
firstDay = ((firstDay - 1) < 0) ? 6 : firstDay -1;
|
||||
const int32 daysInMonth = startOfMonth.DaysInMonth();
|
||||
const int32 firstDayOffset
|
||||
= (7 + startOfMonth.DayOfWeek() - fStartOfWeek) % 7;
|
||||
|
||||
// calc the last day one month before
|
||||
if (date.Month() == 1)
|
||||
date.SetDate(date.Year() -1, 12, 1);
|
||||
else
|
||||
date.SetDate(date.Year(), date.Month() - 1, 1);
|
||||
const int32 lastDayBefore = date.DaysInMonth();
|
||||
BDate lastDayInMonthBefore(startOfMonth);
|
||||
lastDayInMonthBefore.AddDays(-1);
|
||||
const int32 lastDayBefore = lastDayInMonthBefore.DaysInMonth();
|
||||
|
||||
int32 counter = 0;
|
||||
int32 firstDayAfter = 1;
|
||||
for (int32 row = 0; row < 6; ++row) {
|
||||
for (int32 column = 0; column < 7; ++column) {
|
||||
int32 day = counter - (firstDay - 1);
|
||||
if (counter < firstDay
|
||||
|| counter > dayCountCurrent + firstDay - 1) {
|
||||
if (counter - firstDay < 0)
|
||||
day += lastDayBefore;
|
||||
else
|
||||
day = firstDayAfter++;
|
||||
} else {
|
||||
if (day == fDay) {
|
||||
fFocusedDay.SetTo(row, column);
|
||||
fSelectedDay.SetTo(row, column);
|
||||
fNewFocusedDay.SetTo(row, column);
|
||||
}
|
||||
int32 day = 1 + counter - firstDayOffset;
|
||||
if (counter < firstDayOffset)
|
||||
day += lastDayBefore;
|
||||
else if (counter >= firstDayOffset + daysInMonth)
|
||||
day = firstDayAfter++;
|
||||
else if (day == fDate.Day()) {
|
||||
fFocusedDay.SetTo(row, column);
|
||||
fSelectedDay.SetTo(row, column);
|
||||
fNewFocusedDay.SetTo(row, column);
|
||||
}
|
||||
counter++;
|
||||
fDayNumbers[row][column].SetTo("");
|
||||
fDayNumbers[row][column].Truncate(0);
|
||||
fDayNumbers[row][column] << day;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BCalendarView::_SetupWeekNumbers()
|
||||
{
|
||||
BDate date(fYear, fMonth, 1);
|
||||
BDate date(fDate.Year(), fDate.Month(), 1);
|
||||
if (!date.IsValid())
|
||||
return;
|
||||
|
||||
// date on Thursday determines week number (ISO 8601)
|
||||
int dayOfWeek = date.DayOfWeek();
|
||||
// adjust weekday if Monday is week start,
|
||||
// then Sunday is last day in week
|
||||
if (fWeekStart == B_WEEK_START_MONDAY && dayOfWeek == 0)
|
||||
dayOfWeek = 7;
|
||||
date.AddDays(4 - dayOfWeek);
|
||||
|
||||
for (int32 row = 0; row < 6; ++row) {
|
||||
fWeekNumbers[row].SetTo("");
|
||||
fWeekNumbers[row] << date.WeekNumber();
|
||||
@@ -1002,26 +809,24 @@ BCalendarView::_SetupWeekNumbers()
|
||||
|
||||
void
|
||||
BCalendarView::_DrawDay(int32 currRow, int32 currColumn, int32 row,
|
||||
int32 column, int32 counter, BRect frame, const char *text, bool focus)
|
||||
int32 column, int32 counter, BRect frame, const char* text, bool focus)
|
||||
{
|
||||
const BDate date(fYear, fMonth, 1);
|
||||
const int32 daysMonth = date.DaysInMonth();
|
||||
|
||||
int32 firstDay = date.DayOfWeek();
|
||||
if (fWeekStart == B_WEEK_START_MONDAY)
|
||||
firstDay = ((firstDay - 1) < 0) ? 6 : firstDay -1;
|
||||
BDate startOfMonth(fDate.Year(), fDate.Month(), 1);
|
||||
const int32 firstDayOffset
|
||||
= (7 + startOfMonth.DayOfWeek() - fStartOfWeek) % 7;
|
||||
const int32 daysMonth = startOfMonth.DaysInMonth();
|
||||
|
||||
bool enabled = true;
|
||||
bool selected = false;
|
||||
// check for the current date
|
||||
if (currRow == row && currColumn == column) {
|
||||
selected = true; // draw current date selected
|
||||
if (counter <= firstDay || counter > firstDay + daysMonth) {
|
||||
if (counter <= firstDayOffset || counter > firstDayOffset + daysMonth) {
|
||||
enabled = false; // days of month before or after
|
||||
selected = false; // not selected but able to get focus
|
||||
}
|
||||
} else {
|
||||
if (counter <= firstDay || counter > firstDay + daysMonth)
|
||||
if (counter <= firstDayOffset || counter > firstDayOffset + daysMonth)
|
||||
enabled = false; // days of month before or after
|
||||
}
|
||||
|
||||
@@ -1046,7 +851,7 @@ BCalendarView::_DrawDays()
|
||||
BRect tmp = frame;
|
||||
for (int32 column = 0; column < 7; ++column) {
|
||||
counter++;
|
||||
const char *day = fDayNumbers[row][column].String();
|
||||
const char* day = fDayNumbers[row][column].String();
|
||||
bool focus = isFocus && focusRow == row && focusColumn == column;
|
||||
_DrawDay(currRow, currColumn, row, column, counter, tmp, day,
|
||||
focus);
|
||||
@@ -1078,12 +883,11 @@ BCalendarView::_DrawFocusRect()
|
||||
fFocusedDay.SetTo(row, column);
|
||||
|
||||
bool focus = IsFocus() && true;
|
||||
const char *day = fDayNumbers[row][column].String();
|
||||
const char* day = fDayNumbers[row][column].String();
|
||||
_DrawDay(currRow, currColumn, row, column, counter, tmp, day,
|
||||
focus);
|
||||
}
|
||||
else if (focusRow == row && focusColumn == column) {
|
||||
const char *day = fDayNumbers[row][column].String();
|
||||
} else if (focusRow == row && focusColumn == column) {
|
||||
const char* day = fDayNumbers[row][column].String();
|
||||
_DrawDay(currRow, currColumn, row, column, counter, tmp, day,
|
||||
false);
|
||||
}
|
||||
@@ -1152,7 +956,7 @@ BCalendarView::_DrawWeekHeader()
|
||||
|
||||
|
||||
void
|
||||
BCalendarView::_DrawItem(BView *owner, BRect frame, const char *text,
|
||||
BCalendarView::_DrawItem(BView* owner, BRect frame, const char* text,
|
||||
bool isSelected, bool isEnabled, bool focus)
|
||||
{
|
||||
rgb_color lColor = LowColor();
|
||||
@@ -1179,10 +983,10 @@ BCalendarView::_DrawItem(BView *owner, BRect frame, const char *text,
|
||||
SetHighColor(tint_color(black, B_LIGHTEN_2_TINT));
|
||||
|
||||
float offsetH = frame.Width() / 2.0;
|
||||
float offsetV = (frame.Height() / 2.0) + (FontHeight(owner) / 2.0) - 2.0;
|
||||
float offsetV = frame.Height() / 2.0 + FontHeight(owner) / 2.0 - 2.0;
|
||||
|
||||
DrawString(text, BPoint(frame.right - offsetH
|
||||
- (StringWidth(text) / 2.0), frame.top + offsetV));
|
||||
DrawString(text, BPoint(frame.right - offsetH - StringWidth(text) / 2.0,
|
||||
frame.top + offsetV));
|
||||
|
||||
SetLowColor(lColor);
|
||||
SetHighColor(highColor);
|
||||
@@ -1209,13 +1013,12 @@ BCalendarView::_UpdateSelection()
|
||||
&& fNewSelectedDay.column == column) {
|
||||
fSelectedDay.SetTo(row, column);
|
||||
|
||||
const char *day = fDayNumbers[row][column].String();
|
||||
const char* day = fDayNumbers[row][column].String();
|
||||
bool focus = IsFocus() && focusRow == row
|
||||
&& focusColumn == column;
|
||||
_DrawDay(row, column, row, column, counter, tmp, day, focus);
|
||||
}
|
||||
else if (currRow == row && currColumn == column) {
|
||||
const char *day = fDayNumbers[row][column].String();
|
||||
} else if (currRow == row && currColumn == column) {
|
||||
const char* day = fDayNumbers[row][column].String();
|
||||
bool focus = IsFocus() && focusRow == row
|
||||
&& focusColumn == column;
|
||||
_DrawDay(currRow, currColumn, -1, -1, counter, tmp, day, focus);
|
||||
@@ -1256,7 +1059,7 @@ BCalendarView::_FirstCalendarItemFrame() const
|
||||
|
||||
|
||||
BRect
|
||||
BCalendarView::_SetNewSelectedDay(const BPoint &where)
|
||||
BCalendarView::_SetNewSelectedDay(const BPoint& where)
|
||||
{
|
||||
BRect frame = _FirstCalendarItemFrame();
|
||||
|
||||
@@ -1267,7 +1070,15 @@ BCalendarView::_SetNewSelectedDay(const BPoint &where)
|
||||
counter++;
|
||||
if (tmp.Contains(where)) {
|
||||
fNewSelectedDay.SetTo(row, column);
|
||||
fDay = atoi(fDayNumbers[row][column].String());
|
||||
int32 year;
|
||||
int32 month;
|
||||
_GetYearMonthForSelection(fNewSelectedDay, &year, &month);
|
||||
if (month == fDate.Month()) {
|
||||
// only change date if a day in the current month has been
|
||||
// selected
|
||||
int32 day = atoi(fDayNumbers[row][column].String());
|
||||
fDate.SetDate(year, month, day);
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
tmp.OffsetBy(tmp.Width(), 0.0);
|
||||
@@ -1280,7 +1091,7 @@ BCalendarView::_SetNewSelectedDay(const BPoint &where)
|
||||
|
||||
|
||||
BRect
|
||||
BCalendarView::_RectOfDay(const Selection &selection) const
|
||||
BCalendarView::_RectOfDay(const Selection& selection) const
|
||||
{
|
||||
BRect frame = _FirstCalendarItemFrame();
|
||||
|
||||
@@ -1289,9 +1100,8 @@ BCalendarView::_RectOfDay(const Selection &selection) const
|
||||
BRect tmp = frame;
|
||||
for (int32 column = 0; column < 7; ++column) {
|
||||
counter++;
|
||||
if (selection.row == row && selection.column == column) {
|
||||
if (selection.row == row && selection.column == column)
|
||||
return tmp;
|
||||
}
|
||||
tmp.OffsetBy(tmp.Width(), 0.0);
|
||||
}
|
||||
frame.OffsetBy(0.0, frame.Height());
|
||||
|
||||
@@ -187,9 +187,7 @@ DateTimeView::_PrefletUptime() const
|
||||
void
|
||||
DateTimeView::_InitView()
|
||||
{
|
||||
BPrivate::week_start weekStart = (BPrivate::week_start)
|
||||
BLocale::Default()->StartOfWeek();
|
||||
fCalendarView = new BCalendarView("calendar", weekStart);
|
||||
fCalendarView = new BCalendarView("calendar");
|
||||
fCalendarView->SetWeekNumberHeaderVisible(false);
|
||||
fCalendarView->SetSelectionMessage(new BMessage(kDayChanged));
|
||||
fCalendarView->SetInvocationMessage(new BMessage(kDayChanged));
|
||||
@@ -305,8 +303,16 @@ DateTimeView::_UpdateDateTime(BMessage* message)
|
||||
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);
|
||||
static int32 lastDay;
|
||||
static int32 lastMonth;
|
||||
static int32 lastYear;
|
||||
if (day != lastDay || month != lastMonth || year != lastYear) {
|
||||
fDateEdit->SetDate(year, month, day);
|
||||
fCalendarView->SetDate(year, month, day);
|
||||
lastDay = day;
|
||||
lastMonth = month;
|
||||
lastYear = year;
|
||||
}
|
||||
}
|
||||
|
||||
int32 hour;
|
||||
|
||||
Reference in New Issue
Block a user