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