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: Fri, 11 Mar 2005 06:35:40 -0500

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

Modified files:
        src            : clipboard.cpp 

Log message:
        added copy_ucs2_to_clipboard and copy_ucs2_from_clipboard for OS X

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

Patches:
Index: wesnoth/src/clipboard.cpp
diff -u wesnoth/src/clipboard.cpp:1.8 wesnoth/src/clipboard.cpp:1.9
--- wesnoth/src/clipboard.cpp:1.8       Fri Mar 11 00:11:20 2005
+++ wesnoth/src/clipboard.cpp   Fri Mar 11 11:35:39 2005
@@ -414,12 +414,55 @@
 #define CLIPBOARD_FUNCS_DEFINED
 
 #include <Carbon/Carbon.h>
+void copy_ucs2_to_clipboard(const ucs2_string& text) {
+       ucs2_string str;
+       str.reserve(text.size() + 1);
+       for(int i = 0; i < text.size(); ++i) {
+               if(text[i] == '\n')
+                       str.push_back('\r');
+               else
+                       str.push_back(text[i]);
+       }
+       str.push_back(0);
+       OSStatus err = noErr;
+       ScrapRef scrap = kScrapRefNone;
+       err = ClearCurrentScrap();
+       if(err != noErr)
+               return;
+       err = GetCurrentScrap(&scrap);
+       if(err != noErr)
+               return;
+       PutScrapFlavor(scrap, kScrapFlavorTypeUnicode, kScrapFlavorMaskNone, 
str.size(), &str.front());
+}
+
+ucs2_string copy_ucs2_from_clipboard() {
+       ucs2_string str;
+       OSStatus err = noErr;
+       ScrapRef scrap = kScrapRefNone;
+       err = GetCurrentScrap(&scrap);
+       if(err != noErr)
+               return str;
+       Size scrapsize;
+       err = GetScrapFlavorSize(scrap, kScrapFlavorTypeUnicode, &scrapsize);
+       if(err != noErr)
+               return str;
+       str.reserve(scrapsize);
+       str.resize(scrapsize);
+       err = GetScrapFlavorData(scrap, kScrapFlavorTypeUnicode, &scrapsize, 
const_cast<Uint16*>(&str.front()));
+       if(err != noErr)
+               return str.clear();
+       for(int i = 0; i < str.size(); ++i) {
+               if(str[i] == '\r')
+                       str[i] = '\n';
+       }
+       return str;
+}
 
 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++)
+       for (int i = 0; i < text.size(); ++i)
        {
                if (text[i] == '\n')
                {
@@ -451,7 +494,7 @@
        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++)
+       for (int i = 0; i < str.size(); ++i)
        {
                if (str[i] == '\r') str[i] = '\n';
        }




reply via email to

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