[haiku-commits] r41156 - haiku/trunk/src/apps/deskbar

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 31 Mar 2011 23:53:36 +0200 (CEST)

Author: axeld
Date: 2011-03-31 23:53:36 +0200 (Thu, 31 Mar 2011)
New Revision: 41156
Changeset: https://dev.haiku-os.org/changeset/41156

Modified:
   haiku/trunk/src/apps/deskbar/CalendarMenuWindow.cpp
   haiku/trunk/src/apps/deskbar/CalendarMenuWindow.h
Log:
* Fixed "Month +/-" not working on the 31th.
* Renamed _UpdateUI() to _UpdateDate().
* Added copyright year when Karsten wrote that code.


Modified: haiku/trunk/src/apps/deskbar/CalendarMenuWindow.cpp
===================================================================
--- haiku/trunk/src/apps/deskbar/CalendarMenuWindow.cpp 2011-03-31 21:35:53 UTC 
(rev 41155)
+++ haiku/trunk/src/apps/deskbar/CalendarMenuWindow.cpp 2011-03-31 21:53:36 UTC 
(rev 41156)
@@ -1,5 +1,5 @@
 /*
- * Copyright Karsten Heimrich, host.haiku@xxxxxxx All rights reserved.
+ * Copyright 2008 Karsten Heimrich, host.haiku@xxxxxxx All rights reserved.
  * Distributed under the terms of the MIT License.
  */
 
@@ -132,7 +132,7 @@
        AddChild(groupView);
 
        MoveTo(where);
-       _UpdateUI(BDate::CurrentDate(B_LOCAL_TIME));
+       _UpdateDate(BDate::CurrentDate(B_LOCAL_TIME));
 }
 
 
@@ -204,7 +204,7 @@
                        message->FindInt32("month", &month);
                        message->FindInt32("year", &year);
 
-                       _UpdateUI(BDate(year, month, day));
+                       _UpdateDate(year, month, day);
                        break;
                }
 
@@ -212,25 +212,8 @@
                case kMonthUpMessage:
                {
                        BDate date = fCalendarView->Date();
-
-                       int32 day = date.Day();
-                       int32 year = date.Year();
-                       int32 month = date.Month();
-
-                       month += (kMonthDownMessage == message->what) ? -1 : 1;
-                       if (month < 1) {
-                               year--;
-                               month = 12;
-                       } else if (month > 12) {
-                               year++;
-                               month = 1;
-                       }
-                       date.SetDate(year, month, day);
-
-                       if (day > date.DaysInMonth())
-                               day = date.DaysInMonth();
-
-                       _UpdateUI(BDate(year, month, day));
+                       _UpdateDate(date.Year(), date.Month()
+                               + (kMonthDownMessage == message->what ? -1 : 
1), date.Day());
                        break;
                }
 
@@ -238,8 +221,9 @@
                case kYearUpMessage:
                {
                        BDate date = fCalendarView->Date();
-                       int32 i = kYearDownMessage == message->what ? -1 : 1;
-                       _UpdateUI(BDate(date.Year() + i, date.Month(), 
date.Day()));
+                       _UpdateDate(
+                               date.Year() + (kYearDownMessage == 
message->what ? -1 : 1),
+                               date.Month(), date.Day());
                        break;
                }
 
@@ -251,8 +235,33 @@
 
 
 void
-CalendarMenuWindow::_UpdateUI(const BDate& date)
+CalendarMenuWindow::_UpdateDate(int32 year, int32 month, int32 day)
 {
+       if (day < 1) {
+               month--;
+               day = 31;
+       }
+       if (month < 1) {
+               year--;
+               month = 12;
+       }
+       if (month > 12) {
+               year++;
+               month = 1;
+       }
+
+       BDate date(year, month, 1);
+       // Alternatively, we could choose the day at the same position instead
+       if (day > date.DaysInMonth())
+               day = date.DaysInMonth();
+
+       _UpdateDate(BDate(year, month, day));
+}
+
+
+void
+CalendarMenuWindow::_UpdateDate(const BDate& date)
+{
        if (!date.IsValid())
                return;
 

Modified: haiku/trunk/src/apps/deskbar/CalendarMenuWindow.h
===================================================================
--- haiku/trunk/src/apps/deskbar/CalendarMenuWindow.h   2011-03-31 21:35:53 UTC 
(rev 41155)
+++ haiku/trunk/src/apps/deskbar/CalendarMenuWindow.h   2011-03-31 21:53:36 UTC 
(rev 41156)
@@ -1,5 +1,5 @@
 /*
- * Copyright Karsten Heimrich, host.haiku@xxxxxxx All rights reserved.
+ * Copyright 2008 Karsten Heimrich, host.haiku@xxxxxxx All rights reserved.
  * Distributed under the terms of the MIT License.
  */
 #ifndef _CALENDAR_MENU_WINDOW_H_
@@ -18,29 +18,30 @@
        class BCalendarView;
 }
 
-       using BPrivate::BCalendarView;
+using BPrivate::BCalendarView;
 
 
 class CalendarMenuWindow : public BWindow {
 public:
-                                       CalendarMenuWindow(BPoint where);
-       virtual                 ~CalendarMenuWindow();
+                                                               
CalendarMenuWindow(BPoint where);
+       virtual                                         ~CalendarMenuWindow();
 
-       virtual void    Show();
-       virtual void    WindowActivated(bool active);
-       virtual void    MessageReceived(BMessage* message);
+       virtual void                            Show();
+       virtual void                            WindowActivated(bool active);
+       virtual void                            MessageReceived(BMessage* 
message);
 
 private:
-       void                    _UpdateUI(const BDate& date);
-       BButton*                _SetupButton(const char* label, uint32 what, 
float height);
+                       void                            _UpdateDate(int32 year, 
int32 month, int32 day);
+                       void                            _UpdateDate(const 
BDate& date);
+                       BButton*                        _SetupButton(const 
char* label, uint32 what,
+                                                                       float 
height);
 
 private:
-       BStringView*    fYearLabel;
-       BStringView*    fMonthLabel;
-       BCalendarView*  fCalendarView;
-       bool                    fSuppressFirstClose;
+                       BStringView*            fYearLabel;
+                       BStringView*            fMonthLabel;
+                       BCalendarView*          fCalendarView;
+                       bool                            fSuppressFirstClose;
 };
 
 
 #endif // _CALENDAR_MENU_WINDOW_H_
-


Other related posts: