Mercurial > pidgin
changeset 8516:5b25f72c4723
[gaim-migrate @ 9254]
" Buttons don't push in and out when the cursor enters
regions that are differently formatted. For example, if
you move the cursor to a place where the text is bold,
the B button should probably be pushed in.
this patch adds the toolbar to update to the current
format when the mouse is clicked. I also cleaned up
some duplicated code and some logic." --Gary Kramlich
okay, that less than clear text basically boils down to you can move the
cursor with the mouse as well as the keyboard without confusing the toolbar
now
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Sun, 28 Mar 2004 18:00:04 +0000 |
parents | 0b0d70464cad |
children | 5cb93726e4d5 |
files | src/gtkimhtml.c src/gtkimhtml.h src/gtkimhtmltoolbar.c |
diffstat | 3 files changed, 64 insertions(+), 54 deletions(-) [+] |
line wrap: on
line diff
--- a/src/gtkimhtml.c Sun Mar 28 17:57:32 2004 +0000 +++ b/src/gtkimhtml.c Sun Mar 28 18:00:04 2004 +0000 @@ -2560,39 +2560,57 @@ g_object_unref(object); } -void gtk_imhtml_get_current_format(GtkIMHtml *imhtml, gint offset, - gboolean *bold, gboolean *italic, - gboolean *underline) +static gboolean +gtk_imhtml_has_open_tags(GtkIMHtml *imhtml) { + if(imhtml->edit.bold && imhtml->edit.bold->end == NULL) + return TRUE; + + if(imhtml->edit.italic && imhtml->edit.italic->end == NULL) + return TRUE; + + if(imhtml->edit.underline && imhtml->edit.underline->end == NULL) + return TRUE; + + if(imhtml->edit.forecolor && imhtml->edit.forecolor->end == NULL) + return TRUE; + + if(imhtml->edit.backcolor && imhtml->edit.backcolor->end == NULL) + return TRUE; + + if(imhtml->edit.fontface && imhtml->edit.fontface->end == NULL) + return TRUE; + + if(imhtml->edit.sizespan && imhtml->edit.sizespan->end == NULL) + return TRUE; + + return FALSE; +} + +void gtk_imhtml_get_current_format(GtkIMHtml *imhtml, gboolean *bold, + gboolean *italic, gboolean *underline) { GtkTextMark *ins_mark; - GtkTextIter ins_iter, adj_iter, end_iter; + GtkTextIter ins_iter; GSList *tags; - gint position, length, adjusted; - - /* grab the current cursor position compensate for the way that the - * direction that the cursor was moved so that we get all the tags - * for that current location - */ + ins_mark = gtk_text_buffer_get_insert(imhtml->text_buffer); gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &ins_iter, ins_mark); - position = gtk_text_iter_get_offset(&ins_iter); - - gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end_iter); - length = gtk_text_iter_get_offset(&end_iter); - - adjusted = position + offset; - if(offset < 0) { /* moving left or up */ - if(adjusted <= 0) - adjusted = 1; - } else if(offset > 0) { /* moving right or down */ - if(adjusted >= length) - adjusted = length - 1; + + if(gtk_imhtml_has_open_tags(imhtml)) { + GtkTextIter end_iter; + gint position, length; + + position = gtk_text_iter_get_offset(&ins_iter); + + gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end_iter); + length = gtk_text_iter_get_offset(&end_iter); + + if(position == length) + gtk_text_buffer_get_iter_at_offset(imhtml->text_buffer, &ins_iter, + length - 1); } - - gtk_text_buffer_get_iter_at_offset(imhtml->text_buffer, &adj_iter, adjusted); - - /* grab the tags that apply to the cursor location */ - for(tags = gtk_text_iter_get_tags(&adj_iter); + + for(tags = gtk_text_iter_get_tags(&ins_iter); tags != NULL; tags = tags->next) { GtkTextTag *tag = GTK_TEXT_TAG(tags->data);
--- a/src/gtkimhtml.h Sun Mar 28 17:57:32 2004 +0000 +++ b/src/gtkimhtml.h Sun Mar 28 18:00:04 2004 +0000 @@ -232,7 +232,7 @@ /* Editable stuff */ void gtk_imhtml_set_editable(GtkIMHtml *imhtml, gboolean editable); void gtk_imhtml_set_format_functions(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons); -void gtk_imhtml_get_current_format(GtkIMHtml *imhtml, gint offset, gboolean *bold, gboolean *italic, gboolean *underline); +void gtk_imhtml_get_current_format(GtkIMHtml *imhtml, gboolean *bold, gboolean *italic, gboolean *underline); gboolean gtk_imhtml_get_editable(GtkIMHtml *imhtml); gboolean gtk_imhtml_toggle_bold(GtkIMHtml *imhtml); gboolean gtk_imhtml_toggle_italic(GtkIMHtml *imhtml);
--- a/src/gtkimhtmltoolbar.c Sun Mar 28 17:57:32 2004 +0000 +++ b/src/gtkimhtmltoolbar.c Sun Mar 28 18:00:04 2004 +0000 @@ -701,46 +701,38 @@ toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->underline), FALSE, toolbar); } -static void update_format_cb(GtkIMHtml *imhtml, GtkIMHtmlToolbar *toolbar) -{ + +static void update_buttons(GtkIMHtmlToolbar *toolbar) { gboolean bold, italic, underline; bold = italic = underline = FALSE; - gtk_imhtml_get_current_format(imhtml, -1, &bold, &italic, &underline); + gtk_imhtml_get_current_format(GTK_IMHTML(toolbar->imhtml), + &bold, &italic, &underline); if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->bold)) != bold) toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->bold), bold, toolbar); - + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->italic)) != italic) toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->italic), italic, toolbar); - + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->underline)) != underline) toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->underline), underline, toolbar); } -static void cursor_moved_cb(GtkIMHtml *imhtml, GtkMovementStep step, - gint change, gboolean selected, - GtkIMHtmlToolbar *toolbar) -{ - gboolean bold, italic, underline; - - bold = italic = underline = FALSE; - gtk_imhtml_get_current_format(imhtml, change, &bold, &italic, &underline); +static void update_format_cb(GtkIMHtml *imhtml, GtkIMHtmlToolbar *toolbar) { + update_buttons(toolbar); +} - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->bold)) != bold) - toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->bold), bold, - toolbar); - - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->italic)) != italic) - toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->italic), italic, - toolbar); - - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->underline)) != underline) - toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->underline), - underline, toolbar); +static void mark_set_cb(GtkTextBuffer *buffer, GtkTextIter *location, + GtkTextMark *mark, GtkIMHtmlToolbar *toolbar) +{ + if(mark != gtk_text_buffer_get_insert(buffer)) + return; + + update_buttons(toolbar); } enum { @@ -1002,11 +994,11 @@ g_signal_connect(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(G_OBJECT(imhtml), "format_function_update", G_CALLBACK(update_format_cb), toolbar); - g_signal_connect_after(G_OBJECT(imhtml), "move_cursor", G_CALLBACK(cursor_moved_cb), toolbar); + g_signal_connect_after(G_OBJECT(GTK_IMHTML(imhtml)->text_buffer), "mark-set", G_CALLBACK(mark_set_cb), toolbar); bold = italic = underline = FALSE; - gtk_imhtml_get_current_format(GTK_IMHTML(imhtml), 0, &bold, &italic, &underline); + gtk_imhtml_get_current_format(GTK_IMHTML(imhtml), &bold, &italic, &underline); if(bold) toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->bold), bold,