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