diff --git a/.gitee/CODEOWNERS b/.gitee/CODEOWNERS index 6099a845961..5df12826a0f 100644 --- a/.gitee/CODEOWNERS +++ b/.gitee/CODEOWNERS @@ -2639,6 +2639,8 @@ frameworks/core/interfaces/native/node/data_panel_modifier.cpp @arkui_image frameworks/core/interfaces/native/node/data_panel_modifier.h @arkui_image frameworks/core/interfaces/native/node/divider_modifier.cpp @arkuilayout frameworks/core/interfaces/native/node/divider_modifier.h @arkuilayout +frameworks/core/interfaces/native/node/drag_adapter_impl.cpp @arkuievent +frameworks/core/interfaces/native/node/drag_adapter_impl.h @arkuievent frameworks/core/interfaces/native/node/extension_companion_node.cpp @arkuiframework frameworks/core/interfaces/native/node/extension_companion_node.h @arkuiframework frameworks/core/interfaces/native/node/extension_custom_node.cpp @arkuiframework diff --git a/frameworks/core/components_ng/base/view_abstract.cpp b/frameworks/core/components_ng/base/view_abstract.cpp index e3395aa8fb2..5e93b04bf9b 100755 --- a/frameworks/core/components_ng/base/view_abstract.cpp +++ b/frameworks/core/components_ng/base/view_abstract.cpp @@ -4632,6 +4632,15 @@ void ViewAbstract::SetDragEventStrictReportingEnabled(bool dragEventStrictReport dragDropManager->SetEventStrictReportingEnabled(dragEventStrictReportingEnabled); } +void ViewAbstract::SetDragEventStrictReportingEnabled(int32_t instanceId, bool dragEventStrictReportingEnabled) +{ + auto pipeline = PipelineContext::GetContextByContainerId(instanceId); + CHECK_NULL_VOID(pipeline); + auto dragDropManager = pipeline->GetDragDropManager(); + CHECK_NULL_VOID(dragDropManager); + dragDropManager->SetEventStrictReportingEnabled(dragEventStrictReportingEnabled); +} + void ViewAbstract::SetDisallowDropForcedly(bool isDisallowDropForcedly) { auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); diff --git a/frameworks/core/components_ng/base/view_abstract.h b/frameworks/core/components_ng/base/view_abstract.h index 13cc5cebc41..041960b0614 100644 --- a/frameworks/core/components_ng/base/view_abstract.h +++ b/frameworks/core/components_ng/base/view_abstract.h @@ -656,6 +656,7 @@ public: static TextDirection GetDirection(FrameNode* frameNode); static std::map GetAlignRules(FrameNode* frameNode); static FlexAlign GetAlignSelf(FrameNode* frameNode); + static void SetDragEventStrictReportingEnabled(int32_t instanceId, bool dragEventStrictReportingEnabled); // used in JS FrameNode static void SetJSFrameNodeOnClick(FrameNode* frameNode, GestureEventFunc&& clickEventFunc); static void SetJSFrameNodeOnTouch(FrameNode* frameNode, TouchEventFunc&& touchEventFunc); diff --git a/frameworks/core/interfaces/arkoala/arkoala_api.h b/frameworks/core/interfaces/arkoala/arkoala_api.h index 1ad6419724a..e56cb7bf02b 100644 --- a/frameworks/core/interfaces/arkoala/arkoala_api.h +++ b/frameworks/core/interfaces/arkoala/arkoala_api.h @@ -1326,6 +1326,17 @@ struct ArkUIDragInteractionOptions { ArkUI_Bool defaultAnimationBeforeLifting; }; +struct ArkUIDragPreViewAndInteractionOptions { + bool isScaleEnabled = false; + bool defaultAnimationBeforeLifting = false; + bool isMultiSelectionEnabled = false; + bool isNumberBadgeEnabled = false; + bool isDefaultShadowEnabled = false; + bool isDefaultRadiusEnabled = false; + ArkUI_Int32 badgeNumber = 0; + bool isShowBadge = true; +}; + struct ArkUI_DialogDismissEvent; typedef ArkUI_DialogDismissEvent* ArkUIDialogDismissEvent; @@ -1768,6 +1779,7 @@ struct ArkUICommonModifier { void (*setFocusBoxStyle)(ArkUINodeHandle node, ArkUI_Float32 valueMargin, ArkUI_Int32 marginUnit, ArkUI_Float32 valueStrokeWidth, ArkUI_Int32 widthUnit, ArkUI_Uint32 valueColor, ArkUI_Uint32 hasValue); void (*resetFocusBoxStyle)(ArkUINodeHandle node); + void (*setDisAllowDrop)(ArkUINodeHandle node); }; struct ArkUICommonShapeModifier { @@ -4832,6 +4844,12 @@ typedef struct { ArkUINodeAdapterHandle (*getNodeAdapter)(ArkUINodeHandle host); } ArkUINodeAdapterAPI; +typedef struct { + void (*setDragPreview)(ArkUINodeHandle node, void* dragPreview); + void (*setDragEventStrictReportingEnabledWithNode)(bool enabled); + void (*setDragEventStrictReportingEnabledWithContext)(ArkUI_Int32 instanceId, bool enabled); +} ArkUIDragAdapterAPI; + /** * An API to control an implementation. When making changes modifying binary * layout, i.e. adding new events - increase ARKUI_NODE_API_VERSION above for binary @@ -4848,6 +4866,7 @@ struct ArkUIFullNodeAPI { const ArkUIDialogAPI* (*getDialogAPI)(); const ArkUIExtendedNodeAPI* (*getExtendedAPI)(); const ArkUINodeAdapterAPI* (*getNodeAdapterAPI)(); + const ArkUIDragAdapterAPI* (*getDragAdapterAPI)(); }; struct ArkUIAnyAPI { diff --git a/frameworks/core/interfaces/native/BUILD.gn b/frameworks/core/interfaces/native/BUILD.gn index b9aeec8a4de..47fed65bd32 100644 --- a/frameworks/core/interfaces/native/BUILD.gn +++ b/frameworks/core/interfaces/native/BUILD.gn @@ -43,6 +43,7 @@ template("ace_core_interfaces_native_node") { "node/custom_dialog_model.cpp", "node/data_panel_modifier.cpp", "node/divider_modifier.cpp", + "node/drag_adapter_impl.cpp", "node/extension_companion_node.cpp", "node/extension_custom_node.cpp", "node/flex_modifier.cpp", diff --git a/frameworks/core/interfaces/native/node/drag_adapter_impl.cpp b/frameworks/core/interfaces/native/node/drag_adapter_impl.cpp new file mode 100644 index 00000000000..a796dc2d0f1 --- /dev/null +++ b/frameworks/core/interfaces/native/node/drag_adapter_impl.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "core/interfaces/native/node/drag_adapter_impl.h" + +#include "core/components_ng/base/frame_node.h" +#include "core/components_ng/base/view_abstract.h" +#include "core/components_ng/event/gesture_event_hub.h" +#include "core/interfaces/arkoala/arkoala_api.h" + +namespace OHOS::Ace::DragAdapter { +namespace { + +void SetDragPreview(ArkUINodeHandle node, void* dragPreview) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + NG::DragDropInfo dragPreviewInfo; + dragPreviewInfo.pixelMap = PixelMap::CreatePixelMap(dragPreview); + NG::ViewAbstract::SetDragPreview(frameNode, dragPreviewInfo); +} + +void SetDragEventStrictReportingEnabledWithNode(bool enabled) +{ + NG::ViewAbstract::SetDragEventStrictReportingEnabled(enabled); +} + +void SetDragEventStrictReportingEnabledWithContext(ArkUI_Int32 instanceId, bool enabled) +{ + NG::ViewAbstract::SetDragEventStrictReportingEnabled(instanceId, enabled); +} + +} // namespace +const ArkUIDragAdapterAPI* GetDragAdapterAPI() +{ + static const ArkUIDragAdapterAPI impl { + SetDragPreview, + SetDragEventStrictReportingEnabledWithNode, + SetDragEventStrictReportingEnabledWithContext + }; + return &impl; +} +} // namespace OHOS::Ace::DragAdapter \ No newline at end of file diff --git a/frameworks/core/interfaces/native/node/drag_adapter_impl.h b/frameworks/core/interfaces/native/node/drag_adapter_impl.h new file mode 100644 index 00000000000..53e1d0512fb --- /dev/null +++ b/frameworks/core/interfaces/native/node/drag_adapter_impl.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_INTERFACE_INNER_API_NATIVE_NODED_DRAG_ADAPTER_IMPL_H +#define FRAMEWORKS_INTERFACE_INNER_API_NATIVE_NODED_DRAG_ADAPTER_IMPL_H + +#include +#include +#include +#include + +#include "base/error/error_code.h" +#include "base/memory/ace_type.h" +#include "base/memory/referenced.h" +#include "core/components_ng/base/ui_node.h" +#include "core/interfaces/arkoala/arkoala_api.h" + + +namespace OHOS::Ace::DragAdapter { +const ArkUIDragAdapterAPI* GetDragAdapterAPI(); +} // namespace OHOS::Ace::DragAdapter +#endif // FRAMEWORKS_INTERFACE_INNER_API_NATIVE_NODED_DRAG_ADAPTER_IMPL_H \ No newline at end of file diff --git a/frameworks/core/interfaces/native/node/node_api.cpp b/frameworks/core/interfaces/native/node/node_api.cpp index d97e2db9495..b4e12954c8e 100644 --- a/frameworks/core/interfaces/native/node/node_api.cpp +++ b/frameworks/core/interfaces/native/node/node_api.cpp @@ -34,7 +34,9 @@ #include "core/interfaces/native/node/calendar_picker_modifier.h" #include "core/interfaces/native/node/canvas_rendering_context_2d_modifier.h" #include "core/interfaces/native/node/custom_dialog_model.h" +#include "core/interfaces/native/node/drag_adapter_impl.h" #include "core/interfaces/native/node/grid_modifier.h" +#include "core/interfaces/native/node/image_animator_modifier.h" #include "core/interfaces/native/node/node_adapter_impl.h" #include "core/interfaces/native/node/node_animate.h" #include "core/interfaces/native/node/node_canvas_modifier.h" @@ -43,6 +45,7 @@ #include "core/interfaces/native/node/node_drag_modifier.h" #include "core/interfaces/native/node/node_date_picker_modifier.h" #include "core/interfaces/native/node/node_image_modifier.h" +#include "core/interfaces/native/node/node_list_item_modifier.h" #include "core/interfaces/native/node/node_list_modifier.h" #include "core/interfaces/native/node/node_refresh_modifier.h" #include "core/interfaces/native/node/node_scroll_modifier.h" @@ -54,18 +57,12 @@ #include "core/interfaces/native/node/node_textpicker_modifier.h" #include "core/interfaces/native/node/node_timepicker_modifier.h" #include "core/interfaces/native/node/node_toggle_modifier.h" -#include "core/interfaces/native/node/image_animator_modifier.h" -#include "core/interfaces/native/node/util_modifier.h" -#include "core/interfaces/native/node/grid_modifier.h" -#include "core/interfaces/native/node/alphabet_indexer_modifier.h" -#include "core/interfaces/native/node/search_modifier.h" #include "core/interfaces/native/node/radio_modifier.h" #include "core/interfaces/native/node/search_modifier.h" #include "core/interfaces/native/node/select_modifier.h" #include "core/interfaces/native/node/util_modifier.h" #include "core/interfaces/native/node/view_model.h" #include "core/interfaces/native/node/water_flow_modifier.h" -#include "core/interfaces/native/node/node_list_item_modifier.h" #include "core/pipeline_ng/pipeline_context.h" namespace OHOS::Ace::NG { @@ -2018,6 +2015,7 @@ ArkUIFullNodeAPI impl_full = { GetDialogAPI, GetExtendedAPI, // Extended NodeAdapter::GetNodeAdapterAPI, // adapter. + DragAdapter::GetDragAdapterAPI, // drag adapter. }; /* clang-format on */ } // namespace diff --git a/frameworks/core/interfaces/native/node/node_common_modifier.cpp b/frameworks/core/interfaces/native/node/node_common_modifier.cpp index bcc1cdee9ea..71db01fdbc8 100644 --- a/frameworks/core/interfaces/native/node/node_common_modifier.cpp +++ b/frameworks/core/interfaces/native/node/node_common_modifier.cpp @@ -2825,6 +2825,13 @@ void ResetAllowDrop(ArkUINodeHandle node) ViewAbstract::SetAllowDrop(frameNode, allowDrop); } +void SetDisAllowDrop(ArkUINodeHandle node) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + frameNode->SetDisallowDropForcedly(true); +} + void SetAccessibilityLevel(ArkUINodeHandle node, ArkUI_CharPtr value) { auto* frameNode = reinterpret_cast(node); @@ -6178,7 +6185,7 @@ const ArkUICommonModifier* GetCommonModifier() ResetAccessibilityActions, GetAccessibilityActions, SetAccessibilityRole, ResetAccessibilityRole, GetAccessibilityRole, SetFocusScopeId, ResetFocusScopeId, SetFocusScopePriority, ResetFocusScopePriority, SetPixelRound, ResetPixelRound, SetBorderDashParams, GetExpandSafeArea, SetTransition, SetDragPreview, - ResetDragPreview, GetNodeUniqueId, SetFocusBoxStyle, ResetFocusBoxStyle }; + ResetDragPreview, GetNodeUniqueId, SetFocusBoxStyle, ResetFocusBoxStyle, SetDisAllowDrop }; return &modifier; } diff --git a/frameworks/core/interfaces/native/node/node_drag_modifier.cpp b/frameworks/core/interfaces/native/node/node_drag_modifier.cpp index 72e65d0b01a..d9794495de9 100644 --- a/frameworks/core/interfaces/native/node/node_drag_modifier.cpp +++ b/frameworks/core/interfaces/native/node/node_drag_modifier.cpp @@ -116,7 +116,7 @@ void SetDragEventProperty(const RefPtr& info, ArkUINodeEve ++index; } event.dragEvent.dataTypes = strList.data(); - event.dragEvent.dataTypesMaxStrLength = maxLength; + event.dragEvent.dataTypesMaxStrLength = maxLength + 1; } void SetOnDragDrop(ArkUINodeHandle node, void* extraParam) @@ -272,7 +272,7 @@ void SetOnDragEnd(ArkUINodeHandle node, void* extraParam) ++index; } event.dragEvent.dataTypes = strList.data(); - event.dragEvent.dataTypesMaxStrLength = maxLength; + event.dragEvent.dataTypesMaxStrLength = maxLength + 1; auto unifiedData = UdmfClient::GetInstance()->TransformUnifiedDataPtr(info->GetData()); diff --git a/interfaces/native/drag_and_drop.h b/interfaces/native/drag_and_drop.h index 0785733f900..6329091e085 100644 --- a/interfaces/native/drag_and_drop.h +++ b/interfaces/native/drag_and_drop.h @@ -52,7 +52,7 @@ extern "C" { */ typedef enum { /** The drag and drop operation succeeded. */ - ARKUI_DRAG_RESULT_SUCCESSFUL, + ARKUI_DRAG_RESULT_SUCCESSFUL = 0, /** The drag and drop operation failed. */ ARKUI_DRAG_RESULT_FAILED, /** The drag and drop operation was canceled. */ @@ -66,7 +66,7 @@ typedef enum { */ typedef enum { /** Copy. */ - ARKUI_DROP_OPERATION_COPY, + ARKUI_DROP_OPERATION_COPY = 0, /** Cut. */ ARKUI_DROP_OPERATION_MOVE, } ArkUI_DropOperation; @@ -105,7 +105,7 @@ typedef enum { * The system automatically changes the position of the dragged point based on the scenario and * scales the drag preview based on set rules. */ - ARKUI_DRAG_PREVIEW_SCALE_AUTO, + ARKUI_DRAG_PREVIEW_SCALE_AUTO = 0, /** The system does not scale the drag preview. */ ARKUI_DRAG_PREVIEW_SCALE_DISABLED, } ArkUI_DragPreviewScaleMode; @@ -117,7 +117,7 @@ typedef enum { */ typedef enum { /** Unknown. */ - ARKUI_DRAG_STATUS_UNKNOWN = 0, + ARKUI_DRAG_STATUS_UNKNOWN = -1, /** Started. */ ARKUI_DRAG_STATUS_STARTED, /** Ended. */ diff --git a/interfaces/native/event/drag_and_drop_impl.cpp b/interfaces/native/event/drag_and_drop_impl.cpp index 544c351d929..a7184eb0346 100644 --- a/interfaces/native/event/drag_and_drop_impl.cpp +++ b/interfaces/native/event/drag_and_drop_impl.cpp @@ -35,7 +35,7 @@ extern "C" { int32_t OH_ArkUI_DragEvent_GetModifierKeyStates(ArkUI_DragEvent* event, int64_t* keys) { - if (event == NULL || keys == NULL) { + if (!event || !keys) { return ARKUI_ERROR_CODE_PARAM_INVALID; } auto dragEvent = reinterpret_cast(event); @@ -96,11 +96,12 @@ int32_t OH_ArkUI_DragEvent_GetDataTypes( } for (int32_t i = 0; i < length; i++) { if (dragEvent->dataTypes[i]) { - auto ret = strncpy_s(eventTypeArray[i], maxStrLen, dragEvent->dataTypes[i], maxStrLen); + auto strLeng = strlen(dragEvent->dataTypes[i]) + 1; + auto ret = strncpy_s(eventTypeArray[i], strLeng, dragEvent->dataTypes[i], strLeng - 1); if (ret != 0) { return ARKUI_ERROR_CODE_PARAM_INVALID; } - eventTypeArray[i][maxStrLen] = '\0'; + eventTypeArray[i][strLeng] = '\0'; } else { eventTypeArray[i][0] = '\0'; } @@ -108,6 +109,364 @@ int32_t OH_ArkUI_DragEvent_GetDataTypes( return ARKUI_ERROR_CODE_NO_ERROR; } +ArkUI_PreviewDragStatus OH_ArkUI_NodeEvent_GetPreviewDragStatus(ArkUI_NodeEvent* nodeEvent) +{ + if (!nodeEvent || nodeEvent->category != static_cast(NODE_EVENT_CATEGORY_COMPONENT_EVENT)) { + return ArkUI_PreviewDragStatus::ARKUI_PREVIEW_DRAG_STATUS_UNKNOWN; + } + const auto* originNodeEvent = reinterpret_cast(nodeEvent->origin); + if (!originNodeEvent) { + return ArkUI_PreviewDragStatus::ARKUI_PREVIEW_DRAG_STATUS_UNKNOWN; + } + auto status = static_cast(originNodeEvent->componentAsyncEvent.data[0].i32); + return status; +} + +int32_t OH_ArkUI_DragEvent_DisableDefaultDropAnimation(ArkUI_DragEvent* event, bool disable) +{ + if (!event) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + auto* dragEvent = reinterpret_cast(event); + dragEvent->useCustomDropAnimation = disable; + return ARKUI_ERROR_CODE_NO_ERROR; +} + +int32_t OH_ArkUI_SetNodeDraggable(ArkUI_NodeHandle node, bool enabled) +{ + auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); + if (!impl || !node) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + impl->getNodeModifiers()->getCommonModifier()->setDraggable(node->uiNodeHandle, enabled); + return ARKUI_ERROR_CODE_NO_ERROR; +} + +ArkUI_DragPreviewOption* OH_ArkUI_CreateDragPreviewOption(void) +{ + auto* previewOptions = new ArkUIDragPreViewAndInteractionOptions(); + return reinterpret_cast(previewOptions); +} + +void OH_ArkUI_DragPreviewOption_Dispose(ArkUI_DragPreviewOption* option) +{ + delete reinterpret_cast(option); + option = nullptr; +} + +int32_t OH_ArkUI_DragPreviewOption_SetScaleMode(ArkUI_DragPreviewOption* option, ArkUI_DragPreviewScaleMode scaleMode) +{ + if (!option) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + auto* options = reinterpret_cast(option); + if (scaleMode == ArkUI_DragPreviewScaleMode::ARKUI_DRAG_PREVIEW_SCALE_AUTO) { + options->isScaleEnabled = true; + options->isDefaultShadowEnabled = false; + options->isDefaultRadiusEnabled = false; + } else { + options->isScaleEnabled = false; + } + return ARKUI_ERROR_CODE_NO_ERROR; +} + +int32_t OH_ArkUI_DragPreviewOption_SetDefaultShadowEnabled(ArkUI_DragPreviewOption* option, bool enabled) +{ + if (!option) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + auto* options = reinterpret_cast(option); + options->isDefaultShadowEnabled = enabled; + return ARKUI_ERROR_CODE_NO_ERROR; +} + +int32_t OH_ArkUI_DragPreviewOption_SetDefaultRadiusEnabled(ArkUI_DragPreviewOption* option, bool enabled) +{ + if (!option) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + auto* options = reinterpret_cast(option); + options->isDefaultRadiusEnabled = enabled; + return ARKUI_ERROR_CODE_NO_ERROR; +} + +int32_t OH_ArkUI_DragPreviewOption_SetNumberBadgeEnabled(ArkUI_DragPreviewOption* option, bool enabled) +{ + if (!option) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + auto* options = reinterpret_cast(option); + options->isNumberBadgeEnabled = enabled; + options->badgeNumber = static_cast(enabled); + return ARKUI_ERROR_CODE_NO_ERROR; +} + +int32_t OH_ArkUI_DragPreviewOption_SetBadgeNumber(ArkUI_DragPreviewOption* option, uint32_t forcedNumber) +{ + if (!option) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + auto* options = reinterpret_cast(option); + options->badgeNumber = static_cast(forcedNumber); + return ARKUI_ERROR_CODE_NO_ERROR; +} + +int32_t OH_ArkUI_DragPreviewOption_SetDefaultAnimationBeforeLiftingEnabled( + ArkUI_DragPreviewOption* option, bool enabled) +{ + if (!option) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + auto* options = reinterpret_cast(option); + options->defaultAnimationBeforeLifting = enabled; + return ARKUI_ERROR_CODE_NO_ERROR; +} + +int32_t OH_ArkUI_SetNodeDragPreviewOption(ArkUI_NodeHandle node, ArkUI_DragPreviewOption* option) +{ + auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); + if (!impl || !node) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + auto* previewOption = reinterpret_cast(option); + ArkUIDragPreViewOptions dragPreviewOptions; + ArkUI_Int32 modeArray[3] = { -1, -1, -1 }; + ArkUI_Int32 modeSize = 0; + + if (previewOption->isScaleEnabled) { + modeArray[modeSize] = 1; // 1: DragPreviewMode::AUTO + modeSize++; + } else { + modeArray[modeSize] = 2; // 2: DragPreviewMode::DISABLE_SCAL + modeSize++; + if (previewOption->isDefaultShadowEnabled) { + modeArray[modeSize] = 3; // 3: DragPreviewMode::ENABLE_DEFAULT_SHADOW + modeSize++; + } + if (previewOption->isDefaultRadiusEnabled) { + modeArray[modeSize] = 4; // 4: DragPreviewMode::ENABLE_DEFAULT_RADIUS + modeSize++; + } + } + dragPreviewOptions.isModeArray = true; + dragPreviewOptions.modeArray = modeArray; + dragPreviewOptions.modeArrayLength = modeSize; + dragPreviewOptions.isBadgeNumber = previewOption->isNumberBadgeEnabled; + dragPreviewOptions.badgeNumber = previewOption->badgeNumber; + dragPreviewOptions.isShowBadge = previewOption->isShowBadge; + + ArkUIDragInteractionOptions dragInteractionOptions; + dragInteractionOptions.defaultAnimationBeforeLifting = previewOption->defaultAnimationBeforeLifting; + dragInteractionOptions.isMultiSelectionEnabled = previewOption->isMultiSelectionEnabled; + + impl->getNodeModifiers()->getCommonModifier()->setDragPreviewOptions( + node->uiNodeHandle, dragPreviewOptions, dragInteractionOptions); + + return ARKUI_ERROR_CODE_NO_ERROR; +} + +int32_t OH_ArkUI_SetNodeDragPreview(ArkUI_NodeHandle node, OH_PixelmapNative* preview) +{ + auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); + if (!impl || !node || !preview) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + auto previewPixelNative = reinterpret_cast(preview); + auto pixelMap = previewPixelNative->GetInnerPixelmap(); + impl->getDragAdapterAPI()->setDragPreview(node->uiNodeHandle, &pixelMap); + return ARKUI_ERROR_CODE_NO_ERROR; +} +int32_t OH_ArkUI_SetNodeAllowedDropDataTypes(ArkUI_NodeHandle node, const char* typesArray[], int32_t count) +{ + auto* fullImpl = OHOS::Ace::NodeModel::GetFullImpl(); + if (!fullImpl || !node || !typesArray) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + fullImpl->getNodeModifiers()->getCommonModifier()->setAllowDrop(node->uiNodeHandle, typesArray, count); + return ARKUI_ERROR_CODE_NO_ERROR; +} + +int32_t OH_ArkUI_SetDragEventStrictReportWithNode(ArkUI_NodeHandle node, bool enabled) +{ + auto* fullImpl = OHOS::Ace::NodeModel::GetFullImpl(); + if (!fullImpl || !node) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + fullImpl->getDragAdapterAPI()->setDragEventStrictReportingEnabledWithNode(enabled); + return ARKUI_ERROR_CODE_NO_ERROR; +} + +int32_t OH_ArkUI_SetDragEventStrictReportWithContext(ArkUI_ContextHandle uiContext, bool enabled) +{ + auto* fullImpl = OHOS::Ace::NodeModel::GetFullImpl(); + if (!fullImpl || !uiContext) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + auto* context = reinterpret_cast(uiContext); + auto id = context->id; + fullImpl->getDragAdapterAPI()->setDragEventStrictReportingEnabledWithContext(id, enabled); + return ARKUI_ERROR_CODE_NO_ERROR; +} + +int32_t OH_ArkUI_DisallowNodeAnyDropDataTypes(ArkUI_NodeHandle node) +{ + auto* fullImpl = OHOS::Ace::NodeModel::GetFullImpl(); + if (!fullImpl || !node) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + fullImpl->getNodeModifiers()->getCommonModifier()->setDisAllowDrop(node->uiNodeHandle); + return ARKUI_ERROR_CODE_NO_ERROR; +} + +int32_t OH_ArkUI_AllowNodeAllDropDataTypes(ArkUI_NodeHandle node) +{ + auto* fullImpl = OHOS::Ace::NodeModel::GetFullImpl(); + if (!fullImpl || !node) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + fullImpl->getNodeModifiers()->getCommonModifier()->resetAllowDrop(node->uiNodeHandle); + return ARKUI_ERROR_CODE_NO_ERROR; +} + +int32_t OH_ArkUI_DragEvent_GetDragResult(ArkUI_DragEvent* event, ArkUI_DragResult* result) +{ + if (!event || !result) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + auto* dragEvent = reinterpret_cast(event); + *result = static_cast(dragEvent->dragResult); + return ARKUI_ERROR_CODE_NO_ERROR; +} + +int32_t OH_ArkUI_DragEvent_SetDragResult(ArkUI_DragEvent* event, ArkUI_DragResult result) +{ + if (!event) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + auto* dragEvent = reinterpret_cast(event); + dragEvent->dragResult = static_cast(result); + return ARKUI_ERROR_CODE_NO_ERROR; +} + +int32_t OH_ArkUI_DragEvent_SetSuggestedDropOperation(ArkUI_DragEvent* event, ArkUI_DropOperation proposal) +{ + if (!event) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + auto* dragEvent = reinterpret_cast(event); + dragEvent->dragBehavior = static_cast(proposal); + return ARKUI_ERROR_CODE_NO_ERROR; +} + +float OH_ArkUI_DragEvent_GetPreviewTouchPointX(ArkUI_DragEvent* event) +{ + if (!event) { + return 0.0f; + } + auto* dragEvent = reinterpret_cast(event); + auto result = static_cast(dragEvent->touchPointX); + return result; +} + +float OH_ArkUI_DragEvent_GetPreviewTouchPointY(ArkUI_DragEvent* event) +{ + if (!event) { + return 0.0f; + } + auto* dragEvent = reinterpret_cast(event); + auto result = static_cast(dragEvent->touchPointY); + return result; +} + +float OH_ArkUI_DragEvent_GetPreviewRectWidth(ArkUI_DragEvent* event) +{ + if (!event) { + return 0.0f; + } + auto* dragEvent = reinterpret_cast(event); + auto result = static_cast(dragEvent->previewRectWidth); + return result; +} + +float OH_ArkUI_DragEvent_GetPreviewRectHeight(ArkUI_DragEvent* event) +{ + if (!event) { + return 0.0f; + } + auto* dragEvent = reinterpret_cast(event); + auto result = static_cast(dragEvent->previewRectHeight); + return result; +} + +float OH_ArkUI_DragEvent_GetTouchPointXToWindow(ArkUI_DragEvent* event) +{ + if (!event) { + return 0.0f; + } + auto* dragEvent = reinterpret_cast(event); + auto result = static_cast(dragEvent->windowX); + return result; +} + +float OH_ArkUI_DragEvent_GetTouchPointYToWindow(ArkUI_DragEvent* event) +{ + if (!event) { + return 0.0f; + } + auto* dragEvent = reinterpret_cast(event); + auto result = static_cast(dragEvent->windowY); + return result; +} + +float OH_ArkUI_DragEvent_GetTouchPointXToDisplay(ArkUI_DragEvent* event) +{ + if (!event) { + return 0.0f; + } + auto* dragEvent = reinterpret_cast(event); + auto result = static_cast(dragEvent->displayX); + return result; +} + +float OH_ArkUI_DragEvent_GetTouchPointYToDisplay(ArkUI_DragEvent* event) +{ + if (!event) { + return 0.0f; + } + auto* dragEvent = reinterpret_cast(event); + auto result = static_cast(dragEvent->displayY); + return result; +} + +float OH_ArkUI_DragEvent_GetVelocityX(ArkUI_DragEvent* event) +{ + if (!event) { + return 0.0f; + } + auto* dragEvent = reinterpret_cast(event); + auto result = static_cast(dragEvent->velocityX); + return result; +} + +float OH_ArkUI_DragEvent_GetVelocityY(ArkUI_DragEvent* event) +{ + if (!event) { + return 0.0f; + } + auto* dragEvent = reinterpret_cast(event); + auto result = static_cast(dragEvent->velocityY); + return result; +} + +float OH_ArkUI_DragEvent_GetVelocity(ArkUI_DragEvent* event) +{ + if (!event) { + return 0.0f; + } + auto* dragEvent = reinterpret_cast(event); + auto result = static_cast(dragEvent->velocity); + return result; +} #ifdef __cplusplus }; #endif \ No newline at end of file