[haiku-commits] r42720 - in haiku/trunk: headers/os/locale headers/private/shared src/apps/deskbar src/kits/locale src/kits/shared ...

  • From: zooey@xxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 7 Sep 2011 23:41:57 +0200 (CEST)

Author: zooey
Date: 2011-09-07 23:41:57 +0200 (Wed, 07 Sep 2011)
New Revision: 42720
Changeset: https://dev.haiku-os.org/changeset/42720
Ticket: https://dev.haiku-os.org/ticket/7947

Modified:
   haiku/trunk/headers/os/locale/Locale.h
   haiku/trunk/headers/private/shared/CalendarView.h
   haiku/trunk/src/apps/deskbar/CalendarMenuWindow.cpp
   haiku/trunk/src/kits/locale/Locale.cpp
   haiku/trunk/src/kits/shared/CalendarView.cpp
   haiku/trunk/src/preferences/time/DateTimeView.cpp
Log:
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


Modified: haiku/trunk/headers/os/locale/Locale.h
===================================================================
--- haiku/trunk/headers/os/locale/Locale.h      2011-09-07 21:31:06 UTC (rev 
42719)
+++ haiku/trunk/headers/os/locale/Locale.h      2011-09-07 21:41:57 UTC (rev 
42720)
@@ -22,7 +22,7 @@
 class BTimeZone;
 
 
-typedef enum {
+enum BDateElement {
        B_DATE_ELEMENT_INVALID = B_BAD_DATA,
        B_DATE_ELEMENT_YEAR = 0,
        B_DATE_ELEMENT_MONTH,
@@ -31,16 +31,28 @@
        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 {
 public:
                                                                BLocale(const 
BLanguage* language = NULL,
@@ -99,7 +111,7 @@
                                                                        int& 
fieldCount, BDateFormatStyle style
                                                                        ) const;
 
-                       int                                     StartOfWeek() 
const;
+                       status_t                        
GetStartOfWeek(BWeekday* weekday) const;
 
                                                                // Time
 

Modified: haiku/trunk/headers/private/shared/CalendarView.h
===================================================================
--- haiku/trunk/headers/private/shared/CalendarView.h   2011-09-07 21:31:06 UTC 
(rev 42719)
+++ haiku/trunk/headers/private/shared/CalendarView.h   2011-09-07 21:41:57 UTC 
(rev 42720)
@@ -11,6 +11,7 @@
 
 #include <Invoker.h>
 #include <List.h>
+#include <Locale.h>
 #include <String.h>
 #include <View.h>
 
@@ -21,195 +22,169 @@
 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,
+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,
-                                                                       uint32 
resizeMask = B_FOLLOW_LEFT
-                                                                               
| B_FOLLOW_TOP,
-                                                                       uint32 
flags = B_WILL_DRAW | B_FRAME_EVENTS
-                                                                               
| B_NAVIGABLE);
-
                                                                
BCalendarView(const char* name,
                                                                        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);
 };
 
 

Modified: haiku/trunk/src/apps/deskbar/CalendarMenuWindow.cpp
===================================================================
--- haiku/trunk/src/apps/deskbar/CalendarMenuWindow.cpp 2011-09-07 21:31:06 UTC 
(rev 42719)
+++ haiku/trunk/src/apps/deskbar/CalendarMenuWindow.cpp 2011-09-07 21:41:57 UTC 
(rev 42720)
@@ -20,8 +20,6 @@
 
 
 using BPrivate::BCalendarView;
-using BPrivate::B_WEEK_START_SUNDAY;
-using BPrivate::B_WEEK_START_MONDAY;
 
 
 enum {
@@ -90,17 +88,13 @@
 {
        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);

Modified: haiku/trunk/src/kits/locale/Locale.cpp
===================================================================
--- haiku/trunk/src/kits/locale/Locale.cpp      2011-09-07 21:31:06 UTC (rev 
42719)
+++ haiku/trunk/src/kits/locale/Locale.cpp      2011-09-07 21:41:57 UTC (rev 
42720)
@@ -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 @@
 }
 
 
-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;
 }
 
 

Modified: haiku/trunk/src/kits/shared/CalendarView.cpp
===================================================================
--- haiku/trunk/src/kits/shared/CalendarView.cpp        2011-09-07 21:31:06 UTC 
(rev 42719)
+++ haiku/trunk/src/kits/shared/CalendarView.cpp        2011-09-07 21:41:57 UTC 
(rev 42720)
@@ -19,7 +19,7 @@
 
 
 static float
-FontHeight(const BView *view)
+FontHeight(const BView* view)
 {
        if (!view)
                return 0.0;
@@ -35,18 +35,16 @@
 // #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),
+       fStartOfWeek((int32)B_WEEKDAY_MONDAY),
        fDayNameHeaderVisible(true),
        fWeekNumberHeaderVisible(true)
 {
@@ -54,36 +52,15 @@
 }
 
 
-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),
-       fWeekNumberHeaderVisible(true)
-{
-       _InitObject();
-}
-
-
 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),
+       fStartOfWeek((int32)B_WEEKDAY_MONDAY),
        fDayNameHeaderVisible(true),
        fWeekNumberHeaderVisible(true)
 {
@@ -91,68 +68,39 @@
 }
 
 
-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),
-       fWeekNumberHeaderVisible(true)
-{
-       _InitObject();
-}
-
-
 BCalendarView::~BCalendarView()
 {
        SetSelectionMessage(NULL);
 }
 
 
-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);
-       }
+       if (archive->FindInt32("_weekStart", &fStartOfWeek) != B_OK)
+               fStartOfWeek = (int32)B_WEEKDAY_MONDAY;
 
-       int32 start;
-       if (archive->FindInt32("_weekStart", &start) == B_OK)
-               fWeekStart = week_start(start);
-
        if (archive->FindBool("_dayHeader", &fDayNameHeaderVisible) != B_OK)
                fDayNameHeaderVisible = true;
 
@@ -166,7 +114,7 @@
 
 
 BArchivable*
-BCalendarView::Instantiate(BMessage *archive)
+BCalendarView::Instantiate(BMessage* archive)
 {
        if (validate_instantiation(archive, "BCalendarView"))
                return new BCalendarView(archive);
@@ -176,7 +124,7 @@
 
 
 status_t
-BCalendarView::Archive(BMessage *archive, bool deep) const
+BCalendarView::Archive(BMessage* archive, bool deep) const
 {
        status_t status = BView::Archive(archive, deep);
 
@@ -187,18 +135,12 @@
                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);
+               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)
                status = archive->AddBool("_dayHeader", fDayNameHeaderVisible);
 
        if (status == B_OK)
@@ -219,34 +161,6 @@
 
 
 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)
 {
        Invalidate(Bounds());
@@ -283,7 +197,7 @@
 
 
 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 @@
 
 
 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 @@
 
 
 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 @@
 }
 
 
-void
-BCalendarView::MessageReceived(BMessage *message)
-{
-       BView::MessageReceived(message);
-}
-
-
 uint32
 BCalendarView::SelectionCommand() const
 {
@@ -333,7 +240,7 @@
 
 
 void
-BCalendarView::SetSelectionMessage(BMessage *message)
+BCalendarView::SetSelectionMessage(BMessage* message)
 {
        delete fSelectionMessage;
        fSelectionMessage = message;
@@ -355,20 +262,13 @@
 
 
 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)
 {
        if (IsFocus() == state)
@@ -384,7 +284,7 @@
 
 
 status_t
-BCalendarView::Invoke(BMessage *message)
+BCalendarView::Invoke(BMessage* message)
 {
        bool notify = false;
        uint32 kind = InvokeKind(&notify);
@@ -407,11 +307,11 @@
 
        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);
@@ -423,13 +323,6 @@
 
 
 void
-BCalendarView::MouseUp(BPoint point)
-{
-       BView::MouseUp(point);
-}
-
-
-void
 BCalendarView::MouseDown(BPoint where)
 {
        if (!IsFocus()) {
@@ -471,23 +364,15 @@
 
        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)
+BCalendarView::KeyDown(const char* bytes, int32 numBytes)
 {
-       BView::MouseMoved(point, code, dragMessage);
-}
-
-
-void
-BCalendarView::KeyDown(const char *bytes, int32 numBytes)
-{
        const int32 kRows = 6;
        const int32 kColumns = 7;
 
@@ -496,19 +381,17 @@
 
        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 @@
                                        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 @@
                        fSelectionChanged = false;
 
                        Invoke();
-               }       break;
+                       break;
+               }
 
                default:
                        BView::KeyDown(bytes, numBytes);
@@ -558,28 +461,6 @@
 }
 
 
-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 @@
 
 
 void
-BCalendarView::GetPreferredSize(float *width, float *height)
+BCalendarView::GetPreferredSize(float* width, float* height)
 {
        _GetPreferredSize(width, height);
 }
@@ -611,23 +492,21 @@
 {
        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 @@
 BCalendarView::Year() const
 {
        int32 year;
-       int32 month;
-       _GetYearMonth(&year, &month);
+       _GetYearMonthForSelection(fSelectedDay, &year, NULL);
 

[... truncated: 524 lines follow ...]

Other related posts:

  • » [haiku-commits] r42720 - in haiku/trunk: headers/os/locale headers/private/shared src/apps/deskbar src/kits/locale src/kits/shared ... - zooey