d3dx9_30: Add stub for D3DXCpuOptimizations.
[wine.git] / dlls / winex11.drv / xdnd.c
blob6618edd00bfcea218a6e1d121c0752503840dccf
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;
377 TRACE("\n");
379 /* If we have a HDROP type we send a WM_ACCEPTFILES.*/
380 if (GetWindowLongW( hWnd, GWL_EXSTYLE ) & WS_EX_ACCEPTFILES)
381 X11DRV_XDND_SendDropFiles( hWnd );
383 /* Notify OLE of Drop */
384 dropTarget = get_droptarget_pointer(XDNDLastDropTargetWnd);
385 if (dropTarget)
387 HRESULT hr;
388 POINTL pointl;
389 DWORD effect = XDNDDropEffect;
391 pointl.x = XDNDxy.x;
392 pointl.y = XDNDxy.y;
393 hr = IDropTarget_Drop(dropTarget, &XDNDDataObject, MK_LBUTTON,
394 pointl, &effect);
395 if (SUCCEEDED(hr))
397 if (effect != DROPEFFECT_NONE)
398 TRACE("drop succeeded\n");
399 else
400 TRACE("the application refused the drop\n");
402 else
403 WARN("drop failed, error 0x%08X\n", hr);
404 IDropTarget_Release(dropTarget);
407 X11DRV_XDND_FreeDragDropOp();
409 /* Tell the target we are finished. */
410 memset(&e, 0, sizeof(e));
411 e.type = ClientMessage;
412 e.display = event->display;
413 e.window = event->data.l[0];
414 e.message_type = x11drv_atom(XdndFinished);
415 e.format = 32;
416 e.data.l[0] = event->window;
417 XSendEvent(event->display, event->data.l[0], False, NoEventMask, (XEvent*)&e);
420 /**************************************************************************
421 * X11DRV_XDND_LeaveEvent
423 * Handle an XdndLeave event.
425 void X11DRV_XDND_LeaveEvent( HWND hWnd, XClientMessageEvent *event )
427 IDropTarget *dropTarget;
429 TRACE("DND Operation canceled\n");
431 /* Notify OLE of DragLeave */
432 dropTarget = get_droptarget_pointer(XDNDLastDropTargetWnd);
433 if (dropTarget)
435 HRESULT hr = IDropTarget_DragLeave(dropTarget);
436 if (FAILED(hr))
437 WARN("IDropTarget_DragLeave failed, error 0x%08X\n", hr);
438 IDropTarget_Release(dropTarget);
441 X11DRV_XDND_FreeDragDropOp();
445 /**************************************************************************
446 * X11DRV_XDND_ResolveProperty
448 * Resolve all MIME types to windows clipboard formats. All data is cached.
450 static void X11DRV_XDND_ResolveProperty(Display *display, Window xwin, Time tm,
451 Atom *types, unsigned long count)
453 unsigned int i, j;
454 BOOL res;
455 XEvent xe;
456 XDNDDATA *current, *next;
457 BOOL haveHDROP = FALSE;
459 TRACE("count(%ld)\n", count);
461 X11DRV_XDND_FreeDragDropOp(); /* Clear previously cached data */
463 for (i = 0; i < count; i++)
465 HANDLE contents;
466 UINT windowsFormat;
468 TRACE("requesting atom %ld from xwin %ld\n", types[i], xwin);
470 if (types[i] == 0)
471 continue;
473 XConvertSelection(display, x11drv_atom(XdndSelection), types[i],
474 x11drv_atom(XdndTarget), xwin, /*tm*/CurrentTime);
477 * Wait for SelectionNotify
479 for (j = 0; j < SELECTION_RETRIES; j++)
481 res = XCheckTypedWindowEvent(display, xwin, SelectionNotify, &xe);
482 if (res && xe.xselection.selection == x11drv_atom(XdndSelection)) break;
484 usleep(SELECTION_WAIT);
487 if (xe.xselection.property == None)
488 continue;
490 contents = X11DRV_CLIPBOARD_ImportSelection(display, types[i], xwin, x11drv_atom(XdndTarget), &windowsFormat);
491 if (contents)
492 X11DRV_XDND_InsertXDNDData(types[i], windowsFormat, contents);
495 /* On Windows when there is a CF_HDROP, there are no other CF_ formats.
496 * foobar2000 relies on this (spaces -> %20's without it).
498 LIST_FOR_EACH_ENTRY(current, &xdndData, XDNDDATA, entry)
500 if (current->cf_win == CF_HDROP)
502 haveHDROP = TRUE;
503 break;
506 if (haveHDROP)
508 LIST_FOR_EACH_ENTRY_SAFE(current, next, &xdndData, XDNDDATA, entry)
510 if (current->cf_win != CF_HDROP && current->cf_win < CF_MAX)
512 list_remove(&current->entry);
513 GlobalFree(current->contents);
514 HeapFree(GetProcessHeap(), 0, current);
521 /**************************************************************************
522 * X11DRV_XDND_InsertXDNDData
524 * Cache available XDND property
526 static void X11DRV_XDND_InsertXDNDData(int property, int format, HANDLE contents)
528 LPXDNDDATA current = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(XDNDDATA));
530 if (current)
532 EnterCriticalSection(&xdnd_cs);
533 current->cf_xdnd = property;
534 current->cf_win = format;
535 current->contents = contents;
536 list_add_tail(&xdndData, &current->entry);
537 LeaveCriticalSection(&xdnd_cs);
542 /**************************************************************************
543 * X11DRV_XDND_SendDropFiles
545 static void X11DRV_XDND_SendDropFiles(HWND hwnd)
547 LPXDNDDATA current = NULL;
548 BOOL found = FALSE;
550 EnterCriticalSection(&xdnd_cs);
552 /* Find CF_HDROP type if any */
553 LIST_FOR_EACH_ENTRY(current, &xdndData, XDNDDATA, entry)
555 if (current->cf_win == CF_HDROP)
557 found = TRUE;
558 break;
562 if (found)
564 HGLOBAL dropHandle = GlobalAlloc(GMEM_FIXED, GlobalSize(current->contents));
566 if (dropHandle)
568 DROPFILES *lpDrop = GlobalLock(dropHandle);
569 memcpy(lpDrop, GlobalLock(current->contents), GlobalSize(current->contents));
570 GlobalUnlock(current->contents);
571 lpDrop->pt.x = XDNDxy.x;
572 lpDrop->pt.y = XDNDxy.y;
573 lpDrop->fNC = !ScreenToClient(hwnd, &lpDrop->pt);
574 TRACE("Sending WM_DROPFILES: hWnd=0x%p, fNC=%d, x=%d, y=%d, files=%p(%s)\n", hwnd,
575 lpDrop->fNC, lpDrop->pt.x, lpDrop->pt.y, ((char*)lpDrop) + lpDrop->pFiles,
576 debugstr_w((WCHAR*)(((char*)lpDrop) + lpDrop->pFiles)));
577 GlobalUnlock(dropHandle);
578 if (!PostMessageW(hwnd, WM_DROPFILES, (WPARAM)dropHandle, 0))
579 GlobalFree(dropHandle);
583 LeaveCriticalSection(&xdnd_cs);
587 /**************************************************************************
588 * X11DRV_XDND_FreeDragDropOp
590 static void X11DRV_XDND_FreeDragDropOp(void)
592 LPXDNDDATA next;
593 LPXDNDDATA current;
595 TRACE("\n");
597 EnterCriticalSection(&xdnd_cs);
599 /** Free data cache */
600 LIST_FOR_EACH_ENTRY_SAFE(current, next, &xdndData, XDNDDATA, entry)
602 list_remove(&current->entry);
603 GlobalFree(current->contents);
604 HeapFree(GetProcessHeap(), 0, current);
607 XDNDxy.x = XDNDxy.y = 0;
608 XDNDLastTargetWnd = NULL;
609 XDNDLastDropTargetWnd = NULL;
610 XDNDAccepted = FALSE;
612 LeaveCriticalSection(&xdnd_cs);
616 /**************************************************************************
617 * X11DRV_XDND_DescribeClipboardFormat
619 static void X11DRV_XDND_DescribeClipboardFormat(int cfFormat, char *buffer, int size)
621 #define D(x) case x: lstrcpynA(buffer, #x, size); return;
622 switch (cfFormat)
624 D(CF_TEXT)
625 D(CF_BITMAP)
626 D(CF_METAFILEPICT)
627 D(CF_SYLK)
628 D(CF_DIF)
629 D(CF_TIFF)
630 D(CF_OEMTEXT)
631 D(CF_DIB)
632 D(CF_PALETTE)
633 D(CF_PENDATA)
634 D(CF_RIFF)
635 D(CF_WAVE)
636 D(CF_UNICODETEXT)
637 D(CF_ENHMETAFILE)
638 D(CF_HDROP)
639 D(CF_LOCALE)
640 D(CF_DIBV5)
642 #undef D
644 if (CF_PRIVATEFIRST <= cfFormat && cfFormat <= CF_PRIVATELAST)
646 lstrcpynA(buffer, "some private object", size);
647 return;
649 if (CF_GDIOBJFIRST <= cfFormat && cfFormat <= CF_GDIOBJLAST)
651 lstrcpynA(buffer, "some GDI object", size);
652 return;
655 GetClipboardFormatNameA(cfFormat, buffer, size);
659 /* The IDataObject singleton we feed to OLE follows */
661 static HRESULT WINAPI XDNDDATAOBJECT_QueryInterface(IDataObject *dataObject,
662 REFIID riid, void **ppvObject)
664 TRACE("(%p, %s, %p)\n", dataObject, debugstr_guid(riid), ppvObject);
665 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDataObject))
667 *ppvObject = dataObject;
668 IDataObject_AddRef(dataObject);
669 return S_OK;
671 *ppvObject = NULL;
672 return E_NOINTERFACE;
675 static ULONG WINAPI XDNDDATAOBJECT_AddRef(IDataObject *dataObject)
677 TRACE("(%p)\n", dataObject);
678 return 2;
681 static ULONG WINAPI XDNDDATAOBJECT_Release(IDataObject *dataObject)
683 TRACE("(%p)\n", dataObject);
684 return 1;
687 static HRESULT WINAPI XDNDDATAOBJECT_GetData(IDataObject *dataObject,
688 FORMATETC *formatEtc,
689 STGMEDIUM *pMedium)
691 HRESULT hr;
692 char formatDesc[1024];
694 TRACE("(%p, %p, %p)\n", dataObject, formatEtc, pMedium);
695 X11DRV_XDND_DescribeClipboardFormat(formatEtc->cfFormat,
696 formatDesc, sizeof(formatDesc));
697 TRACE("application is looking for %s\n", formatDesc);
699 hr = IDataObject_QueryGetData(dataObject, formatEtc);
700 if (SUCCEEDED(hr))
702 XDNDDATA *current;
703 LIST_FOR_EACH_ENTRY(current, &xdndData, XDNDDATA, entry)
705 if (current->cf_win == formatEtc->cfFormat)
707 pMedium->tymed = TYMED_HGLOBAL;
708 pMedium->u.hGlobal = GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, GlobalSize(current->contents));
709 if (pMedium->u.hGlobal == NULL)
710 return E_OUTOFMEMORY;
711 memcpy(GlobalLock(pMedium->u.hGlobal), GlobalLock(current->contents), GlobalSize(current->contents));
712 GlobalUnlock(pMedium->u.hGlobal);
713 GlobalUnlock(current->contents);
714 pMedium->pUnkForRelease = 0;
715 return S_OK;
719 return hr;
722 static HRESULT WINAPI XDNDDATAOBJECT_GetDataHere(IDataObject *dataObject,
723 FORMATETC *formatEtc,
724 STGMEDIUM *pMedium)
726 FIXME("(%p, %p, %p): stub\n", dataObject, formatEtc, pMedium);
727 return DATA_E_FORMATETC;
730 static HRESULT WINAPI XDNDDATAOBJECT_QueryGetData(IDataObject *dataObject,
731 FORMATETC *formatEtc)
733 char formatDesc[1024];
734 XDNDDATA *current;
736 TRACE("(%p, %p={.tymed=0x%x, .dwAspect=%d, .cfFormat=%d}\n",
737 dataObject, formatEtc, formatEtc->tymed, formatEtc->dwAspect, formatEtc->cfFormat);
738 X11DRV_XDND_DescribeClipboardFormat(formatEtc->cfFormat, formatDesc, sizeof(formatDesc));
740 if (formatEtc->tymed && !(formatEtc->tymed & TYMED_HGLOBAL))
742 FIXME("only HGLOBAL medium types supported right now\n");
743 return DV_E_TYMED;
745 if (formatEtc->dwAspect != DVASPECT_CONTENT)
747 FIXME("only the content aspect is supported right now\n");
748 return E_NOTIMPL;
751 LIST_FOR_EACH_ENTRY(current, &xdndData, XDNDDATA, entry)
753 if (current->cf_win == formatEtc->cfFormat)
755 TRACE("application found %s\n", formatDesc);
756 return S_OK;
759 TRACE("application didn't find %s\n", formatDesc);
760 return DV_E_FORMATETC;
763 static HRESULT WINAPI XDNDDATAOBJECT_GetCanonicalFormatEtc(IDataObject *dataObject,
764 FORMATETC *formatEtc,
765 FORMATETC *formatEtcOut)
767 FIXME("(%p, %p, %p): stub\n", dataObject, formatEtc, formatEtcOut);
768 formatEtcOut->ptd = NULL;
769 return E_NOTIMPL;
772 static HRESULT WINAPI XDNDDATAOBJECT_SetData(IDataObject *dataObject,
773 FORMATETC *formatEtc,
774 STGMEDIUM *pMedium, BOOL fRelease)
776 FIXME("(%p, %p, %p, %s): stub\n", dataObject, formatEtc,
777 pMedium, fRelease?"TRUE":"FALSE");
778 return E_NOTIMPL;
781 static HRESULT WINAPI XDNDDATAOBJECT_EnumFormatEtc(IDataObject *dataObject,
782 DWORD dwDirection,
783 IEnumFORMATETC **ppEnumFormatEtc)
785 DWORD count;
786 FORMATETC *formats;
788 TRACE("(%p, %u, %p)\n", dataObject, dwDirection, ppEnumFormatEtc);
790 if (dwDirection != DATADIR_GET)
792 FIXME("only the get direction is implemented\n");
793 return E_NOTIMPL;
796 count = list_count(&xdndData);
797 formats = HeapAlloc(GetProcessHeap(), 0, count * sizeof(FORMATETC));
798 if (formats)
800 XDNDDATA *current;
801 DWORD i = 0;
802 HRESULT hr;
803 LIST_FOR_EACH_ENTRY(current, &xdndData, XDNDDATA, entry)
805 formats[i].cfFormat = current->cf_win;
806 formats[i].ptd = NULL;
807 formats[i].dwAspect = DVASPECT_CONTENT;
808 formats[i].lindex = -1;
809 formats[i].tymed = TYMED_HGLOBAL;
810 i++;
812 hr = SHCreateStdEnumFmtEtc(count, formats, ppEnumFormatEtc);
813 HeapFree(GetProcessHeap(), 0, formats);
814 return hr;
816 else
817 return E_OUTOFMEMORY;
820 static HRESULT WINAPI XDNDDATAOBJECT_DAdvise(IDataObject *dataObject,
821 FORMATETC *formatEtc, DWORD advf,
822 IAdviseSink *adviseSink,
823 DWORD *pdwConnection)
825 FIXME("(%p, %p, %u, %p, %p): stub\n", dataObject, formatEtc, advf,
826 adviseSink, pdwConnection);
827 return OLE_E_ADVISENOTSUPPORTED;
830 static HRESULT WINAPI XDNDDATAOBJECT_DUnadvise(IDataObject *dataObject,
831 DWORD dwConnection)
833 FIXME("(%p, %u): stub\n", dataObject, dwConnection);
834 return OLE_E_ADVISENOTSUPPORTED;
837 static HRESULT WINAPI XDNDDATAOBJECT_EnumDAdvise(IDataObject *dataObject,
838 IEnumSTATDATA **pEnumAdvise)
840 FIXME("(%p, %p): stub\n", dataObject, pEnumAdvise);
841 return OLE_E_ADVISENOTSUPPORTED;
844 static IDataObjectVtbl xdndDataObjectVtbl =
846 XDNDDATAOBJECT_QueryInterface,
847 XDNDDATAOBJECT_AddRef,
848 XDNDDATAOBJECT_Release,
849 XDNDDATAOBJECT_GetData,
850 XDNDDATAOBJECT_GetDataHere,
851 XDNDDATAOBJECT_QueryGetData,
852 XDNDDATAOBJECT_GetCanonicalFormatEtc,
853 XDNDDATAOBJECT_SetData,
854 XDNDDATAOBJECT_EnumFormatEtc,
855 XDNDDATAOBJECT_DAdvise,
856 XDNDDATAOBJECT_DUnadvise,
857 XDNDDATAOBJECT_EnumDAdvise
860 static IDataObject XDNDDataObject = { &xdndDataObjectVtbl };