• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SetDefaultPickerItemHeight(const Dimension& value);
50     static void SetDialogAcceptEvent(const RefPtr<FrameNode>& frameNode, DialogTextEvent&& onChange);
51     static RefPtr<FrameNode> CreateButtonNode(const RefPtr<FrameNode>& frameNode,
52         const std::vector<ButtonInfo>& buttonInfos, std::map<std::string, NG::DialogTextEvent> dialogEvent,
53         std::map<std::string, NG::DialogGestureEvent> dialogCancelEvent, GestureEventFunc callback);
54     static RefPtr<FrameNode> CreateAgingButtonNode(RefPtr<FrameNode>& textPickerNode,
55         const std::vector<ButtonInfo>& buttonInfos,
56         std::map<std::string, NG::DialogTextEvent> dialogEvent,
57         std::map<std::string, NG::DialogGestureEvent>dialogCancelEvent,
58         std::map<std::string, NG::DialogGestureEvent>dialogMoveForwardEvent,
59         std::map<std::string, NG::DialogGestureEvent> dialogMoveBackwardEvent,
60         GestureEventFunc closeCallback, GestureEventFunc nextCallBack, GestureEventFunc previousCallBack);
61     static RefPtr<FrameNode> CreateDividerNode(const RefPtr<FrameNode>& dateNode);
62     static RefPtr<FrameNode> CreateConfirmNode(const RefPtr<FrameNode>& dateNode,
63         const RefPtr<FrameNode>& textPickerNode, const std::vector<ButtonInfo>& buttonInfos, DialogEvent& acceptEvent);
64     static RefPtr<FrameNode> CreateCancelNode(NG::DialogGestureEvent& cancelEvent,
65         const RefPtr<FrameNode>& textPickerNode, const std::vector<ButtonInfo>& buttonInfos);
66     static RefPtr<FrameNode> CreateForwardNode(NG::DialogGestureEvent& moveForwardEvent,
67         const RefPtr<FrameNode>& textPickerNode, const std::vector<ButtonInfo>& buttonInfos);
68     static RefPtr<FrameNode> CreateBackwardNode(NG::DialogGestureEvent& moveBackwardEvent,
69         const RefPtr<FrameNode>& textPickerNode, const std::vector<ButtonInfo>& buttonInfos);
70 
71 private:
72     static RefPtr<FrameNode> CreateStackNode(RefPtr<PickerTheme> pickerTheme);
73     static RefPtr<FrameNode> CreateColumnNode();
74     static RefPtr<FrameNode> CreateButtonNode();
75     static RefPtr<FrameNode> CreateColumnNode(uint32_t columnKind,
76         uint32_t showCount, RefPtr<PickerTheme> pickerTheme);
77     static RefPtr<FrameNode> CreateIconItemNode(RefPtr<PickerTheme> pickerTheme);
78     static RefPtr<FrameNode> CreateTextItemNode(RefPtr<PickerTheme> pickerTheme);
79     static RefPtr<FrameNode> CreateMixtureItemNode(RefPtr<PickerTheme> pickerTheme);
80     static void SetTextProperties(const RefPtr<PickerTheme>& pickerTheme,
81         const PickerTextProperties& properties);
82     static void OptionsCreateNode(const RefPtr<TextPickerPattern>& textPickerPattern,
83         const TextPickerSettingData& settingData, const RefPtr<FrameNode>& textPickerNode,
84         uint32_t showCount, uint32_t columnCount, RefPtr<PickerTheme> pickerTheme);
85     static void OptionsShowInternal(const RefPtr<TextPickerPattern>& textPickerPattern,
86         const TextPickerSettingData& settingData, const RefPtr<FrameNode>& textPickerNode,
87         uint32_t showCount, RefPtr<PickerTheme> pickerTheme);
88     static void InitOnKeyEvent(const RefPtr<FocusHub>& focusHub);
89     static bool OnKeyEvent(const KeyEvent& event);
90     static void UpdateButtonConfirmLayoutProperty(const RefPtr<FrameNode>& buttonConfirmNode,
91         RefPtr<PickerTheme> pickerTheme);
92     static void UpdateButtonCancelLayoutProperty(const RefPtr<FrameNode>& buttonCancelNode,
93         const RefPtr<PipelineContext>& pipeline);
94     static void UpdateButtonForwardLayoutProperty(const RefPtr<FrameNode>& buttonCancelNode,
95         const RefPtr<PipelineContext>& pipeline);
96     static void UpdateButtonBackwardLayoutProperty(const RefPtr<FrameNode>& buttonCancelNode,
97         const RefPtr<PipelineContext>& pipeline);
98     static void UpdateConfirmButtonTextLayoutProperty(
99         const RefPtr<FrameNode>& textConfirmNode, const RefPtr<PickerTheme>& pickerTheme);
100     static void UpdateCancelButtonTextLayoutProperty(
101         const RefPtr<FrameNode>& textCancelNode, const RefPtr<PickerTheme>& pickerTheme);
102     static void UpdateForwardButtonTextLayoutProperty(
103         const RefPtr<FrameNode>& textCancelNode, const RefPtr<PickerTheme>& pickerTheme);
104     static void UpdateBackwardButtonTextLayoutProperty(
105         const RefPtr<FrameNode>& textCancelNode, const RefPtr<PickerTheme>& pickerTheme);
106     static void UpdateConfirmButtonMargin(
107         const RefPtr<FrameNode>& buttonConfirmNode, const RefPtr<DialogTheme>& dialogTheme);
108     static void UpdateCancelButtonMargin(
109         const RefPtr<FrameNode>& buttonCancelNode, const RefPtr<DialogTheme>& dialogTheme);
110     static void UpdateForwardButtonMargin(
111         const RefPtr<FrameNode>& buttonCancelNode, const RefPtr<DialogTheme>& dialogTheme);
112     static void UpdateBackwardButtonMargin(
113         const RefPtr<FrameNode>& buttonCancelNode, const RefPtr<DialogTheme>& dialogTheme);
114     static void UpdateButtonStyles(const std::vector<ButtonInfo>& buttonInfos, size_t index,
115         const RefPtr<ButtonLayoutProperty>& buttonLayoutProperty, const RefPtr<RenderContext>& buttonRenderContext);
116     static void UpdateButtonStyleAndRole(const std::vector<ButtonInfo>& buttonInfos, size_t index,
117         const RefPtr<ButtonLayoutProperty>& buttonLayoutProperty, const RefPtr<RenderContext>& buttonRenderContext,
118         const RefPtr<ButtonTheme>& buttonTheme);
119     static void UpdateButtonDefaultFocus(const std::vector<ButtonInfo>& buttonInfos,
120         const RefPtr<FrameNode>& buttonNode, bool isConfirm);
121     static void SetDialogNodePageActive(RefPtr<FrameNode>& contentRow, RefPtr<FrameNode>& textPickerNode,
122         const uint32_t& dialogNodePage, const uint32_t& showCount);
123     static RefPtr<FrameNode> SeparatedOptionsShow(RefPtr<FrameNode>& contentColumn, RefPtr<FrameNode>& textPickerNode,
124         const std::vector<ButtonInfo>& buttonInfos,
125         const TextPickerSettingData& settingData,
126         std::map<std::string, NG::DialogTextEvent>& dialogEvent,
127         std::map<std::string, NG::DialogGestureEvent>& dialogCancelEvent,
128         const float& scale, GestureEventFunc closeCallBack, RefPtr<FrameNode>& dialogNode);
129     static void SetDialogButtonActive(RefPtr<FrameNode>& contentColumn,
130         const uint32_t& dialogNodePage, const uint32_t& columnCount);
131     static void SetFirstDialogButtonActive(RefPtr<UINode>& contentRow);
132     static void SetSecondDialogButtonActive(RefPtr<UINode>& contentRow);
133     static void SetThirdDialogButtonActive(RefPtr<UINode>& contentRow);
134     static std::function<void()> CloseDialogEvent(const RefPtr<TextPickerPattern>& textPickerPattern,
135         const RefPtr<FrameNode>& dialogNode);
136 
137     static void SetDividerNodeActive(RefPtr<UINode>& contentRow, bool firstDivider,
138         bool secondDivider, bool thirdDivider);
139     static void SetSingleDividerNodeActive(RefPtr<FrameNode>& dividerNode, bool dividerActive);
140     static const Dimension ConvertFontSizeLimit(const Dimension& fontSizeValue,
141         const Dimension& fontSizeLimit, bool isUserSetFont = false);
142     static const Dimension ConvertFontScaleValue(const Dimension& fontSizeValue,
143         const Dimension& fontSizeLimit = 0.0_vp, bool isUserSetFont = false);
144     static const Dimension AdjustFontSizeScale(const Dimension& fontSizeValue, double fontScale);
145     static void GetUserSettingLimit();
146     static bool NeedAdaptForAging();
147     static void SetTextDisappearProperties(const RefPtr<PickerTheme>& pickerTheme,
148         const PickerTextProperties& properties);
149     static WeakPtr<FrameNode> dialogNode_;
150     static uint32_t dialogNodePage_;
151     static Dimension selectedTextStyleFont_;
152     static Dimension normalTextStyleFont_;
153     static Dimension disappearTextStyleFont_;
154 
155 };
156 } // namespace OHOS::Ace::NG
157 
158 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_PICKER_TEXT_PICKER_DIALOG_VIEW_H
159