Ticket #13689: 0001-BCalendarView-Fix-displaying-locale-based-day-name-h.patch

File 0001-BCalendarView-Fix-displaying-locale-based-day-name-h.patch, 2.8 KB (added by akshay, 7 years ago)
  • headers/private/shared/CalendarView.h

    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:  
    9797
    9898            bool                IsDayNameHeaderVisible() const;
    9999            void                SetDayNameHeaderVisible(bool visible);
     100            void                UpdateDayNameHeader();
    100101
    101102            bool                IsWeekNumberHeaderVisible() const;
    102103            void                SetWeekNumberHeaderVisible(bool visible);
    private:  
    151152            void                _SetupDayNumbers();
    152153            void                _SetupWeekNumbers();
    153154
     155            void                _PopulateDayNames(BDateFormatStyle style);
     156
    154157            void                _DrawDays();
    155158            void                _DrawFocusRect();
    156159            void                _DrawDayHeader();
  • src/kits/shared/CalendarView.cpp

    diff --git a/src/kits/shared/CalendarView.cpp b/src/kits/shared/CalendarView.cpp
    index ca27ead..7bb0c86 100644
    a b  
    1111
    1212#include <stdlib.h>
    1313
     14#include <DateFormat.h>
    1415#include <LayoutUtils.h>
    1516#include <Window.h>
    1617
    BCalendarView::AttachedToWindow()  
    171172void
    172173BCalendarView::FrameResized(float width, float height)
    173174{
     175    _SetupDayNames();
    174176    Invalidate(Bounds());
    175177}
    176178
    BCalendarView::SetDayNameHeaderVisible(bool visible)  
    703705}
    704706
    705707
     708void
     709BCalendarView::UpdateDayNameHeader()
     710{
     711    if (!fDayNameHeaderVisible)
     712        return;
     713
     714    _SetupDayNames();
     715    Invalidate(Bounds().InsetBySelf(1.0, 1.0));
     716}
     717
     718
    706719bool
    707720BCalendarView::IsWeekNumberHeaderVisible() const
    708721{
    BCalendarView::_GetPreferredSize(float* _width, float* _height)  
    844857void
    845858BCalendarView::_SetupDayNames()
    846859{
    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
     872void
     873BCalendarView::_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    }
    849880}
    850881
    851882