1 /*****************************************************************************
2 * gtk2_dragdrop.cpp: GTK2 implementation of the drag & drop
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: gtk2_dragdrop.cpp,v 1.6 2003/04/28 12:00:13 asmax Exp $
7 * Authors: Cyril Deguet <asmax@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111,
23 *****************************************************************************/
27 //--- GTK2 -----------------------------------------------------------------
30 //--- VLC -------------------------------------------------------------------
33 //--- SKIN ------------------------------------------------------------------
34 #include "../src/event.h"
35 #include "../os_api.h"
36 #include "gtk2_dragdrop.h"
39 //---------------------------------------------------------------------------
40 GTK2DropObject::GTK2DropObject( intf_thread_t *_p_intf )
44 //---------------------------------------------------------------------------
45 GTK2DropObject::~GTK2DropObject()
48 //---------------------------------------------------------------------------
49 void GTK2DropObject::HandleDropStart( GdkDragContext *context )
51 GdkAtom atom = gdk_drag_get_selection( context );
57 // Get the owner of the selection
58 GdkWindow *owner = gdk_selection_owner_get( atom );
60 // Find the possible targets for the selection
62 gdk_selection_convert( owner, atom, gdk_atom_intern("TARGETS", FALSE),
64 int len = gdk_selection_property_get( owner, &buffer, &prop_type,
66 for( int i = 0; i < len / sizeof(GdkAtom); i++ )
68 GdkAtom atom = ( (GdkAtom*)buffer )[i];
69 gchar *name = gdk_atom_name( atom );
72 string curTarget = name;
73 if( (curTarget == "text/plain" || curTarget == "STRING") )
83 msg_Warn( p_intf, "Drag&Drop: target not found\n" );
87 gdk_selection_convert( owner, atom, gdk_atom_intern(target.c_str(),
88 FALSE), OSAPI_GetTime() );
89 len = gdk_selection_property_get( owner, &buffer, &prop_type,
91 OSAPI_PostMessage( NULL, VLC_DROP, (unsigned int)buffer, 0 );
94 /* // Get number of files that are dropped into vlc
95 int NbFiles = DragQueryFile( (HDROP)HDrop, 0xFFFFFFFF, NULL, 0 );
97 // For each dropped files
98 for( int i = 0; i < NbFiles; i++ )
100 // Get the name of the file
101 int NameLength = DragQueryFile( (HDROP)HDrop, i, NULL, 0 ) + 1;
102 char *FileName = new char[NameLength];
103 DragQueryFile( (HDROP)HDrop, i, FileName, NameLength );
105 // The pointer must not be deleted here because it will be deleted
106 // in the VLC specific messages processing function
107 PostMessage( NULL, VLC_DROP, (WPARAM)FileName, 0 );
110 DragFinish( (HDROP)HDrop );
113 gdk_drop_finish( context, TRUE,OSAPI_GetTime() );