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