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