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