Mercurial > pidgin
changeset 32138:d9cb56d33839
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!
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Fri, 09 Sep 2011 01:52:12 +0000 |
parents | 1798b24a4fd5 |
children | e28be6277234 |
files | pidgin/gtkconv.c pidgin/gtkutils.c pidgin/gtkutils.h |
diffstat | 3 files changed, 92 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/pidgin/gtkconv.c Thu Sep 08 23:28:40 2011 +0000 +++ b/pidgin/gtkconv.c Fri Sep 09 01:52:12 2011 +0000 @@ -4947,7 +4947,6 @@ 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 @@ 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, >kconv->webview, NULL, &webview_sw); gtk_widget_set_size_request(gtkconv->webview, -1, 0); if (chat) { @@ -5061,23 +5051,18 @@ 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_widget_show_all(webview_sw); + gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0); + } + 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",
--- a/pidgin/gtkutils.c Thu Sep 08 23:28:40 2011 +0000 +++ b/pidgin/gtkutils.c Fri Sep 09 01:52:12 2011 +0000 @@ -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 @@ 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) {
--- a/pidgin/gtkutils.h Thu Sep 08 23:28:40 2011 +0000 +++ b/pidgin/gtkutils.h Fri Sep 09 01:52:12 2011 +0000 @@ -109,6 +109,28 @@ 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.