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