• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #include "core/components_ng/pattern/calendar_picker/calendar_picker_model_ng.h"
17 
18 #include "base/i18n/localization.h"
19 #include "core/components/theme/icon_theme.h"
20 #include "core/components_ng/base/view_stack_processor.h"
21 #include "core/components_ng/pattern/button/button_pattern.h"
22 #include "core/components_ng/pattern/flex/flex_layout_pattern.h"
23 #include "core/components_ng/pattern/flex/flex_layout_property.h"
24 #include "core/components_ng/pattern/image/image_pattern.h"
25 #include "core/components_ng/pattern/text/text_pattern.h"
26 #include "core/components_ng/pattern/text_field/text_field_pattern.h"
27 
28 namespace OHOS::Ace::NG {
29 constexpr int32_t YEAR_NODE_INDEX = 0;
30 constexpr int32_t MONTH_NODE_INDEX = 2;
31 constexpr int32_t DAY_NODE_INDEX = 4;
32 constexpr int32_t DATE_NODE_COUNT = 3;
33 constexpr int32_t ONE_DIGIT_BOUNDARY = 10;
34 constexpr uint32_t MAX_MONTH = 12;
35 constexpr float DEFAULT_HINT_RADIUS = 16.0f;
36 constexpr uint32_t YEAR_LENGTH = 4;
37 static int32_t yearNodeIndex_ = 0;
38 static int32_t monthNodeIndex_ = 2;
39 static int32_t dayNodeIndex_ = 4;
40 const bool DEFAULT_MARK_TODAY = false;
Create(const CalendarSettingData & settingData)41 void CalendarPickerModelNG::Create(const CalendarSettingData& settingData)
42 {
43     auto* stack = ViewStackProcessor::GetInstance();
44     auto nodeId = stack->ClaimNodeId();
45     ACE_LAYOUT_SCOPED_TRACE("Create[%s][self:%d]", V2::CALENDAR_PICKER_ETS_TAG, nodeId);
46     auto pickerNode = CalendarPickerModelNG::CreateNode(nodeId, settingData);
47     stack->Push(pickerNode);
48 }
49 
CreateFrameNode(int32_t nodeId)50 RefPtr<FrameNode> CalendarPickerModelNG::CreateFrameNode(int32_t nodeId)
51 {
52     NG::CalendarSettingData settingData;
53     return CalendarPickerModelNG::CreateNode(nodeId, settingData);
54 }
55 
LayoutPicker(const RefPtr<CalendarPickerPattern> & pickerPattern,RefPtr<FrameNode> & pickerNode,const CalendarSettingData & settingData,const RefPtr<CalendarTheme> & theme)56 void CalendarPickerModelNG::LayoutPicker(const RefPtr<CalendarPickerPattern>& pickerPattern,
57     RefPtr<FrameNode>& pickerNode, const CalendarSettingData& settingData, const RefPtr<CalendarTheme>& theme)
58 {
59     auto textDirection = pickerNode->GetLayoutProperty()->GetNonAutoLayoutDirection();
60     if (!pickerPattern->HasContentNode()) {
61         auto contentNode = CalendarPickerModelNG::CreateCalendarNodeChild(
62             pickerPattern->GetContentId(), settingData, theme, textDirection);
63         CHECK_NULL_VOID(contentNode);
64         contentNode->MountToParent(pickerNode);
65     } else {
66         auto setDate =
67             PickerDate::AdjustDateToRange(settingData.selectedDate, settingData.startDate, settingData.endDate);
68         CHECK_NULL_VOID(pickerPattern);
69         pickerPattern->SetDate(setDate.ToString(true));
70     }
71     auto flexNode = CalendarPickerModelNG::CreateButtonFlexChild(pickerPattern->GetButtonFlexId(), theme);
72     CHECK_NULL_VOID(flexNode);
73     flexNode->MountToParent(pickerNode);
74     if (!pickerPattern->HasAddNode()) {
75         auto addNode = CalendarPickerModelNG::CreateButtonChild(pickerPattern->GetAddId(), true, theme, textDirection);
76         CHECK_NULL_VOID(addNode);
77         addNode->MountToParent(flexNode, 0, true);
78     }
79     if (!pickerPattern->HasSubNode()) {
80         auto subNode = CalendarPickerModelNG::CreateButtonChild(pickerPattern->GetSubId(), false, theme, textDirection);
81         CHECK_NULL_VOID(subNode);
82         subNode->MountToParent(flexNode, 1, true);
83     }
84 }
85 
CreateButtonChild(int32_t id,bool isAdd,const RefPtr<CalendarTheme> & theme,TextDirection textDirection)86 RefPtr<FrameNode> CalendarPickerModelNG::CreateButtonChild(
87     int32_t id, bool isAdd, const RefPtr<CalendarTheme>& theme, TextDirection textDirection)
88 {
89     auto buttonNode =
90         FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG, id, []() { return AceType::MakeRefPtr<ButtonPattern>(); });
91     CHECK_NULL_RETURN(buttonNode, nullptr);
92     auto buttonEventHub = buttonNode->GetEventHub<ButtonEventHub>();
93     CHECK_NULL_RETURN(buttonEventHub, nullptr);
94     buttonEventHub->SetStateEffect(true);
95 
96     auto buttonLayoutProperty = buttonNode->GetLayoutProperty<ButtonLayoutProperty>();
97     CHECK_NULL_RETURN(buttonLayoutProperty, nullptr);
98     buttonLayoutProperty->UpdateType(ButtonType::NORMAL);
99 
100     auto buttonPattern = buttonNode->GetPattern<ButtonPattern>();
101     CHECK_NULL_RETURN(buttonPattern, nullptr);
102 
103     buttonNode->GetLayoutProperty()->UpdateUserDefinedIdealSize(
104         CalcSize(CalcLength(theme->GetEntryButtonWidth()), std::nullopt));
105     buttonNode->GetLayoutProperty()->UpdateLayoutWeight(1);
106     BorderWidthProperty borderWidth;
107     auto isRtl = textDirection == TextDirection::RTL;
108     if (isAdd) {
109         if (isRtl) {
110             borderWidth.rightDimen = theme->GetEntryBorderWidth();
111         } else {
112             borderWidth.leftDimen = theme->GetEntryBorderWidth();
113         }
114         borderWidth.bottomDimen = theme->GetEntryBorderWidth() / 2;
115     } else {
116         if (isRtl) {
117             borderWidth.rightDimen = theme->GetEntryBorderWidth();
118         } else {
119             borderWidth.leftDimen = theme->GetEntryBorderWidth();
120         }
121         borderWidth.topDimen = theme->GetEntryBorderWidth() / 2;
122     }
123     buttonNode->GetLayoutProperty()->UpdateBorderWidth(borderWidth);
124     BorderColorProperty borderColor;
125     borderColor.SetColor(theme->GetEntryBorderColor());
126     buttonNode->GetRenderContext()->UpdateBorderColor(borderColor);
127     buttonNode->MarkModifyDone();
128 
129     auto imageNode = CreateButtonImageChild(isAdd, theme);
130     CHECK_NULL_RETURN(imageNode, nullptr);
131     imageNode->MountToParent(buttonNode);
132     return buttonNode;
133 }
134 
CreateButtonImageChild(bool isAdd,const RefPtr<CalendarTheme> & theme)135 RefPtr<FrameNode> CalendarPickerModelNG::CreateButtonImageChild(bool isAdd, const RefPtr<CalendarTheme>& theme)
136 {
137     auto imageNode = FrameNode::CreateFrameNode(
138         V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>());
139     CHECK_NULL_RETURN(imageNode, nullptr);
140     imageNode->GetLayoutProperty()->UpdateUserDefinedIdealSize(
141         CalcSize(CalcLength(theme->GetEntryArrowWidth()), CalcLength(theme->GetEntryArrowHeight())));
142     auto pipeline = PipelineBase::GetCurrentContext();
143     CHECK_NULL_RETURN(pipeline, nullptr);
144     auto iconTheme = pipeline->GetTheme<IconTheme>();
145     std::string iconPath;
146     ImageSourceInfo imageSourceInfo;
147     if (isAdd) {
148         imageSourceInfo.SetResourceId(InternalResource::ResourceId::IC_PUBLIC_ARROW_UP_SVG);
149         iconPath = iconTheme->GetIconPath(InternalResource::ResourceId::IC_PUBLIC_ARROW_UP_SVG);
150     } else {
151         imageSourceInfo.SetResourceId(InternalResource::ResourceId::IC_PUBLIC_ARROW_DOWN_SVG);
152         iconPath = iconTheme->GetIconPath(InternalResource::ResourceId::IC_PUBLIC_ARROW_DOWN_SVG);
153     }
154     imageSourceInfo.SetSrc(iconPath, theme->GetEntryArrowColor());
155     imageNode->GetLayoutProperty<ImageLayoutProperty>()->UpdateImageSourceInfo(imageSourceInfo);
156     imageNode->MarkModifyDone();
157     return imageNode;
158 }
159 
CreateButtonFlexChild(int32_t buttonFlexId,const RefPtr<CalendarTheme> & theme)160 RefPtr<FrameNode> CalendarPickerModelNG::CreateButtonFlexChild(int32_t buttonFlexId, const RefPtr<CalendarTheme>& theme)
161 {
162     auto flexNode = FrameNode::GetOrCreateFrameNode(
163         V2::COLUMN_ETS_TAG, buttonFlexId, []() { return AceType::MakeRefPtr<LinearLayoutPattern>(true); });
164     CHECK_NULL_RETURN(flexNode, nullptr);
165     auto flexLayoutProperty = flexNode->GetLayoutProperty<LinearLayoutProperty>();
166     CHECK_NULL_RETURN(flexLayoutProperty, nullptr);
167     flexLayoutProperty->UpdateMainAxisAlign(FlexAlign::CENTER);
168     flexLayoutProperty->UpdateMeasureType(MeasureType::MATCH_PARENT_CROSS_AXIS);
169     return flexNode;
170 }
171 
CreateCalendarNodeChild(int32_t contentId,const CalendarSettingData & settingData,const RefPtr<CalendarTheme> & theme,TextDirection textDirection)172 RefPtr<FrameNode> CalendarPickerModelNG::CreateCalendarNodeChild(int32_t contentId,
173     const CalendarSettingData& settingData, const RefPtr<CalendarTheme>& theme, TextDirection textDirection)
174 {
175     auto contentNode = FrameNode::GetOrCreateFrameNode(
176         V2::ROW_ETS_TAG, contentId, []() { return AceType::MakeRefPtr<LinearLayoutPattern>(false); });
177     CHECK_NULL_RETURN(contentNode, nullptr);
178 
179     auto linearLayoutProperty = contentNode->GetLayoutProperty<LinearLayoutProperty>();
180     CHECK_NULL_RETURN(linearLayoutProperty, nullptr);
181 
182     linearLayoutProperty->UpdateMainAxisAlign(FlexAlign::CENTER);
183     linearLayoutProperty->UpdateCrossAxisAlign(FlexAlign::CENTER);
184     contentNode->GetRenderContext()->SetClipToFrame(true);
185     linearLayoutProperty->UpdateMeasureType(MeasureType::MATCH_PARENT);
186     BorderRadiusProperty borderRadius;
187     borderRadius.radiusTopLeft = theme->GetEntryBorderRadius();
188     borderRadius.radiusBottomLeft = theme->GetEntryBorderRadius();
189     borderRadius.radiusTopRight = theme->GetEntryBorderRadius();
190     borderRadius.radiusBottomLeft = theme->GetEntryBorderRadius();
191     contentNode->GetRenderContext()->UpdateBorderRadius(borderRadius);
192     PaddingProperty padding;
193     padding.top = CalcLength(theme->GetEntryDateTopBottomMargin());
194     padding.left = CalcLength(theme->GetEntryDateLeftRightMargin());
195     padding.right = CalcLength(theme->GetEntryDateLeftRightMargin());
196     padding.bottom = CalcLength(theme->GetEntryDateTopBottomMargin());
197     linearLayoutProperty->UpdatePadding(padding);
198     linearLayoutProperty->UpdateLayoutDirection(TextDirection::LTR);
199 
200     CreateDateNode(contentId, settingData);
201     contentNode->MarkModifyDone();
202     return contentNode;
203 }
204 
CreateDateNode(int32_t contentId,const CalendarSettingData & settingData)205 void CalendarPickerModelNG::CreateDateNode(int32_t contentId, const CalendarSettingData& settingData)
206 {
207     auto contentNode = FrameNode::GetOrCreateFrameNode(
208         V2::ROW_ETS_TAG, contentId, []() { return AceType::MakeRefPtr<LinearLayoutPattern>(false); });
209     CHECK_NULL_VOID(contentNode);
210     std::map<std::size_t, std::string> order = GetDateNodeOrder(settingData);
211 
212     auto firstDateNode = CreateDateTextNode(order[0]);
213     CHECK_NULL_VOID(firstDateNode);
214     firstDateNode->MountToParent(contentNode);
215     auto textNode1 = CreateDateTextNode("/");
216     CHECK_NULL_VOID(textNode1);
217     textNode1->MountToParent(contentNode);
218     auto secondDateNode = CreateDateTextNode(order[1]);
219     CHECK_NULL_VOID(secondDateNode);
220     secondDateNode->MountToParent(contentNode);
221     auto textNode2 = CreateDateTextNode("/");
222     CHECK_NULL_VOID(textNode2);
223     textNode2->MountToParent(contentNode);
224     auto thirdDateNode = CreateDateTextNode(order[2]);
225     CHECK_NULL_VOID(thirdDateNode);
226     thirdDateNode->MountToParent(contentNode);
227 }
228 
CreateDateTextNode(const std::string & textContent)229 RefPtr<FrameNode> CalendarPickerModelNG::CreateDateTextNode(const std::string& textContent)
230 {
231     auto pipeline = PipelineBase::GetCurrentContext();
232     CHECK_NULL_RETURN(pipeline, nullptr);
233     RefPtr<CalendarTheme> calendarTheme = pipeline->GetTheme<CalendarTheme>();
234     CHECK_NULL_RETURN(calendarTheme, nullptr);
235     auto textNode = FrameNode::CreateFrameNode(
236         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
237     CHECK_NULL_RETURN(textNode, nullptr);
238     auto textLayoutProperty = textNode->GetLayoutProperty<TextLayoutProperty>();
239     CHECK_NULL_RETURN(textLayoutProperty, nullptr);
240     textLayoutProperty->UpdateContent(textContent);
241     textLayoutProperty->UpdateMaxLines(1);
242     textLayoutProperty->UpdateTextColor(calendarTheme->GetEntryFontColor());
243     textLayoutProperty->UpdateFontSize(calendarTheme->GetEntryFontSize());
244     textNode->MarkModifyDone();
245     return textNode;
246 }
247 
CreateNode(int32_t nodeId,const CalendarSettingData & settingData)248 RefPtr<FrameNode> CalendarPickerModelNG::CreateNode(int32_t nodeId, const CalendarSettingData& settingData)
249 {
250     auto pickerNode = FrameNode::GetOrCreateFrameNode(
251         V2::CALENDAR_PICKER_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<CalendarPickerPattern>(); });
252     auto pickerPattern = pickerNode->GetPattern<CalendarPickerPattern>();
253     CHECK_NULL_RETURN(pickerPattern, pickerNode);
254     auto pipelineContext = pickerNode->GetContext();
255     CHECK_NULL_RETURN(pipelineContext, pickerNode);
256     RefPtr<CalendarTheme> theme = pipelineContext->GetTheme<CalendarTheme>();
257     CHECK_NULL_RETURN(theme, pickerNode);
258     pickerPattern->SetCalendarData(settingData);
259     pickerNode->GetLayoutProperty()->UpdateUserDefinedIdealSize(
260         CalcSize(std::nullopt, CalcLength(theme->GetEntryHeight())));
261     BorderWidthProperty borderWidth;
262     borderWidth.SetBorderWidth(theme->GetEntryBorderWidth());
263     pickerNode->GetLayoutProperty()->UpdateBorderWidth(borderWidth);
264     CHECK_NULL_RETURN(pickerNode->GetRenderContext(), pickerNode);
265     BorderColorProperty borderColor;
266     borderColor.SetColor(theme->GetEntryBorderColor());
267     pickerNode->GetRenderContext()->UpdateBorderColor(borderColor);
268     BorderRadiusProperty borderRadius;
269     borderRadius.SetRadius(theme->GetEntryBorderRadius());
270     pickerNode->GetRenderContext()->UpdateBorderRadius(borderRadius);
271     pickerNode->GetRenderContext()->SetClipToFrame(true);
272     pickerNode->GetRenderContext()->SetClipToBounds(true);
273     pickerNode->GetRenderContext()->UpdateClipEdge(true);
274     CHECK_NULL_RETURN(pickerNode->GetLayoutProperty<LinearLayoutProperty>(), pickerNode);
275     pickerNode->GetLayoutProperty<LinearLayoutProperty>()->UpdateMainAxisAlign(FlexAlign::FLEX_START);
276     pickerNode->GetLayoutProperty<LinearLayoutProperty>()->UpdateCrossAxisAlign(FlexAlign::CENTER);
277     pickerNode->GetLayoutProperty<LinearLayoutProperty>()->UpdateMeasureType(MeasureType::MATCH_CONTENT);
278     CalendarPickerModelNG::LayoutPicker(pickerPattern, pickerNode, settingData, theme);
279 
280     pickerNode->MarkModifyDone();
281     return pickerNode;
282 }
283 
SetEdgeAlign(const CalendarEdgeAlign & alignType,const DimensionOffset & offset)284 void CalendarPickerModelNG::SetEdgeAlign(const CalendarEdgeAlign& alignType, const DimensionOffset& offset)
285 {
286     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
287     CHECK_NULL_VOID(frameNode);
288     auto pickerPattern = frameNode->GetPattern<CalendarPickerPattern>();
289     CHECK_NULL_VOID(pickerPattern);
290     pickerPattern->SetCalendarEdgeAlign(alignType);
291     pickerPattern->SetCalendarDialogOffset(offset);
292 
293     ACE_UPDATE_LAYOUT_PROPERTY(CalendarPickerLayoutProperty, DialogAlignType, alignType);
294     ACE_UPDATE_LAYOUT_PROPERTY(CalendarPickerLayoutProperty, DialogOffset, offset);
295 }
296 
SetTextStyle(const PickerTextStyle & textStyle)297 void CalendarPickerModelNG::SetTextStyle(const PickerTextStyle& textStyle)
298 {
299     auto pipeline = PipelineBase::GetCurrentContext();
300     CHECK_NULL_VOID(pipeline);
301     RefPtr<CalendarTheme> calendarTheme = pipeline->GetTheme<CalendarTheme>();
302     CHECK_NULL_VOID(calendarTheme);
303     if (textStyle.fontSize.has_value() && textStyle.fontSize->IsValid()) {
304         ACE_UPDATE_LAYOUT_PROPERTY(CalendarPickerLayoutProperty, FontSize, textStyle.fontSize.value());
305     } else {
306         ACE_UPDATE_LAYOUT_PROPERTY(CalendarPickerLayoutProperty, FontSize, calendarTheme->GetEntryFontSize());
307     }
308     ACE_UPDATE_LAYOUT_PROPERTY(
309         CalendarPickerLayoutProperty, Color, textStyle.textColor.value_or(calendarTheme->GetEntryFontColor()));
310     ACE_UPDATE_LAYOUT_PROPERTY(CalendarPickerLayoutProperty, Weight, textStyle.fontWeight.value_or(FontWeight::NORMAL));
311 }
312 
SetOnChange(SelectedChangeEvent && onChange)313 void CalendarPickerModelNG::SetOnChange(SelectedChangeEvent&& onChange)
314 {
315     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
316     CHECK_NULL_VOID(frameNode);
317     auto eventHub = frameNode->GetEventHub<CalendarPickerEventHub>();
318     CHECK_NULL_VOID(eventHub);
319     eventHub->SetOnChangeEvent(std::move(onChange));
320 }
321 
SetChangeEvent(SelectedChangeEvent && onChange)322 void CalendarPickerModelNG::SetChangeEvent(SelectedChangeEvent&& onChange)
323 {
324     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
325     CHECK_NULL_VOID(frameNode);
326     auto eventHub = frameNode->GetEventHub<CalendarPickerEventHub>();
327     CHECK_NULL_VOID(eventHub);
328     eventHub->SetChangeEvent(std::move(onChange));
329 }
330 
SetPadding(const PaddingProperty & padding)331 void CalendarPickerModelNG::SetPadding(const PaddingProperty& padding)
332 {
333     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
334     CHECK_NULL_VOID(frameNode);
335     auto pickerPattern = frameNode->GetPattern<CalendarPickerPattern>();
336     CHECK_NULL_VOID(pickerPattern);
337     if (!pickerPattern->HasContentNode()) {
338         return;
339     }
340     auto contentNode = AceType::DynamicCast<FrameNode>(frameNode->GetFirstChild());
341     CHECK_NULL_VOID(contentNode);
342     auto linearLayoutProperty = contentNode->GetLayoutProperty();
343     CHECK_NULL_VOID(linearLayoutProperty);
344     linearLayoutProperty->UpdatePadding(padding);
345 }
346 
SetTextStyle(FrameNode * frameNode,const PickerTextStyle & textStyle)347 void CalendarPickerModelNG::SetTextStyle(FrameNode* frameNode, const PickerTextStyle& textStyle)
348 {
349     auto pipeline = PipelineBase::GetCurrentContextSafely();
350     CHECK_NULL_VOID(pipeline);
351     RefPtr<CalendarTheme> calendarTheme = pipeline->GetTheme<CalendarTheme>();
352     CHECK_NULL_VOID(calendarTheme);
353     if (textStyle.fontSize.has_value() && textStyle.fontSize->IsValid()) {
354         ACE_UPDATE_NODE_LAYOUT_PROPERTY(CalendarPickerLayoutProperty, FontSize, textStyle.fontSize.value(), frameNode);
355     } else {
356         ACE_UPDATE_NODE_LAYOUT_PROPERTY(
357             CalendarPickerLayoutProperty, FontSize, calendarTheme->GetEntryFontSize(), frameNode);
358     }
359     ACE_UPDATE_NODE_LAYOUT_PROPERTY(CalendarPickerLayoutProperty, Color,
360         textStyle.textColor.value_or(calendarTheme->GetEntryFontColor()), frameNode);
361     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
362         CalendarPickerLayoutProperty, Weight, textStyle.fontWeight.value_or(FontWeight::NORMAL), frameNode);
363 }
364 
ClearBorderColor()365 void CalendarPickerModelNG::ClearBorderColor()
366 {
367     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
368     CHECK_NULL_VOID(frameNode);
369     auto pipelineContext = frameNode->GetContext();
370     CHECK_NULL_VOID(pipelineContext);
371     RefPtr<CalendarTheme> theme = pipelineContext->GetTheme<CalendarTheme>();
372     CHECK_NULL_VOID(theme);
373     BorderColorProperty borderColor;
374     borderColor.SetColor(theme->GetEntryBorderColor());
375     frameNode->GetRenderContext()->UpdateBorderColor(borderColor);
376 }
377 
ClearBorderRadius()378 void CalendarPickerModelNG::ClearBorderRadius()
379 {
380     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
381     CHECK_NULL_VOID(frameNode);
382     auto pipelineContext = frameNode->GetContext();
383     CHECK_NULL_VOID(pipelineContext);
384     RefPtr<CalendarTheme> theme = pipelineContext->GetTheme<CalendarTheme>();
385     CHECK_NULL_VOID(theme);
386     BorderRadiusProperty borderRadius;
387     borderRadius.SetRadius(theme->GetEntryBorderRadius());
388     frameNode->GetRenderContext()->UpdateBorderRadius(borderRadius);
389 }
390 
ClearHeight()391 void CalendarPickerModelNG::ClearHeight()
392 {
393     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
394     CHECK_NULL_VOID(frameNode);
395     auto pipelineContext = frameNode->GetContext();
396     CHECK_NULL_VOID(pipelineContext);
397     RefPtr<CalendarTheme> theme = pipelineContext->GetTheme<CalendarTheme>();
398     CHECK_NULL_VOID(theme);
399     frameNode->GetLayoutProperty()->UpdateUserDefinedIdealSize(
400         CalcSize(std::nullopt, CalcLength(theme->GetEntryHeight())));
401 }
402 
ClearBorder()403 void CalendarPickerModelNG::ClearBorder()
404 {
405     ClearBorderWidth();
406     ClearBorderRadius();
407     ClearBorderColor();
408 }
409 
ClearBorderWidth()410 void CalendarPickerModelNG::ClearBorderWidth()
411 {
412     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
413     CHECK_NULL_VOID(frameNode);
414     auto pipelineContext = frameNode->GetContext();
415     CHECK_NULL_VOID(pipelineContext);
416     RefPtr<CalendarTheme> theme = pipelineContext->GetTheme<CalendarTheme>();
417     CHECK_NULL_VOID(theme);
418     BorderWidthProperty borderWidth;
419     borderWidth.SetBorderWidth(theme->GetEntryBorderWidth());
420     frameNode->GetLayoutProperty()->UpdateBorderWidth(borderWidth);
421 }
422 
ClearPadding()423 void CalendarPickerModelNG::ClearPadding()
424 {
425     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
426     CHECK_NULL_VOID(frameNode);
427     auto pickerPattern = frameNode->GetPattern<CalendarPickerPattern>();
428     CHECK_NULL_VOID(pickerPattern);
429     if (!pickerPattern->HasContentNode()) {
430         return;
431     }
432     auto contentNode = AceType::DynamicCast<FrameNode>(frameNode->GetFirstChild());
433     CHECK_NULL_VOID(contentNode);
434     auto linearLayoutProperty = contentNode->GetLayoutProperty();
435     CHECK_NULL_VOID(linearLayoutProperty);
436     auto pipelineContext = frameNode->GetContext();
437     CHECK_NULL_VOID(pipelineContext);
438     RefPtr<CalendarTheme> theme = pipelineContext->GetTheme<CalendarTheme>();
439     CHECK_NULL_VOID(theme);
440     PaddingProperty padding;
441     padding.top = CalcLength(theme->GetEntryDateTopBottomMargin());
442     padding.left = CalcLength(theme->GetEntryDateLeftRightMargin());
443     padding.right = CalcLength(theme->GetEntryDateLeftRightMargin());
444     padding.bottom = CalcLength(theme->GetEntryDateTopBottomMargin());
445     linearLayoutProperty->UpdatePadding(padding);
446 }
447 
GetCalendarTheme()448 RefPtr<CalendarTheme> GetCalendarTheme()
449 {
450     auto pipeline = PipelineBase::GetCurrentContextSafely();
451     CHECK_NULL_RETURN(pipeline, nullptr);
452     return pipeline->GetTheme<CalendarTheme>();
453 }
454 
GetTextStyle(FrameNode * frameNode)455 PickerTextStyle CalendarPickerModelNG::GetTextStyle(FrameNode* frameNode)
456 {
457     PickerTextStyle textStyle;
458     CHECK_NULL_RETURN(frameNode, textStyle);
459     auto calendarTheme = GetCalendarTheme();
460     CHECK_NULL_RETURN(calendarTheme, textStyle);
461     auto calendarPickerProperty = frameNode->GetLayoutProperty<CalendarPickerLayoutProperty>();
462     CHECK_NULL_RETURN(calendarPickerProperty, textStyle);
463     textStyle.textColor =
464         calendarPickerProperty->HasColor() ? calendarPickerProperty->GetColor() : calendarTheme->GetEntryFontColor();
465     textStyle.fontSize = calendarPickerProperty->HasFontSize() ? calendarPickerProperty->GetFontSize()
466                                                                : calendarTheme->GetEntryFontSize();
467     textStyle.fontWeight =
468         calendarPickerProperty->HasWeight() ? calendarPickerProperty->GetWeight() : FontWeight::NORMAL;
469     return textStyle;
470 }
471 
GetEdgeAlignType(FrameNode * frameNode)472 CalendarEdgeAlign CalendarPickerModelNG::GetEdgeAlignType(FrameNode* frameNode)
473 {
474     CHECK_NULL_RETURN(frameNode, CalendarEdgeAlign::EDGE_ALIGN_END);
475     auto layoutProperty = frameNode->GetLayoutProperty<CalendarPickerLayoutProperty>();
476     CHECK_NULL_RETURN(layoutProperty, CalendarEdgeAlign::EDGE_ALIGN_END);
477     return layoutProperty->GetDialogAlignType().value_or(CalendarEdgeAlign::EDGE_ALIGN_END);
478 }
479 
GetEdgeOffset(FrameNode * frameNode)480 DimensionOffset CalendarPickerModelNG::GetEdgeOffset(FrameNode* frameNode)
481 {
482     DimensionOffset offsetDimension(0.0_vp, 0.0_vp);
483     CHECK_NULL_RETURN(frameNode, offsetDimension);
484     auto layoutProperty = frameNode->GetLayoutProperty<CalendarPickerLayoutProperty>();
485     CHECK_NULL_RETURN(layoutProperty, offsetDimension);
486     return layoutProperty->GetDialogOffset().value_or(offsetDimension);
487 }
488 
SetEdgeAlign(FrameNode * frameNode,const CalendarEdgeAlign & alignType,const DimensionOffset & offset)489 void CalendarPickerModelNG::SetEdgeAlign(
490     FrameNode* frameNode, const CalendarEdgeAlign& alignType, const DimensionOffset& offset)
491 {
492     auto layoutProperty = frameNode->GetLayoutProperty<CalendarPickerLayoutProperty>();
493     CHECK_NULL_VOID(layoutProperty);
494     auto pickerPattern = frameNode->GetPattern<CalendarPickerPattern>();
495     CHECK_NULL_VOID(pickerPattern);
496     pickerPattern->SetCalendarEdgeAlign(alignType);
497     pickerPattern->SetCalendarDialogOffset(offset);
498 
499     ACE_UPDATE_NODE_LAYOUT_PROPERTY(CalendarPickerLayoutProperty, DialogAlignType, alignType, frameNode);
500     ACE_UPDATE_NODE_LAYOUT_PROPERTY(CalendarPickerLayoutProperty, DialogOffset, offset, frameNode);
501 }
502 
SetPadding(FrameNode * frameNode,const PaddingProperty & padding)503 void CalendarPickerModelNG::SetPadding(FrameNode* frameNode, const PaddingProperty& padding)
504 {
505     CHECK_NULL_VOID(frameNode);
506     auto pickerPattern = frameNode->GetPattern<CalendarPickerPattern>();
507     CHECK_NULL_VOID(pickerPattern);
508     if (!pickerPattern->HasContentNode()) {
509         return;
510     }
511     auto contentNode = AceType::DynamicCast<FrameNode>(frameNode->GetFirstChild());
512     CHECK_NULL_VOID(contentNode);
513     auto linearLayoutProperty = contentNode->GetLayoutProperty();
514     CHECK_NULL_VOID(linearLayoutProperty);
515     linearLayoutProperty->UpdatePadding(padding);
516 }
517 
ClearPadding(FrameNode * frameNode)518 void CalendarPickerModelNG::ClearPadding(FrameNode* frameNode)
519 {
520     CHECK_NULL_VOID(frameNode);
521     auto pickerPattern = frameNode->GetPattern<CalendarPickerPattern>();
522     CHECK_NULL_VOID(pickerPattern);
523     if (!pickerPattern->HasContentNode()) {
524         return;
525     }
526     auto contentNode = AceType::DynamicCast<FrameNode>(frameNode->GetFirstChild());
527     CHECK_NULL_VOID(contentNode);
528     auto linearLayoutProperty = contentNode->GetLayoutProperty();
529     CHECK_NULL_VOID(linearLayoutProperty);
530     auto pipelineContext = frameNode->GetContext();
531     CHECK_NULL_VOID(pipelineContext);
532     RefPtr<CalendarTheme> theme = pipelineContext->GetTheme<CalendarTheme>();
533     CHECK_NULL_VOID(theme);
534     PaddingProperty padding;
535     padding.top = CalcLength(theme->GetEntryDateTopBottomMargin());
536     padding.left = CalcLength(theme->GetEntryDateLeftRightMargin());
537     padding.right = CalcLength(theme->GetEntryDateLeftRightMargin());
538     padding.bottom = CalcLength(theme->GetEntryDateTopBottomMargin());
539     linearLayoutProperty->UpdatePadding(padding);
540 }
541 
ClearHeight(FrameNode * frameNode)542 void CalendarPickerModelNG::ClearHeight(FrameNode* frameNode)
543 {
544     CHECK_NULL_VOID(frameNode);
545     auto pipelineContext = frameNode->GetContext();
546     CHECK_NULL_VOID(pipelineContext);
547     RefPtr<CalendarTheme> theme = pipelineContext->GetTheme<CalendarTheme>();
548     CHECK_NULL_VOID(theme);
549     ViewAbstract::SetHeight(frameNode, CalcLength(theme->GetEntryHeight()));
550 }
551 
ClearBorderColor(FrameNode * frameNode)552 void CalendarPickerModelNG::ClearBorderColor(FrameNode* frameNode)
553 {
554     CHECK_NULL_VOID(frameNode);
555     auto pipelineContext = frameNode->GetContext();
556     CHECK_NULL_VOID(pipelineContext);
557     RefPtr<CalendarTheme> theme = pipelineContext->GetTheme<CalendarTheme>();
558     CHECK_NULL_VOID(theme);
559     BorderColorProperty borderColor;
560     borderColor.SetColor(theme->GetEntryBorderColor());
561     frameNode->GetRenderContext()->UpdateBorderColor(borderColor);
562 }
563 
ClearBorderRadius(FrameNode * frameNode)564 void CalendarPickerModelNG::ClearBorderRadius(FrameNode* frameNode)
565 {
566     CHECK_NULL_VOID(frameNode);
567     auto pipelineContext = frameNode->GetContext();
568     CHECK_NULL_VOID(pipelineContext);
569     RefPtr<CalendarTheme> theme = pipelineContext->GetTheme<CalendarTheme>();
570     CHECK_NULL_VOID(theme);
571     BorderRadiusProperty borderRadius;
572     borderRadius.SetRadius(theme->GetEntryBorderRadius());
573     frameNode->GetRenderContext()->UpdateBorderRadius(borderRadius);
574 }
575 
ClearBorderWidth(FrameNode * frameNode)576 void CalendarPickerModelNG::ClearBorderWidth(FrameNode* frameNode)
577 {
578     CHECK_NULL_VOID(frameNode);
579     auto pipelineContext = frameNode->GetContext();
580     CHECK_NULL_VOID(pipelineContext);
581     RefPtr<CalendarTheme> theme = pipelineContext->GetTheme<CalendarTheme>();
582     CHECK_NULL_VOID(theme);
583     BorderWidthProperty borderWidth;
584     borderWidth.SetBorderWidth(theme->GetEntryBorderWidth());
585     frameNode->GetLayoutProperty()->UpdateBorderWidth(borderWidth);
586 }
587 
SetHintRadiusWithNode(FrameNode * frameNode,Dimension & radius)588 void CalendarPickerModelNG::SetHintRadiusWithNode(FrameNode* frameNode, Dimension& radius)
589 {
590     CHECK_NULL_VOID(frameNode);
591     auto pickerPattern = frameNode->GetPattern<CalendarPickerPattern>();
592     CHECK_NULL_VOID(pickerPattern);
593     auto calendarDate = pickerPattern->GetCalendarData();
594     calendarDate.dayRadius = radius;
595     pickerPattern->SetCalendarData(calendarDate);
596 }
597 
GetStartDateWithNode(FrameNode * frameNode)598 PickerDate CalendarPickerModelNG::GetStartDateWithNode(FrameNode* frameNode)
599 {
600     PickerDate startDate;
601     CHECK_NULL_RETURN(frameNode, startDate);
602     auto pickerPattern = frameNode->GetPattern<CalendarPickerPattern>();
603     CHECK_NULL_RETURN(pickerPattern, startDate);
604     return pickerPattern->GetCalendarData().startDate;
605 }
606 
GetEndDateWithNode(FrameNode * frameNode)607 PickerDate CalendarPickerModelNG::GetEndDateWithNode(FrameNode* frameNode)
608 {
609     PickerDate endDate;
610     CHECK_NULL_RETURN(frameNode, endDate);
611     auto pickerPattern = frameNode->GetPattern<CalendarPickerPattern>();
612     CHECK_NULL_RETURN(pickerPattern, endDate);
613     return pickerPattern->GetCalendarData().endDate;
614 }
615 
SetStartDateWithNode(FrameNode * frameNode,uint32_t year,uint32_t month,uint32_t day)616 void CalendarPickerModelNG::SetStartDateWithNode(FrameNode* frameNode, uint32_t year, uint32_t month, uint32_t day)
617 {
618     CHECK_NULL_VOID(frameNode);
619     auto pickerPattern = frameNode->GetPattern<CalendarPickerPattern>();
620     CHECK_NULL_VOID(pickerPattern);
621     auto calendarDate = pickerPattern->GetCalendarData();
622     PickerDate defaultDate;
623     if (year > 0 && month > 0 && month <= MAX_MONTH && day > 0 && day <= PickerDate::GetMaxDay(year, month)) {
624         calendarDate.startDate.SetYear(year);
625         calendarDate.startDate.SetMonth(month);
626         calendarDate.startDate.SetDay(day);
627     } else {
628         calendarDate.startDate = defaultDate;
629     }
630     if (calendarDate.endDate.ToDays() > 0 && calendarDate.startDate.ToDays() > calendarDate.endDate.ToDays()) {
631         calendarDate.startDate = defaultDate;
632         calendarDate.endDate = defaultDate;
633         calendarDate.selectedDate = PickerDate::Current();
634     }
635     calendarDate.selectedDate =
636         PickerDate::AdjustDateToRange(calendarDate.selectedDate, calendarDate.startDate, calendarDate.endDate);
637     UpdateSelectedDateContent(frameNode, calendarDate.selectedDate);
638     pickerPattern->SetCalendarData(calendarDate);
639 }
640 
SetEndDateWithNode(FrameNode * frameNode,uint32_t year,uint32_t month,uint32_t day)641 void CalendarPickerModelNG::SetEndDateWithNode(FrameNode* frameNode, uint32_t year, uint32_t month, uint32_t day)
642 {
643     CHECK_NULL_VOID(frameNode);
644     auto pickerPattern = frameNode->GetPattern<CalendarPickerPattern>();
645     CHECK_NULL_VOID(pickerPattern);
646     auto calendarDate = pickerPattern->GetCalendarData();
647     PickerDate defaultDate;
648     if (year > 0 && month > 0 && month <= MAX_MONTH && day > 0 && day <= PickerDate::GetMaxDay(year, month)) {
649         calendarDate.endDate.SetYear(year);
650         calendarDate.endDate.SetMonth(month);
651         calendarDate.endDate.SetDay(day);
652     } else {
653         calendarDate.endDate = defaultDate;
654     }
655     if (calendarDate.endDate.ToDays() > 0 && calendarDate.startDate.ToDays() > calendarDate.endDate.ToDays()) {
656         calendarDate.startDate = defaultDate;
657         calendarDate.endDate = defaultDate;
658         calendarDate.selectedDate = PickerDate::Current();
659     }
660     calendarDate.selectedDate =
661         PickerDate::AdjustDateToRange(calendarDate.selectedDate, calendarDate.startDate, calendarDate.endDate);
662     UpdateSelectedDateContent(frameNode, calendarDate.selectedDate);
663     pickerPattern->SetCalendarData(calendarDate);
664 }
665 
UpdateSelectedDateContent(FrameNode * frameNode,const PickerDate & selectedDate)666 void CalendarPickerModelNG::UpdateSelectedDateContent(FrameNode* frameNode, const PickerDate& selectedDate)
667 {
668     CHECK_NULL_VOID(frameNode);
669     auto year = selectedDate.GetYear();
670     auto month = selectedDate.GetMonth();
671     auto day = selectedDate.GetDay();
672     if (year > 0) {
673         auto yearNode = CalendarPickerModelNG::GetYearNode(frameNode);
674         if (yearNode) {
675             auto textLayoutProperty = yearNode->GetLayoutProperty<TextLayoutProperty>();
676             if (textLayoutProperty) {
677                 auto selectedYearStr = AddLeadingZeroToYear(year);
678                 textLayoutProperty->UpdateContent(selectedYearStr);
679                 yearNode->MarkModifyDone();
680                 yearNode->MarkDirtyNode();
681             }
682         }
683     }
684     if (month > 0) {
685         auto monthNode = CalendarPickerModelNG::GetMonthNode(frameNode);
686         if (monthNode) {
687             auto textLayoutProperty = monthNode->GetLayoutProperty<TextLayoutProperty>();
688             if (textLayoutProperty) {
689                 auto selectedMonthStr = (month < ONE_DIGIT_BOUNDARY ? "0" : "") + std::to_string(month);
690                 textLayoutProperty->UpdateContent(selectedMonthStr);
691                 monthNode->MarkModifyDone();
692                 monthNode->MarkDirtyNode();
693             }
694         }
695     }
696     if (day > 0) {
697         auto dayNode = CalendarPickerModelNG::GetDayNode(frameNode);
698         if (dayNode) {
699             auto textLayoutProperty = dayNode->GetLayoutProperty<TextLayoutProperty>();
700             if (textLayoutProperty) {
701                 auto selectedDayStr = (day < ONE_DIGIT_BOUNDARY ? "0" : "") + std::to_string(day);
702                 textLayoutProperty->UpdateContent(selectedDayStr);
703                 dayNode->MarkModifyDone();
704                 dayNode->MarkDirtyNode();
705             }
706         }
707     }
708 }
709 
SetSelectDateWithNode(FrameNode * frameNode,uint32_t year,uint32_t month,uint32_t day)710 void CalendarPickerModelNG::SetSelectDateWithNode(FrameNode* frameNode, uint32_t year, uint32_t month, uint32_t day)
711 {
712     CHECK_NULL_VOID(frameNode);
713     auto pickerPattern = frameNode->GetPattern<CalendarPickerPattern>();
714     CHECK_NULL_VOID(pickerPattern);
715     auto calendarDate = pickerPattern->GetCalendarData();
716     if (year > 0 && month > 0 && month <= MAX_MONTH && day > 0 && day <= PickerDate::GetMaxDay(year, month)) {
717         calendarDate.selectedDate.SetYear(year);
718         calendarDate.selectedDate.SetMonth(month);
719         calendarDate.selectedDate.SetDay(day);
720     }
721     calendarDate.selectedDate =
722         PickerDate::AdjustDateToRange(calendarDate.selectedDate, calendarDate.startDate, calendarDate.endDate);
723     UpdateSelectedDateContent(frameNode, calendarDate.selectedDate);
724     pickerPattern->SetCalendarData(calendarDate);
725 }
726 
GetYearNode(FrameNode * calendarPickerNode)727 RefPtr<FrameNode> CalendarPickerModelNG::GetYearNode(FrameNode* calendarPickerNode)
728 {
729     CHECK_NULL_RETURN(calendarPickerNode, nullptr);
730     auto feedbackNode = calendarPickerNode->GetFirstChild();
731     CHECK_NULL_RETURN(feedbackNode, nullptr);
732     return AceType::DynamicCast<FrameNode>(feedbackNode->GetChildAtIndex(yearNodeIndex_));
733 }
734 
GetMonthNode(FrameNode * calendarPickerNode)735 RefPtr<FrameNode> CalendarPickerModelNG::GetMonthNode(FrameNode* calendarPickerNode)
736 {
737     CHECK_NULL_RETURN(calendarPickerNode, nullptr);
738     auto feedbackNode = calendarPickerNode->GetFirstChild();
739     CHECK_NULL_RETURN(feedbackNode, nullptr);
740     return AceType::DynamicCast<FrameNode>(feedbackNode->GetChildAtIndex(monthNodeIndex_));
741 }
742 
GetDayNode(FrameNode * calendarPickerNode)743 RefPtr<FrameNode> CalendarPickerModelNG::GetDayNode(FrameNode* calendarPickerNode)
744 {
745     CHECK_NULL_RETURN(calendarPickerNode, nullptr);
746     auto feedbackNode = calendarPickerNode->GetFirstChild();
747     CHECK_NULL_RETURN(feedbackNode, nullptr);
748     return AceType::DynamicCast<FrameNode>(feedbackNode->GetChildAtIndex(dayNodeIndex_));
749 }
750 
GetHintRadius(FrameNode * frameNode)751 Dimension CalendarPickerModelNG::GetHintRadius(FrameNode* frameNode)
752 {
753     Dimension defaultRadius(DEFAULT_HINT_RADIUS);
754     CHECK_NULL_RETURN(frameNode, defaultRadius);
755     auto pickerPattern = frameNode->GetPattern<CalendarPickerPattern>();
756     CHECK_NULL_RETURN(pickerPattern, defaultRadius);
757     auto calendarDate = pickerPattern->GetCalendarData();
758     return calendarDate.dayRadius.value_or(defaultRadius);
759 }
760 
GetSelectDateWithNode(FrameNode * frameNode)761 PickerDate CalendarPickerModelNG::GetSelectDateWithNode(FrameNode* frameNode)
762 {
763     auto defaultSelectedDate = PickerDate::Current();
764     CHECK_NULL_RETURN(frameNode, defaultSelectedDate);
765     auto pickerPattern = frameNode->GetPattern<CalendarPickerPattern>();
766     CHECK_NULL_RETURN(pickerPattern, defaultSelectedDate);
767     return pickerPattern->GetCalendarData().selectedDate;
768 }
769 
SetOnChangeWithNode(FrameNode * frameNode,SelectedChangeEvent && onChange)770 void CalendarPickerModelNG::SetOnChangeWithNode(FrameNode* frameNode, SelectedChangeEvent&& onChange)
771 {
772     CHECK_NULL_VOID(frameNode);
773     auto eventHub = frameNode->GetEventHub<CalendarPickerEventHub>();
774     CHECK_NULL_VOID(eventHub);
775     eventHub->SetOnChangeEvent(std::move(onChange));
776 }
777 
GetDateNodeOrder(const CalendarSettingData & settingData)778 std::map<std::size_t, std::string> CalendarPickerModelNG::GetDateNodeOrder(const CalendarSettingData& settingData)
779 {
780     PickerDate date =
781         PickerDate::AdjustDateToRange(settingData.selectedDate, settingData.startDate, settingData.endDate);
782     std::vector<std::string> outOrder;
783     bool result = Localization::GetInstance()->GetDateOrder(outOrder);
784     std::map<std::size_t, std::string> order;
785     if (!result || outOrder.size() < DATE_NODE_COUNT) {
786         yearNodeIndex_ = YEAR_NODE_INDEX;
787         monthNodeIndex_ = MONTH_NODE_INDEX;
788         dayNodeIndex_ = DAY_NODE_INDEX;
789         auto num = 0;
790         order[num++] = AddLeadingZeroToYear(date.GetYear());
791         order[num++] = (date.GetMonth() < ONE_DIGIT_BOUNDARY ? "0" : "") + std::to_string(date.GetMonth());
792         order[num] = (date.GetDay() < ONE_DIGIT_BOUNDARY ? "0" : "") + std::to_string(date.GetDay());
793     } else {
794         size_t index = 0;
795         for (size_t i = 0; i < outOrder.size(); ++i) {
796             if (outOrder[i] == "year") {
797                 yearNodeIndex_ = static_cast<int32_t>(i + index);
798                 order[i] = AddLeadingZeroToYear(date.GetYear());
799             }
800             if (outOrder[i] == "month") {
801                 monthNodeIndex_ = static_cast<int32_t>(i + index);
802                 order[i] = (date.GetMonth() < ONE_DIGIT_BOUNDARY ? "0" : "") + std::to_string(date.GetMonth());
803             }
804             if (outOrder[i] == "day") {
805                 dayNodeIndex_ = static_cast<int32_t>(i + index);
806                 order[i] = (date.GetDay() < ONE_DIGIT_BOUNDARY ? "0" : "") + std::to_string(date.GetDay());
807             }
808             index++;
809         }
810     }
811 
812     return order;
813 }
814 
AddLeadingZeroToYear(uint32_t year)815 std::string CalendarPickerModelNG::AddLeadingZeroToYear(uint32_t year)
816 {
817     std::string yearStr = std::string(YEAR_LENGTH - std::to_string(year).length(), '0');
818     yearStr += std::to_string(year);
819     return yearStr;
820 }
821 
SetMarkToday(bool isMarkToday)822 void CalendarPickerModelNG::SetMarkToday(bool isMarkToday)
823 {
824     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
825     CHECK_NULL_VOID(frameNode);
826     auto pickerPattern = frameNode->GetPattern<CalendarPickerPattern>();
827     CHECK_NULL_VOID(pickerPattern);
828     pickerPattern->SetMarkToday(isMarkToday);
829 }
830 
SetMarkToday(FrameNode * frameNode,bool isMarkToday)831 void CalendarPickerModelNG::SetMarkToday(FrameNode* frameNode, bool isMarkToday)
832 {
833     CHECK_NULL_VOID(frameNode);
834     auto pickerPattern = frameNode->GetPattern<CalendarPickerPattern>();
835     CHECK_NULL_VOID(pickerPattern);
836     pickerPattern->SetMarkToday(isMarkToday);
837 }
838 
GetMarkToday(FrameNode * frameNode)839 bool CalendarPickerModelNG::GetMarkToday(FrameNode* frameNode)
840 {
841     CHECK_NULL_RETURN(frameNode, DEFAULT_MARK_TODAY);
842     auto pickerPattern = frameNode->GetPattern<CalendarPickerPattern>();
843     CHECK_NULL_RETURN(pickerPattern, DEFAULT_MARK_TODAY);
844     return pickerPattern->GetMarkToday();
845 }
846 
SetDisabledDateRange(FrameNode * frameNode,const std::vector<std::pair<PickerDate,PickerDate>> & disabledDateRange)847 void CalendarPickerModelNG::SetDisabledDateRange(
848     FrameNode* frameNode, const std::vector<std::pair<PickerDate, PickerDate>>& disabledDateRange)
849 {
850     CHECK_NULL_VOID(frameNode);
851     auto pickerPattern = frameNode->GetPattern<CalendarPickerPattern>();
852     CHECK_NULL_VOID(pickerPattern);
853     pickerPattern->SetDisabledDateRange(disabledDateRange);
854 }
855 
GetDisabledDateRange(FrameNode * frameNode)856 std::string CalendarPickerModelNG::GetDisabledDateRange(FrameNode* frameNode)
857 {
858     CHECK_NULL_RETURN(frameNode, "");
859     auto pickerPattern = frameNode->GetPattern<CalendarPickerPattern>();
860     CHECK_NULL_RETURN(pickerPattern, "");
861     return pickerPattern->GetDisabledDateRange();
862 }
863 } // namespace OHOS::Ace::NG
864