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"
30 #include "gtkmarshalers.h"
51 static void gtk_adjustment_class_init (GtkAdjustmentClass *klass);
52 static void gtk_adjustment_init (GtkAdjustment *adjustment);
54 static void gtk_adjustment_get_property (GObject *object,
58 static void gtk_adjustment_set_property (GObject *object,
63 static guint adjustment_signals[LAST_SIGNAL] = { 0 };
67 gtk_adjustment_get_type (void)
69 static GType adjustment_type = 0;
73 static const GTypeInfo adjustment_info =
75 sizeof (GtkAdjustmentClass),
77 NULL, /* base_finalize */
78 (GClassInitFunc) gtk_adjustment_class_init,
79 NULL, /* class_finalize */
80 NULL, /* class_data */
81 sizeof (GtkAdjustment),
83 (GInstanceInitFunc) gtk_adjustment_init,
87 g_type_register_static (GTK_TYPE_OBJECT, "GtkAdjustment",
91 return adjustment_type;
95 gtk_adjustment_class_init (GtkAdjustmentClass *class)
97 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
99 gobject_class->set_property = gtk_adjustment_set_property;
100 gobject_class->get_property = gtk_adjustment_get_property;
102 class->changed = NULL;
103 class->value_changed = NULL;
105 #define STATIC_STRINGS G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
108 * GtkAdjustment:value:
110 * The value of the adjustment.
114 g_object_class_install_property (gobject_class,
116 g_param_spec_double ("value",
118 P_("The value of the adjustment"),
122 G_PARAM_READWRITE | STATIC_STRINGS));
125 * GtkAdjustment:lower:
127 * The minimum value of the adjustment.
131 g_object_class_install_property (gobject_class,
133 g_param_spec_double ("lower",
135 P_("The minimum value of the adjustment"),
139 G_PARAM_READWRITE | STATIC_STRINGS));
142 * GtkAdjustment:upper:
144 * The maximum value of the adjustment.
145 * Note that values will be restricted by
146 * <literal>upper - page-size</literal> if the page-size
147 * property is nonzero.
151 g_object_class_install_property (gobject_class,
153 g_param_spec_double ("upper",
155 P_("The maximum value of the adjustment"),
159 G_PARAM_READWRITE | STATIC_STRINGS));
162 * GtkAdjustment:step-increment:
164 * The step increment of the adjustment.
168 g_object_class_install_property (gobject_class,
170 g_param_spec_double ("step-increment",
171 P_("Step Increment"),
172 P_("The step increment of the adjustment"),
176 G_PARAM_READWRITE | STATIC_STRINGS));
179 * GtkAdjustment:page-increment:
181 * The page increment of the adjustment.
185 g_object_class_install_property (gobject_class,
187 g_param_spec_double ("page-increment",
188 P_("Page Increment"),
189 P_("The page increment of the adjustment"),
193 G_PARAM_READWRITE | STATIC_STRINGS));
196 * GtkAdjustment:page-size:
198 * The page size of the adjustment.
199 * Note that the page-size is irrelevant and should be set to zero
200 * if the adjustment is used for a simple scalar value, e.g. in a
205 g_object_class_install_property (gobject_class,
207 g_param_spec_double ("page-size",
209 P_("The page size of the adjustment"),
213 G_PARAM_READWRITE | STATIC_STRINGS));
216 adjustment_signals[CHANGED] =
217 g_signal_new ("changed",
218 G_OBJECT_CLASS_TYPE (class),
219 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
220 G_STRUCT_OFFSET (GtkAdjustmentClass, changed),
222 _gtk_marshal_VOID__VOID,
224 adjustment_signals[VALUE_CHANGED] =
225 g_signal_new ("value_changed",
226 G_OBJECT_CLASS_TYPE (class),
227 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
228 G_STRUCT_OFFSET (GtkAdjustmentClass, value_changed),
230 _gtk_marshal_VOID__VOID,
235 gtk_adjustment_init (GtkAdjustment *adjustment)
237 adjustment->value = 0.0;
238 adjustment->lower = 0.0;
239 adjustment->upper = 0.0;
240 adjustment->step_increment = 0.0;
241 adjustment->page_increment = 0.0;
242 adjustment->page_size = 0.0;
246 gtk_adjustment_get_property (GObject *object, guint prop_id, GValue *value,
249 GtkAdjustment *adjustment = GTK_ADJUSTMENT (object);
254 g_value_set_double (value, adjustment->value);
257 g_value_set_double (value, adjustment->lower);
260 g_value_set_double (value, adjustment->upper);
262 case PROP_STEP_INCREMENT:
263 g_value_set_double (value, adjustment->step_increment);
265 case PROP_PAGE_INCREMENT:
266 g_value_set_double (value, adjustment->page_increment);
269 g_value_set_double (value, adjustment->page_size);
272 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
278 gtk_adjustment_set_property (GObject * object, guint prop_id,
279 const GValue * value, GParamSpec * pspec)
281 GtkAdjustment *adjustment = GTK_ADJUSTMENT (object);
282 gdouble double_value = g_value_get_double (value);
287 gtk_adjustment_set_value (GTK_ADJUSTMENT (object), double_value);
290 if (adjustment->lower != double_value)
292 adjustment->lower = double_value;
293 g_object_notify (G_OBJECT (adjustment), "lower");
297 if (adjustment->upper != double_value)
299 adjustment->upper = double_value;
300 g_object_notify (G_OBJECT (adjustment), "upper");
303 case PROP_STEP_INCREMENT:
304 if (adjustment->step_increment != double_value)
306 adjustment->step_increment = double_value;
307 g_object_notify (G_OBJECT (adjustment), "step-increment");
310 case PROP_PAGE_INCREMENT:
311 if (adjustment->page_increment != double_value)
313 adjustment->page_increment = double_value;
314 g_object_notify (G_OBJECT (adjustment), "page-increment");
318 if (adjustment->page_size != double_value)
320 adjustment->page_size = double_value;
321 g_object_notify (G_OBJECT (adjustment), "page-size");
325 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
331 gtk_adjustment_new (gdouble value,
334 gdouble step_increment,
335 gdouble page_increment,
338 return g_object_new (GTK_TYPE_ADJUSTMENT,
341 "step-increment", step_increment,
342 "page-increment", page_increment,
343 "page_size", page_size,
349 * gtk_adjustment_get_value:
350 * @adjustment: a #GtkAdjustment
352 * Gets the current value of the adjustment. See
353 * gtk_adjustment_set_value ().
355 * Return value: The current value of the adjustment.
358 gtk_adjustment_get_value (GtkAdjustment *adjustment)
360 g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), 0.);
362 return adjustment->value;
366 gtk_adjustment_set_value (GtkAdjustment *adjustment,
369 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
371 value = CLAMP (value, adjustment->lower, adjustment->upper);
373 if (value != adjustment->value)
375 adjustment->value = value;
377 gtk_adjustment_value_changed (adjustment);
382 gtk_adjustment_changed (GtkAdjustment *adjustment)
384 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
386 g_signal_emit (adjustment, adjustment_signals[CHANGED], 0);
390 gtk_adjustment_value_changed (GtkAdjustment *adjustment)
392 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
394 g_signal_emit (adjustment, adjustment_signals[VALUE_CHANGED], 0);
395 g_object_notify (G_OBJECT (adjustment), "value");
399 gtk_adjustment_clamp_page (GtkAdjustment *adjustment,
403 gboolean need_emission;
405 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
407 lower = CLAMP (lower, adjustment->lower, adjustment->upper);
408 upper = CLAMP (upper, adjustment->lower, adjustment->upper);
410 need_emission = FALSE;
412 if (adjustment->value + adjustment->page_size < upper)
414 adjustment->value = upper - adjustment->page_size;
415 need_emission = TRUE;
417 if (adjustment->value > lower)
419 adjustment->value = lower;
420 need_emission = TRUE;
424 gtk_adjustment_value_changed (adjustment);
427 #define __GTK_ADJUSTMENT_C__
428 #include "gtkaliasdef.c"