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/.
27 #include "gtkadjustment.h"
29 #include "gtkmarshalers.h"
49 static void gtk_adjustment_class_init (GtkAdjustmentClass *klass);
50 static void gtk_adjustment_init (GtkAdjustment *adjustment);
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 };
65 gtk_adjustment_get_type (void)
67 static GType adjustment_type = 0;
71 static const GTypeInfo adjustment_info =
73 sizeof (GtkAdjustmentClass),
75 NULL, /* base_finalize */
76 (GClassInitFunc) gtk_adjustment_class_init,
77 NULL, /* class_finalize */
78 NULL, /* class_data */
79 sizeof (GtkAdjustment),
81 (GInstanceInitFunc) gtk_adjustment_init,
85 g_type_register_static (GTK_TYPE_OBJECT, "GtkAdjustment",
89 return adjustment_type;
93 gtk_adjustment_class_init (GtkAdjustmentClass *class)
95 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
97 gobject_class->set_property = gtk_adjustment_set_property;
98 gobject_class->get_property = gtk_adjustment_get_property;
100 class->changed = NULL;
101 class->value_changed = NULL;
103 g_object_class_install_property (gobject_class,
105 g_param_spec_double ("value",
107 P_("The value of the adjustment"),
113 g_object_class_install_property (gobject_class,
115 g_param_spec_double ("lower",
117 P_("The minimum value of the adjustment"),
123 g_object_class_install_property (gobject_class,
125 g_param_spec_double ("upper",
127 P_("The maximum value of the adjustment"),
133 g_object_class_install_property (gobject_class,
135 g_param_spec_double ("step-increment",
136 P_("Step Increment"),
137 P_("The step increment of the adjustment"),
143 g_object_class_install_property (gobject_class,
145 g_param_spec_double ("page-increment",
146 P_("Page Increment"),
147 P_("The page increment of the adjustment"),
153 g_object_class_install_property (gobject_class,
155 g_param_spec_double ("page-size",
157 P_("The page size of the adjustment"),
164 adjustment_signals[CHANGED] =
165 g_signal_new ("changed",
166 G_OBJECT_CLASS_TYPE (class),
167 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
168 G_STRUCT_OFFSET (GtkAdjustmentClass, changed),
170 _gtk_marshal_VOID__VOID,
172 adjustment_signals[VALUE_CHANGED] =
173 g_signal_new ("value_changed",
174 G_OBJECT_CLASS_TYPE (class),
175 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
176 G_STRUCT_OFFSET (GtkAdjustmentClass, value_changed),
178 _gtk_marshal_VOID__VOID,
183 gtk_adjustment_init (GtkAdjustment *adjustment)
185 adjustment->value = 0.0;
186 adjustment->lower = 0.0;
187 adjustment->upper = 0.0;
188 adjustment->step_increment = 0.0;
189 adjustment->page_increment = 0.0;
190 adjustment->page_size = 0.0;
194 gtk_adjustment_get_property (GObject *object, guint prop_id, GValue *value,
197 GtkAdjustment *adjustment = GTK_ADJUSTMENT (object);
202 g_value_set_double (value, adjustment->value);
205 g_value_set_double (value, adjustment->lower);
208 g_value_set_double (value, adjustment->upper);
210 case PROP_STEP_INCREMENT:
211 g_value_set_double (value, adjustment->step_increment);
213 case PROP_PAGE_INCREMENT:
214 g_value_set_double (value, adjustment->page_increment);
217 g_value_set_double (value, adjustment->page_size);
220 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
226 gtk_adjustment_set_property (GObject * object, guint prop_id,
227 const GValue * value, GParamSpec * pspec)
229 GtkAdjustment *adjustment = GTK_ADJUSTMENT (object);
230 gdouble double_value = g_value_get_double (value);
235 gtk_adjustment_set_value (GTK_ADJUSTMENT (object), double_value);
238 if (adjustment->lower != double_value)
240 adjustment->lower = double_value;
241 g_object_notify (G_OBJECT (adjustment), "lower");
245 if (adjustment->upper != double_value)
247 adjustment->upper = double_value;
248 g_object_notify (G_OBJECT (adjustment), "upper");
251 case PROP_STEP_INCREMENT:
252 if (adjustment->step_increment != double_value)
254 adjustment->step_increment = double_value;
255 g_object_notify (G_OBJECT (adjustment), "step-increment");
258 case PROP_PAGE_INCREMENT:
259 if (adjustment->page_increment != double_value)
261 adjustment->page_increment = double_value;
262 g_object_notify (G_OBJECT (adjustment), "page-increment");
266 if (adjustment->page_size != double_value)
268 adjustment->page_size = double_value;
269 g_object_notify (G_OBJECT (adjustment), "page-size");
273 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
279 gtk_adjustment_new (gdouble value,
282 gdouble step_increment,
283 gdouble page_increment,
286 return g_object_new (GTK_TYPE_ADJUSTMENT,
290 "step-increment", step_increment,
291 "page-increment", page_increment,
292 "page_size", page_size,
297 * gtk_adjustment_get_value:
298 * @adjustment: a #GtkAdjustment
300 * Gets the current value of the adjustment. See
301 * gtk_adjustment_set_value ().
303 * Return value: The current value of the adjustment.
306 gtk_adjustment_get_value (GtkAdjustment *adjustment)
308 g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), 0.);
310 return adjustment->value;
314 gtk_adjustment_set_value (GtkAdjustment *adjustment,
317 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
319 value = CLAMP (value, adjustment->lower, adjustment->upper);
321 if (value != adjustment->value)
323 adjustment->value = value;
325 gtk_adjustment_value_changed (adjustment);
330 gtk_adjustment_changed (GtkAdjustment *adjustment)
332 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
334 g_signal_emit (adjustment, adjustment_signals[CHANGED], 0);
338 gtk_adjustment_value_changed (GtkAdjustment *adjustment)
340 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
342 g_signal_emit (adjustment, adjustment_signals[VALUE_CHANGED], 0);
343 g_object_notify (G_OBJECT (adjustment), "value");
347 gtk_adjustment_clamp_page (GtkAdjustment *adjustment,
351 gboolean need_emission;
353 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
355 lower = CLAMP (lower, adjustment->lower, adjustment->upper);
356 upper = CLAMP (upper, adjustment->lower, adjustment->upper);
358 need_emission = FALSE;
360 if (adjustment->value + adjustment->page_size < upper)
362 adjustment->value = upper - adjustment->page_size;
363 need_emission = TRUE;
365 if (adjustment->value > lower)
367 adjustment->value = lower;
368 need_emission = TRUE;
372 gtk_adjustment_value_changed (adjustment);