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
|
2014-05-27 02:23:55 +02:00
|
|
|
* 2014 Damjan Jovanovic
|
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"
|
2014-05-27 02:23:55 +02:00
|
|
|
#include "shlobj.h"
|
|
|
|
#include "shellapi.h"
|
|
|
|
#include "shlwapi.h"
|
1998-12-07 10:13:40 +01:00
|
|
|
#include "x11drv.h"
|
2011-03-03 20:25:01 +01:00
|
|
|
#include "wine/list.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 */
|
2011-01-31 03:35:44 +01:00
|
|
|
#define SELECTION_RETRIES 500 /* wait for .5 seconds */
|
2003-06-24 01:02:02 +02:00
|
|
|
#define SELECTION_WAIT 1000 /* us */
|
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
|
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
struct tagWINE_CLIPDATA; /* Forward */
|
2005-02-25 22:01:15 +01:00
|
|
|
|
2016-09-20 04:50:21 +02:00
|
|
|
typedef BOOL (*EXPORTFUNC)( Display *display, Window win, Atom prop, Atom target, HANDLE handle );
|
2016-09-20 06:17:30 +02:00
|
|
|
typedef HANDLE (*IMPORTFUNC)( Atom type, const void *data, size_t size );
|
2005-02-25 22:01:15 +01:00
|
|
|
|
2016-09-16 09:58:38 +02:00
|
|
|
typedef struct clipboard_format
|
|
|
|
{
|
2011-03-03 20:52:13 +01:00
|
|
|
struct list entry;
|
2016-09-19 15:55:56 +02:00
|
|
|
UINT id;
|
|
|
|
Atom atom;
|
2016-09-20 06:17:30 +02:00
|
|
|
IMPORTFUNC import;
|
2016-09-20 04:50:21 +02:00
|
|
|
EXPORTFUNC export;
|
2005-02-25 22:01:15 +01:00
|
|
|
} WINE_CLIPFORMAT, *LPWINE_CLIPFORMAT;
|
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
typedef struct tagWINE_CLIPDATA {
|
2011-03-03 20:25:01 +01:00
|
|
|
struct list entry;
|
2005-11-01 19:05:40 +01:00
|
|
|
UINT wFormatID;
|
2009-12-22 21:18:40 +01:00
|
|
|
HANDLE hData;
|
2005-11-01 19:05:40 +01:00
|
|
|
UINT drvData;
|
|
|
|
LPWINE_CLIPFORMAT lpFormat;
|
|
|
|
} WINE_CLIPDATA, *LPWINE_CLIPDATA;
|
|
|
|
|
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
|
|
|
|
2016-09-20 06:17:30 +02:00
|
|
|
static HANDLE import_data( Atom type, const void *data, size_t size );
|
|
|
|
static HANDLE import_enhmetafile( Atom type, const void *data, size_t size );
|
|
|
|
static HANDLE import_metafile( Atom type, const void *data, size_t size );
|
|
|
|
static HANDLE import_pixmap( Atom type, const void *data, size_t size );
|
|
|
|
static HANDLE import_image_bmp( Atom type, const void *data, size_t size );
|
|
|
|
static HANDLE import_string( Atom type, const void *data, size_t size );
|
|
|
|
static HANDLE import_utf8_string( Atom type, const void *data, size_t size );
|
|
|
|
static HANDLE import_compound_text( Atom type, const void *data, size_t size );
|
|
|
|
static HANDLE import_text_uri_list( Atom type, const void *data, size_t size );
|
2016-09-16 09:58:38 +02:00
|
|
|
|
2016-09-20 04:50:21 +02:00
|
|
|
static BOOL export_data( Display *display, Window win, Atom prop, Atom target, HANDLE handle );
|
|
|
|
static BOOL export_string( Display *display, Window win, Atom prop, Atom target, HANDLE handle );
|
|
|
|
static BOOL export_utf8_string( Display *display, Window win, Atom prop, Atom target, HANDLE handle );
|
|
|
|
static BOOL export_compound_text( Display *display, Window win, Atom prop, Atom target, HANDLE handle );
|
|
|
|
static BOOL export_pixmap( Display *display, Window win, Atom prop, Atom target, HANDLE handle );
|
|
|
|
static BOOL export_image_bmp( Display *display, Window win, Atom prop, Atom target, HANDLE handle );
|
|
|
|
static BOOL export_metafile( Display *display, Window win, Atom prop, Atom target, HANDLE handle );
|
|
|
|
static BOOL export_enhmetafile( Display *display, Window win, Atom prop, Atom target, HANDLE handle );
|
|
|
|
static BOOL export_text_html( Display *display, Window win, Atom prop, Atom target, HANDLE handle );
|
|
|
|
static BOOL export_hdrop( Display *display, Window win, Atom prop, Atom target, HANDLE handle );
|
2016-09-16 09:58:38 +02:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
static void X11DRV_CLIPBOARD_FreeData(LPWINE_CLIPDATA lpData);
|
2015-05-04 11:30:39 +02:00
|
|
|
static int X11DRV_CLIPBOARD_QueryAvailableData(Display *display);
|
2008-06-26 16:20:02 +02:00
|
|
|
static BOOL X11DRV_CLIPBOARD_ReadSelectionData(Display *display, LPWINE_CLIPDATA lpData);
|
2016-09-20 06:17:30 +02:00
|
|
|
static BOOL X11DRV_CLIPBOARD_ReadProperty( Display *display, Window w, Atom prop,
|
|
|
|
Atom *type, unsigned char **data, unsigned long *datasize );
|
2008-06-26 16:20:02 +02:00
|
|
|
static BOOL X11DRV_CLIPBOARD_RenderFormat(Display *display, LPWINE_CLIPDATA lpData);
|
2005-02-25 22:01:15 +01:00
|
|
|
static void X11DRV_HandleSelectionRequest( HWND hWnd, XSelectionRequestEvent *event, BOOL bIsMultiple );
|
2016-09-07 04:35:14 +02:00
|
|
|
static void empty_clipboard(void);
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2011-03-03 21:37:35 +01:00
|
|
|
/* Clipboard formats */
|
2005-01-11 16:10:56 +01:00
|
|
|
|
2016-09-16 09:58:38 +02:00
|
|
|
static const WCHAR RichTextFormatW[] = {'R','i','c','h',' ','T','e','x','t',' ','F','o','r','m','a','t',0};
|
|
|
|
static const WCHAR GIFW[] = {'G','I','F',0};
|
|
|
|
static const WCHAR JFIFW[] = {'J','F','I','F',0};
|
|
|
|
static const WCHAR PNGW[] = {'P','N','G',0};
|
|
|
|
static const WCHAR HTMLFormatW[] = {'H','T','M','L',' ','F','o','r','m','a','t',0};
|
|
|
|
|
2011-03-03 20:52:13 +01:00
|
|
|
static const struct
|
2000-01-26 03:21:30 +01:00
|
|
|
{
|
2016-09-16 09:58:38 +02:00
|
|
|
const WCHAR *name;
|
2011-03-03 20:52:13 +01:00
|
|
|
UINT id;
|
|
|
|
UINT data;
|
2016-09-20 06:17:30 +02:00
|
|
|
IMPORTFUNC import;
|
2016-09-20 04:50:21 +02:00
|
|
|
EXPORTFUNC export;
|
2011-03-03 20:52:13 +01:00
|
|
|
} builtin_formats[] =
|
|
|
|
{
|
2016-09-16 09:58:38 +02:00
|
|
|
{ 0, CF_TEXT, XA_STRING, import_string, export_string },
|
|
|
|
{ 0, CF_TEXT, XATOM_text_plain, import_string, export_string },
|
|
|
|
{ 0, CF_BITMAP, XATOM_WCF_BITMAP, import_data, NULL },
|
|
|
|
{ 0, CF_METAFILEPICT, XATOM_WCF_METAFILEPICT, import_metafile, export_metafile },
|
|
|
|
{ 0, CF_SYLK, XATOM_WCF_SYLK, import_data, export_data },
|
|
|
|
{ 0, CF_DIF, XATOM_WCF_DIF, import_data, export_data },
|
|
|
|
{ 0, CF_TIFF, XATOM_WCF_TIFF, import_data, export_data },
|
|
|
|
{ 0, CF_OEMTEXT, XATOM_WCF_OEMTEXT, import_data, export_data },
|
|
|
|
{ 0, CF_DIB, XA_PIXMAP, import_pixmap, export_pixmap },
|
|
|
|
{ 0, CF_PALETTE, XATOM_WCF_PALETTE, import_data, export_data },
|
|
|
|
{ 0, CF_PENDATA, XATOM_WCF_PENDATA, import_data, export_data },
|
|
|
|
{ 0, CF_RIFF, XATOM_WCF_RIFF, import_data, export_data },
|
|
|
|
{ 0, CF_WAVE, XATOM_WCF_WAVE, import_data, export_data },
|
2016-09-17 04:10:31 +02:00
|
|
|
{ 0, CF_UNICODETEXT, XATOM_UTF8_STRING, import_utf8_string, export_utf8_string },
|
|
|
|
{ 0, CF_UNICODETEXT, XATOM_COMPOUND_TEXT, import_compound_text, export_compound_text },
|
2016-09-16 09:58:38 +02:00
|
|
|
{ 0, CF_ENHMETAFILE, XATOM_WCF_ENHMETAFILE, import_enhmetafile, export_enhmetafile },
|
|
|
|
{ 0, CF_HDROP, XATOM_text_uri_list, import_text_uri_list, export_hdrop },
|
|
|
|
{ 0, CF_LOCALE, XATOM_WCF_LOCALE, import_data, export_data },
|
|
|
|
{ 0, CF_DIBV5, XATOM_WCF_DIBV5, import_data, export_data },
|
|
|
|
{ 0, CF_OWNERDISPLAY, XATOM_WCF_OWNERDISPLAY, import_data, export_data },
|
|
|
|
{ 0, CF_DSPTEXT, XATOM_WCF_DSPTEXT, import_data, export_data },
|
|
|
|
{ 0, CF_DSPBITMAP, XATOM_WCF_DSPBITMAP, import_data, export_data },
|
|
|
|
{ 0, CF_DSPMETAFILEPICT, XATOM_WCF_DSPMETAFILEPICT, import_data, export_data },
|
|
|
|
{ 0, CF_DSPENHMETAFILE, XATOM_WCF_DSPENHMETAFILE, import_data, export_data },
|
|
|
|
{ 0, CF_DIB, XATOM_image_bmp, import_image_bmp, export_image_bmp },
|
|
|
|
{ RichTextFormatW, 0, XATOM_text_rtf, import_data, export_data },
|
|
|
|
{ RichTextFormatW, 0, XATOM_text_richtext, import_data, export_data },
|
|
|
|
{ GIFW, 0, XATOM_image_gif, import_data, export_data },
|
|
|
|
{ JFIFW, 0, XATOM_image_jpeg, import_data, export_data },
|
|
|
|
{ PNGW, 0, XATOM_image_png, import_data, export_data },
|
|
|
|
{ HTMLFormatW, 0, XATOM_HTML_Format, import_data, export_data },
|
|
|
|
{ HTMLFormatW, 0, XATOM_text_html, import_data, export_text_html },
|
2003-06-24 01:02:02 +02:00
|
|
|
};
|
|
|
|
|
2011-03-03 20:52:13 +01:00
|
|
|
static struct list format_list = LIST_INIT( format_list );
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cached clipboard data.
|
|
|
|
*/
|
2011-03-03 20:25:01 +01:00
|
|
|
static struct list data_list = LIST_INIT( data_list );
|
2003-06-24 01:02:02 +02:00
|
|
|
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)
|
|
|
|
{
|
2012-09-25 15:51:03 +02:00
|
|
|
w = XCreateWindow(thread_data->display, root_window, 0, 0, 1, 1, 0, CopyFromParent,
|
|
|
|
InputOnly, CopyFromParent, 0, NULL);
|
2005-03-07 20:31:46 +01:00
|
|
|
if (w)
|
2013-01-03 23:59:14 +01:00
|
|
|
{
|
2008-06-26 15:08:08 +02:00
|
|
|
thread_data->selection_wnd = w;
|
2013-01-03 23:59:14 +01:00
|
|
|
|
|
|
|
XSelectInput(thread_data->display, w, PropertyChangeMask);
|
|
|
|
}
|
2005-03-07 20:31:46 +01:00
|
|
|
else
|
|
|
|
FIXME("Failed to create window. Fetching selection data will fail.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2011-03-03 21:09:22 +01:00
|
|
|
static const char *debugstr_format( UINT id )
|
|
|
|
{
|
2011-03-03 21:51:29 +01:00
|
|
|
WCHAR buffer[256];
|
|
|
|
|
|
|
|
if (GetClipboardFormatNameW( id, buffer, 256 ))
|
2011-03-03 21:09:22 +01:00
|
|
|
return wine_dbg_sprintf( "%04x %s", id, debugstr_w(buffer) );
|
2011-03-03 21:51:29 +01:00
|
|
|
|
2011-03-03 21:09:22 +01:00
|
|
|
switch (id)
|
|
|
|
{
|
2016-09-20 04:50:21 +02:00
|
|
|
case 0: return "(none)";
|
2011-03-03 21:09:22 +01:00
|
|
|
#define BUILTIN(id) case id: return #id;
|
|
|
|
BUILTIN(CF_TEXT)
|
|
|
|
BUILTIN(CF_BITMAP)
|
|
|
|
BUILTIN(CF_METAFILEPICT)
|
|
|
|
BUILTIN(CF_SYLK)
|
|
|
|
BUILTIN(CF_DIF)
|
|
|
|
BUILTIN(CF_TIFF)
|
|
|
|
BUILTIN(CF_OEMTEXT)
|
|
|
|
BUILTIN(CF_DIB)
|
|
|
|
BUILTIN(CF_PALETTE)
|
|
|
|
BUILTIN(CF_PENDATA)
|
|
|
|
BUILTIN(CF_RIFF)
|
|
|
|
BUILTIN(CF_WAVE)
|
|
|
|
BUILTIN(CF_UNICODETEXT)
|
|
|
|
BUILTIN(CF_ENHMETAFILE)
|
|
|
|
BUILTIN(CF_HDROP)
|
|
|
|
BUILTIN(CF_LOCALE)
|
|
|
|
BUILTIN(CF_DIBV5)
|
|
|
|
BUILTIN(CF_OWNERDISPLAY)
|
|
|
|
BUILTIN(CF_DSPTEXT)
|
|
|
|
BUILTIN(CF_DSPBITMAP)
|
|
|
|
BUILTIN(CF_DSPMETAFILEPICT)
|
|
|
|
BUILTIN(CF_DSPENHMETAFILE)
|
|
|
|
#undef BUILTIN
|
|
|
|
default: return wine_dbg_sprintf( "%04x", id );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-19 16:07:04 +02:00
|
|
|
static const char *debugstr_xatom( Atom atom )
|
|
|
|
{
|
|
|
|
const char *ret;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
if (!atom) return "(None)";
|
|
|
|
name = XGetAtomName( thread_display(), atom );
|
|
|
|
ret = debugstr_a( name );
|
|
|
|
XFree( name );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2016-09-16 09:58:38 +02:00
|
|
|
static const unsigned int count = sizeof(builtin_formats) / sizeof(builtin_formats[0]);
|
|
|
|
struct clipboard_format *formats;
|
2004-08-12 01:45:34 +02:00
|
|
|
UINT i;
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2016-09-16 09:58:38 +02:00
|
|
|
if (!(formats = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*formats)))) return;
|
2011-03-03 20:52:13 +01:00
|
|
|
|
2016-09-16 09:58:38 +02:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (builtin_formats[i].name)
|
2016-09-19 15:55:56 +02:00
|
|
|
formats[i].id = RegisterClipboardFormatW( builtin_formats[i].name );
|
2016-09-16 09:58:38 +02:00
|
|
|
else
|
2016-09-19 15:55:56 +02:00
|
|
|
formats[i].id = builtin_formats[i].id;
|
2009-11-22 21:30:18 +01:00
|
|
|
|
2016-09-19 15:55:56 +02:00
|
|
|
formats[i].atom = GET_ATOM(builtin_formats[i].data);
|
2016-09-20 06:17:30 +02:00
|
|
|
formats[i].import = builtin_formats[i].import;
|
2016-09-20 04:50:21 +02:00
|
|
|
formats[i].export = builtin_formats[i].export;
|
2016-09-16 09:58:38 +02:00
|
|
|
list_add_tail( &format_list, &formats[i].entry );
|
|
|
|
}
|
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;
|
2011-03-03 21:37:35 +01:00
|
|
|
WCHAR buffer[256];
|
2003-11-21 06:23:17 +01:00
|
|
|
|
2011-03-03 20:52:13 +01:00
|
|
|
count = 0;
|
|
|
|
LIST_FOR_EACH_ENTRY( format, &format_list, WINE_CLIPFORMAT, entry )
|
2016-09-19 15:55:56 +02:00
|
|
|
if (!format->atom) count++;
|
2003-11-21 06:23:17 +01:00
|
|
|
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) );
|
|
|
|
|
2011-03-03 20:52:13 +01:00
|
|
|
i = 0;
|
|
|
|
LIST_FOR_EACH_ENTRY( format, &format_list, WINE_CLIPFORMAT, entry )
|
2016-09-19 15:55:56 +02:00
|
|
|
if (!format->atom) {
|
|
|
|
if (GetClipboardFormatNameW( format->id, buffer, 256 ) > 0)
|
2015-09-24 23:44:17 +02:00
|
|
|
{
|
|
|
|
/* use defined format name */
|
|
|
|
len = WideCharToMultiByte(CP_UNIXCP, 0, buffer, -1, NULL, 0, NULL, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* create a name in the same way as ntdll/atom.c:integral_atom_name
|
|
|
|
* which is normally used by GetClipboardFormatNameW
|
|
|
|
*/
|
|
|
|
static const WCHAR fmt[] = {'#','%','u',0};
|
2016-09-19 15:55:56 +02:00
|
|
|
len = sprintfW(buffer, fmt, format->id) + 1;
|
2015-09-24 23:44:17 +02:00
|
|
|
}
|
2005-05-12 11:56:35 +02:00
|
|
|
names[i] = HeapAlloc(GetProcessHeap(), 0, len);
|
2011-03-03 21:37:35 +01:00
|
|
|
WideCharToMultiByte(CP_UNIXCP, 0, buffer, -1, names[i++], len, NULL, NULL);
|
2005-01-11 16:10:56 +01:00
|
|
|
}
|
2003-11-21 06:23:17 +01:00
|
|
|
|
2008-06-26 16:47:42 +02:00
|
|
|
XInternAtoms( display, names, count, False, atoms );
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2011-03-03 20:52:13 +01:00
|
|
|
i = 0;
|
|
|
|
LIST_FOR_EACH_ENTRY( format, &format_list, WINE_CLIPFORMAT, entry )
|
2016-09-19 15:55:56 +02:00
|
|
|
if (!format->atom) {
|
2005-01-11 16:10:56 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, names[i]);
|
2016-09-19 15:55:56 +02:00
|
|
|
format->atom = atoms[i++];
|
2005-01-11 16:10:56 +01:00
|
|
|
}
|
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.
|
|
|
|
*/
|
2016-09-16 09:58:38 +02:00
|
|
|
static struct clipboard_format *register_format( UINT id, Atom prop )
|
2003-11-21 06:23:17 +01:00
|
|
|
{
|
2016-09-16 09:58:38 +02:00
|
|
|
struct clipboard_format *format;
|
2003-11-21 06:23:17 +01:00
|
|
|
|
|
|
|
/* walk format chain to see if it's already registered */
|
2016-09-16 09:58:38 +02:00
|
|
|
LIST_FOR_EACH_ENTRY( format, &format_list, struct clipboard_format, entry )
|
2016-09-19 15:55:56 +02:00
|
|
|
if (format->id == id) return format;
|
2016-09-16 09:58:38 +02:00
|
|
|
|
|
|
|
if (!(format = HeapAlloc( GetProcessHeap(), 0, sizeof(*format) ))) return NULL;
|
2016-09-19 15:55:56 +02:00
|
|
|
format->id = id;
|
|
|
|
format->atom = prop;
|
2016-09-20 06:17:30 +02:00
|
|
|
format->import = import_data;
|
2016-09-20 04:50:21 +02:00
|
|
|
format->export = export_data;
|
2016-09-16 09:58:38 +02:00
|
|
|
list_add_tail( &format_list, &format->entry );
|
|
|
|
|
2016-09-19 15:55:56 +02:00
|
|
|
TRACE( "Registering format %s atom %ld\n", debugstr_format(id), prop );
|
2016-09-16 09:58:38 +02:00
|
|
|
return format;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_LookupProperty
|
|
|
|
*/
|
2016-09-19 15:55:56 +02:00
|
|
|
static struct clipboard_format *X11DRV_CLIPBOARD_LookupProperty( struct clipboard_format *current, Atom prop )
|
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
|
|
|
{
|
2011-03-03 20:52:13 +01:00
|
|
|
struct list *ptr = current ? ¤t->entry : &format_list;
|
2003-11-21 06:23:17 +01:00
|
|
|
BOOL need_intern = FALSE;
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2011-03-03 20:52:13 +01:00
|
|
|
while ((ptr = list_next( &format_list, ptr )))
|
2003-11-21 06:23:17 +01:00
|
|
|
{
|
2016-09-19 15:55:56 +02:00
|
|
|
struct clipboard_format *format = LIST_ENTRY( ptr, struct clipboard_format, entry );
|
|
|
|
if (format->atom == prop) return format;
|
|
|
|
if (!format->atom) need_intern = TRUE;
|
2003-11-21 06:23:17 +01:00
|
|
|
}
|
|
|
|
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
|
|
|
{
|
2011-03-03 20:25:01 +01:00
|
|
|
WINE_CLIPDATA *data;
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2011-03-03 20:25:01 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( data, &data_list, WINE_CLIPDATA, entry )
|
|
|
|
if (data->wFormatID == wID) return data;
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2011-03-03 20:25:01 +01:00
|
|
|
return NULL;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
2015-05-04 11:30:39 +02:00
|
|
|
* X11DRV_CLIPBOARD_IsProcessOwner
|
2003-06-24 01:02:02 +02:00
|
|
|
*/
|
2015-05-04 11:30:39 +02:00
|
|
|
static BOOL X11DRV_CLIPBOARD_IsProcessOwner( HWND *owner )
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2015-05-04 11:30:39 +02:00
|
|
|
BOOL ret = FALSE;
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
SERVER_START_REQ( set_clipboard_info )
|
|
|
|
{
|
|
|
|
req->flags = 0;
|
2015-05-04 11:30:39 +02:00
|
|
|
if (!wine_server_call_err( req ))
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2015-05-04 11:30:39 +02:00
|
|
|
*owner = wine_server_ptr_handle( reply->old_owner );
|
|
|
|
ret = (reply->flags & CB_PROCESS);
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
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
|
|
|
|
2015-05-04 11:30:39 +02:00
|
|
|
return ret;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_ReleaseOwnership
|
|
|
|
*/
|
|
|
|
static BOOL X11DRV_CLIPBOARD_ReleaseOwnership(void)
|
|
|
|
{
|
2015-05-04 11:30:39 +02:00
|
|
|
BOOL ret;
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
SERVER_START_REQ( set_clipboard_info )
|
|
|
|
{
|
|
|
|
req->flags = SET_CB_RELOWNER | SET_CB_SEQNO;
|
2015-05-04 11:30:39 +02:00
|
|
|
ret = !wine_server_call_err( req );
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
2015-05-04 11:30:39 +02:00
|
|
|
return ret;
|
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
|
|
|
*/
|
2016-09-07 04:35:14 +02:00
|
|
|
static BOOL X11DRV_CLIPBOARD_InsertClipboardData(UINT wFormatID, HANDLE hData,
|
2009-12-22 21:18:40 +01:00
|
|
|
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
|
|
|
|
2016-09-07 04:35:14 +02:00
|
|
|
TRACE("format=%04x lpData=%p hData=%p lpFormat=%p override=%d\n",
|
|
|
|
wFormatID, lpData, hData, lpFormat, override);
|
2005-11-01 19:05:40 +01:00
|
|
|
|
2011-03-07 17:02:21 +01:00
|
|
|
/* make sure the format exists */
|
|
|
|
if (!lpFormat) register_format( wFormatID, 0 );
|
|
|
|
|
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
|
|
|
|
2011-03-03 20:25:01 +01:00
|
|
|
list_add_tail( &data_list, &lpData->entry );
|
2005-11-01 19:05:40 +01:00
|
|
|
ClipDataCount++;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2016-08-18 11:24:28 +02:00
|
|
|
if (!lpData->hData) return;
|
2004-02-20 06:43:00 +01:00
|
|
|
|
2016-08-18 11:24:28 +02:00
|
|
|
switch (lpData->wFormatID)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2016-08-18 11:24:28 +02:00
|
|
|
case CF_BITMAP:
|
2016-09-09 15:49:27 +02:00
|
|
|
case CF_DSPBITMAP:
|
2016-08-18 11:24:28 +02:00
|
|
|
case CF_PALETTE:
|
|
|
|
DeleteObject(lpData->hData);
|
|
|
|
break;
|
|
|
|
case CF_DIB:
|
|
|
|
if (lpData->drvData) XFreePixmap(gdi_display, lpData->drvData);
|
|
|
|
GlobalFree(lpData->hData);
|
|
|
|
break;
|
|
|
|
case CF_METAFILEPICT:
|
2016-09-09 15:49:27 +02:00
|
|
|
case CF_DSPMETAFILEPICT:
|
2009-12-22 21:18:40 +01:00
|
|
|
DeleteMetaFile(((METAFILEPICT *)GlobalLock( lpData->hData ))->hMF );
|
|
|
|
GlobalFree(lpData->hData);
|
2016-08-18 11:24:28 +02:00
|
|
|
break;
|
|
|
|
case CF_ENHMETAFILE:
|
2016-09-09 15:49:27 +02:00
|
|
|
case CF_DSPENHMETAFILE:
|
2016-08-18 11:24:28 +02:00
|
|
|
DeleteEnhMetaFile(lpData->hData);
|
|
|
|
break;
|
|
|
|
default:
|
2009-12-22 21:18:40 +01:00
|
|
|
GlobalFree(lpData->hData);
|
2016-08-18 11:24:28 +02:00
|
|
|
break;
|
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
|
|
|
|
*/
|
2015-05-04 11:30:39 +02:00
|
|
|
static BOOL X11DRV_CLIPBOARD_UpdateCache(void)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
|
|
|
BOOL bret = TRUE;
|
|
|
|
|
2015-05-04 11:30:39 +02:00
|
|
|
if (!selectionAcquired)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2015-05-04 11:30:39 +02:00
|
|
|
DWORD seqno = GetClipboardSequenceNumber();
|
|
|
|
|
|
|
|
if (!seqno)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to retrieve clipboard information.\n");
|
|
|
|
bret = FALSE;
|
|
|
|
}
|
2015-05-04 11:30:39 +02:00
|
|
|
else if (wSeqNo < seqno)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2016-09-07 04:35:14 +02:00
|
|
|
empty_clipboard();
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2015-05-04 11:30:39 +02:00
|
|
|
if (X11DRV_CLIPBOARD_QueryAvailableData(thread_init_display()) < 0)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to cache clipboard data owned by another process.\n");
|
|
|
|
bret = FALSE;
|
|
|
|
}
|
2015-05-04 11:30:39 +02:00
|
|
|
wSeqNo = 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
|
|
|
|
2016-09-07 04:35:14 +02:00
|
|
|
if (!selectionAcquired)
|
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
|
|
|
|
{
|
2015-05-04 11:30:39 +02:00
|
|
|
HWND owner = GetClipboardOwner();
|
2002-08-27 21:19:49 +02:00
|
|
|
|
2015-05-04 11:30:39 +02:00
|
|
|
if (owner)
|
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.
|
|
|
|
*/
|
2015-05-04 11:30:39 +02:00
|
|
|
TRACE("Sending WM_RENDERFORMAT message to hwnd(%p)\n", owner);
|
|
|
|
SendMessageW(owner, 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
|
|
|
|
2016-09-20 04:32:08 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* put_property
|
|
|
|
*
|
|
|
|
* Put data as a property on the specified window.
|
|
|
|
*/
|
|
|
|
static void put_property( Display *display, Window win, Atom prop, Atom type, int format,
|
|
|
|
const void *ptr, size_t size )
|
|
|
|
{
|
|
|
|
const unsigned char *data = ptr;
|
|
|
|
int mode = PropModeReplace;
|
|
|
|
size_t width = (format == 32) ? sizeof(long) : format / 8;
|
|
|
|
size_t max_size = XExtendedMaxRequestSize( display ) * 4;
|
|
|
|
|
|
|
|
if (!max_size) max_size = XMaxRequestSize( display ) * 4;
|
|
|
|
max_size -= 64; /* request overhead */
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
size_t count = min( size, max_size / width );
|
|
|
|
XChangeProperty( display, win, prop, type, format, mode, data, count );
|
|
|
|
mode = PropModeAppend;
|
|
|
|
size -= count;
|
|
|
|
data += count * width;
|
|
|
|
} while (size > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-20 07:13:24 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* convert_selection
|
|
|
|
*/
|
|
|
|
static Atom convert_selection( Display *display, Window win, Atom selection, Atom target )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
XEvent event;
|
|
|
|
|
|
|
|
XConvertSelection( display, selection, target, x11drv_atom(SELECTION_DATA), win, CurrentTime );
|
|
|
|
|
|
|
|
for (i = 0; i < SELECTION_RETRIES; i++)
|
|
|
|
{
|
|
|
|
Bool res = XCheckTypedWindowEvent( display, win, SelectionNotify, &event );
|
|
|
|
if (res && event.xselection.selection == selection && event.xselection.target == target)
|
|
|
|
return event.xselection.property;
|
|
|
|
usleep( SELECTION_WAIT );
|
|
|
|
}
|
|
|
|
ERR( "Timed out waiting for SelectionNotify event\n" );
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-10 17:41:03 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* bitmap_info_size
|
|
|
|
*
|
|
|
|
* Return the size of the bitmap info structure including color table.
|
|
|
|
*/
|
|
|
|
static int bitmap_info_size( const BITMAPINFO * info, WORD coloruse )
|
|
|
|
{
|
|
|
|
unsigned int colors, size, masks = 0;
|
|
|
|
|
|
|
|
if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
|
|
|
|
{
|
|
|
|
const BITMAPCOREHEADER *core = (const BITMAPCOREHEADER *)info;
|
|
|
|
colors = (core->bcBitCount <= 8) ? 1 << core->bcBitCount : 0;
|
|
|
|
return sizeof(BITMAPCOREHEADER) + colors *
|
|
|
|
((coloruse == DIB_RGB_COLORS) ? sizeof(RGBTRIPLE) : sizeof(WORD));
|
|
|
|
}
|
|
|
|
else /* assume BITMAPINFOHEADER */
|
|
|
|
{
|
|
|
|
colors = info->bmiHeader.biClrUsed;
|
|
|
|
if (!colors && (info->bmiHeader.biBitCount <= 8))
|
|
|
|
colors = 1 << info->bmiHeader.biBitCount;
|
|
|
|
if (info->bmiHeader.biCompression == BI_BITFIELDS) masks = 3;
|
|
|
|
size = max( info->bmiHeader.biSize, sizeof(BITMAPINFOHEADER) + masks * sizeof(DWORD) );
|
|
|
|
return size + colors * ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBQUAD) : sizeof(WORD));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* create_dib_from_bitmap
|
|
|
|
*
|
|
|
|
* Allocates a packed DIB and copies the bitmap data into it.
|
|
|
|
*/
|
|
|
|
static HGLOBAL create_dib_from_bitmap(HBITMAP hBmp)
|
|
|
|
{
|
|
|
|
BITMAP bmp;
|
|
|
|
HDC hdc;
|
|
|
|
HGLOBAL hPackedDIB;
|
|
|
|
LPBYTE pPackedDIB;
|
|
|
|
LPBITMAPINFOHEADER pbmiHeader;
|
|
|
|
unsigned int cDataSize, cPackedSize, OffsetBits;
|
|
|
|
int nLinesCopied;
|
|
|
|
|
|
|
|
if (!GetObjectW( hBmp, sizeof(bmp), &bmp )) return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A packed DIB contains a BITMAPINFO structure followed immediately by
|
|
|
|
* an optional color palette and the pixel data.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Calculate the size of the packed DIB */
|
|
|
|
cDataSize = abs( bmp.bmHeight ) * (((bmp.bmWidth * bmp.bmBitsPixel + 31) / 8) & ~3);
|
|
|
|
cPackedSize = sizeof(BITMAPINFOHEADER)
|
|
|
|
+ ( (bmp.bmBitsPixel <= 8) ? (sizeof(RGBQUAD) * (1 << bmp.bmBitsPixel)) : 0 )
|
|
|
|
+ cDataSize;
|
|
|
|
/* Get the offset to the bits */
|
|
|
|
OffsetBits = cPackedSize - cDataSize;
|
|
|
|
|
|
|
|
/* Allocate the packed DIB */
|
|
|
|
TRACE("\tAllocating packed DIB of size %d\n", cPackedSize);
|
2016-08-18 13:57:51 +02:00
|
|
|
hPackedDIB = GlobalAlloc( GMEM_FIXED, cPackedSize );
|
2012-01-10 17:41:03 +01:00
|
|
|
if ( !hPackedDIB )
|
|
|
|
{
|
|
|
|
WARN("Could not allocate packed DIB!\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* A packed DIB starts with a BITMAPINFOHEADER */
|
|
|
|
pPackedDIB = GlobalLock(hPackedDIB);
|
|
|
|
pbmiHeader = (LPBITMAPINFOHEADER)pPackedDIB;
|
|
|
|
|
|
|
|
/* Init the BITMAPINFOHEADER */
|
|
|
|
pbmiHeader->biSize = sizeof(BITMAPINFOHEADER);
|
|
|
|
pbmiHeader->biWidth = bmp.bmWidth;
|
|
|
|
pbmiHeader->biHeight = bmp.bmHeight;
|
|
|
|
pbmiHeader->biPlanes = 1;
|
|
|
|
pbmiHeader->biBitCount = bmp.bmBitsPixel;
|
|
|
|
pbmiHeader->biCompression = BI_RGB;
|
|
|
|
pbmiHeader->biSizeImage = 0;
|
|
|
|
pbmiHeader->biXPelsPerMeter = pbmiHeader->biYPelsPerMeter = 0;
|
|
|
|
pbmiHeader->biClrUsed = 0;
|
|
|
|
pbmiHeader->biClrImportant = 0;
|
|
|
|
|
|
|
|
/* Retrieve the DIB bits from the bitmap and fill in the
|
|
|
|
* DIB color table if present */
|
|
|
|
hdc = GetDC( 0 );
|
|
|
|
nLinesCopied = GetDIBits(hdc, /* Handle to device context */
|
|
|
|
hBmp, /* Handle to bitmap */
|
|
|
|
0, /* First scan line to set in dest bitmap */
|
|
|
|
bmp.bmHeight, /* Number of scan lines to copy */
|
|
|
|
pPackedDIB + OffsetBits, /* [out] Address of array for bitmap bits */
|
|
|
|
(LPBITMAPINFO) pbmiHeader, /* [out] Address of BITMAPINFO structure */
|
|
|
|
0); /* RGB or palette index */
|
|
|
|
GlobalUnlock(hPackedDIB);
|
|
|
|
ReleaseDC( 0, hdc );
|
|
|
|
|
|
|
|
/* Cleanup if GetDIBits failed */
|
|
|
|
if (nLinesCopied != bmp.bmHeight)
|
|
|
|
{
|
|
|
|
TRACE("\tGetDIBits returned %d. Actual lines=%d\n", nLinesCopied, bmp.bmHeight);
|
|
|
|
GlobalFree(hPackedDIB);
|
|
|
|
hPackedDIB = 0;
|
|
|
|
}
|
|
|
|
return hPackedDIB;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-27 02:23:55 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* uri_to_dos
|
|
|
|
*
|
|
|
|
* Converts a text/uri-list URI to DOS filename.
|
|
|
|
*/
|
|
|
|
static WCHAR* uri_to_dos(char *encodedURI)
|
|
|
|
{
|
|
|
|
WCHAR *ret = NULL;
|
|
|
|
int i;
|
|
|
|
int j = 0;
|
|
|
|
char *uri = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, strlen(encodedURI) + 1);
|
|
|
|
if (uri == NULL)
|
|
|
|
return NULL;
|
|
|
|
for (i = 0; encodedURI[i]; ++i)
|
|
|
|
{
|
|
|
|
if (encodedURI[i] == '%')
|
|
|
|
{
|
|
|
|
if (encodedURI[i+1] && encodedURI[i+2])
|
|
|
|
{
|
|
|
|
char buffer[3];
|
|
|
|
int number;
|
|
|
|
buffer[0] = encodedURI[i+1];
|
|
|
|
buffer[1] = encodedURI[i+2];
|
|
|
|
buffer[2] = '\0';
|
|
|
|
sscanf(buffer, "%x", &number);
|
|
|
|
uri[j++] = number;
|
|
|
|
i += 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("invalid URI encoding in %s\n", debugstr_a(encodedURI));
|
|
|
|
HeapFree(GetProcessHeap(), 0, uri);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
uri[j++] = encodedURI[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read http://www.freedesktop.org/wiki/Draganddropwarts and cry... */
|
|
|
|
if (strncmp(uri, "file:/", 6) == 0)
|
|
|
|
{
|
|
|
|
if (uri[6] == '/')
|
|
|
|
{
|
|
|
|
if (uri[7] == '/')
|
|
|
|
{
|
|
|
|
/* file:///path/to/file (nautilus, thunar) */
|
|
|
|
ret = wine_get_dos_file_name(&uri[7]);
|
|
|
|
}
|
|
|
|
else if (uri[7])
|
|
|
|
{
|
|
|
|
/* file://hostname/path/to/file (X file drag spec) */
|
|
|
|
char hostname[256];
|
|
|
|
char *path = strchr(&uri[7], '/');
|
|
|
|
if (path)
|
|
|
|
{
|
|
|
|
*path = '\0';
|
|
|
|
if (strcmp(&uri[7], "localhost") == 0)
|
|
|
|
{
|
|
|
|
*path = '/';
|
|
|
|
ret = wine_get_dos_file_name(path);
|
|
|
|
}
|
|
|
|
else if (gethostname(hostname, sizeof(hostname)) == 0)
|
|
|
|
{
|
|
|
|
if (strcmp(hostname, &uri[7]) == 0)
|
|
|
|
{
|
|
|
|
*path = '/';
|
|
|
|
ret = wine_get_dos_file_name(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (uri[6])
|
|
|
|
{
|
|
|
|
/* file:/path/to/file (konqueror) */
|
|
|
|
ret = wine_get_dos_file_name(&uri[5]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, uri);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
/**************************************************************************
|
2016-09-16 09:58:38 +02:00
|
|
|
* import_string
|
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.
|
|
|
|
*/
|
2016-09-20 06:17:30 +02:00
|
|
|
static HANDLE import_string( Atom type, const void *data, size_t size )
|
2005-11-01 19:05:40 +01:00
|
|
|
{
|
2016-09-20 06:17:30 +02:00
|
|
|
const char *lpdata = data;
|
2005-11-01 19:05:40 +01:00
|
|
|
LPSTR lpstr;
|
2016-09-20 06:17:30 +02:00
|
|
|
size_t i, inlcount = 0;
|
2005-11-01 19:05:40 +01:00
|
|
|
|
2016-09-20 06:17:30 +02:00
|
|
|
for (i = 0; i < size; i++)
|
2005-11-01 19:05:40 +01:00
|
|
|
{
|
|
|
|
if (lpdata[i] == '\n')
|
|
|
|
inlcount++;
|
|
|
|
}
|
|
|
|
|
2016-09-20 06:17:30 +02:00
|
|
|
if ((lpstr = GlobalAlloc( GMEM_FIXED, size + inlcount + 1 )))
|
2005-11-01 19:05:40 +01:00
|
|
|
{
|
2016-09-20 06:17:30 +02:00
|
|
|
for (i = 0, inlcount = 0; i < size; i++)
|
2005-11-01 19:05:40 +01:00
|
|
|
{
|
|
|
|
if (lpdata[i] == '\n')
|
|
|
|
lpstr[inlcount++] = '\r';
|
|
|
|
|
|
|
|
lpstr[inlcount++] = lpdata[i];
|
|
|
|
}
|
2016-09-20 06:17:30 +02:00
|
|
|
lpstr[inlcount] = 0;
|
2005-11-01 19:05:40 +01:00
|
|
|
}
|
2016-09-20 06:17:30 +02:00
|
|
|
return lpstr;
|
2005-11-01 19:05:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
2016-09-16 09:58:38 +02:00
|
|
|
* import_utf8_string
|
2005-11-01 19:05:40 +01:00
|
|
|
*
|
2016-09-16 09:58:38 +02:00
|
|
|
* Import XA_UTF8_STRING, converting the string to CF_UNICODE.
|
1999-09-03 17:17:57 +02:00
|
|
|
*/
|
2016-09-20 06:17:30 +02:00
|
|
|
static HANDLE import_utf8_string( Atom type, const void *data, size_t size )
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
2016-09-20 06:17:30 +02:00
|
|
|
const char *lpdata = data;
|
2003-06-24 01:02:02 +02:00
|
|
|
LPSTR lpstr;
|
2016-09-20 06:17:30 +02:00
|
|
|
size_t i, inlcount = 0;
|
|
|
|
WCHAR *textW = NULL;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2016-09-20 06:17:30 +02:00
|
|
|
for (i = 0; i < size; i++)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
|
|
|
if (lpdata[i] == '\n')
|
|
|
|
inlcount++;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2016-09-20 06:17:30 +02:00
|
|
|
if ((lpstr = HeapAlloc( GetProcessHeap(), 0, size + inlcount + 1 )))
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
|
|
|
UINT count;
|
|
|
|
|
2016-09-20 06:17:30 +02:00
|
|
|
for (i = 0, inlcount = 0; i < size; i++)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
|
|
|
if (lpdata[i] == '\n')
|
|
|
|
lpstr[inlcount++] = '\r';
|
|
|
|
|
|
|
|
lpstr[inlcount++] = lpdata[i];
|
|
|
|
}
|
2016-09-20 06:17:30 +02:00
|
|
|
lpstr[inlcount] = 0;
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
count = MultiByteToWideChar(CP_UTF8, 0, lpstr, -1, NULL, 0);
|
2016-09-20 06:17:30 +02:00
|
|
|
textW = GlobalAlloc( GMEM_FIXED, count * sizeof(WCHAR) );
|
|
|
|
if (textW) MultiByteToWideChar( CP_UTF8, 0, lpstr, -1, textW, count );
|
2003-06-24 01:02:02 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpstr);
|
|
|
|
}
|
2016-09-20 06:17:30 +02:00
|
|
|
return textW;
|
2005-11-01 19:05:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
2016-09-16 09:58:38 +02:00
|
|
|
* import_compound_text
|
2005-11-01 19:05:40 +01:00
|
|
|
*
|
|
|
|
* Import COMPOUND_TEXT to CF_UNICODE
|
|
|
|
*/
|
2016-09-20 06:17:30 +02:00
|
|
|
static HANDLE import_compound_text( Atom type, const void *data, size_t size )
|
2005-11-01 19:05:40 +01:00
|
|
|
{
|
2016-09-20 06:17:30 +02:00
|
|
|
int i, j;
|
2005-11-01 19:05:40 +01:00
|
|
|
char** srcstr;
|
|
|
|
int count, lcount;
|
|
|
|
int srclen, destlen;
|
2016-09-20 06:17:30 +02:00
|
|
|
WCHAR *deststr;
|
2005-11-01 19:05:40 +01:00
|
|
|
XTextProperty txtprop;
|
|
|
|
|
2016-09-20 06:17:30 +02:00
|
|
|
txtprop.value = (BYTE *)data;
|
|
|
|
txtprop.nitems = size;
|
2008-10-31 04:18:00 +01:00
|
|
|
txtprop.encoding = x11drv_atom(COMPOUND_TEXT);
|
|
|
|
txtprop.format = 8;
|
2016-09-20 06:17:30 +02:00
|
|
|
if (XmbTextPropertyToTextList( thread_display(), &txtprop, &srcstr, &count ) != Success) return 0;
|
|
|
|
if (!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]);
|
|
|
|
|
2016-09-20 06:17:30 +02:00
|
|
|
if ((deststr = GlobalAlloc( GMEM_FIXED, (destlen + lcount + 1) * sizeof(WCHAR) )))
|
2005-11-01 19:05:40 +01:00
|
|
|
{
|
|
|
|
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';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
XFreeStringList(srcstr);
|
|
|
|
|
2016-09-20 06:17:30 +02:00
|
|
|
return deststr;
|
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
|
|
|
/**************************************************************************
|
2016-09-16 09:58:38 +02:00
|
|
|
* import_pixmap
|
2003-06-24 01:02:02 +02:00
|
|
|
*
|
|
|
|
* Import XA_PIXMAP, converting the image to CF_DIB.
|
1999-10-24 22:22:24 +02:00
|
|
|
*/
|
2016-09-20 06:17:30 +02:00
|
|
|
static HANDLE import_pixmap( Atom type, const void *data, size_t size )
|
1999-10-24 22:22:24 +02:00
|
|
|
{
|
2016-09-20 06:17:30 +02:00
|
|
|
const Pixmap *pPixmap = (const Pixmap *)data;
|
|
|
|
BYTE *ptr = NULL;
|
|
|
|
XVisualInfo vis = default_visual;
|
|
|
|
char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
|
|
|
|
BITMAPINFO *info = (BITMAPINFO *)buffer;
|
|
|
|
struct gdi_image_bits bits;
|
|
|
|
Window root;
|
|
|
|
int x,y; /* Unused */
|
|
|
|
unsigned border_width; /* Unused */
|
|
|
|
unsigned int depth, width, height;
|
|
|
|
|
|
|
|
/* Get the Pixmap dimensions and bit depth */
|
|
|
|
if (!XGetGeometry(gdi_display, *pPixmap, &root, &x, &y, &width, &height,
|
|
|
|
&border_width, &depth)) depth = 0;
|
|
|
|
if (!pixmap_formats[depth]) return 0;
|
2005-11-01 19:05:40 +01:00
|
|
|
|
2016-09-20 06:17:30 +02:00
|
|
|
TRACE( "pixmap properties: width=%d, height=%d, depth=%d\n", width, height, depth );
|
|
|
|
|
|
|
|
if (depth != vis.depth) switch (pixmap_formats[depth]->bits_per_pixel)
|
2005-11-01 19:05:40 +01:00
|
|
|
{
|
2012-05-11 12:50:25 +02:00
|
|
|
case 1:
|
|
|
|
case 4:
|
|
|
|
case 8:
|
|
|
|
break;
|
|
|
|
case 16: /* assume R5G5B5 */
|
|
|
|
vis.red_mask = 0x7c00;
|
|
|
|
vis.green_mask = 0x03e0;
|
|
|
|
vis.blue_mask = 0x001f;
|
|
|
|
break;
|
|
|
|
case 24: /* assume R8G8B8 */
|
|
|
|
case 32: /* assume A8R8G8B8 */
|
|
|
|
vis.red_mask = 0xff0000;
|
|
|
|
vis.green_mask = 0x00ff00;
|
|
|
|
vis.blue_mask = 0x0000ff;
|
|
|
|
break;
|
|
|
|
default:
|
2012-01-10 17:41:03 +01:00
|
|
|
return 0;
|
2016-09-20 06:17:30 +02:00
|
|
|
}
|
2012-01-10 17:41:03 +01:00
|
|
|
|
2016-09-20 06:17:30 +02:00
|
|
|
if (!get_pixmap_image( *pPixmap, width, height, &vis, info, &bits ))
|
|
|
|
{
|
|
|
|
DWORD info_size = bitmap_info_size( info, DIB_RGB_COLORS );
|
2005-11-01 19:05:40 +01:00
|
|
|
|
2016-09-20 06:17:30 +02:00
|
|
|
ptr = GlobalAlloc( GMEM_FIXED, info_size + info->bmiHeader.biSizeImage );
|
|
|
|
if (ptr)
|
|
|
|
{
|
|
|
|
memcpy( ptr, info, info_size );
|
|
|
|
memcpy( ptr + info_size, bits.ptr, info->bmiHeader.biSizeImage );
|
2012-05-11 12:50:25 +02:00
|
|
|
}
|
2016-09-20 06:17:30 +02:00
|
|
|
if (bits.free) bits.free( &bits );
|
2005-11-01 19:05:40 +01:00
|
|
|
}
|
2016-09-20 06:17:30 +02:00
|
|
|
return ptr;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-25 00:19:38 +02:00
|
|
|
/**************************************************************************
|
2016-09-16 09:58:38 +02:00
|
|
|
* import_image_bmp
|
2009-04-25 00:19:38 +02:00
|
|
|
*
|
|
|
|
* Import image/bmp, converting the image to CF_DIB.
|
|
|
|
*/
|
2016-09-20 06:17:30 +02:00
|
|
|
static HANDLE import_image_bmp( Atom type, const void *data, size_t size )
|
2009-04-25 00:19:38 +02:00
|
|
|
{
|
|
|
|
HANDLE hClipData = 0;
|
2016-09-20 06:17:30 +02:00
|
|
|
const BITMAPFILEHEADER *bfh = data;
|
2009-04-25 00:19:38 +02:00
|
|
|
|
2016-09-20 06:17:30 +02:00
|
|
|
if (size >= sizeof(BITMAPFILEHEADER)+sizeof(BITMAPCOREHEADER) &&
|
|
|
|
bfh->bfType == 0x4d42 /* "BM" */)
|
2009-04-25 00:19:38 +02:00
|
|
|
{
|
2016-09-20 06:17:30 +02:00
|
|
|
const BITMAPINFO *bmi = (const BITMAPINFO *)(bfh + 1);
|
|
|
|
HBITMAP hbmp;
|
|
|
|
HDC hdc = GetDC(0);
|
2009-04-25 00:19:38 +02:00
|
|
|
|
2016-09-20 06:17:30 +02:00
|
|
|
if ((hbmp = CreateDIBitmap( hdc, &bmi->bmiHeader, CBM_INIT,
|
|
|
|
(const BYTE *)data + bfh->bfOffBits, bmi, DIB_RGB_COLORS )))
|
2009-04-25 00:19:38 +02:00
|
|
|
{
|
2012-01-10 17:41:03 +01:00
|
|
|
hClipData = create_dib_from_bitmap( hbmp );
|
2009-04-25 00:19:38 +02:00
|
|
|
DeleteObject(hbmp);
|
|
|
|
}
|
2016-09-20 06:17:30 +02:00
|
|
|
ReleaseDC(0, hdc);
|
2009-04-25 00:19:38 +02:00
|
|
|
}
|
|
|
|
return hClipData;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
/**************************************************************************
|
2016-09-16 09:58:38 +02:00
|
|
|
* import_metafile
|
2003-06-24 01:02:02 +02:00
|
|
|
*/
|
2016-09-20 06:17:30 +02:00
|
|
|
static HANDLE import_metafile( Atom type, const void *data, size_t size )
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2016-09-20 06:17:30 +02:00
|
|
|
METAFILEPICT *mf;
|
2005-11-01 19:05:40 +01:00
|
|
|
|
2016-09-20 06:17:30 +02:00
|
|
|
if (size < sizeof(METAFILEPICT)) return 0;
|
|
|
|
if ((mf = GlobalAlloc( GMEM_FIXED, sizeof(METAFILEPICT) )))
|
2005-11-01 19:05:40 +01:00
|
|
|
{
|
2016-09-20 06:17:30 +02:00
|
|
|
memcpy( mf, data, sizeof(METAFILEPICT) );
|
|
|
|
mf->hMF = SetMetaFileBitsEx( size - sizeof(METAFILEPICT),
|
|
|
|
(const BYTE *)data + sizeof(METAFILEPICT) );
|
2005-11-01 19:05:40 +01:00
|
|
|
}
|
2016-09-20 06:17:30 +02:00
|
|
|
return mf;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
2016-09-16 09:58:38 +02:00
|
|
|
* import_enhmetafile
|
2003-06-24 01:02:02 +02:00
|
|
|
*/
|
2016-09-20 06:17:30 +02:00
|
|
|
static HANDLE import_enhmetafile( Atom type, const void *data, size_t size )
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2016-09-20 06:17:30 +02:00
|
|
|
return SetEnhMetaFileBits( size, data );
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-27 02:23:55 +02:00
|
|
|
/**************************************************************************
|
2016-09-16 09:58:38 +02:00
|
|
|
* import_text_uri_list
|
2014-05-27 02:23:55 +02:00
|
|
|
*
|
|
|
|
* Import text/uri-list.
|
|
|
|
*/
|
2016-09-20 06:17:30 +02:00
|
|
|
static HANDLE import_text_uri_list( Atom type, const void *data, size_t size )
|
2014-05-27 02:23:55 +02:00
|
|
|
{
|
2016-09-20 06:17:30 +02:00
|
|
|
const char *uriList = data;
|
2014-05-27 02:23:55 +02:00
|
|
|
char *uri;
|
|
|
|
WCHAR *path;
|
|
|
|
WCHAR *out = NULL;
|
2016-09-20 06:17:30 +02:00
|
|
|
int total = 0;
|
2014-05-27 02:23:55 +02:00
|
|
|
int capacity = 4096;
|
|
|
|
int start = 0;
|
|
|
|
int end = 0;
|
2016-09-20 06:17:30 +02:00
|
|
|
DROPFILES *dropFiles = NULL;
|
2014-05-27 02:23:55 +02:00
|
|
|
|
2016-09-20 06:17:30 +02:00
|
|
|
if (!(out = HeapAlloc(GetProcessHeap(), 0, capacity * sizeof(WCHAR)))) return 0;
|
2014-05-27 02:23:55 +02:00
|
|
|
|
2016-09-20 06:17:30 +02:00
|
|
|
while (end < size)
|
2014-05-27 02:23:55 +02:00
|
|
|
{
|
2016-09-20 06:17:30 +02:00
|
|
|
while (end < size && uriList[end] != '\r')
|
2014-05-27 02:23:55 +02:00
|
|
|
++end;
|
2016-09-20 06:17:30 +02:00
|
|
|
if (end < (size - 1) && uriList[end+1] != '\n')
|
2014-05-27 02:23:55 +02:00
|
|
|
{
|
|
|
|
WARN("URI list line doesn't end in \\r\\n\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
uri = HeapAlloc(GetProcessHeap(), 0, end - start + 1);
|
|
|
|
if (uri == NULL)
|
|
|
|
break;
|
|
|
|
lstrcpynA(uri, &uriList[start], end - start + 1);
|
|
|
|
path = uri_to_dos(uri);
|
|
|
|
TRACE("converted URI %s to DOS path %s\n", debugstr_a(uri), debugstr_w(path));
|
|
|
|
HeapFree(GetProcessHeap(), 0, uri);
|
|
|
|
|
|
|
|
if (path)
|
|
|
|
{
|
|
|
|
int pathSize = strlenW(path) + 1;
|
2016-09-20 06:17:30 +02:00
|
|
|
if (pathSize > capacity - total)
|
2014-05-27 02:23:55 +02:00
|
|
|
{
|
|
|
|
capacity = 2*capacity + pathSize;
|
|
|
|
out = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, out, (capacity + 1)*sizeof(WCHAR));
|
|
|
|
if (out == NULL)
|
|
|
|
goto done;
|
|
|
|
}
|
2016-09-20 06:17:30 +02:00
|
|
|
memcpy(&out[total], path, pathSize * sizeof(WCHAR));
|
|
|
|
total += pathSize;
|
2014-05-27 02:23:55 +02:00
|
|
|
done:
|
|
|
|
HeapFree(GetProcessHeap(), 0, path);
|
|
|
|
if (out == NULL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
start = end + 2;
|
|
|
|
end = start;
|
|
|
|
}
|
2016-09-20 06:17:30 +02:00
|
|
|
if (out && end >= size)
|
2014-05-27 02:23:55 +02:00
|
|
|
{
|
2016-09-20 06:17:30 +02:00
|
|
|
if ((dropFiles = GlobalAlloc( GMEM_FIXED, sizeof(DROPFILES) + (total + 1) * sizeof(WCHAR) )))
|
2014-05-27 02:23:55 +02:00
|
|
|
{
|
|
|
|
dropFiles->pFiles = sizeof(DROPFILES);
|
|
|
|
dropFiles->pt.x = 0;
|
|
|
|
dropFiles->pt.y = 0;
|
|
|
|
dropFiles->fNC = 0;
|
|
|
|
dropFiles->fWide = TRUE;
|
2016-09-20 06:17:30 +02:00
|
|
|
out[total] = '\0';
|
|
|
|
memcpy( (char*)dropFiles + dropFiles->pFiles, out, (total + 1) * sizeof(WCHAR) );
|
2014-05-27 02:23:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, out);
|
2016-09-20 06:17:30 +02:00
|
|
|
return dropFiles;
|
2014-05-27 02:23:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
/**************************************************************************
|
2016-09-16 09:58:38 +02:00
|
|
|
* import_data
|
2003-06-24 01:02:02 +02:00
|
|
|
*
|
|
|
|
* Generic import clipboard data routine.
|
|
|
|
*/
|
2016-09-20 06:17:30 +02:00
|
|
|
static HANDLE import_data( Atom type, const void *data, size_t size )
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2016-09-20 06:17:30 +02:00
|
|
|
void *ret = GlobalAlloc( GMEM_FIXED, size );
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2016-09-20 06:17:30 +02:00
|
|
|
if (ret) memcpy( ret, data, size );
|
|
|
|
return ret;
|
|
|
|
}
|
2005-11-01 19:05:40 +01:00
|
|
|
|
|
|
|
|
2016-09-20 06:17:30 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* import_selection
|
|
|
|
*
|
|
|
|
* Import a selection target, depending on its type.
|
|
|
|
*/
|
|
|
|
static HANDLE import_selection( Display *display, Window win, Atom prop, struct clipboard_format *format )
|
|
|
|
{
|
|
|
|
unsigned char *data;
|
|
|
|
unsigned long size;
|
|
|
|
Atom type;
|
|
|
|
HANDLE ret;
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2016-09-20 06:17:30 +02:00
|
|
|
if (!format->import) return 0;
|
|
|
|
if (!X11DRV_CLIPBOARD_ReadProperty( display, win, prop, &type, &data, &size )) return 0;
|
|
|
|
ret = format->import( type, data, size );
|
|
|
|
HeapFree( GetProcessHeap(), 0, data );
|
|
|
|
return ret;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
2016-09-20 06:17:30 +02:00
|
|
|
|
2014-05-27 02:22:07 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_ImportSelection
|
|
|
|
*
|
|
|
|
* Import the X selection into the clipboard format registered for the given X target.
|
|
|
|
*/
|
2016-09-20 06:17:30 +02:00
|
|
|
HANDLE X11DRV_CLIPBOARD_ImportSelection(Display *display, Atom target, Window win, Atom prop, UINT *windowsFormat)
|
2014-05-27 02:22:07 +02:00
|
|
|
{
|
2016-09-20 06:17:30 +02:00
|
|
|
struct clipboard_format *format = X11DRV_CLIPBOARD_LookupProperty( NULL, target );
|
|
|
|
if (!format) return 0;
|
|
|
|
*windowsFormat = format->id;
|
|
|
|
return import_selection( display, win, prop, format );
|
2014-05-27 02:22:07 +02:00
|
|
|
}
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
2016-09-16 09:58:38 +02:00
|
|
|
* export_data
|
2003-06-24 01:02:02 +02:00
|
|
|
*
|
|
|
|
* Generic export clipboard data routine.
|
|
|
|
*/
|
2016-09-20 04:50:21 +02:00
|
|
|
static BOOL export_data( Display *display, Window win, Atom prop, Atom target, HANDLE handle )
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2016-09-20 04:50:21 +02:00
|
|
|
void *ptr = GlobalLock( handle );
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2016-09-20 04:50:21 +02:00
|
|
|
if (!ptr) return FALSE;
|
|
|
|
put_property( display, win, prop, target, 8, ptr, GlobalSize( handle ));
|
|
|
|
GlobalUnlock( handle );
|
|
|
|
return TRUE;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
2002-04-06 02:41:43 +02:00
|
|
|
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
/**************************************************************************
|
2016-09-17 04:10:31 +02:00
|
|
|
* export_string
|
2003-06-24 01:02:02 +02:00
|
|
|
*
|
2005-11-01 19:05:40 +01:00
|
|
|
* Export CF_TEXT converting the string to XA_STRING.
|
2003-06-24 01:02:02 +02:00
|
|
|
*/
|
2016-09-20 04:50:21 +02:00
|
|
|
static BOOL export_string( Display *display, Window win, Atom prop, Atom target, HANDLE handle )
|
2005-11-01 19:05:40 +01:00
|
|
|
{
|
|
|
|
UINT i, j;
|
|
|
|
UINT size;
|
|
|
|
LPSTR text, lpstr = NULL;
|
|
|
|
|
2016-09-20 04:50:21 +02:00
|
|
|
text = GlobalLock( handle );
|
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)
|
2016-09-20 04:50:21 +02:00
|
|
|
{
|
|
|
|
GlobalUnlock( handle );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-11-01 19:05:40 +01:00
|
|
|
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];
|
|
|
|
}
|
2016-09-20 04:50:21 +02:00
|
|
|
put_property( display, win, prop, target, 8, lpstr, j );
|
|
|
|
HeapFree( GetProcessHeap(), 0, lpstr );
|
|
|
|
GlobalUnlock( handle );
|
|
|
|
return TRUE;
|
2005-11-01 19:05:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
2016-09-17 04:10:31 +02:00
|
|
|
* export_utf8_string
|
2005-11-01 19:05:40 +01:00
|
|
|
*
|
|
|
|
* Export CF_UNICODE converting the string to UTF8.
|
|
|
|
*/
|
2016-09-20 04:50:21 +02:00
|
|
|
static BOOL export_utf8_string( Display *display, Window win, Atom prop, Atom target, HANDLE handle )
|
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;
|
2016-09-20 04:50:21 +02:00
|
|
|
LPSTR text, lpstr;
|
|
|
|
LPWSTR uni_text = GlobalLock( handle );
|
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)
|
2016-09-20 04:50:21 +02:00
|
|
|
{
|
|
|
|
GlobalUnlock( handle );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-11-01 19:05:40 +01:00
|
|
|
WideCharToMultiByte(CP_UTF8, 0, uni_text, -1, text, size, NULL, NULL);
|
2016-09-20 04:50:21 +02:00
|
|
|
GlobalUnlock( handle );
|
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)
|
2016-09-20 04:50:21 +02:00
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, text);
|
|
|
|
return FALSE;
|
|
|
|
}
|
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];
|
|
|
|
}
|
2016-09-20 04:50:21 +02:00
|
|
|
put_property( display, win, prop, target, 8, lpstr, j );
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpstr);
|
2003-06-24 01:02:02 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, text);
|
2016-09-20 04:50:21 +02:00
|
|
|
GlobalUnlock( handle );
|
|
|
|
return TRUE;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-08 23:02:51 +02:00
|
|
|
/**************************************************************************
|
2016-09-17 04:10:31 +02:00
|
|
|
* export_compound_text
|
2003-07-08 23:02:51 +02:00
|
|
|
*
|
2005-11-01 19:05:40 +01:00
|
|
|
* Export CF_UNICODE to COMPOUND_TEXT
|
2003-07-08 23:02:51 +02:00
|
|
|
*/
|
2016-09-20 04:50:21 +02:00
|
|
|
static BOOL export_compound_text( Display *display, Window win, Atom prop, Atom target, HANDLE handle )
|
2003-07-08 23:02:51 +02:00
|
|
|
{
|
2016-09-20 04:50:21 +02:00
|
|
|
char* lpstr;
|
|
|
|
XTextProperty textprop;
|
2003-07-08 23:02:51 +02:00
|
|
|
XICCEncodingStyle style;
|
2005-11-01 19:05:40 +01:00
|
|
|
UINT i, j;
|
|
|
|
UINT size;
|
2016-09-20 04:50:21 +02:00
|
|
|
LPWSTR uni_text = GlobalLock( handle );
|
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)
|
2016-09-20 04:50:21 +02:00
|
|
|
{
|
|
|
|
GlobalUnlock( handle );
|
|
|
|
return FALSE;
|
|
|
|
}
|
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
|
|
|
|
2016-09-20 04:50:21 +02:00
|
|
|
GlobalUnlock( handle );
|
2003-07-08 23:02:51 +02:00
|
|
|
|
2016-09-20 04:50:21 +02:00
|
|
|
if (target == x11drv_atom(COMPOUND_TEXT))
|
2005-11-01 19:05:40 +01:00
|
|
|
style = XCompoundTextStyle;
|
|
|
|
else
|
|
|
|
style = XStdICCTextStyle;
|
|
|
|
|
|
|
|
/* Update the X property */
|
2016-09-20 04:50:21 +02:00
|
|
|
if (XmbTextListToTextProperty( display, &lpstr, 1, style, &textprop ) == Success)
|
2005-11-01 19:05:40 +01:00
|
|
|
{
|
2016-09-20 04:50:21 +02:00
|
|
|
XSetTextProperty( display, win, &textprop, prop );
|
|
|
|
XFree( textprop.value );
|
2003-07-08 23:02:51 +02:00
|
|
|
}
|
2005-11-01 19:05:40 +01:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpstr);
|
2016-09-20 04:50:21 +02:00
|
|
|
return TRUE;
|
2003-07-08 23:02:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
/**************************************************************************
|
2016-09-16 09:58:38 +02:00
|
|
|
* export_pixmap
|
2003-06-24 01:02:02 +02:00
|
|
|
*
|
|
|
|
* Export CF_DIB to XA_PIXMAP.
|
|
|
|
*/
|
2016-09-20 04:50:21 +02:00
|
|
|
static BOOL export_pixmap( Display *display, Window win, Atom prop, Atom target, HANDLE handle )
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2016-09-20 04:50:21 +02:00
|
|
|
Pixmap pixmap;
|
|
|
|
BITMAPINFO *pbmi;
|
|
|
|
struct gdi_image_bits bits;
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2016-09-20 04:50:21 +02:00
|
|
|
pbmi = GlobalLock( handle );
|
|
|
|
bits.ptr = (LPBYTE)pbmi + bitmap_info_size( pbmi, DIB_RGB_COLORS );
|
|
|
|
bits.free = NULL;
|
|
|
|
bits.is_copy = FALSE;
|
|
|
|
pixmap = create_pixmap_from_image( 0, &default_visual, pbmi, &bits, DIB_RGB_COLORS );
|
|
|
|
GlobalUnlock( handle );
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2016-09-20 04:50:21 +02:00
|
|
|
put_property( display, win, prop, target, 32, &pixmap, 1 );
|
|
|
|
/* FIXME: free the pixmap when the property is deleted */
|
|
|
|
return TRUE;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-30 21:40:29 +02:00
|
|
|
/**************************************************************************
|
2016-09-16 09:58:38 +02:00
|
|
|
* export_image_bmp
|
2009-04-30 21:40:29 +02:00
|
|
|
*
|
|
|
|
* Export CF_DIB to image/bmp.
|
|
|
|
*/
|
2016-09-20 04:50:21 +02:00
|
|
|
static BOOL export_image_bmp( Display *display, Window win, Atom prop, Atom target, HANDLE handle )
|
2009-04-30 21:40:29 +02:00
|
|
|
{
|
2016-09-20 04:50:21 +02:00
|
|
|
LPBYTE dibdata = GlobalLock( handle );
|
2009-04-30 21:40:29 +02:00
|
|
|
UINT bmpsize;
|
|
|
|
BITMAPFILEHEADER *bfh;
|
|
|
|
|
2016-09-20 04:50:21 +02:00
|
|
|
bmpsize = sizeof(BITMAPFILEHEADER) + GlobalSize( handle );
|
|
|
|
bfh = HeapAlloc( GetProcessHeap(), 0, bmpsize );
|
|
|
|
if (bfh)
|
2009-04-30 21:40:29 +02:00
|
|
|
{
|
|
|
|
/* bitmap file header */
|
|
|
|
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));
|
|
|
|
}
|
2016-09-20 04:50:21 +02:00
|
|
|
GlobalUnlock( handle );
|
|
|
|
put_property( display, win, prop, target, 8, bfh, bmpsize );
|
|
|
|
HeapFree( GetProcessHeap(), 0, bfh );
|
|
|
|
return TRUE;
|
2009-04-30 21:40:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
/**************************************************************************
|
2016-09-16 09:58:38 +02:00
|
|
|
* export_metafile
|
2003-06-24 01:02:02 +02:00
|
|
|
*
|
|
|
|
* Export MetaFilePict.
|
|
|
|
*/
|
2016-09-20 04:50:21 +02:00
|
|
|
static BOOL export_metafile( Display *display, Window win, Atom prop, Atom target, HANDLE handle )
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2016-09-20 04:50:21 +02:00
|
|
|
METAFILEPICT *src, *dst;
|
2016-09-16 10:30:49 +02:00
|
|
|
unsigned int size;
|
|
|
|
|
2016-09-20 04:50:21 +02:00
|
|
|
src = GlobalLock( handle );
|
|
|
|
size = GetMetaFileBitsEx(src->hMF, 0, NULL);
|
2016-09-16 10:30:49 +02:00
|
|
|
|
2016-09-20 04:50:21 +02:00
|
|
|
dst = HeapAlloc( GetProcessHeap(), 0, size + sizeof(*dst) );
|
|
|
|
if (dst)
|
2016-09-16 10:30:49 +02:00
|
|
|
{
|
2016-09-20 04:50:21 +02:00
|
|
|
*dst = *src;
|
|
|
|
GetMetaFileBitsEx( src->hMF, size, dst + 1 );
|
2016-09-16 10:30:49 +02:00
|
|
|
}
|
2016-09-20 04:50:21 +02:00
|
|
|
GlobalUnlock( handle );
|
|
|
|
put_property( display, win, prop, target, 8, dst, size + sizeof(*dst) );
|
|
|
|
HeapFree( GetProcessHeap(), 0, dst );
|
|
|
|
return TRUE;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
2016-09-16 09:58:38 +02:00
|
|
|
* export_enhmetafile
|
2003-06-24 01:02:02 +02:00
|
|
|
*
|
|
|
|
* Export EnhMetaFile.
|
|
|
|
*/
|
2016-09-20 04:50:21 +02:00
|
|
|
static BOOL export_enhmetafile( Display *display, Window win, Atom prop, Atom target, HANDLE handle )
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2016-09-16 10:30:49 +02:00
|
|
|
unsigned int size;
|
2016-09-20 04:50:21 +02:00
|
|
|
void *ptr;
|
2016-09-16 10:30:49 +02:00
|
|
|
|
2016-09-20 04:50:21 +02:00
|
|
|
if (!(size = GetEnhMetaFileBits( handle, 0, NULL ))) return FALSE;
|
|
|
|
if (!(ptr = HeapAlloc( GetProcessHeap(), 0, size ))) return FALSE;
|
2016-09-16 10:30:49 +02:00
|
|
|
|
2016-09-20 04:50:21 +02:00
|
|
|
GetEnhMetaFileBits( handle, size, ptr );
|
|
|
|
put_property( display, win, prop, target, 8, ptr, size );
|
|
|
|
HeapFree( GetProcessHeap(), 0, ptr );
|
|
|
|
return 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
2016-09-16 09:58:38 +02:00
|
|
|
* export_text_html
|
2009-11-22 21:30:18 +01:00
|
|
|
*
|
|
|
|
* Export HTML Format to text/html.
|
|
|
|
*
|
|
|
|
* FIXME: We should attempt to add an <a base> tag and convert windows paths.
|
|
|
|
*/
|
2016-09-20 04:50:21 +02:00
|
|
|
static BOOL export_text_html( Display *display, Window win, Atom prop, Atom target, HANDLE handle )
|
2009-11-22 21:30:18 +01:00
|
|
|
{
|
|
|
|
LPCSTR data, field_value;
|
2016-09-20 04:50:21 +02:00
|
|
|
UINT fragmentstart, fragmentend;
|
2009-11-22 21:30:18 +01:00
|
|
|
|
2016-09-20 04:50:21 +02:00
|
|
|
data = GlobalLock( handle );
|
2009-11-22 21:30:18 +01:00
|
|
|
|
|
|
|
/* read the important fields */
|
|
|
|
field_value = get_html_description_field(data, "StartFragment:");
|
|
|
|
if (!field_value)
|
|
|
|
{
|
|
|
|
ERR("Couldn't find StartFragment value\n");
|
2016-09-20 04:50:21 +02:00
|
|
|
goto failed;
|
2009-11-22 21:30:18 +01:00
|
|
|
}
|
|
|
|
fragmentstart = atoi(field_value);
|
|
|
|
|
|
|
|
field_value = get_html_description_field(data, "EndFragment:");
|
|
|
|
if (!field_value)
|
|
|
|
{
|
|
|
|
ERR("Couldn't find EndFragment value\n");
|
2016-09-20 04:50:21 +02:00
|
|
|
goto failed;
|
2009-11-22 21:30:18 +01:00
|
|
|
}
|
|
|
|
fragmentend = atoi(field_value);
|
|
|
|
|
|
|
|
/* export only the fragment */
|
2016-09-20 04:50:21 +02:00
|
|
|
put_property( display, win, prop, target, 8, &data[fragmentstart], fragmentend - fragmentstart );
|
|
|
|
GlobalUnlock( handle );
|
|
|
|
return TRUE;
|
2009-11-22 21:30:18 +01:00
|
|
|
|
2016-09-20 04:50:21 +02:00
|
|
|
failed:
|
|
|
|
GlobalUnlock( handle );
|
|
|
|
return FALSE;
|
2009-11-22 21:30:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-17 20:14:35 +02:00
|
|
|
/**************************************************************************
|
2016-09-16 09:58:38 +02:00
|
|
|
* export_hdrop
|
2014-07-17 20:14:35 +02:00
|
|
|
*
|
|
|
|
* Export CF_HDROP format to text/uri-list.
|
|
|
|
*/
|
2016-09-20 04:50:21 +02:00
|
|
|
static BOOL export_hdrop( Display *display, Window win, Atom prop, Atom target, HANDLE handle )
|
2014-07-17 20:14:35 +02:00
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
UINT numFiles;
|
2016-09-20 04:50:21 +02:00
|
|
|
char *textUriList;
|
2014-07-17 20:14:35 +02:00
|
|
|
UINT textUriListSize = 32;
|
|
|
|
UINT next = 0;
|
|
|
|
|
2016-09-20 04:50:21 +02:00
|
|
|
textUriList = HeapAlloc( GetProcessHeap(), 0, textUriListSize );
|
|
|
|
if (!textUriList) return FALSE;
|
|
|
|
numFiles = DragQueryFileW( handle, 0xFFFFFFFF, NULL, 0 );
|
2014-07-17 20:14:35 +02:00
|
|
|
for (i = 0; i < numFiles; i++)
|
|
|
|
{
|
|
|
|
UINT dosFilenameSize;
|
|
|
|
WCHAR *dosFilename = NULL;
|
|
|
|
char *unixFilename = NULL;
|
|
|
|
UINT uriSize;
|
|
|
|
UINT u;
|
|
|
|
|
2016-09-20 04:50:21 +02:00
|
|
|
dosFilenameSize = 1 + DragQueryFileW( handle, i, NULL, 0 );
|
2014-07-17 20:14:35 +02:00
|
|
|
dosFilename = HeapAlloc(GetProcessHeap(), 0, dosFilenameSize*sizeof(WCHAR));
|
|
|
|
if (dosFilename == NULL) goto failed;
|
2016-09-20 04:50:21 +02:00
|
|
|
DragQueryFileW( handle, i, dosFilename, dosFilenameSize );
|
2014-07-17 20:14:35 +02:00
|
|
|
unixFilename = wine_get_unix_file_name(dosFilename);
|
|
|
|
HeapFree(GetProcessHeap(), 0, dosFilename);
|
|
|
|
if (unixFilename == NULL) goto failed;
|
|
|
|
uriSize = 8 + /* file:/// */
|
|
|
|
3 * (lstrlenA(unixFilename) - 1) + /* "%xy" per char except first '/' */
|
|
|
|
2; /* \r\n */
|
|
|
|
if ((next + uriSize) > textUriListSize)
|
|
|
|
{
|
|
|
|
UINT biggerSize = max( 2 * textUriListSize, next + uriSize );
|
2016-09-20 04:50:21 +02:00
|
|
|
void *bigger = HeapReAlloc( GetProcessHeap(), 0, textUriList, biggerSize );
|
2014-07-17 20:14:35 +02:00
|
|
|
if (bigger)
|
|
|
|
{
|
2016-09-20 04:50:21 +02:00
|
|
|
textUriList = bigger;
|
2014-07-17 20:14:35 +02:00
|
|
|
textUriListSize = biggerSize;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, unixFilename);
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lstrcpyA(&textUriList[next], "file:///");
|
|
|
|
next += 8;
|
|
|
|
/* URL encode everything - unnecessary, but easier/lighter than linking in shlwapi, and can't hurt */
|
|
|
|
for (u = 1; unixFilename[u]; u++)
|
|
|
|
{
|
|
|
|
static const char hex_table[] = "0123456789abcdef";
|
|
|
|
textUriList[next++] = '%';
|
|
|
|
textUriList[next++] = hex_table[unixFilename[u] >> 4];
|
|
|
|
textUriList[next++] = hex_table[unixFilename[u] & 0xf];
|
|
|
|
}
|
|
|
|
textUriList[next++] = '\r';
|
|
|
|
textUriList[next++] = '\n';
|
|
|
|
HeapFree(GetProcessHeap(), 0, unixFilename);
|
|
|
|
}
|
2016-09-20 04:50:21 +02:00
|
|
|
put_property( display, win, prop, target, 8, textUriList, next );
|
|
|
|
HeapFree( GetProcessHeap(), 0, textUriList );
|
|
|
|
return TRUE;
|
2014-07-17 20:14:35 +02:00
|
|
|
|
|
|
|
failed:
|
2016-09-20 04:50:21 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, textUriList );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* export_selection
|
|
|
|
*
|
|
|
|
* Export selection data, depending on the target type.
|
|
|
|
*/
|
|
|
|
static BOOL export_selection( Display *display, Window win, Atom prop, Atom target )
|
|
|
|
{
|
|
|
|
struct clipboard_format *format = X11DRV_CLIPBOARD_LookupProperty( NULL, target );
|
|
|
|
HANDLE handle = 0;
|
|
|
|
|
|
|
|
if (!format || !format->export) return FALSE;
|
|
|
|
|
|
|
|
TRACE( "win %lx prop %s target %s exporting %s\n", win,
|
|
|
|
debugstr_xatom( prop ), debugstr_xatom( target ), debugstr_format( format->id ) );
|
|
|
|
|
|
|
|
if (format->id)
|
|
|
|
{
|
|
|
|
LPWINE_CLIPDATA data = X11DRV_CLIPBOARD_LookupData( format->id );
|
|
|
|
if (!data) return FALSE;
|
|
|
|
if (!X11DRV_CLIPBOARD_RenderFormat( display, data )) return FALSE;
|
|
|
|
handle = data->hData;
|
|
|
|
}
|
|
|
|
return format->export( display, win, prop, target, handle );
|
2014-07-17 20:14:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-09 20:09:40 +02:00
|
|
|
static int is_atom_error( Display *display, XErrorEvent *event, void *arg )
|
|
|
|
{
|
|
|
|
return (event->error_code == BadAtom);
|
|
|
|
}
|
|
|
|
|
2016-08-17 10:23:31 +02:00
|
|
|
static int is_window_error( Display *display, XErrorEvent *event, void *arg )
|
|
|
|
{
|
|
|
|
return (event->error_code == BadWindow);
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2016-09-19 16:07:04 +02:00
|
|
|
TRACE( "property %s -> format %s\n",
|
|
|
|
debugstr_xatom( lpFormat->atom ), debugstr_format( lpFormat->id ));
|
2016-09-19 15:55:56 +02:00
|
|
|
X11DRV_CLIPBOARD_InsertClipboardData( lpFormat->id, 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);
|
|
|
|
|
2011-03-07 17:02:21 +01:00
|
|
|
lpFormat = register_format( RegisterClipboardFormatW(wname), atoms[i] );
|
2005-01-11 16:10:56 +01:00
|
|
|
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;
|
|
|
|
}
|
2016-09-19 16:07:04 +02:00
|
|
|
TRACE( "property %s -> format %s\n",
|
|
|
|
debugstr_xatom( lpFormat->atom ), debugstr_format( lpFormat->id ));
|
2016-09-19 15:55:56 +02:00
|
|
|
X11DRV_CLIPBOARD_InsertClipboardData( lpFormat->id, 0, lpFormat, FALSE );
|
2004-07-08 22:14:37 +02:00
|
|
|
}
|
|
|
|
for (i = 0; i < nb_atoms; i++) XFree( names[i] );
|
|
|
|
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.
|
|
|
|
*/
|
2015-05-04 11:30:39 +02:00
|
|
|
static int X11DRV_CLIPBOARD_QueryAvailableData(Display *display)
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
|
|
|
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;
|
2016-09-20 07:13:24 +02:00
|
|
|
Atom prop;
|
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
|
|
|
|
*/
|
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
|
|
|
{
|
2016-09-20 07:13:24 +02:00
|
|
|
if (use_primary_selection && (prop = convert_selection( display, w, XA_PRIMARY, x11drv_atom(TARGETS) )))
|
2003-11-21 22:48:36 +01:00
|
|
|
selectionCacheSrc = XA_PRIMARY;
|
2016-09-20 07:13:24 +02:00
|
|
|
else if ((prop = convert_selection( display, w, x11drv_atom(CLIPBOARD), x11drv_atom(TARGETS) )))
|
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 */
|
2016-09-20 07:13:24 +02:00
|
|
|
if (convert_selection( display, w, XA_PRIMARY, XA_STRING ))
|
2004-07-08 22:14:37 +02:00
|
|
|
{
|
|
|
|
X11DRV_CLIPBOARD_InsertSelectionProperties(display, &xstr, 1);
|
|
|
|
selectionCacheSrc = XA_PRIMARY;
|
|
|
|
return 1;
|
|
|
|
}
|
2016-09-20 07:13:24 +02:00
|
|
|
else if (convert_selection( display, w, x11drv_atom(CLIPBOARD), XA_STRING ))
|
2004-07-08 22:14:37 +02:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
2012-08-16 16:46:37 +02:00
|
|
|
else return 0; /* No selection owner so report 0 targets available */
|
1999-09-03 17:17:57 +02:00
|
|
|
|
|
|
|
/* Read the TARGETS property contents */
|
2016-09-20 07:13:24 +02:00
|
|
|
if (!XGetWindowProperty(display, w, prop,
|
2003-06-24 01:02:02 +02:00
|
|
|
0, 0x3FFF, True, AnyPropertyType/*XA_ATOM*/, &atype, &aformat, &cSelectionTargets,
|
2015-11-25 22:28:53 +01:00
|
|
|
&remain, (unsigned char**)&targetList))
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2016-09-19 16:07:04 +02:00
|
|
|
TRACE( "type %s format %d count %ld remain %ld\n",
|
|
|
|
debugstr_xatom( 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
|
|
|
XFree(targetList);
|
1999-09-03 17:17:57 +02:00
|
|
|
}
|
2012-08-16 16:46:37 +02:00
|
|
|
else WARN("Failed to read TARGETS property\n");
|
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
|
|
|
{
|
2005-11-01 19:05:40 +01:00
|
|
|
BOOL bRet = FALSE;
|
2016-09-20 07:13:24 +02:00
|
|
|
Atom prop;
|
2005-11-01 19:05:40 +01:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-09-19 16:07:04 +02:00
|
|
|
TRACE("Requesting conversion of %s property %s from selection type %08x\n",
|
|
|
|
debugstr_format( lpData->lpFormat->id ), debugstr_xatom( lpData->lpFormat->atom ),
|
2011-03-03 21:09:22 +01:00
|
|
|
(UINT)selectionCacheSrc);
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2016-09-20 07:13:24 +02:00
|
|
|
prop = convert_selection( display, w, selectionCacheSrc, lpData->lpFormat->atom );
|
|
|
|
if (prop != 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.
|
|
|
|
*/
|
2016-09-20 06:17:30 +02:00
|
|
|
HANDLE hData = import_selection( display, w, prop, lpData->lpFormat );
|
|
|
|
if (hData)
|
|
|
|
bRet = X11DRV_CLIPBOARD_InsertClipboardData(lpData->wFormatID, hData, 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
|
|
|
|
2016-09-19 16:07:04 +02:00
|
|
|
TRACE( "Reading property %s from X window %lx\n", debugstr_xatom( 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
|
|
|
if (XGetWindowProperty(display, w, prop, pos, INT_MAX / 4, False,
|
2015-11-25 22:28:53 +01:00
|
|
|
AnyPropertyType, atype, &aformat, &nitems, &remain, &buffer))
|
2008-03-26 12:14:41 +01:00
|
|
|
{
|
|
|
|
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 );
|
|
|
|
HeapFree( GetProcessHeap(), 0, val );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
val = *data;
|
|
|
|
memcpy( (int *)val + pos, buffer, count );
|
|
|
|
XFree( buffer );
|
|
|
|
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. */
|
2005-11-01 19:05:40 +01:00
|
|
|
XDeleteProperty(display, w, prop);
|
|
|
|
return TRUE;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
|
2013-01-14 20:35:53 +01:00
|
|
|
struct clipboard_data_packet {
|
|
|
|
struct list entry;
|
|
|
|
unsigned long size;
|
|
|
|
unsigned char *data;
|
|
|
|
};
|
|
|
|
|
2008-10-31 04:18:00 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_ReadProperty
|
|
|
|
* Reads the contents of the X selection property.
|
|
|
|
*/
|
2016-09-20 06:17:30 +02:00
|
|
|
static BOOL X11DRV_CLIPBOARD_ReadProperty( Display *display, Window w, Atom prop,
|
|
|
|
Atom *type, unsigned char** data, unsigned long* datasize )
|
2008-10-31 04:18:00 +01:00
|
|
|
{
|
|
|
|
XEvent xe;
|
|
|
|
|
|
|
|
if (prop == None)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
while (XCheckTypedWindowEvent(display, w, PropertyNotify, &xe))
|
|
|
|
;
|
|
|
|
|
2016-09-20 06:17:30 +02:00
|
|
|
if (!X11DRV_CLIPBOARD_GetProperty(display, w, prop, type, data, datasize))
|
2013-01-04 00:00:40 +01:00
|
|
|
return FALSE;
|
|
|
|
|
2016-09-20 06:17:30 +02:00
|
|
|
if (*type == x11drv_atom(INCR))
|
2008-10-31 04:18:00 +01:00
|
|
|
{
|
2013-01-14 20:35:53 +01:00
|
|
|
unsigned char *buf;
|
2008-10-31 04:18:00 +01:00
|
|
|
unsigned long bufsize = 0;
|
2013-01-14 20:35:53 +01:00
|
|
|
struct list packets;
|
|
|
|
struct clipboard_data_packet *packet, *packet2;
|
|
|
|
BOOL res;
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, *data);
|
|
|
|
*data = NULL;
|
|
|
|
|
|
|
|
list_init(&packets);
|
2008-10-31 04:18:00 +01:00
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
int i;
|
2013-01-14 20:35:53 +01:00
|
|
|
unsigned char *prop_data;
|
2008-10-31 04:18:00 +01:00
|
|
|
unsigned long prop_size;
|
|
|
|
|
|
|
|
/* Wait until PropertyNotify is received */
|
|
|
|
for (i = 0; i < SELECTION_RETRIES; i++)
|
|
|
|
{
|
|
|
|
Bool res;
|
|
|
|
|
|
|
|
res = XCheckTypedWindowEvent(display, w, PropertyNotify, &xe);
|
|
|
|
if (res && xe.xproperty.atom == prop &&
|
|
|
|
xe.xproperty.state == PropertyNewValue)
|
|
|
|
break;
|
|
|
|
usleep(SELECTION_WAIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i >= SELECTION_RETRIES ||
|
2016-09-20 06:17:30 +02:00
|
|
|
!X11DRV_CLIPBOARD_GetProperty(display, w, prop, type, &prop_data, &prop_size))
|
2008-10-31 04:18:00 +01:00
|
|
|
{
|
2013-01-14 20:35:53 +01:00
|
|
|
res = FALSE;
|
|
|
|
break;
|
2008-10-31 04:18:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Retrieved entire data. */
|
|
|
|
if (prop_size == 0)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, prop_data);
|
2013-01-14 20:35:53 +01:00
|
|
|
res = TRUE;
|
|
|
|
break;
|
2008-10-31 04:18:00 +01:00
|
|
|
}
|
|
|
|
|
2013-01-14 20:35:53 +01:00
|
|
|
packet = HeapAlloc(GetProcessHeap(), 0, sizeof(*packet));
|
|
|
|
if (!packet)
|
2008-10-31 04:18:00 +01:00
|
|
|
{
|
2012-10-30 20:07:22 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, prop_data);
|
2013-01-14 20:35:53 +01:00
|
|
|
res = FALSE;
|
|
|
|
break;
|
2008-10-31 04:18:00 +01:00
|
|
|
}
|
|
|
|
|
2013-01-14 20:35:53 +01:00
|
|
|
packet->size = prop_size;
|
|
|
|
packet->data = prop_data;
|
|
|
|
list_add_tail(&packets, &packet->entry);
|
2008-10-31 04:18:00 +01:00
|
|
|
bufsize += prop_size;
|
|
|
|
}
|
2013-01-14 20:35:53 +01:00
|
|
|
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
buf = HeapAlloc(GetProcessHeap(), 0, bufsize + 1);
|
|
|
|
if (buf)
|
|
|
|
{
|
|
|
|
unsigned long bytes_copied = 0;
|
|
|
|
*datasize = bufsize;
|
|
|
|
LIST_FOR_EACH_ENTRY( packet, &packets, struct clipboard_data_packet, entry)
|
|
|
|
{
|
|
|
|
memcpy(&buf[bytes_copied], packet->data, packet->size);
|
|
|
|
bytes_copied += packet->size;
|
|
|
|
}
|
|
|
|
buf[bufsize] = 0;
|
|
|
|
*data = buf;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE( packet, packet2, &packets, struct clipboard_data_packet, entry)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, packet->data);
|
|
|
|
HeapFree(GetProcessHeap(), 0, packet);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
2008-10-31 04:18:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2015-05-04 11:30:39 +02:00
|
|
|
HWND owner;
|
2005-01-04 21:34:46 +01:00
|
|
|
|
|
|
|
/* completely give up the selection */
|
|
|
|
TRACE("Lost CLIPBOARD (+PRIMARY) selection\n");
|
|
|
|
|
2015-05-04 11:30:39 +02:00
|
|
|
if (X11DRV_CLIPBOARD_IsProcessOwner( &owner ))
|
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 */
|
2015-05-04 11:30:39 +02:00
|
|
|
SendMessageW(owner, 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
|
|
|
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");
|
|
|
|
}
|
|
|
|
else if ((selType == XA_PRIMARY) && (selectionAcquired & S_CLIPBOARD))
|
|
|
|
{
|
|
|
|
TRACE("Lost PRIMARY. Check if we need to release CLIPBOARD\n");
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
selectionWindow = None;
|
|
|
|
|
2016-09-07 04:35:14 +02:00
|
|
|
empty_clipboard();
|
2005-01-04 21:34:46 +01:00
|
|
|
|
|
|
|
/* 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
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV Clipboard Exports
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
2009-07-10 02:53:00 +02:00
|
|
|
static void selection_acquire(void)
|
|
|
|
{
|
|
|
|
Window owner;
|
|
|
|
Display *display;
|
|
|
|
|
|
|
|
owner = thread_selection_wnd();
|
|
|
|
display = thread_display();
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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
|
|
|
/**************************************************************************
|
2015-06-03 09:45:40 +02:00
|
|
|
* X11DRV_AcquireClipboard
|
1998-12-07 10:13:40 +01:00
|
|
|
*/
|
2015-06-03 09:45:40 +02:00
|
|
|
void 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);
|
|
|
|
|
2015-06-03 09:45:40 +02:00
|
|
|
SendMessageW(hWndClipWindow, WM_X11DRV_ACQUIRE_SELECTION, 0, 0);
|
|
|
|
return;
|
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);
|
2011-08-29 23:36:29 +02:00
|
|
|
selectionThread = CreateThread(NULL, 0, selection_thread_proc, event, 0, NULL);
|
2006-06-05 17:55:14 +02:00
|
|
|
|
2015-06-03 09:45:40 +02:00
|
|
|
if (selectionThread)
|
2009-07-10 02:53:00 +02:00
|
|
|
{
|
2015-06-03 09:45:40 +02:00
|
|
|
WaitForSingleObject(event, INFINITE);
|
|
|
|
CloseHandle(selectionThread);
|
2009-07-10 02:53:00 +02:00
|
|
|
}
|
2009-12-01 14:16:20 +01:00
|
|
|
CloseHandle(event);
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
1999-09-03 17:17:57 +02:00
|
|
|
}
|
1998-12-07 10:13:40 +01:00
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2016-09-07 04:35:14 +02:00
|
|
|
static void empty_clipboard(void)
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
2011-03-03 20:25:01 +01:00
|
|
|
WINE_CLIPDATA *data, *next;
|
1999-09-03 17:17:57 +02:00
|
|
|
|
2011-03-03 20:25:01 +01:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE( data, next, &data_list, WINE_CLIPDATA, entry )
|
|
|
|
{
|
|
|
|
list_remove( &data->entry );
|
|
|
|
X11DRV_CLIPBOARD_FreeData( data );
|
|
|
|
HeapFree( GetProcessHeap(), 0, data );
|
|
|
|
ClipDataCount--;
|
2004-05-07 01:40:30 +02:00
|
|
|
}
|
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
|
|
|
|
2015-06-03 09:38:44 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_EmptyClipboard
|
|
|
|
*
|
|
|
|
* Empty cached clipboard data.
|
|
|
|
*/
|
|
|
|
void CDECL X11DRV_EmptyClipboard(void)
|
|
|
|
{
|
2015-06-03 09:45:40 +02:00
|
|
|
X11DRV_AcquireClipboard( GetOpenClipboardWindow() );
|
2016-09-07 04:35:14 +02:00
|
|
|
empty_clipboard();
|
2015-06-03 09:38:44 +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
|
|
|
{
|
2016-08-23 10:59:36 +02:00
|
|
|
if (!owner) X11DRV_CLIPBOARD_UpdateCache();
|
2004-05-07 01:40:30 +02:00
|
|
|
|
2016-09-07 04:35:14 +02:00
|
|
|
return X11DRV_CLIPBOARD_InsertClipboardData(wFormat, hData, NULL, TRUE);
|
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
|
|
|
{
|
2015-05-04 11:30:39 +02:00
|
|
|
X11DRV_CLIPBOARD_UpdateCache();
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
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
|
|
|
{
|
2011-03-03 20:25:01 +01:00
|
|
|
struct list *ptr = NULL;
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
TRACE("(%04X)\n", wFormat);
|
|
|
|
|
2015-05-04 11:30:39 +02:00
|
|
|
X11DRV_CLIPBOARD_UpdateCache();
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
if (!wFormat)
|
|
|
|
{
|
2011-03-03 20:25:01 +01:00
|
|
|
ptr = list_head( &data_list );
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LPWINE_CLIPDATA lpData = X11DRV_CLIPBOARD_LookupData(wFormat);
|
2011-03-03 20:25:01 +01:00
|
|
|
if (lpData) ptr = list_next( &data_list, &lpData->entry );
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
2011-03-03 20:25:01 +01:00
|
|
|
if (!ptr) return 0;
|
|
|
|
return LIST_ENTRY( ptr, WINE_CLIPDATA, entry )->wFormatID;
|
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;
|
|
|
|
|
|
|
|
TRACE("(%04X)\n", wFormat);
|
|
|
|
|
2015-05-04 11:30:39 +02:00
|
|
|
X11DRV_CLIPBOARD_UpdateCache();
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
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
|
|
|
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
|
|
|
|
2015-05-04 11:30:39 +02:00
|
|
|
X11DRV_CLIPBOARD_UpdateCache();
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
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();
|
2016-09-07 04:35:14 +02:00
|
|
|
empty_clipboard();
|
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;
|
2011-03-03 20:52:13 +01:00
|
|
|
LPWINE_CLIPFORMAT format;
|
2005-11-01 19:05:40 +01:00
|
|
|
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
|
|
|
|
2011-03-03 20:25:01 +01:00
|
|
|
if (!list_head( &data_list )) return None;
|
2005-11-01 19:05:40 +01:00
|
|
|
|
2011-03-03 20:25:01 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( lpData, &data_list, WINE_CLIPDATA, entry )
|
2011-03-03 20:52:13 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( format, &format_list, WINE_CLIPFORMAT, entry )
|
2016-09-20 04:50:21 +02:00
|
|
|
if (format->id == lpData->wFormatID && format->export && format->atom)
|
2005-02-25 22:01:15 +01:00
|
|
|
cTargets++;
|
2005-11-01 19:05:40 +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;
|
|
|
|
targets[i++] = x11drv_atom(TARGETS);
|
|
|
|
|
2011-03-03 20:25:01 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( lpData, &data_list, WINE_CLIPDATA, entry )
|
2011-03-03 20:52:13 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( format, &format_list, WINE_CLIPFORMAT, entry )
|
2016-09-20 04:50:21 +02:00
|
|
|
if (format->id == lpData->wFormatID && format->export && format->atom)
|
2016-09-19 16:07:04 +02:00
|
|
|
{
|
|
|
|
TRACE( "%d: %s -> %s\n", i, debugstr_format( format->id ),
|
|
|
|
debugstr_xatom( format->atom ));
|
2016-09-19 15:55:56 +02:00
|
|
|
targets[i++] = format->atom;
|
2016-09-19 16:07:04 +02:00
|
|
|
}
|
2005-02-25 22:01:15 +01:00
|
|
|
|
2016-09-20 04:32:08 +02:00
|
|
|
put_property( display, requestor, rprop, XA_ATOM, 32, targets, cTargets );
|
2005-02-25 22:01:15 +01:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2012-08-16 16:46:37 +02:00
|
|
|
if (!XGetWindowProperty(display, pevent->requestor, rprop,
|
|
|
|
0, 0x3FFF, False, AnyPropertyType, &atype,&aformat,
|
|
|
|
&cTargetPropList, &remain,
|
2015-11-25 22:28:53 +01:00
|
|
|
(unsigned char**)&targetPropList))
|
2005-02-25 22:01:15 +01:00
|
|
|
{
|
2016-09-19 16:07:04 +02:00
|
|
|
TRACE( "type %s format %d count %ld remain %ld\n",
|
|
|
|
debugstr_xatom( atype ), aformat, cTargetPropList, remain );
|
2005-02-25 22:01:15 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
2016-09-19 16:07:04 +02:00
|
|
|
TRACE( "MULTIPLE(%d): target %s property %s\n",
|
|
|
|
i/2, debugstr_xatom( targetPropList[i] ), debugstr_xatom( targetPropList[i + 1] ));
|
2005-02-25 22:01:15 +01:00
|
|
|
|
|
|
|
/* 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 */
|
|
|
|
XFree(targetPropList);
|
|
|
|
}
|
2012-08-16 16:46:37 +02:00
|
|
|
else TRACE("Couldn't read MULTIPLE property\n");
|
2005-02-25 22:01:15 +01:00
|
|
|
|
|
|
|
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");
|
|
|
|
|
2016-08-17 10:23:31 +02:00
|
|
|
X11DRV_expect_error( display, is_window_error, NULL );
|
|
|
|
|
2005-02-25 22:01:15 +01:00
|
|
|
/*
|
|
|
|
* 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 );
|
|
|
|
}
|
2016-09-20 04:50:21 +02:00
|
|
|
else if (!export_selection( display, event->requestor, rprop, event->target ))
|
|
|
|
rprop = None; /* report failure to client */
|
2005-02-25 22:01:15 +01:00
|
|
|
|
|
|
|
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");
|
|
|
|
XSendEvent(display,event->requestor,False,NoEventMask,(XEvent*)&result);
|
|
|
|
}
|
2016-08-17 10:23:31 +02:00
|
|
|
XSync( display, False );
|
|
|
|
if (X11DRV_check_error()) WARN( "requestor %lx is no longer valid\n", event->requestor );
|
2005-02-25 22:01:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_SelectionRequest
|
|
|
|
*/
|
2016-08-23 15:13:26 +02:00
|
|
|
BOOL 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 );
|
2016-08-23 15:13:26 +02:00
|
|
|
return FALSE;
|
2005-02-25 22:01:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_SelectionClear
|
|
|
|
*/
|
2016-08-23 15:13:26 +02:00
|
|
|
BOOL 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 );
|
2016-08-23 15:13:26 +02:00
|
|
|
return FALSE;
|
2005-02-25 22:01:15 +01:00
|
|
|
}
|