wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src clipboard.cpp


From: Jon Daniel
Subject: [Wesnoth-cvs-commits] wesnoth/src clipboard.cpp
Date: Thu, 10 Mar 2005 19:11:21 -0500

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Jon Daniel <address@hidden>     05/03/11 00:11:21

Modified files:
        src            : clipboard.cpp 

Log message:
        Applied crimson_penguins OS X clipboard support patch

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/clipboard.cpp.diff?tr1=1.7&tr2=1.8&r1=text&r2=text

Patches:
Index: wesnoth/src/clipboard.cpp
diff -u wesnoth/src/clipboard.cpp:1.7 wesnoth/src/clipboard.cpp:1.8
--- wesnoth/src/clipboard.cpp:1.7       Thu Nov 18 04:08:32 2004
+++ wesnoth/src/clipboard.cpp   Fri Mar 11 00:11:20 2005
@@ -410,6 +410,60 @@
 }
 #endif
 
+#ifdef __APPLE__
+#define CLIPBOARD_FUNCS_DEFINED
+
+#include <Carbon/Carbon.h>
+
+void copy_to_clipboard(const std::string& text)
+{
+       std::string new_str;
+       new_str.reserve(text.size());
+       for (int i = 0; i < text.size(); i++)
+       {
+               if (text[i] == '\n')
+               {
+                       new_str.push_back('\r');
+               } else {
+                       new_str.push_back(text[i]);
+               }
+       }
+       OSStatus err = noErr;
+       ScrapRef scrap = kScrapRefNone;
+       err = ClearCurrentScrap();
+       if (err != noErr) return;
+       err = GetCurrentScrap(&scrap);
+       if (err != noErr) return;
+       PutScrapFlavor(scrap, kScrapFlavorTypeText, kScrapFlavorMaskNone, 
text.size(), new_str.c_str());
+}
+
+std::string copy_from_clipboard()
+{
+       ScrapRef curscrap = kScrapRefNone;
+       Size scrapsize = 0;
+       OSStatus err = noErr;
+       err = GetCurrentScrap(&curscrap);
+       if (err != noErr) return "";
+       err = GetScrapFlavorSize(curscrap, kScrapFlavorTypeText, &scrapsize);
+       if (err != noErr) return "";
+       std::string str;
+       str.reserve(scrapsize);
+       str.resize(scrapsize);
+       err = GetScrapFlavorData(curscrap, kScrapFlavorTypeText, &scrapsize, 
const_cast<char*>(str.data()));
+       if (err != noErr) return "";
+       for (int i = 0; i < str.size(); i++)
+       {
+               if (str[i] == '\r') str[i] = '\n';
+       }
+       return str;
+}
+
+void handle_system_event(const SDL_Event& event)
+{
+}
+
+#endif
+
 #ifndef CLIPBOARD_FUNCS_DEFINED
 
 void copy_to_clipboard(const std::string& text)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]