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 Enumerates the level mode. 44 * 45 * @since 16 46 */ 47 typedef enum { 48 /** overlay mode. */ 49 ARKUI_LEVEL_MODE_OVERLAY = 0, 50 /** embedded mode. */ 51 ARKUI_LEVEL_MODE_EMBEDDED, 52 } ArkUI_LevelMode; 53 54 /** 55 * @brief Enumerates the immersive mode. 56 * 57 * @since 16 58 */ 59 typedef enum { 60 /** Mask covering the parent node. */ 61 ARKUI_IMMERSIVE_MODE_DEFAULT = 0, 62 /** Mask extend safe area includes status bar and navigation bar. */ 63 ARKUI_IMMERSIVE_MODE_EXTEND, 64 } ArkUI_ImmersiveMode; 65 66 /** 67 * @brief Invoked when the dialog box is closed. 68 * 69 * @since 12 70 */ 71 typedef bool (*ArkUI_OnWillDismissEvent)(int32_t reason); 72 73 /** 74 * @brief Defines a struct for a dialog box dismiss event. 75 * 76 * @since 12 77 */ 78 typedef struct ArkUI_DialogDismissEvent ArkUI_DialogDismissEvent; 79 80 /** 81 * @brief Provides the custom dialog box APIs for the native side. 82 * 83 * @version 1 84 * @since 12 85 */ 86 typedef struct { 87 /** 88 * @brief Creates a custom dialog box and returns the pointer to the created dialog box. 89 * 90 * @note This method must be called before the <b>show</b> method. 91 * @return Returns the pointer to the created custom dialog box; returns a null pointer if the creation fails. 92 */ 93 ArkUI_NativeDialogHandle (*create)(); 94 /** 95 * @brief Destroys a custom dialog box. 96 * 97 * @param handle Indicates the pointer to the custom dialog box controller. 98 */ 99 void (*dispose)(ArkUI_NativeDialogHandle handle); 100 /** 101 * @brief Attaches the content of a custom dialog box. 102 * 103 * @note This method must be called before the <b>show</b> method. 104 * @param handle Indicates the pointer to the custom dialog box controller. 105 * @param content Indicates the pointer to the root node of the custom dialog box content. 106 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 107 */ 108 int32_t (*setContent)(ArkUI_NativeDialogHandle handle, ArkUI_NodeHandle content); 109 /** 110 * @brief Detaches the content of a custom dialog box. 111 * 112 * @note This method must be called before the <b>show</b> method. 113 * @param handle Indicates the pointer to the custom dialog box controller. 114 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 115 */ 116 int32_t (*removeContent)(ArkUI_NativeDialogHandle handle); 117 /** 118 * @brief Sets the alignment mode for a custom dialog box. 119 * 120 * @note This method must be called before the <b>show</b> method. 121 * @param handle Indicates the pointer to the custom dialog box controller. 122 * @param alignment Indicates the alignment mode. The parameter type is {@link ArkUI_Alignment}. 123 * @param offsetX Indicates the horizontal offset of the custom dialog box. The value is a floating point number. 124 * @param offsetY Indicates the vertical offset of the custom dialog box. The value is a floating point number. 125 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 126 */ 127 int32_t (*setContentAlignment)(ArkUI_NativeDialogHandle handle, int32_t alignment, float offsetX, float offsetY); 128 /** 129 * @brief Resets the alignment mode of a custom dialog box to its default settings. 130 * 131 * @note This method must be called before the <b>show</b> method. 132 * @param handle Indicates the pointer to the custom dialog box controller. 133 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 134 */ 135 int32_t (*resetContentAlignment)(ArkUI_NativeDialogHandle handle); 136 /** 137 * @brief Sets the modal mode for a custom dialog box. 138 * 139 * @note This method must be called before the <b>show</b> method. 140 * @param handle Indicates the pointer to the custom dialog box controller. 141 * @param isModal Specifies whether the custom dialog box is a modal, which has a mask applied. The value 142 * <b>true</b> means that the custom dialog box is a modal, and <b>false</b> means the opposite. 143 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 144 */ 145 int32_t (*setModalMode)(ArkUI_NativeDialogHandle handle, bool isModal); 146 /** 147 * @brief Specifies whether to allow users to touch the mask to dismiss the custom dialog box. 148 * 149 * @note This method must be called before the <b>show</b> method. 150 * @param handle Indicates the pointer to the custom dialog box controller. 151 * @param autoCancel Specifies whether to allow users to touch the mask to dismiss the dialog box. 152 * The value <b>true</b> means to allow users to do so, and <b>false</b> means the opposite. 153 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 154 */ 155 int32_t (*setAutoCancel)(ArkUI_NativeDialogHandle handle, bool autoCancel); 156 /** 157 * @brief Sets the mask for a custom dialog box. 158 * 159 * @note This method must be called before the <b>show</b> method. 160 * @param handle Indicates the pointer to the custom dialog box controller. 161 * @param maskColor Indicates the mask color, in 0xARGB format. 162 * @param maskRect Indicates the pointer to the mask area. Events outside the mask area are transparently 163 * transmitted, and events within the mask area are not. The parameter type is {@link ArkUI_Rect}. 164 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 165 */ 166 int32_t (*setMask)(ArkUI_NativeDialogHandle handle, uint32_t maskColor, const ArkUI_Rect* maskRect); 167 /** 168 * @brief Sets the background color for a custom dialog box. 169 * 170 * @note This method must be called before the <b>show</b> method. 171 * @param handle Indicates the pointer to the custom dialog box controller. 172 * @param backgroundColor Indicates the background color of the custom dialog box, in 0xARGB format. 173 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 174 */ 175 int32_t (*setBackgroundColor)(ArkUI_NativeDialogHandle handle, uint32_t backgroundColor); 176 /** 177 * @brief Sets the background corner radius for a custom dialog box. 178 * 179 * @note This method must be called before the <b>show</b> method. 180 * @param handle Indicates the pointer to the custom dialog box controller. 181 * @param topLeft Indicates the radius of the upper left corner of the custom dialog box background. 182 * @param topRight Indicates the radius of the upper right corner of the custom dialog box background. 183 * @param bottomLeft Indicates the radius of the lower left corner of the custom dialog box background. 184 * @param bottomRight Indicates the radius of the lower right corner of the custom dialog box background. 185 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 186 */ 187 int32_t (*setCornerRadius)(ArkUI_NativeDialogHandle handle, float topLeft, float topRight, 188 float bottomLeft, float bottomRight); 189 /** 190 * @brief Sets the number of grid columns occupied by a custom dialog box. 191 * 192 * @note This method must be called before the <b>show</b> method. 193 * @param handle Indicates the pointer to the custom dialog box controller. 194 * @param gridCount Indicates the number of grid columns occupied by the dialog box. The default value is subject to 195 * the window size, and the maximum value is the maximum number of columns supported by the system. 196 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 197 */ 198 int32_t (*setGridColumnCount)(ArkUI_NativeDialogHandle handle, int32_t gridCount); 199 /** 200 * @brief Specifies whether to use a custom style for the custom dialog box. 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 enableCustomStyle Specifies whether to use a custom style for the dialog box. 205 * <b>true</b>: The dialog box automatically adapts its width to the child components; the rounded corner is 0; 206 * the background color is transparent. 207 * <b>false</b>: The dialog box automatically adapts its width to the grid system and its height to the child 208 * components; the rounded corner is 24 vp. 209 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 210 */ 211 int32_t (*enableCustomStyle)(ArkUI_NativeDialogHandle handle, bool enableCustomStyle); 212 /** 213 * @brief Specifies whether to use a custom animation for a custom dialog box. 214 * 215 * @note This method must be called before the <b>show</b> method. 216 * @param handle Indicates the pointer to the custom dialog box controller. 217 * @param enableCustomAnimation Specifies whether to use a custom animation. The value <b>true</b> means to use a 218 * custom animation, and <b>false</b> means to use the default animation. 219 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 220 */ 221 int32_t (*enableCustomAnimation)(ArkUI_NativeDialogHandle handle, bool enableCustomAnimation); 222 /** 223 * @brief Registers a callback for a custom dialog box so that the user can decide whether to close the dialog box 224 * after they touch the Back button or press the Esc key. 225 * 226 * @note This method must be called before the <b>show</b> method. 227 * @param handle Indicates the pointer to the custom dialog box controller. 228 * @param eventHandler Indicates the callback to register. The parameter type is {@link ArkUI_OnWillDismissEvent}. 229 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 230 */ 231 int32_t (*registerOnWillDismiss)(ArkUI_NativeDialogHandle handle, ArkUI_OnWillDismissEvent eventHandler); 232 /** 233 * @brief Shows a custom dialog box. 234 * 235 * @param handle Indicates the pointer to the custom dialog box controller. 236 * @param showInSubWindow Specifies whether to show the dialog box in a sub-window. 237 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 238 */ 239 int32_t (*show)(ArkUI_NativeDialogHandle handle, bool showInSubWindow); 240 /** 241 * @brief Closes a custom dialog box. If the dialog box has been closed, this API does not take effect. 242 * 243 * @param handle Indicates the pointer to the custom dialog box controller. 244 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 245 */ 246 int32_t (*close)(ArkUI_NativeDialogHandle handle); 247 248 /** 249 * @brief Registers a listener for the dismiss event of the custom dialog box. 250 * 251 * @param handle Indicates the pointer to the custom dialog box controller. 252 * @param userData Indicates the pointer to the custom data. 253 * @param callback Indicates the callback for the dismiss event of the custom dialog box. 254 * @return Returns the result code. 255 * Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if the operation is successful. 256 * Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter error occurs. 257 */ 258 int32_t (*registerOnWillDismissWithUserData)( 259 ArkUI_NativeDialogHandle handle, void* userData, void (*callback)(ArkUI_DialogDismissEvent* event)); 260 } ArkUI_NativeDialogAPI_1; 261 262 /** 263 * @brief Provides the custom dialog box APIs for the native side. 264 * 265 * @version 2 266 * @since 16 267 */ 268 typedef struct { 269 ArkUI_NativeDialogAPI_1 nativeDialogAPI1; 270 /** 271 * @brief Defines the distance between the customDialog and system keyboard. 272 * 273 * @note This method must be called before the <b>show</b> method. 274 * @param handle Indicates the pointer to the custom dialog box controller. 275 * @param distance distance, in vp. 276 * @param unit Indicates the unit, which is an enumerated value of {@link ArkUI_LengthMetricUnit} 277 * @return Returns the result code. 278 * Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if the operation is successful. 279 * Returns {@link ARKUI_ERROR_CODE_CAPI_INIT_ERROR} if the CAPI init error. 280 * Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter error occurs. 281 * @since 16 282 */ 283 int32_t (*setKeyboardAvoidDistance)(ArkUI_NativeDialogHandle handle, float distance, ArkUI_LengthMetricUnit unit); 284 285 /** 286 * @brief Sets the level mode for a custom dialog box. 287 * 288 * @note This method must be called before the <b>show</b> method. 289 * @param handle Indicates the pointer to the custom dialog box controller. 290 * @param levelMode Indicates the level mode. The parameter type is {@link ArkUI_LevelMode}. 291 * @return Returns the error code. 292 * Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if the operation is successful. 293 * Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter error occurs. 294 * @since 16 295 */ 296 int32_t (*setLevelMode)(ArkUI_NativeDialogHandle handle, ArkUI_LevelMode levelMode); 297 298 /** 299 * @brief Sets the level uniqueId for a custom dialog box. 300 * 301 * @note This method must be called before the <b>setLevelMode</b> method. 302 * @param handle Indicates the pointer to the custom dialog box controller. 303 * @param uniqueId Indicates the unique id of any nodes in router or navigation pages. 304 * @return Returns the error code. 305 * Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if the operation is successful. 306 * Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter error occurs. 307 * @since 16 308 */ 309 int32_t (*setLevelUniqueId)(ArkUI_NativeDialogHandle handle, int32_t uniqueId); 310 311 /** 312 * @brief Sets the immersive mode for a custom dialog box. 313 * 314 * @note This method must be called before the <b>show</b> method. 315 * @param handle Indicates the pointer to the custom dialog box controller. 316 * @param immersiveMode Indicates the immersive mode. The parameter type is {@link ArkUI_ImmersiveMode}. 317 * @return Returns the error code. 318 * Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if the operation is successful. 319 * Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter error occurs. 320 * @since 16 321 */ 322 int32_t (*setImmersiveMode)(ArkUI_NativeDialogHandle handle, ArkUI_ImmersiveMode immersiveMode); 323 } ArkUI_NativeDialogAPI_2; 324 325 /** 326 * @brief Sets whether to block the system behavior of dismissing a dialog box. 327 * 328 * @param event Indicates the pointer to a dialog box dismiss event object. 329 * @param shouldBlockDismiss Indicates whether to block the system behavior of dismissing the dialog box. The value 330 * <b>true</b> means to block the system behavior, and <b>false</b> means the opposite. 331 * @since 12 332 */ 333 void OH_ArkUI_DialogDismissEvent_SetShouldBlockDismiss(ArkUI_DialogDismissEvent* event, bool shouldBlockDismiss); 334 335 /** 336 * @brief Obtains the pointer to user data in a dialog box dismiss event object. 337 * 338 * @param event Indicates the pointer to a dialog box dismiss event object. 339 * 340 * @return Returns the pointer to user data. 341 * @since 12 342 */ 343 void* OH_ArkUI_DialogDismissEvent_GetUserData(ArkUI_DialogDismissEvent* event); 344 345 /** 346 * @brief Obtains the c from a dialog box dismiss event object. 347 * 348 * @param event Indicates the pointer to a dialog box dismiss event object. 349 * 350 * @return Returns the dismissal reason. Returns <b>-1</b> if an exception occurs. 351 * {@link DIALOG_DISMISS_BACK_PRESS}: touching the Back button, swiping left or right on the screen, or 352 * pressing the Esc key. 353 * {@link DIALOG_DISMISS_TOUCH_OUTSIDE}: touching the mask. 354 * {@link DIALOG_DISMISS_CLOSE_BUTTON}: touching the Close button. 355 * {@link DIALOG_DISMISS_SLIDE_DOWN}: sliding down. 356 * @since 12 357 */ 358 359 int32_t OH_ArkUI_DialogDismissEvent_GetDismissReason(ArkUI_DialogDismissEvent* event); 360 #ifdef __cplusplus 361 }; 362 #endif 363 364 #endif // ARKUI_NATIVE_DIALOG_H 365