darwin-pasteboard.cpp revision dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2e
/** @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
#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;
}
{
pPasteboard = 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 u32Format, 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 (pu16Tmp)
{
/* 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 (pu16Tmp, RTUtf16Len (pu16Tmp), 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 (cwDestLen == 0)
{
Log (("writeToPasteboard: received empty clipboard data from the guest, returning false.\n"));
return VINF_SUCCESS;
}
/* Allocate the necessary memory */
if (pu16DestText == 0)
{
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 *pu8DestText;
if (RT_SUCCESS (rc))
{
/* Create a CData object which we could pass to the pasteboard */
{
/* Put the Utf-8 version to the pasteboard */
CFSTR ("public.utf8-plain-text"),
textData, 0);
}
}
rc = VINF_SUCCESS;
}
else
return rc;
}