From c59e88aa6fa60c6f7424da737fcaf0496a0bf3d6 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 22 May 2022 17:48:16 -0400 Subject: Add API support for multiple clipboards Adds a PuglClipboard enum, and uses it everywhere necessary to "structurally" support multiple clipboards. Towards re-using this API to support DnD. --- src/win.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'src/win.c') diff --git a/src/win.c b/src/win.c index 2562d5f..d118b36 100644 --- a/src/win.c +++ b/src/win.c @@ -1348,16 +1348,22 @@ puglSetTransientParent(PuglView* view, PuglNativeView parent) } uint32_t -puglGetNumClipboardTypes(const PuglView* const PUGL_UNUSED(view)) +puglGetNumClipboardTypes(const PuglView* const PUGL_UNUSED(view), + const PuglClipboard clipboard) { - return IsClipboardFormatAvailable(CF_UNICODETEXT) ? 1U : 0U; + return (clipboard == PUGL_CLIPBOARD_GENERAL && + IsClipboardFormatAvailable(CF_UNICODETEXT)) + ? 1U + : 0U; } const char* puglGetClipboardType(const PuglView* const PUGL_UNUSED(view), - const uint32_t typeIndex) + const PuglClipboard clipboard, + const uint32_t PUGL_UNUSED(typeIndex)) { - return (typeIndex == 0 && IsClipboardFormatAvailable(CF_UNICODETEXT)) + return (clipboard == PUGL_CLIPBOARD_GENERAL && typeIndex == 0 && + IsClipboardFormatAvailable(CF_UNICODETEXT)) ? "text/plain" : NULL; } @@ -1388,12 +1394,17 @@ puglAcceptOffer(PuglView* const view, } const void* -puglGetClipboard(PuglView* const view, - const uint32_t typeIndex, - size_t* const len) +puglGetClipboard(PuglView* const view, + const PuglClipboard clipboard, + const uint32_t typeIndex, + size_t* const len) { PuglInternals* const impl = view->impl; + if (clipboard != PUGL_CLIPBOARD_GENERAL) { + return NULL; + } + if (typeIndex > 0U || !IsClipboardFormatAvailable(CF_UNICODETEXT) || !OpenClipboard(impl->hwnd)) { return NULL; @@ -1418,13 +1429,18 @@ puglGetClipboard(PuglView* const view, } PuglStatus -puglSetClipboard(PuglView* const view, - const char* const type, - const void* const data, - const size_t len) +puglSetClipboard(PuglView* const view, + const PuglClipboard clipboard, + const char* const type, + const void* const data, + const size_t len) { PuglInternals* const impl = view->impl; + if (clipboard != PUGL_CLIPBOARD_GENERAL) { + return PUGL_FAILURE; + } + PuglStatus st = puglSetBlob(&view->impl->clipboard, data, len); if (st) { return st; -- cgit v1.2.1