1 /* 2 * Copyright (c) 2023-2024 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_CALENDAR_PICKER_CALENDAR_DIALOG_VIEW_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_CALENDAR_PICKER_CALENDAR_DIALOG_VIEW_H 18 19 #include "base/utils/macros.h" 20 #include "core/components/calendar/calendar_data_adapter.h" 21 #include "core/components/common/layout/constants.h" 22 #include "core/components/picker/picker_base_component.h" 23 #include "core/components_ng/pattern/calendar/calendar_event_hub.h" 24 #include "core/components_ng/pattern/calendar/calendar_model_ng.h" 25 #include "core/components_ng/pattern/calendar_picker/calendar_dialog_pattern.h" 26 #include "core/components_ng/pattern/calendar_picker/calendar_type_define.h" 27 28 namespace OHOS::Ace::NG { 29 class ButtonLayoutProperty; 30 class TextLayoutProperty; 31 class PipelineContext; 32 33 class ACE_EXPORT CalendarDialogView { 34 public: 35 static RefPtr<FrameNode> Show(const DialogProperties& dialogProperties, const CalendarSettingData& settingData, 36 const std::vector<ButtonInfo>& buttonInfos, const std::map<std::string, NG::DialogEvent>& dialogEvent, 37 const std::map<std::string, NG::DialogGestureEvent>& dialogCancelEvent); 38 static void UpdateIdealSize(const RefPtr<CalendarTheme>& calendarTheme, 39 const RefPtr<LinearLayoutProperty>& layoutProps, const RefPtr<LayoutProperty>& calendarLayoutProperty, 40 const RefPtr<FrameNode>& calendarNode); 41 static void UpdatePaintProperties(const RefPtr<FrameNode>& monthFrameNode, const CalendarSettingData& settingData); 42 static void UpdateButtons( 43 const RefPtr<FrameNode>& buttonNode, size_t buttonIndex, std::vector<ButtonInfo>& buttonInfos); SetPreviousOrientation()44 static void SetPreviousOrientation() 45 { 46 previousOrientation_ = SystemProperties::GetDeviceOrientation(); 47 } 48 49 static bool CheckOrientationChange(); 50 GetPreviousOrientation()51 static DeviceOrientation GetPreviousOrientation() 52 { 53 return previousOrientation_; 54 } 55 56 static bool ReportChangeEvent(int32_t nodeId, const std::string& compName, 57 const std::string& eventName, const PickerDate& pickerDate); 58 static bool CanReportChangeEvent(PickerDate& pickerDate, const PickerDate& newPickerDate); 59 static bool GetReportChangeEventDate(PickerDate& pickerDate, const std::string& eventData); 60 61 private: 62 static RefPtr<FrameNode> CreateTitleNode(const RefPtr<FrameNode>& calendarNode, 63 const RefPtr<FrameNode>& calendarDialogNode); 64 static RefPtr<FrameNode> CreateWeekNode(const RefPtr<FrameNode>& calendarNode); 65 static RefPtr<FrameNode> CreateScrollNode(); 66 static RefPtr<FrameNode> CreateTitleImageNode( 67 const RefPtr<FrameNode>& calendarNode, const InternalResource::ResourceId& resourceId); 68 static RefPtr<FrameNode> CreateCalendarNode(const RefPtr<FrameNode>& calendarDialogNode, 69 const CalendarSettingData& settingData, const std::map<std::string, NG::DialogEvent>& dialogEvent); 70 static RefPtr<FrameNode> CreateCalendarSwiperNode(); 71 static RefPtr<FrameNode> CreateCalendarMonthNode(int32_t calendarNodeId, 72 const CalendarSettingData& settingData, const DialogEvent& changeEvent); 73 static void UpdateCalendarMonthData(const RefPtr<FrameNode>& calendarDialogNode, 74 const RefPtr<FrameNode>& calendarNode, const CalendarMonth& currentMonth); 75 static void SetDialogChange(const RefPtr<FrameNode>& frameNode, DialogEvent&& onChange); 76 static void SetDialogAcceptEvent(const RefPtr<FrameNode>& frameNode, DialogEvent&& onChange); 77 static RefPtr<FrameNode> CreateButtonNode(bool isConfirm, const std::vector<ButtonInfo>& buttonInfos); 78 static RefPtr<FrameNode> CreateConfirmNode( 79 const RefPtr<FrameNode>& calendarNode, DialogEvent& acceptEvent, const std::vector<ButtonInfo>& buttonInfos); 80 static RefPtr<FrameNode> CreateCancelNode( 81 const NG::DialogGestureEvent& cancelEvent, const std::vector<ButtonInfo>& buttonInfos); 82 static void UpdateButtonStyles(const std::vector<ButtonInfo>& buttonInfos, size_t index, 83 const RefPtr<ButtonLayoutProperty>& buttonLayoutProperty, const RefPtr<RenderContext>& buttonRenderContext); 84 static RefPtr<FrameNode> CreateDividerNode(); 85 static RefPtr<FrameNode> CreateOptionsNode(const RefPtr<FrameNode>& dialogNode, const RefPtr<FrameNode>& dateNode, 86 const std::map<std::string, NG::DialogEvent>& dialogEvent, 87 const std::map<std::string, NG::DialogGestureEvent>& dialogCancelEvent, 88 const std::vector<ButtonInfo>& buttonInfos); 89 static void SetCalendarPaintProperties(const CalendarSettingData& settingData); 90 static void InitOnRequestDataEvent( 91 const RefPtr<FrameNode>& calendarDialogNode, const RefPtr<FrameNode>& calendarNode); 92 static void OnSelectedChangeEvent(int32_t calendarNodeId, const std::string& callbackInfo, 93 const DialogEvent& onChange, const CalendarSettingData& settingData); 94 static void UpdateBackgroundStyle(const RefPtr<RenderContext>& renderContext, 95 const DialogProperties& dialogProperties, const RefPtr<CalendarTheme>& calendarTheme, 96 const RefPtr<FrameNode>& dialogNode); 97 static void UpdateButtonStyleAndRole(const std::vector<ButtonInfo>& buttonInfos, size_t index, 98 const RefPtr<ButtonLayoutProperty>& buttonLayoutProperty, const RefPtr<RenderContext>& buttonRenderContext, 99 const RefPtr<ButtonTheme>& buttonTheme); 100 static void DisableResetOptionButtonColor( 101 const RefPtr<CalendarDialogPattern>& calendarDialogPattern, const std::vector<ButtonInfo>& buttonInfos); 102 static void UpdateButtonDefaultFocus(const std::vector<ButtonInfo>& buttonInfos, 103 const RefPtr<FrameNode>& buttonNode, bool isConfirm); 104 static void UpdateDialogDefaultFocus(const RefPtr<FrameNode>& contentRow, 105 const RefPtr<FrameNode>& contentColumn); 106 static void UpdateDefaultFocusByButtonInfo(const RefPtr<FrameNode>& optionsNode, 107 const RefPtr<FrameNode>& accept, const RefPtr<FrameNode>& cancel); 108 static void UpdateButtonLayoutProperty(const RefPtr<FrameNode>& buttonNode, bool isConfirm, 109 const std::vector<ButtonInfo>& buttonInfos, const RefPtr<PipelineContext>& pipeline); 110 static void UpdateOptionLayoutProps( 111 const RefPtr<FrameNode>& contentRow, const RefPtr<PipelineContext>& pipelineContext); 112 static void OperationsToPattern(const RefPtr<FrameNode>& frameNode, const CalendarSettingData& settingData, 113 const DialogProperties& dialogProperties, const std::vector<ButtonInfo>& buttonInfos); 114 static void CreateChildNode(const RefPtr<FrameNode>& contentColumn, 115 const RefPtr<FrameNode>& dialogNode, const DialogProperties& dialogProperties); 116 static void InitCalendarProperty(const RefPtr<FrameNode>& calendarNode); 117 static void SetCalendarIdealSize( 118 const RefPtr<CalendarTheme>& theme, const RefPtr<LayoutProperty>& calendarLayoutProperty, 119 const Dimension& weekHeight); 120 static void SetTitleIdealSize(const RefPtr<CalendarTheme>& theme, const RefPtr<LinearLayoutProperty>& layoutProps); 121 static void SetWeekTextDirection(const TextDirection& dialogDirection, const TextDirection& calendarDirection, 122 const RefPtr<FrameNode>& weekNode); 123 static DialogEvent GetChangeEvent(const CalendarSettingData& settingData, const RefPtr<FrameNode>& frameNode, 124 const std::map<std::string, NG::DialogEvent>& dialogEvent); 125 static bool ReportChangeEvent(const RefPtr<FrameNode>& frameNode, const std::string& compName, 126 const std::string& eventName, const std::string& eventData); 127 static constexpr double deviceHeightLimit = 640.0; 128 static void UpdateTextLayoutProperty(const RefPtr<TextLayoutProperty>& textLayoutProperty, 129 RefPtr<CalendarTheme>& theme); 130 static DeviceOrientation previousOrientation_; 131 }; 132 } // namespace OHOS::Ace::NG 133 134 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_CALENDAR_PICKER_CALENDAR_DIALOG_VIEW_H 135