Solved

Can't get a drop target to accept drag-and-drop from Opera browser

Posted on 2006-07-09
13
297 Views
Last Modified: 2013-11-20
Opera supports drag-and-drop of URLs from the address bar to the desktop. I have not been able to build an app that works as a drop target for drag-and-drop from Opera. Code that works for IE and Firefox doesn't work for Opera.

Among other things, I have tried using the open source utility ClipSpy (http://www.codeproject.com/clipboard/clipspy.asp) which does work as a drop target for IE and Firefox, but shows a "disallowed" cursor (barred circle) when you try to drop a URL from Opera on its target panel.

At minimum, I need an explanation of why I'm seeing this behavior. Ideally, I would like code that works with Opera, perhaps by modifying ClipSpy so that it accepts (and displays) a URL dropped on it from Opera.

Thanks,

--Steve
0
Comment
Question by:sklein
  • 5
  • 4
  • 4
13 Comments
 
LVL 5

Expert Comment

by:bastibartel
Comment Utility
Hi there,

hyperlinks do not work with std. droptargets as files do.
Try this though

You need an object derived from COleDropTarget  as member of your dialog class. This COleDropTarget
will accept hyperlinks as drops, if a couple of member functions are defined.

//###################
// In your Dlg class you add a variable:
CMyOleDropTarget m_DropTarget;

// In OnInitDialog of your Dlg class you add
m_DropTarget.Register( this );


//##############################
//## Class Definition of my CMyOleDropTarget
//##############################
#include <afxole.h> // if I remember correctly

class CMyOleDropTarget : public COleDropTarget
{
public:
      CMyOleDropTarget() {;}

      BOOL            OnDrop(CWnd* pWnd, COleDataObject* pDataObject, DROPEFFECT dropEffect, CPoint point );
      DROPEFFECT      OnDragEnter(CWnd* pWnd, COleDataObject* pDataObject, DWORD dwKeyState, CPoint point );
      DROPEFFECT      OnDragOver(CWnd* pWnd, COleDataObject* pDataObject, DWORD dwKeyState, CPoint point );
};

//##############################
//## Implementation of my CMyOleDropTarget
//##############################

BOOL CMyOleDropTarget::OnDrop(CWnd* pWnd, COleDataObject* pDataObject, DROPEFFECT dropEffect, CPoint point )
{
      STGMEDIUM r;
      BOOL fRet= pDataObject->GetData(CF_TEXT, &r );
      HGLOBAL hGlob= pDataObject->GetGlobalData( CF_TEXT );
      LPCSTR lpsz= (LPCSTR)GlobalLock( hGlob );
      GlobalUnlock( hGlob );
      
      AfxMessageBox( lpsz ); // debugging
      return( TRUE );
}

DROPEFFECT CMyOleDropTarget::OnDragEnter(CWnd* pWnd, COleDataObject* pDataObject, DWORD dwKeyState, CPoint point )
{
      STGMEDIUM r;
      BOOL fRet= pDataObject->IsDataAvailable(CF_TEXT );
      return( DROPEFFECT_COPY);
}

DROPEFFECT CMyOleDropTarget::OnDragOver(CWnd* pWnd, COleDataObject* pDataObject, DWORD dwKeyState, CPoint point )
{
      return( DROPEFFECT_COPY);
}


Cheers
Sebastian
0
 
LVL 5

Expert Comment

by:bastibartel
Comment Utility
Hi  sklein,

Have you found my code to be useful to you or do you have additional questions ?

Cheers,
Sebastian
0
 
LVL 5

Expert Comment

by:bastibartel
Comment Utility
Hi sklein,
 :-(
0
 

Author Comment

by:sklein
Comment Utility
Sebastian--

Your example code appears to be equivalent to the implementation in ClipSpy. Here are the relevant bits extracted from LeftView.cpp:

class CLeftView : public CListView
{
...
// Implementation
...
protected:
    COleDropTarget m_drop;              // makes the list a drop target
...
}

void CLeftView::OnInitialUpdate()
{
    ...
    // Register the list control as a drop target.
    m_drop.Register ( this );
    ...
}

DROPEFFECT CLeftView::OnDragEnter(COleDataObject* pDataObject, DWORD dwKeyState, CPoint point)
{
    ...
    return DROPEFFECT_COPY;
}

The ClipSpy project works great for dragging and dropping URLs from IE and Firefox, but not for Opera.

I put a breakpoint in CLeftView::OnDragEnter(). I get the break when dragging from Explorer, IE, or Firefox, but not for Opera. I can drag from the Opera address bar to the desktop. Thoughts?

--Steve
0
 
LVL 5

Expert Comment

by:bastibartel
Comment Utility
Hi sklein,

This was a solution from a previous EE question.
I don't have Opera myself and never tested it - sry, I couldn't help you.

Cheers,
Sebastian
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
You will need to know exactly what format is being used by Opera.  I don't have that browser, so I can't test it, but it should be easy for you to do.  In your OnDragEnter handler, make a call to EnumClipboardFormats to learn exactly what Operas has put in there.

    EnumClipboardFormats Function
    http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/dataexchange/clipboard/clipboardreference/clipboardfunctions/enumclipboardformats.asp

You should find one of these:
   Clipboard Formats
   http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/dataexchange/clipboard/clipboardformats.asp

It could be a CF_HDROP or something else (maybe a "rivate" format -- who knows with non-microsoft software? :-)  But once you know what it uses, change the code above in the places where it looks for CF_TEXT to look for that format.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:sklein
Comment Utility
Sebastian--

Thanks for giving it a go.

--Steve
0
 

Author Comment

by:sklein
Comment Utility
Dan--

An interesting suggestion,except that the OnDragEnter event handler is not being called at all if the drag source is Opera (but it is for IE, Firefox, Explorer). Yet clearly Opera is initiating a drag, since the cursor changes and I can drop from Opera to the desktop. When I try to drag over my app (or ClipSpy) I get the barred circle. So somehow the target is rejecting the dragover. Is there somewhere other than OnDragEnter or OnDragOver that can reject the drag target "accept"???

--Steve
0
 
LVL 5

Expert Comment

by:bastibartel
Comment Utility
Hi sklein,

BTW, the code you have quoted is not at all the same as the one I posted.

In your example you are using CView::OnDragEnter
My code uses COleDropTarget::OnDragEnter.

Have you tried the COleDropTarget subclassing appraoch ?

Cheers,
Sebastian
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
Are you 100% certain that OnDragEnter is not being called (or are you relying on the cursor appearance?)  Place a breakpoint or a MessageBox there to be certain.

I've been searching the Web and it does appear that Opera's handling of Drag and Drop is rather unusual -- the fact the ClipSpy does not handle it is an important clue in that regard.  I'll keep looking to see if I can find anything more specific.  It may be a security issue... there are several known exploits related to dragging and perhaps the authors of Opera have avoided those by some unusual methods.
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 500 total points
Comment Utility
This discussion indicates the unusual handling:  You can drag to the desktop only (or within Opera) but Operat itself is rejecting drops on anything else.

    http://my.opera.com/community/forums/topic.dml?id=138677

These guys suggest dropping it on the dektop then dragging it again to the desired target.  I doubt if they'd even consider that if there were a more natural way.

Improvement in Operar Drag-and=drop are high on the "wish list" and the current limits are discussed here:
     http://my.opera.com/community/forums/topic.dml?id=135056

So.. the answer is:  "It can't be done by Opera."  

There is some chance that it is possible to an Opera Plugin to help make it happen, but that is outside of the realm of this question.
0
 

Author Comment

by:sklein
Comment Utility
Sorry for the delay. I'm 100% positive that OnDragEnter is not being called.

The really interesting thing is that if Opera is using DoDragDrop(), the IDropSource interface doesn't appear to allow you to "decline" a drop target. Perhaps the answer is that they don't use DoDragDrop() and "rolled their own".
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
That appears to the the valid assessment.  The Opera forums were filled with chatter about how the code needed to remain platform-neutral.  Presumably the Windows mechanism of querying each potential drop target is not standard on other platforms, or if it is, then it is done in a substantially different way and the programmers did not want bifurcate the codebase so they used a simpler "mouse-capture-until-over-a-recognized-target" technique.

Thanks for the points and the grade :-)

-- Dan
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 47
configuration management 2 99
Get filename and folder into excel 7 67
wordmultiple challenge 12 89
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now