• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "dialog_model.h"
16 
17 #include "node_model.h"
18 
19 #include "base/error/error_code.h"
20 
21 #include "base/utils/utils.h"
22 
23 #include "node_model.h"
24 
25 namespace OHOS::Ace::DialogModel {
26 namespace {
27 constexpr double LEVEL_ORDER_MIN = -100000.0;
28 constexpr double LEVEL_ORDER_MAX = 100000.0;
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 (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 (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 (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 
Create()191 ArkUI_NativeDialogHandle Create()
192 {
193     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
194     if (!impl) {
195         return nullptr;
196     }
197     auto dialog = impl->getDialogAPI()->create();
198     return new ArkUI_NativeDialog({ dialog });
199 }
200 
Dispose(ArkUI_NativeDialogHandle handle)201 void Dispose(ArkUI_NativeDialogHandle handle)
202 {
203     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
204     if (!impl || !handle) {
205         return;
206     }
207     impl->getDialogAPI()->dispose(handle->controller);
208     delete handle;
209     handle = nullptr;
210 }
211 
SetContent(ArkUI_NativeDialogHandle handle,ArkUI_NodeHandle content)212 int32_t SetContent(ArkUI_NativeDialogHandle handle, ArkUI_NodeHandle content)
213 {
214     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
215     if (!impl || !handle || !content) {
216         return ERROR_CODE_PARAM_INVALID;
217     }
218     return impl->getDialogAPI()->setContent(handle->controller, content->uiNodeHandle);
219 }
220 
RemoveContent(ArkUI_NativeDialogHandle handle)221 int32_t RemoveContent(ArkUI_NativeDialogHandle handle)
222 {
223     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
224     if (!impl || !handle) {
225         return ERROR_CODE_PARAM_INVALID;
226     }
227     return impl->getDialogAPI()->removeContent(handle->controller);
228 }
229 
SetContentAlignment(ArkUI_NativeDialogHandle handle,int32_t alignment,float offsetX,float offsetY)230 int32_t SetContentAlignment(ArkUI_NativeDialogHandle handle, int32_t alignment, float offsetX, float offsetY)
231 {
232     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
233     if (!impl || !handle) {
234         return ERROR_CODE_PARAM_INVALID;
235     }
236     return impl->getDialogAPI()->setContentAlignment(handle->controller,
237         alignment, offsetX, offsetY);
238 }
239 
ResetContentAlignment(ArkUI_NativeDialogHandle handle)240 int32_t ResetContentAlignment(ArkUI_NativeDialogHandle handle)
241 {
242     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
243     if (!impl || !handle) {
244         return ERROR_CODE_PARAM_INVALID;
245     }
246     return impl->getDialogAPI()->resetContentAlignment(handle->controller);
247 }
248 
SetModalMode(ArkUI_NativeDialogHandle handle,bool isModal)249 int32_t SetModalMode(ArkUI_NativeDialogHandle handle, bool isModal)
250 {
251     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
252     if (!impl || !handle) {
253         return ERROR_CODE_PARAM_INVALID;
254     }
255     return impl->getDialogAPI()->setModalMode(handle->controller, isModal);
256 }
257 
SetAutoCancel(ArkUI_NativeDialogHandle handle,bool autoCancel)258 int32_t SetAutoCancel(ArkUI_NativeDialogHandle handle, bool autoCancel)
259 {
260     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
261     if (!impl || !handle) {
262         return ERROR_CODE_PARAM_INVALID;
263     }
264     return impl->getDialogAPI()->setAutoCancel(handle->controller, autoCancel);
265 }
266 
SetMask(ArkUI_NativeDialogHandle handle,uint32_t maskColor,const ArkUI_Rect * maskRect)267 int32_t SetMask(ArkUI_NativeDialogHandle handle, uint32_t maskColor, const ArkUI_Rect* maskRect)
268 {
269     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
270     if (!impl || !handle) {
271         return ERROR_CODE_PARAM_INVALID;
272     }
273     if (maskRect) {
274         ArkUIRect rect = { maskRect->x, maskRect->y, maskRect->width, maskRect->height };
275         return impl->getDialogAPI()->setMask(handle->controller, maskColor, &rect);
276     } else {
277         return impl->getDialogAPI()->setMask(handle->controller, maskColor, nullptr);
278     }
279 }
280 
SetBackgroundColor(ArkUI_NativeDialogHandle handle,uint32_t backgroundColor)281 int32_t SetBackgroundColor(ArkUI_NativeDialogHandle handle, uint32_t backgroundColor)
282 {
283     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
284     if (!impl || !handle) {
285         return ERROR_CODE_PARAM_INVALID;
286     }
287     return impl->getDialogAPI()->setBackgroundColor(handle->controller, backgroundColor);
288 }
289 
SetCornerRadius(ArkUI_NativeDialogHandle handle,float topLeft,float topRight,float bottomLeft,float bottomRight)290 int32_t SetCornerRadius(ArkUI_NativeDialogHandle handle, float topLeft, float topRight,
291     float bottomLeft, float bottomRight)
292 {
293     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
294     if (!impl || !handle) {
295         return ERROR_CODE_PARAM_INVALID;
296     }
297     return impl->getDialogAPI()->setCornerRadius(handle->controller,
298         topLeft, topRight, bottomLeft, bottomRight);
299 }
300 
SetGridColumnCount(ArkUI_NativeDialogHandle handle,int32_t gridCount)301 int32_t SetGridColumnCount(ArkUI_NativeDialogHandle handle, int32_t gridCount)
302 {
303     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
304     if (!impl || !handle) {
305         return ERROR_CODE_PARAM_INVALID;
306     }
307     return impl->getDialogAPI()->setGridColumnCount(handle->controller, gridCount);
308 }
309 
EnableCustomStyle(ArkUI_NativeDialogHandle handle,bool enableCustomStyle)310 int32_t EnableCustomStyle(ArkUI_NativeDialogHandle handle, bool enableCustomStyle)
311 {
312     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
313     if (!impl || !handle) {
314         return ERROR_CODE_PARAM_INVALID;
315     }
316     return impl->getDialogAPI()->enableCustomStyle(handle->controller, enableCustomStyle);
317 }
318 
EnableCustomAnimation(ArkUI_NativeDialogHandle handle,bool enableCustomAnimation)319 int32_t EnableCustomAnimation(ArkUI_NativeDialogHandle handle, bool enableCustomAnimation)
320 {
321     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
322     if (!impl || !handle) {
323         return ERROR_CODE_PARAM_INVALID;
324     }
325     return impl->getDialogAPI()->enableCustomAnimation(handle->controller, enableCustomAnimation);
326 }
327 
Show(ArkUI_NativeDialogHandle handle,bool showInSubWindow)328 int32_t Show(ArkUI_NativeDialogHandle handle, bool showInSubWindow)
329 {
330     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
331     if (!impl || !handle) {
332         return ERROR_CODE_PARAM_INVALID;
333     }
334     return impl->getDialogAPI()->show(handle->controller, showInSubWindow);
335 }
336 
Close(ArkUI_NativeDialogHandle handle)337 int32_t Close(ArkUI_NativeDialogHandle handle)
338 {
339     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
340     if (!impl || !handle) {
341         return ERROR_CODE_PARAM_INVALID;
342     }
343     return impl->getDialogAPI()->close(handle->controller);
344 }
345 
RegisterOnWillDismiss(ArkUI_NativeDialogHandle handle,ArkUI_OnWillDismissEvent eventHandler)346 int32_t RegisterOnWillDismiss(ArkUI_NativeDialogHandle handle, ArkUI_OnWillDismissEvent eventHandler)
347 {
348     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
349     if (!impl || !handle) {
350         return ERROR_CODE_PARAM_INVALID;
351     }
352     return impl->getDialogAPI()->registerOnWillDismiss(handle->controller, eventHandler);
353 }
354 
RegisterOnWillDismissWithUserData(ArkUI_NativeDialogHandle handle,void * userData,void (* callback)(ArkUI_DialogDismissEvent * event))355 int32_t RegisterOnWillDismissWithUserData(
356     ArkUI_NativeDialogHandle handle, void* userData, void (*callback)(ArkUI_DialogDismissEvent* event))
357 {
358     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
359     if (!impl || !handle) {
360         return ERROR_CODE_PARAM_INVALID;
361     }
362     int result = impl->getDialogAPI()->registerOnWillDismissWithUserData(handle->controller, userData, callback);
363     return result;
364 }
365 
SetKeyboardAvoidDistance(ArkUI_NativeDialogHandle handle,float distance,ArkUI_LengthMetricUnit unit)366 int32_t SetKeyboardAvoidDistance(
367     ArkUI_NativeDialogHandle handle, float distance, ArkUI_LengthMetricUnit unit)
368 {
369     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
370     if (!impl) {
371         return ARKUI_ERROR_CODE_CAPI_INIT_ERROR;
372     }
373     if (!handle) {
374         return ARKUI_ERROR_CODE_PARAM_INVALID;
375     }
376     if (unit < ARKUI_LENGTH_METRIC_UNIT_DEFAULT || unit > ARKUI_LENGTH_METRIC_UNIT_FP) {
377         return ARKUI_ERROR_CODE_PARAM_INVALID;
378     }
379     int result = impl->getDialogAPI()->setKeyboardAvoidDistance(handle->controller, distance, unit);
380     return result;
381 }
382 
SetLevelMode(ArkUI_NativeDialogHandle handle,ArkUI_LevelMode levelMode)383 int32_t SetLevelMode(ArkUI_NativeDialogHandle handle, ArkUI_LevelMode levelMode)
384 {
385     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
386     if (!impl) {
387         return ARKUI_ERROR_CODE_CAPI_INIT_ERROR;
388     }
389     if (!handle) {
390         return ARKUI_ERROR_CODE_PARAM_INVALID;
391     }
392     if (static_cast<int32_t>(levelMode) < static_cast<int32_t>(ARKUI_LEVEL_MODE_OVERLAY) ||
393         static_cast<int32_t>(levelMode) > static_cast<int32_t>(ARKUI_LEVEL_MODE_EMBEDDED)) {
394         return ARKUI_ERROR_CODE_PARAM_INVALID;
395     }
396     return impl->getDialogAPI()->setLevelMode(handle->controller, static_cast<int32_t>(levelMode));
397 }
398 
SetLevelUniqueId(ArkUI_NativeDialogHandle handle,int32_t uniqueId)399 int32_t SetLevelUniqueId(ArkUI_NativeDialogHandle handle, int32_t uniqueId)
400 {
401     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
402     if (!impl) {
403         return ARKUI_ERROR_CODE_CAPI_INIT_ERROR;
404     }
405     if (!handle || uniqueId < 0) {
406         return ARKUI_ERROR_CODE_PARAM_INVALID;
407     }
408     return impl->getDialogAPI()->setLevelUniqueId(handle->controller, uniqueId);
409 }
410 
SetImmersiveMode(ArkUI_NativeDialogHandle handle,ArkUI_ImmersiveMode immersiveMode)411 int32_t SetImmersiveMode(ArkUI_NativeDialogHandle handle, ArkUI_ImmersiveMode immersiveMode)
412 {
413     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
414     if (!impl) {
415         return ARKUI_ERROR_CODE_CAPI_INIT_ERROR;
416     }
417     if (!handle) {
418         return ARKUI_ERROR_CODE_PARAM_INVALID;
419     }
420     if (static_cast<int32_t>(immersiveMode) < static_cast<int32_t>(ARKUI_IMMERSIVE_MODE_DEFAULT) ||
421         static_cast<int32_t>(immersiveMode) > static_cast<int32_t>(ARKUI_IMMERSIVE_MODE_EXTEND)) {
422         return ARKUI_ERROR_CODE_PARAM_INVALID;
423     }
424     return impl->getDialogAPI()->setImmersiveMode(handle->controller, static_cast<int32_t>(immersiveMode));
425 }
426 
SetLevelOrder(ArkUI_NativeDialogHandle handle,double levelOrder)427 int32_t SetLevelOrder(ArkUI_NativeDialogHandle handle, double levelOrder)
428 {
429     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
430     if (!impl) {
431         return ARKUI_ERROR_CODE_CAPI_INIT_ERROR;
432     }
433     if (!handle) {
434         return ARKUI_ERROR_CODE_PARAM_INVALID;
435     }
436     if (levelOrder < LEVEL_ORDER_MIN || levelOrder > LEVEL_ORDER_MAX) {
437         return ARKUI_ERROR_CODE_PARAM_INVALID;
438     }
439     return impl->getDialogAPI()->setLevelOrder(handle->controller, levelOrder);
440 }
441 
RegisterOnWillAppear(ArkUI_NativeDialogHandle handle,void * userData,void (* callback)(void * userData))442 int32_t RegisterOnWillAppear(ArkUI_NativeDialogHandle handle, void* userData, void (*callback)(void* userData))
443 {
444     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
445     if (!impl || !handle) {
446         return ARKUI_ERROR_CODE_PARAM_INVALID;
447     }
448     int result = impl->getDialogAPI()->registerOnWillAppear(handle->controller, userData, callback);
449     return result;
450 }
451 
RegisterOnDidAppear(ArkUI_NativeDialogHandle handle,void * userData,void (* callback)(void * userData))452 int32_t RegisterOnDidAppear(ArkUI_NativeDialogHandle handle, void* userData, void (*callback)(void* userData))
453 {
454     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
455     if (!impl || !handle) {
456         return ARKUI_ERROR_CODE_PARAM_INVALID;
457     }
458     int result = impl->getDialogAPI()->registerOnDidAppear(handle->controller, userData, callback);
459     return result;
460 }
461 
RegisterOnWillDisappear(ArkUI_NativeDialogHandle handle,void * userData,void (* callback)(void * userData))462 int32_t RegisterOnWillDisappear(ArkUI_NativeDialogHandle handle, void* userData, void (*callback)(void* userData))
463 {
464     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
465     if (!impl || !handle) {
466         return ARKUI_ERROR_CODE_PARAM_INVALID;
467     }
468     int result = impl->getDialogAPI()->registerOnWillDisappear(handle->controller, userData, callback);
469     return result;
470 }
471 
RegisterOnDidDisappear(ArkUI_NativeDialogHandle handle,void * userData,void (* callback)(void * userData))472 int32_t RegisterOnDidDisappear(ArkUI_NativeDialogHandle handle, void* userData, void (*callback)(void* userData))
473 {
474     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
475     if (!impl || !handle) {
476         return ARKUI_ERROR_CODE_PARAM_INVALID;
477     }
478     int result = impl->getDialogAPI()->registerOnDidDisappear(handle->controller, userData, callback);
479     return result;
480 }
481 
SetBorderWidth(ArkUI_NativeDialogHandle handle,float top,float right,float bottom,float left,ArkUI_LengthMetricUnit unit)482 int32_t SetBorderWidth(
483     ArkUI_NativeDialogHandle handle, float top, float right, float bottom, float left, ArkUI_LengthMetricUnit unit)
484 {
485     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
486     if (!impl) {
487         return ARKUI_ERROR_CODE_PARAM_INVALID;
488     }
489     if (!handle) {
490         return ARKUI_ERROR_CODE_PARAM_INVALID;
491     }
492     if (unit < ARKUI_LENGTH_METRIC_UNIT_DEFAULT || unit > ARKUI_LENGTH_METRIC_UNIT_FP) {
493         return ARKUI_ERROR_CODE_PARAM_INVALID;
494     }
495     return impl->getDialogAPI()->setBorderWidth(handle->controller, top, right, bottom, left, unit);
496 }
497 
SetBorderColor(ArkUI_NativeDialogHandle handle,uint32_t top,uint32_t right,uint32_t bottom,uint32_t left)498 int32_t SetBorderColor(ArkUI_NativeDialogHandle handle, uint32_t top, uint32_t right, uint32_t bottom, uint32_t left)
499 {
500     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
501     if (!impl) {
502         return ARKUI_ERROR_CODE_PARAM_INVALID;
503     }
504     if (!handle) {
505         return ARKUI_ERROR_CODE_PARAM_INVALID;
506     }
507     return impl->getDialogAPI()->setBorderColor(handle->controller, top, right, bottom, left);
508 }
509 
SetBorderStyle(ArkUI_NativeDialogHandle handle,int32_t top,int32_t right,int32_t bottom,int32_t left)510 int32_t SetBorderStyle(ArkUI_NativeDialogHandle handle, int32_t top, int32_t right, int32_t bottom, int32_t left)
511 {
512     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
513     if (!impl) {
514         return ARKUI_ERROR_CODE_PARAM_INVALID;
515     }
516     if (!handle) {
517         return ARKUI_ERROR_CODE_PARAM_INVALID;
518     }
519     return impl->getDialogAPI()->setBorderStyle(handle->controller, top, right, bottom, left);
520 }
521 
SetWidth(ArkUI_NativeDialogHandle handle,float width,ArkUI_LengthMetricUnit unit)522 int32_t SetWidth(ArkUI_NativeDialogHandle handle, float width, ArkUI_LengthMetricUnit unit)
523 {
524     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
525     if (!impl) {
526         return ARKUI_ERROR_CODE_PARAM_INVALID;
527     }
528     if (!handle) {
529         return ARKUI_ERROR_CODE_PARAM_INVALID;
530     }
531     if (unit < ARKUI_LENGTH_METRIC_UNIT_DEFAULT || unit > ARKUI_LENGTH_METRIC_UNIT_FP) {
532         return ARKUI_ERROR_CODE_PARAM_INVALID;
533     }
534     int result = impl->getDialogAPI()->setWidth(handle->controller, width, unit);
535     return result;
536 }
537 
SetHeight(ArkUI_NativeDialogHandle handle,float height,ArkUI_LengthMetricUnit unit)538 int32_t SetHeight(ArkUI_NativeDialogHandle handle, float height, ArkUI_LengthMetricUnit unit)
539 {
540     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
541     if (!impl) {
542         return ARKUI_ERROR_CODE_PARAM_INVALID;
543     }
544     if (!handle) {
545         return ARKUI_ERROR_CODE_PARAM_INVALID;
546     }
547     if (unit < ARKUI_LENGTH_METRIC_UNIT_DEFAULT || unit > ARKUI_LENGTH_METRIC_UNIT_FP) {
548         return ARKUI_ERROR_CODE_PARAM_INVALID;
549     }
550     int result = impl->getDialogAPI()->setHeight(handle->controller, height, unit);
551     return result;
552 }
553 
SetShadow(ArkUI_NativeDialogHandle handle,ArkUI_ShadowStyle shadow)554 int32_t SetShadow(ArkUI_NativeDialogHandle handle, ArkUI_ShadowStyle shadow)
555 {
556     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
557     if (!impl) {
558         return ARKUI_ERROR_CODE_PARAM_INVALID;
559     }
560     if (!handle) {
561         return ARKUI_ERROR_CODE_PARAM_INVALID;
562     }
563     int result = impl->getDialogAPI()->setShadow(handle->controller, shadow);
564     return result;
565 }
566 
SetCustomShadow(ArkUI_NativeDialogHandle handle,const ArkUI_AttributeItem * customShadow)567 int32_t SetCustomShadow(ArkUI_NativeDialogHandle handle, const ArkUI_AttributeItem* customShadow)
568 {
569     if (customShadow->size == 0) {
570         return ARKUI_ERROR_CODE_PARAM_INVALID;
571     }
572     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
573     if (!impl) {
574         return ARKUI_ERROR_CODE_PARAM_INVALID;
575     }
576     if (!handle) {
577         return ARKUI_ERROR_CODE_PARAM_INVALID;
578     }
579     ArkUIInt32orFloat32 shadows[ALLOW_SIZE_7] = { 0, { .i32 = NUM_2 }, 0, 0, { .i32 = 0 }, { .u32 = 0 }, { .i32 = 0 } };
580     int length = customShadow->size;
581     if (length > NUM_0) {
582         if (LessNotEqual(customShadow->value[NUM_0].f32, 0.0f)) {
583             return ARKUI_ERROR_CODE_PARAM_INVALID;
584         }
585         shadows[NUM_0].f32 = customShadow->value[NUM_0].f32; // radius
586     }
587     if (length > NUM_2) {
588         shadows[NUM_2].f32 = customShadow->value[NUM_2].f32; // OffsetX
589     }
590     if (length > NUM_3) {
591         shadows[NUM_3].f32 = customShadow->value[NUM_3].f32; // OffsetY
592     }
593     if (length > NUM_4) {
594         if (!InRegion(NUM_0, NUM_1, customShadow->value[NUM_4].i32)) {
595             return ARKUI_ERROR_CODE_PARAM_INVALID;
596         }
597         shadows[NUM_4].i32 = customShadow->value[NUM_4].i32;
598     }
599     if (length > NUM_5) {
600         if (customShadow->value[NUM_1].i32) {
601             if (!InRegion(NUM_0, NUM_2, customShadow->value[NUM_5].i32)) {
602                 return ARKUI_ERROR_CODE_PARAM_INVALID;
603             }
604             shadows[NUM_1].i32 = COLOR_STRATEGY_STYLE;
605             shadows[NUM_5].i32 = customShadow->value[NUM_5].i32;
606         } else {
607             shadows[NUM_1].i32 = COLOR_STYLE;
608             shadows[NUM_5].u32 = customShadow->value[NUM_5].u32;
609         }
610     }
611     if (length > NUM_6) {
612         shadows[NUM_6].i32 = customShadow->value[NUM_6].i32;
613     }
614     int result = impl->getDialogAPI()->setCustomShadow(handle->controller, shadows, ALLOW_SIZE_7);
615     return result;
616 }
617 
SetBackgroundBlurStyle(ArkUI_NativeDialogHandle handle,ArkUI_BlurStyle blurStyle)618 int32_t SetBackgroundBlurStyle(ArkUI_NativeDialogHandle handle, ArkUI_BlurStyle blurStyle)
619 {
620     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
621     if (!impl) {
622         return ARKUI_ERROR_CODE_PARAM_INVALID;
623     }
624     if (!handle) {
625         return ARKUI_ERROR_CODE_PARAM_INVALID;
626     }
627     int result = impl->getDialogAPI()->setBackgroundBlurStyle(handle->controller, blurStyle);
628     return result;
629 }
630 
SetKeyboardAvoidMode(ArkUI_NativeDialogHandle handle,ArkUI_KeyboardAvoidMode keyboardAvoidMode)631 int32_t SetKeyboardAvoidMode(ArkUI_NativeDialogHandle handle, ArkUI_KeyboardAvoidMode keyboardAvoidMode)
632 {
633     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
634     if (!impl) {
635         return ARKUI_ERROR_CODE_PARAM_INVALID;
636     }
637     if (!handle) {
638         return ARKUI_ERROR_CODE_PARAM_INVALID;
639     }
640     int result = impl->getDialogAPI()->setKeyboardAvoidMode(handle->controller, keyboardAvoidMode);
641     return result;
642 }
643 
EnableHoverMode(ArkUI_NativeDialogHandle handle,bool enableHoverMode)644 int32_t EnableHoverMode(ArkUI_NativeDialogHandle handle, bool enableHoverMode)
645 {
646     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
647     if (!impl) {
648         return ARKUI_ERROR_CODE_PARAM_INVALID;
649     }
650     if (!handle) {
651         return ARKUI_ERROR_CODE_PARAM_INVALID;
652     }
653     int result = impl->getDialogAPI()->enableHoverMode(handle->controller, enableHoverMode);
654     return result;
655 }
656 
SetHoverModeArea(ArkUI_NativeDialogHandle handle,ArkUI_HoverModeAreaType hoverModeAreaType)657 int32_t SetHoverModeArea(ArkUI_NativeDialogHandle handle, ArkUI_HoverModeAreaType hoverModeAreaType)
658 {
659     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
660     if (!impl) {
661         return ARKUI_ERROR_CODE_PARAM_INVALID;
662     }
663     if (!handle) {
664         return ARKUI_ERROR_CODE_PARAM_INVALID;
665     }
666     int result = impl->getDialogAPI()->setHoverModeArea(handle->controller, hoverModeAreaType);
667     return result;
668 }
669 
SetFocusable(ArkUI_NativeDialogHandle handle,bool focusable)670 int32_t SetFocusable(ArkUI_NativeDialogHandle handle, bool focusable)
671 {
672     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
673     if (!impl) {
674         return ARKUI_ERROR_CODE_CAPI_INIT_ERROR;
675     }
676     if (!handle) {
677         return ARKUI_ERROR_CODE_PARAM_INVALID;
678     }
679     return impl->getDialogAPI()->setFocusable(handle->controller, focusable);
680 }
681 
SetBackgroundBlurStyleOptions(ArkUI_NativeDialogHandle handle,const ArkUI_AttributeItem * backgroundBlurStyleOptions)682 int32_t SetBackgroundBlurStyleOptions(
683     ArkUI_NativeDialogHandle handle, const ArkUI_AttributeItem* backgroundBlurStyleOptions)
684 {
685     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
686     if (!impl || !handle) {
687         return ERROR_CODE_PARAM_INVALID;
688     }
689     auto size = backgroundBlurStyleOptions->size;
690     if (size < REQUIRED_ONE_PARAM) {
691         return ARKUI_ERROR_CODE_PARAM_INVALID;
692     }
693     int32_t colorMode = ParseColorMode(backgroundBlurStyleOptions, BLURSTYLE_COLOR_MODE);
694     int32_t adaptiveColor = ParseAdaptiveColor(backgroundBlurStyleOptions, BLURSTYLE_ADAPTIVE_COLOR);
695     float scale = ParseScale(backgroundBlurStyleOptions, BLURSTYLE_SCALE);
696     uint32_t grayScaleBlack = ParseGrayScaleBlack(backgroundBlurStyleOptions, BLURSTYLE_GRAY_SCALE_BLACK);
697     uint32_t grayScaleWhite = ParseGrayScaleWhite(backgroundBlurStyleOptions, BLURSTYLE_GRAY_SCALE_WHITE);
698     int32_t policy = ParsePolicy(backgroundBlurStyleOptions, BLURSTYLE_POLICY);
699     bool isValidColor = false;
700     uint32_t inactiveColor = COLOR_TRANSPARENT;
701     if (size > BLURSTYLE_INACTIVE_COLOR) {
702         inactiveColor = ColorAlphaAdapt(backgroundBlurStyleOptions->value[BLURSTYLE_INACTIVE_COLOR].u32);
703         isValidColor = true;
704     }
705     int32_t intArray[NUM_3];
706     intArray[NUM_0] = colorMode;
707     intArray[NUM_1] = adaptiveColor;
708     intArray[NUM_2] = policy;
709     uint32_t uintArray[NUM_3];
710     uintArray[NUM_0] = grayScaleBlack;
711     uintArray[NUM_1] = grayScaleWhite;
712     uintArray[NUM_2] = inactiveColor;
713     int result = impl->getDialogAPI()->setBackgroundBlurStyleOptions(
714         handle->controller, &intArray, scale, &uintArray, isValidColor);
715     return result;
716 }
717 
SetBackgroundEffect(ArkUI_NativeDialogHandle handle,const ArkUI_AttributeItem * backgroundEffect)718 int32_t SetBackgroundEffect(ArkUI_NativeDialogHandle handle, const ArkUI_AttributeItem* backgroundEffect)
719 {
720     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
721     if (!impl || !handle) {
722         return ERROR_CODE_PARAM_INVALID;
723     }
724     auto size = backgroundEffect->size;
725     if (size < REQUIRED_ONE_PARAM) {
726         return ARKUI_ERROR_CODE_PARAM_INVALID;
727     }
728     float radius = ParseRadius(backgroundEffect, EFFECT_RADIUS);
729     float saturation = ParseSaturation(backgroundEffect, EFFECT_SATURATION);
730     float brightness = ParseBrightness(backgroundEffect, EFFECT_BRIGHTNESS);
731     uint32_t color = ParseColor(backgroundEffect, EFFECT_COLOR);
732     int32_t adaptiveColor = ParseAdaptiveColor(backgroundEffect, EFFECT_ADAPTIVE_COLOR);
733     uint32_t grayScaleBlack = ParseGrayScaleBlack(backgroundEffect, EFFECT_GRAY_SCALE_BLACK);
734     uint32_t grayScaleWhite = ParseGrayScaleWhite(backgroundEffect, EFFECT_GRAY_SCALE_WHITE);
735     int32_t policy = ParsePolicy(backgroundEffect, EFFECT_POLICY);
736     bool isValidColor = false;
737     uint32_t inactiveColor = COLOR_TRANSPARENT;
738     if (size > EFFECT_COLOR_INDEX) {
739         inactiveColor = ColorAlphaAdapt(backgroundEffect->value[EFFECT_COLOR_INDEX].u32);
740         isValidColor = true;
741     }
742     float floatArray[NUM_3];
743     floatArray[NUM_0] = radius;
744     floatArray[NUM_1] = saturation;
745     floatArray[NUM_2] = brightness;
746     int32_t intArray[NUM_2];
747     intArray[NUM_0] = adaptiveColor;
748     intArray[NUM_1] = policy;
749     uint32_t uintArray[NUM_4];
750     uintArray[NUM_0] = color;
751     uintArray[NUM_1] = grayScaleBlack;
752     uintArray[NUM_2] = grayScaleWhite;
753     uintArray[NUM_3] = inactiveColor;
754     int result =
755         impl->getDialogAPI()->setBackgroundEffect(handle->controller, &floatArray, &intArray, &uintArray, isValidColor);
756     return result;
757 }
758 } // namespace OHOS::Ace::NG::DialogModel
759 
760 #ifdef __cplusplus
761 extern "C" {
762 #endif
763 
OH_ArkUI_DialogDismissEvent_SetShouldBlockDismiss(ArkUI_DialogDismissEvent * event,bool shouldBlockDismiss)764 void OH_ArkUI_DialogDismissEvent_SetShouldBlockDismiss(ArkUI_DialogDismissEvent* event, bool shouldBlockDismiss)
765 {
766     if (!event) {
767         return;
768     }
769     event->BlockDismiss = shouldBlockDismiss;
770 }
771 
OH_ArkUI_DialogDismissEvent_GetUserData(ArkUI_DialogDismissEvent * event)772 void* OH_ArkUI_DialogDismissEvent_GetUserData(ArkUI_DialogDismissEvent* event)
773 {
774     if (!event) {
775         return nullptr;
776     }
777     return event->userData;
778 }
779 
OH_ArkUI_DialogDismissEvent_GetDismissReason(ArkUI_DialogDismissEvent * event)780 int32_t OH_ArkUI_DialogDismissEvent_GetDismissReason(ArkUI_DialogDismissEvent* event)
781 {
782     if (!event) {
783         return -1;
784     }
785     return event->reason;
786 }
787 
OH_ArkUI_CustomDialog_GetState(ArkUI_NativeDialogHandle handle,ArkUI_DialogState * dialogState)788 int32_t OH_ArkUI_CustomDialog_GetState(ArkUI_NativeDialogHandle handle, ArkUI_DialogState* dialogState)
789 {
790     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
791     int32_t tem = 1;
792     if (!impl || !handle || !dialogState) {
793         return ARKUI_ERROR_CODE_PARAM_INVALID;
794     }
795     *dialogState = static_cast<ArkUI_DialogState>(tem);
796     int32_t result = impl->getDialogAPI()->getState(handle->controller, &tem);
797     if (result == ARKUI_ERROR_CODE_NO_ERROR) {
798         *dialogState = static_cast<ArkUI_DialogState>(tem);
799     }
800     return result;
801 }
802 
803 #ifdef __cplusplus
804 };
805 #endif