/pidgin/main: eb15b7f78e32: Convert GtkStatusBox to use a GtkWeb...
Elliott Sales de Andrade
qulogic at pidgin.im
Tue Aug 14 04:03:26 EDT 2012
Changeset: eb15b7f78e3272f77e046c2ee9cdb8965376dfca
Author: Elliott Sales de Andrade <qulogic at pidgin.im>
Date: 2012-08-13 21:12 -0400
Branch: default
URL: http://hg.pidgin.im/pidgin/main/rev/eb15b7f78e32
Description:
Convert GtkStatusBox to use a GtkWebView.
BTW, sizing doesn't work yet...
diffstat:
pidgin/gtkstatusbox.c | 203 +++++++++++++++++++++++++------------------------
pidgin/gtkstatusbox.h | 6 +-
2 files changed, 108 insertions(+), 101 deletions(-)
diffs (truncated from 500 to 300 lines):
diff --git a/pidgin/gtkstatusbox.c b/pidgin/gtkstatusbox.c
--- a/pidgin/gtkstatusbox.c
+++ b/pidgin/gtkstatusbox.c
@@ -72,8 +72,8 @@
/* Timeout for typing notifications in seconds */
#define TYPING_TIMEOUT 4
-static void imhtml_changed_cb(GtkTextBuffer *buffer, void *data);
-static void imhtml_format_changed_cb(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons, void *data);
+static void webview_changed_cb(GtkWebView *webview, void *data);
+static void webview_format_changed_cb(GtkWebView *webview, GtkWebViewButtons buttons, void *data);
static void remove_typing_cb(PidginStatusBox *box);
static void update_size (PidginStatusBox *box);
static gint get_statusbox_index(PidginStatusBox *box, PurpleSavedStatus *saved_status);
@@ -274,8 +274,11 @@ update_to_reflect_account_status(PidginS
break;
}
- gtk_imhtml_set_populate_primary_clipboard(
- GTK_IMHTML(status_box->imhtml), TRUE);
+#if 0
+ /* TODO WebKit: Doesn't do this? */
+ gtk_webview_set_populate_primary_clipboard(
+ GTK_WEBVIEW(status_box->webview), TRUE);
+#endif
if (status_no != -1) {
GtkTreePath *path;
@@ -291,15 +294,13 @@ update_to_reflect_account_status(PidginS
if (!message || !*message)
{
gtk_widget_hide(status_box->vbox);
- status_box->imhtml_visible = FALSE;
+ status_box->webview_visible = FALSE;
}
else
{
gtk_widget_show_all(status_box->vbox);
- status_box->imhtml_visible = TRUE;
- gtk_imhtml_clear(GTK_IMHTML(status_box->imhtml));
- gtk_imhtml_clear_formatting(GTK_IMHTML(status_box->imhtml));
- gtk_imhtml_append_text(GTK_IMHTML(status_box->imhtml), message, 0);
+ status_box->webview_visible = TRUE;
+ gtk_webview_load_html_string(GTK_WEBVIEW(status_box->webview), message);
}
gtk_widget_set_sensitive(GTK_WIDGET(status_box), TRUE);
pidgin_status_box_refresh(status_box);
@@ -929,7 +930,7 @@ status_menu_refresh_iter(PidginStatusBox
message = purple_savedstatus_get_message(saved_status);
/*
- * If we are going to hide the imhtml, don't retain the
+ * If we are going to hide the webview, don't retain the
* message because showing the old message later is
* confusing. If we are going to set the message to a pre-set,
* then we need to do this anyway
@@ -937,25 +938,25 @@ status_menu_refresh_iter(PidginStatusBox
* Suppress the "changed" signal because the status
* was changed programmatically.
*/
- gtk_widget_set_sensitive(GTK_WIDGET(status_box->imhtml), FALSE);
-
- gtk_imhtml_clear(GTK_IMHTML(status_box->imhtml));
- gtk_imhtml_clear_formatting(GTK_IMHTML(status_box->imhtml));
+ gtk_widget_set_sensitive(GTK_WIDGET(status_box->webview), FALSE);
+
+ gtk_webview_load_html_string(GTK_WEBVIEW(status_box->webview), "");
+ gtk_webview_clear_formatting(GTK_WEBVIEW(status_box->webview));
if (!purple_savedstatus_is_transient(saved_status) || !message || !*message)
{
- status_box->imhtml_visible = FALSE;
+ status_box->webview_visible = FALSE;
gtk_widget_hide(status_box->vbox);
}
else
{
- status_box->imhtml_visible = TRUE;
+ status_box->webview_visible = TRUE;
gtk_widget_show_all(status_box->vbox);
- gtk_imhtml_append_text(GTK_IMHTML(status_box->imhtml), message, 0);
+ gtk_webview_load_html_string(GTK_WEBVIEW(status_box->webview), message);
}
- gtk_widget_set_sensitive(GTK_WIDGET(status_box->imhtml), TRUE);
+ gtk_widget_set_sensitive(GTK_WIDGET(status_box->webview), TRUE);
update_size(status_box);
}
@@ -1132,28 +1133,35 @@ pidgin_status_box_regenerate(PidginStatu
gtk_tree_view_set_search_column(GTK_TREE_VIEW(status_box->tree_view), TEXT_COLUMN);
}
-static gboolean combo_box_scroll_event_cb(GtkWidget *w, GdkEventScroll *event, GtkIMHtml *imhtml)
+static gboolean
+combo_box_scroll_event_cb(GtkWidget *w, GdkEventScroll *event, GtkWebView *webview)
{
pidgin_status_box_popup(PIDGIN_STATUS_BOX(w));
return TRUE;
}
-static gboolean imhtml_scroll_event_cb(GtkWidget *w, GdkEventScroll *event, GtkIMHtml *imhtml)
+static gboolean
+webview_scroll_event_cb(GtkWidget *w, GdkEventScroll *event, GtkWebView *webview)
{
if (event->direction == GDK_SCROLL_UP)
- gtk_imhtml_page_up(imhtml);
+ gtk_webview_page_up(webview);
else if (event->direction == GDK_SCROLL_DOWN)
- gtk_imhtml_page_down(imhtml);
+ gtk_webview_page_down(webview);
return TRUE;
}
-static gboolean imhtml_remove_focus(GtkWidget *w, GdkEventKey *event, PidginStatusBox *status_box)
+static gboolean
+webview_remove_focus(GtkWidget *w, GdkEventKey *event, PidginStatusBox *status_box)
{
- if (event->keyval == GDK_KEY_Tab || event->keyval == GDK_KEY_KP_Tab || event->keyval == GDK_KEY_ISO_Left_Tab)
+ if (event->keyval == GDK_KEY_Return || event->keyval == GDK_KEY_KP_Enter) {
+ remove_typing_cb(status_box);
+ return TRUE;
+ }
+ else if (event->keyval == GDK_KEY_Tab || event->keyval == GDK_KEY_KP_Tab || event->keyval == GDK_KEY_ISO_Left_Tab)
{
/* If last inserted character is a tab, then remove the focus from here */
GtkWidget *top = gtk_widget_get_toplevel(w);
- g_signal_emit_by_name(G_OBJECT(top), "move_focus",
+ g_signal_emit_by_name(G_OBJECT(top), "move-focus",
(event->state & GDK_SHIFT_MASK) ?
GTK_DIR_TAB_BACKWARD: GTK_DIR_TAB_FORWARD);
return TRUE;
@@ -1166,8 +1174,11 @@ static gboolean imhtml_remove_focus(GtkW
{
purple_timeout_remove(status_box->typing);
status_box->typing = 0;
- gtk_imhtml_set_populate_primary_clipboard(
- GTK_IMHTML(status_box->imhtml), TRUE);
+#if 0
+ /* TODO WebKit: Doesn't do this? */
+ gtk_webview_set_populate_primary_clipboard(
+ GTK_WEBVIEW(status_box->webview), TRUE);
+#endif
if (status_box->account != NULL)
update_to_reflect_account_status(status_box, status_box->account,
purple_account_get_active_status(status_box->account));
@@ -1266,18 +1277,10 @@ static void
spellcheck_prefs_cb(const char *name, PurplePrefType type,
gconstpointer value, gpointer data)
{
-#ifdef USE_GTKSPELL
PidginStatusBox *status_box = (PidginStatusBox *)data;
- if (value)
- pidgin_setup_gtkspell(GTK_TEXT_VIEW(status_box->imhtml));
- else
- {
- GtkSpell *spell;
- spell = gtkspell_get_from_text_view(GTK_TEXT_VIEW(status_box->imhtml));
- gtkspell_detach(spell);
- }
-#endif
+ pidgin_webview_set_spellcheck(GTK_WEBVIEW(status_box->webview),
+ (gboolean)GPOINTER_TO_INT(value));
}
#if 0
@@ -1287,7 +1290,7 @@ static gboolean button_released_cb(GtkWi
if (event->button != 1)
return FALSE;
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(box->toggle_button), FALSE);
- if (!box->imhtml_visible)
+ if (!box->webview_visible)
g_signal_emit_by_name(G_OBJECT(box), "changed", NULL, NULL);
return TRUE;
}
@@ -1703,14 +1706,13 @@ treeview_key_press_event(GtkWidget *widg
}
static void
-imhtml_cursor_moved_cb(gpointer data, GtkMovementStep step, gint count, gboolean extend,
- GtkWidget *widget)
+webview_cursor_moved_cb(gpointer data, GtkWebView *webview)
{
/* Restart the typing timeout if arrow keys are pressed while editing the message */
PidginStatusBox *status_box = data;
if (status_box->typing == 0)
return;
- imhtml_changed_cb(NULL, status_box);
+ webview_changed_cb(NULL, status_box);
}
static void
@@ -1761,12 +1763,11 @@ pidgin_status_box_init (PidginStatusBox
GtkCellRenderer *text_rend;
GtkCellRenderer *icon_rend;
GtkCellRenderer *emblem_rend;
- GtkTextBuffer *buffer;
GtkWidget *toplevel;
GtkTreeSelection *sel;
gtk_widget_set_has_window(GTK_WIDGET(status_box), FALSE);
- status_box->imhtml_visible = FALSE;
+ status_box->webview_visible = FALSE;
status_box->network_available = purple_network_is_available();
status_box->connecting = FALSE;
status_box->typing = 0;
@@ -1859,10 +1860,9 @@ pidgin_status_box_init (PidginStatusBox
g_object_set(status_box->text_rend, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
status_box->vbox = gtk_vbox_new(0, FALSE);
- status_box->sw = pidgin_create_imhtml(FALSE, &status_box->imhtml, NULL, NULL);
- gtk_imhtml_set_editable(GTK_IMHTML(status_box->imhtml), TRUE);
-
- buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(status_box->imhtml));
+ status_box->sw = pidgin_create_webview(FALSE, &status_box->webview, NULL, NULL);
+ gtk_webview_set_editable(GTK_WEBVIEW(status_box->webview), TRUE);
+
#if 0
g_signal_connect(G_OBJECT(status_box->toggle_button), "button-press-event",
G_CALLBACK(button_pressed_cb), status_box);
@@ -1873,19 +1873,17 @@ pidgin_status_box_init (PidginStatusBox
G_CALLBACK(toggle_key_press_cb), status_box);
g_signal_connect(G_OBJECT(status_box->toggle_button), "button-press-event",
G_CALLBACK(toggled_cb), status_box);
- g_signal_connect(G_OBJECT(buffer), "changed", G_CALLBACK(imhtml_changed_cb), status_box);
- g_signal_connect(G_OBJECT(status_box->imhtml), "format_function_toggle",
- G_CALLBACK(imhtml_format_changed_cb), status_box);
- g_signal_connect_swapped(G_OBJECT(status_box->imhtml), "move_cursor",
- G_CALLBACK(imhtml_cursor_moved_cb), status_box);
- g_signal_connect(G_OBJECT(status_box->imhtml), "key_press_event",
- G_CALLBACK(imhtml_remove_focus), status_box);
- g_signal_connect_swapped(G_OBJECT(status_box->imhtml), "message_send", G_CALLBACK(remove_typing_cb), status_box);
-
-#ifdef USE_GTKSPELL
+ g_signal_connect(G_OBJECT(status_box->webview), "changed",
+ G_CALLBACK(webview_changed_cb), status_box);
+ g_signal_connect(G_OBJECT(status_box->webview), "format-toggled",
+ G_CALLBACK(webview_format_changed_cb), status_box);
+ g_signal_connect_swapped(G_OBJECT(status_box->webview), "selection-changed",
+ G_CALLBACK(webview_cursor_moved_cb), status_box);
+ g_signal_connect(G_OBJECT(status_box->webview), "key-press-event",
+ G_CALLBACK(webview_remove_focus), status_box);
+
if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/spellcheck"))
- pidgin_setup_gtkspell(GTK_TEXT_VIEW(status_box->imhtml));
-#endif
+ pidgin_webview_set_spellcheck(GTK_WEBVIEW(status_box->webview), TRUE);
gtk_widget_set_parent(status_box->vbox, GTK_WIDGET(status_box));
gtk_widget_show_all(status_box->vbox);
@@ -1893,9 +1891,9 @@ pidgin_status_box_init (PidginStatusBox
gtk_box_pack_start(GTK_BOX(status_box->vbox), status_box->sw, TRUE, TRUE, 0);
- g_signal_connect(G_OBJECT(status_box), "scroll_event", G_CALLBACK(combo_box_scroll_event_cb), NULL);
- g_signal_connect(G_OBJECT(status_box->imhtml), "scroll_event",
- G_CALLBACK(imhtml_scroll_event_cb), status_box->imhtml);
+ g_signal_connect(G_OBJECT(status_box), "scroll-event", G_CALLBACK(combo_box_scroll_event_cb), NULL);
+ g_signal_connect(G_OBJECT(status_box->webview), "scroll-event",
+ G_CALLBACK(webview_scroll_event_cb), status_box->webview);
g_signal_connect(G_OBJECT(status_box->popup_window), "button_release_event", G_CALLBACK(treeview_button_release_cb), status_box);
g_signal_connect(G_OBJECT(status_box->popup_window), "key_press_event", G_CALLBACK(treeview_key_press_event), status_box);
g_signal_connect(G_OBJECT(status_box->tree_view), "cursor-changed",
@@ -1954,8 +1952,8 @@ pidgin_status_box_get_preferred_height(G
*minimum_height = MAX(*minimum_height, 34) + border_width * 2;
*natural_height = MAX(*natural_height, 34) + border_width * 2;
- /* If the gtkimhtml is visible, then add some additional padding */
- if (PIDGIN_STATUS_BOX(widget)->imhtml_visible) {
+ /* If the gtkwebview is visible, then add some additional padding */
+ if (PIDGIN_STATUS_BOX(widget)->webview_visible) {
gtk_widget_get_preferred_height(PIDGIN_STATUS_BOX(widget)->vbox,
&box_min_height, &box_nat_height);
@@ -1980,8 +1978,8 @@ pidgin_status_box_size_request(GtkWidget
requisition->height = MAX(requisition->height, 34);
requisition->height += border_width * 2;
- /* If the gtkimhtml is visible, then add some additional padding */
- if (PIDGIN_STATUS_BOX(widget)->imhtml_visible) {
+ /* If the gtkwebview is visible, then add some additional padding */
+ if (PIDGIN_STATUS_BOX(widget)->webview_visible) {
gtk_widget_size_request(PIDGIN_STATUS_BOX(widget)->vbox, &box_req);
if (box_req.height > 1)
requisition->height += box_req.height + border_width * 2;
@@ -2419,7 +2417,7 @@ activate_currently_selected_status(Pidgi
if (!message || !*message)
{
gtk_widget_hide(status_box->vbox);
- status_box->imhtml_visible = FALSE;
+ status_box->webview_visible = FALSE;
if (message != NULL)
{
g_free(message);
@@ -2577,6 +2575,8 @@ activate_currently_selected_status(Pidgi
static void update_size(PidginStatusBox *status_box)
{
More information about the Commits
mailing list