[balsa] Add print option to context menu for HTML parts
- From: Peter Bloomfield <PeterB src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [balsa] Add print option to context menu for HTML parts
- Date: Fri, 15 Jan 2010 02:20:54 +0000 (UTC)
commit 2bed365a0af264dea848540f0e5e1be573543230
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Thu Jan 14 21:19:26 2010 -0500
Add print option to context menu for HTML parts
* libbalsa/html.h: new methods for printing.
* libbalsa/html.c (libbalsa_html_can_print),
(libbalsa_html_print): implement them.
* src/balsa-mime-widget-text.c (bmwt_populate_popup_menu),
(bmwt_populate_popup_cb): use them.
2010-01-14 Peter Bloomfield
ChangeLog | 8 ++++
libbalsa/html.c | 75 ++++++++++++++++++++++++++++++++++++++++--
libbalsa/html.h | 4 ++
src/balsa-mime-widget-text.c | 12 ++++++-
4 files changed, 95 insertions(+), 4 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 13a0566..80d82d7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2010-01-14 Peter Bloomfield
+ * libbalsa/html.h: new methods for printing.
+ * libbalsa/html.c (libbalsa_html_can_print),
+ (libbalsa_html_print): implement them.
+ * src/balsa-mime-widget-text.c (bmwt_populate_popup_menu),
+ (bmwt_populate_popup_cb): use them.
+
+2010-01-14 Peter Bloomfield
+
* configure.in: require NetworkManager version 0.7.
* src/main-window.c: use GObject-based API instead of deprecated
older API.
diff --git a/libbalsa/html.c b/libbalsa/html.c
index bf39380..3b3ce1f 100644
--- a/libbalsa/html.c
+++ b/libbalsa/html.c
@@ -585,7 +585,6 @@ lbh_js_object_get_property(JSContextRef ctx,
* Search for the text; if text is empty, return TRUE (for consistency
* with GtkTextIter methods).
*/
-
gboolean
libbalsa_html_search_text(GtkWidget * widget,
const gchar * text,
@@ -614,7 +613,6 @@ libbalsa_html_search_text(GtkWidget * widget,
* Get the rectangle containing the currently selected text, for
* scrolling.
*/
-
void
libbalsa_html_get_selection_bounds(GtkWidget * widget,
GdkRectangle * selection_bounds)
@@ -631,7 +629,7 @@ libbalsa_html_get_selection_bounds(GtkWidget * widget,
ctx = lbh_js_get_global_context(web_view);
value = lbh_js_run_script(ctx, script);
- if (JSValueIsObject(ctx, value)) {
+ if (value && JSValueIsObject(ctx, value)) {
JSObjectRef object = JSValueToObject(ctx, value, NULL);
gint x, y;
@@ -650,6 +648,10 @@ libbalsa_html_get_selection_bounds(GtkWidget * widget,
}
}
+/*
+ * Get the WebKitWebView widget from the container; we need to connect
+ * to its "populate-popup" signal.
+ */
GtkWidget *
libbalsa_html_popup_menu_widget(GtkWidget * widget)
{
@@ -659,6 +661,31 @@ libbalsa_html_popup_menu_widget(GtkWidget * widget)
GTK_WIDGET(web_view) : NULL;
}
+/*
+ * Does the widget support printing?
+ */
+gboolean
+libbalsa_html_can_print(GtkWidget * widget)
+{
+ WebKitWebView *web_view;
+
+ return lbh_get_web_view(widget, &web_view);
+}
+
+/*
+ * Print the widget's content.
+ */
+void
+libbalsa_html_print(GtkWidget * widget)
+{
+ WebKitWebView *web_view;
+
+ if (lbh_get_web_view(widget, &web_view)) {
+ WebKitWebFrame *frame = webkit_web_view_get_main_frame(web_view);
+ webkit_web_frame_print(frame);
+ }
+}
+
# else /* defined(HAVE_WEBKIT) */
/* Common code for both GtkHtml widgets. */
@@ -917,6 +944,28 @@ libbalsa_html_copy(GtkWidget * widget)
gtk_html_copy(GTK_HTML(widget));
}
+/*
+ * Does the widget support printing?
+ */
+gboolean
+libbalsa_html_can_print(GtkWidget * widget)
+{
+ return GTK_IS_HTML(widget);
+}
+
+/*
+ * Print the widget's content.
+ */
+void
+libbalsa_html_print(GtkWidget * widget)
+{
+ GtkPrintOperation *operation = gtk_print_operation_new();
+ gtk_html_print_operation_run(GTK_HTML(widget), operation,
+ GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ g_object_unref(operation);
+}
+
# else /* HAVE_GTKHTML3 */
/* Code for GtkHtml-2 */
@@ -1056,6 +1105,23 @@ libbalsa_html_copy(GtkWidget * widget)
{
}
+/*
+ * HtmlView doesn't support printing.
+ */
+gboolean
+libbalsa_html_can_print(GtkWidget * widget)
+{
+ return FALSE;
+}
+
+/*
+ * Do nothing.
+ */
+void
+libbalsa_html_print(GtkWidget * widget)
+{
+}
+
# endif /* HAVE_GTKHTML3 */
/* Common code for both widgets. */
@@ -1118,6 +1184,9 @@ libbalsa_html_get_selection_bounds(GtkWidget * widget,
{
}
+/*
+ * Neither widget implements its own popup widget.
+ */
GtkWidget *
libbalsa_html_popup_menu_widget(GtkWidget *widget)
{
diff --git a/libbalsa/html.h b/libbalsa/html.h
index 4245d62..135fdf0 100644
--- a/libbalsa/html.h
+++ b/libbalsa/html.h
@@ -64,8 +64,12 @@ gboolean libbalsa_html_search_text(GtkWidget * widget, const gchar * text,
gboolean find_forward, gboolean wrap);
void libbalsa_html_get_selection_bounds(GtkWidget * widget,
GdkRectangle * selection_bounds);
+
GtkWidget *libbalsa_html_popup_menu_widget(GtkWidget * widget);
+gboolean libbalsa_html_can_print(GtkWidget * widget);
+void libbalsa_html_print(GtkWidget * widget);
+
# endif /* HAVE_GTKHTML */
LibBalsaHTMLType libbalsa_html_type(const gchar * mime_type);
diff --git a/src/balsa-mime-widget-text.c b/src/balsa-mime-widget-text.c
index 09f196b..3f45bc6 100644
--- a/src/balsa-mime-widget-text.c
+++ b/src/balsa-mime-widget-text.c
@@ -1198,6 +1198,16 @@ bmwt_populate_popup_menu(BalsaMessage * bm,
G_CALLBACK(balsa_mime_widget_ctx_menu_save),
mime_body);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+
+ menuitem = gtk_separator_menu_item_new();
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+
+ menuitem =
+ gtk_image_menu_item_new_from_stock(GTK_STOCK_PRINT, NULL);
+ g_signal_connect_swapped(G_OBJECT(menuitem), "activate",
+ G_CALLBACK(libbalsa_html_print), html);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+ gtk_widget_set_sensitive(menuitem, libbalsa_html_can_print(html));
}
static gboolean
@@ -1234,7 +1244,7 @@ bmwt_populate_popup_cb(GtkWidget * widget, GtkMenu * menu, gpointer data)
/* Remove WebKitWebView's items--they're irrelevant and confusing */
gtk_container_foreach(GTK_CONTAINER(menu),
- (GtkCallback) gtk_widget_destroy, menu);
+ (GtkCallback) gtk_widget_destroy, NULL);
bmwt_populate_popup_menu(bm, html, menu);
gtk_widget_show_all(GTK_WIDGET(menu));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]