use SDL2 to copy to clipboard sdl2transition
authorsheepluva
Tue, 10 Nov 2015 22:37:54 +0100
branchsdl2transition
changeset 11344 b0df3f2fcafc
parent 11343 9006e158a81f
child 11356 b8b208501475
use SDL2 to copy to clipboard
QTfrontend/game.cpp
hedgewars/SDLh.pas
hedgewars/uChat.pas
--- a/QTfrontend/game.cpp	Tue Nov 10 22:18:06 2015 +0100
+++ b/QTfrontend/game.cpp	Tue Nov 10 22:37:54 2015 +0100
@@ -17,7 +17,6 @@
  */
 
 #include <QApplication>
-#include <QClipboard>
 
 #include <QString>
 #include <QCheckBox>
@@ -261,12 +260,6 @@
                 .arg(QString::fromUtf8(msg.mid(2).left(size - 4))));
             return;
         }
-        case 'y':
-        {
-            // copy string to clipboard
-            QApplication::clipboard()->setText(QString::fromUtf8(msg.mid(2)));
-            break;
-        }
         case 'i':
         {
             emit GameStats(msg.at(2), QString::fromUtf8(msg.mid(3)));
--- a/hedgewars/SDLh.pas	Tue Nov 10 22:18:06 2015 +0100
+++ b/hedgewars/SDLh.pas	Tue Nov 10 22:37:54 2015 +0100
@@ -990,7 +990,10 @@
 
 // SDL 2 clipboard functions
 function SDL_HasClipboardText(): Boolean; cdecl; external SDLLibName;
+// returns nil if memory for clipboard contents copy couldn't be allocated
 function SDL_GetClipboardText(): PChar; cdecl; external SDLLibName;
+// returns 0 on success or negative error number on failure
+function SDL_SetClipboardText(const text: PChar): LongInt; cdecl; external SDLLibName;
 
 procedure SDLNet_Write16(value: Word; buf: Pointer);
 procedure SDLNet_Write32(value: LongWord; buf: Pointer);
--- a/hedgewars/uChat.pas	Tue Nov 10 22:18:06 2015 +0100
+++ b/hedgewars/uChat.pas	Tue Nov 10 22:37:54 2015 +0100
@@ -726,7 +726,8 @@
 
 procedure CopyToClipboard(var newContent: shortstring);
 begin
-    SendIPC(_S'y' + copy(newContent, 1, 253) + #0);
+    // SDL2 clipboard
+    SDL_SetClipboardText(Str2PChar(newContent));
 end;
 
 procedure CopySelectionToClipboard();