From b32b6a8633ac957ecc34f78c124768a4735f61f6 Mon Sep 17 00:00:00 2001 From: Akshay Agarwal Date: Tue, 1 Aug 2017 19:49:53 +0530 Subject: [PATCH] Fix highlighting current system date in BCalendarView. Changing the year in Calendar View does not remove the highlighting from previous highlighted day. Changing the system date to a date in a different month(different from the month currently set in calendar view) does not remove the highlighting from currently highlighted day. The disabled day number text belonging to the next month (month after the one currently selected) gets wrongly highlighted while attempting to highlight the day number text belonging to the current month. Signed-off-by: Adrien Destugues ticket : #13605 --- src/kits/shared/CalendarView.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/kits/shared/CalendarView.cpp b/src/kits/shared/CalendarView.cpp index a60aa6b127..ca27ead725 100644 --- a/src/kits/shared/CalendarView.cpp +++ b/src/kits/shared/CalendarView.cpp @@ -763,10 +763,13 @@ BCalendarView::_SetToDay() void BCalendarView::_SetToCurrentDay() { - BDate date(fDate.Year(), fDate.Month(), 1); + BDate date(fCurrentDate.Year(), fCurrentDate.Month(), 1); if (!date.IsValid()) return; - + if (fDate.Year() != date.Year() || fDate.Month() != date.Month()) { + fNewCurrentDay.SetTo(-1, -1); + return; + } const int32 firstDayOffset = (7 + date.DayOfWeek() - fStartOfWeek) % 7; int32 day = 1 - firstDayOffset; @@ -780,7 +783,7 @@ BCalendarView::_SetToCurrentDay() } } - fNewCurrentDay.SetTo(0, 0); + fNewCurrentDay.SetTo(-1, -1); } @@ -881,9 +884,12 @@ BCalendarView::_SetupDayNumbers() fSelectedDay.SetTo(row, column); fNewFocusedDay.SetTo(row, column); } - if (day == fCurrentDate.Day() - && fDate.Month() == fCurrentDate.Month()) + if (day == fCurrentDate.Day() && counter >= firstDayOffset + && counter < firstDayOffset + daysInMonth + && fDate.Month() == fCurrentDate.Month() + && fDate.Year() == fCurrentDate.Year()) fCurrentDay.SetTo(row, column); + counter++; fDayNumbers[row][column].Truncate(0); fDayNumbers[row][column] << day; @@ -1215,13 +1221,11 @@ BCalendarView::_UpdateCurrentDate() fCurrentDate = date; - if (fDate.Year() == date.Year() && fDate.Month() == date.Month()) { - _SetToCurrentDay(); - fCurrentDayChanged = true; - Draw(_RectOfDay(fCurrentDay)); - Draw(_RectOfDay(fNewCurrentDay)); - fCurrentDayChanged = false; - } + _SetToCurrentDay(); + fCurrentDayChanged = true; + Draw(_RectOfDay(fCurrentDay)); + Draw(_RectOfDay(fNewCurrentDay)); + fCurrentDayChanged = false; return; }