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  = GtkColorSelection.html
27  * outPack = gtk
28  * outFile = ColorSelection
29  * strct   = GtkColorSelection
30  * realStrct=
31  * ctorStrct=
32  * clss    = ColorSelection
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gtk_color_selection_
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.ColorSelection;
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.VBox;
73 
74 /**
75  * Description
76  * The GtkColorSelection is a widget that is used to select
77  * a color. It consists of a color wheel and number of sliders
78  * and entry boxes for color parameters such as hue, saturation,
79  * value, red, green, blue, and opacity. It is found on the standard
80  * color selection dialog box GtkColorSelectionDialog.
81  */
82 public class ColorSelection : VBox
83 {
84 	
85 	/** the main Gtk struct */
86 	protected GtkColorSelection* gtkColorSelection;
87 	
88 	
89 	public GtkColorSelection* getColorSelectionStruct()
90 	{
91 		return gtkColorSelection;
92 	}
93 	
94 	
95 	/** the main Gtk struct as a void* */
96 	protected override void* getStruct()
97 	{
98 		return cast(void*)gtkColorSelection;
99 	}
100 	
101 	/**
102 	 * Sets our main struct and passes it to the parent class
103 	 */
104 	public this (GtkColorSelection* gtkColorSelection)
105 	{
106 		super(cast(GtkVBox*)gtkColorSelection);
107 		this.gtkColorSelection = gtkColorSelection;
108 	}
109 	
110 	protected override void setStruct(GObject* obj)
111 	{
112 		super.setStruct(obj);
113 		gtkColorSelection = cast(GtkColorSelection*)obj;
114 	}
115 	
116 	/**
117 	 */
118 	int[string] connectedSignals;
119 	
120 	void delegate(ColorSelection)[] onColorChangedListeners;
121 	/**
122 	 * This signal is emitted when the color changes in the GtkColorSelection
123 	 * according to its update policy.
124 	 */
125 	void addOnColorChanged(void delegate(ColorSelection) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
126 	{
127 		if ( !("color-changed" in connectedSignals) )
128 		{
129 			Signals.connectData(
130 			getStruct(),
131 			"color-changed",
132 			cast(GCallback)&callBackColorChanged,
133 			cast(void*)this,
134 			null,
135 			connectFlags);
136 			connectedSignals["color-changed"] = 1;
137 		}
138 		onColorChangedListeners ~= dlg;
139 	}
140 	extern(C) static void callBackColorChanged(GtkColorSelection* colorselectionStruct, ColorSelection _colorSelection)
141 	{
142 		foreach ( void delegate(ColorSelection) dlg ; _colorSelection.onColorChangedListeners )
143 		{
144 			dlg(_colorSelection);
145 		}
146 	}
147 	
148 	
149 	/**
150 	 * Creates a new GtkColorSelection.
151 	 * Throws: ConstructionException GTK+ fails to create the object.
152 	 */
153 	public this ()
154 	{
155 		// GtkWidget * gtk_color_selection_new (void);
156 		auto p = gtk_color_selection_new();
157 		if(p is null)
158 		{
159 			throw new ConstructionException("null returned by gtk_color_selection_new()");
160 		}
161 		this(cast(GtkColorSelection*) p);
162 	}
163 	
164 	/**
165 	 * Warning
166 	 * gtk_color_selection_set_update_policy is deprecated and should not be used in newly-written code.
167 	 * Sets the policy controlling when the color_changed signals are emitted.
168 	 * Params:
169 	 * policy = a GtkUpdateType value indicating the desired policy.
170 	 */
171 	public void setUpdatePolicy(GtkUpdateType policy)
172 	{
173 		// void gtk_color_selection_set_update_policy  (GtkColorSelection *colorsel,  GtkUpdateType policy);
174 		gtk_color_selection_set_update_policy(gtkColorSelection, policy);
175 	}
176 	
177 	/**
178 	 * Sets the colorsel to use or not use opacity.
179 	 * Params:
180 	 * hasOpacity = TRUE if colorsel can set the opacity, FALSE otherwise.
181 	 */
182 	public void setHasOpacityControl(int hasOpacity)
183 	{
184 		// void gtk_color_selection_set_has_opacity_control  (GtkColorSelection *colorsel,  gboolean has_opacity);
185 		gtk_color_selection_set_has_opacity_control(gtkColorSelection, hasOpacity);
186 	}
187 	
188 	/**
189 	 * Determines whether the colorsel has an opacity control.
190 	 * Returns: TRUE if the colorsel has an opacity control. FALSE if it does't.
191 	 */
192 	public int getHasOpacityControl()
193 	{
194 		// gboolean gtk_color_selection_get_has_opacity_control  (GtkColorSelection *colorsel);
195 		return gtk_color_selection_get_has_opacity_control(gtkColorSelection);
196 	}
197 	
198 	/**
199 	 * Shows and hides the palette based upon the value of has_palette.
200 	 * Params:
201 	 * hasPalette = TRUE if palette is to be visible, FALSE otherwise.
202 	 */
203 	public void setHasPalette(int hasPalette)
204 	{
205 		// void gtk_color_selection_set_has_palette (GtkColorSelection *colorsel,  gboolean has_palette);
206 		gtk_color_selection_set_has_palette(gtkColorSelection, hasPalette);
207 	}
208 	
209 	/**
210 	 * Determines whether the color selector has a color palette.
211 	 * Returns: TRUE if the selector has a palette. FALSE if it hasn't.
212 	 */
213 	public int getHasPalette()
214 	{
215 		// gboolean gtk_color_selection_get_has_palette (GtkColorSelection *colorsel);
216 		return gtk_color_selection_get_has_palette(gtkColorSelection);
217 	}
218 	
219 	/**
220 	 * Returns the current alpha value.
221 	 * Returns: an integer between 0 and 65535.
222 	 */
223 	public ushort getCurrentAlpha()
224 	{
225 		// guint16 gtk_color_selection_get_current_alpha  (GtkColorSelection *colorsel);
226 		return gtk_color_selection_get_current_alpha(gtkColorSelection);
227 	}
228 	
229 	/**
230 	 * Sets the current opacity to be alpha. The first time this is called, it will
231 	 * also set the original opacity to be alpha too.
232 	 * Params:
233 	 * alpha = an integer between 0 and 65535.
234 	 */
235 	public void setCurrentAlpha(ushort alpha)
236 	{
237 		// void gtk_color_selection_set_current_alpha  (GtkColorSelection *colorsel,  guint16 alpha);
238 		gtk_color_selection_set_current_alpha(gtkColorSelection, alpha);
239 	}
240 	
241 	/**
242 	 * Sets color to be the current color in the GtkColorSelection widget.
243 	 * Params:
244 	 * color = a GdkColor to fill in with the current color. [out]
245 	 */
246 	public void getCurrentColor(Color color)
247 	{
248 		// void gtk_color_selection_get_current_color  (GtkColorSelection *colorsel,  GdkColor *color);
249 		gtk_color_selection_get_current_color(gtkColorSelection, (color is null) ? null : color.getColorStruct());
250 	}
251 	
252 	/**
253 	 * Sets the current color to be color. The first time this is called, it will
254 	 * also set the original color to be color too.
255 	 * Params:
256 	 * color = A GdkColor to set the current color with.
257 	 */
258 	public void setCurrentColor(Color color)
259 	{
260 		// void gtk_color_selection_set_current_color  (GtkColorSelection *colorsel,  const GdkColor *color);
261 		gtk_color_selection_set_current_color(gtkColorSelection, (color is null) ? null : color.getColorStruct());
262 	}
263 	
264 	/**
265 	 * Returns the previous alpha value.
266 	 * Returns: an integer between 0 and 65535.
267 	 */
268 	public ushort getPreviousAlpha()
269 	{
270 		// guint16 gtk_color_selection_get_previous_alpha  (GtkColorSelection *colorsel);
271 		return gtk_color_selection_get_previous_alpha(gtkColorSelection);
272 	}
273 	
274 	/**
275 	 * Sets the 'previous' alpha to be alpha. This function should be called with
276 	 * some hesitations, as it might seem confusing to have that alpha change.
277 	 * Params:
278 	 * alpha = an integer between 0 and 65535.
279 	 */
280 	public void setPreviousAlpha(ushort alpha)
281 	{
282 		// void gtk_color_selection_set_previous_alpha  (GtkColorSelection *colorsel,  guint16 alpha);
283 		gtk_color_selection_set_previous_alpha(gtkColorSelection, alpha);
284 	}
285 	
286 	/**
287 	 * Fills color in with the original color value.
288 	 * Params:
289 	 * color = a GdkColor to fill in with the original color value. [out]
290 	 */
291 	public void getPreviousColor(Color color)
292 	{
293 		// void gtk_color_selection_get_previous_color  (GtkColorSelection *colorsel,  GdkColor *color);
294 		gtk_color_selection_get_previous_color(gtkColorSelection, (color is null) ? null : color.getColorStruct());
295 	}
296 	
297 	/**
298 	 * Sets the 'previous' color to be color. This function should be called with
299 	 * some hesitations, as it might seem confusing to have that color change.
300 	 * Calling gtk_color_selection_set_current_color() will also set this color the first
301 	 * time it is called.
302 	 * Params:
303 	 * color = a GdkColor to set the previous color with.
304 	 */
305 	public void setPreviousColor(Color color)
306 	{
307 		// void gtk_color_selection_set_previous_color  (GtkColorSelection *colorsel,  const GdkColor *color);
308 		gtk_color_selection_set_previous_color(gtkColorSelection, (color is null) ? null : color.getColorStruct());
309 	}
310 	
311 	/**
312 	 * Gets the current state of the colorsel.
313 	 * Returns: TRUE if the user is currently dragging a color around, and FALSE if the selection has stopped.
314 	 */
315 	public int isAdjusting()
316 	{
317 		// gboolean gtk_color_selection_is_adjusting (GtkColorSelection *colorsel);
318 		return gtk_color_selection_is_adjusting(gtkColorSelection);
319 	}
320 	
321 	/**
322 	 * Parses a color palette string; the string is a colon-separated
323 	 * list of color names readable by gdk_color_parse().
324 	 * Params:
325 	 * str = a string encoding a color palette.
326 	 * colors = return location for allocated
327 	 * array of GdkColor. [out][array length=n_colors]
328 	 * Returns: TRUE if a palette was successfully parsed.
329 	 */
330 	public static int paletteFromString(string str, out GdkColor[] colors)
331 	{
332 		// gboolean gtk_color_selection_palette_from_string  (const gchar *str,  GdkColor **colors,  gint *n_colors);
333 		GdkColor* outcolors = null;
334 		int nColors;
335 		
336 		auto p = gtk_color_selection_palette_from_string(Str.toStringz(str), &outcolors, &nColors);
337 		
338 		colors = outcolors[0 .. nColors];
339 		return p;
340 	}
341 	
342 	/**
343 	 * Encodes a palette as a string, useful for persistent storage.
344 	 * Params:
345 	 * colors = an array of colors. [array length=n_colors]
346 	 * nColors = length of the array.
347 	 * Returns: allocated string encoding the palette.
348 	 */
349 	public static string paletteToString(Color colors, int nColors)
350 	{
351 		// gchar * gtk_color_selection_palette_to_string  (const GdkColor *colors,  gint n_colors);
352 		return Str.toString(gtk_color_selection_palette_to_string((colors is null) ? null : colors.getColorStruct(), nColors));
353 	}
354 	
355 	/**
356 	 * Warning
357 	 * gtk_color_selection_set_change_palette_hook has been deprecated since version 2.4 and should not be used in newly-written code. This function does not work in multihead environments.
358 	 *  Use gtk_color_selection_set_change_palette_with_screen_hook() instead.
359 	 * Installs a global function to be called whenever the user tries to
360 	 * modify the palette in a color selection. This function should save
361 	 * the new palette contents, and update the GtkSettings property
362 	 * "gtk-color-palette" so all GtkColorSelection widgets will be modified.
363 	 * Params:
364 	 * func = a function to call when the custom palette needs saving.
365 	 * Returns: the previous change palette hook (that was replaced).
366 	 */
367 	public static GtkColorSelectionChangePaletteFunc setChangePaletteHook(GtkColorSelectionChangePaletteFunc func)
368 	{
369 		// GtkColorSelectionChangePaletteFunc gtk_color_selection_set_change_palette_hook  (GtkColorSelectionChangePaletteFunc func);
370 		return gtk_color_selection_set_change_palette_hook(func);
371 	}
372 	
373 	/**
374 	 * Installs a global function to be called whenever the user tries to
375 	 * modify the palette in a color selection. This function should save
376 	 * the new palette contents, and update the GtkSettings property
377 	 * "gtk-color-palette" so all GtkColorSelection widgets will be modified.
378 	 * Since 2.2
379 	 * Params:
380 	 * func = a function to call when the custom palette needs saving.
381 	 * Returns: the previous change palette hook (that was replaced).
382 	 */
383 	public static GtkColorSelectionChangePaletteWithScreenFunc setChangePaletteWithScreenHook(GtkColorSelectionChangePaletteWithScreenFunc func)
384 	{
385 		// GtkColorSelectionChangePaletteWithScreenFunc gtk_color_selection_set_change_palette_with_screen_hook  (GtkColorSelectionChangePaletteWithScreenFunc func);
386 		return gtk_color_selection_set_change_palette_with_screen_hook(func);
387 	}
388 	
389 	/**
390 	 * Warning
391 	 * gtk_color_selection_set_color has been deprecated since version 2.0 and should not be used in newly-written code. Use gtk_color_selection_set_current_color() instead.
392 	 * Sets the current color to be color. The first time this is called, it will
393 	 * also set the original color to be color too.
394 	 * Params:
395 	 * color = an array of 4 doubles specifying the red, green, blue and opacity
396 	 * to set the current color to.
397 	 */
398 	public void setColor(double[] color)
399 	{
400 		// void gtk_color_selection_set_color (GtkColorSelection *colorsel,  gdouble *color);
401 		gtk_color_selection_set_color(gtkColorSelection, color.ptr);
402 	}
403 	
404 	/**
405 	 * Warning
406 	 * gtk_color_selection_get_color has been deprecated since version 2.0 and should not be used in newly-written code. Use gtk_color_selection_get_current_color() instead.
407 	 * Sets color to be the current color in the GtkColorSelection widget.
408 	 * Params:
409 	 * color = an array of 4 gdouble to fill in with the current color.
410 	 */
411 	public void getColor(double[] color)
412 	{
413 		// void gtk_color_selection_get_color (GtkColorSelection *colorsel,  gdouble *color);
414 		gtk_color_selection_get_color(gtkColorSelection, color.ptr);
415 	}
416 }