2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD 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
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = GtkAdjustment.html
27 * outFile = Adjustment
28 * strct = GtkAdjustment
47 * - GtkObject* -> ObjectGtk
52 module gtk
.Adjustment
;
58 import tango
.io
.Stdout
; // use the tango loging?
62 private import gtkc
.gtktypes
;
64 private import gtkc
.gtk
;
67 private import gtk
.ObjectGtk
;
74 * The GtkAdjustment object represents a value which has an associated lower
75 * and upper bound, together with step and page increments, and a page size.
76 * It is used within several GTK+ widgets, including
77 * GtkSpinButton, GtkViewport, and GtkRange (which is a base class for
78 * GtkHScrollbar, GtkVScrollbar, GtkHScale, and GtkVScale).
79 * The GtkAdjustment object does not update the value itself. Instead
80 * it is left up to the owner of the GtkAdjustment to control the value.
81 * The owner of the GtkAdjustment typically calls the
82 * gtk_adjustment_value_changed() and gtk_adjustment_changed() functions
83 * after changing the value and its bounds. This results in the emission of the
84 * "value_changed" or "changed" signal respectively.
86 * The values in a GtkAdjustment are stored as double precision floating point values.
87 * More about the different floating point types can be found in the corresponding
88 * IEEE Floating Point Standard.
89 * In most GtkAdjustment applications, the value member contains a computed number, for instance because
90 * the adjustment is updated by a GtkSpinButton or GtkRange widget which assign adjustment values based
91 * on computations which use user input with pixel precision.
92 * When floats/doubles are computed, they almost never represent the exact number wanted or needed,
93 * but only an approximation of the real value, because floating point numbers are approximations of
94 * real numbers by design (needed to represent infinite precision numbers in a finite number of memory cells).
95 * In the case of a range, spin button or similar widget where the current value is represented by a
96 * floating point number (i.e. an inexact approximation of the real value needed),
97 * adjustment->upper and adjustment->lower may or may not be represented exactly in adjustment->value,
98 * depending on the implementation.
99 * That means, even if a spinner or range looks like it represents adjustment->lower or
100 * adjustment->upper in the graphical display, the actual adjustment->value may very well be off
101 * by a small number (epsilon) that corresponds to ca. half a pixel at the GUI.
102 * To compensate for such boundary cases accurately in user code, additional logic may be required, for instance:
103 * Example1.Epsilon comparison for adjustments
104 * /+* retrieve a computed floating point value +/
105 * double myval = gtk_spin_button_get_value (spinner);
106 * double myval = gtk_range_get_value (range);
107 * double myval = gtk_progress_get_value (progress_widget);
108 * double myval = gtk_adjustment_get_value (adjustment);
109 * /+* adjust for border cases, assuming a screen resolution < 65536 pixels +/
110 * const double epsilon = 0.0000152587890625; /+* 1.0 / 2^16 +/
111 * if (fabs (myval - adjustment->lower) < epsilon)
112 * myval = adjustment->lower;
113 * if (fabs (myval - (adjustment->upper - adjustment->page_size)) < epsilon)
114 * myval = adjustment->upper - adjustment->page_size;
115 * While this compensation code makes some more implicit assumptions,
116 * like the range (adjustment->upper - adjustment->lower) not being significantly smaller than
117 * 1 and only being a few magnitudes larger than the amount of pixels on screen,
118 * and while all code that deals with floating point numbers always warrants a detailed precision
119 * analysis, it should work out well in practice for the vast majority of cases in Gtk+ and uses
120 * of adjustment->value in Gtk+ applications.
121 * But as mentioned, there are more issues that need to be taken care of when dealing with
122 * floating point numbers.
123 * Many of those are addressed by books like Numerical Recipes in C,
124 * in particular the chapter
125 * 1.3 Error, Accuracy, and Stability
126 * is a highly recommended read.
127 * And a further recommended reading is the paper
128 * What Every Computer Scientist Should Know About Floating-Point Arithmetic.
130 private import gtk
.ObjectGtk
;
131 public class Adjustment
: ObjectGtk
134 /** the main Gtk struct */
135 protected GtkAdjustment
* gtkAdjustment
;
138 public GtkAdjustment
* getAdjustmentStruct()
140 return gtkAdjustment
;
144 /** the main Gtk struct as a void* */
145 protected void* getStruct()
147 return cast(void*)gtkAdjustment
;
151 * Sets our main struct and passes it to the parent class
153 public this (GtkAdjustment
* gtkAdjustment
)
157 if ( gtkAdjustment
is null )
162 Stdout("struct gtkAdjustment is null on constructor").newline
;
166 printf("struct gtkAdjustment is null on constructor");
173 assert(gtkAdjustment
!is null, "struct gtkAdjustment is null on constructor");
175 super(cast(GtkObject
*)gtkAdjustment
);
176 this.gtkAdjustment
= gtkAdjustment
;
182 // imports for the signal processing
183 private import gobject
.Signals
;
184 private import gtkc
.gdktypes
;
185 int[char[]] connectedSignals
;
187 void delegate(Adjustment
)[] onChangedListeners
;
188 void addOnChanged(void delegate(Adjustment
) dlg
, ConnectFlags connectFlags
=cast(ConnectFlags
)0)
190 if ( !("changed" in connectedSignals
) )
195 cast(GCallback
)&callBackChanged
,
199 connectedSignals
["changed"] = 1;
201 onChangedListeners
~= dlg
;
203 extern(C
) static void callBackChanged(GtkAdjustment
* adjustmentStruct
, Adjustment adjustment
)
205 bool consumed
= false;
207 foreach ( void delegate(Adjustment
) dlg
; adjustment
.onChangedListeners
)
215 void delegate(Adjustment
)[] onValueChangedListeners
;
216 void addOnValueChanged(void delegate(Adjustment
) dlg
, ConnectFlags connectFlags
=cast(ConnectFlags
)0)
218 if ( !("value-changed" in connectedSignals
) )
223 cast(GCallback
)&callBackValueChanged
,
227 connectedSignals
["value-changed"] = 1;
229 onValueChangedListeners
~= dlg
;
231 extern(C
) static void callBackValueChanged(GtkAdjustment
* adjustmentStruct
, Adjustment adjustment
)
233 bool consumed
= false;
235 foreach ( void delegate(Adjustment
) dlg
; adjustment
.onValueChangedListeners
)
246 * Creates a new GtkAdjustment.
254 * the step increment.
256 * the page increment.
260 * a new GtkAdjustment.
262 public this (double value
, double lower
, double upper
, double stepIncrement
, double pageIncrement
, double pageSize
)
264 // GtkObject* gtk_adjustment_new (gdouble value, gdouble lower, gdouble upper, gdouble step_increment, gdouble page_increment, gdouble page_size);
265 this(cast(GtkAdjustment
*)gtk_adjustment_new(value
, lower
, upper
, stepIncrement
, pageIncrement
, pageSize
) );
269 * Gets the current value of the adjustment. See
270 * gtk_adjustment_set_value().
274 * The current value of the adjustment.
276 public double getValue()
278 // gdouble gtk_adjustment_get_value (GtkAdjustment *adjustment);
279 return gtk_adjustment_get_value(gtkAdjustment
);
283 * Sets the GtkAdjustment value. The value is clamped to lie between
284 * adjustment->lower and
286 * Note that for adjustments which are used in a GtkScrollbar, the effective
287 * range of allowed values goes from adjustment->lower to
288 * adjustment->upper - adjustment->page_size.
294 public void setValue(double value
)
296 // void gtk_adjustment_set_value (GtkAdjustment *adjustment, gdouble value);
297 gtk_adjustment_set_value(gtkAdjustment
, value
);
301 * Updates the GtkAdjustment value to ensure that the range between lower
302 * and upper is in the current page (i.e. between value and value +
304 * If the range is larger than the page size, then only the start of it will
305 * be in the current page.
306 * A "changed" signal will be emitted if the value is changed.
314 public void clampPage(double lower
, double upper
)
316 // void gtk_adjustment_clamp_page (GtkAdjustment *adjustment, gdouble lower, gdouble upper);
317 gtk_adjustment_clamp_page(gtkAdjustment
, lower
, upper
);
321 * Emits a "changed" signal from the GtkAdjustment.
322 * This is typically called by the owner of the GtkAdjustment after it has
323 * changed any of the GtkAdjustment fields other than the value.
327 public void changed()
329 // void gtk_adjustment_changed (GtkAdjustment *adjustment);
330 gtk_adjustment_changed(gtkAdjustment
);
334 * Emits a "value_changed" signal from the GtkAdjustment.
335 * This is typically called by the owner of the GtkAdjustment after it has
336 * changed the GtkAdjustment value field.
340 * The "lower" property
341 * "lower" gdouble : Read / Write
342 * The minimum value of the adjustment.
346 public void valueChanged()
348 // void gtk_adjustment_value_changed (GtkAdjustment *adjustment);
349 gtk_adjustment_value_changed(gtkAdjustment
);