comparison src/gtkimhtml.c @ 11276:17ebda61c6ce

[gaim-migrate @ 13463] Revert part of my last commit because I'm dumb. Then, fix the Ctrl-Up and Ctrl-Down that I broke when fixing the clear button. Now both of those (along with everything else I fixed) should work... I hope! committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Mon, 15 Aug 2005 22:48:20 +0000
parents ffc86d9ad8b7
children 421007f39e53
comparison
equal deleted inserted replaced
11275:ffc86d9ad8b7 11276:17ebda61c6ce
3833 GtkTextIter start, end; 3833 GtkTextIter start, end;
3834 GObject *object; 3834 GObject *object;
3835 3835
3836 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); 3836 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
3837 3837
3838 /* Move the selection bounds, so the format functions will know we want to 3838 /* Move the selection bounds (to select everything), so the format functions
3839 * manipulate the formatting on the entire buffer. */ 3839 * will know we want to manipulate the formatting on the entire buffer. */
3840 #if GTK_CHECK_VERSION(2,4,0) 3840 #if GTK_CHECK_VERSION(2,4,0)
3841 gtk_text_buffer_select_range(imhtml->text_buffer, &end, &end); 3841 gtk_text_buffer_select_range(imhtml->text_buffer, &end, &start);
3842 #else 3842 #else
3843 gtk_text_buffer_move_mark_by_name(imhtml->text_buffer, "insert", &end); 3843 gtk_text_buffer_move_mark_by_name(imhtml->text_buffer, "insert", &end);
3844 gtk_text_buffer_move_mark_by_name(imhtml->text_buffer, "selection_bound", &end); 3844 gtk_text_buffer_move_mark_by_name(imhtml->text_buffer, "selection_bound", &start);
3845 #endif 3845 #endif
3846 3846
3847 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); 3847 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end);
3848 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); 3848 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end);
3849 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); 3849 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end);
3863 imhtml->edit.backcolor = NULL; 3863 imhtml->edit.backcolor = NULL;
3864 imhtml->edit.background = NULL; 3864 imhtml->edit.background = NULL;
3865 3865
3866 object = g_object_ref(G_OBJECT(imhtml)); 3866 object = g_object_ref(G_OBJECT(imhtml));
3867 g_signal_emit(object, signals[CLEAR_FORMAT], 0); 3867 g_signal_emit(object, signals[CLEAR_FORMAT], 0);
3868
3869 /* Remove the selection, placing the cursor at the end. */
3870 #if GTK_CHECK_VERSION(2,4,0)
3871 gtk_text_buffer_select_range(imhtml->text_buffer, &end, &end);
3872 #else
3873 gtk_text_buffer_move_mark_by_name(imhtml->text_buffer, "insert", &end);
3874 gtk_text_buffer_move_mark_by_name(imhtml->text_buffer, "selection_bound", &end);
3875 #endif
3876
3877 gtk_widget_grab_focus(GTK_WIDGET(imhtml));
3878
3868 g_object_unref(object); 3879 g_object_unref(object);
3869
3870 gtk_widget_grab_focus(GTK_WIDGET(imhtml));
3871 } 3880 }
3872 3881
3873 /* 3882 /*
3874 * I had this crazy idea about changing the text cursor color to reflex the foreground color 3883 * I had this crazy idea about changing the text cursor color to reflex the foreground color
3875 * of the text about to be entered. This is the place you'd do it, along with the place where 3884 * of the text about to be entered. This is the place you'd do it, along with the place where
3956 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); 3965 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
3957 if (imhtml->edit.bold) 3966 if (imhtml->edit.bold)
3958 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); 3967 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end);
3959 else 3968 else
3960 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); 3969 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end);
3961 } else if (imhtml->editable) { 3970 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
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
3965 if (imhtml->edit.bold) 3971 if (imhtml->edit.bold)
3966 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); 3972 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end);
3967 else 3973 else
3968 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); 3974 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end);
3975
3969 } 3976 }
3970 } 3977 }
3971 3978
3972 void gtk_imhtml_toggle_bold(GtkIMHtml *imhtml) 3979 void gtk_imhtml_toggle_bold(GtkIMHtml *imhtml)
3973 { 3980 {
3990 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); 3997 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
3991 if (imhtml->edit.italic) 3998 if (imhtml->edit.italic)
3992 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); 3999 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end);
3993 else 4000 else
3994 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); 4001 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end);
3995 } else if (imhtml->editable) { 4002 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
3996 if (!gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) 4003 if (imhtml->edit.italic)
3997 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
3998
3999 if (imhtml->edit.bold)
4000 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); 4004 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end);
4001 else 4005 else
4002 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); 4006 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end);
4003 } 4007 }
4004 } 4008 }
4023 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); 4027 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
4024 if (imhtml->edit.underline) 4028 if (imhtml->edit.underline)
4025 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); 4029 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end);
4026 else 4030 else
4027 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); 4031 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end);
4028 } else if (imhtml->editable) { 4032 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
4029 if (!gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) 4033 if (imhtml->edit.underline)
4030 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
4031
4032 if (imhtml->edit.bold)
4033 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); 4034 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end);
4034 else 4035 else
4035 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); 4036 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end);
4036 } 4037 }
4037 } 4038 }
4057 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); 4058 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
4058 if (imhtml->edit.strike) 4059 if (imhtml->edit.strike)
4059 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); 4060 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end);
4060 else 4061 else
4061 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); 4062 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end);
4062 } else if (imhtml->editable) { 4063 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
4063 if (!gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) 4064 if (imhtml->edit.strike)
4064 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
4065
4066 if (imhtml->edit.bold)
4067 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); 4065 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end);
4068 else 4066 else
4069 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); 4067 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end);
4070 } 4068 }
4071 } 4069 }
4091 if (imhtml->wbfo) { 4089 if (imhtml->wbfo) {
4092 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); 4090 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
4093 remove_font_size(imhtml, &start, &end, TRUE); 4091 remove_font_size(imhtml, &start, &end, TRUE);
4094 gtk_text_buffer_apply_tag(imhtml->text_buffer, 4092 gtk_text_buffer_apply_tag(imhtml->text_buffer,
4095 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); 4093 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end);
4096 } else if (imhtml->editable) { 4094 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
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
4100 remove_font_size(imhtml, &start, &end, FALSE); 4095 remove_font_size(imhtml, &start, &end, FALSE);
4101 gtk_text_buffer_apply_tag(imhtml->text_buffer, 4096 gtk_text_buffer_apply_tag(imhtml->text_buffer,
4102 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); 4097 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end);
4103 } 4098 }
4104 4099
4122 if (imhtml->wbfo) { 4117 if (imhtml->wbfo) {
4123 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); 4118 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
4124 remove_font_size(imhtml, &start, &end, TRUE); 4119 remove_font_size(imhtml, &start, &end, TRUE);
4125 gtk_text_buffer_apply_tag(imhtml->text_buffer, 4120 gtk_text_buffer_apply_tag(imhtml->text_buffer,
4126 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); 4121 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end);
4127 } else if (imhtml->editable) { 4122 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
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
4131 remove_font_size(imhtml, &start, &end, FALSE); 4123 remove_font_size(imhtml, &start, &end, FALSE);
4132 gtk_text_buffer_apply_tag(imhtml->text_buffer, 4124 gtk_text_buffer_apply_tag(imhtml->text_buffer,
4133 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); 4125 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end);
4134 } 4126 }
4135 } 4127 }
4160 if (imhtml->wbfo) { 4152 if (imhtml->wbfo) {
4161 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); 4153 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end);
4162 remove_font_size(imhtml, &start, &end, TRUE); 4154 remove_font_size(imhtml, &start, &end, TRUE);
4163 gtk_text_buffer_apply_tag(imhtml->text_buffer, 4155 gtk_text_buffer_apply_tag(imhtml->text_buffer,
4164 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); 4156 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end);
4165 } else if (imhtml->editable) { 4157 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
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
4169 remove_font_size(imhtml, &start, &end, FALSE); 4158 remove_font_size(imhtml, &start, &end, FALSE);
4170 gtk_text_buffer_apply_tag(imhtml->text_buffer, 4159 gtk_text_buffer_apply_tag(imhtml->text_buffer,
4171 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); 4160 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end);
4172 } 4161 }
4173 } 4162 }
4199 gtk_text_buffer_apply_tag(imhtml->text_buffer, \ 4188 gtk_text_buffer_apply_tag(imhtml->text_buffer, \
4200 find_func(imhtml, edit_field), &start, &end); \ 4189 find_func(imhtml, edit_field), &start, &end); \
4201 } else { \ 4190 } else { \
4202 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, \ 4191 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, \
4203 gtk_text_buffer_get_mark(imhtml->text_buffer, "insert")); \ 4192 gtk_text_buffer_get_mark(imhtml->text_buffer, "insert")); \
4204 if (imhtml->editable) { \ 4193 if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { \
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 \
4208 remove_func(imhtml, &start, &end, FALSE); \ 4194 remove_func(imhtml, &start, &end, FALSE); \
4209 gtk_text_buffer_apply_tag(imhtml->text_buffer, \ 4195 gtk_text_buffer_apply_tag(imhtml->text_buffer, \
4210 find_func(imhtml, \ 4196 find_func(imhtml, \
4211 edit_field), \ 4197 edit_field), \
4212 &start, &end); \ 4198 &start, &end); \
4269 imhtml->edit.link = linktag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL); 4255 imhtml->edit.link = linktag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL);
4270 } 4256 }
4271 g_object_set_data_full(G_OBJECT(linktag), "link_url", g_strdup(url), g_free); 4257 g_object_set_data_full(G_OBJECT(linktag), "link_url", g_strdup(url), g_free);
4272 g_signal_connect(G_OBJECT(linktag), "event", G_CALLBACK(tag_event), NULL); 4258 g_signal_connect(G_OBJECT(linktag), "event", G_CALLBACK(tag_event), NULL);
4273 4259
4274 if (imhtml->editable) { 4260 if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
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
4278 remove_font_link(imhtml, &start, &end, FALSE); 4261 remove_font_link(imhtml, &start, &end, FALSE);
4279 gtk_text_buffer_apply_tag(imhtml->text_buffer, linktag, &start, &end); 4262 gtk_text_buffer_apply_tag(imhtml->text_buffer, linktag, &start, &end);
4280 } 4263 }
4281 } 4264 }
4282 4265