]> git.sesse.net Git - vlc/blob - modules/gui/skins/gtk2/gtk2_dragdrop.cpp
* fixed compilation under linux
[vlc] / modules / gui / skins / gtk2 / gtk2_dragdrop.cpp
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 $
6  *
7  * Authors: Cyril Deguet     <asmax@videolan.org>
8  *
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.
13  *
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.
18  *
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,
22  * USA.
23  *****************************************************************************/
24
25 #ifdef GTK2_SKINS
26
27 //--- GTK2 -----------------------------------------------------------------
28 #include <gdk/gdk.h>
29
30 //--- VLC -------------------------------------------------------------------
31 #include <vlc/intf.h>
32
33 //--- SKIN ------------------------------------------------------------------
34 #include "../src/event.h"
35 #include "../os_api.h"
36 #include "gtk2_dragdrop.h"
37
38
39 //---------------------------------------------------------------------------
40 GTK2DropObject::GTK2DropObject( intf_thread_t *_p_intf )
41 {
42     p_intf = _p_intf;
43 }
44 //---------------------------------------------------------------------------
45 GTK2DropObject::~GTK2DropObject()
46 {
47 }
48 //---------------------------------------------------------------------------
49 void GTK2DropObject::HandleDropStart( GdkDragContext *context )
50 {
51     GdkAtom atom = gdk_drag_get_selection( context );
52     
53     guchar *buffer;
54     GdkAtom prop_type;
55     gint prop_format;
56     
57     // Get the owner of the selection
58     GdkWindow *owner = gdk_selection_owner_get( atom ); 
59
60     // Find the possible targets for the selection
61     string target = "";
62     gdk_selection_convert( owner, atom, gdk_atom_intern("TARGETS", FALSE), 
63                            OSAPI_GetTime() );
64     int len = gdk_selection_property_get( owner, &buffer, &prop_type, 
65                                           &prop_format );
66     for( int i = 0; i < len / sizeof(GdkAtom); i++ )
67     {
68         GdkAtom atom = ( (GdkAtom*)buffer )[i];
69         gchar *name = gdk_atom_name( atom );
70         if( name )
71         {
72             string curTarget = name;
73             if( (curTarget == "text/plain" || curTarget == "STRING") )
74             {
75                 target = curTarget;
76                 break;
77             }
78         }
79     }
80
81     if( target == "" )
82     {
83         msg_Warn( p_intf, "Drag&Drop: target not found\n" );
84     }
85     else
86     {
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, 
90                                           &prop_format);
91         OSAPI_PostMessage( NULL, VLC_DROP, (unsigned int)buffer, 0 );
92     }
93
94 /*    // Get number of files that are dropped into vlc
95     int NbFiles = DragQueryFile( (HDROP)HDrop, 0xFFFFFFFF, NULL, 0 );
96
97     // For each dropped files
98     for( int i = 0; i < NbFiles; i++ )
99     {
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 );
104
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 );
108     }
109
110     DragFinish( (HDROP)HDrop );
111     
112 */
113     gdk_drop_finish( context, TRUE,OSAPI_GetTime() );
114 }
115
116 #endif