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"
53 static void gtk_adjustment_get_property (GObject *object,
57 static void gtk_adjustment_set_property (GObject *object,
61 static void gtk_adjustment_dispatch_properties_changed (GObject *object,
65 static guint adjustment_signals[LAST_SIGNAL] = { 0 };
67 G_DEFINE_TYPE (GtkAdjustment, gtk_adjustment, GTK_TYPE_OBJECT)
70 gtk_adjustment_class_init (GtkAdjustmentClass *class)
72 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
74 gobject_class->set_property = gtk_adjustment_set_property;
75 gobject_class->get_property = gtk_adjustment_get_property;
76 gobject_class->dispatch_properties_changed = gtk_adjustment_dispatch_properties_changed;
78 class->changed = NULL;
79 class->value_changed = NULL;
82 * GtkAdjustment:value:
84 * The value of the adjustment.
88 g_object_class_install_property (gobject_class,
90 g_param_spec_double ("value",
92 P_("The value of the adjustment"),
96 GTK_PARAM_READWRITE));
99 * GtkAdjustment:lower:
101 * The minimum value of the adjustment.
105 g_object_class_install_property (gobject_class,
107 g_param_spec_double ("lower",
109 P_("The minimum value of the adjustment"),
113 GTK_PARAM_READWRITE));
116 * GtkAdjustment:upper:
118 * The maximum value of the adjustment.
119 * Note that values will be restricted by
120 * <literal>upper - page-size</literal> if the page-size
121 * property is nonzero.
125 g_object_class_install_property (gobject_class,
127 g_param_spec_double ("upper",
129 P_("The maximum value of the adjustment"),
133 GTK_PARAM_READWRITE));
136 * GtkAdjustment:step-increment:
138 * The step increment of the adjustment.
142 g_object_class_install_property (gobject_class,
144 g_param_spec_double ("step-increment",
145 P_("Step Increment"),
146 P_("The step increment of the adjustment"),
150 GTK_PARAM_READWRITE));
153 * GtkAdjustment:page-increment:
155 * The page increment of the adjustment.
159 g_object_class_install_property (gobject_class,
161 g_param_spec_double ("page-increment",
162 P_("Page Increment"),
163 P_("The page increment of the adjustment"),
167 GTK_PARAM_READWRITE));
170 * GtkAdjustment:page-size:
172 * The page size of the adjustment.
173 * Note that the page-size is irrelevant and should be set to zero
174 * if the adjustment is used for a simple scalar value, e.g. in a
179 g_object_class_install_property (gobject_class,
181 g_param_spec_double ("page-size",
183 P_("The page size of the adjustment"),
187 GTK_PARAM_READWRITE));
189 adjustment_signals[CHANGED] =
190 g_signal_new (I_("changed"),
191 G_OBJECT_CLASS_TYPE (class),
192 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
193 G_STRUCT_OFFSET (GtkAdjustmentClass, changed),
195 _gtk_marshal_VOID__VOID,
198 adjustment_signals[VALUE_CHANGED] =
199 g_signal_new (I_("value_changed"),
200 G_OBJECT_CLASS_TYPE (class),
201 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
202 G_STRUCT_OFFSET (GtkAdjustmentClass, value_changed),
204 _gtk_marshal_VOID__VOID,
209 gtk_adjustment_init (GtkAdjustment *adjustment)
211 adjustment->value = 0.0;
212 adjustment->lower = 0.0;
213 adjustment->upper = 0.0;
214 adjustment->step_increment = 0.0;
215 adjustment->page_increment = 0.0;
216 adjustment->page_size = 0.0;
220 gtk_adjustment_get_property (GObject *object,
225 GtkAdjustment *adjustment = GTK_ADJUSTMENT (object);
230 g_value_set_double (value, adjustment->value);
233 g_value_set_double (value, adjustment->lower);
236 g_value_set_double (value, adjustment->upper);
238 case PROP_STEP_INCREMENT:
239 g_value_set_double (value, adjustment->step_increment);
241 case PROP_PAGE_INCREMENT:
242 g_value_set_double (value, adjustment->page_increment);
245 g_value_set_double (value, adjustment->page_size);
248 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
254 gtk_adjustment_set_property (GObject *object,
259 GtkAdjustment *adjustment = GTK_ADJUSTMENT (object);
260 gdouble double_value = g_value_get_double (value);
265 gtk_adjustment_set_value (adjustment, double_value);
268 adjustment->lower = double_value;
271 adjustment->upper = double_value;
273 case PROP_STEP_INCREMENT:
274 adjustment->step_increment = double_value;
276 case PROP_PAGE_INCREMENT:
277 adjustment->page_increment = double_value;
280 adjustment->page_size = double_value;
283 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
289 gtk_adjustment_dispatch_properties_changed (GObject *object,
293 gboolean changed = FALSE;
296 G_OBJECT_CLASS (gtk_adjustment_parent_class)->dispatch_properties_changed (object, n_pspecs, pspecs);
298 for (i = 0; i < n_pspecs; i++)
299 switch (pspecs[i]->param_id)
303 case PROP_STEP_INCREMENT:
304 case PROP_PAGE_INCREMENT:
313 gtk_adjustment_changed (GTK_ADJUSTMENT (object));
317 gtk_adjustment_new (gdouble value,
320 gdouble step_increment,
321 gdouble page_increment,
324 return g_object_new (GTK_TYPE_ADJUSTMENT,
327 "step-increment", step_increment,
328 "page-increment", page_increment,
329 "page-size", page_size,
335 * gtk_adjustment_get_value:
336 * @adjustment: a #GtkAdjustment
338 * Gets the current value of the adjustment. See
339 * gtk_adjustment_set_value ().
341 * Return value: The current value of the adjustment.
344 gtk_adjustment_get_value (GtkAdjustment *adjustment)
346 g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), 0.0);
348 return adjustment->value;
352 gtk_adjustment_set_value (GtkAdjustment *adjustment,
355 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
357 value = CLAMP (value, adjustment->lower, adjustment->upper);
359 if (value != adjustment->value)
361 adjustment->value = value;
363 gtk_adjustment_value_changed (adjustment);
368 gtk_adjustment_changed (GtkAdjustment *adjustment)
370 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
372 g_signal_emit (adjustment, adjustment_signals[CHANGED], 0);
376 gtk_adjustment_value_changed (GtkAdjustment *adjustment)
378 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
380 g_signal_emit (adjustment, adjustment_signals[VALUE_CHANGED], 0);
381 g_object_notify (G_OBJECT (adjustment), "value");
385 gtk_adjustment_clamp_page (GtkAdjustment *adjustment,
389 gboolean need_emission;
391 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
393 lower = CLAMP (lower, adjustment->lower, adjustment->upper);
394 upper = CLAMP (upper, adjustment->lower, adjustment->upper);
396 need_emission = FALSE;
398 if (adjustment->value + adjustment->page_size < upper)
400 adjustment->value = upper - adjustment->page_size;
401 need_emission = TRUE;
403 if (adjustment->value > lower)
405 adjustment->value = lower;
406 need_emission = TRUE;
410 gtk_adjustment_value_changed (adjustment);
413 #define __GTK_ADJUSTMENT_C__
414 #include "gtkaliasdef.c"