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/components_ng/property/border_property.h" 25 #include "core/event/ace_event_handler.h" 26 #include "core/gestures/gesture_info.h" 27 #include "core/pipeline/base/component.h" 28 29 namespace OHOS::Ace { 30 31 enum class DialogType { 32 COMMON = 0, 33 ALERT_DIALOG, 34 ACTION_SHEET, 35 CHECKBOX_DIALOG, 36 PROGRESS_DIALOG, 37 }; 38 39 enum class DialogButtonStyle { 40 DEFAULT = 0, 41 HIGHTLIGHT, 42 }; 43 44 // Alignment of dialog in vertical. 45 enum class DialogAlignment { 46 TOP = 0, 47 CENTER, 48 BOTTOM, 49 DEFAULT, 50 TOP_START, 51 TOP_END, 52 CENTER_START, 53 CENTER_END, 54 BOTTOM_START, 55 BOTTOM_END, 56 }; 57 58 // Direction of buttons in dialog 59 enum class DialogButtonDirection { 60 AUTO = 0, 61 HORIZONTAL, 62 VERTICAL, 63 }; 64 65 class DialogAlignmentUtils { 66 public: ConvertDialogAlignmentToString(DialogAlignment dialogAlignment)67 static std::string ConvertDialogAlignmentToString(DialogAlignment dialogAlignment) 68 { 69 std::string Alignment = ""; 70 switch (dialogAlignment) { 71 case DialogAlignment::TOP: 72 Alignment = "DialogAlignment.TOP"; 73 break; 74 case DialogAlignment::CENTER: 75 Alignment = "DialogAlignment.CENTER"; 76 break; 77 case DialogAlignment::BOTTOM: 78 Alignment = "DialogAlignment.BOTTOM"; 79 break; 80 case DialogAlignment::TOP_START: 81 Alignment = "DialogAlignment.TOP_START"; 82 break; 83 case DialogAlignment::TOP_END: 84 Alignment = "DialogAlignment.TOP_END"; 85 break; 86 case DialogAlignment::CENTER_START: 87 Alignment = "DialogAlignment.CENTER_START"; 88 break; 89 case DialogAlignment::CENTER_END: 90 Alignment = "DialogAlignment.CENTER_END"; 91 break; 92 case DialogAlignment::BOTTOM_START: 93 Alignment = "DialogAlignment.BOTTOM_START"; 94 break; 95 case DialogAlignment::BOTTOM_END: 96 Alignment = "DialogAlignment.BOTTOM_END"; 97 break; 98 default: 99 Alignment = "DialogAlignment.DEFAULT"; 100 } 101 return Alignment; 102 } 103 }; 104 105 class DialogButtonDirectionUtils { 106 public: ConvertDialogButtonDirectionToString(DialogButtonDirection buttonDirection)107 static std::string ConvertDialogButtonDirectionToString(DialogButtonDirection buttonDirection) 108 { 109 std::string direction = ""; 110 switch (buttonDirection) { 111 case DialogButtonDirection::HORIZONTAL: 112 direction = "DialogButtonDirection.HORIZONTAL"; 113 break; 114 case DialogButtonDirection::VERTICAL: 115 direction = "DialogButtonDirection.VERTICAL"; 116 break; 117 default: 118 direction = "DialogButtonDirection.AUTO"; 119 } 120 return direction; 121 } 122 }; 123 124 // Information of ActionSheet 125 struct ActionSheetInfo { 126 std::string title; // title of ActionSheet, necessary. 127 std::string icon; // icon of ActionSheet, not necessary. 128 RefPtr<Gesture> gesture; // called when ActionSheet is clicked. 129 RefPtr<NG::ClickEvent> action; // NG sheet item click action 130 131 // Whether sheetInfo is valid, valid if title if not empty. IsValidActionSheetInfo132 bool IsValid() const 133 { 134 return !title.empty(); 135 } 136 }; 137 138 // Information of Button. 139 struct ButtonInfo { 140 std::string text; // text of button. 141 std::string textColor; // style of text in button. 142 bool isBgColorSetted = false; 143 Color bgColor; // background color of button. 144 RefPtr<NG::ClickEvent> action; // NG button click action 145 bool enabled = true; // status of enabled in button. 146 bool defaultFocus = false; // status of defaultFocus in button. 147 std::optional<DialogButtonStyle> dlgButtonStyle; // DialogButtonStyle of dialog. 148 149 // Whether button info is valid, valid if text is not empty. IsValidButtonInfo150 bool IsValid() const 151 { 152 return !text.empty(); 153 } 154 }; 155 156 struct DialogProperties { 157 DialogType type = DialogType::COMMON; // type of dialog, current support common dialog and alert dialog. 158 std::string title; // title of dialog. 159 std::string subtitle; // subtitle of dialog. 160 std::string content; // message of dialog. 161 std::string checkboxContent; // message of checkbox. 162 bool autoCancel = true; // pop dialog when click mask if autoCancel is true. 163 bool customStyle = false; // when true, dialog doesn't paint background or constraint child size. 164 bool isMenu = false; 165 bool isSelect = false; // init checkbox state 166 std::vector<ButtonInfo> buttons; 167 std::function<void()> onCancel; // NG cancel callback 168 std::function<void(int32_t, int32_t)> onSuccess; // NG prompt success callback 169 std::function<void(const bool)> onChange; // onChange success callback 170 DialogAlignment alignment = DialogAlignment::DEFAULT; // Alignment of dialog. 171 DimensionOffset offset; // Offset which base on alignment of Dialog. 172 int32_t gridCount = -1; 173 std::optional<Color> maskColor; 174 std::optional<Color> backgroundColor; 175 std::optional<NG::BorderRadiusProperty> borderRadius; 176 std::optional<AnimationOption> openAnimation; 177 std::optional<AnimationOption> closeAnimation; 178 bool isShowInSubWindow = false; 179 DialogButtonDirection buttonDirection = DialogButtonDirection::AUTO; 180 181 #ifndef NG_BUILD 182 std::unordered_map<std::string, EventMarker> callbacks; // <callback type(success, cancel, complete), eventId> 183 // These ids is used for AlertDialog of declarative. 184 EventMarker primaryId; // first button's callback. 185 EventMarker secondaryId; // second button's callback. 186 #endif 187 188 // These attributes is used for CustomDialog. 189 RefPtr<AceType> customComponent; // Used for CustomDialog in declarative. 190 std::function<void(bool)> onStatusChanged; // Called when dialog appear or disappear. 191 192 // These attributes is used for ActionSheet. 193 std::vector<ActionSheetInfo> sheetsInfo; 194 195 WeakPtr<NG::UINode> windowScene; 196 std::optional<DimensionRect> maskRect; 197 }; 198 199 struct PromptDialogAttr { 200 std::string title; 201 std::string message; 202 bool autoCancel = true; 203 204 std::optional<DialogAlignment> alignment; 205 std::optional<DimensionOffset> offset; 206 std::optional<DimensionRect> maskRect; 207 }; 208 209 } // namespace OHOS::Ace 210 211 #endif // FOUNDATION_ACE_ACE_ENGINE_FRAMEWORKS_CORE_COMPONENTS_COMMON_PROPERTIES_DIALOG_PROPERTIES_H 212