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.Scale;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import gtk.Adjustment;
31 private import gtk.Range;
32 private import gtk.Widget;
33 private import gtk.c.functions;
34 public  import gtk.c.types;
35 private import pango.PgLayout;
36 
37 
38 /**
39  * A `GtkScale` is a slider control used to select a numeric value.
40  * 
41  * ![An example GtkScale](scales.png)
42  * 
43  * To use it, you’ll probably want to investigate the methods on its base
44  * class, [class@GtkRange], in addition to the methods for `GtkScale` itself.
45  * To set the value of a scale, you would normally use [method@Gtk.Range.set_value].
46  * To detect changes to the value, you would normally use the
47  * [signal@Gtk.Range::value-changed] signal.
48  * 
49  * Note that using the same upper and lower bounds for the `GtkScale` (through
50  * the `GtkRange` methods) will hide the slider itself. This is useful for
51  * applications that want to show an undeterminate value on the scale, without
52  * changing the layout of the application (such as movie or music players).
53  * 
54  * # GtkScale as GtkBuildable
55  * 
56  * `GtkScale` supports a custom <marks> element, which can contain multiple
57  * <mark\> elements. The “value” and “position” attributes have the same
58  * meaning as [method@Gtk.Scale.add_mark] parameters of the same name. If
59  * the element is not empty, its content is taken as the markup to show at
60  * the mark. It can be translated with the usual ”translatable” and
61  * “context” attributes.
62  * 
63  * # CSS nodes
64  * 
65  * ```
66  * scale[.fine-tune][.marks-before][.marks-after]
67  * ├── [value][.top][.right][.bottom][.left]
68  * ├── marks.top
69  * │   ├── mark
70  * │   ┊    ├── [label]
71  * │   ┊    ╰── indicator
72  * ┊   ┊
73  * │   ╰── mark
74  * ├── marks.bottom
75  * │   ├── mark
76  * │   ┊    ├── indicator
77  * │   ┊    ╰── [label]
78  * ┊   ┊
79  * │   ╰── mark
80  * ╰── trough
81  * ├── [fill]
82  * ├── [highlight]
83  * ╰── slider
84  * ```
85  * 
86  * `GtkScale` has a main CSS node with name scale and a subnode for its contents,
87  * with subnodes named trough and slider.
88  * 
89  * The main node gets the style class .fine-tune added when the scale is in
90  * 'fine-tuning' mode.
91  * 
92  * If the scale has an origin (see [method@Gtk.Scale.set_has_origin]), there is
93  * a subnode with name highlight below the trough node that is used for rendering
94  * the highlighted part of the trough.
95  * 
96  * If the scale is showing a fill level (see [method@Gtk.Range.set_show_fill_level]),
97  * there is a subnode with name fill below the trough node that is used for
98  * rendering the filled in part of the trough.
99  * 
100  * If marks are present, there is a marks subnode before or after the trough
101  * node, below which each mark gets a node with name mark. The marks nodes get
102  * either the .top or .bottom style class.
103  * 
104  * The mark node has a subnode named indicator. If the mark has text, it also
105  * has a subnode named label. When the mark is either above or left of the
106  * scale, the label subnode is the first when present. Otherwise, the indicator
107  * subnode is the first.
108  * 
109  * The main CSS node gets the 'marks-before' and/or 'marks-after' style classes
110  * added depending on what marks are present.
111  * 
112  * If the scale is displaying the value (see [property@Gtk.Scale:draw-value]),
113  * there is subnode with name value. This node will get the .top or .bottom style
114  * classes similar to the marks node.
115  * 
116  * # Accessibility
117  * 
118  * `GtkScale` uses the %GTK_ACCESSIBLE_ROLE_SLIDER role.
119  */
120 public class Scale : Range
121 {
122 	/** the main Gtk struct */
123 	protected GtkScale* gtkScale;
124 
125 	/** Get the main Gtk struct */
126 	public GtkScale* getScaleStruct(bool transferOwnership = false)
127 	{
128 		if (transferOwnership)
129 			ownedRef = false;
130 		return gtkScale;
131 	}
132 
133 	/** the main Gtk struct as a void* */
134 	protected override void* getStruct()
135 	{
136 		return cast(void*)gtkScale;
137 	}
138 
139 	/**
140 	 * Sets our main struct and passes it to the parent class.
141 	 */
142 	public this (GtkScale* gtkScale, bool ownedRef = false)
143 	{
144 		this.gtkScale = gtkScale;
145 		super(cast(GtkRange*)gtkScale, ownedRef);
146 	}
147 
148 
149 	/** */
150 	public static GType getType()
151 	{
152 		return gtk_scale_get_type();
153 	}
154 
155 	/**
156 	 * Creates a new `GtkScale`.
157 	 *
158 	 * Params:
159 	 *     orientation = the scale’s orientation.
160 	 *     adjustment = the [class@Gtk.Adjustment] which sets
161 	 *         the range of the scale, or %NULL to create a new adjustment.
162 	 *
163 	 * Returns: a new `GtkScale`
164 	 *
165 	 * Throws: ConstructionException GTK+ fails to create the object.
166 	 */
167 	public this(GtkOrientation orientation, Adjustment adjustment)
168 	{
169 		auto __p = gtk_scale_new(orientation, (adjustment is null) ? null : adjustment.getAdjustmentStruct());
170 
171 		if(__p is null)
172 		{
173 			throw new ConstructionException("null returned by new");
174 		}
175 
176 		this(cast(GtkScale*) __p);
177 	}
178 
179 	/**
180 	 * Creates a new scale widget with a range from @min to @max.
181 	 *
182 	 * The returns scale will have the given orientation and will let the
183 	 * user input a number between @min and @max (including @min and @max)
184 	 * with the increment @step. @step must be nonzero; it’s the distance
185 	 * the slider moves when using the arrow keys to adjust the scale
186 	 * value.
187 	 *
188 	 * Note that the way in which the precision is derived works best if
189 	 * @step is a power of ten. If the resulting precision is not suitable
190 	 * for your needs, use [method@Gtk.Scale.set_digits] to correct it.
191 	 *
192 	 * Params:
193 	 *     orientation = the scale’s orientation.
194 	 *     min = minimum value
195 	 *     max = maximum value
196 	 *     step = step increment (tick size) used with keyboard shortcuts
197 	 *
198 	 * Returns: a new #GtkScale
199 	 *
200 	 * Throws: ConstructionException GTK+ fails to create the object.
201 	 */
202 	public this(GtkOrientation orientation, double min, double max, double step)
203 	{
204 		auto __p = gtk_scale_new_with_range(orientation, min, max, step);
205 
206 		if(__p is null)
207 		{
208 			throw new ConstructionException("null returned by new_with_range");
209 		}
210 
211 		this(cast(GtkScale*) __p);
212 	}
213 
214 	/**
215 	 * Adds a mark at @value.
216 	 *
217 	 * A mark is indicated visually by drawing a tick mark next to the scale,
218 	 * and GTK makes it easy for the user to position the scale exactly at the
219 	 * marks value.
220 	 *
221 	 * If @markup is not %NULL, text is shown next to the tick mark.
222 	 *
223 	 * To remove marks from a scale, use [method@Gtk.Scale.clear_marks].
224 	 *
225 	 * Params:
226 	 *     value = the value at which the mark is placed, must be between
227 	 *         the lower and upper limits of the scales’ adjustment
228 	 *     position = where to draw the mark. For a horizontal scale, #GTK_POS_TOP
229 	 *         and %GTK_POS_LEFT are drawn above the scale, anything else below.
230 	 *         For a vertical scale, #GTK_POS_LEFT and %GTK_POS_TOP are drawn to
231 	 *         the left of the scale, anything else to the right.
232 	 *     markup = Text to be shown at the mark, using
233 	 *         Pango markup, or %NULL
234 	 */
235 	public void addMark(double value, GtkPositionType position, string markup)
236 	{
237 		gtk_scale_add_mark(gtkScale, value, position, Str.toStringz(markup));
238 	}
239 
240 	/**
241 	 * Removes any marks that have been added.
242 	 */
243 	public void clearMarks()
244 	{
245 		gtk_scale_clear_marks(gtkScale);
246 	}
247 
248 	/**
249 	 * Gets the number of decimal places that are displayed in the value.
250 	 *
251 	 * Returns: the number of decimal places that are displayed
252 	 */
253 	public int getDigits()
254 	{
255 		return gtk_scale_get_digits(gtkScale);
256 	}
257 
258 	/**
259 	 * Returns whether the current value is displayed as a string
260 	 * next to the slider.
261 	 *
262 	 * Returns: whether the current value is displayed as a string
263 	 */
264 	public bool getDrawValue()
265 	{
266 		return gtk_scale_get_draw_value(gtkScale) != 0;
267 	}
268 
269 	/**
270 	 * Returns whether the scale has an origin.
271 	 *
272 	 * Returns: %TRUE if the scale has an origin.
273 	 */
274 	public bool getHasOrigin()
275 	{
276 		return gtk_scale_get_has_origin(gtkScale) != 0;
277 	}
278 
279 	/**
280 	 * Gets the `PangoLayout` used to display the scale.
281 	 *
282 	 * The returned object is owned by the scale so does not need
283 	 * to be freed by the caller.
284 	 *
285 	 * Returns: the [class@Pango.Layout]
286 	 *     for this scale, or %NULL if the [property@GtkScale:draw-value]
287 	 *     property is %FALSE.
288 	 */
289 	public PgLayout getLayout()
290 	{
291 		auto __p = gtk_scale_get_layout(gtkScale);
292 
293 		if(__p is null)
294 		{
295 			return null;
296 		}
297 
298 		return ObjectG.getDObject!(PgLayout)(cast(PangoLayout*) __p);
299 	}
300 
301 	/**
302 	 * Obtains the coordinates where the scale will draw the
303 	 * `PangoLayout` representing the text in the scale.
304 	 *
305 	 * Remember when using the `PangoLayout` function you need to
306 	 * convert to and from pixels using `PANGO_PIXELS()` or `PANGO_SCALE`.
307 	 *
308 	 * If the [property@GtkScale:draw-value] property is %FALSE, the return
309 	 * values are undefined.
310 	 *
311 	 * Params:
312 	 *     x = location to store X offset of layout, or %NULL
313 	 *     y = location to store Y offset of layout, or %NULL
314 	 */
315 	public void getLayoutOffsets(out int x, out int y)
316 	{
317 		gtk_scale_get_layout_offsets(gtkScale, &x, &y);
318 	}
319 
320 	/**
321 	 * Gets the position in which the current value is displayed.
322 	 *
323 	 * Returns: the position in which the current value is displayed
324 	 */
325 	public GtkPositionType getValuePos()
326 	{
327 		return gtk_scale_get_value_pos(gtkScale);
328 	}
329 
330 	/**
331 	 * Sets the number of decimal places that are displayed in the value.
332 	 *
333 	 * Also causes the value of the adjustment to be rounded to this number
334 	 * of digits, so the retrieved value matches the displayed one, if
335 	 * [property@GtkScale:draw-value] is %TRUE when the value changes. If
336 	 * you want to enforce rounding the value when [property@GtkScale:draw-value]
337 	 * is %FALSE, you can set [property@GtkRange:round-digits] instead.
338 	 *
339 	 * Note that rounding to a small number of digits can interfere with
340 	 * the smooth autoscrolling that is built into `GtkScale`. As an alternative,
341 	 * you can use [method@Gtk.Scale.set_format_value_func] to format the displayed
342 	 * value yourself.
343 	 *
344 	 * Params:
345 	 *     digits = the number of decimal places to display,
346 	 *         e.g. use 1 to display 1.0, 2 to display 1.00, etc
347 	 */
348 	public void setDigits(int digits)
349 	{
350 		gtk_scale_set_digits(gtkScale, digits);
351 	}
352 
353 	/**
354 	 * Specifies whether the current value is displayed as a string next
355 	 * to the slider.
356 	 *
357 	 * Params:
358 	 *     drawValue = %TRUE to draw the value
359 	 */
360 	public void setDrawValue(bool drawValue)
361 	{
362 		gtk_scale_set_draw_value(gtkScale, drawValue);
363 	}
364 
365 	/**
366 	 * @func allows you to change how the scale value is displayed.
367 	 *
368 	 * The given function will return an allocated string representing
369 	 * @value. That string will then be used to display the scale's value.
370 	 *
371 	 * If #NULL is passed as @func, the value will be displayed on
372 	 * its own, rounded according to the value of the
373 	 * [property@GtkScale:digits] property.
374 	 *
375 	 * Params:
376 	 *     func = function that formats the value
377 	 *     userData = user data to pass to @func
378 	 *     destroyNotify = destroy function for @user_data
379 	 */
380 	public void setFormatValueFunc(GtkScaleFormatValueFunc func, void* userData, GDestroyNotify destroyNotify)
381 	{
382 		gtk_scale_set_format_value_func(gtkScale, func, userData, destroyNotify);
383 	}
384 
385 	/**
386 	 * Sets whether the scale has an origin.
387 	 *
388 	 * If [property@GtkScale:has-origin] is set to %TRUE (the default),
389 	 * the scale will highlight the part of the trough between the origin
390 	 * (bottom or left side) and the current value.
391 	 *
392 	 * Params:
393 	 *     hasOrigin = %TRUE if the scale has an origin
394 	 */
395 	public void setHasOrigin(bool hasOrigin)
396 	{
397 		gtk_scale_set_has_origin(gtkScale, hasOrigin);
398 	}
399 
400 	/**
401 	 * Sets the position in which the current value is displayed.
402 	 *
403 	 * Params:
404 	 *     pos = the position in which the current value is displayed
405 	 */
406 	public void setValuePos(GtkPositionType pos)
407 	{
408 		gtk_scale_set_value_pos(gtkScale, pos);
409 	}
410 }