2009-01-16 Carlos Alberto Cortez <calberto.cortez@ggmail.com>
authorCarlos Alberto Cortez <calberto.cortez@gmail.com>
Fri, 16 Jan 2009 20:46:48 +0000 (20:46 -0000)
committerCarlos Alberto Cortez <calberto.cortez@gmail.com>
Fri, 16 Jan 2009 20:46:48 +0000 (20:46 -0000)
* X11Structs.cs:
* XplatUIX11.cs: Properly encode/decode the unicode strings we
store/retrieve in the Clipboard. Also, since we try to convert the
data to different formats, separate the source and the result of
it, so we can always fallback to the original and don't mix wrong
conversions.

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

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

index 0b1a5cc6417bd04c4b700ca90bbc4d82beef27d5..fe429c03a9eb43cf8d2f7f196fb73b5119131983 100644 (file)
@@ -1,3 +1,12 @@
+2009-01-16  Carlos Alberto Cortez <calberto.cortez@ggmail.com>
+
+       * X11Structs.cs:
+       * XplatUIX11.cs: Properly encode/decode the unicode strings we
+       store/retrieve in the Clipboard. Also, since we try to convert the
+       data to different formats, separate the source and the result of
+       it, so we can always fallback to the original and don't mix wrong
+       conversions.
+
 2009-01-16  Mike Gorse  <mgorse@novell.com>
 
        * TextControl.cs: Add UIASelectionChanged event.
index 38622afb6735c01caddc797849fa0eed1055eff7..497d5a7d669d7089b7dd5c7ae0a0386b5be7d7f7 100644 (file)
@@ -1479,6 +1479,7 @@ namespace System.Windows.Forms {
        }
 
        internal struct ClipboardStruct {
+               internal object         Source;
                internal object         Item;                   // Object on the clipboard
                internal object         Type;                   // Type if object on the clipboard
                internal ArrayList      Formats;                // list of formats available in the clipboard
index fac55677ec8163a8e17bb53f4b2a174a39417072..9938b66e0a53063d2bf4202cb6bae1dab4c73dec 100644 (file)
@@ -1249,7 +1249,7 @@ namespace System.Windows.Forms {
                                } else if (property == OEMTEXT) {
                                        Clipboard.Item = Marshal.PtrToStringAnsi(prop);
                                } else if (property == UNICODETEXT) {
-                                       Clipboard.Item = Marshal.PtrToStringAnsi(prop);
+                                       Clipboard.Item = Marshal.PtrToStringUni (prop, Encoding.Unicode.GetMaxCharCount ((int)nitems));
                                } else if (property == RICHTEXTFORMAT)
                                        Clipboard.Item = Marshal.PtrToStringAnsi(prop);
 
@@ -1724,7 +1724,7 @@ namespace System.Windows.Forms {
                                                                xevent.SelectionRequestEvent.target == (IntPtr)RICHTEXTFORMAT) {
                                                        Byte[] bytes;
 
-                                                       bytes = new ASCIIEncoding().GetBytes((string)Clipboard.Item);
+                                                       bytes = new ASCIIEncoding().GetBytes((string)Clipboard.Source);
                                                        buffer = Marshal.AllocHGlobal(bytes.Length);
                                                        buflen = bytes.Length;
 
@@ -1733,14 +1733,19 @@ namespace System.Windows.Forms {
                                                        }
                                                } else if (xevent.SelectionRequestEvent.target == OEMTEXT) {
                                                        // FIXME - this should encode into ISO2022
-                                                       buffer = Marshal.StringToHGlobalAnsi((string)Clipboard.Item);
+                                                       buffer = Marshal.StringToHGlobalAnsi((string)Clipboard.Source);
                                                        while (Marshal.ReadByte(buffer, buflen) != 0) {
                                                                buflen++;
                                                        }
                                                } else if (xevent.SelectionRequestEvent.target == UNICODETEXT) {
-                                                       buffer = Marshal.StringToHGlobalAnsi((string)Clipboard.Item);
-                                                       while (Marshal.ReadByte(buffer, buflen) != 0) {
-                                                               buflen++;
+                                                       Byte [] bytes;
+
+                                                       bytes = Encoding.Unicode.GetBytes ((string)Clipboard.Source);
+                                                       buffer = Marshal.AllocHGlobal (bytes.Length);
+                                                       buflen = bytes.Length;
+
+                                                       for (int i = 0; i < buflen; i++) {
+                                                               Marshal.WriteByte (buffer, i, bytes [i]);
                                                        }
                                                } else {
                                                        buffer = IntPtr.Zero;
@@ -1781,6 +1786,7 @@ namespace System.Windows.Forms {
                                                        TranslatePropertyToClipboard(xevent.SelectionEvent.property);
                                                } else {
                                                        Clipboard.Item = null;
+                                                       Clipboard.Source = null;
                                                }
                                        } else {
                                                Dnd.HandleSelectionNotifyEvent (ref xevent);
@@ -2635,6 +2641,7 @@ namespace System.Windows.Forms {
                }
 
                internal override void ClipboardStore(IntPtr handle, object obj, int type, XplatUI.ObjectToClipboard converter) {
+                       Clipboard.Source = obj;
                        Clipboard.Item = obj;
                        Clipboard.Type = type;
                        Clipboard.Converter = converter;