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_TIME_PICKER_TIME_PICKER_DIALOG_VIEW_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TIME_PICKER_TIME_PICKER_DIALOG_VIEW_H 18 19 #include "base/utils/macros.h" 20 #include "core/components/common/layout/constants.h" 21 #include "core/components/picker/picker_base_component.h" 22 #include "core/components_ng/pattern/button/button_layout_property.h" 23 #include "core/components_ng/pattern/time_picker/timepicker_row_pattern.h" 24 25 namespace OHOS::Ace::NG { 26 27 class ACE_EXPORT TimePickerDialogView { 28 public: 29 static RefPtr<FrameNode> Show(const DialogProperties& dialogProperties, const TimePickerSettingData& settingData, 30 const std::vector<ButtonInfo>& buttonInfos, std::map<std::string, PickerTime> timePickerProperty, 31 std::map<std::string, NG::DialogEvent> dialogEvent, 32 std::map<std::string, NG::DialogGestureEvent> dialogCancelEvent); 33 static void SetSelectedTime(const RefPtr<TimePickerRowPattern>& timePickerRowPattern, const PickerTime& value); 34 static void SetDialogTitleDate(const RefPtr<TimePickerRowPattern>& timePickerRowPattern, const PickerDate& value); 35 static void SetHour24(const RefPtr<TimePickerRowPattern>& timePickerRowPattern, bool isUseMilitaryTime = false); 36 static void SetDialogChange(const RefPtr<FrameNode>& frameNode, DialogEvent&& onChange); 37 static RefPtr<FrameNode> CreateButtonNode(const RefPtr<FrameNode>& frameNode, 38 const RefPtr<FrameNode>& timePickerNode, const std::vector<ButtonInfo>& buttonInfos, 39 std::map<std::string, NG::DialogEvent> dialogEvent, 40 std::map<std::string, NG::DialogGestureEvent> dialogCancelEvent); 41 static void SetDialogAcceptEvent(const RefPtr<FrameNode>& frameNode, DialogEvent&& onChange); 42 static RefPtr<FrameNode> CreateTitleButtonNode(const RefPtr<FrameNode>& dateNode); 43 static RefPtr<FrameNode> CreateDividerNode(const RefPtr<FrameNode>& dateNode, bool isCreateDivider = false); 44 static RefPtr<FrameNode> CreateConfirmNode(const RefPtr<FrameNode>& dateNode, 45 const RefPtr<FrameNode>& timePickerNode, const std::vector<ButtonInfo>& buttonInfos, DialogEvent& acceptEvent); 46 static RefPtr<FrameNode> CreateCancelNode(NG::DialogGestureEvent& cancelEvent, 47 const RefPtr<FrameNode>& timePickerNode, const std::vector<ButtonInfo>& buttonInfos); 48 static RefPtr<FrameNode> CreateBoxNode(); 49 50 private: 51 static RefPtr<FrameNode> CreateStackNode(); 52 static RefPtr<FrameNode> CreateColumnNode(); 53 static RefPtr<FrameNode> CreateButtonNode(); 54 static void UpdateButtonLayoutProperty( 55 const RefPtr<ButtonLayoutProperty>& buttonConfirmLayoutProperty, const RefPtr<PickerTheme>& pickerTheme); 56 static void UpdateConfirmButtonMargin( 57 const RefPtr<ButtonLayoutProperty>& buttonConfirmLayoutProperty, const RefPtr<DialogTheme>& dialogTheme); 58 static void UpdateCancelButtonMargin( 59 const RefPtr<ButtonLayoutProperty>& buttonCancelLayoutProperty, const RefPtr<DialogTheme>& dialogTheme); 60 static void UpdateButtonStyles(const std::vector<ButtonInfo>& buttonInfos, size_t index, 61 const RefPtr<ButtonLayoutProperty>& buttonLayoutProperty, const RefPtr<RenderContext>& buttonRenderContext); 62 static void UpdateButtonStyleAndRole(const std::vector<ButtonInfo>& buttonInfos, size_t index, 63 const RefPtr<ButtonLayoutProperty>& buttonLayoutProperty, const RefPtr<RenderContext>& buttonRenderContext, 64 const RefPtr<ButtonTheme>& buttonTheme); 65 static void SetTextProperties(const RefPtr<PickerTheme>& pickerTheme, const PickerTextProperties& properties); 66 static void UpdateButtonDefaultFocus( 67 const std::vector<ButtonInfo>& buttonInfos, const RefPtr<FrameNode>& buttonNode, bool isConfirm); 68 static void BuildDialogAcceptAndCancelButton(const std::vector<ButtonInfo>& buttonInfos, 69 const TimePickerSettingData& settingData, const RefPtr<FrameNode>& acceptNode, 70 const RefPtr<FrameNode>& timePickerNode, const RefPtr<FrameNode>& dialogNode, 71 const RefPtr<FrameNode>& contentColumn, std::map<std::string, NG::DialogEvent> dialogEvent, 72 std::map<std::string, NG::DialogGestureEvent> dialogCancelEvent); 73 74 static RefPtr<FrameNode> CreateNextPrevButtonNode(std::function<void()>& timePickerSwitchEvent, 75 const RefPtr<FrameNode>& timeNode, const std::vector<ButtonInfo>& buttonInfos); 76 static RefPtr<FrameNode> CreateButtonNodeForAging(const RefPtr<FrameNode>& frameNode, 77 const RefPtr<FrameNode>& timePickerNode, const std::vector<ButtonInfo>& buttonInfos, 78 std::map<std::string, NG::DialogEvent> dialogEvent, 79 std::map<std::string, NG::DialogGestureEvent> dialogCancelEvent); 80 static bool NeedAdaptForAging(); 81 static std::function<void()> CreateAndSetTimePickerSwitchEvent(const RefPtr<FrameNode>& timePicker, 82 const RefPtr<FrameNode>& buttonCancelNode, const RefPtr<FrameNode>& buttonConfirmNode, 83 const RefPtr<FrameNode>& cancelNextDividerNode, const RefPtr<FrameNode>& nextConfirmDividerNode); 84 static void SwitchTimePickerPage(const RefPtr<FrameNode>& timePickerNode, const RefPtr<FrameNode>& buttonCancelNode, 85 const RefPtr<FrameNode>& buttonConfirmNode, const RefPtr<FrameNode>& cancelNextDividerNode, 86 const RefPtr<FrameNode>& nextConfirmDividerNode); 87 static bool GetIsUserSetTextProperties(const PickerTextProperties& properties); 88 static std::function<void(const GestureEvent&)> UpdateTimePickerSwitchEvent( 89 const RefPtr<FrameNode>& timeNode, const RefPtr<FrameNode>& textNode, const RefPtr<DialogTheme>& dialogTheme, 90 const RefPtr<FrameNode>& buttonNode, const std::function<void()>& timePickerSwitchEvent); 91 static std::function<void()> CloseDialogEvent(const RefPtr<TimePickerRowPattern>& timePickerPattern, 92 const RefPtr<FrameNode>& dialogNode); 93 static const Dimension ConvertFontSizeLimit(const Dimension& fontSizeValue, 94 const Dimension& fontSizeLimit, bool isUserSetFont = false); 95 static const Dimension ConvertFontScaleValue(const Dimension& fontSizeValue, 96 const Dimension& fontSizeLimit = 0.0_vp, bool isUserSetFont = false); 97 static const Dimension ConvertTitleFontScaleValue(const Dimension& fontSizeValue); 98 static const Dimension AdjustFontSizeScale(const Dimension& fontSizeValue, double fontScale); 99 static void GetUserSettingLimit(); 100 static void SetTextDisappearProperties(const RefPtr<PickerTheme>& pickerTheme, 101 const PickerTextProperties& properties); 102 static void UpdateConfirmButtonTextLayoutProperty( 103 const RefPtr<TextLayoutProperty>& textLayoutProperty, const RefPtr<PickerTheme>& pickerTheme); 104 static void UpdateCancelButtonTextLayoutProperty( 105 const RefPtr<TextLayoutProperty>& textCancelLayoutProperty, const RefPtr<PickerTheme>& pickerTheme); 106 static bool switchFlag_; 107 static Dimension selectedTextStyleFont_; 108 static Dimension normalTextStyleFont_; 109 static Dimension disappearTextStyleFont_; 110 }; 111 } // namespace OHOS::Ace::NG 112 113 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TIME_PICKER_TIME_PICKER_DIALOG_VIEW_H 114