ws2_32/tests: Add UDP select() test for unbound socket.
[wine/multimedia.git] / dlls / winex11.drv / xdnd.c
blobf6ce5e9d85c2244e174ef6f87f6256ea256408ec
1 /*
2 * XDND handler code
4 * Copyright 2003 Ulrich Czekalla
5 * Copyright 2007 Damjan Jovanovic
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <string.h>
26 #ifdef HAVE_UNISTD_H
27 # include <unistd.h>
28 #endif
29 #include <stdarg.h>
30 #include <stdio.h>
32 #define NONAMELESSUNION
34 #include "windef.h"
35 #include "winbase.h"
36 #include "wingdi.h"
37 #include "winuser.h"
39 #define COBJMACROS
40 #include "x11drv.h"
41 #include "shellapi.h"
42 #include "shlobj.h" /* DROPFILES */
43 #include "oleidl.h"
44 #include "objidl.h"
46 #include "wine/unicode.h"
47 #include "wine/debug.h"
48 #include "wine/list.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(xdnd);
52 /* Maximum wait time for selection notify */
53 #define SELECTION_RETRIES 500 /* wait for .1 seconds */
54 #define SELECTION_WAIT 1000 /* us */
56 typedef struct tagXDNDDATA
58 int cf_win;
59 Atom cf_xdnd;
60 HANDLE contents;
61 struct list entry;
62 } XDNDDATA, *LPXDNDDATA;
64 static struct list xdndData = LIST_INIT(xdndData);
65 static POINT XDNDxy = { 0, 0 };
66 static IDataObject XDNDDataObject;
67 static BOOL XDNDAccepted = FALSE;
68 static DWORD XDNDDropEffect = DROPEFFECT_NONE;
69 /* the last window the mouse was over */
70 static HWND XDNDLastTargetWnd;
71 /* might be an ancestor of XDNDLastTargetWnd */
72 static HWND XDNDLastDropTargetWnd;
74 static void X11DRV_XDND_InsertXDNDData(int property, int format, HANDLE contents);
75 static void X11DRV_XDND_ResolveProperty(Display *display, Window xwin, Time tm,
76 Atom *types, unsigned long count);
77 static void X11DRV_XDND_SendDropFiles(HWND hwnd);
78 static void X11DRV_XDND_FreeDragDropOp(void);
80 static CRITICAL_SECTION xdnd_cs;
81 static CRITICAL_SECTION_DEBUG critsect_debug =
83 0, 0, &xdnd_cs,
84 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
85 0, 0, { (DWORD_PTR)(__FILE__ ": xdnd_cs") }
87 static CRITICAL_SECTION xdnd_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
90 /* Based on functions in dlls/ole32/ole2.c */
91 static HANDLE get_droptarget_local_handle(HWND hwnd)
93 static const WCHAR prop_marshalleddroptarget[] =
94 {'W','i','n','e','M','a','r','s','h','a','l','l','e','d','D','r','o','p','T','a','r','g','e','t',0};
95 HANDLE handle;
96 HANDLE local_handle = 0;
98 handle = GetPropW(hwnd, prop_marshalleddroptarget);
99 if (handle)
101 DWORD pid;
102 HANDLE process;
104 GetWindowThreadProcessId(hwnd, &pid);
105 process = OpenProcess(PROCESS_DUP_HANDLE, FALSE, pid);
106 if (process)
108 DuplicateHandle(process, handle, GetCurrentProcess(), &local_handle, 0, FALSE, DUPLICATE_SAME_ACCESS);
109 CloseHandle(process);
112 return local_handle;
115 static HRESULT create_stream_from_map(HANDLE map, IStream **stream)
117 HRESULT hr = E_OUTOFMEMORY;
118 HGLOBAL hmem;
119 void *data;
120 MEMORY_BASIC_INFORMATION info;
122 data = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0);
123 if(!data) return hr;
125 VirtualQuery(data, &info, sizeof(info));
126 TRACE("size %d\n", (int)info.RegionSize);
128 hmem = GlobalAlloc(GMEM_MOVEABLE, info.RegionSize);
129 if(hmem)
131 memcpy(GlobalLock(hmem), data, info.RegionSize);
132 GlobalUnlock(hmem);
133 hr = CreateStreamOnHGlobal(hmem, TRUE, stream);
135 UnmapViewOfFile(data);
136 return hr;
139 static IDropTarget* get_droptarget_pointer(HWND hwnd)
141 IDropTarget *droptarget = NULL;
142 HANDLE map;
143 IStream *stream;
145 map = get_droptarget_local_handle(hwnd);
146 if(!map) return NULL;
148 if(SUCCEEDED(create_stream_from_map(map, &stream)))
150 CoUnmarshalInterface(stream, &IID_IDropTarget, (void**)&droptarget);
151 IStream_Release(stream);
153 CloseHandle(map);
154 return droptarget;
157 /**************************************************************************
158 * X11DRV_XDND_XdndActionToDROPEFFECT
160 static DWORD X11DRV_XDND_XdndActionToDROPEFFECT(long action)
162 /* In Windows, nothing but the given effects is allowed.
163 * In X the given action is just a hint, and you can always
164 * XdndActionCopy and XdndActionPrivate, so be more permissive. */
165 if (action == x11drv_atom(XdndActionCopy))
166 return DROPEFFECT_COPY;
167 else if (action == x11drv_atom(XdndActionMove))
168 return DROPEFFECT_MOVE | DROPEFFECT_COPY;
169 else if (action == x11drv_atom(XdndActionLink))
170 return DROPEFFECT_LINK | DROPEFFECT_COPY;
171 else if (action == x11drv_atom(XdndActionAsk))
172 /* FIXME: should we somehow ask the user what to do here? */
173 return DROPEFFECT_COPY | DROPEFFECT_MOVE | DROPEFFECT_LINK;
174 FIXME("unknown action %ld, assuming DROPEFFECT_COPY\n", action);
175 return DROPEFFECT_COPY;
178 /**************************************************************************
179 * X11DRV_XDND_DROPEFFECTToXdndAction
181 static long X11DRV_XDND_DROPEFFECTToXdndAction(DWORD effect)
183 if (effect == DROPEFFECT_COPY)
184 return x11drv_atom(XdndActionCopy);
185 else if (effect == DROPEFFECT_MOVE)
186 return x11drv_atom(XdndActionMove);
187 else if (effect == DROPEFFECT_LINK)
188 return x11drv_atom(XdndActionLink);
189 FIXME("unknown drop effect %u, assuming XdndActionCopy\n", effect);
190 return x11drv_atom(XdndActionCopy);
193 /**************************************************************************
194 * X11DRV_XDND_EnterEvent
196 * Handle an XdndEnter event.
198 void X11DRV_XDND_EnterEvent( HWND hWnd, XClientMessageEvent *event )
200 int version;
201 Atom *xdndtypes;
202 unsigned long count = 0;
204 version = (event->data.l[1] & 0xFF000000) >> 24;
205 TRACE("ver(%d) check-XdndTypeList(%ld) data=%ld,%ld,%ld,%ld,%ld\n",
206 version, (event->data.l[1] & 1),
207 event->data.l[0], event->data.l[1], event->data.l[2],
208 event->data.l[3], event->data.l[4]);
210 if (version > WINE_XDND_VERSION)
212 TRACE("Ignores unsupported version\n");
213 return;
216 XDNDAccepted = FALSE;
218 /* If the source supports more than 3 data types we retrieve
219 * the entire list. */
220 if (event->data.l[1] & 1)
222 Atom acttype;
223 int actfmt;
224 unsigned long bytesret;
226 /* Request supported formats from source window */
227 XGetWindowProperty(event->display, event->data.l[0], x11drv_atom(XdndTypeList),
228 0, 65535, FALSE, AnyPropertyType, &acttype, &actfmt, &count,
229 &bytesret, (unsigned char**)&xdndtypes);
231 else
233 count = 3;
234 xdndtypes = (Atom*) &event->data.l[2];
237 if (TRACE_ON(xdnd))
239 unsigned int i;
241 for (i = 0; i < count; i++)
243 if (xdndtypes[i] != 0)
245 char * pn = XGetAtomName(event->display, xdndtypes[i]);
246 TRACE("XDNDEnterAtom %ld: %s\n", xdndtypes[i], pn);
247 XFree(pn);
252 /* Do a one-time data read and cache results */
253 X11DRV_XDND_ResolveProperty(event->display, event->window,
254 event->data.l[1], xdndtypes, count);
256 if (event->data.l[1] & 1)
257 XFree(xdndtypes);
260 /**************************************************************************
261 * X11DRV_XDND_PositionEvent
263 * Handle an XdndPosition event.
265 void X11DRV_XDND_PositionEvent( HWND hWnd, XClientMessageEvent *event )
267 XClientMessageEvent e;
268 int accept = 0; /* Assume we're not accepting */
269 IDropTarget *dropTarget = NULL;
270 DWORD effect;
271 POINTL pointl;
272 HWND targetWindow;
273 HRESULT hr;
275 XDNDxy = root_to_virtual_screen( event->data.l[2] >> 16, event->data.l[2] & 0xFFFF );
276 targetWindow = WindowFromPoint(XDNDxy);
278 pointl.x = XDNDxy.x;
279 pointl.y = XDNDxy.y;
280 effect = X11DRV_XDND_XdndActionToDROPEFFECT(event->data.l[4]);
282 if (!XDNDAccepted || XDNDLastTargetWnd != targetWindow)
284 /* Notify OLE of DragEnter. Result determines if we accept */
285 HWND dropTargetWindow;
287 if (XDNDLastDropTargetWnd)
289 dropTarget = get_droptarget_pointer(XDNDLastDropTargetWnd);
290 if (dropTarget)
292 hr = IDropTarget_DragLeave(dropTarget);
293 if (FAILED(hr))
294 WARN("IDropTarget_DragLeave failed, error 0x%08X\n", hr);
295 IDropTarget_Release(dropTarget);
298 dropTargetWindow = targetWindow;
301 dropTarget = get_droptarget_pointer(dropTargetWindow);
302 } while (dropTarget == NULL && (dropTargetWindow = GetParent(dropTargetWindow)) != NULL);
303 XDNDLastTargetWnd = targetWindow;
304 XDNDLastDropTargetWnd = dropTargetWindow;
305 if (dropTarget)
307 hr = IDropTarget_DragEnter(dropTarget, &XDNDDataObject,
308 MK_LBUTTON, pointl, &effect);
309 if (SUCCEEDED(hr))
311 if (effect != DROPEFFECT_NONE)
313 XDNDAccepted = TRUE;
314 TRACE("the application accepted the drop\n");
316 else
317 TRACE("the application refused the drop\n");
319 else
320 WARN("IDropTarget_DragEnter failed, error 0x%08X\n", hr);
321 IDropTarget_Release(dropTarget);
324 if (XDNDAccepted && XDNDLastTargetWnd == targetWindow)
326 /* If drag accepted notify OLE of DragOver */
327 dropTarget = get_droptarget_pointer(XDNDLastDropTargetWnd);
328 if (dropTarget)
330 hr = IDropTarget_DragOver(dropTarget, MK_LBUTTON, pointl, &effect);
331 if (SUCCEEDED(hr))
332 XDNDDropEffect = effect;
333 else
334 WARN("IDropTarget_DragOver failed, error 0x%08X\n", hr);
335 IDropTarget_Release(dropTarget);
339 if (XDNDAccepted)
340 accept = 1;
341 if (GetWindowLongW( hWnd, GWL_EXSTYLE ) & WS_EX_ACCEPTFILES)
342 accept = 1;
344 TRACE("action req: %ld accept(%d) at x(%d),y(%d)\n",
345 event->data.l[4], accept, XDNDxy.x, XDNDxy.y);
348 * Let source know if we're accepting the drop by
349 * sending a status message.
351 e.type = ClientMessage;
352 e.display = event->display;
353 e.window = event->data.l[0];
354 e.message_type = x11drv_atom(XdndStatus);
355 e.format = 32;
356 e.data.l[0] = event->window;
357 e.data.l[1] = accept;
358 e.data.l[2] = 0; /* Empty Rect */
359 e.data.l[3] = 0; /* Empty Rect */
360 if (accept)
361 e.data.l[4] = X11DRV_XDND_DROPEFFECTToXdndAction(effect);
362 else
363 e.data.l[4] = None;
364 XSendEvent(event->display, event->data.l[0], False, NoEventMask, (XEvent*)&e);
367 /**************************************************************************
368 * X11DRV_XDND_DropEvent
370 * Handle an XdndDrop event.
372 void X11DRV_XDND_DropEvent( HWND hWnd, XClientMessageEvent *event )
374 XClientMessageEvent e;
375 IDropTarget *dropTarget;
376 DWORD effect = XDNDDropEffect;
377 int accept = 0; /* Assume we're not accepting */
379 TRACE("\n");
381 /* If we have a HDROP type we send a WM_ACCEPTFILES.*/
382 if (GetWindowLongW( hWnd, GWL_EXSTYLE ) & WS_EX_ACCEPTFILES)
383 X11DRV_XDND_SendDropFiles( hWnd );
385 /* Notify OLE of Drop */
386 dropTarget = get_droptarget_pointer(XDNDLastDropTargetWnd);
387 if (dropTarget)
389 HRESULT hr;
390 POINTL pointl;
392 pointl.x = XDNDxy.x;
393 pointl.y = XDNDxy.y;
394 hr = IDropTarget_Drop(dropTarget, &XDNDDataObject, MK_LBUTTON,
395 pointl, &effect);
396 if (SUCCEEDED(hr))
398 if (effect != DROPEFFECT_NONE)
400 TRACE("drop succeeded\n");
401 accept = 1;
403 else
404 TRACE("the application refused the drop\n");
406 else
407 WARN("drop failed, error 0x%08X\n", hr);
408 IDropTarget_Release(dropTarget);
411 X11DRV_XDND_FreeDragDropOp();
413 /* Tell the target we are finished. */
414 memset(&e, 0, sizeof(e));
415 e.type = ClientMessage;
416 e.display = event->display;
417 e.window = event->data.l[0];
418 e.message_type = x11drv_atom(XdndFinished);
419 e.format = 32;
420 e.data.l[0] = event->window;
421 e.data.l[1] = accept;
422 if (accept)
423 e.data.l[2] = X11DRV_XDND_DROPEFFECTToXdndAction(effect);
424 else
425 e.data.l[2] = None;
426 XSendEvent(event->display, event->data.l[0], False, NoEventMask, (XEvent*)&e);
429 /**************************************************************************
430 * X11DRV_XDND_LeaveEvent
432 * Handle an XdndLeave event.
434 void X11DRV_XDND_LeaveEvent( HWND hWnd, XClientMessageEvent *event )
436 IDropTarget *dropTarget;
438 TRACE("DND Operation canceled\n");
440 /* Notify OLE of DragLeave */
441 dropTarget = get_droptarget_pointer(XDNDLastDropTargetWnd);
442 if (dropTarget)
444 HRESULT hr = IDropTarget_DragLeave(dropTarget);
445 if (FAILED(hr))
446 WARN("IDropTarget_DragLeave failed, error 0x%08X\n", hr);
447 IDropTarget_Release(dropTarget);
450 X11DRV_XDND_FreeDragDropOp();
454 /**************************************************************************
455 * X11DRV_XDND_ResolveProperty
457 * Resolve all MIME types to windows clipboard formats. All data is cached.
459 static void X11DRV_XDND_ResolveProperty(Display *display, Window xwin, Time tm,
460 Atom *types, unsigned long count)
462 unsigned int i, j;
463 BOOL res;
464 XEvent xe;
465 XDNDDATA *current, *next;
466 BOOL haveHDROP = FALSE;
468 TRACE("count(%ld)\n", count);
470 X11DRV_XDND_FreeDragDropOp(); /* Clear previously cached data */
472 for (i = 0; i < count; i++)
474 HANDLE contents;
475 UINT windowsFormat;
477 TRACE("requesting atom %ld from xwin %ld\n", types[i], xwin);
479 if (types[i] == 0)
480 continue;
482 XConvertSelection(display, x11drv_atom(XdndSelection), types[i],
483 x11drv_atom(XdndTarget), xwin, /*tm*/CurrentTime);
486 * Wait for SelectionNotify
488 for (j = 0; j < SELECTION_RETRIES; j++)
490 res = XCheckTypedWindowEvent(display, xwin, SelectionNotify, &xe);
491 if (res && xe.xselection.selection == x11drv_atom(XdndSelection)) break;
493 usleep(SELECTION_WAIT);
496 if (xe.xselection.property == None)
497 continue;
499 contents = X11DRV_CLIPBOARD_ImportSelection(display, types[i], xwin, x11drv_atom(XdndTarget), &windowsFormat);
500 if (contents)
501 X11DRV_XDND_InsertXDNDData(types[i], windowsFormat, contents);
504 /* On Windows when there is a CF_HDROP, there are no other CF_ formats.
505 * foobar2000 relies on this (spaces -> %20's without it).
507 LIST_FOR_EACH_ENTRY(current, &xdndData, XDNDDATA, entry)
509 if (current->cf_win == CF_HDROP)
511 haveHDROP = TRUE;
512 break;
515 if (haveHDROP)
517 LIST_FOR_EACH_ENTRY_SAFE(current, next, &xdndData, XDNDDATA, entry)
519 if (current->cf_win != CF_HDROP && current->cf_win < CF_MAX)
521 list_remove(&current->entry);
522 GlobalFree(current->contents);
523 HeapFree(GetProcessHeap(), 0, current);
530 /**************************************************************************
531 * X11DRV_XDND_InsertXDNDData
533 * Cache available XDND property
535 static void X11DRV_XDND_InsertXDNDData(int property, int format, HANDLE contents)
537 LPXDNDDATA current = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(XDNDDATA));
539 if (current)
541 EnterCriticalSection(&xdnd_cs);
542 current->cf_xdnd = property;
543 current->cf_win = format;
544 current->contents = contents;
545 list_add_tail(&xdndData, &current->entry);
546 LeaveCriticalSection(&xdnd_cs);
551 /**************************************************************************
552 * X11DRV_XDND_SendDropFiles
554 static void X11DRV_XDND_SendDropFiles(HWND hwnd)
556 LPXDNDDATA current = NULL;
557 BOOL found = FALSE;
559 EnterCriticalSection(&xdnd_cs);
561 /* Find CF_HDROP type if any */
562 LIST_FOR_EACH_ENTRY(current, &xdndData, XDNDDATA, entry)
564 if (current->cf_win == CF_HDROP)
566 found = TRUE;
567 break;
571 if (found)
573 HGLOBAL dropHandle = GlobalAlloc(GMEM_FIXED, GlobalSize(current->contents));
575 if (dropHandle)
577 DROPFILES *lpDrop = GlobalLock(dropHandle);
578 memcpy(lpDrop, GlobalLock(current->contents), GlobalSize(current->contents));
579 GlobalUnlock(current->contents);
580 lpDrop->pt.x = XDNDxy.x;
581 lpDrop->pt.y = XDNDxy.y;
582 lpDrop->fNC = !ScreenToClient(hwnd, &lpDrop->pt);
583 TRACE("Sending WM_DROPFILES: hWnd=0x%p, fNC=%d, x=%d, y=%d, files=%p(%s)\n", hwnd,
584 lpDrop->fNC, lpDrop->pt.x, lpDrop->pt.y, ((char*)lpDrop) + lpDrop->pFiles,
585 debugstr_w((WCHAR*)(((char*)lpDrop) + lpDrop->pFiles)));
586 GlobalUnlock(dropHandle);
587 if (!PostMessageW(hwnd, WM_DROPFILES, (WPARAM)dropHandle, 0))
588 GlobalFree(dropHandle);
592 LeaveCriticalSection(&xdnd_cs);
596 /**************************************************************************
597 * X11DRV_XDND_FreeDragDropOp
599 static void X11DRV_XDND_FreeDragDropOp(void)
601 LPXDNDDATA next;
602 LPXDNDDATA current;
604 TRACE("\n");
606 EnterCriticalSection(&xdnd_cs);
608 /** Free data cache */
609 LIST_FOR_EACH_ENTRY_SAFE(current, next, &xdndData, XDNDDATA, entry)
611 list_remove(&current->entry);
612 GlobalFree(current->contents);
613 HeapFree(GetProcessHeap(), 0, current);
616 XDNDxy.x = XDNDxy.y = 0;
617 XDNDLastTargetWnd = NULL;
618 XDNDLastDropTargetWnd = NULL;
619 XDNDAccepted = FALSE;
621 LeaveCriticalSection(&xdnd_cs);
625 /**************************************************************************
626 * X11DRV_XDND_DescribeClipboardFormat
628 static void X11DRV_XDND_DescribeClipboardFormat(int cfFormat, char *buffer, int size)
630 #define D(x) case x: lstrcpynA(buffer, #x, size); return;
631 switch (cfFormat)
633 D(CF_TEXT)
634 D(CF_BITMAP)
635 D(CF_METAFILEPICT)
636 D(CF_SYLK)
637 D(CF_DIF)
638 D(CF_TIFF)
639 D(CF_OEMTEXT)
640 D(CF_DIB)
641 D(CF_PALETTE)
642 D(CF_PENDATA)
643 D(CF_RIFF)
644 D(CF_WAVE)
645 D(CF_UNICODETEXT)
646 D(CF_ENHMETAFILE)
647 D(CF_HDROP)
648 D(CF_LOCALE)
649 D(CF_DIBV5)
651 #undef D
653 if (CF_PRIVATEFIRST <= cfFormat && cfFormat <= CF_PRIVATELAST)
655 lstrcpynA(buffer, "some private object", size);
656 return;
658 if (CF_GDIOBJFIRST <= cfFormat && cfFormat <= CF_GDIOBJLAST)
660 lstrcpynA(buffer, "some GDI object", size);
661 return;
664 GetClipboardFormatNameA(cfFormat, buffer, size);
668 /* The IDataObject singleton we feed to OLE follows */
670 static HRESULT WINAPI XDNDDATAOBJECT_QueryInterface(IDataObject *dataObject,
671 REFIID riid, void **ppvObject)
673 TRACE("(%p, %s, %p)\n", dataObject, debugstr_guid(riid), ppvObject);
674 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDataObject))
676 *ppvObject = dataObject;
677 IDataObject_AddRef(dataObject);
678 return S_OK;
680 *ppvObject = NULL;
681 return E_NOINTERFACE;
684 static ULONG WINAPI XDNDDATAOBJECT_AddRef(IDataObject *dataObject)
686 TRACE("(%p)\n", dataObject);
687 return 2;
690 static ULONG WINAPI XDNDDATAOBJECT_Release(IDataObject *dataObject)
692 TRACE("(%p)\n", dataObject);
693 return 1;
696 static HRESULT WINAPI XDNDDATAOBJECT_GetData(IDataObject *dataObject,
697 FORMATETC *formatEtc,
698 STGMEDIUM *pMedium)
700 HRESULT hr;
701 char formatDesc[1024];
703 TRACE("(%p, %p, %p)\n", dataObject, formatEtc, pMedium);
704 X11DRV_XDND_DescribeClipboardFormat(formatEtc->cfFormat,
705 formatDesc, sizeof(formatDesc));
706 TRACE("application is looking for %s\n", formatDesc);
708 hr = IDataObject_QueryGetData(dataObject, formatEtc);
709 if (SUCCEEDED(hr))
711 XDNDDATA *current;
712 LIST_FOR_EACH_ENTRY(current, &xdndData, XDNDDATA, entry)
714 if (current->cf_win == formatEtc->cfFormat)
716 pMedium->tymed = TYMED_HGLOBAL;
717 pMedium->u.hGlobal = GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, GlobalSize(current->contents));
718 if (pMedium->u.hGlobal == NULL)
719 return E_OUTOFMEMORY;
720 memcpy(GlobalLock(pMedium->u.hGlobal), GlobalLock(current->contents), GlobalSize(current->contents));
721 GlobalUnlock(pMedium->u.hGlobal);
722 GlobalUnlock(current->contents);
723 pMedium->pUnkForRelease = 0;
724 return S_OK;
728 return hr;
731 static HRESULT WINAPI XDNDDATAOBJECT_GetDataHere(IDataObject *dataObject,
732 FORMATETC *formatEtc,
733 STGMEDIUM *pMedium)
735 FIXME("(%p, %p, %p): stub\n", dataObject, formatEtc, pMedium);
736 return DATA_E_FORMATETC;
739 static HRESULT WINAPI XDNDDATAOBJECT_QueryGetData(IDataObject *dataObject,
740 FORMATETC *formatEtc)
742 char formatDesc[1024];
743 XDNDDATA *current;
745 TRACE("(%p, %p={.tymed=0x%x, .dwAspect=%d, .cfFormat=%d}\n",
746 dataObject, formatEtc, formatEtc->tymed, formatEtc->dwAspect, formatEtc->cfFormat);
747 X11DRV_XDND_DescribeClipboardFormat(formatEtc->cfFormat, formatDesc, sizeof(formatDesc));
749 if (formatEtc->tymed && !(formatEtc->tymed & TYMED_HGLOBAL))
751 FIXME("only HGLOBAL medium types supported right now\n");
752 return DV_E_TYMED;
754 if (formatEtc->dwAspect != DVASPECT_CONTENT)
756 FIXME("only the content aspect is supported right now\n");
757 return E_NOTIMPL;
760 LIST_FOR_EACH_ENTRY(current, &xdndData, XDNDDATA, entry)
762 if (current->cf_win == formatEtc->cfFormat)
764 TRACE("application found %s\n", formatDesc);
765 return S_OK;
768 TRACE("application didn't find %s\n", formatDesc);
769 return DV_E_FORMATETC;
772 static HRESULT WINAPI XDNDDATAOBJECT_GetCanonicalFormatEtc(IDataObject *dataObject,
773 FORMATETC *formatEtc,
774 FORMATETC *formatEtcOut)
776 FIXME("(%p, %p, %p): stub\n", dataObject, formatEtc, formatEtcOut);
777 formatEtcOut->ptd = NULL;
778 return E_NOTIMPL;
781 static HRESULT WINAPI XDNDDATAOBJECT_SetData(IDataObject *dataObject,
782 FORMATETC *formatEtc,
783 STGMEDIUM *pMedium, BOOL fRelease)
785 FIXME("(%p, %p, %p, %s): stub\n", dataObject, formatEtc,
786 pMedium, fRelease?"TRUE":"FALSE");
787 return E_NOTIMPL;
790 static HRESULT WINAPI XDNDDATAOBJECT_EnumFormatEtc(IDataObject *dataObject,
791 DWORD dwDirection,
792 IEnumFORMATETC **ppEnumFormatEtc)
794 DWORD count;
795 FORMATETC *formats;
797 TRACE("(%p, %u, %p)\n", dataObject, dwDirection, ppEnumFormatEtc);
799 if (dwDirection != DATADIR_GET)
801 FIXME("only the get direction is implemented\n");
802 return E_NOTIMPL;
805 count = list_count(&xdndData);
806 formats = HeapAlloc(GetProcessHeap(), 0, count * sizeof(FORMATETC));
807 if (formats)
809 XDNDDATA *current;
810 DWORD i = 0;
811 HRESULT hr;
812 LIST_FOR_EACH_ENTRY(current, &xdndData, XDNDDATA, entry)
814 formats[i].cfFormat = current->cf_win;
815 formats[i].ptd = NULL;
816 formats[i].dwAspect = DVASPECT_CONTENT;
817 formats[i].lindex = -1;
818 formats[i].tymed = TYMED_HGLOBAL;
819 i++;
821 hr = SHCreateStdEnumFmtEtc(count, formats, ppEnumFormatEtc);
822 HeapFree(GetProcessHeap(), 0, formats);
823 return hr;
825 else
826 return E_OUTOFMEMORY;
829 static HRESULT WINAPI XDNDDATAOBJECT_DAdvise(IDataObject *dataObject,
830 FORMATETC *formatEtc, DWORD advf,
831 IAdviseSink *adviseSink,
832 DWORD *pdwConnection)
834 FIXME("(%p, %p, %u, %p, %p): stub\n", dataObject, formatEtc, advf,
835 adviseSink, pdwConnection);
836 return OLE_E_ADVISENOTSUPPORTED;
839 static HRESULT WINAPI XDNDDATAOBJECT_DUnadvise(IDataObject *dataObject,
840 DWORD dwConnection)
842 FIXME("(%p, %u): stub\n", dataObject, dwConnection);
843 return OLE_E_ADVISENOTSUPPORTED;
846 static HRESULT WINAPI XDNDDATAOBJECT_EnumDAdvise(IDataObject *dataObject,
847 IEnumSTATDATA **pEnumAdvise)
849 FIXME("(%p, %p): stub\n", dataObject, pEnumAdvise);
850 return OLE_E_ADVISENOTSUPPORTED;
853 static IDataObjectVtbl xdndDataObjectVtbl =
855 XDNDDATAOBJECT_QueryInterface,
856 XDNDDATAOBJECT_AddRef,
857 XDNDDATAOBJECT_Release,
858 XDNDDATAOBJECT_GetData,
859 XDNDDATAOBJECT_GetDataHere,
860 XDNDDATAOBJECT_QueryGetData,
861 XDNDDATAOBJECT_GetCanonicalFormatEtc,
862 XDNDDATAOBJECT_SetData,
863 XDNDDATAOBJECT_EnumFormatEtc,
864 XDNDDATAOBJECT_DAdvise,
865 XDNDDATAOBJECT_DUnadvise,
866 XDNDDATAOBJECT_EnumDAdvise
869 static IDataObject XDNDDataObject = { &xdndDataObjectVtbl };