2009-04-26 Carlos Alberto Cortez <calberto.cortez@gmail.com>
authorCarlos Alberto Cortez <calberto.cortez@gmail.com>
Mon, 27 Apr 2009 06:09:22 +0000 (06:09 -0000)
committerCarlos Alberto Cortez <calberto.cortez@gmail.com>
Mon, 27 Apr 2009 06:09:22 +0000 (06:09 -0000)
* XplatUIX11.cs: Properly support UTF8 when handling the
SelectionRequest event - this is helpful supporting some window
managers, such KDE, that explictly request the text in utf8, as
opposed to gnome, that supports ascii.
Fixes #489393.

svn path=/trunk/mcs/; revision=132698

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUIX11.cs

index 2f7f8ef05ffddd88fe8ef4c411bd760c50bd611b..d78c5d182de0f9a9b3b7bc27a53062984af62102 100644 (file)
@@ -1,3 +1,11 @@
+2009-04-26  Carlos Alberto Cortez <calberto.cortez@gmail.com> 
+
+       * XplatUIX11.cs: Properly support UTF8 when handling the
+       SelectionRequest event - this is helpful supporting some window
+       managers, such KDE, that explictly request the text in utf8, as
+       opposed to gnome, that supports ascii.
+       Fixes #489393.
+
 2009-04-26  Carlos Alberto Cortez <calberto.cortez@gmail.com>
 
        * ToolStripDropDownItem.cs: When assigning a new
index 736a270d52e8a05775fe6dd806a0df4ca74b21f9..b5398c9b7675c540b13734d7eeb0fd5a21915d85 100644 (file)
@@ -1742,40 +1742,31 @@ namespace System.Windows.Forms {
                                                        Marshal.FreeHGlobal(buffer);
                                                }
                                        } else if (Clipboard.IsSourceText) {
-                                               IntPtr  buffer;
+                                               IntPtr  buffer = IntPtr.Zero;
                                                int     buflen;
+                                               Encoding encoding = null;
 
                                                buflen = 0;
 
+                                               // Select an encoding depending on the target
                                                IntPtr target_atom = xevent.SelectionRequestEvent.target;
-                                               if (target_atom == (IntPtr)Atom.XA_STRING) {
-                                                       Byte[] bytes;
-
-                                                       bytes = Encoding.ASCII.GetBytes(Clipboard.GetPlainText ());
-                                                       buffer = Marshal.AllocHGlobal(bytes.Length);
-                                                       buflen = bytes.Length;
-
-                                                       for (int i = 0; i < buflen; i++) {
-                                                               Marshal.WriteByte(buffer, i, bytes[i]);
-                                                       }
-                                               } else if (target_atom == OEMTEXT) {
-                                                       // FIXME - this should encode into ISO2022
-                                                       buffer = Marshal.StringToHGlobalAnsi(Clipboard.GetPlainText ());
-                                                       while (Marshal.ReadByte(buffer, buflen) != 0) {
-                                                               buflen++;
-                                                       }
-                                               } else if (target_atom == UTF16_STRING) {
+                                               if (target_atom == (IntPtr)Atom.XA_STRING || target_atom == OEMTEXT)
+                                                       // FIXME - EOMTEXT should encode into ISO2022
+                                                       encoding = Encoding.ASCII;
+                                               else if (target_atom == UTF16_STRING)
+                                                       encoding = Encoding.Unicode;
+                                               else if (target_atom == UTF8_STRING)
+                                                       encoding = Encoding.UTF8;
+
+                                               if (encoding != null) {
                                                        Byte [] bytes;
 
-                                                       bytes = Encoding.Unicode.GetBytes (Clipboard.GetPlainText ());
+                                                       bytes = encoding.GetBytes (Clipboard.GetPlainText ());
                                                        buffer = Marshal.AllocHGlobal (bytes.Length);
                                                        buflen = bytes.Length;
 
-                                                       for (int i = 0; i < buflen; i++) {
+                                                       for (int i = 0; i < buflen; i++)
                                                                Marshal.WriteByte (buffer, i, bytes [i]);
-                                                       }
-                                               } else {
-                                                       buffer = IntPtr.Zero;
                                                }
 
                                                if (buffer != IntPtr.Zero) {