alternative to assert
[gtkD.git] / gtkD / src / gtk / SpinButton.d
blobdf5324475c8d1f2eeb55990e0eb9e96c25f7e473
1 /*
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 = 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 * module aliases:
51 * local aliases:
54 module gtk.SpinButton;
56 version(noAssert)
58 version(Tango)
60 import tango.io.Stdout; // use the tango loging?
64 private import gtkc.gtktypes;
66 private import gtkc.gtk;
69 private import gtk.Widget;
70 private import gtk.Adjustment;
75 /**
76 * Description
77 * A GtkSpinButton is an ideal way to allow the user to set the value of some
78 * attribute. Rather than having to directly type a number into a GtkEntry,
79 * GtkSpinButton allows the user to click on one of two arrows to increment or
80 * decrement the displayed value. A value can still be typed in, with the bonus
81 * that it can be checked to ensure it is in a given range.
82 * The main properties of a GtkSpinButton are through a GtkAdjustment. See the
83 * GtkAdjustment section for more details about an adjustment's properties.
84 * Example1.Using a GtkSpinButton to get an integer.
85 * /+* Provides a function to retrieve an integer value from a GtkSpinButton
86 * * and creates a spin button to model percentage values.
87 * +/
88 * gint grab_int_value (GtkSpinButton *a_spinner, gpointer user_data) {
89 * return gtk_spin_button_get_value_as_int (a_spinner);
90 * }
91 * void create_integer_spin_button (void) {
92 * GtkWidget *window, *spinner;
93 * GtkAdjustment *spinner_adj;
94 * spinner_adj = (GtkAdjustment *) gtk_adjustment_new (50.0, 0.0, 100.0, 1.0, 5.0, 5.0);
95 * window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
96 * gtk_container_set_border_width (GTK_CONTAINER (window), 5);
97 * /+* creates the spinner, with no decimal places +/
98 * spinner = gtk_spin_button_new (spinner_adj, 1.0, 0);
99 * gtk_container_add (GTK_CONTAINER (window), spinner);
100 * gtk_widget_show_all (window);
101 * return;
103 * Example2.Using a GtkSpinButton to get a floating point value.
104 * /+* Provides a function to retrieve a floating point value from a
105 * * GtkSpinButton, and creates a high precision spin button.
106 * +/
107 * gfloat grab_int_value (GtkSpinButton *a_spinner, gpointer user_data) {
108 * return gtk_spin_button_get_value (a_spinner);
110 * void create_floating_spin_button (void) {
111 * GtkWidget *window, *spinner;
112 * GtkAdjustment *spinner_adj;
113 * spinner_adj = (GtkAdjustment *) gtk_adjustment_new (2.500, 0.0, 5.0, 0.001, 0.1, 0.1);
114 * window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
115 * gtk_container_set_border_width (GTK_CONTAINER (window), 5);
116 * /+* creates the spinner, with three decimal places +/
117 * spinner = gtk_spin_button_new (spinner_adj, 0.001, 3);
118 * gtk_container_add (GTK_CONTAINER (window), spinner);
119 * gtk_widget_show_all (window);
120 * return;
123 private import gtk.Entry;
124 public class SpinButton : Entry
127 /** the main Gtk struct */
128 protected GtkSpinButton* gtkSpinButton;
131 public GtkSpinButton* getSpinButtonStruct()
133 return gtkSpinButton;
137 /** the main Gtk struct as a void* */
138 protected void* getStruct()
140 return cast(void*)gtkSpinButton;
144 * Sets our main struct and passes it to the parent class
146 public this (GtkSpinButton* gtkSpinButton)
148 version(noAssert)
150 if ( gtkSpinButton is null )
152 int zero = 0;
153 version(Tango)
155 Stdout("struct gtkSpinButton is null on constructor").newline;
157 else
159 printf("struct gtkSpinButton is null on constructor");
161 zero = zero / zero;
164 else
166 assert(gtkSpinButton !is null, "struct gtkSpinButton is null on constructor");
168 super(cast(GtkEntry*)gtkSpinButton);
169 this.gtkSpinButton = gtkSpinButton;
175 // imports for the signal processing
176 private import gobject.Signals;
177 private import gtkc.gdktypes;
178 int[char[]] connectedSignals;
180 void delegate(GtkScrollType, SpinButton)[] onChangeValueListeners;
181 void addOnChangeValue(void delegate(GtkScrollType, SpinButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
183 if ( !("change-value" in connectedSignals) )
185 Signals.connectData(
186 getStruct(),
187 "change-value",
188 cast(GCallback)&callBackChangeValue,
189 cast(void*)this,
190 null,
191 connectFlags);
192 connectedSignals["change-value"] = 1;
194 onChangeValueListeners ~= dlg;
196 extern(C) static void callBackChangeValue(GtkSpinButton* spinbuttonStruct, GtkScrollType arg1, SpinButton spinButton)
198 bool consumed = false;
200 foreach ( void delegate(GtkScrollType, SpinButton) dlg ; spinButton.onChangeValueListeners )
202 dlg(arg1, spinButton);
205 return consumed;
208 gint delegate(gpointer, SpinButton)[] onInputListeners;
209 void addOnInput(gint delegate(gpointer, SpinButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
211 if ( !("input" in connectedSignals) )
213 Signals.connectData(
214 getStruct(),
215 "input",
216 cast(GCallback)&callBackInput,
217 cast(void*)this,
218 null,
219 connectFlags);
220 connectedSignals["input"] = 1;
222 onInputListeners ~= dlg;
224 extern(C) static void callBackInput(GtkSpinButton* spinbuttonStruct, gpointer arg1, SpinButton spinButton)
226 bool consumed = false;
228 foreach ( gint delegate(gpointer, SpinButton) dlg ; spinButton.onInputListeners )
230 dlg(arg1, spinButton);
233 return consumed;
236 gboolean delegate(SpinButton)[] onOutputListeners;
237 void addOnOutput(gboolean delegate(SpinButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
239 if ( !("output" in connectedSignals) )
241 Signals.connectData(
242 getStruct(),
243 "output",
244 cast(GCallback)&callBackOutput,
245 cast(void*)this,
246 null,
247 connectFlags);
248 connectedSignals["output"] = 1;
250 onOutputListeners ~= dlg;
252 extern(C) static void callBackOutput(GtkSpinButton* spinbuttonStruct, SpinButton spinButton)
254 bool consumed = false;
256 foreach ( gboolean delegate(SpinButton) dlg ; spinButton.onOutputListeners )
258 dlg(spinButton);
261 return consumed;
264 void delegate(SpinButton)[] onValueChangedListeners;
265 void addOnValueChanged(void delegate(SpinButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
267 if ( !("value-changed" in connectedSignals) )
269 Signals.connectData(
270 getStruct(),
271 "value-changed",
272 cast(GCallback)&callBackValueChanged,
273 cast(void*)this,
274 null,
275 connectFlags);
276 connectedSignals["value-changed"] = 1;
278 onValueChangedListeners ~= dlg;
280 extern(C) static void callBackValueChanged(GtkSpinButton* spinbuttonStruct, SpinButton spinButton)
282 bool consumed = false;
284 foreach ( void delegate(SpinButton) dlg ; spinButton.onValueChangedListeners )
286 dlg(spinButton);
289 return consumed;
292 void delegate(SpinButton)[] onWrappedListeners;
293 void addOnWrapped(void delegate(SpinButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
295 if ( !("wrapped" in connectedSignals) )
297 Signals.connectData(
298 getStruct(),
299 "wrapped",
300 cast(GCallback)&callBackWrapped,
301 cast(void*)this,
302 null,
303 connectFlags);
304 connectedSignals["wrapped"] = 1;
306 onWrappedListeners ~= dlg;
308 extern(C) static void callBackWrapped(GtkSpinButton* spinbuttonStruct, SpinButton spinButton)
310 bool consumed = false;
312 foreach ( void delegate(SpinButton) dlg ; spinButton.onWrappedListeners )
314 dlg(spinButton);
317 return consumed;
325 * 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.
326 * spin_button:
327 * a GtkSpinButton.
328 * adjustment:
329 * a GtkAdjustment.
330 * climb_rate:
331 * the new climb rate.
332 * digits:
333 * the number of decimal places to display in the spin button.
335 public void configure(Adjustment adjustment, double climbRate, uint digits)
337 // void gtk_spin_button_configure (GtkSpinButton *spin_button, GtkAdjustment *adjustment, gdouble climb_rate, guint digits);
338 gtk_spin_button_configure(gtkSpinButton, (adjustment is null) ? null : adjustment.getAdjustmentStruct(), climbRate, digits);
342 * Creates a new GtkSpinButton.
343 * adjustment:
344 * the GtkAdjustment object that this spin button should use.
345 * climb_rate:
346 * specifies how much the spin button changes when an arrow is clicked on.
347 * digits:
348 * the number of decimal places to display.
349 * Returns:
350 * The new spin button as a GtkWidget.
352 public this (Adjustment adjustment, double climbRate, uint digits)
354 // GtkWidget* gtk_spin_button_new (GtkAdjustment *adjustment, gdouble climb_rate, guint digits);
355 this(cast(GtkSpinButton*)gtk_spin_button_new((adjustment is null) ? null : adjustment.getAdjustmentStruct(), climbRate, digits) );
359 * This is a convenience constructor that allows creation of a numeric
360 * GtkSpinButton without manually creating an adjustment. The value is
361 * initially set to the minimum value and a page increment of 10 * step
362 * is the default. The precision of the spin button is equivalent to the
363 * precision of step.
364 * Note that the way in which the precision is derived works best if step
365 * is a power of ten. If the resulting precision is not suitable for your
366 * needs, use gtk_spin_button_set_digits() to correct it.
367 * min:
368 * Minimum allowable value
369 * max:
370 * Maximum allowable value
371 * step:
372 * Increment added or subtracted by spinning the widget
373 * Returns:
374 * The new spin button as a GtkWidget.
376 public this (double min, double max, double step)
378 // GtkWidget* gtk_spin_button_new_with_range (gdouble min, gdouble max, gdouble step);
379 this(cast(GtkSpinButton*)gtk_spin_button_new_with_range(min, max, step) );
383 * Replaces the GtkAdjustment associated with spin_button.
384 * spin_button:
385 * a GtkSpinButton
386 * adjustment:
387 * a GtkAdjustment to replace the existing adjustment
389 public void setAdjustment(Adjustment adjustment)
391 // void gtk_spin_button_set_adjustment (GtkSpinButton *spin_button, GtkAdjustment *adjustment);
392 gtk_spin_button_set_adjustment(gtkSpinButton, (adjustment is null) ? null : adjustment.getAdjustmentStruct());
396 * Get the adjustment associated with a GtkSpinButton
397 * spin_button:
398 * a GtkSpinButton
399 * Returns:
400 * the GtkAdjustment of spin_button
402 public Adjustment getAdjustment()
404 // GtkAdjustment* gtk_spin_button_get_adjustment (GtkSpinButton *spin_button);
405 return new Adjustment( gtk_spin_button_get_adjustment(gtkSpinButton) );
409 * Set the precision to be displayed by spin_button. Up to 20 digit precision
410 * is allowed.
411 * spin_button:
412 * a GtkSpinButton
413 * digits:
414 * the number of digits after the decimal point to be displayed for the spin button's value
416 public void setDigits(uint digits)
418 // void gtk_spin_button_set_digits (GtkSpinButton *spin_button, guint digits);
419 gtk_spin_button_set_digits(gtkSpinButton, digits);
423 * Sets the step and page increments for spin_button. This affects how
424 * quickly the value changes when the spin button's arrows are activated.
425 * spin_button:
426 * a GtkSpinButton
427 * step:
428 * increment applied for a button 1 press.
429 * page:
430 * increment applied for a button 2 press.
432 public void setIncrements(double step, double page)
434 // void gtk_spin_button_set_increments (GtkSpinButton *spin_button, gdouble step, gdouble page);
435 gtk_spin_button_set_increments(gtkSpinButton, step, page);
439 * Sets the minimum and maximum allowable values for spin_button
440 * spin_button:
441 * a GtkSpinButton
442 * min:
443 * minimum allowable value
444 * max:
445 * maximum allowable value
447 public void setRange(double min, double max)
449 // void gtk_spin_button_set_range (GtkSpinButton *spin_button, gdouble min, gdouble max);
450 gtk_spin_button_set_range(gtkSpinButton, min, max);
455 * Get the value spin_button represented as an integer.
456 * spin_button:
457 * a GtkSpinButton
458 * Returns:
459 * the value of spin_button
461 public int getValueAsInt()
463 // gint gtk_spin_button_get_value_as_int (GtkSpinButton *spin_button);
464 return gtk_spin_button_get_value_as_int(gtkSpinButton);
468 * Set the value of spin_button.
469 * spin_button:
470 * a GtkSpinButton
471 * value:
472 * the new value
474 public void setValue(double value)
476 // void gtk_spin_button_set_value (GtkSpinButton *spin_button, gdouble value);
477 gtk_spin_button_set_value(gtkSpinButton, value);
481 * Sets the update behavior of a spin button. This determines whether the
482 * spin button is always updated or only when a valid value is set.
483 * spin_button:
484 * a GtkSpinButton
485 * policy:
486 * a GtkSpinButtonUpdatePolicy value
488 public void setUpdatePolicy(GtkSpinButtonUpdatePolicy policy)
490 // void gtk_spin_button_set_update_policy (GtkSpinButton *spin_button, GtkSpinButtonUpdatePolicy policy);
491 gtk_spin_button_set_update_policy(gtkSpinButton, policy);
495 * Sets the flag that determines if non-numeric text can be typed into
496 * the spin button.
497 * spin_button:
498 * a GtkSpinButton
499 * numeric:
500 * flag indicating if only numeric entry is allowed.
502 public void setNumeric(int numeric)
504 // void gtk_spin_button_set_numeric (GtkSpinButton *spin_button, gboolean numeric);
505 gtk_spin_button_set_numeric(gtkSpinButton, numeric);
509 * Increment or decrement a spin button's value in a specified direction
510 * by a specified amount.
511 * spin_button:
512 * a GtkSpinButton
513 * direction:
514 * a GtkSpinType indicating the direction to spin.
515 * increment:
516 * step increment to apply in the specified direction.
518 public void spin(GtkSpinType direction, double increment)
520 // void gtk_spin_button_spin (GtkSpinButton *spin_button, GtkSpinType direction, gdouble increment);
521 gtk_spin_button_spin(gtkSpinButton, direction, increment);
525 * Sets the flag that determines if a spin button value wraps around to the
526 * opposite limit when the upper or lower limit of the range is exceeded.
527 * spin_button:
528 * a GtkSpinButton
529 * wrap:
530 * a flag indicating if wrapping behavior is performed.
532 public void setWrap(int wrap)
534 // void gtk_spin_button_set_wrap (GtkSpinButton *spin_button, gboolean wrap);
535 gtk_spin_button_set_wrap(gtkSpinButton, wrap);
539 * Sets the policy as to whether values are corrected to the nearest step
540 * increment when a spin button is activated after providing an invalid value.
541 * spin_button:
542 * a GtkSpinButton
543 * snap_to_ticks:
544 * a flag indicating if invalid values should be corrected.
546 public void setSnapToTicks(int snapToTicks)
548 // void gtk_spin_button_set_snap_to_ticks (GtkSpinButton *spin_button, gboolean snap_to_ticks);
549 gtk_spin_button_set_snap_to_ticks(gtkSpinButton, snapToTicks);
553 * Manually force an update of the spin button.
554 * spin_button:
555 * a GtkSpinButton
557 public void update()
559 // void gtk_spin_button_update (GtkSpinButton *spin_button);
560 gtk_spin_button_update(gtkSpinButton);
564 * Fetches the precision of spin_button. See gtk_spin_button_set_digits().
565 * spin_button:
566 * a GtkSpinButton
567 * Returns:
568 * the current precision
570 public uint getDigits()
572 // guint gtk_spin_button_get_digits (GtkSpinButton *spin_button);
573 return gtk_spin_button_get_digits(gtkSpinButton);
577 * Gets the current step and page the increments used by spin_button. See
578 * gtk_spin_button_set_increments().
579 * spin_button:
580 * a GtkSpinButton
581 * step:
582 * location to store step increment, or NULL
583 * page:
584 * location to store page increment, or NULL
586 public void getIncrements(double* step, double* page)
588 // void gtk_spin_button_get_increments (GtkSpinButton *spin_button, gdouble *step, gdouble *page);
589 gtk_spin_button_get_increments(gtkSpinButton, step, page);
593 * Returns whether non-numeric text can be typed into the spin button.
594 * See gtk_spin_button_set_numeric().
595 * spin_button:
596 * a GtkSpinButton
597 * Returns:
598 * TRUE if only numeric text can be entered
600 public int getNumeric()
602 // gboolean gtk_spin_button_get_numeric (GtkSpinButton *spin_button);
603 return gtk_spin_button_get_numeric(gtkSpinButton);
607 * Gets the range allowed for spin_button. See
608 * gtk_spin_button_set_range().
609 * spin_button:
610 * a GtkSpinButton
611 * min:
612 * location to store minimum allowed value, or NULL
613 * max:
614 * location to store maximum allowed value, or NULL
616 public void getRange(double* min, double* max)
618 // void gtk_spin_button_get_range (GtkSpinButton *spin_button, gdouble *min, gdouble *max);
619 gtk_spin_button_get_range(gtkSpinButton, min, max);
623 * Returns whether the values are corrected to the nearest step. See
624 * gtk_spin_button_set_snap_to_ticks().
625 * spin_button:
626 * a GtkSpinButton
627 * Returns:
628 * TRUE if values are snapped to the nearest step.
630 public int getSnapToTicks()
632 // gboolean gtk_spin_button_get_snap_to_ticks (GtkSpinButton *spin_button);
633 return gtk_spin_button_get_snap_to_ticks(gtkSpinButton);
637 * Gets the update behavior of a spin button. See
638 * gtk_spin_button_set_update_policy().
639 * spin_button:
640 * a GtkSpinButton
641 * Returns:
642 * the current update policy
644 public GtkSpinButtonUpdatePolicy getUpdatePolicy()
646 // GtkSpinButtonUpdatePolicy gtk_spin_button_get_update_policy (GtkSpinButton *spin_button);
647 return gtk_spin_button_get_update_policy(gtkSpinButton);
651 * Get the value in the spin_button.
652 * spin_button:
653 * a GtkSpinButton
654 * Returns:
655 * the value of spin_button
657 public double getValue()
659 // gdouble gtk_spin_button_get_value (GtkSpinButton *spin_button);
660 return gtk_spin_button_get_value(gtkSpinButton);
664 * Returns whether the spin button's value wraps around to the
665 * opposite limit when the upper or lower limit of the range is
666 * exceeded. See gtk_spin_button_set_wrap().
667 * spin_button:
668 * a GtkSpinButton
669 * Returns:
670 * TRUE if the spin button wraps around
672 public int getWrap()
674 // gboolean gtk_spin_button_get_wrap (GtkSpinButton *spin_button);
675 return gtk_spin_button_get_wrap(gtkSpinButton);