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"
29 #include "gtksignal.h"
39 static void gtk_adjustment_class_init (GtkAdjustmentClass *klass);
40 static void gtk_adjustment_init (GtkAdjustment *adjustment);
43 static guint adjustment_signals[LAST_SIGNAL] = { 0 };
47 gtk_adjustment_get_type (void)
49 static GtkType adjustment_type = 0;
53 static const GtkTypeInfo adjustment_info =
56 sizeof (GtkAdjustment),
57 sizeof (GtkAdjustmentClass),
58 (GtkClassInitFunc) gtk_adjustment_class_init,
59 (GtkObjectInitFunc) gtk_adjustment_init,
60 /* reserved_1 */ NULL,
61 /* reserved_2 */ NULL,
62 (GtkClassInitFunc) NULL,
65 adjustment_type = gtk_type_unique (GTK_TYPE_OBJECT, &adjustment_info);
68 return adjustment_type;
72 gtk_adjustment_class_init (GtkAdjustmentClass *class)
74 GtkObjectClass *object_class;
76 object_class = (GtkObjectClass*) class;
78 class->changed = NULL;
79 class->value_changed = NULL;
81 adjustment_signals[CHANGED] =
82 gtk_signal_new ("changed",
83 GTK_RUN_FIRST | GTK_RUN_NO_RECURSE,
84 GTK_CLASS_TYPE (object_class),
85 GTK_SIGNAL_OFFSET (GtkAdjustmentClass, changed),
86 _gtk_marshal_VOID__VOID,
88 adjustment_signals[VALUE_CHANGED] =
89 gtk_signal_new ("value_changed",
90 GTK_RUN_FIRST | GTK_RUN_NO_RECURSE,
91 GTK_CLASS_TYPE (object_class),
92 GTK_SIGNAL_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 = gtk_type_new (gtk_adjustment_get_type ());
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 gtk_signal_emit (GTK_OBJECT (adjustment), adjustment_signals[CHANGED]);
172 gtk_adjustment_value_changed (GtkAdjustment *adjustment)
174 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
176 gtk_signal_emit (GTK_OBJECT (adjustment), adjustment_signals[VALUE_CHANGED]);
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);