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.ColorChooserT;
26 
27 public  import gdk.RGBA;
28 public  import gobject.ObjectG;
29 public  import gobject.Signals;
30 public  import gtkc.gdktypes;
31 public  import gtkc.gtk;
32 public  import gtkc.gtktypes;
33 
34 
35 /**
36  * #GtkColorChooser is an interface that is implemented by widgets
37  * for choosing colors. Depending on the situation, colors may be
38  * allowed to have alpha (translucency).
39  * 
40  * In GTK+, the main widgets that implement this interface are
41  * #GtkColorChooserWidget, #GtkColorChooserDialog and #GtkColorButton.
42  */
43 public template ColorChooserT(TStruct)
44 {
45 	/** Get the main Gtk struct */
46 	public GtkColorChooser* getColorChooserStruct()
47 	{
48 		return cast(GtkColorChooser*)getStruct();
49 	}
50 
51 	/**
52 	 */
53 
54 	/**
55 	 * Adds a palette to the color chooser. If @orientation is horizontal,
56 	 * the colors are grouped in rows, with @colors_per_line colors
57 	 * in each row. If @horizontal is %FALSE, the colors are grouped
58 	 * in columns instead.
59 	 *
60 	 * The default color palette of #GtkColorChooserWidget has
61 	 * 27 colors, organized in columns of 3 colors. The default gray
62 	 * palette has 9 grays in a single row.
63 	 *
64 	 * The layout of the color chooser widget works best when the
65 	 * palettes have 9-10 columns.
66 	 *
67 	 * Calling this function for the first time has the
68 	 * side effect of removing the default color and gray palettes
69 	 * from the color chooser.
70 	 *
71 	 * If @colors is %NULL, removes all previously added palettes.
72 	 *
73 	 * Params:
74 	 *     orientation = %GTK_ORIENTATION_HORIZONTAL if the palette should
75 	 *         be displayed in rows, %GTK_ORIENTATION_VERTICAL for columns
76 	 *     colorsPerLine = the number of colors to show in each row/column
77 	 *     nColors = the total number of elements in @colors
78 	 *     colors = the colors of the palette, or %NULL
79 	 *
80 	 * Since: 3.4
81 	 */
82 	public void addPalette(GtkOrientation orientation, int colorsPerLine, RGBA[] colors)
83 	{
84 		GdkRGBA[] colorsArray = new GdkRGBA[colors.length];
85 		for ( int i = 0; i < colors.length; i++ )
86 		{
87 			colorsArray[i] = *(colors[i].getRGBAStruct());
88 		}
89 		
90 		gtk_color_chooser_add_palette(getColorChooserStruct(), orientation, colorsPerLine, cast(int)colors.length, colorsArray.ptr);
91 	}
92 
93 	/**
94 	 * Gets the currently-selected color.
95 	 *
96 	 * Params:
97 	 *     color = a #GdkRGBA to fill in with the current color
98 	 *
99 	 * Since: 3.4
100 	 */
101 	public void getRgba(out RGBA color)
102 	{
103 		GdkRGBA* outcolor = new GdkRGBA;
104 		
105 		gtk_color_chooser_get_rgba(getColorChooserStruct(), outcolor);
106 		
107 		color = ObjectG.getDObject!(RGBA)(outcolor);
108 	}
109 
110 	/**
111 	 * Returns whether the color chooser shows the alpha channel.
112 	 *
113 	 * Return: %TRUE if the color chooser uses the alpha channel,
114 	 *     %FALSE if not
115 	 *
116 	 * Since: 3.4
117 	 */
118 	public bool getUseAlpha()
119 	{
120 		return gtk_color_chooser_get_use_alpha(getColorChooserStruct()) != 0;
121 	}
122 
123 	/**
124 	 * Sets the color.
125 	 *
126 	 * Params:
127 	 *     color = the new color
128 	 *
129 	 * Since: 3.4
130 	 */
131 	public void setRgba(RGBA color)
132 	{
133 		gtk_color_chooser_set_rgba(getColorChooserStruct(), (color is null) ? null : color.getRGBAStruct());
134 	}
135 
136 	/**
137 	 * Sets whether or not the color chooser should use the alpha channel.
138 	 *
139 	 * Params:
140 	 *     useAlpha = %TRUE if color chooser should use alpha channel, %FALSE if not
141 	 *
142 	 * Since: 3.4
143 	 */
144 	public void setUseAlpha(bool useAlpha)
145 	{
146 		gtk_color_chooser_set_use_alpha(getColorChooserStruct(), useAlpha);
147 	}
148 
149 	int[string] connectedSignals;
150 
151 	void delegate(RGBA, ColorChooserIF)[] _onColorActivatedListeners;
152 	@property void delegate(RGBA, ColorChooserIF)[] onColorActivatedListeners()
153 	{
154 		return _onColorActivatedListeners;
155 	}
156 	/**
157 	 * Emitted when a color is activated from the color chooser.
158 	 * This usually happens when the user clicks a color swatch,
159 	 * or a color is selected and the user presses one of the keys
160 	 * Space, Shift+Space, Return or Enter.
161 	 *
162 	 * Params:
163 	 *     color = the color
164 	 *
165 	 * Since: 3.4
166 	 */
167 	void addOnColorActivated(void delegate(RGBA, ColorChooserIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
168 	{
169 		if ( "color-activated" !in connectedSignals )
170 		{
171 			Signals.connectData(
172 				this,
173 				"color-activated",
174 				cast(GCallback)&callBackColorActivated,
175 				cast(void*)cast(ColorChooserIF)this,
176 				null,
177 				connectFlags);
178 			connectedSignals["color-activated"] = 1;
179 		}
180 		_onColorActivatedListeners ~= dlg;
181 	}
182 	extern(C) static void callBackColorActivated(GtkColorChooser* colorchooserStruct, GdkRGBA* color, ColorChooserIF _colorchooser)
183 	{
184 		foreach ( void delegate(RGBA, ColorChooserIF) dlg; _colorchooser.onColorActivatedListeners )
185 		{
186 			dlg(ObjectG.getDObject!(RGBA)(color), _colorchooser);
187 		}
188 	}
189 }