• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_BASE_PROPERTIES_POPUP_PARAM_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_POPUP_PARAM_H
18 
19 #include <string>
20 
21 #include "base/geometry/dimension.h"
22 #include "core/components/common/properties/border.h"
23 #include "core/components/common/properties/color.h"
24 #include "core/components/common/properties/edge.h"
25 #include "core/components/common/properties/placement.h"
26 #include "core/event/ace_event_handler.h"
27 #include "core/event/touch_event.h"
28 
29 namespace OHOS::Ace {
30 
31 struct ButtonProperties {
32     bool showButton = false;
33     std::string value;
34     EventMarker actionId;
35     //  touchFunc used in Declarative mode.
36     TouchEventFunc touchFunc;
37     RefPtr<NG::ClickEvent> action; // button click action
38 };
39 
40 using StateChangeFunc = std::function<void(const std::string&)>;
41 
42 class PopupParam : public AceType {
43     DECLARE_ACE_TYPE(PopupParam, AceType)
44 
45 public:
46     PopupParam() = default;
47     ~PopupParam() override = default;
48 
SetIsShow(bool isShow)49     void SetIsShow(bool isShow)
50     {
51         isShow_ = isShow;
52     }
53 
IsShow()54     bool IsShow() const
55     {
56         return isShow_;
57     }
58 
SetHasAction(bool hasAction)59     void SetHasAction(bool hasAction)
60     {
61         hasAction_ = hasAction;
62     }
63 
HasAction()64     bool HasAction() const
65     {
66         return hasAction_;
67     }
68 
SetPlacement(const Placement & placement)69     void SetPlacement(const Placement& placement)
70     {
71         placement_ = placement;
72     }
73 
SetMaskColor(const Color & maskColor)74     void SetMaskColor(const Color& maskColor)
75     {
76         maskColor_ = maskColor;
77         isMaskColorSetted_ = true;
78     }
79 
SetBackgroundColor(const Color & backgroundColor)80     void SetBackgroundColor(const Color& backgroundColor)
81     {
82         backgroundColor_ = backgroundColor;
83         isBackgroundColorSetted_ = true;
84     }
85 
SetOnVisibilityChange(const EventMarker & onVisibilityChange)86     void SetOnVisibilityChange(const EventMarker& onVisibilityChange)
87     {
88         onVisibilityChange_ = onVisibilityChange;
89     }
90 
GetPlacement()91     Placement GetPlacement() const
92     {
93         return placement_;
94     }
95 
GetMaskColor()96     const Color& GetMaskColor() const
97     {
98         return maskColor_;
99     }
100 
GetBackgroundColor()101     const Color& GetBackgroundColor() const
102     {
103         return backgroundColor_;
104     }
105 
GetOnVisibilityChange()106     const EventMarker& GetOnVisibilityChange() const
107     {
108         return onVisibilityChange_;
109     }
110 
GetMargin()111     const Edge& GetMargin() const
112     {
113         return margin_;
114     }
115 
SetMargin(const Edge & margin)116     void SetMargin(const Edge& margin)
117     {
118         margin_ = margin;
119     }
120 
GetTargetMargin()121     const Edge& GetTargetMargin() const
122     {
123         return targetMargin_;
124     }
125 
SetTargetMargin(const Edge & targetMargin)126     void SetTargetMargin(const Edge& targetMargin)
127     {
128         targetMargin_ = targetMargin;
129     }
130 
GetPadding()131     const Edge& GetPadding() const
132     {
133         return padding_;
134     }
135 
SetPadding(const Edge & padding)136     void SetPadding(const Edge& padding)
137     {
138         padding_ = padding;
139     }
140 
GetBorder()141     const Border& GetBorder() const
142     {
143         return border_;
144     }
145 
SetBorder(const Border & border)146     void SetBorder(const Border& border)
147     {
148         border_ = border;
149     }
150 
GetArrowOffset()151     const std::optional<Dimension>& GetArrowOffset() const
152     {
153         return arrowOffset_;
154     }
155 
SetArrowOffset(const std::optional<Dimension> & arrowOffset)156     void SetArrowOffset(const std::optional<Dimension>& arrowOffset)
157     {
158         arrowOffset_ = arrowOffset;
159     }
160 
GetTargetId()161     const ComposeId& GetTargetId() const
162     {
163         return targetId_;
164     }
165 
SetTargetId(const ComposeId & targetId)166     void SetTargetId(const ComposeId& targetId)
167     {
168         targetId_ = targetId;
169     }
170 
IsMaskColorSetted()171     bool IsMaskColorSetted() const
172     {
173         return isMaskColorSetted_;
174     }
175 
IsBackgroundColorSetted()176     bool IsBackgroundColorSetted() const
177     {
178         return isBackgroundColorSetted_;
179     }
180 
EnableArrow()181     bool EnableArrow() const
182     {
183         return enableArrow_;
184     }
185 
SetEnableArrow(bool enableArrow)186     void SetEnableArrow(bool enableArrow)
187     {
188         enableArrow_ = enableArrow;
189     }
190 
IsBlockEvent()191     bool IsBlockEvent() const
192     {
193         return blockEvent_;
194     }
195 
SetBlockEvent(bool blockEvent)196     void SetBlockEvent(bool blockEvent)
197     {
198         blockEvent_ = blockEvent;
199     }
200 
IsUseCustom()201     bool IsUseCustom() const
202     {
203         return useCustom_;
204     }
205 
SetUseCustomComponent(bool useCustom)206     void SetUseCustomComponent(bool useCustom)
207     {
208         useCustom_ = useCustom;
209     }
210 
GetTargetSpace()211     const Dimension& GetTargetSpace() const
212     {
213         return targetSpace_;
214     }
215 
SetTargetSpace(const Dimension & targetSpace)216     void SetTargetSpace(const Dimension& targetSpace)
217     {
218         targetSpace_ = targetSpace;
219     }
220 
SetMessage(const std::string & msg)221     void SetMessage(const std::string& msg)
222     {
223         message_ = msg;
224     }
225 
GetMessage()226     std::string GetMessage() const
227     {
228         return message_;
229     }
230 
GetOnStateChange()231     StateChangeFunc GetOnStateChange()
232     {
233         return onStateChange_;
234     }
235 
SetOnStateChange(StateChangeFunc && onStateChange)236     void SetOnStateChange(StateChangeFunc&& onStateChange)
237     {
238         onStateChange_ = onStateChange;
239     }
240 
SetPrimaryButtonProperties(const ButtonProperties & prop)241     void SetPrimaryButtonProperties(const ButtonProperties& prop)
242     {
243         primaryButtonProperties_ = prop;
244     }
245 
SetSecondaryButtonProperties(const ButtonProperties & prop)246     void SetSecondaryButtonProperties(const ButtonProperties& prop)
247     {
248         secondaryButtonProperties_ = prop;
249     }
250 
GetPrimaryButtonProperties()251     const ButtonProperties& GetPrimaryButtonProperties() const
252     {
253         return primaryButtonProperties_;
254     }
255 
GetSecondaryButtonProperties()256     const ButtonProperties& GetSecondaryButtonProperties() const
257     {
258         return secondaryButtonProperties_;
259     }
260 
SetShowInSubWindow(bool isShowInSubWindow)261     void SetShowInSubWindow(bool isShowInSubWindow)
262     {
263         isShowInSubWindow_ = isShowInSubWindow;
264     }
265 
IsShowInSubWindow()266     bool IsShowInSubWindow() const
267     {
268         return isShowInSubWindow_;
269     }
270 
SetTargetSize(const Size & targetSize)271     void SetTargetSize(const Size& targetSize)
272     {
273         targetSize_ = targetSize;
274     }
275 
GetTargetSize()276     const Size& GetTargetSize() const
277     {
278         return targetSize_;
279     }
280 
SetTargetOffset(const Offset & targetOffset)281     void SetTargetOffset(const Offset& targetOffset)
282     {
283         targetOffset_ = targetOffset;
284     }
285 
GetTargetOffset()286     const Offset& GetTargetOffset() const
287     {
288         return targetOffset_;
289     }
290 
291 private:
292     bool isShow_ = true;
293     bool hasAction_ = false;
294     bool enableArrow_ = true;
295     bool isMaskColorSetted_ = false;
296     bool isBackgroundColorSetted_ = false;
297     bool useCustom_ = false;
298     bool isShowInSubWindow_ = false;
299     bool blockEvent_ = true;
300     Color maskColor_;
301     Color backgroundColor_;
302     Placement placement_ = Placement::BOTTOM;
303     EventMarker onVisibilityChange_;
304     Edge padding_;
305     Edge margin_;
306     Edge targetMargin_;
307     Border border_;
308     std::optional<Dimension> arrowOffset_;
309     ComposeId targetId_;
310     Dimension targetSpace_;
311     std::string message_;
312     Offset targetOffset_;
313     Size targetSize_;
314 
315     // Used in NG mode
316     StateChangeFunc onStateChange_;
317     ButtonProperties primaryButtonProperties_;   // first button.
318     ButtonProperties secondaryButtonProperties_; // second button.
319 };
320 
321 } // namespace OHOS::Ace
322 
323 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_POPUP_PARAM_H
324