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 SetShowLunar(bool lunar) override; 36 void SetOnChange(DateChangeEvent&& onChange) override; 37 void SetOnDateChange(DateChangeEvent&& onChange) override; SetSelectedTime(const PickerTime & selectedTime)38 void SetSelectedTime(const PickerTime& selectedTime) override {}; SetHour24(bool value)39 void SetHour24(bool value) override {}; 40 void SetDisappearTextStyle(const RefPtr<PickerTheme>& theme, const PickerTextStyle& value) override; 41 void SetNormalTextStyle(const RefPtr<PickerTheme>& theme, const PickerTextStyle& value) override; 42 void SetSelectedTextStyle(const RefPtr<PickerTheme>& theme, const PickerTextStyle& value) override; 43 void HasUserDefinedDisappearFontFamily(bool isUserDefined) override; 44 void HasUserDefinedNormalFontFamily(bool isUserDefined) override; 45 void HasUserDefinedSelectedFontFamily(bool isUserDefined) override; 46 void SetBackgroundColor(const Color& color) override; 47 void HasUserDefinedOpacity() override; 48 static void SetStartDate(FrameNode* frameNode, const PickerDate& value); 49 static void SetEndDate(FrameNode* frameNode, const PickerDate& value); 50 static void SetSelectedDate(FrameNode* frameNode, const PickerDate& value); 51 static void SetOnDateChange(FrameNode* frameNode, DateChangeEvent&& onChange); 52 static RefPtr<FrameNode> CreateFrameNode(int32_t nodeId); 53 void SetChangeEvent(DateChangeEvent&& onChange) override; 54 static void SetSelectedTextStyle( 55 FrameNode* frameNode, const RefPtr<PickerTheme>& theme, const PickerTextStyle& value); 56 static void SetNormalTextStyle( 57 FrameNode* frameNode, const RefPtr<PickerTheme>& theme, const PickerTextStyle& value); 58 static void SetDisappearTextStyle( 59 FrameNode* frameNode, const RefPtr<PickerTheme>& theme, const PickerTextStyle& value); 60 static void SetShowLunar(FrameNode* frameNode, bool lunar); 61 static void SetBackgroundColor(FrameNode* frameNode, const Color& color); 62 static PickerTextStyle getSelectedTextStyle(FrameNode* frameNode); 63 static PickerTextStyle getNormalTextStyle(FrameNode* frameNode); 64 static PickerTextStyle getDisappearTextStyle(FrameNode* frameNode); 65 static int32_t getLunar(FrameNode* frameNode); 66 static LunarDate getStartDate(FrameNode* frameNode); 67 static LunarDate getEndDate(FrameNode* frameNode); 68 static LunarDate getSelectedDate(FrameNode* frameNode); 69 static uint32_t getBackgroundColor(FrameNode* frameNode); 70 static void SetDefaultAttributes(RefPtr<FrameNode>& frameNode, const RefPtr<PickerTheme>& pickerTheme); 71 static const Dimension ConvertFontScaleValue(const Dimension& fontSizeValue); 72 private: 73 static RefPtr<FrameNode> CreateStackNode(); 74 static RefPtr<FrameNode> CreateColumnNode(); 75 static RefPtr<FrameNode> CreateButtonNode(); 76 void createMonthOrDayColumnNode(const RefPtr<FrameNode>& columnNode, 77 const RefPtr<FrameNode>& dateNode, Color buttonBackgroundColor); 78 void createYearColumnNode(const RefPtr<FrameNode>& columnNode, const RefPtr<FrameNode>& dateNode); 79 std::string dateOrder = ""; 80 std::string dateTimeOrder = ""; 81 }; 82 83 class ACE_EXPORT DatePickerDialogModelNG : public DatePickerDialogModel { 84 public: 85 void SetDatePickerDialogShow(PickerDialogInfo& pickerDialog, NG::DatePickerSettingData& settingData, 86 std::function<void()>&& onCancel, std::function<void(const std::string&)>&& onAccept, 87 std::function<void(const std::string&)>&& onChange, std::function<void(const std::string&)>&& onDateAccept, 88 std::function<void(const std::string&)>&& onDateChange, DatePickerType pickerType, 89 PickerDialogEvent& pickerDialogEvent, const std::vector<ButtonInfo>& buttonInfos) override; 90 }; 91 } // namespace OHOS::Ace::NG 92 93 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_DATE_PICKER_DATE_PICKER_MODEL_NG_VIEW_H 94