From 3f0082a9dda60432b8b759e09f19b495d9d5275c Mon Sep 17 00:00:00 2001 From: Armin Weatherwax Date: Mon, 8 Jun 2009 11:10:27 +0200 Subject: Linux middle mouse button paste/primary selection support and gtk clipboard handler (fixes crashbug using synergy mouse-keyboard-clipboard-sharing over lan) modified: linden/doc/contributions.txt modified: linden/indra/llui/llclipboard.cpp modified: linden/indra/llui/llclipboard.h modified: linden/indra/llui/llfloater.cpp modified: linden/indra/llui/llfloater.h modified: linden/indra/llui/lllineeditor.cpp modified: linden/indra/llui/lllineeditor.h modified: linden/indra/llui/lltexteditor.cpp modified: linden/indra/llui/lltexteditor.h modified: linden/indra/llui/llview.cpp modified: linden/indra/llui/llview.h modified: linden/indra/llwindow/CMakeLists.txt new file: linden/indra/llwindow/llmousehandler.cpp modified: linden/indra/llwindow/llmousehandler.h modified: linden/indra/llwindow/llwindow.cpp modified: linden/indra/llwindow/llwindow.h modified: linden/indra/llwindow/llwindowsdl.cpp modified: linden/indra/llwindow/llwindowsdl.h modified: linden/indra/newview/lltool.cpp modified: linden/indra/newview/lltool.h modified: linden/indra/newview/llviewertexteditor.cpp modified: linden/indra/newview/llviewertexteditor.h modified: linden/indra/newview/llviewerwindow.cpp modified: linden/indra/newview/llviewerwindow.h (cherry picked from commit 594f4830922f4294dda432fa748935adffaeed8f) --- linden/indra/llwindow/CMakeLists.txt | 1 + linden/indra/llwindow/llmousehandler.cpp | 59 ++++ linden/indra/llwindow/llmousehandler.h | 21 +- linden/indra/llwindow/llwindow.cpp | 16 + linden/indra/llwindow/llwindow.h | 6 + linden/indra/llwindow/llwindowsdl.cpp | 570 ++++++------------------------- linden/indra/llwindow/llwindowsdl.h | 13 +- 7 files changed, 204 insertions(+), 482 deletions(-) create mode 100644 linden/indra/llwindow/llmousehandler.cpp (limited to 'linden/indra/llwindow') diff --git a/linden/indra/llwindow/CMakeLists.txt b/linden/indra/llwindow/CMakeLists.txt index 95e315f..afce0c0 100644 --- a/linden/indra/llwindow/CMakeLists.txt +++ b/linden/indra/llwindow/CMakeLists.txt @@ -46,6 +46,7 @@ set(llwindows_HEADER_FILES set(viewer_SOURCE_FILES llwindow.cpp + llmousehandler.cpp ) set(viewer_HEADER_FILES diff --git a/linden/indra/llwindow/llmousehandler.cpp b/linden/indra/llwindow/llmousehandler.cpp new file mode 100644 index 0000000..ae2f147 --- /dev/null +++ b/linden/indra/llwindow/llmousehandler.cpp @@ -0,0 +1,59 @@ +/** + * @file llmousehandler.cpp + * @brief LLMouseHandler class implementation + * + * $LicenseInfo:firstyear=2001&license=viewergpl$ + * + * Copyright (c) 2001-2007, Linden Research, Inc. + * + * Second Life Viewer Source Code + * The source code in this file ("Source Code") is provided by Linden Lab + * to you under the terms of the GNU General Public License, version 2.0 + * ("GPL"), unless you have obtained a separate licensing agreement + * ("Other License"), formally executed by you and Linden Lab. Terms of + * the GPL can be found in doc/GPL-license.txt in this distribution, or + * online at http://secondlife.com/developers/opensource/gplv2 + * + * There are special exceptions to the terms and conditions of the GPL as + * it is applied to this Source Code. View the full text of the exception + * in the file doc/FLOSS-exception.txt in this software distribution, or + * online at http://secondlife.com/developers/opensource/flossexception + * + * By copying, modifying or distributing this software, you acknowledge + * that you have read and understood your obligations described above, + * and agree to abide by those obligations. + * + * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO + * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, + * COMPLETENESS OR PERFORMANCE. + * $/LicenseInfo$ + */ + +#include "llmousehandler.h" + +//virtual +BOOL LLMouseHandler::handleAnyMouseClick(S32 x, S32 y, MASK mask, EClickType clicktype, BOOL down) +{ + BOOL handled = FALSE; + if (down) + { + switch (clicktype) + { + case CLICK_LEFT: handled = handleMouseDown(x, y, mask); break; + case CLICK_RIGHT: handled = handleRightMouseDown(x, y, mask); break; + case CLICK_MIDDLE: handled = handleMiddleMouseDown(x, y, mask); break; + case CLICK_DOUBLELEFT: handled = handleDoubleClick(x, y, mask); break; + } + } + else + { + switch (clicktype) + { + case CLICK_LEFT: handled = handleMouseUp(x, y, mask); break; + case CLICK_RIGHT: handled = handleRightMouseUp(x, y, mask); break; + case CLICK_MIDDLE: handled = handleMiddleMouseUp(x, y, mask); break; + case CLICK_DOUBLELEFT: handled = handleDoubleClick(x, y, mask); break; + } + } + return handled; +} diff --git a/linden/indra/llwindow/llmousehandler.h b/linden/indra/llwindow/llmousehandler.h index dba1fc1..45f837b 100644 --- a/linden/indra/llwindow/llmousehandler.h +++ b/linden/indra/llwindow/llmousehandler.h @@ -32,9 +32,10 @@ #ifndef LL_MOUSEHANDLER_H #define LL_MOUSEHANDLER_H -#include "llstring.h" +#include "linden_common.h" +#include "llrect.h" -// Abstract interface. +// Mostly-abstract interface. // Intended for use via multiple inheritance. // A class may have as many interfaces as it likes, but never needs to inherit one more than once. @@ -48,13 +49,23 @@ public: SHOW_IF_NOT_BLOCKED, SHOW_ALWAYS, } EShowToolTip; + typedef enum { + CLICK_LEFT, + CLICK_MIDDLE, + CLICK_RIGHT, + CLICK_DOUBLELEFT + } EClickType; + virtual BOOL handleAnyMouseClick(S32 x, S32 y, MASK mask, EClickType clicktype, BOOL down); virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask) = 0; virtual BOOL handleMouseUp(S32 x, S32 y, MASK mask) = 0; - virtual BOOL handleHover(S32 x, S32 y, MASK mask) = 0; - virtual BOOL handleScrollWheel(S32 x, S32 y, S32 clicks) = 0; - virtual BOOL handleDoubleClick(S32 x, S32 y, MASK mask) = 0; + virtual BOOL handleMiddleMouseDown(S32 x, S32 y, MASK mask) = 0; + virtual BOOL handleMiddleMouseUp(S32 x, S32 y, MASK mask) = 0; virtual BOOL handleRightMouseDown(S32 x, S32 y, MASK mask) = 0; virtual BOOL handleRightMouseUp(S32 x, S32 y, MASK mask) = 0; + virtual BOOL handleDoubleClick(S32 x, S32 y, MASK mask) = 0; + + virtual BOOL handleHover(S32 x, S32 y, MASK mask) = 0; + virtual BOOL handleScrollWheel(S32 x, S32 y, S32 clicks) = 0; virtual BOOL handleToolTip(S32 x, S32 y, std::string& msg, LLRect* sticky_rect_screen) = 0; virtual EShowToolTip getShowToolTip() { return SHOW_IF_NOT_BLOCKED; }; virtual const std::string& getName() const = 0; diff --git a/linden/indra/llwindow/llwindow.cpp b/linden/indra/llwindow/llwindow.cpp index 44908fb..b4c8ff0 100644 --- a/linden/indra/llwindow/llwindow.cpp +++ b/linden/indra/llwindow/llwindow.cpp @@ -307,6 +307,22 @@ void *LLWindow::getMediaWindow() return getPlatformWindow(); } +//virtual +BOOL LLWindow::isPrimaryTextAvailable() +{ + return FALSE; // no +} +//virtual +BOOL LLWindow::pasteTextFromPrimary(LLWString &dst) +{ + return FALSE; // fail +} +// virtual +BOOL LLWindow::copyTextToPrimary(const LLWString &src) +{ + return FALSE; // fail +} + // static std::string LLWindow::getFontListSans() { diff --git a/linden/indra/llwindow/llwindow.h b/linden/indra/llwindow/llwindow.h index ffc117f..821de2f 100644 --- a/linden/indra/llwindow/llwindow.h +++ b/linden/indra/llwindow/llwindow.h @@ -184,9 +184,15 @@ public: virtual void captureMouse() = 0; virtual void releaseMouse() = 0; virtual void setMouseClipping( BOOL b ) = 0; + virtual BOOL isClipboardTextAvailable() = 0; virtual BOOL pasteTextFromClipboard(LLWString &dst) = 0; virtual BOOL copyTextToClipboard(const LLWString &src) = 0; + + virtual BOOL isPrimaryTextAvailable(); + virtual BOOL pasteTextFromPrimary(LLWString &dst); + virtual BOOL copyTextToPrimary(const LLWString &src); + virtual void flashIcon(F32 seconds) = 0; virtual F32 getGamma() = 0; virtual BOOL setGamma(const F32 gamma) = 0; // Set the gamma diff --git a/linden/indra/llwindow/llwindowsdl.cpp b/linden/indra/llwindow/llwindowsdl.cpp index 8111aaf..5209e6f 100644 --- a/linden/indra/llwindow/llwindowsdl.cpp +++ b/linden/indra/llwindow/llwindowsdl.cpp @@ -188,11 +188,12 @@ Display* LLWindowSDL::get_SDL_Display(void) LLWindowSDL::LLWindowSDL(const std::string& title, S32 x, S32 y, S32 width, - S32 height, U32 flags, - BOOL fullscreen, BOOL clearBg, - BOOL disable_vsync, BOOL use_gl, - BOOL ignore_pixel_depth, U32 fsaa_samples) - : LLWindow(fullscreen, flags), mGamma(1.0f) + S32 height, U32 flags, + BOOL fullscreen, BOOL clearBg, + BOOL disable_vsync, BOOL use_gl, + BOOL ignore_pixel_depth, U32 fsaa_samples) + : LLWindow(fullscreen, flags), Lock_Display(NULL), + Unlock_Display(NULL), mGamma(1.0f) { // Initialize the keyboard gKeyboard = new LLKeyboardSDL(); @@ -717,9 +718,33 @@ BOOL LLWindowSDL::createContext(int x, int y, int width, int height, int bits, B #endif #if LL_X11 - init_x11clipboard(); + /* Grab the window manager specific information */ + SDL_SysWMinfo info; + SDL_VERSION(&info.version); + if ( SDL_GetWMInfo(&info) ) + { + /* Save the information for later use */ + if ( info.subsystem == SDL_SYSWM_X11 ) + { + mSDL_Display = info.info.x11.display; + mSDL_XWindowID = info.info.x11.wmwindow; + Lock_Display = info.info.x11.lock_func; + Unlock_Display = info.info.x11.unlock_func; + } + else + { + llwarns << "We're not running under X11? Wild." + << llendl; + } + } + else + { + llwarns << "We're not running under any known WM. Wild." + << llendl; + } #endif // LL_X11 + //make sure multisampling is disabled by default glDisable(GL_MULTISAMPLE_ARB); @@ -763,8 +788,12 @@ BOOL LLWindowSDL::switchContext(BOOL fullscreen, const LLCoordScreen &size, BOOL void LLWindowSDL::destroyContext() { llinfos << "destroyContext begins" << llendl; + #if LL_X11 - quit_x11clipboard(); + mSDL_Display = NULL; + mSDL_XWindowID = None; + Lock_Display = NULL; + Unlock_Display = NULL; #endif // LL_X11 // Clean up remaining GL state before blowing away window @@ -1212,523 +1241,125 @@ void LLWindowSDL::flashIcon(F32 seconds) #endif // LL_X11 } -#if LL_X11 -/* Lots of low-level X11 stuff to handle X11 copy-and-paste */ - -/* Our X11 clipboard support is a bit bizarre in various - organically-grown ways. Ideally it should be fixed to do - real string-type negotiation (this would make pasting to - xterm faster and pasting to UTF-8 emacs work properly), but - right now it has the rare and desirable trait of being - generally stable and working. */ - -typedef Atom x11clipboard_type; - -/* PRIMARY and CLIPBOARD are the two main kinds of - X11 clipboard. A third are the CUT_BUFFERs which an - obsolete holdover from X10 days and use a quite orthogonal - mechanism. CLIPBOARD is the type whose design most - closely matches SL's own win32-alike explicit copy-and-paste - paradigm. - - Pragmatically we support all three to varying degrees. When - we paste into SL, it is strictly from CLIPBOARD. When we copy, - we support (to as full an extent as the clipboard content type - allows) CLIPBOARD, PRIMARY, and CUT_BUFFER0. - */ -static x11clipboard_type get_x11_readwrite_clipboard_type(void) -{ - return XInternAtom(LLWindowSDL::get_SDL_Display(), "CLIPBOARD", False); -} - -static x11clipboard_type get_x11_write_clipboard_type(void) -{ - return XA_PRIMARY; -} - -/* This is where our own private cutbuffer goes - we don't use - a regular cutbuffer (XA_CUT_BUFFER0 etc) for intermediate - storage because their use isn't really defined for holding UTF8. */ -static x11clipboard_type get_x11_cutbuffer_clipboard_type(void) -{ - return XInternAtom(LLWindowSDL::get_SDL_Display(), "SECONDLIFE_CUTBUFFER", False); -} - -/* Some X11 atom-generators */ -static Atom get_x11_targets_atom(void) -{ - return XInternAtom(LLWindowSDL::get_SDL_Display(), "TARGETS", False); -} - -static Atom get_x11_text_atom(void) -{ - return XInternAtom(LLWindowSDL::get_SDL_Display(), "TEXT", False); -} - -/* These defines, and convert_data/convert_x11clipboard, - mostly exist to support non-text or unusually-encoded - clipboard data, which we don't really have a need for at - the moment. */ -#define SDLCLIPTYPE(A, B, C, D) (int)(((A)<<24)|((B)<<16)|((C)<<8)|((D)<<0)) -#define FORMAT_PREFIX "SECONDLIFE_x11clipboard_0x" - -static -x11clipboard_type convert_format(int type) +#if LL_GTK +BOOL LLWindowSDL::isClipboardTextAvailable() { - if (!gWindowImplementation) + if (ll_try_gtk_init()) { - llwarns << "!gWindowImplementation in convert_format()" - << llendl; - return XA_STRING; - } - - switch (type) - { - case SDLCLIPTYPE('T', 'E', 'X', 'T'): - // old-style X11 clipboard, strictly only ISO 8859-1 encoding - return XA_STRING; - case SDLCLIPTYPE('U', 'T', 'F', '8'): - // newer de-facto UTF8 clipboard atom - return XInternAtom(gWindowImplementation->mSDL_Display, - "UTF8_STRING", False); - default: - { - /* completely arbitrary clipboard types... we don't actually use - these right now, and support is skeletal. */ - char format[sizeof(FORMAT_PREFIX)+8+1]; /* Flawfinder: ignore */ - - snprintf(format, sizeof(format), "%s%08lx", FORMAT_PREFIX, (unsigned long)type); - return XInternAtom(gWindowImplementation->mSDL_Display, - format, False); + GtkClipboard * const clipboard = + gtk_clipboard_get(GDK_NONE); + return gtk_clipboard_wait_is_text_available(clipboard) ? + TRUE : FALSE; } - } + return FALSE; // failure } -/* convert platform string to x11 clipboard format. for our - purposes this is pretty trivial right now. */ -static int -convert_data(int type, char *dst, const char *src, int srclen) +BOOL LLWindowSDL::pasteTextFromClipboard(LLWString &text) { - int dstlen; - - dstlen = 0; - switch (type) + if (ll_try_gtk_init()) { - case SDLCLIPTYPE('T', 'E', 'X', 'T'): - case SDLCLIPTYPE('U', 'T', 'F', '8'): - if (src == NULL) - { - break; - } - if ( srclen == 0 ) - srclen = strlen(src); /* Flawfinder: ignore */ - - dstlen = srclen + 1; - - if ( dst ) // assume caller made it big enough by asking us + GtkClipboard * const clipboard = + gtk_clipboard_get(GDK_NONE); + gchar * const data = gtk_clipboard_wait_for_text(clipboard); + if (data) { - memcpy(dst, src, srclen); /* Flawfinder: ignore */ - dst[srclen] = '\0'; + text = LLWString(utf8str_to_wstring(data)); + g_free(data); + return TRUE; } - break; - - default: - llwarns << "convert_data: Unknown medium type" << llendl; - break; } - return(dstlen); + return FALSE; // failure } -/* Convert x11clipboard data to platform string. This too is - pretty trivial for our needs right now, and just about identical - to above. */ -static int -convert_x11clipboard(int type, char *dst, const char *src, int srclen) +BOOL LLWindowSDL::copyTextToClipboard(const LLWString &text) { - int dstlen; - - dstlen = 0; - switch (type) + if (ll_try_gtk_init()) { - case SDLCLIPTYPE('U', 'T', 'F', '8'): - case SDLCLIPTYPE('T', 'E', 'X', 'T'): - if (src == NULL) - { - break; - } - if ( srclen == 0 ) - srclen = strlen(src); /* Flawfinder: ignore */ - - dstlen = srclen + 1; - - if ( dst ) // assume caller made it big enough by asking us - { - memcpy(dst, src, srclen); /* Flawfinder: ignore */ - dst[srclen] = '\0'; - } - break; - - default: - llwarns << "convert_x11clipboard: Unknown medium type" << llendl; - break; + const std::string utf8 = wstring_to_utf8str(text); + GtkClipboard * const clipboard = + gtk_clipboard_get(GDK_NONE); + gtk_clipboard_set_text(clipboard, utf8.c_str(), utf8.length()); + return TRUE; } - return dstlen; -} - -int -LLWindowSDL::is_empty_x11clipboard(void) -{ - int retval; - - maybe_lock_display(); - retval = ( XGetSelectionOwner(mSDL_Display, get_x11_readwrite_clipboard_type()) == None ); - maybe_unlock_display(); - - return(retval); + return FALSE; // failure } -void -LLWindowSDL::put_x11clipboard(int type, int srclen, const char *src) +BOOL LLWindowSDL::isPrimaryTextAvailable() { - x11clipboard_type format; - int dstlen; - char *dst; - - format = convert_format(type); - dstlen = convert_data(type, NULL, src, srclen); - - dst = (char *)malloc(dstlen); - if ( dst != NULL ) + if (ll_try_gtk_init()) { - maybe_lock_display(); - Window root = DefaultRootWindow(mSDL_Display); - convert_data(type, dst, src, srclen); - // Cutbuffers are only allowed to have STRING atom types, - // but Emacs puts UTF8 inside them anyway. We cautiously - // don't. - if (type == SDLCLIPTYPE('T','E','X','T')) - { - // dstlen-1 so we don't include the trailing \0 - llinfos << "X11: Populating cutbuffer." <event.xevent; - - if ( (xevent.type == SelectionNotify)&& - (xevent.xselection.requestor == owner) ) - selection_response = 1; - } - } else { - llinfos << "X11: Waiting for SYSWM event..." << llendl; - } - } - llinfos << "X11: Clipboard arrived." <type != SDL_SYSWMEVENT ) - { - return(1); - } - - /* Handle window-manager specific clipboard events */ - switch (event->syswm.msg->event.xevent.type) { - /* Copy the selection from SECONDLIFE_CUTBUFFER to the requested property */ - case SelectionRequest: { - XSelectionRequestEvent *req; - XEvent sevent; - int seln_format; - unsigned long nbytes; - unsigned long overflow; - unsigned char *seln_data; - - req = &event->syswm.msg->event.xevent.xselectionrequest; - sevent.xselection.type = SelectionNotify; - sevent.xselection.display = req->display; - sevent.xselection.selection = req->selection; - sevent.xselection.target = None; - sevent.xselection.property = None; - sevent.xselection.requestor = req->requestor; - sevent.xselection.time = req->time; - if ( XGetWindowProperty(LLWindowSDL::get_SDL_Display(), DefaultRootWindow(LLWindowSDL::get_SDL_Display()), - get_x11_cutbuffer_clipboard_type(), 0, INT_MAX/4, False, req->target, - &sevent.xselection.target, &seln_format, - &nbytes, &overflow, &seln_data) == Success ) + GtkClipboard * const clipboard = + gtk_clipboard_get(GDK_SELECTION_PRIMARY); + gchar * const data = gtk_clipboard_wait_for_text(clipboard); + if (data) { - if ( sevent.xselection.target == req->target) - { - if ( sevent.xselection.target == XA_STRING || - sevent.xselection.target == - convert_format(SDLCLIPTYPE('U','T','F','8')) ) - { - if ( seln_data[nbytes-1] == '\0' ) - --nbytes; - } - XChangeProperty(LLWindowSDL::get_SDL_Display(), req->requestor, req->property, - req->target, seln_format, PropModeReplace, - seln_data, nbytes); - sevent.xselection.property = req->property; - } else if (get_x11_targets_atom() == req->target) { - /* only advertise what we currently support */ - const int num_supported = 3; - Atom supported[num_supported] = { - XA_STRING, // will be over-written below - get_x11_text_atom(), - get_x11_targets_atom() - }; - supported[0] = sevent.xselection.target; - XChangeProperty(LLWindowSDL::get_SDL_Display(), req->requestor, - req->property, XA_ATOM, 32, PropModeReplace, - (unsigned char*)supported, - num_supported); - sevent.xselection.property = req->property; - llinfos << "Clipboard: An app asked us what selections format we offer." << llendl; - } else { - llinfos << "Clipboard: An app requested an unsupported selection format " << req->target << ", we have " << sevent.xselection.target << llendl; - sevent.xselection.target = None; - } - XFree(seln_data); + text = LLWString(utf8str_to_wstring(data)); + g_free(data); + return TRUE; } - int sendret = - XSendEvent(LLWindowSDL::get_SDL_Display(),req->requestor,False,0,&sevent); - if ((sendret==BadValue) || (sendret==BadWindow)) - llwarns << "Clipboard SendEvent failed" << llendl; - XSync(LLWindowSDL::get_SDL_Display(), False); - } - break; } - - /* Post the event for X11 clipboard reading above */ - return(1); + return FALSE; // failure } -int -LLWindowSDL::init_x11clipboard(void) +BOOL LLWindowSDL::copyTextToPrimary(const LLWString &text) { - SDL_SysWMinfo info; - int retval; - - /* Grab the window manager specific information */ - retval = -1; - SDL_SetError("SDL is not running on known window manager"); - - SDL_VERSION(&info.version); - if ( SDL_GetWMInfo(&info) ) + if (ll_try_gtk_init()) { - /* Save the information for later use */ - if ( info.subsystem == SDL_SYSWM_X11 ) - { - mSDL_Display = info.info.x11.display; - mSDL_XWindowID = info.info.x11.wmwindow; - Lock_Display = info.info.x11.lock_func; - Unlock_Display = info.info.x11.unlock_func; - - /* Enable the special window hook events */ - SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE); - SDL_SetEventFilter(clipboard_filter_callback); - - retval = 0; - } - else - { - SDL_SetError("SDL is not running on X11"); - } + const std::string utf8 = wstring_to_utf8str(text); + GtkClipboard * const clipboard = + gtk_clipboard_get(GDK_SELECTION_PRIMARY); + gtk_clipboard_set_text(clipboard, utf8.c_str(), utf8.length()); + return TRUE; } - return(retval); -} - -void -LLWindowSDL::quit_x11clipboard(void) -{ - mSDL_Display = NULL; - mSDL_XWindowID = None; - Lock_Display = NULL; - Unlock_Display = NULL; - - SDL_SetEventFilter(NULL); // Stop custom event filtering + return FALSE; // failure } -/************************************************/ - +#else + BOOL LLWindowSDL::isClipboardTextAvailable() { - return !is_empty_x11clipboard(); + return FALSE; // unsupported } - + BOOL LLWindowSDL::pasteTextFromClipboard(LLWString &dst) { - int cliplen; // seems 1 or 2 bytes longer than expected - char *cliptext = NULL; - get_x11clipboard(SDLCLIPTYPE('U','T','F','8'), &cliplen, &cliptext); - if (cliptext) - { - llinfos << "X11: Got UTF8 clipboard text." << llendl; - // at some future time we can use cliplen instead of relying on \0, - // if we ever grok non-ascii, non-utf8 encodings on the clipboard. - std::string clip_str(cliptext); - // we can't necessarily trust the incoming text to be valid UTF-8, - // but utf8str_to_wstring() seems to do an appropriate level of - // validation for avoiding over-reads. - dst = utf8str_to_wstring(clip_str); - /*llinfos << "X11 pasteTextFromClipboard: cliplen=" << cliplen << - " strlen(cliptext)=" << strlen(cliptext) << - " clip_str.length()=" << clip_str.length() << - " dst.length()=" << dst.length() << - llendl;*/ - free(cliptext); - return TRUE; // success - } - get_x11clipboard(SDLCLIPTYPE('T','E','X','T'), &cliplen, &cliptext); - if (cliptext) - { - llinfos << "X11: Got ISO 8859-1 clipboard text." << llendl; - std::string clip_str(cliptext); - std::string utf8_str = rawstr_to_utf8(clip_str); - dst = utf8str_to_wstring(utf8_str); - free(cliptext); - } - return FALSE; // failure + return FALSE; // unsupported } + BOOL LLWindowSDL::copyTextToClipboard(const LLWString &s) { - std::string utf8text = wstring_to_utf8str(s); - const char* cstr = utf8text.c_str(); - if (cstr == NULL) - { - return FALSE; - } - int cstrlen = strlen(cstr); /* Flawfinder: ignore */ - int i; - for (i=0; i