]> Pileus Git - ~andy/gtk/blob - gtk/gtkadjustment.c
made the <widget>_signals[] arrays of type guint rather than gint. made
[~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 Library 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  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the Free
16  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18 #include "gtkadjustment.h"
19 #include "gtksignal.h"
20
21
22 enum {
23   CHANGED,
24   VALUE_CHANGED,
25   LAST_SIGNAL
26 };
27
28
29 static void gtk_adjustment_class_init (GtkAdjustmentClass *klass);
30 static void gtk_adjustment_init       (GtkAdjustment      *adjustment);
31
32
33 static guint adjustment_signals[LAST_SIGNAL] = { 0 };
34
35
36 guint
37 gtk_adjustment_get_type ()
38 {
39   static guint adjustment_type = 0;
40
41   if (!adjustment_type)
42     {
43       GtkTypeInfo adjustment_info =
44       {
45         "GtkAdjustment",
46         sizeof (GtkAdjustment),
47         sizeof (GtkAdjustmentClass),
48         (GtkClassInitFunc) gtk_adjustment_class_init,
49         (GtkObjectInitFunc) gtk_adjustment_init,
50         (GtkArgSetFunc) NULL,
51         (GtkArgGetFunc) NULL,
52       };
53
54       adjustment_type = gtk_type_unique (gtk_data_get_type (), &adjustment_info);
55     }
56
57   return adjustment_type;
58 }
59
60 static void
61 gtk_adjustment_class_init (GtkAdjustmentClass *class)
62 {
63   GtkObjectClass *object_class;
64
65   object_class = (GtkObjectClass*) class;
66
67   adjustment_signals[CHANGED] =
68     gtk_signal_new ("changed",
69                     GTK_RUN_FIRST | GTK_RUN_NO_RECURSE,
70                     object_class->type,
71                     GTK_SIGNAL_OFFSET (GtkAdjustmentClass, changed),
72                     gtk_signal_default_marshaller,
73                     GTK_TYPE_NONE, 0);
74   adjustment_signals[VALUE_CHANGED] =
75     gtk_signal_new ("value_changed",
76                     GTK_RUN_FIRST | GTK_RUN_NO_RECURSE,
77                     object_class->type,
78                     GTK_SIGNAL_OFFSET (GtkAdjustmentClass, value_changed),
79                     gtk_signal_default_marshaller,
80                     GTK_TYPE_NONE, 0);
81
82   gtk_object_class_add_signals (object_class, adjustment_signals, LAST_SIGNAL);
83
84   class->changed = NULL;
85   class->value_changed = NULL;
86 }
87
88 static void
89 gtk_adjustment_init (GtkAdjustment *adjustment)
90 {
91   adjustment->value = 0.0;
92   adjustment->lower = 0.0;
93   adjustment->upper = 0.0;
94   adjustment->step_increment = 0.0;
95   adjustment->page_increment = 0.0;
96   adjustment->page_size = 0.0;
97 }
98
99 GtkObject*
100 gtk_adjustment_new (gfloat value,
101                     gfloat lower,
102                     gfloat upper,
103                     gfloat step_increment,
104                     gfloat page_increment,
105                     gfloat page_size)
106 {
107   GtkAdjustment *adjustment;
108
109   adjustment = gtk_type_new (gtk_adjustment_get_type ());
110
111   adjustment->value = value;
112   adjustment->lower = lower;
113   adjustment->upper = upper;
114   adjustment->step_increment = step_increment;
115   adjustment->page_increment = page_increment;
116   adjustment->page_size = page_size;
117
118   return GTK_OBJECT (adjustment);
119 }
120
121 void
122 gtk_adjustment_set_value (GtkAdjustment        *adjustment,
123                           gfloat                value)
124 {
125   g_return_if_fail (adjustment != NULL);
126   g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
127
128   adjustment->value = CLAMP (value, adjustment->lower, adjustment->upper);
129
130   gtk_signal_emit_by_name (GTK_OBJECT (adjustment), "value_changed");
131 }