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 bool enableHoverMode = false; 39 std::optional<DialogAlignment> alignment; 40 std::optional<DimensionOffset> offset; 41 std::optional<DimensionRect> maskRect; 42 std::optional<Color> backgroundColor; 43 std::optional<int32_t> backgroundBlurStyle; 44 std::optional<Shadow> shadow; 45 std::optional<HoverModeAreaType> hoverModeArea; 46 }; 47 struct PickerDialogEvent { 48 std::function<void()> onDidAppear; 49 std::function<void()> onDidDisappear; 50 std::function<void()> onWillAppear; 51 std::function<void()> onWillDisappear; 52 }; 53 class ACE_FORCE_EXPORT DatePickerModel { 54 public: 55 static DatePickerModel* GetInstance(); 56 virtual ~DatePickerModel() = default; 57 58 virtual void CreateDatePicker(RefPtr<PickerTheme> theme) = 0; 59 virtual void CreateTimePicker(RefPtr<PickerTheme> theme) = 0; 60 virtual void SetStartDate(const PickerDate& value) = 0; 61 virtual void SetEndDate(const PickerDate& value) = 0; 62 virtual void SetSelectedDate(const PickerDate& value) = 0; 63 virtual void SetShowLunar(bool lunar) = 0; 64 virtual void SetOnChange(DateChangeEvent&& onChange) = 0; 65 virtual void SetOnDateChange(DateChangeEvent&& onChange) = 0; 66 virtual void SetSelectedTime(const PickerTime& selectedTime) = 0; 67 virtual void SetHour24(bool value) = 0; 68 virtual void SetDisappearTextStyle(const RefPtr<PickerTheme>& theme, const NG::PickerTextStyle& value) = 0; 69 virtual void SetNormalTextStyle(const RefPtr<PickerTheme>& theme, const NG::PickerTextStyle& value) = 0; 70 virtual void SetSelectedTextStyle(const RefPtr<PickerTheme>& theme, const NG::PickerTextStyle& value) = 0; 71 virtual void HasUserDefinedDisappearFontFamily(bool isUserDefined) = 0; 72 virtual void HasUserDefinedNormalFontFamily(bool isUserDefined) = 0; 73 virtual void HasUserDefinedSelectedFontFamily(bool isUserDefined) = 0; 74 virtual void SetBackgroundColor(const Color& color) = 0; 75 virtual void SetChangeEvent(DateChangeEvent&& onChange) = 0; 76 virtual void HasUserDefinedOpacity() = 0; 77 78 private: 79 static std::unique_ptr<DatePickerModel> datePickerInstance_; 80 static std::mutex mutex_; 81 }; 82 83 class DatePickerDialogModel { 84 public: 85 static DatePickerDialogModel* GetInstance(); 86 virtual ~DatePickerDialogModel() = default; 87 88 virtual void SetDatePickerDialogShow(PickerDialogInfo& pickerDialog, NG::DatePickerSettingData& settingData, 89 std::function<void()>&& onCancel, std::function<void(const std::string&)>&& onAccept, 90 std::function<void(const std::string&)>&& onChange, std::function<void(const std::string&)>&& onDateAccept, 91 std::function<void(const std::string&)>&& onDateChange, DatePickerType pickerType, 92 PickerDialogEvent& dialogEvent, const std::vector<ButtonInfo>& buttonInfos) = 0; 93 94 private: 95 static std::unique_ptr<DatePickerDialogModel> datePickerDialogInstance_; 96 static std::mutex mutex_; 97 }; 98 } // namespace OHOS::Ace 99 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PICKER_PICKER_MODEL_H 100