[14481] | 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 |
---|
| 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-1999. 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_DATA, &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 | adjustment_signals[CHANGED] = |
---|
| 78 | gtk_signal_new ("changed", |
---|
| 79 | GTK_RUN_FIRST | GTK_RUN_NO_RECURSE, |
---|
| 80 | object_class->type, |
---|
| 81 | GTK_SIGNAL_OFFSET (GtkAdjustmentClass, changed), |
---|
| 82 | gtk_marshal_NONE__NONE, |
---|
| 83 | GTK_TYPE_NONE, 0); |
---|
| 84 | adjustment_signals[VALUE_CHANGED] = |
---|
| 85 | gtk_signal_new ("value_changed", |
---|
| 86 | GTK_RUN_FIRST | GTK_RUN_NO_RECURSE, |
---|
| 87 | object_class->type, |
---|
| 88 | GTK_SIGNAL_OFFSET (GtkAdjustmentClass, value_changed), |
---|
| 89 | gtk_marshal_NONE__NONE, |
---|
| 90 | GTK_TYPE_NONE, 0); |
---|
| 91 | |
---|
| 92 | gtk_object_class_add_signals (object_class, adjustment_signals, LAST_SIGNAL); |
---|
| 93 | |
---|
| 94 | class->changed = NULL; |
---|
| 95 | class->value_changed = NULL; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | static void |
---|
| 99 | gtk_adjustment_init (GtkAdjustment *adjustment) |
---|
| 100 | { |
---|
| 101 | adjustment->value = 0.0; |
---|
| 102 | adjustment->lower = 0.0; |
---|
| 103 | adjustment->upper = 0.0; |
---|
| 104 | adjustment->step_increment = 0.0; |
---|
| 105 | adjustment->page_increment = 0.0; |
---|
| 106 | adjustment->page_size = 0.0; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | GtkObject* |
---|
| 110 | gtk_adjustment_new (gfloat value, |
---|
| 111 | gfloat lower, |
---|
| 112 | gfloat upper, |
---|
| 113 | gfloat step_increment, |
---|
| 114 | gfloat page_increment, |
---|
| 115 | gfloat page_size) |
---|
| 116 | { |
---|
| 117 | GtkAdjustment *adjustment; |
---|
| 118 | |
---|
| 119 | adjustment = gtk_type_new (gtk_adjustment_get_type ()); |
---|
| 120 | |
---|
| 121 | adjustment->value = value; |
---|
| 122 | adjustment->lower = lower; |
---|
| 123 | adjustment->upper = upper; |
---|
| 124 | adjustment->step_increment = step_increment; |
---|
| 125 | adjustment->page_increment = page_increment; |
---|
| 126 | adjustment->page_size = page_size; |
---|
| 127 | |
---|
| 128 | return GTK_OBJECT (adjustment); |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | void |
---|
| 132 | gtk_adjustment_set_value (GtkAdjustment *adjustment, |
---|
| 133 | gfloat value) |
---|
| 134 | { |
---|
| 135 | g_return_if_fail (adjustment != NULL); |
---|
| 136 | g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment)); |
---|
| 137 | |
---|
| 138 | value = CLAMP (value, adjustment->lower, adjustment->upper); |
---|
| 139 | |
---|
| 140 | if (value != adjustment->value) |
---|
| 141 | { |
---|
| 142 | adjustment->value = value; |
---|
| 143 | |
---|
| 144 | gtk_adjustment_value_changed (adjustment); |
---|
| 145 | } |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | void |
---|
| 149 | gtk_adjustment_changed (GtkAdjustment *adjustment) |
---|
| 150 | { |
---|
| 151 | g_return_if_fail (adjustment != NULL); |
---|
| 152 | g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment)); |
---|
| 153 | |
---|
| 154 | gtk_signal_emit (GTK_OBJECT (adjustment), adjustment_signals[CHANGED]); |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | void |
---|
| 158 | gtk_adjustment_value_changed (GtkAdjustment *adjustment) |
---|
| 159 | { |
---|
| 160 | g_return_if_fail (adjustment != NULL); |
---|
| 161 | g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment)); |
---|
| 162 | |
---|
| 163 | gtk_signal_emit (GTK_OBJECT (adjustment), adjustment_signals[VALUE_CHANGED]); |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | void |
---|
| 167 | gtk_adjustment_clamp_page (GtkAdjustment *adjustment, |
---|
| 168 | gfloat lower, |
---|
| 169 | gfloat upper) |
---|
| 170 | { |
---|
| 171 | gint need_emission; |
---|
| 172 | |
---|
| 173 | g_return_if_fail (adjustment != NULL); |
---|
| 174 | g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment)); |
---|
| 175 | |
---|
| 176 | lower = CLAMP (lower, adjustment->lower, adjustment->upper); |
---|
| 177 | upper = CLAMP (upper, adjustment->lower, adjustment->upper); |
---|
| 178 | |
---|
| 179 | need_emission = FALSE; |
---|
| 180 | |
---|
| 181 | if (adjustment->value + adjustment->page_size < upper) |
---|
| 182 | { |
---|
| 183 | adjustment->value = upper - adjustment->page_size; |
---|
| 184 | need_emission = TRUE; |
---|
| 185 | } |
---|
| 186 | if (adjustment->value > lower) |
---|
| 187 | { |
---|
| 188 | adjustment->value = lower; |
---|
| 189 | need_emission = TRUE; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | if (need_emission) |
---|
| 193 | gtk_adjustment_value_changed (adjustment); |
---|
| 194 | } |
---|