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 #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/button/button_layout_property.h" 24 #include "core/components_ng/pattern/calendar/calendar_event_hub.h" 25 #include "core/components_ng/pattern/calendar/calendar_model_ng.h" 26 #include "core/components_ng/pattern/calendar_picker/calendar_dialog_pattern.h" 27 #include "core/components_ng/pattern/calendar_picker/calendar_type_define.h" 28 29 namespace OHOS::Ace::NG { 30 class ACE_EXPORT CalendarDialogView { 31 public: 32 static RefPtr<FrameNode> Show(const DialogProperties& dialogProperties, const CalendarSettingData& settingData, 33 const std::vector<ButtonInfo>& buttonInfos, const std::map<std::string, NG::DialogEvent>& dialogEvent, 34 const std::map<std::string, NG::DialogGestureEvent>& dialogCancelEvent); 35 static void UpdateIdealSize(const RefPtr<CalendarTheme>& calendarTheme, 36 const RefPtr<LinearLayoutProperty>& layoutProps, const RefPtr<LayoutProperty>& calendarLayoutProperty); 37 static void UpdatePaintProperties(const RefPtr<FrameNode>& monthFrameNode, const CalendarSettingData& settingData); 38 static void UpdateButtons( 39 const RefPtr<FrameNode>& buttonNode, size_t buttonIndex, std::vector<ButtonInfo>& buttonInfos); SetPreviousOrientation()40 static void SetPreviousOrientation() 41 { 42 previousOrientation_ = SystemProperties::GetDeviceOrientation(); 43 } 44 CheckOrientationChange()45 static bool CheckOrientationChange() 46 { 47 auto pipeline = PipelineContext::GetCurrentContextSafelyWithCheck(); 48 CHECK_NULL_RETURN(pipeline, true); 49 return (!(SystemProperties::GetDeviceOrientation() == previousOrientation_) 50 ? Dimension(pipeline->GetRootWidth()).ConvertToVp() < deviceHeightLimit 51 : Dimension(pipeline->GetRootHeight()).ConvertToVp() < deviceHeightLimit); 52 } 53 GetPreviousOrientation()54 static DeviceOrientation GetPreviousOrientation() 55 { 56 return previousOrientation_; 57 } 58 59 private: 60 static RefPtr<FrameNode> CreateTitleNode(const RefPtr<FrameNode>& calendarNode); 61 static RefPtr<FrameNode> CreateTitleImageNode( 62 const RefPtr<FrameNode>& calendarNode, const InternalResource::ResourceId& resourceId); 63 static RefPtr<FrameNode> CreateCalendarNode(const RefPtr<FrameNode>& calendarDialogNode, 64 const CalendarSettingData& settingData, const std::map<std::string, NG::DialogEvent>& dialogEvent); 65 static RefPtr<FrameNode> CreateCalendarSwiperNode(); 66 static RefPtr<FrameNode> CreateCalendarMonthNode(int32_t calendarNodeId, 67 const CalendarSettingData& settingData, const DialogEvent& changeEvent); 68 static void UpdateCalendarMonthData(const RefPtr<FrameNode>& calendarDialogNode, 69 const RefPtr<FrameNode>& calendarNode, const CalendarMonth& currentMonth); 70 static void SetDialogChange(const RefPtr<FrameNode>& frameNode, DialogEvent&& onChange); 71 static void SetDialogAcceptEvent(const RefPtr<FrameNode>& frameNode, DialogEvent&& onChange); 72 static RefPtr<FrameNode> CreateButtonNode(bool isConfirm, const std::vector<ButtonInfo>& buttonInfos); 73 static RefPtr<FrameNode> CreateConfirmNode( 74 const RefPtr<FrameNode>& calendarNode, DialogEvent& acceptEvent, const std::vector<ButtonInfo>& buttonInfos); 75 static RefPtr<FrameNode> CreateCancelNode( 76 const NG::DialogGestureEvent& cancelEvent, const std::vector<ButtonInfo>& buttonInfos); 77 static void UpdateButtonStyles(const std::vector<ButtonInfo>& buttonInfos, size_t index, 78 const RefPtr<ButtonLayoutProperty>& buttonLayoutProperty, const RefPtr<RenderContext>& buttonRenderContext); 79 static RefPtr<FrameNode> CreateDividerNode(); 80 static RefPtr<FrameNode> CreateOptionsNode(const RefPtr<FrameNode>& dialogNode, const RefPtr<FrameNode>& dateNode, 81 const std::map<std::string, NG::DialogEvent>& dialogEvent, 82 const std::map<std::string, NG::DialogGestureEvent>& dialogCancelEvent, 83 const std::vector<ButtonInfo>& buttonInfos); 84 static void SetCalendarPaintProperties(const CalendarSettingData& settingData); 85 static void InitOnRequestDataEvent( 86 const RefPtr<FrameNode>& calendarDialogNode, const RefPtr<FrameNode>& calendarNode); 87 static void OnSelectedChangeEvent(int32_t calendarNodeId, const std::string& callbackInfo, 88 const DialogEvent& onChange, const CalendarSettingData& settingData); 89 static void UpdateBackgroundStyle( 90 const RefPtr<RenderContext>& renderContext, const DialogProperties& dialogProperties); 91 static void UpdateButtonStyleAndRole(const std::vector<ButtonInfo>& buttonInfos, size_t index, 92 const RefPtr<ButtonLayoutProperty>& buttonLayoutProperty, const RefPtr<RenderContext>& buttonRenderContext, 93 const RefPtr<ButtonTheme>& buttonTheme); 94 static void DisableResetOptionButtonColor( 95 const RefPtr<CalendarDialogPattern>& calendarDialogPattern, const std::vector<ButtonInfo>& buttonInfos); 96 static void UpdateButtonDefaultFocus(const std::vector<ButtonInfo>& buttonInfos, 97 const RefPtr<FrameNode>& buttonNode, bool isConfirm); 98 static void UpdateDialogDefaultFocus(const RefPtr<FrameNode>& contentRow, 99 const RefPtr<FrameNode>& contentColumn); 100 static void UpdateDefaultFocusByButtonInfo(const RefPtr<FrameNode>& optionsNode, 101 const RefPtr<FrameNode>& accept, const RefPtr<FrameNode>& cancel); 102 static void UpdateButtonLayoutProperty(const RefPtr<FrameNode>& buttonNode, bool isConfirm, 103 const std::vector<ButtonInfo>& buttonInfos, const RefPtr<PipelineContext>& pipeline); 104 static void UpdateOptionLayoutProps( 105 const RefPtr<FrameNode>& contentRow, const RefPtr<PipelineContext>& pipelineContext); 106 static void OperationsToPattern(const RefPtr<FrameNode>& frameNode, const CalendarSettingData& settingData, 107 const DialogProperties& dialogProperties, const std::vector<ButtonInfo>& buttonInfos); 108 static void CreateChildNode(const RefPtr<FrameNode>& contentColumn, 109 const RefPtr<FrameNode>& dialogNode, const DialogProperties& dialogProperties); 110 static void InitCalendarProperty(const RefPtr<FrameNode>& calendarNode); 111 static void SetCalendarIdealSize( 112 const RefPtr<CalendarTheme>& theme, const RefPtr<LayoutProperty>& calendarLayoutProperty); 113 static void SetTitleIdealSize(const RefPtr<CalendarTheme>& theme, const RefPtr<LinearLayoutProperty>& layoutProps); 114 static constexpr double deviceHeightLimit = 640.0; 115 static DeviceOrientation previousOrientation_; 116 }; 117 } // namespace OHOS::Ace::NG 118 119 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_CALENDAR_PICKER_CALENDAR_DIALOG_VIEW_H 120