Author: manolo
Date: 2012-06-10 07:51:00 -0700 (Sun, 10 Jun 2012)
New Revision: 9585
Log:
Added the fltk3::decode_uri(char*) function and documented that the dropping of 
filenames 
under X11 produces a URL-encoded, UTF_8 string.

Modified:
   branches/branch-3.0/documentation/src/events.dox
   branches/branch-3.0/include/fltk3/filename.h
   branches/branch-3.0/src/fltk3/open_uri.cxx

Modified: branches/branch-3.0/documentation/src/events.dox
===================================================================
--- branches/branch-3.0/documentation/src/events.dox    2012-06-10 12:33:04 UTC 
(rev 9584)
+++ branches/branch-3.0/documentation/src/events.dox    2012-06-10 14:51:00 UTC 
(rev 9585)
@@ -265,10 +265,18 @@
 FLTK supports drag and drop of text and files from any 
 application on the desktop to an FLTK widget. Text is transferred
 using UTF-8 encoding. Files are received as a list of full path
-and file names, separated by newline. On some platforms, path
-names are prepended with <tt>%file://</tt>.
-See Fl::dnd() for drag and drop from an FLTK widget.
+and file names, separated by newline. 
 
+On some X11 platforms, files are received as a URL-encoded UTF-8 string,
+that is, non-ASCII bytes (and a few others such as space and %) are 
+replaced by the 3 bytes "%XY" where XY are the byte's hexadecimal value.
+The \ref fltk3::decode_uri() function can be used to transform in-place
+the received string into a proper UTF-8 string. On these platforms,
+strings corresponding to dropped files are further prepended 
+by <tt>file://</tt> (or other prefixes such as <tt>computer://</tt>).
+
+See fltk3::dnd() for drag and drop from an FLTK widget.
+
 The drag and drop data is available in Fl::event_text()
 at the concluding \p FL_PASTE. On some platforms, the
 event text is also available for the \p FL_DND_* events,

Modified: branches/branch-3.0/include/fltk3/filename.h
===================================================================
--- branches/branch-3.0/include/fltk3/filename.h        2012-06-10 12:33:04 UTC 
(rev 9584)
+++ branches/branch-3.0/include/fltk3/filename.h        2012-06-10 14:51:00 UTC 
(rev 9585)
@@ -142,6 +142,8 @@
   FLTK3_EXPORT int open_uri(const char *uri, char *msg = (char *)0,
                            int msglen = 0);
   
+  FLTK3_EXPORT void decode_uri(char *uri);
+
 #    ifndef FLTK3_DOXYGEN
   /*
    * fltk3::_filename_isdir_quick() is a private function that checks for a

Modified: branches/branch-3.0/src/fltk3/open_uri.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/open_uri.cxx  2012-06-10 12:33:04 UTC (rev 
9584)
+++ branches/branch-3.0/src/fltk3/open_uri.cxx  2012-06-10 14:51:00 UTC (rev 
9585)
@@ -241,6 +241,27 @@
 #endif // WIN32
 }
 
+/** Decodes a URL-encoded string.
+ 
+ In a Uniform Resource Identifier (URI), all non-ASCII bytes and several 
others (e.g., '<', '%', ' ')
+ are URL-encoded using 3 bytes by "%XY" where XY is the hexadecimal value of 
the byte. This function
+ decodes the URI restoring its original UTF-8 encoded content. Decoding is 
done in-place.
+ */
+void fltk3::decode_uri(char *uri)
+{
+  char *last = uri + strlen(uri);
+  while (uri < last-2) {
+    if (*uri == '%') {
+      int h;
+      if ( sscanf(uri+1, "%2X", &h) != 1 ) break;
+      *uri = h;
+      memmove(uri+1, uri+3, last - (uri+2));
+      last -= 2;
+    }
+    uri++;
+  }
+}
+
 /**   @} */
 
 #if !defined(WIN32) && !defined(__APPLE__)

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to