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.ColorButton;
26 
27 private import gdk.Color;
28 private import gdk.RGBA;
29 private import glib.ConstructionException;
30 private import glib.Str;
31 private import gobject.ObjectG;
32 private import gobject.Signals;
33 private import gtk.Button;
34 private import gtk.ColorChooserIF;
35 private import gtk.ColorChooserT;
36 private import gtk.Widget;
37 public  import gtkc.gdktypes;
38 private import gtkc.gtk;
39 public  import gtkc.gtktypes;
40 
41 
42 /**
43  * The #GtkColorButton is a button which displays the currently selected
44  * color and allows to open a color selection dialog to change the color.
45  * It is suitable widget for selecting a color in a preference dialog.
46  * 
47  * # CSS nodes
48  * 
49  * GtkColorButton has a single CSS node with name button. To differentiate
50  * it from a plain #GtkButton, it gets the .color style class.
51  */
52 public class ColorButton : Button, ColorChooserIF
53 {
54 	/** the main Gtk struct */
55 	protected GtkColorButton* gtkColorButton;
56 
57 	/** Get the main Gtk struct */
58 	public GtkColorButton* getColorButtonStruct()
59 	{
60 		return gtkColorButton;
61 	}
62 
63 	/** the main Gtk struct as a void* */
64 	protected override void* getStruct()
65 	{
66 		return cast(void*)gtkColorButton;
67 	}
68 
69 	protected override void setStruct(GObject* obj)
70 	{
71 		gtkColorButton = cast(GtkColorButton*)obj;
72 		super.setStruct(obj);
73 	}
74 
75 	/**
76 	 * Sets our main struct and passes it to the parent class.
77 	 */
78 	public this (GtkColorButton* gtkColorButton, bool ownedRef = false)
79 	{
80 		this.gtkColorButton = gtkColorButton;
81 		super(cast(GtkButton*)gtkColorButton, ownedRef);
82 	}
83 
84 	// add the ColorChooser capabilities
85 	mixin ColorChooserT!(GtkColorButton);
86 
87 
88 	/** */
89 	public static GType getType()
90 	{
91 		return gtk_color_button_get_type();
92 	}
93 
94 	/**
95 	 * Creates a new color button.
96 	 *
97 	 * This returns a widget in the form of a small button containing
98 	 * a swatch representing the current selected color. When the button
99 	 * is clicked, a color-selection dialog will open, allowing the user
100 	 * to select a color. The swatch will be updated to reflect the new
101 	 * color when the user finishes.
102 	 *
103 	 * Return: a new color button
104 	 *
105 	 * Since: 2.4
106 	 *
107 	 * Throws: ConstructionException GTK+ fails to create the object.
108 	 */
109 	public this()
110 	{
111 		auto p = gtk_color_button_new();
112 		
113 		if(p is null)
114 		{
115 			throw new ConstructionException("null returned by new");
116 		}
117 		
118 		this(cast(GtkColorButton*) p);
119 	}
120 
121 	/**
122 	 * Creates a new color button.
123 	 *
124 	 * Deprecated: Use gtk_color_button_new_with_rgba() instead.
125 	 *
126 	 * Params:
127 	 *     color = A #GdkColor to set the current color with
128 	 *
129 	 * Return: a new color button
130 	 *
131 	 * Since: 2.4
132 	 *
133 	 * Throws: ConstructionException GTK+ fails to create the object.
134 	 */
135 	public this(Color color)
136 	{
137 		auto p = gtk_color_button_new_with_color((color is null) ? null : color.getColorStruct());
138 		
139 		if(p is null)
140 		{
141 			throw new ConstructionException("null returned by new_with_color");
142 		}
143 		
144 		this(cast(GtkColorButton*) p);
145 	}
146 
147 	/**
148 	 * Creates a new color button.
149 	 *
150 	 * Params:
151 	 *     rgba = A #GdkRGBA to set the current color with
152 	 *
153 	 * Return: a new color button
154 	 *
155 	 * Since: 3.0
156 	 *
157 	 * Throws: ConstructionException GTK+ fails to create the object.
158 	 */
159 	public this(RGBA rgba)
160 	{
161 		auto p = gtk_color_button_new_with_rgba((rgba is null) ? null : rgba.getRGBAStruct());
162 		
163 		if(p is null)
164 		{
165 			throw new ConstructionException("null returned by new_with_rgba");
166 		}
167 		
168 		this(cast(GtkColorButton*) p);
169 	}
170 
171 	/**
172 	 * Returns the current alpha value.
173 	 *
174 	 * Deprecated: Use gtk_color_chooser_get_rgba() instead.
175 	 *
176 	 * Return: an integer between 0 and 65535
177 	 *
178 	 * Since: 2.4
179 	 */
180 	public ushort getAlpha()
181 	{
182 		return gtk_color_button_get_alpha(gtkColorButton);
183 	}
184 
185 	/**
186 	 * Sets @color to be the current color in the #GtkColorButton widget.
187 	 *
188 	 * Deprecated: Use gtk_color_chooser_get_rgba() instead.
189 	 *
190 	 * Params:
191 	 *     color = a #GdkColor to fill in with the current color
192 	 *
193 	 * Since: 2.4
194 	 */
195 	public void getColor(out Color color)
196 	{
197 		GdkColor* outcolor = gMalloc!GdkColor();
198 		
199 		gtk_color_button_get_color(gtkColorButton, outcolor);
200 		
201 		color = ObjectG.getDObject!(Color)(outcolor, true);
202 	}
203 
204 	/**
205 	 * Gets the title of the color selection dialog.
206 	 *
207 	 * Return: An internal string, do not free the return value
208 	 *
209 	 * Since: 2.4
210 	 */
211 	public string getTitle()
212 	{
213 		return Str.toString(gtk_color_button_get_title(gtkColorButton));
214 	}
215 
216 	/**
217 	 * Sets the current opacity to be @alpha.
218 	 *
219 	 * Deprecated: Use gtk_color_chooser_set_rgba() instead.
220 	 *
221 	 * Params:
222 	 *     alpha = an integer between 0 and 65535
223 	 *
224 	 * Since: 2.4
225 	 */
226 	public void setAlpha(ushort alpha)
227 	{
228 		gtk_color_button_set_alpha(gtkColorButton, alpha);
229 	}
230 
231 	/**
232 	 * Sets the current color to be @color.
233 	 *
234 	 * Deprecated: Use gtk_color_chooser_set_rgba() instead.
235 	 *
236 	 * Params:
237 	 *     color = A #GdkColor to set the current color with
238 	 *
239 	 * Since: 2.4
240 	 */
241 	public void setColor(Color color)
242 	{
243 		gtk_color_button_set_color(gtkColorButton, (color is null) ? null : color.getColorStruct());
244 	}
245 
246 	/**
247 	 * Sets the title for the color selection dialog.
248 	 *
249 	 * Params:
250 	 *     title = String containing new window title
251 	 *
252 	 * Since: 2.4
253 	 */
254 	public void setTitle(string title)
255 	{
256 		gtk_color_button_set_title(gtkColorButton, Str.toStringz(title));
257 	}
258 
259 	int[string] connectedSignals;
260 
261 	void delegate(ColorButton)[] onColorSetListeners;
262 	/**
263 	 * The ::color-set signal is emitted when the user selects a color.
264 	 * When handling this signal, use gtk_color_button_get_rgba() to
265 	 * find out which color was just selected.
266 	 *
267 	 * Note that this signal is only emitted when the user
268 	 * changes the color. If you need to react to programmatic color changes
269 	 * as well, use the notify::color signal.
270 	 *
271 	 * Since: 2.4
272 	 */
273 	void addOnColorSet(void delegate(ColorButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
274 	{
275 		if ( "color-set" !in connectedSignals )
276 		{
277 			Signals.connectData(
278 				this,
279 				"color-set",
280 				cast(GCallback)&callBackColorSet,
281 				cast(void*)this,
282 				null,
283 				connectFlags);
284 			connectedSignals["color-set"] = 1;
285 		}
286 		onColorSetListeners ~= dlg;
287 	}
288 	extern(C) static void callBackColorSet(GtkColorButton* colorbuttonStruct, ColorButton _colorbutton)
289 	{
290 		foreach ( void delegate(ColorButton) dlg; _colorbutton.onColorSetListeners )
291 		{
292 			dlg(_colorbutton);
293 		}
294 	}
295 }