darwin-pasteboard.cpp revision 6a30d0e9d748ecb8a0c62b4233a97fed255a8a4c
/* $Id$ */
/** @file
* Shared Clipboard: Mac OS X host implementation.
*/
/*
* Copyright (C) 2008 innotek GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/// @todo: same as defined in VBoxClipboardSvc.h
/// @todo r-bird: why don't you include it?
#define VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT 0x01
#define VBOX_SHARED_CLIPBOARD_FMT_BITMAP 0x02
#define VBOX_SHARED_CLIPBOARD_FMT_HTML 0x04
#define LOG_GROUP LOG_GROUP_HGCM
#include "clipboard-helper.h"
//#define SHOW_CLIPBOARD_CONTENT
{
int rc = VINF_SUCCESS;
return rc;
}
{
*pPasteboardRef = NULL;
}
{
Log (("queryPasteboardFormats\n"));
/* Make sure all is in sync */
/* If nothing changed return */
if (!(syncFlags & kPasteboardModified))
return VINF_SUCCESS;
/* Are some items in the pasteboard? */
if (itemCount < 1)
return VINF_SUCCESS;
/* The id of the first element in the pastboard */
int rc = VERR_NOT_SUPPORTED;
{
/* Retrieve all flavors in the pasteboard, maybe there
* is something we can use. */
{
{
flavorIndex));
/* Currently only unicode supported */
{
Log (("Unicode flavor detected.\n"));
}
}
rc = VINF_SUCCESS;
}
}
return rc;
}
int readFromPasteboard (PasteboardRef pPasteboard, uint32_t fFormat, void *pv, uint32_t cb, uint32_t *pcbActual)
{
/* Make sure all is in sync */
/* Are some items in the pasteboard? */
if (itemCount < 1)
return VINF_SUCCESS;
/* The id of the first element in the pastboard */
int rc = VERR_NOT_SUPPORTED;
{
/* The guest request unicode */
{
/* Utf-16 is currently broken on more than one line.
* Has to be investigated. */
#if 0
/* Try utf-16 first */
if (!(err = PasteboardCopyItemFlavorData (pPasteboard, itemID, CFSTR ("public.utf16-plain-text"), &outData)))
{
Log (("Clipboard content is utf-16\n"));
}
/* Second try is utf-8 */
else
#endif
if (!(err = PasteboardCopyItemFlavorData (pPasteboard, itemID, CFSTR ("public.utf8-plain-text"), &outData)))
{
Log (("readFromPastboard: clipboard content is utf-8\n"));
}
if (pwszTmp)
{
/* Check how much longer will the converted text will be. */
if (RT_FAILURE (rc))
{
Log (("readFromPastboard: clipboard conversion failed. vboxClipboardUtf16GetWinSize returned %Vrc. Abandoning.\n", rc));
}
/* Set the actually needed data size */
/* Return success state */
rc = VINF_SUCCESS;
/* Do not copy data if the dst buffer is not big enough. */
{
rc = vboxClipboardUtf16LinToWin (pwszTmp, RTUtf16Len (pwszTmp), static_cast <PRTUTF16> (pv), cb / 2);
if (RT_FAILURE (rc))
{
Log (("readFromPastboard: clipboard conversion failed. vboxClipboardUtf16LinToWin() returned %Vrc. Abandoning.\n", rc));
}
#ifdef SHOW_CLIPBOARD_CONTENT
#endif
}
/* Free the temp string */
}
}
}
return rc;
}
{
/* Clear the pastboard */
if (PasteboardClear (pPasteboard))
return VERR_NOT_SUPPORTED;
/* Make sure all is in sync */
int rc = VERR_NOT_SUPPORTED;
/* Handle the unicode text */
{
/* How long will the converted text be? */
if (RT_FAILURE (rc))
{
Log (("writeToPasteboard: clipboard conversion failed. vboxClipboardUtf16GetLinSize returned %Vrc. Abandoning.\n", rc));
}
/* Empty clipboard? Not critical */
if (cwDest == 0)
{
Log (("writeToPasteboard: received empty clipboard data from the guest, returning false.\n"));
return VINF_SUCCESS;
}
/* Allocate the necessary memory */
if (pwszDestText == NULL)
{
return VERR_NO_MEMORY;
}
/* Convert the EOL */
if (RT_FAILURE (rc))
{
Log (("writeToPasteboard: clipboard conversion failed. vboxClipboardUtf16WinToLin() returned %Vrc. Abandoning.\n", rc));
}
/* Item id is 1. Nothing special here. */
/* Create a CData object which we could pass to the pasteboard */
{
/* Put the Utf-16 version to the pasteboard */
CFSTR ("public.utf16-plain-text"),
textData, 0);
}
/* Create a Utf-8 version */
char *pszDestText;
if (RT_SUCCESS (rc))
{
/* Create a CData object which we could pass to the pasteboard */
reinterpret_cast<UInt8*> (pszDestText), RTUtf16CalcUtf8Len (pwszDestText)))) /** @todo r=bird: why not strlen(pszDestText)? */
{
/* Put the Utf-8 version to the pasteboard */
CFSTR ("public.utf8-plain-text"),
textData, 0);
}
}
rc = VINF_SUCCESS;
}
else
return rc;
}