From d1e23d13d52f06f2aba2ece7ff17091110d8a3bb Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Tue, 4 Jan 2005 11:39:08 +0000 Subject: [PATCH] Change the layout to match clarkbw design. 2005-01-04 Marco Pesenti Gritti * data/evince-ui.xml: Change the layout to match clarkbw design. * shell/Makefile.am: * shell/ev-navigation-action.c: (build_menu), (menu_activated_cb), (set_tooltip_cb), (connect_proxy), (ev_navigation_action_init), (ev_navigation_action_finalize), (ev_navigation_action_set_property), (ev_navigation_action_get_property), (ev_navigation_action_class_init): * shell/ev-navigation-action.h: Implement clarkbw toolbar navigation controls (incomplete) * shell/ev-page-action.c: (update_label), (update_spin), (value_changed_cb), (create_tool_item), (connect_proxy), (ev_page_action_init), (ev_page_action_finalize), (ev_page_action_set_property), (ev_page_action_get_property), (ev_page_action_set_current_page), (ev_page_action_set_total_pages), (ev_page_action_class_init): * shell/ev-page-action.h: Implement a page switcher in the toolbar * shell/ev-view.c: (ev_view_scroll_view): * shell/ev-window.c: (update_total_pages), (ev_window_open), (update_current_page), (view_page_changed_cb), (goto_page_cb), (register_custom_actions), (ev_window_init): Change page on PageUp/Down. --- ChangeLog | 34 +++++ data/evince-ui.xml | 6 +- shell/Makefile.am | 4 + shell/ev-navigation-action.c | 203 +++++++++++++++++++++++++++ shell/ev-navigation-action.h | 63 +++++++++ shell/ev-page-action.c | 263 +++++++++++++++++++++++++++++++++++ shell/ev-page-action.h | 64 +++++++++ shell/ev-view.c | 59 ++++---- shell/ev-window.c | 77 +++++++++- 9 files changed, 740 insertions(+), 33 deletions(-) create mode 100644 shell/ev-navigation-action.c create mode 100644 shell/ev-navigation-action.h create mode 100644 shell/ev-page-action.c create mode 100644 shell/ev-page-action.h diff --git a/ChangeLog b/ChangeLog index 71e8545f..603bfa1f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,37 @@ +2005-01-04 Marco Pesenti Gritti + + * data/evince-ui.xml: + + Change the layout to match clarkbw design. + + * shell/Makefile.am: + * shell/ev-navigation-action.c: (build_menu), (menu_activated_cb), + (set_tooltip_cb), (connect_proxy), (ev_navigation_action_init), + (ev_navigation_action_finalize), + (ev_navigation_action_set_property), + (ev_navigation_action_get_property), + (ev_navigation_action_class_init): + * shell/ev-navigation-action.h: + + Implement clarkbw toolbar navigation controls (incomplete) + + * shell/ev-page-action.c: (update_label), (update_spin), + (value_changed_cb), (create_tool_item), (connect_proxy), + (ev_page_action_init), (ev_page_action_finalize), + (ev_page_action_set_property), (ev_page_action_get_property), + (ev_page_action_set_current_page), + (ev_page_action_set_total_pages), (ev_page_action_class_init): + * shell/ev-page-action.h: + + Implement a page switcher in the toolbar + + * shell/ev-view.c: (ev_view_scroll_view): + * shell/ev-window.c: (update_total_pages), (ev_window_open), + (update_current_page), (view_page_changed_cb), (goto_page_cb), + (register_custom_actions), (ev_window_init): + + Change page on PageUp/Down. + Tue Jan 4 03:22:56 2005 Jonathan Blandford * pdf/xpdf/pdf-document.cc diff --git a/data/evince-ui.xml b/data/evince-ui.xml index 098e3be8..f24b84a9 100644 --- a/data/evince-ui.xml +++ b/data/evince-ui.xml @@ -45,12 +45,12 @@ - + + - + - diff --git a/shell/Makefile.am b/shell/Makefile.am index dee7d1f6..b528da90 100644 --- a/shell/Makefile.am +++ b/shell/Makefile.am @@ -23,6 +23,10 @@ evince_SOURCES= \ ev-application.h \ ev-marshal.c \ ev-marshal.h \ + ev-navigation-action.c \ + ev-navigation-action.h \ + ev-page-action.c \ + ev-page-action.h \ ev-print-job.c \ ev-print-job.h \ ev-view.c \ diff --git a/shell/ev-navigation-action.c b/shell/ev-navigation-action.c new file mode 100644 index 00000000..7b5269a8 --- /dev/null +++ b/shell/ev-navigation-action.c @@ -0,0 +1,203 @@ +/* + * Copyright (C) 2003, 2004 Marco Pesenti Gritti + * Copyright (C) 2003, 2004 Christian Persch + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + */ + +#include "config.h" + +#include "ev-navigation-action.h" +#include "ev-window.h" + +#include +#include +#include +#include +#include +#include +#include + +struct _EvNavigationActionPrivate +{ + EvWindow *window; + EvNavigationDirection direction; + char *arrow_tooltip; +}; + +enum +{ + PROP_0, + PROP_ARROW_TOOLTIP, + PROP_DIRECTION +}; + +static void ev_navigation_action_init (EvNavigationAction *action); +static void ev_navigation_action_class_init (EvNavigationActionClass *class); + +static GObjectClass *parent_class = NULL; + +G_DEFINE_TYPE (EvNavigationAction, ev_navigation_action, GTK_TYPE_ACTION) + +#define EV_NAVIGATION_ACTION_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_NAVIGATION_ACTION, EvNavigationActionPrivate)) + +static GtkWidget * +build_menu (EvNavigationAction *action) +{ + GtkMenuShell *menu; + + menu = GTK_MENU_SHELL (gtk_menu_new ()); + + return GTK_WIDGET (menu); +} + +static void +menu_activated_cb (GtkMenuToolButton *button, + EvNavigationAction *action) +{ + GtkWidget *menu; + + menu = build_menu (action); + gtk_menu_tool_button_set_menu (button, menu); +} + +static gboolean +set_tooltip_cb (GtkMenuToolButton *proxy, + GtkTooltips *tooltips, + const char *tip, + const char *tip_private, + EvNavigationAction *action) +{ + gtk_menu_tool_button_set_arrow_tooltip (proxy, tooltips, + action->priv->arrow_tooltip, + NULL); + + /* don't stop emission */ + return FALSE; +} + +static void +connect_proxy (GtkAction *action, GtkWidget *proxy) +{ + if (GTK_IS_MENU_TOOL_BUTTON (proxy)) + { + GtkWidget *menu; + + /* set dummy menu so the arrow gets sensitive */ + menu = gtk_menu_new (); + gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (proxy), menu); + + g_signal_connect (proxy, "show-menu", + G_CALLBACK (menu_activated_cb), action); + + g_signal_connect (proxy, "set-tooltip", + G_CALLBACK (set_tooltip_cb), action); + } + + GTK_ACTION_CLASS (parent_class)->connect_proxy (action, proxy); +} + +static void +ev_navigation_action_init (EvNavigationAction *action) +{ + action->priv = EV_NAVIGATION_ACTION_GET_PRIVATE (action); +} + +static void +ev_navigation_action_finalize (GObject *object) +{ + EvNavigationAction *action = EV_NAVIGATION_ACTION (object); + + g_free (action->priv->arrow_tooltip); + + parent_class->finalize (object); +} + +static void +ev_navigation_action_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + EvNavigationAction *nav = EV_NAVIGATION_ACTION (object); + + switch (prop_id) + { + case PROP_ARROW_TOOLTIP: + nav->priv->arrow_tooltip = g_value_dup_string (value); + g_object_notify (object, "tooltip"); + break; + case PROP_DIRECTION: + nav->priv->direction = g_value_get_int (value); + break; + } +} + +static void +ev_navigation_action_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + EvNavigationAction *nav = EV_NAVIGATION_ACTION (object); + + switch (prop_id) + { + case PROP_ARROW_TOOLTIP: + g_value_set_string (value, nav->priv->arrow_tooltip); + break; + case PROP_DIRECTION: + g_value_set_int (value, nav->priv->direction); + break; + } +} + +static void +ev_navigation_action_class_init (EvNavigationActionClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + GtkActionClass *action_class = GTK_ACTION_CLASS (class); + + object_class->finalize = ev_navigation_action_finalize; + object_class->set_property = ev_navigation_action_set_property; + object_class->get_property = ev_navigation_action_get_property; + + parent_class = g_type_class_peek_parent (class); + + action_class->toolbar_item_type = GTK_TYPE_MENU_TOOL_BUTTON; + action_class->connect_proxy = connect_proxy; + + g_object_class_install_property (object_class, + PROP_ARROW_TOOLTIP, + g_param_spec_string ("arrow-tooltip", + "Arrow Tooltip", + "Arrow Tooltip", + NULL, + G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, + PROP_DIRECTION, + g_param_spec_int ("direction", + "Direction", + "Direction", + 0, + G_MAXINT, + 0, + G_PARAM_READWRITE)); + + g_type_class_add_private (object_class, sizeof (EvNavigationActionPrivate)); +} diff --git a/shell/ev-navigation-action.h b/shell/ev-navigation-action.h new file mode 100644 index 00000000..8bb7943e --- /dev/null +++ b/shell/ev-navigation-action.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2003, 2004 Marco Pesenti Gritti + * Copyright (C) 2003, 2004 Christian Persch + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + */ + +#ifndef EV_NAVIGATION_ACTION_H +#define EV_NAVIGATION_ACTION_H + +#include + +G_BEGIN_DECLS + +#define EV_TYPE_NAVIGATION_ACTION (ev_navigation_action_get_type ()) +#define EV_NAVIGATION_ACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EV_TYPE_NAVIGATION_ACTION, EvNavigationAction)) +#define EV_NAVIGATION_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EV_TYPE_NAVIGATION_ACTION, EvNavigationActionClass)) +#define EV_IS_NAVIGATION_ACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EV_TYPE_NAVIGATION_ACTION)) +#define EV_IS_NAVIGATION_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), EV_TYPE_NAVIGATION_ACTION)) +#define EV_NAVIGATION_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), EV_TYPE_NAVIGATION_ACTION, EvNavigationActionClass)) + +typedef struct _EvNavigationAction EvNavigationAction; +typedef struct _EvNavigationActionPrivate EvNavigationActionPrivate; +typedef struct _EvNavigationActionClass EvNavigationActionClass; + +typedef enum +{ + EV_NAVIGATION_DIRECTION_BACK, + EV_NAVIGATION_DIRECTION_FORWARD +} EvNavigationDirection; + +struct _EvNavigationAction +{ + GtkAction parent; + + /*< private >*/ + EvNavigationActionPrivate *priv; +}; + +struct _EvNavigationActionClass +{ + GtkActionClass parent_class; +}; + +GType ev_navigation_action_get_type (void); + +G_END_DECLS + +#endif diff --git a/shell/ev-page-action.c b/shell/ev-page-action.c new file mode 100644 index 00000000..a13d61e2 --- /dev/null +++ b/shell/ev-page-action.c @@ -0,0 +1,263 @@ +/* + * Copyright (C) 2003, 2004 Marco Pesenti Gritti + * Copyright (C) 2003, 2004 Christian Persch + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + */ + +#include "config.h" + +#include "ev-page-action.h" +#include "ev-window.h" + +#include +#include +#include +#include +#include + +struct _EvPageActionPrivate +{ + int current_page; + int total_pages; +}; + +enum +{ + PROP_0, + PROP_CURRENT_PAGE, + PROP_TOTAL_PAGES +}; + +static void ev_page_action_init (EvPageAction *action); +static void ev_page_action_class_init (EvPageActionClass *class); + +enum +{ + GOTO_PAGE_SIGNAL, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + +static GObjectClass *parent_class = NULL; + +G_DEFINE_TYPE (EvPageAction, ev_page_action, GTK_TYPE_ACTION) + +#define EV_PAGE_ACTION_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_PAGE_ACTION, EvPageActionPrivate)) + +static void +update_label (GtkAction *action, gpointer dummy, GtkWidget *proxy) +{ + EvPageAction *page = EV_PAGE_ACTION (action); + char *text; + GtkWidget *label; + + label = GTK_WIDGET (g_object_get_data (G_OBJECT (proxy), "label")); + + text = g_strdup_printf (_("of %d"), page->priv->total_pages); + gtk_label_set_text (GTK_LABEL (label), text); +} + +static void +update_spin (GtkAction *action, gpointer dummy, GtkWidget *proxy) +{ + EvPageAction *page = EV_PAGE_ACTION (action); + GtkWidget *spin; + int value; + + spin = GTK_WIDGET (g_object_get_data (G_OBJECT (proxy), "spin")); + + value = gtk_spin_button_get_value (GTK_SPIN_BUTTON (spin)); + + if (value != page->priv->current_page) + { + gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), + page->priv->current_page); + } +} + +static void +value_changed_cb (GtkWidget *spin, GtkAction *action) +{ + int value; + + value = gtk_spin_button_get_value (GTK_SPIN_BUTTON (spin)); + + g_signal_emit (action, signals[GOTO_PAGE_SIGNAL], 0, value); +} + +static GtkWidget * +create_tool_item (GtkAction *action) +{ + GtkWidget *hbox, *spin, *item, *label; + + hbox = gtk_hbox_new (FALSE, 6); + gtk_container_set_border_width (GTK_CONTAINER (hbox), 6); + gtk_widget_show (hbox); + + item = GTK_WIDGET (gtk_tool_item_new ()); + gtk_widget_show (item); + + spin = gtk_spin_button_new_with_range (1, 9999, 1); + gtk_spin_button_set_digits (GTK_SPIN_BUTTON (spin), 0); + g_object_set_data (G_OBJECT (item), "spin", spin); + gtk_widget_show (spin); + + g_signal_connect (spin, "value_changed", + G_CALLBACK (value_changed_cb), + action); + + label = gtk_label_new (""); + g_object_set_data (G_OBJECT (item), "label", label); + update_label (action, NULL, item); + gtk_widget_show (label); + + gtk_box_pack_start (GTK_BOX (hbox), spin, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + gtk_container_add (GTK_CONTAINER (item), hbox); + + return item; +} + +static void +connect_proxy (GtkAction *action, GtkWidget *proxy) +{ + if (GTK_IS_TOOL_ITEM (proxy)) + { + g_signal_connect_object (action, "notify::total-pages", + G_CALLBACK (update_label), + proxy, 0); + g_signal_connect_object (action, "notify::current-page", + G_CALLBACK (update_spin), + proxy, 0); + } + + GTK_ACTION_CLASS (parent_class)->connect_proxy (action, proxy); +} + +static void +ev_page_action_init (EvPageAction *action) +{ + action->priv = EV_PAGE_ACTION_GET_PRIVATE (action); +} + +static void +ev_page_action_finalize (GObject *object) +{ + parent_class->finalize (object); +} + +static void +ev_page_action_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + EvPageAction *page = EV_PAGE_ACTION (object); + + switch (prop_id) + { + case PROP_CURRENT_PAGE: + page->priv->current_page = g_value_get_int (value); + break; + case PROP_TOTAL_PAGES: + page->priv->total_pages = g_value_get_int (value); + break; + } +} + +static void +ev_page_action_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + EvPageAction *page = EV_PAGE_ACTION (object); + + switch (prop_id) + { + case PROP_CURRENT_PAGE: + g_value_set_int (value, page->priv->current_page); + break; + case PROP_TOTAL_PAGES: + g_value_set_int (value, page->priv->total_pages); + break; + } +} + +void +ev_page_action_set_current_page (EvPageAction *page, int current_page) +{ + g_object_set (page, "current-page", current_page, NULL); +} + +void +ev_page_action_set_total_pages (EvPageAction *page, int total_pages) +{ + g_object_set (page, "total-pages", total_pages, NULL); +} + +static void +ev_page_action_class_init (EvPageActionClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + GtkActionClass *action_class = GTK_ACTION_CLASS (class); + + object_class->finalize = ev_page_action_finalize; + object_class->set_property = ev_page_action_set_property; + object_class->get_property = ev_page_action_get_property; + + parent_class = g_type_class_peek_parent (class); + + action_class->toolbar_item_type = GTK_TYPE_TOOL_ITEM; + action_class->create_tool_item = create_tool_item; + action_class->connect_proxy = connect_proxy; + + signals[GOTO_PAGE_SIGNAL] = + g_signal_new ("goto_page", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (EvPageActionClass, goto_page), + NULL, NULL, + g_cclosure_marshal_VOID__INT, + G_TYPE_NONE, + 1, + G_TYPE_INT); + + g_object_class_install_property (object_class, + PROP_CURRENT_PAGE, + g_param_spec_int ("current-page", + "Current Page", + "The number of current page", + 0, + G_MAXINT, + 0, + G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, + PROP_TOTAL_PAGES, + g_param_spec_int ("total-pages", + "Total Pages", + "The total number of pages", + 0, + G_MAXINT, + 0, + G_PARAM_READWRITE)); + + g_type_class_add_private (object_class, sizeof (EvPageActionPrivate)); +} diff --git a/shell/ev-page-action.h b/shell/ev-page-action.h new file mode 100644 index 00000000..1695cb05 --- /dev/null +++ b/shell/ev-page-action.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2003, 2004 Marco Pesenti Gritti + * Copyright (C) 2003, 2004 Christian Persch + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + */ + +#ifndef EV_PAGE_ACTION_H +#define EV_PAGE_ACTION_H + +#include + +G_BEGIN_DECLS + +#define EV_TYPE_PAGE_ACTION (ev_page_action_get_type ()) +#define EV_PAGE_ACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EV_TYPE_PAGE_ACTION, EvPageAction)) +#define EV_PAGE_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EV_TYPE_PAGE_ACTION, EvPageActionClass)) +#define EV_IS_PAGE_ACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EV_TYPE_PAGE_ACTION)) +#define EV_IS_PAGE_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), EV_TYPE_PAGE_ACTION)) +#define EV_PAGE_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), EV_TYPE_PAGE_ACTION, EvPageActionClass)) + +typedef struct _EvPageAction EvPageAction; +typedef struct _EvPageActionPrivate EvPageActionPrivate; +typedef struct _EvPageActionClass EvPageActionClass; + +struct _EvPageAction +{ + GtkAction parent; + + /*< private >*/ + EvPageActionPrivate *priv; +}; + +struct _EvPageActionClass +{ + GtkActionClass parent_class; + + void (* goto_page) (EvPageAction *page_action, + int page_number); +}; + +GType ev_page_action_get_type (void); +void ev_page_action_set_total_pages (EvPageAction *page_action, + int total_pages); +void ev_page_action_set_current_page (EvPageAction *page_action, + int current_page); + +G_END_DECLS + +#endif diff --git a/shell/ev-view.c b/shell/ev-view.c index b9dda6ad..1fdf5d5f 100644 --- a/shell/ev-view.c +++ b/shell/ev-view.c @@ -455,40 +455,41 @@ add_scroll_binding (GtkBindingSet *binding_set, static void ev_view_scroll_view (EvView *view, - GtkScrollType scroll, - gboolean horizontal) + GtkScrollType scroll, + gboolean horizontal) { - GtkAdjustment *adjustment; - double value; - - if (horizontal) { - adjustment = view->hadjustment; + if (scroll == GTK_SCROLL_PAGE_BACKWARD) { + ev_view_set_page (view, ev_view_get_page (view) - 1); + } else if (scroll == GTK_SCROLL_PAGE_FORWARD) { + ev_view_set_page (view, ev_view_get_page (view) + 1); } else { - adjustment = view->vadjustment; - } + GtkAdjustment *adjustment; + double value; - value = adjustment->value; - - switch (scroll) { - case GTK_SCROLL_STEP_BACKWARD: - value -= adjustment->step_increment; - break; - case GTK_SCROLL_STEP_FORWARD: - value += adjustment->step_increment; - break; - case GTK_SCROLL_PAGE_BACKWARD: - value -= adjustment->page_increment; - break; - case GTK_SCROLL_PAGE_FORWARD: - value += adjustment->page_increment; - break; - default: - break; - } + if (horizontal) { + adjustment = view->hadjustment; + } else { + adjustment = view->vadjustment; + } - value = CLAMP (value, adjustment->lower, adjustment->upper - adjustment->page_size); + value = adjustment->value; + + switch (scroll) { + case GTK_SCROLL_STEP_BACKWARD: + value -= adjustment->step_increment; + break; + case GTK_SCROLL_STEP_FORWARD: + value += adjustment->step_increment; + break; + default: + break; + } - gtk_adjustment_set_value (adjustment, value); + value = CLAMP (value, adjustment->lower, + adjustment->upper - adjustment->page_size); + + gtk_adjustment_set_value (adjustment, value); + } } static void diff --git a/shell/ev-window.c b/shell/ev-window.c index a1e86548..1128214b 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -29,6 +29,8 @@ #endif #include "ev-window.h" +#include "ev-navigation-action.h" +#include "ev-page-action.h" #include "ev-sidebar.h" #include "ev-sidebar-bookmarks.h" #include "ev-sidebar-thumbnails.h" @@ -73,6 +75,7 @@ struct _EvWindowPrivate { guint help_message_cid; GtkWidget *exit_fullscreen_popup; char *uri; + GtkAction *page_action; EvDocument *document; @@ -270,6 +273,17 @@ update_window_title (EvDocument *document, GParamSpec *pspec, EvWindow *ev_windo g_free (title); } +static void +update_total_pages (EvWindow *ev_window) +{ + EvPageAction *page_action; + int pages; + + pages = ev_document_get_n_pages (ev_window->priv->document); + page_action = EV_PAGE_ACTION (ev_window->priv->page_action); + ev_page_action_set_total_pages (page_action, pages); +} + void ev_window_open (EvWindow *ev_window, const char *uri) { @@ -308,8 +322,8 @@ ev_window_open (EvWindow *ev_window, const char *uri) ev_sidebar_set_document (EV_SIDEBAR (ev_window->priv->sidebar), document); + update_total_pages (ev_window); update_action_sensitivity (ev_window); - } else { g_assert (error != NULL); g_object_unref (document); @@ -922,10 +936,22 @@ disconnect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action, } } +static void +update_current_page (EvWindow *ev_window) +{ + EvPageAction *page_action; + int page; + + page = ev_view_get_page (EV_VIEW (ev_window->priv->view)); + page_action = EV_PAGE_ACTION (ev_window->priv->page_action); + ev_page_action_set_current_page (page_action, page); +} + static void view_page_changed_cb (EvView *view, EvWindow *ev_window) { + update_current_page (ev_window); update_action_sensitivity (ev_window); } @@ -1166,6 +1192,53 @@ static GtkToggleActionEntry toggle_entries[] = { G_CALLBACK (ev_window_cmd_view_fullscreen) }, }; +static void +goto_page_cb (GtkAction *action, int page_number, EvWindow *ev_window) +{ + + ev_view_set_page (EV_VIEW (ev_window->priv->view), page_number); +} + +static void +register_custom_actions (EvWindow *window, GtkActionGroup *group) +{ + GtkAction *action; + + action = g_object_new (EV_TYPE_NAVIGATION_ACTION, + "name", "NavigationBack", + "label", _("Back"), + "stock_id", GTK_STOCK_GO_BACK, + "tooltip", _("Go back"), + "arrow-tooltip", _("Back history"), + "direction", EV_NAVIGATION_DIRECTION_BACK, + "is_important", TRUE, + NULL); + gtk_action_group_add_action (group, action); + g_object_unref (action); + + action = g_object_new (EV_TYPE_NAVIGATION_ACTION, + "name", "NavigationForward", + "label", _("Forward"), + "stock_id", GTK_STOCK_GO_FORWARD, + "tooltip", _("Go forward"), + "arrow-tooltip", _("Forward history"), + "direction", EV_NAVIGATION_DIRECTION_FORWARD, + NULL); + gtk_action_group_add_action (group, action); + g_object_unref (action); + + action = g_object_new (EV_TYPE_PAGE_ACTION, + "name", "PageSelector", + "label", _("Page"), + "tooltip", _("Select Page"), + NULL); + g_signal_connect (action, "goto_page", + G_CALLBACK (goto_page_cb), window); + window->priv->page_action = action; + gtk_action_group_add_action (group, action); + g_object_unref (action); +} + static void ev_window_init (EvWindow *ev_window) { @@ -1194,6 +1267,8 @@ ev_window_init (EvWindow *ev_window) G_N_ELEMENTS (toggle_entries), ev_window); + register_custom_actions (ev_window, action_group); + ev_window->priv->ui_manager = gtk_ui_manager_new (); gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager, action_group, 0); -- 2.43.5