1998-12-07 10:13:40 +01:00
|
|
|
/*
|
1999-09-03 17:17:57 +02:00
|
|
|
* X11 clipboard windows driver
|
1998-12-07 10:13:40 +01:00
|
|
|
*
|
|
|
|
* Copyright 1994 Martin Ayotte
|
|
|
|
* 1996 Alex Korobka
|
1999-09-03 17:17:57 +02:00
|
|
|
* 1999 Noel Borthwick
|
2003-06-24 01:02:02 +02:00
|
|
|
* 2003 Ulrich Czekalla for CodeWeavers
|
1999-09-03 17:17:57 +02:00
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
1999-09-03 17:17:57 +02:00
|
|
|
* NOTES:
|
|
|
|
* This file contains the X specific implementation for the windows
|
|
|
|
* Clipboard API.
|
|
|
|
*
|
|
|
|
* Wine's internal clipboard is exposed to external apps via the X
|
|
|
|
* selection mechanism.
|
|
|
|
* Currently the driver asserts ownership via two selection atoms:
|
|
|
|
* 1. PRIMARY(XA_PRIMARY)
|
|
|
|
* 2. CLIPBOARD
|
|
|
|
*
|
2001-05-18 23:01:38 +02:00
|
|
|
* In our implementation, the CLIPBOARD selection takes precedence over PRIMARY,
|
1999-09-03 17:17:57 +02:00
|
|
|
* i.e. if a CLIPBOARD selection is available, it is used instead of PRIMARY.
|
2001-05-18 23:01:38 +02:00
|
|
|
* When Wine takes ownership of the clipboard, it takes ownership of BOTH selections.
|
1999-09-03 17:17:57 +02:00
|
|
|
* While giving up selection ownership, if the CLIPBOARD selection is lost,
|
|
|
|
* it will lose both PRIMARY and CLIPBOARD and empty the clipboard.
|
|
|
|
* However if only PRIMARY is lost, it will continue to hold the CLIPBOARD selection
|
|
|
|
* (leaving the clipboard cache content unaffected).
|
|
|
|
*
|
|
|
|
* Every format exposed via a windows clipboard format is also exposed through
|
|
|
|
* a corresponding X selection target. A selection target atom is synthesized
|
|
|
|
* whenever a new Windows clipboard format is registered via RegisterClipboardFormat,
|
2001-05-18 23:01:38 +02:00
|
|
|
* or when a built-in format is used for the first time.
|
1999-09-03 17:17:57 +02:00
|
|
|
* Windows native format are exposed by prefixing the format name with "<WCF>"
|
|
|
|
* This allows us to uniquely identify windows native formats exposed by other
|
|
|
|
* running WINE apps.
|
|
|
|
*
|
|
|
|
* In order to allow external applications to query WINE for supported formats,
|
|
|
|
* we respond to the "TARGETS" selection target. (See EVENT_SelectionRequest
|
|
|
|
* for implementation) We use the same mechanism to query external clients for
|
2001-05-18 23:01:38 +02:00
|
|
|
* availability of a particular format, by caching the list of available targets
|
1999-09-03 17:17:57 +02:00
|
|
|
* by using the clipboard cache's "delayed render" mechanism. If a selection client
|
|
|
|
* does not support the "TARGETS" selection target, we actually attempt to retrieve
|
|
|
|
* the format requested as a fallback mechanism.
|
|
|
|
*
|
|
|
|
* Certain Windows native formats are automatically converted to X native formats
|
|
|
|
* and vice versa. If a native format is available in the selection, it takes
|
|
|
|
* precedence, in order to avoid unnecessary conversions.
|
|
|
|
*
|
2003-11-21 06:23:17 +01:00
|
|
|
* FIXME: global format list needs a critical section
|
1998-12-07 10:13:40 +01:00
|
|
|
*/
|
|
|
|
|
2001-11-06 21:57:11 +01:00
|
|
|
#include "config.h"
|
2003-12-04 06:11:56 +01:00
|
|
|
#include "wine/port.h"
|
1998-12-07 10:13:40 +01:00
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
#include <string.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2000-02-10 20:03:02 +01:00
|
|
|
#include <stdio.h>
|
2000-11-01 04:11:12 +01:00
|
|
|
#include <stdlib.h>
|
2002-08-17 02:43:16 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
1999-11-07 06:12:43 +01:00
|
|
|
#include <fcntl.h>
|
2008-03-26 12:14:41 +01:00
|
|
|
#include <limits.h>
|
2002-08-27 21:19:49 +02:00
|
|
|
#include <time.h>
|
2005-11-01 19:05:40 +01:00
|
|
|
#include <assert.h>
|
1999-10-24 22:22:24 +02:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
1998-12-07 10:13:40 +01:00
|
|
|
#include "x11drv.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2003-06-24 01:02:02 +02:00
|
|
|
#include "wine/unicode.h"
|
|
|
|
#include "wine/server.h"
|
1998-12-07 10:13:40 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(clipboard);
|
1999-04-19 16:56:29 +02:00
|
|
|
|
2003-07-08 23:02:51 +02:00
|
|
|
/* Maximum wait time for selection notify */
|
2003-06-24 01:02:02 +02:00
|
|
|
#define SELECTION_RETRIES 500 /* wait for .1 seconds */
|
|
|
|
#define SELECTION_WAIT 1000 /* us */
|
2003-07-08 23:02:51 +02:00
|
|
|
/* Minimum seconds that must lapse between owner queries */
|
2003-06-24 01:02:02 +02:00
|
|
|
#define OWNERQUERYLAPSETIME 1
|
2002-08-27 21:19:49 +02:00
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
/* Selection masks */
|
|
|
|
#define S_NOSELECTION 0
|
|
|
|
#define S_PRIMARY 1
|
|
|
|
#define S_CLIPBOARD 2
|
|
|
|
|
2003-12-05 05:45:50 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
HWND hWndOpen;
|
|
|
|
HWND hWndOwner;
|
|
|
|
HWND hWndViewer;
|
|
|
|
UINT seqno;
|
|
|
|
UINT flags;
|
|
|
|
} CLIPBOARDINFO, *LPCLIPBOARDINFO;
|
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
struct tagWINE_CLIPDATA; /* Forward */
|
2005-02-25 22:01:15 +01:00
|
|
|
|
2008-06-26 16:20:02 +02:00
|
|
|
typedef HANDLE (*DRVEXPORTFUNC)(Display *display, Window requestor, Atom aTarget, Atom rprop,
|
2005-11-01 19:05:40 +01:00
|
|
|
struct tagWINE_CLIPDATA* lpData, LPDWORD lpBytes);
|
2008-06-26 16:20:02 +02:00
|
|
|
typedef HANDLE (*DRVIMPORTFUNC)(Display *d, Window w, Atom prop);
|
2005-02-25 22:01:15 +01:00
|
|
|
|
|
|
|
typedef struct tagWINE_CLIPFORMAT {
|
|
|
|
UINT wFormatID;
|
|
|
|
LPCWSTR Name;
|
|
|
|
UINT drvData;
|
|
|
|
UINT wFlags;
|
|
|
|
DRVIMPORTFUNC lpDrvImportFunc;
|
|
|
|
DRVEXPORTFUNC lpDrvExportFunc;
|
|
|
|
struct tagWINE_CLIPFORMAT *PrevFormat;
|
|
|
|
struct tagWINE_CLIPFORMAT *NextFormat;
|
|
|
|
} WINE_CLIPFORMAT, *LPWINE_CLIPFORMAT;
|
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
typedef struct tagWINE_CLIPDATA {
|
|
|
|
UINT wFormatID;
|
2009-12-22 21:18:40 +01:00
|
|
|
HANDLE hData;
|
2005-11-01 19:05:40 +01:00
|
|
|
UINT wFlags;
|
|
|
|
UINT drvData;
|
|
|
|
LPWINE_CLIPFORMAT lpFormat;
|
|
|
|
struct tagWINE_CLIPDATA *PrevData;
|
|
|
|
struct tagWINE_CLIPDATA *NextData;
|
|
|
|
} WINE_CLIPDATA, *LPWINE_CLIPDATA;
|
|
|
|
|
|
|
|
#define CF_FLAG_BUILTINFMT 0x0001 /* Built-in windows format */
|
|
|
|
#define CF_FLAG_UNOWNED 0x0002 /* cached data is not owned */
|
|
|
|
#define CF_FLAG_SYNTHESIZED 0x0004 /* Implicitly converted data */
|
|
|
|
#define CF_FLAG_UNICODE 0x0008 /* Data is in unicode */
|
2005-02-25 22:01:15 +01:00
|
|
|
|
1999-10-24 22:22:24 +02:00
|
|
|
static int selectionAcquired = 0; /* Contains the current selection masks */
|
1999-09-03 17:17:57 +02:00
|
|
|
static Window selectionWindow = None; /* The top level X window which owns the selection */
|
2003-06-24 01:02:02 +02:00
|
|
|
static Atom selectionCacheSrc = XA_PRIMARY; /* The selection source from which the clipboard cache was filled */
|
1998-12-07 10:13:40 +01:00
|
|
|
|
2008-12-16 15:32:08 +01:00
|
|
|
void CDECL X11DRV_EmptyClipboard(BOOL keepunowned);
|
|
|
|
void CDECL X11DRV_EndClipboardUpdate(void);
|
2008-06-26 16:20:02 +02:00
|
|
|
static HANDLE X11DRV_CLIPBOARD_ImportClipboardData(Display *d, Window w, Atom prop);
|
|
|
|
static HANDLE X11DRV_CLIPBOARD_ImportEnhMetaFile(Display *d, Window w, Atom prop);
|
|
|
|
static HANDLE X11DRV_CLIPBOARD_ImportMetaFilePict(Display *d, Window w, Atom prop);
|
|
|
|
static HANDLE X11DRV_CLIPBOARD_ImportXAPIXMAP(Display *d, Window w, Atom prop);
|
2009-04-25 00:19:38 +02:00
|
|
|
static HANDLE X11DRV_CLIPBOARD_ImportImageBmp(Display *d, Window w, Atom prop);
|
2008-06-26 16:20:02 +02:00
|
|
|
static HANDLE X11DRV_CLIPBOARD_ImportXAString(Display *d, Window w, Atom prop);
|
|
|
|
static HANDLE X11DRV_CLIPBOARD_ImportUTF8(Display *d, Window w, Atom prop);
|
|
|
|
static HANDLE X11DRV_CLIPBOARD_ImportCompoundText(Display *d, Window w, Atom prop);
|
|
|
|
static HANDLE X11DRV_CLIPBOARD_ExportClipboardData(Display *display, Window requestor, Atom aTarget,
|
2003-07-08 23:02:51 +02:00
|
|
|
Atom rprop, LPWINE_CLIPDATA lpData, LPDWORD lpBytes);
|
2008-06-26 16:20:02 +02:00
|
|
|
static HANDLE X11DRV_CLIPBOARD_ExportString(Display *display, Window requestor, Atom aTarget,
|
2003-07-08 23:02:51 +02:00
|
|
|
Atom rprop, LPWINE_CLIPDATA lpData, LPDWORD lpBytes);
|
2008-06-26 16:20:02 +02:00
|
|
|
static HANDLE X11DRV_CLIPBOARD_ExportXAPIXMAP(Display *display, Window requestor, Atom aTarget,
|
2003-07-08 23:02:51 +02:00
|
|
|
Atom rprop, LPWINE_CLIPDATA lpdata, LPDWORD lpBytes);
|
2009-04-30 21:40:29 +02:00
|
|
|
static HANDLE X11DRV_CLIPBOARD_ExportImageBmp(Display *display, Window requestor, Atom aTarget,
|
|
|
|
Atom rprop, LPWINE_CLIPDATA lpdata, LPDWORD lpBytes);
|
2008-06-26 16:20:02 +02:00
|
|
|
static HANDLE X11DRV_CLIPBOARD_ExportMetaFilePict(Display *display, Window requestor, Atom aTarget,
|
2003-07-08 23:02:51 +02:00
|
|
|
Atom rprop, LPWINE_CLIPDATA lpdata, LPDWORD lpBytes);
|
2008-06-26 16:20:02 +02:00
|
|
|
static HANDLE X11DRV_CLIPBOARD_ExportEnhMetaFile(Display *display, Window requestor, Atom aTarget,
|
2003-07-08 23:02:51 +02:00
|
|
|
Atom rprop, LPWINE_CLIPDATA lpdata, LPDWORD lpBytes);
|
2009-11-22 21:30:18 +01:00
|
|
|
static HANDLE X11DRV_CLIPBOARD_ExportTextHtml(Display *display, Window requestor, Atom aTarget,
|
|
|
|
Atom rprop, LPWINE_CLIPDATA lpdata, LPDWORD lpBytes);
|
2005-01-11 16:10:56 +01:00
|
|
|
static WINE_CLIPFORMAT *X11DRV_CLIPBOARD_InsertClipboardFormat(LPCWSTR FormatName, Atom prop);
|
2008-06-26 16:20:02 +02:00
|
|
|
static BOOL X11DRV_CLIPBOARD_RenderSynthesizedText(Display *display, UINT wFormatID);
|
2003-06-24 01:02:02 +02:00
|
|
|
static void X11DRV_CLIPBOARD_FreeData(LPWINE_CLIPDATA lpData);
|
|
|
|
static BOOL X11DRV_CLIPBOARD_IsSelectionOwner(void);
|
2008-06-26 16:20:02 +02:00
|
|
|
static int X11DRV_CLIPBOARD_QueryAvailableData(Display *display, LPCLIPBOARDINFO lpcbinfo);
|
|
|
|
static BOOL X11DRV_CLIPBOARD_ReadSelectionData(Display *display, LPWINE_CLIPDATA lpData);
|
|
|
|
static BOOL X11DRV_CLIPBOARD_ReadProperty(Display *display, Window w, Atom prop,
|
2005-11-01 19:05:40 +01:00
|
|
|
unsigned char** data, unsigned long* datasize);
|
2008-06-26 16:20:02 +02:00
|
|
|
static BOOL X11DRV_CLIPBOARD_RenderFormat(Display *display, LPWINE_CLIPDATA lpData);
|
2003-06-24 01:02:02 +02:00
|
|
|
static HANDLE X11DRV_CLIPBOARD_SerializeMetafile(INT wformat, HANDLE hdata, LPDWORD lpcbytes, BOOL out);
|
|
|
|
static BOOL X11DRV_CLIPBOARD_SynthesizeData(UINT wFormatID);
|
2008-06-26 16:20:02 +02:00
|
|
|
static BOOL X11DRV_CLIPBOARD_RenderSynthesizedFormat(Display *display, LPWINE_CLIPDATA lpData);
|
|
|
|
static BOOL X11DRV_CLIPBOARD_RenderSynthesizedDIB(Display *display);
|
|
|
|
static BOOL X11DRV_CLIPBOARD_RenderSynthesizedBitmap(Display *display);
|
2005-02-25 22:01:15 +01:00
|
|
|
static void X11DRV_HandleSelectionRequest( HWND hWnd, XSelectionRequestEvent *event, BOOL bIsMultiple );
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
/* Clipboard formats
|
|
|
|
* WARNING: This data ordering is dependent on the WINE_CLIPFORMAT structure
|
|
|
|
* declared in clipboard.h
|
|
|
|
*/
|
2005-01-11 16:10:56 +01:00
|
|
|
static const WCHAR wszCF_TEXT[] = {'W','C','F','_','T','E','X','T',0};
|
|
|
|
static const WCHAR wszCF_BITMAP[] = {'W','C','F','_','B','I','T','M','A','P',0};
|
|
|
|
static const WCHAR wszCF_METAFILEPICT[] = {'W','C','F','_','M','E','T','A','F','I','L','E','P','I','C','T',0};
|
|
|
|
static const WCHAR wszCF_SYLK[] = {'W','C','F','_','S','Y','L','K',0};
|
|
|
|
static const WCHAR wszCF_DIF[] = {'W','C','F','_','D','I','F',0};
|
|
|
|
static const WCHAR wszCF_TIFF[] = {'W','C','F','_','T','I','F','F',0};
|
|
|
|
static const WCHAR wszCF_OEMTEXT[] = {'W','C','F','_','O','E','M','T','E','X','T',0};
|
|
|
|
static const WCHAR wszCF_DIB[] = {'W','C','F','_','D','I','B',0};
|
2009-04-25 00:19:38 +02:00
|
|
|
static const WCHAR wszIMAGEBMP[] = {'i','m','a','g','e','/','b','m','p',0};
|
2005-01-11 16:10:56 +01:00
|
|
|
static const WCHAR wszCF_PALETTE[] = {'W','C','F','_','P','A','L','E','T','T','E',0};
|
|
|
|
static const WCHAR wszCF_PENDATA[] = {'W','C','F','_','P','E','N','D','A','T','A',0};
|
|
|
|
static const WCHAR wszCF_RIFF[] = {'W','C','F','_','R','I','F','F',0};
|
|
|
|
static const WCHAR wszCF_WAVE[] = {'W','C','F','_','W','A','V','E',0};
|
2005-11-01 19:05:40 +01:00
|
|
|
static const WCHAR wszCOMPOUNDTEXT[] = {'C','O','M','P','O','U','N','D','_','T','E','X','T',0};
|
|
|
|
static const WCHAR wszUTF8STRING[] = {'U','T','F','8','_','S','T','R','I','N','G',0};
|
2005-01-11 16:10:56 +01:00
|
|
|
static const WCHAR wszCF_ENHMETAFILE[] = {'W','C','F','_','E','N','H','M','E','T','A','F','I','L','E',0};
|
|
|
|
static const WCHAR wszCF_HDROP[] = {'W','C','F','_','H','D','R','O','P',0};
|
|
|
|
static const WCHAR wszCF_LOCALE[] = {'W','C','F','_','L','O','C','A','L','E',0};
|
|
|
|
static const WCHAR wszCF_DIBV5[] = {'W','C','F','_','D','I','B','V','5',0};
|
|
|
|
static const WCHAR wszCF_OWNERDISPLAY[] = {'W','C','F','_','O','W','N','E','R','D','I','S','P','L','A','Y',0};
|
|
|
|
static const WCHAR wszCF_DSPTEXT[] = {'W','C','F','_','D','S','P','T','E','X','T',0};
|
|
|
|
static const WCHAR wszCF_DSPBITMAP[] = {'W','C','F','_','D','S','P','B','I','T','M','A','P',0};
|
|
|
|
static const WCHAR wszCF_DSPMETAFILEPICT[] = {'W','C','F','_','D','S','P','M','E','T','A','F','I','L','E','P','I','C','T',0};
|
|
|
|
static const WCHAR wszCF_DSPENHMETAFILE[] = {'W','C','F','_','D','S','P','E','N','H','M','E','T','A','F','I','L','E',0};
|
|
|
|
|
2003-11-20 05:24:18 +01:00
|
|
|
static WINE_CLIPFORMAT ClipFormats[] =
|
2000-01-26 03:21:30 +01:00
|
|
|
{
|
2005-11-01 19:05:40 +01:00
|
|
|
{ CF_TEXT, wszCF_TEXT, XA_STRING, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportXAString,
|
|
|
|
X11DRV_CLIPBOARD_ExportString, NULL, &ClipFormats[1]},
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-01-11 16:10:56 +01:00
|
|
|
{ CF_BITMAP, wszCF_BITMAP, 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
|
2004-02-20 06:43:00 +01:00
|
|
|
NULL, &ClipFormats[0], &ClipFormats[2]},
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-01-11 16:10:56 +01:00
|
|
|
{ CF_METAFILEPICT, wszCF_METAFILEPICT, 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportMetaFilePict,
|
2003-06-24 01:02:02 +02:00
|
|
|
X11DRV_CLIPBOARD_ExportMetaFilePict, &ClipFormats[1], &ClipFormats[3]},
|
|
|
|
|
2005-01-11 16:10:56 +01:00
|
|
|
{ CF_SYLK, wszCF_SYLK, 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
|
2003-06-24 01:02:02 +02:00
|
|
|
X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[2], &ClipFormats[4]},
|
|
|
|
|
2005-01-11 16:10:56 +01:00
|
|
|
{ CF_DIF, wszCF_DIF, 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
|
2003-06-24 01:02:02 +02:00
|
|
|
X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[3], &ClipFormats[5]},
|
|
|
|
|
2005-01-11 16:10:56 +01:00
|
|
|
{ CF_TIFF, wszCF_TIFF, 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
|
2003-06-24 01:02:02 +02:00
|
|
|
X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[4], &ClipFormats[6]},
|
|
|
|
|
2005-01-11 16:10:56 +01:00
|
|
|
{ CF_OEMTEXT, wszCF_OEMTEXT, 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
|
2003-06-24 01:02:02 +02:00
|
|
|
X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[5], &ClipFormats[7]},
|
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
{ CF_DIB, wszCF_DIB, XA_PIXMAP, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportXAPIXMAP,
|
2005-01-11 16:10:56 +01:00
|
|
|
X11DRV_CLIPBOARD_ExportXAPIXMAP, &ClipFormats[6], &ClipFormats[8]},
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-01-11 16:10:56 +01:00
|
|
|
{ CF_PALETTE, wszCF_PALETTE, 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
|
2003-06-24 01:02:02 +02:00
|
|
|
X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[7], &ClipFormats[9]},
|
|
|
|
|
2005-01-11 16:10:56 +01:00
|
|
|
{ CF_PENDATA, wszCF_PENDATA, 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
|
2003-06-24 01:02:02 +02:00
|
|
|
X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[8], &ClipFormats[10]},
|
|
|
|
|
2005-01-11 16:10:56 +01:00
|
|
|
{ CF_RIFF, wszCF_RIFF, 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
|
2003-06-24 01:02:02 +02:00
|
|
|
X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[9], &ClipFormats[11]},
|
1999-09-20 17:42:47 +02:00
|
|
|
|
2005-01-11 16:10:56 +01:00
|
|
|
{ CF_WAVE, wszCF_WAVE, 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
|
2003-06-24 01:02:02 +02:00
|
|
|
X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[10], &ClipFormats[12]},
|
1999-09-20 17:42:47 +02:00
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
{ CF_UNICODETEXT, wszUTF8STRING, 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportUTF8,
|
2005-01-11 16:10:56 +01:00
|
|
|
X11DRV_CLIPBOARD_ExportString, &ClipFormats[11], &ClipFormats[13]},
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
/* If UTF8_STRING is not available, attempt COMPUND_TEXT */
|
|
|
|
{ CF_UNICODETEXT, wszCOMPOUNDTEXT, 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportCompoundText,
|
|
|
|
X11DRV_CLIPBOARD_ExportString, &ClipFormats[12], &ClipFormats[14]},
|
|
|
|
|
2005-01-11 16:10:56 +01:00
|
|
|
{ CF_ENHMETAFILE, wszCF_ENHMETAFILE, 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportEnhMetaFile,
|
2005-11-01 19:05:40 +01:00
|
|
|
X11DRV_CLIPBOARD_ExportEnhMetaFile, &ClipFormats[13], &ClipFormats[15]},
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-01-11 16:10:56 +01:00
|
|
|
{ CF_HDROP, wszCF_HDROP, 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
|
2005-11-01 19:05:40 +01:00
|
|
|
X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[14], &ClipFormats[16]},
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-01-11 16:10:56 +01:00
|
|
|
{ CF_LOCALE, wszCF_LOCALE, 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
|
2005-11-01 19:05:40 +01:00
|
|
|
X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[15], &ClipFormats[17]},
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-01-11 16:10:56 +01:00
|
|
|
{ CF_DIBV5, wszCF_DIBV5, 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
|
2005-11-01 19:05:40 +01:00
|
|
|
X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[16], &ClipFormats[18]},
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-01-11 16:10:56 +01:00
|
|
|
{ CF_OWNERDISPLAY, wszCF_OWNERDISPLAY, 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
|
2005-11-01 19:05:40 +01:00
|
|
|
X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[17], &ClipFormats[19]},
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-01-11 16:10:56 +01:00
|
|
|
{ CF_DSPTEXT, wszCF_DSPTEXT, 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
|
2005-11-01 19:05:40 +01:00
|
|
|
X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[18], &ClipFormats[20]},
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-01-11 16:10:56 +01:00
|
|
|
{ CF_DSPBITMAP, wszCF_DSPBITMAP, 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
|
2005-11-01 19:05:40 +01:00
|
|
|
X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[19], &ClipFormats[21]},
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-01-11 16:10:56 +01:00
|
|
|
{ CF_DSPMETAFILEPICT, wszCF_DSPMETAFILEPICT, 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
|
2005-11-01 19:05:40 +01:00
|
|
|
X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[20], &ClipFormats[22]},
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-01-11 16:10:56 +01:00
|
|
|
{ CF_DSPENHMETAFILE, wszCF_DSPENHMETAFILE, 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportClipboardData,
|
2009-04-25 00:19:38 +02:00
|
|
|
X11DRV_CLIPBOARD_ExportClipboardData, &ClipFormats[21], &ClipFormats[23]},
|
|
|
|
|
|
|
|
{ CF_DIB, wszIMAGEBMP, 0, CF_FLAG_BUILTINFMT, X11DRV_CLIPBOARD_ImportImageBmp,
|
2009-04-30 21:40:29 +02:00
|
|
|
X11DRV_CLIPBOARD_ExportImageBmp, &ClipFormats[22], NULL},
|
2003-06-24 01:02:02 +02:00
|
|
|
};
|
|
|
|
|
2003-11-20 05:24:18 +01:00
|
|
|
#define GET_ATOM(prop) (((prop) < FIRST_XATOM) ? (Atom)(prop) : X11DRV_Atoms[(prop) - FIRST_XATOM])
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
/* Maps X properties to Windows formats */
|
2005-01-11 16:10:56 +01:00
|
|
|
static const WCHAR wszRichTextFormat[] = {'R','i','c','h',' ','T','e','x','t',' ','F','o','r','m','a','t',0};
|
|
|
|
static const WCHAR wszGIF[] = {'G','I','F',0};
|
2009-06-19 20:54:33 +02:00
|
|
|
static const WCHAR wszJFIF[] = {'J','F','I','F',0};
|
2009-06-19 20:46:57 +02:00
|
|
|
static const WCHAR wszPNG[] = {'P','N','G',0};
|
2009-11-22 21:30:18 +01:00
|
|
|
static const WCHAR wszHTMLFormat[] = {'H','T','M','L',' ','F','o','r','m','a','t',0};
|
2003-11-20 05:24:18 +01:00
|
|
|
static const struct
|
|
|
|
{
|
2005-01-11 16:10:56 +01:00
|
|
|
LPCWSTR lpszFormat;
|
2003-11-20 05:24:18 +01:00
|
|
|
UINT prop;
|
|
|
|
} PropertyFormatMap[] =
|
|
|
|
{
|
2005-01-11 16:10:56 +01:00
|
|
|
{ wszRichTextFormat, XATOM_text_rtf },
|
2005-11-01 19:05:40 +01:00
|
|
|
{ wszRichTextFormat, XATOM_text_richtext },
|
|
|
|
{ wszGIF, XATOM_image_gif },
|
2009-06-19 20:54:33 +02:00
|
|
|
{ wszJFIF, XATOM_image_jpeg },
|
2009-06-19 20:46:57 +02:00
|
|
|
{ wszPNG, XATOM_image_png },
|
2009-11-22 21:30:18 +01:00
|
|
|
{ wszHTMLFormat, XATOM_HTML_Format }, /* prefer this to text/html */
|
2003-06-24 01:02:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cached clipboard data.
|
|
|
|
*/
|
|
|
|
static LPWINE_CLIPDATA ClipData = NULL;
|
|
|
|
static UINT ClipDataCount = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clipboard sequence number
|
|
|
|
*/
|
2003-11-20 05:24:18 +01:00
|
|
|
static UINT wSeqNo = 0;
|
1998-12-07 10:13:40 +01:00
|
|
|
|
|
|
|
/**************************************************************************
|
2003-06-24 01:02:02 +02:00
|
|
|
* Internal Clipboard implementation methods
|
|
|
|
**************************************************************************/
|
|
|
|
|
2005-03-07 20:31:46 +01:00
|
|
|
static Window thread_selection_wnd(void)
|
|
|
|
{
|
2008-06-26 15:08:08 +02:00
|
|
|
struct x11drv_thread_data *thread_data = x11drv_init_thread_data();
|
|
|
|
Window w = thread_data->selection_wnd;
|
2005-03-07 20:31:46 +01:00
|
|
|
|
|
|
|
if (!w)
|
|
|
|
{
|
2006-06-05 17:55:14 +02:00
|
|
|
XSetWindowAttributes attr;
|
|
|
|
|
|
|
|
attr.event_mask = (ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
|
2008-10-31 04:18:00 +01:00
|
|
|
ButtonPressMask | ButtonReleaseMask | EnterWindowMask | PropertyChangeMask);
|
2006-06-05 17:55:14 +02:00
|
|
|
|
2005-03-07 20:31:46 +01:00
|
|
|
wine_tsx11_lock();
|
2008-06-26 15:08:08 +02:00
|
|
|
w = XCreateWindow(thread_data->display, root_window, 0, 0, 1, 1, 0, screen_depth,
|
2006-06-05 17:55:14 +02:00
|
|
|
InputOutput, CopyFromParent, CWEventMask, &attr);
|
2005-03-07 20:31:46 +01:00
|
|
|
wine_tsx11_unlock();
|
|
|
|
|
|
|
|
if (w)
|
2008-06-26 15:08:08 +02:00
|
|
|
thread_data->selection_wnd = w;
|
2005-03-07 20:31:46 +01:00
|
|
|
else
|
|
|
|
FIXME("Failed to create window. Fetching selection data will fail.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_InitClipboard
|
1998-12-07 10:13:40 +01:00
|
|
|
*/
|
2003-11-21 06:23:17 +01:00
|
|
|
void X11DRV_InitClipboard(void)
|
1998-12-07 10:13:40 +01:00
|
|
|
{
|
2004-08-12 01:45:34 +02:00
|
|
|
UINT i;
|
2009-11-22 21:30:18 +01:00
|
|
|
WINE_CLIPFORMAT *format;
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2003-11-21 06:23:17 +01:00
|
|
|
/* Register known mapping between window formats and X properties */
|
|
|
|
for (i = 0; i < sizeof(PropertyFormatMap)/sizeof(PropertyFormatMap[0]); i++)
|
2005-11-01 19:05:40 +01:00
|
|
|
X11DRV_CLIPBOARD_InsertClipboardFormat(PropertyFormatMap[i].lpszFormat, GET_ATOM(PropertyFormatMap[i].prop));
|
2009-11-22 21:30:18 +01:00
|
|
|
|
|
|
|
/* Set up a conversion function from "HTML Format" to "text/html" */
|
|
|
|
format = X11DRV_CLIPBOARD_InsertClipboardFormat(wszHTMLFormat, GET_ATOM(XATOM_text_html));
|
|
|
|
format->lpDrvExportFunc = X11DRV_CLIPBOARD_ExportTextHtml;
|
2003-11-21 06:23:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* intern_atoms
|
|
|
|
*
|
|
|
|
* Intern atoms for formats that don't have one yet.
|
|
|
|
*/
|
|
|
|
static void intern_atoms(void)
|
|
|
|
{
|
|
|
|
LPWINE_CLIPFORMAT format;
|
2005-01-11 16:10:56 +01:00
|
|
|
int i, count, len;
|
2003-11-21 06:23:17 +01:00
|
|
|
char **names;
|
|
|
|
Atom *atoms;
|
2008-06-26 16:47:42 +02:00
|
|
|
Display *display;
|
2003-11-21 06:23:17 +01:00
|
|
|
|
|
|
|
for (format = ClipFormats, count = 0; format; format = format->NextFormat)
|
|
|
|
if (!format->drvData) count++;
|
|
|
|
if (!count) return;
|
|
|
|
|
2008-06-26 16:47:42 +02:00
|
|
|
display = thread_init_display();
|
|
|
|
|
2003-11-21 06:23:17 +01:00
|
|
|
names = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*names) );
|
|
|
|
atoms = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*atoms) );
|
|
|
|
|
2005-01-11 16:10:56 +01:00
|
|
|
for (format = ClipFormats, i = 0; format; format = format->NextFormat) {
|
|
|
|
if (!format->drvData) {
|
2005-05-12 11:56:35 +02:00
|
|
|
len = WideCharToMultiByte(CP_UNIXCP, 0, format->Name, -1, NULL, 0, NULL, NULL);
|
|
|
|
names[i] = HeapAlloc(GetProcessHeap(), 0, len);
|
|
|
|
WideCharToMultiByte(CP_UNIXCP, 0, format->Name, -1, names[i++], len, NULL, NULL);
|
2005-01-11 16:10:56 +01:00
|
|
|
}
|
|
|
|
}
|
2003-11-21 06:23:17 +01:00
|
|
|
|
|
|
|
wine_tsx11_lock();
|
2008-06-26 16:47:42 +02:00
|
|
|
XInternAtoms( display, names, count, False, atoms );
|
2003-11-21 06:23:17 +01:00
|
|
|
wine_tsx11_unlock();
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-01-11 16:10:56 +01:00
|
|
|
for (format = ClipFormats, i = 0; format; format = format->NextFormat) {
|
|
|
|
if (!format->drvData) {
|
|
|
|
HeapFree(GetProcessHeap(), 0, names[i]);
|
|
|
|
format->drvData = atoms[i++];
|
|
|
|
}
|
|
|
|
}
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2003-11-21 06:23:17 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, names );
|
|
|
|
HeapFree( GetProcessHeap(), 0, atoms );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* register_format
|
|
|
|
*
|
|
|
|
* Register a custom X clipboard format.
|
|
|
|
*/
|
2005-01-11 16:10:56 +01:00
|
|
|
static WINE_CLIPFORMAT *register_format( LPCWSTR FormatName, Atom prop )
|
2003-11-21 06:23:17 +01:00
|
|
|
{
|
|
|
|
LPWINE_CLIPFORMAT lpFormat = ClipFormats;
|
|
|
|
|
2005-01-11 16:10:56 +01:00
|
|
|
TRACE("%s\n", debugstr_w(FormatName));
|
2003-11-21 06:23:17 +01:00
|
|
|
|
|
|
|
/* walk format chain to see if it's already registered */
|
|
|
|
while (lpFormat)
|
|
|
|
{
|
2005-01-11 16:10:56 +01:00
|
|
|
if (CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, lpFormat->Name, -1, FormatName, -1) == CSTR_EQUAL
|
|
|
|
&& (lpFormat->wFlags & CF_FLAG_BUILTINFMT) == 0)
|
2003-11-21 06:23:17 +01:00
|
|
|
return lpFormat;
|
2003-06-24 01:02:02 +02:00
|
|
|
lpFormat = lpFormat->NextFormat;
|
|
|
|
}
|
|
|
|
|
2003-11-21 06:23:17 +01:00
|
|
|
return X11DRV_CLIPBOARD_InsertClipboardFormat(FormatName, prop);
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_LookupFormat
|
|
|
|
*/
|
2005-07-24 19:10:38 +02:00
|
|
|
static LPWINE_CLIPFORMAT X11DRV_CLIPBOARD_LookupFormat(WORD wID)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
|
|
|
LPWINE_CLIPFORMAT lpFormat = ClipFormats;
|
|
|
|
|
|
|
|
while(lpFormat)
|
|
|
|
{
|
|
|
|
if (lpFormat->wFormatID == wID)
|
|
|
|
break;
|
|
|
|
|
|
|
|
lpFormat = lpFormat->NextFormat;
|
|
|
|
}
|
2004-04-05 22:17:13 +02:00
|
|
|
if (lpFormat && !lpFormat->drvData) intern_atoms();
|
2003-06-24 01:02:02 +02:00
|
|
|
return lpFormat;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_LookupProperty
|
|
|
|
*/
|
2005-11-01 19:05:40 +01:00
|
|
|
static LPWINE_CLIPFORMAT X11DRV_CLIPBOARD_LookupProperty(LPWINE_CLIPFORMAT current, UINT drvData)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2003-11-21 06:23:17 +01:00
|
|
|
for (;;)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2003-11-21 06:23:17 +01:00
|
|
|
LPWINE_CLIPFORMAT lpFormat = ClipFormats;
|
|
|
|
BOOL need_intern = FALSE;
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
if (current)
|
|
|
|
lpFormat = current->NextFormat;
|
|
|
|
|
2003-11-21 06:23:17 +01:00
|
|
|
while(lpFormat)
|
|
|
|
{
|
|
|
|
if (lpFormat->drvData == drvData) return lpFormat;
|
|
|
|
if (!lpFormat->drvData) need_intern = TRUE;
|
|
|
|
lpFormat = lpFormat->NextFormat;
|
|
|
|
}
|
|
|
|
if (!need_intern) return NULL;
|
|
|
|
intern_atoms();
|
|
|
|
/* restart the search for the new atoms */
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_LookupData
|
|
|
|
*/
|
2005-07-24 19:10:38 +02:00
|
|
|
static LPWINE_CLIPDATA X11DRV_CLIPBOARD_LookupData(DWORD wID)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
|
|
|
LPWINE_CLIPDATA lpData = ClipData;
|
|
|
|
|
|
|
|
if (lpData)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (lpData->wFormatID == wID)
|
|
|
|
break;
|
|
|
|
|
|
|
|
lpData = lpData->NextData;
|
|
|
|
}
|
|
|
|
while(lpData != ClipData);
|
|
|
|
|
|
|
|
if (lpData->wFormatID != wID)
|
|
|
|
lpData = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return lpData;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* InsertClipboardFormat
|
|
|
|
*/
|
2005-01-11 16:10:56 +01:00
|
|
|
static WINE_CLIPFORMAT *X11DRV_CLIPBOARD_InsertClipboardFormat(LPCWSTR FormatName, Atom prop)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
|
|
|
LPWINE_CLIPFORMAT lpFormat;
|
|
|
|
LPWINE_CLIPFORMAT lpNewFormat;
|
2006-11-25 19:23:55 +01:00
|
|
|
LPWSTR new_name;
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
/* allocate storage for new format entry */
|
2005-03-24 22:01:35 +01:00
|
|
|
lpNewFormat = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_CLIPFORMAT));
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
if(lpNewFormat == NULL)
|
|
|
|
{
|
|
|
|
WARN("No more memory for a new format!\n");
|
2003-11-21 06:23:17 +01:00
|
|
|
return NULL;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
2006-11-25 19:23:55 +01:00
|
|
|
if (!(new_name = HeapAlloc(GetProcessHeap(), 0, (strlenW(FormatName)+1)*sizeof(WCHAR))))
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
|
|
|
WARN("No more memory for the new format name!\n");
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpNewFormat);
|
2003-11-21 06:23:17 +01:00
|
|
|
return NULL;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
2006-11-25 19:23:55 +01:00
|
|
|
lpNewFormat->Name = strcpyW(new_name, FormatName);
|
2003-06-24 01:02:02 +02:00
|
|
|
lpNewFormat->wFlags = 0;
|
2005-01-11 16:10:56 +01:00
|
|
|
lpNewFormat->wFormatID = GlobalAddAtomW(lpNewFormat->Name);
|
2003-11-20 05:24:18 +01:00
|
|
|
lpNewFormat->drvData = prop;
|
2003-06-24 01:02:02 +02:00
|
|
|
lpNewFormat->lpDrvImportFunc = X11DRV_CLIPBOARD_ImportClipboardData;
|
|
|
|
lpNewFormat->lpDrvExportFunc = X11DRV_CLIPBOARD_ExportClipboardData;
|
|
|
|
|
|
|
|
/* Link Format */
|
|
|
|
lpFormat = ClipFormats;
|
|
|
|
|
|
|
|
while(lpFormat->NextFormat) /* Move to last entry */
|
|
|
|
lpFormat = lpFormat->NextFormat;
|
|
|
|
|
|
|
|
lpNewFormat->NextFormat = NULL;
|
|
|
|
lpFormat->NextFormat = lpNewFormat;
|
|
|
|
lpNewFormat->PrevFormat = lpFormat;
|
|
|
|
|
2009-04-24 13:24:52 +02:00
|
|
|
TRACE("Registering format(%04x): %s drvData %d\n",
|
2005-01-11 16:10:56 +01:00
|
|
|
lpNewFormat->wFormatID, debugstr_w(FormatName), lpNewFormat->drvData);
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2003-11-21 06:23:17 +01:00
|
|
|
return lpNewFormat;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_GetClipboardInfo
|
|
|
|
*/
|
|
|
|
static BOOL X11DRV_CLIPBOARD_GetClipboardInfo(LPCLIPBOARDINFO cbInfo)
|
|
|
|
{
|
|
|
|
BOOL bRet = FALSE;
|
|
|
|
|
|
|
|
SERVER_START_REQ( set_clipboard_info )
|
|
|
|
{
|
|
|
|
req->flags = 0;
|
|
|
|
|
|
|
|
if (wine_server_call_err( req ))
|
|
|
|
{
|
|
|
|
ERR("Failed to get clipboard owner.\n");
|
|
|
|
}
|
1999-09-20 17:42:47 +02:00
|
|
|
else
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2008-12-08 16:58:20 +01:00
|
|
|
cbInfo->hWndOpen = wine_server_ptr_handle( reply->old_clipboard );
|
|
|
|
cbInfo->hWndOwner = wine_server_ptr_handle( reply->old_owner );
|
|
|
|
cbInfo->hWndViewer = wine_server_ptr_handle( reply->old_viewer );
|
2003-06-24 01:02:02 +02:00
|
|
|
cbInfo->seqno = reply->seqno;
|
|
|
|
cbInfo->flags = reply->flags;
|
|
|
|
|
|
|
|
bRet = TRUE;
|
|
|
|
}
|
1999-09-20 17:42:47 +02:00
|
|
|
}
|
2003-06-24 01:02:02 +02:00
|
|
|
SERVER_END_REQ;
|
1999-09-03 17:17:57 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_ReleaseOwnership
|
|
|
|
*/
|
|
|
|
static BOOL X11DRV_CLIPBOARD_ReleaseOwnership(void)
|
|
|
|
{
|
|
|
|
BOOL bRet = FALSE;
|
|
|
|
|
|
|
|
SERVER_START_REQ( set_clipboard_info )
|
|
|
|
{
|
|
|
|
req->flags = SET_CB_RELOWNER | SET_CB_SEQNO;
|
|
|
|
|
|
|
|
if (wine_server_call_err( req ))
|
|
|
|
{
|
|
|
|
ERR("Failed to set clipboard.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bRet = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
return bRet;
|
1999-09-03 17:17:57 +02:00
|
|
|
}
|
1998-12-07 10:13:40 +01:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
/**************************************************************************
|
2003-06-24 01:02:02 +02:00
|
|
|
* X11DRV_CLIPBOARD_InsertClipboardData
|
1999-09-03 17:17:57 +02:00
|
|
|
*
|
2003-06-24 01:02:02 +02:00
|
|
|
* Caller *must* have the clipboard open and be the owner.
|
1999-09-03 17:17:57 +02:00
|
|
|
*/
|
2009-12-22 21:18:40 +01:00
|
|
|
static BOOL X11DRV_CLIPBOARD_InsertClipboardData(UINT wFormatID, HANDLE hData, DWORD flags,
|
|
|
|
LPWINE_CLIPFORMAT lpFormat, BOOL override)
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
2005-11-01 19:05:40 +01:00
|
|
|
LPWINE_CLIPDATA lpData = X11DRV_CLIPBOARD_LookupData(wFormatID);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
TRACE("format=%04x lpData=%p hData=%p flags=0x%08x lpFormat=%p override=%d\n",
|
|
|
|
wFormatID, lpData, hData, flags, lpFormat, override);
|
2005-11-01 19:05:40 +01:00
|
|
|
|
|
|
|
if (lpData && !override)
|
|
|
|
return TRUE;
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
if (lpData)
|
1998-12-07 10:13:40 +01:00
|
|
|
{
|
2003-06-24 01:02:02 +02:00
|
|
|
X11DRV_CLIPBOARD_FreeData(lpData);
|
2000-12-11 02:09:56 +01:00
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
lpData->hData = hData;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-03-24 22:01:35 +01:00
|
|
|
lpData = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_CLIPDATA));
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
lpData->wFormatID = wFormatID;
|
2009-12-22 21:18:40 +01:00
|
|
|
lpData->hData = hData;
|
2005-11-01 19:05:40 +01:00
|
|
|
lpData->lpFormat = lpFormat;
|
2004-02-20 06:43:00 +01:00
|
|
|
lpData->drvData = 0;
|
1999-09-03 17:17:57 +02:00
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
if (ClipData)
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
2003-06-24 01:02:02 +02:00
|
|
|
LPWINE_CLIPDATA lpPrevData = ClipData->PrevData;
|
|
|
|
|
|
|
|
lpData->PrevData = lpPrevData;
|
|
|
|
lpData->NextData = ClipData;
|
|
|
|
|
|
|
|
lpPrevData->NextData = lpData;
|
|
|
|
ClipData->PrevData = lpData;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lpData->NextData = lpData;
|
|
|
|
lpData->PrevData = lpData;
|
|
|
|
ClipData = lpData;
|
|
|
|
}
|
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
ClipDataCount++;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
lpData->wFlags = flags;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_FreeData
|
|
|
|
*
|
|
|
|
* Free clipboard data handle.
|
|
|
|
*/
|
|
|
|
static void X11DRV_CLIPBOARD_FreeData(LPWINE_CLIPDATA lpData)
|
|
|
|
{
|
2009-04-24 13:24:52 +02:00
|
|
|
TRACE("%04x\n", lpData->wFormatID);
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
if ((lpData->wFormatID >= CF_GDIOBJFIRST &&
|
|
|
|
lpData->wFormatID <= CF_GDIOBJLAST) ||
|
|
|
|
lpData->wFormatID == CF_BITMAP ||
|
|
|
|
lpData->wFormatID == CF_DIB ||
|
|
|
|
lpData->wFormatID == CF_PALETTE)
|
|
|
|
{
|
2009-12-22 21:18:40 +01:00
|
|
|
if (lpData->hData)
|
|
|
|
DeleteObject(lpData->hData);
|
2004-02-20 06:43:00 +01:00
|
|
|
|
|
|
|
if ((lpData->wFormatID == CF_DIB) && lpData->drvData)
|
|
|
|
XFreePixmap(gdi_display, lpData->drvData);
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
else if (lpData->wFormatID == CF_METAFILEPICT)
|
|
|
|
{
|
2009-12-22 21:18:40 +01:00
|
|
|
if (lpData->hData)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2009-12-22 21:18:40 +01:00
|
|
|
DeleteMetaFile(((METAFILEPICT *)GlobalLock( lpData->hData ))->hMF );
|
|
|
|
GlobalFree(lpData->hData);
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (lpData->wFormatID == CF_ENHMETAFILE)
|
|
|
|
{
|
2009-12-22 21:18:40 +01:00
|
|
|
if (lpData->hData)
|
|
|
|
DeleteEnhMetaFile(lpData->hData);
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
else if (lpData->wFormatID < CF_PRIVATEFIRST ||
|
|
|
|
lpData->wFormatID > CF_PRIVATELAST)
|
|
|
|
{
|
2009-12-22 21:18:40 +01:00
|
|
|
if (lpData->hData)
|
|
|
|
GlobalFree(lpData->hData);
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
lpData->hData = 0;
|
2004-02-20 06:43:00 +01:00
|
|
|
lpData->drvData = 0;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_UpdateCache
|
|
|
|
*/
|
|
|
|
static BOOL X11DRV_CLIPBOARD_UpdateCache(LPCLIPBOARDINFO lpcbinfo)
|
|
|
|
{
|
|
|
|
BOOL bret = TRUE;
|
|
|
|
|
|
|
|
if (!X11DRV_CLIPBOARD_IsSelectionOwner())
|
|
|
|
{
|
|
|
|
if (!X11DRV_CLIPBOARD_GetClipboardInfo(lpcbinfo))
|
|
|
|
{
|
|
|
|
ERR("Failed to retrieve clipboard information.\n");
|
|
|
|
bret = FALSE;
|
|
|
|
}
|
|
|
|
else if (wSeqNo < lpcbinfo->seqno)
|
|
|
|
{
|
2004-05-07 01:40:30 +02:00
|
|
|
X11DRV_EmptyClipboard(TRUE);
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2008-06-26 16:47:42 +02:00
|
|
|
if (X11DRV_CLIPBOARD_QueryAvailableData(thread_init_display(), lpcbinfo) < 0)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to cache clipboard data owned by another process.\n");
|
|
|
|
bret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
2003-06-24 01:02:02 +02:00
|
|
|
X11DRV_EndClipboardUpdate();
|
1999-09-03 17:17:57 +02:00
|
|
|
}
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
wSeqNo = lpcbinfo->seqno;
|
1999-09-03 17:17:57 +02:00
|
|
|
}
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return bret;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_RenderFormat
|
|
|
|
*/
|
2008-06-26 16:20:02 +02:00
|
|
|
static BOOL X11DRV_CLIPBOARD_RenderFormat(Display *display, LPWINE_CLIPDATA lpData)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
|
|
|
BOOL bret = TRUE;
|
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
TRACE(" 0x%04x hData(%p)\n", lpData->wFormatID, lpData->hData);
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
if (lpData->hData) return bret; /* Already rendered */
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2003-07-08 23:02:51 +02:00
|
|
|
if (lpData->wFlags & CF_FLAG_SYNTHESIZED)
|
2008-06-26 16:20:02 +02:00
|
|
|
bret = X11DRV_CLIPBOARD_RenderSynthesizedFormat(display, lpData);
|
2003-07-08 23:02:51 +02:00
|
|
|
else if (!X11DRV_CLIPBOARD_IsSelectionOwner())
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2008-06-26 16:20:02 +02:00
|
|
|
if (!X11DRV_CLIPBOARD_ReadSelectionData(display, lpData))
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
2009-04-24 13:24:52 +02:00
|
|
|
ERR("Failed to cache clipboard data owned by another process. Format=%04x\n",
|
2003-06-24 01:02:02 +02:00
|
|
|
lpData->wFormatID);
|
|
|
|
bret = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-12-05 05:45:50 +01:00
|
|
|
CLIPBOARDINFO cbInfo;
|
2002-08-27 21:19:49 +02:00
|
|
|
|
2003-07-08 23:02:51 +02:00
|
|
|
if (X11DRV_CLIPBOARD_GetClipboardInfo(&cbInfo) && cbInfo.hWndOwner)
|
2003-12-05 05:45:50 +01:00
|
|
|
{
|
|
|
|
/* Send a WM_RENDERFORMAT message to notify the owner to render the
|
|
|
|
* data requested into the clipboard.
|
|
|
|
*/
|
|
|
|
TRACE("Sending WM_RENDERFORMAT message to hwnd(%p)\n", cbInfo.hWndOwner);
|
2009-12-27 14:40:57 +01:00
|
|
|
SendMessageW(cbInfo.hWndOwner, WM_RENDERFORMAT, lpData->wFormatID, 0);
|
2003-12-05 05:45:50 +01:00
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
if (!lpData->hData) bret = FALSE;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
2003-12-05 05:45:50 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("hWndClipOwner is lost!\n");
|
|
|
|
bret = FALSE;
|
|
|
|
}
|
|
|
|
}
|
1999-09-03 17:17:57 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
return bret;
|
|
|
|
}
|
2002-08-27 21:19:49 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* CLIPBOARD_ConvertText
|
|
|
|
* Returns number of required/converted characters - not bytes!
|
|
|
|
*/
|
|
|
|
static INT CLIPBOARD_ConvertText(WORD src_fmt, void const *src, INT src_size,
|
|
|
|
WORD dst_fmt, void *dst, INT dst_size)
|
|
|
|
{
|
|
|
|
UINT cp;
|
|
|
|
|
|
|
|
if(src_fmt == CF_UNICODETEXT)
|
|
|
|
{
|
|
|
|
switch(dst_fmt)
|
|
|
|
{
|
|
|
|
case CF_TEXT:
|
|
|
|
cp = CP_ACP;
|
|
|
|
break;
|
|
|
|
case CF_OEMTEXT:
|
|
|
|
cp = CP_OEMCP;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return WideCharToMultiByte(cp, 0, src, src_size, dst, dst_size, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dst_fmt == CF_UNICODETEXT)
|
|
|
|
{
|
|
|
|
switch(src_fmt)
|
|
|
|
{
|
|
|
|
case CF_TEXT:
|
|
|
|
cp = CP_ACP;
|
|
|
|
break;
|
|
|
|
case CF_OEMTEXT:
|
|
|
|
cp = CP_OEMCP;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return MultiByteToWideChar(cp, 0, src, src_size, dst, dst_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!dst_size) return src_size;
|
|
|
|
|
|
|
|
if(dst_size > src_size) dst_size = src_size;
|
|
|
|
|
|
|
|
if(src_fmt == CF_TEXT )
|
|
|
|
CharToOemBuffA(src, dst, dst_size);
|
|
|
|
else
|
|
|
|
OemToCharBuffA(src, dst, dst_size);
|
|
|
|
|
|
|
|
return dst_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_RenderSynthesizedFormat
|
|
|
|
*/
|
2008-06-26 16:20:02 +02:00
|
|
|
static BOOL X11DRV_CLIPBOARD_RenderSynthesizedFormat(Display *display, LPWINE_CLIPDATA lpData)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
|
|
|
BOOL bret = FALSE;
|
|
|
|
|
2003-07-08 23:02:51 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
if (lpData->wFlags & CF_FLAG_SYNTHESIZED)
|
|
|
|
{
|
|
|
|
UINT wFormatID = lpData->wFormatID;
|
|
|
|
|
|
|
|
if (wFormatID == CF_UNICODETEXT || wFormatID == CF_TEXT || wFormatID == CF_OEMTEXT)
|
2008-06-26 16:20:02 +02:00
|
|
|
bret = X11DRV_CLIPBOARD_RenderSynthesizedText(display, wFormatID);
|
2003-06-24 01:02:02 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (wFormatID)
|
|
|
|
{
|
|
|
|
case CF_DIB:
|
2008-06-26 16:20:02 +02:00
|
|
|
bret = X11DRV_CLIPBOARD_RenderSynthesizedDIB( display );
|
2004-02-20 06:43:00 +01:00
|
|
|
break;
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
case CF_BITMAP:
|
2008-06-26 16:20:02 +02:00
|
|
|
bret = X11DRV_CLIPBOARD_RenderSynthesizedBitmap( display );
|
2004-02-20 06:43:00 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CF_ENHMETAFILE:
|
|
|
|
case CF_METAFILEPICT:
|
2003-06-24 01:02:02 +02:00
|
|
|
FIXME("Synthesizing wFormatID(0x%08x) not implemented\n", wFormatID);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Called to synthesize unknown format\n");
|
|
|
|
break;
|
|
|
|
}
|
1999-09-03 17:17:57 +02:00
|
|
|
}
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
lpData->wFlags &= ~CF_FLAG_SYNTHESIZED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
2003-07-08 23:02:51 +02:00
|
|
|
* X11DRV_CLIPBOARD_RenderSynthesizedText
|
2003-06-24 01:02:02 +02:00
|
|
|
*
|
2003-07-08 23:02:51 +02:00
|
|
|
* Renders synthesized text
|
2003-06-24 01:02:02 +02:00
|
|
|
*/
|
2008-06-26 16:20:02 +02:00
|
|
|
static BOOL X11DRV_CLIPBOARD_RenderSynthesizedText(Display *display, UINT wFormatID)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
|
|
|
LPCSTR lpstrS;
|
|
|
|
LPSTR lpstrT;
|
2009-12-22 21:18:40 +01:00
|
|
|
HANDLE hData;
|
2003-06-24 01:02:02 +02:00
|
|
|
INT src_chars, dst_chars, alloc_size;
|
|
|
|
LPWINE_CLIPDATA lpSource = NULL;
|
|
|
|
|
2009-04-24 13:24:52 +02:00
|
|
|
TRACE("%04x\n", wFormatID);
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2003-07-08 23:02:51 +02:00
|
|
|
if ((lpSource = X11DRV_CLIPBOARD_LookupData(wFormatID)) &&
|
2009-12-22 21:18:40 +01:00
|
|
|
lpSource->hData)
|
2003-06-24 01:02:02 +02:00
|
|
|
return TRUE;
|
|
|
|
|
2003-07-08 23:02:51 +02:00
|
|
|
/* Look for rendered source or non-synthesized source */
|
|
|
|
if ((lpSource = X11DRV_CLIPBOARD_LookupData(CF_UNICODETEXT)) &&
|
2009-12-22 21:18:40 +01:00
|
|
|
(!(lpSource->wFlags & CF_FLAG_SYNTHESIZED) || lpSource->hData))
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2009-04-24 13:24:52 +02:00
|
|
|
TRACE("UNICODETEXT -> %04x\n", wFormatID);
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
2003-07-08 23:02:51 +02:00
|
|
|
else if ((lpSource = X11DRV_CLIPBOARD_LookupData(CF_TEXT)) &&
|
2009-12-22 21:18:40 +01:00
|
|
|
(!(lpSource->wFlags & CF_FLAG_SYNTHESIZED) || lpSource->hData))
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2009-04-24 13:24:52 +02:00
|
|
|
TRACE("TEXT -> %04x\n", wFormatID);
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
2003-07-08 23:02:51 +02:00
|
|
|
else if ((lpSource = X11DRV_CLIPBOARD_LookupData(CF_OEMTEXT)) &&
|
2009-12-22 21:18:40 +01:00
|
|
|
(!(lpSource->wFlags & CF_FLAG_SYNTHESIZED) || lpSource->hData))
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2009-04-24 13:24:52 +02:00
|
|
|
TRACE("OEMTEXT -> %04x\n", wFormatID);
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
2003-07-08 23:02:51 +02:00
|
|
|
if (!lpSource || (lpSource->wFlags & CF_FLAG_SYNTHESIZED &&
|
2009-12-22 21:18:40 +01:00
|
|
|
!lpSource->hData))
|
2003-06-24 01:02:02 +02:00
|
|
|
return FALSE;
|
|
|
|
|
2003-07-08 23:02:51 +02:00
|
|
|
/* Ask the clipboard owner to render the source text if necessary */
|
2009-12-22 21:18:40 +01:00
|
|
|
if (!lpSource->hData && !X11DRV_CLIPBOARD_RenderFormat(display, lpSource))
|
2003-06-24 01:02:02 +02:00
|
|
|
return FALSE;
|
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
lpstrS = GlobalLock(lpSource->hData);
|
2003-06-24 01:02:02 +02:00
|
|
|
if (!lpstrS)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Text always NULL terminated */
|
|
|
|
if(lpSource->wFormatID == CF_UNICODETEXT)
|
|
|
|
src_chars = strlenW((LPCWSTR)lpstrS) + 1;
|
|
|
|
else
|
|
|
|
src_chars = strlen(lpstrS) + 1;
|
|
|
|
|
|
|
|
/* Calculate number of characters in the destination buffer */
|
|
|
|
dst_chars = CLIPBOARD_ConvertText(lpSource->wFormatID, lpstrS,
|
|
|
|
src_chars, wFormatID, NULL, 0);
|
|
|
|
|
|
|
|
if (!dst_chars)
|
|
|
|
return FALSE;
|
|
|
|
|
2009-04-24 13:24:52 +02:00
|
|
|
TRACE("Converting from '%04x' to '%04x', %i chars\n",
|
2003-06-24 01:02:02 +02:00
|
|
|
lpSource->wFormatID, wFormatID, src_chars);
|
|
|
|
|
|
|
|
/* Convert characters to bytes */
|
|
|
|
if(wFormatID == CF_UNICODETEXT)
|
|
|
|
alloc_size = dst_chars * sizeof(WCHAR);
|
|
|
|
else
|
|
|
|
alloc_size = dst_chars;
|
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
hData = GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE |
|
2003-06-24 01:02:02 +02:00
|
|
|
GMEM_DDESHARE, alloc_size);
|
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
lpstrT = GlobalLock(hData);
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
if (lpstrT)
|
|
|
|
{
|
|
|
|
CLIPBOARD_ConvertText(lpSource->wFormatID, lpstrS, src_chars,
|
|
|
|
wFormatID, lpstrT, dst_chars);
|
2009-12-22 21:18:40 +01:00
|
|
|
GlobalUnlock(hData);
|
1999-09-03 17:17:57 +02:00
|
|
|
}
|
1998-12-07 10:13:40 +01:00
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
GlobalUnlock(lpSource->hData);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
return X11DRV_CLIPBOARD_InsertClipboardData(wFormatID, hData, 0, NULL, TRUE);
|
1999-09-03 17:17:57 +02:00
|
|
|
}
|
1998-12-07 10:13:40 +01:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2004-02-20 06:43:00 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_RenderSynthesizedDIB
|
|
|
|
*
|
|
|
|
* Renders synthesized DIB
|
|
|
|
*/
|
2008-06-26 16:20:02 +02:00
|
|
|
static BOOL X11DRV_CLIPBOARD_RenderSynthesizedDIB(Display *display)
|
2004-02-20 06:43:00 +01:00
|
|
|
{
|
|
|
|
BOOL bret = FALSE;
|
|
|
|
LPWINE_CLIPDATA lpSource = NULL;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
if ((lpSource = X11DRV_CLIPBOARD_LookupData(CF_DIB)) && lpSource->hData)
|
2004-02-20 06:43:00 +01:00
|
|
|
{
|
|
|
|
bret = TRUE;
|
|
|
|
}
|
|
|
|
/* If we have a bitmap and it's not synthesized or it has been rendered */
|
|
|
|
else if ((lpSource = X11DRV_CLIPBOARD_LookupData(CF_BITMAP)) &&
|
2009-12-22 21:18:40 +01:00
|
|
|
(!(lpSource->wFlags & CF_FLAG_SYNTHESIZED) || lpSource->hData))
|
2004-02-20 06:43:00 +01:00
|
|
|
{
|
|
|
|
/* Render source if required */
|
2009-12-22 21:18:40 +01:00
|
|
|
if (lpSource->hData || X11DRV_CLIPBOARD_RenderFormat(display, lpSource))
|
2004-02-20 06:43:00 +01:00
|
|
|
{
|
|
|
|
HDC hdc;
|
2009-12-22 21:18:40 +01:00
|
|
|
HGLOBAL hData;
|
2004-02-20 06:43:00 +01:00
|
|
|
|
|
|
|
hdc = GetDC(NULL);
|
2009-12-22 21:18:40 +01:00
|
|
|
hData = X11DRV_DIB_CreateDIBFromBitmap(hdc, lpSource->hData);
|
2004-02-20 06:43:00 +01:00
|
|
|
ReleaseDC(NULL, hdc);
|
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
if (hData)
|
2004-02-20 06:43:00 +01:00
|
|
|
{
|
2009-12-22 21:18:40 +01:00
|
|
|
X11DRV_CLIPBOARD_InsertClipboardData(CF_DIB, hData, 0, NULL, TRUE);
|
2004-02-20 06:43:00 +01:00
|
|
|
bret = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_RenderSynthesizedBitmap
|
|
|
|
*
|
|
|
|
* Renders synthesized bitmap
|
|
|
|
*/
|
2008-06-26 16:20:02 +02:00
|
|
|
static BOOL X11DRV_CLIPBOARD_RenderSynthesizedBitmap(Display *display)
|
2004-02-20 06:43:00 +01:00
|
|
|
{
|
|
|
|
BOOL bret = FALSE;
|
|
|
|
LPWINE_CLIPDATA lpSource = NULL;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
if ((lpSource = X11DRV_CLIPBOARD_LookupData(CF_BITMAP)) && lpSource->hData)
|
2004-02-20 06:43:00 +01:00
|
|
|
{
|
|
|
|
bret = TRUE;
|
|
|
|
}
|
|
|
|
/* If we have a dib and it's not synthesized or it has been rendered */
|
|
|
|
else if ((lpSource = X11DRV_CLIPBOARD_LookupData(CF_DIB)) &&
|
2009-12-22 21:18:40 +01:00
|
|
|
(!(lpSource->wFlags & CF_FLAG_SYNTHESIZED) || lpSource->hData))
|
2004-02-20 06:43:00 +01:00
|
|
|
{
|
|
|
|
/* Render source if required */
|
2009-12-22 21:18:40 +01:00
|
|
|
if (lpSource->hData || X11DRV_CLIPBOARD_RenderFormat(display, lpSource))
|
2004-02-20 06:43:00 +01:00
|
|
|
{
|
|
|
|
HDC hdc;
|
2009-12-22 21:18:40 +01:00
|
|
|
HBITMAP hData;
|
2004-02-20 06:43:00 +01:00
|
|
|
unsigned int offset;
|
|
|
|
LPBITMAPINFOHEADER lpbmih;
|
|
|
|
|
|
|
|
hdc = GetDC(NULL);
|
2009-12-22 21:18:40 +01:00
|
|
|
lpbmih = GlobalLock(lpSource->hData);
|
2004-02-20 06:43:00 +01:00
|
|
|
|
|
|
|
offset = sizeof(BITMAPINFOHEADER)
|
|
|
|
+ ((lpbmih->biBitCount <= 8) ? (sizeof(RGBQUAD) *
|
|
|
|
(1 << lpbmih->biBitCount)) : 0);
|
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
hData = CreateDIBitmap(hdc, lpbmih, CBM_INIT, (LPBYTE)lpbmih +
|
2004-02-20 06:43:00 +01:00
|
|
|
offset, (LPBITMAPINFO) lpbmih, DIB_RGB_COLORS);
|
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
GlobalUnlock(lpSource->hData);
|
2004-02-20 06:43:00 +01:00
|
|
|
ReleaseDC(NULL, hdc);
|
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
if (hData)
|
2004-02-20 06:43:00 +01:00
|
|
|
{
|
2009-12-22 21:18:40 +01:00
|
|
|
X11DRV_CLIPBOARD_InsertClipboardData(CF_BITMAP, hData, 0, NULL, TRUE);
|
2004-02-20 06:43:00 +01:00
|
|
|
bret = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
/**************************************************************************
|
2003-06-24 01:02:02 +02:00
|
|
|
* X11DRV_CLIPBOARD_ImportXAString
|
1999-09-03 17:17:57 +02:00
|
|
|
*
|
2005-11-01 19:05:40 +01:00
|
|
|
* Import XA_STRING, converting the string to CF_TEXT.
|
|
|
|
*/
|
2009-03-13 14:03:18 +01:00
|
|
|
static HANDLE X11DRV_CLIPBOARD_ImportXAString(Display *display, Window w, Atom prop)
|
2005-11-01 19:05:40 +01:00
|
|
|
{
|
|
|
|
LPBYTE lpdata;
|
2006-02-22 19:53:19 +01:00
|
|
|
unsigned long cbytes;
|
2005-11-01 19:05:40 +01:00
|
|
|
LPSTR lpstr;
|
2006-02-22 19:53:19 +01:00
|
|
|
unsigned long i, inlcount = 0;
|
2005-11-01 19:05:40 +01:00
|
|
|
HANDLE hText = 0;
|
|
|
|
|
2008-06-26 16:20:02 +02:00
|
|
|
if (!X11DRV_CLIPBOARD_ReadProperty(display, w, prop, &lpdata, &cbytes))
|
2005-11-01 19:05:40 +01:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; i <= cbytes; i++)
|
|
|
|
{
|
|
|
|
if (lpdata[i] == '\n')
|
|
|
|
inlcount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((hText = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, cbytes + inlcount + 1)))
|
|
|
|
{
|
|
|
|
lpstr = GlobalLock(hText);
|
|
|
|
|
|
|
|
for (i = 0, inlcount = 0; i <= cbytes; i++)
|
|
|
|
{
|
|
|
|
if (lpdata[i] == '\n')
|
|
|
|
lpstr[inlcount++] = '\r';
|
|
|
|
|
|
|
|
lpstr[inlcount++] = lpdata[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
GlobalUnlock(hText);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free the retrieved property data */
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpdata);
|
|
|
|
|
|
|
|
return hText;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_ImportUTF8
|
|
|
|
*
|
2003-06-24 01:02:02 +02:00
|
|
|
* Import XA_STRING, converting the string to CF_UNICODE.
|
1999-09-03 17:17:57 +02:00
|
|
|
*/
|
2009-03-13 14:03:18 +01:00
|
|
|
static HANDLE X11DRV_CLIPBOARD_ImportUTF8(Display *display, Window w, Atom prop)
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
2005-11-01 19:05:40 +01:00
|
|
|
LPBYTE lpdata;
|
2006-02-22 19:53:19 +01:00
|
|
|
unsigned long cbytes;
|
2003-06-24 01:02:02 +02:00
|
|
|
LPSTR lpstr;
|
2006-02-22 19:53:19 +01:00
|
|
|
unsigned long i, inlcount = 0;
|
2003-06-24 01:02:02 +02:00
|
|
|
HANDLE hUnicodeText = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2008-06-26 16:20:02 +02:00
|
|
|
if (!X11DRV_CLIPBOARD_ReadProperty(display, w, prop, &lpdata, &cbytes))
|
2005-11-01 19:05:40 +01:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; i <= cbytes; i++)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
|
|
|
if (lpdata[i] == '\n')
|
|
|
|
inlcount++;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
if ((lpstr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbytes + inlcount + 1)))
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
|
|
|
UINT count;
|
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
for (i = 0, inlcount = 0; i <= cbytes; i++)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
|
|
|
if (lpdata[i] == '\n')
|
|
|
|
lpstr[inlcount++] = '\r';
|
|
|
|
|
|
|
|
lpstr[inlcount++] = lpdata[i];
|
|
|
|
}
|
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
count = MultiByteToWideChar(CP_UTF8, 0, lpstr, -1, NULL, 0);
|
|
|
|
hUnicodeText = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, count * sizeof(WCHAR));
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
if (hUnicodeText)
|
|
|
|
{
|
2003-06-24 01:02:02 +02:00
|
|
|
WCHAR *textW = GlobalLock(hUnicodeText);
|
2005-11-01 19:05:40 +01:00
|
|
|
MultiByteToWideChar(CP_UTF8, 0, lpstr, -1, textW, count);
|
2003-06-24 01:02:02 +02:00
|
|
|
GlobalUnlock(hUnicodeText);
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpstr);
|
|
|
|
}
|
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
/* Free the retrieved property data */
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpdata);
|
|
|
|
|
|
|
|
return hUnicodeText;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_ImportCompoundText
|
|
|
|
*
|
|
|
|
* Import COMPOUND_TEXT to CF_UNICODE
|
|
|
|
*/
|
2008-06-26 16:20:02 +02:00
|
|
|
static HANDLE X11DRV_CLIPBOARD_ImportCompoundText(Display *display, Window w, Atom prop)
|
2005-11-01 19:05:40 +01:00
|
|
|
{
|
2008-11-24 21:06:40 +01:00
|
|
|
int i, j, ret;
|
2005-11-01 19:05:40 +01:00
|
|
|
char** srcstr;
|
|
|
|
int count, lcount;
|
|
|
|
int srclen, destlen;
|
|
|
|
HANDLE hUnicodeText;
|
|
|
|
XTextProperty txtprop;
|
|
|
|
|
2008-10-31 04:18:00 +01:00
|
|
|
if (!X11DRV_CLIPBOARD_ReadProperty(display, w, prop, &txtprop.value, &txtprop.nitems))
|
2005-11-01 19:05:40 +01:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-10-31 04:18:00 +01:00
|
|
|
txtprop.encoding = x11drv_atom(COMPOUND_TEXT);
|
|
|
|
txtprop.format = 8;
|
|
|
|
wine_tsx11_lock();
|
2008-11-24 21:06:40 +01:00
|
|
|
ret = XmbTextPropertyToTextList(display, &txtprop, &srcstr, &count);
|
2005-11-01 19:05:40 +01:00
|
|
|
wine_tsx11_unlock();
|
2008-10-31 04:18:00 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, txtprop.value);
|
2008-11-24 21:06:40 +01:00
|
|
|
if (ret != Success || !count) return 0;
|
2005-11-01 19:05:40 +01:00
|
|
|
|
|
|
|
TRACE("Importing %d line(s)\n", count);
|
|
|
|
|
|
|
|
/* Compute number of lines */
|
|
|
|
srclen = strlen(srcstr[0]);
|
|
|
|
for (i = 0, lcount = 0; i <= srclen; i++)
|
|
|
|
{
|
|
|
|
if (srcstr[0][i] == '\n')
|
|
|
|
lcount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
destlen = MultiByteToWideChar(CP_UNIXCP, 0, srcstr[0], -1, NULL, 0);
|
|
|
|
|
|
|
|
TRACE("lcount = %d, destlen=%d, srcstr %s\n", lcount, destlen, srcstr[0]);
|
|
|
|
|
|
|
|
if ((hUnicodeText = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, (destlen + lcount + 1) * sizeof(WCHAR))))
|
|
|
|
{
|
|
|
|
WCHAR *deststr = GlobalLock(hUnicodeText);
|
|
|
|
MultiByteToWideChar(CP_UNIXCP, 0, srcstr[0], -1, deststr, destlen);
|
|
|
|
|
|
|
|
if (lcount)
|
|
|
|
{
|
|
|
|
for (i = destlen - 1, j = destlen + lcount - 1; i >= 0; i--, j--)
|
|
|
|
{
|
|
|
|
deststr[j] = deststr[i];
|
|
|
|
|
|
|
|
if (deststr[i] == '\n')
|
|
|
|
deststr[--j] = '\r';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GlobalUnlock(hUnicodeText);
|
|
|
|
}
|
|
|
|
|
|
|
|
wine_tsx11_lock();
|
|
|
|
XFreeStringList(srcstr);
|
|
|
|
wine_tsx11_unlock();
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
return hUnicodeText;
|
1999-09-03 17:17:57 +02:00
|
|
|
}
|
1998-12-07 10:13:40 +01:00
|
|
|
|
1999-09-20 17:42:47 +02:00
|
|
|
|
1999-10-24 22:22:24 +02:00
|
|
|
/**************************************************************************
|
2003-06-24 01:02:02 +02:00
|
|
|
* X11DRV_CLIPBOARD_ImportXAPIXMAP
|
|
|
|
*
|
|
|
|
* Import XA_PIXMAP, converting the image to CF_DIB.
|
1999-10-24 22:22:24 +02:00
|
|
|
*/
|
2009-03-13 14:03:18 +01:00
|
|
|
static HANDLE X11DRV_CLIPBOARD_ImportXAPIXMAP(Display *display, Window w, Atom prop)
|
1999-10-24 22:22:24 +02:00
|
|
|
{
|
2005-11-01 19:05:40 +01:00
|
|
|
HWND hwnd;
|
|
|
|
HDC hdc;
|
|
|
|
LPBYTE lpdata;
|
2006-02-22 19:53:19 +01:00
|
|
|
unsigned long cbytes;
|
2005-11-01 19:05:40 +01:00
|
|
|
Pixmap *pPixmap;
|
|
|
|
HANDLE hClipData = 0;
|
|
|
|
|
2008-06-26 16:20:02 +02:00
|
|
|
if (X11DRV_CLIPBOARD_ReadProperty(display, w, prop, &lpdata, &cbytes))
|
2005-11-01 19:05:40 +01:00
|
|
|
{
|
|
|
|
pPixmap = (Pixmap *) lpdata;
|
1999-10-24 22:22:24 +02:00
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
hwnd = GetOpenClipboardWindow();
|
|
|
|
hdc = GetDC(hwnd);
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
hClipData = X11DRV_DIB_CreateDIBFromPixmap(*pPixmap, hdc);
|
|
|
|
ReleaseDC(hwnd, hdc);
|
|
|
|
|
|
|
|
/* Free the retrieved property data */
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpdata);
|
|
|
|
}
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
return hClipData;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-25 00:19:38 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_ImportImageBmp
|
|
|
|
*
|
|
|
|
* Import image/bmp, converting the image to CF_DIB.
|
|
|
|
*/
|
|
|
|
static HANDLE X11DRV_CLIPBOARD_ImportImageBmp(Display *display, Window w, Atom prop)
|
|
|
|
{
|
|
|
|
LPBYTE lpdata;
|
|
|
|
unsigned long cbytes;
|
|
|
|
HANDLE hClipData = 0;
|
|
|
|
|
|
|
|
if (X11DRV_CLIPBOARD_ReadProperty(display, w, prop, &lpdata, &cbytes))
|
|
|
|
{
|
|
|
|
BITMAPFILEHEADER *bfh = (BITMAPFILEHEADER*)lpdata;
|
|
|
|
|
|
|
|
if (cbytes >= sizeof(BITMAPFILEHEADER)+sizeof(BITMAPCOREHEADER) &&
|
|
|
|
bfh->bfType == 0x4d42 /* "BM" */)
|
|
|
|
{
|
|
|
|
BITMAPINFO *bmi = (BITMAPINFO*)(bfh+1);
|
|
|
|
HBITMAP hbmp;
|
|
|
|
HDC hdc;
|
|
|
|
|
|
|
|
hdc = GetDC(0);
|
|
|
|
hbmp = CreateDIBitmap(
|
|
|
|
hdc,
|
|
|
|
&(bmi->bmiHeader),
|
|
|
|
CBM_INIT,
|
|
|
|
lpdata+bfh->bfOffBits,
|
|
|
|
bmi,
|
|
|
|
DIB_RGB_COLORS
|
|
|
|
);
|
|
|
|
|
|
|
|
hClipData = X11DRV_DIB_CreateDIBFromBitmap(hdc, hbmp);
|
|
|
|
|
|
|
|
DeleteObject(hbmp);
|
|
|
|
ReleaseDC(0, hdc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free the retrieved property data */
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hClipData;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_ImportMetaFilePict
|
|
|
|
*
|
|
|
|
* Import MetaFilePict.
|
|
|
|
*/
|
2009-03-13 14:03:18 +01:00
|
|
|
static HANDLE X11DRV_CLIPBOARD_ImportMetaFilePict(Display *display, Window w, Atom prop)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2005-11-01 19:05:40 +01:00
|
|
|
LPBYTE lpdata;
|
2006-02-22 19:53:19 +01:00
|
|
|
unsigned long cbytes;
|
2005-11-01 19:05:40 +01:00
|
|
|
HANDLE hClipData = 0;
|
|
|
|
|
2008-06-26 16:20:02 +02:00
|
|
|
if (X11DRV_CLIPBOARD_ReadProperty(display, w, prop, &lpdata, &cbytes))
|
2005-11-01 19:05:40 +01:00
|
|
|
{
|
|
|
|
if (cbytes)
|
2008-12-01 02:09:52 +01:00
|
|
|
hClipData = X11DRV_CLIPBOARD_SerializeMetafile(CF_METAFILEPICT, lpdata, (LPDWORD)&cbytes, FALSE);
|
2005-11-01 19:05:40 +01:00
|
|
|
|
|
|
|
/* Free the retrieved property data */
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hClipData;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_ImportEnhMetaFile
|
|
|
|
*
|
|
|
|
* Import EnhMetaFile.
|
|
|
|
*/
|
2009-03-13 14:03:18 +01:00
|
|
|
static HANDLE X11DRV_CLIPBOARD_ImportEnhMetaFile(Display *display, Window w, Atom prop)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2005-11-01 19:05:40 +01:00
|
|
|
LPBYTE lpdata;
|
2006-02-22 19:53:19 +01:00
|
|
|
unsigned long cbytes;
|
2005-11-01 19:05:40 +01:00
|
|
|
HANDLE hClipData = 0;
|
|
|
|
|
2008-06-26 16:20:02 +02:00
|
|
|
if (X11DRV_CLIPBOARD_ReadProperty(display, w, prop, &lpdata, &cbytes))
|
2005-11-01 19:05:40 +01:00
|
|
|
{
|
|
|
|
if (cbytes)
|
2008-12-01 02:09:52 +01:00
|
|
|
hClipData = X11DRV_CLIPBOARD_SerializeMetafile(CF_ENHMETAFILE, lpdata, (LPDWORD)&cbytes, FALSE);
|
2005-11-01 19:05:40 +01:00
|
|
|
|
|
|
|
/* Free the retrieved property data */
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hClipData;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_ImportClipbordaData
|
|
|
|
*
|
|
|
|
* Generic import clipboard data routine.
|
|
|
|
*/
|
2009-03-13 14:03:18 +01:00
|
|
|
static HANDLE X11DRV_CLIPBOARD_ImportClipboardData(Display *display, Window w, Atom prop)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
|
|
|
LPVOID lpClipData;
|
2005-11-01 19:05:40 +01:00
|
|
|
LPBYTE lpdata;
|
2006-02-22 19:53:19 +01:00
|
|
|
unsigned long cbytes;
|
2003-06-24 01:02:02 +02:00
|
|
|
HANDLE hClipData = 0;
|
|
|
|
|
2008-06-26 16:20:02 +02:00
|
|
|
if (X11DRV_CLIPBOARD_ReadProperty(display, w, prop, &lpdata, &cbytes))
|
2001-06-19 05:32:44 +02:00
|
|
|
{
|
2005-11-01 19:05:40 +01:00
|
|
|
if (cbytes)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2005-11-01 19:05:40 +01:00
|
|
|
/* Turn on the DDESHARE flag to enable shared 32 bit memory */
|
|
|
|
hClipData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, cbytes);
|
|
|
|
if (hClipData == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if ((lpClipData = GlobalLock(hClipData)))
|
|
|
|
{
|
|
|
|
memcpy(lpClipData, lpdata, cbytes);
|
|
|
|
GlobalUnlock(hClipData);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GlobalFree(hClipData);
|
|
|
|
hClipData = 0;
|
|
|
|
}
|
2005-03-14 11:03:39 +01:00
|
|
|
}
|
2005-11-01 19:05:40 +01:00
|
|
|
|
|
|
|
/* Free the retrieved property data */
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpdata);
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return hClipData;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
2004-01-08 01:43:46 +01:00
|
|
|
X11DRV_CLIPBOARD_ExportClipboardData
|
2003-06-24 01:02:02 +02:00
|
|
|
*
|
|
|
|
* Generic export clipboard data routine.
|
|
|
|
*/
|
2009-03-13 14:03:18 +01:00
|
|
|
static HANDLE X11DRV_CLIPBOARD_ExportClipboardData(Display *display, Window requestor, Atom aTarget,
|
2008-06-26 16:20:02 +02:00
|
|
|
Atom rprop, LPWINE_CLIPDATA lpData, LPDWORD lpBytes)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
|
|
|
LPVOID lpClipData;
|
2005-11-01 19:05:40 +01:00
|
|
|
UINT datasize = 0;
|
2003-06-24 01:02:02 +02:00
|
|
|
HANDLE hClipData = 0;
|
|
|
|
|
|
|
|
*lpBytes = 0; /* Assume failure */
|
|
|
|
|
2008-06-26 16:20:02 +02:00
|
|
|
if (!X11DRV_CLIPBOARD_RenderFormat(display, lpData))
|
2009-04-24 13:24:52 +02:00
|
|
|
ERR("Failed to export %04x format\n", lpData->wFormatID);
|
2003-06-24 01:02:02 +02:00
|
|
|
else
|
|
|
|
{
|
2009-12-22 21:18:40 +01:00
|
|
|
datasize = GlobalSize(lpData->hData);
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
hClipData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, datasize);
|
2005-03-14 11:03:39 +01:00
|
|
|
if (hClipData == 0) return NULL;
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
if ((lpClipData = GlobalLock(hClipData)))
|
|
|
|
{
|
2009-12-22 21:18:40 +01:00
|
|
|
LPVOID lpdata = GlobalLock(lpData->hData);
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
memcpy(lpClipData, lpdata, datasize);
|
|
|
|
*lpBytes = datasize;
|
2001-06-19 05:32:44 +02:00
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
GlobalUnlock(lpData->hData);
|
2003-06-24 01:02:02 +02:00
|
|
|
GlobalUnlock(hClipData);
|
2005-03-14 11:03:39 +01:00
|
|
|
} else {
|
|
|
|
GlobalFree(hClipData);
|
|
|
|
hClipData = 0;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
2001-06-19 05:32:44 +02:00
|
|
|
}
|
1999-10-24 22:22:24 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
return hClipData;
|
|
|
|
}
|
2002-04-06 02:41:43 +02:00
|
|
|
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_ExportXAString
|
|
|
|
*
|
2005-11-01 19:05:40 +01:00
|
|
|
* Export CF_TEXT converting the string to XA_STRING.
|
2003-07-08 23:02:51 +02:00
|
|
|
* Helper function for X11DRV_CLIPBOARD_ExportString.
|
2003-06-24 01:02:02 +02:00
|
|
|
*/
|
2005-07-24 19:10:38 +02:00
|
|
|
static HANDLE X11DRV_CLIPBOARD_ExportXAString(LPWINE_CLIPDATA lpData, LPDWORD lpBytes)
|
2005-11-01 19:05:40 +01:00
|
|
|
{
|
|
|
|
UINT i, j;
|
|
|
|
UINT size;
|
|
|
|
LPSTR text, lpstr = NULL;
|
|
|
|
|
|
|
|
*lpBytes = 0; /* Assume return has zero bytes */
|
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
text = GlobalLock(lpData->hData);
|
2005-11-01 19:05:40 +01:00
|
|
|
size = strlen(text);
|
|
|
|
|
|
|
|
/* remove carriage returns */
|
|
|
|
lpstr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size + 1);
|
|
|
|
if (lpstr == NULL)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
for (i = 0,j = 0; i < size && text[i]; i++)
|
|
|
|
{
|
|
|
|
if (text[i] == '\r' && (text[i+1] == '\n' || text[i+1] == '\0'))
|
|
|
|
continue;
|
|
|
|
lpstr[j++] = text[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
lpstr[j]='\0';
|
|
|
|
*lpBytes = j; /* Number of bytes in string */
|
|
|
|
|
|
|
|
done:
|
|
|
|
HeapFree(GetProcessHeap(), 0, text);
|
2009-12-22 21:18:40 +01:00
|
|
|
GlobalUnlock(lpData->hData);
|
2005-11-01 19:05:40 +01:00
|
|
|
|
|
|
|
return lpstr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_ExportUTF8String
|
|
|
|
*
|
|
|
|
* Export CF_UNICODE converting the string to UTF8.
|
|
|
|
* Helper function for X11DRV_CLIPBOARD_ExportString.
|
|
|
|
*/
|
|
|
|
static HANDLE X11DRV_CLIPBOARD_ExportUTF8String(LPWINE_CLIPDATA lpData, LPDWORD lpBytes)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2004-08-12 01:45:34 +02:00
|
|
|
UINT i, j;
|
2003-06-24 01:02:02 +02:00
|
|
|
UINT size;
|
|
|
|
LPWSTR uni_text;
|
2005-03-14 11:03:39 +01:00
|
|
|
LPSTR text, lpstr = NULL;
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
*lpBytes = 0; /* Assume return has zero bytes */
|
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
uni_text = GlobalLock(lpData->hData);
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
size = WideCharToMultiByte(CP_UTF8, 0, uni_text, -1, NULL, 0, NULL, NULL);
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
text = HeapAlloc(GetProcessHeap(), 0, size);
|
2005-11-01 19:05:40 +01:00
|
|
|
if (!text)
|
|
|
|
goto done;
|
|
|
|
WideCharToMultiByte(CP_UTF8, 0, uni_text, -1, text, size, NULL, NULL);
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
/* remove carriage returns */
|
2005-11-01 19:05:40 +01:00
|
|
|
lpstr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size--);
|
|
|
|
if (lpstr == NULL)
|
|
|
|
goto done;
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
for (i = 0,j = 0; i < size && text[i]; i++)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2005-11-01 19:05:40 +01:00
|
|
|
if (text[i] == '\r' && (text[i+1] == '\n' || text[i+1] == '\0'))
|
|
|
|
continue;
|
2003-06-24 01:02:02 +02:00
|
|
|
lpstr[j++] = text[i];
|
|
|
|
}
|
|
|
|
lpstr[j]='\0';
|
|
|
|
|
|
|
|
*lpBytes = j; /* Number of bytes in string */
|
|
|
|
|
2005-03-14 11:03:39 +01:00
|
|
|
done:
|
2003-06-24 01:02:02 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, text);
|
2009-12-22 21:18:40 +01:00
|
|
|
GlobalUnlock(lpData->hData);
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
return lpstr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
|
2003-07-08 23:02:51 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_ExportCompoundText
|
|
|
|
*
|
2005-11-01 19:05:40 +01:00
|
|
|
* Export CF_UNICODE to COMPOUND_TEXT
|
2003-07-08 23:02:51 +02:00
|
|
|
* Helper function for X11DRV_CLIPBOARD_ExportString.
|
|
|
|
*/
|
2008-06-26 16:20:02 +02:00
|
|
|
static HANDLE X11DRV_CLIPBOARD_ExportCompoundText(Display *display, Window requestor, Atom aTarget, Atom rprop,
|
2003-07-08 23:02:51 +02:00
|
|
|
LPWINE_CLIPDATA lpData, LPDWORD lpBytes)
|
|
|
|
{
|
|
|
|
char* lpstr = 0;
|
|
|
|
XTextProperty prop;
|
|
|
|
XICCEncodingStyle style;
|
2005-11-01 19:05:40 +01:00
|
|
|
UINT i, j;
|
|
|
|
UINT size;
|
|
|
|
LPWSTR uni_text;
|
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
uni_text = GlobalLock(lpData->hData);
|
2005-11-01 19:05:40 +01:00
|
|
|
|
|
|
|
size = WideCharToMultiByte(CP_UNIXCP, 0, uni_text, -1, NULL, 0, NULL, NULL);
|
|
|
|
lpstr = HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
if (!lpstr)
|
|
|
|
return 0;
|
2003-07-08 23:02:51 +02:00
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
WideCharToMultiByte(CP_UNIXCP, 0, uni_text, -1, lpstr, size, NULL, NULL);
|
2003-07-08 23:02:51 +02:00
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
/* remove carriage returns */
|
|
|
|
for (i = 0, j = 0; i < size && lpstr[i]; i++)
|
2003-07-08 23:02:51 +02:00
|
|
|
{
|
2005-11-01 19:05:40 +01:00
|
|
|
if (lpstr[i] == '\r' && (lpstr[i+1] == '\n' || lpstr[i+1] == '\0'))
|
|
|
|
continue;
|
|
|
|
lpstr[j++] = lpstr[i];
|
|
|
|
}
|
|
|
|
lpstr[j]='\0';
|
2003-07-08 23:02:51 +02:00
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
GlobalUnlock(lpData->hData);
|
2003-07-08 23:02:51 +02:00
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
if (aTarget == x11drv_atom(COMPOUND_TEXT))
|
|
|
|
style = XCompoundTextStyle;
|
|
|
|
else
|
|
|
|
style = XStdICCTextStyle;
|
|
|
|
|
|
|
|
/* Update the X property */
|
|
|
|
wine_tsx11_lock();
|
|
|
|
if (XmbTextListToTextProperty(display, &lpstr, 1, style, &prop) == Success)
|
|
|
|
{
|
|
|
|
XSetTextProperty(display, requestor, &prop, rprop);
|
|
|
|
XFree(prop.value);
|
2003-07-08 23:02:51 +02:00
|
|
|
}
|
2005-11-01 19:05:40 +01:00
|
|
|
wine_tsx11_unlock();
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpstr);
|
2003-07-08 23:02:51 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_ExportString
|
|
|
|
*
|
2005-11-01 19:05:40 +01:00
|
|
|
* Export string
|
2003-07-08 23:02:51 +02:00
|
|
|
*/
|
2009-03-13 14:03:18 +01:00
|
|
|
static HANDLE X11DRV_CLIPBOARD_ExportString(Display *display, Window requestor, Atom aTarget, Atom rprop,
|
2008-06-26 16:20:02 +02:00
|
|
|
LPWINE_CLIPDATA lpData, LPDWORD lpBytes)
|
2003-07-08 23:02:51 +02:00
|
|
|
{
|
2008-06-26 16:20:02 +02:00
|
|
|
if (X11DRV_CLIPBOARD_RenderFormat(display, lpData))
|
2003-07-08 23:02:51 +02:00
|
|
|
{
|
|
|
|
if (aTarget == XA_STRING)
|
|
|
|
return X11DRV_CLIPBOARD_ExportXAString(lpData, lpBytes);
|
2003-11-20 05:24:18 +01:00
|
|
|
else if (aTarget == x11drv_atom(COMPOUND_TEXT) || aTarget == x11drv_atom(TEXT))
|
2008-06-26 16:20:02 +02:00
|
|
|
return X11DRV_CLIPBOARD_ExportCompoundText(display, requestor, aTarget,
|
2003-07-08 23:02:51 +02:00
|
|
|
rprop, lpData, lpBytes);
|
|
|
|
else
|
2005-11-01 19:05:40 +01:00
|
|
|
{
|
|
|
|
TRACE("Exporting target %ld to default UTF8_STRING\n", aTarget);
|
|
|
|
return X11DRV_CLIPBOARD_ExportUTF8String(lpData, lpBytes);
|
|
|
|
}
|
2003-07-08 23:02:51 +02:00
|
|
|
}
|
|
|
|
else
|
2009-04-24 13:24:52 +02:00
|
|
|
ERR("Failed to render %04x format\n", lpData->wFormatID);
|
2003-07-08 23:02:51 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_ExportXAPIXMAP
|
|
|
|
*
|
|
|
|
* Export CF_DIB to XA_PIXMAP.
|
|
|
|
*/
|
2009-03-13 14:03:18 +01:00
|
|
|
static HANDLE X11DRV_CLIPBOARD_ExportXAPIXMAP(Display *display, Window requestor, Atom aTarget, Atom rprop,
|
2003-07-08 23:02:51 +02:00
|
|
|
LPWINE_CLIPDATA lpdata, LPDWORD lpBytes)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
|
|
|
HDC hdc;
|
2004-02-20 06:43:00 +01:00
|
|
|
HANDLE hData;
|
|
|
|
unsigned char* lpData;
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2008-06-26 16:20:02 +02:00
|
|
|
if (!X11DRV_CLIPBOARD_RenderFormat(display, lpdata))
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2009-04-24 13:24:52 +02:00
|
|
|
ERR("Failed to export %04x format\n", lpdata->wFormatID);
|
2003-06-24 01:02:02 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-02-20 06:43:00 +01:00
|
|
|
if (!lpdata->drvData) /* If not already rendered */
|
|
|
|
{
|
|
|
|
/* For convert from packed DIB to Pixmap */
|
|
|
|
hdc = GetDC(0);
|
2009-12-22 21:18:40 +01:00
|
|
|
lpdata->drvData = (UINT) X11DRV_DIB_CreatePixmapFromDIB(lpdata->hData, hdc);
|
2004-02-20 06:43:00 +01:00
|
|
|
ReleaseDC(0, hdc);
|
|
|
|
}
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2004-02-20 06:43:00 +01:00
|
|
|
*lpBytes = sizeof(Pixmap); /* pixmap is a 32bit value */
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2004-02-20 06:43:00 +01:00
|
|
|
/* Wrap pixmap so we can return a handle */
|
|
|
|
hData = GlobalAlloc(0, *lpBytes);
|
|
|
|
lpData = GlobalLock(hData);
|
|
|
|
memcpy(lpData, &lpdata->drvData, *lpBytes);
|
|
|
|
GlobalUnlock(hData);
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2008-02-02 18:27:19 +01:00
|
|
|
return hData;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-30 21:40:29 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_ExportImageBmp
|
|
|
|
*
|
|
|
|
* Export CF_DIB to image/bmp.
|
|
|
|
*/
|
|
|
|
static HANDLE X11DRV_CLIPBOARD_ExportImageBmp(Display *display, Window requestor, Atom aTarget, Atom rprop,
|
|
|
|
LPWINE_CLIPDATA lpdata, LPDWORD lpBytes)
|
|
|
|
{
|
|
|
|
HANDLE hpackeddib;
|
|
|
|
LPBYTE dibdata;
|
|
|
|
UINT bmpsize;
|
|
|
|
HANDLE hbmpdata;
|
|
|
|
LPBYTE bmpdata;
|
|
|
|
BITMAPFILEHEADER *bfh;
|
|
|
|
|
|
|
|
*lpBytes = 0;
|
|
|
|
|
|
|
|
if (!X11DRV_CLIPBOARD_RenderFormat(display, lpdata))
|
|
|
|
{
|
|
|
|
ERR("Failed to export %04x format\n", lpdata->wFormatID);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
hpackeddib = lpdata->hData;
|
2009-04-30 21:40:29 +02:00
|
|
|
|
|
|
|
dibdata = GlobalLock(hpackeddib);
|
|
|
|
if (!dibdata)
|
|
|
|
{
|
|
|
|
ERR("Failed to lock packed DIB\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bmpsize = sizeof(BITMAPFILEHEADER) + GlobalSize(hpackeddib);
|
|
|
|
|
|
|
|
hbmpdata = GlobalAlloc(0, bmpsize);
|
|
|
|
|
|
|
|
if (hbmpdata)
|
|
|
|
{
|
|
|
|
bmpdata = GlobalLock(hbmpdata);
|
|
|
|
|
|
|
|
if (!bmpdata)
|
|
|
|
{
|
|
|
|
GlobalFree(hbmpdata);
|
|
|
|
GlobalUnlock(hpackeddib);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* bitmap file header */
|
|
|
|
bfh = (BITMAPFILEHEADER*)bmpdata;
|
|
|
|
bfh->bfType = 0x4d42; /* "BM" */
|
|
|
|
bfh->bfSize = bmpsize;
|
|
|
|
bfh->bfReserved1 = 0;
|
|
|
|
bfh->bfReserved2 = 0;
|
|
|
|
bfh->bfOffBits = sizeof(BITMAPFILEHEADER) + bitmap_info_size((BITMAPINFO*)dibdata, DIB_RGB_COLORS);
|
|
|
|
|
|
|
|
/* rest of bitmap is the same as the packed dib */
|
|
|
|
memcpy(bfh+1, dibdata, bmpsize-sizeof(BITMAPFILEHEADER));
|
|
|
|
|
|
|
|
*lpBytes = bmpsize;
|
|
|
|
|
|
|
|
GlobalUnlock(hbmpdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
GlobalUnlock(hpackeddib);
|
|
|
|
|
|
|
|
return hbmpdata;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_ExportMetaFilePict
|
|
|
|
*
|
|
|
|
* Export MetaFilePict.
|
|
|
|
*/
|
2009-03-13 14:03:18 +01:00
|
|
|
static HANDLE X11DRV_CLIPBOARD_ExportMetaFilePict(Display *display, Window requestor, Atom aTarget, Atom rprop,
|
2008-06-26 16:20:02 +02:00
|
|
|
LPWINE_CLIPDATA lpdata, LPDWORD lpBytes)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2008-06-26 16:20:02 +02:00
|
|
|
if (!X11DRV_CLIPBOARD_RenderFormat(display, lpdata))
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2009-04-24 13:24:52 +02:00
|
|
|
ERR("Failed to export %04x format\n", lpdata->wFormatID);
|
2003-06-24 01:02:02 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
return X11DRV_CLIPBOARD_SerializeMetafile(CF_METAFILEPICT, lpdata->hData, lpBytes, TRUE);
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_ExportEnhMetaFile
|
|
|
|
*
|
|
|
|
* Export EnhMetaFile.
|
|
|
|
*/
|
2009-03-13 14:03:18 +01:00
|
|
|
static HANDLE X11DRV_CLIPBOARD_ExportEnhMetaFile(Display *display, Window requestor, Atom aTarget, Atom rprop,
|
2008-06-26 16:20:02 +02:00
|
|
|
LPWINE_CLIPDATA lpdata, LPDWORD lpBytes)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2008-06-26 16:20:02 +02:00
|
|
|
if (!X11DRV_CLIPBOARD_RenderFormat(display, lpdata))
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2009-04-24 13:24:52 +02:00
|
|
|
ERR("Failed to export %04x format\n", lpdata->wFormatID);
|
2003-06-24 01:02:02 +02:00
|
|
|
return 0;
|
|
|
|
}
|
1999-10-24 22:22:24 +02:00
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
return X11DRV_CLIPBOARD_SerializeMetafile(CF_ENHMETAFILE, lpdata->hData, lpBytes, TRUE);
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
1999-10-24 22:22:24 +02:00
|
|
|
|
|
|
|
|
2009-11-22 21:30:18 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* get_html_description_field
|
|
|
|
*
|
|
|
|
* Find the value of a field in an HTML Format description.
|
|
|
|
*/
|
|
|
|
static LPCSTR get_html_description_field(LPCSTR data, LPCSTR keyword)
|
|
|
|
{
|
|
|
|
LPCSTR pos=data;
|
|
|
|
|
|
|
|
while (pos && *pos && *pos != '<')
|
|
|
|
{
|
|
|
|
if (memcmp(pos, keyword, strlen(keyword)) == 0)
|
|
|
|
return pos+strlen(keyword);
|
|
|
|
|
|
|
|
pos = strchr(pos, '\n');
|
|
|
|
if (pos) pos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_ExportTextHtml
|
|
|
|
*
|
|
|
|
* Export HTML Format to text/html.
|
|
|
|
*
|
|
|
|
* FIXME: We should attempt to add an <a base> tag and convert windows paths.
|
|
|
|
*/
|
|
|
|
static HANDLE X11DRV_CLIPBOARD_ExportTextHtml(Display *display, Window requestor, Atom aTarget,
|
|
|
|
Atom rprop, LPWINE_CLIPDATA lpdata, LPDWORD lpBytes)
|
|
|
|
{
|
|
|
|
HANDLE hdata;
|
|
|
|
LPCSTR data, field_value;
|
|
|
|
UINT fragmentstart, fragmentend, htmlsize;
|
|
|
|
HANDLE hhtmldata=NULL;
|
|
|
|
LPSTR htmldata;
|
|
|
|
|
|
|
|
*lpBytes = 0;
|
|
|
|
|
|
|
|
if (!X11DRV_CLIPBOARD_RenderFormat(display, lpdata))
|
|
|
|
{
|
|
|
|
ERR("Failed to export %04x format\n", lpdata->wFormatID);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
hdata = lpdata->hData;
|
2009-11-22 21:30:18 +01:00
|
|
|
|
|
|
|
data = GlobalLock(hdata);
|
|
|
|
if (!data)
|
|
|
|
{
|
|
|
|
ERR("Failed to lock HTML Format data\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read the important fields */
|
|
|
|
field_value = get_html_description_field(data, "StartFragment:");
|
|
|
|
if (!field_value)
|
|
|
|
{
|
|
|
|
ERR("Couldn't find StartFragment value\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
fragmentstart = atoi(field_value);
|
|
|
|
|
|
|
|
field_value = get_html_description_field(data, "EndFragment:");
|
|
|
|
if (!field_value)
|
|
|
|
{
|
|
|
|
ERR("Couldn't find EndFragment value\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
fragmentend = atoi(field_value);
|
|
|
|
|
|
|
|
/* export only the fragment */
|
|
|
|
htmlsize = fragmentend - fragmentstart + 1;
|
|
|
|
|
|
|
|
hhtmldata = GlobalAlloc(0, htmlsize);
|
|
|
|
|
|
|
|
if (hhtmldata)
|
|
|
|
{
|
|
|
|
htmldata = GlobalLock(hhtmldata);
|
|
|
|
|
|
|
|
if (!htmldata)
|
|
|
|
{
|
|
|
|
GlobalFree(hhtmldata);
|
|
|
|
htmldata = NULL;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(htmldata, &data[fragmentstart], fragmentend-fragmentstart);
|
|
|
|
htmldata[htmlsize-1] = '\0';
|
|
|
|
|
|
|
|
*lpBytes = htmlsize;
|
|
|
|
|
|
|
|
GlobalUnlock(htmldata);
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
|
|
|
|
GlobalUnlock(hdata);
|
|
|
|
|
|
|
|
return hhtmldata;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_QueryTargets
|
|
|
|
*/
|
2004-07-08 22:14:37 +02:00
|
|
|
static BOOL X11DRV_CLIPBOARD_QueryTargets(Display *display, Window w, Atom selection,
|
|
|
|
Atom target, XEvent *xe)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
|
|
|
INT i;
|
|
|
|
Bool res;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
wine_tsx11_lock();
|
2004-07-08 22:14:37 +02:00
|
|
|
XConvertSelection(display, selection, target,
|
|
|
|
x11drv_atom(SELECTION_DATA), w, CurrentTime);
|
2003-06-24 01:02:02 +02:00
|
|
|
wine_tsx11_unlock();
|
1999-10-24 22:22:24 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
/*
|
|
|
|
* Wait until SelectionNotify is received
|
1999-10-24 22:22:24 +02:00
|
|
|
*/
|
2003-06-24 01:02:02 +02:00
|
|
|
for (i = 0; i < SELECTION_RETRIES; i++)
|
1999-10-24 22:22:24 +02:00
|
|
|
{
|
2003-06-24 01:02:02 +02:00
|
|
|
wine_tsx11_lock();
|
|
|
|
res = XCheckTypedWindowEvent(display, w, SelectionNotify, xe);
|
|
|
|
wine_tsx11_unlock();
|
|
|
|
if (res && xe->xselection.selection == selection) break;
|
1999-10-24 22:22:24 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
usleep(SELECTION_WAIT);
|
1999-10-24 22:22:24 +02:00
|
|
|
}
|
|
|
|
|
2009-06-03 15:54:22 +02:00
|
|
|
if (i == SELECTION_RETRIES)
|
|
|
|
{
|
|
|
|
ERR("Timed out waiting for SelectionNotify event\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-06-24 01:02:02 +02:00
|
|
|
/* Verify that the selection returned a valid TARGETS property */
|
2004-07-08 22:14:37 +02:00
|
|
|
if ((xe->xselection.target != target) || (xe->xselection.property == None))
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
|
|
|
/* Selection owner failed to respond or we missed the SelectionNotify */
|
|
|
|
WARN("Failed to retrieve TARGETS for selection %ld.\n", selection);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-10-24 22:22:24 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-09 20:09:40 +02:00
|
|
|
static int is_atom_error( Display *display, XErrorEvent *event, void *arg )
|
|
|
|
{
|
|
|
|
return (event->error_code == BadAtom);
|
|
|
|
}
|
|
|
|
|
2004-07-08 22:14:37 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_InsertSelectionProperties
|
|
|
|
*
|
2005-11-01 19:05:40 +01:00
|
|
|
* Mark properties available for future retrieval.
|
2004-07-08 22:14:37 +02:00
|
|
|
*/
|
|
|
|
static VOID X11DRV_CLIPBOARD_InsertSelectionProperties(Display *display, Atom* properties, UINT count)
|
|
|
|
{
|
2004-08-12 01:45:34 +02:00
|
|
|
UINT i, nb_atoms = 0;
|
2004-07-08 22:14:37 +02:00
|
|
|
Atom *atoms = NULL;
|
|
|
|
|
|
|
|
/* Cache these formats in the clipboard cache */
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2005-11-01 19:05:40 +01:00
|
|
|
LPWINE_CLIPFORMAT lpFormat = X11DRV_CLIPBOARD_LookupProperty(NULL, properties[i]);
|
2004-07-08 22:14:37 +02:00
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
if (lpFormat)
|
|
|
|
{
|
|
|
|
/* We found at least one Window's format that mapps to the property.
|
|
|
|
* Continue looking for more.
|
|
|
|
*
|
|
|
|
* If more than one property map to a Window's format then we use the first
|
|
|
|
* one and ignore the rest.
|
|
|
|
*/
|
|
|
|
while (lpFormat)
|
|
|
|
{
|
2009-04-24 13:24:52 +02:00
|
|
|
TRACE("Atom#%d Property(%d): --> FormatID(%04x) %s\n",
|
2005-11-01 19:05:40 +01:00
|
|
|
i, lpFormat->drvData, lpFormat->wFormatID, debugstr_w(lpFormat->Name));
|
2009-12-22 21:18:40 +01:00
|
|
|
X11DRV_CLIPBOARD_InsertClipboardData(lpFormat->wFormatID, 0, 0, lpFormat, FALSE);
|
2005-11-01 19:05:40 +01:00
|
|
|
lpFormat = X11DRV_CLIPBOARD_LookupProperty(lpFormat, properties[i]);
|
|
|
|
}
|
|
|
|
}
|
2008-04-09 20:09:40 +02:00
|
|
|
else if (properties[i])
|
2004-07-08 22:14:37 +02:00
|
|
|
{
|
|
|
|
/* add it to the list of atoms that we don't know about yet */
|
|
|
|
if (!atoms) atoms = HeapAlloc( GetProcessHeap(), 0,
|
|
|
|
(count - i) * sizeof(*atoms) );
|
|
|
|
if (atoms) atoms[nb_atoms++] = properties[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* query all unknown atoms in one go */
|
|
|
|
if (atoms)
|
|
|
|
{
|
|
|
|
char **names = HeapAlloc( GetProcessHeap(), 0, nb_atoms * sizeof(*names) );
|
|
|
|
if (names)
|
|
|
|
{
|
2008-04-09 20:09:40 +02:00
|
|
|
X11DRV_expect_error( display, is_atom_error, NULL );
|
|
|
|
if (!XGetAtomNames( display, atoms, nb_atoms, names )) nb_atoms = 0;
|
|
|
|
if (X11DRV_check_error())
|
|
|
|
{
|
|
|
|
WARN( "got some bad atoms, ignoring\n" );
|
|
|
|
nb_atoms = 0;
|
|
|
|
}
|
2004-07-08 22:14:37 +02:00
|
|
|
for (i = 0; i < nb_atoms; i++)
|
|
|
|
{
|
2005-01-11 16:10:56 +01:00
|
|
|
WINE_CLIPFORMAT *lpFormat;
|
|
|
|
LPWSTR wname;
|
|
|
|
int len = MultiByteToWideChar(CP_UNIXCP, 0, names[i], -1, NULL, 0);
|
|
|
|
wname = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
|
|
|
|
MultiByteToWideChar(CP_UNIXCP, 0, names[i], -1, wname, len);
|
|
|
|
|
|
|
|
lpFormat = register_format( wname, atoms[i] );
|
|
|
|
HeapFree(GetProcessHeap(), 0, wname);
|
2004-07-08 22:14:37 +02:00
|
|
|
if (!lpFormat)
|
|
|
|
{
|
|
|
|
ERR("Failed to register %s property. Type will not be cached.\n", names[i]);
|
|
|
|
continue;
|
|
|
|
}
|
2009-04-24 13:24:52 +02:00
|
|
|
TRACE("Atom#%d Property(%d): --> FormatID(%04x) %s\n",
|
2005-01-11 16:10:56 +01:00
|
|
|
i, lpFormat->drvData, lpFormat->wFormatID, debugstr_w(lpFormat->Name));
|
2009-12-22 21:18:40 +01:00
|
|
|
X11DRV_CLIPBOARD_InsertClipboardData(lpFormat->wFormatID, 0, 0, lpFormat, FALSE);
|
2004-07-08 22:14:37 +02:00
|
|
|
}
|
|
|
|
wine_tsx11_lock();
|
|
|
|
for (i = 0; i < nb_atoms; i++) XFree( names[i] );
|
|
|
|
wine_tsx11_unlock();
|
|
|
|
HeapFree( GetProcessHeap(), 0, names );
|
|
|
|
}
|
|
|
|
HeapFree( GetProcessHeap(), 0, atoms );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
/**************************************************************************
|
2003-06-24 01:02:02 +02:00
|
|
|
* X11DRV_CLIPBOARD_QueryAvailableData
|
1999-09-03 17:17:57 +02:00
|
|
|
*
|
|
|
|
* Caches the list of data formats available from the current selection.
|
|
|
|
* This queries the selection owner for the TARGETS property and saves all
|
|
|
|
* reported property types.
|
|
|
|
*/
|
2008-06-26 16:20:02 +02:00
|
|
|
static int X11DRV_CLIPBOARD_QueryAvailableData(Display *display, LPCLIPBOARDINFO lpcbinfo)
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
|
|
|
XEvent xe;
|
|
|
|
Atom atype=AnyPropertyType;
|
|
|
|
int aformat;
|
|
|
|
unsigned long remain;
|
|
|
|
Atom* targetList=NULL;
|
|
|
|
Window w;
|
2003-06-24 01:02:02 +02:00
|
|
|
unsigned long cSelectionTargets = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
if (selectionAcquired & (S_PRIMARY | S_CLIPBOARD))
|
|
|
|
{
|
|
|
|
ERR("Received request to cache selection but process is owner=(%08x)\n",
|
|
|
|
(unsigned) selectionWindow);
|
2005-03-01 11:43:58 +01:00
|
|
|
return -1; /* Prevent self request */
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
1999-09-03 17:17:57 +02:00
|
|
|
|
2005-03-07 20:31:46 +01:00
|
|
|
w = thread_selection_wnd();
|
|
|
|
if (!w)
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
2005-03-07 20:31:46 +01:00
|
|
|
ERR("No window available to retrieve selection!\n");
|
2003-07-08 23:02:51 +02:00
|
|
|
return -1;
|
1999-09-03 17:17:57 +02:00
|
|
|
}
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
/*
|
|
|
|
* Query the selection owner for the TARGETS property
|
|
|
|
*/
|
2003-11-21 22:48:36 +01:00
|
|
|
wine_tsx11_lock();
|
2005-04-21 19:31:50 +02:00
|
|
|
if ((use_primary_selection && XGetSelectionOwner(display,XA_PRIMARY)) ||
|
2003-11-21 22:48:36 +01:00
|
|
|
XGetSelectionOwner(display,x11drv_atom(CLIPBOARD)))
|
2003-07-08 23:02:51 +02:00
|
|
|
{
|
2003-11-21 22:48:36 +01:00
|
|
|
wine_tsx11_unlock();
|
2005-04-21 19:31:50 +02:00
|
|
|
if (use_primary_selection && (X11DRV_CLIPBOARD_QueryTargets(display, w, XA_PRIMARY, x11drv_atom(TARGETS), &xe)))
|
2003-11-21 22:48:36 +01:00
|
|
|
selectionCacheSrc = XA_PRIMARY;
|
2004-07-08 22:14:37 +02:00
|
|
|
else if (X11DRV_CLIPBOARD_QueryTargets(display, w, x11drv_atom(CLIPBOARD), x11drv_atom(TARGETS), &xe))
|
2003-11-21 22:48:36 +01:00
|
|
|
selectionCacheSrc = x11drv_atom(CLIPBOARD);
|
|
|
|
else
|
2004-07-08 22:14:37 +02:00
|
|
|
{
|
2006-05-17 12:55:02 +02:00
|
|
|
Atom xstr = XA_STRING;
|
2004-07-08 22:14:37 +02:00
|
|
|
|
|
|
|
/* Selection Owner doesn't understand TARGETS, try retrieving XA_STRING */
|
|
|
|
if (X11DRV_CLIPBOARD_QueryTargets(display, w, XA_PRIMARY, XA_STRING, &xe))
|
|
|
|
{
|
|
|
|
X11DRV_CLIPBOARD_InsertSelectionProperties(display, &xstr, 1);
|
|
|
|
selectionCacheSrc = XA_PRIMARY;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (X11DRV_CLIPBOARD_QueryTargets(display, w, x11drv_atom(CLIPBOARD), XA_STRING, &xe))
|
|
|
|
{
|
|
|
|
X11DRV_CLIPBOARD_InsertSelectionProperties(display, &xstr, 1);
|
|
|
|
selectionCacheSrc = x11drv_atom(CLIPBOARD);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("Failed to query selection owner for available data.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2003-07-08 23:02:51 +02:00
|
|
|
}
|
|
|
|
else /* No selection owner so report 0 targets available */
|
2003-11-21 22:48:36 +01:00
|
|
|
{
|
|
|
|
wine_tsx11_unlock();
|
2003-06-24 01:02:02 +02:00
|
|
|
return 0;
|
2003-11-21 22:48:36 +01:00
|
|
|
}
|
1999-09-03 17:17:57 +02:00
|
|
|
|
|
|
|
/* Read the TARGETS property contents */
|
2003-11-21 22:48:36 +01:00
|
|
|
wine_tsx11_lock();
|
|
|
|
if(XGetWindowProperty(display, xe.xselection.requestor, xe.xselection.property,
|
2003-06-24 01:02:02 +02:00
|
|
|
0, 0x3FFF, True, AnyPropertyType/*XA_ATOM*/, &atype, &aformat, &cSelectionTargets,
|
|
|
|
&remain, (unsigned char**)&targetList) != Success)
|
|
|
|
{
|
2003-11-21 22:48:36 +01:00
|
|
|
wine_tsx11_unlock();
|
2003-06-24 01:02:02 +02:00
|
|
|
WARN("Failed to read TARGETS property\n");
|
|
|
|
}
|
1999-09-03 17:17:57 +02:00
|
|
|
else
|
|
|
|
{
|
2003-11-21 22:48:36 +01:00
|
|
|
wine_tsx11_unlock();
|
2003-11-21 06:23:17 +01:00
|
|
|
TRACE("Type %lx,Format %d,nItems %ld, Remain %ld\n",
|
|
|
|
atype, aformat, cSelectionTargets, remain);
|
1999-09-03 17:17:57 +02:00
|
|
|
/*
|
|
|
|
* The TARGETS property should have returned us a list of atoms
|
|
|
|
* corresponding to each selection target format supported.
|
|
|
|
*/
|
2008-04-08 12:24:54 +02:00
|
|
|
if (atype == XA_ATOM || atype == x11drv_atom(TARGETS))
|
|
|
|
{
|
|
|
|
if (aformat == 32)
|
|
|
|
{
|
|
|
|
X11DRV_CLIPBOARD_InsertSelectionProperties(display, targetList, cSelectionTargets);
|
|
|
|
}
|
|
|
|
else if (aformat == 8) /* work around quartz-wm brain damage */
|
|
|
|
{
|
|
|
|
unsigned long i, count = cSelectionTargets / sizeof(CARD32);
|
|
|
|
Atom *atoms = HeapAlloc( GetProcessHeap(), 0, count * sizeof(Atom) );
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
atoms[i] = ((CARD32 *)targetList)[i]; /* FIXME: byte swapping */
|
|
|
|
X11DRV_CLIPBOARD_InsertSelectionProperties( display, atoms, count );
|
|
|
|
HeapFree( GetProcessHeap(), 0, atoms );
|
|
|
|
}
|
|
|
|
}
|
1999-09-03 17:17:57 +02:00
|
|
|
|
|
|
|
/* Free the list of targets */
|
2003-11-21 22:48:36 +01:00
|
|
|
wine_tsx11_lock();
|
|
|
|
XFree(targetList);
|
|
|
|
wine_tsx11_unlock();
|
1999-09-03 17:17:57 +02:00
|
|
|
}
|
2000-12-23 00:26:18 +01:00
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
return cSelectionTargets;
|
1998-12-07 10:13:40 +01:00
|
|
|
}
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
2005-11-01 19:05:40 +01:00
|
|
|
* X11DRV_CLIPBOARD_ReadSelectionData
|
2003-06-24 01:02:02 +02:00
|
|
|
*
|
|
|
|
* This method is invoked only when we DO NOT own the X selection
|
|
|
|
*
|
|
|
|
* We always get the data from the selection client each time,
|
|
|
|
* since we have no way of determining if the data in our cache is stale.
|
|
|
|
*/
|
2008-06-26 16:20:02 +02:00
|
|
|
static BOOL X11DRV_CLIPBOARD_ReadSelectionData(Display *display, LPWINE_CLIPDATA lpData)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
|
|
|
Bool res;
|
2005-11-01 19:05:40 +01:00
|
|
|
DWORD i;
|
|
|
|
XEvent xe;
|
|
|
|
BOOL bRet = FALSE;
|
|
|
|
|
2009-04-24 13:24:52 +02:00
|
|
|
TRACE("%04x\n", lpData->wFormatID);
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
if (!lpData->lpFormat)
|
|
|
|
{
|
2009-04-24 13:24:52 +02:00
|
|
|
ERR("Requesting format %04x but no source format linked to data.\n",
|
2005-11-01 19:05:40 +01:00
|
|
|
lpData->wFormatID);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
if (!selectionAcquired)
|
|
|
|
{
|
2005-03-07 20:31:46 +01:00
|
|
|
Window w = thread_selection_wnd();
|
2003-06-24 01:02:02 +02:00
|
|
|
if(!w)
|
|
|
|
{
|
2005-03-07 20:31:46 +01:00
|
|
|
ERR("No window available to read selection data!\n");
|
2003-06-24 01:02:02 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
TRACE("Requesting conversion of %s property (%d) from selection type %08x\n",
|
|
|
|
debugstr_w(lpData->lpFormat->Name), lpData->lpFormat->drvData, (UINT)selectionCacheSrc);
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
wine_tsx11_lock();
|
|
|
|
XConvertSelection(display, selectionCacheSrc, lpData->lpFormat->drvData,
|
|
|
|
x11drv_atom(SELECTION_DATA), w, CurrentTime);
|
|
|
|
wine_tsx11_unlock();
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
/* wait until SelectionNotify is received */
|
|
|
|
for (i = 0; i < SELECTION_RETRIES; i++)
|
|
|
|
{
|
2003-06-24 01:02:02 +02:00
|
|
|
wine_tsx11_lock();
|
2005-11-01 19:05:40 +01:00
|
|
|
res = XCheckTypedWindowEvent(display, w, SelectionNotify, &xe);
|
2003-06-24 01:02:02 +02:00
|
|
|
wine_tsx11_unlock();
|
2005-11-01 19:05:40 +01:00
|
|
|
if (res && xe.xselection.selection == selectionCacheSrc) break;
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
usleep(SELECTION_WAIT);
|
|
|
|
}
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2009-06-03 15:54:22 +02:00
|
|
|
if (i == SELECTION_RETRIES)
|
|
|
|
{
|
|
|
|
ERR("Timed out waiting for SelectionNotify event\n");
|
|
|
|
}
|
2005-11-01 19:05:40 +01:00
|
|
|
/* Verify that the selection returned a valid TARGETS property */
|
2009-06-03 15:54:22 +02:00
|
|
|
else if (xe.xselection.property != None)
|
2005-11-01 19:05:40 +01:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Read the contents of the X selection property
|
|
|
|
* into WINE's clipboard cache and converting the
|
|
|
|
* data format if necessary.
|
|
|
|
*/
|
2008-06-26 16:20:02 +02:00
|
|
|
HANDLE hData = lpData->lpFormat->lpDrvImportFunc(display, xe.xselection.requestor,
|
2005-11-01 19:05:40 +01:00
|
|
|
xe.xselection.property);
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2010-03-17 17:39:35 +01:00
|
|
|
if (hData)
|
|
|
|
bRet = X11DRV_CLIPBOARD_InsertClipboardData(lpData->wFormatID, hData, 0, lpData->lpFormat, TRUE);
|
|
|
|
else
|
|
|
|
TRACE("Import function failed\n");
|
2005-11-01 19:05:40 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("Failed to convert selection\n");
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("Received request to cache selection data but process is owner\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Returning %d\n", bRet);
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-12-07 10:13:40 +01:00
|
|
|
/**************************************************************************
|
2008-10-31 04:18:00 +01:00
|
|
|
* X11DRV_CLIPBOARD_GetProperty
|
|
|
|
* Gets type, data and size.
|
1998-12-07 10:13:40 +01:00
|
|
|
*/
|
2008-10-31 04:18:00 +01:00
|
|
|
static BOOL X11DRV_CLIPBOARD_GetProperty(Display *display, Window w, Atom prop,
|
|
|
|
Atom *atype, unsigned char** data, unsigned long* datasize)
|
1998-12-07 10:13:40 +01:00
|
|
|
{
|
2005-11-01 19:05:40 +01:00
|
|
|
int aformat;
|
2008-03-26 12:14:41 +01:00
|
|
|
unsigned long pos = 0, nitems, remain, count;
|
|
|
|
unsigned char *val = NULL, *buffer;
|
2005-11-01 19:05:40 +01:00
|
|
|
|
2008-03-26 12:14:41 +01:00
|
|
|
TRACE("Reading property %lu from X window %lx\n", prop, w);
|
1998-12-07 10:13:40 +01:00
|
|
|
|
2008-03-26 12:14:41 +01:00
|
|
|
for (;;)
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
2008-03-26 12:14:41 +01:00
|
|
|
wine_tsx11_lock();
|
|
|
|
if (XGetWindowProperty(display, w, prop, pos, INT_MAX / 4, False,
|
2008-10-31 04:18:00 +01:00
|
|
|
AnyPropertyType, atype, &aformat, &nitems, &remain, &buffer) != Success)
|
2008-03-26 12:14:41 +01:00
|
|
|
{
|
|
|
|
wine_tsx11_unlock();
|
|
|
|
WARN("Failed to read property\n");
|
|
|
|
HeapFree( GetProcessHeap(), 0, val );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2008-04-07 11:41:54 +02:00
|
|
|
count = get_property_size( aformat, nitems );
|
2008-03-26 12:14:41 +01:00
|
|
|
if (!val) *data = HeapAlloc( GetProcessHeap(), 0, pos * sizeof(int) + count + 1 );
|
|
|
|
else *data = HeapReAlloc( GetProcessHeap(), 0, val, pos * sizeof(int) + count + 1 );
|
2001-02-23 02:31:47 +01:00
|
|
|
|
2008-03-26 12:14:41 +01:00
|
|
|
if (!*data)
|
|
|
|
{
|
|
|
|
XFree( buffer );
|
|
|
|
wine_tsx11_unlock();
|
|
|
|
HeapFree( GetProcessHeap(), 0, val );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
val = *data;
|
|
|
|
memcpy( (int *)val + pos, buffer, count );
|
|
|
|
XFree( buffer );
|
|
|
|
wine_tsx11_unlock();
|
|
|
|
if (!remain)
|
|
|
|
{
|
|
|
|
*datasize = pos * sizeof(int) + count;
|
|
|
|
val[*datasize] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pos += count / sizeof(int);
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
/* Delete the property on the window now that we are done
|
|
|
|
* This will send a PropertyNotify event to the selection owner. */
|
2008-03-26 12:14:41 +01:00
|
|
|
wine_tsx11_lock();
|
2005-11-01 19:05:40 +01:00
|
|
|
XDeleteProperty(display, w, prop);
|
2003-11-21 01:17:33 +01:00
|
|
|
wine_tsx11_unlock();
|
2005-11-01 19:05:40 +01:00
|
|
|
return TRUE;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
|
2008-10-31 04:18:00 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_ReadProperty
|
|
|
|
* Reads the contents of the X selection property.
|
|
|
|
*/
|
|
|
|
static BOOL X11DRV_CLIPBOARD_ReadProperty(Display *display, Window w, Atom prop,
|
|
|
|
unsigned char** data, unsigned long* datasize)
|
|
|
|
{
|
|
|
|
Atom atype;
|
|
|
|
XEvent xe;
|
|
|
|
|
|
|
|
if (prop == None)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!X11DRV_CLIPBOARD_GetProperty(display, w, prop, &atype, data, datasize))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
wine_tsx11_lock();
|
|
|
|
while (XCheckTypedWindowEvent(display, w, PropertyNotify, &xe))
|
|
|
|
;
|
|
|
|
wine_tsx11_unlock();
|
|
|
|
|
|
|
|
if (atype == x11drv_atom(INCR))
|
|
|
|
{
|
|
|
|
unsigned char *buf = *data;
|
|
|
|
unsigned long bufsize = 0;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned char *prop_data, *tmp;
|
|
|
|
unsigned long prop_size;
|
|
|
|
|
|
|
|
/* Wait until PropertyNotify is received */
|
|
|
|
for (i = 0; i < SELECTION_RETRIES; i++)
|
|
|
|
{
|
|
|
|
Bool res;
|
|
|
|
|
|
|
|
wine_tsx11_lock();
|
|
|
|
res = XCheckTypedWindowEvent(display, w, PropertyNotify, &xe);
|
|
|
|
wine_tsx11_unlock();
|
|
|
|
if (res && xe.xproperty.atom == prop &&
|
|
|
|
xe.xproperty.state == PropertyNewValue)
|
|
|
|
break;
|
|
|
|
usleep(SELECTION_WAIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i >= SELECTION_RETRIES ||
|
|
|
|
!X11DRV_CLIPBOARD_GetProperty(display, w, prop, &atype, &prop_data, &prop_size))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, buf);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Retrieved entire data. */
|
|
|
|
if (prop_size == 0)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, prop_data);
|
|
|
|
*data = buf;
|
|
|
|
*datasize = bufsize;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = HeapReAlloc(GetProcessHeap(), 0, buf, bufsize + prop_size + 1);
|
|
|
|
if (!tmp)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, buf);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf = tmp;
|
|
|
|
memcpy(buf + bufsize, prop_data, prop_size + 1);
|
|
|
|
bufsize += prop_size;
|
|
|
|
HeapFree(GetProcessHeap(), 0, prop_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* CLIPBOARD_SerializeMetafile
|
|
|
|
*/
|
|
|
|
static HANDLE X11DRV_CLIPBOARD_SerializeMetafile(INT wformat, HANDLE hdata, LPDWORD lpcbytes, BOOL out)
|
|
|
|
{
|
|
|
|
HANDLE h = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-09-12 12:30:05 +02:00
|
|
|
TRACE(" wFormat=%d hdata=%p out=%d\n", wformat, hdata, out);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
if (out) /* Serialize out, caller should free memory */
|
|
|
|
{
|
|
|
|
*lpcbytes = 0; /* Assume failure */
|
1999-09-20 17:42:47 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
if (wformat == CF_METAFILEPICT)
|
|
|
|
{
|
2008-12-01 02:09:52 +01:00
|
|
|
LPMETAFILEPICT lpmfp = GlobalLock(hdata);
|
2004-02-20 06:43:00 +01:00
|
|
|
unsigned int size = GetMetaFileBitsEx(lpmfp->hMF, 0, NULL);
|
2000-12-11 02:09:56 +01:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
h = GlobalAlloc(0, size + sizeof(METAFILEPICT));
|
|
|
|
if (h)
|
|
|
|
{
|
|
|
|
char *pdata = GlobalLock(h);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
memcpy(pdata, lpmfp, sizeof(METAFILEPICT));
|
|
|
|
GetMetaFileBitsEx(lpmfp->hMF, size, pdata + sizeof(METAFILEPICT));
|
1999-09-20 17:42:47 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
*lpcbytes = size + sizeof(METAFILEPICT);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
GlobalUnlock(h);
|
|
|
|
}
|
1999-09-03 17:17:57 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
GlobalUnlock(hdata);
|
|
|
|
}
|
|
|
|
else if (wformat == CF_ENHMETAFILE)
|
|
|
|
{
|
|
|
|
int size = GetEnhMetaFileBits(hdata, 0, NULL);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
h = GlobalAlloc(0, size);
|
|
|
|
if (h)
|
|
|
|
{
|
|
|
|
LPVOID pdata = GlobalLock(h);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
GetEnhMetaFileBits(hdata, size, pdata);
|
|
|
|
*lpcbytes = size;
|
1999-09-03 17:17:57 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
GlobalUnlock(h);
|
|
|
|
}
|
|
|
|
}
|
1999-09-03 17:17:57 +02:00
|
|
|
}
|
1999-09-20 17:42:47 +02:00
|
|
|
else
|
|
|
|
{
|
2003-06-24 01:02:02 +02:00
|
|
|
if (wformat == CF_METAFILEPICT)
|
|
|
|
{
|
|
|
|
h = GlobalAlloc(0, sizeof(METAFILEPICT));
|
|
|
|
if (h)
|
|
|
|
{
|
2010-04-24 14:05:19 +02:00
|
|
|
unsigned int wiresize;
|
2008-12-01 02:09:52 +01:00
|
|
|
LPMETAFILEPICT lpmfp = GlobalLock(h);
|
2004-02-20 06:43:00 +01:00
|
|
|
|
2008-02-02 18:27:19 +01:00
|
|
|
memcpy(lpmfp, hdata, sizeof(METAFILEPICT));
|
2004-02-20 06:43:00 +01:00
|
|
|
wiresize = *lpcbytes - sizeof(METAFILEPICT);
|
|
|
|
lpmfp->hMF = SetMetaFileBitsEx(wiresize,
|
2005-08-12 12:35:46 +02:00
|
|
|
((const BYTE *)hdata) + sizeof(METAFILEPICT));
|
2003-06-24 01:02:02 +02:00
|
|
|
GlobalUnlock(h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (wformat == CF_ENHMETAFILE)
|
|
|
|
{
|
2008-02-02 18:27:19 +01:00
|
|
|
h = SetEnhMetaFileBits(*lpcbytes, hdata);
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return h;
|
1998-12-07 10:13:40 +01:00
|
|
|
}
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
|
1998-12-07 10:13:40 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_ReleaseSelection
|
|
|
|
*
|
2005-01-04 21:34:46 +01:00
|
|
|
* Release XA_CLIPBOARD and XA_PRIMARY in response to a SelectionClear event.
|
1998-12-07 10:13:40 +01:00
|
|
|
*/
|
2008-06-26 16:20:02 +02:00
|
|
|
static void X11DRV_CLIPBOARD_ReleaseSelection(Display *display, Atom selType, Window w, HWND hwnd, Time time)
|
1998-12-07 10:13:40 +01:00
|
|
|
{
|
1999-10-24 22:22:24 +02:00
|
|
|
/* w is the window that lost the selection
|
1998-12-07 10:13:40 +01:00
|
|
|
*/
|
2003-06-24 01:02:02 +02:00
|
|
|
TRACE("event->window = %08x (selectionWindow = %08x) selectionAcquired=0x%08x\n",
|
|
|
|
(unsigned)w, (unsigned)selectionWindow, (unsigned)selectionAcquired);
|
1998-12-07 10:13:40 +01:00
|
|
|
|
2005-01-04 21:34:46 +01:00
|
|
|
if (selectionAcquired && (w == selectionWindow))
|
1998-12-07 10:13:40 +01:00
|
|
|
{
|
2005-01-04 21:34:46 +01:00
|
|
|
CLIPBOARDINFO cbinfo;
|
|
|
|
|
|
|
|
/* completely give up the selection */
|
|
|
|
TRACE("Lost CLIPBOARD (+PRIMARY) selection\n");
|
|
|
|
|
|
|
|
X11DRV_CLIPBOARD_GetClipboardInfo(&cbinfo);
|
|
|
|
|
2005-03-07 20:31:46 +01:00
|
|
|
if (cbinfo.flags & CB_PROCESS)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2005-03-07 20:31:46 +01:00
|
|
|
/* Since we're still the owner, this wasn't initiated by
|
2005-01-04 21:34:46 +01:00
|
|
|
another Wine process */
|
|
|
|
if (OpenClipboard(hwnd))
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2005-01-04 21:34:46 +01:00
|
|
|
/* Destroy private objects */
|
|
|
|
SendMessageW(cbinfo.hWndOwner, WM_DESTROYCLIPBOARD, 0, 0);
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-01-04 21:34:46 +01:00
|
|
|
/* Give up ownership of the windows clipboard */
|
|
|
|
X11DRV_CLIPBOARD_ReleaseOwnership();
|
|
|
|
CloseClipboard();
|
|
|
|
}
|
|
|
|
}
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-01-04 21:34:46 +01:00
|
|
|
if ((selType == x11drv_atom(CLIPBOARD)) && (selectionAcquired & S_PRIMARY))
|
|
|
|
{
|
|
|
|
TRACE("Lost clipboard. Check if we need to release PRIMARY\n");
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-01-04 21:34:46 +01:00
|
|
|
wine_tsx11_lock();
|
|
|
|
if (selectionWindow == XGetSelectionOwner(display, XA_PRIMARY))
|
|
|
|
{
|
|
|
|
TRACE("We still own PRIMARY. Releasing PRIMARY.\n");
|
|
|
|
XSetSelectionOwner(display, XA_PRIMARY, None, time);
|
1999-09-03 17:17:57 +02:00
|
|
|
}
|
2005-01-04 21:34:46 +01:00
|
|
|
else
|
|
|
|
TRACE("We no longer own PRIMARY\n");
|
|
|
|
wine_tsx11_unlock();
|
|
|
|
}
|
|
|
|
else if ((selType == XA_PRIMARY) && (selectionAcquired & S_CLIPBOARD))
|
|
|
|
{
|
|
|
|
TRACE("Lost PRIMARY. Check if we need to release CLIPBOARD\n");
|
|
|
|
|
|
|
|
wine_tsx11_lock();
|
|
|
|
if (selectionWindow == XGetSelectionOwner(display,x11drv_atom(CLIPBOARD)))
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
2005-01-04 21:34:46 +01:00
|
|
|
TRACE("We still own CLIPBOARD. Releasing CLIPBOARD.\n");
|
|
|
|
XSetSelectionOwner(display, x11drv_atom(CLIPBOARD), None, time);
|
1999-09-03 17:17:57 +02:00
|
|
|
}
|
2005-01-04 21:34:46 +01:00
|
|
|
else
|
|
|
|
TRACE("We no longer own CLIPBOARD\n");
|
|
|
|
wine_tsx11_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
selectionWindow = None;
|
|
|
|
|
|
|
|
X11DRV_EmptyClipboard(FALSE);
|
|
|
|
|
|
|
|
/* Reset the selection flags now that we are done */
|
|
|
|
selectionAcquired = S_NOSELECTION;
|
1998-12-07 10:13:40 +01:00
|
|
|
}
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
1998-12-07 10:13:40 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* IsSelectionOwner (X11DRV.@)
|
|
|
|
*
|
|
|
|
* Returns: TRUE if the selection is owned by this process, FALSE otherwise
|
|
|
|
*/
|
|
|
|
static BOOL X11DRV_CLIPBOARD_IsSelectionOwner(void)
|
|
|
|
{
|
|
|
|
return selectionAcquired;
|
1998-12-07 10:13:40 +01:00
|
|
|
}
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV Clipboard Exports
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
1998-12-07 10:13:40 +01:00
|
|
|
/**************************************************************************
|
2003-06-24 01:02:02 +02:00
|
|
|
* RegisterClipboardFormat (X11DRV.@)
|
|
|
|
*
|
|
|
|
* Registers a custom X clipboard format
|
|
|
|
* Returns: Format id or 0 on failure
|
1998-12-07 10:13:40 +01:00
|
|
|
*/
|
2008-12-16 15:32:08 +01:00
|
|
|
UINT CDECL X11DRV_RegisterClipboardFormat(LPCWSTR FormatName)
|
1998-12-07 10:13:40 +01:00
|
|
|
{
|
2003-11-21 06:23:17 +01:00
|
|
|
LPWINE_CLIPFORMAT lpFormat;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-11-21 06:23:17 +01:00
|
|
|
if (FormatName == NULL) return 0;
|
|
|
|
if (!(lpFormat = register_format( FormatName, 0 ))) return 0;
|
|
|
|
return lpFormat->wFormatID;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
1999-04-01 14:03:52 +02:00
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_GetClipboardFormatName
|
|
|
|
*/
|
2008-12-16 15:32:08 +01:00
|
|
|
INT CDECL X11DRV_GetClipboardFormatName(UINT wFormat, LPWSTR retStr, INT maxlen)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2004-06-25 04:55:37 +02:00
|
|
|
LPWINE_CLIPFORMAT lpFormat;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
TRACE("(%04X, %p, %d) !\n", wFormat, retStr, maxlen);
|
1999-09-20 17:42:47 +02:00
|
|
|
|
2004-06-25 04:55:37 +02:00
|
|
|
if (wFormat < 0xc000)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
2004-06-25 04:55:37 +02:00
|
|
|
return 0;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
2004-06-25 04:55:37 +02:00
|
|
|
lpFormat = X11DRV_CLIPBOARD_LookupFormat(wFormat);
|
|
|
|
|
|
|
|
if (!lpFormat || (lpFormat->wFlags & CF_FLAG_BUILTINFMT))
|
|
|
|
{
|
|
|
|
TRACE("Unknown format 0x%08x!\n", wFormat);
|
|
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return 0;
|
1999-09-20 17:42:47 +02:00
|
|
|
}
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-01-11 16:10:56 +01:00
|
|
|
lstrcpynW(retStr, lpFormat->Name, maxlen);
|
2004-06-25 04:55:37 +02:00
|
|
|
|
2005-01-11 16:10:56 +01:00
|
|
|
return strlenW(retStr);
|
1998-12-07 10:13:40 +01:00
|
|
|
}
|
|
|
|
|
2009-07-10 02:53:00 +02:00
|
|
|
static void selection_acquire(void)
|
|
|
|
{
|
|
|
|
Window owner;
|
|
|
|
Display *display;
|
|
|
|
|
|
|
|
owner = thread_selection_wnd();
|
|
|
|
display = thread_display();
|
|
|
|
|
|
|
|
wine_tsx11_lock();
|
|
|
|
|
|
|
|
selectionAcquired = 0;
|
|
|
|
selectionWindow = 0;
|
|
|
|
|
|
|
|
/* Grab PRIMARY selection if not owned */
|
|
|
|
if (use_primary_selection)
|
|
|
|
XSetSelectionOwner(display, XA_PRIMARY, owner, CurrentTime);
|
|
|
|
|
|
|
|
/* Grab CLIPBOARD selection if not owned */
|
|
|
|
XSetSelectionOwner(display, x11drv_atom(CLIPBOARD), owner, CurrentTime);
|
|
|
|
|
|
|
|
if (use_primary_selection && XGetSelectionOwner(display, XA_PRIMARY) == owner)
|
|
|
|
selectionAcquired |= S_PRIMARY;
|
|
|
|
|
|
|
|
if (XGetSelectionOwner(display,x11drv_atom(CLIPBOARD)) == owner)
|
|
|
|
selectionAcquired |= S_CLIPBOARD;
|
|
|
|
|
|
|
|
wine_tsx11_unlock();
|
|
|
|
|
|
|
|
if (selectionAcquired)
|
|
|
|
{
|
|
|
|
selectionWindow = owner;
|
|
|
|
TRACE("Grabbed X selection, owner=(%08x)\n", (unsigned) owner);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-01 14:16:20 +01:00
|
|
|
static DWORD WINAPI selection_thread_proc(LPVOID p)
|
2009-07-10 02:53:00 +02:00
|
|
|
{
|
2009-12-01 14:16:20 +01:00
|
|
|
HANDLE event = p;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2009-07-10 02:53:00 +02:00
|
|
|
selection_acquire();
|
2009-12-01 14:16:20 +01:00
|
|
|
SetEvent(event);
|
2009-07-10 02:53:00 +02:00
|
|
|
|
|
|
|
while (selectionAcquired)
|
|
|
|
{
|
|
|
|
MsgWaitForMultipleObjectsEx(0, NULL, INFINITE, QS_SENDMESSAGE, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2003-06-24 01:02:02 +02:00
|
|
|
|
1998-12-07 10:13:40 +01:00
|
|
|
/**************************************************************************
|
2001-02-12 04:49:07 +01:00
|
|
|
* AcquireClipboard (X11DRV.@)
|
1998-12-07 10:13:40 +01:00
|
|
|
*/
|
2008-12-16 15:32:08 +01:00
|
|
|
int CDECL X11DRV_AcquireClipboard(HWND hWndClipWindow)
|
1998-12-07 10:13:40 +01:00
|
|
|
{
|
2006-06-05 17:55:14 +02:00
|
|
|
DWORD procid;
|
2009-07-10 02:53:00 +02:00
|
|
|
HANDLE selectionThread;
|
1999-09-03 17:17:57 +02:00
|
|
|
|
2006-06-05 17:55:14 +02:00
|
|
|
TRACE(" %p\n", hWndClipWindow);
|
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
/*
|
2006-06-05 17:55:14 +02:00
|
|
|
* It's important that the selection get acquired from the thread
|
|
|
|
* that owns the clipboard window. The primary reason is that we know
|
|
|
|
* it is running a message loop and therefore can process the
|
|
|
|
* X selection events.
|
1999-09-03 17:17:57 +02:00
|
|
|
*/
|
2006-06-05 17:55:14 +02:00
|
|
|
if (hWndClipWindow &&
|
|
|
|
GetCurrentThreadId() != GetWindowThreadProcessId(hWndClipWindow, &procid))
|
1998-12-07 10:13:40 +01:00
|
|
|
{
|
2006-06-05 17:55:14 +02:00
|
|
|
if (procid != GetCurrentProcessId())
|
|
|
|
{
|
|
|
|
WARN("Setting clipboard owner to other process is not supported\n");
|
|
|
|
hWndClipWindow = NULL;
|
|
|
|
}
|
|
|
|
else
|
2005-03-07 20:31:46 +01:00
|
|
|
{
|
2006-10-08 01:34:01 +02:00
|
|
|
TRACE("Thread %x is acquiring selection with thread %x's window %p\n",
|
2005-03-07 20:31:46 +01:00
|
|
|
GetCurrentThreadId(),
|
2006-06-05 17:55:14 +02:00
|
|
|
GetWindowThreadProcessId(hWndClipWindow, NULL), hWndClipWindow);
|
|
|
|
|
|
|
|
return SendMessageW(hWndClipWindow, WM_X11DRV_ACQUIRE_SELECTION, 0, 0);
|
2005-03-07 20:31:46 +01:00
|
|
|
}
|
2006-06-05 17:55:14 +02:00
|
|
|
}
|
2005-03-07 20:31:46 +01:00
|
|
|
|
2009-07-10 02:53:00 +02:00
|
|
|
if (hWndClipWindow)
|
|
|
|
{
|
|
|
|
selection_acquire();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-01 14:16:20 +01:00
|
|
|
HANDLE event = CreateEventW(NULL, FALSE, FALSE, NULL);
|
|
|
|
selectionThread = CreateThread(NULL, 0, &selection_thread_proc, event, 0, NULL);
|
2006-06-05 17:55:14 +02:00
|
|
|
|
2009-07-10 02:53:00 +02:00
|
|
|
if (!selectionThread)
|
|
|
|
{
|
|
|
|
WARN("Could not start clipboard thread\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2006-06-05 17:55:14 +02:00
|
|
|
|
2009-12-01 14:16:20 +01:00
|
|
|
WaitForSingleObject(event, INFINITE);
|
|
|
|
CloseHandle(event);
|
2009-07-10 02:53:00 +02:00
|
|
|
CloseHandle(selectionThread);
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
2006-06-05 17:55:14 +02:00
|
|
|
|
|
|
|
return 1;
|
1999-09-03 17:17:57 +02:00
|
|
|
}
|
1998-12-07 10:13:40 +01:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
/**************************************************************************
|
2003-06-24 01:02:02 +02:00
|
|
|
* X11DRV_EmptyClipboard
|
2004-05-07 01:40:30 +02:00
|
|
|
*
|
|
|
|
* Empty cached clipboard data.
|
1999-09-03 17:17:57 +02:00
|
|
|
*/
|
2008-12-16 15:32:08 +01:00
|
|
|
void CDECL X11DRV_EmptyClipboard(BOOL keepunowned)
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
2003-06-24 01:02:02 +02:00
|
|
|
if (ClipData)
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
2004-05-07 01:40:30 +02:00
|
|
|
LPWINE_CLIPDATA lpData, lpStart;
|
2003-06-24 01:02:02 +02:00
|
|
|
LPWINE_CLIPDATA lpNext = ClipData;
|
1999-09-03 17:17:57 +02:00
|
|
|
|
2004-05-07 01:40:30 +02:00
|
|
|
TRACE(" called with %d entries in cache.\n", ClipDataCount);
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
do
|
|
|
|
{
|
2004-05-07 01:40:30 +02:00
|
|
|
lpStart = ClipData;
|
2003-06-24 01:02:02 +02:00
|
|
|
lpData = lpNext;
|
|
|
|
lpNext = lpData->NextData;
|
2004-05-07 01:40:30 +02:00
|
|
|
|
|
|
|
if (!keepunowned || !(lpData->wFlags & CF_FLAG_UNOWNED))
|
|
|
|
{
|
2003-06-24 01:02:02 +02:00
|
|
|
lpData->PrevData->NextData = lpData->NextData;
|
|
|
|
lpData->NextData->PrevData = lpData->PrevData;
|
2004-05-07 01:40:30 +02:00
|
|
|
|
|
|
|
if (lpData == ClipData)
|
|
|
|
ClipData = lpNext != lpData ? lpNext : NULL;
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
X11DRV_CLIPBOARD_FreeData(lpData);
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpData);
|
1999-09-03 17:17:57 +02:00
|
|
|
|
2004-05-07 01:40:30 +02:00
|
|
|
ClipDataCount--;
|
|
|
|
}
|
|
|
|
} while (lpNext != lpStart);
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-05-07 01:40:30 +02:00
|
|
|
TRACE(" %d entries remaining in cache.\n", ClipDataCount);
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
1999-09-03 17:17:57 +02:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_SetClipboardData
|
|
|
|
*/
|
2009-12-22 21:18:40 +01:00
|
|
|
BOOL CDECL X11DRV_SetClipboardData(UINT wFormat, HANDLE hData, BOOL owner)
|
2004-05-07 01:40:30 +02:00
|
|
|
{
|
|
|
|
DWORD flags = 0;
|
|
|
|
BOOL bResult = TRUE;
|
|
|
|
|
|
|
|
/* If it's not owned, data can only be set if the format data is not already owned
|
|
|
|
and its rendering is not delayed */
|
|
|
|
if (!owner)
|
2005-11-01 19:05:40 +01:00
|
|
|
{
|
2004-05-07 01:40:30 +02:00
|
|
|
CLIPBOARDINFO cbinfo;
|
|
|
|
LPWINE_CLIPDATA lpRender;
|
|
|
|
|
|
|
|
X11DRV_CLIPBOARD_UpdateCache(&cbinfo);
|
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
if (!hData ||
|
2004-05-07 01:40:30 +02:00
|
|
|
((lpRender = X11DRV_CLIPBOARD_LookupData(wFormat)) &&
|
|
|
|
!(lpRender->wFlags & CF_FLAG_UNOWNED)))
|
|
|
|
bResult = FALSE;
|
|
|
|
else
|
|
|
|
flags = CF_FLAG_UNOWNED;
|
|
|
|
}
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
bResult &= X11DRV_CLIPBOARD_InsertClipboardData(wFormat, hData, flags, NULL, TRUE);
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
return bResult;
|
1999-09-03 17:17:57 +02:00
|
|
|
}
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
/**************************************************************************
|
2003-06-24 01:02:02 +02:00
|
|
|
* CountClipboardFormats
|
1999-09-03 17:17:57 +02:00
|
|
|
*/
|
2008-12-16 15:32:08 +01:00
|
|
|
INT CDECL X11DRV_CountClipboardFormats(void)
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
2003-06-24 01:02:02 +02:00
|
|
|
CLIPBOARDINFO cbinfo;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
X11DRV_CLIPBOARD_UpdateCache(&cbinfo);
|
|
|
|
|
|
|
|
TRACE(" count=%d\n", ClipDataCount);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
return ClipDataCount;
|
1999-09-03 17:17:57 +02:00
|
|
|
}
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
/**************************************************************************
|
2003-06-24 01:02:02 +02:00
|
|
|
* X11DRV_EnumClipboardFormats
|
1999-09-03 17:17:57 +02:00
|
|
|
*/
|
2008-12-16 15:32:08 +01:00
|
|
|
UINT CDECL X11DRV_EnumClipboardFormats(UINT wFormat)
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
2003-06-24 01:02:02 +02:00
|
|
|
CLIPBOARDINFO cbinfo;
|
|
|
|
UINT wNextFormat = 0;
|
|
|
|
|
|
|
|
TRACE("(%04X)\n", wFormat);
|
|
|
|
|
|
|
|
X11DRV_CLIPBOARD_UpdateCache(&cbinfo);
|
|
|
|
|
|
|
|
if (!wFormat)
|
|
|
|
{
|
|
|
|
if (ClipData)
|
|
|
|
wNextFormat = ClipData->wFormatID;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LPWINE_CLIPDATA lpData = X11DRV_CLIPBOARD_LookupData(wFormat);
|
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
if (lpData && lpData->NextData != ClipData)
|
2003-06-24 01:02:02 +02:00
|
|
|
wNextFormat = lpData->NextData->wFormatID;
|
|
|
|
}
|
|
|
|
|
|
|
|
return wNextFormat;
|
1999-09-03 17:17:57 +02:00
|
|
|
}
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
/**************************************************************************
|
2003-06-24 01:02:02 +02:00
|
|
|
* X11DRV_IsClipboardFormatAvailable
|
1999-09-03 17:17:57 +02:00
|
|
|
*/
|
2008-12-16 15:32:08 +01:00
|
|
|
BOOL CDECL X11DRV_IsClipboardFormatAvailable(UINT wFormat)
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
2003-06-24 01:02:02 +02:00
|
|
|
BOOL bRet = FALSE;
|
|
|
|
CLIPBOARDINFO cbinfo;
|
|
|
|
|
|
|
|
TRACE("(%04X)\n", wFormat);
|
|
|
|
|
|
|
|
X11DRV_CLIPBOARD_UpdateCache(&cbinfo);
|
|
|
|
|
|
|
|
if (wFormat != 0 && X11DRV_CLIPBOARD_LookupData(wFormat))
|
|
|
|
bRet = TRUE;
|
|
|
|
|
|
|
|
TRACE("(%04X)- ret(%d)\n", wFormat, bRet);
|
|
|
|
|
|
|
|
return bRet;
|
1998-12-07 10:13:40 +01:00
|
|
|
}
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
|
1998-12-07 10:13:40 +01:00
|
|
|
/**************************************************************************
|
2003-06-24 01:02:02 +02:00
|
|
|
* GetClipboardData (USER.142)
|
1998-12-07 10:13:40 +01:00
|
|
|
*/
|
2009-12-22 21:18:40 +01:00
|
|
|
HANDLE CDECL X11DRV_GetClipboardData(UINT wFormat)
|
1998-12-07 10:13:40 +01:00
|
|
|
{
|
2003-06-24 01:02:02 +02:00
|
|
|
CLIPBOARDINFO cbinfo;
|
|
|
|
LPWINE_CLIPDATA lpRender;
|
1998-12-07 10:13:40 +01:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
TRACE("(%04X)\n", wFormat);
|
2000-12-11 02:09:56 +01:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
X11DRV_CLIPBOARD_UpdateCache(&cbinfo);
|
|
|
|
|
|
|
|
if ((lpRender = X11DRV_CLIPBOARD_LookupData(wFormat)))
|
1999-04-01 14:03:52 +02:00
|
|
|
{
|
2009-12-22 21:18:40 +01:00
|
|
|
if ( !lpRender->hData )
|
2008-06-26 16:47:42 +02:00
|
|
|
X11DRV_CLIPBOARD_RenderFormat(thread_init_display(), lpRender);
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2009-12-22 21:18:40 +01:00
|
|
|
TRACE(" returning %p (type %04x)\n", lpRender->hData, lpRender->wFormatID);
|
|
|
|
return lpRender->hData;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
1998-12-07 10:13:40 +01:00
|
|
|
}
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
|
1998-12-07 10:13:40 +01:00
|
|
|
/**************************************************************************
|
2006-06-05 17:55:14 +02:00
|
|
|
* ResetSelectionOwner
|
1998-12-07 10:13:40 +01:00
|
|
|
*
|
2006-06-05 17:55:14 +02:00
|
|
|
* Called when the thread owning the selection is destroyed and we need to
|
|
|
|
* preserve the selection ownership. We look for another top level window
|
|
|
|
* in this process and send it a message to acquire the selection.
|
1998-12-07 10:13:40 +01:00
|
|
|
*/
|
2006-06-05 17:55:14 +02:00
|
|
|
void X11DRV_ResetSelectionOwner(void)
|
1998-12-07 10:13:40 +01:00
|
|
|
{
|
2006-06-05 17:55:14 +02:00
|
|
|
HWND hwnd;
|
|
|
|
DWORD procid;
|
1999-09-03 17:17:57 +02:00
|
|
|
|
2006-06-05 17:55:14 +02:00
|
|
|
TRACE("\n");
|
1999-09-03 17:17:57 +02:00
|
|
|
|
2006-06-05 17:55:14 +02:00
|
|
|
if (!selectionAcquired || thread_selection_wnd() != selectionWindow)
|
|
|
|
return;
|
1999-09-03 17:17:57 +02:00
|
|
|
|
2006-06-05 17:55:14 +02:00
|
|
|
selectionAcquired = S_NOSELECTION;
|
|
|
|
selectionWindow = 0;
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2006-06-05 17:55:14 +02:00
|
|
|
hwnd = GetWindow(GetDesktopWindow(), GW_CHILD);
|
|
|
|
do
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
2006-06-05 17:55:14 +02:00
|
|
|
if (GetCurrentThreadId() != GetWindowThreadProcessId(hwnd, &procid))
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
2006-06-05 17:55:14 +02:00
|
|
|
if (GetCurrentProcessId() == procid)
|
|
|
|
{
|
|
|
|
if (SendMessageW(hwnd, WM_X11DRV_ACQUIRE_SELECTION, 0, 0))
|
|
|
|
return;
|
|
|
|
}
|
1999-09-03 17:17:57 +02:00
|
|
|
}
|
2006-06-05 17:55:14 +02:00
|
|
|
} while ((hwnd = GetWindow(hwnd, GW_HWNDNEXT)) != NULL);
|
1999-09-03 17:17:57 +02:00
|
|
|
|
2006-06-05 17:55:14 +02:00
|
|
|
WARN("Failed to find another thread to take selection ownership. Clipboard data will be lost.\n");
|
1999-09-03 17:17:57 +02:00
|
|
|
|
2006-06-05 17:55:14 +02:00
|
|
|
X11DRV_CLIPBOARD_ReleaseOwnership();
|
|
|
|
X11DRV_EmptyClipboard(FALSE);
|
1998-12-07 10:13:40 +01:00
|
|
|
}
|
|
|
|
|
1999-09-20 17:42:47 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
2003-06-24 01:02:02 +02:00
|
|
|
* X11DRV_CLIPBOARD_SynthesizeData
|
1999-09-20 17:42:47 +02:00
|
|
|
*/
|
2003-06-24 01:02:02 +02:00
|
|
|
static BOOL X11DRV_CLIPBOARD_SynthesizeData(UINT wFormatID)
|
1999-09-20 17:42:47 +02:00
|
|
|
{
|
2003-06-24 01:02:02 +02:00
|
|
|
BOOL bsyn = TRUE;
|
|
|
|
LPWINE_CLIPDATA lpSource = NULL;
|
2000-01-26 03:21:30 +01:00
|
|
|
|
2009-04-24 13:24:52 +02:00
|
|
|
TRACE(" %04x\n", wFormatID);
|
2002-08-27 21:19:49 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
/* Don't need to synthesize if it already exists */
|
|
|
|
if (X11DRV_CLIPBOARD_LookupData(wFormatID))
|
|
|
|
return TRUE;
|
2002-08-27 21:19:49 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
if (wFormatID == CF_UNICODETEXT || wFormatID == CF_TEXT || wFormatID == CF_OEMTEXT)
|
2002-08-27 21:19:49 +02:00
|
|
|
{
|
2003-06-24 01:02:02 +02:00
|
|
|
bsyn = ((lpSource = X11DRV_CLIPBOARD_LookupData(CF_UNICODETEXT)) &&
|
|
|
|
~lpSource->wFlags & CF_FLAG_SYNTHESIZED) ||
|
|
|
|
((lpSource = X11DRV_CLIPBOARD_LookupData(CF_TEXT)) &&
|
|
|
|
~lpSource->wFlags & CF_FLAG_SYNTHESIZED) ||
|
|
|
|
((lpSource = X11DRV_CLIPBOARD_LookupData(CF_OEMTEXT)) &&
|
|
|
|
~lpSource->wFlags & CF_FLAG_SYNTHESIZED);
|
|
|
|
}
|
|
|
|
else if (wFormatID == CF_ENHMETAFILE)
|
|
|
|
{
|
|
|
|
bsyn = (lpSource = X11DRV_CLIPBOARD_LookupData(CF_METAFILEPICT)) &&
|
|
|
|
~lpSource->wFlags & CF_FLAG_SYNTHESIZED;
|
|
|
|
}
|
|
|
|
else if (wFormatID == CF_METAFILEPICT)
|
|
|
|
{
|
2009-04-17 15:49:29 +02:00
|
|
|
bsyn = (lpSource = X11DRV_CLIPBOARD_LookupData(CF_ENHMETAFILE)) &&
|
2003-06-24 01:02:02 +02:00
|
|
|
~lpSource->wFlags & CF_FLAG_SYNTHESIZED;
|
|
|
|
}
|
|
|
|
else if (wFormatID == CF_DIB)
|
|
|
|
{
|
|
|
|
bsyn = (lpSource = X11DRV_CLIPBOARD_LookupData(CF_BITMAP)) &&
|
|
|
|
~lpSource->wFlags & CF_FLAG_SYNTHESIZED;
|
|
|
|
}
|
|
|
|
else if (wFormatID == CF_BITMAP)
|
|
|
|
{
|
|
|
|
bsyn = (lpSource = X11DRV_CLIPBOARD_LookupData(CF_DIB)) &&
|
|
|
|
~lpSource->wFlags & CF_FLAG_SYNTHESIZED;
|
2002-08-27 21:19:49 +02:00
|
|
|
}
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
if (bsyn)
|
2009-12-22 21:18:40 +01:00
|
|
|
X11DRV_CLIPBOARD_InsertClipboardData(wFormatID, 0, CF_FLAG_SYNTHESIZED, NULL, TRUE);
|
2002-08-27 21:19:49 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
return bsyn;
|
2002-08-27 21:19:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2002-08-27 21:19:49 +02:00
|
|
|
/**************************************************************************
|
2003-06-24 01:02:02 +02:00
|
|
|
* X11DRV_EndClipboardUpdate
|
|
|
|
* TODO:
|
|
|
|
* Add locale if it hasn't already been added
|
2002-08-27 21:19:49 +02:00
|
|
|
*/
|
2008-12-16 15:32:08 +01:00
|
|
|
void CDECL X11DRV_EndClipboardUpdate(void)
|
2002-08-27 21:19:49 +02:00
|
|
|
{
|
2003-06-24 01:02:02 +02:00
|
|
|
INT count = ClipDataCount;
|
2002-08-27 21:19:49 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
/* Do Unicode <-> Text <-> OEM mapping */
|
|
|
|
X11DRV_CLIPBOARD_SynthesizeData(CF_TEXT);
|
|
|
|
X11DRV_CLIPBOARD_SynthesizeData(CF_OEMTEXT);
|
2009-04-17 15:46:06 +02:00
|
|
|
X11DRV_CLIPBOARD_SynthesizeData(CF_UNICODETEXT);
|
2002-08-27 21:19:49 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
/* Enhmetafile <-> MetafilePict mapping */
|
|
|
|
X11DRV_CLIPBOARD_SynthesizeData(CF_ENHMETAFILE);
|
|
|
|
X11DRV_CLIPBOARD_SynthesizeData(CF_METAFILEPICT);
|
2002-08-27 21:19:49 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
/* DIB <-> Bitmap mapping */
|
|
|
|
X11DRV_CLIPBOARD_SynthesizeData(CF_DIB);
|
|
|
|
X11DRV_CLIPBOARD_SynthesizeData(CF_BITMAP);
|
2002-08-27 21:19:49 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
TRACE("%d formats added to cached data\n", ClipDataCount - count);
|
2002-08-27 21:19:49 +02:00
|
|
|
}
|
2005-02-25 22:01:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_SelectionRequest_TARGETS
|
|
|
|
* Service a TARGETS selection request event
|
|
|
|
*/
|
|
|
|
static Atom X11DRV_SelectionRequest_TARGETS( Display *display, Window requestor,
|
|
|
|
Atom target, Atom rprop )
|
|
|
|
{
|
2005-11-01 19:05:40 +01:00
|
|
|
UINT i;
|
2005-02-25 22:01:15 +01:00
|
|
|
Atom* targets;
|
|
|
|
ULONG cTargets;
|
2005-11-01 19:05:40 +01:00
|
|
|
LPWINE_CLIPFORMAT lpFormats;
|
|
|
|
LPWINE_CLIPDATA lpData;
|
2005-02-25 22:01:15 +01:00
|
|
|
|
2006-04-09 23:47:21 +02:00
|
|
|
/* Create X atoms for any clipboard types which don't have atoms yet.
|
|
|
|
* This avoids sending bogus zero atoms.
|
|
|
|
* Without this, copying might not have access to all clipboard types.
|
|
|
|
* FIXME: is it safe to call this here?
|
|
|
|
*/
|
|
|
|
intern_atoms();
|
|
|
|
|
2005-02-25 22:01:15 +01:00
|
|
|
/*
|
|
|
|
* Count the number of items we wish to expose as selection targets.
|
|
|
|
*/
|
2005-11-01 19:05:40 +01:00
|
|
|
cTargets = 1; /* Include TARGETS */
|
2005-02-25 22:01:15 +01:00
|
|
|
|
2006-01-20 19:41:40 +01:00
|
|
|
if (!(lpData = ClipData)) return None;
|
2005-11-01 19:05:40 +01:00
|
|
|
|
|
|
|
do
|
2005-02-25 22:01:15 +01:00
|
|
|
{
|
2005-11-01 19:05:40 +01:00
|
|
|
lpFormats = ClipFormats;
|
2005-02-25 22:01:15 +01:00
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
while (lpFormats)
|
2005-02-25 22:01:15 +01:00
|
|
|
{
|
2005-11-01 19:05:40 +01:00
|
|
|
if ((lpFormats->wFormatID == lpData->wFormatID) &&
|
2006-04-09 23:47:21 +02:00
|
|
|
lpFormats->lpDrvExportFunc && lpFormats->drvData)
|
2005-02-25 22:01:15 +01:00
|
|
|
cTargets++;
|
2005-11-01 19:05:40 +01:00
|
|
|
|
|
|
|
lpFormats = lpFormats->NextFormat;
|
2005-02-25 22:01:15 +01:00
|
|
|
}
|
2005-11-01 19:05:40 +01:00
|
|
|
|
|
|
|
lpData = lpData->NextData;
|
2005-02-25 22:01:15 +01:00
|
|
|
}
|
2005-11-01 19:05:40 +01:00
|
|
|
while (lpData != ClipData);
|
2005-02-25 22:01:15 +01:00
|
|
|
|
2006-10-08 01:34:01 +02:00
|
|
|
TRACE(" found %d formats\n", cTargets);
|
2005-02-25 22:01:15 +01:00
|
|
|
|
|
|
|
/* Allocate temp buffer */
|
2005-03-24 22:01:35 +01:00
|
|
|
targets = HeapAlloc( GetProcessHeap(), 0, cTargets * sizeof(Atom));
|
2005-02-25 22:01:15 +01:00
|
|
|
if(targets == NULL)
|
|
|
|
return None;
|
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
i = 0;
|
|
|
|
lpData = ClipData;
|
|
|
|
targets[i++] = x11drv_atom(TARGETS);
|
|
|
|
|
|
|
|
do
|
2005-02-25 22:01:15 +01:00
|
|
|
{
|
2005-11-01 19:05:40 +01:00
|
|
|
lpFormats = ClipFormats;
|
2005-02-25 22:01:15 +01:00
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
while (lpFormats)
|
2005-02-25 22:01:15 +01:00
|
|
|
{
|
2005-11-01 19:05:40 +01:00
|
|
|
if ((lpFormats->wFormatID == lpData->wFormatID) &&
|
2006-04-09 23:47:21 +02:00
|
|
|
lpFormats->lpDrvExportFunc && lpFormats->drvData)
|
2005-11-01 19:05:40 +01:00
|
|
|
targets[i++] = lpFormats->drvData;
|
2005-02-25 22:01:15 +01:00
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
lpFormats = lpFormats->NextFormat;
|
2005-02-25 22:01:15 +01:00
|
|
|
}
|
2005-11-01 19:05:40 +01:00
|
|
|
|
|
|
|
lpData = lpData->NextData;
|
2005-02-25 22:01:15 +01:00
|
|
|
}
|
2005-11-01 19:05:40 +01:00
|
|
|
while (lpData != ClipData);
|
2005-02-25 22:01:15 +01:00
|
|
|
|
|
|
|
wine_tsx11_lock();
|
|
|
|
|
|
|
|
if (TRACE_ON(clipboard))
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
for ( i = 0; i < cTargets; i++)
|
|
|
|
{
|
2006-04-09 23:47:21 +02:00
|
|
|
char *itemFmtName = XGetAtomName(display, targets[i]);
|
|
|
|
TRACE("\tAtom# %d: Property %ld Type %s\n", i, targets[i], itemFmtName);
|
|
|
|
XFree(itemFmtName);
|
2005-02-25 22:01:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We may want to consider setting the type to xaTargets instead,
|
|
|
|
* in case some apps expect this instead of XA_ATOM */
|
|
|
|
XChangeProperty(display, requestor, rprop, XA_ATOM, 32,
|
|
|
|
PropModeReplace, (unsigned char *)targets, cTargets);
|
|
|
|
wine_tsx11_unlock();
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, targets);
|
|
|
|
|
|
|
|
return rprop;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_SelectionRequest_MULTIPLE
|
|
|
|
* Service a MULTIPLE selection request event
|
|
|
|
* rprop contains a list of (target,property) atom pairs.
|
|
|
|
* The first atom names a target and the second names a property.
|
|
|
|
* The effect is as if we have received a sequence of SelectionRequest events
|
|
|
|
* (one for each atom pair) except that:
|
|
|
|
* 1. We reply with a SelectionNotify only when all the requested conversions
|
|
|
|
* have been performed.
|
|
|
|
* 2. If we fail to convert the target named by an atom in the MULTIPLE property,
|
|
|
|
* we replace the atom in the property by None.
|
|
|
|
*/
|
|
|
|
static Atom X11DRV_SelectionRequest_MULTIPLE( HWND hWnd, XSelectionRequestEvent *pevent )
|
|
|
|
{
|
|
|
|
Display *display = pevent->display;
|
|
|
|
Atom rprop;
|
|
|
|
Atom atype=AnyPropertyType;
|
|
|
|
int aformat;
|
|
|
|
unsigned long remain;
|
|
|
|
Atom* targetPropList=NULL;
|
|
|
|
unsigned long cTargetPropList = 0;
|
|
|
|
|
|
|
|
/* If the specified property is None the requestor is an obsolete client.
|
|
|
|
* We support these by using the specified target atom as the reply property.
|
|
|
|
*/
|
|
|
|
rprop = pevent->property;
|
|
|
|
if( rprop == None )
|
|
|
|
rprop = pevent->target;
|
|
|
|
if (!rprop)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Read the MULTIPLE property contents. This should contain a list of
|
|
|
|
* (target,property) atom pairs.
|
|
|
|
*/
|
|
|
|
wine_tsx11_lock();
|
|
|
|
if(XGetWindowProperty(display, pevent->requestor, rprop,
|
|
|
|
0, 0x3FFF, False, AnyPropertyType, &atype,&aformat,
|
|
|
|
&cTargetPropList, &remain,
|
|
|
|
(unsigned char**)&targetPropList) != Success)
|
|
|
|
{
|
|
|
|
wine_tsx11_unlock();
|
|
|
|
TRACE("\tCouldn't read MULTIPLE property\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("\tType %s,Format %d,nItems %ld, Remain %ld\n",
|
|
|
|
XGetAtomName(display, atype), aformat, cTargetPropList, remain);
|
|
|
|
wine_tsx11_unlock();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure we got what we expect.
|
|
|
|
* NOTE: According to the X-ICCCM Version 2.0 documentation the property sent
|
|
|
|
* in a MULTIPLE selection request should be of type ATOM_PAIR.
|
|
|
|
* However some X apps(such as XPaint) are not compliant with this and return
|
|
|
|
* a user defined atom in atype when XGetWindowProperty is called.
|
|
|
|
* The data *is* an atom pair but is not denoted as such.
|
|
|
|
*/
|
|
|
|
if(aformat == 32 /* atype == xAtomPair */ )
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
/* Iterate through the ATOM_PAIR list and execute a SelectionRequest
|
|
|
|
* for each (target,property) pair */
|
|
|
|
|
|
|
|
for (i = 0; i < cTargetPropList; i+=2)
|
|
|
|
{
|
|
|
|
XSelectionRequestEvent event;
|
|
|
|
|
|
|
|
if (TRACE_ON(clipboard))
|
|
|
|
{
|
|
|
|
char *targetName, *propName;
|
|
|
|
wine_tsx11_lock();
|
|
|
|
targetName = XGetAtomName(display, targetPropList[i]);
|
|
|
|
propName = XGetAtomName(display, targetPropList[i+1]);
|
|
|
|
TRACE("MULTIPLE(%d): Target='%s' Prop='%s'\n",
|
|
|
|
i/2, targetName, propName);
|
|
|
|
XFree(targetName);
|
|
|
|
XFree(propName);
|
|
|
|
wine_tsx11_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We must have a non "None" property to service a MULTIPLE target atom */
|
|
|
|
if ( !targetPropList[i+1] )
|
|
|
|
{
|
|
|
|
TRACE("\tMULTIPLE(%d): Skipping target with empty property!\n", i);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up an XSelectionRequestEvent for this (target,property) pair */
|
2008-03-22 18:10:01 +01:00
|
|
|
event = *pevent;
|
2005-02-25 22:01:15 +01:00
|
|
|
event.target = targetPropList[i];
|
|
|
|
event.property = targetPropList[i+1];
|
|
|
|
|
|
|
|
/* Fire a SelectionRequest, informing the handler that we are processing
|
|
|
|
* a MULTIPLE selection request event.
|
|
|
|
*/
|
|
|
|
X11DRV_HandleSelectionRequest( hWnd, &event, TRUE );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free the list of targets/properties */
|
|
|
|
wine_tsx11_lock();
|
|
|
|
XFree(targetPropList);
|
|
|
|
wine_tsx11_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
return rprop;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_HandleSelectionRequest
|
|
|
|
* Process an event selection request event.
|
|
|
|
* The bIsMultiple flag is used to signal when EVENT_SelectionRequest is called
|
|
|
|
* recursively while servicing a "MULTIPLE" selection target.
|
|
|
|
*
|
|
|
|
* Note: We only receive this event when WINE owns the X selection
|
|
|
|
*/
|
|
|
|
static void X11DRV_HandleSelectionRequest( HWND hWnd, XSelectionRequestEvent *event, BOOL bIsMultiple )
|
|
|
|
{
|
|
|
|
Display *display = event->display;
|
|
|
|
XSelectionEvent result;
|
|
|
|
Atom rprop = None;
|
|
|
|
Window request = event->requestor;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We can only handle the selection request if :
|
|
|
|
* The selection is PRIMARY or CLIPBOARD, AND we can successfully open the clipboard.
|
|
|
|
* Don't do these checks or open the clipboard while recursively processing MULTIPLE,
|
|
|
|
* since this has been already done.
|
|
|
|
*/
|
|
|
|
if ( !bIsMultiple )
|
|
|
|
{
|
|
|
|
if (((event->selection != XA_PRIMARY) && (event->selection != x11drv_atom(CLIPBOARD))))
|
|
|
|
goto END;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the specified property is None the requestor is an obsolete client.
|
|
|
|
* We support these by using the specified target atom as the reply property.
|
|
|
|
*/
|
|
|
|
rprop = event->property;
|
|
|
|
if( rprop == None )
|
|
|
|
rprop = event->target;
|
|
|
|
|
|
|
|
if(event->target == x11drv_atom(TARGETS)) /* Return a list of all supported targets */
|
|
|
|
{
|
|
|
|
/* TARGETS selection request */
|
|
|
|
rprop = X11DRV_SelectionRequest_TARGETS( display, request, event->target, rprop );
|
|
|
|
}
|
|
|
|
else if(event->target == x11drv_atom(MULTIPLE)) /* rprop contains a list of (target, property) atom pairs */
|
|
|
|
{
|
|
|
|
/* MULTIPLE selection request */
|
|
|
|
rprop = X11DRV_SelectionRequest_MULTIPLE( hWnd, event );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-11-01 19:05:40 +01:00
|
|
|
LPWINE_CLIPFORMAT lpFormat = X11DRV_CLIPBOARD_LookupProperty(NULL, event->target);
|
2005-02-25 22:01:15 +01:00
|
|
|
|
|
|
|
if (lpFormat && lpFormat->lpDrvExportFunc)
|
|
|
|
{
|
|
|
|
LPWINE_CLIPDATA lpData = X11DRV_CLIPBOARD_LookupData(lpFormat->wFormatID);
|
|
|
|
|
|
|
|
if (lpData)
|
|
|
|
{
|
|
|
|
unsigned char* lpClipData;
|
|
|
|
DWORD cBytes;
|
2008-06-26 16:20:02 +02:00
|
|
|
HANDLE hClipData = lpFormat->lpDrvExportFunc(display, request, event->target,
|
2005-02-25 22:01:15 +01:00
|
|
|
rprop, lpData, &cBytes);
|
|
|
|
|
|
|
|
if (hClipData && (lpClipData = GlobalLock(hClipData)))
|
|
|
|
{
|
2010-08-24 05:40:19 +02:00
|
|
|
int mode = PropModeReplace;
|
|
|
|
|
2006-10-08 01:34:01 +02:00
|
|
|
TRACE("\tUpdating property %s, %d bytes\n", debugstr_w(lpFormat->Name), cBytes);
|
2005-02-25 22:01:15 +01:00
|
|
|
|
|
|
|
wine_tsx11_lock();
|
2010-08-24 05:40:19 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
int nelements = min(cBytes, 65536);
|
|
|
|
XChangeProperty(display, request, rprop, event->target,
|
|
|
|
8, mode, lpClipData, nelements);
|
|
|
|
mode = PropModeAppend;
|
|
|
|
cBytes -= nelements;
|
|
|
|
lpClipData += nelements;
|
|
|
|
} while (cBytes > 0);
|
2005-02-25 22:01:15 +01:00
|
|
|
wine_tsx11_unlock();
|
|
|
|
|
|
|
|
GlobalUnlock(hClipData);
|
|
|
|
GlobalFree(hClipData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
END:
|
|
|
|
/* reply to sender
|
|
|
|
* SelectionNotify should be sent only at the end of a MULTIPLE request
|
|
|
|
*/
|
|
|
|
if ( !bIsMultiple )
|
|
|
|
{
|
|
|
|
result.type = SelectionNotify;
|
|
|
|
result.display = display;
|
|
|
|
result.requestor = request;
|
|
|
|
result.selection = event->selection;
|
|
|
|
result.property = rprop;
|
|
|
|
result.target = event->target;
|
|
|
|
result.time = event->time;
|
|
|
|
TRACE("Sending SelectionNotify event...\n");
|
|
|
|
wine_tsx11_lock();
|
|
|
|
XSendEvent(display,event->requestor,False,NoEventMask,(XEvent*)&result);
|
|
|
|
wine_tsx11_unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_SelectionRequest
|
|
|
|
*/
|
2005-02-26 18:49:38 +01:00
|
|
|
void X11DRV_SelectionRequest( HWND hWnd, XEvent *event )
|
2005-02-25 22:01:15 +01:00
|
|
|
{
|
2005-02-26 18:49:38 +01:00
|
|
|
X11DRV_HandleSelectionRequest( hWnd, &event->xselectionrequest, FALSE );
|
2005-02-25 22:01:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_SelectionClear
|
|
|
|
*/
|
2005-02-26 18:49:38 +01:00
|
|
|
void X11DRV_SelectionClear( HWND hWnd, XEvent *xev )
|
2005-02-25 22:01:15 +01:00
|
|
|
{
|
2005-02-26 18:49:38 +01:00
|
|
|
XSelectionClearEvent *event = &xev->xselectionclear;
|
2005-02-25 22:01:15 +01:00
|
|
|
if (event->selection == XA_PRIMARY || event->selection == x11drv_atom(CLIPBOARD))
|
2008-06-26 16:20:02 +02:00
|
|
|
X11DRV_CLIPBOARD_ReleaseSelection( event->display, event->selection,
|
|
|
|
event->window, hWnd, event->time );
|
2005-02-25 22:01:15 +01:00
|
|
|
}
|
2009-12-29 20:03:40 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_Clipboard_Cleanup
|
|
|
|
*/
|
|
|
|
void X11DRV_Clipboard_Cleanup(void)
|
|
|
|
{
|
|
|
|
selectionAcquired = S_NOSELECTION;
|
|
|
|
|
|
|
|
X11DRV_EmptyClipboard(FALSE);
|
|
|
|
}
|