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
|
2016-09-21 05:10:32 +02:00
|
|
|
* Copyright 1996 Alex Korobka
|
|
|
|
* Copyright 1999 Noel Borthwick
|
|
|
|
* Copyright 2003 Ulrich Czekalla for CodeWeavers
|
|
|
|
* Copyright 2014 Damjan Jovanovic
|
|
|
|
* Copyright 2016 Alexandre Julliard
|
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
|
|
|
|
2017-05-24 15:17:57 +02:00
|
|
|
#include "x11drv.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_X11_EXTENSIONS_XFIXES_H
|
|
|
|
#include <X11/extensions/Xfixes.h>
|
|
|
|
#endif
|
|
|
|
|
2014-05-27 02:23:55 +02:00
|
|
|
#include "shlobj.h"
|
|
|
|
#include "shellapi.h"
|
|
|
|
#include "shlwapi.h"
|
2017-05-24 15:17:57 +02:00
|
|
|
#include "wine/library.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"
|
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
|
|
|
|
2016-09-23 07:07:59 +02:00
|
|
|
#define SELECTION_UPDATE_DELAY 2000 /* delay between checks of the X11 selection */
|
|
|
|
|
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-26 13:27:40 +02:00
|
|
|
struct clipboard_format
|
2016-09-16 09:58:38 +02:00
|
|
|
{
|
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;
|
2016-09-26 13:27:40 +02:00
|
|
|
};
|
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_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 );
|
2016-09-28 04:38:23 +02:00
|
|
|
static HANDLE import_text( Atom type, const void *data, size_t size );
|
2017-01-11 20:55:21 +01:00
|
|
|
static HANDLE import_text_html( Atom type, const void *data, size_t size );
|
2016-09-20 06:17:30 +02:00
|
|
|
static HANDLE import_text_uri_list( Atom type, const void *data, size_t size );
|
2016-09-22 05:50:34 +02:00
|
|
|
static HANDLE import_targets( 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 );
|
2016-09-28 04:38:23 +02:00
|
|
|
static BOOL export_text( Display *display, Window win, Atom prop, Atom target, HANDLE handle );
|
2016-09-20 04:50:21 +02:00
|
|
|
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_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-21 05:04:07 +02:00
|
|
|
static BOOL export_targets( Display *display, Window win, Atom prop, Atom target, HANDLE handle );
|
2016-09-21 05:03:23 +02:00
|
|
|
static BOOL export_multiple( Display *display, Window win, Atom prop, Atom target, HANDLE handle );
|
2016-09-28 04:38:47 +02:00
|
|
|
static BOOL export_timestamp( Display *display, Window win, Atom prop, Atom target, HANDLE handle );
|
2016-09-16 09:58:38 +02:00
|
|
|
|
2017-01-10 16:21:46 +01:00
|
|
|
static BOOL read_property( Display *display, Window w, Atom prop,
|
|
|
|
Atom *type, unsigned char **data, unsigned long *datasize );
|
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-27 14:36:13 +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 },
|
|
|
|
{ 0, CF_UNICODETEXT, XA_STRING, import_string, export_string },
|
|
|
|
{ 0, CF_UNICODETEXT, XATOM_text_plain, import_string, export_string },
|
2016-09-28 04:38:23 +02:00
|
|
|
{ 0, CF_UNICODETEXT, XATOM_TEXT, import_text, export_text },
|
2016-09-16 09:58:38 +02:00
|
|
|
{ 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_DIB, XA_PIXMAP, import_pixmap, export_pixmap },
|
|
|
|
{ 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 },
|
|
|
|
{ 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_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 },
|
2017-01-11 20:55:21 +01:00
|
|
|
{ HTMLFormatW, 0, XATOM_text_html, import_text_html, export_text_html },
|
2016-09-22 05:50:34 +02:00
|
|
|
{ 0, 0, XATOM_TARGETS, import_targets, export_targets },
|
2016-09-21 05:03:23 +02:00
|
|
|
{ 0, 0, XATOM_MULTIPLE, NULL, export_multiple },
|
2016-09-28 04:38:47 +02:00
|
|
|
{ 0, 0, XATOM_TIMESTAMP, NULL, export_timestamp },
|
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
|
|
|
|
2016-09-26 13:27:40 +02:00
|
|
|
static DWORD clipboard_thread_id;
|
|
|
|
static HWND clipboard_hwnd;
|
|
|
|
static BOOL is_clipboard_owner;
|
|
|
|
static Window selection_window;
|
|
|
|
static Window import_window;
|
|
|
|
static Atom current_selection;
|
2017-01-10 16:23:20 +01:00
|
|
|
static UINT rendered_formats;
|
2016-09-26 13:27:40 +02:00
|
|
|
static ULONG64 last_clipboard_update;
|
2016-09-23 13:28:28 +02:00
|
|
|
static struct clipboard_format **current_x11_formats;
|
|
|
|
static unsigned int nb_current_x11_formats;
|
2017-05-24 15:17:57 +02:00
|
|
|
static BOOL use_xfixes;
|
2016-09-23 13:28:28 +02:00
|
|
|
|
2016-09-26 14:06:14 +02:00
|
|
|
Display *clipboard_display = NULL;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-09-22 06:13:25 +02:00
|
|
|
|
2016-09-22 08:04:33 +02:00
|
|
|
static int is_atom_error( Display *display, XErrorEvent *event, void *arg )
|
|
|
|
{
|
|
|
|
return (event->error_code == BadAtom);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-22 06:13:25 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* find_win32_format
|
|
|
|
*/
|
|
|
|
static struct clipboard_format *find_win32_format( UINT id )
|
|
|
|
{
|
|
|
|
struct clipboard_format *format;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( format, &format_list, struct clipboard_format, entry )
|
|
|
|
if (format->id == id) return format;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-22 08:04:33 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* find_x11_format
|
|
|
|
*/
|
|
|
|
static struct clipboard_format *find_x11_format( Atom atom )
|
|
|
|
{
|
|
|
|
struct clipboard_format *format;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( format, &format_list, struct clipboard_format, entry )
|
|
|
|
if (format->atom == atom) return format;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-26 13:16:06 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* register_builtin_formats
|
|
|
|
*/
|
|
|
|
static void register_builtin_formats(void)
|
|
|
|
{
|
|
|
|
struct clipboard_format *formats;
|
|
|
|
unsigned int i;
|
|
|
|
|
2018-07-07 23:39:08 +02:00
|
|
|
if (!(formats = HeapAlloc( GetProcessHeap(), 0, ARRAY_SIZE(builtin_formats) * sizeof(*formats)))) return;
|
2016-09-26 13:16:06 +02:00
|
|
|
|
2018-07-07 23:39:08 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(builtin_formats); i++)
|
2016-09-26 13:16:06 +02:00
|
|
|
{
|
|
|
|
if (builtin_formats[i].name)
|
|
|
|
formats[i].id = RegisterClipboardFormatW( builtin_formats[i].name );
|
|
|
|
else
|
|
|
|
formats[i].id = builtin_formats[i].id;
|
|
|
|
|
|
|
|
formats[i].atom = GET_ATOM(builtin_formats[i].data);
|
|
|
|
formats[i].import = builtin_formats[i].import;
|
|
|
|
formats[i].export = builtin_formats[i].export;
|
|
|
|
list_add_tail( &format_list, &formats[i].entry );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-22 06:13:25 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* register_formats
|
|
|
|
*/
|
|
|
|
static void register_formats( const UINT *ids, const Atom *atoms, unsigned int count )
|
|
|
|
{
|
|
|
|
struct clipboard_format *formats;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (!(formats = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*formats)))) return;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
formats[i].id = ids[i];
|
|
|
|
formats[i].atom = atoms[i];
|
|
|
|
formats[i].import = import_data;
|
|
|
|
formats[i].export = export_data;
|
|
|
|
list_add_tail( &format_list, &formats[i].entry );
|
|
|
|
TRACE( "registered %s atom %s\n", debugstr_format( ids[i] ), debugstr_xatom( atoms[i] ));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* register_win32_formats
|
|
|
|
*
|
|
|
|
* Register Win32 clipboard formats the first time we encounter them.
|
|
|
|
*/
|
|
|
|
static void register_win32_formats( const UINT *ids, UINT size )
|
|
|
|
{
|
|
|
|
unsigned int count, len;
|
|
|
|
UINT new_ids[256];
|
|
|
|
char *names[256];
|
|
|
|
Atom atoms[256];
|
|
|
|
WCHAR buffer[256];
|
|
|
|
|
2016-09-26 13:16:06 +02:00
|
|
|
if (list_empty( &format_list)) register_builtin_formats();
|
|
|
|
|
2016-09-22 06:13:25 +02:00
|
|
|
while (size)
|
|
|
|
{
|
|
|
|
for (count = 0; count < 256 && size; ids++, size--)
|
|
|
|
{
|
|
|
|
if (find_win32_format( *ids )) continue; /* it already exists */
|
|
|
|
if (!GetClipboardFormatNameW( *ids, buffer, 256 )) continue; /* not a named format */
|
|
|
|
if (!(len = WideCharToMultiByte( CP_UNIXCP, 0, buffer, -1, NULL, 0, NULL, NULL ))) continue;
|
|
|
|
if (!(names[count] = HeapAlloc( GetProcessHeap(), 0, len ))) continue;
|
|
|
|
WideCharToMultiByte( CP_UNIXCP, 0, buffer, -1, names[count], len, NULL, NULL );
|
|
|
|
new_ids[count++] = *ids;
|
|
|
|
}
|
|
|
|
if (!count) return;
|
|
|
|
|
|
|
|
XInternAtoms( thread_display(), names, count, False, atoms );
|
|
|
|
register_formats( new_ids, atoms, count );
|
|
|
|
while (count) HeapFree( GetProcessHeap(), 0, names[--count] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-22 08:04:33 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* register_x11_formats
|
|
|
|
*
|
|
|
|
* Register X11 atom formats the first time we encounter them.
|
|
|
|
*/
|
|
|
|
static void register_x11_formats( const Atom *atoms, UINT size )
|
|
|
|
{
|
|
|
|
Display *display = thread_display();
|
|
|
|
unsigned int i, pos, count;
|
|
|
|
char *names[256];
|
|
|
|
UINT ids[256];
|
|
|
|
Atom new_atoms[256];
|
|
|
|
WCHAR buffer[256];
|
|
|
|
|
2016-09-26 13:16:06 +02:00
|
|
|
if (list_empty( &format_list)) register_builtin_formats();
|
|
|
|
|
2016-09-22 08:04:33 +02:00
|
|
|
while (size)
|
|
|
|
{
|
|
|
|
for (count = 0; count < 256 && size; atoms++, size--)
|
|
|
|
if (!find_x11_format( *atoms )) new_atoms[count++] = *atoms;
|
|
|
|
|
|
|
|
if (!count) return;
|
|
|
|
|
|
|
|
X11DRV_expect_error( display, is_atom_error, NULL );
|
|
|
|
if (!XGetAtomNames( display, new_atoms, count, names )) count = 0;
|
|
|
|
if (X11DRV_check_error())
|
|
|
|
{
|
|
|
|
WARN( "got some bad atoms, ignoring\n" );
|
|
|
|
count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = pos = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (MultiByteToWideChar( CP_UNIXCP, 0, names[i], -1, buffer, 256 ) &&
|
|
|
|
(ids[pos] = RegisterClipboardFormatW( buffer )))
|
|
|
|
new_atoms[pos++] = new_atoms[i];
|
|
|
|
XFree( names[i] );
|
|
|
|
}
|
|
|
|
register_formats( ids, new_atoms, pos );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
2017-01-10 16:21:46 +01:00
|
|
|
static BOOL convert_selection( Display *display, Window win, Atom selection,
|
|
|
|
struct clipboard_format *format, Atom *type,
|
|
|
|
unsigned char **data, unsigned long *size )
|
2016-09-20 07:13:24 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
XEvent event;
|
|
|
|
|
2017-01-10 16:21:46 +01:00
|
|
|
TRACE( "import %s from %s win %lx to format %s\n",
|
|
|
|
debugstr_xatom( format->atom ), debugstr_xatom( selection ),
|
|
|
|
win, debugstr_format( format->id ) );
|
|
|
|
|
|
|
|
XConvertSelection( display, selection, format->atom, x11drv_atom(SELECTION_DATA), win, CurrentTime );
|
2016-09-20 07:13:24 +02:00
|
|
|
|
|
|
|
for (i = 0; i < SELECTION_RETRIES; i++)
|
|
|
|
{
|
|
|
|
Bool res = XCheckTypedWindowEvent( display, win, SelectionNotify, &event );
|
2017-01-10 16:21:46 +01:00
|
|
|
if (res && event.xselection.selection == selection && event.xselection.target == format->atom)
|
|
|
|
return read_property( display, win, event.xselection.property, type, data, size );
|
2016-09-20 07:13:24 +02:00
|
|
|
usleep( SELECTION_WAIT );
|
|
|
|
}
|
|
|
|
ERR( "Timed out waiting for SelectionNotify event\n" );
|
2017-01-10 16:21:46 +01:00
|
|
|
return FALSE;
|
2016-09-20 07:13:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-27 14:13:07 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* unicode_text_from_string
|
|
|
|
*
|
|
|
|
* Convert a string in the specified encoding to CF_UNICODETEXT format.
|
|
|
|
*/
|
|
|
|
static HANDLE unicode_text_from_string( UINT codepage, const void *data, size_t size )
|
|
|
|
{
|
|
|
|
DWORD i, j, count;
|
|
|
|
WCHAR *strW;
|
|
|
|
|
|
|
|
count = MultiByteToWideChar( codepage, 0, data, size, NULL, 0);
|
|
|
|
|
|
|
|
if (!(strW = GlobalAlloc( GMEM_FIXED, (count * 2 + 1) * sizeof(WCHAR) ))) return 0;
|
|
|
|
|
|
|
|
MultiByteToWideChar( codepage, 0, data, size, strW + count, count );
|
|
|
|
for (i = j = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (strW[i + count] == '\n') strW[j++] = '\r';
|
|
|
|
strW[j++] = strW[i + count];
|
|
|
|
}
|
|
|
|
strW[j++] = 0;
|
|
|
|
GlobalReAlloc( strW, j * sizeof(WCHAR), GMEM_FIXED ); /* release unused space */
|
|
|
|
TRACE( "returning %s\n", debugstr_wn( strW, j - 1 ));
|
|
|
|
return strW;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
*
|
2016-09-27 14:36:13 +02:00
|
|
|
* Import XA_STRING, converting the string to CF_UNICODETEXT.
|
2005-11-01 19:05:40 +01:00
|
|
|
*/
|
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-27 14:36:13 +02:00
|
|
|
return unicode_text_from_string( 28591, data, size );
|
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-27 14:13:07 +02:00
|
|
|
* Import XA_UTF8_STRING, converting the string to CF_UNICODETEXT.
|
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-27 14:13:07 +02:00
|
|
|
return unicode_text_from_string( CP_UTF8, data, size );
|
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
|
|
|
*
|
2016-09-27 14:13:07 +02:00
|
|
|
* Import COMPOUND_TEXT to CF_UNICODETEXT.
|
2005-11-01 19:05:40 +01:00
|
|
|
*/
|
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
|
|
|
{
|
|
|
|
char** srcstr;
|
2016-09-27 14:13:07 +02:00
|
|
|
int count;
|
|
|
|
HANDLE ret;
|
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
|
|
|
|
2016-09-27 14:13:07 +02:00
|
|
|
ret = unicode_text_from_string( CP_UNIXCP, srcstr[0], strlen(srcstr[0]) + 1 );
|
2005-11-01 19:05:40 +01:00
|
|
|
XFreeStringList(srcstr);
|
2016-09-27 14:13:07 +02:00
|
|
|
return ret;
|
1999-09-03 17:17:57 +02:00
|
|
|
}
|
1998-12-07 10:13:40 +01:00
|
|
|
|
1999-09-20 17:42:47 +02:00
|
|
|
|
2016-09-28 04:38:23 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* import_text
|
|
|
|
*
|
|
|
|
* Import XA_TEXT, converting the string to CF_UNICODETEXT.
|
|
|
|
*/
|
|
|
|
static HANDLE import_text( Atom type, const void *data, size_t size )
|
|
|
|
{
|
|
|
|
if (type == XA_STRING) return import_string( type, data, size );
|
|
|
|
if (type == x11drv_atom(UTF8_STRING)) return import_utf8_string( type, data, size );
|
|
|
|
if (type == x11drv_atom(COMPOUND_TEXT)) return import_compound_text( type, data, size );
|
|
|
|
FIXME( "unsupported TEXT type %s\n", debugstr_xatom( type ));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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_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
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-11 20:55:21 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* import_text_html
|
|
|
|
*/
|
|
|
|
static HANDLE import_text_html( Atom type, const void *data, size_t size )
|
|
|
|
{
|
|
|
|
static const char header[] =
|
|
|
|
"Version:0.9\n"
|
|
|
|
"StartHTML:0000000100\n"
|
|
|
|
"EndHTML:%010lu\n"
|
|
|
|
"StartFragment:%010lu\n"
|
|
|
|
"EndFragment:%010lu\n"
|
|
|
|
"<!--StartFragment-->";
|
|
|
|
static const char trailer[] = "\n<!--EndFragment-->";
|
|
|
|
char *text = NULL;
|
|
|
|
HANDLE ret;
|
|
|
|
SIZE_T len, total;
|
|
|
|
|
|
|
|
/* Firefox uses UTF-16LE with byte order mark. Convert to UTF-8 without the BOM. */
|
|
|
|
if (size >= sizeof(WCHAR) && ((const WCHAR *)data)[0] == 0xfeff)
|
|
|
|
{
|
|
|
|
len = WideCharToMultiByte( CP_UTF8, 0, (const WCHAR *)data + 1, size / sizeof(WCHAR) - 1,
|
|
|
|
NULL, 0, NULL, NULL );
|
|
|
|
if (!(text = HeapAlloc( GetProcessHeap(), 0, len ))) return 0;
|
|
|
|
WideCharToMultiByte( CP_UTF8, 0, (const WCHAR *)data + 1, size / sizeof(WCHAR) - 1,
|
|
|
|
text, len, NULL, NULL );
|
|
|
|
size = len;
|
|
|
|
data = text;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = strlen( header ) + 12; /* 3 * 4 extra chars for %010lu */
|
|
|
|
total = len + size + sizeof(trailer);
|
|
|
|
if ((ret = GlobalAlloc( GMEM_FIXED, total )))
|
|
|
|
{
|
|
|
|
char *p = ret;
|
|
|
|
p += sprintf( p, header, total - 1, len, len + size + 1 /* include the final \n in the data */ );
|
|
|
|
memcpy( p, data, size );
|
|
|
|
strcpy( p + size, trailer );
|
|
|
|
TRACE( "returning %s\n", debugstr_a( ret ));
|
|
|
|
}
|
|
|
|
HeapFree( GetProcessHeap(), 0, text );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-23 05:33:44 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* import_targets
|
|
|
|
*
|
|
|
|
* Import TARGETS and mark the corresponding clipboard formats as available.
|
|
|
|
*/
|
|
|
|
static HANDLE import_targets( Atom type, const void *data, size_t size )
|
|
|
|
{
|
2016-09-23 13:28:28 +02:00
|
|
|
UINT i, pos, count = size / sizeof(Atom);
|
2016-09-23 05:33:44 +02:00
|
|
|
const Atom *properties = data;
|
2016-09-23 13:28:28 +02:00
|
|
|
struct clipboard_format *format, **formats;
|
2016-09-23 05:33:44 +02:00
|
|
|
|
|
|
|
if (type != XA_ATOM && type != x11drv_atom(TARGETS)) return 0;
|
|
|
|
|
|
|
|
register_x11_formats( properties, count );
|
|
|
|
|
2016-09-23 13:28:28 +02:00
|
|
|
/* the builtin formats contain duplicates, so allocate some extra space */
|
2018-07-07 23:39:08 +02:00
|
|
|
if (!(formats = HeapAlloc( GetProcessHeap(), 0, (count + ARRAY_SIZE(builtin_formats)) * sizeof(*formats ))))
|
2016-09-23 13:28:28 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
pos = 0;
|
2016-09-23 05:33:44 +02:00
|
|
|
LIST_FOR_EACH_ENTRY( format, &format_list, struct clipboard_format, entry )
|
|
|
|
{
|
|
|
|
for (i = 0; i < count; i++) if (properties[i] == format->atom) break;
|
|
|
|
if (i == count) continue;
|
|
|
|
if (format->import && format->id)
|
|
|
|
{
|
|
|
|
TRACE( "property %s -> format %s\n",
|
|
|
|
debugstr_xatom( properties[i] ), debugstr_format( format->id ));
|
2016-09-26 13:24:47 +02:00
|
|
|
SetClipboardData( format->id, 0 );
|
2016-09-23 13:28:28 +02:00
|
|
|
formats[pos++] = format;
|
2016-09-23 05:33:44 +02:00
|
|
|
}
|
|
|
|
else TRACE( "property %s (ignoring)\n", debugstr_xatom( properties[i] ));
|
|
|
|
}
|
2016-09-23 13:28:28 +02:00
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, current_x11_formats );
|
|
|
|
current_x11_formats = formats;
|
|
|
|
nb_current_x11_formats = pos;
|
2016-09-23 05:33:44 +02:00
|
|
|
return (HANDLE)1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
*
|
2016-09-21 05:01:15 +02:00
|
|
|
* Import the specified format from the selection and return a global handle to the data.
|
2016-09-20 06:17:30 +02:00
|
|
|
*/
|
2016-09-21 05:01:15 +02:00
|
|
|
static HANDLE import_selection( Display *display, Window win, Atom selection,
|
|
|
|
struct clipboard_format *format )
|
2016-09-20 06:17:30 +02:00
|
|
|
{
|
|
|
|
unsigned char *data;
|
|
|
|
unsigned long size;
|
2017-01-10 16:21:46 +01:00
|
|
|
Atom type;
|
2016-09-20 06:17:30 +02:00
|
|
|
HANDLE ret;
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2016-09-20 06:17:30 +02:00
|
|
|
if (!format->import) return 0;
|
2016-09-21 05:01:15 +02:00
|
|
|
|
2017-01-10 16:21:46 +01:00
|
|
|
if (!convert_selection( display, win, selection, format, &type, &data, &size ))
|
2016-09-21 05:01:15 +02:00
|
|
|
{
|
|
|
|
TRACE( "failed to convert selection\n" );
|
|
|
|
return 0;
|
|
|
|
}
|
2016-09-20 06:17:30 +02:00
|
|
|
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-22 06:07:44 +02:00
|
|
|
void X11DRV_CLIPBOARD_ImportSelection( Display *display, Window win, Atom selection,
|
|
|
|
Atom *targets, UINT count,
|
|
|
|
void (*callback)( Atom, UINT, HANDLE ))
|
2014-05-27 02:22:07 +02:00
|
|
|
{
|
2016-09-22 06:07:44 +02:00
|
|
|
UINT i;
|
|
|
|
HANDLE handle;
|
|
|
|
struct clipboard_format *format;
|
|
|
|
|
2016-09-22 08:04:33 +02:00
|
|
|
register_x11_formats( targets, count );
|
|
|
|
|
2016-09-22 06:07:44 +02:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2016-09-22 08:04:33 +02:00
|
|
|
if (!(format = find_x11_format( targets[i] ))) continue;
|
2016-09-22 06:07:44 +02:00
|
|
|
if (!format->id) continue;
|
|
|
|
if (!(handle = import_selection( display, win, selection, format ))) continue;
|
|
|
|
callback( targets[i], format->id, handle );
|
|
|
|
}
|
2014-05-27 02:22:07 +02:00
|
|
|
}
|
|
|
|
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2016-09-23 13:28:28 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* render_format
|
|
|
|
*/
|
2017-01-10 16:23:20 +01:00
|
|
|
static HANDLE render_format( UINT id )
|
2016-09-23 13:28:28 +02:00
|
|
|
{
|
2016-09-26 13:27:40 +02:00
|
|
|
Display *display = thread_display();
|
2016-09-23 13:28:28 +02:00
|
|
|
unsigned int i;
|
|
|
|
HANDLE handle = 0;
|
|
|
|
|
2017-01-10 16:23:20 +01:00
|
|
|
if (!current_selection) return 0;
|
2016-09-26 13:27:40 +02:00
|
|
|
|
2016-09-23 13:28:28 +02:00
|
|
|
for (i = 0; i < nb_current_x11_formats; i++)
|
|
|
|
{
|
|
|
|
if (current_x11_formats[i]->id != id) continue;
|
2017-08-25 08:08:13 +02:00
|
|
|
if (!(handle = import_selection( display, import_window,
|
|
|
|
current_selection, current_x11_formats[i] ))) continue;
|
|
|
|
SetClipboardData( id, handle );
|
2016-09-23 13:28:28 +02:00
|
|
|
break;
|
|
|
|
}
|
2017-01-10 16:23:20 +01:00
|
|
|
return handle;
|
2016-09-23 13:28:28 +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
|
|
|
|
|
|
|
|
2016-09-27 14:24:25 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* string_from_unicode_text
|
|
|
|
*
|
|
|
|
* Convert CF_UNICODETEXT data to a string in the specified codepage.
|
|
|
|
*/
|
|
|
|
static char *string_from_unicode_text( UINT codepage, HANDLE handle, UINT *size )
|
|
|
|
{
|
|
|
|
UINT i, j;
|
|
|
|
char *str;
|
|
|
|
WCHAR *strW = GlobalLock( handle );
|
|
|
|
UINT lenW = GlobalSize( handle ) / sizeof(WCHAR);
|
|
|
|
DWORD len = WideCharToMultiByte( codepage, 0, strW, lenW, NULL, 0, NULL, NULL );
|
|
|
|
|
|
|
|
if ((str = HeapAlloc( GetProcessHeap(), 0, len )))
|
|
|
|
{
|
|
|
|
WideCharToMultiByte( codepage, 0, strW, lenW, str, len, NULL, NULL);
|
|
|
|
GlobalUnlock( handle );
|
|
|
|
|
|
|
|
/* remove carriage returns */
|
|
|
|
for (i = j = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
if (str[i] == '\r' && (i == len - 1 || str[i + 1] == '\n')) continue;
|
|
|
|
str[j++] = str[i];
|
|
|
|
}
|
2017-05-10 22:28:27 +02:00
|
|
|
while (j && !str[j - 1]) j--; /* remove trailing nulls */
|
2016-09-27 14:24:25 +02:00
|
|
|
*size = j;
|
|
|
|
TRACE( "returning %s\n", debugstr_an( str, j ));
|
|
|
|
}
|
|
|
|
GlobalUnlock( handle );
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
*
|
2016-09-27 14:36:13 +02:00
|
|
|
* Export CF_UNICODETEXT 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 size;
|
2016-09-27 14:36:13 +02:00
|
|
|
char *text = string_from_unicode_text( 28591, handle, &size );
|
2005-11-01 19:05:40 +01:00
|
|
|
|
2016-09-27 14:36:13 +02:00
|
|
|
if (!text) return FALSE;
|
|
|
|
put_property( display, win, prop, target, 8, text, size );
|
|
|
|
HeapFree( GetProcessHeap(), 0, text );
|
2016-09-20 04:50:21 +02:00
|
|
|
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
|
|
|
{
|
|
|
|
UINT size;
|
2016-09-27 14:24:25 +02:00
|
|
|
char *text = string_from_unicode_text( CP_UTF8, handle, &size );
|
2016-09-20 04:50:21 +02:00
|
|
|
|
2016-09-27 14:24:25 +02:00
|
|
|
if (!text) return FALSE;
|
|
|
|
put_property( display, win, prop, target, 8, text, size );
|
|
|
|
HeapFree( GetProcessHeap(), 0, text );
|
2016-09-20 04:50:21 +02:00
|
|
|
GlobalUnlock( handle );
|
|
|
|
return TRUE;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-28 04:38:23 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* export_text
|
|
|
|
*
|
|
|
|
* Export CF_UNICODE to the polymorphic TEXT type, using UTF8.
|
|
|
|
*/
|
|
|
|
static BOOL export_text( Display *display, Window win, Atom prop, Atom target, HANDLE handle )
|
|
|
|
{
|
|
|
|
return export_utf8_string( display, win, prop, x11drv_atom(UTF8_STRING), handle );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
XTextProperty textprop;
|
2003-07-08 23:02:51 +02:00
|
|
|
XICCEncodingStyle style;
|
2005-11-01 19:05:40 +01:00
|
|
|
UINT size;
|
2016-09-27 14:24:25 +02:00
|
|
|
char *text = string_from_unicode_text( CP_UNIXCP, handle, &size );
|
2003-07-08 23:02:51 +02:00
|
|
|
|
2016-09-27 14:24:25 +02:00
|
|
|
if (!text) return FALSE;
|
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-27 14:24:25 +02:00
|
|
|
if (XmbTextListToTextProperty( display, &text, 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
|
|
|
|
2016-09-27 14:24:25 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, text );
|
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_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
|
|
|
/**************************************************************************
|
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
|
|
|
{
|
2017-05-10 22:28:12 +02:00
|
|
|
const char *p, *data;
|
|
|
|
UINT start = 0, end = 0;
|
|
|
|
BOOL ret = TRUE;
|
2009-11-22 21:30:18 +01:00
|
|
|
|
2017-05-10 22:28:12 +02:00
|
|
|
if (!(data = GlobalLock( handle ))) return FALSE;
|
2009-11-22 21:30:18 +01:00
|
|
|
|
2017-05-10 22:28:12 +02:00
|
|
|
p = data;
|
|
|
|
while (*p && *p != '<')
|
2009-11-22 21:30:18 +01:00
|
|
|
{
|
2017-05-10 22:28:12 +02:00
|
|
|
if (!strncmp( p, "StartFragment:", 14 )) start = atoi( p + 14 );
|
|
|
|
else if (!strncmp( p, "EndFragment:", 12 )) end = atoi( p + 12 );
|
|
|
|
if (!(p = strpbrk( p, "\r\n" ))) break;
|
|
|
|
while (*p == '\r' || *p == '\n') p++;
|
2009-11-22 21:30:18 +01:00
|
|
|
}
|
2017-05-10 22:28:12 +02:00
|
|
|
if (start && start < end && end <= GlobalSize( handle ))
|
|
|
|
put_property( display, win, prop, target, 8, data + start, end - start );
|
|
|
|
else
|
|
|
|
ret = FALSE;
|
2009-11-22 21:30:18 +01:00
|
|
|
|
2016-09-20 04:50:21 +02:00
|
|
|
GlobalUnlock( handle );
|
2017-05-10 22:28:12 +02:00
|
|
|
return ret;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-21 05:10:32 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* get_clipboard_formats
|
|
|
|
*
|
|
|
|
* Return a list of all formats currently available on the Win32 clipboard.
|
|
|
|
* Helper for export_targets.
|
|
|
|
*/
|
|
|
|
static UINT *get_clipboard_formats( UINT *size )
|
|
|
|
{
|
|
|
|
UINT *ids;
|
|
|
|
|
|
|
|
*size = 256;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (!(ids = HeapAlloc( GetProcessHeap(), 0, *size * sizeof(*ids) ))) return NULL;
|
|
|
|
if (GetUpdatedClipboardFormats( ids, *size, size )) break;
|
|
|
|
HeapFree( GetProcessHeap(), 0, ids );
|
|
|
|
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) return NULL;
|
|
|
|
}
|
2016-09-22 06:13:25 +02:00
|
|
|
register_win32_formats( ids, *size );
|
2016-09-21 05:10:32 +02:00
|
|
|
return ids;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* is_format_available
|
|
|
|
*
|
|
|
|
* Check if a clipboard format is included in the list.
|
|
|
|
* Helper for export_targets.
|
|
|
|
*/
|
|
|
|
static BOOL is_format_available( UINT format, const UINT *ids, unsigned int count )
|
|
|
|
{
|
|
|
|
while (count--) if (*ids++ == format) return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* export_targets
|
|
|
|
*
|
|
|
|
* Service a TARGETS selection request event
|
|
|
|
*/
|
|
|
|
static BOOL export_targets( Display *display, Window win, Atom prop, Atom target, HANDLE handle )
|
|
|
|
{
|
|
|
|
struct clipboard_format *format;
|
|
|
|
UINT pos, count, *formats;
|
|
|
|
Atom *targets;
|
|
|
|
|
|
|
|
if (!(formats = get_clipboard_formats( &count ))) return FALSE;
|
|
|
|
|
|
|
|
/* the builtin formats contain duplicates, so allocate some extra space */
|
2018-07-07 23:39:08 +02:00
|
|
|
if (!(targets = HeapAlloc( GetProcessHeap(), 0,
|
|
|
|
(count + ARRAY_SIZE(builtin_formats)) * sizeof(*targets) )))
|
2016-09-21 05:10:32 +02:00
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, formats );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = 0;
|
|
|
|
LIST_FOR_EACH_ENTRY( format, &format_list, struct clipboard_format, entry )
|
|
|
|
{
|
|
|
|
if (!format->export) continue;
|
|
|
|
/* formats with id==0 are always exported */
|
|
|
|
if (format->id && !is_format_available( format->id, formats, count )) continue;
|
|
|
|
TRACE( "%d: %s -> %s\n", pos, debugstr_format( format->id ), debugstr_xatom( format->atom ));
|
|
|
|
targets[pos++] = format->atom;
|
|
|
|
}
|
|
|
|
|
|
|
|
put_property( display, win, prop, XA_ATOM, 32, targets, pos );
|
|
|
|
HeapFree( GetProcessHeap(), 0, targets );
|
|
|
|
HeapFree( GetProcessHeap(), 0, formats );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-20 04:50:21 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* export_selection
|
|
|
|
*
|
|
|
|
* Export selection data, depending on the target type.
|
|
|
|
*/
|
|
|
|
static BOOL export_selection( Display *display, Window win, Atom prop, Atom target )
|
|
|
|
{
|
2016-09-23 05:20:32 +02:00
|
|
|
struct clipboard_format *format;
|
2016-09-20 04:50:21 +02:00
|
|
|
HANDLE handle = 0;
|
2016-09-23 05:20:32 +02:00
|
|
|
BOOL open = FALSE, ret = FALSE;
|
2016-09-21 06:34:32 +02:00
|
|
|
|
2016-09-23 05:20:32 +02:00
|
|
|
LIST_FOR_EACH_ENTRY( format, &format_list, struct clipboard_format, entry )
|
2016-09-20 04:50:21 +02:00
|
|
|
{
|
2016-09-23 05:20:32 +02:00
|
|
|
if (format->atom != target) continue;
|
|
|
|
if (!format->export) continue;
|
|
|
|
if (!format->id)
|
|
|
|
{
|
|
|
|
TRACE( "win %lx prop %s target %s\n", win, debugstr_xatom( prop ), debugstr_xatom( target ));
|
|
|
|
ret = format->export( display, win, prop, target, 0 );
|
|
|
|
break;
|
|
|
|
}
|
2016-09-26 13:27:40 +02:00
|
|
|
if (!open && !(open = OpenClipboard( clipboard_hwnd )))
|
2016-09-23 05:20:32 +02:00
|
|
|
{
|
|
|
|
ERR( "failed to open clipboard for %s\n", debugstr_xatom( target ));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if ((handle = GetClipboardData( format->id )))
|
|
|
|
{
|
|
|
|
TRACE( "win %lx prop %s target %s exporting %s %p\n",
|
|
|
|
win, debugstr_xatom( prop ), debugstr_xatom( target ),
|
|
|
|
debugstr_format( format->id ), handle );
|
2016-09-21 06:34:32 +02:00
|
|
|
|
2016-09-23 05:20:32 +02:00
|
|
|
ret = format->export( display, win, prop, target, handle );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* keep looking for another Win32 format mapping to the same target */
|
|
|
|
}
|
|
|
|
if (open) CloseClipboard();
|
2016-09-21 06:34:32 +02:00
|
|
|
return ret;
|
2014-07-17 20:14:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-21 05:03:23 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* export_multiple
|
|
|
|
*
|
|
|
|
* Service a MULTIPLE selection request event
|
|
|
|
* prop 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 BOOL export_multiple( Display *display, Window win, Atom prop, Atom target, HANDLE handle )
|
|
|
|
{
|
|
|
|
Atom atype;
|
|
|
|
int aformat;
|
|
|
|
Atom *list;
|
|
|
|
unsigned long i, count, failed, remain;
|
|
|
|
|
|
|
|
/* Read the MULTIPLE property contents. This should contain a list of
|
|
|
|
* (target,property) atom pairs.
|
|
|
|
*/
|
|
|
|
if (XGetWindowProperty( display, win, prop, 0, 0x3FFF, False, AnyPropertyType, &atype, &aformat,
|
|
|
|
&count, &remain, (unsigned char**)&list ))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
TRACE( "type %s format %d count %ld remain %ld\n",
|
|
|
|
debugstr_xatom( atype ), aformat, count, remain );
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 */ )
|
|
|
|
{
|
|
|
|
for (i = failed = 0; i < count; i += 2)
|
|
|
|
{
|
|
|
|
if (list[i+1] == None) continue;
|
|
|
|
if (export_selection( display, win, list[i + 1], list[i] )) continue;
|
|
|
|
failed++;
|
|
|
|
list[i + 1] = None;
|
|
|
|
}
|
|
|
|
if (failed) put_property( display, win, prop, atype, 32, list, count );
|
|
|
|
}
|
|
|
|
XFree( list );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-28 04:38:47 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* export_timestamp
|
|
|
|
*
|
|
|
|
* Export the timestamp that was used to acquire the selection
|
|
|
|
*/
|
|
|
|
static BOOL export_timestamp( Display *display, Window win, Atom prop, Atom target, HANDLE handle )
|
|
|
|
{
|
|
|
|
Time time = CurrentTime; /* FIXME */
|
|
|
|
put_property( display, win, prop, XA_INTEGER, 32, &time, 1 );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-12-07 10:13:40 +01:00
|
|
|
/**************************************************************************
|
2008-10-31 04:18:00 +01:00
|
|
|
* X11DRV_CLIPBOARD_GetProperty
|
|
|
|
* Gets type, data and size.
|
1998-12-07 10:13:40 +01:00
|
|
|
*/
|
2008-10-31 04:18:00 +01:00
|
|
|
static BOOL X11DRV_CLIPBOARD_GetProperty(Display *display, Window w, Atom prop,
|
|
|
|
Atom *atype, unsigned char** data, unsigned long* datasize)
|
1998-12-07 10:13:40 +01:00
|
|
|
{
|
2005-11-01 19:05:40 +01:00
|
|
|
int aformat;
|
2008-03-26 12:14:41 +01:00
|
|
|
unsigned long pos = 0, nitems, remain, count;
|
|
|
|
unsigned char *val = NULL, *buffer;
|
2005-11-01 19:05:40 +01:00
|
|
|
|
2008-03-26 12:14:41 +01:00
|
|
|
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
|
|
|
|
2016-09-21 05:01:15 +02:00
|
|
|
TRACE( "got property %s type %s format %u len %lu from window %lx\n",
|
|
|
|
debugstr_xatom( prop ), debugstr_xatom( *atype ), aformat, *datasize, w );
|
|
|
|
|
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
|
|
|
/**************************************************************************
|
2017-01-10 16:21:46 +01:00
|
|
|
* read_property
|
|
|
|
*
|
2008-10-31 04:18:00 +01:00
|
|
|
* Reads the contents of the X selection property.
|
|
|
|
*/
|
2017-01-10 16:21:46 +01:00
|
|
|
static BOOL read_property( 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
|
|
|
/**************************************************************************
|
2016-09-26 13:27:40 +02:00
|
|
|
* acquire_selection
|
1998-12-07 10:13:40 +01:00
|
|
|
*
|
2016-09-26 13:27:40 +02:00
|
|
|
* Acquire the X11 selection when the Win32 clipboard has changed.
|
1998-12-07 10:13:40 +01:00
|
|
|
*/
|
2016-09-26 13:27:40 +02:00
|
|
|
static void acquire_selection( Display *display )
|
1998-12-07 10:13:40 +01:00
|
|
|
{
|
2016-09-26 13:27:40 +02:00
|
|
|
if (selection_window) XDestroyWindow( display, selection_window );
|
2005-01-04 21:34:46 +01:00
|
|
|
|
2016-09-26 13:27:40 +02:00
|
|
|
selection_window = XCreateWindow( display, root_window, 0, 0, 1, 1, 0, CopyFromParent,
|
|
|
|
InputOutput, CopyFromParent, 0, NULL );
|
|
|
|
if (!selection_window) return;
|
2005-01-04 21:34:46 +01:00
|
|
|
|
2016-09-26 13:27:40 +02:00
|
|
|
XSetSelectionOwner( display, x11drv_atom(CLIPBOARD), selection_window, CurrentTime );
|
|
|
|
if (use_primary_selection) XSetSelectionOwner( display, XA_PRIMARY, selection_window, CurrentTime );
|
|
|
|
TRACE( "win %lx\n", selection_window );
|
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
|
|
|
/**************************************************************************
|
2016-09-26 13:27:40 +02:00
|
|
|
* release_selection
|
|
|
|
*
|
|
|
|
* Release the X11 selection when some other X11 app has grabbed it.
|
|
|
|
*/
|
|
|
|
static void release_selection( Display *display, Time time )
|
2009-07-10 02:53:00 +02:00
|
|
|
{
|
2016-09-26 13:27:40 +02:00
|
|
|
assert( selection_window );
|
2009-07-10 02:53:00 +02:00
|
|
|
|
2016-09-26 13:27:40 +02:00
|
|
|
TRACE( "win %lx\n", selection_window );
|
2009-07-10 02:53:00 +02:00
|
|
|
|
2016-09-26 13:27:40 +02:00
|
|
|
/* release PRIMARY if we still own it */
|
|
|
|
if (use_primary_selection && XGetSelectionOwner( display, XA_PRIMARY ) == selection_window)
|
|
|
|
XSetSelectionOwner( display, XA_PRIMARY, None, time );
|
2009-07-10 02:53:00 +02:00
|
|
|
|
2016-09-26 13:27:40 +02:00
|
|
|
XDestroyWindow( display, selection_window );
|
|
|
|
selection_window = 0;
|
|
|
|
}
|
2009-07-10 02:53:00 +02:00
|
|
|
|
|
|
|
|
2016-09-26 13:27:40 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* request_selection_contents
|
|
|
|
*
|
|
|
|
* Retrieve the contents of the X11 selection when it's owned by an X11 app.
|
|
|
|
*/
|
2017-01-10 16:23:20 +01:00
|
|
|
static BOOL request_selection_contents( Display *display, BOOL changed )
|
2016-09-26 13:27:40 +02:00
|
|
|
{
|
|
|
|
struct clipboard_format *targets = find_x11_format( x11drv_atom(TARGETS) );
|
|
|
|
struct clipboard_format *string = find_x11_format( XA_STRING );
|
2017-01-10 16:23:20 +01:00
|
|
|
struct clipboard_format *format = NULL;
|
|
|
|
Window owner = 0;
|
|
|
|
unsigned char *data = NULL;
|
|
|
|
unsigned long size = 0;
|
|
|
|
Atom type = 0;
|
|
|
|
|
|
|
|
static Atom last_selection;
|
|
|
|
static Window last_owner;
|
|
|
|
static struct clipboard_format *last_format;
|
|
|
|
static Atom last_type;
|
|
|
|
static unsigned char *last_data;
|
|
|
|
static unsigned long last_size;
|
2009-07-10 02:53:00 +02:00
|
|
|
|
2016-09-26 13:27:40 +02:00
|
|
|
assert( targets );
|
|
|
|
assert( string );
|
2009-07-10 02:53:00 +02:00
|
|
|
|
2016-09-26 13:27:40 +02:00
|
|
|
current_selection = 0;
|
2017-01-10 16:23:20 +01:00
|
|
|
if (use_primary_selection)
|
2009-07-10 02:53:00 +02:00
|
|
|
{
|
2017-01-10 16:23:20 +01:00
|
|
|
if ((owner = XGetSelectionOwner( display, XA_PRIMARY )))
|
2016-09-26 13:27:40 +02:00
|
|
|
current_selection = XA_PRIMARY;
|
|
|
|
}
|
2017-01-10 16:23:20 +01:00
|
|
|
if (!current_selection)
|
2016-09-26 13:27:40 +02:00
|
|
|
{
|
2017-01-10 16:23:20 +01:00
|
|
|
if ((owner = XGetSelectionOwner( display, x11drv_atom(CLIPBOARD) )))
|
2016-09-26 13:27:40 +02:00
|
|
|
current_selection = x11drv_atom(CLIPBOARD);
|
2009-07-10 02:53:00 +02:00
|
|
|
}
|
|
|
|
|
2017-01-10 16:23:20 +01:00
|
|
|
if (current_selection)
|
|
|
|
{
|
|
|
|
if (convert_selection( display, import_window, current_selection, targets, &type, &data, &size ))
|
|
|
|
format = targets;
|
|
|
|
else if (convert_selection( display, import_window, current_selection, string, &type, &data, &size ))
|
|
|
|
format = string;
|
|
|
|
}
|
|
|
|
|
|
|
|
changed = (changed ||
|
|
|
|
rendered_formats ||
|
|
|
|
last_selection != current_selection ||
|
|
|
|
last_owner != owner ||
|
|
|
|
last_format != format ||
|
|
|
|
last_type != type ||
|
|
|
|
last_size != size ||
|
|
|
|
memcmp( last_data, data, size ));
|
|
|
|
|
|
|
|
if (!changed)
|
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, data );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2016-09-26 13:27:40 +02:00
|
|
|
|
|
|
|
if (!OpenClipboard( clipboard_hwnd )) return FALSE;
|
2017-01-10 16:23:20 +01:00
|
|
|
TRACE( "selection changed, importing\n" );
|
2016-09-26 13:27:40 +02:00
|
|
|
EmptyClipboard();
|
|
|
|
is_clipboard_owner = TRUE;
|
2017-01-10 16:23:20 +01:00
|
|
|
rendered_formats = 0;
|
|
|
|
|
|
|
|
if (format) format->import( type, data, size );
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, last_data );
|
|
|
|
last_selection = current_selection;
|
|
|
|
last_owner = owner;
|
|
|
|
last_format = format;
|
|
|
|
last_type = type;
|
|
|
|
last_data = data;
|
|
|
|
last_size = size;
|
2016-09-26 13:27:40 +02:00
|
|
|
last_clipboard_update = GetTickCount64();
|
|
|
|
CloseClipboard();
|
2017-05-24 15:17:57 +02:00
|
|
|
if (!use_xfixes)
|
|
|
|
SetTimer( clipboard_hwnd, 1, SELECTION_UPDATE_DELAY, NULL );
|
2016-09-26 13:27:40 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2009-12-01 14:16:20 +01:00
|
|
|
|
|
|
|
|
2016-09-26 13:27:40 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* update_clipboard
|
|
|
|
*
|
|
|
|
* Periodically update the clipboard while the selection is owned by an X11 app.
|
|
|
|
*/
|
|
|
|
BOOL update_clipboard( HWND hwnd )
|
|
|
|
{
|
2017-05-24 15:17:57 +02:00
|
|
|
if (use_xfixes) return TRUE;
|
2016-09-26 13:27:40 +02:00
|
|
|
if (hwnd != clipboard_hwnd) return TRUE;
|
|
|
|
if (!is_clipboard_owner) return TRUE;
|
|
|
|
if (GetTickCount64() - last_clipboard_update <= SELECTION_UPDATE_DELAY) return TRUE;
|
2017-01-10 16:23:20 +01:00
|
|
|
return request_selection_contents( thread_display(), FALSE );
|
2016-09-26 13:27:40 +02:00
|
|
|
}
|
|
|
|
|
2009-07-10 02:53:00 +02:00
|
|
|
|
2016-09-26 13:27:40 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* clipboard_wndproc
|
|
|
|
*
|
|
|
|
* Window procedure for the clipboard manager.
|
|
|
|
*/
|
|
|
|
static LRESULT CALLBACK clipboard_wndproc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
|
|
|
|
{
|
|
|
|
switch (msg)
|
2009-07-10 02:53:00 +02:00
|
|
|
{
|
2016-09-26 13:27:40 +02:00
|
|
|
case WM_NCCREATE:
|
|
|
|
return TRUE;
|
|
|
|
case WM_CLIPBOARDUPDATE:
|
|
|
|
if (is_clipboard_owner) break; /* ignore our own changes */
|
|
|
|
acquire_selection( thread_init_display() );
|
|
|
|
break;
|
|
|
|
case WM_RENDERFORMAT:
|
2017-01-10 16:23:20 +01:00
|
|
|
if (render_format( wp )) rendered_formats++;
|
2016-09-26 13:27:40 +02:00
|
|
|
break;
|
2017-01-10 16:23:37 +01:00
|
|
|
case WM_TIMER:
|
|
|
|
if (!is_clipboard_owner) break;
|
|
|
|
request_selection_contents( thread_display(), FALSE );
|
|
|
|
break;
|
2016-09-26 13:27:40 +02:00
|
|
|
case WM_DESTROYCLIPBOARD:
|
|
|
|
TRACE( "WM_DESTROYCLIPBOARD: lost ownership\n" );
|
|
|
|
is_clipboard_owner = FALSE;
|
2017-01-10 16:23:37 +01:00
|
|
|
KillTimer( hwnd, 1 );
|
2016-09-26 13:27:40 +02:00
|
|
|
break;
|
2009-07-10 02:53:00 +02:00
|
|
|
}
|
2016-09-26 13:27:40 +02:00
|
|
|
return DefWindowProcW( hwnd, msg, wp, lp );
|
2009-07-10 02:53:00 +02:00
|
|
|
}
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2016-09-26 13:27:40 +02:00
|
|
|
|
1998-12-07 10:13:40 +01:00
|
|
|
/**************************************************************************
|
2016-09-26 13:27:40 +02:00
|
|
|
* wait_clipboard_mutex
|
|
|
|
*
|
|
|
|
* Make sure that there's only one clipboard thread per window station.
|
1998-12-07 10:13:40 +01:00
|
|
|
*/
|
2016-09-26 13:27:40 +02:00
|
|
|
static BOOL wait_clipboard_mutex(void)
|
1998-12-07 10:13:40 +01:00
|
|
|
{
|
2016-09-26 13:27:40 +02:00
|
|
|
static const WCHAR prefix[] = {'_','_','w','i','n','e','_','c','l','i','p','b','o','a','r','d','_'};
|
|
|
|
WCHAR buffer[MAX_PATH + sizeof(prefix) / sizeof(WCHAR)];
|
|
|
|
HANDLE mutex;
|
|
|
|
|
|
|
|
memcpy( buffer, prefix, sizeof(prefix) );
|
|
|
|
if (!GetUserObjectInformationW( GetProcessWindowStation(), UOI_NAME,
|
|
|
|
buffer + sizeof(prefix) / sizeof(WCHAR),
|
|
|
|
sizeof(buffer) - sizeof(prefix), NULL ))
|
|
|
|
{
|
|
|
|
ERR( "failed to get winstation name\n" );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
mutex = CreateMutexW( NULL, TRUE, buffer );
|
|
|
|
if (GetLastError() == ERROR_ALREADY_EXISTS)
|
|
|
|
{
|
|
|
|
TRACE( "waiting for mutex %s\n", debugstr_w( buffer ));
|
|
|
|
WaitForSingleObject( mutex, INFINITE );
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
1999-09-03 17:17:57 +02:00
|
|
|
|
2006-06-05 17:55:14 +02:00
|
|
|
|
2017-05-24 15:17:57 +02:00
|
|
|
/**************************************************************************
|
2017-05-29 21:45:35 +02:00
|
|
|
* selection_notify_event
|
2017-05-24 15:17:57 +02:00
|
|
|
*
|
|
|
|
* Called when x11 clipboard content changes
|
|
|
|
*/
|
2017-05-29 21:45:35 +02:00
|
|
|
#ifdef SONAME_LIBXFIXES
|
2017-05-24 15:17:57 +02:00
|
|
|
static BOOL selection_notify_event( HWND hwnd, XEvent *event )
|
|
|
|
{
|
|
|
|
XFixesSelectionNotifyEvent *req = (XFixesSelectionNotifyEvent*)event;
|
|
|
|
|
|
|
|
if (!is_clipboard_owner) return FALSE;
|
|
|
|
if (req->owner == selection_window) return FALSE;
|
|
|
|
request_selection_contents( req->display, TRUE );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2017-05-29 21:45:35 +02:00
|
|
|
#endif
|
2017-05-24 15:17:57 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* xfixes_init
|
|
|
|
*
|
|
|
|
* Initialize xfixes to receive clipboard update notifications
|
|
|
|
*/
|
|
|
|
static void xfixes_init(void)
|
|
|
|
{
|
|
|
|
#ifdef SONAME_LIBXFIXES
|
|
|
|
typeof(XFixesSelectSelectionInput) *pXFixesSelectSelectionInput;
|
|
|
|
typeof(XFixesQueryExtension) *pXFixesQueryExtension;
|
|
|
|
typeof(XFixesQueryVersion) *pXFixesQueryVersion;
|
|
|
|
|
|
|
|
int event_base, error_base;
|
|
|
|
int major = 3, minor = 0;
|
|
|
|
void *handle;
|
|
|
|
|
|
|
|
handle = wine_dlopen(SONAME_LIBXFIXES, RTLD_NOW, NULL, 0);
|
|
|
|
if (!handle) return;
|
|
|
|
|
|
|
|
pXFixesQueryExtension = wine_dlsym(handle, "XFixesQueryExtension", NULL, 0);
|
|
|
|
if (!pXFixesQueryExtension) return;
|
|
|
|
pXFixesQueryVersion = wine_dlsym(handle, "XFixesQueryVersion", NULL, 0);
|
|
|
|
if (!pXFixesQueryVersion) return;
|
|
|
|
pXFixesSelectSelectionInput = wine_dlsym(handle, "XFixesSelectSelectionInput", NULL, 0);
|
|
|
|
if (!pXFixesSelectSelectionInput) return;
|
|
|
|
|
|
|
|
if (!pXFixesQueryExtension(clipboard_display, &event_base, &error_base))
|
|
|
|
return;
|
|
|
|
pXFixesQueryVersion(clipboard_display, &major, &minor);
|
|
|
|
use_xfixes = (major >= 1);
|
|
|
|
if (!use_xfixes) return;
|
|
|
|
|
|
|
|
pXFixesSelectSelectionInput(clipboard_display, import_window, x11drv_atom(CLIPBOARD),
|
|
|
|
XFixesSetSelectionOwnerNotifyMask |
|
|
|
|
XFixesSelectionWindowDestroyNotifyMask |
|
|
|
|
XFixesSelectionClientCloseNotifyMask);
|
|
|
|
if (use_primary_selection)
|
|
|
|
{
|
|
|
|
pXFixesSelectSelectionInput(clipboard_display, import_window, XA_PRIMARY,
|
|
|
|
XFixesSetSelectionOwnerNotifyMask |
|
|
|
|
XFixesSelectionWindowDestroyNotifyMask |
|
|
|
|
XFixesSelectionClientCloseNotifyMask);
|
|
|
|
}
|
|
|
|
X11DRV_register_event_handler(event_base + XFixesSelectionNotify,
|
|
|
|
selection_notify_event, "XFixesSelectionNotify");
|
|
|
|
TRACE("xfixes succesully initialized\n");
|
|
|
|
#else
|
|
|
|
WARN("xfixes not supported\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-26 13:27:40 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* clipboard_thread
|
|
|
|
*
|
|
|
|
* Thread running inside the desktop process to manage the clipboard
|
|
|
|
*/
|
|
|
|
static DWORD WINAPI clipboard_thread( void *arg )
|
|
|
|
{
|
|
|
|
static const WCHAR clipboard_classname[] = {'_','_','w','i','n','e','_','c','l','i','p','b','o','a','r','d','_','m','a','n','a','g','e','r',0};
|
|
|
|
XSetWindowAttributes attr;
|
|
|
|
WNDCLASSW class;
|
|
|
|
MSG msg;
|
|
|
|
|
|
|
|
if (!wait_clipboard_mutex()) return 0;
|
|
|
|
|
2016-09-26 14:06:14 +02:00
|
|
|
clipboard_display = thread_init_display();
|
2016-09-26 13:27:40 +02:00
|
|
|
attr.event_mask = PropertyChangeMask;
|
2016-09-26 14:06:14 +02:00
|
|
|
import_window = XCreateWindow( clipboard_display, root_window, 0, 0, 1, 1, 0, CopyFromParent,
|
2016-09-26 13:27:40 +02:00
|
|
|
InputOutput, CopyFromParent, CWEventMask, &attr );
|
|
|
|
if (!import_window)
|
1998-12-07 10:13:40 +01:00
|
|
|
{
|
2016-09-26 13:27:40 +02:00
|
|
|
ERR( "failed to create import window\n" );
|
|
|
|
return 0;
|
2006-06-05 17:55:14 +02:00
|
|
|
}
|
2005-03-07 20:31:46 +01:00
|
|
|
|
2016-09-26 13:27:40 +02:00
|
|
|
memset( &class, 0, sizeof(class) );
|
|
|
|
class.lpfnWndProc = clipboard_wndproc;
|
|
|
|
class.lpszClassName = clipboard_classname;
|
|
|
|
|
|
|
|
if (!RegisterClassW( &class ) && GetLastError() != ERROR_CLASS_ALREADY_EXISTS)
|
2009-07-10 02:53:00 +02:00
|
|
|
{
|
2016-09-26 13:27:40 +02:00
|
|
|
ERR( "could not register clipboard window class err %u\n", GetLastError() );
|
|
|
|
return 0;
|
2009-07-10 02:53:00 +02:00
|
|
|
}
|
2016-09-26 13:27:40 +02:00
|
|
|
if (!(clipboard_hwnd = CreateWindowW( clipboard_classname, NULL, 0, 0, 0, 0, 0,
|
|
|
|
HWND_MESSAGE, 0, 0, NULL )))
|
2009-07-10 02:53:00 +02:00
|
|
|
{
|
2016-09-26 13:27:40 +02:00
|
|
|
ERR( "failed to create clipboard window err %u\n", GetLastError() );
|
|
|
|
return 0;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
2016-09-26 13:27:40 +02:00
|
|
|
|
|
|
|
clipboard_thread_id = GetCurrentThreadId();
|
|
|
|
AddClipboardFormatListener( clipboard_hwnd );
|
|
|
|
register_builtin_formats();
|
2017-01-10 16:23:20 +01:00
|
|
|
request_selection_contents( clipboard_display, TRUE );
|
2016-09-26 13:27:40 +02:00
|
|
|
|
2017-05-24 15:17:57 +02:00
|
|
|
xfixes_init();
|
|
|
|
|
2016-09-26 13:27:40 +02:00
|
|
|
TRACE( "clipboard thread %04x running\n", GetCurrentThreadId() );
|
|
|
|
while (GetMessageW( &msg, 0, 0, 0 )) DispatchMessageW( &msg );
|
|
|
|
return 0;
|
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-23 07:07:59 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_UpdateClipboard
|
|
|
|
*/
|
|
|
|
void CDECL X11DRV_UpdateClipboard(void)
|
|
|
|
{
|
|
|
|
static ULONG last_update;
|
|
|
|
ULONG now;
|
2016-09-26 13:27:40 +02:00
|
|
|
DWORD_PTR ret;
|
2016-09-23 07:07:59 +02:00
|
|
|
|
2017-05-24 15:17:57 +02:00
|
|
|
if (use_xfixes) return;
|
2016-09-26 13:27:40 +02:00
|
|
|
if (GetCurrentThreadId() == clipboard_thread_id) return;
|
2016-09-23 07:07:59 +02:00
|
|
|
now = GetTickCount();
|
|
|
|
if ((int)(now - last_update) <= SELECTION_UPDATE_DELAY) return;
|
2016-09-26 13:27:40 +02:00
|
|
|
if (SendMessageTimeoutW( GetClipboardOwner(), WM_X11DRV_UPDATE_CLIPBOARD, 0, 0,
|
|
|
|
SMTO_ABORTIFHUNG, 5000, &ret ) && ret)
|
|
|
|
last_update = now;
|
2002-08-27 21:19:49 +02:00
|
|
|
}
|
2005-02-25 22:01:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_HandleSelectionRequest
|
|
|
|
*/
|
2016-09-21 05:03:23 +02:00
|
|
|
BOOL X11DRV_SelectionRequest( HWND hwnd, XEvent *xev )
|
2005-02-25 22:01:15 +01:00
|
|
|
{
|
2016-09-21 05:03:23 +02:00
|
|
|
XSelectionRequestEvent *event = &xev->xselectionrequest;
|
2005-02-25 22:01:15 +01:00
|
|
|
Display *display = event->display;
|
2016-09-21 05:03:23 +02:00
|
|
|
XEvent result;
|
2005-02-25 22:01:15 +01:00
|
|
|
Atom rprop = None;
|
|
|
|
|
2016-09-26 13:27:40 +02:00
|
|
|
TRACE( "got request on %lx for selection %s target %s win %lx prop %s\n",
|
|
|
|
event->owner, debugstr_xatom( event->selection ), debugstr_xatom( event->target ),
|
|
|
|
event->requestor, debugstr_xatom( event->property ));
|
|
|
|
|
|
|
|
if (event->owner != selection_window) goto done;
|
|
|
|
if ((event->selection != x11drv_atom(CLIPBOARD)) &&
|
|
|
|
(!use_primary_selection || event->selection != XA_PRIMARY)) goto done;
|
2005-02-25 22:01:15 +01:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
2016-09-21 05:04:07 +02:00
|
|
|
if (!export_selection( display, event->requestor, rprop, event->target ))
|
2016-09-20 04:50:21 +02:00
|
|
|
rprop = None; /* report failure to client */
|
2005-02-25 22:01:15 +01:00
|
|
|
|
2016-09-21 05:03:23 +02:00
|
|
|
done:
|
|
|
|
result.xselection.type = SelectionNotify;
|
|
|
|
result.xselection.display = display;
|
|
|
|
result.xselection.requestor = event->requestor;
|
|
|
|
result.xselection.selection = event->selection;
|
|
|
|
result.xselection.property = rprop;
|
|
|
|
result.xselection.target = event->target;
|
|
|
|
result.xselection.time = event->time;
|
|
|
|
TRACE( "sending SelectionNotify for %s to %lx\n", debugstr_xatom( rprop ), event->requestor );
|
|
|
|
XSendEvent( display, event->requestor, False, NoEventMask, &result );
|
2016-08-23 15:13:26 +02:00
|
|
|
return FALSE;
|
2005-02-25 22:01:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_SelectionClear
|
|
|
|
*/
|
2016-09-26 13:27:40 +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;
|
2016-09-26 13:27:40 +02:00
|
|
|
|
|
|
|
if (event->window != selection_window) return FALSE;
|
|
|
|
if (event->selection != x11drv_atom(CLIPBOARD)) return FALSE;
|
|
|
|
|
|
|
|
release_selection( event->display, event->time );
|
2017-01-10 16:23:20 +01:00
|
|
|
request_selection_contents( event->display, TRUE );
|
2016-08-23 15:13:26 +02:00
|
|
|
return FALSE;
|
2005-02-25 22:01:15 +01:00
|
|
|
}
|
2016-09-26 13:27:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_InitClipboard
|
|
|
|
*/
|
|
|
|
void X11DRV_InitClipboard(void)
|
|
|
|
{
|
|
|
|
DWORD id;
|
|
|
|
HANDLE handle = CreateThread( NULL, 0, clipboard_thread, NULL, 0, &id );
|
|
|
|
|
|
|
|
if (handle) CloseHandle( handle );
|
|
|
|
else ERR( "failed to create clipboard thread\n" );
|
|
|
|
}
|