2 * X11 clipboard windows driver
4 * Copyright 1994 Martin Ayotte
7 * 2003 Ulrich Czekalla for CodeWeavers
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * This file contains the X specific implementation for the windows
27 * Wine's internal clipboard is exposed to external apps via the X
28 * selection mechanism.
29 * Currently the driver asserts ownership via two selection atoms:
30 * 1. PRIMARY(XA_PRIMARY)
33 * In our implementation, the CLIPBOARD selection takes precedence over PRIMARY,
34 * i.e. if a CLIPBOARD selection is available, it is used instead of PRIMARY.
35 * When Wine takes ownership of the clipboard, it takes ownership of BOTH selections.
36 * While giving up selection ownership, if the CLIPBOARD selection is lost,
37 * it will lose both PRIMARY and CLIPBOARD and empty the clipboard.
38 * However if only PRIMARY is lost, it will continue to hold the CLIPBOARD selection
39 * (leaving the clipboard cache content unaffected).
41 * Every format exposed via a windows clipboard format is also exposed through
42 * a corresponding X selection target. A selection target atom is synthesized
43 * whenever a new Windows clipboard format is registered via RegisterClipboardFormat,
44 * or when a built-in format is used for the first time.
45 * Windows native format are exposed by prefixing the format name with "<WCF>"
46 * This allows us to uniquely identify windows native formats exposed by other
49 * In order to allow external applications to query WINE for supported formats,
50 * we respond to the "TARGETS" selection target. (See EVENT_SelectionRequest
51 * for implementation) We use the same mechanism to query external clients for
52 * availability of a particular format, by caching the list of available targets
53 * by using the clipboard cache's "delayed render" mechanism. If a selection client
54 * does not support the "TARGETS" selection target, we actually attempt to retrieve
55 * the format requested as a fallback mechanism.
57 * Certain Windows native formats are automatically converted to X native formats
58 * and vice versa. If a native format is available in the selection, it takes
59 * precedence, in order to avoid unnecessary conversions.
79 #include "clipboard.h"
82 #include "wine/debug.h"
83 #include "wine/unicode.h"
84 #include "wine/server.h"
86 WINE_DEFAULT_DEBUG_CHANNEL(clipboard);
88 #define HGDIOBJ_32(handle16) ((HGDIOBJ)(ULONG_PTR)(handle16))
90 /* Maximum wait time for selection notify */
91 #define SELECTION_RETRIES 500 /* wait for .1 seconds */
92 #define SELECTION_WAIT 1000 /* us */
93 /* Minimum seconds that must lapse between owner queries */
94 #define OWNERQUERYLAPSETIME 1
97 #define S_NOSELECTION 0
101 /* CLIPBOARD atom names */
102 #define _CLIPBOARD "CLIPBOARD"
103 #define _TARGETS "TARGETS"
104 #define _MULTIPLE "MULTIPLE"
105 #define _SELECTIONDATA "SELECTION_DATA"
107 #define _COMPOUNDTEXT "COMPOUND_TEXT"
109 Atom xaClipboard = None;
110 Atom xaTargets = None;
111 Atom xaMultiple = None;
112 Atom xaSelectionData = None;
114 Atom xaCompoundText = None;
116 static int selectionAcquired = 0; /* Contains the current selection masks */
117 static Window selectionWindow = None; /* The top level X window which owns the selection */
118 static BOOL clearAllSelections = FALSE; /* Always lose all selections */
119 static Atom selectionCacheSrc = XA_PRIMARY; /* The selection source from which the clipboard cache was filled */
120 static Window PrimarySelectionOwner = None; /* The window which owns the primary selection */
121 static Window ClipboardSelectionOwner = None; /* The window which owns the clipboard selection */
123 INT X11DRV_RegisterClipboardFormat(LPCSTR FormatName);
124 void X11DRV_EmptyClipboard(void);
125 void X11DRV_EndClipboardUpdate(void);
126 HANDLE X11DRV_CLIPBOARD_ImportClipboardData(LPBYTE lpdata, UINT cBytes);
127 HANDLE X11DRV_CLIPBOARD_ImportEnhMetaFile(LPBYTE lpdata, UINT cBytes);
128 HANDLE X11DRV_CLIPBOARD_ImportMetaFilePict(LPBYTE lpdata, UINT cBytes);
129 HANDLE X11DRV_CLIPBOARD_ImportXAPIXMAP(LPBYTE lpdata, UINT cBytes);
130 HANDLE X11DRV_CLIPBOARD_ImportXAString(LPBYTE lpdata, UINT cBytes);
131 HANDLE X11DRV_CLIPBOARD_ExportClipboardData(Window requestor, Atom aTarget,
132 Atom rprop, LPWINE_CLIPDATA lpData, LPDWORD lpBytes);
133 HANDLE X11DRV_CLIPBOARD_ExportString(Window requestor, Atom aTarget,
134 Atom rprop, LPWINE_CLIPDATA lpData, LPDWORD lpBytes);
135 HANDLE X11DRV_CLIPBOARD_ExportXAPIXMAP(Window requestor, Atom aTarget,
136 Atom rprop, LPWINE_CLIPDATA lpdata, LPDWORD lpBytes);
137 HANDLE X11DRV_CLIPBOARD_ExportMetaFilePict(Window requestor, Atom aTarget,
138 Atom rprop, LPWINE_CLIPDATA lpdata, LPDWORD lpBytes);
139 HANDLE X11DRV_CLIPBOARD_ExportEnhMetaFile(Window requestor, Atom aTarget,
140 Atom rprop, LPWINE_CLIPDATA lpdata, LPDWORD lpBytes);
141 UINT X11DRV_CLIPBOARD_InsertClipboardFormat(LPCSTR FormatName, LPCSTR PropertyName);
142 static BOOL X11DRV_CLIPBOARD_ReadSelection(LPWINE_CLIPFORMAT lpData, Window w, Atom prop);
143 static BOOL X11DRV_CLIPBOARD_RenderSynthesizedText(UINT wFormatID);
144 static void X11DRV_CLIPBOARD_FreeData(LPWINE_CLIPDATA lpData);
145 static BOOL X11DRV_CLIPBOARD_IsSelectionOwner(void);
146 static int X11DRV_CLIPBOARD_QueryAvailableData(LPCLIPBOARDINFO lpcbinfo);
147 static BOOL X11DRV_CLIPBOARD_ReadClipboardData(UINT wFormat);
148 static BOOL X11DRV_CLIPBOARD_RenderFormat(LPWINE_CLIPDATA lpData);
149 static HANDLE X11DRV_CLIPBOARD_SerializeMetafile(INT wformat, HANDLE hdata, LPDWORD lpcbytes, BOOL out);
150 static BOOL X11DRV_CLIPBOARD_SynthesizeData(UINT wFormatID);
151 static BOOL X11DRV_CLIPBOARD_RenderSynthesizedFormat(LPWINE_CLIPDATA lpData);
154 * WARNING: This data ordering is dependent on the WINE_CLIPFORMAT structure
155 * declared in clipboard.h
157 WINE_CLIPFORMAT ClipFormats[] =
159 { CF_TEXT, "WCF_TEXT", 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
160 X11DRV_CLIPBOARD_ExportClipboardData, NULL, &ClipFormats[1]},
162 { CF_BITMAP, "WCF_BITMAP", 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
163 X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[0], &ClipFormats[2]},
165 { CF_METAFILEPICT, "WCF_METAFILEPICT", 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportMetaFilePict,
166 X11DRV_CLIPBOARD_ExportMetaFilePict, &ClipFormats[1], &ClipFormats[3]},
168 { CF_SYLK, "WCF_SYLK", 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
169 X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[2], &ClipFormats[4]},
171 { CF_DIF, "WCF_DIF", 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
172 X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[3], &ClipFormats[5]},
174 { CF_TIFF, "WCF_TIFF", 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
175 X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[4], &ClipFormats[6]},
177 { CF_OEMTEXT, "WCF_OEMTEXT", 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
178 X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[5], &ClipFormats[7]},
180 { CF_DIB, "WCF_DIB", 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportXAPIXMAP,
181 X11DRV_CLIPBOARD_ExportXAPIXMAP, &ClipFormats[6], &ClipFormats[8]},
183 { CF_PALETTE, "WCF_PALETTE", 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
184 X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[7], &ClipFormats[9]},
186 { CF_PENDATA, "WCF_PENDATA", 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
187 X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[8], &ClipFormats[10]},
189 { CF_RIFF, "WCF_RIFF", 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
190 X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[9], &ClipFormats[11]},
192 { CF_WAVE, "WCF_WAVE", 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
193 X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[10], &ClipFormats[12]},
195 { CF_UNICODETEXT, "WCF_UNICODETEXT", XA_STRING, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportXAString,
196 X11DRV_CLIPBOARD_ExportString, &ClipFormats[11], &ClipFormats[13]},
198 { CF_ENHMETAFILE, "WCF_ENHMETAFILE", 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportEnhMetaFile,
199 X11DRV_CLIPBOARD_ExportEnhMetaFile, &ClipFormats[12], &ClipFormats[14]},
201 { CF_HDROP, "WCF_HDROP", 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
202 X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[13], &ClipFormats[15]},
204 { CF_LOCALE, "WCF_LOCALE", 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
205 X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[14], &ClipFormats[16]},
207 { CF_DIBV5, "WCF_DIBV5", 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
208 X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[15], &ClipFormats[17]},
210 { CF_OWNERDISPLAY, "WCF_OWNERDISPLAY", 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
211 X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[16], &ClipFormats[18]},
213 { CF_DSPTEXT, "WCF_DSPTEXT", 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
214 X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[17], &ClipFormats[19]},
216 { CF_DSPBITMAP, "WCF_DSPBITMAP", 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
217 X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[18], &ClipFormats[20]},
219 { CF_DSPMETAFILEPICT, "WCF_DSPMETAFILEPICT", 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
220 X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[19], &ClipFormats[21]},
222 { CF_DSPENHMETAFILE, "WCF_DSPENHMETAFILE", 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
223 X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[20], NULL}
227 /* Maps X properties to Windows formats */
228 PROPERTYFORMATMAP PropertyFormatMap[] =
230 { "text/rtf", "Rich Text Format" },
231 /* Temporarily disable text/html because Evolution incorrectly pastes strings with extra nulls */
232 /*{ "text/html", "HTML Format" },*/
233 { "image/gif", "GIF" },
237 /* Maps equivalent X properties. It is assumed that lpszProperty must already
238 be in ClipFormats or PropertyFormatMap. */
239 PROPERTYALIASMAP PropertyAliasMap[] =
241 /* lpszProperty, Alias */
242 { "text/rtf", 0, "text/richtext", 0 },
243 { "XAString", XA_STRING, _COMPOUNDTEXT, 0 },
244 { "XAString", XA_STRING, _TEXT, 0 },
249 * Cached clipboard data.
251 static LPWINE_CLIPDATA ClipData = NULL;
252 static UINT ClipDataCount = 0;
255 * Clipboard sequence number
259 /**************************************************************************
260 * Internal Clipboard implementation methods
261 **************************************************************************/
263 /**************************************************************************
264 * X11DRV_InitClipboard
266 BOOL X11DRV_InitClipboard(Display *display)
270 PROPERTYALIASMAP *lpalias;
271 LPWINE_CLIPFORMAT lpFormat = ClipFormats;
273 xaClipboard = TSXInternAtom( display, _CLIPBOARD, FALSE );
274 xaTargets = TSXInternAtom( display, _TARGETS, FALSE );
275 xaMultiple = TSXInternAtom(display, _MULTIPLE, False);
276 xaSelectionData = TSXInternAtom(display, _SELECTIONDATA, False);
277 xaText = TSXInternAtom(display, _TEXT, False);
278 xaCompoundText = TSXInternAtom(display, _COMPOUNDTEXT, False);
280 if(!RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Clipboard", &hkey))
283 DWORD type, count = sizeof(buffer);
284 if(!RegQueryValueExA(hkey, "ClearAllSelections", 0, &type, buffer, &count))
285 clearAllSelections = atoi(buffer);
289 /* Register known formats */
292 if (!lpFormat->wFormatID)
293 lpFormat->wFormatID = GlobalAddAtomA(lpFormat->Name);
295 if (!lpFormat->drvData)
296 lpFormat->drvData = TSXInternAtom(display, lpFormat->Name, False);
298 lpFormat = lpFormat->NextFormat;
301 /* Register known mapping between window formats and X properties */
302 for (i = 0; i < sizeof(PropertyFormatMap)/sizeof(PROPERTYFORMATMAP); i++)
303 X11DRV_CLIPBOARD_InsertClipboardFormat(PropertyFormatMap[i].lpszFormat,
304 PropertyFormatMap[i].lpszProperty);
306 /* Register known mapping between X properties */
307 for (i = 0; i < sizeof(PropertyAliasMap)/sizeof(PROPERTYALIASMAP); i++)
309 lpalias = &PropertyAliasMap[i];
310 if (!lpalias->drvDataProperty)
311 lpalias->drvDataProperty = TSXInternAtom(display, lpalias->lpszProperty, False);
312 if (!lpalias->drvDataAlias)
313 lpalias->drvDataAlias = TSXInternAtom(display, lpalias->lpszAlias, False);
320 /**************************************************************************
321 * X11DRV_CLIPBOARD_LookupFormat
323 LPWINE_CLIPFORMAT X11DRV_CLIPBOARD_LookupFormat(WORD wID)
325 LPWINE_CLIPFORMAT lpFormat = ClipFormats;
329 if (lpFormat->wFormatID == wID)
332 lpFormat = lpFormat->NextFormat;
339 /**************************************************************************
340 * X11DRV_CLIPBOARD_LookupProperty
342 LPWINE_CLIPFORMAT X11DRV_CLIPBOARD_LookupProperty(UINT drvData)
344 LPWINE_CLIPFORMAT lpFormat = ClipFormats;
348 if (lpFormat->drvData == drvData)
351 lpFormat = lpFormat->NextFormat;
358 /**************************************************************************
359 * X11DRV_CLIPBOARD_LookupAliasProperty
361 LPWINE_CLIPFORMAT X11DRV_CLIPBOARD_LookupAliasProperty(UINT drvDataAlias)
364 LPWINE_CLIPFORMAT lpFormat = NULL;
366 for (i = 0; i < sizeof(PropertyAliasMap)/sizeof(PROPERTYALIASMAP); i++)
368 if (PropertyAliasMap[i].drvDataAlias == drvDataAlias)
370 lpFormat = X11DRV_CLIPBOARD_LookupProperty(PropertyAliasMap[i].drvDataProperty);
379 /**************************************************************************
380 * X11DRV_CLIPBOARD_LookupPropertyAlias
382 UINT X11DRV_CLIPBOARD_LookupPropertyAlias(UINT drvDataProperty)
387 for (i = 0; i < sizeof(PropertyAliasMap)/sizeof(PROPERTYALIASMAP); i++)
389 if (PropertyAliasMap[i].drvDataProperty == drvDataProperty)
391 alias = PropertyAliasMap[i].drvDataAlias;
400 /**************************************************************************
401 * X11DRV_CLIPBOARD_LookupData
403 LPWINE_CLIPDATA X11DRV_CLIPBOARD_LookupData(DWORD wID)
405 LPWINE_CLIPDATA lpData = ClipData;
411 if (lpData->wFormatID == wID)
414 lpData = lpData->NextData;
416 while(lpData != ClipData);
418 if (lpData->wFormatID != wID)
426 /**************************************************************************
427 * InsertClipboardFormat
429 UINT X11DRV_CLIPBOARD_InsertClipboardFormat(LPCSTR FormatName, LPCSTR PropertyName)
431 LPWINE_CLIPFORMAT lpFormat;
432 LPWINE_CLIPFORMAT lpNewFormat;
434 /* allocate storage for new format entry */
435 lpNewFormat = (LPWINE_CLIPFORMAT) HeapAlloc(GetProcessHeap(),
436 0, sizeof(WINE_CLIPFORMAT));
438 if(lpNewFormat == NULL)
440 WARN("No more memory for a new format!\n");
444 if (!(lpNewFormat->Name = HeapAlloc(GetProcessHeap(), 0, strlen(FormatName)+1)))
446 WARN("No more memory for the new format name!\n");
447 HeapFree(GetProcessHeap(), 0, lpNewFormat);
451 strcpy(lpNewFormat->Name, FormatName);
452 lpNewFormat->wFlags = 0;
453 lpNewFormat->wFormatID = GlobalAddAtomA(lpNewFormat->Name);
454 lpNewFormat->drvData = TSXInternAtom(thread_display(), PropertyName, False);
455 lpNewFormat->lpDrvImportFunc = X11DRV_CLIPBOARD_ImportClipboardData;
456 lpNewFormat->lpDrvExportFunc = X11DRV_CLIPBOARD_ExportClipboardData;
459 lpFormat = ClipFormats;
461 while(lpFormat->NextFormat) /* Move to last entry */
462 lpFormat = lpFormat->NextFormat;
464 lpNewFormat->NextFormat = NULL;
465 lpFormat->NextFormat = lpNewFormat;
466 lpNewFormat->PrevFormat = lpFormat;
468 TRACE("Registering format(%d): %s drvData(%d): %s\n",
469 lpNewFormat->wFormatID,
471 lpNewFormat->drvData,
474 return lpNewFormat->wFormatID;
480 /**************************************************************************
481 * X11DRV_CLIPBOARD_GetClipboardInfo
483 static BOOL X11DRV_CLIPBOARD_GetClipboardInfo(LPCLIPBOARDINFO cbInfo)
487 SERVER_START_REQ( set_clipboard_info )
491 if (wine_server_call_err( req ))
493 ERR("Failed to get clipboard owner.\n");
497 cbInfo->hWndOpen = reply->old_clipboard;
498 cbInfo->hWndOwner = reply->old_owner;
499 cbInfo->hWndViewer = reply->old_viewer;
500 cbInfo->seqno = reply->seqno;
501 cbInfo->flags = reply->flags;
512 /**************************************************************************
513 * X11DRV_CLIPBOARD_ReleaseOwnership
515 static BOOL X11DRV_CLIPBOARD_ReleaseOwnership(void)
519 SERVER_START_REQ( set_clipboard_info )
521 req->flags = SET_CB_RELOWNER | SET_CB_SEQNO;
523 if (wine_server_call_err( req ))
525 ERR("Failed to set clipboard.\n");
539 /**************************************************************************
540 * X11DRV_CLIPBOARD_InsertClipboardData
542 * Caller *must* have the clipboard open and be the owner.
544 static BOOL X11DRV_CLIPBOARD_InsertClipboardData(UINT wFormat, HANDLE16 hData16, HANDLE hData32, DWORD flags)
546 LPWINE_CLIPDATA lpData = X11DRV_CLIPBOARD_LookupData(wFormat);
548 TRACE("format=%d lpData=%p hData16=%08x hData32=%08x flags=0x%08lx\n",
549 wFormat, lpData, hData16, (unsigned int)hData32, flags);
553 X11DRV_CLIPBOARD_FreeData(lpData);
555 lpData->hData16 = hData16; /* 0 is legal, see WM_RENDERFORMAT */
556 lpData->hData32 = hData32;
560 lpData = (LPWINE_CLIPDATA) HeapAlloc(GetProcessHeap(),
561 0, sizeof(WINE_CLIPDATA));
563 lpData->wFormatID = wFormat;
564 lpData->hData16 = hData16; /* 0 is legal, see WM_RENDERFORMAT */
565 lpData->hData32 = hData32;
569 LPWINE_CLIPDATA lpPrevData = ClipData->PrevData;
571 lpData->PrevData = lpPrevData;
572 lpData->NextData = ClipData;
574 lpPrevData->NextData = lpData;
575 ClipData->PrevData = lpData;
579 lpData->NextData = lpData;
580 lpData->PrevData = lpData;
587 lpData->wFlags = flags;
593 /**************************************************************************
594 * X11DRV_CLIPBOARD_FreeData
596 * Free clipboard data handle.
598 static void X11DRV_CLIPBOARD_FreeData(LPWINE_CLIPDATA lpData)
600 TRACE("%d\n", lpData->wFormatID);
602 if ((lpData->wFormatID >= CF_GDIOBJFIRST &&
603 lpData->wFormatID <= CF_GDIOBJLAST) ||
604 lpData->wFormatID == CF_BITMAP ||
605 lpData->wFormatID == CF_DIB ||
606 lpData->wFormatID == CF_PALETTE)
609 DeleteObject(lpData->hData32);
612 DeleteObject(HGDIOBJ_32(lpData->hData16));
614 else if (lpData->wFormatID == CF_METAFILEPICT)
618 DeleteMetaFile(((METAFILEPICT *)GlobalLock( lpData->hData32 ))->hMF );
619 GlobalFree(lpData->hData32);
622 /* HMETAFILE16 and HMETAFILE32 are apparently the same thing,
623 and a shallow copy is enough to share a METAFILEPICT
624 structure between 16bit and 32bit clipboards. The MetaFile
625 should of course only be deleted once. */
626 GlobalFree16(lpData->hData16);
631 METAFILEPICT16* lpMetaPict = (METAFILEPICT16 *) GlobalLock16(lpData->hData16);
635 DeleteMetaFile16(lpMetaPict->hMF);
639 GlobalFree16(lpData->hData16);
642 else if (lpData->wFormatID == CF_ENHMETAFILE)
645 DeleteEnhMetaFile(lpData->hData32);
647 else if (lpData->wFormatID < CF_PRIVATEFIRST ||
648 lpData->wFormatID > CF_PRIVATELAST)
651 GlobalFree(lpData->hData32);
654 GlobalFree16(lpData->hData16);
662 /**************************************************************************
663 * X11DRV_CLIPBOARD_UpdateCache
665 static BOOL X11DRV_CLIPBOARD_UpdateCache(LPCLIPBOARDINFO lpcbinfo)
669 if (!X11DRV_CLIPBOARD_IsSelectionOwner())
671 if (!X11DRV_CLIPBOARD_GetClipboardInfo(lpcbinfo))
673 ERR("Failed to retrieve clipboard information.\n");
676 else if (wSeqNo < lpcbinfo->seqno)
678 X11DRV_EmptyClipboard();
680 if (X11DRV_CLIPBOARD_QueryAvailableData(lpcbinfo) < 0)
682 ERR("Failed to cache clipboard data owned by another process.\n");
687 X11DRV_EndClipboardUpdate();
690 wSeqNo = lpcbinfo->seqno;
698 /**************************************************************************
699 * X11DRV_CLIPBOARD_RenderFormat
701 static BOOL X11DRV_CLIPBOARD_RenderFormat(LPWINE_CLIPDATA lpData)
705 TRACE(" 0x%04x hData32(0x%08x) hData16(0x%08x)\n",
706 lpData->wFormatID, (unsigned int)lpData->hData32, lpData->hData16);
708 if (lpData->hData32 || lpData->hData16)
709 return bret; /* Already rendered */
711 if (lpData->wFlags & CF_FLAG_SYNTHESIZED)
712 bret = X11DRV_CLIPBOARD_RenderSynthesizedFormat(lpData);
713 else if (!X11DRV_CLIPBOARD_IsSelectionOwner())
715 if (!X11DRV_CLIPBOARD_ReadClipboardData(lpData->wFormatID))
717 ERR("Failed to cache clipboard data owned by another process. Format=%d\n",
724 CLIPBOARDINFO cbInfo;
726 if (X11DRV_CLIPBOARD_GetClipboardInfo(&cbInfo) && cbInfo.hWndOwner)
728 /* Send a WM_RENDERFORMAT message to notify the owner to render the
729 * data requested into the clipboard.
731 TRACE("Sending WM_RENDERFORMAT message to hwnd(%p)\n", cbInfo.hWndOwner);
732 SendMessageW(cbInfo.hWndOwner, WM_RENDERFORMAT, (WPARAM)lpData->wFormatID, 0);
734 if (!lpData->hData32 && !lpData->hData16)
739 ERR("hWndClipOwner is lost!\n");
748 /**************************************************************************
749 * CLIPBOARD_ConvertText
750 * Returns number of required/converted characters - not bytes!
752 static INT CLIPBOARD_ConvertText(WORD src_fmt, void const *src, INT src_size,
753 WORD dst_fmt, void *dst, INT dst_size)
757 if(src_fmt == CF_UNICODETEXT)
770 return WideCharToMultiByte(cp, 0, src, src_size, dst, dst_size, NULL, NULL);
773 if(dst_fmt == CF_UNICODETEXT)
786 return MultiByteToWideChar(cp, 0, src, src_size, dst, dst_size);
789 if(!dst_size) return src_size;
791 if(dst_size > src_size) dst_size = src_size;
793 if(src_fmt == CF_TEXT )
794 CharToOemBuffA(src, dst, dst_size);
796 OemToCharBuffA(src, dst, dst_size);
802 /**************************************************************************
803 * X11DRV_CLIPBOARD_RenderSynthesizedFormat
805 static BOOL X11DRV_CLIPBOARD_RenderSynthesizedFormat(LPWINE_CLIPDATA lpData)
811 if (lpData->wFlags & CF_FLAG_SYNTHESIZED)
813 UINT wFormatID = lpData->wFormatID;
815 if (wFormatID == CF_UNICODETEXT || wFormatID == CF_TEXT || wFormatID == CF_OEMTEXT)
816 bret = X11DRV_CLIPBOARD_RenderSynthesizedText(wFormatID);
822 case CF_METAFILEPICT:
825 FIXME("Synthesizing wFormatID(0x%08x) not implemented\n", wFormatID);
829 FIXME("Called to synthesize unknown format\n");
834 lpData->wFlags &= ~CF_FLAG_SYNTHESIZED;
841 /**************************************************************************
842 * X11DRV_CLIPBOARD_RenderSynthesizedText
844 * Renders synthesized text
846 static BOOL X11DRV_CLIPBOARD_RenderSynthesizedText(UINT wFormatID)
851 INT src_chars, dst_chars, alloc_size;
852 LPWINE_CLIPDATA lpSource = NULL;
854 TRACE(" %d\n", wFormatID);
856 if ((lpSource = X11DRV_CLIPBOARD_LookupData(wFormatID)) &&
860 /* Look for rendered source or non-synthesized source */
861 if ((lpSource = X11DRV_CLIPBOARD_LookupData(CF_UNICODETEXT)) &&
862 (!(lpSource->wFlags & CF_FLAG_SYNTHESIZED) || lpSource->hData32))
864 TRACE("UNICODETEXT -> %d\n", wFormatID);
866 else if ((lpSource = X11DRV_CLIPBOARD_LookupData(CF_TEXT)) &&
867 (!(lpSource->wFlags & CF_FLAG_SYNTHESIZED) || lpSource->hData32))
869 TRACE("TEXT -> %d\n", wFormatID);
871 else if ((lpSource = X11DRV_CLIPBOARD_LookupData(CF_OEMTEXT)) &&
872 (!(lpSource->wFlags & CF_FLAG_SYNTHESIZED) || lpSource->hData32))
874 TRACE("OEMTEXT -> %d\n", wFormatID);
877 if (!lpSource || (lpSource->wFlags & CF_FLAG_SYNTHESIZED &&
881 /* Ask the clipboard owner to render the source text if necessary */
882 if (!lpSource->hData32 && !X11DRV_CLIPBOARD_RenderFormat(lpSource))
885 if (lpSource->hData32)
887 lpstrS = (LPSTR)GlobalLock(lpSource->hData32);
891 lpstrS = (LPSTR)GlobalLock16(lpSource->hData16);
897 /* Text always NULL terminated */
898 if(lpSource->wFormatID == CF_UNICODETEXT)
899 src_chars = strlenW((LPCWSTR)lpstrS) + 1;
901 src_chars = strlen(lpstrS) + 1;
903 /* Calculate number of characters in the destination buffer */
904 dst_chars = CLIPBOARD_ConvertText(lpSource->wFormatID, lpstrS,
905 src_chars, wFormatID, NULL, 0);
910 TRACE("Converting from '%d' to '%d', %i chars\n",
911 lpSource->wFormatID, wFormatID, src_chars);
913 /* Convert characters to bytes */
914 if(wFormatID == CF_UNICODETEXT)
915 alloc_size = dst_chars * sizeof(WCHAR);
917 alloc_size = dst_chars;
919 hData32 = GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE |
920 GMEM_DDESHARE, alloc_size);
922 lpstrT = (LPSTR)GlobalLock(hData32);
926 CLIPBOARD_ConvertText(lpSource->wFormatID, lpstrS, src_chars,
927 wFormatID, lpstrT, dst_chars);
928 GlobalUnlock(hData32);
932 if (lpSource->hData32)
933 GlobalUnlock(lpSource->hData32);
935 GlobalUnlock16(lpSource->hData16);
937 return X11DRV_CLIPBOARD_InsertClipboardData(wFormatID, 0, hData32, 0);
941 /**************************************************************************
942 * X11DRV_CLIPBOARD_ImportXAString
944 * Import XA_STRING, converting the string to CF_UNICODE.
946 HANDLE X11DRV_CLIPBOARD_ImportXAString(LPBYTE lpdata, UINT cBytes)
949 UINT i, inlcount = 0;
950 HANDLE hUnicodeText = 0;
952 for (i = 0; i <= cBytes; i++)
954 if (lpdata[i] == '\n')
958 if ((lpstr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cBytes + inlcount + 1)))
962 for (i = 0, inlcount = 0; i <= cBytes; i++)
964 if (lpdata[i] == '\n')
965 lpstr[inlcount++] = '\r';
967 lpstr[inlcount++] = lpdata[i];
970 count = MultiByteToWideChar(CP_UNIXCP, 0, lpstr, -1, NULL, 0);
971 hUnicodeText = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, count * sizeof(WCHAR));
975 WCHAR *textW = GlobalLock(hUnicodeText);
976 MultiByteToWideChar(CP_UNIXCP, 0, lpstr, -1, textW, count);
977 GlobalUnlock(hUnicodeText);
980 HeapFree(GetProcessHeap(), 0, lpstr);
987 /**************************************************************************
988 * X11DRV_CLIPBOARD_ImportXAPIXMAP
990 * Import XA_PIXMAP, converting the image to CF_DIB.
992 HANDLE X11DRV_CLIPBOARD_ImportXAPIXMAP(LPBYTE lpdata, UINT cBytes)
994 HANDLE hTargetImage = 0; /* Handle to store the converted DIB */
995 Pixmap *pPixmap = (Pixmap *) lpdata;
996 HWND hwnd = GetOpenClipboardWindow();
997 HDC hdc = GetDC(hwnd);
999 hTargetImage = X11DRV_DIB_CreateDIBFromPixmap(*pPixmap, hdc, TRUE);
1001 ReleaseDC(hwnd, hdc);
1003 return hTargetImage;
1007 /**************************************************************************
1008 * X11DRV_CLIPBOARD_ImportMetaFilePict
1010 * Import MetaFilePict.
1012 HANDLE X11DRV_CLIPBOARD_ImportMetaFilePict(LPBYTE lpdata, UINT cBytes)
1014 return X11DRV_CLIPBOARD_SerializeMetafile(CF_METAFILEPICT, (HANDLE)lpdata, (LPDWORD)&cBytes, FALSE);
1018 /**************************************************************************
1019 * X11DRV_ImportEnhMetaFile
1021 * Import EnhMetaFile.
1023 HANDLE X11DRV_CLIPBOARD_ImportEnhMetaFile(LPBYTE lpdata, UINT cBytes)
1025 return X11DRV_CLIPBOARD_SerializeMetafile(CF_ENHMETAFILE, (HANDLE)lpdata, (LPDWORD)&cBytes, FALSE);
1029 /**************************************************************************
1030 * X11DRV_ImportClipbordaData
1032 * Generic import clipboard data routine.
1034 HANDLE X11DRV_CLIPBOARD_ImportClipboardData(LPBYTE lpdata, UINT cBytes)
1037 HANDLE hClipData = 0;
1041 /* Turn on the DDESHARE flag to enable shared 32 bit memory */
1042 hClipData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, cBytes);
1043 if ((lpClipData = GlobalLock(hClipData)))
1045 memcpy(lpClipData, lpdata, cBytes);
1046 GlobalUnlock(hClipData);
1056 /**************************************************************************
1057 * X11DRV_CLIPBOARD_ExportClipboardData
1059 * Generic export clipboard data routine.
1061 HANDLE X11DRV_CLIPBOARD_ExportClipboardData(Window requestor, Atom aTarget,
1062 Atom rprop, LPWINE_CLIPDATA lpData, LPDWORD lpBytes)
1066 HANDLE hClipData = 0;
1068 *lpBytes = 0; /* Assume failure */
1070 if (!X11DRV_CLIPBOARD_RenderFormat(lpData))
1071 ERR("Failed to export %d format\n", lpData->wFormatID);
1074 cBytes = GlobalSize(lpData->hData32);
1076 hClipData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, cBytes);
1078 if ((lpClipData = GlobalLock(hClipData)))
1080 LPVOID lpdata = GlobalLock(lpData->hData32);
1082 memcpy(lpClipData, lpdata, cBytes);
1085 GlobalUnlock(lpData->hData32);
1086 GlobalUnlock(hClipData);
1094 /**************************************************************************
1095 * X11DRV_CLIPBOARD_ExportXAString
1097 * Export CF_UNICODE converting the string to XA_STRING.
1098 * Helper function for X11DRV_CLIPBOARD_ExportString.
1100 HANDLE X11DRV_CLIPBOARD_ExportXAString(LPWINE_CLIPDATA lpData, LPDWORD lpBytes)
1107 *lpBytes = 0; /* Assume return has zero bytes */
1109 uni_text = GlobalLock(lpData->hData32);
1111 size = WideCharToMultiByte(CP_UNIXCP, 0, uni_text, -1, NULL, 0, NULL, NULL);
1113 text = HeapAlloc(GetProcessHeap(), 0, size);
1116 WideCharToMultiByte(CP_UNIXCP, 0, uni_text, -1, text, size, NULL, NULL);
1118 /* remove carriage returns */
1120 lpstr = (char*)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size-- );
1121 if(lpstr == NULL) return None;
1122 for(i = 0,j = 0; i < size && text[i]; i++ )
1124 if( text[i] == '\r' &&
1125 (text[i+1] == '\n' || text[i+1] == '\0') ) continue;
1126 lpstr[j++] = text[i];
1130 *lpBytes = j; /* Number of bytes in string */
1132 HeapFree(GetProcessHeap(), 0, text);
1133 GlobalUnlock(lpData->hData32);
1139 /**************************************************************************
1140 * X11DRV_CLIPBOARD_ExportCompoundText
1142 * Export CF_UNICODE to COMPOUND_TEXT or TEXT
1143 * Helper function for X11DRV_CLIPBOARD_ExportString.
1145 HANDLE X11DRV_CLIPBOARD_ExportCompoundText(Window requestor, Atom aTarget, Atom rprop,
1146 LPWINE_CLIPDATA lpData, LPDWORD lpBytes)
1148 Display *display = thread_display();
1151 XICCEncodingStyle style;
1153 lpstr = (char*) X11DRV_CLIPBOARD_ExportXAString(lpData, lpBytes);
1157 if (aTarget == xaCompoundText)
1158 style = XCompoundTextStyle;
1160 style = XStdICCTextStyle;
1162 /* Update the X property */
1164 if (XmbTextListToTextProperty(display, &lpstr, 1, style, &prop) == Success)
1166 XSetTextProperty(display, requestor, &prop, rprop);
1169 wine_tsx11_unlock();
1171 HeapFree( GetProcessHeap(), 0, lpstr );
1177 /**************************************************************************
1178 * X11DRV_CLIPBOARD_ExportString
1180 * Export CF_UNICODE string
1182 HANDLE X11DRV_CLIPBOARD_ExportString(Window requestor, Atom aTarget, Atom rprop,
1183 LPWINE_CLIPDATA lpData, LPDWORD lpBytes)
1185 if (X11DRV_CLIPBOARD_RenderFormat(lpData))
1187 if (aTarget == XA_STRING)
1188 return X11DRV_CLIPBOARD_ExportXAString(lpData, lpBytes);
1189 else if (aTarget == xaCompoundText || aTarget == xaText)
1190 return X11DRV_CLIPBOARD_ExportCompoundText(requestor, aTarget,
1191 rprop, lpData, lpBytes);
1193 ERR("Unknown target %ld to %d format\n", aTarget, lpData->wFormatID);
1196 ERR("Failed to render %d format\n", lpData->wFormatID);
1202 /**************************************************************************
1203 * X11DRV_CLIPBOARD_ExportXAPIXMAP
1205 * Export CF_DIB to XA_PIXMAP.
1207 HANDLE X11DRV_CLIPBOARD_ExportXAPIXMAP(Window requestor, Atom aTarget, Atom rprop,
1208 LPWINE_CLIPDATA lpdata, LPDWORD lpBytes)
1213 if (!X11DRV_CLIPBOARD_RenderFormat(lpdata))
1215 ERR("Failed to export %d format\n", lpdata->wFormatID);
1221 /* For convert from packed DIB to Pixmap */
1222 pixmap = X11DRV_DIB_CreatePixmapFromDIB(lpdata, hdc);
1223 *lpBytes = 4; /* pixmap is a 32bit value */
1227 return (HANDLE) pixmap;
1231 /**************************************************************************
1232 * X11DRV_CLIPBOARD_ExportMetaFilePict
1234 * Export MetaFilePict.
1236 HANDLE X11DRV_CLIPBOARD_ExportMetaFilePict(Window requestor, Atom aTarget, Atom rprop,
1237 LPWINE_CLIPDATA lpdata, LPDWORD lpBytes)
1239 if (!X11DRV_CLIPBOARD_RenderFormat(lpdata))
1241 ERR("Failed to export %d format\n", lpdata->wFormatID);
1245 return X11DRV_CLIPBOARD_SerializeMetafile(CF_METAFILEPICT, (HANDLE)lpdata->hData32,
1250 /**************************************************************************
1251 * X11DRV_CLIPBOARD_ExportEnhMetaFile
1253 * Export EnhMetaFile.
1255 HANDLE X11DRV_CLIPBOARD_ExportEnhMetaFile(Window requestor, Atom aTarget, Atom rprop,
1256 LPWINE_CLIPDATA lpdata, LPDWORD lpBytes)
1258 if (!X11DRV_CLIPBOARD_RenderFormat(lpdata))
1260 ERR("Failed to export %d format\n", lpdata->wFormatID);
1264 return X11DRV_CLIPBOARD_SerializeMetafile(CF_ENHMETAFILE, (HANDLE)lpdata->hData32,
1269 /**************************************************************************
1270 * X11DRV_CLIPBOARD_QueryTargets
1272 static BOOL X11DRV_CLIPBOARD_QueryTargets(Display *display, Window w, Atom selection, XEvent *xe)
1278 XConvertSelection(display, selection, xaTargets, xaSelectionData, w, CurrentTime);
1279 wine_tsx11_unlock();
1282 * Wait until SelectionNotify is received
1284 for (i = 0; i < SELECTION_RETRIES; i++)
1287 res = XCheckTypedWindowEvent(display, w, SelectionNotify, xe);
1288 wine_tsx11_unlock();
1289 if (res && xe->xselection.selection == selection) break;
1291 usleep(SELECTION_WAIT);
1294 /* Verify that the selection returned a valid TARGETS property */
1295 if ((xe->xselection.target != xaTargets) || (xe->xselection.property == None))
1297 /* Selection owner failed to respond or we missed the SelectionNotify */
1298 WARN("Failed to retrieve TARGETS for selection %ld.\n", selection);
1306 /**************************************************************************
1307 * X11DRV_CLIPBOARD_QueryAvailableData
1309 * Caches the list of data formats available from the current selection.
1310 * This queries the selection owner for the TARGETS property and saves all
1311 * reported property types.
1313 static int X11DRV_CLIPBOARD_QueryAvailableData(LPCLIPBOARDINFO lpcbinfo)
1315 Display *display = thread_display();
1317 Atom atype=AnyPropertyType;
1319 unsigned long remain;
1320 Atom* targetList=NULL;
1322 HWND hWndClipWindow;
1323 unsigned long cSelectionTargets = 0;
1325 if (selectionAcquired & (S_PRIMARY | S_CLIPBOARD))
1327 ERR("Received request to cache selection but process is owner=(%08x)\n",
1328 (unsigned) selectionWindow);
1330 selectionAcquired = S_NOSELECTION;
1332 if (TSXGetSelectionOwner(display,XA_PRIMARY) == selectionWindow)
1333 selectionAcquired |= S_PRIMARY;
1335 if (TSXGetSelectionOwner(display,xaClipboard) == selectionWindow)
1336 selectionAcquired |= S_CLIPBOARD;
1338 if (!(selectionAcquired == (S_PRIMARY | S_CLIPBOARD)))
1340 WARN("Lost selection but process didn't process SelectClear\n");
1341 selectionWindow = None;
1345 return -1; /* Prevent self request */
1349 if (lpcbinfo->flags & CB_OWNER)
1350 hWndClipWindow = lpcbinfo->hWndOwner;
1351 else if (lpcbinfo->flags & CB_OPEN)
1352 hWndClipWindow = lpcbinfo->hWndOpen;
1354 hWndClipWindow = GetActiveWindow();
1356 if (!hWndClipWindow)
1358 WARN("No window available to retrieve selection!n");
1362 w = X11DRV_get_whole_window(GetAncestor(hWndClipWindow, GA_ROOT));
1365 * Query the selection owner for the TARGETS property
1367 if (TSXGetSelectionOwner(display,XA_PRIMARY) ||
1368 TSXGetSelectionOwner(display,xaClipboard))
1370 if (X11DRV_CLIPBOARD_QueryTargets(display, w, XA_PRIMARY, &xe))
1371 selectionCacheSrc = XA_PRIMARY;
1372 else if (X11DRV_CLIPBOARD_QueryTargets(display, w, xaClipboard, &xe))
1373 selectionCacheSrc = xaClipboard;
1377 else /* No selection owner so report 0 targets available */
1380 /* Read the TARGETS property contents */
1381 if(TSXGetWindowProperty(display, xe.xselection.requestor, xe.xselection.property,
1382 0, 0x3FFF, True, AnyPropertyType/*XA_ATOM*/, &atype, &aformat, &cSelectionTargets,
1383 &remain, (unsigned char**)&targetList) != Success)
1385 WARN("Failed to read TARGETS property\n");
1389 TRACE("Type %s,Format %d,nItems %ld, Remain %ld\n",
1390 TSXGetAtomName(display,atype),aformat,cSelectionTargets, remain);
1392 * The TARGETS property should have returned us a list of atoms
1393 * corresponding to each selection target format supported.
1395 if ((atype == XA_ATOM || atype == xaTargets) && aformat == 32)
1399 /* Cache these formats in the clipboard cache */
1400 for (i = 0; i < cSelectionTargets; i++)
1402 LPWINE_CLIPFORMAT lpFormat = X11DRV_CLIPBOARD_LookupProperty(targetList[i]);
1405 lpFormat = X11DRV_CLIPBOARD_LookupAliasProperty(targetList[i]);
1409 LPSTR lpName = TSXGetAtomName(display, targetList[i]);
1410 X11DRV_RegisterClipboardFormat(lpName);
1412 lpFormat = X11DRV_CLIPBOARD_LookupProperty(targetList[i]);
1416 ERR("Failed to cache %s property\n", lpName);
1423 TRACE("Atom#%d Property(%d): --> FormatID(%d) %s\n",
1424 i, lpFormat->drvData, lpFormat->wFormatID, lpFormat->Name);
1426 X11DRV_CLIPBOARD_InsertClipboardData(lpFormat->wFormatID, 0, 0, 0);
1430 /* Free the list of targets */
1431 TSXFree(targetList);
1434 return cSelectionTargets;
1438 /**************************************************************************
1439 * X11DRV_CLIPBOARD_ReadClipboardData
1441 * This method is invoked only when we DO NOT own the X selection
1443 * We always get the data from the selection client each time,
1444 * since we have no way of determining if the data in our cache is stale.
1446 static BOOL X11DRV_CLIPBOARD_ReadClipboardData(UINT wFormat)
1448 Display *display = thread_display();
1452 HWND hWndClipWindow = GetOpenClipboardWindow();
1453 HWND hWnd = (hWndClipWindow) ? hWndClipWindow : GetActiveWindow();
1455 LPWINE_CLIPFORMAT lpFormat;
1457 TRACE("%d\n", wFormat);
1459 if (!selectionAcquired)
1461 Window w = X11DRV_get_whole_window(GetAncestor(hWnd, GA_ROOT));
1464 FIXME("No parent win found %p %p\n", hWnd, hWndClipWindow);
1468 lpFormat = X11DRV_CLIPBOARD_LookupFormat(wFormat);
1470 if (lpFormat->drvData)
1476 TRACE("Requesting %s selection (%d) from win(%08x)\n",
1477 lpFormat->Name, lpFormat->drvData, (UINT)selectionCacheSrc);
1480 XConvertSelection(display, selectionCacheSrc, lpFormat->drvData,
1481 xaSelectionData, w, CurrentTime);
1482 wine_tsx11_unlock();
1484 /* wait until SelectionNotify is received */
1485 for (i = 0; i < SELECTION_RETRIES; i++)
1488 res = XCheckTypedWindowEvent(display, w, SelectionNotify, &xe);
1489 wine_tsx11_unlock();
1490 if (res && xe.xselection.selection == selectionCacheSrc) break;
1492 usleep(SELECTION_WAIT);
1495 /* If the property wasn't available check for aliases */
1496 if (xe.xselection.property == None &&
1497 (alias = X11DRV_CLIPBOARD_LookupPropertyAlias(lpFormat->drvData)))
1500 XConvertSelection(display, selectionCacheSrc, alias,
1501 xaSelectionData, w, CurrentTime);
1502 wine_tsx11_unlock();
1504 /* wait until SelectionNotify is received */
1505 for (i = 0; i < SELECTION_RETRIES; i++)
1508 res = XCheckTypedWindowEvent(display, w, SelectionNotify, &xe);
1509 wine_tsx11_unlock();
1510 if (res && xe.xselection.selection == selectionCacheSrc) break;
1512 usleep(SELECTION_WAIT);
1516 /* Verify that the selection returned a valid TARGETS property */
1517 if (xe.xselection.property != None)
1520 * Read the contents of the X selection property
1521 * into WINE's clipboard cache converting the
1522 * selection to be compatible if possible.
1524 bRet = X11DRV_CLIPBOARD_ReadSelection(lpFormat, xe.xselection.requestor,
1525 xe.xselection.property);
1531 ERR("Received request to cache selection data but process is owner\n");
1534 TRACE("Returning %d\n", bRet);
1540 /**************************************************************************
1541 * X11DRV_CLIPBOARD_ReadSelection
1542 * Reads the contents of the X selection property into the WINE clipboard cache
1543 * converting the selection into a format compatible with the windows clipboard
1545 * This method is invoked only to read the contents of a the selection owned
1546 * by an external application. i.e. when we do not own the X selection.
1548 static BOOL X11DRV_CLIPBOARD_ReadSelection(LPWINE_CLIPFORMAT lpData, Window w, Atom prop)
1550 Display *display = thread_display();
1551 Atom atype=AnyPropertyType;
1553 unsigned long total,nitems,remain,itemSize,val_cnt;
1554 long lRequestLength,bwc;
1556 unsigned char* buffer;
1562 TRACE("Reading X selection type %s\n", lpData->Name);
1565 * First request a zero length in order to figure out the request size.
1567 if(TSXGetWindowProperty(display,w,prop,0,0,False, AnyPropertyType,
1568 &atype, &aformat, &nitems, &itemSize, &val) != Success)
1570 WARN("Failed to get property size\n");
1574 /* Free zero length return data if any */
1581 TRACE("Retrieving %ld bytes\n", itemSize * aformat/8);
1583 lRequestLength = (itemSize * aformat/8)/4 + 1;
1586 /* Read property in 4K blocks */
1587 if (TSXGetWindowProperty(display,w,prop,0,4096,False, AnyPropertyType/*reqType*/,
1588 &atype, &aformat, &nitems, &remain, &buffer) != Success)
1590 WARN("Failed to read property\n");
1594 val = (char*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nitems*bwc);
1595 memcpy(val,buffer,nitems*bwc);
1599 for (total = nitems*bwc, val_cnt = 0; remain;)
1601 val_cnt +=nitems*bwc;
1602 if (TSXGetWindowProperty(display, w, prop, (total / 4), 4096, False,
1603 AnyPropertyType, &atype, &aformat, &nitems, &remain, &buffer) != Success)
1605 WARN("Failed to read property\n");
1606 HeapFree(GetProcessHeap(), 0, val);
1610 total += nitems*bwc;
1611 HeapReAlloc(GetProcessHeap(),0,val, total);
1612 memcpy(&val[val_cnt], buffer, nitems*(aformat/8));
1616 bRet = X11DRV_CLIPBOARD_InsertClipboardData(lpData->wFormatID, 0, lpData->lpDrvImportFunc(val, total), 0);
1618 /* Delete the property on the window now that we are done
1619 * This will send a PropertyNotify event to the selection owner. */
1620 TSXDeleteProperty(display,w,prop);
1622 /* Free the retrieved property data */
1623 HeapFree(GetProcessHeap(),0,val);
1629 /**************************************************************************
1630 * CLIPBOARD_SerializeMetafile
1632 static HANDLE X11DRV_CLIPBOARD_SerializeMetafile(INT wformat, HANDLE hdata, LPDWORD lpcbytes, BOOL out)
1636 TRACE(" wFormat=%d hdata=%08x out=%d\n", wformat, (unsigned int) hdata, out);
1638 if (out) /* Serialize out, caller should free memory */
1640 *lpcbytes = 0; /* Assume failure */
1642 if (wformat == CF_METAFILEPICT)
1644 LPMETAFILEPICT lpmfp = (LPMETAFILEPICT) GlobalLock(hdata);
1645 int size = GetMetaFileBitsEx(lpmfp->hMF, 0, NULL);
1647 h = GlobalAlloc(0, size + sizeof(METAFILEPICT));
1650 char *pdata = GlobalLock(h);
1652 memcpy(pdata, lpmfp, sizeof(METAFILEPICT));
1653 GetMetaFileBitsEx(lpmfp->hMF, size, pdata + sizeof(METAFILEPICT));
1655 *lpcbytes = size + sizeof(METAFILEPICT);
1660 GlobalUnlock(hdata);
1662 else if (wformat == CF_ENHMETAFILE)
1664 int size = GetEnhMetaFileBits(hdata, 0, NULL);
1666 h = GlobalAlloc(0, size);
1669 LPVOID pdata = GlobalLock(h);
1671 GetEnhMetaFileBits(hdata, size, pdata);
1680 if (wformat == CF_METAFILEPICT)
1682 h = GlobalAlloc(0, sizeof(METAFILEPICT));
1685 LPMETAFILEPICT pmfp = (LPMETAFILEPICT) GlobalLock(h);
1687 memcpy(pmfp, (LPVOID)hdata, sizeof(METAFILEPICT));
1688 pmfp->hMF = SetMetaFileBitsEx(*lpcbytes - sizeof(METAFILEPICT),
1689 (char *)hdata + sizeof(METAFILEPICT));
1694 else if (wformat == CF_ENHMETAFILE)
1696 h = SetEnhMetaFileBits(*lpcbytes, (LPVOID)hdata);
1704 /**************************************************************************
1705 * X11DRV_CLIPBOARD_ReleaseSelection
1707 * Release an XA_PRIMARY or XA_CLIPBOARD selection that we own, in response
1708 * to a SelectionClear event.
1709 * This can occur in response to another client grabbing the X selection.
1710 * If the XA_CLIPBOARD selection is lost, we relinquish XA_PRIMARY as well.
1712 void X11DRV_CLIPBOARD_ReleaseSelection(Atom selType, Window w, HWND hwnd)
1714 Display *display = thread_display();
1716 /* w is the window that lost the selection
1718 TRACE("event->window = %08x (selectionWindow = %08x) selectionAcquired=0x%08x\n",
1719 (unsigned)w, (unsigned)selectionWindow, (unsigned)selectionAcquired);
1721 if (selectionAcquired)
1723 if (w == selectionWindow)
1725 /* If we're losing the CLIPBOARD selection, or if the preferences in .winerc
1726 * dictate that *all* selections should be cleared on loss of a selection,
1727 * we must give up all the selections we own.
1729 if (clearAllSelections || (selType == xaClipboard))
1731 CLIPBOARDINFO cbinfo;
1733 /* completely give up the selection */
1734 TRACE("Lost CLIPBOARD (+PRIMARY) selection\n");
1736 /* We are completely giving up the selection. There is a
1737 * potential race condition where the apps that now owns
1738 * the selection has already grabbed both selections. In
1739 * this case, if we clear any selection we may clear the
1740 * new owners selection. To prevent this common case we
1741 * try to open the clipboard. If we can't, we assume it
1742 * was a wine apps that took it and has taken both selections.
1743 * In this case, don't bother releasing the other selection.
1744 * Otherwise only release the selection if we still own it.
1746 X11DRV_CLIPBOARD_GetClipboardInfo(&cbinfo);
1748 if (cbinfo.flags & CB_OWNER)
1750 /* Since we're still the owner, this wasn't initiated by
1751 another Wine process */
1752 if (OpenClipboard(hwnd))
1754 /* We really lost CLIPBOARD but want to voluntarily lose PRIMARY */
1755 if ((selType == xaClipboard) && (selectionAcquired & S_PRIMARY))
1757 TRACE("Lost clipboard. Check if we need to release PRIMARY\n");
1758 if (selectionWindow == TSXGetSelectionOwner(display,XA_PRIMARY))
1760 TRACE("We still own PRIMARY. Releasing PRIMARY.\n");
1761 XSetSelectionOwner(display, XA_PRIMARY, None, CurrentTime);
1764 TRACE("We no longer own PRIMARY\n");
1767 /* We really lost PRIMARY but want to voluntarily lose CLIPBOARD */
1768 if ((selType == XA_PRIMARY) && (selectionAcquired & S_CLIPBOARD))
1770 TRACE("Lost PRIMARY. Check if we need to release CLIPBOARD\n");
1771 if (selectionWindow == TSXGetSelectionOwner(display,xaClipboard))
1773 TRACE("We still own CLIPBOARD. Releasing CLIPBOARD.\n");
1774 XSetSelectionOwner(display, xaClipboard, None, CurrentTime);
1777 TRACE("We no longer own CLIPBOARD\n");
1780 /* Destroy private objects */
1781 SendMessageW(cbinfo.hWndOwner, WM_DESTROYCLIPBOARD, 0, 0);
1783 /* Give up ownership of the windows clipboard */
1784 X11DRV_CLIPBOARD_ReleaseOwnership();
1791 TRACE("Lost selection to other Wine process.\n");
1794 selectionWindow = None;
1795 PrimarySelectionOwner = ClipboardSelectionOwner = 0;
1797 X11DRV_EmptyClipboard();
1799 /* Reset the selection flags now that we are done */
1800 selectionAcquired = S_NOSELECTION;
1802 else if ( selType == XA_PRIMARY ) /* Give up only PRIMARY selection */
1804 TRACE("Lost PRIMARY selection\n");
1805 PrimarySelectionOwner = 0;
1806 selectionAcquired &= ~S_PRIMARY; /* clear S_PRIMARY mask */
1813 /**************************************************************************
1814 * IsSelectionOwner (X11DRV.@)
1816 * Returns: TRUE if the selection is owned by this process, FALSE otherwise
1818 static BOOL X11DRV_CLIPBOARD_IsSelectionOwner(void)
1820 return selectionAcquired;
1824 /**************************************************************************
1825 * X11DRV Clipboard Exports
1826 **************************************************************************/
1829 /**************************************************************************
1830 * RegisterClipboardFormat (X11DRV.@)
1832 * Registers a custom X clipboard format
1833 * Returns: Format id or 0 on failure
1835 INT X11DRV_RegisterClipboardFormat(LPCSTR FormatName)
1837 LPWINE_CLIPFORMAT lpFormat = ClipFormats;
1839 if (FormatName == NULL)
1842 TRACE("('%s') !\n", FormatName);
1844 /* walk format chain to see if it's already registered */
1847 if ( !strcasecmp(lpFormat->Name, FormatName) &&
1848 (lpFormat->wFlags & CF_FLAG_BUILTINFMT) == 0)
1849 return lpFormat->wFormatID;
1851 if (!lpFormat->NextFormat)
1854 lpFormat = lpFormat->NextFormat;
1857 return X11DRV_CLIPBOARD_InsertClipboardFormat(FormatName, FormatName);
1861 /**************************************************************************
1862 * X11DRV_GetClipboardFormatName
1864 INT X11DRV_GetClipboardFormatName(UINT wFormat, LPSTR retStr, INT maxlen)
1867 LPWINE_CLIPFORMAT lpFormat = X11DRV_CLIPBOARD_LookupFormat(wFormat);
1869 TRACE("(%04X, %p, %d) !\n", wFormat, retStr, maxlen);
1871 if (!lpFormat || (lpFormat->wFlags & CF_FLAG_BUILTINFMT))
1873 TRACE("Unknown format 0x%08x!\n", wFormat);
1874 SetLastError(ERROR_INVALID_PARAMETER);
1878 strncpy(retStr, lpFormat->Name, maxlen - 1);
1879 retStr[maxlen - 1] = 0;
1881 len = strlen(retStr);
1888 /**************************************************************************
1889 * AcquireClipboard (X11DRV.@)
1891 void X11DRV_AcquireClipboard(HWND hWndClipWindow)
1893 Display *display = thread_display();
1896 * Acquire X selection if we don't already own it.
1897 * Note that we only acquire the selection if it hasn't been already
1898 * acquired by us, and ignore the fact that another X window may be
1899 * asserting ownership. The reason for this is we need *any* top level
1900 * X window to hold selection ownership. The actual clipboard data requests
1901 * are made via GetClipboardData from EVENT_SelectionRequest and this
1902 * ensures that the real HWND owner services the request.
1903 * If the owning X window gets destroyed the selection ownership is
1904 * re-cycled to another top level X window in X11DRV_CLIPBOARD_ResetOwner.
1907 if (!(selectionAcquired == (S_PRIMARY | S_CLIPBOARD)))
1911 if (!hWndClipWindow)
1912 hWndClipWindow = GetActiveWindow();
1914 owner = X11DRV_get_whole_window(GetAncestor(hWndClipWindow, GA_ROOT));
1916 /* Grab PRIMARY selection if not owned */
1917 if (!(selectionAcquired & S_PRIMARY))
1918 TSXSetSelectionOwner(display, XA_PRIMARY, owner, CurrentTime);
1920 /* Grab CLIPBOARD selection if not owned */
1921 if (!(selectionAcquired & S_CLIPBOARD))
1922 TSXSetSelectionOwner(display, xaClipboard, owner, CurrentTime);
1924 if (TSXGetSelectionOwner(display,XA_PRIMARY) == owner)
1925 selectionAcquired |= S_PRIMARY;
1927 if (TSXGetSelectionOwner(display,xaClipboard) == owner)
1928 selectionAcquired |= S_CLIPBOARD;
1930 if (selectionAcquired)
1932 selectionWindow = owner;
1933 TRACE("Grabbed X selection, owner=(%08x)\n", (unsigned) owner);
1938 WARN("Received request to acquire selection but process is already owner=(%08x)\n", (unsigned) selectionWindow);
1940 selectionAcquired = S_NOSELECTION;
1942 if (TSXGetSelectionOwner(display,XA_PRIMARY) == selectionWindow)
1943 selectionAcquired |= S_PRIMARY;
1945 if (TSXGetSelectionOwner(display,xaClipboard) == selectionWindow)
1946 selectionAcquired |= S_CLIPBOARD;
1948 if (!(selectionAcquired == (S_PRIMARY | S_CLIPBOARD)))
1950 WARN("Lost selection but process didn't process SelectClear\n");
1951 selectionWindow = None;
1957 /**************************************************************************
1958 * X11DRV_EmptyClipboard
1960 void X11DRV_EmptyClipboard(void)
1964 LPWINE_CLIPDATA lpData;
1965 LPWINE_CLIPDATA lpNext = ClipData;
1970 lpNext = lpData->NextData;
1971 lpData->PrevData->NextData = lpData->NextData;
1972 lpData->NextData->PrevData = lpData->PrevData;
1973 X11DRV_CLIPBOARD_FreeData(lpData);
1974 HeapFree(GetProcessHeap(), 0, lpData);
1975 } while (lpNext != lpData);
1978 TRACE(" %d entries deleted from cache.\n", ClipDataCount);
1986 /**************************************************************************
1987 * X11DRV_SetClipboardData
1989 BOOL X11DRV_SetClipboardData(UINT wFormat, HANDLE16 hData16, HANDLE hData32)
1991 BOOL bResult = FALSE;
1993 if (X11DRV_CLIPBOARD_InsertClipboardData(wFormat, hData16, hData32, 0))
2000 /**************************************************************************
2001 * CountClipboardFormats
2003 INT X11DRV_CountClipboardFormats(void)
2005 CLIPBOARDINFO cbinfo;
2007 X11DRV_CLIPBOARD_UpdateCache(&cbinfo);
2009 TRACE(" count=%d\n", ClipDataCount);
2011 return ClipDataCount;
2015 /**************************************************************************
2016 * X11DRV_EnumClipboardFormats
2018 UINT X11DRV_EnumClipboardFormats(UINT wFormat)
2020 CLIPBOARDINFO cbinfo;
2021 UINT wNextFormat = 0;
2023 TRACE("(%04X)\n", wFormat);
2025 X11DRV_CLIPBOARD_UpdateCache(&cbinfo);
2030 wNextFormat = ClipData->wFormatID;
2034 LPWINE_CLIPDATA lpData = X11DRV_CLIPBOARD_LookupData(wFormat);
2036 if (lpData && lpData->NextData != ClipData)
2037 wNextFormat = lpData->NextData->wFormatID;
2044 /**************************************************************************
2045 * X11DRV_IsClipboardFormatAvailable
2047 BOOL X11DRV_IsClipboardFormatAvailable(UINT wFormat)
2050 CLIPBOARDINFO cbinfo;
2052 TRACE("(%04X)\n", wFormat);
2054 X11DRV_CLIPBOARD_UpdateCache(&cbinfo);
2056 if (wFormat != 0 && X11DRV_CLIPBOARD_LookupData(wFormat))
2059 TRACE("(%04X)- ret(%d)\n", wFormat, bRet);
2065 /**************************************************************************
2066 * GetClipboardData (USER.142)
2068 BOOL X11DRV_GetClipboardData(UINT wFormat, HANDLE16* phData16, HANDLE* phData32)
2070 CLIPBOARDINFO cbinfo;
2071 LPWINE_CLIPDATA lpRender;
2073 TRACE("(%04X)\n", wFormat);
2075 X11DRV_CLIPBOARD_UpdateCache(&cbinfo);
2077 if ((lpRender = X11DRV_CLIPBOARD_LookupData(wFormat)))
2079 if ( !lpRender->hData32 )
2080 X11DRV_CLIPBOARD_RenderFormat(lpRender);
2082 /* Convert between 32 -> 16 bit data, if necessary */
2083 if (lpRender->hData32 && !lpRender->hData16)
2087 if (lpRender->wFormatID == CF_METAFILEPICT)
2088 size = sizeof(METAFILEPICT16);
2090 size = GlobalSize(lpRender->hData32);
2092 lpRender->hData16 = GlobalAlloc16(GMEM_ZEROINIT, size);
2094 if (!lpRender->hData16)
2095 ERR("(%04X) -- not enough memory in 16b heap\n", wFormat);
2098 if (lpRender->wFormatID == CF_METAFILEPICT)
2100 FIXME("\timplement function CopyMetaFilePict32to16\n");
2101 FIXME("\tin the appropriate file.\n");
2102 #ifdef SOMEONE_IMPLEMENTED_ME
2103 CopyMetaFilePict32to16(GlobalLock16(lpRender->hData16),
2104 GlobalLock(lpRender->hData32));
2109 memcpy(GlobalLock16(lpRender->hData16),
2110 GlobalLock(lpRender->hData32), size);
2113 GlobalUnlock16(lpRender->hData16);
2114 GlobalUnlock(lpRender->hData32);
2118 /* Convert between 32 -> 16 bit data, if necessary */
2119 if (lpRender->hData16 && !lpRender->hData32)
2123 if (lpRender->wFormatID == CF_METAFILEPICT)
2124 size = sizeof(METAFILEPICT16);
2126 size = GlobalSize(lpRender->hData32);
2128 lpRender->hData32 = GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE |
2129 GMEM_DDESHARE, size);
2131 if (lpRender->wFormatID == CF_METAFILEPICT)
2133 FIXME("\timplement function CopyMetaFilePict16to32\n");
2134 FIXME("\tin the appropriate file.\n");
2135 #ifdef SOMEONE_IMPLEMENTED_ME
2136 CopyMetaFilePict16to32(GlobalLock16(lpRender->hData32),
2137 GlobalLock(lpRender->hData16));
2142 memcpy(GlobalLock(lpRender->hData32),
2143 GlobalLock16(lpRender->hData16), size);
2146 GlobalUnlock(lpRender->hData32);
2147 GlobalUnlock16(lpRender->hData16);
2151 *phData16 = lpRender->hData16;
2154 *phData32 = lpRender->hData32;
2156 TRACE(" returning hData16(%04x) hData32(%04x) (type %d)\n",
2157 lpRender->hData16, (unsigned int) lpRender->hData32, lpRender->wFormatID);
2159 return lpRender->hData16 || lpRender->hData32;
2166 /**************************************************************************
2167 * ResetSelectionOwner (X11DRV.@)
2169 * Called from DestroyWindow() to prevent X selection from being lost when
2170 * a top level window is destroyed, by switching ownership to another top
2172 * Any top level window can own the selection. See X11DRV_CLIPBOARD_Acquire
2173 * for a more detailed description of this.
2175 void X11DRV_ResetSelectionOwner(HWND hwnd, BOOL bFooBar)
2177 Display *display = thread_display();
2178 HWND hWndClipOwner = 0;
2180 Window XWnd = X11DRV_get_whole_window(hwnd);
2181 BOOL bLostSelection = FALSE;
2182 Window selectionPrevWindow;
2184 /* There is nothing to do if we don't own the selection,
2185 * or if the X window which currently owns the selection is different
2186 * from the one passed in.
2188 if (!selectionAcquired || XWnd != selectionWindow
2189 || selectionWindow == None )
2192 if ((bFooBar && XWnd) || (!bFooBar && !XWnd))
2195 hWndClipOwner = GetClipboardOwner();
2197 TRACE("clipboard owner = %p, selection window = %08x\n",
2198 hWndClipOwner, (unsigned)selectionWindow);
2200 /* now try to salvage current selection from being destroyed by X */
2201 TRACE("checking %08x\n", (unsigned) XWnd);
2203 selectionPrevWindow = selectionWindow;
2204 selectionWindow = None;
2206 if (!(tmp = GetWindow(hwnd, GW_HWNDNEXT)))
2207 tmp = GetWindow(hwnd, GW_HWNDFIRST);
2209 if (tmp && tmp != hwnd)
2210 selectionWindow = X11DRV_get_whole_window(tmp);
2212 if (selectionWindow != None)
2214 /* We must pretend that we don't own the selection while making the switch
2215 * since a SelectionClear event will be sent to the last owner.
2216 * If there is no owner X11DRV_CLIPBOARD_ReleaseSelection will do nothing.
2218 int saveSelectionState = selectionAcquired;
2219 selectionAcquired = S_NOSELECTION;
2221 TRACE("\tswitching selection from %08x to %08x\n",
2222 (unsigned)selectionPrevWindow, (unsigned)selectionWindow);
2224 /* Assume ownership for the PRIMARY and CLIPBOARD selection */
2225 if (saveSelectionState & S_PRIMARY)
2226 TSXSetSelectionOwner(display, XA_PRIMARY, selectionWindow, CurrentTime);
2228 TSXSetSelectionOwner(display, xaClipboard, selectionWindow, CurrentTime);
2230 /* Restore the selection masks */
2231 selectionAcquired = saveSelectionState;
2233 /* Lose the selection if something went wrong */
2234 if (((saveSelectionState & S_PRIMARY) &&
2235 (TSXGetSelectionOwner(display, XA_PRIMARY) != selectionWindow)) ||
2236 (TSXGetSelectionOwner(display, xaClipboard) != selectionWindow))
2238 bLostSelection = TRUE;
2242 /* Update selection state */
2243 if (saveSelectionState & S_PRIMARY)
2244 PrimarySelectionOwner = selectionWindow;
2246 ClipboardSelectionOwner = selectionWindow;
2251 bLostSelection = TRUE;
2256 TRACE("Lost the selection!\n");
2258 X11DRV_CLIPBOARD_ReleaseOwnership();
2259 selectionAcquired = S_NOSELECTION;
2260 ClipboardSelectionOwner = PrimarySelectionOwner = 0;
2261 selectionWindow = 0;
2266 /**************************************************************************
2267 * X11DRV_CLIPBOARD_SynthesizeData
2269 static BOOL X11DRV_CLIPBOARD_SynthesizeData(UINT wFormatID)
2272 LPWINE_CLIPDATA lpSource = NULL;
2274 TRACE(" %d\n", wFormatID);
2276 /* Don't need to synthesize if it already exists */
2277 if (X11DRV_CLIPBOARD_LookupData(wFormatID))
2280 if (wFormatID == CF_UNICODETEXT || wFormatID == CF_TEXT || wFormatID == CF_OEMTEXT)
2282 bsyn = ((lpSource = X11DRV_CLIPBOARD_LookupData(CF_UNICODETEXT)) &&
2283 ~lpSource->wFlags & CF_FLAG_SYNTHESIZED) ||
2284 ((lpSource = X11DRV_CLIPBOARD_LookupData(CF_TEXT)) &&
2285 ~lpSource->wFlags & CF_FLAG_SYNTHESIZED) ||
2286 ((lpSource = X11DRV_CLIPBOARD_LookupData(CF_OEMTEXT)) &&
2287 ~lpSource->wFlags & CF_FLAG_SYNTHESIZED);
2289 else if (wFormatID == CF_ENHMETAFILE)
2291 bsyn = (lpSource = X11DRV_CLIPBOARD_LookupData(CF_METAFILEPICT)) &&
2292 ~lpSource->wFlags & CF_FLAG_SYNTHESIZED;
2294 else if (wFormatID == CF_METAFILEPICT)
2296 bsyn = (lpSource = X11DRV_CLIPBOARD_LookupData(CF_METAFILEPICT)) &&
2297 ~lpSource->wFlags & CF_FLAG_SYNTHESIZED;
2299 else if (wFormatID == CF_DIB)
2301 bsyn = (lpSource = X11DRV_CLIPBOARD_LookupData(CF_BITMAP)) &&
2302 ~lpSource->wFlags & CF_FLAG_SYNTHESIZED;
2304 else if (wFormatID == CF_BITMAP)
2306 bsyn = (lpSource = X11DRV_CLIPBOARD_LookupData(CF_DIB)) &&
2307 ~lpSource->wFlags & CF_FLAG_SYNTHESIZED;
2311 X11DRV_CLIPBOARD_InsertClipboardData(wFormatID, 0, 0, CF_FLAG_SYNTHESIZED);
2318 /**************************************************************************
2319 * X11DRV_EndClipboardUpdate
2321 * Add locale if it hasn't already been added
2323 void X11DRV_EndClipboardUpdate(void)
2325 INT count = ClipDataCount;
2327 /* Do Unicode <-> Text <-> OEM mapping */
2328 X11DRV_CLIPBOARD_SynthesizeData(CF_UNICODETEXT);
2329 X11DRV_CLIPBOARD_SynthesizeData(CF_TEXT);
2330 X11DRV_CLIPBOARD_SynthesizeData(CF_OEMTEXT);
2332 /* Enhmetafile <-> MetafilePict mapping */
2333 X11DRV_CLIPBOARD_SynthesizeData(CF_ENHMETAFILE);
2334 X11DRV_CLIPBOARD_SynthesizeData(CF_METAFILEPICT);
2336 /* DIB <-> Bitmap mapping */
2337 X11DRV_CLIPBOARD_SynthesizeData(CF_DIB);
2338 X11DRV_CLIPBOARD_SynthesizeData(CF_BITMAP);
2340 TRACE("%d formats added to cached data\n", ClipDataCount - count);