1 /* 2 * Copyright (c) 2024 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 ARKUI_NATIVE_DIALOG_H 17 #define ARKUI_NATIVE_DIALOG_H 18 19 #include <stdbool.h> 20 #include "native_type.h" 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 /** 27 * @brief Enumerates the actions for triggering closure of the dialog box. 28 * 29 * @since 12 30 */ 31 typedef enum { 32 /** Touching the system-defined Back button or pressing the Esc key. */ 33 DIALOG_DISMISS_BACK_PRESS = 0, 34 /** Touching the mask. */ 35 DIALOG_DISMISS_TOUCH_OUTSIDE, 36 /** 点击关闭按钮。*/ 37 DIALOG_DISMISS_CLOSE_BUTTON, 38 /** 下拉关闭。*/ 39 DIALOG_DISMISS_SLIDE_DOWN, 40 } ArkUI_DismissReason; 41 42 /** 43 * @brief Invoked when the dialog box is closed. 44 * 45 * @since 12 46 */ 47 typedef bool (*ArkUI_OnWillDismissEvent)(int32_t reason); 48 49 /** 50 * @brief Defines a struct for a dialog box dismiss event. 51 * 52 * @since 12 53 */ 54 typedef struct ArkUI_DialogDismissEvent ArkUI_DialogDismissEvent; 55 56 /** 57 * @brief Provides the custom dialog box APIs for the native side. 58 * 59 * @version 1 60 * @since 12 61 */ 62 typedef struct { 63 /** 64 * @brief Creates a custom dialog box and returns the pointer to the created dialog box. 65 * 66 * @note This method must be called before the <b>show</b> method. 67 * @return Returns the pointer to the created custom dialog box; returns a null pointer if the creation fails. 68 */ 69 ArkUI_NativeDialogHandle (*create)(); 70 /** 71 * @brief Destroys a custom dialog box. 72 * 73 * @param handle Indicates the pointer to the custom dialog box controller. 74 */ 75 void (*dispose)(ArkUI_NativeDialogHandle handle); 76 /** 77 * @brief Attaches the content of a custom dialog box. 78 * 79 * @note This method must be called before the <b>show</b> method. 80 * @param handle Indicates the pointer to the custom dialog box controller. 81 * @param content Indicates the pointer to the root node of the custom dialog box content. 82 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 83 */ 84 int32_t (*setContent)(ArkUI_NativeDialogHandle handle, ArkUI_NodeHandle content); 85 /** 86 * @brief Detaches the content of a custom dialog box. 87 * 88 * @note This method must be called before the <b>show</b> method. 89 * @param handle Indicates the pointer to the custom dialog box controller. 90 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 91 */ 92 int32_t (*removeContent)(ArkUI_NativeDialogHandle handle); 93 /** 94 * @brief Sets the alignment mode for a custom dialog box. 95 * 96 * @note This method must be called before the <b>show</b> method. 97 * @param handle Indicates the pointer to the custom dialog box controller. 98 * @param alignment Indicates the alignment mode. The parameter type is {@link ArkUI_Alignment}. 99 * @param offsetX Indicates the horizontal offset of the custom dialog box. The value is a floating point number. 100 * @param offsetY Indicates the vertical offset of the custom dialog box. The value is a floating point number. 101 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 102 */ 103 int32_t (*setContentAlignment)(ArkUI_NativeDialogHandle handle, int32_t alignment, float offsetX, float offsetY); 104 /** 105 * @brief Resets the alignment mode of a custom dialog box to its default settings. 106 * 107 * @note This method must be called before the <b>show</b> method. 108 * @param handle Indicates the pointer to the custom dialog box controller. 109 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 110 */ 111 int32_t (*resetContentAlignment)(ArkUI_NativeDialogHandle handle); 112 /** 113 * @brief Sets the modal mode for a custom dialog box. 114 * 115 * @note This method must be called before the <b>show</b> method. 116 * @param handle Indicates the pointer to the custom dialog box controller. 117 * @param isModal Specifies whether the custom dialog box is a modal, which has a mask applied. The value 118 * <b>true</b> means that the custom dialog box is a modal, and <b>false</b> means the opposite. 119 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 120 */ 121 int32_t (*setModalMode)(ArkUI_NativeDialogHandle handle, bool isModal); 122 /** 123 * @brief Specifies whether to allow users to touch the mask to dismiss the custom dialog box. 124 * 125 * @note This method must be called before the <b>show</b> method. 126 * @param handle Indicates the pointer to the custom dialog box controller. 127 * @param autoCancel Specifies whether to allow users to touch the mask to dismiss the dialog box. 128 * The value <b>true</b> means to allow users to do so, and <b>false</b> means the opposite. 129 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 130 */ 131 int32_t (*setAutoCancel)(ArkUI_NativeDialogHandle handle, bool autoCancel); 132 /** 133 * @brief Sets the mask for a custom dialog box. 134 * 135 * @note This method must be called before the <b>show</b> method. 136 * @param handle Indicates the pointer to the custom dialog box controller. 137 * @param maskColor Indicates the mask color, in 0xARGB format. 138 * @param maskRect Indicates the pointer to the mask area. Events outside the mask area are transparently 139 * transmitted, and events within the mask area are not. The parameter type is {@link ArkUI_Rect}. 140 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 141 */ 142 int32_t (*setMask)(ArkUI_NativeDialogHandle handle, uint32_t maskColor, const ArkUI_Rect* maskRect); 143 /** 144 * @brief Sets the background color for a custom dialog box. 145 * 146 * @note This method must be called before the <b>show</b> method. 147 * @param handle Indicates the pointer to the custom dialog box controller. 148 * @param backgroundColor Indicates the background color of the custom dialog box, in 0xARGB format. 149 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 150 */ 151 int32_t (*setBackgroundColor)(ArkUI_NativeDialogHandle handle, uint32_t backgroundColor); 152 /** 153 * @brief Sets the background corner radius for a custom dialog box. 154 * 155 * @note This method must be called before the <b>show</b> method. 156 * @param handle Indicates the pointer to the custom dialog box controller. 157 * @param topLeft Indicates the radius of the upper left corner of the custom dialog box background. 158 * @param topRight Indicates the radius of the upper right corner of the custom dialog box background. 159 * @param bottomLeft Indicates the radius of the lower left corner of the custom dialog box background. 160 * @param bottomRight Indicates the radius of the lower right corner of the custom dialog box background. 161 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 162 */ 163 int32_t (*setCornerRadius)(ArkUI_NativeDialogHandle handle, float topLeft, float topRight, 164 float bottomLeft, float bottomRight); 165 /** 166 * @brief Sets the number of grid columns occupied by a custom dialog box. 167 * 168 * @note This method must be called before the <b>show</b> method. 169 * @param handle Indicates the pointer to the custom dialog box controller. 170 * @param gridCount Indicates the number of grid columns occupied by the dialog box. The default value is subject to 171 * the window size, and the maximum value is the maximum number of columns supported by the system. 172 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 173 */ 174 int32_t (*setGridColumnCount)(ArkUI_NativeDialogHandle handle, int32_t gridCount); 175 /** 176 * @brief Specifies whether to use a custom style for the custom dialog box. 177 * 178 * @note This method must be called before the <b>show</b> method. 179 * @param handle Indicates the pointer to the custom dialog box controller. 180 * @param enableCustomStyle Specifies whether to use a custom style for the dialog box. 181 * <b>true</b>: The dialog box automatically adapts its width to the child components; the rounded corner is 0; 182 * the background color is transparent. 183 * <b>false</b>: The dialog box automatically adapts its width to the grid system and its height to the child 184 * components; the rounded corner is 24 vp. 185 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 186 */ 187 int32_t (*enableCustomStyle)(ArkUI_NativeDialogHandle handle, bool enableCustomStyle); 188 /** 189 * @brief Specifies whether to use a custom animation for a custom dialog box. 190 * 191 * @note This method must be called before the <b>show</b> method. 192 * @param handle Indicates the pointer to the custom dialog box controller. 193 * @param enableCustomAnimation Specifies whether to use a custom animation. The value <b>true</b> means to use a 194 * custom animation, and <b>false</b> means to use the default animation. 195 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 196 */ 197 int32_t (*enableCustomAnimation)(ArkUI_NativeDialogHandle handle, bool enableCustomAnimation); 198 /** 199 * @brief Registers a callback for a custom dialog box so that the user can decide whether to close the dialog box 200 * after they touch the Back button or press the Esc key. 201 * 202 * @note This method must be called before the <b>show</b> method. 203 * @param handle Indicates the pointer to the custom dialog box controller. 204 * @param eventHandler Indicates the callback to register. The parameter type is {@link ArkUI_OnWillDismissEvent}. 205 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 206 */ 207 int32_t (*registerOnWillDismiss)(ArkUI_NativeDialogHandle handle, ArkUI_OnWillDismissEvent eventHandler); 208 /** 209 * @brief Shows a custom dialog box. 210 * 211 * @param handle Indicates the pointer to the custom dialog box controller. 212 * @param showInSubWindow Specifies whether to show the dialog box in a sub-window. 213 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 214 */ 215 int32_t (*show)(ArkUI_NativeDialogHandle handle, bool showInSubWindow); 216 /** 217 * @brief Closes a custom dialog box. If the dialog box has been closed, this API does not take effect. 218 * 219 * @param handle Indicates the pointer to the custom dialog box controller. 220 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 221 */ 222 int32_t (*close)(ArkUI_NativeDialogHandle handle); 223 224 /** 225 * @brief Registers a listener for the dismiss event of the custom dialog box. 226 * 227 * @param handle Indicates the pointer to the custom dialog box controller. 228 * @param userData Indicates the pointer to the custom data. 229 * @param callback Indicates the callback for the dismiss event of the custom dialog box. 230 * @return Returns the result code. 231 * Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if the operation is successful. 232 * Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter error occurs. 233 */ 234 int32_t (*registerOnWillDismissWithUserData)( 235 ArkUI_NativeDialogHandle handle, void* userData, void (*callback)(ArkUI_DialogDismissEvent* event)); 236 } ArkUI_NativeDialogAPI_1; 237 238 /** 239 * @brief Sets whether to block the system behavior of dismissing a dialog box. 240 * 241 * @param event Indicates the pointer to a dialog box dismiss event object. 242 * @param shouldBlockDismiss Indicates whether to block the system behavior of dismissing the dialog box. The value 243 * <b>true</b> means to block the system behavior, and <b>false</b> means the opposite. 244 * @since 12 245 */ 246 void OH_ArkUI_DialogDismissEvent_SetShouldBlockDismiss(ArkUI_DialogDismissEvent* event, bool shouldBlockDismiss); 247 248 /** 249 * @brief Obtains the pointer to user data in a dialog box dismiss event object. 250 * 251 * @param event Indicates the pointer to a dialog box dismiss event object. 252 * 253 * @return Returns the pointer to user data. 254 * @since 12 255 */ 256 void* OH_ArkUI_DialogDismissEvent_GetUserData(ArkUI_DialogDismissEvent* event); 257 258 /** 259 * @brief Obtains the c from a dialog box dismiss event object. 260 * 261 * @param event Indicates the pointer to a dialog box dismiss event object. 262 * 263 * @return Returns the dismissal reason. Returns <b>-1</b> if an exception occurs. 264 * {@link DIALOG_DISMISS_BACK_PRESS}: touching the Back button, swiping left or right on the screen, or 265 * pressing the Esc key. 266 * {@link DIALOG_DISMISS_TOUCH_OUTSIDE}: touching the mask. 267 * {@link DIALOG_DISMISS_CLOSE_BUTTON}: touching the Close button. 268 * {@link DIALOG_DISMISS_SLIDE_DOWN}: sliding down. 269 * @since 12 270 */ 271 272 int32_t OH_ArkUI_DialogDismissEvent_GetDismissReason(ArkUI_DialogDismissEvent* event); 273 #ifdef __cplusplus 274 }; 275 #endif 276 277 #endif // ARKUI_NATIVE_DIALOG_H 278