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 module gtk.Range;
26 
27 private import gobject.ObjectG;
28 private import gobject.Signals;
29 private import gtk.Adjustment;
30 private import gtk.OrientableIF;
31 private import gtk.OrientableT;
32 private import gtk.Widget;
33 public  import gtkc.gdktypes;
34 private import gtkc.gtk;
35 public  import gtkc.gtktypes;
36 
37 
38 /**
39  * #GtkRange is the common base class for widgets which visualize an
40  * adjustment, e.g #GtkScale or #GtkScrollbar.
41  * 
42  * Apart from signals for monitoring the parameters of the adjustment,
43  * #GtkRange provides properties and methods for influencing the sensitivity
44  * of the “steppers”. It also provides properties and methods for setting a
45  * “fill level” on range widgets. See gtk_range_set_fill_level().
46  */
47 public class Range : Widget, OrientableIF
48 {
49 	/** the main Gtk struct */
50 	protected GtkRange* gtkRange;
51 
52 	/** Get the main Gtk struct */
53 	public GtkRange* getRangeStruct()
54 	{
55 		return gtkRange;
56 	}
57 
58 	/** the main Gtk struct as a void* */
59 	protected override void* getStruct()
60 	{
61 		return cast(void*)gtkRange;
62 	}
63 
64 	protected override void setStruct(GObject* obj)
65 	{
66 		gtkRange = cast(GtkRange*)obj;
67 		super.setStruct(obj);
68 	}
69 
70 	/**
71 	 * Sets our main struct and passes it to the parent class.
72 	 */
73 	public this (GtkRange* gtkRange, bool ownedRef = false)
74 	{
75 		this.gtkRange = gtkRange;
76 		super(cast(GtkWidget*)gtkRange, ownedRef);
77 	}
78 
79 	// add the Orientable capabilities
80 	mixin OrientableT!(GtkRange);
81 
82 
83 	/** */
84 	public static GType getType()
85 	{
86 		return gtk_range_get_type();
87 	}
88 
89 	/**
90 	 * Get the #GtkAdjustment which is the “model” object for #GtkRange.
91 	 * See gtk_range_set_adjustment() for details.
92 	 * The return value does not have a reference added, so should not
93 	 * be unreferenced.
94 	 *
95 	 * Return: a #GtkAdjustment
96 	 */
97 	public Adjustment getAdjustment()
98 	{
99 		auto p = gtk_range_get_adjustment(gtkRange);
100 		
101 		if(p is null)
102 		{
103 			return null;
104 		}
105 		
106 		return ObjectG.getDObject!(Adjustment)(cast(GtkAdjustment*) p);
107 	}
108 
109 	/**
110 	 * Gets the current position of the fill level indicator.
111 	 *
112 	 * Return: The current fill level
113 	 *
114 	 * Since: 2.12
115 	 */
116 	public double getFillLevel()
117 	{
118 		return gtk_range_get_fill_level(gtkRange);
119 	}
120 
121 	/**
122 	 * Gets the value set by gtk_range_set_flippable().
123 	 *
124 	 * Return: %TRUE if the range is flippable
125 	 *
126 	 * Since: 2.18
127 	 */
128 	public bool getFlippable()
129 	{
130 		return gtk_range_get_flippable(gtkRange) != 0;
131 	}
132 
133 	/**
134 	 * Gets the value set by gtk_range_set_inverted().
135 	 *
136 	 * Return: %TRUE if the range is inverted
137 	 */
138 	public bool getInverted()
139 	{
140 		return gtk_range_get_inverted(gtkRange) != 0;
141 	}
142 
143 	/**
144 	 * Gets the sensitivity policy for the stepper that points to the
145 	 * 'lower' end of the GtkRange’s adjustment.
146 	 *
147 	 * Return: The lower stepper’s sensitivity policy.
148 	 *
149 	 * Since: 2.10
150 	 */
151 	public GtkSensitivityType getLowerStepperSensitivity()
152 	{
153 		return gtk_range_get_lower_stepper_sensitivity(gtkRange);
154 	}
155 
156 	/**
157 	 * This function is useful mainly for #GtkRange subclasses.
158 	 *
159 	 * See gtk_range_set_min_slider_size().
160 	 *
161 	 * Return: The minimum size of the range’s slider.
162 	 *
163 	 * Since: 2.20
164 	 */
165 	public int getMinSliderSize()
166 	{
167 		return gtk_range_get_min_slider_size(gtkRange);
168 	}
169 
170 	/**
171 	 * This function returns the area that contains the range’s trough
172 	 * and its steppers, in widget->window coordinates.
173 	 *
174 	 * This function is useful mainly for #GtkRange subclasses.
175 	 *
176 	 * Params:
177 	 *     rangeRect = return location for the range rectangle
178 	 *
179 	 * Since: 2.20
180 	 */
181 	public void getRangeRect(out GdkRectangle rangeRect)
182 	{
183 		gtk_range_get_range_rect(gtkRange, &rangeRect);
184 	}
185 
186 	/**
187 	 * Gets whether the range is restricted to the fill level.
188 	 *
189 	 * Return: %TRUE if @range is restricted to the fill level.
190 	 *
191 	 * Since: 2.12
192 	 */
193 	public bool getRestrictToFillLevel()
194 	{
195 		return gtk_range_get_restrict_to_fill_level(gtkRange) != 0;
196 	}
197 
198 	/**
199 	 * Gets the number of digits to round the value to when
200 	 * it changes. See #GtkRange::change-value.
201 	 *
202 	 * Return: the number of digits to round to
203 	 *
204 	 * Since: 2.24
205 	 */
206 	public int getRoundDigits()
207 	{
208 		return gtk_range_get_round_digits(gtkRange);
209 	}
210 
211 	/**
212 	 * Gets whether the range displays the fill level graphically.
213 	 *
214 	 * Return: %TRUE if @range shows the fill level.
215 	 *
216 	 * Since: 2.12
217 	 */
218 	public bool getShowFillLevel()
219 	{
220 		return gtk_range_get_show_fill_level(gtkRange) != 0;
221 	}
222 
223 	/**
224 	 * This function returns sliders range along the long dimension,
225 	 * in widget->window coordinates.
226 	 *
227 	 * This function is useful mainly for #GtkRange subclasses.
228 	 *
229 	 * Params:
230 	 *     sliderStart = return location for the slider's
231 	 *         start, or %NULL
232 	 *     sliderEnd = return location for the slider's
233 	 *         end, or %NULL
234 	 *
235 	 * Since: 2.20
236 	 */
237 	public void getSliderRange(out int sliderStart, out int sliderEnd)
238 	{
239 		gtk_range_get_slider_range(gtkRange, &sliderStart, &sliderEnd);
240 	}
241 
242 	/**
243 	 * This function is useful mainly for #GtkRange subclasses.
244 	 *
245 	 * See gtk_range_set_slider_size_fixed().
246 	 *
247 	 * Return: whether the range’s slider has a fixed size.
248 	 *
249 	 * Since: 2.20
250 	 */
251 	public bool getSliderSizeFixed()
252 	{
253 		return gtk_range_get_slider_size_fixed(gtkRange) != 0;
254 	}
255 
256 	/**
257 	 * Gets the sensitivity policy for the stepper that points to the
258 	 * 'upper' end of the GtkRange’s adjustment.
259 	 *
260 	 * Return: The upper stepper’s sensitivity policy.
261 	 *
262 	 * Since: 2.10
263 	 */
264 	public GtkSensitivityType getUpperStepperSensitivity()
265 	{
266 		return gtk_range_get_upper_stepper_sensitivity(gtkRange);
267 	}
268 
269 	/**
270 	 * Gets the current value of the range.
271 	 *
272 	 * Return: current value of the range.
273 	 */
274 	public double getValue()
275 	{
276 		return gtk_range_get_value(gtkRange);
277 	}
278 
279 	/**
280 	 * Sets the adjustment to be used as the “model” object for this range
281 	 * widget. The adjustment indicates the current range value, the
282 	 * minimum and maximum range values, the step/page increments used
283 	 * for keybindings and scrolling, and the page size. The page size
284 	 * is normally 0 for #GtkScale and nonzero for #GtkScrollbar, and
285 	 * indicates the size of the visible area of the widget being scrolled.
286 	 * The page size affects the size of the scrollbar slider.
287 	 *
288 	 * Params:
289 	 *     adjustment = a #GtkAdjustment
290 	 */
291 	public void setAdjustment(Adjustment adjustment)
292 	{
293 		gtk_range_set_adjustment(gtkRange, (adjustment is null) ? null : adjustment.getAdjustmentStruct());
294 	}
295 
296 	/**
297 	 * Set the new position of the fill level indicator.
298 	 *
299 	 * The “fill level” is probably best described by its most prominent
300 	 * use case, which is an indicator for the amount of pre-buffering in
301 	 * a streaming media player. In that use case, the value of the range
302 	 * would indicate the current play position, and the fill level would
303 	 * be the position up to which the file/stream has been downloaded.
304 	 *
305 	 * This amount of prebuffering can be displayed on the range’s trough
306 	 * and is themeable separately from the trough. To enable fill level
307 	 * display, use gtk_range_set_show_fill_level(). The range defaults
308 	 * to not showing the fill level.
309 	 *
310 	 * Additionally, it’s possible to restrict the range’s slider position
311 	 * to values which are smaller than the fill level. This is controller
312 	 * by gtk_range_set_restrict_to_fill_level() and is by default
313 	 * enabled.
314 	 *
315 	 * Params:
316 	 *     fillLevel = the new position of the fill level indicator
317 	 *
318 	 * Since: 2.12
319 	 */
320 	public void setFillLevel(double fillLevel)
321 	{
322 		gtk_range_set_fill_level(gtkRange, fillLevel);
323 	}
324 
325 	/**
326 	 * If a range is flippable, it will switch its direction if it is
327 	 * horizontal and its direction is %GTK_TEXT_DIR_RTL.
328 	 *
329 	 * See gtk_widget_get_direction().
330 	 *
331 	 * Params:
332 	 *     flippable = %TRUE to make the range flippable
333 	 *
334 	 * Since: 2.18
335 	 */
336 	public void setFlippable(bool flippable)
337 	{
338 		gtk_range_set_flippable(gtkRange, flippable);
339 	}
340 
341 	/**
342 	 * Sets the step and page sizes for the range.
343 	 * The step size is used when the user clicks the #GtkScrollbar
344 	 * arrows or moves #GtkScale via arrow keys. The page size
345 	 * is used for example when moving via Page Up or Page Down keys.
346 	 *
347 	 * Params:
348 	 *     step = step size
349 	 *     page = page size
350 	 */
351 	public void setIncrements(double step, double page)
352 	{
353 		gtk_range_set_increments(gtkRange, step, page);
354 	}
355 
356 	/**
357 	 * Ranges normally move from lower to higher values as the
358 	 * slider moves from top to bottom or left to right. Inverted
359 	 * ranges have higher values at the top or on the right rather than
360 	 * on the bottom or left.
361 	 *
362 	 * Params:
363 	 *     setting = %TRUE to invert the range
364 	 */
365 	public void setInverted(bool setting)
366 	{
367 		gtk_range_set_inverted(gtkRange, setting);
368 	}
369 
370 	/**
371 	 * Sets the sensitivity policy for the stepper that points to the
372 	 * 'lower' end of the GtkRange’s adjustment.
373 	 *
374 	 * Params:
375 	 *     sensitivity = the lower stepper’s sensitivity policy.
376 	 *
377 	 * Since: 2.10
378 	 */
379 	public void setLowerStepperSensitivity(GtkSensitivityType sensitivity)
380 	{
381 		gtk_range_set_lower_stepper_sensitivity(gtkRange, sensitivity);
382 	}
383 
384 	/**
385 	 * Sets the minimum size of the range’s slider.
386 	 *
387 	 * This function is useful mainly for #GtkRange subclasses.
388 	 *
389 	 * Params:
390 	 *     minSize = The slider’s minimum size
391 	 *
392 	 * Since: 2.20
393 	 */
394 	public void setMinSliderSize(int minSize)
395 	{
396 		gtk_range_set_min_slider_size(gtkRange, minSize);
397 	}
398 
399 	/**
400 	 * Sets the allowable values in the #GtkRange, and clamps the range
401 	 * value to be between @min and @max. (If the range has a non-zero
402 	 * page size, it is clamped between @min and @max - page-size.)
403 	 *
404 	 * Params:
405 	 *     min = minimum range value
406 	 *     max = maximum range value
407 	 */
408 	public void setRange(double min, double max)
409 	{
410 		gtk_range_set_range(gtkRange, min, max);
411 	}
412 
413 	/**
414 	 * Sets whether the slider is restricted to the fill level. See
415 	 * gtk_range_set_fill_level() for a general description of the fill
416 	 * level concept.
417 	 *
418 	 * Params:
419 	 *     restrictToFillLevel = Whether the fill level restricts slider movement.
420 	 *
421 	 * Since: 2.12
422 	 */
423 	public void setRestrictToFillLevel(bool restrictToFillLevel)
424 	{
425 		gtk_range_set_restrict_to_fill_level(gtkRange, restrictToFillLevel);
426 	}
427 
428 	/**
429 	 * Sets the number of digits to round the value to when
430 	 * it changes. See #GtkRange::change-value.
431 	 *
432 	 * Params:
433 	 *     roundDigits = the precision in digits, or -1
434 	 *
435 	 * Since: 2.24
436 	 */
437 	public void setRoundDigits(int roundDigits)
438 	{
439 		gtk_range_set_round_digits(gtkRange, roundDigits);
440 	}
441 
442 	/**
443 	 * Sets whether a graphical fill level is show on the trough. See
444 	 * gtk_range_set_fill_level() for a general description of the fill
445 	 * level concept.
446 	 *
447 	 * Params:
448 	 *     showFillLevel = Whether a fill level indicator graphics is shown.
449 	 *
450 	 * Since: 2.12
451 	 */
452 	public void setShowFillLevel(bool showFillLevel)
453 	{
454 		gtk_range_set_show_fill_level(gtkRange, showFillLevel);
455 	}
456 
457 	/**
458 	 * Sets whether the range’s slider has a fixed size, or a size that
459 	 * depends on its adjustment’s page size.
460 	 *
461 	 * This function is useful mainly for #GtkRange subclasses.
462 	 *
463 	 * Params:
464 	 *     sizeFixed = %TRUE to make the slider size constant
465 	 *
466 	 * Since: 2.20
467 	 */
468 	public void setSliderSizeFixed(bool sizeFixed)
469 	{
470 		gtk_range_set_slider_size_fixed(gtkRange, sizeFixed);
471 	}
472 
473 	/**
474 	 * Sets the sensitivity policy for the stepper that points to the
475 	 * 'upper' end of the GtkRange’s adjustment.
476 	 *
477 	 * Params:
478 	 *     sensitivity = the upper stepper’s sensitivity policy.
479 	 *
480 	 * Since: 2.10
481 	 */
482 	public void setUpperStepperSensitivity(GtkSensitivityType sensitivity)
483 	{
484 		gtk_range_set_upper_stepper_sensitivity(gtkRange, sensitivity);
485 	}
486 
487 	/**
488 	 * Sets the current value of the range; if the value is outside the
489 	 * minimum or maximum range values, it will be clamped to fit inside
490 	 * them. The range emits the #GtkRange::value-changed signal if the
491 	 * value changes.
492 	 *
493 	 * Params:
494 	 *     value = new value of the range
495 	 */
496 	public void setValue(double value)
497 	{
498 		gtk_range_set_value(gtkRange, value);
499 	}
500 
501 	int[string] connectedSignals;
502 
503 	void delegate(double, Range)[] onAdjustBoundsListeners;
504 	/**
505 	 * Emitted before clamping a value, to give the application a
506 	 * chance to adjust the bounds.
507 	 *
508 	 * Params:
509 	 *     value = the value before we clamp
510 	 */
511 	void addOnAdjustBounds(void delegate(double, Range) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
512 	{
513 		if ( "adjust-bounds" !in connectedSignals )
514 		{
515 			Signals.connectData(
516 				this,
517 				"adjust-bounds",
518 				cast(GCallback)&callBackAdjustBounds,
519 				cast(void*)this,
520 				null,
521 				connectFlags);
522 			connectedSignals["adjust-bounds"] = 1;
523 		}
524 		onAdjustBoundsListeners ~= dlg;
525 	}
526 	extern(C) static void callBackAdjustBounds(GtkRange* rangeStruct, double value, Range _range)
527 	{
528 		foreach ( void delegate(double, Range) dlg; _range.onAdjustBoundsListeners )
529 		{
530 			dlg(value, _range);
531 		}
532 	}
533 
534 	bool delegate(GtkScrollType, double, Range)[] onChangeValueListeners;
535 	/**
536 	 * The #GtkRange::change-value signal is emitted when a scroll action is
537 	 * performed on a range.  It allows an application to determine the
538 	 * type of scroll event that occurred and the resultant new value.
539 	 * The application can handle the event itself and return %TRUE to
540 	 * prevent further processing.  Or, by returning %FALSE, it can pass
541 	 * the event to other handlers until the default GTK+ handler is
542 	 * reached.
543 	 *
544 	 * The value parameter is unrounded.  An application that overrides
545 	 * the GtkRange::change-value signal is responsible for clamping the
546 	 * value to the desired number of decimal digits; the default GTK+
547 	 * handler clamps the value based on #GtkRange:round-digits.
548 	 *
549 	 * It is not possible to use delayed update policies in an overridden
550 	 * #GtkRange::change-value handler.
551 	 *
552 	 * Params:
553 	 *     scroll = the type of scroll action that was performed
554 	 *     value = the new value resulting from the scroll action
555 	 *
556 	 * Return: %TRUE to prevent other handlers from being invoked for
557 	 *     the signal, %FALSE to propagate the signal further
558 	 *
559 	 * Since: 2.6
560 	 */
561 	void addOnChangeValue(bool delegate(GtkScrollType, double, Range) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
562 	{
563 		if ( "change-value" !in connectedSignals )
564 		{
565 			Signals.connectData(
566 				this,
567 				"change-value",
568 				cast(GCallback)&callBackChangeValue,
569 				cast(void*)this,
570 				null,
571 				connectFlags);
572 			connectedSignals["change-value"] = 1;
573 		}
574 		onChangeValueListeners ~= dlg;
575 	}
576 	extern(C) static int callBackChangeValue(GtkRange* rangeStruct, GtkScrollType scroll, double value, Range _range)
577 	{
578 		foreach ( bool delegate(GtkScrollType, double, Range) dlg; _range.onChangeValueListeners )
579 		{
580 			if ( dlg(scroll, value, _range) )
581 			{
582 				return 1;
583 			}
584 		}
585 		
586 		return 0;
587 	}
588 
589 	void delegate(GtkScrollType, Range)[] onMoveSliderListeners;
590 	/**
591 	 * Virtual function that moves the slider. Used for keybindings.
592 	 *
593 	 * Params:
594 	 *     step = how to move the slider
595 	 */
596 	void addOnMoveSlider(void delegate(GtkScrollType, Range) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
597 	{
598 		if ( "move-slider" !in connectedSignals )
599 		{
600 			Signals.connectData(
601 				this,
602 				"move-slider",
603 				cast(GCallback)&callBackMoveSlider,
604 				cast(void*)this,
605 				null,
606 				connectFlags);
607 			connectedSignals["move-slider"] = 1;
608 		}
609 		onMoveSliderListeners ~= dlg;
610 	}
611 	extern(C) static void callBackMoveSlider(GtkRange* rangeStruct, GtkScrollType step, Range _range)
612 	{
613 		foreach ( void delegate(GtkScrollType, Range) dlg; _range.onMoveSliderListeners )
614 		{
615 			dlg(step, _range);
616 		}
617 	}
618 
619 	void delegate(Range)[] onValueChangedListeners;
620 	/**
621 	 * Emitted when the range value changes.
622 	 */
623 	void addOnValueChanged(void delegate(Range) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
624 	{
625 		if ( "value-changed" !in connectedSignals )
626 		{
627 			Signals.connectData(
628 				this,
629 				"value-changed",
630 				cast(GCallback)&callBackValueChanged,
631 				cast(void*)this,
632 				null,
633 				connectFlags);
634 			connectedSignals["value-changed"] = 1;
635 		}
636 		onValueChangedListeners ~= dlg;
637 	}
638 	extern(C) static void callBackValueChanged(GtkRange* rangeStruct, Range _range)
639 	{
640 		foreach ( void delegate(Range) dlg; _range.onValueChangedListeners )
641 		{
642 			dlg(_range);
643 		}
644 	}
645 }