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.ScaleButton;
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.Button;
33 private import gtk.OrientableIF;
34 private import gtk.OrientableT;
35 private import gtk.Widget;
36 private import gtk.c.functions;
37 public  import gtk.c.types;
38 public  import gtkc.gtktypes;
39 private import std.algorithm;
40 
41 
42 /**
43  * #GtkScaleButton provides a button which pops up a scale widget.
44  * This kind of widget is commonly used for volume controls in multimedia
45  * applications, and GTK+ provides a #GtkVolumeButton subclass that
46  * is tailored for this use case.
47  * 
48  * # CSS nodes
49  * 
50  * GtkScaleButton has a single CSS node with name button. To differentiate
51  * it from a plain #GtkButton, it gets the .scale style class.
52  */
53 public class ScaleButton : Button, OrientableIF
54 {
55 	/** the main Gtk struct */
56 	protected GtkScaleButton* gtkScaleButton;
57 
58 	/** Get the main Gtk struct */
59 	public GtkScaleButton* getScaleButtonStruct(bool transferOwnership = false)
60 	{
61 		if (transferOwnership)
62 			ownedRef = false;
63 		return gtkScaleButton;
64 	}
65 
66 	/** the main Gtk struct as a void* */
67 	protected override void* getStruct()
68 	{
69 		return cast(void*)gtkScaleButton;
70 	}
71 
72 	/**
73 	 * Sets our main struct and passes it to the parent class.
74 	 */
75 	public this (GtkScaleButton* gtkScaleButton, bool ownedRef = false)
76 	{
77 		this.gtkScaleButton = gtkScaleButton;
78 		super(cast(GtkButton*)gtkScaleButton, ownedRef);
79 	}
80 
81 	// add the Orientable capabilities
82 	mixin OrientableT!(GtkScaleButton);
83 
84 
85 	/** */
86 	public static GType getType()
87 	{
88 		return gtk_scale_button_get_type();
89 	}
90 
91 	/**
92 	 * Creates a #GtkScaleButton, with a range between @min and @max, with
93 	 * a stepping of @step.
94 	 *
95 	 * Params:
96 	 *     size = a stock icon size (#GtkIconSize)
97 	 *     min = the minimum value of the scale (usually 0)
98 	 *     max = the maximum value of the scale (usually 100)
99 	 *     step = the stepping of value when a scroll-wheel event,
100 	 *         or up/down arrow event occurs (usually 2)
101 	 *     icons = a %NULL-terminated
102 	 *         array of icon names, or %NULL if you want to set the list
103 	 *         later with gtk_scale_button_set_icons()
104 	 *
105 	 * Returns: a new #GtkScaleButton
106 	 *
107 	 * Since: 2.12
108 	 *
109 	 * Throws: ConstructionException GTK+ fails to create the object.
110 	 */
111 	public this(GtkIconSize size, double min, double max, double step, string[] icons)
112 	{
113 		auto p = gtk_scale_button_new(size, min, max, step, Str.toStringzArray(icons));
114 
115 		if(p is null)
116 		{
117 			throw new ConstructionException("null returned by new");
118 		}
119 
120 		this(cast(GtkScaleButton*) p);
121 	}
122 
123 	/**
124 	 * Gets the #GtkAdjustment associated with the #GtkScaleButton’s scale.
125 	 * See gtk_range_get_adjustment() for details.
126 	 *
127 	 * Returns: the adjustment associated with the scale
128 	 *
129 	 * Since: 2.12
130 	 */
131 	public Adjustment getAdjustment()
132 	{
133 		auto p = gtk_scale_button_get_adjustment(gtkScaleButton);
134 
135 		if(p is null)
136 		{
137 			return null;
138 		}
139 
140 		return ObjectG.getDObject!(Adjustment)(cast(GtkAdjustment*) p);
141 	}
142 
143 	/**
144 	 * Retrieves the minus button of the #GtkScaleButton.
145 	 *
146 	 * Returns: the minus button of the #GtkScaleButton as a #GtkButton
147 	 *
148 	 * Since: 2.14
149 	 */
150 	public Button getMinusButton()
151 	{
152 		auto p = gtk_scale_button_get_minus_button(gtkScaleButton);
153 
154 		if(p is null)
155 		{
156 			return null;
157 		}
158 
159 		return ObjectG.getDObject!(Button)(cast(GtkButton*) p);
160 	}
161 
162 	/**
163 	 * Retrieves the plus button of the #GtkScaleButton.
164 	 *
165 	 * Returns: the plus button of the #GtkScaleButton as a #GtkButton
166 	 *
167 	 * Since: 2.14
168 	 */
169 	public Button getPlusButton()
170 	{
171 		auto p = gtk_scale_button_get_plus_button(gtkScaleButton);
172 
173 		if(p is null)
174 		{
175 			return null;
176 		}
177 
178 		return ObjectG.getDObject!(Button)(cast(GtkButton*) p);
179 	}
180 
181 	/**
182 	 * Retrieves the popup of the #GtkScaleButton.
183 	 *
184 	 * Returns: the popup of the #GtkScaleButton
185 	 *
186 	 * Since: 2.14
187 	 */
188 	public Widget getPopup()
189 	{
190 		auto p = gtk_scale_button_get_popup(gtkScaleButton);
191 
192 		if(p is null)
193 		{
194 			return null;
195 		}
196 
197 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
198 	}
199 
200 	/**
201 	 * Gets the current value of the scale button.
202 	 *
203 	 * Returns: current value of the scale button
204 	 *
205 	 * Since: 2.12
206 	 */
207 	public double getValue()
208 	{
209 		return gtk_scale_button_get_value(gtkScaleButton);
210 	}
211 
212 	/**
213 	 * Sets the #GtkAdjustment to be used as a model
214 	 * for the #GtkScaleButton’s scale.
215 	 * See gtk_range_set_adjustment() for details.
216 	 *
217 	 * Params:
218 	 *     adjustment = a #GtkAdjustment
219 	 *
220 	 * Since: 2.12
221 	 */
222 	public void setAdjustment(Adjustment adjustment)
223 	{
224 		gtk_scale_button_set_adjustment(gtkScaleButton, (adjustment is null) ? null : adjustment.getAdjustmentStruct());
225 	}
226 
227 	/**
228 	 * Sets the icons to be used by the scale button.
229 	 * For details, see the #GtkScaleButton:icons property.
230 	 *
231 	 * Params:
232 	 *     icons = a %NULL-terminated array of icon names
233 	 *
234 	 * Since: 2.12
235 	 */
236 	public void setIcons(string[] icons)
237 	{
238 		gtk_scale_button_set_icons(gtkScaleButton, Str.toStringzArray(icons));
239 	}
240 
241 	/**
242 	 * Sets the current value of the scale; if the value is outside
243 	 * the minimum or maximum range values, it will be clamped to fit
244 	 * inside them. The scale button emits the #GtkScaleButton::value-changed
245 	 * signal if the value changes.
246 	 *
247 	 * Params:
248 	 *     value = new value of the scale button
249 	 *
250 	 * Since: 2.12
251 	 */
252 	public void setValue(double value)
253 	{
254 		gtk_scale_button_set_value(gtkScaleButton, value);
255 	}
256 
257 	protected class OnPopdownDelegateWrapper
258 	{
259 		void delegate(ScaleButton) dlg;
260 		gulong handlerId;
261 
262 		this(void delegate(ScaleButton) dlg)
263 		{
264 			this.dlg = dlg;
265 			onPopdownListeners ~= this;
266 		}
267 
268 		void remove(OnPopdownDelegateWrapper source)
269 		{
270 			foreach(index, wrapper; onPopdownListeners)
271 			{
272 				if (wrapper.handlerId == source.handlerId)
273 				{
274 					onPopdownListeners[index] = null;
275 					onPopdownListeners = std.algorithm.remove(onPopdownListeners, index);
276 					break;
277 				}
278 			}
279 		}
280 	}
281 	OnPopdownDelegateWrapper[] onPopdownListeners;
282 
283 	/**
284 	 * The ::popdown signal is a
285 	 * [keybinding signal][GtkBindingSignal]
286 	 * which gets emitted to popdown the scale widget.
287 	 *
288 	 * The default binding for this signal is Escape.
289 	 *
290 	 * Since: 2.12
291 	 */
292 	gulong addOnPopdown(void delegate(ScaleButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
293 	{
294 		auto wrapper = new OnPopdownDelegateWrapper(dlg);
295 		wrapper.handlerId = Signals.connectData(
296 			this,
297 			"popdown",
298 			cast(GCallback)&callBackPopdown,
299 			cast(void*)wrapper,
300 			cast(GClosureNotify)&callBackPopdownDestroy,
301 			connectFlags);
302 		return wrapper.handlerId;
303 	}
304 
305 	extern(C) static void callBackPopdown(GtkScaleButton* scalebuttonStruct, OnPopdownDelegateWrapper wrapper)
306 	{
307 		wrapper.dlg(wrapper.outer);
308 	}
309 
310 	extern(C) static void callBackPopdownDestroy(OnPopdownDelegateWrapper wrapper, GClosure* closure)
311 	{
312 		wrapper.remove(wrapper);
313 	}
314 
315 	protected class OnPopupDelegateWrapper
316 	{
317 		void delegate(ScaleButton) dlg;
318 		gulong handlerId;
319 
320 		this(void delegate(ScaleButton) dlg)
321 		{
322 			this.dlg = dlg;
323 			onPopupListeners ~= this;
324 		}
325 
326 		void remove(OnPopupDelegateWrapper source)
327 		{
328 			foreach(index, wrapper; onPopupListeners)
329 			{
330 				if (wrapper.handlerId == source.handlerId)
331 				{
332 					onPopupListeners[index] = null;
333 					onPopupListeners = std.algorithm.remove(onPopupListeners, index);
334 					break;
335 				}
336 			}
337 		}
338 	}
339 	OnPopupDelegateWrapper[] onPopupListeners;
340 
341 	/**
342 	 * The ::popup signal is a
343 	 * [keybinding signal][GtkBindingSignal]
344 	 * which gets emitted to popup the scale widget.
345 	 *
346 	 * The default bindings for this signal are Space, Enter and Return.
347 	 *
348 	 * Since: 2.12
349 	 */
350 	gulong addOnPopup(void delegate(ScaleButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
351 	{
352 		auto wrapper = new OnPopupDelegateWrapper(dlg);
353 		wrapper.handlerId = Signals.connectData(
354 			this,
355 			"popup",
356 			cast(GCallback)&callBackPopup,
357 			cast(void*)wrapper,
358 			cast(GClosureNotify)&callBackPopupDestroy,
359 			connectFlags);
360 		return wrapper.handlerId;
361 	}
362 
363 	extern(C) static void callBackPopup(GtkScaleButton* scalebuttonStruct, OnPopupDelegateWrapper wrapper)
364 	{
365 		wrapper.dlg(wrapper.outer);
366 	}
367 
368 	extern(C) static void callBackPopupDestroy(OnPopupDelegateWrapper wrapper, GClosure* closure)
369 	{
370 		wrapper.remove(wrapper);
371 	}
372 
373 	protected class OnValueChangedDelegateWrapper
374 	{
375 		void delegate(double, ScaleButton) dlg;
376 		gulong handlerId;
377 
378 		this(void delegate(double, ScaleButton) dlg)
379 		{
380 			this.dlg = dlg;
381 			onValueChangedListeners ~= this;
382 		}
383 
384 		void remove(OnValueChangedDelegateWrapper source)
385 		{
386 			foreach(index, wrapper; onValueChangedListeners)
387 			{
388 				if (wrapper.handlerId == source.handlerId)
389 				{
390 					onValueChangedListeners[index] = null;
391 					onValueChangedListeners = std.algorithm.remove(onValueChangedListeners, index);
392 					break;
393 				}
394 			}
395 		}
396 	}
397 	OnValueChangedDelegateWrapper[] onValueChangedListeners;
398 
399 	/**
400 	 * The ::value-changed signal is emitted when the value field has
401 	 * changed.
402 	 *
403 	 * Params:
404 	 *     value = the new value
405 	 *
406 	 * Since: 2.12
407 	 */
408 	gulong addOnValueChanged(void delegate(double, ScaleButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
409 	{
410 		auto wrapper = new OnValueChangedDelegateWrapper(dlg);
411 		wrapper.handlerId = Signals.connectData(
412 			this,
413 			"value-changed",
414 			cast(GCallback)&callBackValueChanged,
415 			cast(void*)wrapper,
416 			cast(GClosureNotify)&callBackValueChangedDestroy,
417 			connectFlags);
418 		return wrapper.handlerId;
419 	}
420 
421 	extern(C) static void callBackValueChanged(GtkScaleButton* scalebuttonStruct, double value, OnValueChangedDelegateWrapper wrapper)
422 	{
423 		wrapper.dlg(value, wrapper.outer);
424 	}
425 
426 	extern(C) static void callBackValueChangedDestroy(OnValueChangedDelegateWrapper wrapper, GClosure* closure)
427 	{
428 		wrapper.remove(wrapper);
429 	}
430 }