discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Multi-lingual cut & paste support (was Re: One for our asian language ex


From: Kazunobu Kuriyama
Subject: Multi-lingual cut & paste support (was Re: One for our asian language experts...)
Date: Wed, 30 Jul 2003 14:58:45 +0900
User-agent: Mozilla/5.0 (X11; U; Linux i686; ja-JP; rv:1.4) Gecko/20030624 Netscape/7.1

Hi,

Attached is the patch that enables multi-lingual cut & paste with gpbs.

The modification was done along the line suggested by Richard Frith-MacDonald and Alexander Malmberg. In particular, the URL indicated by Alexander Malmberg was quite helpful. Owing to it, it took half an hour (or less) to finish coding.

Because it makes use of the recent XFree86's utf8 support, the underlying
window system must be XFree86 4.0.2 or higher to enjoy the new functionality.

In case the window system doesn't satisfy the requirement above, the implementation
automatically falls back to the original one.

By the way, it seems gpbs has a problem with its initialization. I had xedit
and Ink run.  I input a string in xedit and tried to do a cut-and-paste from
xedit to Ink.  I failed.  Then I input another string in Ink and tried to a
cut-and-paste from Ink to xedit. I succeeded. I gave one more try to xedit-to-
Ink cut-and-paste.  This time I succeeded.  Do you have some ideas on what I
saw?

It could be possible to write a patch in such a way that other versions of X Window System enjoy multi-lingual cut & paste. I intentionally leave it out becuase

(1) It will takes extra days to write the code for encoding and decoding the
data of type COMPOUND TEXT. As you know, there is a person who wants to do
   multi-lingual cut-and-paste right now.
(2) For each language, an implementation must specify a character encoding explicitly. This implies that the results of cut & paste depend on the language environment under which applications run. Say, suppose you have xedit running under LANG=ja_JP and Ink running under LANG=en_UK. What happens when you try to do a cut-and-paste between these two applications? Moreover, the user may set GNUSTEP_STRING_ ENCODING to a certain value. You also have to take this into consideration to predict what happens. To make gpbs reliable even under these nasty situations, an reengineering may be needed (or make the users understood that GNUstep behaves
   as such).

Any feedback is welcome.

- Kazu
2003-07-30  Kazunobu Kuriyama  <kazunobu.kuriyama@nifty.com>

        * Tools/xpbs.m: Multi-lingual cut & paste support

--- xpbs.m      2003-07-30 12:39:18.000000000 +0900
+++ xpbs.m.rev  2003-07-30 12:39:29.000000000 +0900
@@ -30,6 +30,12 @@
 #include <X11/Xutil.h>
 #include <x11/xdnd.h>
 
+#ifdef X_HAVE_UTF8_STRING
+#warning "XFree86 UTF8 extension used"
+#else
+#warning "XFRee86 UTF8 extension not used: gpbs supports ISO Latin 1 
characters only"
+#endif
+
 static Atom    osTypeToX(NSString *t);
 static NSString        *xTypeToOs(Atom t);
 
@@ -51,7 +57,10 @@
   "USER",
   "TEXT",
   "NULL",
-  "FILE_NAME"
+  "FILE_NAME",
+#ifdef X_HAVE_UTF8_STRING
+  "UTF8_STRING"
+#endif
 };
 static Atom atoms[sizeof(atom_names)/sizeof(char*)];
 
@@ -74,6 +83,9 @@
 #define XG_TEXT                 atoms[12]
 #define XG_NULL                 atoms[13]
 #define XG_FILE_NAME           atoms[14]
+#ifdef X_HAVE_UTF8_STRING
+#define XG_UTF8_STRING         atoms[15]
+#endif
 
 
 
@@ -81,7 +93,11 @@
 osTypeToX(NSString *t)
 {
   if ([t isEqualToString: NSStringPboardType] == YES)
+#ifdef X_HAVE_UTF8_STRING
+    return XG_UTF8_STRING;
+#else
     return XA_STRING;
+#endif
   else if ([t isEqualToString: NSColorPboardType] == YES)
     return XG_NULL;
   else if ([t isEqualToString: NSFileContentsPboardType] == YES)
@@ -113,7 +129,11 @@
 static NSString*
 xTypeToOs(Atom t)
 {
+#ifdef X_HAVE_UTF8_STRING
+  if (t == XG_UTF8_STRING)
+#else
   if (t == XA_STRING)
+#endif
     return NSStringPboardType;
   else if (t == XG_TEXT)
     return NSStringPboardType;
@@ -160,6 +180,7 @@
   return True;
 }
 
+#ifdef USE_xConvertSelection 
 // This never gets called! 
 static unsigned char*
 xConvertSelection(Display* display,
@@ -245,6 +266,7 @@
 
   return data;
 }
+#endif // USE_xConvertSelection  defined
 
 @interface     XPbOwner : NSObject
 {
@@ -673,8 +695,13 @@
           * Ask the X system to provide the pasteboard data in the
           * appropriate property of our application root window.
           */
+#ifdef X_HAVE_UTF8_STRING
+         XConvertSelection(xDisplay, [self xPb], XG_UTF8_STRING,
+           [self xPb], xAppWin, whenRequested);
+#else // X_HAVE_UTF8_STRING not defined
          XConvertSelection(xDisplay, [self xPb], XA_STRING,
            [self xPb], xAppWin, whenRequested);
+#endif // X_HAVE_UTF8_STRING not defined
          XFlush(xDisplay);
 
          /*
@@ -766,7 +793,11 @@
   int          status;
   unsigned char        *data;
   Atom         actual_target;
+#ifdef X_HAVE_UTF8_STRING
+  Atom         new_target = XG_UTF8_STRING;
+#else // X_HAVE_UTF8_STRING not defined
   Atom         new_target = XA_STRING;
+#endif // X_HAVE_UTF8_STRING
   int          actual_format;
   unsigned long        bytes_remaining;
   unsigned long        number_items;
@@ -799,6 +830,22 @@
 // Convert data to text string.
 // string = PropertyToString(xDisplay,new_target,number_items,(char*)data);
 
+#ifdef X_HAVE_UTF8_STRING
+      if (actual_target == XG_UTF8_STRING)
+       {
+         NSData        *d;
+         NSString      *s;
+
+         d = [[NSData alloc] initWithBytes: (void *)data
+                                    length: number_items];
+         s = [[NSString alloc] initWithData: d
+                                   encoding: NSUTF8StringEncoding];
+         RELEASE(d);
+         d = [NSSerializer serializePropertyList: s];
+         RELEASE(s);
+         [self setData: d];
+       }
+#else // X_HAVE_UTF8_STRING not defined
       if (new_target == XA_STRING)
        {
          NSData        *d;
@@ -813,6 +860,7 @@
          RELEASE(s);
          [self setData: d];
        }
+#endif // X_HAVE_UTF8_STRING not defined
       else
        {
          NSLog(@"Unsupported data type from X selection.");
@@ -964,7 +1012,11 @@
          if ([osType isEqualToString: NSStringPboardType])
            {
              NSString  *s = [_pb stringForType: NSStringPboardType];
+#ifdef X_HAVE_UTF8_STRING
+             NSData *d = [s dataUsingEncoding: NSUTF8StringEncoding];
+#else // X_HAVE_UTF8_STRING not defined
              NSData *d = [s dataUsingEncoding: NSISOLatin1StringEncoding];
+#endif // X_HAVE_UTF8_STRING not defined
 
              format = 8;
              if (d != nil)
@@ -1056,7 +1108,11 @@
        * The property doesn't exist - so we will be creating a new (empty)
        * property.
        */
+#ifdef X_HAVE_UTF8_STRING
+      actualType = XG_UTF8_STRING;
+#else // X_HAVE_UTF8_STRING not defined
       actualType = XA_STRING;
+#endif // X_HAVE_UTF8_STRING not defined
       actualFormat = 8;
     }
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]