From c864a2cb08054fa9d26623bca2e89c28a0fe1717 Mon Sep 17 00:00:00 2001 From: Henrique Santiago Date: Sun, 20 Mar 2011 18:08:57 -0300 Subject: [PATCH] clipboard fix --- src/framework/platform.h | 4 ++-- src/framework/win32platform.cpp | 23 +++++++++++++++++++++++ src/framework/x11platform.cpp | 4 ++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/framework/platform.h b/src/framework/platform.h index 55758337..33c17b77 100644 --- a/src/framework/platform.h +++ b/src/framework/platform.h @@ -57,8 +57,8 @@ namespace Platform /// Check if GL extension is supported bool isExtensionSupported(const char *ext); - const char *getTextFromClipboard(); - void copyToClipboard(const char *text); + const char *getClipboardText(); + void setClipboardText(const char *text); void hideMouseCursor(); void showMouseCursor(); diff --git a/src/framework/win32platform.cpp b/src/framework/win32platform.cpp index 8cc8a4ab..89b64cb3 100644 --- a/src/framework/win32platform.cpp +++ b/src/framework/win32platform.cpp @@ -244,6 +244,29 @@ bool Platform::isExtensionSupported(const char *ext) return false; } +const char *Platform::getClipboardText() +{ + const char *text = ""; + if(OpenClipboard(NULL)) { + text = (const char*)GetClipboardData(CF_TEXT); + CloseClipboard(); + } + return text; +} + +void Platform::setClipboardText(const char *text) +{ + int textLenght = strlen(text); + HANDLE hData = new HANDLE[textLenght + 1]; + memcpy(hData, text, textLenght + 1); + + if(OpenClipboard(NULL)) { + EmptyClipboard(); + SetClipboardData(CF_TEXT, hData); + CloseClipboard(); + } +} + void Platform::hideMouseCursor() { ShowCursor(false); diff --git a/src/framework/x11platform.cpp b/src/framework/x11platform.cpp index 636b35fe..7711028d 100644 --- a/src/framework/x11platform.cpp +++ b/src/framework/x11platform.cpp @@ -601,7 +601,7 @@ bool Platform::isExtensionSupported(const char *ext) return false; } -const char *Platform::getTextFromClipboard() +const char *Platform::getClipboardText() { Window ownerWindow = XGetSelectionOwner(x11.display, x11.atomClipboard); if(ownerWindow == x11.window) @@ -650,7 +650,7 @@ const char *Platform::getTextFromClipboard() return clipboard.c_str(); } -void Platform::copyToClipboard(const char *text) +void Platform::setClipboardText(const char *text) { x11.clipboardText = text; XSetSelectionOwner(x11.display, x11.atomClipboard, x11.window, CurrentTime);