Revision: 17833
http://svn.sourceforge.net/gaim/?rev=17833&view=rev
Author: datallah
Date: 2006-11-27 22:37:12 -0800 (Mon, 27 Nov 2006)
Log Message:
-----------
Fix "Paste" and "Paste as Plain Text" from the imhtml on win32.
This was apparently broken by gtk changing how the clipboard is handled internally. This is a much cleaner way to do this anyway.
I should probably check if it works on GTK+ 2.6.10.
Modified Paths:
--------------
trunk/gtk/gtkimhtml.c
Modified: trunk/gtk/gtkimhtml.c
===================================================================
--- trunk/gtk/gtkimhtml.c 2006-11-28 00:15:31 UTC (rev 17832)
+++ trunk/gtk/gtkimhtml.c 2006-11-28 06:37:12 UTC (rev 17833)
@@ -142,7 +142,11 @@
static guint signals [LAST_SIGNAL] = { 0 };
static GtkTargetEntry selection_targets[] = {
+#ifndef _WIN32
{ "text/html", 0, TARGET_HTML },
+#else
+ { "HTML Format", 0, TARGET_HTML },
+#endif
{ "UTF8_STRING", 0, TARGET_UTF8_STRING },
{ "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT },
{ "STRING", 0, TARGET_STRING },
@@ -153,11 +157,6 @@
};
#ifdef _WIN32
-/* Win32 clipboard format value, and functions to convert back and
- * forth between HTML and the clipboard format.
- */
-static UINT win_html_fmt;
-
static gchar *
clipboard_win32_to_html(char *clipboard) {
const char *header;
@@ -241,38 +240,18 @@
return g_string_free(clipboard, FALSE);
}
-static void clipboard_copy_html_win32(GtkIMHtml *imhtml) {
- gchar *clipboard = clipboard_html_to_win32(imhtml->clipboard_html_string);
- if (clipboard != NULL) {
- HWND hwnd = GDK_WINDOW_HWND(GTK_WIDGET(imhtml)->window);
- if (OpenClipboard(hwnd)) {
- if (EmptyClipboard()) {
- gint length = strlen(clipboard);
- HGLOBAL hdata = GlobalAlloc(GMEM_MOVEABLE, length);
- if (hdata != NULL) {
- gchar *buffer = GlobalLock(hdata);
- memcpy(buffer, clipboard, length);
- GlobalUnlock(hdata);
-
- if (SetClipboardData(win_html_fmt, hdata) == NULL) {
- gchar *err_msg =
- g_win32_error_message(GetLastError());
- gaim_debug_info("html clipboard",
- "Unable to set clipboard data: %s\n",
- err_msg ? err_msg : "Unknown Error");
- g_free(err_msg);
- }
- }
- }
- CloseClipboard();
- }
- g_free(clipboard);
- }
-}
-
static gboolean clipboard_paste_html_win32(GtkIMHtml *imhtml) {
gboolean pasted = FALSE;
+ /* Win32 clipboard format value, and functions to convert back and
+ * forth between HTML and the clipboard format.
+ */
+ static UINT win_html_fmt = 0;
+
+ /* Register HTML Format as desired clipboard format */
+ if (!win_html_fmt)
+ win_html_fmt = RegisterClipboardFormat("HTML Format");
+
if (gtk_text_view_get_editable(GTK_TEXT_VIEW(imhtml))
&& IsClipboardFormatAvailable(win_html_fmt)) {
gboolean error_reading_clipboard = FALSE;
@@ -281,7 +260,8 @@
if (OpenClipboard(hwnd)) {
HGLOBAL hdata = GetClipboardData(win_html_fmt);
if (hdata == NULL) {
- error_reading_clipboard = TRUE;
+ if (GetLastError() != ERROR_SUCCESS)
+ error_reading_clipboard = TRUE;
} else {
char *buffer = GlobalLock(hdata);
if (buffer == NULL) {
@@ -298,7 +278,6 @@
}
CloseClipboard();
-
} else {
error_reading_clipboard = TRUE;
}
@@ -892,7 +871,7 @@
static void gtk_imhtml_clipboard_get(GtkClipboard *clipboard, GtkSelectionData *selection_data, guint info, GtkIMHtml *imhtml) {
- char *text;
+ char *text = NULL;
gboolean primary;
GtkTextIter start, end;
GtkTextMark *sel = gtk_text_buffer_get_selection_bound(imhtml->text_buffer);
@@ -903,8 +882,9 @@
primary = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY) == clipboard;
if (info == TARGET_HTML) {
- gsize len;
char *selection;
+#ifndef _WIN32
+ gsize len;
GString *str = g_string_new(NULL);
if (primary) {
text = gtk_imhtml_get_markup_range(imhtml, &start, &end);
@@ -918,6 +898,10 @@
selection = g_convert(str->str, str->len, "UCS-2", "UTF-8", NULL, &len, NULL);
gtk_selection_data_set(selection_data, gdk_atom_intern("text/html", FALSE), 16, (const guchar *)selection, len);
g_string_free(str, TRUE);
+#else
+ selection = clipboard_html_to_win32(imhtml->clipboard_html_string);
+ gtk_selection_data_set(selection_data, gdk_atom_intern("HTML Format", FALSE), 8, (const guchar *)selection, strlen(selection));
+#endif
g_free(selection);
} else {
if (primary) {
@@ -968,12 +952,6 @@
imhtml->clipboard_html_string = gtk_imhtml_get_markup_range(imhtml, &start, &end);
imhtml->clipboard_text_string = gtk_imhtml_get_text(imhtml, &start, &end);
-#ifdef _WIN32
- /* We're going to still copy plain text, but let's toss the "HTML Format"
- we need into the windows clipboard now as well. */
- clipboard_copy_html_win32(imhtml);
-#endif
-
g_signal_stop_emission_by_name(imhtml, "copy-clipboard");
}
@@ -999,12 +977,6 @@
imhtml->clipboard_html_string = gtk_imhtml_get_markup_range(imhtml, &start, &end);
imhtml->clipboard_text_string = gtk_imhtml_get_text(imhtml, &start, &end);
-#ifdef _WIN32
- /* We're going to still copy plain text, but let's toss the "HTML Format"
- we need into the windows clipboard now as well. */
- clipboard_copy_html_win32(imhtml);
-#endif
-
if (imhtml->editable)
gtk_text_buffer_delete_selection(imhtml->text_buffer, FALSE, FALSE);
g_signal_stop_emission_by_name(imhtml, "cut-clipboard");
@@ -1431,11 +1403,6 @@
gtk_imhtml_set_editable(imhtml, FALSE);
g_signal_connect(G_OBJECT(imhtml), "populate-popup",
G_CALLBACK(hijack_menu_cb), NULL);
-
-#ifdef _WIN32
- /* Register HTML Format as desired clipboard format */
- win_html_fmt = RegisterClipboardFormat("HTML Format");
-#endif
}
GtkWidget *gtk_imhtml_new(void *a, void *b)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|