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
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.
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.
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.
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/.
32 /* #define OLE2_DND */
37 #include "gdkproperty.h"
38 #include "gdkinternals.h"
39 #include "gdkprivate-win32.h"
40 #include "gdkdrawable-win32.h"
53 typedef struct _GdkDragContextPrivate GdkDragContextPrivate;
57 GDK_DRAG_STATUS_MOTION_WAIT,
58 GDK_DRAG_STATUS_ACTION_WAIT,
69 #define PRINT_GUID(guid) \
70 g_print ("guid = %.08x-%.04x-%.04x-%.02x%.02x-%.02x%.02x%.02x%.02x%.02x%.02x", \
71 ((gulong *) guid)[0], \
72 ((gushort *) guid)[2], \
73 ((gushort *) guid)[3], \
74 ((guchar *) guid)[8], \
75 ((guchar *) guid)[9], \
76 ((guchar *) guid)[10], \
77 ((guchar *) guid)[11], \
78 ((guchar *) guid)[12], \
79 ((guchar *) guid)[13], \
80 ((guchar *) guid)[14], \
81 ((guchar *) guid)[15]);
84 static FORMATETC *formats;
89 /* Structure that holds information about a drag in progress.
90 * this is used on both source and destination sides.
92 struct _GdkDragContextPrivate {
93 GdkDragContext context;
97 guint16 last_x; /* Coordinates from last event */
100 guint drag_status; /* Current status of drag */
103 GdkDragContext *current_dest_drag = NULL;
107 static GList *contexts;
110 gdk_drag_context_new (void)
112 GdkDragContextPrivate *result;
114 result = g_new0 (GdkDragContextPrivate, 1);
116 result->ref_count = 1;
118 contexts = g_list_prepend (contexts, result);
120 return (GdkDragContext *) result;
124 gdk_drag_context_ref (GdkDragContext *context)
126 g_return_if_fail (context != NULL);
128 ((GdkDragContextPrivate *)context)->ref_count++;
132 gdk_drag_context_unref (GdkDragContext *context)
134 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
136 g_return_if_fail (context != NULL);
138 if (private->ref_count <= 0)
141 private->ref_count--;
143 GDK_NOTE (DND, g_print ("gdk_drag_context_unref: %d%s\n",
145 (private->ref_count == 0 ? " freeing" : "")));
147 if (private->ref_count == 0)
149 g_dataset_destroy (private);
151 g_list_free (context->targets);
153 if (context->source_window)
154 gdk_drawable_unref (context->source_window);
156 if (context->dest_window)
157 gdk_drawable_unref (context->dest_window);
159 contexts = g_list_remove (contexts, private);
166 static GdkDragContext *
167 gdk_drag_context_find (gboolean is_source,
171 GList *tmp_list = contexts;
172 GdkDragContext *context;
176 context = (GdkDragContext *)tmp_list->data;
178 if ((!context->is_source == !is_source) &&
179 ((source_xid == None) || (context->source_window &&
180 (GDK_WINDOW_XWINDOW (context->source_window) == source_xid))) &&
181 ((dest_xid == None) || (context->dest_window &&
182 (GDK_WINDOW_XWINDOW (context->dest_window) == dest_xid))))
185 tmp_list = tmp_list->next;
197 GdkDragContext *context;
198 } target_drag_context;
204 GdkDragContext *context;
205 } source_drag_context;
220 static enum_formats *enum_formats_new (void);
222 static ULONG STDMETHODCALLTYPE
223 idroptarget_addref (LPDROPTARGET This)
225 target_drag_context *ctx = (target_drag_context *) This;
226 GdkDragContextPrivate *private = (GdkDragContextPrivate *) ctx->context;
228 gdk_drag_context_ref (ctx->context);
229 GDK_NOTE (DND, g_print ("idroptarget_addref %#x %d\n",
230 This, private->ref_count));
232 return private->ref_count;
235 static HRESULT STDMETHODCALLTYPE
236 idroptarget_queryinterface (LPDROPTARGET This,
240 GDK_NOTE (DND, g_print ("idroptarget_queryinterface %#x\n", This));
246 if (IsEqualGUID (riid, &IID_IUnknown))
248 g_print ("...IUnknown\n");
249 idroptarget_addref (This);
253 else if (IsEqualGUID (riid, &IID_IDropTarget))
255 g_print ("...IDropTarget\n");
256 idroptarget_addref (This);
262 g_print ("...Huh?\n");
263 return E_NOINTERFACE;
267 static ULONG STDMETHODCALLTYPE
268 idroptarget_release (LPDROPTARGET This)
270 target_drag_context *ctx = (target_drag_context *) This;
271 GdkDragContextPrivate *private = (GdkDragContextPrivate *) ctx->context;
272 int ref_count = private->ref_count - 1;
274 gdk_drag_context_unref (ctx->context);
275 GDK_NOTE (DND, g_print ("idroptarget_release %#x %d\n",
284 static HRESULT STDMETHODCALLTYPE
285 idroptarget_dragenter (LPDROPTARGET This,
286 LPDATAOBJECT pDataObj,
291 GDK_NOTE (DND, g_print ("idroptarget_dragenter %#x\n", This));
296 static HRESULT STDMETHODCALLTYPE
297 idroptarget_dragover (LPDROPTARGET This,
302 GDK_NOTE (DND, g_print ("idroptarget_dragover %#x\n", This));
307 static HRESULT STDMETHODCALLTYPE
308 idroptarget_dragleave (LPDROPTARGET This)
310 GDK_NOTE (DND, g_print ("idroptarget_dragleave %#x\n", This));
315 static HRESULT STDMETHODCALLTYPE
316 idroptarget_drop (LPDROPTARGET This,
317 LPDATAOBJECT pDataObj,
322 GDK_NOTE (DND, g_print ("idroptarget_drop %#x\n", This));
327 static ULONG STDMETHODCALLTYPE
328 idropsource_addref (LPDROPSOURCE This)
330 source_drag_context *ctx = (source_drag_context *) This;
331 GdkDragContextPrivate *private = (GdkDragContextPrivate *) ctx->context;
333 gdk_drag_context_ref (ctx->context);
334 GDK_NOTE (DND, g_print ("idropsource_addref %#x %d\n",
335 This, private->ref_count));
337 return private->ref_count;
340 static HRESULT STDMETHODCALLTYPE
341 idropsource_queryinterface (LPDROPSOURCE This,
345 GDK_NOTE (DND, g_print ("idropsource_queryinterface %#x\n", This));
350 if (IsEqualGUID (riid, &IID_IUnknown))
352 g_print ("...IUnknown\n");
353 idropsource_addref (This);
357 else if (IsEqualGUID (riid, &IID_IDropSource))
359 g_print ("...IDropSource\n");
360 idropsource_addref (This);
366 g_print ("...Huh?\n");
367 return E_NOINTERFACE;
371 static ULONG STDMETHODCALLTYPE
372 idropsource_release (LPDROPSOURCE This)
374 source_drag_context *ctx = (source_drag_context *) This;
375 GdkDragContextPrivate *private = (GdkDragContextPrivate *) ctx->context;
376 int ref_count = private->ref_count - 1;
378 gdk_drag_context_unref (ctx->context);
379 GDK_NOTE (DND, g_print ("idropsource_release %#x %d\n",
388 static HRESULT STDMETHODCALLTYPE
389 idropsource_querycontinuedrag (LPDROPSOURCE This,
393 GDK_NOTE (DND, g_print ("idropsource_querycontinuedrag %#x\n", This));
398 static HRESULT STDMETHODCALLTYPE
399 idropsource_givefeedback (LPDROPSOURCE This,
402 GDK_NOTE (DND, g_print ("idropsource_givefeedback %#x\n", This));
407 static ULONG STDMETHODCALLTYPE
408 idataobject_addref (LPDATAOBJECT This)
410 data_object *dobj = (data_object *) This;
411 int ref_count = ++dobj->ref_count;
413 GDK_NOTE (DND, g_print ("idataobject_addref %#x %d\n", This, ref_count));
418 static HRESULT STDMETHODCALLTYPE
419 idataobject_queryinterface (LPDATAOBJECT This,
423 GDK_NOTE (DND, g_print ("idataobject_queryinterface %#x\n", This));
428 if (IsEqualGUID (riid, &IID_IUnknown))
430 g_print ("...IUnknown\n");
431 idataobject_addref (This);
435 else if (IsEqualGUID (riid, &IID_IDataObject))
437 g_print ("...IDataObject\n");
438 idataobject_addref (This);
444 g_print ("...Huh?\n");
445 return E_NOINTERFACE;
449 static ULONG STDMETHODCALLTYPE
450 idataobject_release (LPDATAOBJECT This)
452 data_object *dobj = (data_object *) This;
453 int ref_count = --dobj->ref_count;
455 GDK_NOTE (DND, g_print ("idataobject_release %#x %d\n", This, ref_count));
463 static HRESULT STDMETHODCALLTYPE
464 idataobject_getdata (LPDATAOBJECT This,
465 LPFORMATETC pFormatEtc,
468 GDK_NOTE (DND, g_print ("idataobject_getdata %#x\n", This));
473 static HRESULT STDMETHODCALLTYPE
474 idataobject_getdatahere (LPDATAOBJECT This,
475 LPFORMATETC pFormatEtc,
478 GDK_NOTE (DND, g_print ("idataobject_getdatahere %#x\n", This));
483 static HRESULT STDMETHODCALLTYPE
484 idataobject_querygetdata (LPDATAOBJECT This,
485 LPFORMATETC pFormatEtc)
489 GDK_NOTE (DND, g_print ("idataobject_querygetdata %#x %#x", This, pFormatEtc->cfFormat));
491 for (i = 0; i < nformats; i++)
492 if (pFormatEtc->cfFormat == formats[i].cfFormat)
494 GDK_NOTE (DND, g_print (" S_OK\n"));
498 GDK_NOTE (DND, g_print (" DV_E_FORMATETC\n"));
499 return DV_E_FORMATETC;
502 static HRESULT STDMETHODCALLTYPE
503 idataobject_getcanonicalformatetc (LPDATAOBJECT This,
504 LPFORMATETC pFormatEtcIn,
505 LPFORMATETC pFormatEtcOut)
507 GDK_NOTE (DND, g_print ("idataobject_getcanonicalformatetc %#x\n", This));
512 static HRESULT STDMETHODCALLTYPE
513 idataobject_setdata (LPDATAOBJECT This,
514 LPFORMATETC pFormatEtc,
518 GDK_NOTE (DND, g_print ("idataobject_setdata %#x\n", This));
523 static HRESULT STDMETHODCALLTYPE
524 idataobject_enumformatetc (LPDATAOBJECT This,
526 LPENUMFORMATETC *ppEnumFormatEtc)
528 GDK_NOTE (DND, g_print ("idataobject_enumformatetc %#x\n", This));
530 if (dwDirection != DATADIR_GET)
533 *ppEnumFormatEtc = &enum_formats_new ()->ief;
537 static HRESULT STDMETHODCALLTYPE
538 idataobject_dadvise (LPDATAOBJECT This,
539 LPFORMATETC pFormatetc,
541 LPADVISESINK pAdvSink,
542 DWORD *pdwConnection)
544 GDK_NOTE (DND, g_print ("idataobject_dadvise %#x\n", This));
549 static HRESULT STDMETHODCALLTYPE
550 idataobject_dunadvise (LPDATAOBJECT This,
553 GDK_NOTE (DND, g_print ("idataobject_dunadvise %#x\n", This));
558 static HRESULT STDMETHODCALLTYPE
559 idataobject_enumdadvise (LPDATAOBJECT This,
560 LPENUMSTATDATA *ppenumAdvise)
562 GDK_NOTE (DND, g_print ("idataobject_enumdadvise %#x\n", This));
567 static ULONG STDMETHODCALLTYPE
568 ienumformatetc_addref (LPENUMFORMATETC This)
570 enum_formats *en = (enum_formats *) This;
571 int ref_count = ++en->ref_count;
573 GDK_NOTE (DND, g_print ("ienumformatetc_addref %#x %d\n", This, ref_count));
578 static HRESULT STDMETHODCALLTYPE
579 ienumformatetc_queryinterface (LPENUMFORMATETC This,
583 GDK_NOTE (DND, g_print ("ienumformatetc_queryinterface %#x\n", This));
588 if (IsEqualGUID (riid, &IID_IUnknown))
590 g_print ("...IUnknown\n");
591 ienumformatetc_addref (This);
595 else if (IsEqualGUID (riid, &IID_IEnumFORMATETC))
597 g_print ("...IEnumFORMATETC\n");
598 ienumformatetc_addref (This);
604 g_print ("...Huh?\n");
605 return E_NOINTERFACE;
609 static ULONG STDMETHODCALLTYPE
610 ienumformatetc_release (LPENUMFORMATETC This)
612 enum_formats *en = (enum_formats *) This;
613 int ref_count = --en->ref_count;
615 GDK_NOTE (DND, g_print ("ienumformatetc_release %#x %d\n", This, ref_count));
623 static HRESULT STDMETHODCALLTYPE
624 ienumformatetc_next (LPENUMFORMATETC This,
629 enum_formats *en = (enum_formats *) This;
632 GDK_NOTE (DND, g_print ("ienumformatetc_next %#x %d %d\n", This, en->ix, celt));
635 for (i = 0; i < celt; i++)
637 if (en->ix >= nformats)
639 elts[i] = formats[en->ix++];
652 static HRESULT STDMETHODCALLTYPE
653 ienumformatetc_skip (LPENUMFORMATETC This,
656 enum_formats *en = (enum_formats *) This;
658 GDK_NOTE (DND, g_print ("ienumformatetc_skip %#x %d %d\n", This, en->ix, celt));
664 static HRESULT STDMETHODCALLTYPE
665 ienumformatetc_reset (LPENUMFORMATETC This)
667 enum_formats *en = (enum_formats *) This;
669 GDK_NOTE (DND, g_print ("ienumformatetc_reset %#x\n", This));
676 static HRESULT STDMETHODCALLTYPE
677 ienumformatetc_clone (LPENUMFORMATETC This,
678 LPENUMFORMATETC *ppEnumFormatEtc)
680 enum_formats *en = (enum_formats *) This;
683 GDK_NOTE (DND, g_print ("ienumformatetc_clone %#x\n", This));
685 new = enum_formats_new ();
689 *ppEnumFormatEtc = &new->ief;
694 static IDropTargetVtbl idt_vtbl = {
695 idroptarget_queryinterface,
698 idroptarget_dragenter,
699 idroptarget_dragover,
700 idroptarget_dragleave,
704 static IDropSourceVtbl ids_vtbl = {
705 idropsource_queryinterface,
708 idropsource_querycontinuedrag,
709 idropsource_givefeedback
712 static IDataObjectVtbl ido_vtbl = {
713 idataobject_queryinterface,
717 idataobject_getdatahere,
718 idataobject_querygetdata,
719 idataobject_getcanonicalformatetc,
721 idataobject_enumformatetc,
723 idataobject_dunadvise,
724 idataobject_enumdadvise
727 static IEnumFORMATETCVtbl ief_vtbl = {
728 ienumformatetc_queryinterface,
729 ienumformatetc_addref,
730 ienumformatetc_release,
733 ienumformatetc_reset,
737 #endif /* OLE2_DND */
739 static target_drag_context *
740 target_context_new (void)
742 target_drag_context *result;
744 result = g_new0 (target_drag_context, 1);
747 result->idt.lpVtbl = &idt_vtbl;
750 result->context = gdk_drag_context_new ();
751 result->context->is_source = FALSE;
753 GDK_NOTE (DND, g_print ("target_context_new: %#x\n", result));
758 static source_drag_context *
759 source_context_new (void)
761 source_drag_context *result;
763 result = g_new0 (source_drag_context, 1);
766 result->ids.lpVtbl = &ids_vtbl;
769 result->context = gdk_drag_context_new ();
770 result->context->is_source = TRUE;
772 GDK_NOTE (DND, g_print ("source_context_new: %#x\n", result));
779 data_object_new (void)
783 result = g_new0 (data_object, 1);
785 result->ido.lpVtbl = &ido_vtbl;
786 result->ref_count = 1;
788 GDK_NOTE (DND, g_print ("data_object_new: %#x\n", result));
794 static enum_formats *
795 enum_formats_new (void)
797 enum_formats *result;
799 result = g_new0 (enum_formats, 1);
801 result->ief.lpVtbl = &ief_vtbl;
802 result->ref_count = 1;
805 GDK_NOTE (DND, g_print ("enum_formats_new: %#x\n", result));
812 /* From MS Knowledge Base article Q130698 */
814 /* resolve_link() fills the filename and path buffer
815 * with relevant information
816 * hWnd - calling app's window handle.
818 * lpszLinkName - name of the link file passed into the function.
820 * lpszPath - the buffer that will receive the file pathname.
824 resolve_link(HWND hWnd,
825 LPCTSTR lpszLinkName,
827 LPSTR lpszDescription)
833 /* Assume Failure to start with: */
836 *lpszDescription = 0;
838 /* Call CoCreateInstance to obtain the IShellLink interface
839 * pointer. This call fails if CoInitialize is not called, so it is
840 * assumed that CoInitialize has been called.
843 hres = CoCreateInstance (&CLSID_ShellLink,
845 CLSCTX_INPROC_SERVER,
848 if (SUCCEEDED (hres))
852 /* The IShellLink interface supports the IPersistFile
853 * interface. Get an interface pointer to it.
855 hres = psl->lpVtbl->QueryInterface (psl,
858 if (SUCCEEDED (hres))
862 /* Convert the given link name string to wide character string. */
863 MultiByteToWideChar (CP_ACP, 0,
867 hres = ppf->lpVtbl->Load (ppf, wsz, STGM_READ);
868 if (SUCCEEDED (hres))
870 /* Resolve the link by calling the Resolve()
871 * interface function.
873 hres = psl->lpVtbl->Resolve(psl, hWnd,
876 if (SUCCEEDED (hres))
878 hres = psl->lpVtbl->GetPath (psl, lpszPath,
880 (WIN32_FIND_DATA*)&wfd,
883 if (SUCCEEDED (hres) && lpszDescription != NULL)
885 hres = psl->lpVtbl->GetDescription (psl,
889 if (!SUCCEEDED (hres))
894 ppf->lpVtbl->Release (ppf);
896 psl->lpVtbl->Release (psl);
898 return SUCCEEDED (hres);
901 static GdkFilterReturn
902 gdk_dropfiles_filter (GdkXEvent *xev,
906 GdkDragContext *context;
907 GdkDragContextPrivate *private;
908 static GdkAtom text_uri_list_atom = GDK_NONE;
910 MSG *msg = (MSG *) xev;
914 guchar fileName[MAX_PATH], linkedFile[MAX_PATH];
916 if (text_uri_list_atom == GDK_NONE)
917 text_uri_list_atom = gdk_atom_intern ("text/uri-list", FALSE);
919 if (msg->message == WM_DROPFILES)
921 GDK_NOTE (DND, g_print ("WM_DROPFILES: %#x\n", msg->hwnd));
923 context = gdk_drag_context_new ();
924 private = (GdkDragContextPrivate *) context;
925 context->protocol = GDK_DRAG_PROTO_WIN32_DROPFILES;
926 context->is_source = FALSE;
927 context->source_window = gdk_parent_root;
928 context->dest_window = event->any.window;
929 gdk_drawable_ref (context->dest_window);
930 /* WM_DROPFILES drops are always file names */
932 g_list_append (NULL, GUINT_TO_POINTER (text_uri_list_atom));
933 current_dest_drag = context;
935 event->dnd.type = GDK_DROP_START;
936 event->dnd.context = current_dest_drag;
937 gdk_drag_context_ref (current_dest_drag);
939 hdrop = (HANDLE) msg->wParam;
940 DragQueryPoint (hdrop, &pt);
941 ClientToScreen (msg->hwnd, &pt);
943 event->dnd.x_root = pt.x;
944 event->dnd.y_root = pt.y;
945 event->dnd.time = msg->time;
947 nfiles = DragQueryFile (hdrop, 0xFFFFFFFF, NULL, 0);
949 result = g_string_new (NULL);
950 for (i = 0; i < nfiles; i++)
952 g_string_append (result, "file:");
953 DragQueryFile (hdrop, i, fileName, MAX_PATH);
955 /* Resolve shortcuts */
956 if (resolve_link (msg->hwnd, fileName, linkedFile, NULL))
958 g_string_append (result, linkedFile);
959 GDK_NOTE (DND, g_print ("...%s link to %s\n",
960 fileName, linkedFile));
964 g_string_append (result, fileName);
965 GDK_NOTE (DND, g_print ("...%s\n", fileName));
967 g_string_append (result, "\015\012");
969 gdk_sel_prop_store (gdk_parent_root, text_uri_list_atom, 8,
970 result->str, result->len + 1);
974 return GDK_FILTER_TRANSLATE;
977 return GDK_FILTER_CONTINUE;
980 /*************************************************************
981 ************************** Public API ***********************
982 *************************************************************/
989 hres = OleInitialize (NULL);
991 if (! SUCCEEDED (hres))
992 g_error ("OleInitialize failed");
995 formats = g_new (FORMATETC, nformats);
997 formats[0].cfFormat = CF_TEXT;
998 formats[0].ptd = NULL;
999 formats[0].dwAspect = DVASPECT_CONTENT;
1000 formats[0].lindex = -1;
1001 formats[0].tymed = TYMED_HGLOBAL;
1003 formats[1].cfFormat = CF_GDIOBJFIRST;
1004 formats[1].ptd = NULL;
1005 formats[1].dwAspect = DVASPECT_CONTENT;
1006 formats[1].lindex = -1;
1007 formats[1].tymed = TYMED_HGLOBAL;
1012 gdk_win32_dnd_exit (void)
1022 gdk_drag_do_leave (GdkDragContext *context,
1025 if (context->dest_window)
1027 GDK_NOTE (DND, g_print ("gdk_drag_do_leave\n"));
1028 gdk_drawable_unref (context->dest_window);
1029 context->dest_window = NULL;
1034 gdk_drag_begin (GdkWindow *window,
1038 source_drag_context *ctx;
1048 g_return_val_if_fail (window != NULL, NULL);
1050 GDK_NOTE (DND, g_print ("gdk_drag_begin\n"));
1052 ctx = source_context_new ();
1053 ctx->context->protocol = GDK_DRAG_PROTO_OLE2;
1054 ctx->context->source_window = window;
1055 gdk_drawable_ref (window);
1058 tmp_list = g_list_last (targets);
1059 ctx->context->targets = NULL;
1062 ctx->context->targets = g_list_prepend (ctx->context->targets,
1064 tmp_list = tmp_list->prev;
1067 ctx->context->actions = 0;
1069 dobj = data_object_new ();
1071 global = GlobalAlloc (GMEM_FIXED, sizeof (ctx));
1073 memcpy (&global, ctx, sizeof (ctx));
1075 medium.tymed = TYMED_HGLOBAL;
1076 medium.hGlobal = global;
1077 medium.pUnkForRelease = NULL;
1079 dobj->ido.lpVtbl->SetData (&dobj->ido, &formats[1], &medium, TRUE);
1081 hResult = DoDragDrop (&dobj->ido, &ctx->ids, DROPEFFECT_MOVE|DROPEFFECT_COPY, &dwEffect);
1083 GDK_NOTE (DND, g_print ("DoDragDrop returned %s\n",
1084 (hResult == DRAGDROP_S_DROP ? "DRAGDROP_S_DROP" :
1085 (hResult == DRAGDROP_S_CANCEL ? "DRAGDROP_S_CANCEL" :
1086 (hResult == E_UNEXPECTED ? "E_UNEXPECTED" :
1087 g_strdup_printf ("%#.8x", hResult))))));
1089 dobj->ido.lpVtbl->Release (&dobj->ido);
1090 ctx->ids.lpVtbl->Release (&ctx->ids);
1092 return ctx->context;
1096 gdk_drag_get_protocol (guint32 xid,
1097 GdkDragProtocol *protocol)
1099 /* This isn't used */
1104 gdk_drag_find_window (GdkDragContext *context,
1105 GdkWindow *drag_window,
1108 GdkWindow **dest_window,
1109 GdkDragProtocol *protocol)
1111 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
1115 GDK_NOTE (DND, g_print ("gdk_drag_find_window: %#x +%d+%d\n",
1116 (drag_window ? GDK_DRAWABLE_XID (drag_window) : 0),
1121 recipient = WindowFromPoint (pt);
1122 if (recipient == NULL)
1123 *dest_window = NULL;
1126 *dest_window = gdk_window_lookup (recipient);
1128 gdk_drawable_ref (*dest_window);
1129 *protocol = GDK_DRAG_PROTO_WIN32_DROPFILES;
1134 gdk_drag_motion (GdkDragContext *context,
1135 GdkWindow *dest_window,
1136 GdkDragProtocol protocol,
1139 GdkDragAction suggested_action,
1140 GdkDragAction possible_actions,
1143 GDK_NOTE (DND, g_print ("gdk_drag_motion\n"));
1149 gdk_drag_drop (GdkDragContext *context,
1152 g_return_if_fail (context != NULL);
1154 GDK_NOTE (DND, g_print ("gdk_drag_drop\n"));
1158 gdk_drag_abort (GdkDragContext *context,
1161 g_return_if_fail (context != NULL);
1163 GDK_NOTE (DND, g_print ("gdk_drag_abort\n"));
1165 gdk_drag_do_leave (context, time);
1168 /* Destination side */
1171 gdk_drag_status (GdkDragContext *context,
1172 GdkDragAction action,
1175 GDK_NOTE (DND, g_print ("gdk_drag_status\n"));
1179 gdk_drop_reply (GdkDragContext *context,
1183 GDK_NOTE (DND, g_print ("gdk_drop_reply\n"));
1187 gdk_drop_finish (GdkDragContext *context,
1191 GDK_NOTE (DND, g_print ("gdk_drop_finish\n"));
1194 static GdkFilterReturn
1195 gdk_destroy_filter (GdkXEvent *xev,
1200 MSG *msg = (MSG *) xev;
1202 if (msg->message == WM_DESTROY)
1204 IDropTarget *idtp = (IDropTarget *) data;
1206 GDK_NOTE (DND, g_print ("gdk_destroy_filter: WM_DESTROY: %#x\n", msg->hwnd));
1208 idtp->lpVtbl->Release (idtp);
1210 RevokeDragDrop (msg->hwnd);
1211 CoLockObjectExternal (idtp, FALSE, TRUE);
1214 return GDK_FILTER_CONTINUE;
1218 gdk_window_register_dnd (GdkWindow *window)
1221 target_drag_context *ctx;
1225 g_return_if_fail (window != NULL);
1227 GDK_NOTE (DND, g_print ("gdk_window_register_dnd: %#x\n",
1228 GDK_DRAWABLE_XID (window)));
1230 /* We always claim to accept dropped files, but in fact we might not,
1231 * of course. This function is called in such a way that it cannot know
1232 * whether the window (widget) in question actually accepts files
1233 * (in gtk, data of type text/uri-list) or not.
1235 gdk_window_add_filter (window, gdk_dropfiles_filter, NULL);
1236 DragAcceptFiles (GDK_WINDOW_HWND (window), TRUE);
1239 /* Register for OLE2 d&d */
1240 ctx = target_context_new ();
1241 ctx->context->protocol = GDK_DRAG_PROTO_OLE2;
1242 hres = CoLockObjectExternal ((IUnknown *) &ctx->idt, TRUE, FALSE);
1243 if (!SUCCEEDED (hres))
1244 OTHER_API_FAILED ("CoLockObjectExternal");
1247 hres = RegisterDragDrop (GDK_DRAWABLE_XID (window), &ctx->idt);
1248 if (hres == DRAGDROP_E_ALREADYREGISTERED)
1250 g_print ("DRAGDROP_E_ALREADYREGISTERED\n");
1252 ctx->idt.lpVtbl->Release (&ctx->idt);
1254 CoLockObjectExternal ((IUnknown *) &ctx->idt, FALSE, FALSE);
1256 else if (!SUCCEEDED (hres))
1257 OTHER_API_FAILED ("RegisterDragDrop");
1260 gdk_window_add_filter (window, gdk_destroy_filter, &ctx->idt);
1266 /*************************************************************
1267 * gdk_drag_get_selection:
1268 * Returns the selection atom for the current source window
1272 *************************************************************/
1275 gdk_drag_get_selection (GdkDragContext *context)
1277 if (context->protocol == GDK_DRAG_PROTO_WIN32_DROPFILES)
1278 return gdk_win32_dropfiles_atom;
1279 else if (context->protocol == GDK_DRAG_PROTO_OLE2)
1280 return gdk_ole2_dnd_atom;