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  * Conversion parameters:
26  * inFile  = GtkColorButton.html
27  * outPack = gtk
28  * outFile = ColorButton
29  * strct   = GtkColorButton
30  * realStrct=
31  * ctorStrct=
32  * clss    = ColorButton
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gtk_color_button_
41  * 	- gtk_
42  * omit structs:
43  * omit prefixes:
44  * omit code:
45  * omit signals:
46  * imports:
47  * 	- glib.Str
48  * 	- gdk.Color
49  * structWrap:
50  * 	- GdkColor* -> Color
51  * module aliases:
52  * local aliases:
53  * overrides:
54  */
55 
56 module gtk.ColorButton;
57 
58 public  import gtkc.gtktypes;
59 
60 private import gtkc.gtk;
61 private import glib.ConstructionException;
62 private import gobject.ObjectG;
63 
64 private import gobject.Signals;
65 public  import gtkc.gdktypes;
66 
67 private import glib.Str;
68 private import gdk.Color;
69 
70 
71 
72 private import gtk.Button;
73 
74 /**
75  * Description
76  * The GtkColorButton is a button which displays the currently selected color
77  * an allows to open a color selection dialog to change the color. It is suitable
78  * widget for selecting a color in a preference dialog.
79  */
80 public class ColorButton : Button
81 {
82 	
83 	/** the main Gtk struct */
84 	protected GtkColorButton* gtkColorButton;
85 	
86 	
87 	public GtkColorButton* getColorButtonStruct()
88 	{
89 		return gtkColorButton;
90 	}
91 	
92 	
93 	/** the main Gtk struct as a void* */
94 	protected override void* getStruct()
95 	{
96 		return cast(void*)gtkColorButton;
97 	}
98 	
99 	/**
100 	 * Sets our main struct and passes it to the parent class
101 	 */
102 	public this (GtkColorButton* gtkColorButton)
103 	{
104 		super(cast(GtkButton*)gtkColorButton);
105 		this.gtkColorButton = gtkColorButton;
106 	}
107 	
108 	protected override void setStruct(GObject* obj)
109 	{
110 		super.setStruct(obj);
111 		gtkColorButton = cast(GtkColorButton*)obj;
112 	}
113 	
114 	/**
115 	 */
116 	int[string] connectedSignals;
117 	
118 	void delegate(ColorButton)[] onColorSetListeners;
119 	/**
120 	 * The ::color-set signal is emitted when the user selects a color.
121 	 * When handling this signal, use gtk_color_button_get_color() and
122 	 * gtk_color_button_get_alpha() to find out which color was just selected.
123 	 * Note that this signal is only emitted when the user
124 	 * changes the color. If you need to react to programmatic color changes
125 	 * as well, use the notify::color signal.
126 	 * Since 2.4
127 	 * See Also
128 	 * GtkColorSelectionDialog, GtkFontButton
129 	 */
130 	void addOnColorSet(void delegate(ColorButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
131 	{
132 		if ( !("color-set" in connectedSignals) )
133 		{
134 			Signals.connectData(
135 			getStruct(),
136 			"color-set",
137 			cast(GCallback)&callBackColorSet,
138 			cast(void*)this,
139 			null,
140 			connectFlags);
141 			connectedSignals["color-set"] = 1;
142 		}
143 		onColorSetListeners ~= dlg;
144 	}
145 	extern(C) static void callBackColorSet(GtkColorButton* widgetStruct, ColorButton _colorButton)
146 	{
147 		foreach ( void delegate(ColorButton) dlg ; _colorButton.onColorSetListeners )
148 		{
149 			dlg(_colorButton);
150 		}
151 	}
152 	
153 	
154 	/**
155 	 * Creates a new color button. This returns a widget in the form of
156 	 * a small button containing a swatch representing the current selected
157 	 * color. When the button is clicked, a color-selection dialog will open,
158 	 * allowing the user to select a color. The swatch will be updated to reflect
159 	 * the new color when the user finishes.
160 	 * Since 2.4
161 	 * Throws: ConstructionException GTK+ fails to create the object.
162 	 */
163 	public this ()
164 	{
165 		// GtkWidget * gtk_color_button_new (void);
166 		auto p = gtk_color_button_new();
167 		if(p is null)
168 		{
169 			throw new ConstructionException("null returned by gtk_color_button_new()");
170 		}
171 		this(cast(GtkColorButton*) p);
172 	}
173 	
174 	/**
175 	 * Creates a new color button.
176 	 * Since 2.4
177 	 * Params:
178 	 * color = A GdkColor to set the current color with.
179 	 * Throws: ConstructionException GTK+ fails to create the object.
180 	 */
181 	public this (Color color)
182 	{
183 		// GtkWidget * gtk_color_button_new_with_color (const GdkColor *color);
184 		auto p = gtk_color_button_new_with_color((color is null) ? null : color.getColorStruct());
185 		if(p is null)
186 		{
187 			throw new ConstructionException("null returned by gtk_color_button_new_with_color((color is null) ? null : color.getColorStruct())");
188 		}
189 		this(cast(GtkColorButton*) p);
190 	}
191 	
192 	/**
193 	 * Sets the current color to be color.
194 	 * Since 2.4
195 	 * Params:
196 	 * color = A GdkColor to set the current color with.
197 	 */
198 	public void setColor(Color color)
199 	{
200 		// void gtk_color_button_set_color (GtkColorButton *color_button,  const GdkColor *color);
201 		gtk_color_button_set_color(gtkColorButton, (color is null) ? null : color.getColorStruct());
202 	}
203 	
204 	/**
205 	 * Sets color to be the current color in the GtkColorButton widget.
206 	 * Since 2.4
207 	 * Params:
208 	 * color = a GdkColor to fill in with the current color.
209 	 */
210 	public void getColor(Color color)
211 	{
212 		// void gtk_color_button_get_color (GtkColorButton *color_button,  GdkColor *color);
213 		gtk_color_button_get_color(gtkColorButton, (color is null) ? null : color.getColorStruct());
214 	}
215 	
216 	/**
217 	 * Sets the current opacity to be alpha.
218 	 * Since 2.4
219 	 * Params:
220 	 * alpha = an integer between 0 and 65535.
221 	 */
222 	public void setAlpha(ushort alpha)
223 	{
224 		// void gtk_color_button_set_alpha (GtkColorButton *color_button,  guint16 alpha);
225 		gtk_color_button_set_alpha(gtkColorButton, alpha);
226 	}
227 	
228 	/**
229 	 * Returns the current alpha value.
230 	 * Since 2.4
231 	 * Returns: an integer between 0 and 65535.
232 	 */
233 	public ushort getAlpha()
234 	{
235 		// guint16 gtk_color_button_get_alpha (GtkColorButton *color_button);
236 		return gtk_color_button_get_alpha(gtkColorButton);
237 	}
238 	
239 	/**
240 	 * Sets whether or not the color button should use the alpha channel.
241 	 * Since 2.4
242 	 * Params:
243 	 * useAlpha = TRUE if color button should use alpha channel, FALSE if not.
244 	 */
245 	public void setUseAlpha(int useAlpha)
246 	{
247 		// void gtk_color_button_set_use_alpha (GtkColorButton *color_button,  gboolean use_alpha);
248 		gtk_color_button_set_use_alpha(gtkColorButton, useAlpha);
249 	}
250 	
251 	/**
252 	 * Does the color selection dialog use the alpha channel?
253 	 * Since 2.4
254 	 * Returns: TRUE if the color sample uses alpha channel, FALSE if not.
255 	 */
256 	public int getUseAlpha()
257 	{
258 		// gboolean gtk_color_button_get_use_alpha (GtkColorButton *color_button);
259 		return gtk_color_button_get_use_alpha(gtkColorButton);
260 	}
261 	
262 	/**
263 	 * Sets the title for the color selection dialog.
264 	 * Since 2.4
265 	 * Params:
266 	 * title = String containing new window title.
267 	 */
268 	public void setTitle(string title)
269 	{
270 		// void gtk_color_button_set_title (GtkColorButton *color_button,  const gchar *title);
271 		gtk_color_button_set_title(gtkColorButton, Str.toStringz(title));
272 	}
273 	
274 	/**
275 	 * Gets the title of the color selection dialog.
276 	 * Since 2.4
277 	 * Returns: An internal string, do not free the return value
278 	 */
279 	public string getTitle()
280 	{
281 		// const gchar * gtk_color_button_get_title (GtkColorButton *color_button);
282 		return Str.toString(gtk_color_button_get_title(gtkColorButton));
283 	}
284 }