changeset 9465:8a4797a608ae

[gaim-migrate @ 10290] 1) Fixes the parsing for Win32 clipboard format so that we more accurately grab the right text 2) Revises our Win32 clipboard format conversion to act more like IE, since this is as close as we will get to "the right way" 3) Makes clipboard pasting not paste HTML comments (this one effects linux too, and fixes a problem i've seen pasting from oo.o) committer: Tailor Script <tailor@pidgin.im>
author Tim Ringenbach <marv@pidgin.im>
date Wed, 07 Jul 2004 01:35:27 +0000
parents 4a69de50f11a
children d27156c9c876
files src/gtkimhtml.c
diffstat 1 files changed, 50 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtkimhtml.c	Tue Jul 06 23:16:20 2004 +0000
+++ b/src/gtkimhtml.c	Wed Jul 07 01:35:27 2004 +0000
@@ -149,13 +149,44 @@
 
 static gchar *
 clipboard_win32_to_html(char *clipboard) {
+	const char *header;
 	const char *begin, *end;
+	gint start=0;
+	gint finish=0;
 	gchar *html;
-
-	begin = strstr(clipboard, "<!--StartFragment");
-	while(*begin++ != '>');
-	end = strstr(clipboard, "<!--EndFragment");
-	html = g_strstrip(g_strndup(begin, (end ? (end - begin) : strlen(begin))));
+	FILE *fd;
+
+#if 0 /* Debugging for Windows clipboard */
+	gaim_debug_info("imhtml clipboard", "from clipboard: %s\n", clipboard);
+
+	fd = fopen("e:\\gaimcb.txt", "wb");
+	fprintf(fd, "%s", clipboard);
+	fclose(fd);
+#endif
+
+	if (header = strstr(clipboard, "Version:1.0\n"))
+
+	if (!(header = strstr(clipboard, "StartFragment:")))
+		return NULL;
+
+	sscanf(header, "StartFragment:%d", &start);
+
+	header = strstr(clipboard, "EndFragment:");
+	sscanf(header, "EndFragment:%d", &finish);
+
+	begin = clipboard + start;
+
+	if (header == NULL)
+		end = clipboard + strlen(clipboard);
+	else
+		end = clipboard + finish;
+
+	html = g_strstrip(g_strndup(begin, end-begin));
+
+#if 0 /* Debugging for Windows clipboard */
+	gaim_debug_info("imhtml clipboard", "HTML fragment: %s\n", html);
+#endif
+
 	return html;
 }
 
@@ -169,16 +200,21 @@
 		return NULL;
 
 	length = strlen(html);
-	clipboard = g_string_new ("Version:0.9\r\n");
+	clipboard = g_string_new ("Version:1.0\r\n");
 	g_string_append(clipboard, "StartHTML:0000000105\r\n");
-	g_string_append(clipboard, g_strdup_printf("EndHTML:%010d\r\n", 143 + length));
-	g_string_append(clipboard, "StartFragment:0000000105\r\n");
-	g_string_append(clipboard, g_strdup_printf("EndFragment:%010d\r\n", 143 + length));
-	g_string_append(clipboard, "<!--StartFragment-->");
+	g_string_append(clipboard, g_strdup_printf("EndHTML:%010d\r\n", 147 + length));
+	g_string_append(clipboard, "StartFragment:0000000127\r\n");
+	g_string_append(clipboard, g_strdup_printf("EndFragment:%010d\r\n", 127 + length));
+	g_string_append(clipboard, "<!--StartFragment-->\r\n");
 	g_string_append(clipboard, html);
-	g_string_append(clipboard, "<!--EndFragment-->");
+	g_string_append(clipboard, "\r\n<!--EndFragment-->");
 	ret = clipboard->str;
 	g_string_free(clipboard, FALSE);
+
+#if 0 /* Debugging for Windows clipboard */
+	gaim_debug_info("imhtml clipboard", "from gaim: %s\n", ret);
+#endif
+
 	return ret;
 }
 #endif
@@ -725,7 +761,7 @@
 static void imhtml_paste_insert(GtkIMHtml *imhtml, const char *text, gboolean plaintext)
 {
 	GtkTextIter iter;
-	GtkIMHtmlOptions flags = plaintext ? 0 : GTK_IMHTML_NO_NEWLINE;
+	GtkIMHtmlOptions flags = plaintext ? 0 : (GTK_IMHTML_NO_NEWLINE | GTK_IMHTML_NO_COMMENTS);
 
 	if (gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL))
 		gtk_text_buffer_delete_selection(imhtml->text_buffer, TRUE, TRUE);
@@ -2463,9 +2499,10 @@
 				case 62:	/* comment */
 					/* NEW_BIT (NEW_TEXT_BIT); */
 					ws[wpos] = '\0';
+
 					gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
 
-					if (imhtml->show_comments)
+					if (imhtml->show_comments && !(options & GTK_IMHTML_NO_COMMENTS))
 						wpos = g_snprintf (ws, len, "%s", tag);
 					/* NEW_BIT (NEW_COMMENT_BIT); */
 					break;