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 19:59:27 -0500

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

Modified files:
        src            : clipboard.cpp 

Log message:
        * added copy_ucs2_to_clipboard function for win32
        * updated copy_to_clipboard function for win32

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

Patches:
Index: wesnoth/src/clipboard.cpp
diff -u wesnoth/src/clipboard.cpp:1.11 wesnoth/src/clipboard.cpp:1.12
--- wesnoth/src/clipboard.cpp:1.11      Fri Mar 11 11:59:07 2005
+++ wesnoth/src/clipboard.cpp   Sat Mar 12 00:59:26 2005
@@ -335,25 +335,75 @@
 void handle_system_event(const SDL_Event& )
 {}
 
-void copy_to_clipboard(const std::string& text)
+void copy_ucs2_to_clipboard(const ucs2_string& text)
 {
-       if(text.empty()) {
+       if(text.empty())
                return;
-       }
-       
+       if(!OpenClipboard(NULL))
+               return;
+       EmptyClipboard();
 
-       if(!OpenClipboard(0)) {
+       // convert newlines
+       ucs2_string str;
+       str.reserve(text.size() + 1);
+       ucs2_string::const_iterator first = text.begin();
+       ucs2_string::const_iterator last = text.begin();
+       do {
+               if(*last != '\n') {
+                       ++last;
+                       continue;
+               }
+               str.insert(str.end(), first, last);
+               str.push_back('\r');
+               str.push_back('\n');
+               first = ++last;
+       } while(last != text.end());
+       str.push_back('\0');
+       
+       HGLOBAL hglb = GlobalAlloc(GMEM_MOVEABLE, str.size() * sizeof(Uint16));
+       if(hglb == NULL) {
+               CloseClipboard();
                return;
        }
+       Uint16* const buffer = reinterpret_cast<Uint16* 
const>(GlobalLock(hglb));
+       memcpy(buffer, (Uint16 const *)&str.front(), str.size() * 
sizeof(Uint16));
+       GlobalUnlock(hglb);
+       SetClipboardData(CF_UNICODETEXT, hglb);
+       CloseClipboard();
+}
 
+void copy_to_clipboard(const std::string& text)
+{
+       if(text.empty())
+               return;
+       if(!OpenClipboard(NULL))
+               return;
        EmptyClipboard();
 
-       const HGLOBAL clip_buffer = GlobalAlloc(GMEM_DDESHARE,text.size()+1);
-       char* const buffer = reinterpret_cast<char*>(GlobalLock(clip_buffer));
-       strcpy(buffer,text.c_str());
-
-       GlobalUnlock(clip_buffer);
-       SetClipboardData(CF_TEXT,clip_buffer);
+       // convert newlines
+       std::string str;
+       str.reserve(text.size());
+       std::string::const_iterator first = text.begin();
+       std::string::const_iterator last = text.begin();
+       do {
+               if(*last != '\n') {
+                       ++last;
+                       continue;
+               }
+               str.append(first, last);
+               str.append("\r\n");
+               first = ++last;
+       } while(last != text.end());
+       
+       const HGLOBAL hglb = GlobalAlloc(GMEM_MOVEABLE, (str.size() + 1) * 
sizeof(TCHAR));
+       if(hglb == NULL) {
+               CloseClipboard();
+               return;
+       }
+       char* const buffer = reinterpret_cast<char* const>(GlobalLock(hglb));
+       strcpy(buffer, str.c_str());
+       GlobalUnlock(hglb);
+       SetClipboardData(CF_TEXT, hglb);
        CloseClipboard();
 }
 




reply via email to

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