1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = GtkSpinButton.html
27  * outPack = gtk
28  * outFile = SpinButton
29  * strct   = GtkSpinButton
30  * realStrct=
31  * ctorStrct=
32  * clss    = SpinButton
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gtk_spin_button_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- gtk.Adjustment
47  * structWrap:
48  * 	- GtkAdjustment* -> Adjustment
49  * module aliases:
50  * local aliases:
51  * overrides:
52  */
53 
54 module gtk.SpinButton;
55 
56 public  import gtkc.gtktypes;
57 
58 private import gtkc.gtk;
59 private import glib.ConstructionException;
60 private import gobject.ObjectG;
61 
62 private import gobject.Signals;
63 public  import gtkc.gdktypes;
64 private import gtk.Adjustment;
65 
66 
67 private import gtk.Entry;
68 
69 /**
70  * A GtkSpinButton is an ideal way to allow the user to set the value of
71  * some attribute. Rather than having to directly type a number into a
72  * GtkEntry, GtkSpinButton allows the user to click on one of two arrows
73  * to increment or decrement the displayed value. A value can still be
74  * typed in, with the bonus that it can be checked to ensure it is in a
75  * given range.
76  *
77  * The main properties of a GtkSpinButton are through an adjustment.
78  * See the GtkAdjustment section for more details about an adjustment's
79  * properties.
80  *
81  * $(DDOC_COMMENT example)
82  *
83  * $(DDOC_COMMENT example)
84  */
85 public class SpinButton : Entry
86 {
87 	
88 	/** the main Gtk struct */
89 	protected GtkSpinButton* gtkSpinButton;
90 	
91 	
92 	/** Get the main Gtk struct */
93 	public GtkSpinButton* getSpinButtonStruct()
94 	{
95 		return gtkSpinButton;
96 	}
97 	
98 	
99 	/** the main Gtk struct as a void* */
100 	protected override void* getStruct()
101 	{
102 		return cast(void*)gtkSpinButton;
103 	}
104 	
105 	/**
106 	 * Sets our main struct and passes it to the parent class
107 	 */
108 	public this (GtkSpinButton* gtkSpinButton)
109 	{
110 		super(cast(GtkEntry*)gtkSpinButton);
111 		this.gtkSpinButton = gtkSpinButton;
112 	}
113 	
114 	protected override void setStruct(GObject* obj)
115 	{
116 		super.setStruct(obj);
117 		gtkSpinButton = cast(GtkSpinButton*)obj;
118 	}
119 	
120 	/**
121 	 */
122 	int[string] connectedSignals;
123 	
124 	void delegate(GtkScrollType, SpinButton)[] onChangeValueListeners;
125 	/**
126 	 */
127 	void addOnChangeValue(void delegate(GtkScrollType, SpinButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
128 	{
129 		if ( !("change-value" in connectedSignals) )
130 		{
131 			Signals.connectData(
132 			getStruct(),
133 			"change-value",
134 			cast(GCallback)&callBackChangeValue,
135 			cast(void*)this,
136 			null,
137 			connectFlags);
138 			connectedSignals["change-value"] = 1;
139 		}
140 		onChangeValueListeners ~= dlg;
141 	}
142 	extern(C) static void callBackChangeValue(GtkSpinButton* spinbuttonStruct, GtkScrollType arg1, SpinButton _spinButton)
143 	{
144 		foreach ( void delegate(GtkScrollType, SpinButton) dlg ; _spinButton.onChangeValueListeners )
145 		{
146 			dlg(arg1, _spinButton);
147 		}
148 	}
149 	
150 	gint delegate(void*, SpinButton)[] onInputListeners;
151 	/**
152 	 * The ::input signal can be used to influence the conversion of
153 	 * the users input into a double value. The signal handler is
154 	 * expected to use gtk_entry_get_text() to retrieve the text of
155 	 * the entry and set new_value to the new value.
156 	 * The default conversion uses g_strtod().
157 	 * TRUE for a successful conversion, FALSE if the input
158 	 * was not handled, and GTK_INPUT_ERROR if the conversion failed.
159 	 */
160 	void addOnInput(gint delegate(void*, SpinButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
161 	{
162 		if ( !("input" in connectedSignals) )
163 		{
164 			Signals.connectData(
165 			getStruct(),
166 			"input",
167 			cast(GCallback)&callBackInput,
168 			cast(void*)this,
169 			null,
170 			connectFlags);
171 			connectedSignals["input"] = 1;
172 		}
173 		onInputListeners ~= dlg;
174 	}
175 	extern(C) static void callBackInput(GtkSpinButton* spinButtonStruct, void* newValue, SpinButton _spinButton)
176 	{
177 		foreach ( gint delegate(void*, SpinButton) dlg ; _spinButton.onInputListeners )
178 		{
179 			dlg(newValue, _spinButton);
180 		}
181 	}
182 	
183 	bool delegate(SpinButton)[] onOutputListeners;
184 	/**
185 	 * The ::output signal can be used to change to formatting
186 	 * of the value that is displayed in the spin buttons entry.
187 	 * $(DDOC_COMMENT example)
188 	 * TRUE if the value has been displayed
189 	 */
190 	void addOnOutput(bool delegate(SpinButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
191 	{
192 		if ( !("output" in connectedSignals) )
193 		{
194 			Signals.connectData(
195 			getStruct(),
196 			"output",
197 			cast(GCallback)&callBackOutput,
198 			cast(void*)this,
199 			null,
200 			connectFlags);
201 			connectedSignals["output"] = 1;
202 		}
203 		onOutputListeners ~= dlg;
204 	}
205 	extern(C) static gboolean callBackOutput(GtkSpinButton* spinButtonStruct, SpinButton _spinButton)
206 	{
207 		foreach ( bool delegate(SpinButton) dlg ; _spinButton.onOutputListeners )
208 		{
209 			if ( dlg(_spinButton) )
210 			{
211 				return 1;
212 			}
213 		}
214 		
215 		return 0;
216 	}
217 	
218 	void delegate(SpinButton)[] onValueChangedListeners;
219 	/**
220 	 */
221 	void addOnValueChanged(void delegate(SpinButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
222 	{
223 		if ( !("value-changed" in connectedSignals) )
224 		{
225 			Signals.connectData(
226 			getStruct(),
227 			"value-changed",
228 			cast(GCallback)&callBackValueChanged,
229 			cast(void*)this,
230 			null,
231 			connectFlags);
232 			connectedSignals["value-changed"] = 1;
233 		}
234 		onValueChangedListeners ~= dlg;
235 	}
236 	extern(C) static void callBackValueChanged(GtkSpinButton* spinbuttonStruct, SpinButton _spinButton)
237 	{
238 		foreach ( void delegate(SpinButton) dlg ; _spinButton.onValueChangedListeners )
239 		{
240 			dlg(_spinButton);
241 		}
242 	}
243 	
244 	void delegate(SpinButton)[] onWrappedListeners;
245 	/**
246 	 * The wrapped signal is emitted right after the spinbutton wraps
247 	 * from its maximum to minimum value or vice-versa.
248 	 * Since 2.10
249 	 * See Also
250 	 * GtkEntry
251 	 */
252 	void addOnWrapped(void delegate(SpinButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
253 	{
254 		if ( !("wrapped" in connectedSignals) )
255 		{
256 			Signals.connectData(
257 			getStruct(),
258 			"wrapped",
259 			cast(GCallback)&callBackWrapped,
260 			cast(void*)this,
261 			null,
262 			connectFlags);
263 			connectedSignals["wrapped"] = 1;
264 		}
265 		onWrappedListeners ~= dlg;
266 	}
267 	extern(C) static void callBackWrapped(GtkSpinButton* spinbuttonStruct, SpinButton _spinButton)
268 	{
269 		foreach ( void delegate(SpinButton) dlg ; _spinButton.onWrappedListeners )
270 		{
271 			dlg(_spinButton);
272 		}
273 	}
274 	
275 	
276 	/**
277 	 * Changes the properties of an existing spin button. The adjustment,
278 	 * climb rate, and number of decimal places are all changed accordingly,
279 	 * after this function call.
280 	 * Params:
281 	 * adjustment = a GtkAdjustment. [allow-none]
282 	 * climbRate = the new climb rate
283 	 * digits = the number of decimal places to display in the spin button
284 	 */
285 	public void configure(Adjustment adjustment, double climbRate, uint digits)
286 	{
287 		// void gtk_spin_button_configure (GtkSpinButton *spin_button,  GtkAdjustment *adjustment,  gdouble climb_rate,  guint digits);
288 		gtk_spin_button_configure(gtkSpinButton, (adjustment is null) ? null : adjustment.getAdjustmentStruct(), climbRate, digits);
289 	}
290 	
291 	/**
292 	 * Creates a new GtkSpinButton.
293 	 * Params:
294 	 * adjustment = the GtkAdjustment object that this spin
295 	 * button should use, or NULL. [allow-none]
296 	 * climbRate = specifies how much the spin button changes when an arrow
297 	 * is clicked on
298 	 * digits = the number of decimal places to display
299 	 * Throws: ConstructionException GTK+ fails to create the object.
300 	 */
301 	public this (Adjustment adjustment, double climbRate, uint digits)
302 	{
303 		// GtkWidget * gtk_spin_button_new (GtkAdjustment *adjustment,  gdouble climb_rate,  guint digits);
304 		auto p = gtk_spin_button_new((adjustment is null) ? null : adjustment.getAdjustmentStruct(), climbRate, digits);
305 		if(p is null)
306 		{
307 			throw new ConstructionException("null returned by gtk_spin_button_new((adjustment is null) ? null : adjustment.getAdjustmentStruct(), climbRate, digits)");
308 		}
309 		this(cast(GtkSpinButton*) p);
310 	}
311 	
312 	/**
313 	 * This is a convenience constructor that allows creation of a numeric
314 	 * GtkSpinButton without manually creating an adjustment. The value is
315 	 * initially set to the minimum value and a page increment of 10 * step
316 	 * is the default. The precision of the spin button is equivalent to the
317 	 * precision of step.
318 	 * Note that the way in which the precision is derived works best if step
319 	 * is a power of ten. If the resulting precision is not suitable for your
320 	 * needs, use gtk_spin_button_set_digits() to correct it.
321 	 * Params:
322 	 * min = Minimum allowable value
323 	 * max = Maximum allowable value
324 	 * step = Increment added or subtracted by spinning the widget
325 	 * Throws: ConstructionException GTK+ fails to create the object.
326 	 */
327 	public this (double min, double max, double step)
328 	{
329 		// GtkWidget * gtk_spin_button_new_with_range (gdouble min,  gdouble max,  gdouble step);
330 		auto p = gtk_spin_button_new_with_range(min, max, step);
331 		if(p is null)
332 		{
333 			throw new ConstructionException("null returned by gtk_spin_button_new_with_range(min, max, step)");
334 		}
335 		this(cast(GtkSpinButton*) p);
336 	}
337 	
338 	/**
339 	 * Replaces the GtkAdjustment associated with spin_button.
340 	 * Params:
341 	 * adjustment = a GtkAdjustment to replace the existing adjustment
342 	 */
343 	public void setAdjustment(Adjustment adjustment)
344 	{
345 		// void gtk_spin_button_set_adjustment (GtkSpinButton *spin_button,  GtkAdjustment *adjustment);
346 		gtk_spin_button_set_adjustment(gtkSpinButton, (adjustment is null) ? null : adjustment.getAdjustmentStruct());
347 	}
348 	
349 	/**
350 	 * Get the adjustment associated with a GtkSpinButton
351 	 * Returns: the GtkAdjustment of spin_button. [transfer none]
352 	 */
353 	public Adjustment getAdjustment()
354 	{
355 		// GtkAdjustment * gtk_spin_button_get_adjustment (GtkSpinButton *spin_button);
356 		auto p = gtk_spin_button_get_adjustment(gtkSpinButton);
357 		
358 		if(p is null)
359 		{
360 			return null;
361 		}
362 		
363 		return ObjectG.getDObject!(Adjustment)(cast(GtkAdjustment*) p);
364 	}
365 	
366 	/**
367 	 * Set the precision to be displayed by spin_button. Up to 20 digit precision
368 	 * is allowed.
369 	 * Params:
370 	 * digits = the number of digits after the decimal point to be displayed for the spin button's value
371 	 */
372 	public void setDigits(uint digits)
373 	{
374 		// void gtk_spin_button_set_digits (GtkSpinButton *spin_button,  guint digits);
375 		gtk_spin_button_set_digits(gtkSpinButton, digits);
376 	}
377 	
378 	/**
379 	 * Sets the step and page increments for spin_button. This affects how
380 	 * quickly the value changes when the spin button's arrows are activated.
381 	 * Params:
382 	 * step = increment applied for a button 1 press.
383 	 * page = increment applied for a button 2 press.
384 	 */
385 	public void setIncrements(double step, double page)
386 	{
387 		// void gtk_spin_button_set_increments (GtkSpinButton *spin_button,  gdouble step,  gdouble page);
388 		gtk_spin_button_set_increments(gtkSpinButton, step, page);
389 	}
390 	
391 	/**
392 	 * Sets the minimum and maximum allowable values for spin_button.
393 	 * If the current value is outside this range, it will be adjusted
394 	 * to fit within the range, otherwise it will remain unchanged.
395 	 * Params:
396 	 * min = minimum allowable value
397 	 * max = maximum allowable value
398 	 */
399 	public void setRange(double min, double max)
400 	{
401 		// void gtk_spin_button_set_range (GtkSpinButton *spin_button,  gdouble min,  gdouble max);
402 		gtk_spin_button_set_range(gtkSpinButton, min, max);
403 	}
404 	
405 	/**
406 	 * Get the value spin_button represented as an integer.
407 	 * Returns: the value of spin_button
408 	 */
409 	public int getValueAsInt()
410 	{
411 		// gint gtk_spin_button_get_value_as_int (GtkSpinButton *spin_button);
412 		return gtk_spin_button_get_value_as_int(gtkSpinButton);
413 	}
414 	
415 	/**
416 	 * Sets the value of spin_button.
417 	 * Params:
418 	 * value = the new value
419 	 */
420 	public void setValue(double value)
421 	{
422 		// void gtk_spin_button_set_value (GtkSpinButton *spin_button,  gdouble value);
423 		gtk_spin_button_set_value(gtkSpinButton, value);
424 	}
425 	
426 	/**
427 	 * Sets the update behavior of a spin button.
428 	 * This determines whether the spin button is always updated
429 	 * or only when a valid value is set.
430 	 * Params:
431 	 * policy = a GtkSpinButtonUpdatePolicy value
432 	 */
433 	public void setUpdatePolicy(GtkSpinButtonUpdatePolicy policy)
434 	{
435 		// void gtk_spin_button_set_update_policy (GtkSpinButton *spin_button,  GtkSpinButtonUpdatePolicy policy);
436 		gtk_spin_button_set_update_policy(gtkSpinButton, policy);
437 	}
438 	
439 	/**
440 	 * Sets the flag that determines if non-numeric text can be typed
441 	 * into the spin button.
442 	 * Params:
443 	 * numeric = flag indicating if only numeric entry is allowed
444 	 */
445 	public void setNumeric(int numeric)
446 	{
447 		// void gtk_spin_button_set_numeric (GtkSpinButton *spin_button,  gboolean numeric);
448 		gtk_spin_button_set_numeric(gtkSpinButton, numeric);
449 	}
450 	
451 	/**
452 	 * Increment or decrement a spin button's value in a specified
453 	 * direction by a specified amount.
454 	 * Params:
455 	 * direction = a GtkSpinType indicating the direction to spin
456 	 * increment = step increment to apply in the specified direction
457 	 */
458 	public void spin(GtkSpinType direction, double increment)
459 	{
460 		// void gtk_spin_button_spin (GtkSpinButton *spin_button,  GtkSpinType direction,  gdouble increment);
461 		gtk_spin_button_spin(gtkSpinButton, direction, increment);
462 	}
463 	
464 	/**
465 	 * Sets the flag that determines if a spin button value wraps
466 	 * around to the opposite limit when the upper or lower limit
467 	 * of the range is exceeded.
468 	 * Params:
469 	 * wrap = a flag indicating if wrapping behavior is performed
470 	 */
471 	public void setWrap(int wrap)
472 	{
473 		// void gtk_spin_button_set_wrap (GtkSpinButton *spin_button,  gboolean wrap);
474 		gtk_spin_button_set_wrap(gtkSpinButton, wrap);
475 	}
476 	
477 	/**
478 	 * Sets the policy as to whether values are corrected to the
479 	 * nearest step increment when a spin button is activated after
480 	 * providing an invalid value.
481 	 * Params:
482 	 * snapToTicks = a flag indicating if invalid values should be corrected
483 	 */
484 	public void setSnapToTicks(int snapToTicks)
485 	{
486 		// void gtk_spin_button_set_snap_to_ticks (GtkSpinButton *spin_button,  gboolean snap_to_ticks);
487 		gtk_spin_button_set_snap_to_ticks(gtkSpinButton, snapToTicks);
488 	}
489 	
490 	/**
491 	 * Manually force an update of the spin button.
492 	 */
493 	public void update()
494 	{
495 		// void gtk_spin_button_update (GtkSpinButton *spin_button);
496 		gtk_spin_button_update(gtkSpinButton);
497 	}
498 	
499 	/**
500 	 * Fetches the precision of spin_button. See gtk_spin_button_set_digits().
501 	 * Returns: the current precision
502 	 */
503 	public uint getDigits()
504 	{
505 		// guint gtk_spin_button_get_digits (GtkSpinButton *spin_button);
506 		return gtk_spin_button_get_digits(gtkSpinButton);
507 	}
508 	
509 	/**
510 	 * Gets the current step and page the increments used by spin_button. See
511 	 * gtk_spin_button_set_increments().
512 	 * Params:
513 	 * step = location to store step increment, or NULL. [out][allow-none]
514 	 * page = location to store page increment, or NULL. [out][allow-none]
515 	 */
516 	public void getIncrements(out double step, out double page)
517 	{
518 		// void gtk_spin_button_get_increments (GtkSpinButton *spin_button,  gdouble *step,  gdouble *page);
519 		gtk_spin_button_get_increments(gtkSpinButton, &step, &page);
520 	}
521 	
522 	/**
523 	 * Returns whether non-numeric text can be typed into the spin button.
524 	 * See gtk_spin_button_set_numeric().
525 	 * Returns: TRUE if only numeric text can be entered
526 	 */
527 	public int getNumeric()
528 	{
529 		// gboolean gtk_spin_button_get_numeric (GtkSpinButton *spin_button);
530 		return gtk_spin_button_get_numeric(gtkSpinButton);
531 	}
532 	
533 	/**
534 	 * Gets the range allowed for spin_button.
535 	 * See gtk_spin_button_set_range().
536 	 * Params:
537 	 * min = location to store minimum allowed value, or NULL. [out][allow-none]
538 	 * max = location to store maximum allowed value, or NULL. [out][allow-none]
539 	 */
540 	public void getRange(out double min, out double max)
541 	{
542 		// void gtk_spin_button_get_range (GtkSpinButton *spin_button,  gdouble *min,  gdouble *max);
543 		gtk_spin_button_get_range(gtkSpinButton, &min, &max);
544 	}
545 	
546 	/**
547 	 * Returns whether the values are corrected to the nearest step.
548 	 * See gtk_spin_button_set_snap_to_ticks().
549 	 * Returns: TRUE if values are snapped to the nearest step
550 	 */
551 	public int getSnapToTicks()
552 	{
553 		// gboolean gtk_spin_button_get_snap_to_ticks (GtkSpinButton *spin_button);
554 		return gtk_spin_button_get_snap_to_ticks(gtkSpinButton);
555 	}
556 	
557 	/**
558 	 * Gets the update behavior of a spin button.
559 	 * See gtk_spin_button_set_update_policy().
560 	 * Returns: the current update policy
561 	 */
562 	public GtkSpinButtonUpdatePolicy getUpdatePolicy()
563 	{
564 		// GtkSpinButtonUpdatePolicy gtk_spin_button_get_update_policy  (GtkSpinButton *spin_button);
565 		return gtk_spin_button_get_update_policy(gtkSpinButton);
566 	}
567 	
568 	/**
569 	 * Get the value in the spin_button.
570 	 * Returns: the value of spin_button
571 	 */
572 	public double getValue()
573 	{
574 		// gdouble gtk_spin_button_get_value (GtkSpinButton *spin_button);
575 		return gtk_spin_button_get_value(gtkSpinButton);
576 	}
577 	
578 	/**
579 	 * Returns whether the spin button's value wraps around to the
580 	 * opposite limit when the upper or lower limit of the range is
581 	 * exceeded. See gtk_spin_button_set_wrap().
582 	 * Returns: TRUE if the spin button wraps around
583 	 */
584 	public int getWrap()
585 	{
586 		// gboolean gtk_spin_button_get_wrap (GtkSpinButton *spin_button);
587 		return gtk_spin_button_get_wrap(gtkSpinButton);
588 	}
589 }