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