summaryrefslogtreecommitdiff
path: root/cut-n-paste/zoom-control
diff options
context:
space:
mode:
Diffstat (limited to 'cut-n-paste/zoom-control')
-rw-r--r--cut-n-paste/zoom-control/Makefile.am16
-rw-r--r--cut-n-paste/zoom-control/ephy-zoom-action.c336
-rw-r--r--cut-n-paste/zoom-control/ephy-zoom-action.h68
-rw-r--r--cut-n-paste/zoom-control/ephy-zoom-control.c345
-rw-r--r--cut-n-paste/zoom-control/ephy-zoom-control.h63
-rw-r--r--cut-n-paste/zoom-control/ephy-zoom.c68
-rw-r--r--cut-n-paste/zoom-control/ephy-zoom.h81
7 files changed, 977 insertions, 0 deletions
diff --git a/cut-n-paste/zoom-control/Makefile.am b/cut-n-paste/zoom-control/Makefile.am
new file mode 100644
index 00000000..af8bd48e
--- /dev/null
+++ b/cut-n-paste/zoom-control/Makefile.am
@@ -0,0 +1,16 @@
+noinst_LTLIBRARIES = libephyzoom.la
+
+libephyzoom_la_SOURCES = \
+ ephy-zoom-action.h \
+ ephy-zoom-action.c \
+ ephy-zoom-control.c \
+ ephy-zoom-control.h \
+ ephy-zoom.c \
+ ephy-zoom.h
+
+libephyzoom_la_CFLAGS = \
+ $(SHELL_CORE_CFLAGS) \
+ $(WARNING_CFLAGS) \
+ $(DISABLE_DEPRECATED)
+
+-include $(top_srcdir)/git.mk
diff --git a/cut-n-paste/zoom-control/ephy-zoom-action.c b/cut-n-paste/zoom-control/ephy-zoom-action.c
new file mode 100644
index 00000000..b6250c8b
--- /dev/null
+++ b/cut-n-paste/zoom-control/ephy-zoom-action.c
@@ -0,0 +1,336 @@
+/*
+ * Copyright (C) 2003 Marco Pesenti Gritti
+ * Copyright (C) 2003, 2004 Christian Persch
+ *
+ * Modified 2005 by James Bowes for use in evince.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $Id$
+ */
+
+#include "config.h"
+
+#include "ephy-zoom-action.h"
+#include "ephy-zoom-control.h"
+#include "ephy-zoom.h"
+
+#include <glib-object.h>
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#define EPHY_ZOOM_ACTION_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_ZOOM_ACTION, EphyZoomActionPrivate))
+
+struct _EphyZoomActionPrivate
+{
+ float zoom;
+ float min_zoom;
+ float max_zoom;
+};
+
+enum
+{
+ PROP_0,
+ PROP_ZOOM,
+ PROP_MIN_ZOOM,
+ PROP_MAX_ZOOM
+};
+
+
+static void ephy_zoom_action_init (EphyZoomAction *action);
+static void ephy_zoom_action_class_init (EphyZoomActionClass *class);
+
+enum
+{
+ ZOOM_TO_LEVEL_SIGNAL,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+G_DEFINE_TYPE (EphyZoomAction, ephy_zoom_action, GTK_TYPE_ACTION)
+
+static void
+zoom_to_level_cb (EphyZoomControl *control,
+ float zoom,
+ EphyZoomAction *action)
+{
+ g_signal_emit (action, signals[ZOOM_TO_LEVEL_SIGNAL], 0, zoom);
+}
+
+static void
+sync_zoom_cb (GtkAction *action, GParamSpec *pspec, GtkWidget *proxy)
+{
+ EphyZoomAction *zoom_action = EPHY_ZOOM_ACTION (action);
+
+ g_object_set (G_OBJECT (proxy), "zoom", zoom_action->priv->zoom, NULL);
+}
+
+static void
+sync_min_zoom_cb (GtkAction *action, GParamSpec *pspec, GtkWidget *proxy)
+{
+ EphyZoomAction *zoom_action = EPHY_ZOOM_ACTION (action);
+
+ g_object_set (G_OBJECT (proxy), "min-zoom", zoom_action->priv->min_zoom, NULL);
+}
+
+static void
+sync_max_zoom_cb (GtkAction *action, GParamSpec *pspec, GtkWidget *proxy)
+{
+ EphyZoomAction *zoom_action = EPHY_ZOOM_ACTION (action);
+
+ g_object_set (G_OBJECT (proxy), "max-zoom", zoom_action->priv->max_zoom, NULL);
+}
+
+static void
+connect_proxy (GtkAction *action, GtkWidget *proxy)
+{
+ if (EPHY_IS_ZOOM_CONTROL (proxy))
+ {
+ g_signal_connect_object (action, "notify::zoom",
+ G_CALLBACK (sync_zoom_cb), proxy, 0);
+ g_signal_connect_object (action, "notify::min-zoom",
+ G_CALLBACK (sync_min_zoom_cb), proxy, 0);
+ g_signal_connect_object (action, "notify::max-zoom",
+ G_CALLBACK (sync_max_zoom_cb), proxy, 0);
+ g_signal_connect (proxy, "zoom_to_level",
+ G_CALLBACK (zoom_to_level_cb), action);
+ }
+
+ GTK_ACTION_CLASS (ephy_zoom_action_parent_class)->connect_proxy (action, proxy);
+}
+
+static void
+proxy_menu_activate_cb (GtkMenuItem *menu_item, EphyZoomAction *action)
+{
+ gint index;
+ float zoom;
+
+ /* menu item was toggled OFF */
+ if (!gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (menu_item))) return;
+
+ index = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menu_item), "zoom-level"));
+ zoom = zoom_levels[index].level;
+
+ if (zoom != action->priv->zoom)
+ {
+ g_signal_emit (action, signals[ZOOM_TO_LEVEL_SIGNAL], 0, zoom);
+ }
+}
+
+static GtkWidget *
+create_menu_item (GtkAction *action)
+{
+ EphyZoomActionPrivate *p = EPHY_ZOOM_ACTION (action)->priv;
+ GtkWidget *menu, *menu_item;
+ GSList *group = NULL;
+ int i;
+
+ menu = gtk_menu_new ();
+
+ for (i = 0; i < n_zoom_levels; i++)
+ {
+ if (zoom_levels[i].level == EPHY_ZOOM_SEPARATOR)
+ {
+ menu_item = gtk_separator_menu_item_new ();
+ }
+ else
+ {
+ menu_item = gtk_radio_menu_item_new_with_label (group,
+ _(zoom_levels[i].name));
+ group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menu_item));
+
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item),
+ p->zoom == zoom_levels[i].level);
+
+ g_object_set_data (G_OBJECT (menu_item), "zoom-level", GINT_TO_POINTER (i));
+ g_signal_connect_object (G_OBJECT (menu_item), "activate",
+ G_CALLBACK (proxy_menu_activate_cb), action, 0);
+ }
+
+ gtk_widget_show (menu_item);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
+ }
+
+ gtk_widget_show (menu);
+
+ menu_item = GTK_ACTION_CLASS (ephy_zoom_action_parent_class)->create_menu_item (action);
+
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), menu);
+
+ gtk_widget_show (menu_item);
+
+ return menu_item;
+}
+
+static void
+ephy_zoom_action_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EphyZoomAction *action;
+
+ action = EPHY_ZOOM_ACTION (object);
+
+ switch (prop_id)
+ {
+ case PROP_ZOOM:
+ action->priv->zoom = g_value_get_float (value);
+ break;
+ case PROP_MIN_ZOOM:
+ action->priv->min_zoom = g_value_get_float (value);
+ break;
+ case PROP_MAX_ZOOM:
+ action->priv->max_zoom = g_value_get_float (value);
+ break;
+ }
+}
+
+static void
+ephy_zoom_action_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EphyZoomAction *action;
+
+ action = EPHY_ZOOM_ACTION (object);
+
+ switch (prop_id)
+ {
+ case PROP_ZOOM:
+ g_value_set_float (value, action->priv->zoom);
+ break;
+ case PROP_MIN_ZOOM:
+ g_value_set_float (value, action->priv->min_zoom);
+ break;
+ case PROP_MAX_ZOOM:
+ g_value_set_float (value, action->priv->max_zoom);
+ break;
+ }
+}
+
+static void
+ephy_zoom_action_class_init (EphyZoomActionClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+ GtkActionClass *action_class = GTK_ACTION_CLASS (class);
+
+ object_class->set_property = ephy_zoom_action_set_property;
+ object_class->get_property = ephy_zoom_action_get_property;
+
+ action_class->toolbar_item_type = EPHY_TYPE_ZOOM_CONTROL;
+ action_class->connect_proxy = connect_proxy;
+ action_class->create_menu_item = create_menu_item;
+
+ g_object_class_install_property (object_class,
+ PROP_ZOOM,
+ g_param_spec_float ("zoom",
+ "Zoom",
+ "Zoom",
+ ZOOM_MINIMAL,
+ ZOOM_MAXIMAL,
+ 1.0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_MIN_ZOOM,
+ g_param_spec_float ("min-zoom",
+ "MinZoom",
+ "The minimum zoom",
+ ZOOM_MINIMAL,
+ ZOOM_MAXIMAL,
+ ZOOM_MINIMAL,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_MAX_ZOOM,
+ g_param_spec_float ("max-zoom",
+ "MaxZoom",
+ "The maximum zoom",
+ ZOOM_MINIMAL,
+ ZOOM_MAXIMAL,
+ ZOOM_MAXIMAL,
+ G_PARAM_READWRITE));
+
+ signals[ZOOM_TO_LEVEL_SIGNAL] =
+ g_signal_new ("zoom_to_level",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (EphyZoomActionClass, zoom_to_level),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__FLOAT,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_FLOAT);
+
+ g_type_class_add_private (object_class, sizeof (EphyZoomActionPrivate));
+}
+
+static void
+ephy_zoom_action_init (EphyZoomAction *action)
+{
+ action->priv = EPHY_ZOOM_ACTION_GET_PRIVATE (action);
+
+ action->priv->zoom = 1.0;
+}
+
+void
+ephy_zoom_action_set_zoom_level (EphyZoomAction *action, float zoom)
+{
+ g_return_if_fail (EPHY_IS_ZOOM_ACTION (action));
+
+ if (zoom < ZOOM_MINIMAL || zoom > ZOOM_MAXIMAL) return;
+
+ action->priv->zoom = zoom;
+ g_object_notify (G_OBJECT (action), "zoom");
+}
+
+float
+ephy_zoom_action_get_zoom_level (EphyZoomAction *action)
+{
+ g_return_val_if_fail (EPHY_IS_ZOOM_ACTION (action), 1.0);
+
+ return action->priv->zoom;
+}
+
+void
+ephy_zoom_action_set_min_zoom_level (EphyZoomAction *action,
+ float zoom)
+{
+ g_return_if_fail (EPHY_IS_ZOOM_ACTION (action));
+
+ if (zoom < ZOOM_MINIMAL || zoom > ZOOM_MAXIMAL) return;
+
+ action->priv->min_zoom = zoom;
+ if (action->priv->zoom > 0 && action->priv->zoom < zoom)
+ ephy_zoom_action_set_zoom_level (action, zoom);
+
+ g_object_notify (G_OBJECT (action), "min-zoom");
+}
+
+void
+ephy_zoom_action_set_max_zoom_level (EphyZoomAction *action,
+ float zoom)
+{
+ g_return_if_fail (EPHY_IS_ZOOM_ACTION (action));
+
+ if (zoom < ZOOM_MINIMAL || zoom > ZOOM_MAXIMAL) return;
+
+ action->priv->max_zoom = zoom;
+ if (action->priv->zoom > 0 && action->priv->zoom > zoom)
+ ephy_zoom_action_set_zoom_level (action, zoom);
+
+ g_object_notify (G_OBJECT (action), "max-zoom");
+}
diff --git a/cut-n-paste/zoom-control/ephy-zoom-action.h b/cut-n-paste/zoom-control/ephy-zoom-action.h
new file mode 100644
index 00000000..cf9f6feb
--- /dev/null
+++ b/cut-n-paste/zoom-control/ephy-zoom-action.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2003 Marco Pesenti Gritti
+ * Copyright (C) 2003 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $Id$
+ */
+
+#ifndef EPHY_ZOOM_ACTION_H
+#define EPHY_ZOOM_ACTION_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_ZOOM_ACTION (ephy_zoom_action_get_type ())
+#define EPHY_ZOOM_ACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EPHY_TYPE_ZOOM_ACTION, EphyZoomAction))
+#define EPHY_ZOOM_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EPHY_TYPE_ZOOM_ACTION, EphyZoomActionClass))
+#define EPHY_IS_ZOOM_ACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EPHY_TYPE_ZOOM_ACTION))
+#define EPHY_IS_ZOOM_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), EPHY_TYPE_ZOOM_ACTION))
+#define EPHY_ZOOM_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), EPHY_TYPE_ZOOM_ACTION, EphyZoomActionClass))
+
+typedef struct _EphyZoomAction EphyZoomAction;
+typedef struct _EphyZoomActionClass EphyZoomActionClass;
+typedef struct _EphyZoomActionPrivate EphyZoomActionPrivate;
+
+struct _EphyZoomAction
+{
+ GtkAction parent;
+
+ /*< private >*/
+ EphyZoomActionPrivate *priv;
+};
+
+struct _EphyZoomActionClass
+{
+ GtkActionClass parent_class;
+
+ void (* zoom_to_level) (EphyZoomAction *action, float level);
+};
+
+GType ephy_zoom_action_get_type (void) G_GNUC_CONST;
+
+void ephy_zoom_action_set_zoom_level (EphyZoomAction *action,
+ float zoom);
+float ephy_zoom_action_get_zoom_level (EphyZoomAction *action);
+
+void ephy_zoom_action_set_min_zoom_level (EphyZoomAction *action,
+ float zoom);
+void ephy_zoom_action_set_max_zoom_level (EphyZoomAction *action,
+ float zoom);
+
+G_END_DECLS
+
+#endif
diff --git a/cut-n-paste/zoom-control/ephy-zoom-control.c b/cut-n-paste/zoom-control/ephy-zoom-control.c
new file mode 100644
index 00000000..6c86b4a4
--- /dev/null
+++ b/cut-n-paste/zoom-control/ephy-zoom-control.c
@@ -0,0 +1,345 @@
+/*
+ * Copyright (C) 2003, 2004 Christian Persch
+ *
+ * Modified 2005 by James Bowes for use in evince.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $Id$
+ */
+
+#include "config.h"
+
+#include "ephy-zoom-control.h"
+#include "ephy-zoom.h"
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+
+#define EPHY_ZOOM_CONTROL_GET_PRIVATE(object)\
+ (G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_ZOOM_CONTROL, EphyZoomControlPrivate))
+
+struct _EphyZoomControlPrivate
+{
+ GtkComboBox *combo;
+ float zoom;
+ float min_zoom;
+ float max_zoom;
+ guint handler_id;
+};
+
+enum
+{
+ COL_TEXT,
+ COL_IS_SEP
+};
+
+enum
+{
+ PROP_0,
+ PROP_ZOOM,
+ PROP_MIN_ZOOM,
+ PROP_MAX_ZOOM
+};
+
+enum
+{
+ ZOOM_TO_LEVEL_SIGNAL,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL];
+
+G_DEFINE_TYPE (EphyZoomControl, ephy_zoom_control, GTK_TYPE_TOOL_ITEM)
+
+static void
+combo_changed_cb (GtkComboBox *combo, EphyZoomControl *control)
+{
+ gint index;
+ float zoom;
+
+ index = gtk_combo_box_get_active (combo);
+ zoom = zoom_levels[index].level;
+
+ if (zoom != control->priv->zoom)
+ {
+ g_signal_emit (control, signals[ZOOM_TO_LEVEL_SIGNAL], 0, zoom);
+ }
+}
+
+static void
+sync_zoom_cb (EphyZoomControl *control, GParamSpec *pspec, gpointer data)
+{
+ EphyZoomControlPrivate *p = control->priv;
+ guint index;
+
+ index = ephy_zoom_get_zoom_level_index (p->zoom);
+
+ g_signal_handler_block (p->combo, p->handler_id);
+ gtk_combo_box_set_active (p->combo, index);
+ g_signal_handler_unblock (p->combo, p->handler_id);
+}
+
+static void
+sync_zoom_max_min_cb (EphyZoomControl *control, GParamSpec *pspec, gpointer data)
+{
+ EphyZoomControlPrivate *p = control->priv;
+ GtkListStore *model = (GtkListStore *)gtk_combo_box_get_model (p->combo);
+ GtkTreeIter iter;
+ gint i;
+
+ g_signal_handler_block (p->combo, p->handler_id);
+ gtk_list_store_clear (model);
+
+ for (i = 0; i < n_zoom_levels; i++)
+ {
+ if (zoom_levels[i].level > 0) {
+ if (zoom_levels[i].level < p->min_zoom)
+ continue;
+
+ if (zoom_levels[i].level > p->max_zoom)
+ break;
+ }
+
+ gtk_list_store_append (model, &iter);
+
+ if (zoom_levels[i].name != NULL) {
+ gtk_list_store_set (model, &iter,
+ COL_TEXT, _(zoom_levels[i].name),
+ -1);
+ } else {
+ gtk_list_store_set (model, &iter,
+ COL_IS_SEP, zoom_levels[i].name == NULL,
+ -1);
+ }
+ }
+
+ gtk_combo_box_set_active (p->combo, ephy_zoom_get_zoom_level_index (p->zoom));
+ g_signal_handler_unblock (p->combo, p->handler_id);
+}
+
+static gboolean
+row_is_separator (GtkTreeModel *model,
+ GtkTreeIter *iter,
+ gpointer data)
+{
+ gboolean is_sep;
+ gtk_tree_model_get (model, iter, COL_IS_SEP, &is_sep, -1);
+ return is_sep;
+}
+
+static void
+ephy_zoom_control_finalize (GObject *o)
+{
+ EphyZoomControl *control = EPHY_ZOOM_CONTROL (o);
+
+ g_object_unref (control->priv->combo);
+
+ G_OBJECT_CLASS (ephy_zoom_control_parent_class)->finalize (o);
+}
+
+static void
+ephy_zoom_control_init (EphyZoomControl *control)
+{
+ EphyZoomControlPrivate *p;
+ GtkWidget *vbox;
+ GtkCellRenderer *renderer;
+ GtkListStore *store;
+ GtkTreeIter iter;
+ guint i;
+
+ p = EPHY_ZOOM_CONTROL_GET_PRIVATE (control);
+ control->priv = p;
+
+ p->zoom = 1.0;
+
+ store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
+
+ for (i = 0; i < n_zoom_levels; i++)
+ {
+ gtk_list_store_append (store, &iter);
+
+ if (zoom_levels[i].name != NULL) {
+ gtk_list_store_set (store, &iter,
+ COL_TEXT, _(zoom_levels[i].name),
+ -1);
+ } else {
+ gtk_list_store_set (store, &iter,
+ COL_IS_SEP, zoom_levels[i].name == NULL,
+ -1);
+ }
+ }
+
+ p->combo = GTK_COMBO_BOX (gtk_combo_box_new_with_model (GTK_TREE_MODEL (store)));
+ g_object_unref (store);
+
+ renderer = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (p->combo), renderer, TRUE);
+ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (p->combo), renderer,
+ "text", COL_TEXT, NULL);
+ gtk_combo_box_set_row_separator_func (p->combo,
+ (GtkTreeViewRowSeparatorFunc) row_is_separator,
+ NULL, NULL);
+
+ gtk_combo_box_set_focus_on_click (p->combo, FALSE);
+ g_object_ref_sink (G_OBJECT (p->combo));
+ gtk_widget_show (GTK_WIDGET (p->combo));
+
+ i = ephy_zoom_get_zoom_level_index (p->zoom);
+ gtk_combo_box_set_active (p->combo, i);
+
+ vbox = gtk_vbox_new (TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (p->combo), TRUE, FALSE, 0);
+ gtk_widget_show (vbox);
+
+ gtk_container_add (GTK_CONTAINER (control), vbox);
+
+ p->handler_id = g_signal_connect (p->combo, "changed",
+ G_CALLBACK (combo_changed_cb), control);
+
+ g_signal_connect_object (control, "notify::zoom",
+ G_CALLBACK (sync_zoom_cb), NULL, 0);
+ g_signal_connect_object (control, "notify::min-zoom",
+ G_CALLBACK (sync_zoom_max_min_cb), NULL, 0);
+ g_signal_connect_object (control, "notify::max-zoom",
+ G_CALLBACK (sync_zoom_max_min_cb), NULL, 0);
+}
+
+static void
+ephy_zoom_control_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EphyZoomControl *control;
+ EphyZoomControlPrivate *p;
+
+ control = EPHY_ZOOM_CONTROL (object);
+ p = control->priv;
+
+ switch (prop_id)
+ {
+ case PROP_ZOOM:
+ p->zoom = g_value_get_float (value);
+ break;
+ case PROP_MIN_ZOOM:
+ p->min_zoom = g_value_get_float (value);
+ break;
+ case PROP_MAX_ZOOM:
+ p->max_zoom = g_value_get_float (value);
+ break;
+ }
+}
+
+static void
+ephy_zoom_control_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EphyZoomControl *control;
+ EphyZoomControlPrivate *p;
+
+ control = EPHY_ZOOM_CONTROL (object);
+ p = control->priv;
+
+ switch (prop_id)
+ {
+ case PROP_ZOOM:
+ g_value_set_float (value, p->zoom);
+ break;
+ case PROP_MIN_ZOOM:
+ g_value_set_float (value, p->min_zoom);
+ break;
+ case PROP_MAX_ZOOM:
+ g_value_set_float (value, p->max_zoom);
+ break;
+ }
+}
+
+static void
+ephy_zoom_control_class_init (EphyZoomControlClass *klass)
+{
+ GObjectClass *object_class;
+ GtkToolItemClass *tool_item_class;
+
+ object_class = (GObjectClass *)klass;
+ tool_item_class = (GtkToolItemClass *)klass;
+
+ object_class->set_property = ephy_zoom_control_set_property;
+ object_class->get_property = ephy_zoom_control_get_property;
+ object_class->finalize = ephy_zoom_control_finalize;
+
+ g_object_class_install_property (object_class,
+ PROP_ZOOM,
+ g_param_spec_float ("zoom",
+ "Zoom",
+ "Zoom level to display in the item.",
+ ZOOM_MINIMAL,
+ ZOOM_MAXIMAL,
+ 1.0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_MIN_ZOOM,
+ g_param_spec_float ("min-zoom",
+ "MinZoom",
+ "The minimum zoom",
+ ZOOM_MINIMAL,
+ ZOOM_MAXIMAL,
+ ZOOM_MINIMAL,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_MAX_ZOOM,
+ g_param_spec_float ("max-zoom",
+ "MaxZoom",
+ "The maximum zoom",
+ ZOOM_MINIMAL,
+ ZOOM_MAXIMAL,
+ ZOOM_MAXIMAL,
+ G_PARAM_READWRITE));
+
+ signals[ZOOM_TO_LEVEL_SIGNAL] =
+ g_signal_new ("zoom_to_level",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EphyZoomControlClass,
+ zoom_to_level),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__FLOAT,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_FLOAT);
+
+ g_type_class_add_private (object_class, sizeof (EphyZoomControlPrivate));
+}
+
+void
+ephy_zoom_control_set_zoom_level (EphyZoomControl *control, float zoom)
+{
+ g_return_if_fail (EPHY_IS_ZOOM_CONTROL (control));
+
+ if (zoom < ZOOM_MINIMAL || zoom > ZOOM_MAXIMAL) return;
+
+ control->priv->zoom = zoom;
+ g_object_notify (G_OBJECT (control), "zoom");
+}
+
+float
+ephy_zoom_control_get_zoom_level (EphyZoomControl *control)
+{
+ g_return_val_if_fail (EPHY_IS_ZOOM_CONTROL (control), 1.0);
+
+ return control->priv->zoom;
+}
diff --git a/cut-n-paste/zoom-control/ephy-zoom-control.h b/cut-n-paste/zoom-control/ephy-zoom-control.h
new file mode 100644
index 00000000..8e74e7b1
--- /dev/null
+++ b/cut-n-paste/zoom-control/ephy-zoom-control.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2003 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $Id$
+ */
+
+#ifndef EPHY_ZOOM_CONTROL_H
+#define EPHY_ZOOM_CONTROL_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_ZOOM_CONTROL (ephy_zoom_control_get_type())
+#define EPHY_ZOOM_CONTROL(object) (G_TYPE_CHECK_INSTANCE_CAST((object), EPHY_TYPE_ZOOM_CONTROL, EphyZoomControl))
+#define EPHY_ZOOM_CONTROL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EPHY_TYPE_ZOOM_CONTROL, EphyZoomControlClass))
+#define EPHY_IS_ZOOM_CONTROL(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EPHY_TYPE_ZOOM_CONTROL))
+#define EPHY_IS_ZOOM_CONTROL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EPHY_TYPE_ZOOM_CONTROL))
+#define EPHY_ZOOM_CONTROL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), EPHY_TYPE_ZOOM_CONTROL, EphyZoomControlClass))
+
+typedef struct _EphyZoomControl EphyZoomControl;
+typedef struct _EphyZoomControlClass EphyZoomControlClass;
+typedef struct _EphyZoomControlPrivate EphyZoomControlPrivate;
+
+struct _EphyZoomControlClass
+{
+ GtkToolItemClass parent_class;
+
+ /* signals */
+ void (*zoom_to_level) (EphyZoomControl *control, float level);
+};
+
+struct _EphyZoomControl
+{
+ GtkToolItem parent_object;
+
+ /*< private >*/
+ EphyZoomControlPrivate *priv;
+};
+
+GType ephy_zoom_control_get_type (void);
+
+void ephy_zoom_control_set_zoom_level (EphyZoomControl *control, float zoom);
+
+float ephy_zoom_control_get_zoom_level (EphyZoomControl *control);
+
+G_END_DECLS
+
+#endif
diff --git a/cut-n-paste/zoom-control/ephy-zoom.c b/cut-n-paste/zoom-control/ephy-zoom.c
new file mode 100644
index 00000000..83bb8291
--- /dev/null
+++ b/cut-n-paste/zoom-control/ephy-zoom.c
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2003 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $Id$
+ */
+
+#include "config.h"
+
+#include "ephy-zoom.h"
+
+#include <math.h>
+
+guint
+ephy_zoom_get_zoom_level_index (float level)
+{
+ guint i;
+ float previous, current, mean;
+
+ /* Handle our options at the beginning of the list. */
+ if (level == EPHY_ZOOM_BEST_FIT) {
+ return 0;
+ } else if (level == EPHY_ZOOM_FIT_WIDTH) {
+ return 1;
+ }
+
+ previous = zoom_levels[3].level;
+
+ for (i = 4; i < n_zoom_levels; i++)
+ {
+ current = zoom_levels[i].level;
+ mean = sqrt (previous * current);
+
+ if (level <= mean) return i - 1;
+
+ previous = current;
+ }
+
+ return n_zoom_levels - 1;
+}
+
+
+float
+ephy_zoom_get_changed_zoom_level (float level, gint steps)
+{
+ guint index;
+
+ index = ephy_zoom_get_zoom_level_index (level);
+ return zoom_levels[CLAMP(index + steps, 3, n_zoom_levels - 1)].level;
+}
+
+float ephy_zoom_get_nearest_zoom_level (float level)
+{
+ return ephy_zoom_get_changed_zoom_level (level, 0);
+}
diff --git a/cut-n-paste/zoom-control/ephy-zoom.h b/cut-n-paste/zoom-control/ephy-zoom.h
new file mode 100644
index 00000000..bf01f0d7
--- /dev/null
+++ b/cut-n-paste/zoom-control/ephy-zoom.h
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2003 Christian Persch
+ *
+ * Modified 2005 by James Bowes for use in evince.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $Id$
+ */
+
+#ifndef EPHY_ZOOM_H
+#define EPHY_ZOOM_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib.h>
+#include <glib/gi18n.h>
+
+G_BEGIN_DECLS
+
+#define EPHY_ZOOM_BEST_FIT (-3.0)
+#define EPHY_ZOOM_FIT_WIDTH (-4.0)
+#define EPHY_ZOOM_SEPARATOR (-5.0)
+
+static const
+struct
+{
+ gchar *name;
+ float level;
+}
+
+zoom_levels[] =
+{
+ { N_("Best Fit"), EPHY_ZOOM_BEST_FIT },
+ { N_("Fit Page Width"), EPHY_ZOOM_FIT_WIDTH },
+ { NULL, EPHY_ZOOM_SEPARATOR },
+ { N_("50%"), 0.5 },
+ { N_("70%"), 0.7071067811 },
+ { N_("85%"), 0.8408964152 },
+ { N_("100%"), 1.0 },
+ { N_("125%"), 1.1892071149 },
+ { N_("150%"), 1.4142135623 },
+ { N_("175%"), 1.6817928304 },
+ { N_("200%"), 2.0 },
+ { N_("300%"), 2.8284271247 },
+ { N_("400%"), 4.0 },
+ { N_("800%"), 8.0 },
+ { N_("1600%"), 16.0 },
+ { N_("3200%"), 32.0 },
+ { N_("6400%"), 64.0 }
+};
+static const guint n_zoom_levels = G_N_ELEMENTS (zoom_levels);
+
+#define ZOOM_MINIMAL (EPHY_ZOOM_SEPARATOR)
+#define ZOOM_MAXIMAL (zoom_levels[n_zoom_levels - 1].level)
+#define ZOOM_IN (-1.0)
+#define ZOOM_OUT (-2.0)
+
+guint ephy_zoom_get_zoom_level_index (float level);
+
+float ephy_zoom_get_changed_zoom_level (float level, gint steps);
+
+float ephy_zoom_get_nearest_zoom_level (float level);
+
+G_END_DECLS
+
+#endif