+Tue Dec 21 23:57:37 2004 Owen Taylor <otaylor@redhat.com>
+
+ * data/evince-ui.xml: Add a few more toolbar items.
+
+ * shell/ev-window.c: Hook up page navigation toolbar
+ items.
+
+ * shell/ev-view.[ch]: add ev_view_set/get_page and
+ a page-changed signal.
+
+ * backend/ev-document.{h,cc} pdf/xpdf/pdf-document.cc::
+ Add ev_document_get_page().
+
+ * shell/ev-window.c: Sensitize/desensitize navigation
+ actions.
+
2004-12-21 Havoc Pennington <hp@redhat.com>
* backend/ev-backend-marshal.c,
iface->set_page (document, page);
}
+int
+ev_document_get_page (EvDocument *document)
+{
+ EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
+ return iface->get_page (document);
+}
+
void
ev_document_set_target (EvDocument *document,
GdkDrawable *target)
int (* get_n_pages) (EvDocument *document);
void (* set_page) (EvDocument *document,
int page);
+ int (* get_page) (EvDocument *document);
void (* set_target) (EvDocument *document,
GdkDrawable *target);
void (* set_scale) (EvDocument *document,
int ev_document_get_n_pages (EvDocument *document);
void ev_document_set_page (EvDocument *document,
int page);
+int ev_document_get_page (EvDocument *document);
void ev_document_set_target (EvDocument *document,
GdkDrawable *target);
void ev_document_set_scale (EvDocument *document,
<toolbar name="ToolBar">
<toolitem action="FileOpen"/>
+ <separator/>
+ <toolitem action="GoFirstPage"/>
+ <toolitem action="GoPreviousPage"/>
+ <toolitem action="GoNextPage"/>
+ <toolitem action="GoLastPage"/>
</toolbar>
</ui>
{
PdfDocument *pdf_document = PDF_DOCUMENT (document);
+ page = CLAMP (page, 1, ev_document_get_n_pages (document));
+
if (page != pdf_document->page) {
pdf_document->page = page;
pdf_document->page_valid = FALSE;
}
+static int
+pdf_document_get_page (EvDocument *document)
+{
+ PdfDocument *pdf_document = PDF_DOCUMENT (document);
+
+ return pdf_document->page;
+}
+
static void
redraw_callback (void *data)
{
iface->load = pdf_document_load;
iface->get_n_pages = pdf_document_get_n_pages;
iface->set_page = pdf_document_set_page;
+ iface->get_page = pdf_document_get_page;
iface->set_scale = pdf_document_set_scale;
iface->set_target = pdf_document_set_target;
iface->set_page_offset = pdf_document_set_page_offset;
+VOID:NONE
VOID:OBJECT,OBJECT
void (*set_scroll_adjustments) (EvView *view,
GtkAdjustment *hadjustment,
GtkAdjustment *vadjustment);
+
+ /* Should this be notify::page? */
+ void (*page_changed) (EvView *view);
};
+static guint page_changed_signal = 0;
+
static void ev_view_set_scroll_adjustments (EvView *view,
GtkAdjustment *hadjustment,
GtkAdjustment *vadjustment);
G_TYPE_NONE, 2,
GTK_TYPE_ADJUSTMENT,
GTK_TYPE_ADJUSTMENT);
+ page_changed_signal = g_signal_new ("page-changed",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (EvViewClass, page_changed),
+ NULL, NULL,
+ ev_marshal_VOID__NONE,
+ G_TYPE_NONE, 0);
}
static void
g_return_if_fail (EV_IS_VIEW (view));
if (document != view->document) {
+ int old_page = ev_view_get_page (view);
+
if (view->document)
g_object_unref (view->document);
ev_document_set_target (view->document, view->bin_window);
gtk_widget_queue_resize (GTK_WIDGET (view));
+
+ if (old_page != ev_view_get_page (view))
+ g_signal_emit (view, page_changed_signal, 0);
+ }
+}
+
+void
+ev_view_set_page (EvView *view,
+ int page)
+{
+ if (view->document) {
+ int old_page = ev_document_get_page (view->document);
+ if (old_page != page)
+ ev_document_set_page (view->document, page);
+ if (old_page != ev_document_get_page (view->document)) {
+ g_signal_emit (view, page_changed_signal, 0);
+ gtk_widget_queue_draw (GTK_WIDGET (view));
+ }
}
}
+
+int
+ev_view_get_page (EvView *view)
+{
+ if (view->document)
+ return ev_document_get_page (view->document);
+ else
+ return 1;
+}
GType ev_view_get_type (void) G_GNUC_CONST;
GtkWidget* ev_view_new (void);
-void ev_view_set_document (EvView *view,
- EvDocument *document);
+void ev_view_set_document (EvView *view,
+ EvDocument *document);
+void ev_view_set_page (EvView *view,
+ int page);
+int ev_view_get_page (EvView *view);
G_END_DECLS
GtkWidget *find_bar;
GtkWidget *bonobo_widget;
GtkWidget *view;
+ GtkActionGroup *action_group;
GtkUIManager *ui_manager;
GtkWidget *statusbar;
guint help_message_cid;
}
#endif
+static void
+set_action_sensitive (EvWindow *ev_window,
+ const char *name,
+ gboolean sensitive)
+{
+ GtkAction *action = gtk_action_group_get_action (ev_window->priv->action_group,
+ name);
+ gtk_action_set_sensitive (action, sensitive);
+}
+
+static void
+update_action_sensitivity (EvWindow *ev_window)
+{
+ int n_pages;
+ int page;
+
+ if (ev_window->priv->document)
+ n_pages = ev_document_get_n_pages (ev_window->priv->document);
+ else
+ n_pages = 1;
+
+ page = ev_view_get_page (EV_VIEW (ev_window->priv->view));
+
+ set_action_sensitive (ev_window, "GoFirstPage", page > 1);
+ set_action_sensitive (ev_window, "GoPreviousPage", page > 1);
+ set_action_sensitive (ev_window, "GoNextPage", page < n_pages);
+ set_action_sensitive (ev_window, "GoLastPage", page < n_pages);
+}
+
gboolean
ev_window_is_empty (const EvWindow *ev_window)
{
ev_view_set_document (EV_VIEW (ev_window->priv->view),
document);
+
+ update_action_sensitivity (ev_window);
} else {
GtkWidget *dialog;
{
g_return_if_fail (EV_IS_WINDOW (ev_window));
- /* FIXME */
+ ev_view_set_page (EV_VIEW (ev_window->priv->view),
+ ev_view_get_page (EV_VIEW (ev_window->priv->view)) - 1);
}
static void
{
g_return_if_fail (EV_IS_WINDOW (ev_window));
- /* FIXME */
+ ev_view_set_page (EV_VIEW (ev_window->priv->view),
+ ev_view_get_page (EV_VIEW (ev_window->priv->view)) + 1);
}
static void
{
g_return_if_fail (EV_IS_WINDOW (ev_window));
- /* FIXME */
+ ev_view_set_page (EV_VIEW (ev_window->priv->view), 1);
}
static void
{
g_return_if_fail (EV_IS_WINDOW (ev_window));
- /* FIXME */
+ ev_view_set_page (EV_VIEW (ev_window->priv->view), G_MAXINT);
}
static void
}
}
+static void
+view_page_changed_cb (EvView *view,
+ EvWindow *ev_window)
+{
+ update_action_sensitivity (ev_window);
+}
+
static void
find_bar_previous_cb (EggFindBar *find_bar,
EvWindow *ev_window)
priv->ui_manager = NULL;
}
+ if (priv->action_group) {
+ g_object_unref (priv->action_group);
+ priv->action_group = NULL;
+ }
+
G_OBJECT_CLASS (parent_class)->dispose (object);
}
ev_window->priv->main_box = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (ev_window), ev_window->priv->main_box);
gtk_widget_show (ev_window->priv->main_box);
-
+
action_group = gtk_action_group_new ("MenuActions");
+ ev_window->priv->action_group = action_group;
gtk_action_group_set_translation_domain (action_group, NULL);
gtk_action_group_add_actions (action_group, entries,
G_N_ELEMENTS (entries), ev_window);
gtk_widget_show (ev_window->priv->view);
gtk_container_add (GTK_CONTAINER (scrolled_window),
ev_window->priv->view);
+ g_signal_connect (ev_window->priv->view,
+ "page-changed",
+ G_CALLBACK (view_page_changed_cb),
+ ev_window);
ev_window->priv->statusbar = gtk_statusbar_new ();
gtk_widget_show (ev_window->priv->statusbar);
"notify::visible",
G_CALLBACK (find_bar_search_changed_cb),
ev_window);
+
+ update_action_sensitivity (ev_window);
}