• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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_NG_PATTERNS_DATE_PICKER_DATE_PICKER_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_DATE_PICKER_DATE_PICKER_PATTERN_H
18 
19 #include <optional>
20 
21 #include "core/components/common/layout/constants.h"
22 #include "core/components/picker/picker_data.h"
23 #include "core/components/theme/app_theme.h"
24 #include "core/components/picker/picker_theme.h"
25 #include "core/components_ng/base/frame_node.h"
26 #include "core/components_ng/event/event_hub.h"
27 #include "core/components_ng/pattern/button/button_layout_property.h"
28 #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h"
29 #include "core/components_ng/pattern/pattern.h"
30 #include "core/components_ng/pattern/picker/datepicker_accessibility_property.h"
31 #include "core/components_ng/pattern/picker/datepicker_column_pattern.h"
32 #include "core/components_ng/pattern/picker/datepicker_event_hub.h"
33 #include "core/components_ng/pattern/picker/datepicker_layout_property.h"
34 #include "core/components_ng/pattern/picker/datepicker_row_layout_property.h"
35 #include "core/components_ng/pattern/text/text_pattern.h"
36 #include "core/components_ng/pattern/picker/datepicker_dialog_view.h"
37 
38 namespace OHOS::Ace::NG {
39 class InspectorFilter;
40 namespace {
41 const Dimension FOCUS_PAINT_WIDTH = 2.0_vp;
42 constexpr Dimension PICKER_DIALOG_MARGIN_FORM_EDGE = 24.0_vp;
43 constexpr Dimension PICKER_MARGIN_FROM_TITLE_AND_BUTTON = 8.0_vp;
44 }
45 
46 class DatePickerPattern : public LinearLayoutPattern {
47     DECLARE_ACE_TYPE(DatePickerPattern, LinearLayoutPattern);
48 
49 public:
DatePickerPattern()50     DatePickerPattern() : LinearLayoutPattern(false) {};
51 
52     ~DatePickerPattern() override = default;
53 
54     void BeforeCreateLayoutWrapper() override;
55 
OnColorModeChange(uint32_t colorMode)56     void OnColorModeChange(uint32_t colorMode) override
57     {
58         LinearLayoutPattern::OnColorModeChange(colorMode);
59         auto host = GetHost();
60         CHECK_NULL_VOID(host);
61         host->MarkModifyDone();
62     }
63 
IsAtomicNode()64     bool IsAtomicNode() const override
65     {
66         return true;
67     }
68 
CreateEventHub()69     RefPtr<EventHub> CreateEventHub() override
70     {
71         return MakeRefPtr<DatePickerEventHub>();
72     }
73 
CreateLayoutAlgorithm()74     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
75     {
76         return MakeRefPtr<LinearLayoutAlgorithm>();
77     }
78 
CreateLayoutProperty()79     RefPtr<LayoutProperty> CreateLayoutProperty() override
80     {
81         return MakeRefPtr<DataPickerRowLayoutProperty>();
82     }
83 
CreateNodePaintMethod()84     RefPtr<NodePaintMethod> CreateNodePaintMethod() override
85     {
86         auto paintMethod = MakeRefPtr<DatePickerPaintMethod>(WeakClaim(this));
87         paintMethod->SetEnabled(enabled_);
88         paintMethod->SetBackgroundColor(backgroundColor_);
89         return paintMethod;
90     }
91 
CreateAccessibilityProperty()92     RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override
93     {
94         return MakeRefPtr<DatePickerAccessibilityProperty>();
95     }
96 
SetConfirmNode(WeakPtr<FrameNode> buttonConfirmNode)97     void SetConfirmNode(WeakPtr<FrameNode> buttonConfirmNode)
98     {
99         weakButtonConfirm_ = buttonConfirmNode;
100     }
101 
SetCancelNode(WeakPtr<FrameNode> buttonCancelNode)102     void SetCancelNode(WeakPtr<FrameNode> buttonCancelNode)
103     {
104         weakButtonCancel_ = buttonCancelNode;
105     }
106 
SetNextPrevButtonNode(WeakPtr<FrameNode> nextPrevButtonNode)107     void SetNextPrevButtonNode(WeakPtr<FrameNode> nextPrevButtonNode)
108     {
109         nextPrevButtonNode_ = nextPrevButtonNode;
110     }
111 
SetIsNext(bool isNext)112     void SetIsNext(bool isNext)
113     {
114         isNext_ = isNext;
115     }
116 
SetLunarSwitchTextNode(WeakPtr<FrameNode> lunarSwitchTextNode)117     void SetLunarSwitchTextNode(WeakPtr<FrameNode> lunarSwitchTextNode)
118     {
119         weakLunarSwitchText_ = lunarSwitchTextNode;
120     }
121 
SetLunarSwitchCheckbox(WeakPtr<FrameNode> lunarSwitchCheckbox)122     void SetLunarSwitchCheckbox(WeakPtr<FrameNode> lunarSwitchCheckbox)
123     {
124         weakLunarSwitchCheckbox_ = lunarSwitchCheckbox;
125     }
126 
127     void OnFontConfigurationUpdate() override;
128 
129     void OnFontScaleConfigurationUpdate() override;
130 
131     void OnLanguageConfigurationUpdate() override;
132 
133     void OnColorConfigurationUpdate() override;
134 
135     bool OnThemeScopeUpdate(int32_t themeScopeId) override;
136 
137     void SetChangeCallback(ColumnChangeCallback&& value);
138 
139     void HandleColumnChange(const RefPtr<FrameNode>& tag, bool isAdd, uint32_t index, bool needNotify);
140 
141     void SolarColumnsBuilding(const PickerDate& current);
142 
143     void LunarColumnsBuilding(const LunarDate& current);
144 
145     void SolarMonthDaysColumnsBuilding(const PickerDate& current);
146 
147     void LunarMonthDaysColumnBuilding(const LunarDate& current);
148 
149     void HandleYearChange(bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags);
150 
151     void HandleMonthChange(bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags);
152 
153     void HandleLunarMonthChange(bool isAdd, uint32_t index);
154 
155     void HandleLunarYearChange(bool isAdd, uint32_t index);
156 
157     void HandleSolarYearChange(bool isAdd, uint32_t index);
158 
159     LunarDate GetCurrentLunarDate(uint32_t lunarYear) const;
160 
161     void OrderCurrentLunarDate(
162         RefPtr<FrameNode>& stackYear, RefPtr<FrameNode>& stackMonth, RefPtr<FrameNode>& stackDay) const;
163 
164     void HandleSolarMonthChange(bool isAdd, uint32_t index);
165 
166     void HandleDayChange(bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags);
167 
168     void HandleReduceLunarDayChange(uint32_t index);
169 
170     void HandleLunarDayChange(bool isAdd, uint32_t index);
171 
172     void HandleAddLunarDayChange(uint32_t index);
173 
174     void HandleSolarDayChange(bool isAdd, uint32_t index);
175 
176     void IncreaseLinkageYearMonth(PickerDate& date);
177 
178     void ReduceLinkageYearMonth(PickerDate& date);
179 
180     void HandleSolarMonthDaysChange(bool isAdd, uint32_t index);
181 
182     void HandleLunarMonthDaysChange(bool isAdd, uint32_t index);
183 
184     void HandleAddLunarMonthDaysChange(uint32_t index);
185 
186     void HandleReduceLunarMonthDaysChange(uint32_t index);
187 
188     LunarDate GetCurrentLunarDateByMonthDaysColumn(uint32_t lunarYear) const;
189 
190     PickerDate GetCurrentDate() const;
191 
192     void SetEventCallback(EventCallback&& value);
193 
194     void FireChangeEvent(bool refresh);
195 
196     void FlushColumn();
197 
198     void FlushMonthDaysColumn();
199 
200     void AdjustLunarDate(LunarDate& date);
201 
202     int LunarDateCompare(const LunarDate& left, const LunarDate& right) const;
203 
204     std::unordered_map<std::string, RefPtr<FrameNode>> GetAllChildNode();
205 
206     void OrderAllChildNode(RefPtr<FrameNode>& stackYear, RefPtr<FrameNode>& stackMonth, RefPtr<FrameNode>& stackDay);
207 
GetColumn(const int32_t & tag)208     RefPtr<FrameNode> GetColumn(const int32_t& tag) const
209     {
210         auto iter = std::find_if(datePickerColumns_.begin(), datePickerColumns_.end(), [&tag](const auto& c) {
211                 auto column = c.Upgrade();
212                 return column && column->GetId() == tag;
213             });
214         return (iter == datePickerColumns_.end()) ? nullptr : (*iter).Upgrade();
215     }
216 
SetColumn(const RefPtr<FrameNode> & value)217     void SetColumn(const RefPtr<FrameNode>& value)
218     {
219         datePickerColumns_.emplace_back(value);
220     }
221 
ClearColumn()222     void ClearColumn()
223     {
224         datePickerColumns_.clear();
225     }
226 
SetShowLunar(bool value)227     void SetShowLunar(bool value)
228     {
229         lunar_ = value;
230     }
231 
IsShowLunar()232     bool IsShowLunar() const
233     {
234         return lunar_;
235     }
236 
SetCanLoop(bool value)237     void SetCanLoop(bool value)
238     {
239         isLoop_ = value;
240     }
241 
GetCanLoop()242     bool GetCanLoop() const
243     {
244         auto datePickerRowLayoutProperty = GetLayoutProperty<DataPickerRowLayoutProperty>();
245         CHECK_NULL_RETURN(datePickerRowLayoutProperty, isLoop_);
246         return datePickerRowLayoutProperty->GetCanLoopValue(true);
247     }
248 
SetShowMonthDaysFlag(bool value)249     void SetShowMonthDaysFlag(bool value)
250     {
251         showMonthDays_ = value;
252     }
253 
ShowMonthDays()254     bool ShowMonthDays() const
255     {
256         return showMonthDays_;
257     }
258 
SetShowTimeFlag(bool value)259     void SetShowTimeFlag(bool value)
260     {
261         showTime_ = value;
262     }
263 
SetShowLunarSwitch(bool value)264     void SetShowLunarSwitch(bool value)
265     {
266         showLunarSwitch_ = value;
267     }
268 
GetShowLunarSwitch()269     bool GetShowLunarSwitch()
270     {
271         return showLunarSwitch_;
272     }
273 
GetDialogAcceptEvent()274     const EventMarker& GetDialogAcceptEvent() const
275     {
276         return OnDialogAccept_;
277     }
SetDialogAcceptEvent(const EventMarker & value)278     void SetDialogAcceptEvent(const EventMarker& value)
279     {
280         OnDialogAccept_ = value;
281     }
282 
GetDialogCancelEvent()283     const EventMarker& GetDialogCancelEvent() const
284     {
285         return OnDialogCancel_;
286     }
SetDialogCancelEvent(const EventMarker & value)287     void SetDialogCancelEvent(const EventMarker& value)
288     {
289         OnDialogCancel_ = value;
290     }
291 
GetDialogChangeEvent()292     const EventMarker& GetDialogChangeEvent() const
293     {
294         return OnDialogChange_;
295     }
SetDialogChangeEvent(const EventMarker & value)296     void SetDialogChangeEvent(const EventMarker& value)
297     {
298         OnDialogChange_ = value;
299     }
300 
SetResizePickerItemHeight(double resizePickerItemHeight)301     void SetResizePickerItemHeight(double resizePickerItemHeight)
302     {
303         resizePickerItemHeight_ = resizePickerItemHeight;
304     }
305 
GetResizePickerItemHeight()306     double GetResizePickerItemHeight() const
307     {
308         return resizePickerItemHeight_;
309     }
310 
SetResizeFlag(bool resizeFlag)311     void SetResizeFlag(bool resizeFlag)
312     {
313         resizeFlag_ = resizeFlag;
314     }
315 
GetResizeFlag()316     bool GetResizeFlag() const
317     {
318         return resizeFlag_;
319     }
320 
SetIsShowInDialog(bool isShowInDialog)321     void SetIsShowInDialog(bool isShowInDialog)
322     {
323         isShowInDialog_ = isShowInDialog;
324     }
325 
GetIsShowInDialog()326     bool GetIsShowInDialog() const
327     {
328         return isShowInDialog_;
329     }
330 
GetOptionCount(RefPtr<FrameNode> & frameNode)331     uint32_t GetOptionCount(RefPtr<FrameNode>& frameNode)
332     {
333         return options_[frameNode].size();
334     }
335 
GetOptionValue(RefPtr<FrameNode> & frameNode,uint32_t index)336     PickerDateF GetOptionValue(RefPtr<FrameNode>& frameNode, uint32_t index)
337     {
338         if (index >= GetOptionCount(frameNode)) {
339             LOGE("index out of range.");
340             return {};
341         }
342         return options_[frameNode][index];
343     }
344 
GetAllOptions(RefPtr<FrameNode> & frameNode)345     const std::vector<PickerDateF>& GetAllOptions(RefPtr<FrameNode>& frameNode)
346     {
347         return options_[frameNode];
348     }
349 
GetOptions()350     const std::map<WeakPtr<FrameNode>, std::vector<PickerDateF>>& GetOptions() const
351     {
352         return options_;
353     }
354 
GetShowCount()355     uint32_t GetShowCount() const
356     {
357         return showCount_;
358     }
359 
SetShowCount(uint32_t showCount)360     void SetShowCount(uint32_t showCount)
361     {
362         showCount_ = showCount;
363     }
364 
SetDateOrder(std::string dateOrder)365     void SetDateOrder(std::string dateOrder)
366     {
367         isDateOrderChange_ = dateOrder != dateOrder_;
368         dateOrder_ = dateOrder;
369     }
370 
GetYearFormatString(uint32_t year)371     static std::string GetYearFormatString(uint32_t year)
372     {
373         return PickerStringFormatter::GetYear(year);
374     }
375 
GetMonthFormatString(uint32_t month,bool isLunar,bool isLeap)376     static std::string GetMonthFormatString(uint32_t month, bool isLunar, bool isLeap)
377     {
378         if (isLunar) {
379             return PickerStringFormatter::GetLunarMonth(month, isLeap);
380         }
381         return PickerStringFormatter::GetSolarMonth(month);
382     }
383 
GetDayFormatString(uint32_t day,bool isLunar)384     static std::string GetDayFormatString(uint32_t day, bool isLunar)
385     {
386         if (isLunar) {
387             return PickerStringFormatter::GetLunarDay(day);
388         }
389         return PickerStringFormatter::GetSolarDay(day);
390     }
391 
392     uint32_t GetLunarMaxDay(uint32_t year, uint32_t month, bool isLeap) const;
393 
394     bool GetLunarLeapMonth(uint32_t year, uint32_t& outLeapMonth) const;
395 
396     LunarDate SolarToLunar(const PickerDate& date) const;
397 
398     PickerDate LunarToSolar(const LunarDate& date) const;
399 
400     void UpdateCurrentOffset(float offset);
401 
402     void OnDataLinking(
403         const RefPtr<FrameNode>& tag, bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags);
404 
405     void HandleMonthDaysChange(
406         const RefPtr<FrameNode>& tag, bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags);
407 
408     std::string GetSelectedObject(bool isColumnChange, int status = -1) const;
409 
GetSelectDate()410     const LunarDate& GetSelectDate()
411     {
412         return selectedLunar_;
413     }
414 
SetSelectDate(const PickerDate & value)415     void SetSelectDate(const PickerDate& value)
416     {
417         selectedDate_ = value;
418         isFiredDateChange_ = firedDateStr_.has_value() && firedDateStr_.value() == GetSelectedObject(false);
419         firedDateStr_.reset();
420         if (selectedDate_.GetYear() <= 0) {
421             LOGW("selectedDate error");
422             selectedDate_ = PickerDate::Current();
423         }
424         AdjustSolarDate(selectedDate_, startDateSolar_, endDateSolar_);
425         selectedLunar_ = SolarToLunar(selectedDate_);
426     }
427 
GetSelectedDate()428     const PickerDate& GetSelectedDate()
429     {
430         return selectedDate_;
431     }
432 
SetStartDate(const PickerDate & value)433     void SetStartDate(const PickerDate& value)
434     {
435         startDateSolar_ = value;
436         AdjustSolarDate(startDateSolar_, limitStartDate_, limitEndDate_);
437         startDateLunar_ = SolarToLunar(startDateSolar_);
438     }
439 
GetStartDateLunar()440     const LunarDate& GetStartDateLunar()
441     {
442         return startDateLunar_;
443     }
444 
GetStartDateSolar()445     const PickerDate& GetStartDateSolar()
446     {
447         return startDateSolar_;
448     }
449 
SetEndDate(const PickerDate & value)450     void SetEndDate(const PickerDate& value)
451     {
452         endDateSolar_ = value;
453         AdjustSolarDate(endDateSolar_, limitStartDate_, limitEndDate_);
454         endDateLunar_ = SolarToLunar(endDateSolar_);
455     }
456 
GetEndDateLunar()457     const LunarDate& GetEndDateLunar()
458     {
459         return endDateLunar_;
460     }
461 
GetEndDateSolar()462     const PickerDate& GetEndDateSolar()
463     {
464         return endDateSolar_;
465     }
466 
SetMode(const DatePickerMode & value)467     void SetMode(const DatePickerMode& value)
468     {
469         isForceUpdate_ = value != datePickerMode_;
470         datePickerMode_ = value;
471     }
472 
GetMode()473     const DatePickerMode& GetMode()
474     {
475         return datePickerMode_;
476     }
477 
AdjustSolarDate(PickerDate & date,const PickerDate & start,const PickerDate & end)478     void AdjustSolarDate(PickerDate& date, const PickerDate& start, const PickerDate& end) const
479     {
480         if (SolarDateCompare(date, start) < 0) {
481             date = start;
482             return;
483         }
484         if (SolarDateCompare(date, end) > 0) {
485             date = end;
486         }
487     }
488 
AdjustSolarDate(PickerDate & date)489     void AdjustSolarDate(PickerDate& date) const
490     {
491         AdjustSolarDate(date, startDateSolar_, endDateSolar_);
492     }
493 
SolarDateCompare(const PickerDate & left,const PickerDate & right)494     static int SolarDateCompare(const PickerDate& left, const PickerDate& right)
495     {
496         static const int leftEqualRight = 0; // means left = right
497         static const int leftGreatRight = 1; // means left > right
498         static const int leftLessRight = -1; // means left < right
499         if (left.GetYear() > right.GetYear()) {
500             return leftGreatRight;
501         }
502         if (left.GetYear() < right.GetYear()) {
503             return leftLessRight;
504         }
505         if (left.GetMonth() > right.GetMonth()) {
506             return leftGreatRight;
507         }
508         if (left.GetMonth() < right.GetMonth()) {
509             return leftLessRight;
510         }
511         if (left.GetDay() > right.GetDay()) {
512             return leftGreatRight;
513         }
514         if (left.GetDay() < right.GetDay()) {
515             return leftLessRight;
516         }
517         return leftEqualRight;
518     }
519 
HasYearNode()520     bool HasYearNode() const
521     {
522         return yearId_.has_value();
523     }
524 
GetYearId()525     int32_t GetYearId()
526     {
527         if (!yearId_.has_value()) {
528             yearId_ = ElementRegister::GetInstance()->MakeUniqueId();
529         }
530         return yearId_.value();
531     }
532 
HasMonthNode()533     bool HasMonthNode() const
534     {
535         return monthId_.has_value();
536     }
537 
GetMonthId()538     int32_t GetMonthId()
539     {
540         if (!monthId_.has_value()) {
541             monthId_ = ElementRegister::GetInstance()->MakeUniqueId();
542         }
543         return monthId_.value();
544     }
545 
HasDayNode()546     bool HasDayNode() const
547     {
548         return dayId_.has_value();
549     }
550 
GetDayId()551     int32_t GetDayId()
552     {
553         if (!dayId_.has_value()) {
554             dayId_ = ElementRegister::GetInstance()->MakeUniqueId();
555         }
556         return dayId_.value();
557     }
558 
HasMonthDaysNode()559     bool HasMonthDaysNode() const
560     {
561         return monthDaysId_.has_value();
562     }
563 
GetMonthDaysId()564     int32_t GetMonthDaysId()
565     {
566         if (!monthDaysId_.has_value()) {
567             monthDaysId_ = ElementRegister::GetInstance()->MakeUniqueId();
568         }
569         return monthDaysId_.value();
570     }
571 
HasTitleNode()572     bool HasTitleNode() const
573     {
574         return titleId_.has_value();
575     }
576 
SetTitleId(const int32_t id)577     bool SetTitleId(const int32_t id)
578     {
579         if (HasTitleNode()) {
580             return false;
581         }
582         titleId_ = id;
583         return true;
584     }
585 
GetTitleId()586     int32_t GetTitleId()
587     {
588         if (!titleId_.has_value()) {
589             titleId_ = ElementRegister::GetInstance()->MakeUniqueId();
590         }
591         return titleId_.value();
592     }
593 
HasButtonTitleNode()594     bool HasButtonTitleNode() const
595     {
596         return ButtonTitleId_.has_value();
597     }
598 
GetButtonTitleId()599     int32_t GetButtonTitleId()
600     {
601         if (!ButtonTitleId_.has_value()) {
602             ButtonTitleId_ = ElementRegister::GetInstance()->MakeUniqueId();
603         }
604         return ButtonTitleId_.value();
605     }
606 
HasDividerNode()607     bool HasDividerNode() const
608     {
609         return DividerId_.has_value();
610     }
611 
GetDividerId()612     int32_t GetDividerId()
613     {
614         if (!DividerId_.has_value()) {
615             DividerId_ = ElementRegister::GetInstance()->MakeUniqueId();
616         }
617         return DividerId_.value();
618     }
619 
SetBackgroundColor(const Color & color)620     void SetBackgroundColor(const Color& color)
621     {
622         backgroundColor_ = color;
623     }
624 
625     static const std::string& GetYear(uint32_t year);
626 
627     static const std::string& GetSolarMonth(uint32_t month);
628 
629     static const std::string& GetSolarDay(uint32_t day);
630 
631     static const std::string& GetLunarMonth(uint32_t month, bool isLeap);
632 
633     static const std::string& GetLunarDay(uint32_t day);
634 
635     const std::string GetText();
636 
GetFocusPattern()637     FocusPattern GetFocusPattern() const override
638     {
639         auto pipeline = PipelineBase::GetCurrentContext();
640         CHECK_NULL_RETURN(pipeline, FocusPattern());
641         auto pickerTheme = pipeline->GetTheme<PickerTheme>();
642         CHECK_NULL_RETURN(pickerTheme, FocusPattern());
643         auto focusColor = pickerTheme->GetFocusColor();
644         FocusPaintParam focusPaintParams;
645         focusPaintParams.SetPaintColor(focusColor);
646         return { FocusType::NODE, true, FocusStyleType::CUSTOM_REGION, focusPaintParams };
647     }
648 
SetCurrentFocusKeyID(int32_t value)649     void SetCurrentFocusKeyID(int32_t value)
650     {
651         focusKeyID_ = value;
652     }
653 
GetCurrentFocusKeyID()654     int32_t GetCurrentFocusKeyID()
655     {
656         return focusKeyID_;
657     }
658 
SetCurrentPage(uint32_t value)659     void SetCurrentPage(uint32_t value)
660     {
661         currentPage_ = value;
662     }
663 
GetCurrentPage()664     uint32_t GetCurrentPage()
665     {
666         return currentPage_;
667     }
668 
669     bool NeedAdaptForAging();
670 
671     void ShowTitle(int32_t titleId);
672     std::string GetVisibleColumnsText();
673     void GetColumnText(const RefPtr<FrameNode>& columnNode, std::string& result);
674     void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override;
SetContentRowNode(RefPtr<FrameNode> & contentRowNode)675     void SetContentRowNode(RefPtr<FrameNode>& contentRowNode)
676     {
677         contentRowNode_ = contentRowNode;
678     }
SetbuttonTitleNode(RefPtr<FrameNode> & buttonTitleNode)679     void SetbuttonTitleNode(RefPtr<FrameNode>& buttonTitleNode)
680     {
681         buttonTitleNode_ = buttonTitleNode;
682     }
683 
SetPickerTag(bool isPicker)684     void SetPickerTag(bool isPicker)
685     {
686         isPicker_ = isPicker;
687     }
688 
689     void SetFocusDisable();
690     void SetFocusEnable();
691     static const std::string GetFormatString(PickerDateF data);
692 
HasUserDefinedDisappearFontFamily(bool isUserDefined)693     void HasUserDefinedDisappearFontFamily(bool isUserDefined)
694     {
695         hasUserDefinedDisappearFontFamily_ = isUserDefined;
696     }
697 
GetHasUserDefinedDisappearFontFamily()698     bool GetHasUserDefinedDisappearFontFamily()
699     {
700         return hasUserDefinedDisappearFontFamily_;
701     }
702 
HasUserDefinedNormalFontFamily(bool isUserDefined)703     void HasUserDefinedNormalFontFamily(bool isUserDefined)
704     {
705         hasUserDefinedNormalFontFamily_ = isUserDefined;
706     }
707 
GetHasUserDefinedNormalFontFamily()708     bool GetHasUserDefinedNormalFontFamily()
709     {
710         return hasUserDefinedNormalFontFamily_;
711     }
712 
HasUserDefinedSelectedFontFamily(bool isUserDefined)713     void HasUserDefinedSelectedFontFamily(bool isUserDefined)
714     {
715         hasUserDefinedSelectedFontFamily_ = isUserDefined;
716     }
717 
GetHasUserDefinedSelectedFontFamily()718     bool GetHasUserDefinedSelectedFontFamily()
719     {
720         return hasUserDefinedSelectedFontFamily_;
721     }
722 
updateFontConfigurationEvent(const std::function<void ()> & closeDialogEvent)723     void updateFontConfigurationEvent(const std::function<void()>& closeDialogEvent)
724     {
725         closeDialogEvent_ = closeDialogEvent;
726     }
727 
GetTextProperties()728     const PickerTextProperties& GetTextProperties() const
729     {
730         return textProperties_;
731     }
732 
SetTextProperties(const PickerTextProperties & properties)733     void SetTextProperties(const PickerTextProperties& properties)
734     {
735         textProperties_ = properties;
736         if (properties.disappearTextStyle_.fontSize.has_value() && properties.disappearTextStyle_.fontSize->IsValid()) {
737             isUserSetGradientFont_ = true;
738             gradientHeight_ = properties.disappearTextStyle_.fontSize.value();
739         }
740 
741         if (properties.normalTextStyle_.fontSize.has_value() && properties.normalTextStyle_.fontSize->IsValid()) {
742             isUserSetGradientFont_ = true;
743             gradientHeight_ = std::max(properties.normalTextStyle_.fontSize.value(), gradientHeight_);
744         }
745 
746         if (properties.selectedTextStyle_.fontSize.has_value() && properties.selectedTextStyle_.fontSize->IsValid()) {
747             isUserSetDividerSpacingFont_ = true;
748             dividerSpacing_ = properties.selectedTextStyle_.fontSize.value();
749         }
750     }
751 
GetIsUserSetDividerSpacingFont()752     bool GetIsUserSetDividerSpacingFont()
753     {
754         return isUserSetDividerSpacingFont_;
755     }
756 
GetIsUserSetGradientFont()757     bool GetIsUserSetGradientFont()
758     {
759         return isUserSetGradientFont_;
760     }
761 
GetDividerSpacing()762     Dimension GetDividerSpacing()
763     {
764         return dividerSpacing_;
765     }
766 
GetGradientHeight()767     Dimension GetGradientHeight()
768     {
769         return gradientHeight_;
770     }
771 
SetPaintDividerSpacing(float & value)772     void SetPaintDividerSpacing(float& value)
773     {
774         paintDividerSpacing_ = value;
775     }
776 
GetPaintDividerSpacing()777     float GetPaintDividerSpacing()
778     {
779         return paintDividerSpacing_;
780     }
781 
782     static bool ReportDateChangeEvent(int32_t nodeId, const std::string& compName,
783         const std::string& eventName, const std::string& eventData);
784 
SetUserDefinedOpacity(double opacity)785     void SetUserDefinedOpacity(double opacity)
786     {
787         curOpacity_ = opacity;
788     }
789 
SetEnableHapticFeedback(bool value)790     void SetEnableHapticFeedback(bool value)
791     {
792         if (isEnableHaptic_ != value) {
793             isHapticChanged_ = true;
794         }
795         isEnableHaptic_ = value;
796     }
797 
GetEnableHapticFeedback()798     bool GetEnableHapticFeedback() const
799     {
800         return isEnableHaptic_;
801     }
802 
803     void ColumnPatternInitHapticController();
804     void ColumnPatternInitHapticController(const RefPtr<FrameNode>& columnNode);
805     void ColumnPatternStopHaptic();
806 
807     void SetDigitalCrownSensitivity(int32_t crownSensitivity);
808     void UpdateUserSetSelectColor();
809     void UpdateDisappearTextStyle(const PickerTextStyle& textStyle);
810     void UpdateNormalTextStyle(const PickerTextStyle& textStyle);
811     void UpdateSelectedTextStyle(const PickerTextStyle& textStyle);
812 
813 private:
814     void OnModifyDone() override;
815     void OnAttachToFrameNode() override;
816     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
817     static void Init();
818     void InitDisabled();
819     void GetInnerFocusPaintRect(RoundRect& paintRect);
820     void PaintFocusState();
821     void InitOnKeyEvent(const RefPtr<FocusHub>& focusHub);
822     bool OnKeyEvent(const KeyEvent& event);
823     bool HandleDirectionKey(KeyCode code);
824     void InitFocusEvent();
825     void InitSelectorProps();
826     void HandleFocusEvent();
827     void HandleBlurEvent();
828     void AddIsFocusActiveUpdateEvent();
829     void RemoveIsFocusActiveUpdateEvent();
830     void GetInnerFocusButtonPaintRect(RoundRect& paintRect, float focusButtonXOffset);
831     void UpdateFocusButtonState();
832     void SetHaveFocus(bool haveFocus);
833     void UpdateColumnButtonStyles(const RefPtr<FrameNode>& columnNode, bool haveFocus, bool needMarkDirty);
834     PickerDate GetCurrentDateByMonthDaysColumn() const;
835     PickerDate GetCurrentDateByYearMonthDayColumn() const;
836     void OrderCurrentDateByYearMonthDayColumn(
837         RefPtr<FrameNode>& stackYear, RefPtr<FrameNode>& stackMonth, RefPtr<FrameNode>& stackDay) const;
838     void FillSolarYearOptions(const PickerDate& current, RefPtr<FrameNode>& yearColumn);
839     void UpdateTitleTextColor(const RefPtr<FrameNode>& buttonTitleNode, const RefPtr<PickerTheme>& pickerTheme);
840     void FillLunarMonthDaysOptions(const LunarDate& current, RefPtr<FrameNode>& monthDaysColumn);
841     void AdjustSolarStartEndDate();
842     void AdjustLunarStartEndDate();
843     void UpdateButtonMargin(
844         const RefPtr<FrameNode>& buttonNode, const RefPtr<DialogTheme>& dialogTheme, const bool isConfirmOrNextNode);
845     void UpdateButtonNode(const RefPtr<FrameNode>& buttonNode, const bool isConfirmNode);
846     void ShowColumnByDatePickMode();
847     void UpdateStackPropVisibility(const RefPtr<FrameNode>& stackNode,
848         const VisibleType visibleType, const int32_t weight);
849     void ClearFocus();
850     void SetDefaultFocus();
851     void AdjustFocusBoxOffset(double& centerX);
852     bool IsCircle();
853     bool CurrentIsLunar();
854 #ifdef SUPPORT_DIGITAL_CROWN
855     void InitOnCrownEvent(const RefPtr<FocusHub>& focusHub);
856     bool OnCrownEvent(const CrownEvent& event);
857 #endif
858     void InitFocusKeyEvent();
859     void FlushChildNodes();
860     void UpdateLunarSwitch();
861     void UpdateDateOrder();
862     void UpdateDialogAgingButton(const RefPtr<FrameNode>& buttonNode, bool isNext);
863     Dimension ConvertFontScaleValue(const Dimension& fontSizeValue);
864 
865     void UpdateTextStyleCommon(
866         const PickerTextStyle& textStyle,
867         const TextStyle& defaultTextStyle,
868         std::function<void(const Color&)> updateTextColorFunc,
869         std::function<void(const Dimension&)> updateFontSizeFunc,
870         std::function<void(const std::vector<std::string>&)> updateFontFamilyFunc);
871 
872     RefPtr<ClickEvent> clickEventListener_;
873     bool enabled_ = true;
874     int32_t focusKeyID_ = 0;
875     uint32_t currentPage_ = 0;
876     std::map<WeakPtr<FrameNode>, std::vector<PickerDateF>> options_;
877     uint32_t showCount_ = 0;
878     std::string dateOrder_ = "";
879     std::vector<WeakPtr<FrameNode>> datePickerColumns_;
880     bool lunar_ = false;
881     bool isLoop_ = true;
882     bool showMonthDays_ = false;
883     bool showTime_ = false;
884     bool showLunarSwitch_ = false;
885     Color backgroundColor_ = Color::WHITE;
886     std::optional<int32_t> yearId_;
887     std::optional<int32_t> monthId_;
888     std::optional<int32_t> dayId_;
889     std::optional<int32_t> monthDaysId_;
890     std::optional<int32_t> dateNodeId_;
891     std::optional<int32_t> titleId_;
892     std::optional<int32_t> ButtonTitleId_;
893     std::optional<int32_t> DividerId_;
894     double resizePickerItemHeight_ = 0.0;
895     bool resizeFlag_ = false;
896     bool isShowInDialog_ = false;
897     bool focusEventInitialized_ = false;
898     bool haveFocus_ = false;
899     bool useButtonFocusArea_ = false;
900     Dimension selectorItemRadius_ = 8.0_vp;
901     std::function<void(bool)> isFocusActiveUpdateEvent_;
902     EventMarker OnDialogAccept_;
903     EventMarker OnDialogCancel_;
904     EventMarker OnDialogChange_;
905     WeakPtr<FrameNode> weakButtonConfirm_;
906     WeakPtr<FrameNode> weakButtonCancel_;
907     WeakPtr<FrameNode> weakLunarSwitchText_;
908     WeakPtr<FrameNode> weakLunarSwitchCheckbox_;
909     WeakPtr<FrameNode> nextPrevButtonNode_;
910     bool isNext_ = true;
911     PickerDate startDateSolar_ = PickerDate(1970, 1, 1); // default start date is 1970-1-1 from FA document.
912     LunarDate startDateLunar_;
913     PickerDate endDateSolar_ = PickerDate(2100, 12, 31); // default end date is 2100-12-31 from FA document.
914     LunarDate endDateLunar_;
915     PickerDate selectedDate_ = PickerDate::Current();
916     LunarDate selectedLunar_;
917     PickerDate startDefaultDateSolar_ = PickerDate(1970, 1, 1); // default start date is 1970-1-1 from FA document.
918     PickerDate endDefaultDateSolar_ = PickerDate(2100, 12, 31); // default end date is 2100-12-31 from FA document.
919     const PickerDate limitStartDate_ = PickerDate(1900, 1, 31);
920     const PickerDate limitEndDate_ = PickerDate(2100, 12, 31);
921     static bool inited_;
922     static const std::string empty_;
923     static const PickerDateF emptyPickerDate_;
924     static std::unordered_map<uint32_t, std::string> years_;       // year from 1900 to 2100,count is 201
925     static std::unordered_map<uint32_t, std::string> solarMonths_; // solar month from 1 to 12,count is 12
926     static std::unordered_map<uint32_t, std::string> solarDays_;   // solar day from 1 to 31, count is 31
927     static std::unordered_map<uint32_t, std::string> lunarMonths_; // lunar month from 1 to 24, count is 24
928     static std::unordered_map<uint32_t, std::string> lunarDays_;   // lunar day from 1 to 30, count is 30
929     static std::vector<std::string> tagOrder_;    // year month day tag order
930     static std::vector<std::string> localizedMonths_;
931     WeakPtr<FrameNode> contentRowNode_;
932     WeakPtr<FrameNode> buttonTitleNode_;
933     bool isPicker_ = false;
934     bool isFiredDateChange_ = false;
935     bool isForceUpdate_ = false;
936     bool isDateOrderChange_ = false;
937     std::optional<std::string> firedDateStr_;
938     void CalcLeftTotalColumnWidth(const RefPtr<FrameNode>& host, float &leftTotalColumnWidth, float childSize);
939     bool CheckFocusID(int32_t childSize);
940     bool ParseDirectionKey(RefPtr<DatePickerColumnPattern>& pattern, KeyCode& code, uint32_t totalOptionCount,
941                           int32_t childSize);
942     bool ReportDateChangeEvent(const std::string& compName,
943         const std::string& eventName, const std::string& eventData);
944 
945     bool hasUserDefinedDisappearFontFamily_ = false;
946     bool hasUserDefinedNormalFontFamily_ = false;
947     bool hasUserDefinedSelectedFontFamily_ = false;
948     std::function<void()> closeDialogEvent_;
949     bool isUserSetDividerSpacingFont_ = false;
950     bool isUserSetGradientFont_ = false;
951     Dimension gradientHeight_;
952     Dimension dividerSpacing_;
953     float paintDividerSpacing_ = 1.0f;
954     PickerTextProperties textProperties_;
955     double curOpacity_ = 1.0;
956     DatePickerMode datePickerMode_ = DatePickerMode::DATE;
957     bool isFocus_ = true;
958     bool isEnableHaptic_ = true;
959     bool isHapticChanged_ = true;
960 
961     ACE_DISALLOW_COPY_AND_MOVE(DatePickerPattern);
962     std::string selectedColumnId_;
963     bool lastTimeIsLuanar_ = true;
964     bool isFirstTimeSetFocus_ = true;
965     bool isDirectionSetByAr = false;
966 };
967 } // namespace OHOS::Ace::NG
968 
969 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_DATE_PICKER_DATE_PICKER_PATTERN_H
970