Mercurial > pidgin.yaz
changeset 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 | 67a929d50cfe |
children | 17ebda61c6ce |
files | src/gtkconv.c src/gtkimhtml.c src/gtkimhtmltoolbar.c src/gtkprefs.c |
diffstat | 4 files changed, 108 insertions(+), 52 deletions(-) [+] |
line wrap: on
line diff
--- a/src/gtkconv.c Mon Aug 15 16:22:25 2005 +0000 +++ b/src/gtkconv.c Mon Aug 15 19:46:32 2005 +0000 @@ -364,6 +364,12 @@ } } +static void +clear_formatting_cb(GtkIMHtml *imhtml, GaimGtkConversation *gtkconv) +{ + default_formatize(gtkconv); +} + static const char * gaim_gtk_get_cmd_prefix(void) { @@ -1766,7 +1772,6 @@ conv->send_history = conv->send_history->next; gtk_imhtml_clear(GTK_IMHTML(gtkconv->entry)); - gtk_imhtml_clear_formatting(GTK_IMHTML(gtkconv->entry)); gtk_imhtml_append_text_with_images( GTK_IMHTML(gtkconv->entry), conv->send_history->data, 0, NULL); @@ -1790,7 +1795,6 @@ conv->send_history = conv->send_history->prev; gtk_imhtml_clear(GTK_IMHTML(gtkconv->entry)); - gtk_imhtml_clear_formatting(GTK_IMHTML(gtkconv->entry)); gtk_imhtml_append_text_with_images( GTK_IMHTML(gtkconv->entry), conv->send_history->data, 0, NULL); @@ -4182,6 +4186,9 @@ */ default_formatize(gtkconv); + g_signal_connect_after(G_OBJECT(gtkconv->entry), "format_function_clear", + G_CALLBACK(clear_formatting_cb), gtkconv); + gtkconv->u.im->animate = gaim_prefs_get_bool("/gaim/gtk/conversations/im/animate_buddy_icons"); gtkconv->u.im->show_icon = TRUE;
--- a/src/gtkimhtml.c Mon Aug 15 16:22:25 2005 +0000 +++ b/src/gtkimhtml.c Mon Aug 15 19:46:32 2005 +0000 @@ -1113,8 +1113,7 @@ { /* since this function is the handler for the formatting keystrokes, we need to check here that the formatting attempted is permitted */ - if (!(imhtml->format_functions & buttons)) - return; + buttons &= imhtml->format_functions; switch (buttons) { case GTK_IMHTML_BOLD: @@ -3831,23 +3830,42 @@ void gtk_imhtml_clear_formatting(GtkIMHtml *imhtml) { - gboolean bold, italic, uline; - bold = italic = uline = FALSE; - - gtk_imhtml_get_current_format(imhtml, &bold, &italic, &uline); - if (bold) - gtk_imhtml_toggle_bold(imhtml); - if (italic) - gtk_imhtml_toggle_italic(imhtml); - if (uline) - gtk_imhtml_toggle_underline(imhtml); - - gtk_imhtml_font_set_size(imhtml, 3); - gtk_imhtml_toggle_fontface(imhtml, NULL); - - gtk_imhtml_toggle_forecolor(imhtml, NULL); - gtk_imhtml_toggle_backcolor(imhtml, NULL); - gtk_imhtml_toggle_background(imhtml, NULL); + GtkTextIter start, end; + GObject *object; + + gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); + + /* Move the selection bounds, so the format functions will know we want to + * manipulate the formatting on the entire buffer. */ +#if GTK_CHECK_VERSION(2,4,0) + gtk_text_buffer_select_range(imhtml->text_buffer, &end, &end); +#else + gtk_text_buffer_move_mark_by_name(imhtml->text_buffer, "insert", &end); + gtk_text_buffer_move_mark_by_name(imhtml->text_buffer, "selection_bound", &end); +#endif + + gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); + gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); + gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); + gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); + remove_font_size(imhtml, &start, &end, TRUE); + remove_font_face(imhtml, &start, &end, TRUE); + remove_font_forecolor(imhtml, &start, &end, TRUE); + remove_font_backcolor(imhtml, &start, &end, TRUE); + remove_font_background(imhtml, &start, &end, TRUE); + + imhtml->edit.bold = 0; + imhtml->edit.italic = 0; + imhtml->edit.underline = 0; + imhtml->edit.strike = 0; + imhtml->edit.fontsize = 3; + imhtml->edit.forecolor = NULL; + imhtml->edit.backcolor = NULL; + imhtml->edit.background = NULL; + + object = g_object_ref(G_OBJECT(imhtml)); + g_signal_emit(object, signals[CLEAR_FORMAT], 0); + g_object_unref(object); gtk_widget_grab_focus(GTK_WIDGET(imhtml)); } @@ -3940,12 +3958,14 @@ gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); else gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); - } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { + } else if (imhtml->editable) { + if (!gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) + gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); + if (imhtml->edit.bold) gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); else gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); - } } @@ -3972,8 +3992,11 @@ gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); else gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); - } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { - if (imhtml->edit.italic) + } else if (imhtml->editable) { + if (!gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) + gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); + + if (imhtml->edit.bold) gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); else gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); @@ -4002,8 +4025,11 @@ gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); else gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); - } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { - if (imhtml->edit.underline) + } else if (imhtml->editable) { + if (!gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) + gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); + + if (imhtml->edit.bold) gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); else gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); @@ -4033,8 +4059,11 @@ gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); else gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); - } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { - if (imhtml->edit.strike) + } else if (imhtml->editable) { + if (!gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) + gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); + + if (imhtml->edit.bold) gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); else gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); @@ -4064,7 +4093,10 @@ remove_font_size(imhtml, &start, &end, TRUE); gtk_text_buffer_apply_tag(imhtml->text_buffer, find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); - } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { + } else if (imhtml->editable) { + if (!gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) + gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); + remove_font_size(imhtml, &start, &end, FALSE); gtk_text_buffer_apply_tag(imhtml->text_buffer, find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); @@ -4092,7 +4124,10 @@ remove_font_size(imhtml, &start, &end, TRUE); gtk_text_buffer_apply_tag(imhtml->text_buffer, find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); - } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { + } else if (imhtml->editable) { + if (!gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) + gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); + remove_font_size(imhtml, &start, &end, FALSE); gtk_text_buffer_apply_tag(imhtml->text_buffer, find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); @@ -4127,7 +4162,10 @@ remove_font_size(imhtml, &start, &end, TRUE); gtk_text_buffer_apply_tag(imhtml->text_buffer, find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); - } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { + } else if (imhtml->editable) { + if (!gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) + gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); + remove_font_size(imhtml, &start, &end, FALSE); gtk_text_buffer_apply_tag(imhtml->text_buffer, find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); @@ -4163,7 +4201,10 @@ } else { \ gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, \ gtk_text_buffer_get_mark(imhtml->text_buffer, "insert")); \ - if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { \ + if (imhtml->editable) { \ + if (!gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) \ + gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); \ +\ remove_func(imhtml, &start, &end, FALSE); \ gtk_text_buffer_apply_tag(imhtml->text_buffer, \ find_func(imhtml, \ @@ -4230,7 +4271,10 @@ g_object_set_data_full(G_OBJECT(linktag), "link_url", g_strdup(url), g_free); g_signal_connect(G_OBJECT(linktag), "event", G_CALLBACK(tag_event), NULL); - if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { + if (imhtml->editable) { + if (!gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) + gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); + remove_font_link(imhtml, &start, &end, FALSE); gtk_text_buffer_apply_tag(imhtml->text_buffer, linktag, &start, &end); }
--- a/src/gtkimhtmltoolbar.c Mon Aug 15 16:22:25 2005 +0000 +++ b/src/gtkimhtmltoolbar.c Mon Aug 15 19:46:32 2005 +0000 @@ -38,6 +38,11 @@ static GtkHBoxClass *parent_class = NULL; +static void toggle_button_set_active_block(GtkToggleButton *button, + gboolean is_active, + GtkIMHtmlToolbar *toolbar); + + static void do_bold(GtkWidget *bold, GtkIMHtmlToolbar *toolbar) { g_return_if_fail(toolbar != NULL); @@ -324,7 +329,7 @@ static void clear_formatting_cb(GtkWidget *clear, GtkIMHtmlToolbar *toolbar) { - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->clear), FALSE); + toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->clear), FALSE, toolbar); gtk_imhtml_clear_formatting(GTK_IMHTML(toolbar->imhtml)); } @@ -772,21 +777,6 @@ g_object_unref(object); } -static void reset_buttons_cb(GtkIMHtml *imhtml, GtkIMHtmlToolbar *toolbar) -{ - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->bold))) - toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->bold), FALSE, - toolbar); - - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->italic))) - toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->italic), - FALSE, toolbar); - - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->underline))) - toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->underline), - FALSE, toolbar); -} - static void update_buttons(GtkIMHtmlToolbar *toolbar) { gboolean bold, italic, underline; char *tmp; @@ -1111,7 +1101,7 @@ toolbar->imhtml = imhtml; g_signal_connect(G_OBJECT(imhtml), "format_buttons_update", G_CALLBACK(update_buttons_cb), toolbar); g_signal_connect_after(G_OBJECT(imhtml), "format_function_toggle", G_CALLBACK(toggle_button_cb), toolbar); - g_signal_connect(G_OBJECT(imhtml), "format_function_clear", G_CALLBACK(reset_buttons_cb), toolbar); + g_signal_connect_after(G_OBJECT(imhtml), "format_function_clear", G_CALLBACK(update_format_cb), toolbar); g_signal_connect(G_OBJECT(imhtml), "format_function_update", G_CALLBACK(update_format_cb), toolbar); g_signal_connect_after(G_OBJECT(GTK_IMHTML(imhtml)->text_buffer), "mark-set", G_CALLBACK(mark_set_cb), toolbar);
--- a/src/gtkprefs.c Mon Aug 15 16:22:25 2005 +0000 +++ b/src/gtkprefs.c Mon Aug 15 19:46:32 2005 +0000 @@ -818,6 +818,20 @@ } } +static void +formatting_clear_cb(GtkIMHtml *imhtml, void *data) +{ + gaim_prefs_set_bool("/gaim/gtk/conversations/send_bold", FALSE); + gaim_prefs_set_bool("/gaim/gtk/conversations/send_italic", FALSE); + gaim_prefs_set_bool("/gaim/gtk/conversations/send_underline", FALSE); + + gaim_prefs_set_int("/gaim/gtk/conversations/font_size", 3); + + gaim_prefs_set_string("/gaim/gtk/conversations/font_face", ""); + gaim_prefs_set_string("/gaim/gtk/conversations/fgcolor", ""); + gaim_prefs_set_string("/gaim/gtk/conversations/bgcolor", ""); +} + static GtkWidget * list_page() { @@ -929,7 +943,8 @@ g_signal_connect_after(G_OBJECT(imhtml), "format_function_toggle", G_CALLBACK(formatting_toggle_cb), toolbar); - + g_signal_connect_after(G_OBJECT(imhtml), "format_function_clear", + G_CALLBACK(formatting_clear_cb), NULL); /* All the tab options! */ vbox = gaim_gtk_make_frame(ret, _("Tab Options"));