diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-09-18 17:49:18 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-09-18 17:49:18 +0300 |
commit | 70b520b1e876f9698bb95baa2d274ea289a0c6bd (patch) | |
tree | 152c7519b0d9b8fb424af2373ec48db823a85575 /src/utils/copynpaste.cpp | |
parent | 62ec17f6e489ec50f17219444468aeb8969dc961 (diff) | |
parent | 3b999f51c740d0541c53d223518e5e4bb482d996 (diff) | |
download | manaverse-70b520b1e876f9698bb95baa2d274ea289a0c6bd.tar.gz manaverse-70b520b1e876f9698bb95baa2d274ea289a0c6bd.tar.bz2 manaverse-70b520b1e876f9698bb95baa2d274ea289a0c6bd.tar.xz manaverse-70b520b1e876f9698bb95baa2d274ea289a0c6bd.zip |
Merge branch 'master' into strippedstripped1.1.9.18
Conflicts:
src/guichan/cliprectangle.cpp
src/guichan/focushandler.cpp
src/guichan/gui.cpp
src/guichan/include/guichan/cliprectangle.hpp
src/guichan/include/guichan/inputevent.hpp
src/guichan/include/guichan/keyevent.hpp
src/guichan/include/guichan/mouseevent.hpp
src/guichan/include/guichan/widgets/button.hpp
src/guichan/include/guichan/widgets/checkbox.hpp
src/guichan/include/guichan/widgets/dropdown.hpp
src/guichan/include/guichan/widgets/radiobutton.hpp
src/guichan/include/guichan/widgets/slider.hpp
src/guichan/include/guichan/widgets/tab.hpp
src/guichan/include/guichan/widgets/tabbedarea.hpp
src/guichan/include/guichan/widgets/textfield.hpp
src/guichan/include/guichan/widgets/window.hpp
src/guichan/inputevent.cpp
src/guichan/keyevent.cpp
src/guichan/mouseevent.cpp
src/guichan/widget.cpp
src/guichan/widgets/button.cpp
src/guichan/widgets/checkbox.cpp
src/guichan/widgets/dropdown.cpp
src/guichan/widgets/radiobutton.cpp
src/guichan/widgets/slider.cpp
src/guichan/widgets/tab.cpp
src/guichan/widgets/tabbedarea.cpp
src/guichan/widgets/textfield.cpp
src/guichan/widgets/window.cpp
Diffstat (limited to 'src/utils/copynpaste.cpp')
-rw-r--r-- | src/utils/copynpaste.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/utils/copynpaste.cpp b/src/utils/copynpaste.cpp index 5b1ccb5bc..6d1c675d3 100644 --- a/src/utils/copynpaste.cpp +++ b/src/utils/copynpaste.cpp @@ -1,6 +1,7 @@ /* * Retrieve string pasted depending on OS mechanisms. * Copyright (C) 2001-2010 Wormux Team + * Copyright (C) 2011 ManaPlus Developers * * This file is part of The ManaPlus Client. * @@ -90,6 +91,40 @@ bool retrieveBuffer(std::string& text, std::string::size_type& pos) CloseClipboard(); return ret; } + +bool sendBuffer(std::string& text) +{ + int wCharsLen = MultiByteToWideChar(CP_UTF8, 0, text.c_str(), -1, NULL, 0); + if (!wCharsLen) + return false; + + HANDLE h; + WCHAR *out; + h = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, wCharsLen * sizeof(WCHAR)); + out = (WCHAR*)GlobalLock(h); + + MultiByteToWideChar(CP_UTF8, 0, text.c_str(), -1, out, wCharsLen); + + if (!OpenClipboard(0)) + { + GlobalUnlock(h); + GlobalFree(h); + return false; + } + GlobalUnlock(h); + EmptyClipboard(); + if (!SetClipboardData(CF_UNICODETEXT, out)) + { + GlobalFree(h); + CloseClipboard(); + return false; + } + GlobalFree(h); + CloseClipboard(); + + return true; +} + #elif defined(__APPLE__) #ifdef Status @@ -243,6 +278,11 @@ bool retrieveBuffer(std::string& text, std::string::size_type& pos) } } +bool sendBuffer(std::string& text) +{ + return false; +} + #elif USE_X11 static char* getSelection2(Display *dpy, Window us, Atom selection, Atom request_target) @@ -362,9 +402,56 @@ bool retrieveBuffer(std::string& text, std::string::size_type& pos) } return false; } + +bool sendBuffer(std::string& text) +{ + pid_t pid; + int fd[2]; + + if (pipe(fd)) + return false; + + if ((pid = fork()) == -1) + { // fork error + return false; + } + else if (!pid) + { // child + close(fd[1]); + + if (fd[0] != STDIN_FILENO) + { + if (dup2(fd[0], STDIN_FILENO) != STDIN_FILENO) + { + close(fd[0]); + exit(1); + } + close(fd[0]); + } + execl("/usr/bin/xsel", "xsel", "-i", (char *)0); + exit(1); + } + + // parent + close(fd[0]); + const int len = strlen(text.c_str()); + if (write(fd[1], text.c_str(), len) != len) + { + close(fd[1]); + return false; + } + close(fd[1]); + return true; +} + #else bool retrieveBuffer(std::string&, std::string::size_type&) { return false; } + +bool sendBuffer(std::string& text) +{ + return false; +} #endif |