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