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"
28 #include "gtkmarshalers.h"
38 static void gtk_adjustment_class_init (GtkAdjustmentClass *klass);
39 static void gtk_adjustment_init (GtkAdjustment *adjustment);
42 static guint adjustment_signals[LAST_SIGNAL] = { 0 };
46 gtk_adjustment_get_type (void)
48 static GType adjustment_type = 0;
52 static const GTypeInfo adjustment_info =
54 sizeof (GtkAdjustmentClass),
56 NULL, /* base_finalize */
57 (GClassInitFunc) gtk_adjustment_class_init,
58 NULL, /* class_finalize */
59 NULL, /* class_data */
60 sizeof (GtkAdjustment),
62 (GInstanceInitFunc) gtk_adjustment_init,
66 g_type_register_static (GTK_TYPE_OBJECT, "GtkAdjustment",
70 return adjustment_type;
74 gtk_adjustment_class_init (GtkAdjustmentClass *class)
76 class->changed = NULL;
77 class->value_changed = NULL;
79 adjustment_signals[CHANGED] =
80 g_signal_new ("changed",
81 G_OBJECT_CLASS_TYPE (class),
82 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
83 G_STRUCT_OFFSET (GtkAdjustmentClass, changed),
85 _gtk_marshal_VOID__VOID,
87 adjustment_signals[VALUE_CHANGED] =
88 g_signal_new ("value_changed",
89 G_OBJECT_CLASS_TYPE (class),
90 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
91 G_STRUCT_OFFSET (GtkAdjustmentClass, value_changed),
93 _gtk_marshal_VOID__VOID,
98 gtk_adjustment_init (GtkAdjustment *adjustment)
100 adjustment->value = 0.0;
101 adjustment->lower = 0.0;
102 adjustment->upper = 0.0;
103 adjustment->step_increment = 0.0;
104 adjustment->page_increment = 0.0;
105 adjustment->page_size = 0.0;
109 gtk_adjustment_new (gdouble value,
112 gdouble step_increment,
113 gdouble page_increment,
116 GtkAdjustment *adjustment;
118 adjustment = g_object_new (GTK_TYPE_ADJUSTMENT, NULL);
120 adjustment->value = value;
121 adjustment->lower = lower;
122 adjustment->upper = upper;
123 adjustment->step_increment = step_increment;
124 adjustment->page_increment = page_increment;
125 adjustment->page_size = page_size;
127 return GTK_OBJECT (adjustment);
131 * gtk_adjustment_get_value:
132 * @adjustment: a #GtkAdjustment
134 * Gets the current value of the adjustment. See
135 * gtk_adjustment_set_value ().
137 * Return value: The current value of the adjustment.
140 gtk_adjustment_get_value (GtkAdjustment *adjustment)
142 g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), 0.);
144 return adjustment->value;
148 gtk_adjustment_set_value (GtkAdjustment *adjustment,
151 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
153 value = CLAMP (value, adjustment->lower, adjustment->upper);
155 if (value != adjustment->value)
157 adjustment->value = value;
159 gtk_adjustment_value_changed (adjustment);
164 gtk_adjustment_changed (GtkAdjustment *adjustment)
166 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
168 g_signal_emit (adjustment, adjustment_signals[CHANGED], 0);
172 gtk_adjustment_value_changed (GtkAdjustment *adjustment)
174 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
176 g_signal_emit (adjustment, adjustment_signals[VALUE_CHANGED], 0);
180 gtk_adjustment_clamp_page (GtkAdjustment *adjustment,
184 gboolean need_emission;
186 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
188 lower = CLAMP (lower, adjustment->lower, adjustment->upper);
189 upper = CLAMP (upper, adjustment->lower, adjustment->upper);
191 need_emission = FALSE;
193 if (adjustment->value + adjustment->page_size < upper)
195 adjustment->value = upper - adjustment->page_size;
196 need_emission = TRUE;
198 if (adjustment->value > lower)
200 adjustment->value = lower;
201 need_emission = TRUE;
205 gtk_adjustment_value_changed (adjustment);