darwin-pasteboard.cpp revision be641d8f2dc377d6a4403f3822d8bed08f51e28a
/* $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.
*/
#define LOG_GROUP LOG_GROUP_HGCM
#include "VBox/HostServices/VBoxClipboardSvc.h"
#include "clipboard-helper.h"
/* For debugging */
//#define SHOW_CLIPBOARD_CONTENT
/**
* Initialize the global pasteboard and return a reference to it.
*
* @param pPasteboardRef Reference to the global pasteboard.
*
* @returns IPRT status code.
*/
{
int rc = VINF_SUCCESS;
return rc;
}
/**
* Release the reference to the global pasteboard.
*
* @param pPasteboardRef Reference to the global pasteboard.
*/
{
*pPasteboardRef = NULL;
}
/**
* Inspect the global pasteboard for new content. Check if there is some type
* that is supported by vbox and return it.
*
* @param pPasteboardRef Reference to the global pasteboard.
* @param pfFormats Pointer for the bit combination of the
* supported types.
* @param pbChanged True if something has changed after the
* last call.
*
* @returns IPRT status code.
*/
{
Log (("queryNewPasteboardFormats\n"));
*pbChanged = true;
/* Make sure all is in sync */
/* If nothing changed return */
if (!(syncFlags & kPasteboardModified))
{
*pbChanged = false;
return VINF_SUCCESS;
}
/* Are some items in the pasteboard? */
if (itemCount < 1)
return VINF_SUCCESS;
/* The id of the first element in the pasteboard */
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;
}
/**
* Read content from the host clipboard and write it to the internal clipboard
* structure for further processing.
*
* @param pPasteboardRef Reference to the global pasteboard.
* @param fFormats The format type which should be read.
* @param pv The destination buffer.
* @param cb The size of the destination buffer.
* @param pcbActual The size which is needed to transfer the content.
*
* @returns IPRT status code.
*/
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 pasteboard */
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 (("readFromPasteboard: clipboard content is utf-8\n"));
}
if (pwszTmp)
{
/* Check how much longer will the converted text will be. */
if (RT_FAILURE (rc))
{
Log (("readFromPasteboard: 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 (("readFromPasteboard: clipboard conversion failed. vboxClipboardUtf16LinToWin() returned %Vrc. Abandoning.\n", rc));
}
#ifdef SHOW_CLIPBOARD_CONTENT
#endif
}
/* Free the temp string */
}
}
}
return rc;
}
/**
* Write clipboard content to the host clipboard from the internal clipboard
* structure.
*
* @param pPasteboardRef Reference to the global pasteboard.
* @param pv The source buffer.
* @param cb The size of the source buffer.
* @param fFormats The format type which should be written.
*
* @returns IPRT status code.
*/
{
/* Clear the pasteboard */
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 */
{
/* Put the Utf-8 version to the pasteboard */
CFSTR ("public.utf8-plain-text"),
textData, 0);
}
}
rc = VINF_SUCCESS;
}
else
return rc;
}