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 
141 	public static GType getType()
142 	{
143 		return gtk_level_bar_get_type();
144 	}
145 
146 	/**
147 	 * Creates a new #GtkLevelBar.
148 	 *
149 	 * Return: a #GtkLevelBar.
150 	 *
151 	 * Since: 3.6
152 	 *
153 	 * Throws: ConstructionException GTK+ fails to create the object.
154 	 */
155 	public this()
156 	{
157 		auto p = gtk_level_bar_new();
158 		
159 		if(p is null)
160 		{
161 			throw new ConstructionException("null returned by new");
162 		}
163 		
164 		this(cast(GtkLevelBar*) p);
165 	}
166 
167 	/**
168 	 * Utility constructor that creates a new #GtkLevelBar for the specified
169 	 * interval.
170 	 *
171 	 * Params:
172 	 *     minValue = a positive value
173 	 *     maxValue = a positive value
174 	 *
175 	 * Return: a #GtkLevelBar
176 	 *
177 	 * Since: 3.6
178 	 *
179 	 * Throws: ConstructionException GTK+ fails to create the object.
180 	 */
181 	public this(double minValue, double maxValue)
182 	{
183 		auto p = gtk_level_bar_new_for_interval(minValue, maxValue);
184 		
185 		if(p is null)
186 		{
187 			throw new ConstructionException("null returned by new_for_interval");
188 		}
189 		
190 		this(cast(GtkLevelBar*) p);
191 	}
192 
193 	/**
194 	 * Adds a new offset marker on @self at the position specified by @value.
195 	 * When the bar value is in the interval topped by @value (or between @value
196 	 * and #GtkLevelBar:max-value in case the offset is the last one on the bar)
197 	 * a style class named `level-`@name will be applied
198 	 * when rendering the level bar fill.
199 	 * If another offset marker named @name exists, its value will be
200 	 * replaced by @value.
201 	 *
202 	 * Params:
203 	 *     name = the name of the new offset
204 	 *     value = the value for the new offset
205 	 *
206 	 * Since: 3.6
207 	 */
208 	public void addOffsetValue(string name, double value)
209 	{
210 		gtk_level_bar_add_offset_value(gtkLevelBar, Str.toStringz(name), value);
211 	}
212 
213 	/**
214 	 * Return the value of the #GtkLevelBar:inverted property.
215 	 *
216 	 * Return: %TRUE if the level bar is inverted
217 	 *
218 	 * Since: 3.8
219 	 */
220 	public bool getInverted()
221 	{
222 		return gtk_level_bar_get_inverted(gtkLevelBar) != 0;
223 	}
224 
225 	/**
226 	 * Returns the value of the #GtkLevelBar:max-value property.
227 	 *
228 	 * Return: a positive value
229 	 *
230 	 * Since: 3.6
231 	 */
232 	public double getMaxValue()
233 	{
234 		return gtk_level_bar_get_max_value(gtkLevelBar);
235 	}
236 
237 	/**
238 	 * Returns the value of the #GtkLevelBar:min-value property.
239 	 *
240 	 * Return: a positive value
241 	 *
242 	 * Since: 3.6
243 	 */
244 	public double getMinValue()
245 	{
246 		return gtk_level_bar_get_min_value(gtkLevelBar);
247 	}
248 
249 	/**
250 	 * Returns the value of the #GtkLevelBar:mode property.
251 	 *
252 	 * Return: a #GtkLevelBarMode
253 	 *
254 	 * Since: 3.6
255 	 */
256 	public GtkLevelBarMode getMode()
257 	{
258 		return gtk_level_bar_get_mode(gtkLevelBar);
259 	}
260 
261 	/**
262 	 * Fetches the value specified for the offset marker @name in @self,
263 	 * returning %TRUE in case an offset named @name was found.
264 	 *
265 	 * Params:
266 	 *     name = the name of an offset in the bar
267 	 *     value = location where to store the value
268 	 *
269 	 * Return: %TRUE if the specified offset is found
270 	 *
271 	 * Since: 3.6
272 	 */
273 	public bool getOffsetValue(string name, out double value)
274 	{
275 		return gtk_level_bar_get_offset_value(gtkLevelBar, Str.toStringz(name), &value) != 0;
276 	}
277 
278 	/**
279 	 * Returns the value of the #GtkLevelBar:value property.
280 	 *
281 	 * Return: a value in the interval between
282 	 *     #GtkLevelBar:min-value and #GtkLevelBar:max-value
283 	 *
284 	 * Since: 3.6
285 	 */
286 	public double getValue()
287 	{
288 		return gtk_level_bar_get_value(gtkLevelBar);
289 	}
290 
291 	/**
292 	 * Removes an offset marker previously added with
293 	 * gtk_level_bar_add_offset_value().
294 	 *
295 	 * Params:
296 	 *     name = the name of an offset in the bar
297 	 *
298 	 * Since: 3.6
299 	 */
300 	public void removeOffsetValue(string name)
301 	{
302 		gtk_level_bar_remove_offset_value(gtkLevelBar, Str.toStringz(name));
303 	}
304 
305 	/**
306 	 * Sets the value of the #GtkLevelBar:inverted property.
307 	 *
308 	 * Params:
309 	 *     inverted = %TRUE to invert the level bar
310 	 *
311 	 * Since: 3.8
312 	 */
313 	public void setInverted(bool inverted)
314 	{
315 		gtk_level_bar_set_inverted(gtkLevelBar, inverted);
316 	}
317 
318 	/**
319 	 * Sets the value of the #GtkLevelBar:max-value property.
320 	 *
321 	 * Params:
322 	 *     value = a positive value
323 	 *
324 	 * Since: 3.6
325 	 */
326 	public void setMaxValue(double value)
327 	{
328 		gtk_level_bar_set_max_value(gtkLevelBar, value);
329 	}
330 
331 	/**
332 	 * Sets the value of the #GtkLevelBar:min-value property.
333 	 *
334 	 * Params:
335 	 *     value = a positive value
336 	 *
337 	 * Since: 3.6
338 	 */
339 	public void setMinValue(double value)
340 	{
341 		gtk_level_bar_set_min_value(gtkLevelBar, value);
342 	}
343 
344 	/**
345 	 * Sets the value of the #GtkLevelBar:mode property.
346 	 *
347 	 * Params:
348 	 *     mode = a #GtkLevelBarMode
349 	 *
350 	 * Since: 3.6
351 	 */
352 	public void setMode(GtkLevelBarMode mode)
353 	{
354 		gtk_level_bar_set_mode(gtkLevelBar, mode);
355 	}
356 
357 	/**
358 	 * Sets the value of the #GtkLevelBar:value property.
359 	 *
360 	 * Params:
361 	 *     value = a value in the interval between
362 	 *         #GtkLevelBar:min-value and #GtkLevelBar:max-value
363 	 *
364 	 * Since: 3.6
365 	 */
366 	public void setValue(double value)
367 	{
368 		gtk_level_bar_set_value(gtkLevelBar, value);
369 	}
370 
371 	int[string] connectedSignals;
372 
373 	void delegate(string, LevelBar)[] onOffsetChangedListeners;
374 	/**
375 	 * Emitted when an offset specified on the bar changes value as an
376 	 * effect to gtk_level_bar_add_offset_value() being called.
377 	 *
378 	 * The signal supports detailed connections; you can connect to the
379 	 * detailed signal "changed::x" in order to only receive callbacks when
380 	 * the value of offset "x" changes.
381 	 *
382 	 * Params:
383 	 *     name = the name of the offset that changed value
384 	 *
385 	 * Since: 3.6
386 	 */
387 	void addOnOffsetChanged(void delegate(string, LevelBar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
388 	{
389 		if ( "offset-changed" !in connectedSignals )
390 		{
391 			Signals.connectData(
392 				this,
393 				"offset-changed",
394 				cast(GCallback)&callBackOffsetChanged,
395 				cast(void*)this,
396 				null,
397 				connectFlags);
398 			connectedSignals["offset-changed"] = 1;
399 		}
400 		onOffsetChangedListeners ~= dlg;
401 	}
402 	extern(C) static void callBackOffsetChanged(GtkLevelBar* levelbarStruct, char* name, LevelBar _levelbar)
403 	{
404 		foreach ( void delegate(string, LevelBar) dlg; _levelbar.onOffsetChangedListeners )
405 		{
406 			dlg(Str.toString(name), _levelbar);
407 		}
408 	}
409 }