123b3eb3cSopenharmony_ci/*
223b3eb3cSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
323b3eb3cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
423b3eb3cSopenharmony_ci * you may not use this file except in compliance with the License.
523b3eb3cSopenharmony_ci * You may obtain a copy of the License at
623b3eb3cSopenharmony_ci *
723b3eb3cSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
823b3eb3cSopenharmony_ci *
923b3eb3cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1023b3eb3cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1123b3eb3cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1223b3eb3cSopenharmony_ci * See the License for the specific language governing permissions and
1323b3eb3cSopenharmony_ci * limitations under the License.
1423b3eb3cSopenharmony_ci */
1523b3eb3cSopenharmony_ci
1623b3eb3cSopenharmony_ci#ifndef ARKUI_NATIVE_DIALOG_H
1723b3eb3cSopenharmony_ci#define ARKUI_NATIVE_DIALOG_H
1823b3eb3cSopenharmony_ci
1923b3eb3cSopenharmony_ci#include <stdbool.h>
2023b3eb3cSopenharmony_ci#include "native_type.h"
2123b3eb3cSopenharmony_ci
2223b3eb3cSopenharmony_ci#ifdef __cplusplus
2323b3eb3cSopenharmony_ciextern "C" {
2423b3eb3cSopenharmony_ci#endif
2523b3eb3cSopenharmony_ci
2623b3eb3cSopenharmony_ci/**
2723b3eb3cSopenharmony_ci * @brief Enumerates the actions for triggering closure of the dialog box.
2823b3eb3cSopenharmony_ci *
2923b3eb3cSopenharmony_ci * @since 12
3023b3eb3cSopenharmony_ci */
3123b3eb3cSopenharmony_citypedef enum {
3223b3eb3cSopenharmony_ci    /** Touching the system-defined Back button or pressing the Esc key. */
3323b3eb3cSopenharmony_ci    DIALOG_DISMISS_BACK_PRESS = 0,
3423b3eb3cSopenharmony_ci    /** Touching the mask. */
3523b3eb3cSopenharmony_ci    DIALOG_DISMISS_TOUCH_OUTSIDE,
3623b3eb3cSopenharmony_ci    /** 点击关闭按钮。*/
3723b3eb3cSopenharmony_ci    DIALOG_DISMISS_CLOSE_BUTTON,
3823b3eb3cSopenharmony_ci    /** 下拉关闭。*/
3923b3eb3cSopenharmony_ci    DIALOG_DISMISS_SLIDE_DOWN,
4023b3eb3cSopenharmony_ci} ArkUI_DismissReason;
4123b3eb3cSopenharmony_ci
4223b3eb3cSopenharmony_ci/**
4323b3eb3cSopenharmony_ci * @brief Invoked when the dialog box is closed.
4423b3eb3cSopenharmony_ci *
4523b3eb3cSopenharmony_ci * @since 12
4623b3eb3cSopenharmony_ci */
4723b3eb3cSopenharmony_citypedef bool (*ArkUI_OnWillDismissEvent)(int32_t reason);
4823b3eb3cSopenharmony_ci
4923b3eb3cSopenharmony_ci/**
5023b3eb3cSopenharmony_ci * @brief Defines a struct for a dialog box dismiss event.
5123b3eb3cSopenharmony_ci *
5223b3eb3cSopenharmony_ci * @since 12
5323b3eb3cSopenharmony_ci */
5423b3eb3cSopenharmony_citypedef struct ArkUI_DialogDismissEvent ArkUI_DialogDismissEvent;
5523b3eb3cSopenharmony_ci
5623b3eb3cSopenharmony_ci/**
5723b3eb3cSopenharmony_ci * @brief Provides the custom dialog box APIs for the native side.
5823b3eb3cSopenharmony_ci *
5923b3eb3cSopenharmony_ci * @version 1
6023b3eb3cSopenharmony_ci * @since 12
6123b3eb3cSopenharmony_ci */
6223b3eb3cSopenharmony_citypedef struct {
6323b3eb3cSopenharmony_ci    /**
6423b3eb3cSopenharmony_ci    * @brief Creates a custom dialog box and returns the pointer to the created dialog box.
6523b3eb3cSopenharmony_ci    *
6623b3eb3cSopenharmony_ci    * @note This method must be called before the <b>show</b> method.
6723b3eb3cSopenharmony_ci    * @return Returns the pointer to the created custom dialog box; returns a null pointer if the creation fails.
6823b3eb3cSopenharmony_ci    */
6923b3eb3cSopenharmony_ci    ArkUI_NativeDialogHandle (*create)();
7023b3eb3cSopenharmony_ci    /**
7123b3eb3cSopenharmony_ci    * @brief Destroys a custom dialog box.
7223b3eb3cSopenharmony_ci    *
7323b3eb3cSopenharmony_ci    * @param handle Indicates the pointer to the custom dialog box controller.
7423b3eb3cSopenharmony_ci    */
7523b3eb3cSopenharmony_ci    void (*dispose)(ArkUI_NativeDialogHandle handle);
7623b3eb3cSopenharmony_ci    /**
7723b3eb3cSopenharmony_ci    * @brief Attaches the content of a custom dialog box.
7823b3eb3cSopenharmony_ci    *
7923b3eb3cSopenharmony_ci    * @note This method must be called before the <b>show</b> method.
8023b3eb3cSopenharmony_ci    * @param handle Indicates the pointer to the custom dialog box controller.
8123b3eb3cSopenharmony_ci    * @param content Indicates the pointer to the root node of the custom dialog box content.
8223b3eb3cSopenharmony_ci    * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs.
8323b3eb3cSopenharmony_ci    */
8423b3eb3cSopenharmony_ci    int32_t (*setContent)(ArkUI_NativeDialogHandle handle, ArkUI_NodeHandle content);
8523b3eb3cSopenharmony_ci    /**
8623b3eb3cSopenharmony_ci    * @brief Detaches the content of a custom dialog box.
8723b3eb3cSopenharmony_ci    *
8823b3eb3cSopenharmony_ci    * @note This method must be called before the <b>show</b> method.
8923b3eb3cSopenharmony_ci    * @param handle Indicates the pointer to the custom dialog box controller.
9023b3eb3cSopenharmony_ci    * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs.
9123b3eb3cSopenharmony_ci    */
9223b3eb3cSopenharmony_ci    int32_t (*removeContent)(ArkUI_NativeDialogHandle handle);
9323b3eb3cSopenharmony_ci    /**
9423b3eb3cSopenharmony_ci    * @brief Sets the alignment mode for a custom dialog box.
9523b3eb3cSopenharmony_ci    *
9623b3eb3cSopenharmony_ci    * @note This method must be called before the <b>show</b> method.
9723b3eb3cSopenharmony_ci    * @param handle Indicates the pointer to the custom dialog box controller.
9823b3eb3cSopenharmony_ci    * @param alignment Indicates the alignment mode. The parameter type is {@link ArkUI_Alignment}.
9923b3eb3cSopenharmony_ci    * @param offsetX Indicates the horizontal offset of the custom dialog box. The value is a floating point number.
10023b3eb3cSopenharmony_ci    * @param offsetY Indicates the vertical offset of the custom dialog box. The value is a floating point number.
10123b3eb3cSopenharmony_ci    * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs.
10223b3eb3cSopenharmony_ci    */
10323b3eb3cSopenharmony_ci    int32_t (*setContentAlignment)(ArkUI_NativeDialogHandle handle, int32_t alignment, float offsetX, float offsetY);
10423b3eb3cSopenharmony_ci    /**
10523b3eb3cSopenharmony_ci    * @brief Resets the alignment mode of a custom dialog box to its default settings.
10623b3eb3cSopenharmony_ci    *
10723b3eb3cSopenharmony_ci    * @note This method must be called before the <b>show</b> method.
10823b3eb3cSopenharmony_ci    * @param handle Indicates the pointer to the custom dialog box controller.
10923b3eb3cSopenharmony_ci    * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs.
11023b3eb3cSopenharmony_ci    */
11123b3eb3cSopenharmony_ci    int32_t (*resetContentAlignment)(ArkUI_NativeDialogHandle handle);
11223b3eb3cSopenharmony_ci    /**
11323b3eb3cSopenharmony_ci    * @brief Sets the modal mode for a custom dialog box.
11423b3eb3cSopenharmony_ci    *
11523b3eb3cSopenharmony_ci    * @note This method must be called before the <b>show</b> method.
11623b3eb3cSopenharmony_ci    * @param handle Indicates the pointer to the custom dialog box controller.
11723b3eb3cSopenharmony_ci    * @param isModal Specifies whether the custom dialog box is a modal, which has a mask applied. The value
11823b3eb3cSopenharmony_ci    * <b>true</b> means that the custom dialog box is a modal, and <b>false</b> means the opposite.
11923b3eb3cSopenharmony_ci    * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs.
12023b3eb3cSopenharmony_ci    */
12123b3eb3cSopenharmony_ci    int32_t (*setModalMode)(ArkUI_NativeDialogHandle handle, bool isModal);
12223b3eb3cSopenharmony_ci    /**
12323b3eb3cSopenharmony_ci    * @brief Specifies whether to allow users to touch the mask to dismiss the custom dialog box.
12423b3eb3cSopenharmony_ci    *
12523b3eb3cSopenharmony_ci    * @note This method must be called before the <b>show</b> method.
12623b3eb3cSopenharmony_ci    * @param handle Indicates the pointer to the custom dialog box controller.
12723b3eb3cSopenharmony_ci    * @param autoCancel Specifies whether to allow users to touch the mask to dismiss the dialog box.
12823b3eb3cSopenharmony_ci    * The value <b>true</b> means to allow users to do so, and <b>false</b> means the opposite.
12923b3eb3cSopenharmony_ci    * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs.
13023b3eb3cSopenharmony_ci    */
13123b3eb3cSopenharmony_ci    int32_t (*setAutoCancel)(ArkUI_NativeDialogHandle handle, bool autoCancel);
13223b3eb3cSopenharmony_ci    /**
13323b3eb3cSopenharmony_ci    * @brief Sets the mask for a custom dialog box.
13423b3eb3cSopenharmony_ci    *
13523b3eb3cSopenharmony_ci    * @note This method must be called before the <b>show</b> method.
13623b3eb3cSopenharmony_ci    * @param handle Indicates the pointer to the custom dialog box controller.
13723b3eb3cSopenharmony_ci    * @param maskColor Indicates the mask color, in 0xARGB format.
13823b3eb3cSopenharmony_ci    * @param maskRect Indicates the pointer to the mask area. Events outside the mask area are transparently
13923b3eb3cSopenharmony_ci    * transmitted, and events within the mask area are not. The parameter type is {@link ArkUI_Rect}.
14023b3eb3cSopenharmony_ci    * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs.
14123b3eb3cSopenharmony_ci    */
14223b3eb3cSopenharmony_ci    int32_t (*setMask)(ArkUI_NativeDialogHandle handle, uint32_t maskColor, const ArkUI_Rect* maskRect);
14323b3eb3cSopenharmony_ci    /**
14423b3eb3cSopenharmony_ci    * @brief Sets the background color for a custom dialog box.
14523b3eb3cSopenharmony_ci    *
14623b3eb3cSopenharmony_ci    * @note This method must be called before the <b>show</b> method.
14723b3eb3cSopenharmony_ci    * @param handle Indicates the pointer to the custom dialog box controller.
14823b3eb3cSopenharmony_ci    * @param backgroundColor Indicates the background color of the custom dialog box, in 0xARGB format.
14923b3eb3cSopenharmony_ci    * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs.
15023b3eb3cSopenharmony_ci    */
15123b3eb3cSopenharmony_ci    int32_t (*setBackgroundColor)(ArkUI_NativeDialogHandle handle, uint32_t backgroundColor);
15223b3eb3cSopenharmony_ci    /**
15323b3eb3cSopenharmony_ci    * @brief Sets the background corner radius for a custom dialog box.
15423b3eb3cSopenharmony_ci    *
15523b3eb3cSopenharmony_ci    * @note This method must be called before the <b>show</b> method.
15623b3eb3cSopenharmony_ci    * @param handle Indicates the pointer to the custom dialog box controller.
15723b3eb3cSopenharmony_ci    * @param topLeft Indicates the radius of the upper left corner of the custom dialog box background.
15823b3eb3cSopenharmony_ci    * @param topRight Indicates the radius of the upper right corner of the custom dialog box background.
15923b3eb3cSopenharmony_ci    * @param bottomLeft Indicates the radius of the lower left corner of the custom dialog box background.
16023b3eb3cSopenharmony_ci    * @param bottomRight Indicates the radius of the lower right corner of the custom dialog box background.
16123b3eb3cSopenharmony_ci    * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs.
16223b3eb3cSopenharmony_ci    */
16323b3eb3cSopenharmony_ci    int32_t (*setCornerRadius)(ArkUI_NativeDialogHandle handle, float topLeft, float topRight,
16423b3eb3cSopenharmony_ci        float bottomLeft, float bottomRight);
16523b3eb3cSopenharmony_ci    /**
16623b3eb3cSopenharmony_ci    * @brief Sets the number of grid columns occupied by a custom dialog box.
16723b3eb3cSopenharmony_ci    *
16823b3eb3cSopenharmony_ci    * @note This method must be called before the <b>show</b> method.
16923b3eb3cSopenharmony_ci    * @param handle Indicates the pointer to the custom dialog box controller.
17023b3eb3cSopenharmony_ci    * @param gridCount Indicates the number of grid columns occupied by the dialog box. The default value is subject to
17123b3eb3cSopenharmony_ci    * the window size, and the maximum value is the maximum number of columns supported by the system.
17223b3eb3cSopenharmony_ci    * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs.
17323b3eb3cSopenharmony_ci    */
17423b3eb3cSopenharmony_ci    int32_t (*setGridColumnCount)(ArkUI_NativeDialogHandle handle, int32_t gridCount);
17523b3eb3cSopenharmony_ci    /**
17623b3eb3cSopenharmony_ci    * @brief Specifies whether to use a custom style for the custom dialog box.
17723b3eb3cSopenharmony_ci    *
17823b3eb3cSopenharmony_ci    * @note This method must be called before the <b>show</b> method.
17923b3eb3cSopenharmony_ci    * @param handle Indicates the pointer to the custom dialog box controller.
18023b3eb3cSopenharmony_ci    * @param enableCustomStyle Specifies whether to use a custom style for the dialog box.
18123b3eb3cSopenharmony_ci    * <b>true</b>: The dialog box automatically adapts its width to the child components; the rounded corner is 0;
18223b3eb3cSopenharmony_ci    * the background color is transparent.
18323b3eb3cSopenharmony_ci    * <b>false</b>: The dialog box automatically adapts its width to the grid system and its height to the child
18423b3eb3cSopenharmony_ci    * components; the rounded corner is 24 vp.
18523b3eb3cSopenharmony_ci    * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs.
18623b3eb3cSopenharmony_ci    */
18723b3eb3cSopenharmony_ci    int32_t (*enableCustomStyle)(ArkUI_NativeDialogHandle handle, bool enableCustomStyle);
18823b3eb3cSopenharmony_ci    /**
18923b3eb3cSopenharmony_ci    * @brief Specifies whether to use a custom animation for a custom dialog box.
19023b3eb3cSopenharmony_ci    *
19123b3eb3cSopenharmony_ci    * @note This method must be called before the <b>show</b> method.
19223b3eb3cSopenharmony_ci    * @param handle Indicates the pointer to the custom dialog box controller.
19323b3eb3cSopenharmony_ci    * @param enableCustomAnimation Specifies whether to use a custom animation. The value <b>true</b> means to use a
19423b3eb3cSopenharmony_ci    * custom animation, and <b>false</b> means to use the default animation.
19523b3eb3cSopenharmony_ci    * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs.
19623b3eb3cSopenharmony_ci    */
19723b3eb3cSopenharmony_ci    int32_t (*enableCustomAnimation)(ArkUI_NativeDialogHandle handle, bool enableCustomAnimation);
19823b3eb3cSopenharmony_ci    /**
19923b3eb3cSopenharmony_ci    * @brief Registers a callback for a custom dialog box so that the user can decide whether to close the dialog box
20023b3eb3cSopenharmony_ci    * after they touch the Back button or press the Esc key.
20123b3eb3cSopenharmony_ci    *
20223b3eb3cSopenharmony_ci    * @note This method must be called before the <b>show</b> method.
20323b3eb3cSopenharmony_ci    * @param handle Indicates the pointer to the custom dialog box controller.
20423b3eb3cSopenharmony_ci    * @param eventHandler Indicates the callback to register. The parameter type is {@link ArkUI_OnWillDismissEvent}.
20523b3eb3cSopenharmony_ci    * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs.
20623b3eb3cSopenharmony_ci    */
20723b3eb3cSopenharmony_ci    int32_t (*registerOnWillDismiss)(ArkUI_NativeDialogHandle handle, ArkUI_OnWillDismissEvent eventHandler);
20823b3eb3cSopenharmony_ci    /**
20923b3eb3cSopenharmony_ci    * @brief Shows a custom dialog box.
21023b3eb3cSopenharmony_ci    *
21123b3eb3cSopenharmony_ci    * @param handle Indicates the pointer to the custom dialog box controller.
21223b3eb3cSopenharmony_ci    * @param showInSubWindow Specifies whether to show the dialog box in a sub-window.
21323b3eb3cSopenharmony_ci    * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs.
21423b3eb3cSopenharmony_ci    */
21523b3eb3cSopenharmony_ci    int32_t (*show)(ArkUI_NativeDialogHandle handle, bool showInSubWindow);
21623b3eb3cSopenharmony_ci    /**
21723b3eb3cSopenharmony_ci    * @brief Closes a custom dialog box. If the dialog box has been closed, this API does not take effect.
21823b3eb3cSopenharmony_ci    *
21923b3eb3cSopenharmony_ci    * @param handle Indicates the pointer to the custom dialog box controller.
22023b3eb3cSopenharmony_ci    * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs.
22123b3eb3cSopenharmony_ci    */
22223b3eb3cSopenharmony_ci    int32_t (*close)(ArkUI_NativeDialogHandle handle);
22323b3eb3cSopenharmony_ci
22423b3eb3cSopenharmony_ci    /**
22523b3eb3cSopenharmony_ci    * @brief Registers a listener for the dismiss event of the custom dialog box.
22623b3eb3cSopenharmony_ci    *
22723b3eb3cSopenharmony_ci    * @param handle Indicates the pointer to the custom dialog box controller.
22823b3eb3cSopenharmony_ci    * @param userData Indicates the pointer to the custom data.
22923b3eb3cSopenharmony_ci    * @param callback Indicates the callback for the dismiss event of the custom dialog box.
23023b3eb3cSopenharmony_ci    * @return Returns the result code.
23123b3eb3cSopenharmony_ci    *         Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if the operation is successful.
23223b3eb3cSopenharmony_ci    *         Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter error occurs.
23323b3eb3cSopenharmony_ci    */
23423b3eb3cSopenharmony_ci    int32_t (*registerOnWillDismissWithUserData)(
23523b3eb3cSopenharmony_ci        ArkUI_NativeDialogHandle handle, void* userData, void (*callback)(ArkUI_DialogDismissEvent* event));
23623b3eb3cSopenharmony_ci} ArkUI_NativeDialogAPI_1;
23723b3eb3cSopenharmony_ci
23823b3eb3cSopenharmony_ci/**
23923b3eb3cSopenharmony_ci * @brief Sets whether to block the system behavior of dismissing a dialog box.
24023b3eb3cSopenharmony_ci *
24123b3eb3cSopenharmony_ci * @param event Indicates the pointer to a dialog box dismiss event object.
24223b3eb3cSopenharmony_ci * @param shouldBlockDismiss Indicates whether to block the system behavior of dismissing the dialog box. The value
24323b3eb3cSopenharmony_ci *                           <b>true</b> means to block the system behavior, and <b>false</b> means the opposite.
24423b3eb3cSopenharmony_ci * @since 12
24523b3eb3cSopenharmony_ci */
24623b3eb3cSopenharmony_civoid OH_ArkUI_DialogDismissEvent_SetShouldBlockDismiss(ArkUI_DialogDismissEvent* event, bool shouldBlockDismiss);
24723b3eb3cSopenharmony_ci
24823b3eb3cSopenharmony_ci/**
24923b3eb3cSopenharmony_ci * @brief Obtains the pointer to user data in a dialog box dismiss event object.
25023b3eb3cSopenharmony_ci *
25123b3eb3cSopenharmony_ci * @param event Indicates the pointer to a dialog box dismiss event object.
25223b3eb3cSopenharmony_ci *
25323b3eb3cSopenharmony_ci * @return Returns the pointer to user data.
25423b3eb3cSopenharmony_ci * @since 12
25523b3eb3cSopenharmony_ci */
25623b3eb3cSopenharmony_civoid* OH_ArkUI_DialogDismissEvent_GetUserData(ArkUI_DialogDismissEvent* event);
25723b3eb3cSopenharmony_ci
25823b3eb3cSopenharmony_ci/**
25923b3eb3cSopenharmony_ci * @brief Obtains the c from a dialog box dismiss event object.
26023b3eb3cSopenharmony_ci *
26123b3eb3cSopenharmony_ci * @param event Indicates the pointer to a dialog box dismiss event object.
26223b3eb3cSopenharmony_ci *
26323b3eb3cSopenharmony_ci * @return Returns the dismissal reason. Returns <b>-1</b> if an exception occurs.
26423b3eb3cSopenharmony_ci *         {@link DIALOG_DISMISS_BACK_PRESS}: touching the Back button, swiping left or right on the screen, or
26523b3eb3cSopenharmony_ci *                                            pressing the Esc key.
26623b3eb3cSopenharmony_ci *         {@link DIALOG_DISMISS_TOUCH_OUTSIDE}: touching the mask.
26723b3eb3cSopenharmony_ci *         {@link DIALOG_DISMISS_CLOSE_BUTTON}: touching the Close button.
26823b3eb3cSopenharmony_ci *         {@link DIALOG_DISMISS_SLIDE_DOWN}: sliding down.
26923b3eb3cSopenharmony_ci * @since 12
27023b3eb3cSopenharmony_ci */
27123b3eb3cSopenharmony_ciint32_t OH_ArkUI_DialogDismissEvent_GetDismissReason(ArkUI_DialogDismissEvent* event);
27223b3eb3cSopenharmony_ci
27323b3eb3cSopenharmony_ci#ifdef __cplusplus
27423b3eb3cSopenharmony_ci};
27523b3eb3cSopenharmony_ci#endif
27623b3eb3cSopenharmony_ci
27723b3eb3cSopenharmony_ci#endif // ARKUI_NATIVE_DIALOG_H
278