]> Pileus Git - ~andy/gtk/blob - gtk/gtkadjustment.c
Handle quoting of / with \; properly handle __ in paths, quote " and \n in
[~andy/gtk] / gtk / gtkadjustment.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 /*
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/. 
25  */
26
27 #include "gtkadjustment.h"
28 #include "gtksignal.h"
29
30
31 enum {
32   CHANGED,
33   VALUE_CHANGED,
34   LAST_SIGNAL
35 };
36
37
38 static void gtk_adjustment_class_init (GtkAdjustmentClass *klass);
39 static void gtk_adjustment_init       (GtkAdjustment      *adjustment);
40
41
42 static guint adjustment_signals[LAST_SIGNAL] = { 0 };
43
44
45 GtkType
46 gtk_adjustment_get_type (void)
47 {
48   static GtkType adjustment_type = 0;
49
50   if (!adjustment_type)
51     {
52       static const GtkTypeInfo adjustment_info =
53       {
54         "GtkAdjustment",
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,
62       };
63
64       adjustment_type = gtk_type_unique (GTK_TYPE_OBJECT, &adjustment_info);
65     }
66
67   return adjustment_type;
68 }
69
70 static void
71 gtk_adjustment_class_init (GtkAdjustmentClass *class)
72 {
73   GtkObjectClass *object_class;
74
75   object_class = (GtkObjectClass*) class;
76
77   class->changed = NULL;
78   class->value_changed = NULL;
79
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,
86                     GTK_TYPE_NONE, 0);
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,
93                     GTK_TYPE_NONE, 0);
94 }
95
96 static void
97 gtk_adjustment_init (GtkAdjustment *adjustment)
98 {
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;
105 }
106
107 GtkObject*
108 gtk_adjustment_new (gdouble value,
109                     gdouble lower,
110                     gdouble upper,
111                     gdouble step_increment,
112                     gdouble page_increment,
113                     gdouble page_size)
114 {
115   GtkAdjustment *adjustment;
116
117   adjustment = gtk_type_new (gtk_adjustment_get_type ());
118
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;
125
126   return GTK_OBJECT (adjustment);
127 }
128
129 void
130 gtk_adjustment_set_value (GtkAdjustment        *adjustment,
131                           gdouble               value)
132 {
133   g_return_if_fail (adjustment != NULL);
134   g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
135
136   value = CLAMP (value, adjustment->lower, adjustment->upper);
137
138   if (value != adjustment->value)
139     {
140       adjustment->value = value;
141
142       gtk_adjustment_value_changed (adjustment);
143     }
144 }
145
146 void
147 gtk_adjustment_changed (GtkAdjustment        *adjustment)
148 {
149   g_return_if_fail (adjustment != NULL);
150   g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
151
152   gtk_signal_emit (GTK_OBJECT (adjustment), adjustment_signals[CHANGED]);
153 }
154
155 void
156 gtk_adjustment_value_changed (GtkAdjustment        *adjustment)
157 {
158   g_return_if_fail (adjustment != NULL);
159   g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
160
161   gtk_signal_emit (GTK_OBJECT (adjustment), adjustment_signals[VALUE_CHANGED]);
162 }
163
164 void
165 gtk_adjustment_clamp_page (GtkAdjustment *adjustment,
166                            gdouble        lower,
167                            gdouble        upper)
168 {
169   gboolean need_emission;
170
171   g_return_if_fail (adjustment != NULL);
172   g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
173
174   lower = CLAMP (lower, adjustment->lower, adjustment->upper);
175   upper = CLAMP (upper, adjustment->lower, adjustment->upper);
176
177   need_emission = FALSE;
178
179   if (adjustment->value + adjustment->page_size < upper)
180     {
181       adjustment->value = upper - adjustment->page_size;
182       need_emission = TRUE;
183     }
184   if (adjustment->value > lower)
185     {
186       adjustment->value = lower;
187       need_emission = TRUE;
188     }
189
190   if (need_emission)
191     gtk_adjustment_value_changed (adjustment);
192 }