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