win32.cpp revision dd2204401754cb451c14fddb6946ad837f63f7b5
/** @file
* Shared Clipboard: Win32 host.
*/
/*
* Copyright (C) 2006-2007 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.
*/
#include <windows.h>
#include <process.h>
#include "VBoxClipboard.h"
static char gachWindowClassName[] = "VBoxSharedClipboardClass";
struct _VBOXCLIPBOARDCONTEXT
{
bool fTerminate;
};
/* Only one client is supported. There seems to be no need for more clients. */
static VBOXCLIPBOARDCONTEXT g_ctx;
#ifdef LOG_ENABLED
{
{
Log(("DUMP: VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT:\n"));
{
}
else
{
}
}
else if (u32Format & VBOX_SHARED_CLIPBOARD_FMT_BITMAP)
{
dprintf(("DUMP: VBOX_SHARED_CLIPBOARD_FMT_BITMAP\n"));
}
else if (u32Format & VBOX_SHARED_CLIPBOARD_FMT_HTML)
{
Log(("DUMP: VBOX_SHARED_CLIPBOARD_FMT_HTML:\n"));
{
}
else
{
}
}
else
{
}
}
#else
#define vboxClipboardDump(__pv, __cb, __format) do { NOREF(__pv); NOREF(__cb); NOREF(__format); } while (0)
#endif /* LOG_ENABLED */
{
dprintf (("vboxClipboardGetData.\n"));
*pcbActualDst = cbSrc;
{
/* Do not copy data. The dst buffer is not enough. */
return;
}
return;
}
{
Assert(pCtx->pClient->data.pv == NULL && pCtx->pClient->data.cb == 0 && pCtx->pClient->data.u32Format == 0);
LogFlow(("vboxClipboardReadDataFromClient wait completed\n"));
return VINF_SUCCESS;
}
{
LogFlow(("vboxClipboardChanged\n"));
{
return;
}
/* Query list of available formats and report to host. */
{
uint32_t u32Formats = 0;
{
switch (format)
{
case CF_UNICODETEXT:
case CF_TEXT:
break;
case CF_DIB:
case CF_BITMAP:
break;
default:
if (format >= 0xC000)
{
if (cActual)
{
{
}
}
}
break;
}
}
CloseClipboard ();
}
}
{
switch (msg)
{
case WM_CHANGECBCHAIN:
{
Log(("WM_CHANGECBCHAIN\n"));
{
/* The window that was next to our in the chain is being removed.
* Relink to the new next window.
*/
}
else
{
if (pCtx->hwndNextInChain)
{
/* Pass the message further. */
}
}
} break;
case WM_DRAWCLIPBOARD:
{
if (GetClipboardOwner () != hwnd)
{
/* Clipboard was updated by another application. */
}
if (pCtx->hwndNextInChain)
{
/* Pass the message to next windows in the clipboard chain. */
}
} break;
case WM_CLOSE:
{
/* Do nothing. Ignore the message. */
} break;
case WM_RENDERFORMAT:
{
/* Insert the requested clipboard format data into the clipboard. */
switch (format)
{
case CF_UNICODETEXT:
break;
case CF_DIB:
break;
default:
if (format >= 0xC000)
{
if (cActual)
{
{
}
}
}
break;
}
{
/* Unsupported clipboard format is requested. */
Log(("WM_RENDERFORMAT unsupported format requested or client is not active.\n"));
EmptyClipboard ();
}
else
{
if ( VBOX_SUCCESS (vboxrc)
{
if (hMem)
{
if (pMem)
{
Log(("WM_RENDERFORMAT setting data\n"));
{
}
/* The memory must be unlocked before inserting to the Clipboard. */
GlobalUnlock (hMem);
/* 'hMem' contains the host clipboard data.
* size is 'cb' and format is 'format'.
*/
if (hClip)
{
/* The hMem ownership has gone to the system. Nothing to do. */
break;
}
}
GlobalFree (hMem);
}
}
/* Something went wrong. */
EmptyClipboard ();
}
} break;
case WM_RENDERALLFORMATS:
{
Log(("WM_RENDERALLFORMATS\n"));
/* Do nothing. The clipboard formats will be unavailable now, because the
* windows is to be destroyed and therefore the guest side becames inactive.
*/
if (OpenClipboard (hwnd))
{
}
} break;
case WM_USER:
{
{
/* Host has pending formats message. Ignore the guest announcement,
* because host clipboard has more priority.
*/
break;
}
/* Announce available formats. Do not insert data, they will be inserted in WM_RENDER*. */
if (OpenClipboard (hwnd))
{
Log(("WM_USER emptied clipboard\n"));
{
dprintf(("window proc WM_USER: VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT\n"));
}
{
dprintf(("window proc WM_USER: VBOX_SHARED_CLIPBOARD_FMT_BITMAP\n"));
}
{
if (format != 0)
{
}
}
}
else
{
dprintf(("window proc WM_USER: failed to open clipboard\n"));
}
} break;
default:
{
}
}
return rc;
}
{
/* Create a window and make it a clipboard viewer. */
int rc = VINF_SUCCESS;
LogFlow(("VBoxClipboardThread\n"));
/* Register the Window Class. */
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
if (atomWindowClass == 0)
{
Log(("Failed to register window class\n"));
}
else
{
/* Create the window. */
{
Log(("Failed to create window\n"));
}
else
{
{
}
}
}
{
}
if (atomWindowClass != 0)
{
atomWindowClass = 0;
}
return 0;
}
/*
* Public platform dependent functions.
*/
int vboxClipboardInit (void)
{
int rc = VINF_SUCCESS;
if (RT_FAILURE (rc))
{
}
return rc;
}
void vboxClipboardDestroy (void)
{
Log(("vboxClipboardDestroy\n"));
/* Set the termination flag and ping the window thread. */
g_ctx.fTerminate = true;
{
}
/* Wait for the window thread to terminate. */
}
{
Log(("vboxClipboardConnect\n"));
{
/* One client only. */
return VERR_NOT_SUPPORTED;
}
/* Synch the host clipboard content with the client. */
return VINF_SUCCESS;
}
{
/* Synch the host clipboard content with the client. */
return VINF_SUCCESS;
}
{
Log(("vboxClipboardDisconnect\n"));
}
{
/*
* The guest announces formats. Forward to the window thread.
*/
}
int vboxClipboardReadData (VBOXCLIPBOARDCLIENTDATA *pClient, uint32_t u32Format, void *pv, uint32_t cb, uint32_t *pcbActual)
{
/*
* The guest wants to read data in the given format.
*/
{
dprintf(("Clipboard opened.\n"));
{
{
{
dprintf(("CF_DIB\n"));
}
else
{
}
}
}
else if (u32Format & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)
{
{
{
dprintf(("CF_UNICODETEXT\n"));
vboxClipboardGetData (VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, uniString, (lstrlenW (uniString) + 1) * 2,
}
else
{
}
}
}
else if (u32Format & VBOX_SHARED_CLIPBOARD_FMT_HTML)
{
if (format != 0)
{
{
{
dprintf(("CF_HTML\n"));
}
else
{
}
}
}
}
CloseClipboard ();
}
else
{
dprintf(("failed to open clipboard\n"));
}
{
/* Reply with empty data. */
vboxClipboardGetData (0, NULL, 0,
}
return VINF_SUCCESS;
}
void vboxClipboardWriteData (VBOXCLIPBOARDCLIENTDATA *pClient, void *pv, uint32_t cb, uint32_t u32Format)
{
LogFlow(("vboxClipboardWriteData\n"));
/*
* The guest returns data that was requested in the WM_RENDERFORMAT handler.
*/
if (cb > 0)
{
{
}
}
}