Skip to main content
Inspiring
January 13, 2012
Answered

Drop an URL on a InDesign document from a Flex panel

  • January 13, 2012
  • 1 reply
  • 3150 views

Hi Everyone,

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 IDragDropTarget* 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

This topic has been closed for replies.
Correct answer perigee_rde

My use of GetDragItem is only in experimental code of a development plugin and I did not verify that for your case.

I have a production plugin though that accepts browser drag&drop of links. My approach was to substitute the links during Internalize with some download to be placed by the standard file dropping place helper, thus I did not use GetDragItem at all. Internalize already receives the IPMDataObject ...

Browsers deliver many flavors at the same time, different even by the kind of object the link is bound to. In that plugin I had to do severe shuffling (ReorderFlavors during multiple helpers) to get the whole thing to work - I think kSysFileDataExchHandlerNetscapeHelperBoss was stealing away anythink resembling a link at highest priority.

The original debug session was 5 years ago with InDesign 2 so I don't remember the nifty details, and just pray that nothing breaks when I have to do another port or support another browser. From that experience I remember the whole InDesign D&D mechanism is an overcomplicated mess of too many phases, but still insufficiently factored in the later phases.

Dirk


I finally found a "solution". This one is dirty, but I could not find any other clean solution, so I use it.

The solution is the following one : In the couldAcceptTypes method, I get the first object of the DataObjectIterator, and store the itemID I retrieve from the object contained within. I store it with a dirty memcpy (No other solution, the method is declared as const).

Then, in the ProcessDragCommand, I retrieve the itemID, and then call GetDragItem with this itemID. There I finally get the item.

Why should I do such a solution ? Because the itemID on PC is alsways 1. But on Mac, the one I retrieved was something like 719531, or whatever. I don't know why.

If this solution can help someone, this will be good. If someone find a clean solution, I would appreciate to know it.

@Dirk : I tried your solution, but could not manage it to make it work. I may have done something wrongly, I don't know...

1 reply

Inspiring
January 13, 2012

Hi,

if CanDo returns kFalse for the flavor kURLDExternalFlavor then retry it with kURLExternalFlavor.

Markus

Inspiring
January 13, 2012

Hi,

I tried, but unsuccessful... Is there anything platfom-dependent in the flavors causing such a desagrement ? Or is the problem somewhere else ?

Rémi

Inspiring
January 19, 2012

Hi,

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 IDragDropTarget* 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