Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-07-09
13
Medium Priority
?
328 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 4
13 Comments
 
LVL 5

Expert Comment

by:bastibartel
ID: 17069558
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
ID: 17079716
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
ID: 17079869
Hi sklein,
 :-(
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

Author Comment

by:sklein
ID: 17085707
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
ID: 17085936
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
ID: 17086246
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
 

Author Comment

by:sklein
ID: 17086691
Sebastian--

Thanks for giving it a go.

--Steve
0
 

Author Comment

by:sklein
ID: 17086764
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
ID: 17088178
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
ID: 17093880
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 2000 total points
ID: 17094222
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
ID: 17119781
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
ID: 17124739
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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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 brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

670 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