GNOME Bugzilla – Bug 649390
CRLF text is copied to clipboard as CRCRLF on Windows
Last modified: 2013-06-18 12:38:10 UTC
Created attachment 187214 [details] Repro in O'Caml Copying text containing CRLF line endings to the clipboard is broken in the current Windows port. For example, copying "Hello\r\nBye" using gtk_clipboard_set_text results in the text "Hello\r\r\nBye" on the clipboard. The general phenomenon is that GTK/GDK replaces LFs by CRLFs, and it copies existing CRs as-is. Repro ===== - Run the O'Caml program clipboard_test.ml in attach. - Run the C# program get_clipboard.cs in attach. The output is incorrect. As evidence that the problem is in GTK/GDK and not in Windows or C#: - Run the C# program set_clipboard.cs in attach. - Run the C# program get_clipboard.cs in attach. The output is correct. Proposed Fix ============ I believe the problem could be solved easily if the LF-to-CRLF conversion code in function _gdk_win32_window_change_property in file gdk/win32/gdkproperty-win32.c were made more robust so that it would properly convert LF, CR, and CRLF line endings to CRLF. Detailed Control Flow ===================== gtk_clipboard_set_text gtk_clipboard_set_with_data(get_func=text_get_func) gtk_target_list_add_text_targets adds targets utf8_atom (="UTF8_STRING") and others gtk_clipboard_set_contents gtk_selection_owner_set_for_display gdk_selection_owner_set_for_display _gdk_win32_display_set_selection_owner gdk_event_put(type=GDK_SELECTION_REQUEST, target=_utf8_string (="UTF8_STRING", see gdk/win32/gdkmain-win32.c)) gtk_selection_add_targets gdk_win32_selection_add_targets // Only relevant for delay-rendered formats gtk_main g_main_loop_run ... gtk_main_do_event(event.type=GDK_SELECTION_REQUEST) gtk_widget_event gtk_widget_event_internal g_signal_emit(signal="selection-request-event") _gtk_selection_request gtk_selection_invoke_handler g_signal_emit_by_name("selection-get", data, info) "selection-get" event on clipboard widget selection_get_cb (in gtk/gtkselection.c) text_get_func gtk_selection_data_set_text gtk_selection_data_set gdk_property_change _gdk_win32_window_change_property (in gdk/win32/gdkproperty-win32.c) SetClipboardData(CF_UNICODETEXT, lf2crlf(data)) There are a number of places in gdk/win32/gdkselection-win32.c and gtk/gtkselection.c where the required conversions are done but these are not on the code path that results from a gtk_selection_set_text call.
Created attachment 187215 [details] C# program to show the contents of the clipboard
Created attachment 187216 [details] C# program for setting the contents of the clipboard
Created attachment 237498 [details] [review] Patch for the issue.
Any reason why this stupidly annoying bug isn't fixed yet, even though it has a patch for such a long time?
After much googling (I'm not a developer), I managed to cross-compile GTK with this fix applied and tested it on Windows 7. I can confirm that this patch does fix this particular problem.
thanks for testing !
Review of attachment 237498 [details] [review]: lets get this in, then
Pushed to gtk-2-24 and git master. This problem has been fixed in our software repository. The fix will go into the next software release. Thank you for your bug report.