Commit 23b6ca2f authored by Cyril Deguet's avatar Cyril Deguet

* drag&drop works ! (at least with mozilla)

parent 5ee03109
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* gtk2_dragdrop.cpp: GTK2 implementation of the drag & drop * gtk2_dragdrop.cpp: GTK2 implementation of the drag & drop
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * Copyright (C) 2003 VideoLAN
* $Id: gtk2_dragdrop.cpp,v 1.3 2003/04/16 21:40:07 ipkiss Exp $ * $Id: gtk2_dragdrop.cpp,v 1.4 2003/04/19 11:16:17 asmax Exp $
* *
* Authors: Cyril Deguet <asmax@videolan.org> * Authors: Cyril Deguet <asmax@videolan.org>
* *
...@@ -25,27 +25,69 @@ ...@@ -25,27 +25,69 @@
#if !defined WIN32 #if !defined WIN32
//--- GTK2 ----------------------------------------------------------------- //--- GTK2 -----------------------------------------------------------------
//#include <windows.h> #include <gdk/gdk.h>
//--- VLC -------------------------------------------------------------------
#include <vlc/intf.h>
//--- SKIN ------------------------------------------------------------------ //--- SKIN ------------------------------------------------------------------
#include "../src/event.h" #include "../src/event.h"
#include "../os_api.h"
#include "gtk2_dragdrop.h" #include "gtk2_dragdrop.h"
/*
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
GTK2DropObject::GTK2DropObject() : IDropTarget() GTK2DropObject::GTK2DropObject( intf_thread_t *_p_intf )
{ {
References = 1; p_intf = _p_intf;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
GTK2DropObject::~GTK2DropObject() GTK2DropObject::~GTK2DropObject()
{ {
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void GTK2DropObject::HandleDrop( HDROP HDrop ) void GTK2DropObject::HandleDropStart( GdkDragContext *context )
{ {
// Get number of files that are dropped into vlc GdkAtom atom = gdk_drag_get_selection( context );
guchar *buffer;
GdkAtom prop_type;
gint prop_format;
// Get the owner of the selection
GdkWindow *owner = gdk_selection_owner_get( atom );
// Find the possible targets for the selection
string target = "";
gdk_selection_convert( owner, atom, gdk_atom_intern("TARGETS", FALSE),
OSAPI_GetTime() );
int len = gdk_selection_property_get( owner, &buffer, &prop_type,
&prop_format );
for( int i = 0; i < len / sizeof(GdkAtom); i++ )
{
GdkAtom atom = ( (GdkAtom*)buffer )[i];
string name = gdk_atom_name( atom );
if( name == "text/plain" || name == "STRING" )
{
target = name;
break;
}
}
if( target == "" )
{
msg_Warn( p_intf, "Drag&Drop: target not found\n" );
}
else
{
gdk_selection_convert( owner, atom, gdk_atom_intern(target.c_str(),
FALSE), OSAPI_GetTime() );
len = gdk_selection_property_get( owner, &buffer, &prop_type,
&prop_format);
OSAPI_PostMessage( NULL, VLC_DROP, (unsigned int)buffer, 0 );
}
/* // Get number of files that are dropped into vlc
int NbFiles = DragQueryFile( (HDROP)HDrop, 0xFFFFFFFF, NULL, 0 ); int NbFiles = DragQueryFile( (HDROP)HDrop, 0xFFFFFFFF, NULL, 0 );
// For each dropped files // For each dropped files
...@@ -62,107 +104,9 @@ void GTK2DropObject::HandleDrop( HDROP HDrop ) ...@@ -62,107 +104,9 @@ void GTK2DropObject::HandleDrop( HDROP HDrop )
} }
DragFinish( (HDROP)HDrop ); DragFinish( (HDROP)HDrop );
}
//---------------------------------------------------------------------------
STDMETHODIMP GTK2DropObject::QueryInterface( REFIID iid, void FAR* FAR* ppv )
{
// Tell other objects about our capabilities
if( iid == IID_IUnknown || iid == IID_IDropTarget )
{
*ppv = this;
AddRef();
return S_OK;
}
*ppv = NULL;
return ResultFromScode( E_NOINTERFACE );
}
//---------------------------------------------------------------------------
STDMETHODIMP_(ULONG) GTK2DropObject::AddRef()
{
return ++References;
}
//---------------------------------------------------------------------------
STDMETHODIMP_(ULONG) GTK2DropObject::Release()
{
if( --References == 0 )
{
delete this;
return 0;
}
return References;
}
//---------------------------------------------------------------------------
STDMETHODIMP GTK2DropObject::DragEnter( LPDATAOBJECT pDataObj,
DWORD grfKeyState, POINTL pt, DWORD *pdwEffect )
{
FORMATETC fmtetc;
fmtetc.cfFormat = CF_HDROP;
fmtetc.ptd = NULL;
fmtetc.dwAspect = DVASPECT_CONTENT;
fmtetc.lindex = -1;
fmtetc.tymed = TYMED_HGLOBAL;
// Check that the drag source provides CF_HDROP,
// which is the only format we accept
if( pDataObj->QueryGetData( &fmtetc ) == S_OK )
*pdwEffect = DROPEFFECT_COPY;
else
*pdwEffect = DROPEFFECT_NONE;
return S_OK;
}
//---------------------------------------------------------------------------
STDMETHODIMP GTK2DropObject::DragOver( DWORD grfKeyState, POINTL pt,
DWORD *pdwEffect )
{
// For visual feedback
// TODO
return S_OK;
}
//---------------------------------------------------------------------------
STDMETHODIMP GTK2DropObject::DragLeave()
{
// Remove visual feedback
// TODO
return S_OK;
}
//---------------------------------------------------------------------------
STDMETHODIMP GTK2DropObject::Drop( LPDATAOBJECT pDataObj, DWORD grfKeyState,
POINTL pt, DWORD *pdwEffect )
{
// User has dropped on us -- get the CF_HDROP data from drag source
FORMATETC fmtetc;
fmtetc.cfFormat = CF_HDROP;
fmtetc.ptd = NULL;
fmtetc.dwAspect = DVASPECT_CONTENT;
fmtetc.lindex = -1;
fmtetc.tymed = TYMED_HGLOBAL;
STGMEDIUM medium;
HRESULT hr = pDataObj->GetData( &fmtetc, &medium );
if( !FAILED(hr) )
{
// Grab a pointer to the data
HGLOBAL HFiles = medium.hGlobal;
HDROP HDrop = (HDROP)GlobalLock( HFiles );
// Notify the Form of the drop
HandleDrop( HDrop );
// Release the pointer to the memory
GlobalUnlock( HFiles );
// ReleaseStgMedium( &medium );
}
else
{
*pdwEffect = DROPEFFECT_NONE;
return hr;
}
return S_OK;
}
*/ */
gdk_drop_finish( context, TRUE,OSAPI_GetTime() );
}
#endif #endif
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* gtk2_dragdrop.h: GTK2 implementation of the drag & drop * gtk2_dragdrop.h: GTK2 implementation of the drag & drop
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * Copyright (C) 2003 VideoLAN
* $Id: gtk2_dragdrop.h,v 1.1 2003/04/12 21:43:27 asmax Exp $ * $Id: gtk2_dragdrop.h,v 1.2 2003/04/19 11:16:17 asmax Exp $
* *
* Authors: Cyril Deguet <asmax@videolan.org> * Authors: Cyril Deguet <asmax@videolan.org>
* *
...@@ -27,36 +27,21 @@ ...@@ -27,36 +27,21 @@
#define VLC_SKIN_GTK2_DRAGDROP #define VLC_SKIN_GTK2_DRAGDROP
//--- GTK2 ----------------------------------------------------------------- //--- GTK2 -----------------------------------------------------------------
//#include <shellapi.h> #include <gdk/gdk.h>
//#include <ole2.h>
#include <stdio.h>
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
/* class GTK2DropObject
class GTK2DropObject : public IDropTarget
{ {
intf_thread_t *p_intf;
public: public:
GTK2DropObject(); GTK2DropObject( intf_thread_t *_p_intf );
virtual ~GTK2DropObject(); virtual ~GTK2DropObject();
protected: void HandleDropStart( GdkDragContext *context );
// IUnknown methods };
STDMETHOD(QueryInterface)( REFIID riid, void FAR* FAR* ppvObj );
STDMETHOD_(ULONG, AddRef)();
STDMETHOD_(ULONG, Release)();
// IDropTarget methods
STDMETHOD(DragEnter)( LPDATAOBJECT pDataObj, DWORD grfKeyState,
POINTL pt, DWORD *pdwEffect );
STDMETHOD(DragOver)( DWORD grfKeyState, POINTL pt, DWORD *pdwEffect );
STDMETHOD(DragLeave)();
STDMETHOD(Drop)( LPDATAOBJECT pDataObj, DWORD grfKeyState,
POINTL pt, DWORD *pdwEffect );
private:
unsigned long References;
// Helper function
void HandleDrop( HDROP HDrop );
};*/
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#endif #endif
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* gtk2_theme.cpp: GTK2 implementation of the Theme class * gtk2_theme.cpp: GTK2 implementation of the Theme class
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * Copyright (C) 2003 VideoLAN
* $Id: gtk2_theme.cpp,v 1.17 2003/04/18 16:04:17 asmax Exp $ * $Id: gtk2_theme.cpp,v 1.18 2003/04/19 11:16:17 asmax Exp $
* *
* Authors: Cyril Deguet <asmax@videolan.org> * Authors: Cyril Deguet <asmax@videolan.org>
* *
...@@ -260,8 +260,6 @@ void GTK2Theme::AddWindow( string name, int x, int y, bool visible, ...@@ -260,8 +260,6 @@ void GTK2Theme::AddWindow( string name, int x, int y, bool visible,
return; return;
} }
gdk_window_register_dnd( gwnd );
gdk_window_show( gwnd ); gdk_window_show( gwnd );
WindowList.push_back( (Window *)new OSWindow( p_intf, gwnd, x, y, visible, WindowList.push_back( (Window *)new OSWindow( p_intf, gwnd, x, y, visible,
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* gtk2_window.cpp: GTK2 implementation of the Window class * gtk2_window.cpp: GTK2 implementation of the Window class
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * Copyright (C) 2003 VideoLAN
* $Id: gtk2_window.cpp,v 1.20 2003/04/18 16:04:17 asmax Exp $ * $Id: gtk2_window.cpp,v 1.21 2003/04/19 11:16:17 asmax Exp $
* *
* Authors: Cyril Deguet <asmax@videolan.org> * Authors: Cyril Deguet <asmax@videolan.org>
* *
...@@ -102,17 +102,14 @@ GTK2Window::GTK2Window( intf_thread_t *p_intf, GdkWindow *gwnd, int x, int y, ...@@ -102,17 +102,14 @@ GTK2Window::GTK2Window( intf_thread_t *p_intf, GdkWindow *gwnd, int x, int y,
SendMessage( ToolTipWindow, TTM_ADDTOOL, 0, SendMessage( ToolTipWindow, TTM_ADDTOOL, 0,
(LPARAM)(LPTOOLINFO) &ToolTipInfo ); (LPARAM)(LPTOOLINFO) &ToolTipInfo );
*/
// Drag & drop
if( DragDrop ) if( DragDrop )
{ {
// Initialize the OLE library
OleInitialize( NULL );
DropTarget = (LPDROPTARGET) new GTK2DropObject();
// register the listview as a drop target // register the listview as a drop target
RegisterDragDrop( hWnd, DropTarget ); GTK2DropObject *DropDrop = new GTK2DropObject( p_intf );
gdk_window_register_dnd( gwnd );
} }
*/
// Create Tool Tip window // Create Tool Tip window
/* GdkWindowAttr attr; /* GdkWindowAttr attr;
attr.event_mask = GDK_ALL_EVENTS_MASK; attr.event_mask = GDK_ALL_EVENTS_MASK;
...@@ -240,6 +237,10 @@ bool GTK2Window::ProcessOSEvent( Event *evt ) ...@@ -240,6 +237,10 @@ bool GTK2Window::ProcessOSEvent( Event *evt )
(int)( (GdkEventButton *)p2 )->y, 1 ); (int)( (GdkEventButton *)p2 )->y, 1 );
return true; return true;
case GDK_DROP_START:
DropObject->HandleDropStart( ( (GdkEventDND *)p2 )->context );
return true;
default: default:
return false; return false;
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* gtk2_window.h: GTK2 implementation of the Window class * gtk2_window.h: GTK2 implementation of the Window class
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * Copyright (C) 2003 VideoLAN
* $Id: gtk2_window.h,v 1.5 2003/04/15 20:33:58 karibu Exp $ * $Id: gtk2_window.h,v 1.6 2003/04/19 11:16:17 asmax Exp $
* *
* Authors: Cyril Deguet <asmax@videolan.org> * Authors: Cyril Deguet <asmax@videolan.org>
* *
...@@ -46,13 +46,13 @@ class GTK2Window : public Window ...@@ -46,13 +46,13 @@ class GTK2Window : public Window
int WindowY; int WindowY;
string Name; string Name;
// Drag&Drop
GTK2DropObject *DropObject;
// Tooltip texts // Tooltip texts
GdkWindow *ToolTipWindow; GdkWindow *ToolTipWindow;
// TOOLINFO ToolTipInfo; // TOOLINFO ToolTipInfo;
// Drag & drop
// LPDROPTARGET DropTarget;
// Left button down // Left button down
bool LButtonDown; bool LButtonDown;
bool RButtonDown; bool RButtonDown;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment