pidgin: 67b28e53: Add some formatting signals to webview f...

qulogic at pidgin.im qulogic at pidgin.im
Thu Jan 5 23:00:54 EST 2012


----------------------------------------------------------------------
Revision: 67b28e53ba4214063346ec807dddbcb80089b5d9
Parent:   f102530de280bc229ae948996fc728655d498b40
Author:   qulogic at pidgin.im
Date:     01/05/12 00:59:21
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/67b28e53ba4214063346ec807dddbcb80089b5d9

Changelog: 

Add some formatting signals to webview from imhtml.

Changes against parent f102530de280bc229ae948996fc728655d498b40

  patched  pidgin/gtkwebview.c
  patched  pidgin/gtkwebview.h

-------------- next part --------------
============================================================
--- pidgin/gtkwebview.c	b40c2bda5f3e0d67d5f9dc32c66137c6f28ddb3b
+++ pidgin/gtkwebview.c	1936e448c00a23c2b901e3a693448da473df1c3c
@@ -28,6 +28,7 @@
 #include "internal.h"
 #include "pidgin.h"
 
+#include <gdk/gdkkeysyms.h>
 #include "gtkwebview.h"
 
 #define MAX_FONT_SIZE 7
@@ -37,6 +38,15 @@
 #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
  *****************************************************************************/
@@ -327,6 +337,37 @@ webview_clear_formatting(GtkWebView *web
 	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
  *****************************************************************************/
@@ -356,11 +397,67 @@ gtk_webview_class_init(GtkWebViewClass *
 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
============================================================
--- pidgin/gtkwebview.h	bb1c525358d553e120275152f12834fe85e525d1
+++ pidgin/gtkwebview.h	e46233d6e576081f295f21296f79ddce69fe3236
@@ -70,6 +70,11 @@ struct _GtkWebViewClass
 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


More information about the Commits mailing list