comparison src/gtkimhtml.c @ 8719:513b8bbcc104

[gaim-migrate @ 9474] " This fixes a bug where pasting a link, or in general clicking in the middle of it and then sending would get the link tag stuck on, and everything you typed after that would be a link, unless you pasted some nonlink rich text. This also makes it so you can't append to a link when it's the last character of the buffer, like you can every other tag. Also, I made some slight improvements to copy/pasting. Seems the length parameter (in pasted_received_cb) is the total bytes, not the number of x bit (where x often = 16) units. So that (length * (bits/8)) thing that I think Sean was doing was causing problems." --Tim Ringenbach - marv_sf oh and i have apparently attributed much of datallah's work today to other people committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Tue, 20 Apr 2004 04:08:24 +0000
parents 4c7bc4b0f190
children 3ac178eedac2
comparison
equal deleted inserted replaced
8718:6ab61697426e 8719:513b8bbcc104
555 /* Mozilla asks that we start our text/html with the Unicode byte order mark */ 555 /* Mozilla asks that we start our text/html with the Unicode byte order mark */
556 str = g_string_append_unichar(str, 0xfeff); 556 str = g_string_append_unichar(str, 0xfeff);
557 str = g_string_append(str, text); 557 str = g_string_append(str, text);
558 str = g_string_append_unichar(str, 0x0000); 558 str = g_string_append_unichar(str, 0x0000);
559 selection = g_convert(str->str, str->len, "UCS-2", "UTF-8", NULL, &len, NULL); 559 selection = g_convert(str->str, str->len, "UCS-2", "UTF-8", NULL, &len, NULL);
560 gtk_selection_data_set (selection_data, gdk_atom_intern("text/html", FALSE), 16, selection, len); 560 gtk_selection_data_set(selection_data, gdk_atom_intern("text/html", FALSE), 16, selection, len);
561 g_string_free(str, TRUE); 561 g_string_free(str, TRUE);
562 g_free(selection); 562 g_free(selection);
563 } else { 563 } else {
564 if (primary) { 564 if (primary) {
565 text = gtk_imhtml_get_text(imhtml, &start, &end); 565 text = gtk_imhtml_get_text(imhtml, &start, &end);
727 727
728 tmp = gaim_escape_html(text); 728 tmp = gaim_escape_html(text);
729 g_free(text); 729 g_free(text);
730 text = tmp; 730 text = tmp;
731 } else { 731 } else {
732 text = g_malloc((selection_data->format / 8) * selection_data->length); 732 #if 0
733 memcpy(text, selection_data->data, selection_data->length * (selection_data->format / 8)); 733 /* Here's some debug code, for figuring out what sent to us over the clipboard. */
734 {
735 int i;
736
737 gaim_debug_misc("gtkimhtml", "In paste_received_cb():\n\tformat = %d, length = %d\n\t",
738 selection_data->format, selection_data->length);
739
740 for (i = 0; i < (/*(selection_data->format / 8) **/ selection_data->length); i++) {
741 if ((i % 70) == 0)
742 printf("\n\t");
743 if (selection_data->data[i] == '\0')
744 printf(".");
745 else
746 printf("%c", selection_data->data[i]);
747 }
748 printf("\n");
749 }
750 #endif
751 text = g_malloc(selection_data->length);
752 memcpy(text, selection_data->data, selection_data->length);
734 } 753 }
735 754
736 memcpy (&c, text, 2); 755 memcpy (&c, text, 2);
737 if (c == 0xfeff) { 756 if (c == 0xfeff) {
738 /* This is UCS2 */ 757 /* This is UCS2 */
739 char *utf8 = g_convert(text+2, (selection_data->length * (selection_data->format / 8)) - 2, "UTF-8", "UCS-2", NULL, NULL, NULL); 758 char *utf8 = g_convert(text+2, selection_data->length - 2, "UTF-8", "UCS-2", NULL, NULL, NULL);
740 g_free(text); 759 g_free(text);
741 text = utf8; 760 text = utf8;
742 if (!text) { 761 if (!text) {
743 gaim_debug_warning("gtkimhtml", "g_convert failed in paste_received_cb\n"); 762 gaim_debug_warning("gtkimhtml", "g_convert failed in paste_received_cb\n");
744 return; 763 return;
2449 scale->free(scale); 2468 scale->free(scale);
2450 } 2469 }
2451 g_list_free(imhtml->scalables); 2470 g_list_free(imhtml->scalables);
2452 imhtml->scalables = NULL; 2471 imhtml->scalables = NULL;
2453 2472
2454 imhtml->edit.bold = FALSE; 2473 gtk_imhtml_close_tags(imhtml, &start);
2455 imhtml->edit.italic = FALSE;
2456 imhtml->edit.underline = FALSE;
2457
2458 if (imhtml->edit.fontface)
2459 g_free(imhtml->edit.fontface);
2460 imhtml->edit.fontface = NULL;
2461
2462 if (imhtml->edit.forecolor)
2463 g_free(imhtml->edit.forecolor);
2464 imhtml->edit.forecolor = NULL;
2465
2466 if (imhtml->edit.backcolor)
2467 g_free(imhtml->edit.backcolor);
2468 imhtml->edit.backcolor = NULL;
2469
2470 imhtml->edit.fontsize = 0;
2471 2474
2472 g_signal_emit(object, signals[CLEAR_FORMAT], 0); 2475 g_signal_emit(object, signals[CLEAR_FORMAT], 0);
2473 g_object_unref(object); 2476 g_object_unref(object);
2474 } 2477 }
2475 2478
3047 * I may not do this, because people will bitch about Gaim overriding their gtk theme's cursor 3050 * I may not do this, because people will bitch about Gaim overriding their gtk theme's cursor
3048 * colors. 3051 * colors.
3049 * 3052 *
3050 * Just in case I do do this, I asked about what to set the secondary text cursor to. 3053 * Just in case I do do this, I asked about what to set the secondary text cursor to.
3051 * 3054 *
3052 (12:45:27) ?? ???: secondary_cursor_color = (rgb(background) + rgb(primary_cursor_color) ) / 2 * 3055 * (12:45:27) ?? ???: secondary_cursor_color = (rgb(background) + rgb(primary_cursor_color) ) / 2
3053 (12:45:55) ?? ???: understand? * 3056 * (12:45:55) ?? ???: understand?
3054 * (12:46:14) Tim: yeah. i didn't know there was an exact formula 3057 * (12:46:14) Tim: yeah. i didn't know there was an exact formula
3055 (12:46:56) ?? ???: u might need to exactract separate each color from RGB * 3058 * (12:46:56) ?? ???: u might need to exactract separate each color from RGB
3056 */ 3059 */
3057 3060
3058 static void mark_set_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark, 3061 static void mark_set_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark,
3059 GtkIMHtml *imhtml) 3062 GtkIMHtml *imhtml)
3060 { 3063 {
3104 imhtml->edit.backcolor = g_strdup(&(tag->name)[10]); 3107 imhtml->edit.backcolor = g_strdup(&(tag->name)[10]);
3105 if (strncmp(tag->name, "FONT FACE ", 10) == 0) 3108 if (strncmp(tag->name, "FONT FACE ", 10) == 0)
3106 imhtml->edit.fontface = g_strdup(&(tag->name)[10]); 3109 imhtml->edit.fontface = g_strdup(&(tag->name)[10]);
3107 if (strncmp(tag->name, "FONT SIZE ", 10) == 0) 3110 if (strncmp(tag->name, "FONT SIZE ", 10) == 0)
3108 imhtml->edit.fontsize = strtol(&(tag->name)[10], NULL, 10); 3111 imhtml->edit.fontsize = strtol(&(tag->name)[10], NULL, 10);
3109 if (strncmp(tag->name, "LINK ", 5) == 0) 3112 if ((strncmp(tag->name, "LINK ", 5) == 0) && !gtk_text_iter_is_end(&iter))
3110 imhtml->edit.link = tag; 3113 imhtml->edit.link = tag;
3111 } 3114 }
3112 } 3115 }
3113 3116
3114 g_slist_free(tags); 3117 g_slist_free(tags);
3630 if (imhtml->edit.fontface) 3633 if (imhtml->edit.fontface)
3631 gtk_imhtml_toggle_fontface(imhtml, NULL); 3634 gtk_imhtml_toggle_fontface(imhtml, NULL);
3632 3635
3633 imhtml->edit.fontsize = 0; 3636 imhtml->edit.fontsize = 0;
3634 3637
3638 if (imhtml->edit.link)
3639 gtk_imhtml_toggle_link(imhtml, NULL);
3640
3635 gtk_text_buffer_remove_all_tags(imhtml->text_buffer, iter, iter); 3641 gtk_text_buffer_remove_all_tags(imhtml->text_buffer, iter, iter);
3636 3642
3637 } 3643 }
3638 3644
3639 char *gtk_imhtml_get_markup(GtkIMHtml *imhtml) 3645 char *gtk_imhtml_get_markup(GtkIMHtml *imhtml)