darwin-pasteboard.cpp revision 04582cbe4711c5c860680c6cb8d8df1800de2019
904ef975124106054684a976dfb30f70372372e1vboxsync * Shared Clipboard: Mac OS X host implementation.
c7814cf6e1240a519cbec0441e033d0e2470ed00vboxsync * Includes contributions from Fran�ois Revol
904ef975124106054684a976dfb30f70372372e1vboxsync * Copyright (C) 2008-2012 Oracle Corporation
904ef975124106054684a976dfb30f70372372e1vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
904ef975124106054684a976dfb30f70372372e1vboxsync * available from http://www.virtualbox.org. This file is free software;
904ef975124106054684a976dfb30f70372372e1vboxsync * you can redistribute it and/or modify it under the terms of the GNU
904ef975124106054684a976dfb30f70372372e1vboxsync * General Public License (GPL) as published by the Free Software
904ef975124106054684a976dfb30f70372372e1vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
904ef975124106054684a976dfb30f70372372e1vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
904ef975124106054684a976dfb30f70372372e1vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
904ef975124106054684a976dfb30f70372372e1vboxsync/* For debugging */
904ef975124106054684a976dfb30f70372372e1vboxsync//#define SHOW_CLIPBOARD_CONTENT
904ef975124106054684a976dfb30f70372372e1vboxsync * Initialize the global pasteboard and return a reference to it.
904ef975124106054684a976dfb30f70372372e1vboxsync * @param pPasteboardRef Reference to the global pasteboard.
904ef975124106054684a976dfb30f70372372e1vboxsync * @returns IPRT status code.
904ef975124106054684a976dfb30f70372372e1vboxsync if (PasteboardCreate(kPasteboardClipboard, pPasteboardRef))
d544fe535c163a24bf8cd831b39264da292b8adfvboxsync * Release the reference to the global pasteboard.
d544fe535c163a24bf8cd831b39264da292b8adfvboxsync * @param pPasteboardRef Reference to the global pasteboard.
d544fe535c163a24bf8cd831b39264da292b8adfvboxsyncvoid destroyPasteboard(PasteboardRef *pPasteboardRef)
d544fe535c163a24bf8cd831b39264da292b8adfvboxsync * Inspect the global pasteboard for new content. Check if there is some type
d544fe535c163a24bf8cd831b39264da292b8adfvboxsync * that is supported by vbox and return it.
d544fe535c163a24bf8cd831b39264da292b8adfvboxsync * @param pPasteboardRef Reference to the global pasteboard.
d544fe535c163a24bf8cd831b39264da292b8adfvboxsync * @param pfFormats Pointer for the bit combination of the
d544fe535c163a24bf8cd831b39264da292b8adfvboxsync * supported types.
d544fe535c163a24bf8cd831b39264da292b8adfvboxsync * @param pbChanged True if something has changed after the
d544fe535c163a24bf8cd831b39264da292b8adfvboxsync * last call.
d544fe535c163a24bf8cd831b39264da292b8adfvboxsync * @returns IPRT status code. (Always VINF_SUCCESS atm.)
d544fe535c163a24bf8cd831b39264da292b8adfvboxsyncint queryNewPasteboardFormats(PasteboardRef pPasteboard, uint32_t *pfFormats, bool *pfChanged)
904ef975124106054684a976dfb30f70372372e1vboxsync /* Make sure all is in sync */
904ef975124106054684a976dfb30f70372372e1vboxsync /* If nothing changed return */
904ef975124106054684a976dfb30f70372372e1vboxsync /* Are some items in the pasteboard? */
904ef975124106054684a976dfb30f70372372e1vboxsync err = PasteboardGetItemCount(pPasteboard, &itemCount);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync /* The id of the first element in the pasteboard */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync if (!(err = PasteboardGetItemIdentifier(pPasteboard, 1, &itemID)))
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync /* Retrieve all flavors in the pasteboard, maybe there
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * is something we can use. */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync if (!(err = PasteboardCopyItemFlavors(pPasteboard, itemID, &flavorTypeArray)))
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync for (CFIndex flavorIndex = 0; flavorIndex < flavorCount; flavorIndex++)
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync flavorType = static_cast <CFStringRef>(CFArrayGetValueAtIndex(flavorTypeArray,
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync /* Currently only unicode supported */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync if (UTTypeConformsTo(flavorType, kUTTypeUTF8PlainText) ||
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync UTTypeConformsTo(flavorType, kUTTypeUTF16PlainText))
904ef975124106054684a976dfb30f70372372e1vboxsync *pfFormats |= VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT;
904ef975124106054684a976dfb30f70372372e1vboxsync Log(("queryNewPasteboardFormats: rc = %02X\n", rc));
904ef975124106054684a976dfb30f70372372e1vboxsync * Read content from the host clipboard and write it to the internal clipboard
904ef975124106054684a976dfb30f70372372e1vboxsync * structure for further processing.
904ef975124106054684a976dfb30f70372372e1vboxsync * @param pPasteboardRef Reference to the global pasteboard.
904ef975124106054684a976dfb30f70372372e1vboxsync * @param fFormats The format type which should be read.
904ef975124106054684a976dfb30f70372372e1vboxsync * @param pv The destination buffer.
904ef975124106054684a976dfb30f70372372e1vboxsync * @param cb The size of the destination buffer.
904ef975124106054684a976dfb30f70372372e1vboxsync * @param pcbActual The size which is needed to transfer the content.
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * @returns IPRT status code.
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncint readFromPasteboard(PasteboardRef pPasteboard, uint32_t fFormat, void *pv, uint32_t cb, uint32_t *pcbActual)
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync Log(("readFromPasteboard: fFormat = %02X\n", fFormat));
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync /* Make sure all is in sync */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync /* Are some items in the pasteboard? */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync err = PasteboardGetItemCount(pPasteboard, &itemCount);
904ef975124106054684a976dfb30f70372372e1vboxsync /* The id of the first element in the pasteboard */
904ef975124106054684a976dfb30f70372372e1vboxsync if (!(err = PasteboardGetItemIdentifier(pPasteboard, 1, &itemID)))
904ef975124106054684a976dfb30f70372372e1vboxsync /* The guest request unicode */
904ef975124106054684a976dfb30f70372372e1vboxsync if (fFormat & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)
904ef975124106054684a976dfb30f70372372e1vboxsync /* Try utf-16 first */
904ef975124106054684a976dfb30f70372372e1vboxsync if (!(err = PasteboardCopyItemFlavorData(pPasteboard, itemID, kUTTypeUTF16PlainText, &outData)))
if (pwszString)
if (pszString)
if (pwszTmp)
Log(("readFromPasteboard: clipboard conversion failed. vboxClipboardUtf16GetWinSize returned %Rrc. Abandoning.\n", rc));
Log(("readFromPasteboard: clipboard conversion failed. vboxClipboardUtf16LinToWin() returned %Rrc. Abandoning.\n", rc));
#ifdef SHOW_CLIPBOARD_CONTENT
if (pTmp)
const void *pDib;
Log(("readFromPasteboard: unknown bitmap format. vboxClipboardBmpGetDib returned %Rrc. Abandoning.\n", rc));
#ifdef SHOW_CLIPBOARD_CONTENT
return rc;
return VERR_NOT_SUPPORTED;
Log(("writeToPasteboard: clipboard conversion failed. vboxClipboardUtf16GetLinSize returned %Rrc. Abandoning.\n", rc));
if (cwDest == 0)
return VINF_SUCCESS;
return VERR_NO_MEMORY;
Log(("writeToPasteboard: clipboard conversion failed. vboxClipboardUtf16WinToLin() returned %Rrc. Abandoning.\n", rc));
textData, 0);
char *pszDestText;
textData, 0);
void *pBmp;
bmpData, 0);
return rc;