Mercurial > pidgin
comparison src/gtkimhtml.c @ 9924:872c4d8c1192
[gaim-migrate @ 10816]
Sam S. added back support for rendering <strike>
Before anyone gets too excited and decides to add back sup, sub, and pre,
I'd like to recode some stuff in imhtml and make it easier and cleaner to
add tags, especially simple boolean tags like strike.
committer: Tailor Script <tailor@pidgin.im>
author | Tim Ringenbach <marv@pidgin.im> |
---|---|
date | Tue, 31 Aug 2004 20:10:21 +0000 |
parents | 650ea0a0d55e |
children | f1f239fa8973 |
comparison
equal
deleted
inserted
replaced
9923:248c3f88ce99 | 9924:872c4d8c1192 |
---|---|
1063 /*gtk_text_view_set_indent(GTK_TEXT_VIEW(imhtml), -15);*/ | 1063 /*gtk_text_view_set_indent(GTK_TEXT_VIEW(imhtml), -15);*/ |
1064 /*gtk_text_view_set_justification(GTK_TEXT_VIEW(imhtml), GTK_JUSTIFY_FILL);*/ | 1064 /*gtk_text_view_set_justification(GTK_TEXT_VIEW(imhtml), GTK_JUSTIFY_FILL);*/ |
1065 | 1065 |
1066 /* These tags will be used often and can be reused--we create them on init and then apply them by name | 1066 /* These tags will be used often and can be reused--we create them on init and then apply them by name |
1067 * other tags (color, size, face, etc.) will have to be created and applied dynamically | 1067 * other tags (color, size, face, etc.) will have to be created and applied dynamically |
1068 * Note that even though we created STRIKE, SUB, SUP, and PRE tags here, we don't really | 1068 * Note that even though we created SUB, SUP, and PRE tags here, we don't really |
1069 * apply them anywhere yet. */ | 1069 * apply them anywhere yet. */ |
1070 gtk_text_buffer_create_tag(imhtml->text_buffer, "BOLD", "weight", PANGO_WEIGHT_BOLD, NULL); | 1070 gtk_text_buffer_create_tag(imhtml->text_buffer, "BOLD", "weight", PANGO_WEIGHT_BOLD, NULL); |
1071 gtk_text_buffer_create_tag(imhtml->text_buffer, "ITALICS", "style", PANGO_STYLE_ITALIC, NULL); | 1071 gtk_text_buffer_create_tag(imhtml->text_buffer, "ITALICS", "style", PANGO_STYLE_ITALIC, NULL); |
1072 gtk_text_buffer_create_tag(imhtml->text_buffer, "UNDERLINE", "underline", PANGO_UNDERLINE_SINGLE, NULL); | 1072 gtk_text_buffer_create_tag(imhtml->text_buffer, "UNDERLINE", "underline", PANGO_UNDERLINE_SINGLE, NULL); |
1073 gtk_text_buffer_create_tag(imhtml->text_buffer, "STRIKE", "strikethrough", TRUE, NULL); | 1073 gtk_text_buffer_create_tag(imhtml->text_buffer, "STRIKE", "strikethrough", TRUE, NULL); |
2100 if ((underline == 0) && (imhtml->format_functions & GTK_IMHTML_UNDERLINE) && !imhtml->wbfo) | 2100 if ((underline == 0) && (imhtml->format_functions & GTK_IMHTML_UNDERLINE) && !imhtml->wbfo) |
2101 gtk_imhtml_toggle_underline(imhtml); | 2101 gtk_imhtml_toggle_underline(imhtml); |
2102 break; | 2102 break; |
2103 case 13: /* S */ | 2103 case 13: /* S */ |
2104 case 14: /* STRIKE */ | 2104 case 14: /* STRIKE */ |
2105 /* FIXME: reimplement this */ | 2105 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
2106 ws[0] = '\0'; wpos = 0; | |
2107 if ((strike == 0) && (imhtml->format_functions & GTK_IMHTML_STRIKE)) | |
2108 gtk_imhtml_toggle_strike(imhtml); | |
2106 strike++; | 2109 strike++; |
2107 break; | 2110 break; |
2108 case 15: /* /S */ | 2111 case 15: /* /S */ |
2109 case 16: /* /STRIKE */ | 2112 case 16: /* /STRIKE */ |
2110 /* FIXME: reimplement this */ | 2113 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
2114 ws[0] = '\0'; wpos = 0; | |
2111 if (strike) | 2115 if (strike) |
2112 strike--; | 2116 strike--; |
2117 if ((strike == 0) && (imhtml->format_functions & GTK_IMHTML_STRIKE) && !imhtml->wbfo) | |
2118 gtk_imhtml_toggle_strike(imhtml); | |
2113 break; | 2119 break; |
2114 case 17: /* SUB */ | 2120 case 17: /* SUB */ |
2115 /* FIXME: reimpliment this */ | 2121 /* FIXME: reimpliment this */ |
2116 sub++; | 2122 sub++; |
2117 break; | 2123 break; |
3295 if (imhtml->edit.underline) | 3301 if (imhtml->edit.underline) |
3296 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, end); | 3302 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, end); |
3297 else | 3303 else |
3298 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, end); | 3304 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, end); |
3299 | 3305 |
3306 if (imhtml->edit.strike) | |
3307 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, end); | |
3308 else | |
3309 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, end); | |
3310 | |
3300 if (imhtml->edit.forecolor) { | 3311 if (imhtml->edit.forecolor) { |
3301 remove_font_forecolor(imhtml, &start, end, TRUE); | 3312 remove_font_forecolor(imhtml, &start, end, TRUE); |
3302 gtk_text_buffer_apply_tag(imhtml->text_buffer, | 3313 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
3303 find_font_forecolor_tag(imhtml, imhtml->edit.forecolor), | 3314 find_font_forecolor_tag(imhtml, imhtml->edit.forecolor), |
3304 &start, end); | 3315 &start, end); |
3444 return; | 3455 return; |
3445 | 3456 |
3446 if (!gtk_text_buffer_get_char_count(buffer)) | 3457 if (!gtk_text_buffer_get_char_count(buffer)) |
3447 return; | 3458 return; |
3448 | 3459 |
3449 imhtml->edit.bold = imhtml->edit.italic = imhtml->edit.underline = FALSE; | 3460 imhtml->edit.bold = imhtml->edit.italic = imhtml->edit.underline = imhtml->edit.strike = FALSE; |
3450 if (imhtml->edit.forecolor) | 3461 if (imhtml->edit.forecolor) |
3451 g_free(imhtml->edit.forecolor); | 3462 g_free(imhtml->edit.forecolor); |
3452 imhtml->edit.forecolor = NULL; | 3463 imhtml->edit.forecolor = NULL; |
3453 if (imhtml->edit.backcolor) | 3464 if (imhtml->edit.backcolor) |
3454 g_free(imhtml->edit.backcolor); | 3465 g_free(imhtml->edit.backcolor); |
3475 imhtml->edit.bold = TRUE; | 3486 imhtml->edit.bold = TRUE; |
3476 if (strcmp(tag->name, "ITALICS") == 0) | 3487 if (strcmp(tag->name, "ITALICS") == 0) |
3477 imhtml->edit.italic = TRUE; | 3488 imhtml->edit.italic = TRUE; |
3478 if (strcmp(tag->name, "UNDERLINE") == 0) | 3489 if (strcmp(tag->name, "UNDERLINE") == 0) |
3479 imhtml->edit.underline = TRUE; | 3490 imhtml->edit.underline = TRUE; |
3491 if (strcmp(tag->name, "STRIKE") == 0) | |
3492 imhtml->edit.strike = TRUE; | |
3480 if (strncmp(tag->name, "FORECOLOR ", 10) == 0) | 3493 if (strncmp(tag->name, "FORECOLOR ", 10) == 0) |
3481 imhtml->edit.forecolor = g_strdup(&(tag->name)[10]); | 3494 imhtml->edit.forecolor = g_strdup(&(tag->name)[10]); |
3482 if (strncmp(tag->name, "BACKCOLOR ", 10) == 0) | 3495 if (strncmp(tag->name, "BACKCOLOR ", 10) == 0) |
3483 imhtml->edit.backcolor = g_strdup(&(tag->name)[10]); | 3496 imhtml->edit.backcolor = g_strdup(&(tag->name)[10]); |
3484 if (strncmp(tag->name, "FONT FACE ", 10) == 0) | 3497 if (strncmp(tag->name, "FONT FACE ", 10) == 0) |
3568 object = g_object_ref(G_OBJECT(imhtml)); | 3581 object = g_object_ref(G_OBJECT(imhtml)); |
3569 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_UNDERLINE); | 3582 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_UNDERLINE); |
3570 g_object_unref(object); | 3583 g_object_unref(object); |
3571 | 3584 |
3572 return imhtml->edit.underline != FALSE; | 3585 return imhtml->edit.underline != FALSE; |
3586 } | |
3587 | |
3588 gboolean gtk_imhtml_toggle_strike(GtkIMHtml *imhtml) | |
3589 { | |
3590 GObject *object; | |
3591 GtkTextIter start, end; | |
3592 | |
3593 imhtml->edit.strike = !imhtml->edit.strike; | |
3594 | |
3595 if (imhtml->wbfo) { | |
3596 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
3597 if (imhtml->edit.strike) | |
3598 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); | |
3599 else | |
3600 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); | |
3601 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
3602 if (imhtml->edit.strike) | |
3603 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); | |
3604 else | |
3605 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); | |
3606 } | |
3607 object = g_object_ref(G_OBJECT(imhtml)); | |
3608 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_STRIKE); | |
3609 g_object_unref(object); | |
3610 | |
3611 return imhtml->edit.strike != FALSE; | |
3573 } | 3612 } |
3574 | 3613 |
3575 void gtk_imhtml_font_set_size(GtkIMHtml *imhtml, gint size) | 3614 void gtk_imhtml_font_set_size(GtkIMHtml *imhtml, gint size) |
3576 { | 3615 { |
3577 GObject *object; | 3616 GObject *object; |
3928 return "<b>"; | 3967 return "<b>"; |
3929 } else if (strcmp(name, "ITALICS") == 0) { | 3968 } else if (strcmp(name, "ITALICS") == 0) { |
3930 return "<i>"; | 3969 return "<i>"; |
3931 } else if (strcmp(name, "UNDERLINE") == 0) { | 3970 } else if (strcmp(name, "UNDERLINE") == 0) { |
3932 return "<u>"; | 3971 return "<u>"; |
3972 } else if (strcmp(name, "STRIKE") == 0) { | |
3973 return "<s>"; | |
3933 } else if (strncmp(name, "LINK ", 5) == 0) { | 3974 } else if (strncmp(name, "LINK ", 5) == 0) { |
3934 char *tmp = g_object_get_data(G_OBJECT(tag), "link_url"); | 3975 char *tmp = g_object_get_data(G_OBJECT(tag), "link_url"); |
3935 if (tmp) { | 3976 if (tmp) { |
3936 g_snprintf(buf, sizeof(buf), "<a href=\"%s\">", tmp); | 3977 g_snprintf(buf, sizeof(buf), "<a href=\"%s\">", tmp); |
3937 buf[sizeof(buf)-1] = '\0'; | 3978 buf[sizeof(buf)-1] = '\0'; |
3967 return "</b>"; | 4008 return "</b>"; |
3968 } else if (strcmp(name, "ITALICS") == 0) { | 4009 } else if (strcmp(name, "ITALICS") == 0) { |
3969 return "</i>"; | 4010 return "</i>"; |
3970 } else if (strcmp(name, "UNDERLINE") == 0) { | 4011 } else if (strcmp(name, "UNDERLINE") == 0) { |
3971 return "</u>"; | 4012 return "</u>"; |
4013 } else if (strcmp(name, "STRIKE") == 0) { | |
4014 return "</s>"; | |
3972 } else if (strncmp(name, "LINK ", 5) == 0) { | 4015 } else if (strncmp(name, "LINK ", 5) == 0) { |
3973 return "</a>"; | 4016 return "</a>"; |
3974 } else if (strncmp(name, "FORECOLOR ", 10) == 0) { | 4017 } else if (strncmp(name, "FORECOLOR ", 10) == 0) { |
3975 return "</font>"; | 4018 return "</font>"; |
3976 } else if (strncmp(name, "BACKCOLOR ", 10) == 0) { | 4019 } else if (strncmp(name, "BACKCOLOR ", 10) == 0) { |
4113 gtk_imhtml_toggle_italic(imhtml); | 4156 gtk_imhtml_toggle_italic(imhtml); |
4114 | 4157 |
4115 if (imhtml->edit.underline) | 4158 if (imhtml->edit.underline) |
4116 gtk_imhtml_toggle_underline(imhtml); | 4159 gtk_imhtml_toggle_underline(imhtml); |
4117 | 4160 |
4161 if (imhtml->edit.strike) | |
4162 gtk_imhtml_toggle_strike(imhtml); | |
4163 | |
4118 if (imhtml->edit.forecolor) | 4164 if (imhtml->edit.forecolor) |
4119 gtk_imhtml_toggle_forecolor(imhtml, NULL); | 4165 gtk_imhtml_toggle_forecolor(imhtml, NULL); |
4120 | 4166 |
4121 if (imhtml->edit.backcolor) | 4167 if (imhtml->edit.backcolor) |
4122 gtk_imhtml_toggle_backcolor(imhtml, NULL); | 4168 gtk_imhtml_toggle_backcolor(imhtml, NULL); |