Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/libmisc
diff options
context:
space:
mode:
authorCarlos Garcia Campos <carlosgc@gnome.org>2009-04-08 13:10:00 (GMT)
committer Carlos Garcia Campos <carlosgc@src.gnome.org>2009-04-08 13:10:00 (GMT)
commit5adc9f2e1a99e29b8a761388e17c08a6e4d79d5d (patch)
tree7f517616d8a21ef5184b7378915e1813c003b35a /libmisc
parenta281d3cc1f64de07b4b8336c580ad4f5fcb861ed (diff)
Move EvPageAction and EvStockIcons from shell to a new internal library
2009-04-08 Carlos Garcia Campos <carlosgc@gnome.org> * configure.ac: * Makefile.am: * po/POTFILES.in: * shell/Makefile.am: * shell/ev-page-action-widget.[ch]: * shell/ev-page-action.[ch]: * shell/ev-stock-icons.[ch]: * shell/ev-application.c: * shell/main.c: * libmisc/Makefile.am: * libmisc/ev-page-action-widget.[ch]: * libmisc/ev-page-action.[ch]: * libmisc/ev-stock-icons.[ch]: Move EvPageAction and EvStockIcons from shell to a new internal library (libevmisc) that will be used by the evince previewer too. svn path=/trunk/; revision=3577
Diffstat (limited to 'libmisc')
-rw-r--r--libmisc/Makefile.am15
-rw-r--r--libmisc/ev-page-action-widget.c304
-rw-r--r--libmisc/ev-page-action-widget.h58
-rw-r--r--libmisc/ev-page-action.c416
-rw-r--r--libmisc/ev-page-action.h66
-rw-r--r--libmisc/ev-stock-icons.c129
-rw-r--r--libmisc/ev-stock-icons.h49
7 files changed, 1037 insertions, 0 deletions
diff --git a/libmisc/Makefile.am b/libmisc/Makefile.am
new file mode 100644
index 0000000..7f6ad9b
--- /dev/null
+++ b/libmisc/Makefile.am
@@ -0,0 +1,15 @@
+noinst_LTLIBRARIES = libevmisc.la
+
+libevmisc_la_SOURCES = \
+ ev-page-action.c \
+ ev-page-action.h \
+ ev-page-action-widget.c \
+ ev-page-action-widget.h \
+ ev-stock-icons.c \
+ ev-stock-icons.h
+
+libevmisc_la_CFLAGS = \
+ -DDATADIR=\"$(pkgdatadir)\" \
+ $(SHELL_CORE_CFLAGS) \
+ $(WARNING_CFLAGS) \
+ $(DISABLE_DEPRECATED) \ No newline at end of file
diff --git a/libmisc/ev-page-action-widget.c b/libmisc/ev-page-action-widget.c
new file mode 100644
index 0000000..28b6759
--- /dev/null
+++ b/libmisc/ev-page-action-widget.c
@@ -0,0 +1,304 @@
+/*
+ * 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.
+ *
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#include <evince-document.h>
+#include "ev-page-action.h"
+#include "ev-page-action-widget.h"
+
+/* Widget we pass back */
+static void ev_page_action_widget_init (EvPageActionWidget *action_widget);
+static void ev_page_action_widget_class_init (EvPageActionWidgetClass *action_widget);
+
+enum
+{
+ WIDGET_ACTIVATE_LINK,
+ WIDGET_N_SIGNALS
+};
+
+static guint widget_signals[WIDGET_N_SIGNALS] = {0, };
+
+G_DEFINE_TYPE (EvPageActionWidget, ev_page_action_widget, GTK_TYPE_TOOL_ITEM)
+
+static void
+ev_page_action_widget_init (EvPageActionWidget *action_widget)
+{
+ return;
+}
+
+void
+ev_page_action_widget_set_page_cache (EvPageActionWidget *action_widget,
+ EvPageCache *page_cache)
+{
+ if (action_widget->page_cache != NULL) {
+ g_object_remove_weak_pointer (G_OBJECT (action_widget->page_cache),
+ (gpointer)&action_widget->page_cache);
+ action_widget->page_cache = NULL;
+ }
+
+ if (page_cache != NULL) {
+ action_widget->page_cache = page_cache;
+ g_object_add_weak_pointer (G_OBJECT (page_cache),
+ (gpointer)&action_widget->page_cache);
+ }
+}
+
+static void
+ev_page_action_widget_finalize (GObject *object)
+{
+ EvPageActionWidget *action_widget = EV_PAGE_ACTION_WIDGET (object);
+
+ ev_page_action_widget_set_page_cache (action_widget, NULL);
+
+ G_OBJECT_CLASS (ev_page_action_widget_parent_class)->finalize (object);
+}
+
+static void
+ev_page_action_widget_class_init (EvPageActionWidgetClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ object_class->finalize = ev_page_action_widget_finalize;
+
+ widget_signals[WIDGET_ACTIVATE_LINK] = g_signal_new ("activate_link",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (EvPageActionClass, activate_link),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE, 1,
+ G_TYPE_OBJECT);
+
+}
+
+static gboolean
+match_selected_cb (GtkEntryCompletion *completion,
+ GtkTreeModel *filter_model,
+ GtkTreeIter *filter_iter,
+ EvPageActionWidget *proxy)
+{
+ EvLink *link;
+ GtkTreeIter *iter;
+
+ gtk_tree_model_get (filter_model, filter_iter,
+ 0, &iter,
+ -1);
+ gtk_tree_model_get (proxy->model, iter,
+ EV_DOCUMENT_LINKS_COLUMN_LINK, &link,
+ -1);
+
+ g_signal_emit (proxy, widget_signals[WIDGET_ACTIVATE_LINK], 0, link);
+
+ if (link)
+ g_object_unref (link);
+
+ gtk_tree_iter_free (iter);
+
+ return TRUE;
+}
+
+
+static void
+display_completion_text (GtkCellLayout *cell_layout,
+ GtkCellRenderer *renderer,
+ GtkTreeModel *filter_model,
+ GtkTreeIter *filter_iter,
+ EvPageActionWidget *proxy)
+{
+ EvLink *link;
+ GtkTreeIter *iter;
+
+ gtk_tree_model_get (filter_model, filter_iter,
+ 0, &iter,
+ -1);
+ gtk_tree_model_get (proxy->model, iter,
+ EV_DOCUMENT_LINKS_COLUMN_LINK, &link,
+ -1);
+
+ g_object_set (renderer, "text", ev_link_get_title (link), NULL);
+
+ if (link)
+ g_object_unref (link);
+
+ gtk_tree_iter_free (iter);
+}
+
+static gboolean
+match_completion (GtkEntryCompletion *completion,
+ const gchar *key,
+ GtkTreeIter *filter_iter,
+ EvPageActionWidget *proxy)
+{
+ EvLink *link;
+ GtkTreeIter *iter;
+ const gchar *text = NULL;
+
+ gtk_tree_model_get (gtk_entry_completion_get_model (completion),
+ filter_iter,
+ 0, &iter,
+ -1);
+ gtk_tree_model_get (proxy->model, iter,
+ EV_DOCUMENT_LINKS_COLUMN_LINK, &link,
+ -1);
+
+
+ if (link) {
+ text = ev_link_get_title (link);
+ g_object_unref (link);
+ }
+
+ gtk_tree_iter_free (iter);
+
+ if (text && key) {
+ gchar *normalized_text;
+ gchar *normalized_key;
+ gchar *case_normalized_text;
+ gchar *case_normalized_key;
+ gboolean retval = FALSE;
+
+ normalized_text = g_utf8_normalize (text, -1, G_NORMALIZE_ALL);
+ normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL);
+ case_normalized_text = g_utf8_casefold (normalized_text, -1);
+ case_normalized_key = g_utf8_casefold (normalized_key, -1);
+
+ if (strstr (case_normalized_text, case_normalized_key))
+ retval = TRUE;
+
+ g_free (normalized_text);
+ g_free (normalized_key);
+ g_free (case_normalized_text);
+ g_free (case_normalized_key);
+
+ return retval;
+ }
+
+ return FALSE;
+}
+
+/* user data to set on the widget. */
+#define EPA_FILTER_MODEL_DATA "epa-filter-model"
+
+static gboolean
+build_new_tree_cb (GtkTreeModel *model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ gpointer data)
+{
+ GtkTreeModel *filter_model = GTK_TREE_MODEL (data);
+ EvLink *link;
+ EvLinkAction *action;
+ EvLinkActionType type;
+
+ gtk_tree_model_get (model, iter,
+ EV_DOCUMENT_LINKS_COLUMN_LINK, &link,
+ -1);
+
+ if (!link)
+ return FALSE;
+
+ action = ev_link_get_action (link);
+ if (!action) {
+ g_object_unref (link);
+ return FALSE;
+ }
+
+ type = ev_link_action_get_action_type (action);
+
+ if (type == EV_LINK_ACTION_TYPE_GOTO_DEST) {
+ GtkTreeIter filter_iter;
+
+ gtk_list_store_append (GTK_LIST_STORE (filter_model), &filter_iter);
+ gtk_list_store_set (GTK_LIST_STORE (filter_model), &filter_iter,
+ 0, iter,
+ -1);
+ }
+
+ g_object_unref (link);
+
+ return FALSE;
+}
+
+static GtkTreeModel *
+get_filter_model_from_model (GtkTreeModel *model)
+{
+ GtkTreeModel *filter_model;
+
+ filter_model =
+ (GtkTreeModel *) g_object_get_data (G_OBJECT (model), EPA_FILTER_MODEL_DATA);
+ if (filter_model == NULL) {
+ filter_model = (GtkTreeModel *) gtk_list_store_new (1, GTK_TYPE_TREE_ITER);
+
+ gtk_tree_model_foreach (model,
+ build_new_tree_cb,
+ filter_model);
+ g_object_set_data_full (G_OBJECT (model), EPA_FILTER_MODEL_DATA, filter_model, g_object_unref);
+ }
+
+ return filter_model;
+}
+
+
+void
+ev_page_action_widget_update_model (EvPageActionWidget *proxy, GtkTreeModel *model)
+{
+ GtkTreeModel *filter_model;
+
+ if (model != NULL) {
+ /* Magik */
+ GtkEntryCompletion *completion;
+ GtkCellRenderer *renderer;
+
+ proxy->model = model;
+ filter_model = get_filter_model_from_model (model);
+
+ completion = gtk_entry_completion_new ();
+
+ g_object_set (G_OBJECT (completion),
+ "popup-set-width", FALSE,
+ "model", filter_model,
+ NULL);
+
+ g_signal_connect (completion, "match-selected", G_CALLBACK (match_selected_cb), proxy);
+ gtk_entry_completion_set_match_func (completion,
+ (GtkEntryCompletionMatchFunc) match_completion,
+ proxy, NULL);
+
+ /* Set up the layout */
+ renderer = (GtkCellRenderer *)
+ g_object_new (GTK_TYPE_CELL_RENDERER_TEXT,
+ "ellipsize", PANGO_ELLIPSIZE_END,
+ "width_chars", 30,
+ NULL);
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (completion), renderer, TRUE);
+ gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (completion),
+ renderer,
+ (GtkCellLayoutDataFunc) display_completion_text,
+ proxy, NULL);
+ gtk_entry_set_completion (GTK_ENTRY (proxy->entry), completion);
+
+ g_object_unref (completion);
+ g_object_unref (model);
+ }
+}
diff --git a/libmisc/ev-page-action-widget.h b/libmisc/ev-page-action-widget.h
new file mode 100644
index 0000000..5583d6a
--- /dev/null
+++ b/libmisc/ev-page-action-widget.h
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ *
+ */
+
+#include <evince-view.h>
+
+#include <gtk/gtk.h>
+
+#define EV_TYPE_PAGE_ACTION_WIDGET (ev_page_action_widget_get_type ())
+#define EV_PAGE_ACTION_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EV_TYPE_PAGE_ACTION_WIDGET, EvPageActionWidget))
+
+typedef struct _EvPageActionWidget EvPageActionWidget;
+typedef struct _EvPageActionWidgetClass EvPageActionWidgetClass;
+
+struct _EvPageActionWidget
+{
+ GtkToolItem parent;
+
+ GtkWidget *entry;
+ GtkWidget *label;
+ EvPageCache *page_cache;
+ guint signal_id;
+ GtkTreeModel *filter_model;
+ GtkTreeModel *model;
+};
+
+struct _EvPageActionWidgetClass
+{
+ GtkToolItemClass parent_class;
+
+ void (* activate_link) (EvPageActionWidget *page_action,
+ EvLink *link);
+};
+
+GType ev_page_action_widget_get_type (void);
+
+void
+ev_page_action_widget_update_model (EvPageActionWidget *proxy, GtkTreeModel *model);
+
+void
+ev_page_action_widget_set_page_cache (EvPageActionWidget *action_widget,
+ EvPageCache *page_cache);
diff --git a/libmisc/ev-page-action.c b/libmisc/ev-page-action.c
new file mode 100644
index 0000000..f2a1536
--- /dev/null
+++ b/libmisc/ev-page-action.c
@@ -0,0 +1,416 @@
+/*
+ * 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.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include <stdlib.h>
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#include "ev-page-action.h"
+#include "ev-page-action-widget.h"
+
+struct _EvPageActionPrivate
+{
+ EvPageCache *page_cache;
+ GtkTreeModel *model;
+};
+
+
+static void ev_page_action_init (EvPageAction *action);
+static void ev_page_action_class_init (EvPageActionClass *class);
+
+enum
+{
+ ACTIVATE_LINK,
+ N_SIGNALS
+};
+
+static guint signals[N_SIGNALS] = {0, };
+
+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))
+
+enum {
+ PROP_0,
+ PROP_PAGE_CACHE,
+ PROP_MODEL,
+};
+
+static void
+update_pages_label (EvPageActionWidget *proxy,
+ gint page,
+ EvPageCache *page_cache)
+{
+ char *label_text;
+ gint n_pages;
+
+ n_pages = page_cache ? ev_page_cache_get_n_pages (page_cache) : 0;
+ if (page_cache && ev_page_cache_has_nonnumeric_page_labels (page_cache)) {
+ label_text = g_strdup_printf (_("(%d of %d)"), page + 1, n_pages);
+ } else {
+ label_text = g_strdup_printf (_("of %d"), n_pages);
+ }
+ gtk_label_set_text (GTK_LABEL (proxy->label), label_text);
+ g_free (label_text);
+}
+
+static void
+page_changed_cb (EvPageCache *page_cache,
+ gint page,
+ EvPageActionWidget *proxy)
+{
+ g_assert (proxy);
+
+ if (page_cache != NULL && page >= 0) {
+ gchar *page_label;
+
+ gtk_entry_set_width_chars (GTK_ENTRY (proxy->entry),
+ CLAMP (ev_page_cache_get_max_label_chars (page_cache),
+ 6, 12));
+
+ page_label = ev_page_cache_get_page_label (page_cache, page);
+ gtk_entry_set_text (GTK_ENTRY (proxy->entry), page_label);
+ gtk_editable_set_position (GTK_EDITABLE (proxy->entry), -1);
+ g_free (page_label);
+
+ } else {
+ gtk_entry_set_text (GTK_ENTRY (proxy->entry), "");
+ }
+
+ update_pages_label (proxy, page, page_cache);
+}
+
+static void
+activate_cb (GtkWidget *entry, GtkAction *action)
+{
+ EvPageAction *page = EV_PAGE_ACTION (action);
+ EvPageCache *page_cache;
+ const char *text;
+ gchar *page_label;
+
+ EvLinkDest *link_dest;
+ EvLinkAction *link_action;
+ EvLink *link;
+ gchar *link_text;
+
+ text = gtk_entry_get_text (GTK_ENTRY (entry));
+ page_cache = page->priv->page_cache;
+
+
+ link_dest = ev_link_dest_new_page_label (text);
+ link_action = ev_link_action_new_dest (link_dest);
+ link_text = g_strdup_printf ("Page: %s", text);
+ link = ev_link_new (link_text, link_action);
+
+ g_signal_emit (action, signals[ACTIVATE_LINK], 0, link);
+
+ g_object_unref (link);
+ g_free (link_text);
+
+ /* rest the entry to the current page if we were unable to
+ * change it */
+ page_label = ev_page_cache_get_page_label (page_cache,
+ ev_page_cache_get_current_page (page_cache));
+ gtk_entry_set_text (GTK_ENTRY (entry), page_label);
+ gtk_editable_set_position (GTK_EDITABLE (entry), -1);
+ g_free (page_label);
+}
+
+static gboolean page_scroll_cb(GtkWidget *widget, GdkEventScroll *event, EvPageAction* action)
+{
+ gint pageno;
+
+ pageno = ev_page_cache_get_current_page (action->priv->page_cache);
+ if ((event->direction == GDK_SCROLL_DOWN) &&
+ (pageno < ev_page_cache_get_n_pages(action->priv->page_cache) - 1))
+ pageno++;
+ if ((event->direction == GDK_SCROLL_UP) && (pageno > 0))
+ pageno--;
+ ev_page_cache_set_current_page (action->priv->page_cache, pageno);
+
+ return TRUE;
+}
+
+static GtkWidget *
+create_tool_item (GtkAction *action)
+{
+ EvPageActionWidget *proxy;
+ GtkWidget *hbox;
+ AtkObject *obj;
+
+ proxy = g_object_new (ev_page_action_widget_get_type (), NULL);
+ gtk_container_set_border_width (GTK_CONTAINER (proxy), 6);
+ gtk_widget_show (GTK_WIDGET (proxy));
+
+ hbox = gtk_hbox_new (FALSE, 0);
+ gtk_box_set_spacing (GTK_BOX (hbox), 6);
+
+ proxy->entry = gtk_entry_new ();
+ obj = gtk_widget_get_accessible (proxy->entry);
+ atk_object_set_name (obj, "page-label-entry");
+
+ g_signal_connect(proxy->entry, "scroll-event",G_CALLBACK(page_scroll_cb),action);
+ gtk_widget_add_events(GTK_WIDGET(proxy->entry),GDK_BUTTON_MOTION_MASK);
+ gtk_entry_set_width_chars (GTK_ENTRY (proxy->entry), 5);
+ gtk_box_pack_start (GTK_BOX (hbox), proxy->entry, FALSE, FALSE, 0);
+ gtk_widget_show (proxy->entry);
+ g_signal_connect (proxy->entry, "activate",
+ G_CALLBACK (activate_cb),
+ action);
+
+ proxy->label = gtk_label_new (NULL);
+ gtk_box_pack_start (GTK_BOX (hbox), proxy->label, FALSE, FALSE, 0);
+ gtk_widget_show (proxy->label);
+
+ gtk_container_add (GTK_CONTAINER (proxy), hbox);
+ gtk_widget_show (hbox);
+
+ return GTK_WIDGET (proxy);
+}
+
+static void
+update_page_cache (EvPageAction *page, GParamSpec *pspec, EvPageActionWidget *proxy)
+{
+ EvPageCache *page_cache;
+ guint signal_id;
+
+ page_cache = page->priv->page_cache;
+
+ /* clear the old signal */
+ if (proxy->signal_id > 0 && proxy->page_cache)
+ g_signal_handler_disconnect (proxy->page_cache, proxy->signal_id);
+
+ if (page_cache != NULL) {
+ signal_id = g_signal_connect_object (page_cache,
+ "page-changed",
+ G_CALLBACK (page_changed_cb),
+ proxy, 0);
+ /* Set the initial value */
+ page_changed_cb (page_cache,
+ ev_page_cache_get_current_page (page_cache),
+ proxy);
+ } else {
+ /* Or clear the entry */
+ signal_id = 0;
+ page_changed_cb (NULL, 0, proxy);
+ }
+ ev_page_action_widget_set_page_cache (proxy, page_cache);
+ proxy->signal_id = signal_id;
+}
+
+static void
+activate_link_cb (EvPageActionWidget *proxy, EvLink *link, EvPageAction *action)
+{
+ g_signal_emit (action, signals[ACTIVATE_LINK], 0, link);
+}
+
+static void
+update_model (EvPageAction *page, GParamSpec *pspec, EvPageActionWidget *proxy)
+{
+ GtkTreeModel *model;
+
+ g_object_get (G_OBJECT (page),
+ "model", &model,
+ NULL);
+
+ ev_page_action_widget_update_model (proxy, model);
+}
+
+static void
+connect_proxy (GtkAction *action, GtkWidget *proxy)
+{
+ if (GTK_IS_TOOL_ITEM (proxy)) {
+ g_signal_connect_object (action, "notify::page-cache",
+ G_CALLBACK (update_page_cache),
+ proxy, 0);
+ g_signal_connect (proxy, "activate_link",
+ G_CALLBACK (activate_link_cb),
+ action);
+ update_page_cache (EV_PAGE_ACTION (action), NULL,
+ EV_PAGE_ACTION_WIDGET (proxy));
+ g_signal_connect_object (action, "notify::model",
+ G_CALLBACK (update_model),
+ proxy, 0);
+ }
+
+ GTK_ACTION_CLASS (ev_page_action_parent_class)->connect_proxy (action, proxy);
+}
+
+static void
+ev_page_action_dispose (GObject *object)
+{
+ EvPageAction *page = EV_PAGE_ACTION (object);
+
+ if (page->priv->page_cache) {
+ g_object_unref (page->priv->page_cache);
+ page->priv->page_cache = NULL;
+ }
+
+ G_OBJECT_CLASS (ev_page_action_parent_class)->dispose (object);
+}
+
+static void
+ev_page_action_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EvPageAction *page;
+ EvPageCache *page_cache;
+ GtkTreeModel *model;
+
+ page = EV_PAGE_ACTION (object);
+
+ switch (prop_id)
+ {
+ case PROP_PAGE_CACHE:
+ page_cache = page->priv->page_cache;
+ page->priv->page_cache = EV_PAGE_CACHE (g_value_dup_object (value));
+ if (page_cache)
+ g_object_unref (page_cache);
+ break;
+ case PROP_MODEL:
+ model = page->priv->model;
+ page->priv->model = GTK_TREE_MODEL (g_value_dup_object (value));
+ if (model)
+ g_object_unref (model);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+ev_page_action_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EvPageAction *page;
+
+ page = EV_PAGE_ACTION (object);
+
+ switch (prop_id)
+ {
+ case PROP_PAGE_CACHE:
+ g_value_set_object (value, page->priv->page_cache);
+ break;
+ case PROP_MODEL:
+ g_value_set_object (value, page->priv->model);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+void
+ev_page_action_set_document (EvPageAction *page, EvDocument *document)
+{
+ EvPageCache *page_cache = NULL;
+
+ if (document)
+ page_cache = ev_page_cache_get (document);
+
+ g_object_set (page,
+ "page-cache", page_cache,
+ "model", NULL,
+ NULL);
+}
+
+void
+ev_page_action_set_model (EvPageAction *page_action,
+ GtkTreeModel *model)
+{
+ g_object_set (page_action,
+ "model", model,
+ NULL);
+}
+
+void
+ev_page_action_grab_focus (EvPageAction *page_action)
+{
+ GSList *proxies;
+
+ proxies = gtk_action_get_proxies (GTK_ACTION (page_action));
+ for (; proxies != NULL; proxies = proxies->next) {
+ EvPageActionWidget *proxy;
+
+ proxy = EV_PAGE_ACTION_WIDGET (proxies->data);
+
+ if (GTK_WIDGET_MAPPED (GTK_WIDGET (proxy)))
+ gtk_widget_grab_focus (proxy->entry);
+ }
+}
+
+static void
+ev_page_action_init (EvPageAction *page)
+{
+ page->priv = EV_PAGE_ACTION_GET_PRIVATE (page);
+}
+
+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->dispose = ev_page_action_dispose;
+ object_class->set_property = ev_page_action_set_property;
+ object_class->get_property = ev_page_action_get_property;
+
+ action_class->toolbar_item_type = GTK_TYPE_TOOL_ITEM;
+ action_class->create_tool_item = create_tool_item;
+ action_class->connect_proxy = connect_proxy;
+
+ signals[ACTIVATE_LINK] = g_signal_new ("activate_link",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (EvPageActionClass, activate_link),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE, 1,
+ G_TYPE_OBJECT);
+
+ g_object_class_install_property (object_class,
+ PROP_PAGE_CACHE,
+ g_param_spec_object ("page-cache",
+ "Page Cache",
+ "Current page cache",
+ EV_TYPE_PAGE_CACHE,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class,
+ PROP_MODEL,
+ g_param_spec_object ("model",
+ "Model",
+ "Current Model",
+ GTK_TYPE_TREE_MODEL,
+ G_PARAM_READWRITE));
+
+ g_type_class_add_private (object_class, sizeof (EvPageActionPrivate));
+}
diff --git a/libmisc/ev-page-action.h b/libmisc/ev-page-action.h
new file mode 100644
index 0000000..dc13bdd
--- /dev/null
+++ b/libmisc/ev-page-action.h
@@ -0,0 +1,66 @@
+/*
+ * 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.
+ *
+ */
+
+#ifndef EV_PAGE_ACTION_H
+#define EV_PAGE_ACTION_H
+
+#include <gtk/gtk.h>
+
+#include <evince-document.h>
+
+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 (* activate_link) (EvPageAction *page_action,
+ EvLink *link);
+};
+
+GType ev_page_action_get_type (void);
+void ev_page_action_set_document (EvPageAction *page_action,
+ EvDocument *document);
+void ev_page_action_set_model (EvPageAction *page_action,
+ GtkTreeModel *model);
+void ev_page_action_grab_focus (EvPageAction *page_action);
+
+G_END_DECLS
+
+#endif
diff --git a/libmisc/ev-stock-icons.c b/libmisc/ev-stock-icons.c
new file mode 100644
index 0000000..8b121e9
--- /dev/null
+++ b/libmisc/ev-stock-icons.c
@@ -0,0 +1,129 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* Stock icons for Evince
+ *
+ * Copyright (C) 2003 Martin Kretzschmar
+ *
+ * Author:
+ * Martin Kretzschmar <Martin.Kretzschmar@inf.tu-dresden.de>
+ *
+ * Evince 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 of the License, or
+ * (at your option) any later version.
+ *
+ * Evince 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.
+ */
+
+#include <config.h>
+
+#include <gtk/gtk.h>
+#include <gdk/gdk.h>
+
+#include "ev-stock-icons.h"
+
+typedef struct {
+ char *stock_id;
+ char *icon;
+} EvStockIcon;
+
+/* Evince stock icons */
+static const EvStockIcon stock_icons [] = {
+ { EV_STOCK_ZOOM, "zoom" },
+ { EV_STOCK_ZOOM_PAGE, "zoom-fit-page" },
+ { EV_STOCK_ZOOM_WIDTH, "zoom-fit-width" },
+ { EV_STOCK_VIEW_DUAL, "view-page-facing" },
+ { EV_STOCK_VIEW_CONTINUOUS, "view-page-continuous" },
+ { EV_STOCK_ROTATE_LEFT, "object-rotate-left"},
+ { EV_STOCK_ROTATE_RIGHT, "object-rotate-right"},
+ { EV_STOCK_RUN_PRESENTATION, "x-office-presentation"},
+ { EV_STOCK_VISIBLE, "eye"}
+};
+
+static gchar *ev_icons_path;
+
+/**
+ * ev_stock_icons_init:
+ *
+ * Creates a new icon factory, adding the base stock icons to it.
+ */
+void
+ev_stock_icons_init (void)
+{
+ GtkIconFactory *factory;
+ GtkIconSource *source;
+ gint i;
+
+ ev_icons_path = g_build_filename (DATADIR, "icons", NULL);
+
+ factory = gtk_icon_factory_new ();
+ gtk_icon_factory_add_default (factory);
+
+ source = gtk_icon_source_new ();
+
+ for (i = 0; i < G_N_ELEMENTS (stock_icons); i++) {
+ GtkIconSet *set;
+
+ gtk_icon_source_set_icon_name (source, stock_icons [i].icon);
+
+ set = gtk_icon_set_new ();
+ gtk_icon_set_add_source (set, source);
+
+ gtk_icon_factory_add (factory, stock_icons [i].stock_id, set);
+ gtk_icon_set_unref (set);
+ }
+
+ gtk_icon_source_free (source);
+
+ g_object_unref (G_OBJECT (factory));
+
+ ev_stock_icons_add_icons_path ();
+}
+
+void
+ev_stock_icons_shutdown (void)
+{
+ g_free (ev_icons_path);
+}
+
+void
+ev_stock_icons_add_icons_path_for_screen (GdkScreen *screen)
+{
+ GtkIconTheme *icon_theme;
+
+ g_return_if_fail (ev_icons_path != NULL);
+
+ icon_theme = screen ? gtk_icon_theme_get_for_screen (screen) : gtk_icon_theme_get_default ();
+ if (icon_theme) {
+ gchar **path = NULL;
+ gint n_paths;
+ gint i;
+
+ /* GtkIconTheme will then look in Evince custom hicolor dir
+ * for icons as well as the standard search paths
+ */
+ gtk_icon_theme_get_search_path (icon_theme, &path, &n_paths);
+ for (i = n_paths - 1; i >= 0; i--) {
+ if (g_ascii_strcasecmp (ev_icons_path, path[i]) == 0)
+ break;
+ }
+
+ if (i < 0)
+ gtk_icon_theme_append_search_path (icon_theme,
+ ev_icons_path);
+
+ g_strfreev (path);
+ }
+}
+
+void
+ev_stock_icons_add_icons_path (void)
+{
+ ev_stock_icons_add_icons_path_for_screen (gdk_screen_get_default ());
+}
diff --git a/libmisc/ev-stock-icons.h b/libmisc/ev-stock-icons.h
new file mode 100644
index 0000000..793314d
--- /dev/null
+++ b/libmisc/ev-stock-icons.h
@@ -0,0 +1,49 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* Stock icons for Evince
+ *
+ * Copyright (C) 2003 Martin Kretzschmar
+ *
+ * Author:
+ * Martin Kretzschmar <Martin.Kretzschmar@inf.tu-dresden.de>
+ *
+ * Evince 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 of the License, or
+ * (at your option) any later version.
+ *
+ * Evince 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.
+ */
+
+#ifndef __EV_STOCK_ICONS_H__
+#define __EV_STOCK_ICONS_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+/* Evince stock icons */
+#define EV_STOCK_ZOOM "zoom"
+#define EV_STOCK_ZOOM_PAGE "zoom-fit-page"
+#define EV_STOCK_ZOOM_WIDTH "zoom-fit-width"
+#define EV_STOCK_VIEW_DUAL "view-page-facing"
+#define EV_STOCK_VIEW_CONTINUOUS "view-page-continuous"
+#define EV_STOCK_ROTATE_LEFT "object-rotate-left"
+#define EV_STOCK_ROTATE_RIGHT "object-rotate-right"
+#define EV_STOCK_RUN_PRESENTATION "x-office-presentation"
+#define EV_STOCK_VISIBLE "eye"
+
+void ev_stock_icons_init (void);
+void ev_stock_icons_shutdown (void);
+void ev_stock_icons_add_icons_path (void);
+void ev_stock_icons_add_icons_path_for_screen (GdkScreen *screen);
+
+G_END_DECLS
+
+#endif /* __EV_STOCK_ICONS_H__ */