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