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_TEXT_PICKER_TEXT_PICKER_DIALOG_VIEW_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_PICKER_TEXT_PICKER_DIALOG_VIEW_H
18 
19 #include "base/utils/macros.h"
20 #include "core/components/common/layout/constants.h"
21 #include "core/components/picker/picker_base_component.h"
22 #include "core/components_ng/pattern/button/button_layout_property.h"
23 #include "core/components_ng/pattern/text_picker/textpicker_event_hub.h"
24 #include "core/components_ng/pattern/text_picker/textpicker_pattern.h"
25 
26 namespace OHOS::Ace::NG {
27 
28 class ACE_EXPORT TextPickerDialogView {
29 public:
30     static RefPtr<FrameNode> Show(const DialogProperties& dialogProperties, const TextPickerSettingData& settingData,
31         const std::vector<ButtonInfo>& buttonInfos, std::map<std::string, NG::DialogTextEvent> dialogEvent,
32         std::map<std::string, NG::DialogGestureEvent> dialogCancelEvent);
33     static RefPtr<FrameNode> RangeShow(const DialogProperties& dialogProperties,
34         const TextPickerSettingData& settingData, const std::vector<ButtonInfo>& buttonInfos,
35         std::map<std::string, NG::DialogTextEvent>& dialogEvent,
36         std::map<std::string, NG::DialogGestureEvent>& dialogCancelEvent);
37     static RefPtr<FrameNode> OptionsShow(const DialogProperties& dialogProperties,
38         const TextPickerSettingData& settingData, const std::vector<ButtonInfo>& buttonInfos,
39         std::map<std::string, NG::DialogTextEvent>& dialogEvent,
40         std::map<std::string, NG::DialogGestureEvent>& dialogCancelEvent);
41     static void SetSelected(const RefPtr<TextPickerPattern>& textPickerPattern, uint32_t value = 0);
42     static void SetSelectedValues(const RefPtr<TextPickerPattern>& textPickerPattern,
43         const std::vector<uint32_t>& values);
44     static void SetValues(const RefPtr<TextPickerPattern>& textPickerPattern,
45         const std::vector<std::string>& values);
46     static void SetRange(const RefPtr<TextPickerPattern>& textPickerPattern,
47         const std::vector<NG::RangeContent>& value);
48     static void SetDialogChange(const RefPtr<FrameNode>& frameNode, DialogTextEvent&& onChange);
49     static void SetDialogScrollStop(const RefPtr<FrameNode>& frameNode, DialogTextEvent&& onScrollStop);
50     static void SetDefaultPickerItemHeight(const Dimension& value);
51     static void SetDialogAcceptEvent(const RefPtr<FrameNode>& frameNode, DialogTextEvent&& onChange);
52     static RefPtr<FrameNode> CreateButtonNode(const RefPtr<FrameNode>& frameNode,
53         const std::vector<ButtonInfo>& buttonInfos, std::map<std::string, NG::DialogTextEvent> dialogEvent,
54         std::map<std::string, NG::DialogGestureEvent> dialogCancelEvent, GestureEventFunc callback);
55     static RefPtr<FrameNode> CreateAgingButtonNode(RefPtr<FrameNode>& textPickerNode,
56         const std::vector<ButtonInfo>& buttonInfos,
57         std::map<std::string, NG::DialogTextEvent> dialogEvent,
58         std::map<std::string, NG::DialogGestureEvent>dialogCancelEvent,
59         std::map<std::string, NG::DialogGestureEvent>dialogMoveForwardEvent,
60         std::map<std::string, NG::DialogGestureEvent> dialogMoveBackwardEvent,
61         GestureEventFunc closeCallback, GestureEventFunc nextCallBack, GestureEventFunc previousCallBack);
62     static RefPtr<FrameNode> CreateDividerNode(const RefPtr<FrameNode>& dateNode);
63     static RefPtr<FrameNode> CreateConfirmNode(const RefPtr<FrameNode>& dateNode,
64         const RefPtr<FrameNode>& textPickerNode, const std::vector<ButtonInfo>& buttonInfos, DialogEvent& acceptEvent);
65     static RefPtr<FrameNode> CreateCancelNode(NG::DialogGestureEvent& cancelEvent,
66         const RefPtr<FrameNode>& textPickerNode, const std::vector<ButtonInfo>& buttonInfos);
67     static RefPtr<FrameNode> CreateForwardNode(NG::DialogGestureEvent& moveForwardEvent,
68         const RefPtr<FrameNode>& textPickerNode, const std::vector<ButtonInfo>& buttonInfos);
69     static RefPtr<FrameNode> CreateBackwardNode(NG::DialogGestureEvent& moveBackwardEvent,
70         const RefPtr<FrameNode>& textPickerNode, const std::vector<ButtonInfo>& buttonInfos);
71 
72 private:
73     static RefPtr<FrameNode> CreateStackNode(RefPtr<PickerTheme> pickerTheme);
74     static RefPtr<FrameNode> CreateColumnNode();
75     static RefPtr<FrameNode> CreateButtonNode();
76     static RefPtr<FrameNode> CreateColumnNode(uint32_t columnKind,
77         uint32_t showCount, RefPtr<PickerTheme> pickerTheme);
78     static RefPtr<FrameNode> CreateIconItemNode(RefPtr<PickerTheme> pickerTheme);
79     static RefPtr<FrameNode> CreateTextItemNode(RefPtr<PickerTheme> pickerTheme);
80     static RefPtr<FrameNode> CreateMixtureItemNode(RefPtr<PickerTheme> pickerTheme);
81     static void SetTextProperties(const RefPtr<PickerTheme>& pickerTheme,
82         const PickerTextProperties& properties);
83     static void OptionsCreateNode(const RefPtr<TextPickerPattern>& textPickerPattern,
84         const TextPickerSettingData& settingData, const RefPtr<FrameNode>& textPickerNode,
85         uint32_t showCount, uint32_t columnCount, RefPtr<PickerTheme> pickerTheme);
86     static void OptionsShowInternal(const RefPtr<TextPickerPattern>& textPickerPattern,
87         const TextPickerSettingData& settingData, const RefPtr<FrameNode>& textPickerNode,
88         uint32_t showCount, RefPtr<PickerTheme> pickerTheme);
89     static void InitOnKeyEvent(const RefPtr<FocusHub>& focusHub);
90     static bool OnKeyEvent(const KeyEvent& event);
91     static void UpdateButtonConfirmLayoutProperty(const RefPtr<FrameNode>& buttonConfirmNode,
92         RefPtr<PickerTheme> pickerTheme);
93     static void UpdateButtonCancelLayoutProperty(const RefPtr<FrameNode>& buttonCancelNode,
94         const RefPtr<PipelineContext>& pipeline);
95     static void UpdateButtonForwardLayoutProperty(const RefPtr<FrameNode>& buttonCancelNode,
96         const RefPtr<PipelineContext>& pipeline);
97     static void UpdateButtonBackwardLayoutProperty(const RefPtr<FrameNode>& buttonCancelNode,
98         const RefPtr<PipelineContext>& pipeline);
99     static void UpdateConfirmButtonTextLayoutProperty(
100         const RefPtr<FrameNode>& textConfirmNode, const RefPtr<PickerTheme>& pickerTheme);
101     static void UpdateCancelButtonTextLayoutProperty(
102         const RefPtr<FrameNode>& textCancelNode, const RefPtr<PickerTheme>& pickerTheme);
103     static void UpdateForwardButtonTextLayoutProperty(
104         const RefPtr<FrameNode>& textCancelNode, const RefPtr<PickerTheme>& pickerTheme);
105     static void UpdateBackwardButtonTextLayoutProperty(
106         const RefPtr<FrameNode>& textCancelNode, const RefPtr<PickerTheme>& pickerTheme);
107     static void UpdateConfirmButtonMargin(
108         const RefPtr<FrameNode>& buttonConfirmNode, const RefPtr<DialogTheme>& dialogTheme);
109     static void UpdateCancelButtonMargin(
110         const RefPtr<FrameNode>& buttonCancelNode, const RefPtr<DialogTheme>& dialogTheme);
111     static void UpdateForwardButtonMargin(
112         const RefPtr<FrameNode>& buttonCancelNode, const RefPtr<DialogTheme>& dialogTheme);
113     static void UpdateBackwardButtonMargin(
114         const RefPtr<FrameNode>& buttonCancelNode, const RefPtr<DialogTheme>& dialogTheme);
115     static void UpdateButtonStyles(const std::vector<ButtonInfo>& buttonInfos, size_t index,
116         const RefPtr<ButtonLayoutProperty>& buttonLayoutProperty, const RefPtr<RenderContext>& buttonRenderContext);
117     static void UpdateButtonStyleAndRole(const std::vector<ButtonInfo>& buttonInfos, size_t index,
118         const RefPtr<ButtonLayoutProperty>& buttonLayoutProperty, const RefPtr<RenderContext>& buttonRenderContext,
119         const RefPtr<ButtonTheme>& buttonTheme);
120     static void UpdateButtonDefaultFocus(const std::vector<ButtonInfo>& buttonInfos,
121         const RefPtr<FrameNode>& buttonNode, bool isConfirm);
122     static void SetDialogNodePageActive(RefPtr<FrameNode>& contentRow, RefPtr<FrameNode>& textPickerNode,
123         const uint32_t& dialogNodePage, const uint32_t& showCount);
124     static RefPtr<FrameNode> SeparatedOptionsShow(RefPtr<FrameNode>& contentColumn, RefPtr<FrameNode>& textPickerNode,
125         const std::vector<ButtonInfo>& buttonInfos,
126         const TextPickerSettingData& settingData,
127         std::map<std::string, NG::DialogTextEvent>& dialogEvent,
128         std::map<std::string, NG::DialogGestureEvent>& dialogCancelEvent,
129         const float& scale, GestureEventFunc closeCallBack, RefPtr<FrameNode>& dialogNode);
130     static void SetDialogButtonActive(RefPtr<FrameNode>& contentColumn,
131         const uint32_t& dialogNodePage, const uint32_t& columnCount);
132     static void SetFirstDialogButtonActive(RefPtr<UINode>& contentRow);
133     static void SetSecondDialogButtonActive(RefPtr<UINode>& contentRow);
134     static void SetThirdDialogButtonActive(RefPtr<UINode>& contentRow);
135     static std::function<void()> CloseDialogEvent(const RefPtr<TextPickerPattern>& textPickerPattern,
136         const RefPtr<FrameNode>& dialogNode);
137 
138     static void SetDividerNodeActive(RefPtr<UINode>& contentRow, bool firstDivider,
139         bool secondDivider, bool thirdDivider);
140     static void SetSingleDividerNodeActive(RefPtr<FrameNode>& dividerNode, bool dividerActive);
141     static const Dimension ConvertFontSizeLimit(const Dimension& fontSizeValue,
142         const Dimension& fontSizeLimit, bool isUserSetFont = false);
143     static const Dimension ConvertFontScaleValue(const Dimension& fontSizeValue,
144         const Dimension& fontSizeLimit = 0.0_vp, bool isUserSetFont = false);
145     static const Dimension AdjustFontSizeScale(const Dimension& fontSizeValue, double fontScale);
146     static void GetUserSettingLimit();
147     static bool NeedAdaptForAging();
148     static void SetTextDisappearProperties(const RefPtr<PickerTheme>& pickerTheme,
149         const PickerTextProperties& properties);
150     static WeakPtr<FrameNode> dialogNode_;
151     static uint32_t dialogNodePage_;
152     static Dimension selectedTextStyleFont_;
153     static Dimension normalTextStyleFont_;
154     static Dimension disappearTextStyleFont_;
155 
156 };
157 } // namespace OHOS::Ace::NG
158 
159 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_PICKER_TEXT_PICKER_DIALOG_VIEW_H
160