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_PATTERN_PICKER_PICKER_MODEL_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PICKER_PICKER_MODEL_H 18 19 #include <mutex> 20 21 #include "core/components/picker/picker_data.h" 22 #include "core/components/picker/picker_theme.h" 23 #include "core/components_ng/pattern/picker/picker_type_define.h" 24 25 namespace OHOS::Ace { 26 using DateChangeEvent = std::function<void(const BaseEventInfo* info)>; 27 struct PickerDialogInfo { 28 bool isLunar; 29 PickerDate parseStartDate; 30 PickerDate parseEndDate; 31 PickerDate parseSelectedDate; 32 PickerTime pickerTime; 33 bool isUseMilitaryTime; 34 bool isSelectedTime; 35 bool isStartDate; 36 bool isEndDate; 37 bool isSelectedDate; 38 std::optional<DialogAlignment> alignment; 39 std::optional<DimensionOffset> offset; 40 std::optional<DimensionRect> maskRect; 41 std::optional<Color> backgroundColor; 42 std::optional<int32_t> backgroundBlurStyle; 43 std::optional<Shadow> shadow; 44 }; 45 struct PickerDialogEvent { 46 std::function<void()> onDidAppear; 47 std::function<void()> onDidDisappear; 48 std::function<void()> onWillAppear; 49 std::function<void()> onWillDisappear; 50 }; 51 class ACE_FORCE_EXPORT DatePickerModel { 52 public: 53 static DatePickerModel* GetInstance(); 54 virtual ~DatePickerModel() = default; 55 56 virtual void CreateDatePicker(RefPtr<PickerTheme> theme) = 0; 57 virtual void CreateTimePicker(RefPtr<PickerTheme> theme) = 0; 58 virtual void SetStartDate(const PickerDate& value) = 0; 59 virtual void SetEndDate(const PickerDate& value) = 0; 60 virtual void SetSelectedDate(const PickerDate& value) = 0; 61 virtual void SetShowLunar(bool lunar) = 0; 62 virtual void SetOnChange(DateChangeEvent&& onChange) = 0; 63 virtual void SetOnDateChange(DateChangeEvent&& onChange) = 0; 64 virtual void SetSelectedTime(const PickerTime& selectedTime) = 0; 65 virtual void SetHour24(bool value) = 0; 66 virtual void SetDisappearTextStyle(const RefPtr<PickerTheme>& theme, const NG::PickerTextStyle& value) = 0; 67 virtual void SetNormalTextStyle(const RefPtr<PickerTheme>& theme, const NG::PickerTextStyle& value) = 0; 68 virtual void SetSelectedTextStyle(const RefPtr<PickerTheme>& theme, const NG::PickerTextStyle& value) = 0; 69 virtual void HasUserDefinedDisappearFontFamily(bool isUserDefined) = 0; 70 virtual void HasUserDefinedNormalFontFamily(bool isUserDefined) = 0; 71 virtual void HasUserDefinedSelectedFontFamily(bool isUserDefined) = 0; 72 virtual void SetBackgroundColor(const Color& color) = 0; 73 virtual void SetChangeEvent(DateChangeEvent&& onChange) = 0; 74 virtual void HasUserDefinedOpacity() = 0; 75 76 private: 77 static std::unique_ptr<DatePickerModel> datePickerInstance_; 78 static std::mutex mutex_; 79 }; 80 81 class DatePickerDialogModel { 82 public: 83 static DatePickerDialogModel* GetInstance(); 84 virtual ~DatePickerDialogModel() = default; 85 86 virtual void SetDatePickerDialogShow(PickerDialogInfo& pickerDialog, NG::DatePickerSettingData& settingData, 87 std::function<void()>&& onCancel, std::function<void(const std::string&)>&& onAccept, 88 std::function<void(const std::string&)>&& onChange, std::function<void(const std::string&)>&& onDateAccept, 89 std::function<void(const std::string&)>&& onDateChange, DatePickerType pickerType, 90 PickerDialogEvent& dialogEvent, const std::vector<ButtonInfo>& buttonInfos) = 0; 91 92 private: 93 static std::unique_ptr<DatePickerDialogModel> datePickerDialogInstance_; 94 static std::mutex mutex_; 95 }; 96 } // namespace OHOS::Ace 97 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PICKER_PICKER_MODEL_H 98