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.LevelBar;
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.OrientableIF;
32 private import gtk.OrientableT;
33 private import gtk.Widget;
34 public  import gtkc.gdktypes;
35 private import gtkc.gtk;
36 public  import gtkc.gtktypes;
37 
38 
39 /**
40  * The #GtkLevelBar is a bar widget that can be used
41  * as a level indicator. Typical use cases are displaying the strength
42  * of a password, or showing the charge level of a battery.
43  * 
44  * Use gtk_level_bar_set_value() to set the current value, and
45  * gtk_level_bar_add_offset_value() to set the value offsets at which
46  * the bar will be considered in a different state. GTK will add two offsets
47  * by default on the level bar: #GTK_LEVEL_BAR_OFFSET_LOW and
48  * #GTK_LEVEL_BAR_OFFSET_HIGH, with values 0.25 and 0.75 respectively.
49  * 
50  * ## Adding a custom offset on the bar
51  * 
52  * |[<!-- language="C" -->
53  * 
54  * static GtkWidget *
55  * create_level_bar (void)
56  * {
57  * GtkWidget *widget;
58  * GtkLevelBar *bar;
59  * 
60  * widget = gtk_level_bar_new ();
61  * bar = GTK_LEVEL_BAR (widget);
62  * 
63  * /<!---->* This changes the value of the default low offset
64  * *<!---->/
65  * 
66  * gtk_level_bar_add_offset_value (bar,
67  * GTK_LEVEL_BAR_OFFSET_LOW,
68  * 0.10);
69  * 
70  * /<!---->* This adds a new offset to the bar; the application will
71  * be able to change its color by using the following selector,
72  * either by adding it to its CSS file or using
73  * gtk_css_provider_load_from_data() and
74  * gtk_style_context_add_provider()
75  * 
76  * * .level-bar.fill-block.level-my-offset {
77  * *   background-color: green;
78  * *   border-style: solid;
79  * *   border-color: black;
80  * *   border-style: 1px;
81  * * }
82  * *<!---->/
83  * 
84  * gtk_level_bar_add_offset_value (bar, "my-offset", 0.60);
85  * 
86  * return widget;
87  * }
88  * ]|
89  * 
90  * The default interval of values is between zero and one, but it’s possible to
91  * modify the interval using gtk_level_bar_set_min_value() and
92  * gtk_level_bar_set_max_value(). The value will be always drawn in proportion to
93  * the admissible interval, i.e. a value of 15 with a specified interval between
94  * 10 and 20 is equivalent to a value of 0.5 with an interval between 0 and 1.
95  * When #GTK_LEVEL_BAR_MODE_DISCRETE is used, the bar level is rendered
96  * as a finite and number of separated blocks instead of a single one. The number
97  * of blocks that will be rendered is equal to the number of units specified by
98  * the admissible interval.
99  * For instance, to build a bar rendered with five blocks, it’s sufficient to
100  * set the minimum value to 0 and the maximum value to 5 after changing the indicator
101  * mode to discrete.
102  */
103 public class LevelBar : Widget, OrientableIF
104 {
105 	/** the main Gtk struct */
106 	protected GtkLevelBar* gtkLevelBar;
107 
108 	/** Get the main Gtk struct */
109 	public GtkLevelBar* getLevelBarStruct()
110 	{
111 		return gtkLevelBar;
112 	}
113 
114 	/** the main Gtk struct as a void* */
115 	protected override void* getStruct()
116 	{
117 		return cast(void*)gtkLevelBar;
118 	}
119 
120 	protected override void setStruct(GObject* obj)
121 	{
122 		gtkLevelBar = cast(GtkLevelBar*)obj;
123 		super.setStruct(obj);
124 	}
125 
126 	/**
127 	 * Sets our main struct and passes it to the parent class.
128 	 */
129 	public this (GtkLevelBar* gtkLevelBar, bool ownedRef = false)
130 	{
131 		this.gtkLevelBar = gtkLevelBar;
132 		super(cast(GtkWidget*)gtkLevelBar, ownedRef);
133 	}
134 
135 	// add the Orientable capabilities
136 	mixin OrientableT!(GtkLevelBar);
137 
138 
139 	/** */
140 	public static GType getType()
141 	{
142 		return gtk_level_bar_get_type();
143 	}
144 
145 	/**
146 	 * Creates a new #GtkLevelBar.
147 	 *
148 	 * Return: a #GtkLevelBar.
149 	 *
150 	 * Since: 3.6
151 	 *
152 	 * Throws: ConstructionException GTK+ fails to create the object.
153 	 */
154 	public this()
155 	{
156 		auto p = gtk_level_bar_new();
157 		
158 		if(p is null)
159 		{
160 			throw new ConstructionException("null returned by new");
161 		}
162 		
163 		this(cast(GtkLevelBar*) p);
164 	}
165 
166 	/**
167 	 * Utility constructor that creates a new #GtkLevelBar for the specified
168 	 * interval.
169 	 *
170 	 * Params:
171 	 *     minValue = a positive value
172 	 *     maxValue = a positive value
173 	 *
174 	 * Return: a #GtkLevelBar
175 	 *
176 	 * Since: 3.6
177 	 *
178 	 * Throws: ConstructionException GTK+ fails to create the object.
179 	 */
180 	public this(double minValue, double maxValue)
181 	{
182 		auto p = gtk_level_bar_new_for_interval(minValue, maxValue);
183 		
184 		if(p is null)
185 		{
186 			throw new ConstructionException("null returned by new_for_interval");
187 		}
188 		
189 		this(cast(GtkLevelBar*) p);
190 	}
191 
192 	/**
193 	 * Adds a new offset marker on @self at the position specified by @value.
194 	 * When the bar value is in the interval topped by @value (or between @value
195 	 * and #GtkLevelBar:max-value in case the offset is the last one on the bar)
196 	 * a style class named `level-`@name will be applied
197 	 * when rendering the level bar fill.
198 	 * If another offset marker named @name exists, its value will be
199 	 * replaced by @value.
200 	 *
201 	 * Params:
202 	 *     name = the name of the new offset
203 	 *     value = the value for the new offset
204 	 *
205 	 * Since: 3.6
206 	 */
207 	public void addOffsetValue(string name, double value)
208 	{
209 		gtk_level_bar_add_offset_value(gtkLevelBar, Str.toStringz(name), value);
210 	}
211 
212 	/**
213 	 * Return the value of the #GtkLevelBar:inverted property.
214 	 *
215 	 * Return: %TRUE if the level bar is inverted
216 	 *
217 	 * Since: 3.8
218 	 */
219 	public bool getInverted()
220 	{
221 		return gtk_level_bar_get_inverted(gtkLevelBar) != 0;
222 	}
223 
224 	/**
225 	 * Returns the value of the #GtkLevelBar:max-value property.
226 	 *
227 	 * Return: a positive value
228 	 *
229 	 * Since: 3.6
230 	 */
231 	public double getMaxValue()
232 	{
233 		return gtk_level_bar_get_max_value(gtkLevelBar);
234 	}
235 
236 	/**
237 	 * Returns the value of the #GtkLevelBar:min-value property.
238 	 *
239 	 * Return: a positive value
240 	 *
241 	 * Since: 3.6
242 	 */
243 	public double getMinValue()
244 	{
245 		return gtk_level_bar_get_min_value(gtkLevelBar);
246 	}
247 
248 	/**
249 	 * Returns the value of the #GtkLevelBar:mode property.
250 	 *
251 	 * Return: a #GtkLevelBarMode
252 	 *
253 	 * Since: 3.6
254 	 */
255 	public GtkLevelBarMode getMode()
256 	{
257 		return gtk_level_bar_get_mode(gtkLevelBar);
258 	}
259 
260 	/**
261 	 * Fetches the value specified for the offset marker @name in @self,
262 	 * returning %TRUE in case an offset named @name was found.
263 	 *
264 	 * Params:
265 	 *     name = the name of an offset in the bar
266 	 *     value = location where to store the value
267 	 *
268 	 * Return: %TRUE if the specified offset is found
269 	 *
270 	 * Since: 3.6
271 	 */
272 	public bool getOffsetValue(string name, out double value)
273 	{
274 		return gtk_level_bar_get_offset_value(gtkLevelBar, Str.toStringz(name), &value) != 0;
275 	}
276 
277 	/**
278 	 * Returns the value of the #GtkLevelBar:value property.
279 	 *
280 	 * Return: a value in the interval between
281 	 *     #GtkLevelBar:min-value and #GtkLevelBar:max-value
282 	 *
283 	 * Since: 3.6
284 	 */
285 	public double getValue()
286 	{
287 		return gtk_level_bar_get_value(gtkLevelBar);
288 	}
289 
290 	/**
291 	 * Removes an offset marker previously added with
292 	 * gtk_level_bar_add_offset_value().
293 	 *
294 	 * Params:
295 	 *     name = the name of an offset in the bar
296 	 *
297 	 * Since: 3.6
298 	 */
299 	public void removeOffsetValue(string name)
300 	{
301 		gtk_level_bar_remove_offset_value(gtkLevelBar, Str.toStringz(name));
302 	}
303 
304 	/**
305 	 * Sets the value of the #GtkLevelBar:inverted property.
306 	 *
307 	 * Params:
308 	 *     inverted = %TRUE to invert the level bar
309 	 *
310 	 * Since: 3.8
311 	 */
312 	public void setInverted(bool inverted)
313 	{
314 		gtk_level_bar_set_inverted(gtkLevelBar, inverted);
315 	}
316 
317 	/**
318 	 * Sets the value of the #GtkLevelBar:max-value property.
319 	 *
320 	 * Params:
321 	 *     value = a positive value
322 	 *
323 	 * Since: 3.6
324 	 */
325 	public void setMaxValue(double value)
326 	{
327 		gtk_level_bar_set_max_value(gtkLevelBar, value);
328 	}
329 
330 	/**
331 	 * Sets the value of the #GtkLevelBar:min-value property.
332 	 *
333 	 * Params:
334 	 *     value = a positive value
335 	 *
336 	 * Since: 3.6
337 	 */
338 	public void setMinValue(double value)
339 	{
340 		gtk_level_bar_set_min_value(gtkLevelBar, value);
341 	}
342 
343 	/**
344 	 * Sets the value of the #GtkLevelBar:mode property.
345 	 *
346 	 * Params:
347 	 *     mode = a #GtkLevelBarMode
348 	 *
349 	 * Since: 3.6
350 	 */
351 	public void setMode(GtkLevelBarMode mode)
352 	{
353 		gtk_level_bar_set_mode(gtkLevelBar, mode);
354 	}
355 
356 	/**
357 	 * Sets the value of the #GtkLevelBar:value property.
358 	 *
359 	 * Params:
360 	 *     value = a value in the interval between
361 	 *         #GtkLevelBar:min-value and #GtkLevelBar:max-value
362 	 *
363 	 * Since: 3.6
364 	 */
365 	public void setValue(double value)
366 	{
367 		gtk_level_bar_set_value(gtkLevelBar, value);
368 	}
369 
370 	int[string] connectedSignals;
371 
372 	void delegate(string, LevelBar)[] onOffsetChangedListeners;
373 	/**
374 	 * Emitted when an offset specified on the bar changes value as an
375 	 * effect to gtk_level_bar_add_offset_value() being called.
376 	 *
377 	 * The signal supports detailed connections; you can connect to the
378 	 * detailed signal "changed::x" in order to only receive callbacks when
379 	 * the value of offset "x" changes.
380 	 *
381 	 * Params:
382 	 *     name = the name of the offset that changed value
383 	 *
384 	 * Since: 3.6
385 	 */
386 	void addOnOffsetChanged(void delegate(string, LevelBar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
387 	{
388 		if ( "offset-changed" !in connectedSignals )
389 		{
390 			Signals.connectData(
391 				this,
392 				"offset-changed",
393 				cast(GCallback)&callBackOffsetChanged,
394 				cast(void*)this,
395 				null,
396 				connectFlags);
397 			connectedSignals["offset-changed"] = 1;
398 		}
399 		onOffsetChangedListeners ~= dlg;
400 	}
401 	extern(C) static void callBackOffsetChanged(GtkLevelBar* levelbarStruct, char* name, LevelBar _levelbar)
402 	{
403 		foreach ( void delegate(string, LevelBar) dlg; _levelbar.onOffsetChangedListeners )
404 		{
405 			dlg(Str.toString(name), _levelbar);
406 		}
407 	}
408 }