diff options
author | Marco Pesenti Gritti <mpg@redhat.com> | 2005-05-16 09:07:43 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <marco@src.gnome.org> | 2005-05-16 09:07:43 (GMT) |
commit | 3159bda019e6ee334bfd11af45bd8ada0a871f33 (patch) | |
tree | e34539f96f2879b93fb04a101cb322ea4d2ae63a /shell | |
parent | ba33ad17ac72e6383eae5fec2974480e4ae892f7 (diff) |
Expose api to print a range (with dialog). Make private _print use it.
2005-05-16 Marco Pesenti Gritti <mpg@redhat.com>
* shell/ev-window.c: (ev_window_print), (ev_window_print_range):
* shell/ev-window.h:
Expose api to print a range (with dialog). Make private _print use
it.
* shell/ev-sidebar-links.c: (print_section_cb), (button_press_cb),
(ev_sidebar_links_construct):
Show a print context menu on linkx, it prints the selected
section.
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ev-sidebar-links.c | 84 | ||||
-rw-r--r-- | shell/ev-window.c | 26 | ||||
-rw-r--r-- | shell/ev-window.h | 3 |
3 files changed, 106 insertions, 7 deletions
diff --git a/shell/ev-sidebar-links.c b/shell/ev-sidebar-links.c index 80eb610..93959b3 100644 --- a/shell/ev-sidebar-links.c +++ b/shell/ev-sidebar-links.c @@ -223,6 +223,85 @@ create_loading_model (void) } static void +print_section_cb (GtkWidget *menuitem, EvSidebarLinks *sidebar) +{ + GtkWidget *window; + GtkTreeSelection *selection; + GtkTreeModel *model; + GtkTreeIter iter; + + selection = gtk_tree_view_get_selection + (GTK_TREE_VIEW (sidebar->priv->tree_view)); + + if (gtk_tree_selection_get_selected (selection, &model, &iter)) { + EvLink *link; + int first_page, last_page; + + gtk_tree_model_get (model, &iter, + EV_DOCUMENT_LINKS_COLUMN_LINK, &link, + -1); + first_page = ev_link_get_page (link) + 1; + + if (gtk_tree_model_iter_next (model, &iter)) { + gtk_tree_model_get (model, &iter, + EV_DOCUMENT_LINKS_COLUMN_LINK, &link, + -1); + last_page = ev_link_get_page (link); + } else { + last_page = -1; + } + + window = gtk_widget_get_toplevel (GTK_WIDGET (sidebar)); + if (EV_IS_WINDOW (window)) { + ev_window_print_range (EV_WINDOW (window), + first_page, last_page); + } + } +} + +static gboolean +button_press_cb (GtkWidget *treeview, + GdkEventButton *event, + EvSidebarLinks *sidebar) +{ + GtkTreePath *path = NULL; + + if (event->button == 3) { + if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (treeview), + event->x, + event->y, + &path, + NULL, NULL, NULL)) { + GtkWidget *menu; + GtkWidget *item; + + gtk_tree_view_set_cursor (GTK_TREE_VIEW (treeview), + path, NULL, FALSE); + + menu = gtk_menu_new (); + item = gtk_image_menu_item_new_from_stock + (GTK_STOCK_PRINT, NULL); + gtk_label_set_label (GTK_LABEL (GTK_BIN (item)->child), + _("Print...")); + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + g_signal_connect (item, "activate", + G_CALLBACK (print_section_cb), sidebar); + + gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, 2, + gtk_get_current_event_time ()); + + gtk_tree_path_free (path); + + return TRUE; + } + } + + return FALSE; +} + + +static void ev_sidebar_links_construct (EvSidebarLinks *ev_sidebar_links) { EvSidebarLinksPrivate *priv; @@ -274,7 +353,10 @@ ev_sidebar_links_construct (EvSidebarLinks *ev_sidebar_links) (GtkTreeCellDataFunc) links_page_num_func, ev_sidebar_links, NULL); - + g_signal_connect (GTK_TREE_VIEW (priv->tree_view), + "button_press_event", + G_CALLBACK (button_press_cb), + ev_sidebar_links); } static void diff --git a/shell/ev-window.c b/shell/ev-window.c index 085f60a..f1b4160 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -1070,23 +1070,38 @@ using_postscript_printer (GnomePrintConfig *config) } static void -ev_window_print (EvWindow *ev_window) +ev_window_print (EvWindow *window) +{ + EvPageCache *page_cache; + int last_page; + + page_cache = ev_document_get_page_cache (window->priv->document); + last_page = ev_page_cache_get_n_pages (page_cache); + + ev_window_print_range (window, 1, -1); +} + +void +ev_window_print_range (EvWindow *ev_window, int first_page, int last_page) { GnomePrintConfig *config; GnomePrintJob *job; GtkWidget *print_dialog; - EvPageCache *page_cache; gchar *pages_label; EvPrintJob *print_job = NULL; + EvPageCache *page_cache; g_return_if_fail (EV_IS_WINDOW (ev_window)); g_return_if_fail (ev_window->priv->document != NULL); + page_cache = ev_document_get_page_cache (ev_window->priv->document); + if (last_page == -1) { + last_page = ev_page_cache_get_n_pages (page_cache); + } + config = gnome_print_config_default (); job = gnome_print_job_new (config); - page_cache = ev_document_get_page_cache (ev_window->priv->document); - print_dialog = gnome_print_dialog_new (job, (guchar *) _("Print"), (GNOME_PRINT_DIALOG_RANGE | GNOME_PRINT_DIALOG_COPIES)); @@ -1095,8 +1110,7 @@ ev_window_print (EvWindow *ev_window) gnome_print_dialog_construct_range_page (GNOME_PRINT_DIALOG (print_dialog), GNOME_PRINT_RANGE_ALL | GNOME_PRINT_RANGE_RANGE, - 1, - ev_page_cache_get_n_pages (page_cache), + first_page, last_page, NULL, (const guchar *)pages_label); g_free (pages_label); diff --git a/shell/ev-window.h b/shell/ev-window.h index d6085a8..fe2c279 100644 --- a/shell/ev-window.h +++ b/shell/ev-window.h @@ -56,6 +56,9 @@ void ev_window_open (EvWindow *ev_window, void ev_window_open_page (EvWindow *ev_window, int page); gboolean ev_window_is_empty (const EvWindow *ev_window); +void ev_window_print_range (EvWindow *ev_window, + int first_page, + int last_page); G_END_DECLS |