changeset 8481:6d0869404696

[gaim-migrate @ 9214] " this fixes and should close 9, 10, and 12 on simguys list... those are... 9 Buttons that are pushed in when text is sent, stay pushed in. They should reset to the default for the line based on the B/I/U preferences. 10 Buttons are not properly pushed in if B/I/U are set in the prefs when the conversation window appears. 12 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. While working on these i uncovered another bug which i'll start working on shortly, but thats no reason to hold this back when someone may find something I missed..." --Gary Kramlich as per his note, this does not fix moving the cursor with the mouse, but that doesn't work without this patch either. committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Sun, 21 Mar 2004 18:38:30 +0000
parents b0cebd011cc0
children 791c05d1679d
files src/dialogs.c src/gtkconv.c src/gtkimhtml.c src/gtkimhtml.h src/gtkimhtmltoolbar.c
diffstat 5 files changed, 222 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/src/dialogs.c	Sun Mar 21 18:24:29 2004 +0000
+++ b/src/dialogs.c	Sun Mar 21 18:38:30 2004 +0000
@@ -797,6 +797,10 @@
 	gtk_imhtml_set_editable(GTK_IMHTML(ca->text), TRUE);
 	gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(ca->text), GTK_WRAP_WORD_CHAR);
 
+	gtk_imhtml_smiley_shortcuts(GTK_IMHTML(ca->text),
+			gaim_prefs_get_bool("/gaim/gtk/conversations/smiley_shortcuts"));
+	gtk_imhtml_html_shortcuts(GTK_IMHTML(ca->text),
+			gaim_prefs_get_bool("/gaim/gtk/conversations/html_shortcuts"));
 	if (gaim_prefs_get_bool("/gaim/gtk/conversations/spellcheck"))
 		gaim_gtk_setup_gtkspell(GTK_TEXT_VIEW(ca->text));
 	gtk_imhtmltoolbar_attach(GTK_IMHTMLTOOLBAR(ca->toolbar), ca->text);
--- a/src/gtkconv.c	Sun Mar 21 18:24:29 2004 +0000
+++ b/src/gtkconv.c	Sun Mar 21 18:38:30 2004 +0000
@@ -227,13 +227,13 @@
 	{
 		if (gaim_prefs_get_bool("/gaim/gtk/conversations/send_bold"))
 			gtk_imhtml_toggle_bold(GTK_IMHTML(c->entry));
-
+		
 		if (gaim_prefs_get_bool("/gaim/gtk/conversations/send_italic"))
 			gtk_imhtml_toggle_italic(GTK_IMHTML(c->entry));
 
 		if (gaim_prefs_get_bool("/gaim/gtk/conversations/send_underline"))
 			gtk_imhtml_toggle_underline(GTK_IMHTML(c->entry));
-
+		
 		if (gaim_prefs_get_bool("/gaim/gtk/conversations/use_custom_font") ||
 			c->has_font)
 		{
@@ -3787,7 +3787,6 @@
 		gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->entry));
 	gaim_setup_imhtml(gtkconv->entry);
 	gtk_imhtml_set_editable(GTK_IMHTML(gtkconv->entry), TRUE);
-	default_formatize(conv);
 	gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(gtkconv->entry),
 								GTK_WRAP_WORD_CHAR);
 	gtk_widget_set_size_request(gtkconv->entry, -1,
@@ -3811,6 +3810,10 @@
 	gtk_widget_show(gtkconv->entry);
 	gtk_imhtmltoolbar_attach(GTK_IMHTMLTOOLBAR(gtkconv->toolbar),
 							 gtkconv->entry);
+	/* had to move this after the imtoolbar is attached so that the
+	 * signals get fired to toggle the buttons on the toolbar as well.
+	 */
+	default_formatize(conv);
 
 	gtkconv->bbox = gtk_hbox_new(FALSE, 6);
 	gtk_box_pack_start(GTK_BOX(vbox2), gtkconv->bbox, FALSE, FALSE, 0);
--- a/src/gtkimhtml.c	Sun Mar 21 18:24:29 2004 +0000
+++ b/src/gtkimhtml.c	Sun Mar 21 18:38:30 2004 +0000
@@ -367,7 +367,6 @@
 
 gboolean gtk_key_pressed_cb(GtkIMHtml *imhtml, GdkEventKey *event, gpointer data)
 {	
-	GObject *object;
 	char buf[7];
 	buf[0] = '\0';
 
@@ -390,9 +389,6 @@
 			if (imhtml->format_functions & GTK_IMHTML_BOLD) {
 				if(imhtml->html_shortcuts) {
 					gtk_imhtml_toggle_bold(imhtml);
-					object = g_object_ref(G_OBJECT(imhtml));
-					g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_BOLD);
-					g_object_unref(object);
 					return TRUE;
 				}
 			}
@@ -410,27 +406,23 @@
 			
 		case 'i':
 		case 'I':
-			if (imhtml->format_functions & GTK_IMHTML_ITALIC)
+			if (imhtml->format_functions & GTK_IMHTML_ITALIC) {
 				if(imhtml->html_shortcuts) {
 					gtk_imhtml_toggle_italic(imhtml);
-					object = g_object_ref(G_OBJECT(imhtml));
-					g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_ITALIC);
-					g_object_unref(object);
 					return TRUE;
 				}
+			}
 			return FALSE;
 			break;
 			
 		case 'u':  /* ctrl-u is GDK_Clear, which clears the line. */
 		case 'U':
-			if (imhtml->format_functions & GTK_IMHTML_UNDERLINE)
+			if (imhtml->format_functions & GTK_IMHTML_UNDERLINE) {
 				if(imhtml->html_shortcuts) {
 					gtk_imhtml_toggle_underline(imhtml);
-					object = g_object_ref(G_OBJECT(imhtml));
-					g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_UNDERLINE);
-					g_object_unref(object);
 					return TRUE;
 				}
+			}
 			return FALSE;
 			break;
 			
@@ -656,8 +648,8 @@
 					      G_STRUCT_OFFSET(GtkIMHtmlClass, clear_format),
 					      NULL,
 					      0,
-					      g_cclosure_marshal_VOID__VOID,
-					     G_TYPE_NONE, 0);
+						  g_cclosure_marshal_VOID__VOID,
+						  G_TYPE_NONE, 0);
 	gobject_class->finalize = gtk_imhtml_finalize;
 }
 
@@ -2078,6 +2070,7 @@
 			g_free, (GDestroyNotify)gtk_smiley_tree_destroy);
 	imhtml->default_smilies = gtk_smiley_tree_new();
 }
+
 void       gtk_imhtml_show_smileys     (GtkIMHtml        *imhtml,
 					gboolean          show)
 {
@@ -2144,7 +2137,7 @@
 	imhtml->edit.backcolor = NULL;
 	imhtml->edit.sizespan = NULL;
 	imhtml->edit.fontsize = 3;
-	printf("Emiting signal\n");
+
 	g_signal_emit(object, signals[CLEAR_FORMAT], 0);
 	g_object_unref(object);
 }
@@ -2556,6 +2549,59 @@
 	g_object_unref(object);
 }
 
+void gtk_imhtml_get_current_format(GtkIMHtml *imhtml, gint offset,
+								   gboolean *bold, gboolean *italic,
+								   gboolean *underline)
+{
+	GtkTextMark *ins_mark;
+	GtkTextIter ins_iter, adj_iter, end_iter;
+	GSList *tags;
+	gint position, length, adjusted;
+	
+	printf("get_current_format\n");
+	
+	/* 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;
+	}
+	
+	printf("position: %d, offset: %d, length: %d, adjusted: %d\n",
+		   position, offset, length, adjusted);
+	
+	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);
+		tags != NULL; tags = tags->next)
+	{
+		GtkTextTag *tag = GTK_TEXT_TAG(tags->data);
+		if(tag->name) {
+			printf("tag: %s\n", tag->name);
+			if(g_ascii_strcasecmp(tag->name, "BOLD") == 0)
+				(*bold) = TRUE;
+			if(g_ascii_strcasecmp(tag->name, "ITALICS") == 0)
+				(*italic) = TRUE;
+			if(g_ascii_strcasecmp(tag->name, "UNDERLINE") == 0)
+				(*underline) = TRUE;
+		}
+	}
+}
+
 gboolean gtk_imhtml_get_editable(GtkIMHtml *imhtml)
 {
 	return imhtml->editable;
@@ -2564,17 +2610,20 @@
 gboolean gtk_imhtml_toggle_bold(GtkIMHtml *imhtml)
 {
 	GtkIMHtmlFormatSpan *span;
+	GObject *object;
 	GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer);
 	GtkTextIter iter;
+	
 	gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins);
+	
 	if (!imhtml->edit.bold) {
-		span = g_malloc(sizeof(GtkIMHtmlFormatSpan));
+		span = g_new0(GtkIMHtmlFormatSpan, 1);
 		span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE);
 		span->start_tag = g_strdup("<b>");
 		span->end = NULL;
 		span->end_tag = g_strdup("</b>");
 		span->buffer = imhtml->text_buffer;
-		span->tag =  gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), "BOLD");
+		span->tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), "BOLD");
 		imhtml->edit.bold = span;
 		imhtml->format_spans = g_list_append(imhtml->format_spans, span);
 	} else {
@@ -2592,17 +2641,25 @@
 		}
 		imhtml->edit.bold = NULL;
 	}
-	return imhtml->edit.bold != NULL;
+
+	object = g_object_ref(G_OBJECT(imhtml));
+	g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_BOLD);
+	g_object_unref(object);
+
+	return (imhtml->edit.bold != NULL);
 }
 
 gboolean gtk_imhtml_toggle_italic(GtkIMHtml *imhtml)
 {
 	GtkIMHtmlFormatSpan *span;
+	GObject *object;
 	GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer);
 	GtkTextIter iter;
+	
 	gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins);
+	
 	if (!imhtml->edit.italic) {
-		span = g_malloc(sizeof(GtkIMHtmlFormatSpan));
+		span = g_new0(GtkIMHtmlFormatSpan, 1);
 		span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE);
 		span->start_tag = g_strdup("<i>");
 		span->end = NULL;
@@ -2626,17 +2683,25 @@
 		}
 		imhtml->edit.italic = NULL;
 	}
+
+	object = g_object_ref(G_OBJECT(imhtml));
+	g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_ITALIC);
+	g_object_unref(object);
+
 	return imhtml->edit.italic != NULL;
 }
 
 gboolean gtk_imhtml_toggle_underline(GtkIMHtml *imhtml)
 {
 	GtkIMHtmlFormatSpan *span;
+	GObject *object;
 	GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer);
 	GtkTextIter iter;
+
 	gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins);
+
 	if (!imhtml->edit.underline) {
-		span = g_malloc(sizeof(GtkIMHtmlFormatSpan));
+		span = g_new0(GtkIMHtmlFormatSpan, 1);
 		span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE);
 		span->start_tag = g_strdup("<u>");
 		span->end = NULL;
@@ -2660,6 +2725,11 @@
 		}
 		imhtml->edit.underline = NULL;
 	}
+
+	object = g_object_ref(G_OBJECT(imhtml));
+	g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_UNDERLINE);
+	g_object_unref(object);
+
 	return imhtml->edit.underline != NULL;
 }
 
@@ -2909,6 +2979,7 @@
 	GList *starters = imhtml->format_spans;
 	GList *closers = NULL;
 	GString *str = g_string_new("");
+	
 	g_list_sort_with_data(starters, (GCompareDataFunc)span_compare_begin, imhtml->text_buffer);
 
 	gtk_text_iter_order(start, end);
@@ -2946,7 +3017,11 @@
 				 * can't, for some reason.  The warning depends on how much HTML I send
 				 * in my message, kind of.
 				 */
+				/* comment this out until myself or someone else finishes
+				 * it.  This is supposed to apply a tag to selected text,
+				 * i believe...
 				gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &eiter, espan->end);
+				 */
 			}
 			sspan = (GtkIMHtmlFormatSpan*)starters->data;
 			gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &siter, sspan->start);
--- a/src/gtkimhtml.h	Sun Mar 21 18:24:29 2004 +0000
+++ b/src/gtkimhtml.h	Sun Mar 21 18:38:30 2004 +0000
@@ -231,6 +231,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);
 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 21 18:24:29 2004 +0000
+++ b/src/gtkimhtmltoolbar.c	Sun Mar 21 18:38:30 2004 +0000
@@ -36,24 +36,57 @@
 
 static void do_bold(GtkWidget *bold, GtkIMHtmlToolbar *toolbar)
 {
+	GObject *object;
+	
 	g_return_if_fail(toolbar);
+	
+	/* block the format_function_toggle handler */
+	object = g_object_ref(G_OBJECT(GTK_IMHTML(toolbar->imhtml)));
+	g_signal_handlers_block_matched(object,	G_SIGNAL_MATCH_DATA, 0, 0, NULL,
+									NULL, toolbar);
 	gtk_imhtml_toggle_bold(GTK_IMHTML(toolbar->imhtml));
+	g_signal_handlers_unblock_matched(object, G_SIGNAL_MATCH_DATA, 0, 0, NULL,
+									  NULL, toolbar);
+	g_object_unref(object);
+	
 	gtk_widget_grab_focus(toolbar->imhtml);
 }
 
 static void
 do_italic(GtkWidget *italic, GtkIMHtmlToolbar *toolbar)
 {
+	GObject *object;
+	
 	g_return_if_fail(toolbar);
+	
+	/* block the format_function_toggle handler */
+	object = g_object_ref(G_OBJECT(GTK_IMHTML(toolbar->imhtml)));
+	g_signal_handlers_block_matched(object,	G_SIGNAL_MATCH_DATA, 0, 0, NULL,
+									NULL, toolbar);
 	gtk_imhtml_toggle_italic(GTK_IMHTML(toolbar->imhtml));
+	g_signal_handlers_unblock_matched(object, G_SIGNAL_MATCH_DATA, 0, 0, NULL,
+									  NULL, toolbar);
+	g_object_unref(object);
+	
 	gtk_widget_grab_focus(toolbar->imhtml);
 }
 
 static void
 do_underline(GtkWidget *underline, GtkIMHtmlToolbar *toolbar)
 {
+	GObject *object;
+	
 	g_return_if_fail(toolbar);
+	
+	/* block the format_function_toggle handler */
+	object = g_object_ref(G_OBJECT(GTK_IMHTML(toolbar->imhtml)));
+	g_signal_handlers_block_matched(object,	G_SIGNAL_MATCH_DATA, 0, 0, NULL,
+									NULL, toolbar);
 	gtk_imhtml_toggle_underline(GTK_IMHTML(toolbar->imhtml));
+	g_signal_handlers_unblock_matched(object, G_SIGNAL_MATCH_DATA, 0, 0, NULL,
+									  NULL, toolbar);
+	g_object_unref(object);
+	
 	gtk_widget_grab_focus(toolbar->imhtml);
 }
 
@@ -77,8 +110,6 @@
 	gtk_widget_grab_focus(toolbar->imhtml);
 }
 
-
-
 static void
 destroy_toolbar_font(GtkWidget *widget, GdkEvent *event,
 					 GtkIMHtmlToolbar *toolbar)
@@ -602,7 +633,6 @@
 
 static void update_buttons_cb(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons, GtkIMHtmlToolbar *toolbar)
 {
-
 	gtk_widget_set_sensitive(GTK_WIDGET(toolbar->bold), buttons & GTK_IMHTML_BOLD);
 	gtk_widget_set_sensitive(GTK_WIDGET(toolbar->italic), buttons & GTK_IMHTML_ITALIC);
 	gtk_widget_set_sensitive(GTK_WIDGET(toolbar->underline), buttons & GTK_IMHTML_UNDERLINE);
@@ -617,33 +647,81 @@
 	gtk_widget_set_sensitive(GTK_WIDGET(toolbar->image), buttons & GTK_IMHTML_IMAGE);
 	gtk_widget_set_sensitive(GTK_WIDGET(toolbar->link), buttons & GTK_IMHTML_LINK);
 	gtk_widget_set_sensitive(GTK_WIDGET(toolbar->smiley), buttons & GTK_IMHTML_SMILEY);
+}
 
+/* we call this when we want to _set_active the toggle button, it'll
+ * block the callback thats connected to the button so we don't have to
+ * do the double toggling hack
+ */
+static void toggle_button_set_active_block(GtkToggleButton *button,
+										   gboolean is_active,
+										   GtkIMHtmlToolbar *toolbar)
+{
+	GObject *object;
+	g_return_if_fail(toolbar);
+
+	object = g_object_ref(button);
+	g_signal_handlers_block_matched(object, G_SIGNAL_MATCH_DATA,
+									0, 0, NULL, NULL, toolbar);
+	gtk_toggle_button_set_active(button, is_active);
+	g_signal_handlers_unblock_matched(object, G_SIGNAL_MATCH_DATA,
+									  0, 0, NULL, NULL, toolbar);
+	g_object_unref(object);
 }
 
 static void toggle_button_cb(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons, GtkIMHtmlToolbar *toolbar)
 {
-	/* This is hacky.  I have to tolerate the fact that set_active causes the signal to be emited, so I wind up
-	 * toggling in gtkimhtml twice here */
-
-	if (buttons & GTK_IMHTML_BOLD) {
-		gtk_imhtml_toggle_bold(imhtml);
-		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->bold), !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->bold)));
-	}
+	if (buttons & GTK_IMHTML_BOLD)
+		toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->bold),
+									   !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->bold)),
+									   toolbar);
 
-	if (buttons & GTK_IMHTML_ITALIC) {
-		gtk_imhtml_toggle_italic(imhtml);
-		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->italic), !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->italic)));
-	}
+	if (buttons & GTK_IMHTML_ITALIC)
+		toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->italic),
+									   !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->italic)),
+									   toolbar);
 
-	if (buttons & GTK_IMHTML_UNDERLINE) {
-		gtk_imhtml_toggle_underline(imhtml);
-		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->underline), !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->underline)));
-	}
+	if (buttons & GTK_IMHTML_UNDERLINE)
+		toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->underline),
+									   !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->underline)),
+									   toolbar);
 }
 
 static void reset_buttons_cb(GtkIMHtml *imhtml, GtkIMHtmlToolbar *toolbar)
 {
-	printf("yo!\n");
+	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 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);	
+
+	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);
 }
 
 enum {
@@ -893,6 +971,8 @@
 
 void gtk_imhtmltoolbar_attach(GtkIMHtmlToolbar *toolbar, GtkWidget *imhtml)
 {
+	gboolean bold, italic, underline;
+
 	g_return_if_fail(toolbar != NULL);
 	g_return_if_fail(GTK_IS_IMHTMLTOOLBAR(toolbar));
 	g_return_if_fail(imhtml != NULL);
@@ -902,6 +982,23 @@
 	g_signal_connect(G_OBJECT(imhtml), "format_functions_update", G_CALLBACK(update_buttons_cb), toolbar);
 	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_after(G_OBJECT(imhtml), "move_cursor", G_CALLBACK(cursor_moved_cb), toolbar);
+
+	bold = italic = underline = FALSE;
+
+	gtk_imhtml_get_current_format(GTK_IMHTML(imhtml), 0, &bold, &italic, &underline);
+	
+	if(bold)
+		toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->bold), bold,
+									   toolbar);
+	
+	if(italic)
+		toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->italic), italic,
+									   toolbar);
+
+	if(underline)
+		toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->underline),
+									   underline, toolbar);
 }
 
 void gtk_imhtmltoolbar_associate_smileys(GtkIMHtmlToolbar *toolbar, const char *proto_id)