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_MODEL_NG_VIEW_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_DATE_PICKER_DATE_PICKER_MODEL_NG_VIEW_H 18 19 #include "base/i18n/localization.h" 20 #include "base/utils/macros.h" 21 #include "core/components/common/layout/constants.h" 22 #include "core/components/picker/picker_base_component.h" 23 #include "core/components_ng/pattern/picker/datepicker_event_hub.h" 24 #include "core/components_ng/pattern/picker/datepicker_layout_property.h" 25 #include "core/components_ng/pattern/picker/picker_model.h" 26 27 namespace OHOS::Ace::NG { 28 class ACE_EXPORT DatePickerModelNG : public DatePickerModel { 29 public: 30 void CreateDatePicker(RefPtr<PickerTheme> theme) override; CreateTimePicker(RefPtr<PickerTheme> theme)31 void CreateTimePicker(RefPtr<PickerTheme> theme) override {}; 32 void SetStartDate(const PickerDate& value) override; 33 void SetEndDate(const PickerDate& value) override; 34 void SetSelectedDate(const PickerDate& value) override; 35 void SetMode(const DatePickerMode& value) override; 36 void SetShowLunar(bool lunar) override; 37 void SetCanLoop(bool isLoop) override; 38 void SetOnChange(DateChangeEvent&& onChange) override; 39 void SetOnDateChange(DateChangeEvent&& onChange) override; SetSelectedTime(const PickerTime & selectedTime)40 void SetSelectedTime(const PickerTime& selectedTime) override {}; SetHour24(bool value)41 void SetHour24(bool value) override {}; 42 void SetDisappearTextStyle(const RefPtr<PickerTheme>& theme, const PickerTextStyle& value) override; 43 void SetNormalTextStyle(const RefPtr<PickerTheme>& theme, const PickerTextStyle& value) override; 44 void SetSelectedTextStyle(const RefPtr<PickerTheme>& theme, const PickerTextStyle& value) override; 45 void HasUserDefinedDisappearFontFamily(bool isUserDefined) override; 46 void HasUserDefinedNormalFontFamily(bool isUserDefined) override; 47 void HasUserDefinedSelectedFontFamily(bool isUserDefined) override; 48 void SetBackgroundColor(const Color& color) override; 49 void HasUserDefinedOpacity() override; 50 void SetEnableHapticFeedback(bool isEnableHapticFeedback) override; 51 void UpdateUserSetSelectColor() override; 52 static void SetStartDate(FrameNode* frameNode, const PickerDate& value); 53 static void SetEndDate(FrameNode* frameNode, const PickerDate& value); 54 static void SetSelectedDate(FrameNode* frameNode, const PickerDate& value); 55 static void SetMode(FrameNode* frameNode, const DatePickerMode& value); 56 static void SetOnDateChange(FrameNode* frameNode, DateChangeEvent&& onChange); 57 static void SetOnChange(FrameNode* frameNode, DateChangeEvent&& onChange); 58 static RefPtr<FrameNode> CreateFrameNode(int32_t nodeId); 59 void SetChangeEvent(DateChangeEvent&& onChange) override; 60 void SetDigitalCrownSensitivity(int32_t crownSensitivity) override; 61 static void SetSelectedTextStyle( 62 FrameNode* frameNode, const RefPtr<PickerTheme>& theme, const PickerTextStyle& value); 63 static void SetNormalTextStyle( 64 FrameNode* frameNode, const RefPtr<PickerTheme>& theme, const PickerTextStyle& value); 65 static void SetDisappearTextStyle( 66 FrameNode* frameNode, const RefPtr<PickerTheme>& theme, const PickerTextStyle& value); 67 static void SetShowLunar(FrameNode* frameNode, bool lunar); 68 static void SetBackgroundColor(FrameNode* frameNode, const Color& color); 69 static PickerTextStyle getSelectedTextStyle(FrameNode* frameNode); 70 static PickerTextStyle getNormalTextStyle(FrameNode* frameNode); 71 static PickerTextStyle getDisappearTextStyle(FrameNode* frameNode); 72 static int32_t getLunar(FrameNode* frameNode); 73 static LunarDate getStartDate(FrameNode* frameNode); 74 static LunarDate getEndDate(FrameNode* frameNode); 75 static LunarDate getSelectedDate(FrameNode* frameNode); 76 static DatePickerMode getMode(FrameNode* frameNode); 77 static uint32_t getBackgroundColor(FrameNode* frameNode); 78 static void SetDefaultAttributes(RefPtr<FrameNode>& frameNode, const RefPtr<PickerTheme>& pickerTheme); 79 static const Dimension ConvertFontScaleValue(const Dimension& fontSizeValue); 80 static bool GetEnableHapticFeedback(FrameNode* frameNode); 81 static void SetEnableHapticFeedback(FrameNode* frameNode, bool isEnableHapticFeedback); 82 static bool GetCanLoop(FrameNode* frameNode); 83 static void SetCanLoop(FrameNode* frameNode, bool isLoop); 84 static void SetDigitalCrownSensitivity(FrameNode* frameNode, int32_t crownSensitivity); 85 private: 86 static RefPtr<FrameNode> CreateStackNode(); 87 static RefPtr<FrameNode> CreateColumnNode(); 88 static RefPtr<FrameNode> CreateButtonNode(); 89 void CreateDateColumn(const RefPtr<FrameNode>& columnNode, const RefPtr<FrameNode>& dateNode); 90 static void ParseResTextStyle(const PickerTextStyle& textStyleOpt, const std::string& textStyleType, 91 std::function<void(const PickerTextStyle&)> updateTextStyleFunc); 92 static void ParseDisappearTextStyleResObj(const PickerTextStyle& textStyleOpt); 93 static void ParseSelectedTextStyleResObj(const PickerTextStyle& textStyleOpt); 94 static void ParseNormalTextStyleResObj(const PickerTextStyle& textStyleOpt); 95 96 std::string dateOrder = ""; 97 std::string dateTimeOrder = ""; 98 }; 99 100 class ACE_FORCE_EXPORT DatePickerDialogModelNG : public DatePickerDialogModel { 101 public: 102 void SetDatePickerDialogShow(PickerDialogInfo& pickerDialog, NG::DatePickerSettingData& settingData, 103 std::function<void()>&& onCancel, std::function<void(const std::string&)>&& onAccept, 104 std::function<void(const std::string&)>&& onChange, std::function<void(const std::string&)>&& onDateAccept, 105 std::function<void(const std::string&)>&& onDateChange, DatePickerType pickerType, 106 PickerDialogEvent& pickerDialogEvent, const std::vector<ButtonInfo>& buttonInfos) override; 107 }; 108 } // namespace OHOS::Ace::NG 109 110 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_DATE_PICKER_DATE_PICKER_MODEL_NG_VIEW_H 111