Mercurial > pidgin.yaz
comparison src/gtkimhtml.c @ 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 | d0380151c6d1 |
children | b6971539f7af |
comparison
equal
deleted
inserted
replaced
9464:4a69de50f11a | 9465:8a4797a608ae |
---|---|
147 */ | 147 */ |
148 static UINT win_html_fmt; | 148 static UINT win_html_fmt; |
149 | 149 |
150 static gchar * | 150 static gchar * |
151 clipboard_win32_to_html(char *clipboard) { | 151 clipboard_win32_to_html(char *clipboard) { |
152 const char *header; | |
152 const char *begin, *end; | 153 const char *begin, *end; |
154 gint start=0; | |
155 gint finish=0; | |
153 gchar *html; | 156 gchar *html; |
154 | 157 FILE *fd; |
155 begin = strstr(clipboard, "<!--StartFragment"); | 158 |
156 while(*begin++ != '>'); | 159 #if 0 /* Debugging for Windows clipboard */ |
157 end = strstr(clipboard, "<!--EndFragment"); | 160 gaim_debug_info("imhtml clipboard", "from clipboard: %s\n", clipboard); |
158 html = g_strstrip(g_strndup(begin, (end ? (end - begin) : strlen(begin)))); | 161 |
162 fd = fopen("e:\\gaimcb.txt", "wb"); | |
163 fprintf(fd, "%s", clipboard); | |
164 fclose(fd); | |
165 #endif | |
166 | |
167 if (header = strstr(clipboard, "Version:1.0\n")) | |
168 | |
169 if (!(header = strstr(clipboard, "StartFragment:"))) | |
170 return NULL; | |
171 | |
172 sscanf(header, "StartFragment:%d", &start); | |
173 | |
174 header = strstr(clipboard, "EndFragment:"); | |
175 sscanf(header, "EndFragment:%d", &finish); | |
176 | |
177 begin = clipboard + start; | |
178 | |
179 if (header == NULL) | |
180 end = clipboard + strlen(clipboard); | |
181 else | |
182 end = clipboard + finish; | |
183 | |
184 html = g_strstrip(g_strndup(begin, end-begin)); | |
185 | |
186 #if 0 /* Debugging for Windows clipboard */ | |
187 gaim_debug_info("imhtml clipboard", "HTML fragment: %s\n", html); | |
188 #endif | |
189 | |
159 return html; | 190 return html; |
160 } | 191 } |
161 | 192 |
162 static gchar * | 193 static gchar * |
163 clipboard_html_to_win32(char *html) { | 194 clipboard_html_to_win32(char *html) { |
167 | 198 |
168 if (html == NULL) | 199 if (html == NULL) |
169 return NULL; | 200 return NULL; |
170 | 201 |
171 length = strlen(html); | 202 length = strlen(html); |
172 clipboard = g_string_new ("Version:0.9\r\n"); | 203 clipboard = g_string_new ("Version:1.0\r\n"); |
173 g_string_append(clipboard, "StartHTML:0000000105\r\n"); | 204 g_string_append(clipboard, "StartHTML:0000000105\r\n"); |
174 g_string_append(clipboard, g_strdup_printf("EndHTML:%010d\r\n", 143 + length)); | 205 g_string_append(clipboard, g_strdup_printf("EndHTML:%010d\r\n", 147 + length)); |
175 g_string_append(clipboard, "StartFragment:0000000105\r\n"); | 206 g_string_append(clipboard, "StartFragment:0000000127\r\n"); |
176 g_string_append(clipboard, g_strdup_printf("EndFragment:%010d\r\n", 143 + length)); | 207 g_string_append(clipboard, g_strdup_printf("EndFragment:%010d\r\n", 127 + length)); |
177 g_string_append(clipboard, "<!--StartFragment-->"); | 208 g_string_append(clipboard, "<!--StartFragment-->\r\n"); |
178 g_string_append(clipboard, html); | 209 g_string_append(clipboard, html); |
179 g_string_append(clipboard, "<!--EndFragment-->"); | 210 g_string_append(clipboard, "\r\n<!--EndFragment-->"); |
180 ret = clipboard->str; | 211 ret = clipboard->str; |
181 g_string_free(clipboard, FALSE); | 212 g_string_free(clipboard, FALSE); |
213 | |
214 #if 0 /* Debugging for Windows clipboard */ | |
215 gaim_debug_info("imhtml clipboard", "from gaim: %s\n", ret); | |
216 #endif | |
217 | |
182 return ret; | 218 return ret; |
183 } | 219 } |
184 #endif | 220 #endif |
185 | 221 |
186 static GtkSmileyTree* | 222 static GtkSmileyTree* |
723 } | 759 } |
724 | 760 |
725 static void imhtml_paste_insert(GtkIMHtml *imhtml, const char *text, gboolean plaintext) | 761 static void imhtml_paste_insert(GtkIMHtml *imhtml, const char *text, gboolean plaintext) |
726 { | 762 { |
727 GtkTextIter iter; | 763 GtkTextIter iter; |
728 GtkIMHtmlOptions flags = plaintext ? 0 : GTK_IMHTML_NO_NEWLINE; | 764 GtkIMHtmlOptions flags = plaintext ? 0 : (GTK_IMHTML_NO_NEWLINE | GTK_IMHTML_NO_COMMENTS); |
729 | 765 |
730 if (gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) | 766 if (gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) |
731 gtk_text_buffer_delete_selection(imhtml->text_buffer, TRUE, TRUE); | 767 gtk_text_buffer_delete_selection(imhtml->text_buffer, TRUE, TRUE); |
732 | 768 |
733 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, gtk_text_buffer_get_insert(imhtml->text_buffer)); | 769 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, gtk_text_buffer_get_insert(imhtml->text_buffer)); |
2461 case 60: /* SPAN */ | 2497 case 60: /* SPAN */ |
2462 break; | 2498 break; |
2463 case 62: /* comment */ | 2499 case 62: /* comment */ |
2464 /* NEW_BIT (NEW_TEXT_BIT); */ | 2500 /* NEW_BIT (NEW_TEXT_BIT); */ |
2465 ws[wpos] = '\0'; | 2501 ws[wpos] = '\0'; |
2502 | |
2466 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | 2503 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
2467 | 2504 |
2468 if (imhtml->show_comments) | 2505 if (imhtml->show_comments && !(options & GTK_IMHTML_NO_COMMENTS)) |
2469 wpos = g_snprintf (ws, len, "%s", tag); | 2506 wpos = g_snprintf (ws, len, "%s", tag); |
2470 /* NEW_BIT (NEW_COMMENT_BIT); */ | 2507 /* NEW_BIT (NEW_COMMENT_BIT); */ |
2471 break; | 2508 break; |
2472 default: | 2509 default: |
2473 break; | 2510 break; |