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  * 	- gtk_
42  * omit structs:
43  * omit prefixes:
44  * omit code:
45  * omit signals:
46  * imports:
47  * 	- glib.Str
48  * 	- pango.PgLayout
49  * structWrap:
50  * 	- PangoLayout* -> PgLayout
51  * module aliases:
52  * local aliases:
53  * overrides:
54  */
55 
56 module gtk.Scale;
57 
58 public  import gtkc.gtktypes;
59 
60 private import gtkc.gtk;
61 private import glib.ConstructionException;
62 private import gobject.ObjectG;
63 
64 private import gobject.Signals;
65 public  import gtkc.gdktypes;
66 
67 private import glib.Str;
68 private import pango.PgLayout;
69 
70 
71 
72 private import gtk.Range;
73 
74 /**
75  * Description
76  * A GtkScale is a slider control used to select a numeric value.
77  * To use it, you'll probably want to investigate the methods on
78  * its base class, GtkRange, in addition to the methods for GtkScale itself.
79  * To set the value of a scale, you would normally use gtk_range_set_value().
80  * To detect changes to the value, you would normally use the "value_changed"
81  * signal.
82  * The GtkScale widget is an abstract class, used only for deriving the
83  * subclasses GtkHScale and GtkVScale. To create a scale widget,
84  * call gtk_hscale_new_with_range() or gtk_vscale_new_with_range().
85  * GtkScale as GtkBuildable
86  * GtkScale supports a custom <marks> element, which
87  * can contain multiple <mark> elements. The "value" and "position"
88  * attributes have the same meaning as gtk_scale_add_mark() parameters of the
89  * same name. If the element is not empty, its content is taken as the markup
90  * to show at the mark. It can be translated with the usual "translatable and
91  * "context" attributes.
92  */
93 public class Scale : Range
94 {
95 	
96 	/** the main Gtk struct */
97 	protected GtkScale* gtkScale;
98 	
99 	
100 	public GtkScale* getScaleStruct()
101 	{
102 		return gtkScale;
103 	}
104 	
105 	
106 	/** the main Gtk struct as a void* */
107 	protected override void* getStruct()
108 	{
109 		return cast(void*)gtkScale;
110 	}
111 	
112 	/**
113 	 * Sets our main struct and passes it to the parent class
114 	 */
115 	public this (GtkScale* gtkScale)
116 	{
117 		super(cast(GtkRange*)gtkScale);
118 		this.gtkScale = gtkScale;
119 	}
120 	
121 	protected override void setStruct(GObject* obj)
122 	{
123 		super.setStruct(obj);
124 		gtkScale = cast(GtkScale*)obj;
125 	}
126 	
127 	/**
128 	 */
129 	int[string] connectedSignals;
130 	
131 	string delegate(gdouble, Scale)[] onFormatValueListeners;
132 	/**
133 	 * Signal which allows you to change how the scale value is displayed.
134 	 * Connect a signal handler which returns an allocated string representing
135 	 * value. That string will then be used to display the scale's value.
136 	 * Here's an example signal handler which displays a value 1.0 as
137 	 * with "-->1.0<--".
138 	 * $(DDOC_COMMENT example)
139 	 */
140 	void addOnFormatValue(string delegate(gdouble, Scale) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
141 	{
142 		if ( !("format-value" in connectedSignals) )
143 		{
144 			Signals.connectData(
145 			getStruct(),
146 			"format-value",
147 			cast(GCallback)&callBackFormatValue,
148 			cast(void*)this,
149 			null,
150 			connectFlags);
151 			connectedSignals["format-value"] = 1;
152 		}
153 		onFormatValueListeners ~= dlg;
154 	}
155 	extern(C) static void callBackFormatValue(GtkScale* scaleStruct, gdouble value, Scale _scale)
156 	{
157 		foreach ( string delegate(gdouble, Scale) dlg ; _scale.onFormatValueListeners )
158 		{
159 			dlg(value, _scale);
160 		}
161 	}
162 	
163 	
164 	/**
165 	 * Sets the number of decimal places that are displayed in the value.
166 	 * Also causes the value of the adjustment to be rounded off to this
167 	 * number of digits, so the retrieved value matches the value the user saw.
168 	 * Params:
169 	 * digits = the number of decimal places to display,
170 	 * e.g. use 1 to display 1.0, 2 to display 1.00, etc
171 	 */
172 	public void setDigits(int digits)
173 	{
174 		// void gtk_scale_set_digits (GtkScale *scale,  gint digits);
175 		gtk_scale_set_digits(gtkScale, digits);
176 	}
177 	
178 	/**
179 	 * Specifies whether the current value is displayed as a string next
180 	 * to the slider.
181 	 * Params:
182 	 * drawValue = TRUE to draw the value
183 	 */
184 	public void setDrawValue(int drawValue)
185 	{
186 		// void gtk_scale_set_draw_value (GtkScale *scale,  gboolean draw_value);
187 		gtk_scale_set_draw_value(gtkScale, drawValue);
188 	}
189 	
190 	/**
191 	 * Sets the position in which the current value is displayed.
192 	 * Params:
193 	 * pos = the position in which the current value is displayed
194 	 */
195 	public void setValuePos(GtkPositionType pos)
196 	{
197 		// void gtk_scale_set_value_pos (GtkScale *scale,  GtkPositionType pos);
198 		gtk_scale_set_value_pos(gtkScale, pos);
199 	}
200 	
201 	/**
202 	 * Gets the number of decimal places that are displayed in the value.
203 	 * Returns: the number of decimal places that are displayed
204 	 */
205 	public int getDigits()
206 	{
207 		// gint gtk_scale_get_digits (GtkScale *scale);
208 		return gtk_scale_get_digits(gtkScale);
209 	}
210 	
211 	/**
212 	 * Returns whether the current value is displayed as a string
213 	 * next to the slider.
214 	 * Returns: whether the current value is displayed as a string
215 	 */
216 	public int getDrawValue()
217 	{
218 		// gboolean gtk_scale_get_draw_value (GtkScale *scale);
219 		return gtk_scale_get_draw_value(gtkScale);
220 	}
221 	
222 	/**
223 	 * Gets the position in which the current value is displayed.
224 	 * Returns: the position in which the current value is displayed
225 	 */
226 	public GtkPositionType getValuePos()
227 	{
228 		// GtkPositionType gtk_scale_get_value_pos (GtkScale *scale);
229 		return gtk_scale_get_value_pos(gtkScale);
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 	 * Since 2.4
237 	 * Returns: the PangoLayout for this scale, or NULL if the "draw-value" property is FALSE. [transfer none]
238 	 */
239 	public PgLayout getLayout()
240 	{
241 		// PangoLayout * gtk_scale_get_layout (GtkScale *scale);
242 		auto p = gtk_scale_get_layout(gtkScale);
243 		
244 		if(p is null)
245 		{
246 			return null;
247 		}
248 		
249 		return ObjectG.getDObject!(PgLayout)(cast(PangoLayout*) p);
250 	}
251 	
252 	/**
253 	 * Obtains the coordinates where the scale will draw the
254 	 * PangoLayout representing the text in the scale. Remember
255 	 * when using the PangoLayout function you need to convert to
256 	 * and from pixels using PANGO_PIXELS() or PANGO_SCALE.
257 	 * If the "draw-value" property is FALSE, the return
258 	 * values are undefined.
259 	 * Since 2.4
260 	 * Params:
261 	 * x = location to store X offset of layout, or NULL. [out][allow-none]
262 	 * y = location to store Y offset of layout, or NULL. [out][allow-none]
263 	 */
264 	public void getLayoutOffsets(out int x, out int y)
265 	{
266 		// void gtk_scale_get_layout_offsets (GtkScale *scale,  gint *x,  gint *y);
267 		gtk_scale_get_layout_offsets(gtkScale, &x, &y);
268 	}
269 	
270 	/**
271 	 * Adds a mark at value.
272 	 * A mark is indicated visually by drawing a tick mark next to the scale,
273 	 * and GTK+ makes it easy for the user to position the scale exactly at the
274 	 * marks value.
275 	 * If markup is not NULL, text is shown next to the tick mark.
276 	 * To remove marks from a scale, use gtk_scale_clear_marks().
277 	 * Since 2.16
278 	 * Params:
279 	 * value = the value at which the mark is placed, must be between
280 	 * the lower and upper limits of the scales' adjustment
281 	 * position = where to draw the mark. For a horizontal scale, GTK_POS_TOP
282 	 * is drawn above the scale, anything else below. For a vertical scale,
283 	 * GTK_POS_LEFT is drawn to the left of the scale, anything else to the
284 	 * right.
285 	 * markup = Text to be shown at the mark, using Pango markup, or NULL. [allow-none]
286 	 */
287 	public void addMark(double value, GtkPositionType position, string markup)
288 	{
289 		// void gtk_scale_add_mark (GtkScale *scale,  gdouble value,  GtkPositionType position,  const gchar *markup);
290 		gtk_scale_add_mark(gtkScale, value, position, Str.toStringz(markup));
291 	}
292 	
293 	/**
294 	 * Removes any marks that have been added with gtk_scale_add_mark().
295 	 * Since 2.16
296 	 */
297 	public void clearMarks()
298 	{
299 		// void gtk_scale_clear_marks (GtkScale *scale);
300 		gtk_scale_clear_marks(gtkScale);
301 	}
302 }