From e931f660caea5257841103196a389fd5eae6be07 Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Thu, 9 Dec 2010 21:52:07 +0000 Subject: [PATCH] STR #2472: X11 only: fixes DnD between FLTK and other apps for non-ASCII text. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7992 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_x.cxx | 24 +++++++++++++++--------- src/fl_dnd_x.cxx | 3 ++- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Fl_x.cxx b/src/Fl_x.cxx index be4a88026..12fd89e61 100644 --- a/src/Fl_x.cxx +++ b/src/Fl_x.cxx @@ -278,6 +278,20 @@ int fl_ready() { # endif } +// replace \r\n by \n +static void convert_crlf(unsigned char *string, long& len) +{ + unsigned char *p = string, *q = p + len; + while (p < q) { + if (*p == '\r' && *(p + 1) == '\n' && p + 1 < q) { + memmove(p, p + 1, q - p - 1); + q--; + len--; + } + p++; + } +} + //////////////////////////////////////////////////////////////// Display *fl_display; @@ -955,23 +969,15 @@ int fl_handle(const XEvent& thisevent) text_prop.encoding=actual; text_prop.nitems=count; char **text_list; -#ifndef X_HAVE_UTF8_STRING text_list = (char**)&portion; -#else - int list_count = 0; - Xutf8TextPropertyToTextList(fl_display, (const XTextProperty*)&text_prop, &text_list, &list_count); - if (list_count == 0) text_list = (char**)&portion; -#endif int bytesnew = strlen(*text_list)+1; buffer = (unsigned char*)realloc(buffer, bytesread+bytesnew+remaining); memcpy(buffer+bytesread, *text_list, bytesnew); XFree(portion); -#ifdef X_HAVE_UTF8_STRING - if (list_count > 0) XFreeStringList(text_list); -#endif bytesread += bytesnew - 1; if (!remaining) break; } + convert_crlf(buffer, bytesread); Fl::e_text = buffer ? (char*)buffer : (char *)""; Fl::e_length = bytesread; int old_event = Fl::e_number; diff --git a/src/fl_dnd_x.cxx b/src/fl_dnd_x.cxx index 403793965..f07ac859b 100644 --- a/src/fl_dnd_x.cxx +++ b/src/fl_dnd_x.cxx @@ -43,6 +43,7 @@ extern Atom fl_XdndActionCopy; extern Atom fl_XdndFinished; //extern Atom fl_XdndProxy; extern Atom fl_XdndURIList; +extern Atom fl_XaUtf8String; extern char fl_i_own_selection[2]; extern char *fl_selection_buffer[2]; @@ -149,7 +150,7 @@ int Fl::dnd() { } else { // Send plain text... fl_sendClientMessage(target_window, fl_XdndEnter, source_window, - dndversion<<24, XA_STRING, 0, 0); + dndversion<<24, fl_XaUtf8String, 0, 0); } } }