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#include "dialog_model.h" 1623b3eb3cSopenharmony_ci 1723b3eb3cSopenharmony_ci#include "node_model.h" 1823b3eb3cSopenharmony_ci 1923b3eb3cSopenharmony_ci#include "base/error/error_code.h" 2023b3eb3cSopenharmony_ci 2123b3eb3cSopenharmony_cinamespace OHOS::Ace::DialogModel { 2223b3eb3cSopenharmony_ciArkUI_NativeDialogHandle Create() 2323b3eb3cSopenharmony_ci{ 2423b3eb3cSopenharmony_ci auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 2523b3eb3cSopenharmony_ci if (!impl) { 2623b3eb3cSopenharmony_ci return nullptr; 2723b3eb3cSopenharmony_ci } 2823b3eb3cSopenharmony_ci auto dialog = impl->getDialogAPI()->create(); 2923b3eb3cSopenharmony_ci return new ArkUI_NativeDialog({ dialog }); 3023b3eb3cSopenharmony_ci} 3123b3eb3cSopenharmony_ci 3223b3eb3cSopenharmony_civoid Dispose(ArkUI_NativeDialogHandle handle) 3323b3eb3cSopenharmony_ci{ 3423b3eb3cSopenharmony_ci auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 3523b3eb3cSopenharmony_ci if (!impl || !handle) { 3623b3eb3cSopenharmony_ci return; 3723b3eb3cSopenharmony_ci } 3823b3eb3cSopenharmony_ci impl->getDialogAPI()->dispose(handle->controller); 3923b3eb3cSopenharmony_ci delete handle; 4023b3eb3cSopenharmony_ci handle = nullptr; 4123b3eb3cSopenharmony_ci} 4223b3eb3cSopenharmony_ci 4323b3eb3cSopenharmony_ciint32_t SetContent(ArkUI_NativeDialogHandle handle, ArkUI_NodeHandle content) 4423b3eb3cSopenharmony_ci{ 4523b3eb3cSopenharmony_ci auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 4623b3eb3cSopenharmony_ci if (!impl || !handle || !content) { 4723b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 4823b3eb3cSopenharmony_ci } 4923b3eb3cSopenharmony_ci return impl->getDialogAPI()->setContent(handle->controller, content->uiNodeHandle); 5023b3eb3cSopenharmony_ci} 5123b3eb3cSopenharmony_ci 5223b3eb3cSopenharmony_ciint32_t RemoveContent(ArkUI_NativeDialogHandle handle) 5323b3eb3cSopenharmony_ci{ 5423b3eb3cSopenharmony_ci auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 5523b3eb3cSopenharmony_ci if (!impl || !handle) { 5623b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 5723b3eb3cSopenharmony_ci } 5823b3eb3cSopenharmony_ci return impl->getDialogAPI()->removeContent(handle->controller); 5923b3eb3cSopenharmony_ci} 6023b3eb3cSopenharmony_ci 6123b3eb3cSopenharmony_ciint32_t SetContentAlignment(ArkUI_NativeDialogHandle handle, int32_t alignment, float offsetX, float offsetY) 6223b3eb3cSopenharmony_ci{ 6323b3eb3cSopenharmony_ci auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 6423b3eb3cSopenharmony_ci if (!impl || !handle) { 6523b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 6623b3eb3cSopenharmony_ci } 6723b3eb3cSopenharmony_ci return impl->getDialogAPI()->setContentAlignment(handle->controller, 6823b3eb3cSopenharmony_ci alignment, offsetX, offsetY); 6923b3eb3cSopenharmony_ci} 7023b3eb3cSopenharmony_ci 7123b3eb3cSopenharmony_ciint32_t ResetContentAlignment(ArkUI_NativeDialogHandle handle) 7223b3eb3cSopenharmony_ci{ 7323b3eb3cSopenharmony_ci auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 7423b3eb3cSopenharmony_ci if (!impl || !handle) { 7523b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 7623b3eb3cSopenharmony_ci } 7723b3eb3cSopenharmony_ci return impl->getDialogAPI()->resetContentAlignment(handle->controller); 7823b3eb3cSopenharmony_ci} 7923b3eb3cSopenharmony_ci 8023b3eb3cSopenharmony_ciint32_t SetModalMode(ArkUI_NativeDialogHandle handle, bool isModal) 8123b3eb3cSopenharmony_ci{ 8223b3eb3cSopenharmony_ci auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 8323b3eb3cSopenharmony_ci if (!impl || !handle) { 8423b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 8523b3eb3cSopenharmony_ci } 8623b3eb3cSopenharmony_ci return impl->getDialogAPI()->setModalMode(handle->controller, isModal); 8723b3eb3cSopenharmony_ci} 8823b3eb3cSopenharmony_ci 8923b3eb3cSopenharmony_ciint32_t SetAutoCancel(ArkUI_NativeDialogHandle handle, bool autoCancel) 9023b3eb3cSopenharmony_ci{ 9123b3eb3cSopenharmony_ci auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 9223b3eb3cSopenharmony_ci if (!impl || !handle) { 9323b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 9423b3eb3cSopenharmony_ci } 9523b3eb3cSopenharmony_ci return impl->getDialogAPI()->setAutoCancel(handle->controller, autoCancel); 9623b3eb3cSopenharmony_ci} 9723b3eb3cSopenharmony_ci 9823b3eb3cSopenharmony_ciint32_t SetMask(ArkUI_NativeDialogHandle handle, uint32_t maskColor, const ArkUI_Rect* maskRect) 9923b3eb3cSopenharmony_ci{ 10023b3eb3cSopenharmony_ci auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 10123b3eb3cSopenharmony_ci if (!impl || !handle) { 10223b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 10323b3eb3cSopenharmony_ci } 10423b3eb3cSopenharmony_ci if (maskRect) { 10523b3eb3cSopenharmony_ci ArkUIRect rect = { maskRect->x, maskRect->y, maskRect->width, maskRect->height }; 10623b3eb3cSopenharmony_ci return impl->getDialogAPI()->setMask(handle->controller, maskColor, &rect); 10723b3eb3cSopenharmony_ci } else { 10823b3eb3cSopenharmony_ci return impl->getDialogAPI()->setMask(handle->controller, maskColor, nullptr); 10923b3eb3cSopenharmony_ci } 11023b3eb3cSopenharmony_ci} 11123b3eb3cSopenharmony_ci 11223b3eb3cSopenharmony_ciint32_t SetBackgroundColor(ArkUI_NativeDialogHandle handle, uint32_t backgroundColor) 11323b3eb3cSopenharmony_ci{ 11423b3eb3cSopenharmony_ci auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 11523b3eb3cSopenharmony_ci if (!impl || !handle) { 11623b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 11723b3eb3cSopenharmony_ci } 11823b3eb3cSopenharmony_ci return impl->getDialogAPI()->setBackgroundColor(handle->controller, backgroundColor); 11923b3eb3cSopenharmony_ci} 12023b3eb3cSopenharmony_ci 12123b3eb3cSopenharmony_ciint32_t SetCornerRadius(ArkUI_NativeDialogHandle handle, float topLeft, float topRight, 12223b3eb3cSopenharmony_ci float bottomLeft, float bottomRight) 12323b3eb3cSopenharmony_ci{ 12423b3eb3cSopenharmony_ci auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 12523b3eb3cSopenharmony_ci if (!impl || !handle) { 12623b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 12723b3eb3cSopenharmony_ci } 12823b3eb3cSopenharmony_ci return impl->getDialogAPI()->setCornerRadius(handle->controller, 12923b3eb3cSopenharmony_ci topLeft, topRight, bottomLeft, bottomRight); 13023b3eb3cSopenharmony_ci} 13123b3eb3cSopenharmony_ci 13223b3eb3cSopenharmony_ciint32_t SetGridColumnCount(ArkUI_NativeDialogHandle handle, int32_t gridCount) 13323b3eb3cSopenharmony_ci{ 13423b3eb3cSopenharmony_ci auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 13523b3eb3cSopenharmony_ci if (!impl || !handle) { 13623b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 13723b3eb3cSopenharmony_ci } 13823b3eb3cSopenharmony_ci return impl->getDialogAPI()->setGridColumnCount(handle->controller, gridCount); 13923b3eb3cSopenharmony_ci} 14023b3eb3cSopenharmony_ci 14123b3eb3cSopenharmony_ciint32_t EnableCustomStyle(ArkUI_NativeDialogHandle handle, bool enableCustomStyle) 14223b3eb3cSopenharmony_ci{ 14323b3eb3cSopenharmony_ci auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 14423b3eb3cSopenharmony_ci if (!impl || !handle) { 14523b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 14623b3eb3cSopenharmony_ci } 14723b3eb3cSopenharmony_ci return impl->getDialogAPI()->enableCustomStyle(handle->controller, enableCustomStyle); 14823b3eb3cSopenharmony_ci} 14923b3eb3cSopenharmony_ci 15023b3eb3cSopenharmony_ciint32_t EnableCustomAnimation(ArkUI_NativeDialogHandle handle, bool enableCustomAnimation) 15123b3eb3cSopenharmony_ci{ 15223b3eb3cSopenharmony_ci auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 15323b3eb3cSopenharmony_ci if (!impl || !handle) { 15423b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 15523b3eb3cSopenharmony_ci } 15623b3eb3cSopenharmony_ci return impl->getDialogAPI()->enableCustomAnimation(handle->controller, enableCustomAnimation); 15723b3eb3cSopenharmony_ci} 15823b3eb3cSopenharmony_ci 15923b3eb3cSopenharmony_ciint32_t Show(ArkUI_NativeDialogHandle handle, bool showInSubWindow) 16023b3eb3cSopenharmony_ci{ 16123b3eb3cSopenharmony_ci auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 16223b3eb3cSopenharmony_ci if (!impl || !handle) { 16323b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 16423b3eb3cSopenharmony_ci } 16523b3eb3cSopenharmony_ci return impl->getDialogAPI()->show(handle->controller, showInSubWindow); 16623b3eb3cSopenharmony_ci} 16723b3eb3cSopenharmony_ci 16823b3eb3cSopenharmony_ciint32_t Close(ArkUI_NativeDialogHandle handle) 16923b3eb3cSopenharmony_ci{ 17023b3eb3cSopenharmony_ci auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 17123b3eb3cSopenharmony_ci if (!impl || !handle) { 17223b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 17323b3eb3cSopenharmony_ci } 17423b3eb3cSopenharmony_ci return impl->getDialogAPI()->close(handle->controller); 17523b3eb3cSopenharmony_ci} 17623b3eb3cSopenharmony_ci 17723b3eb3cSopenharmony_ciint32_t RegisterOnWillDismiss(ArkUI_NativeDialogHandle handle, ArkUI_OnWillDismissEvent eventHandler) 17823b3eb3cSopenharmony_ci{ 17923b3eb3cSopenharmony_ci auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 18023b3eb3cSopenharmony_ci if (!impl || !handle) { 18123b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 18223b3eb3cSopenharmony_ci } 18323b3eb3cSopenharmony_ci return impl->getDialogAPI()->registerOnWillDismiss(handle->controller, eventHandler); 18423b3eb3cSopenharmony_ci} 18523b3eb3cSopenharmony_ci 18623b3eb3cSopenharmony_ciint32_t RegisterOnWillDismissWithUserData( 18723b3eb3cSopenharmony_ci ArkUI_NativeDialogHandle handle, void* userData, void (*callback)(ArkUI_DialogDismissEvent* event)) 18823b3eb3cSopenharmony_ci{ 18923b3eb3cSopenharmony_ci auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 19023b3eb3cSopenharmony_ci if (!impl || !handle) { 19123b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 19223b3eb3cSopenharmony_ci } 19323b3eb3cSopenharmony_ci int result = impl->getDialogAPI()->registerOnWillDismissWithUserData(handle->controller, userData, callback); 19423b3eb3cSopenharmony_ci return result; 19523b3eb3cSopenharmony_ci} 19623b3eb3cSopenharmony_ci 19723b3eb3cSopenharmony_ci} // namespace OHOS::Ace::NG::DialogModel 19823b3eb3cSopenharmony_ci 19923b3eb3cSopenharmony_ci#ifdef __cplusplus 20023b3eb3cSopenharmony_ciextern "C" { 20123b3eb3cSopenharmony_ci#endif 20223b3eb3cSopenharmony_ci 20323b3eb3cSopenharmony_civoid OH_ArkUI_DialogDismissEvent_SetShouldBlockDismiss(ArkUI_DialogDismissEvent* event, bool shouldBlockDismiss) 20423b3eb3cSopenharmony_ci{ 20523b3eb3cSopenharmony_ci if (!event) { 20623b3eb3cSopenharmony_ci return; 20723b3eb3cSopenharmony_ci } 20823b3eb3cSopenharmony_ci event->BlockDismiss = shouldBlockDismiss; 20923b3eb3cSopenharmony_ci} 21023b3eb3cSopenharmony_ci 21123b3eb3cSopenharmony_civoid* OH_ArkUI_DialogDismissEvent_GetUserData(ArkUI_DialogDismissEvent* event) 21223b3eb3cSopenharmony_ci{ 21323b3eb3cSopenharmony_ci if (!event) { 21423b3eb3cSopenharmony_ci return nullptr; 21523b3eb3cSopenharmony_ci } 21623b3eb3cSopenharmony_ci return event->userData; 21723b3eb3cSopenharmony_ci} 21823b3eb3cSopenharmony_ci 21923b3eb3cSopenharmony_ciint32_t OH_ArkUI_DialogDismissEvent_GetDismissReason(ArkUI_DialogDismissEvent* event) 22023b3eb3cSopenharmony_ci{ 22123b3eb3cSopenharmony_ci if (!event) { 22223b3eb3cSopenharmony_ci return -1; 22323b3eb3cSopenharmony_ci } 22423b3eb3cSopenharmony_ci return event->reason; 22523b3eb3cSopenharmony_ci} 22623b3eb3cSopenharmony_ci 22723b3eb3cSopenharmony_ci#ifdef __cplusplus 22823b3eb3cSopenharmony_ci}; 22923b3eb3cSopenharmony_ci#endif