DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L2849
Version: 1.3-current


Under Linux Debian, drag and drop of a filename to an FLTK widget 
fails if the pathname contains non-ascii characters
because the filename does not arrive as a correct UTF-8 string.

Notice that drag and drop of non-ascii text, as opposed to pathnames,
works well under Linux Debian.

To reproduce:
- create on your desktop an empty file named "téléphone"
- run the editor demo program
- drag the "téléphone" file from your desktop to the editor window
you see
   file:///home/<username>/Desktop/t%C3%A9l%C3%A9phone
in the editor window
instead of the expected
   file:///home/<username>/Desktop/téléphone

It happens that the pathname arrives UTF-8 encoded, but with 
non-ascii bytes replaced by the 3 ascii bytes %XY where XY are the 
hex byte value.

The attached dnd.diff patch fixes this for Linux/Debian by 
replacing, only when the dnd data begins with "file://", all %XX
instances by the corresponding single byte value.

Is this fix acceptable, or do other Linux/Unix systems, or X servers,
or file managers behave differently with dropping non-ascii pathnames?
If have no access to other X11 systems for tests.


Link: http://www.fltk.org/str.php?L2849
Version: 1.3-current
Index: src/Fl_x.cxx
===================================================================
--- src/Fl_x.cxx        (revision 9572)
+++ src/Fl_x.cxx        (working copy)
@@ -1045,6 +1045,21 @@
     }
     Fl::e_text = buffer ? (char*)buffer : (char *)"";
     Fl::e_length = bytesread;
+    if (strncmp(Fl::e_text, "file://", 7) == 0) {
+      char *q = Fl::e_text;
+      char *last = q + bytesread;
+      while (q <= last) {
+       if (*q == '%') {
+         int h;
+         // non-ascii chars (and '%') are encoded by %## using their 
hexadecimal value
+         sscanf(q+1, "%2X", &h);
+         *q = h;
+         memmove(q+1, q+3, last - (q+2));
+         last -= 2; Fl::e_length -= 2;
+       }
+       q++;
+      }
+    }
     int old_event = Fl::e_number;
     fl_selection_requestor->handle(Fl::e_number = FL_PASTE);
     Fl::e_number = old_event;
_______________________________________________
fltk-bugs mailing list
fltk-bugs@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk-bugs

Reply via email to