darwin-pasteboard.cpp revision 7f8c3a19fc6774798746c0782be09b88e54bf960
/* $Id$ */
/** @file
* Shared Clipboard: Mac OS X host implementation.
*/
/*
* Includes contributions from Fran�ois Revol
*
* Copyright (C) 2008-2012 Oracle Corporation
*
* 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 "VBox/GuestHost/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. (Always VINF_SUCCESS atm.)
*/
{
Log(("queryNewPasteboardFormats\n"));
*pfChanged = true;
/* Make sure all is in sync */
/* If nothing changed return */
if (!(syncFlags & kPasteboardModified))
{
*pfChanged = 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 = VINF_SUCCESS;
{
/* Retrieve all flavors in the pasteboard, maybe there
* is something we can use. */
{
{
flavorIndex));
/* Currently only unicode supported */
{
Log(("Unicode flavor detected.\n"));
}
{
Log(("BMP flavor detected.\n"));
}
}
}
}
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 */
{
/* Try utf-16 first */
{
Log(("Clipboard content is utf-16\n"));
}
/* Second try is utf-8 */
else
{
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 %Rrc. 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. */
{
if (RT_FAILURE(rc))
{
Log(("readFromPasteboard: clipboard conversion failed. vboxClipboardUtf16LinToWin() returned %Rrc. Abandoning.\n", rc));
}
#ifdef SHOW_CLIPBOARD_CONTENT
#endif
}
/* Free the temp string */
}
}
/* The guest request BITMAP */
else if (fFormat & VBOX_SHARED_CLIPBOARD_FMT_BITMAP)
{
/* Get the data from the pasteboard */
{
Log(("Clipboard content is BMP\n"));
}
if (pTmp)
{
const void *pDib;
if (RT_FAILURE(rc))
{
Log(("readFromPasteboard: unknown bitmap format. vboxClipboardBmpGetDib returned %Rrc. Abandoning.\n", rc));
}
/* Return success state */
rc = VINF_SUCCESS;
/* Do not copy data if the dst buffer is not big enough. */
{
#ifdef SHOW_CLIPBOARD_CONTENT
#endif
}
}
}
}
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 %Rrc. 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 %Rrc. 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 */
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 */
textData, 0);
}
}
rc = VINF_SUCCESS;
}
/* Handle the bitmap */
else if (fFormat & VBOX_SHARED_CLIPBOARD_FMT_BITMAP)
{
/* Create a full BMP from it */
void *pBmp;
/* Item id is 1. Nothing special here. */
if (RT_SUCCESS(rc))
{
/* Create a CData object which we could pass to the pasteboard */
{
/* Put the Utf-8 version to the pasteboard */
bmpData, 0);
}
}
rc = VINF_SUCCESS;
}
else
return rc;
}