1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
28 #include "gtkadjustment.h"
29 #include "gtkmarshalers.h"
30 #include "gtkprivate.h"
52 static void gtk_adjustment_get_property (GObject *object,
56 static void gtk_adjustment_set_property (GObject *object,
61 static guint adjustment_signals[LAST_SIGNAL] = { 0 };
63 G_DEFINE_TYPE (GtkAdjustment, gtk_adjustment, GTK_TYPE_OBJECT);
66 gtk_adjustment_class_init (GtkAdjustmentClass *class)
68 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
70 gobject_class->set_property = gtk_adjustment_set_property;
71 gobject_class->get_property = gtk_adjustment_get_property;
73 class->changed = NULL;
74 class->value_changed = NULL;
77 * GtkAdjustment:value:
79 * The value of the adjustment.
83 g_object_class_install_property (gobject_class,
85 g_param_spec_double ("value",
87 P_("The value of the adjustment"),
91 GTK_PARAM_READWRITE));
94 * GtkAdjustment:lower:
96 * The minimum value of the adjustment.
100 g_object_class_install_property (gobject_class,
102 g_param_spec_double ("lower",
104 P_("The minimum value of the adjustment"),
108 GTK_PARAM_READWRITE));
111 * GtkAdjustment:upper:
113 * The maximum value of the adjustment.
114 * Note that values will be restricted by
115 * <literal>upper - page-size</literal> if the page-size
116 * property is nonzero.
120 g_object_class_install_property (gobject_class,
122 g_param_spec_double ("upper",
124 P_("The maximum value of the adjustment"),
128 GTK_PARAM_READWRITE));
131 * GtkAdjustment:step-increment:
133 * The step increment of the adjustment.
137 g_object_class_install_property (gobject_class,
139 g_param_spec_double ("step-increment",
140 P_("Step Increment"),
141 P_("The step increment of the adjustment"),
145 GTK_PARAM_READWRITE));
148 * GtkAdjustment:page-increment:
150 * The page increment of the adjustment.
154 g_object_class_install_property (gobject_class,
156 g_param_spec_double ("page-increment",
157 P_("Page Increment"),
158 P_("The page increment of the adjustment"),
162 GTK_PARAM_READWRITE));
165 * GtkAdjustment:page-size:
167 * The page size of the adjustment.
168 * Note that the page-size is irrelevant and should be set to zero
169 * if the adjustment is used for a simple scalar value, e.g. in a
174 g_object_class_install_property (gobject_class,
176 g_param_spec_double ("page-size",
178 P_("The page size of the adjustment"),
182 GTK_PARAM_READWRITE));
185 adjustment_signals[CHANGED] =
186 g_signal_new (I_("changed"),
187 G_OBJECT_CLASS_TYPE (class),
188 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
189 G_STRUCT_OFFSET (GtkAdjustmentClass, changed),
191 _gtk_marshal_VOID__VOID,
193 adjustment_signals[VALUE_CHANGED] =
194 g_signal_new (I_("value_changed"),
195 G_OBJECT_CLASS_TYPE (class),
196 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
197 G_STRUCT_OFFSET (GtkAdjustmentClass, value_changed),
199 _gtk_marshal_VOID__VOID,
204 gtk_adjustment_init (GtkAdjustment *adjustment)
206 adjustment->value = 0.0;
207 adjustment->lower = 0.0;
208 adjustment->upper = 0.0;
209 adjustment->step_increment = 0.0;
210 adjustment->page_increment = 0.0;
211 adjustment->page_size = 0.0;
215 gtk_adjustment_get_property (GObject *object, guint prop_id, GValue *value,
218 GtkAdjustment *adjustment = GTK_ADJUSTMENT (object);
223 g_value_set_double (value, adjustment->value);
226 g_value_set_double (value, adjustment->lower);
229 g_value_set_double (value, adjustment->upper);
231 case PROP_STEP_INCREMENT:
232 g_value_set_double (value, adjustment->step_increment);
234 case PROP_PAGE_INCREMENT:
235 g_value_set_double (value, adjustment->page_increment);
238 g_value_set_double (value, adjustment->page_size);
241 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
247 gtk_adjustment_set_property (GObject * object, guint prop_id,
248 const GValue * value, GParamSpec * pspec)
250 GtkAdjustment *adjustment = GTK_ADJUSTMENT (object);
251 gdouble double_value = g_value_get_double (value);
256 gtk_adjustment_set_value (GTK_ADJUSTMENT (object), double_value);
259 if (adjustment->lower != double_value)
261 adjustment->lower = double_value;
262 g_object_notify (G_OBJECT (adjustment), "lower");
266 if (adjustment->upper != double_value)
268 adjustment->upper = double_value;
269 g_object_notify (G_OBJECT (adjustment), "upper");
272 case PROP_STEP_INCREMENT:
273 if (adjustment->step_increment != double_value)
275 adjustment->step_increment = double_value;
276 g_object_notify (G_OBJECT (adjustment), "step-increment");
279 case PROP_PAGE_INCREMENT:
280 if (adjustment->page_increment != double_value)
282 adjustment->page_increment = double_value;
283 g_object_notify (G_OBJECT (adjustment), "page-increment");
287 if (adjustment->page_size != double_value)
289 adjustment->page_size = double_value;
290 g_object_notify (G_OBJECT (adjustment), "page-size");
294 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
300 gtk_adjustment_new (gdouble value,
303 gdouble step_increment,
304 gdouble page_increment,
307 return g_object_new (GTK_TYPE_ADJUSTMENT,
310 "step-increment", step_increment,
311 "page-increment", page_increment,
312 "page-size", page_size,
318 * gtk_adjustment_get_value:
319 * @adjustment: a #GtkAdjustment
321 * Gets the current value of the adjustment. See
322 * gtk_adjustment_set_value ().
324 * Return value: The current value of the adjustment.
327 gtk_adjustment_get_value (GtkAdjustment *adjustment)
329 g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), 0.);
331 return adjustment->value;
335 gtk_adjustment_set_value (GtkAdjustment *adjustment,
338 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
340 value = CLAMP (value, adjustment->lower, adjustment->upper);
342 if (value != adjustment->value)
344 adjustment->value = value;
346 gtk_adjustment_value_changed (adjustment);
351 gtk_adjustment_changed (GtkAdjustment *adjustment)
353 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
355 g_signal_emit (adjustment, adjustment_signals[CHANGED], 0);
359 gtk_adjustment_value_changed (GtkAdjustment *adjustment)
361 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
363 g_signal_emit (adjustment, adjustment_signals[VALUE_CHANGED], 0);
364 g_object_notify (G_OBJECT (adjustment), "value");
368 gtk_adjustment_clamp_page (GtkAdjustment *adjustment,
372 gboolean need_emission;
374 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
376 lower = CLAMP (lower, adjustment->lower, adjustment->upper);
377 upper = CLAMP (upper, adjustment->lower, adjustment->upper);
379 need_emission = FALSE;
381 if (adjustment->value + adjustment->page_size < upper)
383 adjustment->value = upper - adjustment->page_size;
384 need_emission = TRUE;
386 if (adjustment->value > lower)
388 adjustment->value = lower;
389 need_emission = TRUE;
393 gtk_adjustment_value_changed (adjustment);
396 #define __GTK_ADJUSTMENT_C__
397 #include "gtkaliasdef.c"