Mercurial > pidgin.yaz
comparison src/gtkimhtml.c @ 11275:ffc86d9ad8b7
[gaim-migrate @ 13461]
Make the new clear formatting button work.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Mon, 15 Aug 2005 19:46:32 +0000 |
parents | 1cbe76d30e81 |
children | 17ebda61c6ce |
comparison
equal
deleted
inserted
replaced
11274:67a929d50cfe | 11275:ffc86d9ad8b7 |
---|---|
1111 | 1111 |
1112 static void imhtml_toggle_format(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons) | 1112 static void imhtml_toggle_format(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons) |
1113 { | 1113 { |
1114 /* since this function is the handler for the formatting keystrokes, | 1114 /* since this function is the handler for the formatting keystrokes, |
1115 we need to check here that the formatting attempted is permitted */ | 1115 we need to check here that the formatting attempted is permitted */ |
1116 if (!(imhtml->format_functions & buttons)) | 1116 buttons &= imhtml->format_functions; |
1117 return; | |
1118 | 1117 |
1119 switch (buttons) { | 1118 switch (buttons) { |
1120 case GTK_IMHTML_BOLD: | 1119 case GTK_IMHTML_BOLD: |
1121 imhtml_toggle_bold(imhtml); | 1120 imhtml_toggle_bold(imhtml); |
1122 break; | 1121 break; |
3829 } | 3828 } |
3830 | 3829 |
3831 void | 3830 void |
3832 gtk_imhtml_clear_formatting(GtkIMHtml *imhtml) | 3831 gtk_imhtml_clear_formatting(GtkIMHtml *imhtml) |
3833 { | 3832 { |
3834 gboolean bold, italic, uline; | 3833 GtkTextIter start, end; |
3835 bold = italic = uline = FALSE; | 3834 GObject *object; |
3836 | 3835 |
3837 gtk_imhtml_get_current_format(imhtml, &bold, &italic, &uline); | 3836 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
3838 if (bold) | 3837 |
3839 gtk_imhtml_toggle_bold(imhtml); | 3838 /* Move the selection bounds, so the format functions will know we want to |
3840 if (italic) | 3839 * manipulate the formatting on the entire buffer. */ |
3841 gtk_imhtml_toggle_italic(imhtml); | 3840 #if GTK_CHECK_VERSION(2,4,0) |
3842 if (uline) | 3841 gtk_text_buffer_select_range(imhtml->text_buffer, &end, &end); |
3843 gtk_imhtml_toggle_underline(imhtml); | 3842 #else |
3844 | 3843 gtk_text_buffer_move_mark_by_name(imhtml->text_buffer, "insert", &end); |
3845 gtk_imhtml_font_set_size(imhtml, 3); | 3844 gtk_text_buffer_move_mark_by_name(imhtml->text_buffer, "selection_bound", &end); |
3846 gtk_imhtml_toggle_fontface(imhtml, NULL); | 3845 #endif |
3847 | 3846 |
3848 gtk_imhtml_toggle_forecolor(imhtml, NULL); | 3847 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); |
3849 gtk_imhtml_toggle_backcolor(imhtml, NULL); | 3848 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); |
3850 gtk_imhtml_toggle_background(imhtml, NULL); | 3849 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); |
3850 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); | |
3851 remove_font_size(imhtml, &start, &end, TRUE); | |
3852 remove_font_face(imhtml, &start, &end, TRUE); | |
3853 remove_font_forecolor(imhtml, &start, &end, TRUE); | |
3854 remove_font_backcolor(imhtml, &start, &end, TRUE); | |
3855 remove_font_background(imhtml, &start, &end, TRUE); | |
3856 | |
3857 imhtml->edit.bold = 0; | |
3858 imhtml->edit.italic = 0; | |
3859 imhtml->edit.underline = 0; | |
3860 imhtml->edit.strike = 0; | |
3861 imhtml->edit.fontsize = 3; | |
3862 imhtml->edit.forecolor = NULL; | |
3863 imhtml->edit.backcolor = NULL; | |
3864 imhtml->edit.background = NULL; | |
3865 | |
3866 object = g_object_ref(G_OBJECT(imhtml)); | |
3867 g_signal_emit(object, signals[CLEAR_FORMAT], 0); | |
3868 g_object_unref(object); | |
3851 | 3869 |
3852 gtk_widget_grab_focus(GTK_WIDGET(imhtml)); | 3870 gtk_widget_grab_focus(GTK_WIDGET(imhtml)); |
3853 } | 3871 } |
3854 | 3872 |
3855 /* | 3873 /* |
3938 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | 3956 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
3939 if (imhtml->edit.bold) | 3957 if (imhtml->edit.bold) |
3940 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); | 3958 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); |
3941 else | 3959 else |
3942 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); | 3960 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); |
3943 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | 3961 } else if (imhtml->editable) { |
3962 if (!gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) | |
3963 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
3964 | |
3944 if (imhtml->edit.bold) | 3965 if (imhtml->edit.bold) |
3945 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); | 3966 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); |
3946 else | 3967 else |
3947 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); | 3968 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); |
3948 | |
3949 } | 3969 } |
3950 } | 3970 } |
3951 | 3971 |
3952 void gtk_imhtml_toggle_bold(GtkIMHtml *imhtml) | 3972 void gtk_imhtml_toggle_bold(GtkIMHtml *imhtml) |
3953 { | 3973 { |
3970 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | 3990 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
3971 if (imhtml->edit.italic) | 3991 if (imhtml->edit.italic) |
3972 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); | 3992 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); |
3973 else | 3993 else |
3974 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); | 3994 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); |
3975 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | 3995 } else if (imhtml->editable) { |
3976 if (imhtml->edit.italic) | 3996 if (!gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) |
3997 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
3998 | |
3999 if (imhtml->edit.bold) | |
3977 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); | 4000 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); |
3978 else | 4001 else |
3979 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); | 4002 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); |
3980 } | 4003 } |
3981 } | 4004 } |
4000 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | 4023 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
4001 if (imhtml->edit.underline) | 4024 if (imhtml->edit.underline) |
4002 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); | 4025 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); |
4003 else | 4026 else |
4004 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); | 4027 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); |
4005 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | 4028 } else if (imhtml->editable) { |
4006 if (imhtml->edit.underline) | 4029 if (!gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) |
4030 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
4031 | |
4032 if (imhtml->edit.bold) | |
4007 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); | 4033 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); |
4008 else | 4034 else |
4009 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); | 4035 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); |
4010 } | 4036 } |
4011 } | 4037 } |
4031 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | 4057 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
4032 if (imhtml->edit.strike) | 4058 if (imhtml->edit.strike) |
4033 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); | 4059 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); |
4034 else | 4060 else |
4035 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); | 4061 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); |
4036 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | 4062 } else if (imhtml->editable) { |
4037 if (imhtml->edit.strike) | 4063 if (!gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) |
4064 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
4065 | |
4066 if (imhtml->edit.bold) | |
4038 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); | 4067 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); |
4039 else | 4068 else |
4040 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); | 4069 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); |
4041 } | 4070 } |
4042 } | 4071 } |
4062 if (imhtml->wbfo) { | 4091 if (imhtml->wbfo) { |
4063 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | 4092 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
4064 remove_font_size(imhtml, &start, &end, TRUE); | 4093 remove_font_size(imhtml, &start, &end, TRUE); |
4065 gtk_text_buffer_apply_tag(imhtml->text_buffer, | 4094 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
4066 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | 4095 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); |
4067 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | 4096 } else if (imhtml->editable) { |
4097 if (!gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) | |
4098 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
4099 | |
4068 remove_font_size(imhtml, &start, &end, FALSE); | 4100 remove_font_size(imhtml, &start, &end, FALSE); |
4069 gtk_text_buffer_apply_tag(imhtml->text_buffer, | 4101 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
4070 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | 4102 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); |
4071 } | 4103 } |
4072 | 4104 |
4090 if (imhtml->wbfo) { | 4122 if (imhtml->wbfo) { |
4091 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | 4123 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
4092 remove_font_size(imhtml, &start, &end, TRUE); | 4124 remove_font_size(imhtml, &start, &end, TRUE); |
4093 gtk_text_buffer_apply_tag(imhtml->text_buffer, | 4125 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
4094 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | 4126 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); |
4095 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | 4127 } else if (imhtml->editable) { |
4128 if (!gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) | |
4129 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
4130 | |
4096 remove_font_size(imhtml, &start, &end, FALSE); | 4131 remove_font_size(imhtml, &start, &end, FALSE); |
4097 gtk_text_buffer_apply_tag(imhtml->text_buffer, | 4132 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
4098 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | 4133 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); |
4099 } | 4134 } |
4100 } | 4135 } |
4125 if (imhtml->wbfo) { | 4160 if (imhtml->wbfo) { |
4126 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | 4161 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
4127 remove_font_size(imhtml, &start, &end, TRUE); | 4162 remove_font_size(imhtml, &start, &end, TRUE); |
4128 gtk_text_buffer_apply_tag(imhtml->text_buffer, | 4163 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
4129 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | 4164 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); |
4130 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | 4165 } else if (imhtml->editable) { |
4166 if (!gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) | |
4167 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
4168 | |
4131 remove_font_size(imhtml, &start, &end, FALSE); | 4169 remove_font_size(imhtml, &start, &end, FALSE); |
4132 gtk_text_buffer_apply_tag(imhtml->text_buffer, | 4170 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
4133 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | 4171 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); |
4134 } | 4172 } |
4135 } | 4173 } |
4161 gtk_text_buffer_apply_tag(imhtml->text_buffer, \ | 4199 gtk_text_buffer_apply_tag(imhtml->text_buffer, \ |
4162 find_func(imhtml, edit_field), &start, &end); \ | 4200 find_func(imhtml, edit_field), &start, &end); \ |
4163 } else { \ | 4201 } else { \ |
4164 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, \ | 4202 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, \ |
4165 gtk_text_buffer_get_mark(imhtml->text_buffer, "insert")); \ | 4203 gtk_text_buffer_get_mark(imhtml->text_buffer, "insert")); \ |
4166 if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { \ | 4204 if (imhtml->editable) { \ |
4205 if (!gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) \ | |
4206 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); \ | |
4207 \ | |
4167 remove_func(imhtml, &start, &end, FALSE); \ | 4208 remove_func(imhtml, &start, &end, FALSE); \ |
4168 gtk_text_buffer_apply_tag(imhtml->text_buffer, \ | 4209 gtk_text_buffer_apply_tag(imhtml->text_buffer, \ |
4169 find_func(imhtml, \ | 4210 find_func(imhtml, \ |
4170 edit_field), \ | 4211 edit_field), \ |
4171 &start, &end); \ | 4212 &start, &end); \ |
4228 imhtml->edit.link = linktag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL); | 4269 imhtml->edit.link = linktag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL); |
4229 } | 4270 } |
4230 g_object_set_data_full(G_OBJECT(linktag), "link_url", g_strdup(url), g_free); | 4271 g_object_set_data_full(G_OBJECT(linktag), "link_url", g_strdup(url), g_free); |
4231 g_signal_connect(G_OBJECT(linktag), "event", G_CALLBACK(tag_event), NULL); | 4272 g_signal_connect(G_OBJECT(linktag), "event", G_CALLBACK(tag_event), NULL); |
4232 | 4273 |
4233 if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | 4274 if (imhtml->editable) { |
4275 if (!gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) | |
4276 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
4277 | |
4234 remove_font_link(imhtml, &start, &end, FALSE); | 4278 remove_font_link(imhtml, &start, &end, FALSE); |
4235 gtk_text_buffer_apply_tag(imhtml->text_buffer, linktag, &start, &end); | 4279 gtk_text_buffer_apply_tag(imhtml->text_buffer, linktag, &start, &end); |
4236 } | 4280 } |
4237 } | 4281 } |
4238 | 4282 |