2013-03-11 04:58:03 +01:00
|
|
|
/*
|
|
|
|
* Mac clipboard driver
|
|
|
|
*
|
|
|
|
* Copyright 1994 Martin Ayotte
|
|
|
|
* 1996 Alex Korobka
|
|
|
|
* 1999 Noel Borthwick
|
|
|
|
* 2003 Ulrich Czekalla for CodeWeavers
|
|
|
|
* Copyright 2011, 2012, 2013 Ken Thomases for CodeWeavers Inc.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "macdrv.h"
|
|
|
|
#include "winuser.h"
|
2013-03-13 22:52:50 +01:00
|
|
|
#include "shellapi.h"
|
|
|
|
#include "shlobj.h"
|
2013-03-11 04:58:03 +01:00
|
|
|
#include "wine/list.h"
|
2013-03-11 04:58:21 +01:00
|
|
|
#include "wine/server.h"
|
2013-03-11 04:58:03 +01:00
|
|
|
#include "wine/unicode.h"
|
|
|
|
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(clipboard);
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Types
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
typedef HANDLE (*DRVIMPORTFUNC)(CFDataRef data);
|
2013-03-11 04:58:21 +01:00
|
|
|
typedef CFDataRef (*DRVEXPORTFUNC)(HANDLE data);
|
2013-03-11 04:58:03 +01:00
|
|
|
|
2013-11-22 11:31:44 +01:00
|
|
|
typedef struct _WINE_CLIPFORMAT
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
UINT format_id;
|
|
|
|
CFStringRef type;
|
|
|
|
DRVIMPORTFUNC import_func;
|
|
|
|
DRVEXPORTFUNC export_func;
|
|
|
|
BOOL synthesized;
|
|
|
|
struct _WINE_CLIPFORMAT *natural_format;
|
2013-03-11 04:58:03 +01:00
|
|
|
} WINE_CLIPFORMAT;
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Constants
|
|
|
|
**************************************************************************/
|
|
|
|
|
2016-10-23 20:03:33 +02:00
|
|
|
#define CLIPBOARD_UPDATE_DELAY 2000 /* delay between checks of the Mac pasteboard */
|
|
|
|
|
2013-03-11 04:58:03 +01:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Forward Function Declarations
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
static HANDLE import_clipboard_data(CFDataRef data);
|
2013-03-13 22:52:36 +01:00
|
|
|
static HANDLE import_bmp_to_bitmap(CFDataRef data);
|
|
|
|
static HANDLE import_bmp_to_dib(CFDataRef data);
|
2013-11-22 11:31:31 +01:00
|
|
|
static HANDLE import_enhmetafile(CFDataRef data);
|
2017-01-13 20:36:20 +01:00
|
|
|
static HANDLE import_html(CFDataRef data);
|
2013-11-22 11:31:28 +01:00
|
|
|
static HANDLE import_metafilepict(CFDataRef data);
|
2013-03-13 22:52:50 +01:00
|
|
|
static HANDLE import_nsfilenames_to_hdrop(CFDataRef data);
|
2013-03-11 04:58:03 +01:00
|
|
|
static HANDLE import_utf8_to_text(CFDataRef data);
|
|
|
|
static HANDLE import_utf8_to_unicodetext(CFDataRef data);
|
2013-08-22 07:07:11 +02:00
|
|
|
static HANDLE import_utf16_to_unicodetext(CFDataRef data);
|
2013-03-11 04:58:03 +01:00
|
|
|
|
2013-03-11 04:58:21 +01:00
|
|
|
static CFDataRef export_clipboard_data(HANDLE data);
|
2013-03-13 22:52:36 +01:00
|
|
|
static CFDataRef export_bitmap_to_bmp(HANDLE data);
|
|
|
|
static CFDataRef export_dib_to_bmp(HANDLE data);
|
2013-11-22 11:31:31 +01:00
|
|
|
static CFDataRef export_enhmetafile(HANDLE data);
|
2013-03-13 22:52:50 +01:00
|
|
|
static CFDataRef export_hdrop_to_filenames(HANDLE data);
|
2017-01-13 20:36:21 +01:00
|
|
|
static CFDataRef export_html(HANDLE data);
|
2013-11-22 11:31:28 +01:00
|
|
|
static CFDataRef export_metafilepict(HANDLE data);
|
2013-03-11 04:58:21 +01:00
|
|
|
static CFDataRef export_text_to_utf8(HANDLE data);
|
|
|
|
static CFDataRef export_unicodetext_to_utf8(HANDLE data);
|
2013-08-22 07:07:11 +02:00
|
|
|
static CFDataRef export_unicodetext_to_utf16(HANDLE data);
|
2013-03-11 04:58:21 +01:00
|
|
|
|
2013-03-11 04:58:03 +01:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Static Variables
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/* Clipboard formats */
|
|
|
|
static struct list format_list = LIST_INIT(format_list);
|
|
|
|
|
|
|
|
/* There are two naming schemes involved and we want to have a mapping between
|
|
|
|
them. There are Win32 clipboard format names and there are Mac pasteboard
|
|
|
|
types.
|
|
|
|
|
|
|
|
The Win32 standard clipboard formats don't have names, but they are associated
|
|
|
|
with Mac pasteboard types through the following tables, which are used to
|
|
|
|
initialize the format_list. Where possible, the standard clipboard formats
|
|
|
|
are mapped to predefined pasteboard type UTIs. Otherwise, we create Wine-
|
|
|
|
specific types of the form "org.winehq.builtin.<format>", where <format> is
|
|
|
|
the name of the symbolic constant for the format minus "CF_" and lowercased.
|
|
|
|
E.g. CF_BITMAP -> org.winehq.builtin.bitmap.
|
|
|
|
|
|
|
|
Win32 clipboard formats which originate in a Windows program may be registered
|
|
|
|
with an arbitrary name. We construct a Mac pasteboard type from these by
|
|
|
|
prepending "org.winehq.registered." to the registered name.
|
|
|
|
|
|
|
|
Likewise, Mac pasteboard types which originate in other apps may have
|
2013-11-22 11:31:25 +01:00
|
|
|
arbitrary type strings. We ignore these.
|
2013-03-11 04:58:03 +01:00
|
|
|
|
|
|
|
Summary:
|
|
|
|
Win32 clipboard format names:
|
|
|
|
<none> standard clipboard format; maps via
|
|
|
|
format_list to either a predefined Mac UTI
|
|
|
|
or org.winehq.builtin.<format>.
|
|
|
|
<other> name registered within Win32 land; maps to
|
|
|
|
org.winehq.registered.<other>
|
|
|
|
Mac pasteboard type names:
|
|
|
|
org.winehq.builtin.<format ID> representation of Win32 standard clipboard
|
|
|
|
format for which there was no corresponding
|
|
|
|
predefined Mac UTI; maps via format_list
|
|
|
|
org.winehq.registered.<format name> representation of Win32 registered
|
|
|
|
clipboard format name; maps to <format name>
|
|
|
|
<other> Mac pasteboard type originating with system
|
|
|
|
or other apps; either maps via format_list
|
2013-11-22 11:31:25 +01:00
|
|
|
to a standard clipboard format or ignored
|
2013-03-11 04:58:03 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
UINT id;
|
|
|
|
CFStringRef type;
|
|
|
|
DRVIMPORTFUNC import;
|
2013-03-11 04:58:21 +01:00
|
|
|
DRVEXPORTFUNC export;
|
2013-03-11 04:58:03 +01:00
|
|
|
BOOL synthesized;
|
|
|
|
} builtin_format_ids[] =
|
|
|
|
{
|
2016-10-23 20:03:24 +02:00
|
|
|
{ CF_BITMAP, CFSTR("org.winehq.builtin.bitmap"), import_bmp_to_bitmap, export_bitmap_to_bmp, FALSE },
|
|
|
|
{ CF_DIBV5, CFSTR("org.winehq.builtin.dibv5"), import_clipboard_data, export_clipboard_data, FALSE },
|
2013-03-13 22:52:31 +01:00
|
|
|
{ CF_DIF, CFSTR("org.winehq.builtin.dif"), import_clipboard_data, export_clipboard_data, FALSE },
|
2016-10-23 20:03:23 +02:00
|
|
|
{ CF_ENHMETAFILE, CFSTR("org.winehq.builtin.enhmetafile"), import_enhmetafile, export_enhmetafile, FALSE },
|
2013-03-13 22:52:31 +01:00
|
|
|
{ CF_LOCALE, CFSTR("org.winehq.builtin.locale"), import_clipboard_data, export_clipboard_data, FALSE },
|
2016-10-23 20:03:23 +02:00
|
|
|
{ CF_METAFILEPICT, CFSTR("org.winehq.builtin.metafilepict"), import_metafilepict, export_metafilepict, FALSE },
|
2016-10-23 20:03:25 +02:00
|
|
|
{ CF_OEMTEXT, CFSTR("org.winehq.builtin.oemtext"), import_clipboard_data, export_clipboard_data, FALSE },
|
2013-03-13 22:52:31 +01:00
|
|
|
{ CF_PALETTE, CFSTR("org.winehq.builtin.palette"), import_clipboard_data, export_clipboard_data, FALSE },
|
|
|
|
{ CF_PENDATA, CFSTR("org.winehq.builtin.pendata"), import_clipboard_data, export_clipboard_data, FALSE },
|
|
|
|
{ CF_RIFF, CFSTR("org.winehq.builtin.riff"), import_clipboard_data, export_clipboard_data, FALSE },
|
|
|
|
{ CF_SYLK, CFSTR("org.winehq.builtin.sylk"), import_clipboard_data, export_clipboard_data, FALSE },
|
2016-10-23 20:03:25 +02:00
|
|
|
{ CF_TEXT, CFSTR("org.winehq.builtin.text"), import_clipboard_data, export_clipboard_data, FALSE },
|
2013-03-13 22:52:31 +01:00
|
|
|
{ CF_TIFF, CFSTR("public.tiff"), import_clipboard_data, export_clipboard_data, FALSE },
|
|
|
|
{ CF_WAVE, CFSTR("com.microsoft.waveform-audio"), import_clipboard_data, export_clipboard_data, FALSE },
|
|
|
|
|
2013-03-13 22:52:36 +01:00
|
|
|
{ CF_DIB, CFSTR("org.winehq.builtin.dib"), import_clipboard_data, export_clipboard_data, FALSE },
|
2016-10-23 20:03:23 +02:00
|
|
|
{ CF_DIB, CFSTR("com.microsoft.bmp"), import_bmp_to_dib, export_dib_to_bmp, TRUE },
|
2016-02-26 10:55:28 +01:00
|
|
|
|
2013-03-13 22:52:50 +01:00
|
|
|
{ CF_HDROP, CFSTR("org.winehq.builtin.hdrop"), import_clipboard_data, export_clipboard_data, FALSE },
|
|
|
|
{ CF_HDROP, CFSTR("NSFilenamesPboardType"), import_nsfilenames_to_hdrop, export_hdrop_to_filenames, TRUE },
|
2013-11-22 11:31:28 +01:00
|
|
|
|
2016-10-23 20:03:23 +02:00
|
|
|
{ CF_UNICODETEXT, CFSTR("org.winehq.builtin.unicodetext"), import_clipboard_data, export_clipboard_data, FALSE },
|
|
|
|
{ CF_UNICODETEXT, CFSTR("public.utf16-plain-text"), import_utf16_to_unicodetext, export_unicodetext_to_utf16,TRUE },
|
|
|
|
{ CF_UNICODETEXT, CFSTR("public.utf8-plain-text"), import_utf8_to_unicodetext, export_unicodetext_to_utf8, TRUE },
|
2013-03-11 04:58:03 +01:00
|
|
|
};
|
|
|
|
|
2013-03-13 22:52:31 +01:00
|
|
|
static const WCHAR wszRichTextFormat[] = {'R','i','c','h',' ','T','e','x','t',' ','F','o','r','m','a','t',0};
|
|
|
|
static const WCHAR wszGIF[] = {'G','I','F',0};
|
|
|
|
static const WCHAR wszJFIF[] = {'J','F','I','F',0};
|
|
|
|
static const WCHAR wszPNG[] = {'P','N','G',0};
|
|
|
|
static const WCHAR wszHTMLFormat[] = {'H','T','M','L',' ','F','o','r','m','a','t',0};
|
|
|
|
static const struct
|
|
|
|
{
|
2013-03-26 06:47:58 +01:00
|
|
|
LPCWSTR name;
|
|
|
|
CFStringRef type;
|
|
|
|
DRVIMPORTFUNC import;
|
|
|
|
DRVEXPORTFUNC export;
|
2017-01-13 20:36:20 +01:00
|
|
|
BOOL synthesized;
|
2013-03-13 22:52:31 +01:00
|
|
|
} builtin_format_names[] =
|
|
|
|
{
|
2013-03-26 06:47:58 +01:00
|
|
|
{ wszRichTextFormat, CFSTR("public.rtf"), import_clipboard_data, export_clipboard_data },
|
|
|
|
{ wszGIF, CFSTR("com.compuserve.gif"), import_clipboard_data, export_clipboard_data },
|
|
|
|
{ wszJFIF, CFSTR("public.jpeg"), import_clipboard_data, export_clipboard_data },
|
|
|
|
{ wszPNG, CFSTR("public.png"), import_clipboard_data, export_clipboard_data },
|
2017-01-13 20:36:20 +01:00
|
|
|
{ wszHTMLFormat, NULL, import_clipboard_data, export_clipboard_data },
|
2017-01-13 20:36:21 +01:00
|
|
|
{ wszHTMLFormat, CFSTR("public.html"), import_html, export_html, TRUE },
|
2013-03-26 06:48:02 +01:00
|
|
|
{ CFSTR_SHELLURLW, CFSTR("public.url"), import_utf8_to_text, export_text_to_utf8 },
|
2013-03-13 22:52:31 +01:00
|
|
|
};
|
|
|
|
|
2013-03-11 04:58:03 +01:00
|
|
|
/* The prefix prepended to a Win32 clipboard format name to make a Mac pasteboard type. */
|
|
|
|
static const CFStringRef registered_name_type_prefix = CFSTR("org.winehq.registered.");
|
|
|
|
|
2016-10-23 20:03:32 +02:00
|
|
|
static DWORD clipboard_thread_id;
|
|
|
|
static HWND clipboard_hwnd;
|
|
|
|
static BOOL is_clipboard_owner;
|
|
|
|
static macdrv_window clipboard_cocoa_window;
|
|
|
|
static ULONG64 last_clipboard_update;
|
2017-02-02 21:51:45 +01:00
|
|
|
static DWORD last_get_seqno;
|
2016-10-23 20:03:32 +02:00
|
|
|
static WINE_CLIPFORMAT **current_mac_formats;
|
|
|
|
static unsigned int nb_current_mac_formats;
|
2016-10-23 20:03:33 +02:00
|
|
|
static WCHAR clipboard_pipe_name[256];
|
2016-10-23 20:03:32 +02:00
|
|
|
|
2013-03-11 04:58:03 +01:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Internal Clipboard implementation methods
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* format_list functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* debugstr_format
|
|
|
|
*/
|
2013-03-13 22:53:32 +01:00
|
|
|
const char *debugstr_format(UINT id)
|
2013-03-11 04:58:03 +01:00
|
|
|
{
|
|
|
|
WCHAR buffer[256];
|
|
|
|
|
|
|
|
if (GetClipboardFormatNameW(id, buffer, 256))
|
|
|
|
return wine_dbg_sprintf("0x%04x %s", id, debugstr_w(buffer));
|
|
|
|
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
#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("0x%04x", id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* insert_clipboard_format
|
|
|
|
*/
|
|
|
|
static WINE_CLIPFORMAT *insert_clipboard_format(UINT id, CFStringRef type)
|
|
|
|
{
|
|
|
|
WINE_CLIPFORMAT *format;
|
|
|
|
|
|
|
|
format = HeapAlloc(GetProcessHeap(), 0, sizeof(*format));
|
|
|
|
|
|
|
|
if (format == NULL)
|
|
|
|
{
|
|
|
|
WARN("No more memory for a new format!\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
format->format_id = id;
|
|
|
|
format->import_func = import_clipboard_data;
|
2013-03-11 04:58:21 +01:00
|
|
|
format->export_func = export_clipboard_data;
|
2013-03-11 04:58:03 +01:00
|
|
|
format->synthesized = FALSE;
|
2013-11-22 11:31:44 +01:00
|
|
|
format->natural_format = NULL;
|
2013-03-11 04:58:03 +01:00
|
|
|
|
|
|
|
if (type)
|
|
|
|
format->type = CFStringCreateCopy(NULL, type);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WCHAR buffer[256];
|
|
|
|
|
2018-08-15 23:26:24 +02:00
|
|
|
if (!GetClipboardFormatNameW(format->format_id, buffer, ARRAY_SIZE(buffer)))
|
2013-04-08 22:43:13 +02:00
|
|
|
{
|
|
|
|
WARN("failed to get name for format %s; error 0x%08x\n", debugstr_format(format->format_id), GetLastError());
|
|
|
|
HeapFree(GetProcessHeap(), 0, format);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-11-22 11:31:25 +01:00
|
|
|
format->type = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@%S"),
|
2020-06-01 18:31:53 +02:00
|
|
|
registered_name_type_prefix, (const WCHAR*)buffer);
|
2013-03-11 04:58:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
list_add_tail(&format_list, &format->entry);
|
|
|
|
|
|
|
|
TRACE("Registering format %s type %s\n", debugstr_format(format->format_id),
|
|
|
|
debugstr_cf(format->type));
|
|
|
|
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* register_format
|
|
|
|
*
|
|
|
|
* Register a custom Mac clipboard format.
|
|
|
|
*/
|
|
|
|
static WINE_CLIPFORMAT* register_format(UINT id, CFStringRef type)
|
|
|
|
{
|
|
|
|
WINE_CLIPFORMAT *format;
|
|
|
|
|
|
|
|
/* walk format chain to see if it's already registered */
|
|
|
|
LIST_FOR_EACH_ENTRY(format, &format_list, WINE_CLIPFORMAT, entry)
|
|
|
|
if (format->format_id == id) return format;
|
|
|
|
|
|
|
|
return insert_clipboard_format(id, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-23 20:03:32 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* natural_format_for_format
|
|
|
|
*
|
|
|
|
* Find the "natural" format for this format_id (the one which isn't
|
|
|
|
* synthesized from another type).
|
|
|
|
*/
|
|
|
|
static WINE_CLIPFORMAT* natural_format_for_format(UINT format_id)
|
|
|
|
{
|
|
|
|
WINE_CLIPFORMAT *format;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(format, &format_list, WINE_CLIPFORMAT, entry)
|
|
|
|
if (format->format_id == format_id && !format->synthesized) break;
|
|
|
|
|
|
|
|
if (&format->entry == &format_list)
|
|
|
|
format = NULL;
|
|
|
|
|
|
|
|
TRACE("%s -> %p/%s\n", debugstr_format(format_id), format, debugstr_cf(format ? format->type : NULL));
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* register_builtin_formats
|
|
|
|
*/
|
|
|
|
static void register_builtin_formats(void)
|
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
WINE_CLIPFORMAT *format;
|
|
|
|
|
|
|
|
/* Register built-in formats */
|
2018-08-15 23:26:24 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(builtin_format_ids); i++)
|
2016-10-23 20:03:32 +02:00
|
|
|
{
|
|
|
|
if (!(format = HeapAlloc(GetProcessHeap(), 0, sizeof(*format)))) break;
|
|
|
|
format->format_id = builtin_format_ids[i].id;
|
|
|
|
format->type = CFRetain(builtin_format_ids[i].type);
|
|
|
|
format->import_func = builtin_format_ids[i].import;
|
|
|
|
format->export_func = builtin_format_ids[i].export;
|
|
|
|
format->synthesized = builtin_format_ids[i].synthesized;
|
|
|
|
format->natural_format = NULL;
|
|
|
|
list_add_tail(&format_list, &format->entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Register known mappings between Windows formats and Mac types */
|
2018-08-15 23:26:24 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(builtin_format_names); i++)
|
2016-10-23 20:03:32 +02:00
|
|
|
{
|
|
|
|
if (!(format = HeapAlloc(GetProcessHeap(), 0, sizeof(*format)))) break;
|
|
|
|
format->format_id = RegisterClipboardFormatW(builtin_format_names[i].name);
|
|
|
|
format->import_func = builtin_format_names[i].import;
|
|
|
|
format->export_func = builtin_format_names[i].export;
|
2017-01-13 20:36:20 +01:00
|
|
|
format->synthesized = builtin_format_names[i].synthesized;
|
2016-10-23 20:03:32 +02:00
|
|
|
format->natural_format = NULL;
|
2017-01-13 20:36:20 +01:00
|
|
|
|
|
|
|
if (builtin_format_names[i].type)
|
|
|
|
format->type = CFRetain(builtin_format_names[i].type);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
format->type = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@%S"),
|
|
|
|
registered_name_type_prefix, builtin_format_names[i].name);
|
|
|
|
}
|
|
|
|
|
2016-10-23 20:03:32 +02:00
|
|
|
list_add_tail(&format_list, &format->entry);
|
|
|
|
}
|
2017-01-13 20:36:20 +01:00
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(format, &format_list, WINE_CLIPFORMAT, entry)
|
|
|
|
{
|
|
|
|
if (format->synthesized)
|
|
|
|
format->natural_format = natural_format_for_format(format->format_id);
|
|
|
|
}
|
2016-10-23 20:03:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-11 04:58:03 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* format_for_type
|
|
|
|
*/
|
2016-10-23 20:03:29 +02:00
|
|
|
static WINE_CLIPFORMAT* format_for_type(CFStringRef type)
|
2013-03-11 04:58:03 +01:00
|
|
|
{
|
2016-10-23 20:03:29 +02:00
|
|
|
WINE_CLIPFORMAT *format;
|
2013-03-11 04:58:03 +01:00
|
|
|
|
2016-10-23 20:03:29 +02:00
|
|
|
TRACE("type %s\n", debugstr_cf(type));
|
2013-03-11 04:58:03 +01:00
|
|
|
|
2016-10-23 20:03:32 +02:00
|
|
|
if (list_empty(&format_list)) register_builtin_formats();
|
|
|
|
|
2016-10-23 20:03:29 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(format, &format_list, WINE_CLIPFORMAT, entry)
|
2013-03-11 04:58:03 +01:00
|
|
|
{
|
|
|
|
if (CFEqual(format->type, type))
|
2013-11-06 13:59:00 +01:00
|
|
|
goto done;
|
2013-03-11 04:58:03 +01:00
|
|
|
}
|
|
|
|
|
2013-11-06 13:58:42 +01:00
|
|
|
format = NULL;
|
2016-10-23 20:03:29 +02:00
|
|
|
if (CFStringHasPrefix(type, CFSTR("org.winehq.builtin.")))
|
2013-03-11 04:58:03 +01:00
|
|
|
{
|
2016-10-23 20:03:29 +02:00
|
|
|
ERR("Shouldn't happen. Built-in type %s should have matched something in format list.\n",
|
|
|
|
debugstr_cf(type));
|
|
|
|
}
|
|
|
|
else if (CFStringHasPrefix(type, registered_name_type_prefix))
|
|
|
|
{
|
|
|
|
LPWSTR name;
|
|
|
|
int len = CFStringGetLength(type) - CFStringGetLength(registered_name_type_prefix);
|
2013-11-22 11:31:25 +01:00
|
|
|
|
2016-10-23 20:03:29 +02:00
|
|
|
name = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
|
|
|
|
CFStringGetCharacters(type, CFRangeMake(CFStringGetLength(registered_name_type_prefix), len),
|
|
|
|
(UniChar*)name);
|
|
|
|
name[len] = 0;
|
2013-03-11 04:58:03 +01:00
|
|
|
|
2016-10-23 20:03:29 +02:00
|
|
|
format = register_format(RegisterClipboardFormatW(name), type);
|
|
|
|
if (!format)
|
|
|
|
ERR("Failed to register format for type %s name %s\n", debugstr_cf(type), debugstr_w(name));
|
2013-03-11 04:58:03 +01:00
|
|
|
|
2016-10-23 20:03:29 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, name);
|
2013-03-11 04:58:03 +01:00
|
|
|
}
|
|
|
|
|
2013-11-06 13:59:00 +01:00
|
|
|
done:
|
2013-03-11 04:58:03 +01:00
|
|
|
TRACE(" -> %p/%s\n", format, debugstr_format(format ? format->format_id : 0));
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-13 22:52:36 +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 */
|
|
|
|
{
|
2016-10-26 17:58:35 +02:00
|
|
|
colors = min(info->bmiHeader.biClrUsed, 256);
|
2013-03-13 22:52:36 +01:00
|
|
|
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.
|
|
|
|
*/
|
2016-10-23 20:03:27 +02:00
|
|
|
static HGLOBAL create_dib_from_bitmap(HBITMAP bitmap)
|
2013-03-13 22:52:36 +01:00
|
|
|
{
|
2016-10-23 20:03:27 +02:00
|
|
|
HANDLE ret = 0;
|
|
|
|
BITMAPINFOHEADER header;
|
|
|
|
HDC hdc = GetDC(0);
|
|
|
|
DWORD header_size;
|
|
|
|
BITMAPINFO *bmi;
|
2013-03-13 22:52:36 +01:00
|
|
|
|
2016-10-23 20:03:27 +02:00
|
|
|
memset(&header, 0, sizeof(header));
|
|
|
|
header.biSize = sizeof(header);
|
|
|
|
if (!GetDIBits(hdc, bitmap, 0, 0, NULL, (BITMAPINFO *)&header, DIB_RGB_COLORS)) goto done;
|
2013-03-13 22:52:36 +01:00
|
|
|
|
2016-10-23 20:03:27 +02:00
|
|
|
header_size = bitmap_info_size((BITMAPINFO *)&header, DIB_RGB_COLORS);
|
|
|
|
if (!(ret = GlobalAlloc(GMEM_FIXED, header_size + header.biSizeImage))) goto done;
|
|
|
|
bmi = (BITMAPINFO *)ret;
|
|
|
|
memset(bmi, 0, header_size);
|
|
|
|
memcpy(bmi, &header, header.biSize);
|
|
|
|
GetDIBits(hdc, bitmap, 0, abs(header.biHeight), (char *)bmi + header_size, bmi, DIB_RGB_COLORS);
|
|
|
|
|
|
|
|
done:
|
|
|
|
ReleaseDC(0, hdc);
|
|
|
|
return ret;
|
2013-03-13 22:52:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-03 21:03:24 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* create_bitmap_from_dib
|
|
|
|
*
|
|
|
|
* Given a packed DIB, creates a bitmap object from it.
|
|
|
|
*/
|
|
|
|
static HANDLE create_bitmap_from_dib(HANDLE dib)
|
|
|
|
{
|
|
|
|
HANDLE ret = 0;
|
|
|
|
BITMAPINFO *bmi;
|
|
|
|
|
|
|
|
if (dib && (bmi = GlobalLock(dib)))
|
|
|
|
{
|
|
|
|
HDC hdc;
|
|
|
|
unsigned int offset;
|
|
|
|
|
|
|
|
hdc = GetDC(NULL);
|
|
|
|
|
|
|
|
offset = bitmap_info_size(bmi, DIB_RGB_COLORS);
|
|
|
|
|
|
|
|
ret = CreateDIBitmap(hdc, &bmi->bmiHeader, CBM_INIT, (LPBYTE)bmi + offset,
|
|
|
|
bmi, DIB_RGB_COLORS);
|
|
|
|
|
|
|
|
GlobalUnlock(dib);
|
|
|
|
ReleaseDC(NULL, hdc);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-13 20:36:21 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* get_html_description_field
|
|
|
|
*
|
|
|
|
* Find the value of a field in an HTML Format description.
|
|
|
|
*/
|
|
|
|
static const char* get_html_description_field(const char* data, const char* keyword)
|
|
|
|
{
|
|
|
|
const char* pos = data;
|
|
|
|
|
|
|
|
while (pos && *pos && *pos != '<')
|
|
|
|
{
|
|
|
|
if (memcmp(pos, keyword, strlen(keyword)) == 0)
|
|
|
|
return pos + strlen(keyword);
|
|
|
|
|
|
|
|
pos = strchr(pos, '\n');
|
|
|
|
if (pos) pos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-11 04:58:03 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* import_clipboard_data
|
|
|
|
*
|
|
|
|
* Generic import clipboard data routine.
|
|
|
|
*/
|
|
|
|
static HANDLE import_clipboard_data(CFDataRef data)
|
|
|
|
{
|
|
|
|
HANDLE data_handle = NULL;
|
|
|
|
|
|
|
|
size_t len = CFDataGetLength(data);
|
|
|
|
if (len)
|
|
|
|
{
|
|
|
|
LPVOID p;
|
|
|
|
|
|
|
|
/* Turn on the DDESHARE flag to enable shared 32 bit memory */
|
2016-10-23 20:03:20 +02:00
|
|
|
data_handle = GlobalAlloc(GMEM_FIXED, len);
|
2013-03-11 04:58:03 +01:00
|
|
|
if (!data_handle)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if ((p = GlobalLock(data_handle)))
|
|
|
|
{
|
|
|
|
memcpy(p, CFDataGetBytePtr(data), len);
|
|
|
|
GlobalUnlock(data_handle);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GlobalFree(data_handle);
|
|
|
|
data_handle = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return data_handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-26 10:55:28 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* import_bmp_to_bitmap
|
|
|
|
*
|
|
|
|
* Import BMP data, converting to CF_BITMAP format.
|
|
|
|
*/
|
|
|
|
static HANDLE import_bmp_to_bitmap(CFDataRef data)
|
|
|
|
{
|
|
|
|
HANDLE ret;
|
|
|
|
HANDLE dib = import_bmp_to_dib(data);
|
|
|
|
|
|
|
|
ret = create_bitmap_from_dib(dib);
|
|
|
|
|
2013-03-13 22:52:36 +01:00
|
|
|
GlobalFree(dib);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* import_bmp_to_dib
|
|
|
|
*
|
2016-02-26 10:55:28 +01:00
|
|
|
* Import BMP data, converting to CF_DIB or CF_DIBV5 format. This just
|
|
|
|
* entails stripping the BMP file format header.
|
2013-03-13 22:52:36 +01:00
|
|
|
*/
|
|
|
|
static HANDLE import_bmp_to_dib(CFDataRef data)
|
|
|
|
{
|
|
|
|
HANDLE ret = 0;
|
|
|
|
BITMAPFILEHEADER *bfh = (BITMAPFILEHEADER*)CFDataGetBytePtr(data);
|
|
|
|
CFIndex len = CFDataGetLength(data);
|
|
|
|
|
|
|
|
if (len >= sizeof(*bfh) + sizeof(BITMAPCOREHEADER) &&
|
|
|
|
bfh->bfType == 0x4d42 /* "BM" */)
|
|
|
|
{
|
|
|
|
BITMAPINFO *bmi = (BITMAPINFO*)(bfh + 1);
|
|
|
|
BYTE* p;
|
|
|
|
|
|
|
|
len -= sizeof(*bfh);
|
2016-10-23 20:03:20 +02:00
|
|
|
ret = GlobalAlloc(GMEM_FIXED, len);
|
2013-03-13 22:52:36 +01:00
|
|
|
if (!ret || !(p = GlobalLock(ret)))
|
|
|
|
{
|
|
|
|
GlobalFree(ret);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(p, bmi, len);
|
|
|
|
GlobalUnlock(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-22 11:31:31 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* import_enhmetafile
|
|
|
|
*
|
|
|
|
* Import enhanced metafile data, converting it to CF_ENHMETAFILE.
|
|
|
|
*/
|
|
|
|
static HANDLE import_enhmetafile(CFDataRef data)
|
|
|
|
{
|
|
|
|
HANDLE ret = 0;
|
|
|
|
CFIndex len = CFDataGetLength(data);
|
|
|
|
|
|
|
|
TRACE("data %s\n", debugstr_cf(data));
|
|
|
|
|
|
|
|
if (len)
|
|
|
|
ret = SetEnhMetaFileBits(len, (const BYTE*)CFDataGetBytePtr(data));
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-13 20:36:20 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* import_html
|
|
|
|
*
|
|
|
|
* Import HTML data.
|
|
|
|
*/
|
|
|
|
static HANDLE import_html(CFDataRef data)
|
|
|
|
{
|
|
|
|
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-->";
|
|
|
|
HANDLE ret;
|
|
|
|
SIZE_T len, total;
|
|
|
|
size_t size = CFDataGetLength(data);
|
|
|
|
|
|
|
|
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 */);
|
|
|
|
CFDataGetBytes(data, CFRangeMake(0, size), (UInt8*)p);
|
|
|
|
strcpy(p + size, trailer);
|
|
|
|
TRACE("returning %s\n", debugstr_a(ret));
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-22 11:31:28 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* import_metafilepict
|
|
|
|
*
|
|
|
|
* Import metafile picture data, converting it to CF_METAFILEPICT.
|
|
|
|
*/
|
|
|
|
static HANDLE import_metafilepict(CFDataRef data)
|
|
|
|
{
|
|
|
|
HANDLE ret = 0;
|
|
|
|
CFIndex len = CFDataGetLength(data);
|
|
|
|
METAFILEPICT *mfp;
|
|
|
|
|
|
|
|
TRACE("data %s\n", debugstr_cf(data));
|
|
|
|
|
2016-10-23 20:03:20 +02:00
|
|
|
if (len >= sizeof(*mfp) && (ret = GlobalAlloc(GMEM_FIXED, sizeof(*mfp))))
|
2013-11-22 11:31:28 +01:00
|
|
|
{
|
|
|
|
const BYTE *bytes = (const BYTE*)CFDataGetBytePtr(data);
|
|
|
|
|
|
|
|
mfp = GlobalLock(ret);
|
|
|
|
memcpy(mfp, bytes, sizeof(*mfp));
|
|
|
|
mfp->hMF = SetMetaFileBitsEx(len - sizeof(*mfp), bytes + sizeof(*mfp));
|
|
|
|
GlobalUnlock(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-13 22:52:50 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* import_nsfilenames_to_hdrop
|
|
|
|
*
|
|
|
|
* Import NSFilenamesPboardType data, converting the property-list-
|
|
|
|
* serialized array of path strings to CF_HDROP.
|
|
|
|
*/
|
|
|
|
static HANDLE import_nsfilenames_to_hdrop(CFDataRef data)
|
|
|
|
{
|
|
|
|
HDROP hdrop = NULL;
|
|
|
|
CFArrayRef names;
|
|
|
|
CFIndex count, i;
|
|
|
|
size_t len;
|
|
|
|
char *buffer = NULL;
|
|
|
|
WCHAR **paths = NULL;
|
|
|
|
DROPFILES* dropfiles;
|
|
|
|
UniChar* p;
|
|
|
|
|
|
|
|
TRACE("data %s\n", debugstr_cf(data));
|
|
|
|
|
|
|
|
names = (CFArrayRef)CFPropertyListCreateWithData(NULL, data, kCFPropertyListImmutable,
|
|
|
|
NULL, NULL);
|
|
|
|
if (!names || CFGetTypeID(names) != CFArrayGetTypeID())
|
|
|
|
{
|
|
|
|
WARN("failed to interpret data as a CFArray\n");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
count = CFArrayGetCount(names);
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
CFIndex this_len;
|
|
|
|
CFStringRef name = (CFStringRef)CFArrayGetValueAtIndex(names, i);
|
|
|
|
TRACE(" %s\n", debugstr_cf(name));
|
|
|
|
if (CFGetTypeID(name) != CFStringGetTypeID())
|
|
|
|
{
|
|
|
|
WARN("non-string in array\n");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
this_len = CFStringGetMaximumSizeOfFileSystemRepresentation(name);
|
|
|
|
if (this_len > len)
|
|
|
|
len = this_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer = HeapAlloc(GetProcessHeap(), 0, len);
|
|
|
|
if (!buffer)
|
|
|
|
{
|
|
|
|
WARN("failed to allocate buffer for file-system representations\n");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
paths = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, count * sizeof(paths[0]));
|
|
|
|
if (!paths)
|
|
|
|
{
|
|
|
|
WARN("failed to allocate array of DOS paths\n");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
CFStringRef name = (CFStringRef)CFArrayGetValueAtIndex(names, i);
|
|
|
|
if (!CFStringGetFileSystemRepresentation(name, buffer, len))
|
|
|
|
{
|
|
|
|
WARN("failed to get file-system representation for %s\n", debugstr_cf(name));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
paths[i] = wine_get_dos_file_name(buffer);
|
|
|
|
if (!paths[i])
|
|
|
|
{
|
|
|
|
WARN("failed to get DOS path for %s\n", debugstr_a(buffer));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
len = 1; /* for the terminating null */
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
len += strlenW(paths[i]) + 1;
|
|
|
|
|
2016-10-23 20:03:20 +02:00
|
|
|
hdrop = GlobalAlloc(GMEM_FIXED, sizeof(*dropfiles) + len * sizeof(WCHAR));
|
2013-03-13 22:52:50 +01:00
|
|
|
if (!hdrop || !(dropfiles = GlobalLock(hdrop)))
|
|
|
|
{
|
|
|
|
WARN("failed to allocate HDROP\n");
|
|
|
|
GlobalFree(hdrop);
|
|
|
|
hdrop = NULL;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
dropfiles->pFiles = sizeof(*dropfiles);
|
|
|
|
dropfiles->pt.x = 0;
|
|
|
|
dropfiles->pt.y = 0;
|
|
|
|
dropfiles->fNC = FALSE;
|
|
|
|
dropfiles->fWide = TRUE;
|
|
|
|
|
|
|
|
p = (WCHAR*)(dropfiles + 1);
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
strcpyW(p, paths[i]);
|
|
|
|
p += strlenW(p) + 1;
|
|
|
|
}
|
|
|
|
*p = 0;
|
|
|
|
|
|
|
|
GlobalUnlock(hdrop);
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (paths)
|
|
|
|
{
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
HeapFree(GetProcessHeap(), 0, paths[i]);
|
|
|
|
HeapFree(GetProcessHeap(), 0, paths);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, buffer);
|
|
|
|
if (names) CFRelease(names);
|
|
|
|
return hdrop;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-11 04:58:03 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* import_utf8_to_text
|
|
|
|
*
|
|
|
|
* Import a UTF-8 string, converting the string to CF_TEXT.
|
|
|
|
*/
|
|
|
|
static HANDLE import_utf8_to_text(CFDataRef data)
|
|
|
|
{
|
2016-10-23 20:03:25 +02:00
|
|
|
HANDLE ret = NULL;
|
2013-03-11 04:58:03 +01:00
|
|
|
HANDLE unicode_handle = import_utf8_to_unicodetext(data);
|
2016-10-23 20:03:25 +02:00
|
|
|
LPWSTR unicode_string = GlobalLock(unicode_handle);
|
|
|
|
|
|
|
|
if (unicode_string)
|
|
|
|
{
|
|
|
|
int unicode_len;
|
|
|
|
HANDLE handle;
|
|
|
|
char *p;
|
|
|
|
INT len;
|
|
|
|
|
|
|
|
unicode_len = GlobalSize(unicode_handle) / sizeof(WCHAR);
|
|
|
|
|
|
|
|
len = WideCharToMultiByte(CP_ACP, 0, unicode_string, unicode_len, NULL, 0, NULL, NULL);
|
|
|
|
if (!unicode_len || unicode_string[unicode_len - 1]) len += 1;
|
|
|
|
handle = GlobalAlloc(GMEM_FIXED, len);
|
|
|
|
|
|
|
|
if (handle && (p = GlobalLock(handle)))
|
|
|
|
{
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, unicode_string, unicode_len, p, len, NULL, NULL);
|
|
|
|
p[len - 1] = 0;
|
|
|
|
GlobalUnlock(handle);
|
|
|
|
ret = handle;
|
|
|
|
}
|
|
|
|
GlobalUnlock(unicode_handle);
|
|
|
|
}
|
2013-03-11 04:58:03 +01:00
|
|
|
|
|
|
|
GlobalFree(unicode_handle);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* import_utf8_to_unicodetext
|
|
|
|
*
|
|
|
|
* Import a UTF-8 string, converting the string to CF_UNICODETEXT.
|
|
|
|
*/
|
|
|
|
static HANDLE import_utf8_to_unicodetext(CFDataRef data)
|
|
|
|
{
|
|
|
|
const BYTE *src;
|
2013-10-21 06:55:00 +02:00
|
|
|
unsigned long src_len;
|
2013-03-11 04:58:03 +01:00
|
|
|
unsigned long new_lines = 0;
|
|
|
|
LPSTR dst;
|
|
|
|
unsigned long i, j;
|
|
|
|
HANDLE unicode_handle = NULL;
|
|
|
|
|
|
|
|
src = CFDataGetBytePtr(data);
|
2013-10-21 06:55:00 +02:00
|
|
|
src_len = CFDataGetLength(data);
|
|
|
|
for (i = 0; i < src_len; i++)
|
2013-03-11 04:58:03 +01:00
|
|
|
{
|
|
|
|
if (src[i] == '\n')
|
|
|
|
new_lines++;
|
|
|
|
}
|
|
|
|
|
2013-10-21 06:55:00 +02:00
|
|
|
if ((dst = HeapAlloc(GetProcessHeap(), 0, src_len + new_lines + 1)))
|
2013-03-11 04:58:03 +01:00
|
|
|
{
|
|
|
|
UINT count;
|
|
|
|
|
2013-10-21 06:55:00 +02:00
|
|
|
for (i = 0, j = 0; i < src_len; i++)
|
2013-03-11 04:58:03 +01:00
|
|
|
{
|
|
|
|
if (src[i] == '\n')
|
|
|
|
dst[j++] = '\r';
|
|
|
|
|
|
|
|
dst[j++] = src[i];
|
|
|
|
}
|
|
|
|
dst[j] = 0;
|
|
|
|
|
|
|
|
count = MultiByteToWideChar(CP_UTF8, 0, dst, -1, NULL, 0);
|
2016-10-23 20:03:20 +02:00
|
|
|
unicode_handle = GlobalAlloc(GMEM_FIXED, count * sizeof(WCHAR));
|
2013-03-11 04:58:03 +01:00
|
|
|
|
|
|
|
if (unicode_handle)
|
|
|
|
{
|
|
|
|
WCHAR *textW = GlobalLock(unicode_handle);
|
|
|
|
MultiByteToWideChar(CP_UTF8, 0, dst, -1, textW, count);
|
|
|
|
GlobalUnlock(unicode_handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
return unicode_handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-22 07:07:11 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* import_utf16_to_unicodetext
|
|
|
|
*
|
|
|
|
* Import a UTF-8 string, converting the string to CF_UNICODETEXT.
|
|
|
|
*/
|
|
|
|
static HANDLE import_utf16_to_unicodetext(CFDataRef data)
|
|
|
|
{
|
|
|
|
const WCHAR *src;
|
2013-10-21 06:55:00 +02:00
|
|
|
unsigned long src_len;
|
2013-08-22 07:07:11 +02:00
|
|
|
unsigned long new_lines = 0;
|
|
|
|
LPWSTR dst;
|
|
|
|
unsigned long i, j;
|
|
|
|
HANDLE unicode_handle;
|
|
|
|
|
|
|
|
src = (const WCHAR *)CFDataGetBytePtr(data);
|
2013-10-21 06:55:00 +02:00
|
|
|
src_len = CFDataGetLength(data) / sizeof(WCHAR);
|
|
|
|
for (i = 0; i < src_len; i++)
|
2013-08-22 07:07:11 +02:00
|
|
|
{
|
|
|
|
if (src[i] == '\n')
|
|
|
|
new_lines++;
|
2016-10-23 20:03:21 +02:00
|
|
|
else if (src[i] == '\r' && (i + 1 >= src_len || src[i + 1] != '\n'))
|
|
|
|
new_lines++;
|
2013-08-22 07:07:11 +02:00
|
|
|
}
|
|
|
|
|
2016-10-23 20:03:20 +02:00
|
|
|
if ((unicode_handle = GlobalAlloc(GMEM_FIXED, (src_len + new_lines + 1) * sizeof(WCHAR))))
|
2013-08-22 07:07:11 +02:00
|
|
|
{
|
|
|
|
dst = GlobalLock(unicode_handle);
|
|
|
|
|
2013-10-21 06:55:00 +02:00
|
|
|
for (i = 0, j = 0; i < src_len; i++)
|
2013-08-22 07:07:11 +02:00
|
|
|
{
|
|
|
|
if (src[i] == '\n')
|
|
|
|
dst[j++] = '\r';
|
|
|
|
|
|
|
|
dst[j++] = src[i];
|
2016-10-23 20:03:21 +02:00
|
|
|
|
|
|
|
if (src[i] == '\r' && (i + 1 >= src_len || src[i + 1] != '\n'))
|
|
|
|
dst[j++] = '\n';
|
2013-08-22 07:07:11 +02:00
|
|
|
}
|
|
|
|
dst[j] = 0;
|
|
|
|
|
|
|
|
GlobalUnlock(unicode_handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
return unicode_handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-11 04:58:21 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* export_clipboard_data
|
|
|
|
*
|
|
|
|
* Generic export clipboard data routine.
|
|
|
|
*/
|
|
|
|
static CFDataRef export_clipboard_data(HANDLE data)
|
|
|
|
{
|
|
|
|
CFDataRef ret;
|
|
|
|
UINT len;
|
|
|
|
LPVOID src;
|
|
|
|
|
|
|
|
len = GlobalSize(data);
|
|
|
|
src = GlobalLock(data);
|
|
|
|
if (!src) return NULL;
|
|
|
|
|
|
|
|
ret = CFDataCreate(NULL, src, len);
|
|
|
|
GlobalUnlock(data);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-13 22:52:36 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* export_bitmap_to_bmp
|
|
|
|
*
|
|
|
|
* Export CF_BITMAP to BMP file format.
|
|
|
|
*/
|
|
|
|
static CFDataRef export_bitmap_to_bmp(HANDLE data)
|
|
|
|
{
|
|
|
|
CFDataRef ret = NULL;
|
|
|
|
HGLOBAL dib;
|
|
|
|
|
|
|
|
dib = create_dib_from_bitmap(data);
|
|
|
|
if (dib)
|
|
|
|
{
|
|
|
|
ret = export_dib_to_bmp(dib);
|
|
|
|
GlobalFree(dib);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* export_dib_to_bmp
|
|
|
|
*
|
2016-02-26 10:55:28 +01:00
|
|
|
* Export CF_DIB or CF_DIBV5 to BMP file format. This just entails
|
|
|
|
* prepending a BMP file format header to the data.
|
2013-03-13 22:52:36 +01:00
|
|
|
*/
|
|
|
|
static CFDataRef export_dib_to_bmp(HANDLE data)
|
|
|
|
{
|
|
|
|
CFMutableDataRef ret = NULL;
|
|
|
|
BYTE *dibdata;
|
|
|
|
CFIndex len;
|
|
|
|
BITMAPFILEHEADER bfh;
|
|
|
|
|
|
|
|
dibdata = GlobalLock(data);
|
|
|
|
if (!dibdata)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
len = sizeof(bfh) + GlobalSize(data);
|
|
|
|
ret = CFDataCreateMutable(NULL, len);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
bfh.bfType = 0x4d42; /* "BM" */
|
|
|
|
bfh.bfSize = len;
|
|
|
|
bfh.bfReserved1 = 0;
|
|
|
|
bfh.bfReserved2 = 0;
|
|
|
|
bfh.bfOffBits = sizeof(bfh) + bitmap_info_size((BITMAPINFO*)dibdata, DIB_RGB_COLORS);
|
|
|
|
CFDataAppendBytes(ret, (UInt8*)&bfh, sizeof(bfh));
|
|
|
|
|
|
|
|
/* rest of bitmap is the same as the packed dib */
|
|
|
|
CFDataAppendBytes(ret, (UInt8*)dibdata, len - sizeof(bfh));
|
|
|
|
}
|
|
|
|
|
|
|
|
GlobalUnlock(data);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-22 11:31:31 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* export_enhmetafile
|
|
|
|
*
|
|
|
|
* Export an enhanced metafile to data.
|
|
|
|
*/
|
|
|
|
static CFDataRef export_enhmetafile(HANDLE data)
|
|
|
|
{
|
|
|
|
CFMutableDataRef ret = NULL;
|
|
|
|
unsigned int size = GetEnhMetaFileBits(data, 0, NULL);
|
|
|
|
|
|
|
|
TRACE("data %p\n", data);
|
|
|
|
|
|
|
|
ret = CFDataCreateMutable(NULL, size);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
CFDataSetLength(ret, size);
|
|
|
|
GetEnhMetaFileBits(data, size, (BYTE*)CFDataGetMutableBytePtr(ret));
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE(" -> %s\n", debugstr_cf(ret));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-13 22:52:50 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* export_hdrop_to_filenames
|
|
|
|
*
|
|
|
|
* Export CF_HDROP to NSFilenamesPboardType data, which is a CFArray of
|
|
|
|
* CFStrings (holding Unix paths) which is serialized as a property list.
|
|
|
|
*/
|
|
|
|
static CFDataRef export_hdrop_to_filenames(HANDLE data)
|
|
|
|
{
|
|
|
|
CFDataRef ret = NULL;
|
|
|
|
DROPFILES *dropfiles;
|
|
|
|
CFMutableArrayRef filenames = NULL;
|
|
|
|
void *p;
|
|
|
|
WCHAR *buffer = NULL;
|
|
|
|
size_t buffer_len = 0;
|
|
|
|
|
|
|
|
TRACE("data %p\n", data);
|
|
|
|
|
|
|
|
if (!(dropfiles = GlobalLock(data)))
|
|
|
|
{
|
|
|
|
WARN("failed to lock data %p\n", data);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
filenames = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
|
|
|
|
if (!filenames)
|
|
|
|
{
|
|
|
|
WARN("failed to create filenames array\n");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = (char*)dropfiles + dropfiles->pFiles;
|
|
|
|
while (dropfiles->fWide ? *(WCHAR*)p : *(char*)p)
|
|
|
|
{
|
|
|
|
char *unixname;
|
|
|
|
CFStringRef filename;
|
|
|
|
|
|
|
|
TRACE(" %s\n", dropfiles->fWide ? debugstr_w(p) : debugstr_a(p));
|
|
|
|
|
|
|
|
if (dropfiles->fWide)
|
|
|
|
unixname = wine_get_unix_file_name(p);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int len = MultiByteToWideChar(CP_ACP, 0, p, -1, NULL, 0);
|
|
|
|
if (len)
|
|
|
|
{
|
|
|
|
if (len > buffer_len)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, buffer);
|
|
|
|
buffer_len = len * 2;
|
|
|
|
buffer = HeapAlloc(GetProcessHeap(), 0, buffer_len * sizeof(*buffer));
|
|
|
|
}
|
|
|
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, p, -1, buffer, buffer_len);
|
|
|
|
unixname = wine_get_unix_file_name(buffer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
unixname = NULL;
|
|
|
|
}
|
|
|
|
if (!unixname)
|
|
|
|
{
|
|
|
|
WARN("failed to convert DOS path to Unix: %s\n",
|
|
|
|
dropfiles->fWide ? debugstr_w(p) : debugstr_a(p));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dropfiles->fWide)
|
|
|
|
p = (WCHAR*)p + strlenW(p) + 1;
|
|
|
|
else
|
|
|
|
p = (char*)p + strlen(p) + 1;
|
|
|
|
|
|
|
|
filename = CFStringCreateWithFileSystemRepresentation(NULL, unixname);
|
|
|
|
HeapFree(GetProcessHeap(), 0, unixname);
|
|
|
|
if (!filename)
|
|
|
|
{
|
|
|
|
WARN("failed to create CFString from Unix path %s\n", debugstr_a(unixname));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
CFArrayAppendValue(filenames, filename);
|
|
|
|
CFRelease(filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = CFPropertyListCreateData(NULL, filenames, kCFPropertyListXMLFormat_v1_0, 0, NULL);
|
|
|
|
|
|
|
|
done:
|
|
|
|
HeapFree(GetProcessHeap(), 0, buffer);
|
|
|
|
GlobalUnlock(data);
|
|
|
|
if (filenames) CFRelease(filenames);
|
|
|
|
TRACE(" -> %s\n", debugstr_cf(ret));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-13 20:36:21 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* export_html
|
|
|
|
*
|
|
|
|
* Export HTML Format to public.html data.
|
|
|
|
*
|
|
|
|
* FIXME: We should attempt to add an <a base> tag and convert windows paths.
|
|
|
|
*/
|
|
|
|
static CFDataRef export_html(HANDLE handle)
|
|
|
|
{
|
|
|
|
CFDataRef ret;
|
|
|
|
const char *data, *field_value;
|
|
|
|
int fragmentstart, fragmentend;
|
|
|
|
|
|
|
|
data = GlobalLock(handle);
|
|
|
|
|
|
|
|
/* read the important fields */
|
|
|
|
field_value = get_html_description_field(data, "StartFragment:");
|
|
|
|
if (!field_value)
|
|
|
|
{
|
|
|
|
ERR("Couldn't find StartFragment value\n");
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
fragmentstart = atoi(field_value);
|
|
|
|
|
|
|
|
field_value = get_html_description_field(data, "EndFragment:");
|
|
|
|
if (!field_value)
|
|
|
|
{
|
|
|
|
ERR("Couldn't find EndFragment value\n");
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
fragmentend = atoi(field_value);
|
|
|
|
|
|
|
|
/* export only the fragment */
|
|
|
|
ret = CFDataCreate(NULL, (const UInt8*)&data[fragmentstart], fragmentend - fragmentstart);
|
|
|
|
GlobalUnlock(handle);
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
failed:
|
|
|
|
GlobalUnlock(handle);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-22 11:31:28 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* export_metafilepict
|
|
|
|
*
|
|
|
|
* Export a metafile to data.
|
|
|
|
*/
|
|
|
|
static CFDataRef export_metafilepict(HANDLE data)
|
|
|
|
{
|
|
|
|
CFMutableDataRef ret = NULL;
|
|
|
|
METAFILEPICT *mfp = GlobalLock(data);
|
|
|
|
unsigned int size = GetMetaFileBitsEx(mfp->hMF, 0, NULL);
|
|
|
|
|
|
|
|
TRACE("data %p\n", data);
|
|
|
|
|
|
|
|
ret = CFDataCreateMutable(NULL, sizeof(*mfp) + size);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
CFDataAppendBytes(ret, (UInt8*)mfp, sizeof(*mfp));
|
|
|
|
CFDataIncreaseLength(ret, size);
|
|
|
|
GetMetaFileBitsEx(mfp->hMF, size, (BYTE*)CFDataGetMutableBytePtr(ret) + sizeof(*mfp));
|
|
|
|
}
|
|
|
|
|
|
|
|
GlobalUnlock(data);
|
|
|
|
TRACE(" -> %s\n", debugstr_cf(ret));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-11 04:58:21 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* export_text_to_utf8
|
|
|
|
*
|
|
|
|
* Export CF_TEXT to UTF-8.
|
|
|
|
*/
|
|
|
|
static CFDataRef export_text_to_utf8(HANDLE data)
|
|
|
|
{
|
2016-10-23 20:03:25 +02:00
|
|
|
CFDataRef ret = NULL;
|
|
|
|
const char* str;
|
|
|
|
|
|
|
|
if ((str = GlobalLock(data)))
|
|
|
|
{
|
|
|
|
int str_len = GlobalSize(data);
|
|
|
|
int wstr_len;
|
|
|
|
WCHAR *wstr;
|
|
|
|
HANDLE unicode;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
wstr_len = MultiByteToWideChar(CP_ACP, 0, str, str_len, NULL, 0);
|
|
|
|
if (!str_len || str[str_len - 1]) wstr_len += 1;
|
|
|
|
wstr = HeapAlloc(GetProcessHeap(), 0, wstr_len * sizeof(WCHAR));
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, str, str_len, wstr, wstr_len);
|
|
|
|
wstr[wstr_len - 1] = 0;
|
|
|
|
|
|
|
|
unicode = GlobalAlloc(GMEM_FIXED, wstr_len * sizeof(WCHAR));
|
|
|
|
if (unicode && (p = GlobalLock(unicode)))
|
|
|
|
{
|
|
|
|
memcpy(p, wstr, wstr_len * sizeof(WCHAR));
|
|
|
|
GlobalUnlock(unicode);
|
|
|
|
}
|
2013-03-11 04:58:21 +01:00
|
|
|
|
2016-10-23 20:03:25 +02:00
|
|
|
ret = export_unicodetext_to_utf8(unicode);
|
2013-03-11 04:58:21 +01:00
|
|
|
|
2016-10-23 20:03:25 +02:00
|
|
|
GlobalFree(unicode);
|
|
|
|
GlobalUnlock(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2013-08-22 07:07:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-11 04:58:21 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* export_unicodetext_to_utf8
|
|
|
|
*
|
|
|
|
* Export CF_UNICODETEXT to UTF-8.
|
|
|
|
*/
|
|
|
|
static CFDataRef export_unicodetext_to_utf8(HANDLE data)
|
|
|
|
{
|
|
|
|
CFMutableDataRef ret;
|
|
|
|
LPVOID src;
|
|
|
|
INT dst_len;
|
|
|
|
|
|
|
|
src = GlobalLock(data);
|
|
|
|
if (!src) return NULL;
|
|
|
|
|
|
|
|
dst_len = WideCharToMultiByte(CP_UTF8, 0, src, -1, NULL, 0, NULL, NULL);
|
|
|
|
if (dst_len) dst_len--; /* Leave off null terminator. */
|
|
|
|
ret = CFDataCreateMutable(NULL, dst_len);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
LPSTR dst;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
CFDataSetLength(ret, dst_len);
|
|
|
|
dst = (LPSTR)CFDataGetMutableBytePtr(ret);
|
|
|
|
WideCharToMultiByte(CP_UTF8, 0, src, -1, dst, dst_len, NULL, NULL);
|
|
|
|
|
|
|
|
/* Remove carriage returns */
|
|
|
|
for (i = 0, j = 0; i < dst_len; i++)
|
|
|
|
{
|
|
|
|
if (dst[i] == '\r' &&
|
|
|
|
(i + 1 >= dst_len || dst[i + 1] == '\n' || dst[i + 1] == '\0'))
|
|
|
|
continue;
|
|
|
|
dst[j++] = dst[i];
|
|
|
|
}
|
|
|
|
CFDataSetLength(ret, j);
|
|
|
|
}
|
|
|
|
GlobalUnlock(data);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-22 07:07:11 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* export_unicodetext_to_utf16
|
|
|
|
*
|
|
|
|
* Export CF_UNICODETEXT to UTF-16.
|
|
|
|
*/
|
|
|
|
static CFDataRef export_unicodetext_to_utf16(HANDLE data)
|
|
|
|
{
|
|
|
|
CFMutableDataRef ret;
|
|
|
|
const WCHAR *src;
|
2013-10-21 06:55:00 +02:00
|
|
|
INT src_len;
|
2013-08-22 07:07:11 +02:00
|
|
|
|
|
|
|
src = GlobalLock(data);
|
|
|
|
if (!src) return NULL;
|
|
|
|
|
2013-10-21 06:55:00 +02:00
|
|
|
src_len = GlobalSize(data) / sizeof(WCHAR);
|
|
|
|
if (src_len) src_len--; /* Leave off null terminator. */
|
|
|
|
ret = CFDataCreateMutable(NULL, src_len * sizeof(WCHAR));
|
2013-08-22 07:07:11 +02:00
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
LPWSTR dst;
|
|
|
|
int i, j;
|
|
|
|
|
2013-10-21 06:55:00 +02:00
|
|
|
CFDataSetLength(ret, src_len * sizeof(WCHAR));
|
2013-08-22 07:07:11 +02:00
|
|
|
dst = (LPWSTR)CFDataGetMutableBytePtr(ret);
|
|
|
|
|
|
|
|
/* Remove carriage returns */
|
2013-10-21 06:55:00 +02:00
|
|
|
for (i = 0, j = 0; i < src_len; i++)
|
2013-08-22 07:07:11 +02:00
|
|
|
{
|
|
|
|
if (src[i] == '\r' &&
|
2013-10-21 06:55:00 +02:00
|
|
|
(i + 1 >= src_len || src[i + 1] == '\n' || src[i + 1] == '\0'))
|
2013-08-22 07:07:11 +02:00
|
|
|
continue;
|
|
|
|
dst[j++] = src[i];
|
|
|
|
}
|
2013-10-21 06:54:49 +02:00
|
|
|
CFDataSetLength(ret, j * sizeof(WCHAR));
|
2013-08-22 07:07:11 +02:00
|
|
|
}
|
|
|
|
GlobalUnlock(data);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-13 22:53:16 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* macdrv_get_pasteboard_data
|
|
|
|
*/
|
2013-03-13 22:53:32 +01:00
|
|
|
HANDLE macdrv_get_pasteboard_data(CFTypeRef pasteboard, UINT desired_format)
|
2013-03-13 22:53:16 +01:00
|
|
|
{
|
|
|
|
CFArrayRef types;
|
|
|
|
CFIndex count;
|
|
|
|
CFIndex i;
|
|
|
|
CFStringRef type, best_type;
|
|
|
|
WINE_CLIPFORMAT* best_format = NULL;
|
|
|
|
HANDLE data = NULL;
|
|
|
|
|
|
|
|
TRACE("pasteboard %p, desired_format %s\n", pasteboard, debugstr_format(desired_format));
|
|
|
|
|
|
|
|
types = macdrv_copy_pasteboard_types(pasteboard);
|
|
|
|
if (!types)
|
|
|
|
{
|
|
|
|
WARN("Failed to copy pasteboard types\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
count = CFArrayGetCount(types);
|
|
|
|
TRACE("got %ld types\n", count);
|
|
|
|
|
|
|
|
for (i = 0; (!best_format || best_format->synthesized) && i < count; i++)
|
|
|
|
{
|
|
|
|
WINE_CLIPFORMAT* format;
|
|
|
|
|
|
|
|
type = CFArrayGetValueAtIndex(types, i);
|
|
|
|
|
2016-10-23 20:03:29 +02:00
|
|
|
if ((format = format_for_type(type)))
|
2013-03-13 22:53:16 +01:00
|
|
|
{
|
2016-10-23 20:03:29 +02:00
|
|
|
TRACE("for type %s got format %p/%s\n", debugstr_cf(type), format, debugstr_format(format->format_id));
|
2013-03-13 22:53:16 +01:00
|
|
|
|
|
|
|
if (format->format_id == desired_format)
|
|
|
|
{
|
|
|
|
/* The best format is the matching one which is not synthesized. Failing that,
|
|
|
|
the best format is the first matching synthesized format. */
|
|
|
|
if (!format->synthesized || !best_format)
|
|
|
|
{
|
|
|
|
best_type = type;
|
|
|
|
best_format = format;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (best_format)
|
|
|
|
{
|
|
|
|
CFDataRef pasteboard_data = macdrv_copy_pasteboard_data(pasteboard, best_type);
|
|
|
|
|
|
|
|
TRACE("got pasteboard data for type %s: %s\n", debugstr_cf(best_type), debugstr_cf(pasteboard_data));
|
|
|
|
|
|
|
|
if (pasteboard_data)
|
|
|
|
{
|
|
|
|
data = best_format->import_func(pasteboard_data);
|
|
|
|
CFRelease(pasteboard_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CFRelease(types);
|
|
|
|
TRACE(" -> %p\n", data);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-13 22:53:21 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* macdrv_pasteboard_has_format
|
|
|
|
*/
|
2013-03-13 22:53:32 +01:00
|
|
|
BOOL macdrv_pasteboard_has_format(CFTypeRef pasteboard, UINT desired_format)
|
2013-03-13 22:53:21 +01:00
|
|
|
{
|
|
|
|
CFArrayRef types;
|
|
|
|
int count;
|
|
|
|
UINT i;
|
|
|
|
BOOL found = FALSE;
|
|
|
|
|
|
|
|
TRACE("pasteboard %p, desired_format %s\n", pasteboard, debugstr_format(desired_format));
|
|
|
|
|
|
|
|
types = macdrv_copy_pasteboard_types(pasteboard);
|
|
|
|
if (!types)
|
|
|
|
{
|
|
|
|
WARN("Failed to copy pasteboard types\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
count = CFArrayGetCount(types);
|
|
|
|
TRACE("got %d types\n", count);
|
|
|
|
|
2016-10-23 20:03:29 +02:00
|
|
|
for (i = 0; i < count; i++)
|
2013-03-13 22:53:21 +01:00
|
|
|
{
|
|
|
|
CFStringRef type = CFArrayGetValueAtIndex(types, i);
|
2016-10-23 20:03:29 +02:00
|
|
|
WINE_CLIPFORMAT* format = format_for_type(type);
|
2013-03-13 22:53:21 +01:00
|
|
|
|
2016-10-23 20:03:29 +02:00
|
|
|
if (format)
|
2013-03-13 22:53:21 +01:00
|
|
|
{
|
|
|
|
TRACE("for type %s got format %s\n", debugstr_cf(type), debugstr_format(format->format_id));
|
|
|
|
|
|
|
|
if (format->format_id == desired_format)
|
2016-10-23 20:03:29 +02:00
|
|
|
{
|
2013-03-13 22:53:21 +01:00
|
|
|
found = TRUE;
|
2016-10-23 20:03:29 +02:00
|
|
|
break;
|
|
|
|
}
|
2013-03-13 22:53:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CFRelease(types);
|
|
|
|
TRACE(" -> %d\n", found);
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-13 22:53:27 +01:00
|
|
|
/**************************************************************************
|
2017-01-11 18:06:21 +01:00
|
|
|
* get_formats_for_pasteboard_types
|
2013-03-13 22:53:27 +01:00
|
|
|
*/
|
2017-01-11 18:06:21 +01:00
|
|
|
static WINE_CLIPFORMAT** get_formats_for_pasteboard_types(CFArrayRef types, UINT *num_formats)
|
2013-03-13 22:53:27 +01:00
|
|
|
{
|
2016-10-23 20:03:31 +02:00
|
|
|
CFIndex count, i;
|
|
|
|
CFMutableSetRef seen_formats;
|
|
|
|
WINE_CLIPFORMAT** formats;
|
|
|
|
UINT pos;
|
2013-03-13 22:53:27 +01:00
|
|
|
|
|
|
|
count = CFArrayGetCount(types);
|
|
|
|
TRACE("got %ld types\n", count);
|
|
|
|
|
|
|
|
if (!count)
|
|
|
|
return NULL;
|
|
|
|
|
2016-10-23 20:03:31 +02:00
|
|
|
seen_formats = CFSetCreateMutable(NULL, count, NULL);
|
|
|
|
if (!seen_formats)
|
|
|
|
{
|
|
|
|
WARN("Failed to allocate seen formats set\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
formats = HeapAlloc(GetProcessHeap(), 0, count * sizeof(*formats));
|
2013-03-13 22:53:27 +01:00
|
|
|
if (!formats)
|
|
|
|
{
|
|
|
|
WARN("Failed to allocate formats array\n");
|
2016-10-23 20:03:31 +02:00
|
|
|
CFRelease(seen_formats);
|
2013-03-13 22:53:27 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-10-23 20:03:31 +02:00
|
|
|
pos = 0;
|
2013-03-13 22:53:27 +01:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
CFStringRef type = CFArrayGetValueAtIndex(types, i);
|
2016-10-23 20:03:31 +02:00
|
|
|
WINE_CLIPFORMAT* format = format_for_type(type);
|
2013-03-13 22:53:27 +01:00
|
|
|
|
2016-10-23 20:03:29 +02:00
|
|
|
if (!format)
|
2013-03-13 22:53:27 +01:00
|
|
|
{
|
2016-10-23 20:03:29 +02:00
|
|
|
TRACE("ignoring type %s\n", debugstr_cf(type));
|
|
|
|
continue;
|
2013-11-22 11:31:48 +01:00
|
|
|
}
|
2013-03-13 22:53:27 +01:00
|
|
|
|
2016-10-23 20:03:29 +02:00
|
|
|
if (!format->synthesized)
|
2013-11-22 11:31:48 +01:00
|
|
|
{
|
2016-10-23 20:03:29 +02:00
|
|
|
TRACE("for type %s got format %p/%s\n", debugstr_cf(type), format, debugstr_format(format->format_id));
|
2016-10-23 20:03:31 +02:00
|
|
|
CFSetAddValue(seen_formats, (void*)format->format_id);
|
|
|
|
formats[pos++] = format;
|
2016-10-23 20:03:29 +02:00
|
|
|
}
|
|
|
|
else if (format->natural_format &&
|
|
|
|
CFArrayContainsValue(types, CFRangeMake(0, count), format->natural_format->type))
|
|
|
|
{
|
|
|
|
TRACE("for type %s deferring synthesized formats because type %s is also present\n",
|
|
|
|
debugstr_cf(type), debugstr_cf(format->natural_format->type));
|
|
|
|
}
|
2016-10-23 20:03:31 +02:00
|
|
|
else if (CFSetContainsValue(seen_formats, (void*)format->format_id))
|
2016-10-23 20:03:29 +02:00
|
|
|
{
|
|
|
|
TRACE("for type %s got duplicate synthesized format %p/%s; skipping\n", debugstr_cf(type), format,
|
|
|
|
debugstr_format(format->format_id));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("for type %s got synthesized format %p/%s\n", debugstr_cf(type), format, debugstr_format(format->format_id));
|
2016-10-23 20:03:31 +02:00
|
|
|
CFSetAddValue(seen_formats, (void*)format->format_id);
|
|
|
|
formats[pos++] = format;
|
2013-11-22 11:31:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now go back through the types adding the synthesized formats that we deferred before. */
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
CFStringRef type = CFArrayGetValueAtIndex(types, i);
|
2016-10-23 20:03:31 +02:00
|
|
|
WINE_CLIPFORMAT* format = format_for_type(type);
|
2013-11-22 11:31:48 +01:00
|
|
|
|
2016-10-23 20:03:29 +02:00
|
|
|
if (!format) continue;
|
|
|
|
if (!format->synthesized) continue;
|
|
|
|
|
|
|
|
/* Don't duplicate a real value with a synthesized value. */
|
2016-10-23 20:03:31 +02:00
|
|
|
if (CFSetContainsValue(seen_formats, (void*)format->format_id)) continue;
|
2016-10-23 20:03:29 +02:00
|
|
|
|
|
|
|
TRACE("for type %s got synthesized format %p/%s\n", debugstr_cf(type), format, debugstr_format(format->format_id));
|
2016-10-23 20:03:31 +02:00
|
|
|
CFSetAddValue(seen_formats, (void*)format->format_id);
|
|
|
|
formats[pos++] = format;
|
2013-03-13 22:53:27 +01:00
|
|
|
}
|
|
|
|
|
2016-10-23 20:03:31 +02:00
|
|
|
CFRelease(seen_formats);
|
2013-03-13 22:53:27 +01:00
|
|
|
|
2016-10-23 20:03:31 +02:00
|
|
|
if (!pos)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, formats);
|
|
|
|
formats = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*num_formats = pos;
|
2013-03-13 22:53:27 +01:00
|
|
|
return formats;
|
2016-10-23 20:03:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-11 18:06:21 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* get_formats_for_pasteboard
|
|
|
|
*/
|
|
|
|
static WINE_CLIPFORMAT** get_formats_for_pasteboard(CFTypeRef pasteboard, UINT *num_formats)
|
|
|
|
{
|
|
|
|
CFArrayRef types;
|
|
|
|
WINE_CLIPFORMAT** formats;
|
|
|
|
|
|
|
|
TRACE("pasteboard %s\n", debugstr_cf(pasteboard));
|
|
|
|
|
|
|
|
types = macdrv_copy_pasteboard_types(pasteboard);
|
|
|
|
if (!types)
|
|
|
|
{
|
|
|
|
WARN("Failed to copy pasteboard types\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
formats = get_formats_for_pasteboard_types(types, num_formats);
|
|
|
|
CFRelease(types);
|
|
|
|
return formats;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-23 20:03:31 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* macdrv_get_pasteboard_formats
|
|
|
|
*/
|
|
|
|
UINT* macdrv_get_pasteboard_formats(CFTypeRef pasteboard, UINT* num_formats)
|
|
|
|
{
|
|
|
|
WINE_CLIPFORMAT** formats;
|
|
|
|
UINT count, i;
|
|
|
|
UINT* format_ids;
|
|
|
|
|
|
|
|
formats = get_formats_for_pasteboard(pasteboard, &count);
|
|
|
|
if (!formats)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
format_ids = HeapAlloc(GetProcessHeap(), 0, count);
|
|
|
|
if (!format_ids)
|
|
|
|
{
|
|
|
|
WARN("Failed to allocate formats IDs array\n");
|
|
|
|
HeapFree(GetProcessHeap(), 0, formats);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
format_ids[i] = formats[i]->format_id;
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, formats);
|
|
|
|
|
|
|
|
*num_formats = count;
|
|
|
|
return format_ids;
|
2013-03-13 22:53:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-11 04:58:03 +01:00
|
|
|
/**************************************************************************
|
2016-10-23 20:03:32 +02:00
|
|
|
* 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 i;
|
2013-03-11 04:58:03 +01:00
|
|
|
|
2016-10-23 20:03:32 +02:00
|
|
|
if (list_empty(&format_list)) register_builtin_formats();
|
2013-03-11 04:58:03 +01:00
|
|
|
|
2016-10-23 20:03:32 +02:00
|
|
|
for (i = 0; i < size; i++)
|
|
|
|
register_format(ids[i], NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* get_clipboard_formats
|
|
|
|
*
|
|
|
|
* Return a list of all formats currently available on the Win32 clipboard.
|
|
|
|
* Helper for set_mac_pasteboard_types_from_win32_clipboard.
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
register_win32_formats(ids, *size);
|
|
|
|
return ids;
|
|
|
|
}
|
2013-03-11 04:58:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
2016-10-23 20:03:32 +02:00
|
|
|
* set_mac_pasteboard_types_from_win32_clipboard
|
2013-03-11 04:58:03 +01:00
|
|
|
*/
|
2016-10-23 20:03:32 +02:00
|
|
|
static void set_mac_pasteboard_types_from_win32_clipboard(void)
|
2013-03-11 04:58:03 +01:00
|
|
|
{
|
2013-03-26 06:47:58 +01:00
|
|
|
WINE_CLIPFORMAT *format;
|
2016-10-23 20:03:32 +02:00
|
|
|
UINT count, i, *formats;
|
2013-03-11 04:58:03 +01:00
|
|
|
|
2016-10-23 20:03:32 +02:00
|
|
|
if (!(formats = get_clipboard_formats(&count))) return;
|
|
|
|
|
2016-10-23 20:03:34 +02:00
|
|
|
macdrv_clear_pasteboard(clipboard_cocoa_window);
|
2016-10-23 20:03:32 +02:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
2013-03-11 04:58:03 +01:00
|
|
|
{
|
2016-10-23 20:03:32 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(format, &format_list, WINE_CLIPFORMAT, entry)
|
|
|
|
{
|
|
|
|
if (format->format_id != formats[i]) continue;
|
|
|
|
TRACE("%s -> %s\n", debugstr_format(format->format_id), debugstr_cf(format->type));
|
|
|
|
macdrv_set_pasteboard_data(format->type, NULL, clipboard_cocoa_window);
|
|
|
|
}
|
2013-03-11 04:58:03 +01:00
|
|
|
}
|
2013-03-13 22:52:31 +01:00
|
|
|
|
2016-10-23 20:03:32 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, formats);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* set_win32_clipboard_formats_from_mac_pasteboard
|
|
|
|
*/
|
2017-01-11 18:06:21 +01:00
|
|
|
static void set_win32_clipboard_formats_from_mac_pasteboard(CFArrayRef types)
|
2016-10-23 20:03:32 +02:00
|
|
|
{
|
|
|
|
WINE_CLIPFORMAT** formats;
|
|
|
|
UINT count, i;
|
|
|
|
|
2017-01-11 18:06:21 +01:00
|
|
|
formats = get_formats_for_pasteboard_types(types, &count);
|
2016-10-23 20:03:32 +02:00
|
|
|
if (!formats)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
2013-11-22 11:31:44 +01:00
|
|
|
{
|
2016-10-23 20:03:32 +02:00
|
|
|
TRACE("adding format %s\n", debugstr_format(formats[i]->format_id));
|
|
|
|
SetClipboardData(formats[i]->format_id, 0);
|
2013-11-22 11:31:44 +01:00
|
|
|
}
|
|
|
|
|
2016-10-23 20:03:32 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, current_mac_formats);
|
|
|
|
current_mac_formats = formats;
|
|
|
|
nb_current_mac_formats = count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* render_format
|
|
|
|
*/
|
|
|
|
static void render_format(UINT id)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < nb_current_mac_formats; i++)
|
2013-03-26 06:47:58 +01:00
|
|
|
{
|
2016-10-23 20:03:32 +02:00
|
|
|
CFDataRef pasteboard_data;
|
|
|
|
|
|
|
|
if (current_mac_formats[i]->format_id != id) continue;
|
|
|
|
|
|
|
|
pasteboard_data = macdrv_copy_pasteboard_data(NULL, current_mac_formats[i]->type);
|
|
|
|
if (pasteboard_data)
|
|
|
|
{
|
|
|
|
HANDLE handle = current_mac_formats[i]->import_func(pasteboard_data);
|
|
|
|
CFRelease(pasteboard_data);
|
2017-05-30 09:56:25 +02:00
|
|
|
if (handle) SetClipboardData(id, handle);
|
2016-10-23 20:03:32 +02:00
|
|
|
break;
|
|
|
|
}
|
2013-03-26 06:47:58 +01:00
|
|
|
}
|
2013-03-11 04:58:03 +01:00
|
|
|
}
|
2013-03-11 04:58:51 +01:00
|
|
|
|
|
|
|
|
2016-10-23 20:03:32 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* grab_win32_clipboard
|
|
|
|
*
|
|
|
|
* Grab the Win32 clipboard when a Mac app has taken ownership of the
|
|
|
|
* pasteboard, and fill it with the pasteboard data types.
|
|
|
|
*/
|
2017-05-30 09:56:25 +02:00
|
|
|
static void grab_win32_clipboard(void)
|
2016-10-23 20:03:32 +02:00
|
|
|
{
|
2017-01-11 18:06:21 +01:00
|
|
|
static CFArrayRef last_types;
|
|
|
|
CFArrayRef types;
|
|
|
|
|
|
|
|
types = macdrv_copy_pasteboard_types(NULL);
|
|
|
|
if (!types)
|
|
|
|
{
|
|
|
|
WARN("Failed to copy pasteboard types\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-30 09:56:25 +02:00
|
|
|
if (!macdrv_has_pasteboard_changed() && last_types && CFEqual(types, last_types))
|
2017-01-11 18:06:21 +01:00
|
|
|
{
|
|
|
|
CFRelease(types);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last_types) CFRelease(last_types);
|
|
|
|
last_types = types; /* takes ownership */
|
|
|
|
|
2017-01-11 18:06:20 +01:00
|
|
|
if (!OpenClipboard(clipboard_hwnd)) return;
|
2016-10-23 20:03:32 +02:00
|
|
|
EmptyClipboard();
|
|
|
|
is_clipboard_owner = TRUE;
|
|
|
|
last_clipboard_update = GetTickCount64();
|
2017-01-11 18:06:21 +01:00
|
|
|
set_win32_clipboard_formats_from_mac_pasteboard(types);
|
2016-10-23 20:03:32 +02:00
|
|
|
CloseClipboard();
|
2017-01-11 18:06:22 +01:00
|
|
|
SetTimer(clipboard_hwnd, 1, CLIPBOARD_UPDATE_DELAY, NULL);
|
2016-10-23 20:03:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-23 20:03:33 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* update_clipboard
|
|
|
|
*
|
|
|
|
* Periodically update the clipboard while the clipboard is owned by a
|
|
|
|
* Mac app.
|
|
|
|
*/
|
2017-01-11 18:06:20 +01:00
|
|
|
static void update_clipboard(void)
|
2016-10-23 20:03:33 +02:00
|
|
|
{
|
|
|
|
static BOOL updating;
|
|
|
|
|
|
|
|
TRACE("is_clipboard_owner %d last_clipboard_update %llu now %llu\n",
|
2020-06-01 18:31:52 +02:00
|
|
|
is_clipboard_owner, (unsigned long long)last_clipboard_update, (unsigned long long)GetTickCount64());
|
2016-10-23 20:03:33 +02:00
|
|
|
|
2017-01-11 18:06:20 +01:00
|
|
|
if (updating) return;
|
2016-10-23 20:03:33 +02:00
|
|
|
updating = TRUE;
|
|
|
|
|
|
|
|
if (is_clipboard_owner)
|
|
|
|
{
|
|
|
|
if (GetTickCount64() - last_clipboard_update > CLIPBOARD_UPDATE_DELAY)
|
2017-05-30 09:56:25 +02:00
|
|
|
grab_win32_clipboard();
|
2016-10-23 20:03:33 +02:00
|
|
|
}
|
2016-10-23 20:03:34 +02:00
|
|
|
else if (!macdrv_is_pasteboard_owner(clipboard_cocoa_window))
|
2017-05-30 09:56:25 +02:00
|
|
|
grab_win32_clipboard();
|
2016-10-23 20:03:33 +02:00
|
|
|
|
|
|
|
updating = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-23 20:03:32 +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)
|
|
|
|
{
|
|
|
|
case WM_NCCREATE:
|
|
|
|
return TRUE;
|
|
|
|
case WM_CLIPBOARDUPDATE:
|
|
|
|
if (is_clipboard_owner) break; /* ignore our own changes */
|
2017-02-02 21:51:45 +01:00
|
|
|
if ((LONG)(GetClipboardSequenceNumber() - last_get_seqno) <= 0) break;
|
2016-10-23 20:03:32 +02:00
|
|
|
set_mac_pasteboard_types_from_win32_clipboard();
|
|
|
|
break;
|
|
|
|
case WM_RENDERFORMAT:
|
|
|
|
render_format(wp);
|
|
|
|
break;
|
2017-01-11 18:06:22 +01:00
|
|
|
case WM_TIMER:
|
|
|
|
if (!is_clipboard_owner) break;
|
2017-05-30 09:56:25 +02:00
|
|
|
grab_win32_clipboard();
|
2017-01-11 18:06:22 +01:00
|
|
|
break;
|
2016-10-23 20:03:32 +02:00
|
|
|
case WM_DESTROYCLIPBOARD:
|
|
|
|
TRACE("WM_DESTROYCLIPBOARD: lost ownership\n");
|
|
|
|
is_clipboard_owner = FALSE;
|
2017-01-11 18:06:22 +01:00
|
|
|
KillTimer(hwnd, 1);
|
2016-10-23 20:03:32 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return DefWindowProcW(hwnd, msg, wp, lp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* wait_clipboard_mutex
|
|
|
|
*
|
|
|
|
* Make sure that there's only one clipboard thread per window station.
|
|
|
|
*/
|
|
|
|
static BOOL wait_clipboard_mutex(void)
|
|
|
|
{
|
|
|
|
static const WCHAR prefix[] = {'_','_','w','i','n','e','_','c','l','i','p','b','o','a','r','d','_'};
|
2018-08-15 23:26:24 +02:00
|
|
|
WCHAR buffer[MAX_PATH + ARRAY_SIZE(prefix)];
|
2016-10-23 20:03:32 +02:00
|
|
|
HANDLE mutex;
|
|
|
|
|
|
|
|
memcpy(buffer, prefix, sizeof(prefix));
|
|
|
|
if (!GetUserObjectInformationW(GetProcessWindowStation(), UOI_NAME,
|
2018-08-15 23:26:24 +02:00
|
|
|
buffer + ARRAY_SIZE(prefix),
|
2016-10-23 20:03:32 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-23 20:03:33 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* init_pipe_name
|
|
|
|
*
|
|
|
|
* Init-once helper for get_pipe_name.
|
|
|
|
*/
|
|
|
|
static BOOL CALLBACK init_pipe_name(INIT_ONCE* once, void* param, void** context)
|
|
|
|
{
|
|
|
|
static const WCHAR prefix[] = {'\\','\\','.','\\','p','i','p','e','\\','_','_','w','i','n','e','_','c','l','i','p','b','o','a','r','d','_'};
|
|
|
|
|
|
|
|
memcpy(clipboard_pipe_name, prefix, sizeof(prefix));
|
|
|
|
if (!GetUserObjectInformationW(GetProcessWindowStation(), UOI_NAME,
|
2018-08-15 23:26:24 +02:00
|
|
|
clipboard_pipe_name + ARRAY_SIZE(prefix),
|
2016-10-23 20:03:33 +02:00
|
|
|
sizeof(clipboard_pipe_name) - sizeof(prefix), NULL))
|
|
|
|
{
|
|
|
|
ERR("failed to get winstation name\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* get_pipe_name
|
|
|
|
*
|
|
|
|
* Get the name of the pipe used to communicate with the per-window-station
|
|
|
|
* clipboard manager thread.
|
|
|
|
*/
|
|
|
|
static const WCHAR* get_pipe_name(void)
|
|
|
|
{
|
|
|
|
static INIT_ONCE once = INIT_ONCE_STATIC_INIT;
|
|
|
|
InitOnceExecuteOnce(&once, init_pipe_name, NULL, NULL);
|
|
|
|
return clipboard_pipe_name[0] ? clipboard_pipe_name : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-23 20:03:32 +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};
|
|
|
|
WNDCLASSW class;
|
|
|
|
struct macdrv_window_features wf;
|
2016-10-23 20:03:33 +02:00
|
|
|
const WCHAR* pipe_name;
|
|
|
|
HANDLE pipe = NULL;
|
|
|
|
HANDLE event = NULL;
|
|
|
|
OVERLAPPED overlapped;
|
|
|
|
BOOL need_connect = TRUE, pending = FALSE;
|
2016-10-23 20:03:32 +02:00
|
|
|
MSG msg;
|
|
|
|
|
|
|
|
if (!wait_clipboard_mutex()) return 0;
|
|
|
|
|
|
|
|
memset(&class, 0, sizeof(class));
|
|
|
|
class.lpfnWndProc = clipboard_wndproc;
|
|
|
|
class.lpszClassName = clipboard_classname;
|
|
|
|
|
|
|
|
if (!RegisterClassW(&class) && GetLastError() != ERROR_CLASS_ALREADY_EXISTS)
|
|
|
|
{
|
|
|
|
ERR("could not register clipboard window class err %u\n", GetLastError());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!(clipboard_hwnd = CreateWindowW(clipboard_classname, NULL, 0, 0, 0, 0, 0,
|
|
|
|
HWND_MESSAGE, 0, 0, NULL)))
|
|
|
|
{
|
|
|
|
ERR("failed to create clipboard window err %u\n", GetLastError());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&wf, 0, sizeof(wf));
|
|
|
|
clipboard_cocoa_window = macdrv_create_cocoa_window(&wf, CGRectMake(100, 100, 100, 100), clipboard_hwnd,
|
|
|
|
macdrv_init_thread_data()->queue);
|
|
|
|
if (!clipboard_cocoa_window)
|
|
|
|
{
|
|
|
|
ERR("failed to create clipboard Cocoa window\n");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2016-10-23 20:03:33 +02:00
|
|
|
pipe_name = get_pipe_name();
|
|
|
|
if (!pipe_name)
|
|
|
|
{
|
|
|
|
ERR("failed to get pipe name\n");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
pipe = CreateNamedPipeW(pipe_name, PIPE_ACCESS_OUTBOUND | FILE_FLAG_OVERLAPPED,
|
|
|
|
PIPE_TYPE_BYTE, PIPE_UNLIMITED_INSTANCES, 1, 1, 0, NULL);
|
|
|
|
if (!pipe)
|
|
|
|
{
|
|
|
|
ERR("failed to create named pipe: %u\n", GetLastError());
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
event = CreateEventW(NULL, TRUE, FALSE, NULL);
|
|
|
|
if (!event)
|
|
|
|
{
|
|
|
|
ERR("failed to create event: %d\n", GetLastError());
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2016-10-23 20:03:32 +02:00
|
|
|
clipboard_thread_id = GetCurrentThreadId();
|
|
|
|
AddClipboardFormatListener(clipboard_hwnd);
|
|
|
|
register_builtin_formats();
|
2017-05-30 09:56:25 +02:00
|
|
|
grab_win32_clipboard();
|
2016-10-23 20:03:32 +02:00
|
|
|
|
|
|
|
TRACE("clipboard thread %04x running\n", GetCurrentThreadId());
|
2016-10-23 20:03:33 +02:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
DWORD result;
|
|
|
|
|
|
|
|
if (need_connect)
|
|
|
|
{
|
|
|
|
pending = FALSE;
|
|
|
|
memset(&overlapped, 0, sizeof(overlapped));
|
|
|
|
overlapped.hEvent = event;
|
|
|
|
if (ConnectNamedPipe(pipe, &overlapped))
|
|
|
|
{
|
|
|
|
ERR("asynchronous ConnectNamedPipe unexpectedly returned true: %d\n", GetLastError());
|
|
|
|
ResetEvent(event);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = GetLastError();
|
|
|
|
switch (result)
|
|
|
|
{
|
|
|
|
case ERROR_PIPE_CONNECTED:
|
|
|
|
case ERROR_NO_DATA:
|
|
|
|
SetEvent(event);
|
|
|
|
need_connect = FALSE;
|
|
|
|
break;
|
|
|
|
case ERROR_IO_PENDING:
|
|
|
|
need_connect = FALSE;
|
|
|
|
pending = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("failed to initiate pipe connection: %d\n", result);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = MsgWaitForMultipleObjectsEx(1, &event, INFINITE, QS_ALLINPUT, MWMO_ALERTABLE | MWMO_INPUTAVAILABLE);
|
|
|
|
switch (result)
|
|
|
|
{
|
|
|
|
case WAIT_OBJECT_0:
|
|
|
|
{
|
|
|
|
DWORD written;
|
|
|
|
|
|
|
|
if (pending && !GetOverlappedResult(pipe, &overlapped, &written, FALSE))
|
|
|
|
ERR("failed to connect pipe: %d\n", GetLastError());
|
|
|
|
|
|
|
|
update_clipboard();
|
|
|
|
DisconnectNamedPipe(pipe);
|
|
|
|
need_connect = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WAIT_OBJECT_0 + 1:
|
|
|
|
while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
|
|
|
|
{
|
|
|
|
if (msg.message == WM_QUIT)
|
|
|
|
goto done;
|
|
|
|
DispatchMessageW(&msg);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WAIT_IO_COMPLETION:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("failed to wait for connection or input: %d\n", GetLastError());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-10-23 20:03:32 +02:00
|
|
|
|
|
|
|
done:
|
2016-10-23 20:03:33 +02:00
|
|
|
if (event) CloseHandle(event);
|
|
|
|
if (pipe) CloseHandle(pipe);
|
2016-10-23 20:03:32 +02:00
|
|
|
macdrv_destroy_cocoa_window(clipboard_cocoa_window);
|
|
|
|
DestroyWindow(clipboard_hwnd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Mac User Driver Clipboard Exports
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
2016-10-23 20:03:33 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* macdrv_UpdateClipboard
|
|
|
|
*/
|
|
|
|
void CDECL macdrv_UpdateClipboard(void)
|
|
|
|
{
|
|
|
|
static ULONG last_update;
|
|
|
|
ULONG now, end;
|
|
|
|
const WCHAR* pipe_name;
|
|
|
|
HANDLE pipe;
|
|
|
|
BYTE dummy;
|
|
|
|
DWORD count;
|
|
|
|
OVERLAPPED overlapped = { 0 };
|
|
|
|
BOOL canceled = FALSE;
|
|
|
|
|
|
|
|
if (GetCurrentThreadId() == clipboard_thread_id) return;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
now = GetTickCount();
|
|
|
|
if ((int)(now - last_update) <= CLIPBOARD_UPDATE_DELAY) return;
|
|
|
|
last_update = now;
|
|
|
|
|
|
|
|
if (!(pipe_name = get_pipe_name())) return;
|
|
|
|
pipe = CreateFileW(pipe_name, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
|
|
|
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
|
2016-12-05 18:32:24 +01:00
|
|
|
if (pipe == INVALID_HANDLE_VALUE)
|
2016-10-23 20:03:33 +02:00
|
|
|
{
|
|
|
|
WARN("failed to open pipe to clipboard manager: %d\n", GetLastError());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
overlapped.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
|
|
|
|
if (!overlapped.hEvent)
|
|
|
|
{
|
|
|
|
ERR("failed to create event: %d\n", GetLastError());
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We expect the read to fail because the server just closes our connection. This
|
|
|
|
is just waiting for that close to happen. */
|
|
|
|
if (ReadFile(pipe, &dummy, sizeof(dummy), NULL, &overlapped))
|
|
|
|
{
|
|
|
|
WARN("asynchronous ReadFile unexpectedly returned true: %d\n", GetLastError());
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD error = GetLastError();
|
|
|
|
if (error == ERROR_PIPE_NOT_CONNECTED || error == ERROR_BROKEN_PIPE)
|
|
|
|
{
|
|
|
|
/* The server accepted, handled, and closed our connection before we
|
|
|
|
attempted the read, which is fine. */
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
else if (error != ERROR_IO_PENDING)
|
|
|
|
{
|
|
|
|
ERR("failed to initiate read from pipe: %d\n", error);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
end = now + 500;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
DWORD result, timeout;
|
|
|
|
|
|
|
|
if (canceled)
|
|
|
|
timeout = INFINITE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
now = GetTickCount();
|
|
|
|
timeout = end - now;
|
|
|
|
if ((int)timeout < 0)
|
|
|
|
timeout = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = MsgWaitForMultipleObjectsEx(1, &overlapped.hEvent, timeout, QS_SENDMESSAGE, MWMO_ALERTABLE);
|
|
|
|
switch (result)
|
|
|
|
{
|
|
|
|
case WAIT_OBJECT_0:
|
|
|
|
{
|
|
|
|
if (GetOverlappedResult(pipe, &overlapped, &count, FALSE))
|
|
|
|
WARN("unexpectedly succeeded in reading from pipe\n");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = GetLastError();
|
2017-01-13 20:36:22 +01:00
|
|
|
if (result != ERROR_BROKEN_PIPE && result != ERROR_OPERATION_ABORTED &&
|
|
|
|
result != ERROR_HANDLES_CLOSED)
|
2016-10-23 20:03:33 +02:00
|
|
|
WARN("failed to read from pipe: %d\n", result);
|
|
|
|
}
|
|
|
|
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
case WAIT_OBJECT_0 + 1:
|
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE))
|
|
|
|
DispatchMessageW(&msg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WAIT_IO_COMPLETION:
|
|
|
|
break;
|
|
|
|
case WAIT_TIMEOUT:
|
|
|
|
WARN("timed out waiting for read\n");
|
|
|
|
CancelIoEx(pipe, &overlapped);
|
|
|
|
canceled = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (canceled)
|
|
|
|
{
|
|
|
|
ERR("failed to wait for cancel: %d\n", GetLastError());
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR("failed to wait for read: %d\n", GetLastError());
|
|
|
|
CancelIoEx(pipe, &overlapped);
|
|
|
|
canceled = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (overlapped.hEvent) CloseHandle(overlapped.hEvent);
|
|
|
|
CloseHandle(pipe);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-23 20:03:32 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* MACDRV Private Clipboard Exports
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
2013-03-11 04:58:51 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* query_pasteboard_data
|
|
|
|
*/
|
|
|
|
BOOL query_pasteboard_data(HWND hwnd, CFStringRef type)
|
|
|
|
{
|
2016-10-23 20:03:30 +02:00
|
|
|
WINE_CLIPFORMAT *format;
|
2013-03-11 04:58:51 +01:00
|
|
|
BOOL ret = FALSE;
|
2016-10-23 20:03:30 +02:00
|
|
|
HANDLE handle;
|
2013-03-11 04:58:51 +01:00
|
|
|
|
2016-10-23 20:03:32 +02:00
|
|
|
TRACE("win %p/%p type %s\n", hwnd, clipboard_cocoa_window, debugstr_cf(type));
|
2013-03-11 04:58:51 +01:00
|
|
|
|
2016-10-23 20:03:29 +02:00
|
|
|
format = format_for_type(type);
|
2016-10-23 20:03:30 +02:00
|
|
|
if (!format) return FALSE;
|
2013-03-11 04:58:51 +01:00
|
|
|
|
2016-10-23 20:03:32 +02:00
|
|
|
if (!OpenClipboard(clipboard_hwnd))
|
2016-10-23 20:03:29 +02:00
|
|
|
{
|
2016-10-23 20:03:30 +02:00
|
|
|
ERR("failed to open clipboard for %s\n", debugstr_cf(type));
|
|
|
|
return FALSE;
|
2016-10-23 20:03:29 +02:00
|
|
|
}
|
2013-03-11 04:58:51 +01:00
|
|
|
|
2016-10-23 20:03:30 +02:00
|
|
|
if ((handle = GetClipboardData(format->format_id)))
|
2016-10-23 20:03:29 +02:00
|
|
|
{
|
2016-10-23 20:03:30 +02:00
|
|
|
CFDataRef data;
|
2013-03-11 04:58:51 +01:00
|
|
|
|
2016-10-23 20:03:30 +02:00
|
|
|
TRACE("exporting %s %p\n", debugstr_format(format->format_id), handle);
|
|
|
|
|
|
|
|
if ((data = format->export_func(handle)))
|
|
|
|
{
|
2016-10-23 20:03:32 +02:00
|
|
|
ret = macdrv_set_pasteboard_data(format->type, data, clipboard_cocoa_window);
|
2016-10-23 20:03:30 +02:00
|
|
|
CFRelease(data);
|
|
|
|
}
|
2013-03-11 04:58:51 +01:00
|
|
|
}
|
|
|
|
|
2017-02-02 21:51:45 +01:00
|
|
|
last_get_seqno = GetClipboardSequenceNumber();
|
|
|
|
|
2016-10-23 20:03:30 +02:00
|
|
|
CloseClipboard();
|
2013-03-11 04:58:51 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2016-10-23 20:03:32 +02:00
|
|
|
|
|
|
|
|
2016-10-23 20:03:34 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* macdrv_lost_pasteboard_ownership
|
|
|
|
*
|
|
|
|
* Handler for the LOST_PASTEBOARD_OWNERSHIP event.
|
|
|
|
*/
|
|
|
|
void macdrv_lost_pasteboard_ownership(HWND hwnd)
|
|
|
|
{
|
|
|
|
TRACE("win %p\n", hwnd);
|
|
|
|
if (!macdrv_is_pasteboard_owner(clipboard_cocoa_window))
|
2017-05-30 09:56:25 +02:00
|
|
|
grab_win32_clipboard();
|
2016-10-23 20:03:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-23 20:03:32 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* macdrv_init_clipboard
|
|
|
|
*/
|
|
|
|
void macdrv_init_clipboard(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");
|
|
|
|
}
|