+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.
+
2005-05-15 Carlos Garcia Campos <carlosgc@gnome.org>
* shell/ev-sidebar.c: make the drop down menu as width as the toggle
return retval;
}
+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)
{
(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
}
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));
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);