2014-11-06 01:14:32 +03:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
*
|
|
|
|
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2015-06-02 14:05:10 +03:00
|
|
|
* Copyright 2015 Thincast Technologies GmbH
|
|
|
|
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
2014-11-06 01:14:32 +03:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import "Clipboard.h"
|
2022-02-01 18:08:24 +03:00
|
|
|
#import "MRDPView.h"
|
2014-11-06 01:14:32 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
int mac_cliprdr_send_client_format_list(CliprdrClientContext *cliprdr)
|
2014-11-06 01:14:32 +03:00
|
|
|
{
|
|
|
|
UINT32 formatId;
|
|
|
|
UINT32 numFormats;
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT32 *pFormatIds;
|
|
|
|
const char *formatName;
|
|
|
|
CLIPRDR_FORMAT *formats;
|
2020-04-20 17:02:02 +03:00
|
|
|
CLIPRDR_FORMAT_LIST formatList = { 0 };
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2022-10-13 17:25:36 +03:00
|
|
|
WINPR_ASSERT(cliprdr);
|
|
|
|
mfContext *mfc = (mfContext *)cliprdr->custom;
|
|
|
|
WINPR_ASSERT(mfc);
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
pFormatIds = NULL;
|
|
|
|
numFormats = ClipboardGetFormatIds(mfc->clipboard, &pFormatIds);
|
2019-11-06 17:24:51 +03:00
|
|
|
|
|
|
|
formats = (CLIPRDR_FORMAT *)calloc(numFormats, sizeof(CLIPRDR_FORMAT));
|
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
if (!formats)
|
|
|
|
return -1;
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 index = 0; index < numFormats; index++)
|
2014-11-06 01:14:32 +03:00
|
|
|
{
|
|
|
|
formatId = pFormatIds[index];
|
|
|
|
formatName = ClipboardGetFormatName(mfc->clipboard, formatId);
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
formats[index].formatId = formatId;
|
|
|
|
formats[index].formatName = NULL;
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
if ((formatId > CF_MAX) && formatName)
|
|
|
|
formats[index].formatName = _strdup(formatName);
|
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2024-05-22 17:30:21 +03:00
|
|
|
formatList.common.msgFlags = 0;
|
2014-11-06 01:14:32 +03:00
|
|
|
formatList.numFormats = numFormats;
|
|
|
|
formatList.formats = formats;
|
2022-07-01 12:04:22 +03:00
|
|
|
formatList.common.msgType = CB_FORMAT_LIST;
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
mfc->cliprdr->ClientFormatList(mfc->cliprdr, &formatList);
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 index = 0; index < numFormats; index++)
|
2014-11-21 00:05:13 +03:00
|
|
|
{
|
|
|
|
free(formats[index].formatName);
|
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
free(pFormatIds);
|
|
|
|
free(formats);
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static int mac_cliprdr_send_client_format_list_response(CliprdrClientContext *cliprdr, BOOL status)
|
2014-11-21 00:05:13 +03:00
|
|
|
{
|
|
|
|
CLIPRDR_FORMAT_LIST_RESPONSE formatListResponse;
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2022-07-01 12:04:22 +03:00
|
|
|
formatListResponse.common.msgType = CB_FORMAT_LIST_RESPONSE;
|
|
|
|
formatListResponse.common.msgFlags = status ? CB_RESPONSE_OK : CB_RESPONSE_FAIL;
|
|
|
|
formatListResponse.common.dataLen = 0;
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-21 00:05:13 +03:00
|
|
|
cliprdr->ClientFormatListResponse(cliprdr, &formatListResponse);
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-21 00:05:13 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static int mac_cliprdr_send_client_format_data_request(CliprdrClientContext *cliprdr,
|
|
|
|
UINT32 formatId)
|
2014-11-06 01:14:32 +03:00
|
|
|
{
|
2022-10-13 17:25:36 +03:00
|
|
|
CLIPRDR_FORMAT_DATA_REQUEST formatDataRequest = { 0 };
|
|
|
|
WINPR_ASSERT(cliprdr);
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2022-10-13 17:25:36 +03:00
|
|
|
mfContext *mfc = (mfContext *)cliprdr->custom;
|
|
|
|
WINPR_ASSERT(mfc);
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2022-07-01 12:04:22 +03:00
|
|
|
formatDataRequest.common.msgType = CB_FORMAT_DATA_REQUEST;
|
|
|
|
formatDataRequest.common.msgFlags = 0;
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
formatDataRequest.requestedFormatId = formatId;
|
|
|
|
mfc->requestedFormatId = formatId;
|
|
|
|
ResetEvent(mfc->clipboardRequestEvent);
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
cliprdr->ClientFormatDataRequest(cliprdr, &formatDataRequest);
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static int mac_cliprdr_send_client_capabilities(CliprdrClientContext *cliprdr)
|
2014-11-06 01:14:32 +03:00
|
|
|
{
|
|
|
|
CLIPRDR_CAPABILITIES capabilities;
|
|
|
|
CLIPRDR_GENERAL_CAPABILITY_SET generalCapabilitySet;
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
capabilities.cCapabilitiesSets = 1;
|
2019-11-06 17:24:51 +03:00
|
|
|
capabilities.capabilitySets = (CLIPRDR_CAPABILITY_SET *)&(generalCapabilitySet);
|
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
generalCapabilitySet.capabilitySetType = CB_CAPSTYPE_GENERAL;
|
|
|
|
generalCapabilitySet.capabilitySetLength = 12;
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
generalCapabilitySet.version = CB_CAPS_VERSION_2;
|
|
|
|
generalCapabilitySet.generalFlags = CB_USE_LONG_FORMAT_NAMES;
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
cliprdr->ClientCapabilities(cliprdr, &capabilities);
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT mac_cliprdr_monitor_ready(CliprdrClientContext *cliprdr,
|
|
|
|
const CLIPRDR_MONITOR_READY *monitorReady)
|
2014-11-06 01:14:32 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
mfContext *mfc = (mfContext *)cliprdr->custom;
|
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
mfc->clipboardSync = TRUE;
|
|
|
|
mac_cliprdr_send_client_capabilities(cliprdr);
|
|
|
|
mac_cliprdr_send_client_format_list(cliprdr);
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2015-06-02 14:05:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-06 01:14:32 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT mac_cliprdr_server_capabilities(CliprdrClientContext *cliprdr,
|
|
|
|
const CLIPRDR_CAPABILITIES *capabilities)
|
2014-11-06 01:14:32 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
CLIPRDR_CAPABILITY_SET *capabilitySet;
|
|
|
|
mfContext *mfc = (mfContext *)cliprdr->custom;
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 index = 0; index < capabilities->cCapabilitiesSets; index++)
|
2014-11-06 01:14:32 +03:00
|
|
|
{
|
|
|
|
capabilitySet = &(capabilities->capabilitySets[index]);
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
if ((capabilitySet->capabilitySetType == CB_CAPSTYPE_GENERAL) &&
|
|
|
|
(capabilitySet->capabilitySetLength >= CB_CAPSTYPE_GENERAL_LEN))
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
CLIPRDR_GENERAL_CAPABILITY_SET *generalCapabilitySet =
|
|
|
|
(CLIPRDR_GENERAL_CAPABILITY_SET *)capabilitySet;
|
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
mfc->clipboardCapabilities = generalCapabilitySet->generalFlags;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2015-06-02 14:05:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-06 01:14:32 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT mac_cliprdr_server_format_list(CliprdrClientContext *cliprdr,
|
|
|
|
const CLIPRDR_FORMAT_LIST *formatList)
|
2014-11-06 01:14:32 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
CLIPRDR_FORMAT *format;
|
|
|
|
mfContext *mfc = (mfContext *)cliprdr->custom;
|
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
if (mfc->serverFormats)
|
|
|
|
{
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 index = 0; index < mfc->numServerFormats; index++)
|
2014-11-06 01:14:32 +03:00
|
|
|
{
|
|
|
|
free(mfc->serverFormats[index].formatName);
|
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
free(mfc->serverFormats);
|
|
|
|
mfc->serverFormats = NULL;
|
|
|
|
mfc->numServerFormats = 0;
|
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
if (formatList->numFormats < 1)
|
2015-06-02 14:05:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
mfc->numServerFormats = formatList->numFormats;
|
2019-11-06 17:24:51 +03:00
|
|
|
mfc->serverFormats = (CLIPRDR_FORMAT *)calloc(mfc->numServerFormats, sizeof(CLIPRDR_FORMAT));
|
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
if (!mfc->serverFormats)
|
2015-06-02 14:05:10 +03:00
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 index = 0; index < mfc->numServerFormats; index++)
|
2014-11-06 01:14:32 +03:00
|
|
|
{
|
|
|
|
mfc->serverFormats[index].formatId = formatList->formats[index].formatId;
|
|
|
|
mfc->serverFormats[index].formatName = NULL;
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
if (formatList->formats[index].formatName)
|
|
|
|
mfc->serverFormats[index].formatName = _strdup(formatList->formats[index].formatName);
|
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-21 00:05:13 +03:00
|
|
|
mac_cliprdr_send_client_format_list_response(cliprdr, TRUE);
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 index = 0; index < mfc->numServerFormats; index++)
|
2014-11-06 01:14:32 +03:00
|
|
|
{
|
|
|
|
format = &(mfc->serverFormats[index]);
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
if (format->formatId == CF_UNICODETEXT)
|
|
|
|
{
|
|
|
|
mac_cliprdr_send_client_format_data_request(cliprdr, CF_UNICODETEXT);
|
|
|
|
break;
|
|
|
|
}
|
2014-12-21 22:17:51 +03:00
|
|
|
else if (format->formatId == CF_OEMTEXT)
|
|
|
|
{
|
|
|
|
mac_cliprdr_send_client_format_data_request(cliprdr, CF_OEMTEXT);
|
|
|
|
break;
|
|
|
|
}
|
2014-11-06 01:14:32 +03:00
|
|
|
else if (format->formatId == CF_TEXT)
|
|
|
|
{
|
|
|
|
mac_cliprdr_send_client_format_data_request(cliprdr, CF_TEXT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2015-06-02 14:05:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-06 01:14:32 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT
|
|
|
|
mac_cliprdr_server_format_list_response(CliprdrClientContext *cliprdr,
|
|
|
|
const CLIPRDR_FORMAT_LIST_RESPONSE *formatListResponse)
|
2014-11-06 01:14:32 +03:00
|
|
|
{
|
2015-06-02 14:05:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-06 01:14:32 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT
|
|
|
|
mac_cliprdr_server_lock_clipboard_data(CliprdrClientContext *cliprdr,
|
|
|
|
const CLIPRDR_LOCK_CLIPBOARD_DATA *lockClipboardData)
|
2014-11-06 01:14:32 +03:00
|
|
|
{
|
2015-06-02 14:05:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-06 01:14:32 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT
|
|
|
|
mac_cliprdr_server_unlock_clipboard_data(CliprdrClientContext *cliprdr,
|
|
|
|
const CLIPRDR_UNLOCK_CLIPBOARD_DATA *unlockClipboardData)
|
2014-11-06 01:14:32 +03:00
|
|
|
{
|
2015-06-02 14:05:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-06 01:14:32 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT
|
|
|
|
mac_cliprdr_server_format_data_request(CliprdrClientContext *cliprdr,
|
|
|
|
const CLIPRDR_FORMAT_DATA_REQUEST *formatDataRequest)
|
2014-11-06 01:14:32 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
BYTE *data;
|
2014-11-06 01:14:32 +03:00
|
|
|
UINT32 size;
|
|
|
|
UINT32 formatId;
|
2022-10-13 17:25:36 +03:00
|
|
|
CLIPRDR_FORMAT_DATA_RESPONSE response = { 0 };
|
|
|
|
|
|
|
|
WINPR_ASSERT(cliprdr);
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2022-10-13 17:25:36 +03:00
|
|
|
mfContext *mfc = (mfContext *)cliprdr->custom;
|
|
|
|
WINPR_ASSERT(mfc);
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
formatId = formatDataRequest->requestedFormatId;
|
2019-11-06 17:24:51 +03:00
|
|
|
data = (BYTE *)ClipboardGetData(mfc->clipboard, formatId, &size);
|
|
|
|
|
2022-07-01 12:04:22 +03:00
|
|
|
response.common.msgFlags = CB_RESPONSE_OK;
|
|
|
|
response.common.dataLen = size;
|
2014-11-06 01:14:32 +03:00
|
|
|
response.requestedFormatData = data;
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
if (!data)
|
|
|
|
{
|
2022-07-01 12:04:22 +03:00
|
|
|
response.common.msgFlags = CB_RESPONSE_FAIL;
|
|
|
|
response.common.dataLen = 0;
|
2014-11-06 01:14:32 +03:00
|
|
|
response.requestedFormatData = NULL;
|
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
cliprdr->ClientFormatDataResponse(cliprdr, &response);
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
free(data);
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2015-06-02 14:05:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-06 01:14:32 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT
|
|
|
|
mac_cliprdr_server_format_data_response(CliprdrClientContext *cliprdr,
|
|
|
|
const CLIPRDR_FORMAT_DATA_RESPONSE *formatDataResponse)
|
2014-11-06 01:14:32 +03:00
|
|
|
{
|
|
|
|
UINT32 formatId;
|
2019-11-06 17:24:51 +03:00
|
|
|
CLIPRDR_FORMAT *format = NULL;
|
|
|
|
mfContext *mfc = (mfContext *)cliprdr->custom;
|
|
|
|
MRDPView *view = (MRDPView *)mfc->view;
|
|
|
|
|
2022-07-01 12:04:22 +03:00
|
|
|
if (formatDataResponse->common.msgFlags & CB_RESPONSE_FAIL)
|
2014-11-21 00:05:13 +03:00
|
|
|
{
|
|
|
|
SetEvent(mfc->clipboardRequestEvent);
|
2015-06-02 14:05:10 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-11-21 00:05:13 +03:00
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2023-07-17 11:19:18 +03:00
|
|
|
for (UINT32 index = 0; index < mfc->numServerFormats; index++)
|
2014-11-06 01:14:32 +03:00
|
|
|
{
|
|
|
|
if (mfc->requestedFormatId == mfc->serverFormats[index].formatId)
|
|
|
|
format = &(mfc->serverFormats[index]);
|
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
if (!format)
|
|
|
|
{
|
|
|
|
SetEvent(mfc->clipboardRequestEvent);
|
2015-06-02 14:05:10 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-11-06 01:14:32 +03:00
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
if (format->formatName)
|
|
|
|
formatId = ClipboardRegisterFormat(mfc->clipboard, format->formatName);
|
|
|
|
else
|
|
|
|
formatId = format->formatId;
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2023-07-17 11:19:18 +03:00
|
|
|
const size_t size = formatDataResponse->common.dataLen;
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2016-10-06 14:31:25 +03:00
|
|
|
ClipboardSetData(mfc->clipboard, formatId, formatDataResponse->requestedFormatData, size);
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
SetEvent(mfc->clipboardRequestEvent);
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-12-21 22:17:51 +03:00
|
|
|
if ((formatId == CF_TEXT) || (formatId == CF_OEMTEXT) || (formatId == CF_UNICODETEXT))
|
2014-11-06 01:14:32 +03:00
|
|
|
{
|
2023-07-17 11:19:18 +03:00
|
|
|
formatId = ClipboardRegisterFormat(mfc->clipboard, "text/plain");
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2023-07-17 11:19:18 +03:00
|
|
|
UINT32 dstSize = 0;
|
2023-09-20 17:30:56 +03:00
|
|
|
char *data = ClipboardGetData(mfc->clipboard, formatId, &dstSize);
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2023-07-17 11:19:18 +03:00
|
|
|
dstSize = strnlen(data, dstSize); /* we need the size without the null terminator */
|
2019-11-06 17:24:51 +03:00
|
|
|
|
|
|
|
NSString *str = [[NSString alloc] initWithBytes:(void *)data
|
2023-07-17 11:19:18 +03:00
|
|
|
length:dstSize
|
2019-11-06 17:24:51 +03:00
|
|
|
encoding:NSUTF8StringEncoding];
|
2014-11-06 01:14:32 +03:00
|
|
|
free(data);
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2022-02-01 18:19:43 +03:00
|
|
|
NSArray *types = [[NSArray alloc] initWithObjects:NSPasteboardTypeString, nil];
|
2014-11-06 01:14:32 +03:00
|
|
|
[view->pasteboard_wr declareTypes:types owner:view];
|
2022-02-01 18:19:43 +03:00
|
|
|
[view->pasteboard_wr setString:str forType:NSPasteboardTypeString];
|
2014-11-06 01:14:32 +03:00
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2015-06-02 14:05:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-06 01:14:32 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT
|
|
|
|
mac_cliprdr_server_file_contents_request(CliprdrClientContext *cliprdr,
|
|
|
|
const CLIPRDR_FILE_CONTENTS_REQUEST *fileContentsRequest)
|
2014-11-06 01:14:32 +03:00
|
|
|
{
|
2015-06-02 14:05:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-06 01:14:32 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT mac_cliprdr_server_file_contents_response(
|
|
|
|
CliprdrClientContext *cliprdr, const CLIPRDR_FILE_CONTENTS_RESPONSE *fileContentsResponse)
|
2014-11-06 01:14:32 +03:00
|
|
|
{
|
2015-06-02 14:05:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-06 01:14:32 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
void mac_cliprdr_init(mfContext *mfc, CliprdrClientContext *cliprdr)
|
2014-11-06 01:14:32 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
cliprdr->custom = (void *)mfc;
|
2014-11-06 01:14:32 +03:00
|
|
|
mfc->cliprdr = cliprdr;
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
mfc->clipboard = ClipboardCreate();
|
|
|
|
mfc->clipboardRequestEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
cliprdr->MonitorReady = mac_cliprdr_monitor_ready;
|
|
|
|
cliprdr->ServerCapabilities = mac_cliprdr_server_capabilities;
|
|
|
|
cliprdr->ServerFormatList = mac_cliprdr_server_format_list;
|
|
|
|
cliprdr->ServerFormatListResponse = mac_cliprdr_server_format_list_response;
|
|
|
|
cliprdr->ServerLockClipboardData = mac_cliprdr_server_lock_clipboard_data;
|
|
|
|
cliprdr->ServerUnlockClipboardData = mac_cliprdr_server_unlock_clipboard_data;
|
|
|
|
cliprdr->ServerFormatDataRequest = mac_cliprdr_server_format_data_request;
|
|
|
|
cliprdr->ServerFormatDataResponse = mac_cliprdr_server_format_data_response;
|
|
|
|
cliprdr->ServerFileContentsRequest = mac_cliprdr_server_file_contents_request;
|
|
|
|
cliprdr->ServerFileContentsResponse = mac_cliprdr_server_file_contents_response;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
void mac_cliprdr_uninit(mfContext *mfc, CliprdrClientContext *cliprdr)
|
2014-11-06 01:14:32 +03:00
|
|
|
{
|
|
|
|
cliprdr->custom = NULL;
|
|
|
|
mfc->cliprdr = NULL;
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2014-11-06 01:14:32 +03:00
|
|
|
ClipboardDestroy(mfc->clipboard);
|
|
|
|
CloseHandle(mfc->clipboardRequestEvent);
|
|
|
|
}
|