]> Pileus Git - ~andy/gtk/blob - gdk/win32/gdkdnd.c
Updated Korean translation
[~andy/gtk] / gdk / win32 / gdkdnd.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 #define INITGUID
31
32 #include <string.h>
33
34 #include <ole2.h>
35 #include <shlobj.h>
36 #include <shlguid.h>
37
38 #include <gdk/gdk.h>
39 #include "gdkx.h"
40
41 typedef struct _GdkDragContextPrivate GdkDragContextPrivate;
42
43 typedef enum {
44   GDK_DRAG_STATUS_DRAG,
45   GDK_DRAG_STATUS_MOTION_WAIT,
46   GDK_DRAG_STATUS_ACTION_WAIT,
47   GDK_DRAG_STATUS_DROP
48 } GtkDragStatus;
49
50 typedef enum {
51   GDK_DRAG_SOURCE,
52   GDK_DRAG_TARGET
53 } GdkDragKind;
54
55 #ifdef OLE2_DND
56
57 HRESULT STDMETHODCALLTYPE
58   m_query_interface_target (IDropTarget __RPC_FAR *This,
59                             /* [in] */ REFIID riid,
60                             /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject);
61
62 ULONG STDMETHODCALLTYPE
63   m_add_ref_target (IDropTarget __RPC_FAR *This);
64
65 ULONG STDMETHODCALLTYPE
66   m_release_target (IDropTarget __RPC_FAR *This);
67
68 HRESULT STDMETHODCALLTYPE 
69   m_drag_enter (IDropTarget __RPC_FAR *This,
70                 /* [unique][in] */ IDataObject __RPC_FAR *pDataObj,
71                 /* [in] */ DWORD grfKeyState,
72                 /* [in] */ POINTL pt,
73                 /* [out][in] */ DWORD __RPC_FAR *pdwEffect);
74
75 HRESULT STDMETHODCALLTYPE
76   m_drag_over (IDropTarget __RPC_FAR *This,
77                /* [in] */ DWORD grfKeyState,
78                /* [in] */ POINTL pt,
79                /* [out][in] */ DWORD __RPC_FAR *pdwEffect);
80
81 HRESULT STDMETHODCALLTYPE
82   m_drag_leave (IDropTarget __RPC_FAR *This);
83
84 HRESULT STDMETHODCALLTYPE
85   m_drop (IDropTarget __RPC_FAR *This,
86           /* [unique][in] */ IDataObject __RPC_FAR *pDataObj,
87           /* [in] */ DWORD grfKeyState,
88           /* [in] */ POINTL pt,
89           /* [out][in] */ DWORD __RPC_FAR *pdwEffect);
90
91 HRESULT STDMETHODCALLTYPE
92   m_query_interface_source (IDropSource __RPC_FAR *This,
93                             /* [in] */ REFIID riid,
94                             /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject);
95
96 ULONG STDMETHODCALLTYPE
97   m_add_ref_source (IDropSource __RPC_FAR *This);
98
99 ULONG STDMETHODCALLTYPE
100   m_release_source (IDropSource __RPC_FAR *This);
101
102 HRESULT STDMETHODCALLTYPE
103   m_query_continue_drag (IDropSource __RPC_FAR *This,
104                          /* [in] */ BOOL fEscapePressed,
105                          /* [in] */ DWORD grfKeyState);
106 HRESULT STDMETHODCALLTYPE
107   m_give_feedback (IDropSource __RPC_FAR *This,
108                    /* [in] */ DWORD dwEffect);
109
110 #endif /* OLE2_DND */
111
112 /* Structure that holds information about a drag in progress.
113  * this is used on both source and destination sides.
114  */
115 struct _GdkDragContextPrivate {
116   GdkDragContext context;
117
118   guint   ref_count;
119
120   guint16 last_x;               /* Coordinates from last event */
121   guint16 last_y;
122   HWND  dest_xid;
123   guint drag_status;            /* Current status of drag */
124 };
125
126 GdkDragContext *current_dest_drag = NULL;
127
128 /* Drag Contexts */
129
130 static GList *contexts;
131
132 GdkDragContext *
133 gdk_drag_context_new        (void)
134 {
135   GdkDragContextPrivate *result;
136
137   result = g_new0 (GdkDragContextPrivate, 1);
138
139   result->ref_count = 1;
140
141   contexts = g_list_prepend (contexts, result);
142
143   return (GdkDragContext *)result;
144 }
145
146 #if OLE2_DND
147
148 typedef struct {
149   IDropTarget idt;
150   GdkDragContext *context;
151 } target_drag_context;
152
153 typedef struct {
154   IDropSource ids;
155   GdkDragContext *context;
156 } source_drag_context;
157
158 HRESULT STDMETHODCALLTYPE
159 m_query_interface_target (IDropTarget __RPC_FAR *This,
160                           /* [in] */ REFIID riid,
161                           /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
162 {
163   GDK_NOTE (DND, g_print ("m_query_interface_target\n"));
164
165   *ppvObject = NULL;
166
167   g_print ("riid = %.08x-%.04x-%.04x-%.02x%.02x-%.02x%.02x%.02x%.02x%.02x%.02x",
168            ((gulong *) riid)[0],
169            ((gushort *) riid)[2],
170            ((gushort *) riid)[3],
171            ((guchar *) riid)[8],
172            ((guchar *) riid)[9],
173            ((guchar *) riid)[10],
174            ((guchar *) riid)[11],
175            ((guchar *) riid)[12],
176            ((guchar *) riid)[13],
177            ((guchar *) riid)[14],
178            ((guchar *) riid)[15]);
179   if (IsEqualGUID (riid, &IID_IUnknown))
180     {
181       m_add_ref_target (This);
182       *ppvObject = This;
183       g_print ("...IUnknown\n");
184       return S_OK;
185     }
186   else if (IsEqualGUID (riid, &IID_IDropTarget))
187     {
188       m_add_ref_target (This);
189       *ppvObject = This;
190       g_print ("...IDropTarget\n");
191       return S_OK;
192     }
193   else
194     {
195       g_print ("...Huh?\n");
196       return E_NOINTERFACE;
197     }
198 }
199
200 ULONG STDMETHODCALLTYPE
201 m_add_ref_target (IDropTarget __RPC_FAR *This)
202 {
203   target_drag_context *ctx = (target_drag_context *) This;
204   GdkDragContextPrivate *private = (GdkDragContextPrivate *) ctx->context;
205
206   GDK_NOTE (DND, g_print ("m_add_ref_target\n"));
207   gdk_drag_context_ref (ctx->context);
208   
209   return private->ref_count;
210 }
211
212 ULONG STDMETHODCALLTYPE
213 m_release_target (IDropTarget __RPC_FAR *This)
214 {
215   target_drag_context *ctx = (target_drag_context *) This;
216   GdkDragContextPrivate *private = (GdkDragContextPrivate *) ctx->context;
217
218   GDK_NOTE (DND, g_print ("m_release_target\n"));
219   gdk_drag_context_unref (ctx->context);
220
221   if (private->ref_count == 1)
222     {
223       gdk_drag_context_unref (ctx->context);
224       return 0;
225     }
226   else
227     return private->ref_count - 1;
228 }
229
230 HRESULT STDMETHODCALLTYPE 
231 m_drag_enter (IDropTarget __RPC_FAR *This,
232               /* [unique][in] */ IDataObject __RPC_FAR *pDataObj,
233               /* [in] */ DWORD grfKeyState,
234               /* [in] */ POINTL pt,
235               /* [out][in] */ DWORD __RPC_FAR *pdwEffect)
236 {
237   GDK_NOTE (DND, g_print ("m_drag_enter\n"));
238   return E_UNEXPECTED;
239 }
240
241 HRESULT STDMETHODCALLTYPE
242 m_drag_over (IDropTarget __RPC_FAR *This,
243              /* [in] */ DWORD grfKeyState,
244              /* [in] */ POINTL pt,
245              /* [out][in] */ DWORD __RPC_FAR *pdwEffect)
246 {
247   GDK_NOTE (DND, g_print ("m_drag_over\n"));
248   return E_UNEXPECTED;
249 }
250
251 HRESULT STDMETHODCALLTYPE
252 m_drag_leave (IDropTarget __RPC_FAR *This)
253 {
254   GDK_NOTE (DND, g_print ("m_drag_leave\n"));
255   return E_UNEXPECTED;
256 }
257
258 HRESULT STDMETHODCALLTYPE
259 m_drop (IDropTarget __RPC_FAR *This,
260         /* [unique][in] */ IDataObject __RPC_FAR *pDataObj,
261         /* [in] */ DWORD grfKeyState,
262         /* [in] */ POINTL pt,
263         /* [out][in] */ DWORD __RPC_FAR *pdwEffect)
264 {
265   GDK_NOTE (DND, g_print ("m_drop\n"));
266   return E_UNEXPECTED;
267 }
268  
269 HRESULT STDMETHODCALLTYPE
270 m_query_interface_source (IDropSource __RPC_FAR *This,
271                           /* [in] */ REFIID riid,
272                           /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
273 {
274   GDK_NOTE (DND, g_print ("m_query_interface_source\n"));
275
276   *ppvObject = NULL;
277
278   g_print ("riid = %.02x%.02x%.02x%.02x-%.02x%.02x-%.02x%.02x-%.02x%.02x-%.02x%.02x%.02x%.02x%.02x%.02x",
279            ((guchar *) riid)[0],
280            ((guchar *) riid)[1],
281            ((guchar *) riid)[2],
282            ((guchar *) riid)[3],
283            ((guchar *) riid)[4],
284            ((guchar *) riid)[5],
285            ((guchar *) riid)[6],
286            ((guchar *) riid)[7],
287            ((guchar *) riid)[8],
288            ((guchar *) riid)[9],
289            ((guchar *) riid)[10],
290            ((guchar *) riid)[11],
291            ((guchar *) riid)[12],
292            ((guchar *) riid)[13],
293            ((guchar *) riid)[14],
294            ((guchar *) riid)[15]);
295   if (IsEqualGUID (riid, &IID_IUnknown))
296     {
297       m_add_ref_source (This);
298       *ppvObject = This;
299       g_print ("...IUnknown\n");
300       return S_OK;
301     }
302   else if (IsEqualGUID (riid, &IID_IDropSource))
303     {
304       m_add_ref_source (This);
305       *ppvObject = This;
306       g_print ("...IDropSource\n");
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 /* From MS Knowledge Base article Q130698 */
479
480 /* resolve_link() fills the filename and path buffer
481  * with relevant information
482  * hWnd         - calling app's window handle.
483  *
484  * lpszLinkName - name of the link file passed into the function.
485  *
486  * lpszPath     - the buffer that will receive the file pathname.
487  */
488
489 static HRESULT 
490 resolve_link(HWND hWnd,
491              LPCTSTR lpszLinkName,
492              LPSTR lpszPath,
493              LPSTR lpszDescription)
494 {
495   HRESULT hres;
496   IShellLink *psl;
497   WIN32_FIND_DATA wfd;
498
499   /* Assume Failure to start with: */
500   *lpszPath = 0;
501   if (lpszDescription)
502     *lpszDescription = 0;
503
504   /* Call CoCreateInstance to obtain the IShellLink interface
505    * pointer. This call fails if CoInitialize is not called, so it is
506    * assumed that CoInitialize has been called.
507    */
508
509   hres = CoCreateInstance (&CLSID_ShellLink,
510                            NULL,
511                            CLSCTX_INPROC_SERVER,
512                            &IID_IShellLink,
513                            (LPVOID *)&psl);
514   if (SUCCEEDED (hres))
515    {
516      IPersistFile *ppf;
517      
518      /* The IShellLink interface supports the IPersistFile
519       * interface. Get an interface pointer to it.
520       */
521      hres = psl->lpVtbl->QueryInterface (psl,
522                                          &IID_IPersistFile,
523                                          (LPVOID *) &ppf);
524      if (SUCCEEDED (hres))
525        {
526          WORD wsz[MAX_PATH];
527
528          /* Convert the given link name string to wide character string. */
529          MultiByteToWideChar (CP_ACP, 0,
530                               lpszLinkName,
531                               -1, wsz, MAX_PATH);
532          /* Load the file. */
533          hres = ppf->lpVtbl->Load (ppf, wsz, STGM_READ);
534          if (SUCCEEDED (hres))
535            {
536              /* Resolve the link by calling the Resolve()
537               * interface function.
538               */
539              hres = psl->lpVtbl->Resolve(psl,  hWnd,
540                                          SLR_ANY_MATCH |
541                                          SLR_NO_UI);
542              if (SUCCEEDED (hres))
543                {
544                  hres = psl->lpVtbl->GetPath (psl, lpszPath,
545                                               MAX_PATH,
546                                               (WIN32_FIND_DATA*)&wfd,
547                                               0);
548
549                  if (SUCCEEDED (hres) && lpszDescription != NULL)
550                    {
551                      hres = psl->lpVtbl->GetDescription (psl,
552                                                          lpszDescription,
553                                                          MAX_PATH );
554
555                      if (!SUCCEEDED (hres))
556                        return FALSE;
557                    }
558                }
559            }
560          ppf->lpVtbl->Release (ppf);
561        }
562      psl->lpVtbl->Release (psl);
563    }
564   return SUCCEEDED (hres);
565 }
566
567 static GdkFilterReturn
568 gdk_dropfiles_filter (GdkXEvent *xev,
569                       GdkEvent  *event,
570                       gpointer   data)
571 {
572   GdkDragContext *context;
573   GdkDragContextPrivate *private;
574   static GdkAtom text_uri_list_atom = GDK_NONE;
575   GString *result;
576   MSG *msg = (MSG *) xev;
577   HANDLE hdrop;
578   POINT pt;
579   gint nfiles, i, k;
580   guchar fileName[MAX_PATH], linkedFile[MAX_PATH];
581   
582   if (text_uri_list_atom == GDK_NONE)
583     text_uri_list_atom = gdk_atom_intern ("text/uri-list", FALSE);
584
585   if (msg->message == WM_DROPFILES)
586     {
587       GDK_NOTE (DND, g_print ("WM_DROPFILES: %#x\n", msg->hwnd));
588
589       context = gdk_drag_context_new ();
590       private = (GdkDragContextPrivate *) context;
591       context->protocol = GDK_DRAG_PROTO_WIN32_DROPFILES;
592       context->is_source = FALSE;
593       context->source_window = (GdkWindow *) &gdk_root_parent;
594       context->dest_window = event->any.window;
595       gdk_window_ref (context->dest_window);
596       /* WM_DROPFILES drops are always file names */
597       context->targets =
598         g_list_append (NULL, GUINT_TO_POINTER (text_uri_list_atom));
599       current_dest_drag = context;
600
601       event->dnd.type = GDK_DROP_START;
602       event->dnd.context = current_dest_drag;
603       gdk_drag_context_ref (current_dest_drag);
604       
605       hdrop = (HANDLE) msg->wParam;
606       DragQueryPoint (hdrop, &pt);
607       ClientToScreen (msg->hwnd, &pt);
608
609       event->dnd.x_root = pt.x;
610       event->dnd.y_root = pt.y;
611       event->dnd.time = msg->time;
612
613       nfiles = DragQueryFile (hdrop, 0xFFFFFFFF, NULL, 0);
614
615       result = g_string_new (NULL);
616       for (i = 0; i < nfiles; i++)
617         {
618           g_string_append (result, "file:");
619           DragQueryFile (hdrop, i, fileName, MAX_PATH);
620
621           /* Resolve shortcuts */
622           if (resolve_link (msg->hwnd, fileName, linkedFile, NULL))
623             {
624               g_string_append (result, linkedFile);
625               GDK_NOTE (DND, g_print ("...%s link to %s\n",
626                                       fileName, linkedFile));
627             }
628           else
629             {
630               g_string_append (result, fileName);
631               GDK_NOTE (DND, g_print ("...%s\n", fileName));
632             }
633           g_string_append (result, "\015\012");
634         }
635       gdk_sel_prop_store ((GdkWindow *) &gdk_root_parent,
636                           text_uri_list_atom, 8, result->str, result->len + 1);
637
638       DragFinish (hdrop);
639       
640       return GDK_FILTER_TRANSLATE;
641     }
642   else
643     return GDK_FILTER_CONTINUE;
644 }
645                      
646
647 /*************************************************************
648  ************************** Public API ***********************
649  *************************************************************/
650
651 void
652 gdk_dnd_init (void)
653 {
654   HRESULT hres;
655
656   hres = OleInitialize (NULL);
657
658   if (! SUCCEEDED (hres))
659     g_error ("OleInitialize failed");
660 }                     
661
662 void
663 gdk_dnd_exit (void)
664 {
665   OleUninitialize ();
666 }
667
668 /* Source side */
669
670 static void
671 gdk_drag_do_leave (GdkDragContext *context, guint32 time)
672 {
673   if (context->dest_window)
674     {
675       GDK_NOTE (DND, g_print ("gdk_drag_do_leave\n"));
676       gdk_window_unref (context->dest_window);
677       context->dest_window = NULL;
678     }
679 }
680
681 GdkDragContext * 
682 gdk_drag_begin (GdkWindow     *window,
683                 GList         *targets)
684 {
685   GList *tmp_list;
686   GdkDragContext *new_context;
687   
688   g_return_val_if_fail (window != NULL, NULL);
689
690   GDK_NOTE (DND, g_print ("gdk_drag_begin\n"));
691
692   new_context = gdk_drag_context_new ();
693   new_context->is_source = TRUE;
694   new_context->source_window = window;
695   gdk_window_ref (window);
696
697   tmp_list = g_list_last (targets);
698   new_context->targets = NULL;
699   while (tmp_list)
700     {
701       new_context->targets = g_list_prepend (new_context->targets,
702                                              tmp_list->data);
703       tmp_list = tmp_list->prev;
704     }
705
706   new_context->actions = 0;
707
708   return new_context;
709 }
710
711 guint32
712 gdk_drag_get_protocol (guint32          xid,
713                        GdkDragProtocol *protocol)
714 {
715   /* This isn't used */
716   return 0;
717 }
718
719 void
720 gdk_drag_find_window (GdkDragContext  *context,
721                       GdkWindow       *drag_window,
722                       gint             x_root,
723                       gint             y_root,
724                       GdkWindow      **dest_window,
725                       GdkDragProtocol *protocol)
726 {
727   GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
728   GdkWindowPrivate *drag_window_private = (GdkWindowPrivate *) drag_window;
729   HWND recipient;
730   POINT pt;
731
732   GDK_NOTE (DND, g_print ("gdk_drag_find_window: %#x +%d+%d\n",
733                           (drag_window ? drag_window_private->xwindow : 0),
734                           x_root, y_root));
735
736   pt.x = x_root;
737   pt.y = y_root;
738   recipient = WindowFromPoint (pt);
739   if (recipient == NULL)
740     *dest_window = NULL;
741   else
742     {
743       *dest_window = gdk_window_lookup (recipient);
744       if (*dest_window)
745         gdk_window_ref (*dest_window);
746       *protocol = GDK_DRAG_PROTO_WIN32_DROPFILES;
747     }
748 }
749
750 gboolean        
751 gdk_drag_motion (GdkDragContext *context,
752                  GdkWindow      *dest_window,
753                  GdkDragProtocol protocol,
754                  gint            x_root, 
755                  gint            y_root,
756                  GdkDragAction   suggested_action,
757                  GdkDragAction   possible_actions,
758                  guint32         time)
759 {
760   return FALSE;
761 }
762
763 void
764 gdk_drag_drop (GdkDragContext *context,
765                guint32         time)
766 {
767   g_return_if_fail (context != NULL);
768
769   g_warning ("gdk_drag_drop: not implemented\n");
770 }
771
772 void
773 gdk_drag_abort (GdkDragContext *context,
774                 guint32         time)
775 {
776   g_return_if_fail (context != NULL);
777
778   gdk_drag_do_leave (context, time);
779 }
780
781 /* Destination side */
782
783 void             
784 gdk_drag_status (GdkDragContext   *context,
785                  GdkDragAction     action,
786                  guint32           time)
787 {
788   GDK_NOTE (DND, g_print ("gdk_drag_status\n"));
789 }
790
791 void 
792 gdk_drop_reply (GdkDragContext   *context,
793                 gboolean          ok,
794                 guint32           time)
795 {
796 }
797
798 void             
799 gdk_drop_finish (GdkDragContext   *context,
800                  gboolean          success,
801                  guint32           time)
802 {
803 }
804
805
806 void            
807 gdk_window_register_dnd (GdkWindow      *window)
808 {
809   GdkWindowPrivate *private = (GdkWindowPrivate *) window;
810 #if OLE2_DND
811   target_drag_context *context;
812   HRESULT hres;
813 #endif
814
815   g_return_if_fail (window != NULL);
816
817   GDK_NOTE (DND, g_print ("gdk_window_register_dnd: %#x\n", private->xwindow));
818
819   /* We always claim to accept dropped files, but in fact we might not,
820    * of course. This function is called in such a way that it cannot know
821    * whether the window (widget) in question actually accepts files
822    * (in gtk, data of type text/uri-list) or not.
823    */
824   gdk_window_add_filter (window, gdk_dropfiles_filter, NULL);
825   DragAcceptFiles (private->xwindow, TRUE);
826
827 #if OLE2_DND
828   /* Register for OLE2 d&d */
829   context = target_context_new ();
830   hres = CoLockObjectExternal ((IUnknown *) &context->idt, TRUE, FALSE);
831   if (!SUCCEEDED (hres))
832     g_warning ("gdk_window_register_dnd: CoLockObjectExternal failed");
833   else
834     {
835       hres = RegisterDragDrop (private->xwindow, &context->idt);
836       if (hres == DRAGDROP_E_ALREADYREGISTERED)
837         {
838           g_print ("DRAGDROP_E_ALREADYREGISTERED\n");
839           CoLockObjectExternal ((IUnknown *) &context->idt, FALSE, FALSE);
840         }
841       else if (!SUCCEEDED (hres))
842         g_warning ("gdk_window_register_dnd: RegisterDragDrop failed");
843     }
844 #endif
845 }
846
847 /*************************************************************
848  * gdk_drag_get_selection:
849  *     Returns the selection atom for the current source window
850  *   arguments:
851  *     
852  *   results:
853  *************************************************************/
854
855 GdkAtom       
856 gdk_drag_get_selection (GdkDragContext *context)
857 {
858   if (context->protocol == GDK_DRAG_PROTO_WIN32_DROPFILES)
859     return gdk_win32_dropfiles_atom;
860   else if (context->protocol == GDK_DRAG_PROTO_OLE2)
861     return gdk_ole2_dnd_atom;
862   else
863     return GDK_NONE;
864 }