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);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user