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