darwin-pasteboard.cpp revision 7d9e0d289e799c0ee5b9307fe7358ddc53bd34dd
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * Shared Clipboard: Mac OS X host implementation.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * Copyright (C) 2008 Sun Microsystems, Inc.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * available from http://www.virtualbox.org. This file is free software;
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * you can redistribute it and/or modify it under the terms of the GNU
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * General Public License (GPL) as published by the Free Software
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * additional information or have any questions.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync/* For debugging */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync//#define SHOW_CLIPBOARD_CONTENT
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * Initialize the global pasteboard and return a reference to it.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * @param pPasteboardRef Reference to the global pasteboard.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * @returns IPRT status code.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync if (PasteboardCreate (kPasteboardClipboard, pPasteboardRef))
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * Release the reference to the global pasteboard.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * @param pPasteboardRef Reference to the global pasteboard.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsyncvoid destroyPasteboard (PasteboardRef *pPasteboardRef)
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * Inspect the global pasteboard for new content. Check if there is some type
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * that is supported by vbox and return it.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * @param pPasteboardRef Reference to the global pasteboard.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * @param pfFormats Pointer for the bit combination of the
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * supported types.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * @param pbChanged True if something has changed after the
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * last call.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * @returns IPRT status code. (Always VINF_SUCCESS atm.)
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsyncint queryNewPasteboardFormats (PasteboardRef pPasteboard, uint32_t *pfFormats, bool *pfChanged)
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync /* Make sure all is in sync */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync /* If nothing changed return */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync /* Are some items in the pasteboard? */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync err = PasteboardGetItemCount (pPasteboard, &itemCount);
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync /* The id of the first element in the pasteboard */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync if (!(err = PasteboardGetItemIdentifier (pPasteboard, 1, &itemID)))
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync /* Retrieve all flavors in the pasteboard, maybe there
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * is something we can use. */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync if (!(err = PasteboardCopyItemFlavors (pPasteboard, itemID, &flavorTypeArray)))
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync for (CFIndex flavorIndex = 0; flavorIndex < flavorCount; flavorIndex++)
6754e49069315bd28137abb0f9241e3aeb99a97evboxsync flavorType = static_cast <CFStringRef> (CFArrayGetValueAtIndex (flavorTypeArray,
6754e49069315bd28137abb0f9241e3aeb99a97evboxsync /* Currently only unicode supported */
6754e49069315bd28137abb0f9241e3aeb99a97evboxsync if (UTTypeConformsTo (flavorType, CFSTR ("public.utf8-plain-text")) ||
6754e49069315bd28137abb0f9241e3aeb99a97evboxsync UTTypeConformsTo (flavorType, CFSTR ("public.utf16-plain-text")))
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync *pfFormats |= VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT;
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync Log (("queryNewPasteboardFormats: rc = %02X\n", rc));
return rc;
int readFromPasteboard (PasteboardRef pPasteboard, uint32_t fFormat, void *pv, uint32_t cb, uint32_t *pcbActual)
return VINF_SUCCESS;
if (!(err = PasteboardCopyItemFlavorData (pPasteboard, itemID, CFSTR ("public.utf16-plain-text"), &outData)))
if (!(err = PasteboardCopyItemFlavorData (pPasteboard, itemID, CFSTR ("public.utf8-plain-text"), &outData)))
if (pwszTmp)
Log (("readFromPasteboard: clipboard conversion failed. vboxClipboardUtf16GetWinSize returned %Rrc. Abandoning.\n", rc));
rc = vboxClipboardUtf16LinToWin (pwszTmp, RTUtf16Len (pwszTmp), static_cast <PRTUTF16> (pv), cb / 2);
Log (("readFromPasteboard: clipboard conversion failed. vboxClipboardUtf16LinToWin() 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);
return rc;