]> Pileus Git - ~andy/gtk/blob - gdk/win32/gdkdnd-win32.c
Add new keysyms from X11R6.4 (including EuroSign).
[~andy/gtk] / gdk / win32 / gdkdnd-win32.c
1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 1995-1999 Peter Mattis, Spencer Kimball and Josh MacDonald
3  * Copyright (C) 1998-1999 Tor Lillqvist
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 /*
22  * Modified by the GTK+ Team and others 1997-1999.  See the AUTHORS
23  * file for a list of people on the GTK+ Team.  See the ChangeLog
24  * files for a list of changes.  These files are distributed with
25  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
26  */
27
28 #include "config.h"
29
30 #include <string.h>
31
32 #define INITGUID
33
34 #include "gdkdnd.h"
35 #include "gdkproperty.h"
36 #include "gdkprivate.h"
37 #include "gdkx.h"
38
39 #ifdef OLE2_DND
40 #include <ole2.h>
41 #else
42 #include <objbase.h>
43 #endif
44
45 #ifdef _MSC_VER                 /* These aren't in mingw32 */
46 #include <shlobj.h>
47 #include <shlguid.h>
48 #endif
49
50 #include <gdk/gdk.h>
51
52 typedef struct _GdkDragContextPrivate GdkDragContextPrivate;
53
54 typedef enum {
55   GDK_DRAG_STATUS_DRAG,
56   GDK_DRAG_STATUS_MOTION_WAIT,
57   GDK_DRAG_STATUS_ACTION_WAIT,
58   GDK_DRAG_STATUS_DROP
59 } GtkDragStatus;
60
61 typedef enum {
62   GDK_DRAG_SOURCE,
63   GDK_DRAG_TARGET
64 } GdkDragKind;
65
66 #ifdef OLE2_DND
67
68 #define PRINT_RIID(riid) \
69   g_print ("riid = %.08x-%.04x-%.04x-%.02x%.02x-%.02x%.02x%.02x%.02x%.02x%.02x", \
70            ((gulong *)  riid)[0], \
71            ((gushort *) riid)[2], \
72            ((gushort *) riid)[3], \
73            ((guchar *)  riid)[8], \
74            ((guchar *)  riid)[9], \
75            ((guchar *)  riid)[10], \
76            ((guchar *)  riid)[11], \
77            ((guchar *)  riid)[12], \
78            ((guchar *)  riid)[13], \
79            ((guchar *)  riid)[14], \
80            ((guchar *)  riid)[15]);
81
82
83 HRESULT STDMETHODCALLTYPE
84   m_query_interface_target (IDropTarget __RPC_FAR *This,
85                             /* [in] */ REFIID riid,
86                             /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject);
87
88 ULONG STDMETHODCALLTYPE
89   m_add_ref_target (IDropTarget __RPC_FAR *This);
90
91 ULONG STDMETHODCALLTYPE
92   m_release_target (IDropTarget __RPC_FAR *This);
93
94 HRESULT STDMETHODCALLTYPE 
95   m_drag_enter (IDropTarget __RPC_FAR *This,
96                 /* [unique][in] */ IDataObject __RPC_FAR *pDataObj,
97                 /* [in] */ DWORD grfKeyState,
98                 /* [in] */ POINTL pt,
99                 /* [out][in] */ DWORD __RPC_FAR *pdwEffect);
100
101 HRESULT STDMETHODCALLTYPE
102   m_drag_over (IDropTarget __RPC_FAR *This,
103                /* [in] */ DWORD grfKeyState,
104                /* [in] */ POINTL pt,
105                /* [out][in] */ DWORD __RPC_FAR *pdwEffect);
106
107 HRESULT STDMETHODCALLTYPE
108   m_drag_leave (IDropTarget __RPC_FAR *This);
109
110 HRESULT STDMETHODCALLTYPE
111   m_drop (IDropTarget __RPC_FAR *This,
112           /* [unique][in] */ IDataObject __RPC_FAR *pDataObj,
113           /* [in] */ DWORD grfKeyState,
114           /* [in] */ POINTL pt,
115           /* [out][in] */ DWORD __RPC_FAR *pdwEffect);
116
117 HRESULT STDMETHODCALLTYPE
118   m_query_interface_source (IDropSource __RPC_FAR *This,
119                             /* [in] */ REFIID riid,
120                             /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject);
121
122 ULONG STDMETHODCALLTYPE
123   m_add_ref_source (IDropSource __RPC_FAR *This);
124
125 ULONG STDMETHODCALLTYPE
126   m_release_source (IDropSource __RPC_FAR *This);
127
128 HRESULT STDMETHODCALLTYPE
129   m_query_continue_drag (IDropSource __RPC_FAR *This,
130                          /* [in] */ BOOL fEscapePressed,
131                          /* [in] */ DWORD grfKeyState);
132 HRESULT STDMETHODCALLTYPE
133   m_give_feedback (IDropSource __RPC_FAR *This,
134                    /* [in] */ DWORD dwEffect);
135
136 #endif /* OLE2_DND */
137
138 /* Structure that holds information about a drag in progress.
139  * this is used on both source and destination sides.
140  */
141 struct _GdkDragContextPrivate {
142   GdkDragContext context;
143
144   guint   ref_count;
145
146   guint16 last_x;               /* Coordinates from last event */
147   guint16 last_y;
148   HWND  dest_xid;
149   guint drag_status;            /* Current status of drag */
150 };
151
152 GdkDragContext *current_dest_drag = NULL;
153
154 /* Drag Contexts */
155
156 static GList *contexts;
157
158 GdkDragContext *
159 gdk_drag_context_new        (void)
160 {
161   GdkDragContextPrivate *result;
162
163   result = g_new0 (GdkDragContextPrivate, 1);
164
165   result->ref_count = 1;
166
167   contexts = g_list_prepend (contexts, result);
168
169   return (GdkDragContext *)result;
170 }
171
172 #ifdef OLE2_DND
173
174 typedef struct {
175   IDropTarget idt;
176   GdkDragContext *context;
177 } target_drag_context;
178
179 typedef struct {
180   IDropSource ids;
181   GdkDragContext *context;
182 } source_drag_context;
183
184 HRESULT STDMETHODCALLTYPE
185 m_query_interface_target (IDropTarget __RPC_FAR *This,
186                           /* [in] */ REFIID riid,
187                           /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
188 {
189   GDK_NOTE (DND, g_print ("m_query_interface_target\n"));
190
191   *ppvObject = NULL;
192
193   PRINT_RIID (riid);
194
195   if (IsEqualGUID (riid, &IID_IUnknown))
196     {
197       g_print ("...IUnknown\n");
198       m_add_ref_target (This);
199       *ppvObject = This;
200       return S_OK;
201     }
202   else if (IsEqualGUID (riid, &IID_IDropTarget))
203     {
204       g_print ("...IDropTarget\n");
205       m_add_ref_target (This);
206       *ppvObject = This;
207       return S_OK;
208     }
209   else
210     {
211       g_print ("...Huh?\n");
212       return E_NOINTERFACE;
213     }
214 }
215
216 ULONG STDMETHODCALLTYPE
217 m_add_ref_target (IDropTarget __RPC_FAR *This)
218 {
219   target_drag_context *ctx = (target_drag_context *) This;
220   GdkDragContextPrivate *private = (GdkDragContextPrivate *) ctx->context;
221
222   GDK_NOTE (DND, g_print ("m_add_ref_target\n"));
223   gdk_drag_context_ref (ctx->context);
224   
225   return private->ref_count;
226 }
227
228 ULONG STDMETHODCALLTYPE
229 m_release_target (IDropTarget __RPC_FAR *This)
230 {
231   target_drag_context *ctx = (target_drag_context *) This;
232   GdkDragContextPrivate *private = (GdkDragContextPrivate *) ctx->context;
233
234   GDK_NOTE (DND, g_print ("m_release_target\n"));
235   gdk_drag_context_unref (ctx->context);
236
237   if (private->ref_count == 1)
238     {
239       gdk_drag_context_unref (ctx->context);
240       return 0;
241     }
242   else
243     return private->ref_count - 1;
244 }
245
246 HRESULT STDMETHODCALLTYPE 
247 m_drag_enter (IDropTarget __RPC_FAR *This,
248               /* [unique][in] */ IDataObject __RPC_FAR *pDataObj,
249               /* [in] */ DWORD grfKeyState,
250               /* [in] */ POINTL pt,
251               /* [out][in] */ DWORD __RPC_FAR *pdwEffect)
252 {
253   GDK_NOTE (DND, g_print ("m_drag_enter\n"));
254   return E_UNEXPECTED;
255 }
256
257 HRESULT STDMETHODCALLTYPE
258 m_drag_over (IDropTarget __RPC_FAR *This,
259              /* [in] */ DWORD grfKeyState,
260              /* [in] */ POINTL pt,
261              /* [out][in] */ DWORD __RPC_FAR *pdwEffect)
262 {
263   GDK_NOTE (DND, g_print ("m_drag_over\n"));
264   return E_UNEXPECTED;
265 }
266
267 HRESULT STDMETHODCALLTYPE
268 m_drag_leave (IDropTarget __RPC_FAR *This)
269 {
270   GDK_NOTE (DND, g_print ("m_drag_leave\n"));
271   return E_UNEXPECTED;
272 }
273
274 HRESULT STDMETHODCALLTYPE
275 m_drop (IDropTarget __RPC_FAR *This,
276         /* [unique][in] */ IDataObject __RPC_FAR *pDataObj,
277         /* [in] */ DWORD grfKeyState,
278         /* [in] */ POINTL pt,
279         /* [out][in] */ DWORD __RPC_FAR *pdwEffect)
280 {
281   GDK_NOTE (DND, g_print ("m_drop\n"));
282   return E_UNEXPECTED;
283 }
284
285 HRESULT STDMETHODCALLTYPE
286 m_query_interface_source (IDropSource __RPC_FAR *This,
287                           /* [in] */ REFIID riid,
288                           /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
289 {
290   GDK_NOTE (DND, g_print ("m_query_interface_source\n"));
291
292   *ppvObject = NULL;
293
294   PRINT_RIID (riid);
295   if (IsEqualGUID (riid, &IID_IUnknown))
296     {
297       g_print ("...IUnknown\n");
298       m_add_ref_source (This);
299       *ppvObject = This;
300       return S_OK;
301     }
302   else if (IsEqualGUID (riid, &IID_IDropSource))
303     {
304       g_print ("...IDropSource\n");
305       m_add_ref_source (This);
306       *ppvObject = This;
307       return S_OK;
308     }
309   else
310     {
311       g_print ("...Huh?\n");
312       return E_NOINTERFACE;
313     }
314 }
315
316 ULONG STDMETHODCALLTYPE
317 m_add_ref_source (IDropSource __RPC_FAR *This)
318 {
319   source_drag_context *ctx = (source_drag_context *) This;
320   GdkDragContextPrivate *private = (GdkDragContextPrivate *) ctx->context;
321
322   GDK_NOTE (DND, g_print ("m_add_ref_source\n"));
323   gdk_drag_context_ref (ctx->context);
324   
325   return private->ref_count;
326 }
327
328 ULONG STDMETHODCALLTYPE
329 m_release_source (IDropSource __RPC_FAR *This)
330 {
331   source_drag_context *ctx = (source_drag_context *) This;
332   GdkDragContextPrivate *private = (GdkDragContextPrivate *) ctx->context;
333
334   GDK_NOTE (DND, g_print ("m_release_source\n"));
335   gdk_drag_context_unref (ctx->context);
336
337   if (private->ref_count == 1)
338     {
339       gdk_drag_context_unref (ctx->context);
340       return 0;
341     }
342   else
343     return private->ref_count - 1;
344 }
345
346 HRESULT STDMETHODCALLTYPE
347 m_query_continue_drag (IDropSource __RPC_FAR *This,
348                        /* [in] */ BOOL fEscapePressed,
349                        /* [in] */ DWORD grfKeyState)
350 {
351   GDK_NOTE (DND, g_print ("m_query_continue_drag\n"));
352   return E_UNEXPECTED;
353 }
354
355 HRESULT STDMETHODCALLTYPE
356 m_give_feedback (IDropSource __RPC_FAR *This,
357                  /* [in] */ DWORD dwEffect)
358 {
359   GDK_NOTE (DND, g_print ("m_give_feedback\n"));
360   return E_UNEXPECTED;
361 }
362
363 static IDropTargetVtbl idt_vtbl = {
364   m_query_interface_target,
365   m_add_ref_target,
366   m_release_target,
367   m_drag_enter,
368   m_drag_over,
369   m_drag_leave,
370   m_drop
371 };
372
373 static IDropSourceVtbl ids_vtbl = {
374   m_query_interface_source,
375   m_add_ref_source,
376   m_release_source,
377   m_query_continue_drag,
378   m_give_feedback
379 };
380
381 target_drag_context *
382 target_context_new (void)
383 {
384   target_drag_context *result;
385
386   result = g_new0 (target_drag_context, 1);
387
388   result->idt.lpVtbl = &idt_vtbl;
389
390   result->context = gdk_drag_context_new ();
391
392   return result;
393 }
394
395 source_drag_context *
396 source_context_new (void)
397 {
398   source_drag_context *result;
399
400   result = g_new0 (source_drag_context, 1);
401
402   result->ids.lpVtbl = &ids_vtbl;
403
404   result->context = gdk_drag_context_new ();
405
406   return result;
407 }
408
409 #endif /* OLE2_DND */
410
411 void
412 gdk_drag_context_ref (GdkDragContext *context)
413 {
414   g_return_if_fail (context != NULL);
415
416   ((GdkDragContextPrivate *)context)->ref_count++;
417 }
418
419 void
420 gdk_drag_context_unref (GdkDragContext *context)
421 {
422   GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
423   
424   g_return_if_fail (context != NULL);
425
426   private->ref_count--;
427
428   GDK_NOTE (DND, g_print ("gdk_drag_context_unref: %d%s\n",
429                           private->ref_count,
430                           (private->ref_count == 0 ? " freeing" : "")));
431
432   if (private->ref_count == 0)
433     {
434       g_dataset_destroy (private);
435       
436       g_list_free (context->targets);
437
438       if (context->source_window)
439         gdk_window_unref (context->source_window);
440
441       if (context->dest_window)
442         gdk_window_unref (context->dest_window);
443
444       contexts = g_list_remove (contexts, private);
445       g_free (private);
446     }
447 }
448
449 #if 0
450
451 static GdkDragContext *
452 gdk_drag_context_find (gboolean is_source,
453                        HWND     source_xid,
454                        HWND     dest_xid)
455 {
456   GList *tmp_list = contexts;
457   GdkDragContext *context;
458
459   while (tmp_list)
460     {
461       context = (GdkDragContext *)tmp_list->data;
462
463       if ((!context->is_source == !is_source) &&
464           ((source_xid == None) || (context->source_window &&
465             (GDK_WINDOW_XWINDOW (context->source_window) == source_xid))) &&
466           ((dest_xid == None) || (context->dest_window &&
467             (GDK_WINDOW_XWINDOW (context->dest_window) == dest_xid))))
468         return context;
469       
470       tmp_list = tmp_list->next;
471     }
472
473   return NULL;
474 }
475
476 #endif
477
478 #ifdef _MSC_VER
479
480 /* From MS Knowledge Base article Q130698 */
481
482 /* resolve_link() fills the filename and path buffer
483  * with relevant information
484  * hWnd         - calling app's window handle.
485  *
486  * lpszLinkName - name of the link file passed into the function.
487  *
488  * lpszPath     - the buffer that will receive the file pathname.
489  */
490
491 static HRESULT 
492 resolve_link(HWND hWnd,
493              LPCTSTR lpszLinkName,
494              LPSTR lpszPath,
495              LPSTR lpszDescription)
496 {
497   HRESULT hres;
498   IShellLink *psl;
499   WIN32_FIND_DATA wfd;
500
501   /* Assume Failure to start with: */
502   *lpszPath = 0;
503   if (lpszDescription)
504     *lpszDescription = 0;
505
506   /* Call CoCreateInstance to obtain the IShellLink interface
507    * pointer. This call fails if CoInitialize is not called, so it is
508    * assumed that CoInitialize has been called.
509    */
510
511   hres = CoCreateInstance (&CLSID_ShellLink,
512                            NULL,
513                            CLSCTX_INPROC_SERVER,
514                            &IID_IShellLink,
515                            (LPVOID *)&psl);
516   if (SUCCEEDED (hres))
517    {
518      IPersistFile *ppf;
519      
520      /* The IShellLink interface supports the IPersistFile
521       * interface. Get an interface pointer to it.
522       */
523      hres = psl->lpVtbl->QueryInterface (psl,
524                                          &IID_IPersistFile,
525                                          (LPVOID *) &ppf);
526      if (SUCCEEDED (hres))
527        {
528          WORD wsz[MAX_PATH];
529
530          /* Convert the given link name string to wide character string. */
531          MultiByteToWideChar (CP_ACP, 0,
532                               lpszLinkName,
533                               -1, wsz, MAX_PATH);
534          /* Load the file. */
535          hres = ppf->lpVtbl->Load (ppf, wsz, STGM_READ);
536          if (SUCCEEDED (hres))
537            {
538              /* Resolve the link by calling the Resolve()
539               * interface function.
540               */
541              hres = psl->lpVtbl->Resolve(psl,  hWnd,
542                                          SLR_ANY_MATCH |
543                                          SLR_NO_UI);
544              if (SUCCEEDED (hres))
545                {
546                  hres = psl->lpVtbl->GetPath (psl, lpszPath,
547                                               MAX_PATH,
548                                               (WIN32_FIND_DATA*)&wfd,
549                                               0);
550
551                  if (SUCCEEDED (hres) && lpszDescription != NULL)
552                    {
553                      hres = psl->lpVtbl->GetDescription (psl,
554                                                          lpszDescription,
555                                                          MAX_PATH );
556
557                      if (!SUCCEEDED (hres))
558                        return FALSE;
559                    }
560                }
561            }
562          ppf->lpVtbl->Release (ppf);
563        }
564      psl->lpVtbl->Release (psl);
565    }
566   return SUCCEEDED (hres);
567 }
568
569 #else
570
571 #define resolve_link(hWnd, lpszLinkName, lpszPath, lpszDescription) FALSE
572
573 #endif
574
575 static GdkFilterReturn
576 gdk_dropfiles_filter (GdkXEvent *xev,
577                       GdkEvent  *event,
578                       gpointer   data)
579 {
580   GdkDragContext *context;
581   GdkDragContextPrivate *private;
582   static GdkAtom text_uri_list_atom = GDK_NONE;
583   GString *result;
584   MSG *msg = (MSG *) xev;
585   HANDLE hdrop;
586   POINT pt;
587   gint nfiles, i, k;
588   guchar fileName[MAX_PATH], linkedFile[MAX_PATH];
589   
590   if (text_uri_list_atom == GDK_NONE)
591     text_uri_list_atom = gdk_atom_intern ("text/uri-list", FALSE);
592
593   if (msg->message == WM_DROPFILES)
594     {
595       GDK_NOTE (DND, g_print ("WM_DROPFILES: %#x\n", msg->hwnd));
596
597       context = gdk_drag_context_new ();
598       private = (GdkDragContextPrivate *) context;
599       context->protocol = GDK_DRAG_PROTO_WIN32_DROPFILES;
600       context->is_source = FALSE;
601       context->source_window = (GdkWindow *) gdk_root_parent;
602       context->dest_window = event->any.window;
603       gdk_window_ref (context->dest_window);
604       /* WM_DROPFILES drops are always file names */
605       context->targets =
606         g_list_append (NULL, GUINT_TO_POINTER (text_uri_list_atom));
607       current_dest_drag = context;
608
609       event->dnd.type = GDK_DROP_START;
610       event->dnd.context = current_dest_drag;
611       gdk_drag_context_ref (current_dest_drag);
612       
613       hdrop = (HANDLE) msg->wParam;
614       DragQueryPoint (hdrop, &pt);
615       ClientToScreen (msg->hwnd, &pt);
616
617       event->dnd.x_root = pt.x;
618       event->dnd.y_root = pt.y;
619       event->dnd.time = msg->time;
620
621       nfiles = DragQueryFile (hdrop, 0xFFFFFFFF, NULL, 0);
622
623       result = g_string_new (NULL);
624       for (i = 0; i < nfiles; i++)
625         {
626           g_string_append (result, "file:");
627           DragQueryFile (hdrop, i, fileName, MAX_PATH);
628
629           /* Resolve shortcuts */
630           if (resolve_link (msg->hwnd, fileName, linkedFile, NULL))
631             {
632               g_string_append (result, linkedFile);
633               GDK_NOTE (DND, g_print ("...%s link to %s\n",
634                                       fileName, linkedFile));
635             }
636           else
637             {
638               g_string_append (result, fileName);
639               GDK_NOTE (DND, g_print ("...%s\n", fileName));
640             }
641           g_string_append (result, "\015\012");
642         }
643       gdk_sel_prop_store ((GdkWindow *) gdk_root_parent,
644                           text_uri_list_atom, 8, result->str, result->len + 1);
645
646       DragFinish (hdrop);
647       
648       return GDK_FILTER_TRANSLATE;
649     }
650   else
651     return GDK_FILTER_CONTINUE;
652 }
653
654 /*************************************************************
655  ************************** Public API ***********************
656  *************************************************************/
657
658 void
659 gdk_dnd_init (void)
660 {
661   HRESULT hres;
662 #ifdef OLE2_DND
663   hres = OleInitialize (NULL);
664
665   if (! SUCCEEDED (hres))
666     g_error ("OleInitialize failed");
667 #endif
668 }      
669
670 void
671 gdk_dnd_exit (void)
672 {
673 #ifdef OLE2_DND
674   OleUninitialize ();
675 #endif
676 }
677
678 /* Source side */
679
680 static void
681 gdk_drag_do_leave (GdkDragContext *context, guint32 time)
682 {
683   if (context->dest_window)
684     {
685       GDK_NOTE (DND, g_print ("gdk_drag_do_leave\n"));
686       gdk_window_unref (context->dest_window);
687       context->dest_window = NULL;
688     }
689 }
690
691 GdkDragContext * 
692 gdk_drag_begin (GdkWindow     *window,
693                 GList         *targets)
694 {
695   GList *tmp_list;
696   GdkDragContext *new_context;
697   
698   g_return_val_if_fail (window != NULL, NULL);
699
700   GDK_NOTE (DND, g_print ("gdk_drag_begin\n"));
701
702   new_context = gdk_drag_context_new ();
703   new_context->is_source = TRUE;
704   new_context->source_window = window;
705   gdk_window_ref (window);
706
707   tmp_list = g_list_last (targets);
708   new_context->targets = NULL;
709   while (tmp_list)
710     {
711       new_context->targets = g_list_prepend (new_context->targets,
712                                              tmp_list->data);
713       tmp_list = tmp_list->prev;
714     }
715
716   new_context->actions = 0;
717
718   return new_context;
719 }
720
721 guint32
722 gdk_drag_get_protocol (guint32          xid,
723                        GdkDragProtocol *protocol)
724 {
725   /* This isn't used */
726   return 0;
727 }
728
729 void
730 gdk_drag_find_window (GdkDragContext  *context,
731                       GdkWindow       *drag_window,
732                       gint             x_root,
733                       gint             y_root,
734                       GdkWindow      **dest_window,
735                       GdkDragProtocol *protocol)
736 {
737   GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
738   GdkDrawablePrivate *drag_window_private = (GdkDrawablePrivate*) drag_window;
739   HWND recipient;
740   POINT pt;
741
742   GDK_NOTE (DND, g_print ("gdk_drag_find_window: %#x +%d+%d\n",
743                           (drag_window ? drag_window_private->xwindow : 0),
744                           x_root, y_root));
745
746   pt.x = x_root;
747   pt.y = y_root;
748   recipient = WindowFromPoint (pt);
749   if (recipient == NULL)
750     *dest_window = NULL;
751   else
752     {
753       *dest_window = gdk_window_lookup (recipient);
754       if (*dest_window)
755         gdk_window_ref (*dest_window);
756       *protocol = GDK_DRAG_PROTO_WIN32_DROPFILES;
757     }
758 }
759
760 gboolean
761 gdk_drag_motion (GdkDragContext *context,
762                  GdkWindow      *dest_window,
763                  GdkDragProtocol protocol,
764                  gint            x_root, 
765                  gint            y_root,
766                  GdkDragAction   suggested_action,
767                  GdkDragAction   possible_actions,
768                  guint32         time)
769 {
770   return FALSE;
771 }
772
773 void
774 gdk_drag_drop (GdkDragContext *context,
775                guint32         time)
776 {
777   g_return_if_fail (context != NULL);
778
779   g_warning ("gdk_drag_drop: not implemented\n");
780 }
781
782 void
783 gdk_drag_abort (GdkDragContext *context,
784                 guint32         time)
785 {
786   g_return_if_fail (context != NULL);
787
788   gdk_drag_do_leave (context, time);
789 }
790
791 /* Destination side */
792
793 void
794 gdk_drag_status (GdkDragContext   *context,
795                  GdkDragAction     action,
796                  guint32           time)
797 {
798   GDK_NOTE (DND, g_print ("gdk_drag_status\n"));
799 }
800
801 void 
802 gdk_drop_reply (GdkDragContext   *context,
803                 gboolean          ok,
804                 guint32           time)
805 {
806 }
807
808 void
809 gdk_drop_finish (GdkDragContext   *context,
810                  gboolean          success,
811                  guint32           time)
812 {
813 }
814
815 static GdkFilterReturn
816 gdk_destroy_filter (GdkXEvent *xev,
817                     GdkEvent  *event,
818                     gpointer   data)
819 {
820 #ifdef OLE2_DND
821   MSG *msg = (MSG *) xev;
822
823   if (msg->message == WM_DESTROY)
824     {
825       IDropTarget *idtp = (IDropTarget *) data;
826
827       GDK_NOTE (DND, g_print ("gdk_destroy_filter: WM_DESTROY: %#x\n", msg->hwnd));
828       RevokeDragDrop (msg->hwnd);
829       CoLockObjectExternal (idtp, FALSE, TRUE);
830     }
831 #endif
832   return GDK_FILTER_CONTINUE;
833 }
834
835 void
836 gdk_window_register_dnd (GdkWindow      *window)
837 {
838   GdkDrawablePrivate *private = (GdkDrawablePrivate *) window;
839 #ifdef OLE2_DND
840   target_drag_context *context;
841   HRESULT hres;
842 #endif
843
844   g_return_if_fail (window != NULL);
845
846   GDK_NOTE (DND, g_print ("gdk_window_register_dnd: %#x\n", private->xwindow));
847
848   /* We always claim to accept dropped files, but in fact we might not,
849    * of course. This function is called in such a way that it cannot know
850    * whether the window (widget) in question actually accepts files
851    * (in gtk, data of type text/uri-list) or not.
852    */
853   gdk_window_add_filter (window, gdk_dropfiles_filter, NULL);
854   DragAcceptFiles (private->xwindow, TRUE);
855
856 #ifdef OLE2_DND
857   /* Register for OLE2 d&d */
858   context = target_context_new ();
859   hres = CoLockObjectExternal ((IUnknown *) &context->idt, TRUE, FALSE);
860   if (!SUCCEEDED (hres))
861     g_warning ("gdk_window_register_dnd: CoLockObjectExternal failed");
862   else
863     {
864       hres = RegisterDragDrop (private->xwindow, &context->idt);
865       if (hres == DRAGDROP_E_ALREADYREGISTERED)
866         {
867           g_print ("DRAGDROP_E_ALREADYREGISTERED\n");
868           CoLockObjectExternal ((IUnknown *) &context->idt, FALSE, FALSE);
869         }
870       else if (!SUCCEEDED (hres))
871         g_warning ("gdk_window_register_dnd: RegisterDragDrop failed");
872       else
873         {
874           gdk_window_add_filter (window, gdk_destroy_filter, &context->idt);
875         }
876     }
877 #endif
878 }
879
880 /*************************************************************
881  * gdk_drag_get_selection:
882  *     Returns the selection atom for the current source window
883  *   arguments:
884  *
885  *   results:
886  *************************************************************/
887
888 GdkAtom
889 gdk_drag_get_selection (GdkDragContext *context)
890 {
891   if (context->protocol == GDK_DRAG_PROTO_WIN32_DROPFILES)
892     return gdk_win32_dropfiles_atom;
893   else if (context->protocol == GDK_DRAG_PROTO_OLE2)
894     return gdk_ole2_dnd_atom;
895   else
896     return GDK_NONE;
897 }