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