[evince] [ephy-zoom] Add max/min zoom properties
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince] [ephy-zoom] Add max/min zoom properties
- Date: Mon, 31 May 2010 17:08:27 +0000 (UTC)
commit 8e0b5c5df827306c6c4e3761b1ea4a9f3a1674ed
Author: Carlos Garcia Campos <carlosgc gnome org>
Date: Mon May 31 17:31:26 2010 +0200
[ephy-zoom] Add max/min zoom properties
cut-n-paste/zoom-control/ephy-zoom-action.c | 87 +++++++++++++++++++++++++-
cut-n-paste/zoom-control/ephy-zoom-action.h | 11 +++-
cut-n-paste/zoom-control/ephy-zoom-control.c | 78 +++++++++++++++++++++++-
3 files changed, 170 insertions(+), 6 deletions(-)
---
diff --git a/cut-n-paste/zoom-control/ephy-zoom-action.c b/cut-n-paste/zoom-control/ephy-zoom-action.c
index 15a08df..a264649 100644
--- a/cut-n-paste/zoom-control/ephy-zoom-action.c
+++ b/cut-n-paste/zoom-control/ephy-zoom-action.c
@@ -36,12 +36,16 @@
struct _EphyZoomActionPrivate
{
float zoom;
+ float min_zoom;
+ float max_zoom;
};
enum
{
PROP_0,
- PROP_ZOOM
+ PROP_ZOOM,
+ PROP_MIN_ZOOM,
+ PROP_MAX_ZOOM
};
@@ -103,13 +107,32 @@ sync_zoom_cb (GtkAction *action, GParamSpec *pspec, GtkWidget *proxy)
}
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);
}
@@ -195,6 +218,12 @@ ephy_zoom_action_set_property (GObject *object,
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;
}
}
@@ -213,6 +242,12 @@ ephy_zoom_action_get_property (GObject *object,
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;
}
}
@@ -240,6 +275,24 @@ ephy_zoom_action_class_init (EphyZoomActionClass *class)
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",
@@ -281,3 +334,33 @@ ephy_zoom_action_get_zoom_level (EphyZoomAction *action)
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
index d7362c0..2d07c69 100644
--- a/cut-n-paste/zoom-control/ephy-zoom-action.h
+++ b/cut-n-paste/zoom-control/ephy-zoom-action.h
@@ -52,11 +52,16 @@ struct _EphyZoomActionClass
void (* zoom_to_level) (EphyZoomAction *action, float level);
};
-GType ephy_zoom_action_get_type (void);
+GType ephy_zoom_action_get_type (void);
-void ephy_zoom_action_set_zoom_level (EphyZoomAction *action, float zoom);
+void ephy_zoom_action_set_zoom_level (EphyZoomAction *action,
+ float zoom);
+float ephy_zoom_action_get_zoom_level (EphyZoomAction *action);
-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
diff --git a/cut-n-paste/zoom-control/ephy-zoom-control.c b/cut-n-paste/zoom-control/ephy-zoom-control.c
index 07bd030..6c86b4a 100644
--- a/cut-n-paste/zoom-control/ephy-zoom-control.c
+++ b/cut-n-paste/zoom-control/ephy-zoom-control.c
@@ -35,6 +35,8 @@ struct _EphyZoomControlPrivate
{
GtkComboBox *combo;
float zoom;
+ float min_zoom;
+ float max_zoom;
guint handler_id;
};
@@ -47,7 +49,9 @@ enum
enum
{
PROP_0,
- PROP_ZOOM
+ PROP_ZOOM,
+ PROP_MIN_ZOOM,
+ PROP_MAX_ZOOM
};
enum
@@ -88,6 +92,44 @@ sync_zoom_cb (EphyZoomControl *control, GParamSpec *pspec, gpointer data)
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,
@@ -169,6 +211,10 @@ ephy_zoom_control_init (EphyZoomControl *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
@@ -188,6 +234,12 @@ ephy_zoom_control_set_property (GObject *object,
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;
}
}
@@ -208,6 +260,12 @@ ephy_zoom_control_get_property (GObject *object,
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;
}
}
@@ -233,6 +291,24 @@ ephy_zoom_control_class_init (EphyZoomControlClass *klass)
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",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]