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