1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CALENDAR_RENDER_CALENDAR_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CALENDAR_RENDER_CALENDAR_H
18 
19 #include "core/components/calendar/calendar_component.h"
20 #include "core/components/calendar/focusable_grid.h"
21 #include "core/gestures/click_recognizer.h"
22 #include "core/pipeline/base/render_node.h"
23 
24 namespace OHOS::Ace {
25 
26 class RenderCalendar : public RenderNode, protected FocusableGrid, public CalendarDataChangeListener {
27     DECLARE_ACE_TYPE(RenderCalendar, RenderNode, FocusableGrid, CalendarDataChangeListener);
28 
29 public:
30     RenderCalendar();
31     ~RenderCalendar() override = default;
32 
33     static RefPtr<RenderNode> Create();
34 
35     void Update(const RefPtr<Component>& component) override;
36     void OnPaintFinish() override;
37     void PerformLayout() override;
38     void OnStatusChanged(RenderStatus renderStatus) override;
39     void OnDataChanged(const CalendarDaysOfMonth& data) override;
40     void OnSelectedDay(int32_t selected) override;
41     void OnFocusChanged(bool focusStatus) override;
42     void HandleClick(const Offset& offset);
43     void UpdateCardCalendarAttr(CardCalendarAttr&& attr) override;
44     void UpdateBreakInformation();
45     void OnSwiperMove() override;
46 
GetCalendarController()47     const RefPtr<CalendarController>& GetCalendarController() const
48     {
49         return calendarController_;
50     }
51 
GetCalendarDataAdapter()52     const RefPtr<CalendarDataAdapter>& GetCalendarDataAdapter() const
53     {
54         return dataAdapter_;
55     }
56 
GetShowHoliday()57     bool GetShowHoliday() const
58     {
59         return showHoliday_;
60     }
61 
GetNeedSlide()62     bool GetNeedSlide() const
63     {
64         return needSlide_;
65     }
66 
GetAxis()67     Axis GetAxis() const
68     {
69         return axis_;
70     }
71 
GetStartDayOfWeek()72     int32_t GetStartDayOfWeek() const
73     {
74         return startDayOfWeek_;
75     }
76 
GetOffdays()77     const std::string& GetOffdays() const
78     {
79         return offDays_;
80     }
81 
GetCalendarTheme()82     const CalendarThemeStructure& GetCalendarTheme() const
83     {
84         return calendarTheme_;
85     }
86 
87 protected:
88     int32_t GetIndexByGrid(int32_t row, int32_t column) override;
89     void FocusChanged(int32_t oldIndex, int32_t newIndex) override;
90     void OnTouchTestHit(
91         const Offset& coordinateOffset, const TouchRestrict& touchRestrict, TouchTestResult& result) override;
92     int32_t JudgeArea(const Offset& offset);
93     bool IsValid(int32_t index) const;
94     bool IsToday(const CalendarDay& day) const;
95 
96     std::vector<std::string> weekNumbers_;
97     std::vector<CalendarDay> calendarDays_;
98     std::string offDays_;
99     CalendarMonth currentMonth_;
100     CalendarThemeStructure calendarTheme_;
101     TextDirection textDirection_ = TextDirection::LTR;
102     int32_t indexOfContainer_ = 0;
103     int32_t lastDayIndex_ = 0;
104     int32_t touchIndex_ = -1;
105     double dayWidth_ = 0.0;
106     double dayHeight_ = 0.0;
107     double weekHeight_ = 0.0;
108     double maxWidth_ = 0.0;
109     double maxHeight_ = 0.0;
110     double colSpace_ = 0.0;
111     double dailyFiveRowSpace_ = 0.0;
112     double dailySixRowSpace_ = 0.0;
113 
114     // default selected first day of month
115     bool cardCalendar_ = false;
116     bool calendarFocusStatus_ = false;
117     bool hasRequestFocus_ = false;
118     bool hasTouched_ = false;
119     bool showHoliday_ = true;
120     bool showLunar_ = false;
121     bool isV2Component_ = false;
122     bool needSlide_ = false;
123     bool isNeedRepaint_ = false;
124     Axis axis_ = Axis::HORIZONTAL;
125     int32_t startDayOfWeek_ = 6;
126     CalendarType type_ { CalendarType::NORMAL };
127     RefPtr<CalendarController> calendarController_;
128     RefPtr<CalendarDataAdapter> dataAdapter_;
129 
130 private:
131     void OnDateSelected(const CalendarDay& date);
132     void UpdateAccessibility();
133 
134     std::function<void(const std::string&)> selectedChangeEvent_;
135     RefPtr<ClickRecognizer> clickDetector_;
136 };
137 
138 } // namespace OHOS::Ace
139 
140 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CALENDAR_RENDER_CALENDAR_H
141