alternative to assert
[gtkD.git] / src / gtk / SpinButton.d
blob28895da400421d1079dce3629a3e260f2d886c43
1 /*
2 * This file is part of duit.
4 * duit 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 * duit 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 duit; 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 = GtkSpinButton.html
26 * outPack = gtk
27 * outFile = SpinButton
28 * strct = GtkSpinButton
29 * realStrct=
30 * ctorStrct=
31 * clss = SpinButton
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - gtk_spin_button_
40 * - gtk_
41 * omit structs:
42 * omit prefixes:
43 * omit code:
44 * imports:
45 * - gtk.Widget
46 * - gtk.Adjustment
47 * structWrap:
48 * - GtkAdjustment* -> Adjustment
49 * - GtkWidget* -> Widget
50 * local aliases:
53 module gtk.SpinButton;
55 private import gtk.gtktypes;
57 private import lib.gtk;
59 private import gtk.Widget;
60 private import gtk.Adjustment;
62 /**
63 * Description
64 * A GtkSpinButton is an ideal way to allow the user to set the value of some
65 * attribute. Rather than having to directly type a number into a GtkEntry,
66 * GtkSpinButton allows the user to click on one of two arrows to increment or
67 * decrement the displayed value. A value can still be typed in, with the bonus
68 * that it can be checked to ensure it is in a given range.
69 * The main properties of a GtkSpinButton are through a GtkAdjustment. See the
70 * GtkAdjustment section for more details about an adjustment's properties.
71 * Example1.Using a GtkSpinButton to get an integer.
72 * /+* Provides a function to retrieve an integer value from a GtkSpinButton
73 * * and creates a spin button to model percentage values.
74 * +/
75 * gint grab_int_value (GtkSpinButton *a_spinner, gpointer user_data) {
76 * return gtk_spin_button_get_value_as_int (a_spinner);
77 * }
78 * void create_integer_spin_button (void) {
79 * GtkWidget *window, *spinner;
80 * GtkAdjustment *spinner_adj;
81 * spinner_adj = (GtkAdjustment *) gtk_adjustment_new (50.0, 0.0, 100.0, 1.0, 5.0, 5.0);
82 * window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
83 * gtk_container_set_border_width (GTK_CONTAINER (window), 5);
84 * /+* creates the spinner, with no decimal places +/
85 * spinner = gtk_spin_button_new (spinner_adj, 1.0, 0);
86 * gtk_container_add (GTK_CONTAINER (window), spinner);
87 * gtk_widget_show_all (window);
88 * return;
89 * }
90 * Example2.Using a GtkSpinButton to get a floating point value.
91 * /+* Provides a function to retrieve a floating point value from a
92 * * GtkSpinButton, and creates a high precision spin button.
93 * +/
94 * gfloat grab_int_value (GtkSpinButton *a_spinner, gpointer user_data) {
95 * return gtk_spin_button_get_value (a_spinner);
96 * }
97 * void create_floating_spin_button (void) {
98 * GtkWidget *window, *spinner;
99 * GtkAdjustment *spinner_adj;
100 * spinner_adj = (GtkAdjustment *) gtk_adjustment_new (2.500, 0.0, 5.0, 0.001, 0.1, 0.1);
101 * window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
102 * gtk_container_set_border_width (GTK_CONTAINER (window), 5);
103 * /+* creates the spinner, with three decimal places +/
104 * spinner = gtk_spin_button_new (spinner_adj, 0.001, 3);
105 * gtk_container_add (GTK_CONTAINER (window), spinner);
106 * gtk_widget_show_all (window);
107 * return;
110 private import gtk.Entry;
111 public class SpinButton : Entry
114 /** the main Gtk struct */
115 protected GtkSpinButton* gtkSpinButton;
118 public GtkSpinButton* getSpinButtonStruct()
120 return gtkSpinButton;
124 /** the main Gtk struct as a void* */
125 protected void* getStruct()
127 return cast(void*)gtkSpinButton;
131 * Sets our main struct and passes it to the parent class
133 public this (GtkSpinButton* gtkSpinButton)
135 super(cast(GtkEntry*)gtkSpinButton);
136 this.gtkSpinButton = gtkSpinButton;
142 // imports for the signal processing
143 private import gobject.Signals;
144 private import gdk.gdktypes;
145 int[char[]] connectedSignals;
147 void delegate(GtkScrollType, SpinButton)[] onChangeValueListeners;
148 void addOnChangeValue(void delegate(GtkScrollType, SpinButton) dlg)
150 if ( !("change-value" in connectedSignals) )
152 Signals.connectData(
153 getStruct(),
154 "change-value",
155 cast(GCallback)&callBackChangeValue,
156 this,
157 null,
158 cast(ConnectFlags)0);
159 connectedSignals["change-value"] = 1;
161 onChangeValueListeners ~= dlg;
163 extern(C) static void callBackChangeValue(GtkSpinButton* spinbuttonStruct, GtkScrollType arg1, SpinButton spinButton)
165 bit consumed = false;
167 foreach ( void delegate(GtkScrollType, SpinButton) dlg ; spinButton.onChangeValueListeners )
169 dlg(arg1, spinButton);
172 return consumed;
175 gint delegate(gpointer, SpinButton)[] onInputListeners;
176 void addOnInput(gint delegate(gpointer, SpinButton) dlg)
178 if ( !("input" in connectedSignals) )
180 Signals.connectData(
181 getStruct(),
182 "input",
183 cast(GCallback)&callBackInput,
184 this,
185 null,
186 cast(ConnectFlags)0);
187 connectedSignals["input"] = 1;
189 onInputListeners ~= dlg;
191 extern(C) static void callBackInput(GtkSpinButton* spinbuttonStruct, gpointer arg1, SpinButton spinButton)
193 bit consumed = false;
195 foreach ( gint delegate(gpointer, SpinButton) dlg ; spinButton.onInputListeners )
197 dlg(arg1, spinButton);
200 return consumed;
203 gboolean delegate(SpinButton)[] onOutputListeners;
204 void addOnOutput(gboolean delegate(SpinButton) dlg)
206 if ( !("output" in connectedSignals) )
208 Signals.connectData(
209 getStruct(),
210 "output",
211 cast(GCallback)&callBackOutput,
212 this,
213 null,
214 cast(ConnectFlags)0);
215 connectedSignals["output"] = 1;
217 onOutputListeners ~= dlg;
219 extern(C) static void callBackOutput(GtkSpinButton* spinbuttonStruct, SpinButton spinButton)
221 bit consumed = false;
223 foreach ( gboolean delegate(SpinButton) dlg ; spinButton.onOutputListeners )
225 dlg(spinButton);
228 return consumed;
231 void delegate(SpinButton)[] onValueChangedListeners;
232 void addOnValueChanged(void delegate(SpinButton) dlg)
234 if ( !("value-changed" in connectedSignals) )
236 Signals.connectData(
237 getStruct(),
238 "value-changed",
239 cast(GCallback)&callBackValueChanged,
240 this,
241 null,
242 cast(ConnectFlags)0);
243 connectedSignals["value-changed"] = 1;
245 onValueChangedListeners ~= dlg;
247 extern(C) static void callBackValueChanged(GtkSpinButton* spinbuttonStruct, SpinButton spinButton)
249 bit consumed = false;
251 foreach ( void delegate(SpinButton) dlg ; spinButton.onValueChangedListeners )
253 dlg(spinButton);
256 return consumed;
259 void delegate(SpinButton)[] onWrappedListeners;
260 void addOnWrapped(void delegate(SpinButton) dlg)
262 if ( !("wrapped" in connectedSignals) )
264 Signals.connectData(
265 getStruct(),
266 "wrapped",
267 cast(GCallback)&callBackWrapped,
268 this,
269 null,
270 cast(ConnectFlags)0);
271 connectedSignals["wrapped"] = 1;
273 onWrappedListeners ~= dlg;
275 extern(C) static void callBackWrapped(GtkSpinButton* spinbuttonStruct, SpinButton spinButton)
277 bit consumed = false;
279 foreach ( void delegate(SpinButton) dlg ; spinButton.onWrappedListeners )
281 dlg(spinButton);
284 return consumed;
292 * Changes the properties of an existing spin button. The adjustment, climb rate, and number of decimal places are all changed accordingly, after this function call.
293 * spin_button:
294 * a GtkSpinButton.
295 * adjustment:
296 * a GtkAdjustment.
297 * climb_rate:
298 * the new climb rate.
299 * digits:
300 * the number of decimal places to display in the spin button.
302 public void configure(Adjustment adjustment, double climbRate, uint digits)
304 // void gtk_spin_button_configure (GtkSpinButton *spin_button, GtkAdjustment *adjustment, gdouble climb_rate, guint digits);
305 gtk_spin_button_configure(gtkSpinButton, (adjustment is null) ? null : adjustment.getAdjustmentStruct(), climbRate, digits);
309 * Creates a new GtkSpinButton.
310 * adjustment:
311 * the GtkAdjustment object that this spin button should use.
312 * climb_rate:
313 * specifies how much the spin button changes when an arrow is clicked on.
314 * digits:
315 * the number of decimal places to display.
316 * Returns:
317 * The new spin button as a GtkWidget.
319 public this (Adjustment adjustment, double climbRate, uint digits)
321 // GtkWidget* gtk_spin_button_new (GtkAdjustment *adjustment, gdouble climb_rate, guint digits);
322 this(cast(GtkSpinButton*)gtk_spin_button_new((adjustment is null) ? null : adjustment.getAdjustmentStruct(), climbRate, digits) );
326 * This is a convenience constructor that allows creation of a numeric
327 * GtkSpinButton without manually creating an adjustment. The value is
328 * initially set to the minimum value and a page increment of 10 * step
329 * is the default. The precision of the spin button is equivalent to the
330 * precision of step.
331 * Note that the way in which the precision is derived works best if step
332 * is a power of ten. If the resulting precision is not suitable for your
333 * needs, use gtk_spin_button_set_digits() to correct it.
334 * min:
335 * Minimum allowable value
336 * max:
337 * Maximum allowable value
338 * step:
339 * Increment added or subtracted by spinning the widget
340 * Returns:
341 * The new spin button as a GtkWidget.
343 public this (double min, double max, double step)
345 // GtkWidget* gtk_spin_button_new_with_range (gdouble min, gdouble max, gdouble step);
346 this(cast(GtkSpinButton*)gtk_spin_button_new_with_range(min, max, step) );
350 * Replaces the GtkAdjustment associated with spin_button.
351 * spin_button:
352 * a GtkSpinButton
353 * adjustment:
354 * a GtkAdjustment to replace the existing adjustment
356 public void setAdjustment(Adjustment adjustment)
358 // void gtk_spin_button_set_adjustment (GtkSpinButton *spin_button, GtkAdjustment *adjustment);
359 gtk_spin_button_set_adjustment(gtkSpinButton, (adjustment is null) ? null : adjustment.getAdjustmentStruct());
363 * Get the adjustment associated with a GtkSpinButton
364 * spin_button:
365 * a GtkSpinButton
366 * Returns:
367 * the GtkAdjustment of spin_button
369 public Adjustment getAdjustment()
371 // GtkAdjustment* gtk_spin_button_get_adjustment (GtkSpinButton *spin_button);
372 return new Adjustment( gtk_spin_button_get_adjustment(gtkSpinButton) );
376 * Set the precision to be displayed by spin_button. Up to 20 digit precision
377 * is allowed.
378 * spin_button:
379 * a GtkSpinButton
380 * digits:
381 * the number of digits after the decimal point to be displayed for the spin button's value
383 public void setDigits(uint digits)
385 // void gtk_spin_button_set_digits (GtkSpinButton *spin_button, guint digits);
386 gtk_spin_button_set_digits(gtkSpinButton, digits);
390 * Sets the step and page increments for spin_button. This affects how
391 * quickly the value changes when the spin button's arrows are activated.
392 * spin_button:
393 * a GtkSpinButton
394 * step:
395 * increment applied for a button 1 press.
396 * page:
397 * increment applied for a button 2 press.
399 public void setIncrements(double step, double page)
401 // void gtk_spin_button_set_increments (GtkSpinButton *spin_button, gdouble step, gdouble page);
402 gtk_spin_button_set_increments(gtkSpinButton, step, page);
406 * Sets the minimum and maximum allowable values for spin_button
407 * spin_button:
408 * a GtkSpinButton
409 * min:
410 * minimum allowable value
411 * max:
412 * maximum allowable value
414 public void setRange(double min, double max)
416 // void gtk_spin_button_set_range (GtkSpinButton *spin_button, gdouble min, gdouble max);
417 gtk_spin_button_set_range(gtkSpinButton, min, max);
422 * Get the value spin_button represented as an integer.
423 * spin_button:
424 * a GtkSpinButton
425 * Returns:
426 * the value of spin_button
428 public int getValueAsInt()
430 // gint gtk_spin_button_get_value_as_int (GtkSpinButton *spin_button);
431 return gtk_spin_button_get_value_as_int(gtkSpinButton);
435 * Set the value of spin_button.
436 * spin_button:
437 * a GtkSpinButton
438 * value:
439 * the new value
441 public void setValue(double value)
443 // void gtk_spin_button_set_value (GtkSpinButton *spin_button, gdouble value);
444 gtk_spin_button_set_value(gtkSpinButton, value);
448 * Sets the update behavior of a spin button. This determines whether the
449 * spin button is always updated or only when a valid value is set.
450 * spin_button:
451 * a GtkSpinButton
452 * policy:
453 * a GtkSpinButtonUpdatePolicy value
455 public void setUpdatePolicy(GtkSpinButtonUpdatePolicy policy)
457 // void gtk_spin_button_set_update_policy (GtkSpinButton *spin_button, GtkSpinButtonUpdatePolicy policy);
458 gtk_spin_button_set_update_policy(gtkSpinButton, policy);
462 * Sets the flag that determines if non-numeric text can be typed into
463 * the spin button.
464 * spin_button:
465 * a GtkSpinButton
466 * numeric:
467 * flag indicating if only numeric entry is allowed.
469 public void setNumeric(int numeric)
471 // void gtk_spin_button_set_numeric (GtkSpinButton *spin_button, gboolean numeric);
472 gtk_spin_button_set_numeric(gtkSpinButton, numeric);
476 * Increment or decrement a spin button's value in a specified direction
477 * by a specified amount.
478 * spin_button:
479 * a GtkSpinButton
480 * direction:
481 * a GtkSpinType indicating the direction to spin.
482 * increment:
483 * step increment to apply in the specified direction.
485 public void spin(GtkSpinType direction, double increment)
487 // void gtk_spin_button_spin (GtkSpinButton *spin_button, GtkSpinType direction, gdouble increment);
488 gtk_spin_button_spin(gtkSpinButton, direction, increment);
492 * Sets the flag that determines if a spin button value wraps around to the
493 * opposite limit when the upper or lower limit of the range is exceeded.
494 * spin_button:
495 * a GtkSpinButton
496 * wrap:
497 * a flag indicating if wrapping behavior is performed.
499 public void setWrap(int wrap)
501 // void gtk_spin_button_set_wrap (GtkSpinButton *spin_button, gboolean wrap);
502 gtk_spin_button_set_wrap(gtkSpinButton, wrap);
506 * Sets the policy as to whether values are corrected to the nearest step
507 * increment when a spin button is activated after providing an invalid value.
508 * spin_button:
509 * a GtkSpinButton
510 * snap_to_ticks:
511 * a flag indicating if invalid values should be corrected.
513 public void setSnapToTicks(int snapToTicks)
515 // void gtk_spin_button_set_snap_to_ticks (GtkSpinButton *spin_button, gboolean snap_to_ticks);
516 gtk_spin_button_set_snap_to_ticks(gtkSpinButton, snapToTicks);
520 * Manually force an update of the spin button.
521 * spin_button:
522 * a GtkSpinButton
524 public void update()
526 // void gtk_spin_button_update (GtkSpinButton *spin_button);
527 gtk_spin_button_update(gtkSpinButton);
531 * Fetches the precision of spin_button. See gtk_spin_button_set_digits().
532 * spin_button:
533 * a GtkSpinButton
534 * Returns:
535 * the current precision
537 public uint getDigits()
539 // guint gtk_spin_button_get_digits (GtkSpinButton *spin_button);
540 return gtk_spin_button_get_digits(gtkSpinButton);
544 * Gets the current step and page the increments used by spin_button. See
545 * gtk_spin_button_set_increments().
546 * spin_button:
547 * a GtkSpinButton
548 * step:
549 * location to store step increment, or NULL
550 * page:
551 * location to store page increment, or NULL
553 public void getIncrements(double* step, double* page)
555 // void gtk_spin_button_get_increments (GtkSpinButton *spin_button, gdouble *step, gdouble *page);
556 gtk_spin_button_get_increments(gtkSpinButton, step, page);
560 * Returns whether non-numeric text can be typed into the spin button.
561 * See gtk_spin_button_set_numeric().
562 * spin_button:
563 * a GtkSpinButton
564 * Returns:
565 * TRUE if only numeric text can be entered
567 public int getNumeric()
569 // gboolean gtk_spin_button_get_numeric (GtkSpinButton *spin_button);
570 return gtk_spin_button_get_numeric(gtkSpinButton);
574 * Gets the range allowed for spin_button. See
575 * gtk_spin_button_set_range().
576 * spin_button:
577 * a GtkSpinButton
578 * min:
579 * location to store minimum allowed value, or NULL
580 * max:
581 * location to store maximum allowed value, or NULL
583 public void getRange(double* min, double* max)
585 // void gtk_spin_button_get_range (GtkSpinButton *spin_button, gdouble *min, gdouble *max);
586 gtk_spin_button_get_range(gtkSpinButton, min, max);
590 * Returns whether the values are corrected to the nearest step. See
591 * gtk_spin_button_set_snap_to_ticks().
592 * spin_button:
593 * a GtkSpinButton
594 * Returns:
595 * TRUE if values are snapped to the nearest step.
597 public int getSnapToTicks()
599 // gboolean gtk_spin_button_get_snap_to_ticks (GtkSpinButton *spin_button);
600 return gtk_spin_button_get_snap_to_ticks(gtkSpinButton);
604 * Gets the update behavior of a spin button. See
605 * gtk_spin_button_set_update_policy().
606 * spin_button:
607 * a GtkSpinButton
608 * Returns:
609 * the current update policy
611 public GtkSpinButtonUpdatePolicy getUpdatePolicy()
613 // GtkSpinButtonUpdatePolicy gtk_spin_button_get_update_policy (GtkSpinButton *spin_button);
614 return gtk_spin_button_get_update_policy(gtkSpinButton);
618 * Get the value in the spin_button.
619 * spin_button:
620 * a GtkSpinButton
621 * Returns:
622 * the value of spin_button
624 public double getValue()
626 // gdouble gtk_spin_button_get_value (GtkSpinButton *spin_button);
627 return gtk_spin_button_get_value(gtkSpinButton);
631 * Returns whether the spin button's value wraps around to the
632 * opposite limit when the upper or lower limit of the range is
633 * exceeded. See gtk_spin_button_set_wrap().
634 * spin_button:
635 * a GtkSpinButton
636 * Returns:
637 * TRUE if the spin button wraps around
639 public int getWrap()
641 // gboolean gtk_spin_button_get_wrap (GtkSpinButton *spin_button);
642 return gtk_spin_button_get_wrap(gtkSpinButton);