Browse Source

clipboard fix

Henrique Santiago 10 years ago
parent
commit
c864a2cb08
3 changed files with 27 additions and 4 deletions
  1. 2
    2
      src/framework/platform.h
  2. 23
    0
      src/framework/win32platform.cpp
  3. 2
    2
      src/framework/x11platform.cpp

+ 2
- 2
src/framework/platform.h View File

@@ -57,8 +57,8 @@ namespace Platform
57 57
     /// Check if GL extension is supported
58 58
     bool isExtensionSupported(const char *ext);
59 59
 
60
-    const char *getTextFromClipboard();
61
-    void copyToClipboard(const char *text);
60
+    const char *getClipboardText();
61
+    void setClipboardText(const char *text);
62 62
 
63 63
     void hideMouseCursor();
64 64
     void showMouseCursor();

+ 23
- 0
src/framework/win32platform.cpp View File

@@ -244,6 +244,29 @@ bool Platform::isExtensionSupported(const char *ext)
244 244
     return false;
245 245
 }
246 246
 
247
+const char *Platform::getClipboardText()
248
+{
249
+    const char *text = "";
250
+    if(OpenClipboard(NULL)) {
251
+        text = (const char*)GetClipboardData(CF_TEXT);
252
+        CloseClipboard();
253
+    }
254
+    return text;
255
+}
256
+
257
+void Platform::setClipboardText(const char *text)
258
+{
259
+    int textLenght = strlen(text);
260
+    HANDLE hData = new HANDLE[textLenght + 1];
261
+    memcpy(hData, text, textLenght + 1);
262
+
263
+    if(OpenClipboard(NULL)) {
264
+        EmptyClipboard();
265
+        SetClipboardData(CF_TEXT, hData);
266
+        CloseClipboard();
267
+    }
268
+}
269
+
247 270
 void Platform::hideMouseCursor()
248 271
 {
249 272
     ShowCursor(false);

+ 2
- 2
src/framework/x11platform.cpp View File

@@ -601,7 +601,7 @@ bool Platform::isExtensionSupported(const char *ext)
601 601
     return false;
602 602
 }
603 603
 
604
-const char *Platform::getTextFromClipboard()
604
+const char *Platform::getClipboardText()
605 605
 {
606 606
     Window ownerWindow = XGetSelectionOwner(x11.display, x11.atomClipboard);
607 607
     if(ownerWindow ==  x11.window)
@@ -650,7 +650,7 @@ const char *Platform::getTextFromClipboard()
650 650
     return clipboard.c_str();
651 651
 }
652 652
 
653
-void Platform::copyToClipboard(const char *text)
653
+void Platform::setClipboardText(const char *text)
654 654
 {
655 655
     x11.clipboardText = text;
656 656
     XSetSelectionOwner(x11.display, x11.atomClipboard, x11.window, CurrentTime);

Loading…
Cancel
Save