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_class_init (GtkAdjustmentClass *klass);
53 static void gtk_adjustment_init (GtkAdjustment *adjustment);
55 static void gtk_adjustment_get_property (GObject *object,
59 static void gtk_adjustment_set_property (GObject *object,
64 static guint adjustment_signals[LAST_SIGNAL] = { 0 };
68 gtk_adjustment_get_type (void)
70 static GType adjustment_type = 0;
74 static const GTypeInfo adjustment_info =
76 sizeof (GtkAdjustmentClass),
78 NULL, /* base_finalize */
79 (GClassInitFunc) gtk_adjustment_class_init,
80 NULL, /* class_finalize */
81 NULL, /* class_data */
82 sizeof (GtkAdjustment),
84 (GInstanceInitFunc) gtk_adjustment_init,
88 g_type_register_static (GTK_TYPE_OBJECT, "GtkAdjustment",
92 return adjustment_type;
96 gtk_adjustment_class_init (GtkAdjustmentClass *class)
98 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
100 gobject_class->set_property = gtk_adjustment_set_property;
101 gobject_class->get_property = gtk_adjustment_get_property;
103 class->changed = NULL;
104 class->value_changed = NULL;
107 * GtkAdjustment:value:
109 * The value of the adjustment.
113 g_object_class_install_property (gobject_class,
115 g_param_spec_double ("value",
117 P_("The value of the adjustment"),
121 GTK_PARAM_READWRITE));
124 * GtkAdjustment:lower:
126 * The minimum value of the adjustment.
130 g_object_class_install_property (gobject_class,
132 g_param_spec_double ("lower",
134 P_("The minimum value of the adjustment"),
138 GTK_PARAM_READWRITE));
141 * GtkAdjustment:upper:
143 * The maximum value of the adjustment.
144 * Note that values will be restricted by
145 * <literal>upper - page-size</literal> if the page-size
146 * property is nonzero.
150 g_object_class_install_property (gobject_class,
152 g_param_spec_double ("upper",
154 P_("The maximum value of the adjustment"),
158 GTK_PARAM_READWRITE));
161 * GtkAdjustment:step-increment:
163 * The step increment of the adjustment.
167 g_object_class_install_property (gobject_class,
169 g_param_spec_double ("step-increment",
170 P_("Step Increment"),
171 P_("The step increment of the adjustment"),
175 GTK_PARAM_READWRITE));
178 * GtkAdjustment:page-increment:
180 * The page increment of the adjustment.
184 g_object_class_install_property (gobject_class,
186 g_param_spec_double ("page-increment",
187 P_("Page Increment"),
188 P_("The page increment of the adjustment"),
192 GTK_PARAM_READWRITE));
195 * GtkAdjustment:page-size:
197 * The page size of the adjustment.
198 * Note that the page-size is irrelevant and should be set to zero
199 * if the adjustment is used for a simple scalar value, e.g. in a
204 g_object_class_install_property (gobject_class,
206 g_param_spec_double ("page-size",
208 P_("The page size of the adjustment"),
212 GTK_PARAM_READWRITE));
215 adjustment_signals[CHANGED] =
216 g_signal_new ("changed",
217 G_OBJECT_CLASS_TYPE (class),
218 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
219 G_STRUCT_OFFSET (GtkAdjustmentClass, changed),
221 _gtk_marshal_VOID__VOID,
223 adjustment_signals[VALUE_CHANGED] =
224 g_signal_new ("value_changed",
225 G_OBJECT_CLASS_TYPE (class),
226 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
227 G_STRUCT_OFFSET (GtkAdjustmentClass, value_changed),
229 _gtk_marshal_VOID__VOID,
234 gtk_adjustment_init (GtkAdjustment *adjustment)
236 adjustment->value = 0.0;
237 adjustment->lower = 0.0;
238 adjustment->upper = 0.0;
239 adjustment->step_increment = 0.0;
240 adjustment->page_increment = 0.0;
241 adjustment->page_size = 0.0;
245 gtk_adjustment_get_property (GObject *object, guint prop_id, GValue *value,
248 GtkAdjustment *adjustment = GTK_ADJUSTMENT (object);
253 g_value_set_double (value, adjustment->value);
256 g_value_set_double (value, adjustment->lower);
259 g_value_set_double (value, adjustment->upper);
261 case PROP_STEP_INCREMENT:
262 g_value_set_double (value, adjustment->step_increment);
264 case PROP_PAGE_INCREMENT:
265 g_value_set_double (value, adjustment->page_increment);
268 g_value_set_double (value, adjustment->page_size);
271 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
277 gtk_adjustment_set_property (GObject * object, guint prop_id,
278 const GValue * value, GParamSpec * pspec)
280 GtkAdjustment *adjustment = GTK_ADJUSTMENT (object);
281 gdouble double_value = g_value_get_double (value);
286 gtk_adjustment_set_value (GTK_ADJUSTMENT (object), double_value);
289 if (adjustment->lower != double_value)
291 adjustment->lower = double_value;
292 g_object_notify (G_OBJECT (adjustment), "lower");
296 if (adjustment->upper != double_value)
298 adjustment->upper = double_value;
299 g_object_notify (G_OBJECT (adjustment), "upper");
302 case PROP_STEP_INCREMENT:
303 if (adjustment->step_increment != double_value)
305 adjustment->step_increment = double_value;
306 g_object_notify (G_OBJECT (adjustment), "step-increment");
309 case PROP_PAGE_INCREMENT:
310 if (adjustment->page_increment != double_value)
312 adjustment->page_increment = double_value;
313 g_object_notify (G_OBJECT (adjustment), "page-increment");
317 if (adjustment->page_size != double_value)
319 adjustment->page_size = double_value;
320 g_object_notify (G_OBJECT (adjustment), "page-size");
324 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
330 gtk_adjustment_new (gdouble value,
333 gdouble step_increment,
334 gdouble page_increment,
337 return g_object_new (GTK_TYPE_ADJUSTMENT,
340 "step-increment", step_increment,
341 "page-increment", page_increment,
342 "page_size", page_size,
348 * gtk_adjustment_get_value:
349 * @adjustment: a #GtkAdjustment
351 * Gets the current value of the adjustment. See
352 * gtk_adjustment_set_value ().
354 * Return value: The current value of the adjustment.
357 gtk_adjustment_get_value (GtkAdjustment *adjustment)
359 g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), 0.);
361 return adjustment->value;
365 gtk_adjustment_set_value (GtkAdjustment *adjustment,
368 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
370 value = CLAMP (value, adjustment->lower, adjustment->upper);
372 if (value != adjustment->value)
374 adjustment->value = value;
376 gtk_adjustment_value_changed (adjustment);
381 gtk_adjustment_changed (GtkAdjustment *adjustment)
383 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
385 g_signal_emit (adjustment, adjustment_signals[CHANGED], 0);
389 gtk_adjustment_value_changed (GtkAdjustment *adjustment)
391 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
393 g_signal_emit (adjustment, adjustment_signals[VALUE_CHANGED], 0);
394 g_object_notify (G_OBJECT (adjustment), "value");
398 gtk_adjustment_clamp_page (GtkAdjustment *adjustment,
402 gboolean need_emission;
404 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
406 lower = CLAMP (lower, adjustment->lower, adjustment->upper);
407 upper = CLAMP (upper, adjustment->lower, adjustment->upper);
409 need_emission = FALSE;
411 if (adjustment->value + adjustment->page_size < upper)
413 adjustment->value = upper - adjustment->page_size;
414 need_emission = TRUE;
416 if (adjustment->value > lower)
418 adjustment->value = lower;
419 need_emission = TRUE;
423 gtk_adjustment_value_changed (adjustment);
426 #define __GTK_ADJUSTMENT_C__
427 #include "gtkaliasdef.c"