1 /*
2 * Copyright (c) 2025 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 #include "dialog_option.h"
17
18 #include "native_dialog.h"
19 #include "node_model.h"
20
21 #include "base/error/error_code.h"
22 #include "base/utils/utils.h"
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 namespace {
29 constexpr int NUM_0 = 0;
30 constexpr int NUM_1 = 1;
31 constexpr int NUM_2 = 2;
32 constexpr int NUM_3 = 3;
33 constexpr int NUM_4 = 4;
34 constexpr int NUM_5 = 5;
35 constexpr int NUM_6 = 6;
36 const int ALLOW_SIZE_7(7);
37 constexpr int COLOR_STRATEGY_STYLE = 1;
38 constexpr int COLOR_STYLE = 2;
39 constexpr int32_t REQUIRED_ONE_PARAM = 1;
40 constexpr int32_t BLURSTYLE_COLOR_MODE = 0;
41 constexpr int32_t BLURSTYLE_ADAPTIVE_COLOR = 1;
42 constexpr int32_t BLURSTYLE_SCALE = 2;
43 constexpr int32_t BLURSTYLE_GRAY_SCALE_BLACK = 3;
44 constexpr int32_t BLURSTYLE_GRAY_SCALE_WHITE = 4;
45 constexpr int32_t BLURSTYLE_POLICY = 5;
46 constexpr int32_t BLURSTYLE_INACTIVE_COLOR = 6;
47 constexpr int32_t EFFECT_RADIUS = 0;
48 constexpr int32_t EFFECT_SATURATION = 1;
49 constexpr int32_t EFFECT_BRIGHTNESS = 2;
50 constexpr int32_t EFFECT_COLOR = 3;
51 constexpr int32_t EFFECT_ADAPTIVE_COLOR = 4;
52 constexpr int32_t EFFECT_GRAY_SCALE_BLACK = 5;
53 constexpr int32_t EFFECT_GRAY_SCALE_WHITE = 6;
54 constexpr int32_t EFFECT_POLICY = 7;
55 constexpr int32_t EFFECT_COLOR_INDEX = 8;
56 constexpr uint32_t COLOR_TRANSPARENT = 0x00000000;
57 constexpr uint32_t COLOR_ALPHA_OFFSET = 24;
58 constexpr uint32_t COLOR_ALPHA_VALUE = 0xFF000000;
59
ColorAlphaAdapt(uint32_t origin)60 uint32_t ColorAlphaAdapt(uint32_t origin)
61 {
62 uint32_t result = origin;
63 if ((origin >> COLOR_ALPHA_OFFSET) == 0) {
64 result = origin | COLOR_ALPHA_VALUE;
65 }
66 return result;
67 }
68
ParseColorMode(const ArkUI_AttributeItem * item,int32_t index)69 int32_t ParseColorMode(const ArkUI_AttributeItem* item, int32_t index)
70 {
71 auto size = item->size;
72 int32_t colorMode = ARKUI_COLOR_MODE_SYSTEM;
73 if (size > index) {
74 int32_t value = item->value[index].i32;
75 if (value >= static_cast<int32_t>(ARKUI_COLOR_MODE_SYSTEM) &&
76 value <= static_cast<int32_t>(ARKUI_COLOR_MODE_DARK)) {
77 colorMode = value;
78 }
79 }
80 return colorMode;
81 }
82
ParseAdaptiveColor(const ArkUI_AttributeItem * item,int32_t index)83 int32_t ParseAdaptiveColor(const ArkUI_AttributeItem* item, int32_t index)
84 {
85 auto size = item->size;
86 int32_t adaptiveColor = ARKUI_ADAPTIVE_COLOR_DEFAULT;
87 if (size > index) {
88 int32_t value = item->value[index].i32;
89 if (value >= static_cast<int32_t>(ARKUI_ADAPTIVE_COLOR_DEFAULT) &&
90 value <= static_cast<int32_t>(ARKUI_ADAPTIVE_COLOR_AVERAGE)) {
91 adaptiveColor = value;
92 }
93 }
94 return adaptiveColor;
95 }
96
ParseScale(const ArkUI_AttributeItem * item,int32_t index)97 float ParseScale(const ArkUI_AttributeItem* item, int32_t index)
98 {
99 auto size = item->size;
100 float scale = 1.0f;
101 if (size > index) {
102 scale = std::clamp(item->value[index].f32, 0.0f, 1.0f);
103 }
104 return scale;
105 }
106
ParseGrayScaleBlack(const ArkUI_AttributeItem * item,int32_t index)107 uint32_t ParseGrayScaleBlack(const ArkUI_AttributeItem* item, int32_t index)
108 {
109 auto size = item->size;
110 uint32_t grayScaleBlack = 0;
111 if (size > index) {
112 grayScaleBlack = item->value[index].u32;
113 }
114 return grayScaleBlack;
115 }
116
ParseGrayScaleWhite(const ArkUI_AttributeItem * item,int32_t index)117 uint32_t ParseGrayScaleWhite(const ArkUI_AttributeItem* item, int32_t index)
118 {
119 auto size = item->size;
120 uint32_t grayScaleWhite = 0;
121 if (size > index) {
122 grayScaleWhite = item->value[index].u32;
123 }
124 return grayScaleWhite;
125 }
126
ParsePolicy(const ArkUI_AttributeItem * item,int32_t index)127 int32_t ParsePolicy(const ArkUI_AttributeItem* item, int32_t index)
128 {
129 auto size = item->size;
130 int32_t policy = ARKUI_BLUR_STYLE_ACTIVE_POLICY_ALWAYS_ACTIVE;
131 if (size > index) {
132 int32_t value = item->value[index].i32;
133 if (value >= static_cast<int32_t>(ARKUI_BLUR_STYLE_ACTIVE_POLICY_FOLLOWS_WINDOW_ACTIVE_STATE) &&
134 value <= static_cast<int32_t>(ARKUI_BLUR_STYLE_ACTIVE_POLICY_ALWAYS_INACTIVE)) {
135 policy = value;
136 }
137 }
138 return policy;
139 }
140
ParseRadius(const ArkUI_AttributeItem * item,int32_t index)141 float ParseRadius(const ArkUI_AttributeItem* item, int32_t index)
142 {
143 auto size = item->size;
144 float radius = 0.0f;
145 if (size > index) {
146 float value = item->value[index].f32;
147 if (OHOS::Ace::GreatOrEqual(value, 0.0f)) {
148 radius = value;
149 }
150 }
151 return radius;
152 }
153
ParseSaturation(const ArkUI_AttributeItem * item,int32_t index)154 float ParseSaturation(const ArkUI_AttributeItem* item, int32_t index)
155 {
156 auto size = item->size;
157 float saturation = 1.0f;
158 if (size > index) {
159 float value = item->value[index].f32;
160 if (OHOS::Ace::GreatOrEqual(value, 0.0f)) {
161 saturation = value;
162 }
163 }
164 return saturation;
165 }
166
ParseBrightness(const ArkUI_AttributeItem * item,int32_t index)167 float ParseBrightness(const ArkUI_AttributeItem* item, int32_t index)
168 {
169 auto size = item->size;
170 float brightness = 1.0f;
171 if (size > index) {
172 float value = item->value[index].f32;
173 if (OHOS::Ace::GreatOrEqual(value, 0.0f)) {
174 brightness = value;
175 }
176 }
177 return brightness;
178 }
179
ParseColor(const ArkUI_AttributeItem * item,int32_t index)180 uint32_t ParseColor(const ArkUI_AttributeItem* item, int32_t index)
181 {
182 auto size = item->size;
183 uint32_t color = COLOR_TRANSPARENT;
184 if (size > index) {
185 color = ColorAlphaAdapt(item->value[index].u32);
186 }
187 return color;
188 }
189 } // namespace
190
OH_ArkUI_CustomDialog_CreateOptions(ArkUI_NodeHandle content)191 ArkUI_CustomDialogOptions* OH_ArkUI_CustomDialog_CreateOptions(ArkUI_NodeHandle content)
192 {
193 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
194 if (!impl || !content) {
195 return nullptr;
196 }
197 auto dialog = impl->getDialogAPI()->create();
198 auto options = new ArkUI_CustomDialogOptions({ dialog });
199 impl->getDialogAPI()->setContent(options->handle, content->uiNodeHandle);
200 return options;
201 }
202
OH_ArkUI_CustomDialog_DisposeOptions(ArkUI_CustomDialogOptions * options)203 void OH_ArkUI_CustomDialog_DisposeOptions(ArkUI_CustomDialogOptions* options)
204 {
205 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
206 if (!impl || !options) {
207 return;
208 }
209 impl->getDialogAPI()->dispose(options->handle);
210 delete options;
211 options = nullptr;
212 }
213
OH_ArkUI_CustomDialog_OpenDialog(ArkUI_CustomDialogOptions * options,void (* callback)(int32_t dialogId))214 int32_t OH_ArkUI_CustomDialog_OpenDialog(ArkUI_CustomDialogOptions* options, void (*callback)(int32_t dialogId))
215 {
216 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
217 if (!impl || !options) {
218 return ARKUI_ERROR_CODE_PARAM_INVALID;
219 }
220 return impl->getDialogAPI()->openCustomDialog(options->handle, callback);
221 }
222
OH_ArkUI_CustomDialog_UpdateDialog(ArkUI_CustomDialogOptions * options,void (* callback)(int32_t dialogId))223 int32_t OH_ArkUI_CustomDialog_UpdateDialog(ArkUI_CustomDialogOptions* options, void (*callback)(int32_t dialogId))
224 {
225 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
226 if (!impl || !options) {
227 return ARKUI_ERROR_CODE_PARAM_INVALID;
228 }
229 return impl->getDialogAPI()->updateCustomDialog(options->handle, callback);
230 }
231
OH_ArkUI_CustomDialog_CloseDialog(int32_t dialogId)232 int32_t OH_ArkUI_CustomDialog_CloseDialog(int32_t dialogId)
233 {
234 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
235 if (!impl) {
236 return ARKUI_ERROR_CODE_PARAM_INVALID;
237 }
238 return impl->getDialogAPI()->closeCustomDialog(dialogId);
239 }
240
OH_ArkUI_CustomDialog_SetLevelMode(ArkUI_CustomDialogOptions * options,ArkUI_LevelMode levelMode)241 int32_t OH_ArkUI_CustomDialog_SetLevelMode(ArkUI_CustomDialogOptions* options, ArkUI_LevelMode levelMode)
242 {
243 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
244 if (!impl || !options) {
245 return ARKUI_ERROR_CODE_PARAM_INVALID;
246 }
247 if (static_cast<int32_t>(levelMode) < static_cast<int32_t>(ARKUI_LEVEL_MODE_OVERLAY) ||
248 static_cast<int32_t>(levelMode) > static_cast<int32_t>(ARKUI_LEVEL_MODE_EMBEDDED)) {
249 return ARKUI_ERROR_CODE_PARAM_INVALID;
250 }
251 return impl->getDialogAPI()->setLevelMode(options->handle, static_cast<int32_t>(levelMode));
252 }
253
OH_ArkUI_CustomDialog_SetLevelUniqueId(ArkUI_CustomDialogOptions * options,int32_t uniqueId)254 int32_t OH_ArkUI_CustomDialog_SetLevelUniqueId(ArkUI_CustomDialogOptions* options, int32_t uniqueId)
255 {
256 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
257 if (!impl || !options) {
258 return ARKUI_ERROR_CODE_PARAM_INVALID;
259 }
260 if (uniqueId < 0) {
261 return ARKUI_ERROR_CODE_PARAM_INVALID;
262 }
263 return impl->getDialogAPI()->setLevelUniqueId(options->handle, uniqueId);
264 }
265
OH_ArkUI_CustomDialog_SetImmersiveMode(ArkUI_CustomDialogOptions * options,ArkUI_ImmersiveMode immersiveMode)266 int32_t OH_ArkUI_CustomDialog_SetImmersiveMode(ArkUI_CustomDialogOptions* options, ArkUI_ImmersiveMode immersiveMode)
267 {
268 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
269 if (!impl || !options) {
270 return ARKUI_ERROR_CODE_PARAM_INVALID;
271 }
272 if (static_cast<int32_t>(immersiveMode) < static_cast<int32_t>(ARKUI_IMMERSIVE_MODE_DEFAULT) ||
273 static_cast<int32_t>(immersiveMode) > static_cast<int32_t>(ARKUI_IMMERSIVE_MODE_EXTEND)) {
274 return ARKUI_ERROR_CODE_PARAM_INVALID;
275 }
276 return impl->getDialogAPI()->setImmersiveMode(options->handle, static_cast<int32_t>(immersiveMode));
277 }
278
OH_ArkUI_CustomDialog_SetBackgroundColor(ArkUI_CustomDialogOptions * options,uint32_t backgroundColor)279 int32_t OH_ArkUI_CustomDialog_SetBackgroundColor(ArkUI_CustomDialogOptions* options, uint32_t backgroundColor)
280 {
281 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
282 if (!impl || !options) {
283 return ARKUI_ERROR_CODE_PARAM_INVALID;
284 }
285 return impl->getDialogAPI()->setBackgroundColor(options->handle, backgroundColor);
286 }
287
OH_ArkUI_CustomDialog_SetCornerRadius(ArkUI_CustomDialogOptions * options,float topLeft,float topRight,float bottomLeft,float bottomRight)288 int32_t OH_ArkUI_CustomDialog_SetCornerRadius(
289 ArkUI_CustomDialogOptions* options, float topLeft, float topRight, float bottomLeft, float bottomRight)
290 {
291 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
292 if (!impl || !options) {
293 return ARKUI_ERROR_CODE_PARAM_INVALID;
294 }
295 return impl->getDialogAPI()->setCornerRadius(options->handle, topLeft, topRight, bottomLeft, bottomRight);
296 }
297
OH_ArkUI_CustomDialog_SetBorderWidth(ArkUI_CustomDialogOptions * options,float top,float right,float bottom,float left,ArkUI_LengthMetricUnit unit)298 int32_t OH_ArkUI_CustomDialog_SetBorderWidth(
299 ArkUI_CustomDialogOptions* options, float top, float right, float bottom, float left, ArkUI_LengthMetricUnit unit)
300 {
301 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
302 if (!impl || !options) {
303 return ARKUI_ERROR_CODE_PARAM_INVALID;
304 }
305 return impl->getDialogAPI()->setBorderWidth(options->handle, top, right, bottom, left, unit);
306 }
307
OH_ArkUI_CustomDialog_SetBorderColor(ArkUI_CustomDialogOptions * options,uint32_t top,uint32_t right,uint32_t bottom,uint32_t left)308 int32_t OH_ArkUI_CustomDialog_SetBorderColor(
309 ArkUI_CustomDialogOptions* options, uint32_t top, uint32_t right, uint32_t bottom, uint32_t left)
310 {
311 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
312 if (!impl || !options) {
313 return ARKUI_ERROR_CODE_PARAM_INVALID;
314 }
315 return impl->getDialogAPI()->setBorderColor(options->handle, top, right, bottom, left);
316 }
317
OH_ArkUI_CustomDialog_SetBorderStyle(ArkUI_CustomDialogOptions * options,int32_t top,int32_t right,int32_t bottom,int32_t left)318 int32_t OH_ArkUI_CustomDialog_SetBorderStyle(
319 ArkUI_CustomDialogOptions* options, int32_t top, int32_t right, int32_t bottom, int32_t left)
320 {
321 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
322 if (!impl || !options) {
323 return ARKUI_ERROR_CODE_PARAM_INVALID;
324 }
325 return impl->getDialogAPI()->setBorderStyle(options->handle, top, right, bottom, left);
326 }
327
OH_ArkUI_CustomDialog_SetWidth(ArkUI_CustomDialogOptions * options,float width,ArkUI_LengthMetricUnit unit)328 int32_t OH_ArkUI_CustomDialog_SetWidth(ArkUI_CustomDialogOptions* options, float width, ArkUI_LengthMetricUnit unit)
329 {
330 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
331 if (!impl || !options) {
332 return ARKUI_ERROR_CODE_PARAM_INVALID;
333 }
334 return impl->getDialogAPI()->setWidth(options->handle, width, unit);
335 }
336
OH_ArkUI_CustomDialog_SetHeight(ArkUI_CustomDialogOptions * options,float height,ArkUI_LengthMetricUnit unit)337 int32_t OH_ArkUI_CustomDialog_SetHeight(ArkUI_CustomDialogOptions* options, float height, ArkUI_LengthMetricUnit unit)
338 {
339 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
340 if (!impl || !options) {
341 return ARKUI_ERROR_CODE_PARAM_INVALID;
342 }
343 return impl->getDialogAPI()->setHeight(options->handle, height, unit);
344 }
345
OH_ArkUI_CustomDialog_SetShadow(ArkUI_CustomDialogOptions * options,ArkUI_ShadowStyle shadow)346 int32_t OH_ArkUI_CustomDialog_SetShadow(ArkUI_CustomDialogOptions* options, ArkUI_ShadowStyle shadow)
347 {
348 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
349 if (!impl || !options) {
350 return ARKUI_ERROR_CODE_PARAM_INVALID;
351 }
352 return impl->getDialogAPI()->setShadow(options->handle, shadow);
353 }
354
OH_ArkUI_CustomDialog_SetCustomShadow(ArkUI_CustomDialogOptions * options,const ArkUI_AttributeItem * customShadow)355 int32_t OH_ArkUI_CustomDialog_SetCustomShadow(
356 ArkUI_CustomDialogOptions* options, const ArkUI_AttributeItem* customShadow)
357 {
358 if (customShadow->size == 0) {
359 return ARKUI_ERROR_CODE_PARAM_INVALID;
360 }
361 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
362 if (!impl || !options) {
363 return ARKUI_ERROR_CODE_PARAM_INVALID;
364 }
365 ArkUIInt32orFloat32 shadows[ALLOW_SIZE_7] = { 0, { .i32 = NUM_2 }, 0, 0, { .i32 = 0 }, { .u32 = 0 }, { .i32 = 0 } };
366 int length = customShadow->size;
367 if (length > NUM_0) {
368 if (OHOS::Ace::LessNotEqual(customShadow->value[NUM_0].f32, 0.0f)) {
369 return ARKUI_ERROR_CODE_PARAM_INVALID;
370 }
371 shadows[NUM_0].f32 = customShadow->value[NUM_0].f32; // radius
372 }
373 if (length > NUM_2) {
374 shadows[NUM_2].f32 = customShadow->value[NUM_2].f32; // OffsetX
375 }
376 if (length > NUM_3) {
377 shadows[NUM_3].f32 = customShadow->value[NUM_3].f32; // OffsetY
378 }
379 if (length > NUM_4) {
380 if (!OHOS::Ace::InRegion(NUM_0, NUM_1, customShadow->value[NUM_4].i32)) {
381 return ARKUI_ERROR_CODE_PARAM_INVALID;
382 }
383 shadows[NUM_4].i32 = customShadow->value[NUM_4].i32;
384 }
385 if (length > NUM_5) {
386 if (customShadow->value[NUM_1].i32) {
387 if (!OHOS::Ace::InRegion(NUM_0, NUM_2, customShadow->value[NUM_5].i32)) {
388 return ARKUI_ERROR_CODE_PARAM_INVALID;
389 }
390 shadows[NUM_1].i32 = COLOR_STRATEGY_STYLE;
391 shadows[NUM_5].i32 = customShadow->value[NUM_5].i32;
392 } else {
393 shadows[NUM_1].i32 = COLOR_STYLE;
394 shadows[NUM_5].u32 = customShadow->value[NUM_5].u32;
395 }
396 }
397 if (length > NUM_6) {
398 shadows[NUM_6].i32 = customShadow->value[NUM_6].i32;
399 }
400 return impl->getDialogAPI()->setCustomShadow(options->handle, shadows, ALLOW_SIZE_7);
401 }
402
OH_ArkUI_CustomDialog_SetBackgroundBlurStyle(ArkUI_CustomDialogOptions * options,ArkUI_BlurStyle blurStyle)403 int32_t OH_ArkUI_CustomDialog_SetBackgroundBlurStyle(ArkUI_CustomDialogOptions* options, ArkUI_BlurStyle blurStyle)
404 {
405 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
406 if (!impl || !options) {
407 return ARKUI_ERROR_CODE_PARAM_INVALID;
408 }
409 return impl->getDialogAPI()->setBackgroundBlurStyle(options->handle, blurStyle);
410 }
411
OH_ArkUI_CustomDialog_SetAlignment(ArkUI_CustomDialogOptions * options,int32_t alignment,float offsetX,float offsetY)412 int32_t OH_ArkUI_CustomDialog_SetAlignment(
413 ArkUI_CustomDialogOptions* options, int32_t alignment, float offsetX, float offsetY)
414 {
415 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
416 if (!impl || !options) {
417 return ARKUI_ERROR_CODE_PARAM_INVALID;
418 }
419 return impl->getDialogAPI()->setContentAlignment(options->handle, alignment, offsetX, offsetY);
420 }
421
OH_ArkUI_CustomDialog_SetModalMode(ArkUI_CustomDialogOptions * options,bool isModal)422 int32_t OH_ArkUI_CustomDialog_SetModalMode(ArkUI_CustomDialogOptions* options, bool isModal)
423 {
424 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
425 if (!impl || !options) {
426 return ARKUI_ERROR_CODE_PARAM_INVALID;
427 }
428 return impl->getDialogAPI()->setModalMode(options->handle, isModal);
429 }
430
OH_ArkUI_CustomDialog_SetAutoCancel(ArkUI_CustomDialogOptions * options,bool autoCancel)431 int32_t OH_ArkUI_CustomDialog_SetAutoCancel(ArkUI_CustomDialogOptions* options, bool autoCancel)
432 {
433 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
434 if (!impl || !options) {
435 return ARKUI_ERROR_CODE_PARAM_INVALID;
436 }
437 return impl->getDialogAPI()->setAutoCancel(options->handle, autoCancel);
438 }
439
OH_ArkUI_CustomDialog_SetSubwindowMode(ArkUI_CustomDialogOptions * options,bool showInSubwindow)440 int32_t OH_ArkUI_CustomDialog_SetSubwindowMode(ArkUI_CustomDialogOptions* options, bool showInSubwindow)
441 {
442 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
443 if (!impl || !options) {
444 return ARKUI_ERROR_CODE_PARAM_INVALID;
445 }
446 return impl->getDialogAPI()->setSubwindowMode(options->handle, showInSubwindow);
447 }
448
OH_ArkUI_CustomDialog_SetMask(ArkUI_CustomDialogOptions * options,uint32_t maskColor,const ArkUI_Rect * maskRect)449 int32_t OH_ArkUI_CustomDialog_SetMask(
450 ArkUI_CustomDialogOptions* options, uint32_t maskColor, const ArkUI_Rect* maskRect)
451 {
452 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
453 if (!impl || !options) {
454 return ARKUI_ERROR_CODE_PARAM_INVALID;
455 }
456 if (maskRect) {
457 ArkUIRect rect = { maskRect->x, maskRect->y, maskRect->width, maskRect->height };
458 return impl->getDialogAPI()->setMask(options->handle, maskColor, &rect);
459 } else {
460 return impl->getDialogAPI()->setMask(options->handle, maskColor, nullptr);
461 }
462 }
463
OH_ArkUI_CustomDialog_SetKeyboardAvoidMode(ArkUI_CustomDialogOptions * options,ArkUI_KeyboardAvoidMode keyboardAvoidMode)464 int32_t OH_ArkUI_CustomDialog_SetKeyboardAvoidMode(
465 ArkUI_CustomDialogOptions* options, ArkUI_KeyboardAvoidMode keyboardAvoidMode)
466 {
467 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
468 if (!impl || !options) {
469 return ARKUI_ERROR_CODE_PARAM_INVALID;
470 }
471 return impl->getDialogAPI()->setKeyboardAvoidMode(options->handle, keyboardAvoidMode);
472 }
473
OH_ArkUI_CustomDialog_SetHoverModeEnabled(ArkUI_CustomDialogOptions * options,bool enabled)474 int32_t OH_ArkUI_CustomDialog_SetHoverModeEnabled(ArkUI_CustomDialogOptions* options, bool enabled)
475 {
476 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
477 if (!impl || !options) {
478 return ARKUI_ERROR_CODE_PARAM_INVALID;
479 }
480 return impl->getDialogAPI()->enableHoverMode(options->handle, enabled);
481 }
482
OH_ArkUI_CustomDialog_SetHoverModeArea(ArkUI_CustomDialogOptions * options,ArkUI_HoverModeAreaType hoverModeAreaType)483 int32_t OH_ArkUI_CustomDialog_SetHoverModeArea(
484 ArkUI_CustomDialogOptions* options, ArkUI_HoverModeAreaType hoverModeAreaType)
485 {
486 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
487 if (!impl || !options) {
488 return ARKUI_ERROR_CODE_PARAM_INVALID;
489 }
490 return impl->getDialogAPI()->setHoverModeArea(options->handle, hoverModeAreaType);
491 }
492
OH_ArkUI_CustomDialog_RegisterOnWillDismissCallback(ArkUI_CustomDialogOptions * options,void * userData,void (* callback)(ArkUI_DialogDismissEvent * event))493 int32_t OH_ArkUI_CustomDialog_RegisterOnWillDismissCallback(
494 ArkUI_CustomDialogOptions* options, void* userData, void (*callback)(ArkUI_DialogDismissEvent* event))
495 {
496 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
497 if (!impl || !options) {
498 return ARKUI_ERROR_CODE_PARAM_INVALID;
499 }
500 return impl->getDialogAPI()->registerOnWillDismissWithUserData(options->handle, userData, callback);
501 }
502
OH_ArkUI_CustomDialog_RegisterOnWillAppearCallback(ArkUI_CustomDialogOptions * options,void * userData,void (* callback)(void * userData))503 int32_t OH_ArkUI_CustomDialog_RegisterOnWillAppearCallback(
504 ArkUI_CustomDialogOptions* options, void* userData, void (*callback)(void* userData))
505 {
506 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
507 if (!impl || !options) {
508 return ARKUI_ERROR_CODE_PARAM_INVALID;
509 }
510 return impl->getDialogAPI()->registerOnWillAppear(options->handle, userData, callback);
511 }
512
OH_ArkUI_CustomDialog_RegisterOnDidAppearCallback(ArkUI_CustomDialogOptions * options,void * userData,void (* callback)(void * userData))513 int32_t OH_ArkUI_CustomDialog_RegisterOnDidAppearCallback(
514 ArkUI_CustomDialogOptions* options, void* userData, void (*callback)(void* userData))
515 {
516 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
517 if (!impl || !options) {
518 return ARKUI_ERROR_CODE_PARAM_INVALID;
519 }
520 return impl->getDialogAPI()->registerOnDidAppear(options->handle, userData, callback);
521 }
522
OH_ArkUI_CustomDialog_RegisterOnWillDisappearCallback(ArkUI_CustomDialogOptions * options,void * userData,void (* callback)(void * userData))523 int32_t OH_ArkUI_CustomDialog_RegisterOnWillDisappearCallback(
524 ArkUI_CustomDialogOptions* options, void* userData, void (*callback)(void* userData))
525 {
526 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
527 if (!impl || !options) {
528 return ARKUI_ERROR_CODE_PARAM_INVALID;
529 }
530 return impl->getDialogAPI()->registerOnWillDisappear(options->handle, userData, callback);
531 }
532
OH_ArkUI_CustomDialog_RegisterOnDidDisappearCallback(ArkUI_CustomDialogOptions * options,void * userData,void (* callback)(void * userData))533 int32_t OH_ArkUI_CustomDialog_RegisterOnDidDisappearCallback(
534 ArkUI_CustomDialogOptions* options, void* userData, void (*callback)(void* userData))
535 {
536 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
537 if (!impl || !options) {
538 return ARKUI_ERROR_CODE_PARAM_INVALID;
539 }
540 return impl->getDialogAPI()->registerOnDidDisappear(options->handle, userData, callback);
541 }
542
OH_ArkUI_CustomDialog_SetBackgroundBlurStyleOptions(ArkUI_CustomDialogOptions * options,const ArkUI_AttributeItem * backgroundBlurStyleOptions)543 int32_t OH_ArkUI_CustomDialog_SetBackgroundBlurStyleOptions(
544 ArkUI_CustomDialogOptions* options, const ArkUI_AttributeItem* backgroundBlurStyleOptions)
545 {
546 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
547 if (!impl || !options) {
548 return ARKUI_ERROR_CODE_PARAM_INVALID;
549 }
550 auto size = backgroundBlurStyleOptions->size;
551 if (size < REQUIRED_ONE_PARAM) {
552 return ARKUI_ERROR_CODE_PARAM_INVALID;
553 }
554 int32_t colorMode = ParseColorMode(backgroundBlurStyleOptions, BLURSTYLE_COLOR_MODE);
555 int32_t adaptiveColor = ParseAdaptiveColor(backgroundBlurStyleOptions, BLURSTYLE_ADAPTIVE_COLOR);
556 float scale = ParseScale(backgroundBlurStyleOptions, BLURSTYLE_SCALE);
557 uint32_t grayScaleBlack = ParseGrayScaleBlack(backgroundBlurStyleOptions, BLURSTYLE_GRAY_SCALE_BLACK);
558 uint32_t grayScaleWhite = ParseGrayScaleWhite(backgroundBlurStyleOptions, BLURSTYLE_GRAY_SCALE_WHITE);
559 int32_t policy = ParsePolicy(backgroundBlurStyleOptions, BLURSTYLE_POLICY);
560 bool isValidColor = false;
561 uint32_t inactiveColor = COLOR_TRANSPARENT;
562 if (size > BLURSTYLE_INACTIVE_COLOR) {
563 inactiveColor = ColorAlphaAdapt(backgroundBlurStyleOptions->value[BLURSTYLE_INACTIVE_COLOR].u32);
564 isValidColor = true;
565 }
566 int32_t intArray[NUM_3];
567 intArray[NUM_0] = colorMode;
568 intArray[NUM_1] = adaptiveColor;
569 intArray[NUM_2] = policy;
570 uint32_t uintArray[NUM_3];
571 uintArray[NUM_0] = grayScaleBlack;
572 uintArray[NUM_1] = grayScaleWhite;
573 uintArray[NUM_2] = inactiveColor;
574 return impl->getDialogAPI()->setBackgroundBlurStyleOptions(
575 options->handle, &intArray, scale, &uintArray, isValidColor);
576 }
577
OH_ArkUI_CustomDialog_SetBackgroundEffect(ArkUI_CustomDialogOptions * options,const ArkUI_AttributeItem * backgroundEffect)578 int32_t OH_ArkUI_CustomDialog_SetBackgroundEffect(
579 ArkUI_CustomDialogOptions* options, const ArkUI_AttributeItem* backgroundEffect)
580 {
581 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
582 if (!impl || !options) {
583 return ARKUI_ERROR_CODE_PARAM_INVALID;
584 }
585 auto size = backgroundEffect->size;
586 if (size < REQUIRED_ONE_PARAM) {
587 return ARKUI_ERROR_CODE_PARAM_INVALID;
588 }
589 float radius = ParseRadius(backgroundEffect, EFFECT_RADIUS);
590 float saturation = ParseSaturation(backgroundEffect, EFFECT_SATURATION);
591 float brightness = ParseBrightness(backgroundEffect, EFFECT_BRIGHTNESS);
592 uint32_t color = ParseColor(backgroundEffect, EFFECT_COLOR);
593 int32_t adaptiveColor = ParseAdaptiveColor(backgroundEffect, EFFECT_ADAPTIVE_COLOR);
594 uint32_t grayScaleBlack = ParseGrayScaleBlack(backgroundEffect, EFFECT_GRAY_SCALE_BLACK);
595 uint32_t grayScaleWhite = ParseGrayScaleWhite(backgroundEffect, EFFECT_GRAY_SCALE_WHITE);
596 int32_t policy = ParsePolicy(backgroundEffect, EFFECT_POLICY);
597 bool isValidColor = false;
598 uint32_t inactiveColor = COLOR_TRANSPARENT;
599 if (size > EFFECT_COLOR_INDEX) {
600 inactiveColor = ColorAlphaAdapt(backgroundEffect->value[EFFECT_COLOR_INDEX].u32);
601 isValidColor = true;
602 }
603 float floatArray[NUM_3];
604 floatArray[NUM_0] = radius;
605 floatArray[NUM_1] = saturation;
606 floatArray[NUM_2] = brightness;
607 int32_t intArray[NUM_2];
608 intArray[NUM_0] = adaptiveColor;
609 intArray[NUM_1] = policy;
610 uint32_t uintArray[NUM_4];
611 uintArray[NUM_0] = color;
612 uintArray[NUM_1] = grayScaleBlack;
613 uintArray[NUM_2] = grayScaleWhite;
614 uintArray[NUM_3] = inactiveColor;
615 return impl->getDialogAPI()->setBackgroundEffect(options->handle, &floatArray, &intArray, &uintArray, isValidColor);
616 }
617
618 #ifdef __cplusplus
619 };
620 #endif
621