InDesign SDK:从 Flex 面板拖放

发布于 2024-12-27 00:55:03 字数 2408 浏览 5 评论 0原文

我在 InDesign 中有一个 Flex 面板,我可以从中拖动一个 URL。如果我将此 URL 放到文本编辑器或 Web 浏览器上,它就会起作用。但当我尝试将其放到 InDesign 文档中时,就有点困难了。

我已经实现了 CDragDropTargetFlavorHelper 的子类。 Drop在Windows上完美运行。但在 mac 上,我在 CouldAcceptTypes 方法中遇到问题:

DragDrop::TargetResponse AutocatDNDCustomFlavorHelper::CouldAcceptTypes(const  DragDropTarget* target, DataObjectIterator* dataIter, const IDragDropSource* fromSource,  const IDragDropController* controller) const
{
    if (0 != dataIter && 0 != target)
    {

        DataExchangeResponse response = dataIter->FlavorExistsWithPriorityInAllObjects(kURLDExternalFlavor);
        if (response.CanDo())
        {
            ...
        }
    }
}

问题是,response.canDo() 在 Windows 上回答 kTrue,但在 Mac 上回答 kFalse。我尝试探索 dataIter 的内容,但对 dataIter->First() 的调用返回 nil。我尝试了控制器->GetItemCount(),它返回 1。但是如果我尝试控制器->GetDragItem(1),我会得到一个 nil 指针。我的印象是没有任何物品。不过,正如我所说,该拖放可以在 InDesign 以外的其他应用程序上运行。

是内化的问题吗?还是别的什么?它让我干燥。

提前致谢

-------------------------- 编辑 -------------------- ---------------- 我解决了这个问题,但又发现了另一个问题。 Flex 面板发送的风格已更改,因此它是文本风格而不是 URL 风格。我的方法 canAcceptType 现在可以工作:

DragDrop::TargetResponse AutocatDNDCustomFlavorHelper::CouldAcceptTypes(const DragDropTarget* target, DataObjectIterator* dataIter, const IDragDropSource* fromSource, const IDragDropController* controller) const
{
    if (0 != dataIter && 0 != target)
    {
        // Check for URL Flavor in the drag
        DataExchangeResponse response = dataIter->FlavorExistsWithPriorityInAllObjects(kTEXTExternalFlavor);
        if (response.CanDo())
            {
                return DragDrop::TargetResponse(response, DragDrop::kDropWillCopy);
            }
    }
    return DragDrop::kWontAcceptTargetResponse;
}

问题现在出在 ProcessDragDropCommand 方法中。这是代码:

ErrorCode AutocatDNDCustomFlavorHelper::ProcessDragDropCommand(IDragDropTarget* target, IDragDropController* controller, DragDrop::eCommandType action)
{
    // retrieve drop data
    IPMDataObject* dragDataObject = controller->GetDragItem(1);
    uint32 dataSize = dragDataObject->GetSizeOfFlavorData(kTEXTExternalFlavor) ;
    ...
}

问题是我得到的 IMPDataObject 为零。控制器中没有项目。但是,DataObjectIterator 中的 CouldAcceptTypes 方法中有一些项。那么,我的物品在哪里?

我尝试使用自定义 CDataExchangeHandlerFor,但无法真正理解它的用途。无论如何它都不起作用。

有人有想法吗?

问候, 雷米

I have a Flex panel, in InDesign, from which I drag an URL. If I drop this URL on a text editor or a web browser, it works. But when I try to drop it on my InDesign document, it's a little bit harder.

I have implemented a subclass of CDragDropTargetFlavorHelper. The drop works perfectly on Windows. But on mac, I have problems in the method CouldAcceptTypes :

DragDrop::TargetResponse AutocatDNDCustomFlavorHelper::CouldAcceptTypes(const  DragDropTarget* target, DataObjectIterator* dataIter, const IDragDropSource* fromSource,  const IDragDropController* controller) const
{
    if (0 != dataIter && 0 != target)
    {

        DataExchangeResponse response = dataIter->FlavorExistsWithPriorityInAllObjects(kURLDExternalFlavor);
        if (response.CanDo())
        {
            ...
        }
    }
}

The problem is that response.canDo() answers kTrue on Windows, but kFalse on Mac. I tried to explore the content of dataIter, but a call on dataIter->First() returns nil. I tried a controller->GetItemCount(), which returns 1. But if I try a controller->GetDragItem(1), I get a nil pointer. I have the impress there is no item. Though, the drop works on another app than InDesign, as I said.

Is it a problem of internalization ? Or something else ? It let me dry.

Thanks in advance

-------------------------- EDIT -----------------------------------
I solved this problem, but discovered another one. The flavor sent by the flex panel has been changed, so that it's a text flavor instead of an URL flavor. My method couldAcceptType works now :

DragDrop::TargetResponse AutocatDNDCustomFlavorHelper::CouldAcceptTypes(const DragDropTarget* target, DataObjectIterator* dataIter, const IDragDropSource* fromSource, const IDragDropController* controller) const
{
    if (0 != dataIter && 0 != target)
    {
        // Check for URL Flavor in the drag
        DataExchangeResponse response = dataIter->FlavorExistsWithPriorityInAllObjects(kTEXTExternalFlavor);
        if (response.CanDo())
            {
                return DragDrop::TargetResponse(response, DragDrop::kDropWillCopy);
            }
    }
    return DragDrop::kWontAcceptTargetResponse;
}

The problem is now in the ProcessDragDropCommand method. Here is the code :

ErrorCode AutocatDNDCustomFlavorHelper::ProcessDragDropCommand(IDragDropTarget* target, IDragDropController* controller, DragDrop::eCommandType action)
{
    // retrieve drop data
    IPMDataObject* dragDataObject = controller->GetDragItem(1);
    uint32 dataSize = dragDataObject->GetSizeOfFlavorData(kTEXTExternalFlavor) ;
    ...
}

The problem is the IMPDataObject I get is nil. There is no item in the controller. However, there were items in the CouldAcceptTypes method, in the DataObjectIterator. So, where are my items ?

I tried using a custom CDataExchangeHandlerFor, but could not really understand what its usage was for. It didn't work anyway.

Has anyone an idea ?

Regards,
Rémi

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风吹过旳痕迹 2025-01-03 00:55:03

问题在于 GetDragItem 的参数。 PC 上为 1。在 Mac 上这是一个奇怪的值(类似于 719853)。我发现的唯一肮脏的解决方案是从 CouldAcceptTypes 方法中从 dataIter 检索的对象中执行 memcpy,并在 ProcessDragDropCommand 方法中使用它。

The problem is the argument of the GetDragItem. It is 1 on PC. It is a strange value on Mac (something like 719853). The only dirty solution I found is doing a memcpy from the object retrieved drom the dataIter in the CouldAcceptTypes method, and use it in the ProcessDragDropCommand method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文