From 49c8c359849b4e0f279f6eab4da5d3109a229dfc Mon Sep 17 00:00:00 2001
From: Akshay Agarwal <agarwal.akshay.akshay8@gmail.com>
Date: Fri, 1 Sep 2017 19:49:32 +0530
Subject: [PATCH] BCalendarView: Fix displaying locale based day name header.
* Use BDateFormat::GetDayName() to fetch weekday names.
* Use appropriate symbol width(Mon, Mo, M) depending on the frame width.
* Provide functionality to update day name header in case of locale
preferences change.
---
headers/private/shared/CalendarView.h | 3 +++
src/kits/shared/CalendarView.cpp | 35 +++++++++++++++++++++++++++++++++--
2 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/headers/private/shared/CalendarView.h b/headers/private/shared/CalendarView.h
index c644dfb..9ce4216 100644
a
|
b
|
public:
|
97 | 97 | |
98 | 98 | bool IsDayNameHeaderVisible() const; |
99 | 99 | void SetDayNameHeaderVisible(bool visible); |
| 100 | void UpdateDayNameHeader(); |
100 | 101 | |
101 | 102 | bool IsWeekNumberHeaderVisible() const; |
102 | 103 | void SetWeekNumberHeaderVisible(bool visible); |
… |
… |
private:
|
151 | 152 | void _SetupDayNumbers(); |
152 | 153 | void _SetupWeekNumbers(); |
153 | 154 | |
| 155 | void _PopulateDayNames(BDateFormatStyle style); |
| 156 | |
154 | 157 | void _DrawDays(); |
155 | 158 | void _DrawFocusRect(); |
156 | 159 | void _DrawDayHeader(); |
diff --git a/src/kits/shared/CalendarView.cpp b/src/kits/shared/CalendarView.cpp
index ca27ead..7bb0c86 100644
a
|
b
|
|
11 | 11 | |
12 | 12 | #include <stdlib.h> |
13 | 13 | |
| 14 | #include <DateFormat.h> |
14 | 15 | #include <LayoutUtils.h> |
15 | 16 | #include <Window.h> |
16 | 17 | |
… |
… |
BCalendarView::AttachedToWindow()
|
171 | 172 | void |
172 | 173 | BCalendarView::FrameResized(float width, float height) |
173 | 174 | { |
| 175 | _SetupDayNames(); |
174 | 176 | Invalidate(Bounds()); |
175 | 177 | } |
176 | 178 | |
… |
… |
BCalendarView::SetDayNameHeaderVisible(bool visible)
|
703 | 705 | } |
704 | 706 | |
705 | 707 | |
| 708 | void |
| 709 | BCalendarView::UpdateDayNameHeader() |
| 710 | { |
| 711 | if (!fDayNameHeaderVisible) |
| 712 | return; |
| 713 | |
| 714 | _SetupDayNames(); |
| 715 | Invalidate(Bounds().InsetBySelf(1.0, 1.0)); |
| 716 | } |
| 717 | |
| 718 | |
706 | 719 | bool |
707 | 720 | BCalendarView::IsWeekNumberHeaderVisible() const |
708 | 721 | { |
… |
… |
BCalendarView::_GetPreferredSize(float* _width, float* _height)
|
844 | 857 | void |
845 | 858 | BCalendarView::_SetupDayNames() |
846 | 859 | { |
847 | | for (int32 i = 0; i <= 6; ++i) |
848 | | fDayNames[i] = fDate.ShortDayName(1 + (fStartOfWeek - 1 + i) % 7); |
| 860 | BDateFormatStyle style = B_LONG_DATE_FORMAT; |
| 861 | float width, height; |
| 862 | while (style != B_DATE_FORMAT_STYLE_COUNT) { |
| 863 | _PopulateDayNames(style); |
| 864 | GetPreferredSize(&width, &height); |
| 865 | if (width < Bounds().Width()) |
| 866 | return; |
| 867 | style = static_cast<BDateFormatStyle>(static_cast<int>(style) + 1); |
| 868 | } |
| 869 | } |
| 870 | |
| 871 | |
| 872 | void |
| 873 | BCalendarView::_PopulateDayNames(BDateFormatStyle style) |
| 874 | { |
| 875 | for (int32 i = 0; i <= 6; ++i) { |
| 876 | fDayNames[i] = ""; |
| 877 | BDateFormat().GetDayName(1 + (fStartOfWeek - 1 + i) % 7, |
| 878 | fDayNames[i], style); |
| 879 | } |
849 | 880 | } |
850 | 881 | |
851 | 882 | |