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 <cstdint>
16
17 #include "interfaces/native/drag_and_drop.h"
18 #include "interfaces/native/node/event_converter.h"
19 #include "interfaces/native/node/node_model.h"
20 #include "async_task_params.h"
21 #include "data_params_conversion.h"
22 #include "native_node.h"
23 #include "native_type.h"
24 #include "ndk_data_conversion.h"
25 #include "pixelmap_native_impl.h"
26 #include "securec.h"
27 #include "udmf_async_client.h"
28 #include "unified_types.h"
29
30 #include "base/error/error_code.h"
31 #include "base/log/log_wrapper.h"
32 #include "base/utils/utils.h"
33 #include "core/interfaces/arkoala/arkoala_api.h"
34 #include "frameworks/bridge/common/utils/engine_helper.h"
35 #include "frameworks/core/common/ace_engine.h"
36 #include "frameworks/core/common/container.h"
37 #include "frameworks/core/interfaces/native/node/node_api.h"
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 namespace {
44 constexpr int32_t MAX_POINTID = 9;
45 constexpr int32_t MIN_POINTID = 0;
46 } // namespace
47
OH_ArkUI_DragEvent_GetModifierKeyStates(ArkUI_DragEvent * event,uint64_t * keys)48 int32_t OH_ArkUI_DragEvent_GetModifierKeyStates(ArkUI_DragEvent* event, uint64_t* keys)
49 {
50 if (!event || !keys) {
51 return ARKUI_ERROR_CODE_PARAM_INVALID;
52 }
53 auto dragEvent = reinterpret_cast<ArkUIDragEvent*>(event);
54 *keys = dragEvent->modifierKeyState;
55 return ARKUI_ERROR_CODE_NO_ERROR;
56 }
57
OH_ArkUI_DragEvent_SetData(ArkUI_DragEvent * event,OH_UdmfData * data)58 int32_t OH_ArkUI_DragEvent_SetData(ArkUI_DragEvent* event, OH_UdmfData* data)
59 {
60 auto dragEvent = reinterpret_cast<ArkUIDragEvent*>(event);
61
62 if (!event || !data || !dragEvent) {
63 return ARKUI_ERROR_CODE_PARAM_INVALID;
64 }
65 dragEvent->unifiedData = data;
66
67 return ARKUI_ERROR_CODE_NO_ERROR;
68 }
69
OH_ArkUI_DragEvent_GetUdmfData(ArkUI_DragEvent * event,OH_UdmfData * data)70 int32_t OH_ArkUI_DragEvent_GetUdmfData(ArkUI_DragEvent* event, OH_UdmfData* data)
71 {
72 auto dragEvent = reinterpret_cast<ArkUIDragEvent*>(event);
73
74 if (!event || !dragEvent || (dragEvent->unifiedData == nullptr) || !data) {
75 return ARKUI_ERROR_CODE_PARAM_INVALID;
76 }
77
78 if (!(dragEvent->isSuitGetData)) {
79 return ARKUI_ERROR_CODE_PARAM_INVALID;
80 }
81 auto unifiedData =
82 std::make_shared<OHOS::UDMF::UnifiedData>(*reinterpret_cast<OHOS::UDMF::UnifiedData*>(dragEvent->unifiedData));
83
84 auto status = OHOS::UDMF::NdkDataConversion::GetNdkUnifiedData(unifiedData, data);
85 if (status) {
86 return ARKUI_ERROR_CODE_PARAM_INVALID;
87 }
88 return ARKUI_ERROR_CODE_NO_ERROR;
89 }
90
OH_ArkUI_DragEvent_GetDataTypeCount(ArkUI_DragEvent * event,int32_t * count)91 int32_t OH_ArkUI_DragEvent_GetDataTypeCount(ArkUI_DragEvent* event, int32_t* count)
92 {
93 auto dragEvent = reinterpret_cast<ArkUIDragEvent*>(event);
94
95 if (!event || !count || !dragEvent) {
96 return ARKUI_ERROR_CODE_PARAM_INVALID;
97 }
98 *count = dragEvent->dataTypesCount;
99 return ARKUI_ERROR_CODE_NO_ERROR;
100 }
101
OH_ArkUI_DragEvent_GetDataTypes(ArkUI_DragEvent * event,char * eventTypeArray[],int32_t length,int32_t maxStrLen)102 int32_t OH_ArkUI_DragEvent_GetDataTypes(
103 ArkUI_DragEvent* event, char* eventTypeArray[], int32_t length, int32_t maxStrLen)
104 {
105 auto dragEvent = reinterpret_cast<ArkUIDragEvent*>(event);
106 if (!event || !eventTypeArray || !dragEvent) {
107 return ARKUI_ERROR_CODE_PARAM_INVALID;
108 }
109
110 if (length < dragEvent->dataTypesCount || maxStrLen < dragEvent->dataTypesMaxStrLength) {
111 return ARKUI_ERROR_CODE_BUFFER_SIZE_ERROR;
112 }
113 for (int32_t i = 0; i < length; i++) {
114 if (dragEvent->dataTypes[i]) {
115 auto strLeng = strlen(dragEvent->dataTypes[i]) + 1;
116 auto ret = strncpy_s(eventTypeArray[i], strLeng, dragEvent->dataTypes[i], strLeng - 1);
117 if (ret != 0) {
118 return ARKUI_ERROR_CODE_PARAM_INVALID;
119 }
120 eventTypeArray[i][strLeng - 1] = '\0';
121 } else {
122 eventTypeArray[i][0] = '\0';
123 }
124 }
125 return ARKUI_ERROR_CODE_NO_ERROR;
126 }
127
OH_ArkUI_CreateDragActionWithNode(ArkUI_NodeHandle node)128 ArkUI_DragAction* OH_ArkUI_CreateDragActionWithNode(ArkUI_NodeHandle node)
129 {
130 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
131 if (!impl || !node) {
132 return nullptr;
133 }
134 auto dragActions = impl->getDragAdapterAPI()->createDragActionWithNode(node->uiNodeHandle);
135 return reinterpret_cast<ArkUI_DragAction*>(dragActions);
136 }
137
OH_ArkUI_CreateDragActionWithContext(ArkUI_ContextHandle uiContext)138 ArkUI_DragAction* OH_ArkUI_CreateDragActionWithContext(ArkUI_ContextHandle uiContext)
139 {
140 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
141 if (!impl || !uiContext) {
142 return nullptr;
143 }
144 auto* context = reinterpret_cast<ArkUIContext*>(uiContext);
145 auto dragActions = impl->getDragAdapterAPI()->createDragActionWithContext(context);
146 return reinterpret_cast<ArkUI_DragAction*>(dragActions);
147 }
148
OH_ArkUI_DragAction_Dispose(ArkUI_DragAction * dragAction)149 void OH_ArkUI_DragAction_Dispose(ArkUI_DragAction* dragAction)
150 {
151 if (!dragAction) {
152 return;
153 }
154 delete reinterpret_cast<ArkUIDragAction*>(dragAction);
155 dragAction = nullptr;
156 }
157
OH_ArkUI_DragAction_SetPointerId(ArkUI_DragAction * dragAction,int32_t pointer)158 int32_t OH_ArkUI_DragAction_SetPointerId(ArkUI_DragAction* dragAction, int32_t pointer)
159 {
160 if (!dragAction) {
161 return ARKUI_ERROR_CODE_PARAM_INVALID;
162 }
163 auto* dragActions = reinterpret_cast<ArkUIDragAction*>(dragAction);
164 if (!dragActions) {
165 return ARKUI_ERROR_CODE_PARAM_INVALID;
166 }
167 if (pointer > MAX_POINTID || pointer < MIN_POINTID) {
168 dragActions->pointerId = -1;
169 return ARKUI_ERROR_CODE_PARAM_INVALID;
170 }
171 dragActions->pointerId = pointer;
172 return ARKUI_ERROR_CODE_NO_ERROR;
173 }
174
OH_ArkUI_DragAction_SetPixelMaps(ArkUI_DragAction * dragAction,OH_PixelmapNative * pixelmapArray[],int32_t size)175 int32_t OH_ArkUI_DragAction_SetPixelMaps(ArkUI_DragAction* dragAction, OH_PixelmapNative* pixelmapArray[], int32_t size)
176 {
177 if (!dragAction || !pixelmapArray) {
178 return ARKUI_ERROR_CODE_PARAM_INVALID;
179 }
180 auto* dragActions = reinterpret_cast<ArkUIDragAction*>(dragAction);
181 if (!dragActions) {
182 return ARKUI_ERROR_CODE_PARAM_INVALID;
183 }
184 int32_t count = 0;
185 for (int32_t index = 0; index < size; index++) {
186 if (!pixelmapArray[index]) {
187 continue;
188 }
189 count++;
190 }
191 if (count < size || size < 0) {
192 return ARKUI_ERROR_CODE_PARAM_INVALID;
193 }
194 dragActions->pixelmapNativeList = reinterpret_cast<void**>(pixelmapArray);
195 dragActions->size = size;
196 return ARKUI_ERROR_CODE_NO_ERROR;
197 }
198
OH_ArkUI_DragAction_SetTouchPointX(ArkUI_DragAction * dragAction,float x)199 int32_t OH_ArkUI_DragAction_SetTouchPointX(ArkUI_DragAction* dragAction, float x)
200 {
201 if (!dragAction) {
202 return ARKUI_ERROR_CODE_PARAM_INVALID;
203 }
204 auto* dragActions = reinterpret_cast<ArkUIDragAction*>(dragAction);
205 if (!dragActions) {
206 return ARKUI_ERROR_CODE_PARAM_INVALID;
207 }
208 dragActions->touchPointX = x;
209 dragActions->hasTouchPoint = true;
210 return ARKUI_ERROR_CODE_NO_ERROR;
211 }
212
OH_ArkUI_DragAction_SetTouchPointY(ArkUI_DragAction * dragAction,float y)213 int32_t OH_ArkUI_DragAction_SetTouchPointY(ArkUI_DragAction* dragAction, float y)
214 {
215 if (!dragAction) {
216 return ARKUI_ERROR_CODE_PARAM_INVALID;
217 }
218 auto* dragActions = reinterpret_cast<ArkUIDragAction*>(dragAction);
219 if (!dragActions) {
220 return ARKUI_ERROR_CODE_PARAM_INVALID;
221 }
222 dragActions->touchPointY = y;
223 dragActions->hasTouchPoint = true;
224 return ARKUI_ERROR_CODE_NO_ERROR;
225 }
226
OH_ArkUI_DragAction_SetData(ArkUI_DragAction * dragAction,OH_UdmfData * data)227 int32_t OH_ArkUI_DragAction_SetData(ArkUI_DragAction* dragAction, OH_UdmfData* data)
228 {
229 if (!dragAction || !data) {
230 return ARKUI_ERROR_CODE_PARAM_INVALID;
231 }
232 auto* dragActions = reinterpret_cast<ArkUIDragAction*>(dragAction);
233 dragActions->unifiedData = data;
234 return ARKUI_ERROR_CODE_NO_ERROR;
235 }
236
OH_ArkUI_DragAction_SetDragPreviewOption(ArkUI_DragAction * dragAction,ArkUI_DragPreviewOption * option)237 int32_t OH_ArkUI_DragAction_SetDragPreviewOption(ArkUI_DragAction* dragAction, ArkUI_DragPreviewOption* option)
238 {
239 if (!dragAction || !option) {
240 return ARKUI_ERROR_CODE_PARAM_INVALID;
241 }
242 auto* dragActions = reinterpret_cast<ArkUIDragAction*>(dragAction);
243 auto* options = reinterpret_cast<ArkUIDragPreViewAndInteractionOptions*>(option);
244 if (!dragActions || !options) {
245 return ARKUI_ERROR_CODE_PARAM_INVALID;
246 }
247 dragActions->dragPreviewOption = *options;
248 return ARKUI_ERROR_CODE_NO_ERROR;
249 }
250
OH_ArkUI_DragAction_RegisterStatusListener(ArkUI_DragAction * dragAction,void * userData,void (* listener)(ArkUI_DragAndDropInfo * dragAndDropInfo,void * userData))251 int32_t OH_ArkUI_DragAction_RegisterStatusListener(ArkUI_DragAction* dragAction, void* userData,
252 void (*listener)(ArkUI_DragAndDropInfo* dragAndDropInfo, void* userData))
253 {
254 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
255 if (!impl || !dragAction) {
256 return ARKUI_ERROR_CODE_PARAM_INVALID;
257 }
258 impl->getDragAdapterAPI()->registerStatusListener(
259 reinterpret_cast<ArkUIDragAction*>(dragAction), userData, (reinterpret_cast<DragStatusCallback>(listener)));
260 return ARKUI_ERROR_CODE_NO_ERROR;
261 }
262
OH_ArkUI_DragAction_UnregisterStatusListener(ArkUI_DragAction * dragAction)263 void OH_ArkUI_DragAction_UnregisterStatusListener(ArkUI_DragAction* dragAction)
264 {
265 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
266 if (!impl || !dragAction) {
267 return;
268 }
269 impl->getDragAdapterAPI()->unregisterStatusListener(reinterpret_cast<ArkUIDragAction*>(dragAction));
270 }
271
OH_ArkUI_DragAndDropInfo_GetDragStatus(ArkUI_DragAndDropInfo * dragAndDropInfo)272 ArkUI_DragStatus OH_ArkUI_DragAndDropInfo_GetDragStatus(ArkUI_DragAndDropInfo* dragAndDropInfo)
273 {
274 if (!dragAndDropInfo) {
275 return ArkUI_DragStatus::ARKUI_DRAG_STATUS_UNKNOWN;
276 }
277 auto* dragAndDropInfos = reinterpret_cast<ArkUIDragAndDropInfo*>(dragAndDropInfo);
278 if (!dragAndDropInfos) {
279 return ArkUI_DragStatus::ARKUI_DRAG_STATUS_UNKNOWN;
280 }
281 return static_cast<ArkUI_DragStatus>(dragAndDropInfos->status);
282 }
283
OH_ArkUI_DragAndDropInfo_GetDragEvent(ArkUI_DragAndDropInfo * dragAndDropInfo)284 ArkUI_DragEvent* OH_ArkUI_DragAndDropInfo_GetDragEvent(ArkUI_DragAndDropInfo* dragAndDropInfo)
285 {
286 if (!dragAndDropInfo) {
287 return nullptr;
288 }
289 auto* dragAndDropInfos = reinterpret_cast<ArkUIDragAndDropInfo*>(dragAndDropInfo);
290 return reinterpret_cast<ArkUI_DragEvent*>(dragAndDropInfos->dragEvent);
291 }
292
OH_ArkUI_StartDrag(ArkUI_DragAction * dragAction)293 int32_t OH_ArkUI_StartDrag(ArkUI_DragAction* dragAction)
294 {
295 if (!dragAction) {
296 return ARKUI_ERROR_CODE_PARAM_INVALID;
297 }
298 auto* dragActions = reinterpret_cast<ArkUIDragAction*>(dragAction);
299 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
300 if (!dragActions || !impl) {
301 return ARKUI_ERROR_CODE_PARAM_INVALID;
302 }
303 std::vector<std::shared_ptr<OHOS::Media::PixelMap>> pixelMapList;
304 auto pixelmapArray = reinterpret_cast<OH_PixelmapNative**>(dragActions->pixelmapNativeList);
305 for (int32_t index = 0; index < dragActions->size; index++) {
306 if (!pixelmapArray[index]) {
307 continue;
308 }
309 pixelMapList.push_back(pixelmapArray[index]->GetInnerPixelmap());
310 }
311 dragActions->pixelmapArray = reinterpret_cast<void**>(pixelMapList.data());
312 impl->getDragAdapterAPI()->startDrag(dragActions);
313 return ARKUI_ERROR_CODE_NO_ERROR;
314 }
315
OH_ArkUI_NodeEvent_GetPreDragStatus(ArkUI_NodeEvent * nodeEvent)316 ArkUI_PreDragStatus OH_ArkUI_NodeEvent_GetPreDragStatus(ArkUI_NodeEvent* nodeEvent)
317 {
318 if (!nodeEvent || nodeEvent->category != static_cast<int32_t>(NODE_EVENT_CATEGORY_COMPONENT_EVENT)) {
319 return ArkUI_PreDragStatus::ARKUI_PRE_DRAG_STATUS_UNKNOWN;
320 }
321 const auto* originNodeEvent = reinterpret_cast<ArkUINodeEvent*>(nodeEvent->origin);
322 if (!originNodeEvent) {
323 return ArkUI_PreDragStatus::ARKUI_PRE_DRAG_STATUS_UNKNOWN;
324 }
325 auto status = static_cast<ArkUI_PreDragStatus>(originNodeEvent->componentAsyncEvent.data[0].i32);
326 return status;
327 }
328
OH_ArkUI_DragEvent_DisableDefaultDropAnimation(ArkUI_DragEvent * event,bool disable)329 int32_t OH_ArkUI_DragEvent_DisableDefaultDropAnimation(ArkUI_DragEvent* event, bool disable)
330 {
331 if (!event) {
332 return ARKUI_ERROR_CODE_PARAM_INVALID;
333 }
334 auto* dragEvent = reinterpret_cast<ArkUIDragEvent*>(event);
335 dragEvent->useCustomDropAnimation = disable;
336 return ARKUI_ERROR_CODE_NO_ERROR;
337 }
338
OH_ArkUI_SetNodeDraggable(ArkUI_NodeHandle node,bool enabled)339 int32_t OH_ArkUI_SetNodeDraggable(ArkUI_NodeHandle node, bool enabled)
340 {
341 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
342 if (!impl || !node) {
343 return ARKUI_ERROR_CODE_PARAM_INVALID;
344 }
345 impl->getNodeModifiers()->getCommonModifier()->setDraggable(node->uiNodeHandle, enabled);
346 return ARKUI_ERROR_CODE_NO_ERROR;
347 }
348
OH_ArkUI_CreateDragPreviewOption(void)349 ArkUI_DragPreviewOption* OH_ArkUI_CreateDragPreviewOption(void)
350 {
351 auto* previewOptions = new ArkUIDragPreViewAndInteractionOptions();
352 return reinterpret_cast<ArkUI_DragPreviewOption*>(previewOptions);
353 }
354
OH_ArkUI_DragPreviewOption_Dispose(ArkUI_DragPreviewOption * option)355 void OH_ArkUI_DragPreviewOption_Dispose(ArkUI_DragPreviewOption* option)
356 {
357 delete reinterpret_cast<ArkUIDragPreViewAndInteractionOptions*>(option);
358 option = nullptr;
359 }
360
OH_ArkUI_DragPreviewOption_SetScaleMode(ArkUI_DragPreviewOption * option,ArkUI_DragPreviewScaleMode scaleMode)361 int32_t OH_ArkUI_DragPreviewOption_SetScaleMode(ArkUI_DragPreviewOption* option, ArkUI_DragPreviewScaleMode scaleMode)
362 {
363 if (!option) {
364 return ARKUI_ERROR_CODE_PARAM_INVALID;
365 }
366 auto* options = reinterpret_cast<ArkUIDragPreViewAndInteractionOptions*>(option);
367 if (scaleMode == ArkUI_DragPreviewScaleMode::ARKUI_DRAG_PREVIEW_SCALE_AUTO) {
368 options->isScaleEnabled = true;
369 options->isDefaultShadowEnabled = false;
370 options->isDefaultRadiusEnabled = false;
371 } else {
372 options->isScaleEnabled = false;
373 }
374 return ARKUI_ERROR_CODE_NO_ERROR;
375 }
376
OH_ArkUI_DragPreviewOption_SetDefaultShadowEnabled(ArkUI_DragPreviewOption * option,bool enabled)377 int32_t OH_ArkUI_DragPreviewOption_SetDefaultShadowEnabled(ArkUI_DragPreviewOption* option, bool enabled)
378 {
379 if (!option) {
380 return ARKUI_ERROR_CODE_PARAM_INVALID;
381 }
382 auto* options = reinterpret_cast<ArkUIDragPreViewAndInteractionOptions*>(option);
383 options->isDefaultShadowEnabled = enabled;
384 return ARKUI_ERROR_CODE_NO_ERROR;
385 }
386
OH_ArkUI_DragPreviewOption_SetDefaultRadiusEnabled(ArkUI_DragPreviewOption * option,bool enabled)387 int32_t OH_ArkUI_DragPreviewOption_SetDefaultRadiusEnabled(ArkUI_DragPreviewOption* option, bool enabled)
388 {
389 if (!option) {
390 return ARKUI_ERROR_CODE_PARAM_INVALID;
391 }
392 auto* options = reinterpret_cast<ArkUIDragPreViewAndInteractionOptions*>(option);
393 options->isDefaultRadiusEnabled = enabled;
394 return ARKUI_ERROR_CODE_NO_ERROR;
395 }
396
OH_ArkUI_DragPreviewOption_SetNumberBadgeEnabled(ArkUI_DragPreviewOption * option,bool enabled)397 int32_t OH_ArkUI_DragPreviewOption_SetNumberBadgeEnabled(ArkUI_DragPreviewOption* option, bool enabled)
398 {
399 if (!option) {
400 return ARKUI_ERROR_CODE_PARAM_INVALID;
401 }
402 auto* options = reinterpret_cast<ArkUIDragPreViewAndInteractionOptions*>(option);
403 options->isNumberBadgeEnabled = false;
404 options->isShowBadge = enabled;
405 return ARKUI_ERROR_CODE_NO_ERROR;
406 }
407
OH_ArkUI_DragPreviewOption_SetBadgeNumber(ArkUI_DragPreviewOption * option,uint32_t forcedNumber)408 int32_t OH_ArkUI_DragPreviewOption_SetBadgeNumber(ArkUI_DragPreviewOption* option, uint32_t forcedNumber)
409 {
410 if (!option) {
411 return ARKUI_ERROR_CODE_PARAM_INVALID;
412 }
413 auto* options = reinterpret_cast<ArkUIDragPreViewAndInteractionOptions*>(option);
414 options->isNumberBadgeEnabled = true;
415 options->badgeNumber = static_cast<ArkUI_Int32>(forcedNumber);
416 return ARKUI_ERROR_CODE_NO_ERROR;
417 }
418
OH_ArkUI_DragPreviewOption_SetDefaultAnimationBeforeLiftingEnabled(ArkUI_DragPreviewOption * option,bool enabled)419 int32_t OH_ArkUI_DragPreviewOption_SetDefaultAnimationBeforeLiftingEnabled(
420 ArkUI_DragPreviewOption* option, bool enabled)
421 {
422 if (!option) {
423 return ARKUI_ERROR_CODE_PARAM_INVALID;
424 }
425 auto* options = reinterpret_cast<ArkUIDragPreViewAndInteractionOptions*>(option);
426 options->defaultAnimationBeforeLifting = enabled;
427 return ARKUI_ERROR_CODE_NO_ERROR;
428 }
429
OH_ArkUI_SetNodeDragPreviewOption(ArkUI_NodeHandle node,ArkUI_DragPreviewOption * option)430 int32_t OH_ArkUI_SetNodeDragPreviewOption(ArkUI_NodeHandle node, ArkUI_DragPreviewOption* option)
431 {
432 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
433 if (!impl || !node) {
434 return ARKUI_ERROR_CODE_PARAM_INVALID;
435 }
436 auto* previewOption = reinterpret_cast<ArkUIDragPreViewAndInteractionOptions*>(option);
437 ArkUIDragPreViewOptions dragPreviewOptions;
438 ArkUI_Int32 modeArray[3] = { -1, -1, -1 };
439 ArkUI_Int32 modeSize = 0;
440
441 if (previewOption->isScaleEnabled) {
442 modeArray[modeSize] = 1; // 1: DragPreviewMode::AUTO
443 modeSize++;
444 } else {
445 modeArray[modeSize] = 2; // 2: DragPreviewMode::DISABLE_SCAL
446 modeSize++;
447 if (previewOption->isDefaultShadowEnabled) {
448 modeArray[modeSize] = 3; // 3: DragPreviewMode::ENABLE_DEFAULT_SHADOW
449 modeSize++;
450 }
451 if (previewOption->isDefaultRadiusEnabled) {
452 modeArray[modeSize] = 4; // 4: DragPreviewMode::ENABLE_DEFAULT_RADIUS
453 modeSize++;
454 }
455 }
456 dragPreviewOptions.isModeArray = true;
457 dragPreviewOptions.modeArray = modeArray;
458 dragPreviewOptions.modeArrayLength = modeSize;
459 dragPreviewOptions.isBadgeNumber = previewOption->isNumberBadgeEnabled;
460 dragPreviewOptions.badgeNumber = previewOption->badgeNumber;
461 dragPreviewOptions.isShowBadge = previewOption->isShowBadge;
462
463 ArkUIDragInteractionOptions dragInteractionOptions;
464 dragInteractionOptions.defaultAnimationBeforeLifting = previewOption->defaultAnimationBeforeLifting;
465 dragInteractionOptions.isMultiSelectionEnabled = previewOption->isMultiSelectionEnabled;
466
467 impl->getNodeModifiers()->getCommonModifier()->setDragPreviewOptions(
468 node->uiNodeHandle, dragPreviewOptions, dragInteractionOptions);
469
470 return ARKUI_ERROR_CODE_NO_ERROR;
471 }
472
OH_ArkUI_SetNodeDragPreview(ArkUI_NodeHandle node,OH_PixelmapNative * preview)473 int32_t OH_ArkUI_SetNodeDragPreview(ArkUI_NodeHandle node, OH_PixelmapNative* preview)
474 {
475 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
476 if (!impl || !node) {
477 return ARKUI_ERROR_CODE_PARAM_INVALID;
478 }
479 if (!preview) {
480 impl->getNodeModifiers()->getCommonModifier()->resetDragPreview(node->uiNodeHandle);
481 return ARKUI_ERROR_CODE_NO_ERROR;
482 }
483 auto previewPixelNative = reinterpret_cast<OH_PixelmapNativeHandle>(preview);
484 auto pixelMap = previewPixelNative->GetInnerPixelmap();
485 impl->getDragAdapterAPI()->setDragPreview(node->uiNodeHandle, &pixelMap);
486 return ARKUI_ERROR_CODE_NO_ERROR;
487 }
488
OH_ArkUI_SetNodeAllowedDropDataTypes(ArkUI_NodeHandle node,const char * typesArray[],int32_t count)489 int32_t OH_ArkUI_SetNodeAllowedDropDataTypes(ArkUI_NodeHandle node, const char* typesArray[], int32_t count)
490 {
491 auto* fullImpl = OHOS::Ace::NodeModel::GetFullImpl();
492 if (!fullImpl || !node || !typesArray) {
493 return ARKUI_ERROR_CODE_PARAM_INVALID;
494 }
495 fullImpl->getNodeModifiers()->getCommonModifier()->setAllowDrop(node->uiNodeHandle, typesArray, count);
496 return ARKUI_ERROR_CODE_NO_ERROR;
497 }
498
OH_ArkUI_SetDragEventStrictReportWithNode(ArkUI_NodeHandle node,bool enabled)499 int32_t OH_ArkUI_SetDragEventStrictReportWithNode(ArkUI_NodeHandle node, bool enabled)
500 {
501 auto* fullImpl = OHOS::Ace::NodeModel::GetFullImpl();
502 if (!fullImpl || !node) {
503 return ARKUI_ERROR_CODE_PARAM_INVALID;
504 }
505 fullImpl->getDragAdapterAPI()->setDragEventStrictReportingEnabledWithNode(enabled);
506 return ARKUI_ERROR_CODE_NO_ERROR;
507 }
508
OH_ArkUI_SetDragEventStrictReportWithContext(ArkUI_ContextHandle uiContext,bool enabled)509 int32_t OH_ArkUI_SetDragEventStrictReportWithContext(ArkUI_ContextHandle uiContext, bool enabled)
510 {
511 auto* fullImpl = OHOS::Ace::NodeModel::GetFullImpl();
512 if (!fullImpl || !uiContext) {
513 return ARKUI_ERROR_CODE_PARAM_INVALID;
514 }
515 auto* context = reinterpret_cast<ArkUI_Context*>(uiContext);
516 auto id = context->id;
517 fullImpl->getDragAdapterAPI()->setDragEventStrictReportingEnabledWithContext(id, enabled);
518 return ARKUI_ERROR_CODE_NO_ERROR;
519 }
520
OH_ArkUI_DisallowNodeAnyDropDataTypes(ArkUI_NodeHandle node)521 int32_t OH_ArkUI_DisallowNodeAnyDropDataTypes(ArkUI_NodeHandle node)
522 {
523 auto* fullImpl = OHOS::Ace::NodeModel::GetFullImpl();
524 if (!fullImpl || !node) {
525 return ARKUI_ERROR_CODE_PARAM_INVALID;
526 }
527 fullImpl->getNodeModifiers()->getCommonModifier()->setDisAllowDrop(node->uiNodeHandle);
528 return ARKUI_ERROR_CODE_NO_ERROR;
529 }
530
OH_ArkUI_AllowNodeAllDropDataTypes(ArkUI_NodeHandle node)531 int32_t OH_ArkUI_AllowNodeAllDropDataTypes(ArkUI_NodeHandle node)
532 {
533 auto* fullImpl = OHOS::Ace::NodeModel::GetFullImpl();
534 if (!fullImpl || !node) {
535 return ARKUI_ERROR_CODE_PARAM_INVALID;
536 }
537 fullImpl->getNodeModifiers()->getCommonModifier()->resetAllowDrop(node->uiNodeHandle);
538 return ARKUI_ERROR_CODE_NO_ERROR;
539 }
540
OH_ArkUI_DragEvent_GetDragResult(ArkUI_DragEvent * event,ArkUI_DragResult * result)541 int32_t OH_ArkUI_DragEvent_GetDragResult(ArkUI_DragEvent* event, ArkUI_DragResult* result)
542 {
543 if (!event || !result) {
544 return ARKUI_ERROR_CODE_PARAM_INVALID;
545 }
546 auto* dragEvent = reinterpret_cast<ArkUIDragEvent*>(event);
547 *result = static_cast<ArkUI_DragResult>(dragEvent->dragResult);
548 return ARKUI_ERROR_CODE_NO_ERROR;
549 }
550
OH_ArkUI_DragEvent_SetDragResult(ArkUI_DragEvent * event,ArkUI_DragResult result)551 int32_t OH_ArkUI_DragEvent_SetDragResult(ArkUI_DragEvent* event, ArkUI_DragResult result)
552 {
553 if (!event) {
554 return ARKUI_ERROR_CODE_PARAM_INVALID;
555 }
556 auto* dragEvent = reinterpret_cast<ArkUIDragEvent*>(event);
557 dragEvent->dragResult = static_cast<ArkUI_Int32>(result);
558 return ARKUI_ERROR_CODE_NO_ERROR;
559 }
560
OH_ArkUI_DragEvent_SetSuggestedDropOperation(ArkUI_DragEvent * event,ArkUI_DropOperation proposal)561 int32_t OH_ArkUI_DragEvent_SetSuggestedDropOperation(ArkUI_DragEvent* event, ArkUI_DropOperation proposal)
562 {
563 if (!event) {
564 return ARKUI_ERROR_CODE_PARAM_INVALID;
565 }
566 auto* dragEvent = reinterpret_cast<ArkUIDragEvent*>(event);
567 dragEvent->dragBehavior = static_cast<ArkUI_Int32>(proposal);
568 return ARKUI_ERROR_CODE_NO_ERROR;
569 }
570
OH_ArkUI_DragEvent_GetDropOperation(ArkUI_DragEvent * event,ArkUI_DropOperation * operation)571 int32_t OH_ArkUI_DragEvent_GetDropOperation(ArkUI_DragEvent* event, ArkUI_DropOperation* operation)
572 {
573 if (!event || !operation) {
574 return ARKUI_ERROR_CODE_PARAM_INVALID;
575 }
576 auto* dragEvent = reinterpret_cast<ArkUIDragEvent*>(event);
577 if (dragEvent->dragBehavior >= static_cast<int32_t>(ArkUI_DropOperation::ARKUI_DROP_OPERATION_COPY) &&
578 dragEvent->dragBehavior <= static_cast<int32_t>(ArkUI_DropOperation::ARKUI_DROP_OPERATION_MOVE)) {
579 *operation = static_cast<ArkUI_DropOperation>(dragEvent->dragBehavior);
580 } else {
581 *operation = ARKUI_DROP_OPERATION_COPY;
582 }
583 return ARKUI_ERROR_CODE_NO_ERROR;
584 }
585
OH_ArkUI_DragEvent_GetPreviewTouchPointX(ArkUI_DragEvent * event)586 float OH_ArkUI_DragEvent_GetPreviewTouchPointX(ArkUI_DragEvent* event)
587 {
588 if (!event) {
589 return 0.0f;
590 }
591 auto* dragEvent = reinterpret_cast<ArkUIDragEvent*>(event);
592 auto result = static_cast<float>(dragEvent->touchPointX);
593 return result;
594 }
595
OH_ArkUI_DragEvent_GetPreviewTouchPointY(ArkUI_DragEvent * event)596 float OH_ArkUI_DragEvent_GetPreviewTouchPointY(ArkUI_DragEvent* event)
597 {
598 if (!event) {
599 return 0.0f;
600 }
601 auto* dragEvent = reinterpret_cast<ArkUIDragEvent*>(event);
602 auto result = static_cast<float>(dragEvent->touchPointY);
603 return result;
604 }
605
OH_ArkUI_DragEvent_GetPreviewRectWidth(ArkUI_DragEvent * event)606 float OH_ArkUI_DragEvent_GetPreviewRectWidth(ArkUI_DragEvent* event)
607 {
608 if (!event) {
609 return 0.0f;
610 }
611 auto* dragEvent = reinterpret_cast<ArkUIDragEvent*>(event);
612 auto result = static_cast<float>(dragEvent->previewRectWidth);
613 return result;
614 }
615
OH_ArkUI_DragEvent_GetPreviewRectHeight(ArkUI_DragEvent * event)616 float OH_ArkUI_DragEvent_GetPreviewRectHeight(ArkUI_DragEvent* event)
617 {
618 if (!event) {
619 return 0.0f;
620 }
621 auto* dragEvent = reinterpret_cast<ArkUIDragEvent*>(event);
622 auto result = static_cast<float>(dragEvent->previewRectHeight);
623 return result;
624 }
625
OH_ArkUI_DragEvent_GetTouchPointXToWindow(ArkUI_DragEvent * event)626 float OH_ArkUI_DragEvent_GetTouchPointXToWindow(ArkUI_DragEvent* event)
627 {
628 if (!event) {
629 return 0.0f;
630 }
631 auto* dragEvent = reinterpret_cast<ArkUIDragEvent*>(event);
632 auto result = static_cast<float>(dragEvent->windowX);
633 return result;
634 }
635
OH_ArkUI_DragEvent_GetTouchPointYToWindow(ArkUI_DragEvent * event)636 float OH_ArkUI_DragEvent_GetTouchPointYToWindow(ArkUI_DragEvent* event)
637 {
638 if (!event) {
639 return 0.0f;
640 }
641 auto* dragEvent = reinterpret_cast<ArkUIDragEvent*>(event);
642 auto result = static_cast<float>(dragEvent->windowY);
643 return result;
644 }
645
OH_ArkUI_DragEvent_GetTouchPointXToDisplay(ArkUI_DragEvent * event)646 float OH_ArkUI_DragEvent_GetTouchPointXToDisplay(ArkUI_DragEvent* event)
647 {
648 if (!event) {
649 return 0.0f;
650 }
651 auto* dragEvent = reinterpret_cast<ArkUIDragEvent*>(event);
652 auto result = static_cast<float>(dragEvent->displayX);
653 return result;
654 }
655
OH_ArkUI_DragEvent_GetTouchPointYToDisplay(ArkUI_DragEvent * event)656 float OH_ArkUI_DragEvent_GetTouchPointYToDisplay(ArkUI_DragEvent* event)
657 {
658 if (!event) {
659 return 0.0f;
660 }
661 auto* dragEvent = reinterpret_cast<ArkUIDragEvent*>(event);
662 auto result = static_cast<float>(dragEvent->displayY);
663 return result;
664 }
665
OH_ArkUI_DragEvent_GetVelocityX(ArkUI_DragEvent * event)666 float OH_ArkUI_DragEvent_GetVelocityX(ArkUI_DragEvent* event)
667 {
668 if (!event) {
669 return 0.0f;
670 }
671 auto* dragEvent = reinterpret_cast<ArkUIDragEvent*>(event);
672 auto result = static_cast<float>(dragEvent->velocityX);
673 return result;
674 }
675
OH_ArkUI_DragEvent_GetVelocityY(ArkUI_DragEvent * event)676 float OH_ArkUI_DragEvent_GetVelocityY(ArkUI_DragEvent* event)
677 {
678 if (!event) {
679 return 0.0f;
680 }
681 auto* dragEvent = reinterpret_cast<ArkUIDragEvent*>(event);
682 auto result = static_cast<float>(dragEvent->velocityY);
683 return result;
684 }
685
OH_ArkUI_DragEvent_GetVelocity(ArkUI_DragEvent * event)686 float OH_ArkUI_DragEvent_GetVelocity(ArkUI_DragEvent* event)
687 {
688 if (!event) {
689 return 0.0f;
690 }
691 auto* dragEvent = reinterpret_cast<ArkUIDragEvent*>(event);
692 auto result = static_cast<float>(dragEvent->velocity);
693 return result;
694 }
695
OH_ArkUI_DragEvent_StartDataLoading(ArkUI_DragEvent * event,OH_UdmfGetDataParams * options,char * key,unsigned int keyLen)696 int32_t OH_ArkUI_DragEvent_StartDataLoading(
697 ArkUI_DragEvent* event, OH_UdmfGetDataParams *options, char* key, unsigned int keyLen)
698 {
699 if (!event || !options || !key || !keyLen || keyLen < UDMF_KEY_BUFFER_LEN) {
700 return ARKUI_ERROR_CODE_PARAM_INVALID;
701 }
702 auto* dragEvent = reinterpret_cast<ArkUIDragEvent*>(event);
703 if (!(dragEvent->isSuitGetData)) {
704 return ARKUI_ERROR_CODE_PARAM_INVALID;
705 }
706 int32_t length = strlen(dragEvent->key);
707 for (int32_t i = 0; i < length; i++) {
708 key[i] = dragEvent->key[i];
709 }
710 OHOS::UDMF::QueryOption query;
711 query.key = key;
712 query.intention = OHOS::UDMF::Intention::UD_INTENTION_DRAG;
713 OHOS::UDMF::GetDataParams getDataParams;
714 OH_UdmfGetDataParams &optionsRef = *options;
715 auto status = static_cast<int32_t>(
716 OHOS::UDMF::DataParamsConversion::GetInnerDataParams(optionsRef, query, getDataParams));
717 if (status != 0) {
718 return ARKUI_ERROR_CODE_PARAM_INVALID;
719 }
720 status = static_cast<int32_t>(
721 OHOS::UDMF::UdmfAsyncClient::GetInstance().StartAsyncDataRetrieval(getDataParams));
722 if (status != 0) {
723 return ARKUI_ERROR_CODE_PARAM_INVALID;
724 }
725 return ARKUI_ERROR_CODE_NO_ERROR;
726 }
727
OH_ArkUI_CancelDataLoading(ArkUI_ContextHandle uiContent,const char * key)728 int32_t OH_ArkUI_CancelDataLoading(ArkUI_ContextHandle uiContent, const char* key)
729 {
730 if (!uiContent || !key) {
731 return ARKUI_ERROR_CODE_PARAM_INVALID;
732 }
733 auto status = static_cast<int32_t>(OHOS::UDMF::UdmfAsyncClient::GetInstance().Cancel(key));
734 if (status != 0) {
735 return ARKUI_ERROR_CODE_PARAM_INVALID;
736 }
737 return ARKUI_ERROR_CODE_NO_ERROR;
738 }
739
OH_ArkUI_DisableDropDataPrefetchOnNode(ArkUI_NodeHandle node,bool disable)740 int32_t OH_ArkUI_DisableDropDataPrefetchOnNode(ArkUI_NodeHandle node, bool disable)
741 {
742 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
743 if (!impl || !node) {
744 return ARKUI_ERROR_CODE_PARAM_INVALID;
745 }
746 impl->getNodeModifiers()->getCommonModifier()->setDisableDataPrefetch(node->uiNodeHandle, disable);
747 return ARKUI_ERROR_CODE_NO_ERROR;
748 }
749 #ifdef __cplusplus
750 };
751 #endif