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