* Fixed "Month +/-" not working on the 31th.
* Renamed _UpdateUI() to _UpdateDate(). * Added copyright year when Karsten wrote that code. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41156 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright Karsten Heimrich, [email protected]. All rights reserved.
|
* Copyright 2008 Karsten Heimrich, [email protected]. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -132,7 +132,7 @@ CalendarMenuWindow::CalendarMenuWindow(BPoint where)
|
|||||||
AddChild(groupView);
|
AddChild(groupView);
|
||||||
|
|
||||||
MoveTo(where);
|
MoveTo(where);
|
||||||
_UpdateUI(BDate::CurrentDate(B_LOCAL_TIME));
|
_UpdateDate(BDate::CurrentDate(B_LOCAL_TIME));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -204,7 +204,7 @@ CalendarMenuWindow::MessageReceived(BMessage* message)
|
|||||||
message->FindInt32("month", &month);
|
message->FindInt32("month", &month);
|
||||||
message->FindInt32("year", &year);
|
message->FindInt32("year", &year);
|
||||||
|
|
||||||
_UpdateUI(BDate(year, month, day));
|
_UpdateDate(year, month, day);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,25 +212,8 @@ CalendarMenuWindow::MessageReceived(BMessage* message)
|
|||||||
case kMonthUpMessage:
|
case kMonthUpMessage:
|
||||||
{
|
{
|
||||||
BDate date = fCalendarView->Date();
|
BDate date = fCalendarView->Date();
|
||||||
|
_UpdateDate(date.Year(), date.Month()
|
||||||
int32 day = date.Day();
|
+ (kMonthDownMessage == message->what ? -1 : 1), 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));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,8 +221,9 @@ CalendarMenuWindow::MessageReceived(BMessage* message)
|
|||||||
case kYearUpMessage:
|
case kYearUpMessage:
|
||||||
{
|
{
|
||||||
BDate date = fCalendarView->Date();
|
BDate date = fCalendarView->Date();
|
||||||
int32 i = kYearDownMessage == message->what ? -1 : 1;
|
_UpdateDate(
|
||||||
_UpdateUI(BDate(date.Year() + i, date.Month(), date.Day()));
|
date.Year() + (kYearDownMessage == message->what ? -1 : 1),
|
||||||
|
date.Month(), date.Day());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,7 +235,32 @@ CalendarMenuWindow::MessageReceived(BMessage* message)
|
|||||||
|
|
||||||
|
|
||||||
void
|
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())
|
if (!date.IsValid())
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright Karsten Heimrich, [email protected]. All rights reserved.
|
* Copyright 2008 Karsten Heimrich, [email protected]. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef _CALENDAR_MENU_WINDOW_H_
|
#ifndef _CALENDAR_MENU_WINDOW_H_
|
||||||
@@ -18,7 +18,7 @@ namespace BPrivate {
|
|||||||
class BCalendarView;
|
class BCalendarView;
|
||||||
}
|
}
|
||||||
|
|
||||||
using BPrivate::BCalendarView;
|
using BPrivate::BCalendarView;
|
||||||
|
|
||||||
|
|
||||||
class CalendarMenuWindow : public BWindow {
|
class CalendarMenuWindow : public BWindow {
|
||||||
@@ -31,8 +31,10 @@ public:
|
|||||||
virtual void MessageReceived(BMessage* message);
|
virtual void MessageReceived(BMessage* message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _UpdateUI(const BDate& date);
|
void _UpdateDate(int32 year, int32 month, int32 day);
|
||||||
BButton* _SetupButton(const char* label, uint32 what, float height);
|
void _UpdateDate(const BDate& date);
|
||||||
|
BButton* _SetupButton(const char* label, uint32 what,
|
||||||
|
float height);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BStringView* fYearLabel;
|
BStringView* fYearLabel;
|
||||||
@@ -43,4 +45,3 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
#endif // _CALENDAR_MENU_WINDOW_H_
|
#endif // _CALENDAR_MENU_WINDOW_H_
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user