24 int mac_cliprdr_send_client_format_list(CliprdrClientContext *cliprdr)
29 const char *formatName;
33 WINPR_ASSERT(cliprdr);
38 numFormats = ClipboardGetFormatIds(mfc->clipboard, &pFormatIds);
45 for (UINT32 index = 0; index < numFormats; index++)
47 formatId = pFormatIds[index];
48 formatName = ClipboardGetFormatName(mfc->clipboard, formatId);
50 formats[index].formatId = formatId;
51 formats[index].formatName = NULL;
53 if ((formatId > CF_MAX) && formatName)
54 formats[index].formatName = _strdup(formatName);
57 formatList.common.msgFlags = 0;
58 formatList.numFormats = numFormats;
59 formatList.formats = formats;
60 formatList.common.msgType = CB_FORMAT_LIST;
62 mfc->cliprdr->ClientFormatList(mfc->cliprdr, &formatList);
64 for (UINT32 index = 0; index < numFormats; index++)
66 free(formats[index].formatName);
75 static int mac_cliprdr_send_client_format_list_response(CliprdrClientContext *cliprdr, BOOL status)
79 formatListResponse.common.msgType = CB_FORMAT_LIST_RESPONSE;
80 formatListResponse.common.msgFlags = status ? CB_RESPONSE_OK : CB_RESPONSE_FAIL;
81 formatListResponse.common.dataLen = 0;
83 cliprdr->ClientFormatListResponse(cliprdr, &formatListResponse);
88 static int mac_cliprdr_send_client_format_data_request(CliprdrClientContext *cliprdr,
92 WINPR_ASSERT(cliprdr);
97 formatDataRequest.common.msgType = CB_FORMAT_DATA_REQUEST;
98 formatDataRequest.common.msgFlags = 0;
100 formatDataRequest.requestedFormatId = formatId;
101 mfc->requestedFormatId = formatId;
102 (void)ResetEvent(mfc->clipboardRequestEvent);
104 cliprdr->ClientFormatDataRequest(cliprdr, &formatDataRequest);
109 static int mac_cliprdr_send_client_capabilities(CliprdrClientContext *cliprdr)
114 capabilities.cCapabilitiesSets = 1;
117 generalCapabilitySet.capabilitySetType = CB_CAPSTYPE_GENERAL;
118 generalCapabilitySet.capabilitySetLength = 12;
120 generalCapabilitySet.version = CB_CAPS_VERSION_2;
121 generalCapabilitySet.generalFlags = CB_USE_LONG_FORMAT_NAMES;
123 cliprdr->ClientCapabilities(cliprdr, &capabilities);
133 static UINT mac_cliprdr_monitor_ready(CliprdrClientContext *cliprdr,
138 mfc->clipboardSync = TRUE;
139 mac_cliprdr_send_client_capabilities(cliprdr);
140 mac_cliprdr_send_client_format_list(cliprdr);
142 return CHANNEL_RC_OK;
150 static UINT mac_cliprdr_server_capabilities(CliprdrClientContext *cliprdr,
156 for (UINT32 index = 0; index < capabilities->cCapabilitiesSets; index++)
158 capabilitySet = &(capabilities->capabilitySets[index]);
160 if ((capabilitySet->capabilitySetType == CB_CAPSTYPE_GENERAL) &&
161 (capabilitySet->capabilitySetLength >= CB_CAPSTYPE_GENERAL_LEN))
166 mfc->clipboardCapabilities = generalCapabilitySet->generalFlags;
171 return CHANNEL_RC_OK;
179 static UINT mac_cliprdr_server_format_list(CliprdrClientContext *cliprdr,
185 if (mfc->serverFormats)
187 for (UINT32 index = 0; index < mfc->numServerFormats; index++)
189 free(mfc->serverFormats[index].formatName);
192 free(mfc->serverFormats);
193 mfc->serverFormats = NULL;
194 mfc->numServerFormats = 0;
197 if (formatList->numFormats < 1)
198 return CHANNEL_RC_OK;
200 mfc->numServerFormats = formatList->numFormats;
203 if (!mfc->serverFormats)
204 return CHANNEL_RC_NO_MEMORY;
206 for (UINT32 index = 0; index < mfc->numServerFormats; index++)
208 mfc->serverFormats[index].formatId = formatList->formats[index].formatId;
209 mfc->serverFormats[index].formatName = NULL;
211 if (formatList->formats[index].formatName)
212 mfc->serverFormats[index].formatName = _strdup(formatList->formats[index].formatName);
215 mac_cliprdr_send_client_format_list_response(cliprdr, TRUE);
217 for (UINT32 index = 0; index < mfc->numServerFormats; index++)
219 format = &(mfc->serverFormats[index]);
221 if (format->formatId == CF_UNICODETEXT)
223 mac_cliprdr_send_client_format_data_request(cliprdr, CF_UNICODETEXT);
226 else if (format->formatId == CF_OEMTEXT)
228 mac_cliprdr_send_client_format_data_request(cliprdr, CF_OEMTEXT);
231 else if (format->formatId == CF_TEXT)
233 mac_cliprdr_send_client_format_data_request(cliprdr, CF_TEXT);
238 return CHANNEL_RC_OK;
247 mac_cliprdr_server_format_list_response(CliprdrClientContext *cliprdr,
250 return CHANNEL_RC_OK;
259 mac_cliprdr_server_lock_clipboard_data(CliprdrClientContext *cliprdr,
262 return CHANNEL_RC_OK;
271 mac_cliprdr_server_unlock_clipboard_data(CliprdrClientContext *cliprdr,
274 return CHANNEL_RC_OK;
283 mac_cliprdr_server_format_data_request(CliprdrClientContext *cliprdr,
291 WINPR_ASSERT(cliprdr);
296 formatId = formatDataRequest->requestedFormatId;
297 data = (BYTE *)ClipboardGetData(mfc->clipboard, formatId, &size);
299 response.common.msgFlags = CB_RESPONSE_OK;
300 response.common.dataLen = size;
301 response.requestedFormatData = data;
305 response.common.msgFlags = CB_RESPONSE_FAIL;
306 response.common.dataLen = 0;
307 response.requestedFormatData = NULL;
310 cliprdr->ClientFormatDataResponse(cliprdr, &response);
314 return CHANNEL_RC_OK;
323 mac_cliprdr_server_format_data_response(CliprdrClientContext *cliprdr,
331 if (formatDataResponse->common.msgFlags & CB_RESPONSE_FAIL)
333 (void)SetEvent(mfc->clipboardRequestEvent);
334 return ERROR_INTERNAL_ERROR;
337 for (UINT32 index = 0; index < mfc->numServerFormats; index++)
339 if (mfc->requestedFormatId == mfc->serverFormats[index].formatId)
340 format = &(mfc->serverFormats[index]);
345 (void)SetEvent(mfc->clipboardRequestEvent);
346 return ERROR_INTERNAL_ERROR;
349 if (format->formatName)
350 formatId = ClipboardRegisterFormat(mfc->clipboard, format->formatName);
352 formatId = format->formatId;
354 const size_t size = formatDataResponse->common.dataLen;
356 ClipboardSetData(mfc->clipboard, formatId, formatDataResponse->requestedFormatData, size);
358 (void)SetEvent(mfc->clipboardRequestEvent);
360 if ((formatId == CF_TEXT) || (formatId == CF_OEMTEXT) || (formatId == CF_UNICODETEXT))
362 formatId = ClipboardRegisterFormat(mfc->clipboard,
"text/plain");
365 char *data = ClipboardGetData(mfc->clipboard, formatId, &dstSize);
367 dstSize = strnlen(data, dstSize);
369 NSString *str = [[NSString alloc] initWithBytes:(void *)data
371 encoding:NSUTF8StringEncoding];
374 NSArray *types = [[NSArray alloc] initWithObjects:NSPasteboardTypeString, nil];
375 [view->pasteboard_wr declareTypes:types owner:view];
376 [view->pasteboard_wr setString:str forType:NSPasteboardTypeString];
379 return CHANNEL_RC_OK;
388 mac_cliprdr_server_file_contents_request(CliprdrClientContext *cliprdr,
391 return CHANNEL_RC_OK;
399 static UINT mac_cliprdr_server_file_contents_response(
402 return CHANNEL_RC_OK;
405 void mac_cliprdr_init(
mfContext *mfc, CliprdrClientContext *cliprdr)
407 cliprdr->custom = (
void *)mfc;
408 mfc->cliprdr = cliprdr;
410 mfc->clipboard = ClipboardCreate();
411 mfc->clipboardRequestEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
413 cliprdr->MonitorReady = mac_cliprdr_monitor_ready;
414 cliprdr->ServerCapabilities = mac_cliprdr_server_capabilities;
415 cliprdr->ServerFormatList = mac_cliprdr_server_format_list;
416 cliprdr->ServerFormatListResponse = mac_cliprdr_server_format_list_response;
417 cliprdr->ServerLockClipboardData = mac_cliprdr_server_lock_clipboard_data;
418 cliprdr->ServerUnlockClipboardData = mac_cliprdr_server_unlock_clipboard_data;
419 cliprdr->ServerFormatDataRequest = mac_cliprdr_server_format_data_request;
420 cliprdr->ServerFormatDataResponse = mac_cliprdr_server_format_data_response;
421 cliprdr->ServerFileContentsRequest = mac_cliprdr_server_file_contents_request;
422 cliprdr->ServerFileContentsResponse = mac_cliprdr_server_file_contents_response;
425 void mac_cliprdr_uninit(
mfContext *mfc, CliprdrClientContext *cliprdr)
427 cliprdr->custom = NULL;
430 ClipboardDestroy(mfc->clipboard);
431 (void)CloseHandle(mfc->clipboardRequestEvent);