changeset 32472:4db23cc97da4

merge of '13d6e924c9257b20e21050646cab88043bdb2e15' and 'a07b7bfd5f979c74126ebea4f86249f24ff00dfd'
author andrew.victor@mxit.com
date Mon, 09 Jan 2012 11:32:01 +0000
parents 307d487f21ee (diff) 49fc653d72c6 (current diff)
children 6ffb26b8a8ce
files
diffstat 12 files changed, 2708 insertions(+), 80 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Jan 09 11:31:00 2012 +0000
+++ b/ChangeLog	Mon Jan 09 11:32:01 2012 +0000
@@ -6,9 +6,12 @@
 	  (Dan Williams) (#13859)
 
 	AIM and ICQ:
-	* Make buddy list management code more efficient. (Oliver) (#4816)
+	* Allow signing on with usernames containing periods and
+	  underscores. (#13500)
+	* Allow adding buddies containing periods and underscores. (#13500)
 	* Don't try to format ICQ usernames entered as email addresses.
 	  Gets rid of an "Unable to format username" error at login. (#13883)
+	* Make buddy list management code more efficient. (Oliver) (#4816)
 
 	Bonjour:
 	* Support file transfers up to ~9 EiB.
--- a/libpurple/protocols/oscar/util.c	Mon Jan 09 11:31:00 2012 +0000
+++ b/libpurple/protocols/oscar/util.c	Mon Jan 09 11:32:01 2012 +0000
@@ -141,12 +141,12 @@
 	if (purple_email_is_valid(name))
 		return TRUE;
 
-	/* Normal AIM usernames can't start with a number */
-	if (isdigit(name[0]))
+	/* Normal AIM usernames can't start with a number, period or underscore */
+	if (isalnum(name[0]))
 		return FALSE;
 
 	for (i = 0; name[i] != '\0'; i++) {
-		if (!isalnum(name[i]) && (name[i] != ' '))
+		if (!isalnum(name[i]) && name[i] != ' ' && name[i] != '.' && name[i] != '_')
 			return FALSE;
 	}
 
--- a/pidgin/Makefile.am	Mon Jan 09 11:31:00 2012 +0000
+++ b/pidgin/Makefile.am	Mon Jan 09 11:32:01 2012 +0000
@@ -86,6 +86,7 @@
 	gtkthemes.c \
 	gtkutils.c \
 	gtkwebview.c \
+	gtkwebviewtoolbar.c \
 	gtkwhiteboard.c \
 	minidialog.c \
 	pidgintooltip.c \
@@ -140,6 +141,7 @@
 	gtkthemes.h \
 	gtkutils.h \
 	gtkwebview.h \
+	gtkwebviewtoolbar.h \
 	gtkwhiteboard.h \
 	minidialog.h \
 	pidgintooltip.h \
--- a/pidgin/Makefile.mingw	Mon Jan 09 11:31:00 2012 +0000
+++ b/pidgin/Makefile.mingw	Mon Jan 09 11:32:01 2012 +0000
@@ -94,6 +94,7 @@
 			gtkthemes.c \
 			gtkutils.c \
 			gtkwebview.c \
+			gtkwebviewtoolbar.c \
 			gtkwhiteboard.c \
 			minidialog.c \
 			pidginstock.c \
--- a/pidgin/gtkconv.c	Mon Jan 09 11:31:00 2012 +0000
+++ b/pidgin/gtkconv.c	Mon Jan 09 11:32:01 2012 +0000
@@ -8381,6 +8381,7 @@
 	purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/conversations/send_bold", FALSE);
 	purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/conversations/send_italic", FALSE);
 	purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/conversations/send_underline", FALSE);
+	purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/conversations/send_strike", FALSE);
 	purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/conversations/spellcheck", TRUE);
 	purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/conversations/show_incoming_formatting", TRUE);
 	purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/conversations/resize_custom_smileys", TRUE);
--- a/pidgin/gtkprefs.c	Mon Jan 09 11:31:00 2012 +0000
+++ b/pidgin/gtkprefs.c	Mon Jan 09 11:32:01 2012 +0000
@@ -48,14 +48,14 @@
 #include "gtkconv-theme.h"
 #include "gtkdebug.h"
 #include "gtkdialogs.h"
-#include "gtkimhtml.h"
-#include "gtkimhtmltoolbar.h"
 #include "gtkprefs.h"
 #include "gtksavedstatuses.h"
 #include "gtksound.h"
 #include "gtkstatus-icon-theme.h"
 #include "gtkthemes.h"
 #include "gtkutils.h"
+#include "gtkwebview.h"
+#include "gtkwebviewtoolbar.h"
 #include "pidginstock.h"
 
 #define PROXYHOST 0
@@ -79,7 +79,7 @@
 static int notebook_page = 0;
 
 /* Conversations page */
-static GtkWidget *sample_imhtml = NULL;
+static GtkWidget *sample_webview = NULL;
 
 /* Themes page */
 static GtkWidget *prefs_sound_themes_combo_box;
@@ -349,7 +349,7 @@
 	prefs_status_themes_combo_box = NULL;
 	prefs_smiley_themes_combo_box = NULL;
 
-	sample_imhtml = NULL;
+	sample_webview = NULL;
 
 	notebook_page = 0;
 	prefsnotebook = NULL;
@@ -991,7 +991,10 @@
 		gtk_tree_model_get(GTK_TREE_MODEL(prefs_smiley_themes), &new_iter, 2, &new_theme, -1);
 
 		purple_prefs_set_string(PIDGIN_PREFS_ROOT "/smileys/theme", new_theme);
-		pidgin_themes_smiley_themeize(sample_imhtml);
+#if 0
+/* TODO: WebKit-ify smileys */
+		pidgin_themes_smiley_themeize(sample_webview);
+#endif
 
 		g_free(new_theme);
 	}
@@ -1280,82 +1283,83 @@
 }
 
 static void
-formatting_toggle_cb(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons, void *toolbar)
+formatting_toggle_cb(GtkWebView *webview, GtkWebViewButtons buttons, void *toolbar)
 {
-	gboolean bold, italic, uline;
-
-	gtk_imhtml_get_current_format(GTK_IMHTML(imhtml),
-								  &bold, &italic, &uline);
-
-	if (buttons & GTK_IMHTML_BOLD)
-		purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/conversations/send_bold", bold);
-	if (buttons & GTK_IMHTML_ITALIC)
-		purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/conversations/send_italic", italic);
-	if (buttons & GTK_IMHTML_UNDERLINE)
-		purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/conversations/send_underline", uline);
-
-	if (buttons & GTK_IMHTML_GROW || buttons & GTK_IMHTML_SHRINK)
+	gboolean bold, italic, uline, strike;
+
+	gtk_webview_get_current_format(webview, &bold, &italic, &uline, &strike);
+
+	if (buttons & GTK_WEBVIEW_BOLD)
+		purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/conversations/send_bold",
+		                      bold);
+	if (buttons & GTK_WEBVIEW_ITALIC)
+		purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/conversations/send_italic",
+		                      italic);
+	if (buttons & GTK_WEBVIEW_UNDERLINE)
+		purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/conversations/send_underline",
+		                      uline);
+	if (buttons & GTK_WEBVIEW_STRIKE)
+		purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/conversations/send_strike",
+		                      strike);
+
+	if (buttons & GTK_WEBVIEW_GROW || buttons & GTK_WEBVIEW_SHRINK)
 		purple_prefs_set_int(PIDGIN_PREFS_ROOT "/conversations/font_size",
-						   gtk_imhtml_get_current_fontsize(GTK_IMHTML(imhtml)));
-	if (buttons & GTK_IMHTML_FACE) {
-		char *face = gtk_imhtml_get_current_fontface(GTK_IMHTML(imhtml));
+		                     gtk_webview_get_current_fontsize(webview));
+	if (buttons & GTK_WEBVIEW_FACE) {
+		const char *face = gtk_webview_get_current_fontface(webview);
 		if (!face)
-			face = g_strdup("");
+			face = "";
 
 		purple_prefs_set_string(PIDGIN_PREFS_ROOT "/conversations/font_face", face);
-		g_free(face);
 	}
 
-	if (buttons & GTK_IMHTML_FORECOLOR) {
-		char *color = gtk_imhtml_get_current_forecolor(GTK_IMHTML(imhtml));
+	if (buttons & GTK_WEBVIEW_FORECOLOR) {
+		const char *color = gtk_webview_get_current_forecolor(webview);
 		if (!color)
-			color = g_strdup("");
+			color = "";
 
 		purple_prefs_set_string(PIDGIN_PREFS_ROOT "/conversations/fgcolor", color);
-		g_free(color);
 	}
 
-	if (buttons & GTK_IMHTML_BACKCOLOR) {
-		char *color;
+	if (buttons & GTK_WEBVIEW_BACKCOLOR) {
+		const char *color;
 		GObject *object;
 
-		color = gtk_imhtml_get_current_backcolor(GTK_IMHTML(imhtml));
+		color = gtk_webview_get_current_backcolor(webview);
 		if (!color)
-			color = g_strdup("");
+			color = "";
 
 		/* Block the signal to prevent a loop. */
-		object = g_object_ref(G_OBJECT(imhtml));
+		object = g_object_ref(G_OBJECT(webview));
 		g_signal_handlers_block_matched(object, G_SIGNAL_MATCH_DATA, 0, 0, NULL,
-										NULL, toolbar);
+		                                NULL, toolbar);
 		/* Clear the backcolor. */
-		gtk_imhtml_toggle_backcolor(GTK_IMHTML(imhtml), "");
+		gtk_webview_toggle_backcolor(webview, "");
 		/* Unblock the signal. */
-		g_signal_handlers_unblock_matched(object, G_SIGNAL_MATCH_DATA, 0, 0, NULL,
-										  NULL, toolbar);
+		g_signal_handlers_unblock_matched(object, G_SIGNAL_MATCH_DATA, 0, 0,
+		                                  NULL, NULL, toolbar);
 		g_object_unref(object);
 
 		/* This will fire a toggle signal and get saved below. */
-		gtk_imhtml_toggle_background(GTK_IMHTML(imhtml), color);
-
-		g_free(color);
+		gtk_webview_toggle_background(webview, color);
 	}
 
-	if (buttons & GTK_IMHTML_BACKGROUND) {
-		char *color = gtk_imhtml_get_current_background(GTK_IMHTML(imhtml));
+	if (buttons & GTK_WEBVIEW_BACKGROUND) {
+		const char *color = gtk_webview_get_current_background(webview);
 		if (!color)
-			color = g_strdup("");
+			color = "";
 
 		purple_prefs_set_string(PIDGIN_PREFS_ROOT "/conversations/bgcolor", color);
-		g_free(color);
 	}
 }
 
 static void
-formatting_clear_cb(GtkIMHtml *imhtml, void *data)
+formatting_clear_cb(GtkWebView *webview, void *data)
 {
 	purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/conversations/send_bold", FALSE);
 	purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/conversations/send_italic", FALSE);
 	purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/conversations/send_underline", FALSE);
+	purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/conversations/send_strike", FALSE);
 
 	purple_prefs_set_int(PIDGIN_PREFS_ROOT "/conversations/font_size", 3);
 
@@ -1571,7 +1575,7 @@
 		desc = pango_font_description_from_string(font);
 	}
 
-	gtk_widget_modify_font(sample_imhtml, desc);
+	gtk_widget_modify_font(sample_webview, desc);
 	if (desc)
 		pango_font_description_free(desc);
 
@@ -1595,7 +1599,7 @@
 	GtkWidget *toolbar;
 	GtkWidget *iconpref1;
 	GtkWidget *iconpref2;
-	GtkWidget *imhtml;
+	GtkWidget *webview;
 	GtkWidget *frame;
 	GtkWidget *hbox;
 	GtkWidget *checkbox;
@@ -1685,33 +1689,39 @@
 
 	vbox = pidgin_make_frame(ret, _("Default Formatting"));
 
-	frame = pidgin_create_imhtml(TRUE, &imhtml, &toolbar, NULL);
+	frame = pidgin_create_webview(TRUE, &webview, &toolbar, NULL);
 	gtk_widget_show(frame);
-	gtk_widget_set_name(imhtml, "pidgin_prefs_font_imhtml");
+	gtk_widget_set_name(webview, "pidgin_prefs_font_webview");
 	gtk_widget_set_size_request(frame, 450, -1);
-	gtk_imhtml_set_whole_buffer_formatting_only(GTK_IMHTML(imhtml), TRUE);
-	gtk_imhtml_set_format_functions(GTK_IMHTML(imhtml),
-									GTK_IMHTML_BOLD |
-									GTK_IMHTML_ITALIC |
-									GTK_IMHTML_UNDERLINE |
-									GTK_IMHTML_GROW |
-									GTK_IMHTML_SHRINK |
-									GTK_IMHTML_FACE |
-									GTK_IMHTML_FORECOLOR |
-									GTK_IMHTML_BACKCOLOR |
-									GTK_IMHTML_BACKGROUND);
-
-	gtk_imhtml_append_text(GTK_IMHTML(imhtml), _("This is how your outgoing message text will appear when you use protocols that support formatting."), 0);
+	gtk_webview_set_whole_buffer_formatting_only(GTK_WEBVIEW(webview), TRUE);
+	gtk_webview_set_format_functions(GTK_WEBVIEW(webview),
+	                                 GTK_WEBVIEW_BOLD |
+	                                 GTK_WEBVIEW_ITALIC |
+	                                 GTK_WEBVIEW_UNDERLINE |
+	                                 GTK_WEBVIEW_STRIKE |
+	                                 GTK_WEBVIEW_GROW |
+	                                 GTK_WEBVIEW_SHRINK |
+	                                 GTK_WEBVIEW_FACE |
+	                                 GTK_WEBVIEW_FORECOLOR |
+	                                 GTK_WEBVIEW_BACKCOLOR |
+	                                 GTK_WEBVIEW_BACKGROUND);
+
+	gtk_webview_append_html(GTK_WEBVIEW(webview),
+	                        _("This is how your outgoing message text will "
+	                          "appear when you use protocols that support "
+	                          "formatting."));
 
 	gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
 
-	gtk_imhtml_setup_entry(GTK_IMHTML(imhtml), PURPLE_CONNECTION_HTML | PURPLE_CONNECTION_FORMATTING_WBFO);
-
-	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);
-	sample_imhtml = imhtml;
+	gtk_webview_setup_entry(GTK_WEBVIEW(webview),
+	                        PURPLE_CONNECTION_HTML |
+	                        PURPLE_CONNECTION_FORMATTING_WBFO);
+
+	g_signal_connect_after(G_OBJECT(webview), "format-toggled",
+	                       G_CALLBACK(formatting_toggle_cb), toolbar);
+	g_signal_connect_after(G_OBJECT(webview), "format-cleared",
+	                       G_CALLBACK(formatting_clear_cb), NULL);
+	sample_webview = webview;
 
 	gtk_widget_show(ret);
 
--- a/pidgin/gtkutils.c	Mon Jan 09 11:31:00 2012 +0000
+++ b/pidgin/gtkutils.c	Mon Jan 09 11:32:01 2012 +0000
@@ -68,6 +68,7 @@
 #include "gtkthemes.h"
 #include "gtkutils.h"
 #include "gtkwebview.h"
+#include "gtkwebviewtoolbar.h"
 #include "pidgin/minidialog.h"
 
 typedef struct {
@@ -127,6 +128,32 @@
 
 }
 
+void
+pidgin_setup_webview(GtkWidget *webview)
+{
+	g_return_if_fail(webview != NULL);
+	g_return_if_fail(GTK_IS_WEBVIEW(webview));
+
+#if 0
+/* TODO: WebKit this stuff... */
+	pidgin_themes_smiley_themeize(webview);
+#endif
+
+#ifdef _WIN32
+	if (!purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/use_theme_font")) {
+		WebKitWebSettings *settings = webkit_web_settings_new();
+		g_object_set(G_OBJECT(settings), "default-font-size",
+		             purple_prefs_get_int(PIDGIN_PREFS_ROOT "/conversations/font_size"),
+		             NULL);
+		g_object_set(G_OBJECT(settings), "default-font-family",
+		             purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/custom_font"),
+		             NULL);
+
+		webkit_web_view_set_settings(WEBKIT_WEB_VIEW(webview), settings);
+	}
+#endif
+}
+
 static
 void pidgin_window_init(GtkWindow *wnd, const char *title, guint border_width, const char *role, gboolean resizable)
 {
@@ -295,7 +322,7 @@
 	gtk_widget_show(vbox);
 
 	if (editable) {
-		toolbar = gtk_imhtmltoolbar_new();
+		toolbar = gtk_webviewtoolbar_new();
 		gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
 		gtk_widget_show(toolbar);
 
@@ -307,10 +334,7 @@
 	}
 
 	webview = gtk_webview_new();
-#if 0
-	/* TODO WEBKIT: Don't have editable webview yet. */
 	gtk_webview_set_editable(GTK_WEBVIEW(webview), editable);
-#endif /* if 0 */
 #ifdef USE_GTKSPELL
 	if (editable && purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/spellcheck"))
 		pidgin_setup_gtkspell(GTK_TEXT_VIEW(webview));
@@ -318,9 +342,10 @@
 	gtk_widget_show(webview);
 
 	if (editable) {
-		gtk_imhtmltoolbar_attach(GTK_IMHTMLTOOLBAR(toolbar), webview);
-		gtk_imhtmltoolbar_associate_smileys(GTK_IMHTMLTOOLBAR(toolbar), "default");
+		gtk_webviewtoolbar_attach(GTK_WEBVIEWTOOLBAR(toolbar), webview);
+		gtk_webviewtoolbar_associate_smileys(GTK_WEBVIEWTOOLBAR(toolbar), "default");
 	}
+	pidgin_setup_webview(webview);
 
 	sw = pidgin_make_scrollable(webview, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC, GTK_SHADOW_NONE, -1, -1);
 	gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0);
--- a/pidgin/gtkutils.h	Mon Jan 09 11:31:00 2012 +0000
+++ b/pidgin/gtkutils.h	Mon Jan 09 11:32:01 2012 +0000
@@ -107,6 +107,14 @@
 GtkWidget *pidgin_create_imhtml(gboolean editable, GtkWidget **imhtml_ret, GtkWidget **toolbar_ret, GtkWidget **sw_ret);
 
 /**
+ * Sets up a gtkwebview widget, loads it with smileys, and sets the
+ * default signal handlers.
+ *
+ * @param webview The gtkwebview widget to setup.
+ */
+void pidgin_setup_webview(GtkWidget *webview);
+
+/**
  * Create an GtkWebView widget and associated GtkIMHtmlToolbar widget.  This
  * function puts both widgets in a nice GtkFrame.  They're separated by an
  * attractive GtkSeparator.
--- a/pidgin/gtkwebview.c	Mon Jan 09 11:31:00 2012 +0000
+++ b/pidgin/gtkwebview.c	Mon Jan 09 11:32:01 2012 +0000
@@ -28,14 +28,25 @@
 #include "internal.h"
 #include "pidgin.h"
 
+#include <gdk/gdkkeysyms.h>
 #include "gtkwebview.h"
 
+#define MAX_FONT_SIZE 7
 #define MAX_SCROLL_TIME 0.4 /* seconds */
 #define SCROLL_DELAY 33 /* milliseconds */
 
 #define GTK_WEBVIEW_GET_PRIVATE(obj) \
 	(G_TYPE_INSTANCE_GET_PRIVATE((obj), GTK_TYPE_WEBVIEW, GtkWebViewPriv))
 
+enum {
+	BUTTONS_UPDATE,
+	TOGGLE_FORMAT,
+	CLEAR_FORMAT,
+	UPDATE_FORMAT,
+	LAST_SIGNAL
+};
+static guint signals[LAST_SIGNAL] = { 0 };
+
 /******************************************************************************
  * Structs
  *****************************************************************************/
@@ -52,6 +63,23 @@
 	GtkAdjustment *vadj;
 	guint scroll_src;
 	GTimer *scroll_time;
+
+	/* Format options */
+	GtkWebViewButtons format_functions;
+	struct {
+		gboolean wbfo:1;	/* Whole buffer formatting only. */
+		gboolean bold:1;
+		gboolean italic:1;
+		gboolean underline:1;
+		gboolean strike:1;
+		gchar *forecolor;
+		gchar *backcolor;
+		gchar *background;
+		gchar *fontface;
+		int fontsize;
+		/*GtkTextTag *link;*/
+	} edit;
+
 } GtkWebViewPriv;
 
 /******************************************************************************
@@ -282,6 +310,64 @@
 	return FALSE;
 }
 
+static void
+webview_clear_formatting(GtkWebView *webview)
+{
+	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+
+	if (!webkit_web_view_get_editable(WEBKIT_WEB_VIEW(webview)))
+		return;
+
+	priv->edit.bold = FALSE;
+	priv->edit.italic = FALSE;
+	priv->edit.underline = FALSE;
+	priv->edit.strike = FALSE;
+	priv->edit.fontsize = 0;
+
+	g_free(priv->edit.fontface);
+	priv->edit.fontface = NULL;
+
+	g_free(priv->edit.forecolor);
+	priv->edit.forecolor = NULL;
+
+	g_free(priv->edit.backcolor);
+	priv->edit.backcolor = NULL;
+
+	g_free(priv->edit.background);
+	priv->edit.background = NULL;
+}
+
+static void
+webview_toggle_format(GtkWebView *webview, GtkWebViewButtons buttons)
+{
+	/* since this function is the handler for the formatting keystrokes,
+	   we need to check here that the formatting attempted is permitted */
+	buttons &= gtk_webview_get_format_functions(webview);
+
+	switch (buttons) {
+	case GTK_WEBVIEW_BOLD:
+		gtk_webview_toggle_bold(webview);
+		break;
+	case GTK_WEBVIEW_ITALIC:
+		gtk_webview_toggle_italic(webview);
+		break;
+	case GTK_WEBVIEW_UNDERLINE:
+		gtk_webview_toggle_underline(webview);
+		break;
+	case GTK_WEBVIEW_STRIKE:
+		gtk_webview_toggle_strike(webview);
+		break;
+	case GTK_WEBVIEW_SHRINK:
+		gtk_webview_font_shrink(webview);
+		break;
+	case GTK_WEBVIEW_GROW:
+		gtk_webview_font_grow(webview);
+		break;
+	default:
+		break;
+	}
+}
+
 /******************************************************************************
  * GObject Stuff
  *****************************************************************************/
@@ -311,11 +397,67 @@
 static void
 gtk_webview_class_init(GtkWebViewClass *klass, gpointer userdata)
 {
+	GObjectClass *gobject_class;
+	GtkBindingSet *binding_set;
+
 	parent_class = g_type_class_ref(webkit_web_view_get_type());
+	gobject_class = G_OBJECT_CLASS(klass);
 
 	g_type_class_add_private(klass, sizeof(GtkWebViewPriv));
 
-	G_OBJECT_CLASS(klass)->finalize = gtk_webview_finalize;
+	signals[BUTTONS_UPDATE] = g_signal_new("allowed-formats-updated",
+	                                       G_TYPE_FROM_CLASS(gobject_class),
+	                                       G_SIGNAL_RUN_FIRST,
+	                                       G_STRUCT_OFFSET(GtkWebViewClass, buttons_update),
+	                                       NULL, 0, g_cclosure_marshal_VOID__INT,
+	                                       G_TYPE_NONE, 1, G_TYPE_INT);
+	signals[TOGGLE_FORMAT] = g_signal_new("format-toggled",
+	                                      G_TYPE_FROM_CLASS(gobject_class),
+	                                      G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+	                                      G_STRUCT_OFFSET(GtkWebViewClass, toggle_format),
+	                                      NULL, 0, g_cclosure_marshal_VOID__INT,
+	                                      G_TYPE_NONE, 1, G_TYPE_INT);
+	signals[CLEAR_FORMAT] = g_signal_new("format-cleared",
+	                                     G_TYPE_FROM_CLASS(gobject_class),
+	                                     G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
+	                                     G_STRUCT_OFFSET(GtkWebViewClass, clear_format),
+	                                     NULL, 0, g_cclosure_marshal_VOID__VOID,
+	                                     G_TYPE_NONE, 0);
+	signals[UPDATE_FORMAT] = g_signal_new("format-updated",
+	                                      G_TYPE_FROM_CLASS(gobject_class),
+	                                      G_SIGNAL_RUN_FIRST,
+	                                      G_STRUCT_OFFSET(GtkWebViewClass, update_format),
+	                                      NULL, 0, g_cclosure_marshal_VOID__VOID,
+	                                      G_TYPE_NONE, 0);
+
+	klass->toggle_format = webview_toggle_format;
+	klass->clear_format = webview_clear_formatting;
+
+	gobject_class->finalize = gtk_webview_finalize;
+
+	binding_set = gtk_binding_set_by_class(parent_class);
+	gtk_binding_entry_add_signal(binding_set, GDK_KEY_b, GDK_CONTROL_MASK,
+	                             "format-toggled", 1, G_TYPE_INT,
+	                             GTK_WEBVIEW_BOLD);
+	gtk_binding_entry_add_signal(binding_set, GDK_KEY_i, GDK_CONTROL_MASK,
+	                             "format-toggled", 1, G_TYPE_INT,
+	                             GTK_WEBVIEW_ITALIC);
+	gtk_binding_entry_add_signal(binding_set, GDK_KEY_u, GDK_CONTROL_MASK,
+	                             "format-toggled", 1, G_TYPE_INT,
+	                             GTK_WEBVIEW_UNDERLINE);
+	gtk_binding_entry_add_signal(binding_set, GDK_KEY_plus, GDK_CONTROL_MASK,
+	                             "format-toggled", 1, G_TYPE_INT,
+	                             GTK_WEBVIEW_GROW);
+	gtk_binding_entry_add_signal(binding_set, GDK_KEY_equal, GDK_CONTROL_MASK,
+	                             "format-toggled", 1, G_TYPE_INT,
+	                             GTK_WEBVIEW_GROW);
+	gtk_binding_entry_add_signal(binding_set, GDK_KEY_minus, GDK_CONTROL_MASK,
+	                             "format-toggled", 1, G_TYPE_INT,
+	                             GTK_WEBVIEW_SHRINK);
+
+	binding_set = gtk_binding_set_by_class(klass);
+	gtk_binding_entry_add_signal(binding_set, GDK_KEY_r, GDK_CONTROL_MASK,
+	                             "format-cleared", 0);
 }
 
 static void
@@ -503,3 +645,346 @@
 	gtk_adjustment_set_value(vadj, scroll_val);
 }
 
+void
+gtk_webview_set_editable(GtkWebView *webview, gboolean editable)
+{
+	webkit_web_view_set_editable(WEBKIT_WEB_VIEW(webview), editable);
+}
+
+void
+gtk_webview_setup_entry(GtkWebView *webview, PurpleConnectionFlags flags)
+{
+	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	GtkWebViewButtons buttons;
+
+	if (flags & PURPLE_CONNECTION_HTML) {
+		char color[8];
+		GdkColor fg_color, bg_color;
+
+		buttons = GTK_WEBVIEW_ALL;
+
+		if (flags & PURPLE_CONNECTION_NO_BGCOLOR)
+			buttons &= ~GTK_WEBVIEW_BACKCOLOR;
+		if (flags & PURPLE_CONNECTION_NO_FONTSIZE)
+		{
+			buttons &= ~GTK_WEBVIEW_GROW;
+			buttons &= ~GTK_WEBVIEW_SHRINK;
+		}
+		if (flags & PURPLE_CONNECTION_NO_URLDESC)
+			buttons &= ~GTK_WEBVIEW_LINKDESC;
+
+		gtk_webview_set_format_functions(webview, GTK_WEBVIEW_ALL);
+		if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_bold") != priv->edit.bold)
+			gtk_webview_toggle_bold(webview);
+
+		if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_italic") != priv->edit.italic)
+			gtk_webview_toggle_italic(webview);
+
+		if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_underline") != priv->edit.underline)
+			gtk_webview_toggle_underline(webview);
+
+		if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_strike") != priv->edit.strike)
+			gtk_webview_toggle_strike(webview);
+
+		gtk_webview_toggle_fontface(webview,
+			purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/font_face"));
+
+		if (!(flags & PURPLE_CONNECTION_NO_FONTSIZE))
+		{
+			int size = purple_prefs_get_int(PIDGIN_PREFS_ROOT "/conversations/font_size");
+
+			/* 3 is the default. */
+			if (size != 3)
+				gtk_webview_font_set_size(webview, size);
+		}
+
+		if (strcmp(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/fgcolor"), "") != 0)
+		{
+			gdk_color_parse(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/fgcolor"),
+							&fg_color);
+			g_snprintf(color, sizeof(color), "#%02x%02x%02x",
+									fg_color.red   / 256,
+									fg_color.green / 256,
+									fg_color.blue  / 256);
+		} else
+			strcpy(color, "");
+
+		gtk_webview_toggle_forecolor(webview, color);
+
+		if(!(flags & PURPLE_CONNECTION_NO_BGCOLOR) &&
+		   strcmp(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/bgcolor"), "") != 0)
+		{
+			gdk_color_parse(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/bgcolor"),
+							&bg_color);
+			g_snprintf(color, sizeof(color), "#%02x%02x%02x",
+									bg_color.red   / 256,
+									bg_color.green / 256,
+									bg_color.blue  / 256);
+		} else
+			strcpy(color, "");
+
+		gtk_webview_toggle_background(webview, color);
+
+		if (flags & PURPLE_CONNECTION_FORMATTING_WBFO)
+			gtk_webview_set_whole_buffer_formatting_only(webview, TRUE);
+		else
+			gtk_webview_set_whole_buffer_formatting_only(webview, FALSE);
+	} else {
+		buttons = GTK_WEBVIEW_SMILEY | GTK_WEBVIEW_IMAGE;
+		webview_clear_formatting(webview);
+	}
+
+	if (flags & PURPLE_CONNECTION_NO_IMAGES)
+		buttons &= ~GTK_WEBVIEW_IMAGE;
+
+	if (flags & PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY)
+		buttons |= GTK_WEBVIEW_CUSTOM_SMILEY;
+	else
+		buttons &= ~GTK_WEBVIEW_CUSTOM_SMILEY;
+
+	gtk_webview_set_format_functions(webview, buttons);
+}
+
+void
+gtk_webview_set_whole_buffer_formatting_only(GtkWebView *webview, gboolean wbfo)
+{
+	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	priv->edit.wbfo = wbfo;
+}
+
+void
+gtk_webview_set_format_functions(GtkWebView *webview, GtkWebViewButtons buttons)
+{
+	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	GObject *object = g_object_ref(G_OBJECT(webview));
+	priv->format_functions = buttons;
+	g_signal_emit(object, signals[BUTTONS_UPDATE], 0, buttons);
+	g_object_unref(object);
+}
+
+GtkWebViewButtons
+gtk_webview_get_format_functions(GtkWebView *webview)
+{
+	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	return priv->format_functions;
+}
+
+void
+gtk_webview_get_current_format(GtkWebView *webview, gboolean *bold,
+                               gboolean *italic, gboolean *underline,
+                               gboolean *strike)
+{
+	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	if (bold)
+		*bold = priv->edit.bold;
+	if (italic)
+		*italic = priv->edit.italic;
+	if (underline)
+		*underline = priv->edit.underline;
+	if (strike)
+		*strike = priv->edit.strike;
+}
+
+const char *
+gtk_webview_get_current_fontface(GtkWebView *webview)
+{
+	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	return priv->edit.fontface;
+}
+
+const char *
+gtk_webview_get_current_forecolor(GtkWebView *webview)
+{
+	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	return priv->edit.forecolor;
+}
+
+const char *
+gtk_webview_get_current_backcolor(GtkWebView *webview)
+{
+	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	return priv->edit.backcolor;
+}
+
+const char *
+gtk_webview_get_current_background(GtkWebView *webview)
+{
+	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	return priv->edit.background;
+}
+
+gint
+gtk_webview_get_current_fontsize(GtkWebView *webview)
+{
+	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	return priv->edit.fontsize;
+}
+
+gboolean
+gtk_webview_get_editable(GtkWebView *webview)
+{
+	return webkit_web_view_get_editable(WEBKIT_WEB_VIEW(webview));
+}
+
+void
+gtk_webview_clear_formatting(GtkWebView *webview)
+{
+	GObject *object;
+
+	object = g_object_ref(G_OBJECT(webview));
+	g_signal_emit(object, signals[CLEAR_FORMAT], 0);
+
+	gtk_widget_grab_focus(GTK_WIDGET(webview));
+
+	g_object_unref(object);
+}
+
+void
+gtk_webview_toggle_bold(GtkWebView *webview)
+{
+	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	WebKitDOMDocument *dom;
+
+	priv->edit.bold = !priv->edit.bold;
+
+	dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
+	webkit_dom_document_exec_command(dom, "bold", FALSE, "");
+}
+
+void
+gtk_webview_toggle_italic(GtkWebView *webview)
+{
+	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	WebKitDOMDocument *dom;
+
+	priv->edit.italic = !priv->edit.italic;
+
+	dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
+	webkit_dom_document_exec_command(dom, "italic", FALSE, "");
+}
+
+void
+gtk_webview_toggle_underline(GtkWebView *webview)
+{
+	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	WebKitDOMDocument *dom;
+
+	priv->edit.underline = !priv->edit.underline;
+
+	dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
+	webkit_dom_document_exec_command(dom, "underline", FALSE, "");
+}
+
+void
+gtk_webview_toggle_strike(GtkWebView *webview)
+{
+	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	WebKitDOMDocument *dom;
+
+	priv->edit.strike = !priv->edit.strike;
+
+	dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
+	webkit_dom_document_exec_command(dom, "strikethrough", FALSE, "");
+}
+
+gboolean
+gtk_webview_toggle_forecolor(GtkWebView *webview, const char *color)
+{
+	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	WebKitDOMDocument *dom;
+
+	g_free(priv->edit.forecolor);
+	priv->edit.forecolor = g_strdup(color);
+
+	dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
+	webkit_dom_document_exec_command(dom, "forecolor", FALSE, color);
+
+	return FALSE;
+}
+
+gboolean
+gtk_webview_toggle_backcolor(GtkWebView *webview, const char *color)
+{
+	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	WebKitDOMDocument *dom;
+
+	g_free(priv->edit.backcolor);
+	priv->edit.backcolor = g_strdup(color);
+
+	dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
+	webkit_dom_document_exec_command(dom, "backcolor", FALSE, color);
+
+	return FALSE;
+}
+
+gboolean
+gtk_webview_toggle_background(GtkWebView *webview, const char *color)
+{
+	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+
+	g_free(priv->edit.background);
+	priv->edit.background = g_strdup(color);
+
+	return FALSE;
+}
+
+gboolean
+gtk_webview_toggle_fontface(GtkWebView *webview, const char *face)
+{
+	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	WebKitDOMDocument *dom;
+
+	g_free(priv->edit.fontface);
+	priv->edit.fontface = g_strdup(face);
+
+	dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
+	webkit_dom_document_exec_command(dom, "fontname", FALSE, face);
+
+	return FALSE;
+}
+
+void
+gtk_webview_font_set_size(GtkWebView *webview, gint size)
+{
+	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	WebKitDOMDocument *dom;
+	char *tmp;
+
+	priv->edit.fontsize = size;
+
+	dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
+	tmp = g_strdup_printf("%d", size);
+	webkit_dom_document_exec_command(dom, "fontsize", FALSE, tmp);
+	g_free(tmp);
+}
+
+void
+gtk_webview_font_shrink(GtkWebView *webview)
+{
+	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	WebKitDOMDocument *dom;
+	char *tmp;
+
+	priv->edit.fontsize = MAX(priv->edit.fontsize - 1, 1);
+
+	dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
+	tmp = g_strdup_printf("%d", priv->edit.fontsize);
+	webkit_dom_document_exec_command(dom, "fontsize", FALSE, tmp);
+	g_free(tmp);
+}
+
+void
+gtk_webview_font_grow(GtkWebView *webview)
+{
+	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	WebKitDOMDocument *dom;
+	char *tmp;
+
+	priv->edit.fontsize = MIN(priv->edit.fontsize + 1, MAX_FONT_SIZE);
+
+	dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
+	tmp = g_strdup_printf("%d", priv->edit.fontsize);
+	webkit_dom_document_exec_command(dom, "fontsize", FALSE, tmp);
+	g_free(tmp);
+}
+
--- a/pidgin/gtkwebview.h	Mon Jan 09 11:31:00 2012 +0000
+++ b/pidgin/gtkwebview.h	Mon Jan 09 11:32:01 2012 +0000
@@ -39,6 +39,26 @@
 #define GTK_IS_WEBVIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GTK_TYPE_WEBVIEW))
 #define GTK_WEBVIEW_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_TYPE_WEBVIEW, GtkWebViewClass))
 
+typedef enum {
+	GTK_WEBVIEW_BOLD          = 1 << 0,
+	GTK_WEBVIEW_ITALIC        = 1 << 1,
+	GTK_WEBVIEW_UNDERLINE     = 1 << 2,
+	GTK_WEBVIEW_GROW          = 1 << 3,
+	GTK_WEBVIEW_SHRINK        = 1 << 4,
+	GTK_WEBVIEW_FACE          = 1 << 5,
+	GTK_WEBVIEW_FORECOLOR     = 1 << 6,
+	GTK_WEBVIEW_BACKCOLOR     = 1 << 7,
+	GTK_WEBVIEW_BACKGROUND    = 1 << 8,
+	GTK_WEBVIEW_LINK          = 1 << 9,
+	GTK_WEBVIEW_IMAGE         = 1 << 10,
+	GTK_WEBVIEW_SMILEY        = 1 << 11,
+	GTK_WEBVIEW_LINKDESC      = 1 << 12,
+	GTK_WEBVIEW_STRIKE        = 1 << 13,
+	/** Show custom smileys when appropriate. */
+	GTK_WEBVIEW_CUSTOM_SMILEY = 1 << 14,
+	GTK_WEBVIEW_ALL           = -1
+} GtkWebViewButtons;
+
 typedef struct _GtkWebView GtkWebView;
 typedef struct _GtkWebViewClass GtkWebViewClass;
 
@@ -50,6 +70,11 @@
 struct _GtkWebViewClass
 {
 	WebKitWebViewClass parent;
+
+	void (*buttons_update)(GtkWebView *, GtkWebViewButtons);
+	void (*toggle_format)(GtkWebView *, GtkWebViewButtons);
+	void (*clear_format)(GtkWebView *);
+	void (*update_format)(GtkWebView *);
 };
 
 G_BEGIN_DECLS
@@ -150,6 +175,226 @@
  */
 void gtk_webview_page_down(GtkWebView *webview);
 
+/**
+ * Enables or disables editing in a GtkWebView.
+ *
+ * @param webview  The GtkWebView
+ * @param editable @c TRUE to make the widget editable, or @c FALSE otherwise.
+ */
+void gtk_webview_set_editable(GtkWebView *webview, gboolean editable);
+
+/**
+ * Setup formatting for a GtkWebView depending on the flags specified.
+ *
+ * @param webview The GtkWebView.
+ * @param flags   The connection flags describing the allowed formatting.
+ */
+void gtk_webview_setup_entry(GtkWebView *webview, PurpleConnectionFlags flags);
+
+/**
+ * Enables or disables whole buffer formatting only (wbfo) in a GtkWebView.
+ * In this mode formatting options to the buffer take effect for the entire
+ * buffer instead of specific text.
+ *
+ * @param webview The GtkWebView
+ * @param wbfo    @c TRUE to enable the mode, or @c FALSE otherwise.
+ */
+void gtk_webview_set_whole_buffer_formatting_only(GtkWebView *webview,
+                                                  gboolean wbfo);
+
+/**
+ * Indicates which formatting functions to enable and disable in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ * @param buttons A GtkWebViewButtons bitmask indicating which functions to use
+ */
+void gtk_webview_set_format_functions(GtkWebView *webview,
+                                      GtkWebViewButtons buttons);
+
+/**
+ * Returns which formatting functions are enabled in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ *
+ * @return A GtkWebViewButtons bitmask indicating which functions to are enabled
+ */
+GtkWebViewButtons gtk_webview_get_format_functions(GtkWebView *webview);
+
+/**
+ * Sets each boolean to @c TRUE or @c FALSE to indicate if that formatting
+ * option is enabled at the current position in a GtkWebView.
+ *
+ * @param webview       The GtkWebView
+ * @param bold          The boolean to set for bold or @c NULL.
+ * @param italic        The boolean to set for italic or @c NULL.
+ * @param underline     The boolean to set for underline or @c NULL.
+ * @param strikethrough The boolean to set for strikethrough or @c NULL.
+ */
+void gtk_webview_get_current_format(GtkWebView *webview, gboolean *bold,
+                                    gboolean *italic, gboolean *underline,
+                                    gboolean *strike);
+
+/**
+ * Returns a string containing the selected font face at the current position
+ * in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ *
+ * @return A string containing the font face or @c NULL if none is set.
+ */
+const char *gtk_webview_get_current_fontface(GtkWebView *webview);
+
+/**
+ * Returns a string containing the selected foreground color at the current
+ * position in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ *
+ * @return A string containing the foreground color or @c NULL if none is set.
+ */
+const char *gtk_webview_get_current_forecolor(GtkWebView *webview);
+
+/**
+ * Returns a string containing the selected font background color at the current
+ * position in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ *
+ * @return A string containing the background color or @c NULL if none is set.
+ */
+const char *gtk_webview_get_current_backcolor(GtkWebView *webview);
+
+/**
+ * Returns a string containing the selected background color at the current
+ * position in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ *
+ * @return A string containg the background color or @c NULL if none is set.
+ */
+const char *gtk_webview_get_current_background(GtkWebView *webview);
+
+/**
+ * Returns a integer containing the selected HTML font size at the current
+ * position in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ *
+ * @return The HTML font size.
+ */
+gint gtk_webview_get_current_fontsize(GtkWebView *webview);
+
+/**
+ * Checks whether a GtkWebView is marked as editable.
+ *
+ * @param webview The GtkWebView
+ *
+ * @return @c TRUE if the IM/HTML is editable, or @c FALSE otherwise.
+ */
+gboolean gtk_webview_get_editable(GtkWebView *webview);
+
+/**
+ * Clear all the formatting on a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ */
+void gtk_webview_clear_formatting(GtkWebView *webview);
+
+/**
+ * Toggles bold at the cursor location or selection in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ */
+void gtk_webview_toggle_bold(GtkWebView *webview);
+
+/**
+ * Toggles italic at the cursor location or selection in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ */
+void gtk_webview_toggle_italic(GtkWebView *webview);
+
+/**
+ * Toggles underline at the cursor location or selection in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ */
+void gtk_webview_toggle_underline(GtkWebView *webview);
+
+/**
+ * Toggles strikethrough at the cursor location or selection in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ */
+void gtk_webview_toggle_strike(GtkWebView *webview);
+
+/**
+ * Toggles a foreground color at the current location or selection in a
+ * GtkWebView.
+ *
+ * @param webview The GtkWebView
+ * @param color  The HTML-style color, or @c NULL or "" to clear the color.
+ *
+ * @return @c TRUE if a color was set, or @c FALSE if it was cleared.
+ */
+gboolean gtk_webview_toggle_forecolor(GtkWebView *webview, const char *color);
+
+/**
+ * Toggles a background color at the current location or selection in a
+ * GtkWebView.
+ *
+ * @param webview The GtkWebView
+ * @param color  The HTML-style color, or @c NULL or "" to clear the color.
+ *
+ * @return @c TRUE if a color was set, or @c FALSE if it was cleared.
+ */
+gboolean gtk_webview_toggle_backcolor(GtkWebView *webview, const char *color);
+
+/**
+ * Toggles a background color at the current location or selection in a 
+ * GtkWebView.
+ *
+ * @param webview The GtkWebView
+ * @param color  The HTML-style color, or @c NULL or "" to clear the color.
+ *
+ * @return @c TRUE if a color was set, or @c FALSE if it was cleared.
+ */
+gboolean gtk_webview_toggle_background(GtkWebView *webview, const char *color);
+
+/**
+ * Toggles a font face at the current location or selection in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ * @param face   The font face name, or @c NULL or "" to clear the font.
+ *
+ * @return @c TRUE if a font name was set, or @c FALSE if it was cleared.
+ */
+gboolean gtk_webview_toggle_fontface(GtkWebView *webview, const char *face);
+
+/**
+ * Sets the font size at the current location or selection in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ * @param size   The HTML font size to use.
+ */
+void gtk_webview_font_set_size(GtkWebView *webview, gint size);
+
+/**
+ * Decreases the font size by 1 at the current location or selection in a
+ * GtkWebView.
+ *
+ * @param webview The GtkWebView
+ */
+void gtk_webview_font_shrink(GtkWebView *webview);
+
+/**
+ * Increases the font size by 1 at the current location or selection in a
+ * GtkWebView.
+ *
+ * @param webview The GtkWebView
+ */
+void gtk_webview_font_grow(GtkWebView *webview);
+
 G_END_DECLS
 
 #endif /* _PIDGIN_WEBVIEW_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pidgin/gtkwebviewtoolbar.c	Mon Jan 09 11:32:01 2012 +0000
@@ -0,0 +1,1752 @@
+/*
+ * @file gtkwebviewtoolbar.c GTK+ WebView Toolbar
+ * @ingroup pidgin
+ */
+
+/* pidgin
+ *
+ * Pidgin is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ *
+ */
+#include "internal.h"
+#include "pidgin.h"
+
+#include "imgstore.h"
+#include "notify.h"
+#include "prefs.h"
+#include "request.h"
+#include "pidginstock.h"
+#include "util.h"
+#include "debug.h"
+
+#include "gtkdialogs.h"
+#include "gtkwebviewtoolbar.h"
+#include "gtksmiley.h"
+#include "gtkthemes.h"
+#include "gtkutils.h"
+
+#include <gdk/gdkkeysyms.h>
+
+#if !GTK_CHECK_VERSION(2,18,0)
+#define gtk_widget_get_visible(x) GTK_WIDGET_VISIBLE((x))
+#define gtk_widget_is_sensitive(x) GTK_WIDGET_IS_SENSITIVE((x))
+#if !GTK_CHECK_VERSION(2,12,0)
+#define gtk_widget_set_tooltip_text(w, t) \
+	gtk_tooltips_set_tip(priv->tooltips, (w), (t), NULL)
+#endif
+#endif
+
+#define GTK_WEBVIEWTOOLBAR_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE((obj), GTK_TYPE_WEBVIEWTOOLBAR, GtkWebViewToolbarPriv))
+
+/******************************************************************************
+ * Structs
+ *****************************************************************************/
+
+typedef struct _GtkWebViewToolbarPriv {
+	PurpleConversation *active_conv;
+
+	GtkWidget *wide_view;
+	GtkWidget *lean_view;
+
+#if !GTK_CHECK_VERSION(2,12,0)
+	GtkTooltips *tooltips;
+#endif
+
+	GtkWidget *font_label;
+	GtkWidget *font_menu;
+
+	GtkWidget *bold;
+	GtkWidget *italic;
+	GtkWidget *underline;
+	GtkWidget *strike;
+
+	GtkWidget *larger_size;
+	GtkWidget *normal_size;
+	GtkWidget *smaller_size;
+
+	GtkWidget *font;
+	GtkWidget *fgcolor;
+	GtkWidget *bgcolor;
+
+	GtkWidget *clear;
+
+	GtkWidget *insert_menu;
+	GtkWidget *image;
+	GtkWidget *link;
+	GtkWidget *insert_hr;
+
+	GtkWidget *smiley;
+	GtkWidget *attention;
+	GtkWidget *call;
+
+	GtkWidget *font_dialog;
+	GtkWidget *fgcolor_dialog;
+	GtkWidget *bgcolor_dialog;
+	GtkWidget *link_dialog;
+	GtkWidget *smiley_dialog;
+	GtkWidget *image_dialog;
+
+	char *sml;
+} GtkWebViewToolbarPriv;
+
+/******************************************************************************
+ * Globals
+ *****************************************************************************/
+
+static GtkHBoxClass *parent_class = NULL;
+
+/******************************************************************************
+ * Prototypes
+ *****************************************************************************/
+
+static void
+toggle_button_set_active_block(GtkToggleButton *button, gboolean is_active,
+                               GtkWebViewToolbar *toolbar);
+
+static gboolean
+gtk_webviewtoolbar_popup_menu(GtkWidget *widget, GdkEventButton *event,
+                              GtkWebViewToolbar *toolbar);
+
+/******************************************************************************
+ * Helpers
+ *****************************************************************************/
+
+static void
+do_bold(GtkWidget *bold, GtkWebViewToolbar *toolbar)
+{
+	g_return_if_fail(toolbar != NULL);
+	gtk_webview_toggle_bold(GTK_WEBVIEW(toolbar->webview));
+	gtk_widget_grab_focus(toolbar->webview);
+}
+
+static void
+do_italic(GtkWidget *italic, GtkWebViewToolbar *toolbar)
+{
+	g_return_if_fail(toolbar != NULL);
+	gtk_webview_toggle_italic(GTK_WEBVIEW(toolbar->webview));
+	gtk_widget_grab_focus(toolbar->webview);
+}
+
+static void
+do_underline(GtkWidget *underline, GtkWebViewToolbar *toolbar)
+{
+	g_return_if_fail(toolbar != NULL);
+	gtk_webview_toggle_underline(GTK_WEBVIEW(toolbar->webview));
+	gtk_widget_grab_focus(toolbar->webview);
+}
+
+static void
+do_strikethrough(GtkWidget *strikethrough, GtkWebViewToolbar *toolbar)
+{
+	g_return_if_fail(toolbar != NULL);
+	gtk_webview_toggle_strike(GTK_WEBVIEW(toolbar->webview));
+	gtk_widget_grab_focus(toolbar->webview);
+}
+
+static void
+do_small(GtkWidget *smalltb, GtkWebViewToolbar *toolbar)
+{
+	g_return_if_fail(toolbar != NULL);
+	/* Only shrink the font on activation, not deactivation as well */
+	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(smalltb)))
+		gtk_webview_font_shrink(GTK_WEBVIEW(toolbar->webview));
+	gtk_widget_grab_focus(toolbar->webview);
+}
+
+static void
+do_big(GtkWidget *large, GtkWebViewToolbar *toolbar)
+{
+	g_return_if_fail(toolbar);
+	/* Only grow the font on activation, not deactivation as well */
+	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(large)))
+		gtk_webview_font_grow(GTK_WEBVIEW(toolbar->webview));
+	gtk_widget_grab_focus(toolbar->webview);
+}
+
+static gboolean
+destroy_toolbar_font(GtkWidget *widget, GdkEvent *event,
+					 GtkWebViewToolbar *toolbar)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+
+	if (widget != NULL)
+		gtk_webview_toggle_fontface(GTK_WEBVIEW(toolbar->webview), "");
+
+	if (priv->font_dialog != NULL)
+	{
+		gtk_widget_destroy(priv->font_dialog);
+		priv->font_dialog = NULL;
+	}
+
+	return FALSE;
+}
+
+static void
+realize_toolbar_font(GtkWidget *widget, GtkWebViewToolbar *toolbar)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	GtkFontSelection *sel;
+
+	sel = GTK_FONT_SELECTION(GTK_FONT_SELECTION_DIALOG(priv->font_dialog)->fontsel);
+	gtk_widget_hide_all(gtk_widget_get_parent(sel->size_entry));
+	gtk_widget_show_all(sel->family_list);
+	gtk_widget_show(gtk_widget_get_parent(sel->family_list));
+	gtk_widget_show(gtk_widget_get_parent(gtk_widget_get_parent(sel->family_list)));
+}
+
+static void
+cancel_toolbar_font(GtkWidget *widget, GtkWebViewToolbar *toolbar)
+{
+	destroy_toolbar_font(widget, NULL, toolbar);
+}
+
+static void
+apply_font(GtkWidget *widget, GtkWebViewToolbar *toolbar)
+{
+	/* this could be expanded to include font size, weight, etc.
+	   but for now only works with font face */
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	GtkFontSelectionDialog *fontsel = GTK_FONT_SELECTION_DIALOG(priv->font_dialog);
+	gchar *fontname = gtk_font_selection_dialog_get_font_name(fontsel);
+
+	if (fontname) {
+		const gchar *family_name = NULL;
+		PangoFontDescription *desc = NULL;
+
+		desc = pango_font_description_from_string(fontname);
+		family_name = pango_font_description_get_family(desc);
+
+		if (family_name) {
+			gtk_webview_toggle_fontface(GTK_WEBVIEW(toolbar->webview),
+			                           family_name);
+		}
+
+		pango_font_description_free(desc);
+		g_free(fontname);
+	}
+
+	cancel_toolbar_font(NULL, toolbar);
+}
+
+static void
+toggle_font(GtkWidget *font, GtkWebViewToolbar *toolbar)
+{
+	GtkWebViewToolbarPriv *priv;
+	g_return_if_fail(toolbar);
+	priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+
+	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(font))) {
+		const char *fontname = gtk_webview_get_current_fontface(GTK_WEBVIEW(toolbar->webview));
+
+		if (!priv->font_dialog) {
+			priv->font_dialog = gtk_font_selection_dialog_new(_("Select Font"));
+
+			if (fontname) {
+				char *fonttif = g_strdup_printf("%s 12", fontname);
+				gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(priv->font_dialog),
+														fonttif);
+				g_free(fonttif);
+			} else {
+				gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(priv->font_dialog),
+														DEFAULT_FONT_FACE);
+			}
+
+			g_signal_connect(G_OBJECT(priv->font_dialog), "delete_event",
+							 G_CALLBACK(destroy_toolbar_font), toolbar);
+			g_signal_connect(G_OBJECT(GTK_FONT_SELECTION_DIALOG(priv->font_dialog)->ok_button), "clicked",
+							 G_CALLBACK(apply_font), toolbar);
+			g_signal_connect(G_OBJECT(GTK_FONT_SELECTION_DIALOG(priv->font_dialog)->cancel_button), "clicked",
+							 G_CALLBACK(cancel_toolbar_font), toolbar);
+			g_signal_connect_after(G_OBJECT(priv->font_dialog), "realize",
+							 G_CALLBACK(realize_toolbar_font), toolbar);
+		}
+
+		gtk_window_present(GTK_WINDOW(priv->font_dialog));
+	} else {
+		cancel_toolbar_font(font, toolbar);
+	}
+
+	gtk_widget_grab_focus(toolbar->webview);
+}
+
+static gboolean
+destroy_toolbar_fgcolor(GtkWidget *widget, GdkEvent *event,
+						GtkWebViewToolbar *toolbar)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+
+	if (widget != NULL)
+		gtk_webview_toggle_forecolor(GTK_WEBVIEW(toolbar->webview), "");
+
+	if (priv->fgcolor_dialog != NULL)
+	{
+		gtk_widget_destroy(priv->fgcolor_dialog);
+		priv->fgcolor_dialog = NULL;
+	}
+
+	return FALSE;
+}
+
+static void
+cancel_toolbar_fgcolor(GtkWidget *widget, GtkWebViewToolbar *toolbar)
+{
+	destroy_toolbar_fgcolor(widget, NULL, toolbar);
+}
+
+static void
+do_fgcolor(GtkWidget *widget, GtkWebViewToolbar *toolbar)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	GtkColorSelectionDialog *dialog;
+	GtkColorSelection *colorsel;
+	GdkColor text_color;
+	char *open_tag;
+
+	dialog = GTK_COLOR_SELECTION_DIALOG(priv->fgcolor_dialog);
+	colorsel = GTK_COLOR_SELECTION(dialog->colorsel);
+
+	open_tag = g_malloc(30);
+	gtk_color_selection_get_current_color(colorsel, &text_color);
+	g_snprintf(open_tag, 23, "#%02X%02X%02X",
+			   text_color.red / 256,
+			   text_color.green / 256,
+			   text_color.blue / 256);
+	gtk_webview_toggle_forecolor(GTK_WEBVIEW(toolbar->webview), open_tag);
+	g_free(open_tag);
+
+	cancel_toolbar_fgcolor(NULL, toolbar);
+}
+
+static void
+toggle_fg_color(GtkWidget *color, GtkWebViewToolbar *toolbar)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(color))) {
+		GtkWidget *colorsel;
+		GdkColor fgcolor;
+		const char *color = gtk_webview_get_current_forecolor(GTK_WEBVIEW(toolbar->webview));
+
+		if (!priv->fgcolor_dialog) {
+			priv->fgcolor_dialog = gtk_color_selection_dialog_new(_("Select Text Color"));
+			colorsel = GTK_COLOR_SELECTION_DIALOG(priv->fgcolor_dialog)->colorsel;
+			if (color) {
+				gdk_color_parse(color, &fgcolor);
+				gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(colorsel), &fgcolor);
+			}
+
+			g_signal_connect(G_OBJECT(priv->fgcolor_dialog), "delete_event",
+							 G_CALLBACK(destroy_toolbar_fgcolor), toolbar);
+			g_signal_connect(G_OBJECT(GTK_COLOR_SELECTION_DIALOG(priv->fgcolor_dialog)->ok_button), "clicked",
+							 G_CALLBACK(do_fgcolor), toolbar);
+			g_signal_connect(G_OBJECT(GTK_COLOR_SELECTION_DIALOG(priv->fgcolor_dialog)->cancel_button), "clicked",
+							 G_CALLBACK(cancel_toolbar_fgcolor), toolbar);
+		}
+
+		gtk_window_present(GTK_WINDOW(priv->fgcolor_dialog));
+	} else {
+		cancel_toolbar_fgcolor(color, toolbar);
+	}
+
+	gtk_widget_grab_focus(toolbar->webview);
+}
+
+static gboolean
+destroy_toolbar_bgcolor(GtkWidget *widget, GdkEvent *event,
+						GtkWebViewToolbar *toolbar)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	if (widget != NULL) {
+#if 0
+		if (gtk_text_buffer_get_selection_bounds(GTK_WEBVIEW(toolbar->webview)->text_buffer, NULL, NULL))
+			gtk_webview_toggle_backcolor(GTK_WEBVIEW(toolbar->webview), "");
+		else
+#endif
+			gtk_webview_toggle_background(GTK_WEBVIEW(toolbar->webview), "");
+	}
+
+	if (priv->bgcolor_dialog != NULL)
+	{
+		gtk_widget_destroy(priv->bgcolor_dialog);
+		priv->bgcolor_dialog = NULL;
+	}
+
+	return FALSE;
+}
+
+static void
+cancel_toolbar_bgcolor(GtkWidget *widget, GtkWebViewToolbar *toolbar)
+{
+	destroy_toolbar_bgcolor(widget, NULL, toolbar);
+}
+
+static void
+do_bgcolor(GtkWidget *widget, GtkWebViewToolbar *toolbar)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	GtkColorSelectionDialog *dialog;
+	GtkColorSelection *colorsel;
+	GdkColor text_color;
+	char *open_tag;
+
+	dialog = GTK_COLOR_SELECTION_DIALOG(priv->bgcolor_dialog);
+	colorsel = GTK_COLOR_SELECTION(dialog->colorsel);
+
+	open_tag = g_malloc(30);
+	gtk_color_selection_get_current_color(colorsel, &text_color);
+	g_snprintf(open_tag, 23, "#%02X%02X%02X",
+			   text_color.red / 256,
+			   text_color.green / 256,
+			   text_color.blue / 256);
+#if 0
+	if (gtk_text_buffer_get_selection_bounds(GTK_WEBVIEW(toolbar->webview)->text_buffer, NULL, NULL))
+		gtk_webview_toggle_backcolor(GTK_WEBVIEW(toolbar->webview), open_tag);
+	else
+#endif
+		gtk_webview_toggle_background(GTK_WEBVIEW(toolbar->webview), open_tag);
+	g_free(open_tag);
+
+	cancel_toolbar_bgcolor(NULL, toolbar);
+}
+
+static void
+toggle_bg_color(GtkWidget *color, GtkWebViewToolbar *toolbar)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(color))) {
+		GtkWidget *colorsel;
+		GdkColor bgcolor;
+		const char *color = gtk_webview_get_current_backcolor(GTK_WEBVIEW(toolbar->webview));
+
+		if (!priv->bgcolor_dialog) {
+			priv->bgcolor_dialog = gtk_color_selection_dialog_new(_("Select Background Color"));
+			colorsel = GTK_COLOR_SELECTION_DIALOG(priv->bgcolor_dialog)->colorsel;
+			if (color) {
+				gdk_color_parse(color, &bgcolor);
+				gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(colorsel), &bgcolor);
+			}
+
+			g_signal_connect(G_OBJECT(priv->bgcolor_dialog), "delete_event",
+							 G_CALLBACK(destroy_toolbar_bgcolor), toolbar);
+			g_signal_connect(G_OBJECT(GTK_COLOR_SELECTION_DIALOG(priv->bgcolor_dialog)->ok_button), "clicked",
+							 G_CALLBACK(do_bgcolor), toolbar);
+			g_signal_connect(G_OBJECT(GTK_COLOR_SELECTION_DIALOG(priv->bgcolor_dialog)->cancel_button), "clicked",
+							 G_CALLBACK(cancel_toolbar_bgcolor), toolbar);
+		}
+
+		gtk_window_present(GTK_WINDOW(priv->bgcolor_dialog));
+	} else {
+		cancel_toolbar_bgcolor(color, toolbar);
+	}
+
+	gtk_widget_grab_focus(toolbar->webview);
+}
+
+static void
+clear_formatting_cb(GtkWidget *clear, GtkWebViewToolbar *toolbar)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	toggle_button_set_active_block(GTK_TOGGLE_BUTTON(priv->clear), FALSE, toolbar);
+	gtk_webview_clear_formatting(GTK_WEBVIEW(toolbar->webview));
+}
+
+static void
+cancel_link_cb(GtkWebViewToolbar *toolbar, PurpleRequestFields *fields)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->link), FALSE);
+
+	priv->link_dialog = NULL;
+}
+
+static void
+close_link_dialog(GtkWebViewToolbar *toolbar)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	if (priv->link_dialog != NULL)
+	{
+		purple_request_close(PURPLE_REQUEST_FIELDS, priv->link_dialog);
+		priv->link_dialog = NULL;
+	}
+}
+
+static void
+do_insert_link_cb(GtkWebViewToolbar *toolbar, PurpleRequestFields *fields)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	const char *url, *description;
+
+	url = purple_request_fields_get_string(fields, "url");
+	if (gtk_webview_get_format_functions(GTK_WEBVIEW(toolbar->webview)) & GTK_WEBVIEW_LINKDESC)
+		description = purple_request_fields_get_string(fields, "description");
+	else
+		description = NULL;
+
+	if (description == NULL)
+		description = url;
+
+#if 0
+	gtk_webview_insert_link(GTK_WEBVIEW(toolbar->webview),
+	                       gtk_text_buffer_get_insert(GTK_WEBVIEW(toolbar->webview)->text_buffer),
+	                       url, description);
+#endif
+
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->link), FALSE);
+
+	priv->link_dialog = NULL;
+}
+
+static void
+insert_link_cb(GtkWidget *w, GtkWebViewToolbar *toolbar)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->link))) {
+		PurpleRequestFields *fields;
+		PurpleRequestFieldGroup *group;
+		PurpleRequestField *field;
+#if 0
+		GtkTextIter start, end;
+#endif
+		char *msg;
+		char *desc = NULL;
+
+		fields = purple_request_fields_new();
+
+		group = purple_request_field_group_new(NULL);
+		purple_request_fields_add_group(fields, group);
+
+		field = purple_request_field_string_new("url", _("_URL"), NULL, FALSE);
+		purple_request_field_set_required(field, TRUE);
+		purple_request_field_group_add_field(group, field);
+
+		if (gtk_webview_get_format_functions(GTK_WEBVIEW(toolbar->webview)) & GTK_WEBVIEW_LINKDESC) {
+#if 0
+			if (gtk_text_buffer_get_selection_bounds(GTK_WEBVIEW(toolbar->webview)->text_buffer, &start, &end)) {
+				desc = gtk_webview_get_text(GTK_WEBVIEW(toolbar->webview), &start, &end);
+			}
+#endif
+			field = purple_request_field_string_new("description", _("_Description"),
+							      desc, FALSE);
+			purple_request_field_group_add_field(group, field);
+			msg = g_strdup(_("Please enter the URL and description of the "
+							 "link that you want to insert. The description "
+							 "is optional."));
+		} else {
+			msg = g_strdup(_("Please enter the URL of the "
+									"link that you want to insert."));
+		}
+
+		priv->link_dialog =
+			purple_request_fields(toolbar, _("Insert Link"),
+					    NULL,
+						msg,
+					    fields,
+					    _("_Insert"), G_CALLBACK(do_insert_link_cb),
+					    _("Cancel"), G_CALLBACK(cancel_link_cb),
+						NULL, NULL, NULL,
+					    toolbar);
+		g_free(msg);
+		g_free(desc);
+	} else {
+		close_link_dialog(toolbar);
+	}
+
+	gtk_widget_grab_focus(toolbar->webview);
+}
+
+static void
+insert_hr_cb(GtkWidget *widget, GtkWebViewToolbar *toolbar)
+{
+#if 0
+	GtkTextIter iter;
+	GtkTextMark *ins;
+	GtkIMHtmlScalable *hr;
+
+	ins = gtk_text_buffer_get_insert(gtk_text_view_get_buffer(GTK_TEXT_VIEW(toolbar->webview)));
+	gtk_text_buffer_get_iter_at_mark(gtk_text_view_get_buffer(GTK_TEXT_VIEW(toolbar->webview)), &iter, ins);
+	hr = gtk_webview_hr_new();
+	gtk_webview_hr_add_to(hr, GTK_WEBVIEW(toolbar->webview), &iter);
+#endif
+}
+
+static void
+do_insert_image_cb(GtkWidget *widget, int response, GtkWebViewToolbar *toolbar)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->image), FALSE);
+#if 0
+	gchar *filename, *name, *buf;
+	char *filedata;
+	size_t size;
+	GError *error = NULL;
+	int id;
+	GtkTextIter iter;
+	GtkTextMark *ins;
+
+	if (response != GTK_RESPONSE_ACCEPT)
+	{
+		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->image), FALSE);
+		return;
+	}
+
+	filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget));
+
+	if (filename == NULL) {
+		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->image), FALSE);
+		return;
+	}
+
+	/* The following triggers a callback that closes the widget */
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->image), FALSE);
+
+	if (!g_file_get_contents(filename, &filedata, &size, &error)) {
+		purple_notify_error(NULL, NULL, error->message, NULL);
+
+		g_error_free(error);
+		g_free(filename);
+
+		return;
+	}
+
+	name = strrchr(filename, G_DIR_SEPARATOR) + 1;
+
+	id = purple_imgstore_add_with_id(filedata, size, name);
+
+	if (id == 0) {
+		buf = g_strdup_printf(_("Failed to store image: %s\n"), filename);
+		purple_notify_error(NULL, NULL, buf, NULL);
+
+		g_free(buf);
+		g_free(filename);
+
+		return;
+	}
+
+	g_free(filename);
+
+	ins = gtk_text_buffer_get_insert(gtk_text_view_get_buffer(GTK_TEXT_VIEW(toolbar->webview)));
+	gtk_text_buffer_get_iter_at_mark(gtk_text_view_get_buffer(GTK_TEXT_VIEW(toolbar->webview)),
+									 &iter, ins);
+	gtk_webview_insert_image_at_iter(GTK_WEBVIEW(toolbar->webview), id, &iter);
+	purple_imgstore_unref_by_id(id);
+#endif
+}
+
+static void
+insert_image_cb(GtkWidget *save, GtkWebViewToolbar *toolbar)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	GtkWidget *window;
+
+	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->image))) {
+		window = gtk_file_chooser_dialog_new(_("Insert Image"),
+						NULL,
+						GTK_FILE_CHOOSER_ACTION_OPEN,
+						GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+						GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+						NULL);
+		gtk_dialog_set_default_response(GTK_DIALOG(window), GTK_RESPONSE_ACCEPT);
+		g_signal_connect(G_OBJECT(GTK_FILE_CHOOSER(window)),
+				"response", G_CALLBACK(do_insert_image_cb), toolbar);
+
+		gtk_widget_show(window);
+		priv->image_dialog = window;
+	} else {
+		gtk_widget_destroy(priv->image_dialog);
+		priv->image_dialog = NULL;
+	}
+
+	gtk_widget_grab_focus(toolbar->webview);
+}
+
+#if 0
+static void
+destroy_smiley_dialog(GtkWebViewToolbar *toolbar)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	if (priv->smiley_dialog != NULL)
+	{
+		gtk_widget_destroy(priv->smiley_dialog);
+		priv->smiley_dialog = NULL;
+	}
+}
+
+static gboolean
+close_smiley_dialog(GtkWebViewToolbar *toolbar)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->smiley), FALSE);
+	return FALSE;
+}
+
+
+static void
+insert_smiley_text(GtkWidget *widget, GtkWebViewToolbar *toolbar)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	char *smiley_text, *escaped_smiley;
+
+	smiley_text = g_object_get_data(G_OBJECT(widget), "smiley_text");
+	escaped_smiley = g_markup_escape_text(smiley_text, -1);
+
+	gtk_webview_insert_smiley(GTK_WEBVIEW(toolbar->webview),
+							 GTK_WEBVIEW(toolbar->webview)->protocol_name,
+							 escaped_smiley);
+
+	g_free(escaped_smiley);
+
+	close_smiley_dialog(toolbar);
+}
+
+/* smiley buttons list */
+struct smiley_button_list {
+	int width, height;
+	GtkWidget *button;
+	const GtkIMHtmlSmiley *smiley;
+	struct smiley_button_list *next;
+};
+
+static struct smiley_button_list *
+sort_smileys(struct smiley_button_list *ls, GtkWebViewToolbar *toolbar,
+			 int *width, const GtkIMHtmlSmiley *smiley)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	GtkWidget *image;
+	GtkWidget *button;
+	GtkRequisition size;
+	struct smiley_button_list *cur;
+	struct smiley_button_list *it, *it_last;
+	const gchar *filename = smiley->file;
+	gchar *face = smiley->smile;
+	PurpleSmiley *psmiley = NULL;
+	gboolean supports_custom = (gtk_webview_get_format_functions(GTK_WEBVIEW(toolbar->webview)) & GTK_WEBVIEW_CUSTOM_SMILEY);
+
+	cur = g_new0(struct smiley_button_list, 1);
+	it = ls;
+	it_last = ls; /* list iterators*/
+	image = gtk_image_new_from_file(filename);
+
+	gtk_widget_size_request(image, &size);
+
+	if (size.width > 24 &&
+			smiley->flags & GTK_WEBVIEW_SMILEY_CUSTOM) { /* This is a custom smiley, let's scale it */
+		GdkPixbuf *pixbuf = NULL;
+		GtkImageType type;
+
+		type = gtk_image_get_storage_type(GTK_IMAGE(image));
+
+		if (type == GTK_IMAGE_PIXBUF) {
+			pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image));
+		} else if (type == GTK_IMAGE_ANIMATION) {
+			GdkPixbufAnimation *animation;
+
+			animation = gtk_image_get_animation(GTK_IMAGE(image));
+
+			pixbuf = gdk_pixbuf_animation_get_static_image(animation);
+		}
+
+		if (pixbuf != NULL) {
+			GdkPixbuf *resized;
+			resized = gdk_pixbuf_scale_simple(pixbuf, 24, 24,
+					GDK_INTERP_HYPER);
+
+			gtk_image_set_from_pixbuf(GTK_IMAGE(image), resized); /* This unrefs pixbuf */
+			gtk_widget_size_request(image, &size);
+			g_object_unref(G_OBJECT(resized));
+		}
+	}
+
+	(*width) += size.width;
+
+	button = gtk_button_new();
+	gtk_container_add(GTK_CONTAINER(button), image);
+
+	g_object_set_data(G_OBJECT(button), "smiley_text", face);
+	g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(insert_smiley_text), toolbar);
+
+	gtk_widget_set_tooltip_text(button, face);
+
+	/* these look really weird with borders */
+	gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
+
+	psmiley = purple_smileys_find_by_shortcut(smiley->smile);
+	/* If this is a "non-custom" smiley, check to see if its shortcut is
+	  "shadowed" by any custom smiley. This can only happen if the connection
+	  is custom smiley-enabled */
+	if (supports_custom && psmiley && !(smiley->flags & GTK_WEBVIEW_SMILEY_CUSTOM)) {
+		gchar tip[128];
+		g_snprintf(tip, sizeof(tip),
+			_("This smiley is disabled because a custom smiley exists for this shortcut:\n %s"),
+			face);
+		gtk_widget_set_tooltip_text(button, tip);
+		gtk_widget_set_sensitive(button, FALSE);
+	} else if (psmiley) {
+		/* Remove the button if the smiley is destroyed */
+		g_signal_connect_object(G_OBJECT(psmiley), "destroy", G_CALLBACK(gtk_widget_destroy),
+				button, G_CONNECT_SWAPPED);
+	}
+
+	/* set current element to add */
+	cur->height = size.height;
+	cur->width = size.width;
+	cur->button = button;
+	cur->smiley = smiley;
+	cur->next = ls;
+
+	/* check where to insert by height */
+	if (ls == NULL)
+		return cur;
+	while (it != NULL) {
+		it_last = it;
+		it = it->next;
+	}
+	cur->next = it;
+	it_last->next = cur;
+	return ls;
+}
+
+static gboolean
+smiley_is_unique(GSList *list, GtkIMHtmlSmiley *smiley)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	while (list) {
+		GtkIMHtmlSmiley *cur = (GtkIMHtmlSmiley *) list->data;
+		if (!strcmp(cur->file, smiley->file))
+			return FALSE;
+		list = list->next;
+	}
+	return TRUE;
+}
+
+static gboolean
+smiley_dialog_input_cb(GtkWidget *dialog, GdkEvent *event,
+                       GtkWebViewToolbar *toolbar)
+{
+	if ((event->type == GDK_KEY_PRESS && event->key.keyval == GDK_Escape) ||
+	    (event->type == GDK_BUTTON_PRESS && event->button.button == 1))
+	{
+		close_smiley_dialog(toolbar);
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
+static void
+add_smiley_list(GtkWidget *container, struct smiley_button_list *list,
+                int max_width, gboolean custom)
+{
+	GtkWidget *line;
+	int line_width = 0;
+
+	if (!list)
+		return;
+
+	line = gtk_hbox_new(FALSE, 0);
+	gtk_box_pack_start(GTK_BOX(container), line, FALSE, FALSE, 0);
+	for (; list; list = list->next) {
+		if (custom != !!(list->smiley->flags & GTK_WEBVIEW_SMILEY_CUSTOM))
+			continue;
+		gtk_box_pack_start(GTK_BOX(line), list->button, FALSE, FALSE, 0);
+		gtk_widget_show(list->button);
+		line_width += list->width;
+		if (line_width >= max_width) {
+			if (list->next) {
+				line = gtk_hbox_new(FALSE, 0);
+				gtk_box_pack_start(GTK_BOX(container), line, FALSE, FALSE, 0);
+			}
+			line_width = 0;
+		}
+	}
+}
+#endif
+
+static void
+insert_smiley_cb(GtkWidget *smiley, GtkWebViewToolbar *toolbar)
+{
+#if 0
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	GtkWidget *dialog, *vbox;
+	GtkWidget *smiley_table = NULL;
+	GSList *smileys, *unique_smileys = NULL;
+	const GSList *custom_smileys = NULL;
+	gboolean supports_custom = FALSE;
+	GtkRequisition req;
+	GtkWidget *scrolled, *viewport;
+
+	if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(smiley))) {
+		destroy_smiley_dialog(toolbar);
+		gtk_widget_grab_focus(toolbar->webview);
+		return;
+	}
+
+	if (priv->sml)
+		smileys = pidgin_themes_get_proto_smileys(priv->sml);
+	else
+		smileys = pidgin_themes_get_proto_smileys(NULL);
+
+	/* Note: prepend smileys to list to avoid O(n^2) overhead when there is
+	  a large number of smileys... need to revers the list after for the dialog
+	  work... */
+	while(smileys) {
+		GtkIMHtmlSmiley *smiley = (GtkIMHtmlSmiley *) smileys->data;
+		if(!smiley->hidden) {
+			if(smiley_is_unique(unique_smileys, smiley)) {
+				unique_smileys = g_slist_prepend(unique_smileys, smiley);
+			}
+		}
+		smileys = smileys->next;
+	}
+	supports_custom = (gtk_webview_get_format_functions(GTK_WEBVIEW(toolbar->webview)) & GTK_WEBVIEW_CUSTOM_SMILEY);
+	if (toolbar->webview && supports_custom) {
+		const GSList *iterator = NULL;
+		custom_smileys = pidgin_smileys_get_all();
+
+		for (iterator = custom_smileys ; iterator ;
+			 iterator = g_slist_next(iterator)) {
+			GtkIMHtmlSmiley *smiley = (GtkIMHtmlSmiley *) iterator->data;
+			unique_smileys = g_slist_prepend(unique_smileys, smiley);
+		}
+	}
+
+	/* we need to reverse the list to get the smileys in the correct order */
+	unique_smileys = g_slist_reverse(unique_smileys);
+
+	dialog = pidgin_create_dialog(_("Smile!"), 0, "smiley_dialog", FALSE);
+	gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_MOUSE);
+	vbox = pidgin_dialog_get_vbox_with_properties(GTK_DIALOG(dialog), FALSE, 0);
+
+	if (unique_smileys != NULL) {
+		struct smiley_button_list *ls;
+		int max_line_width, num_lines, button_width = 0;
+
+		/* We use hboxes packed in a vbox */
+		ls = NULL;
+		max_line_width = 0;
+		num_lines = floor(sqrt(g_slist_length(unique_smileys)));
+		smiley_table = gtk_vbox_new(FALSE, 0);
+
+		if (supports_custom) {
+			GtkWidget *manage = gtk_button_new_with_mnemonic(_("_Manage custom smileys"));
+			GtkRequisition req;
+			g_signal_connect(G_OBJECT(manage), "clicked",
+					G_CALLBACK(pidgin_smiley_manager_show), NULL);
+			g_signal_connect_swapped(G_OBJECT(manage), "clicked",
+					G_CALLBACK(gtk_widget_destroy), dialog);
+			gtk_box_pack_end(GTK_BOX(vbox), manage, FALSE, TRUE, 0);
+			gtk_widget_size_request(manage, &req);
+			button_width = req.width;
+		}
+
+		/* create list of smileys sorted by height */
+		while (unique_smileys) {
+			GtkIMHtmlSmiley *smiley = (GtkIMHtmlSmiley *) unique_smileys->data;
+			if (!smiley->hidden) {
+				ls = sort_smileys(ls, toolbar, &max_line_width, smiley);
+			}
+			unique_smileys = g_slist_delete_link(unique_smileys, unique_smileys);
+		}
+		/* The window will be at least as wide as the 'Manage ..' button */
+		max_line_width = MAX(button_width, max_line_width / num_lines);
+
+		/* pack buttons of the list */
+		add_smiley_list(smiley_table, ls, max_line_width, FALSE);
+		if (supports_custom) {
+			gtk_box_pack_start(GTK_BOX(smiley_table), gtk_hseparator_new(), TRUE, FALSE, 0);
+			add_smiley_list(smiley_table, ls, max_line_width, TRUE);
+		}
+		while (ls) {
+			struct smiley_button_list *tmp = ls->next;
+			g_free(ls);
+			ls = tmp;
+		}
+
+		gtk_widget_add_events(dialog, GDK_KEY_PRESS_MASK);
+	}
+	else {
+		smiley_table = gtk_label_new(_("This theme has no available smileys."));
+		gtk_widget_add_events(dialog, GDK_KEY_PRESS_MASK | GDK_BUTTON_PRESS_MASK);
+		g_signal_connect(G_OBJECT(dialog), "button-press-event", (GCallback)smiley_dialog_input_cb, toolbar);
+	}
+
+
+	scrolled = pidgin_make_scrollable(smiley_table, GTK_POLICY_NEVER, GTK_POLICY_NEVER, GTK_SHADOW_NONE, -1, -1);
+	gtk_box_pack_start(GTK_BOX(vbox), scrolled, TRUE, TRUE, 0);
+	gtk_widget_show(smiley_table);
+
+	viewport = gtk_widget_get_parent(smiley_table);
+	gtk_viewport_set_shadow_type(GTK_VIEWPORT(viewport), GTK_SHADOW_NONE);
+
+	/* connect signals */
+	g_signal_connect_swapped(G_OBJECT(dialog), "destroy", G_CALLBACK(close_smiley_dialog), toolbar);
+	g_signal_connect(G_OBJECT(dialog), "key-press-event", G_CALLBACK(smiley_dialog_input_cb), toolbar);
+
+	gtk_window_set_transient_for(GTK_WINDOW(dialog),
+			GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(toolbar))));
+
+	/* show everything */
+	gtk_widget_show_all(dialog);
+
+	gtk_widget_size_request(viewport, &req);
+	gtk_widget_set_size_request(scrolled, MIN(300, req.width), MIN(290, req.height));
+
+	/* The window has to be made resizable, and the scrollbars in the scrolled window
+	 * enabled only after setting the desired size of the window. If we do either of
+	 * these tasks before now, GTK+ miscalculates the required size, and erronously
+	 * makes one or both scrollbars visible (sometimes).
+	 * I too think this hack is gross. But I couldn't find a better way -- sadrul */
+	gtk_window_set_resizable(GTK_WINDOW(dialog), TRUE);
+	g_object_set(G_OBJECT(scrolled),
+		"hscrollbar-policy", GTK_POLICY_AUTOMATIC,
+		"vscrollbar-policy", GTK_POLICY_AUTOMATIC,
+		NULL);
+
+#ifdef _WIN32
+	winpidgin_ensure_onscreen(dialog);
+#endif
+
+	priv->smiley_dialog = dialog;
+
+	gtk_widget_grab_focus(toolbar->webview);
+#endif
+}
+
+static void
+send_attention_cb(GtkWidget *attention, GtkWebViewToolbar *toolbar)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	PurpleConversation *conv = priv->active_conv;
+	const gchar *who = purple_conversation_get_name(conv);
+	PurpleConnection *gc = purple_conversation_get_connection(conv);
+
+	toggle_button_set_active_block(GTK_TOGGLE_BUTTON(attention), FALSE, toolbar);
+	purple_prpl_send_attention(gc, who, 0);
+	gtk_widget_grab_focus(toolbar->webview);
+}
+
+static void
+update_buttons_cb(GtkWebView *webview, GtkWebViewButtons buttons,
+                  GtkWebViewToolbar *toolbar)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	gtk_widget_set_sensitive(GTK_WIDGET(priv->bold), buttons & GTK_WEBVIEW_BOLD);
+	gtk_widget_set_sensitive(GTK_WIDGET(priv->italic), buttons & GTK_WEBVIEW_ITALIC);
+	gtk_widget_set_sensitive(GTK_WIDGET(priv->underline), buttons & GTK_WEBVIEW_UNDERLINE);
+	gtk_widget_set_sensitive(GTK_WIDGET(priv->strike), buttons & GTK_WEBVIEW_STRIKE);
+
+	gtk_widget_set_sensitive(GTK_WIDGET(priv->larger_size), buttons & GTK_WEBVIEW_GROW);
+	gtk_widget_set_sensitive(GTK_WIDGET(priv->smaller_size), buttons & GTK_WEBVIEW_SHRINK);
+
+	gtk_widget_set_sensitive(GTK_WIDGET(priv->font), buttons & GTK_WEBVIEW_FACE);
+	gtk_widget_set_sensitive(GTK_WIDGET(priv->fgcolor), buttons & GTK_WEBVIEW_FORECOLOR);
+	gtk_widget_set_sensitive(GTK_WIDGET(priv->bgcolor), buttons & GTK_WEBVIEW_BACKCOLOR);
+
+	gtk_widget_set_sensitive(GTK_WIDGET(priv->clear),
+							 (buttons & GTK_WEBVIEW_BOLD ||
+							  buttons & GTK_WEBVIEW_ITALIC ||
+							  buttons & GTK_WEBVIEW_UNDERLINE ||
+							  buttons & GTK_WEBVIEW_STRIKE ||
+							  buttons & GTK_WEBVIEW_GROW ||
+							  buttons & GTK_WEBVIEW_SHRINK ||
+							  buttons & GTK_WEBVIEW_FACE ||
+							  buttons & GTK_WEBVIEW_FORECOLOR ||
+							  buttons & GTK_WEBVIEW_BACKCOLOR));
+
+	gtk_widget_set_sensitive(GTK_WIDGET(priv->image), buttons & GTK_WEBVIEW_IMAGE);
+	gtk_widget_set_sensitive(GTK_WIDGET(priv->link), buttons & GTK_WEBVIEW_LINK);
+	gtk_widget_set_sensitive(GTK_WIDGET(priv->smiley), buttons & GTK_WEBVIEW_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,
+                               GtkWebViewToolbar *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
+update_buttons(GtkWebViewToolbar *toolbar)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	gboolean bold, italic, underline, strike;
+	const char *tmp;
+	const char *tmp2;
+	GtkLabel *label = GTK_LABEL(priv->font_label);
+
+	gtk_label_set_label(label, _("_Font"));
+
+	gtk_webview_get_current_format(GTK_WEBVIEW(toolbar->webview),
+	                               &bold, &italic, &underline, &strike);
+
+	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->bold)) != bold)
+		toggle_button_set_active_block(GTK_TOGGLE_BUTTON(priv->bold), bold,
+									   toolbar);
+	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->italic)) != italic)
+		toggle_button_set_active_block(GTK_TOGGLE_BUTTON(priv->italic), italic,
+									   toolbar);
+	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->underline)) != underline)
+		toggle_button_set_active_block(GTK_TOGGLE_BUTTON(priv->underline),
+									   underline, toolbar);
+	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->strike)) != strike)
+		toggle_button_set_active_block(GTK_TOGGLE_BUTTON(priv->strike),
+									   strike, toolbar);
+
+	/* These buttons aren't ever "active". */
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->smaller_size), FALSE);
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->larger_size), FALSE);
+
+	if (bold) {
+		gchar *markup = g_strdup_printf("<b>%s</b>",
+				gtk_label_get_label(label));
+		gtk_label_set_markup_with_mnemonic(label, markup);
+		g_free(markup);
+	}
+	if (italic) {
+		gchar *markup = g_strdup_printf("<i>%s</i>",
+				gtk_label_get_label(label));
+		gtk_label_set_markup_with_mnemonic(label, markup);
+		g_free(markup);
+	}
+	if (underline) {
+		gchar *markup = g_strdup_printf("<u>%s</u>",
+				gtk_label_get_label(label));
+		gtk_label_set_markup_with_mnemonic(label, markup);
+		g_free(markup);
+	}
+	if (strike) {
+		gchar *markup = g_strdup_printf("<s>%s</s>",
+				gtk_label_get_label(label));
+		gtk_label_set_markup_with_mnemonic(label, markup);
+		g_free(markup);
+	}
+
+	tmp = gtk_webview_get_current_fontface(GTK_WEBVIEW(toolbar->webview));
+	toggle_button_set_active_block(GTK_TOGGLE_BUTTON(priv->font),
+								   (tmp != NULL), toolbar);
+	if (tmp != NULL) {
+		gchar *markup = g_strdup_printf("<span font_desc=\"%s\">%s</span>",
+				tmp, gtk_label_get_label(label));
+		gtk_label_set_markup_with_mnemonic(label, markup);
+		g_free(markup);
+	}
+
+	tmp = gtk_webview_get_current_forecolor(GTK_WEBVIEW(toolbar->webview));
+	toggle_button_set_active_block(GTK_TOGGLE_BUTTON(priv->fgcolor),
+								   (tmp != NULL), toolbar);
+	if (tmp != NULL) {
+		gchar *markup = g_strdup_printf("<span foreground=\"%s\">%s</span>",
+				tmp, gtk_label_get_label(label));
+		gtk_label_set_markup_with_mnemonic(label, markup);
+		g_free(markup);
+	}
+
+	tmp = gtk_webview_get_current_backcolor(GTK_WEBVIEW(toolbar->webview));
+	tmp2 = gtk_webview_get_current_background(GTK_WEBVIEW(toolbar->webview));
+	toggle_button_set_active_block(GTK_TOGGLE_BUTTON(priv->bgcolor),
+								   (tmp != NULL || tmp2 != NULL), toolbar);
+	if (tmp != NULL) {
+		gchar *markup = g_strdup_printf("<span background=\"%s\">%s</span>",
+				tmp, gtk_label_get_label(label));
+		gtk_label_set_markup_with_mnemonic(label, markup);
+		g_free(markup);
+	}
+}
+
+static void
+toggle_button_cb(GtkWebView *webview, GtkWebViewButtons buttons,
+                 GtkWebViewToolbar *toolbar)
+{
+	update_buttons(toolbar);
+}
+
+static void
+update_format_cb(GtkWebView *webview, GtkWebViewToolbar *toolbar)
+{
+	update_buttons(toolbar);
+}
+
+#if 0
+static void
+mark_set_cb(GtkTextBuffer *buffer, GtkTextIter *location, GtkTextMark *mark,
+            GtkWebViewToolbar *toolbar)
+{
+	if(mark != gtk_text_buffer_get_insert(buffer))
+		return;
+
+	update_buttons(toolbar);
+}
+#endif
+
+/* This comes from gtkmenutoolbutton.c from gtk+
+ * Copyright (C) 2003 Ricardo Fernandez Pascual
+ * Copyright (C) 2004 Paolo Borelli
+ */
+static void
+menu_position_func(GtkMenu           *menu,
+                   int               *x,
+                   int               *y,
+                   gboolean          *push_in,
+                   gpointer          data)
+{
+	GtkWidget *widget = GTK_WIDGET(data);
+	GtkRequisition menu_req;
+	gint ythickness = widget->style->ythickness;
+	int savy;
+
+	gtk_widget_size_request(GTK_WIDGET (menu), &menu_req);
+	gdk_window_get_origin(widget->window, x, y);
+	*x += widget->allocation.x;
+	*y += widget->allocation.y + widget->allocation.height;
+	savy = *y;
+
+	pidgin_menu_position_func_helper(menu, x, y, push_in, data);
+
+	if (savy > *y + ythickness + 1)
+		*y -= widget->allocation.height;
+}
+
+static gboolean
+button_activate_on_click(GtkWidget *button, GdkEventButton *event,
+                         GtkWebViewToolbar *toolbar)
+{
+	if (event->button == 1 && GTK_IS_TOGGLE_BUTTON(button))
+		gtk_widget_activate(button);
+	else if (event->button == 3)
+		return gtk_webviewtoolbar_popup_menu(button, event, toolbar);
+	return FALSE;
+}
+
+static void
+pidgin_menu_clicked(GtkWidget *button, GtkMenu *menu)
+{
+	gtk_widget_show_all(GTK_WIDGET(menu));
+	gtk_menu_popup(menu, NULL, NULL, menu_position_func, button, 0, gtk_get_current_event_time());
+}
+
+static void
+pidgin_menu_deactivate(GtkWidget *menu, GtkToggleButton *button)
+{
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE);
+}
+
+static void
+switch_toolbar_view(GtkWidget *item, GtkWebViewToolbar *toolbar)
+{
+	purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/conversations/toolbar/wide",
+			!purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/toolbar/wide"));
+}
+
+static gboolean
+gtk_webviewtoolbar_popup_menu(GtkWidget *widget, GdkEventButton *event,
+                              GtkWebViewToolbar *toolbar)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	GtkWidget *menu;
+	GtkWidget *item;
+	gboolean wide;
+
+	if (event->button != 3)
+		return FALSE;
+
+	wide = gtk_widget_get_visible(priv->bold);
+
+	menu = gtk_menu_new();
+	item = gtk_menu_item_new_with_mnemonic(wide ? _("Group Items") : _("Ungroup Items"));
+	g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(switch_toolbar_view), toolbar);
+	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+	gtk_widget_show(item);
+
+	gtk_menu_popup(GTK_MENU(menu), NULL, NULL, pidgin_menu_position_func_helper,
+				widget, event->button, event->time);
+	return TRUE;
+}
+
+static void
+button_visibility_changed(GtkWidget *button, gpointer dontcare, GtkWidget *item)
+{
+	if (gtk_widget_get_visible(button))
+		gtk_widget_hide(item);
+	else
+		gtk_widget_show(item);
+}
+
+static void
+button_sensitiveness_changed(GtkWidget *button, gpointer dontcare, GtkWidget *item)
+{
+	gtk_widget_set_sensitive(item, gtk_widget_is_sensitive(button));
+}
+
+static void
+update_menuitem(GtkToggleButton *button, GtkCheckMenuItem *item)
+{
+	g_signal_handlers_block_by_func(G_OBJECT(item), G_CALLBACK(gtk_button_clicked), button);
+	gtk_check_menu_item_set_active(item, gtk_toggle_button_get_active(button));
+	g_signal_handlers_unblock_by_func(G_OBJECT(item), G_CALLBACK(gtk_button_clicked), button);
+}
+
+static void
+enable_markup(GtkWidget *widget, gpointer null)
+{
+	if (GTK_IS_LABEL(widget))
+		g_object_set(G_OBJECT(widget), "use-markup", TRUE, NULL);
+}
+
+static void
+webviewtoolbar_view_pref_changed(const char *name, PurplePrefType type,
+                                 gconstpointer value, gpointer toolbar)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	if (value) {
+		gtk_widget_hide_all(priv->lean_view);
+		gtk_widget_show_all(priv->wide_view);
+	} else {
+		gtk_widget_hide_all(priv->wide_view);
+		gtk_widget_show_all(priv->lean_view);
+	}
+}
+
+/******************************************************************************
+ * GObject stuff
+ *****************************************************************************/
+
+static void
+gtk_webviewtoolbar_finalize(GObject *object)
+{
+	GtkWebViewToolbar *toolbar = GTK_WEBVIEWTOOLBAR(object);
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+
+	if (priv->image_dialog != NULL)
+	{
+		gtk_widget_destroy(priv->image_dialog);
+		priv->image_dialog = NULL;
+	}
+
+	destroy_toolbar_font(NULL, NULL, toolbar);
+	if (priv->smiley_dialog != NULL) {
+#if 0
+		g_signal_handlers_disconnect_by_func(G_OBJECT(priv->smiley_dialog), close_smiley_dialog, toolbar);
+		destroy_smiley_dialog(toolbar);
+#endif
+	}
+	destroy_toolbar_bgcolor(NULL, NULL, toolbar);
+	destroy_toolbar_fgcolor(NULL, NULL, toolbar);
+	close_link_dialog(toolbar);
+	if (toolbar->webview) {
+		g_signal_handlers_disconnect_matched(toolbar->webview,
+				G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL,
+				toolbar);
+#if 0
+		g_signal_handlers_disconnect_matched(GTK_WEBVIEW(toolbar->webview)->text_buffer,
+				G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL,
+				toolbar);
+#endif
+	}
+
+	g_free(priv->sml);
+
+#if !GTK_CHECK_VERSION(2,12,0)
+	gtk_object_sink(GTK_OBJECT(priv->tooltips));
+#endif
+
+	if (priv->font_menu)
+		gtk_widget_destroy(priv->font_menu);
+	if (priv->insert_menu)
+		gtk_widget_destroy(priv->insert_menu);
+
+	purple_prefs_disconnect_by_handle(object);
+
+	G_OBJECT_CLASS(parent_class)->finalize (object);
+}
+
+static void
+gtk_webviewtoolbar_class_init(GtkWebViewToolbarClass *class)
+{
+	GObjectClass *gobject_class;
+	gobject_class = (GObjectClass *)class;
+	parent_class = g_type_class_ref(GTK_TYPE_HBOX);
+	gobject_class->finalize = gtk_webviewtoolbar_finalize;
+
+	g_type_class_add_private(class, sizeof(GtkWebViewToolbarPriv));
+
+	purple_prefs_add_none(PIDGIN_PREFS_ROOT "/conversations/toolbar");
+	purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/conversations/toolbar/wide", FALSE);
+}
+
+static void
+gtk_webviewtoolbar_create_old_buttons(GtkWebViewToolbar *toolbar)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	GtkWidget *hbox;
+	GtkWidget *button;
+	struct {
+		char *stock;
+		gpointer callback;
+		GtkWidget **button;
+		const char *tooltip;
+	} buttons[] = {
+		{GTK_STOCK_BOLD, G_CALLBACK(do_bold), &priv->bold, _("Bold")},
+		{GTK_STOCK_ITALIC, do_italic, &priv->italic, _("Italic")},
+		{GTK_STOCK_UNDERLINE, do_underline, &priv->underline, _("Underline")},
+		{GTK_STOCK_STRIKETHROUGH, do_strikethrough, &priv->strike, _("Strikethrough")},
+		{"", NULL, NULL, NULL},
+		{PIDGIN_STOCK_TOOLBAR_TEXT_LARGER, do_big, &priv->larger_size, _("Increase Font Size")},
+		{PIDGIN_STOCK_TOOLBAR_TEXT_SMALLER, do_small, &priv->smaller_size, _("Decrease Font Size")},
+		{"", NULL, NULL, NULL},
+		{PIDGIN_STOCK_TOOLBAR_FONT_FACE, toggle_font, &priv->font, _("Font Face")},
+		{PIDGIN_STOCK_TOOLBAR_FGCOLOR, toggle_fg_color, &priv->fgcolor, _("Foreground Color")},
+		{PIDGIN_STOCK_TOOLBAR_BGCOLOR, toggle_bg_color, &priv->bgcolor, _("Background Color")},
+		{"", NULL, NULL, NULL},
+		{PIDGIN_STOCK_CLEAR, clear_formatting_cb, &priv->clear, _("Reset Formatting")},
+		{"", NULL, NULL, NULL},
+		{PIDGIN_STOCK_TOOLBAR_INSERT_IMAGE, insert_image_cb, &priv->image, _("Insert IM Image")},
+		{PIDGIN_STOCK_TOOLBAR_INSERT_LINK, insert_link_cb, &priv->link, _("Insert Link")},
+		{"", NULL, NULL, NULL},
+		{PIDGIN_STOCK_TOOLBAR_SMILEY, insert_smiley_cb, &priv->smiley, _("Insert Smiley")},
+		{PIDGIN_STOCK_TOOLBAR_SEND_ATTENTION, send_attention_cb, &priv->attention, _("Send Attention")},
+		{NULL, NULL, NULL, NULL}
+	};
+	int iter;
+
+	hbox = gtk_hbox_new(FALSE, 0);
+
+	for (iter = 0; buttons[iter].stock; iter++) {
+		if (buttons[iter].stock[0]) {
+			button = pidgin_pixbuf_toolbar_button_from_stock(buttons[iter].stock);
+			g_signal_connect(G_OBJECT(button), "button-press-event", G_CALLBACK(gtk_webviewtoolbar_popup_menu), toolbar);
+			g_signal_connect(G_OBJECT(button), "clicked",
+					 G_CALLBACK(buttons[iter].callback), toolbar);
+			*(buttons[iter].button) = button;
+			gtk_widget_set_tooltip_text(button, buttons[iter].tooltip);
+		} else
+			button = gtk_vseparator_new();
+		gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
+	}
+
+	gtk_box_pack_start(GTK_BOX(toolbar), hbox, FALSE, FALSE, 0);
+	priv->wide_view = hbox;
+}
+
+static void
+gtk_webviewtoolbar_init(GtkWebViewToolbar *toolbar)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	GtkWidget *hbox = GTK_WIDGET(toolbar), *event = gtk_event_box_new();
+	GtkWidget *bbox, *box = gtk_hbox_new(FALSE, 0);
+	GtkWidget *image;
+	GtkWidget *label;
+	GtkWidget *insert_button;
+	GtkWidget *font_button;
+	GtkWidget *smiley_button;
+	GtkWidget *attention_button;
+	GtkWidget *font_menu;
+	GtkWidget *insert_menu;
+	GtkWidget *menuitem;
+	GtkWidget *sep;
+	int i;
+	struct {
+		const char *label;
+		GtkWidget **button;
+		gboolean check;
+	} buttons[] = {
+		{_("<b>_Bold</b>"), &priv->bold, TRUE},
+		{_("<i>_Italic</i>"), &priv->italic, TRUE},
+		{_("<u>_Underline</u>"), &priv->underline, TRUE},
+		{_("<span strikethrough='true'>Strikethrough</span>"), &priv->strike, TRUE},
+		{_("<span size='larger'>_Larger</span>"), &priv->larger_size, TRUE},
+#if 0
+		{_("_Normal"), &priv->normal_size, TRUE},
+#endif
+		{_("<span size='smaller'>_Smaller</span>"), &priv->smaller_size, TRUE},
+		/* If we want to show the formatting for the following items, we would
+		 * need to update them when formatting changes. The above items don't need
+		 * no updating nor nothin' */
+		{_("_Font face"), &priv->font, TRUE},
+		{_("Foreground _color"), &priv->fgcolor, TRUE},
+		{_("Bac_kground color"), &priv->bgcolor, TRUE},
+		{_("_Reset formatting"), &priv->clear, FALSE},
+		{NULL, NULL, FALSE}
+	};
+
+	toolbar->webview = NULL;
+	priv->font_dialog = NULL;
+	priv->fgcolor_dialog = NULL;
+	priv->bgcolor_dialog = NULL;
+	priv->link_dialog = NULL;
+	priv->smiley_dialog = NULL;
+	priv->image_dialog = NULL;
+
+#if !GTK_CHECK_VERSION(2,12,0)
+	priv->tooltips = gtk_tooltips_new();
+#endif
+
+	gtk_box_set_spacing(GTK_BOX(toolbar), 3);
+
+	gtk_webviewtoolbar_create_old_buttons(toolbar);
+
+	/* Fonts */
+	font_button = gtk_toggle_button_new();
+	gtk_button_set_relief(GTK_BUTTON(font_button), GTK_RELIEF_NONE);
+	bbox = gtk_hbox_new(FALSE, 3);
+	gtk_container_add(GTK_CONTAINER(font_button), bbox);
+	image = gtk_image_new_from_stock(GTK_STOCK_BOLD, gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL));
+	gtk_box_pack_start(GTK_BOX(bbox), image, FALSE, FALSE, 0);
+	priv->font_label = label = gtk_label_new_with_mnemonic(_("_Font"));
+	gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
+	gtk_box_pack_start(GTK_BOX(bbox), label, FALSE, FALSE, 0);
+	gtk_box_pack_start(GTK_BOX(box), font_button, FALSE, FALSE, 0);
+	gtk_widget_show_all(font_button);
+
+	priv->font_menu = font_menu = gtk_menu_new();
+
+	for (i = 0; buttons[i].label; i++) {
+		GtkWidget *old = *buttons[i].button;
+		if (buttons[i].check) {
+			menuitem = gtk_check_menu_item_new_with_mnemonic(buttons[i].label);
+			g_signal_connect_after(G_OBJECT(old), "toggled",
+						G_CALLBACK(update_menuitem), menuitem);
+		} else {
+			menuitem = gtk_menu_item_new_with_mnemonic(buttons[i].label);
+		}
+		g_signal_connect_swapped(G_OBJECT(menuitem), "activate",
+				G_CALLBACK(gtk_button_clicked), old);
+		gtk_menu_shell_append(GTK_MENU_SHELL(font_menu), menuitem);
+		g_signal_connect(G_OBJECT(old), "notify::sensitive",
+				G_CALLBACK(button_sensitiveness_changed), menuitem);
+		g_signal_connect(G_OBJECT(old), "notify::visible",
+				G_CALLBACK(button_visibility_changed), menuitem);
+		gtk_container_foreach(GTK_CONTAINER(menuitem), (GtkCallback)enable_markup, NULL);
+	}
+
+	g_signal_connect(G_OBJECT(font_button), "button-press-event", G_CALLBACK(button_activate_on_click), toolbar);
+	g_signal_connect(G_OBJECT(font_button), "activate", G_CALLBACK(pidgin_menu_clicked), font_menu);
+	g_signal_connect(G_OBJECT(font_menu), "deactivate", G_CALLBACK(pidgin_menu_deactivate), font_button);
+
+	/* Sep */
+	sep = gtk_vseparator_new();
+	gtk_box_pack_start(GTK_BOX(box), sep, FALSE, FALSE, 0);
+	gtk_widget_show_all(sep);
+
+	/* Insert */
+	insert_button = gtk_toggle_button_new();
+	gtk_button_set_relief(GTK_BUTTON(insert_button), GTK_RELIEF_NONE);
+	bbox = gtk_hbox_new(FALSE, 3);
+	gtk_container_add(GTK_CONTAINER(insert_button), bbox);
+	image = gtk_image_new_from_stock(PIDGIN_STOCK_TOOLBAR_INSERT, gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL));
+	gtk_box_pack_start(GTK_BOX(bbox), image, FALSE, FALSE, 0);
+	label = gtk_label_new_with_mnemonic(_("_Insert"));
+	gtk_box_pack_start(GTK_BOX(bbox), label, FALSE, FALSE, 0);
+	gtk_box_pack_start(GTK_BOX(box), insert_button, FALSE, FALSE, 0);
+	gtk_widget_show_all(insert_button);
+
+	priv->insert_menu = insert_menu = gtk_menu_new();
+
+	menuitem = gtk_menu_item_new_with_mnemonic(_("_Image"));
+	g_signal_connect_swapped(G_OBJECT(menuitem), "activate", G_CALLBACK(gtk_button_clicked), priv->image);
+	gtk_menu_shell_append(GTK_MENU_SHELL(insert_menu), menuitem);
+	g_signal_connect(G_OBJECT(priv->image), "notify::sensitive",
+			G_CALLBACK(button_sensitiveness_changed), menuitem);
+	g_signal_connect(G_OBJECT(priv->image), "notify::visible",
+			G_CALLBACK(button_visibility_changed), menuitem);
+
+	menuitem = gtk_menu_item_new_with_mnemonic(_("_Link"));
+	g_signal_connect_swapped(G_OBJECT(menuitem), "activate", G_CALLBACK(gtk_button_clicked), priv->link);
+	gtk_menu_shell_append(GTK_MENU_SHELL(insert_menu), menuitem);
+	g_signal_connect(G_OBJECT(priv->link), "notify::sensitive",
+			G_CALLBACK(button_sensitiveness_changed), menuitem);
+	g_signal_connect(G_OBJECT(priv->link), "notify::visible",
+			G_CALLBACK(button_visibility_changed), menuitem);
+
+	menuitem = gtk_menu_item_new_with_mnemonic(_("_Horizontal rule"));
+	g_signal_connect(G_OBJECT(menuitem), "activate"	, G_CALLBACK(insert_hr_cb), toolbar);
+	gtk_menu_shell_append(GTK_MENU_SHELL(insert_menu), menuitem);
+	priv->insert_hr = menuitem;
+
+	g_signal_connect(G_OBJECT(insert_button), "button-press-event", G_CALLBACK(button_activate_on_click), toolbar);
+	g_signal_connect(G_OBJECT(insert_button), "activate", G_CALLBACK(pidgin_menu_clicked), insert_menu);
+	g_signal_connect(G_OBJECT(insert_menu), "deactivate", G_CALLBACK(pidgin_menu_deactivate), insert_button);
+	priv->sml = NULL;
+
+	/* Sep */
+	sep = gtk_vseparator_new();
+	gtk_box_pack_start(GTK_BOX(box), sep, FALSE, FALSE, 0);
+	gtk_widget_show_all(sep);
+
+	/* Smiley */
+	smiley_button = gtk_button_new();
+	gtk_button_set_relief(GTK_BUTTON(smiley_button), GTK_RELIEF_NONE);
+	bbox = gtk_hbox_new(FALSE, 3);
+	gtk_container_add(GTK_CONTAINER(smiley_button), bbox);
+	image = gtk_image_new_from_stock(PIDGIN_STOCK_TOOLBAR_SMILEY, gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL));
+	gtk_box_pack_start(GTK_BOX(bbox), image, FALSE, FALSE, 0);
+	label = gtk_label_new_with_mnemonic(_("_Smile!"));
+	gtk_box_pack_start(GTK_BOX(bbox), label, FALSE, FALSE, 0);
+	gtk_box_pack_start(GTK_BOX(box), smiley_button, FALSE, FALSE, 0);
+	g_signal_connect(G_OBJECT(smiley_button), "button-press-event", G_CALLBACK(gtk_webviewtoolbar_popup_menu), toolbar);
+	g_signal_connect_swapped(G_OBJECT(smiley_button), "clicked", G_CALLBACK(gtk_button_clicked), priv->smiley);
+	gtk_widget_show_all(smiley_button);
+
+	/* Sep */
+	sep = gtk_vseparator_new();
+	gtk_box_pack_start(GTK_BOX(box), sep, FALSE, FALSE, 0);
+	gtk_widget_show_all(sep);
+
+	/* Attention */
+	attention_button = gtk_button_new();
+	gtk_button_set_relief(GTK_BUTTON(attention_button), GTK_RELIEF_NONE);
+	bbox = gtk_hbox_new(FALSE, 3);
+	gtk_container_add(GTK_CONTAINER(attention_button), bbox);
+	image = gtk_image_new_from_stock(PIDGIN_STOCK_TOOLBAR_SEND_ATTENTION,
+		gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL));
+	gtk_box_pack_start(GTK_BOX(bbox), image, FALSE, FALSE, 0);
+	label = gtk_label_new_with_mnemonic(_("_Attention!"));
+	gtk_box_pack_start(GTK_BOX(bbox), label, FALSE, FALSE, 0);
+	gtk_box_pack_start(GTK_BOX(box), attention_button, FALSE, FALSE, 0);
+	g_signal_connect_swapped(G_OBJECT(attention_button), "clicked",
+		G_CALLBACK(gtk_button_clicked), priv->attention);
+	gtk_widget_show_all(attention_button);
+
+	g_signal_connect(G_OBJECT(priv->attention), "notify::sensitive",
+			G_CALLBACK(button_sensitiveness_changed), attention_button);
+	g_signal_connect(G_OBJECT(priv->attention), "notify::visible",
+			G_CALLBACK(button_visibility_changed), attention_button);
+
+	/* set attention button to be greyed out until we get a conversation */
+	gtk_widget_set_sensitive(priv->attention, FALSE);
+
+	gtk_box_pack_start(GTK_BOX(hbox), box, FALSE, FALSE, 0);
+	priv->lean_view = box;
+	gtk_widget_show(box);
+
+	purple_prefs_connect_callback(toolbar, PIDGIN_PREFS_ROOT "/conversations/toolbar/wide",
+			webviewtoolbar_view_pref_changed, toolbar);
+	g_signal_connect_data(G_OBJECT(toolbar), "realize",
+			G_CALLBACK(purple_prefs_trigger_callback), PIDGIN_PREFS_ROOT "/conversations/toolbar/wide",
+			NULL, G_CONNECT_AFTER | G_CONNECT_SWAPPED);
+
+	gtk_event_box_set_visible_window(GTK_EVENT_BOX(event), FALSE);
+
+	gtk_widget_add_events(event, GDK_BUTTON_PRESS_MASK);
+	gtk_box_pack_start(GTK_BOX(hbox), event, TRUE, TRUE, 0);
+	g_signal_connect(G_OBJECT(event), "button-press-event", G_CALLBACK(gtk_webviewtoolbar_popup_menu), toolbar);
+	gtk_widget_show(event);
+}
+
+/******************************************************************************
+ * Public API
+ *****************************************************************************/
+
+GtkWidget *
+gtk_webviewtoolbar_new(void)
+{
+	return GTK_WIDGET(g_object_new(gtk_webviewtoolbar_get_type(), NULL));
+}
+
+GType
+gtk_webviewtoolbar_get_type(void)
+{
+	static GType webviewtoolbar_type = 0;
+
+	if (!webviewtoolbar_type) {
+		static const GTypeInfo webviewtoolbar_info = {
+			sizeof(GtkWebViewToolbarClass),
+			NULL,
+			NULL,
+			(GClassInitFunc)gtk_webviewtoolbar_class_init,
+			NULL,
+			NULL,
+			sizeof(GtkWebViewToolbar),
+			0,
+			(GInstanceInitFunc)gtk_webviewtoolbar_init,
+			NULL
+		};
+
+		webviewtoolbar_type = g_type_register_static(GTK_TYPE_HBOX,
+				"GtkWebViewToolbar", &webviewtoolbar_info, 0);
+	}
+
+	return webviewtoolbar_type;
+}
+
+void
+gtk_webviewtoolbar_attach(GtkWebViewToolbar *toolbar, GtkWidget *webview)
+{
+	GtkWebViewButtons buttons;
+
+	g_return_if_fail(toolbar != NULL);
+	g_return_if_fail(GTK_IS_WEBVIEWTOOLBAR(toolbar));
+	g_return_if_fail(webview != NULL);
+	g_return_if_fail(GTK_IS_WEBVIEW(webview));
+
+	toolbar->webview = webview;
+	g_signal_connect(G_OBJECT(webview), "allowed-formats-updated",
+	                 G_CALLBACK(update_buttons_cb), toolbar);
+	g_signal_connect_after(G_OBJECT(webview), "format-toggled",
+	                       G_CALLBACK(toggle_button_cb), toolbar);
+	g_signal_connect_after(G_OBJECT(webview), "format-cleared",
+	                       G_CALLBACK(update_format_cb), toolbar);
+	g_signal_connect(G_OBJECT(webview), "format-updated",
+	                 G_CALLBACK(update_format_cb), toolbar);
+#if 0
+	g_signal_connect_after(G_OBJECT(GTK_WEBVIEW(webview)->text_buffer), "mark-set", G_CALLBACK(mark_set_cb), toolbar);
+#endif
+
+	buttons = gtk_webview_get_format_functions(GTK_WEBVIEW(webview));
+	update_buttons_cb(GTK_WEBVIEW(webview), buttons, toolbar);
+	update_buttons(toolbar);
+}
+
+void
+gtk_webviewtoolbar_associate_smileys(GtkWebViewToolbar *toolbar,
+                                     const char *proto_id)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	g_free(priv->sml);
+	priv->sml = g_strdup(proto_id);
+}
+
+void
+gtk_webviewtoolbar_switch_active_conversation(GtkWebViewToolbar *toolbar,
+                                              PurpleConversation *conv)
+{
+	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	PurpleConnection *gc = purple_conversation_get_connection(conv);
+	PurplePlugin *prpl = purple_connection_get_prpl(gc);
+
+	priv->active_conv = conv;
+
+	/* gray out attention button on protocols that don't support it
+	 for the time being it is always disabled for chats */
+	gtk_widget_set_sensitive(priv->attention,
+		conv && prpl && purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM &&
+		PURPLE_PLUGIN_PROTOCOL_INFO(prpl)->send_attention != NULL);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pidgin/gtkwebviewtoolbar.h	Mon Jan 09 11:32:01 2012 +0000
@@ -0,0 +1,96 @@
+/*
+ * GtkWebViewToolbar
+ *
+ * Pidgin is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ *
+ */
+#ifndef _PIDGINWEBVIEWTOOLBAR_H_
+#define _PIDGINWEBVIEWTOOLBAR_H_
+
+#include <gtk/gtk.h>
+#include "gtkwebview.h"
+
+#define DEFAULT_FONT_FACE "Helvetica 12"
+
+#define GTK_TYPE_WEBVIEWTOOLBAR            (gtk_webviewtoolbar_get_type())
+#define GTK_WEBVIEWTOOLBAR(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_TYPE_WEBVIEWTOOLBAR, GtkWebViewToolbar))
+#define GTK_WEBVIEWTOOLBAR_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), GTK_TYPE_WEBVIEWTOOLBAR, GtkWebViewToolbarClass))
+#define GTK_IS_WEBVIEWTOOLBAR(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTK_TYPE_WEBVIEWTOOLBAR))
+#define GTK_IS_WEBVIEWTOOLBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GTK_TYPE_WEBVIEWTOOLBAR))
+#define GTK_WEBVIEWTOOLBAR_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_TYPE_WEBVIEWTOOLBAR, GtkWebViewToolbarClass))
+
+typedef struct _GtkWebViewToolbar GtkWebViewToolbar;
+typedef struct _GtkWebViewToolbarClass GtkWebViewToolbarClass;
+
+struct _GtkWebViewToolbar {
+	GtkHBox box;
+
+	GtkWidget *webview;
+};
+
+struct _GtkWebViewToolbarClass {
+	GtkHBoxClass parent_class;
+};
+
+G_BEGIN_DECLS
+
+/**
+ * Returns the GType for a GtkWebViewToolbar widget
+ *
+ * @return The GType for GtkWebViewToolbar widget
+ */
+GType gtk_webviewtoolbar_get_type(void);
+
+/**
+ * Create a new GtkWebViewToolbar object
+ *
+ * @return A GtkWidget corresponding to the GtkWebViewToolbar object
+ */
+GtkWidget *gtk_webviewtoolbar_new(void);
+
+/**
+ * Attach a GtkWebViewToolbar object to a GtkWebView
+ *
+ * @param toolbar The GtkWebViewToolbar object
+ * @param webview The GtkWebView object
+ */
+void gtk_webviewtoolbar_attach(GtkWebViewToolbar *toolbar, GtkWidget *webview);
+
+/**
+ * Associate the smileys from a protocol to a GtkWebViewToolbar object
+ *
+ * @param toolbar  The GtkWebViewToolbar object
+ * @param proto_id The ID of the protocol from which smileys are associated
+ */
+void gtk_webviewtoolbar_associate_smileys(GtkWebViewToolbar *toolbar,
+                                          const char *proto_id);
+
+/**
+ * Switch the active conversation for a GtkWebViewToolbar object
+ *
+ * @param toolbar The GtkWebViewToolbar object
+ * @param conv    The new conversation
+ */
+void gtk_webviewtoolbar_switch_active_conversation(GtkWebViewToolbar *toolbar,
+                                                   PurpleConversation *conv);
+
+G_END_DECLS
+
+#endif /* _PIDGINWEBVIEWTOOLBAR_H_ */
+