• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_ACE_ENGINE_FRAMEWORKS_CORE_COMPONENTS_COMMON_PROPERTIES_DIALOG_PROPERTIES_H
17 #define FOUNDATION_ACE_ACE_ENGINE_FRAMEWORKS_CORE_COMPONENTS_COMMON_PROPERTIES_DIALOG_PROPERTIES_H
18 
19 #include <cstdint>
20 
21 #include "base/geometry/dimension_offset.h"
22 #include "core/components/common/properties/color.h"
23 #include "core/components_ng/event/click_event.h"
24 #include "core/event/ace_event_handler.h"
25 #include "core/gestures/gesture_info.h"
26 #include "core/pipeline/base/component.h"
27 
28 namespace OHOS::Ace {
29 
30 enum class DialogType {
31     COMMON = 0,
32     ALERT_DIALOG,
33     ACTION_SHEET,
34 };
35 
36 // Alignment of dialog in vertical.
37 enum class DialogAlignment {
38     TOP = 0,
39     CENTER,
40     BOTTOM,
41     DEFAULT,
42     TOP_START,
43     TOP_END,
44     CENTER_START,
45     CENTER_END,
46     BOTTOM_START,
47     BOTTOM_END,
48 };
49 
50 class DialogAlignmentUtils {
51 public:
ConvertDialogAlignmentToString(DialogAlignment dialogAlignment)52     static std::string ConvertDialogAlignmentToString(DialogAlignment dialogAlignment)
53     {
54         std::string Alignment = "";
55         switch (dialogAlignment) {
56             case DialogAlignment::TOP:
57                 Alignment = "DialogAlignment.TOP";
58                 break;
59             case DialogAlignment::CENTER:
60                 Alignment = "DialogAlignment.CENTER";
61                 break;
62             case DialogAlignment::BOTTOM:
63                 Alignment = "DialogAlignment.BOTTOM";
64                 break;
65             case DialogAlignment::TOP_START:
66                 Alignment = "DialogAlignment.TOP_START";
67                 break;
68             case DialogAlignment::TOP_END:
69                 Alignment = "DialogAlignment.TOP_END";
70                 break;
71             case DialogAlignment::CENTER_START:
72                 Alignment = "DialogAlignment.CENTER_START";
73                 break;
74             case DialogAlignment::CENTER_END:
75                 Alignment = "DialogAlignment.CENTER_END";
76                 break;
77             case DialogAlignment::BOTTOM_START:
78                 Alignment = "DialogAlignment.BOTTOM_START";
79                 break;
80             case DialogAlignment::BOTTOM_END:
81                 Alignment = "DialogAlignment.BOTTOM_END";
82                 break;
83             default:
84                 Alignment = "DialogAlignment.DEFAULT";
85         }
86         return Alignment;
87     }
88 };
89 
90 // Information of ActionSheet
91 struct ActionSheetInfo {
92     std::string title;             // title of ActionSheet, necessary.
93     std::string icon;              // icon of ActionSheet, not necessary.
94     EventMarker callbackId;        // called when ActionSheet is clicked.
95     RefPtr<Gesture> gesture;       // called when ActionSheet is clicked.
96     RefPtr<NG::ClickEvent> action; // NG sheet item click action
97 
98     // Whether sheetInfo is valid, valid if title if not empty.
IsValidActionSheetInfo99     bool IsValid() const
100     {
101         return !title.empty();
102     }
103 };
104 
105 // Information of Button.
106 struct ButtonInfo {
107     std::string text;      // text of button.
108     std::string textColor; // style of text in button.
109     bool isBgColorSetted = false;
110     Color bgColor;                 // background color of button.
111     RefPtr<NG::ClickEvent> action; // NG button click action
112 
113     // Whether button info is valid, valid if text is not empty.
IsValidButtonInfo114     bool IsValid() const
115     {
116         return !text.empty();
117     }
118 };
119 
120 struct DialogProperties {
121     DialogType type = DialogType::COMMON; // type of dialog, current support common dialog and alert dialog.
122     std::string title;                    // title of dialog.
123     std::string content;                  // message of dialog.
124     bool autoCancel = true;               // pop dialog when click mask if autoCancel is true.
125     bool customStyle = false;             // when true, dialog doesn't paint background or constraint child size.
126     bool isMenu = false;
127     std::vector<ButtonInfo> buttons;
128     std::unordered_map<std::string, EventMarker> callbacks; // <callback type(success, cancel, complete), eventId>
129     std::function<void()> onCancel;                         // NG cancel callback
130     std::function<void(int32_t, int32_t)> onSuccess;        // NG prompt success callback
131     DialogAlignment alignment = DialogAlignment::DEFAULT;   // Alignment of dialog.
132     DimensionOffset offset;                                 // Offset which base on alignment of Dialog.
133     int32_t gridCount = -1;
134     std::optional<Color> maskColor;
135     std::optional<AnimationOption> openAnimation;
136     std::optional<AnimationOption> closeAnimation;
137     bool isShowInSubWindow = false;
138 
139     // These ids is used for AlertDialog of declarative.
140     EventMarker primaryId;   // first button's callback.
141     EventMarker secondaryId; // second button's callback.
142 
143     // These attributes is used for CustomDialog.
144     RefPtr<Component> customComponent;         // Used for CustomDialog in declarative.
145     std::function<void(bool)> onStatusChanged; // Called when dialog appear or disappear.
146 
147     // These attributes is used for ActionSheet.
148     std::vector<ActionSheetInfo> sheetsInfo;
149 };
150 
151 } // namespace OHOS::Ace
152 
153 #endif // FOUNDATION_ACE_ACE_ENGINE_FRAMEWORKS_CORE_COMPONENTS_COMMON_PROPERTIES_DIALOG_PROPERTIES_H
154