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