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 "gtksignal.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 GtkType adjustment_type = 0;
52 static const GtkTypeInfo adjustment_info =
55 sizeof (GtkAdjustment),
56 sizeof (GtkAdjustmentClass),
57 (GtkClassInitFunc) gtk_adjustment_class_init,
58 (GtkObjectInitFunc) gtk_adjustment_init,
59 /* reserved_1 */ NULL,
60 /* reserved_2 */ NULL,
61 (GtkClassInitFunc) NULL,
64 adjustment_type = gtk_type_unique (GTK_TYPE_OBJECT, &adjustment_info);
67 return adjustment_type;
71 gtk_adjustment_class_init (GtkAdjustmentClass *class)
73 GtkObjectClass *object_class;
75 object_class = (GtkObjectClass*) class;
77 class->changed = NULL;
78 class->value_changed = NULL;
80 adjustment_signals[CHANGED] =
81 gtk_signal_new ("changed",
82 GTK_RUN_FIRST | GTK_RUN_NO_RECURSE,
83 GTK_CLASS_TYPE (object_class),
84 GTK_SIGNAL_OFFSET (GtkAdjustmentClass, changed),
85 gtk_marshal_VOID__VOID,
87 adjustment_signals[VALUE_CHANGED] =
88 gtk_signal_new ("value_changed",
89 GTK_RUN_FIRST | GTK_RUN_NO_RECURSE,
90 GTK_CLASS_TYPE (object_class),
91 GTK_SIGNAL_OFFSET (GtkAdjustmentClass, value_changed),
92 gtk_marshal_VOID__VOID,
97 gtk_adjustment_init (GtkAdjustment *adjustment)
99 adjustment->value = 0.0;
100 adjustment->lower = 0.0;
101 adjustment->upper = 0.0;
102 adjustment->step_increment = 0.0;
103 adjustment->page_increment = 0.0;
104 adjustment->page_size = 0.0;
108 gtk_adjustment_new (gdouble value,
111 gdouble step_increment,
112 gdouble page_increment,
115 GtkAdjustment *adjustment;
117 adjustment = gtk_type_new (gtk_adjustment_get_type ());
119 adjustment->value = value;
120 adjustment->lower = lower;
121 adjustment->upper = upper;
122 adjustment->step_increment = step_increment;
123 adjustment->page_increment = page_increment;
124 adjustment->page_size = page_size;
126 return GTK_OBJECT (adjustment);
130 gtk_adjustment_set_value (GtkAdjustment *adjustment,
133 g_return_if_fail (adjustment != NULL);
134 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
136 value = CLAMP (value, adjustment->lower, adjustment->upper);
138 if (value != adjustment->value)
140 adjustment->value = value;
142 gtk_adjustment_value_changed (adjustment);
147 gtk_adjustment_changed (GtkAdjustment *adjustment)
149 g_return_if_fail (adjustment != NULL);
150 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
152 gtk_signal_emit (GTK_OBJECT (adjustment), adjustment_signals[CHANGED]);
156 gtk_adjustment_value_changed (GtkAdjustment *adjustment)
158 g_return_if_fail (adjustment != NULL);
159 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
161 gtk_signal_emit (GTK_OBJECT (adjustment), adjustment_signals[VALUE_CHANGED]);
165 gtk_adjustment_clamp_page (GtkAdjustment *adjustment,
169 gboolean need_emission;
171 g_return_if_fail (adjustment != NULL);
172 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
174 lower = CLAMP (lower, adjustment->lower, adjustment->upper);
175 upper = CLAMP (upper, adjustment->lower, adjustment->upper);
177 need_emission = FALSE;
179 if (adjustment->value + adjustment->page_size < upper)
181 adjustment->value = upper - adjustment->page_size;
182 need_emission = TRUE;
184 if (adjustment->value > lower)
186 adjustment->value = lower;
187 need_emission = TRUE;
191 gtk_adjustment_value_changed (adjustment);