pidgin: b0a25495: Add a pidgin_create_webview utility func...

qulogic at pidgin.im qulogic at pidgin.im
Thu Sep 8 22:01:03 EDT 2011


----------------------------------------------------------------------
Revision: b0a254953fc36ede3bde903c137d76d2a1dec4dc
Parent:   d66f9264e66660ae12935d0356e802554e5902d3
Author:   qulogic at pidgin.im
Date:     09/08/11 21:52:12
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/b0a254953fc36ede3bde903c137d76d2a1dec4dc

Changelog: 

Add a pidgin_create_webview utility function, which acts similarly to
the imhtml version. Note that an editable webview does not yet exist,
so don't call this function with editable=TRUE!

Changes against parent d66f9264e66660ae12935d0356e802554e5902d3

  patched  pidgin/gtkconv.c
  patched  pidgin/gtkutils.c
  patched  pidgin/gtkutils.h

-------------- next part --------------
============================================================
--- pidgin/gtkconv.c	72440fc4e230fb0fa77b01a8db76b8e2226dadac
+++ pidgin/gtkconv.c	c7aeca76b335597909c1cc0d58353ca6493524fc
@@ -4947,7 +4947,6 @@ setup_common_pane(PidginConversation *gt
 	PurpleConversation *conv = gtkconv->active_conv;
 	PurpleBuddy *buddy;
 	gboolean chat = (conv->type == PURPLE_CONV_TYPE_CHAT);
-	GtkPolicyType webview_sw_hscroll;
 	int buddyicon_size = 0;
 
 	/* Setup the top part of the pane */
@@ -5039,16 +5038,7 @@ setup_common_pane(PidginConversation *gt
 	g_object_set(rend, "xalign", 0.0, "xpad", 6, "ypad", 0, NULL);
 
 	/* Setup the webkit widget */
-	/* TODO: create a pidgin_create_webview() function in utils*/
-	webview_sw = gtk_scrolled_window_new(NULL, NULL);
-	gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(webview_sw), GTK_SHADOW_IN);
-	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(webview_sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
-
-	gtkconv->webview = gtk_webview_new();
-	gtk_webview_set_vadjustment(GTK_WEBVIEW(gtkconv->webview),
-			gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(webview_sw)));
-	gtk_container_add(GTK_CONTAINER(webview_sw), gtkconv->webview);
-
+	frame = pidgin_create_webview(FALSE, &gtkconv->webview, NULL, &webview_sw);
 	gtk_widget_set_size_request(gtkconv->webview, -1, 0);
 
 	if (chat) {
@@ -5061,23 +5051,18 @@ setup_common_pane(PidginConversation *gt
 		hpaned = gtk_hpaned_new();
 		gtk_box_pack_start(GTK_BOX(vbox), hpaned, TRUE, TRUE, 0);
 		gtk_widget_show(hpaned);
-		gtk_paned_pack1(GTK_PANED(hpaned), webview_sw, TRUE, TRUE);
+		gtk_paned_pack1(GTK_PANED(hpaned), frame, TRUE, TRUE);
 
 		/* Now add the userlist */
 		setup_chat_userlist(gtkconv, hpaned);
 	} else {
-		gtk_box_pack_start(GTK_BOX(vbox), webview_sw, TRUE, TRUE, 0);
+		gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
 	}
-	gtk_widget_show_all(webview_sw);
+	gtk_widget_show_all(frame);
 
 	gtk_widget_set_name(gtkconv->webview, "pidgin_conv_webview");
 	g_object_set_data(G_OBJECT(gtkconv->webview), "gtkconv", gtkconv);
 
-	gtk_scrolled_window_get_policy(GTK_SCROLLED_WINDOW(webview_sw),
-	                               &webview_sw_hscroll, NULL);
-	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(webview_sw),
-	                               webview_sw_hscroll, GTK_POLICY_ALWAYS);
-
 	g_signal_connect_after(G_OBJECT(gtkconv->webview), "button_press_event",
 	                       G_CALLBACK(entry_stop_rclick_cb), NULL);
 	g_signal_connect(G_OBJECT(gtkconv->webview), "key_press_event",
============================================================
--- pidgin/gtkutils.c	0d1b6aee14af6571333a2b6074e708906c27457b
+++ pidgin/gtkutils.c	bef6204e01f9d0f13fc06f3dc3cf236a1c3fd8fa
@@ -67,6 +67,7 @@
 #include "pidginstock.h"
 #include "gtkthemes.h"
 #include "gtkutils.h"
+#include "gtkwebview.h"
 #include "pidgin/minidialog.h"
 
 typedef struct {
@@ -276,6 +277,70 @@ pidgin_create_imhtml(gboolean editable, 
 	return frame;
 }
 
+GtkWidget *
+pidgin_create_webview(gboolean editable, GtkWidget **webview_ret, GtkWidget **toolbar_ret, GtkWidget **sw_ret)
+{
+	GtkWidget *frame;
+	GtkWidget *webview;
+	GtkWidget *sep;
+	GtkWidget *sw;
+	GtkWidget *toolbar = NULL;
+	GtkWidget *vbox;
+
+	frame = gtk_frame_new(NULL);
+	gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
+
+	vbox = gtk_vbox_new(FALSE, 0);
+	gtk_container_add(GTK_CONTAINER(frame), vbox);
+	gtk_widget_show(vbox);
+
+	if (editable) {
+		toolbar = gtk_imhtmltoolbar_new();
+		gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
+		gtk_widget_show(toolbar);
+
+		sep = gtk_hseparator_new();
+		gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0);
+		g_signal_connect_swapped(G_OBJECT(toolbar), "show", G_CALLBACK(gtk_widget_show), sep);
+		g_signal_connect_swapped(G_OBJECT(toolbar), "hide", G_CALLBACK(gtk_widget_hide), sep);
+		gtk_widget_show(sep);
+	}
+
+	webview = gtk_webview_new();
+#if 0
+	/* FIXME: Don't have editable webview yet. */
+	gtk_webview_set_editable(GTK_WEBVIEW(webview), editable);
+#endif
+	gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(webview), GTK_WRAP_WORD_CHAR);
+#ifdef USE_GTKSPELL
+	if (editable && purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/spellcheck"))
+		pidgin_setup_gtkspell(GTK_TEXT_VIEW(webview));
+#endif
+	gtk_widget_show(webview);
+
+	if (editable) {
+		gtk_imhtmltoolbar_attach(GTK_IMHTMLTOOLBAR(toolbar), webview);
+		gtk_imhtmltoolbar_associate_smileys(GTK_IMHTMLTOOLBAR(toolbar), "default");
+	}
+
+	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);
+
+	gtk_webview_set_vadjustment(GTK_WEBVIEW(webview),
+			gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(sw)));
+
+	if (webview_ret != NULL)
+		*webview_ret = webview;
+
+	if (editable && (toolbar_ret != NULL))
+		*toolbar_ret = toolbar;
+
+	if (sw_ret != NULL)
+		*sw_ret = sw;
+
+	return frame;
+}
+
 void
 pidgin_set_sensitive_if_input(GtkWidget *entry, GtkWidget *dialog)
 {
============================================================
--- pidgin/gtkutils.h	87131c0d472b78b884749e0e14b804cd446ae32d
+++ pidgin/gtkutils.h	2e249909ea0f5927d7db6bce4430dac873b54ef5
@@ -109,6 +109,28 @@ GtkWidget *pidgin_create_imhtml(gboolean
 GtkWidget *pidgin_create_imhtml(gboolean editable, GtkWidget **imhtml_ret, GtkWidget **toolbar_ret, GtkWidget **sw_ret);
 
 /**
+ * Create an GtkWebView widget and associated GtkIMHtmlToolbar widget.  This
+ * function puts both widgets in a nice GtkFrame.  They're separated by an
+ * attractive GtkSeparator.
+ * FIXME: There is no editable GtkWebView yet.
+ *
+ * @param editable @c TRUE if this webview should be editable.  If this is
+ *        @c FALSE, then the toolbar will NOT be created.  If this webview
+ *        should be read-only at first, but may become editable later, then
+ *        pass in @c TRUE here and then manually call gtk_webview_set_editable()
+ *        later.
+ * @param webview_ret A pointer to a pointer to a GtkWidget.  This pointer
+ *        will be set to the webview when this function exits.
+ * @param toolbar_ret A pointer to a pointer to a GtkWidget.  If editable is
+ *        TRUE then this will be set to the toolbar when this function exits.
+ *        Otherwise this will be set to @c NULL.
+ * @param sw_ret This will be filled with a pointer to the scrolled window
+ *        widget which contains the webview.
+ * @return The GtkFrame containing the toolbar and webview.
+ */
+GtkWidget *pidgin_create_webview(gboolean editable, GtkWidget **webview_ret, GtkWidget **toolbar_ret, GtkWidget **sw_ret);
+
+/**
  * Creates a small button
  *
  * @param  image   A button image.


More information about the Commits mailing list