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.ColorSelection;
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.Box;
34 private import gtk.Widget;
35 public  import gtkc.gdktypes;
36 private import gtkc.gtk;
37 public  import gtkc.gtktypes;
38 
39 
40 /** */
41 public class ColorSelection : Box
42 {
43 	/** the main Gtk struct */
44 	protected GtkColorSelection* gtkColorSelection;
45 
46 	/** Get the main Gtk struct */
47 	public GtkColorSelection* getColorSelectionStruct()
48 	{
49 		return gtkColorSelection;
50 	}
51 
52 	/** the main Gtk struct as a void* */
53 	protected override void* getStruct()
54 	{
55 		return cast(void*)gtkColorSelection;
56 	}
57 
58 	protected override void setStruct(GObject* obj)
59 	{
60 		gtkColorSelection = cast(GtkColorSelection*)obj;
61 		super.setStruct(obj);
62 	}
63 
64 	/**
65 	 * Sets our main struct and passes it to the parent class.
66 	 */
67 	public this (GtkColorSelection* gtkColorSelection, bool ownedRef = false)
68 	{
69 		this.gtkColorSelection = gtkColorSelection;
70 		super(cast(GtkBox*)gtkColorSelection, ownedRef);
71 	}
72 
73 
74 	/** */
75 	public static GType getType()
76 	{
77 		return gtk_color_selection_get_type();
78 	}
79 
80 	/**
81 	 * Creates a new GtkColorSelection.
82 	 *
83 	 * Return: a new #GtkColorSelection
84 	 *
85 	 * Throws: ConstructionException GTK+ fails to create the object.
86 	 */
87 	public this()
88 	{
89 		auto p = gtk_color_selection_new();
90 		
91 		if(p is null)
92 		{
93 			throw new ConstructionException("null returned by new");
94 		}
95 		
96 		this(cast(GtkColorSelection*) p);
97 	}
98 
99 	/**
100 	 * Parses a color palette string; the string is a colon-separated
101 	 * list of color names readable by gdk_color_parse().
102 	 *
103 	 * Params:
104 	 *     str = a string encoding a color palette
105 	 *     colors = return location for
106 	 *         allocated array of #GdkColor
107 	 *     nColors = return location for length of array
108 	 *
109 	 * Return: %TRUE if a palette was successfully parsed
110 	 */
111 	public static bool paletteFromString(string str, out Color[] colors)
112 	{
113 		GdkColor* outcolors = null;
114 		int nColors;
115 		
116 		auto p = gtk_color_selection_palette_from_string(Str.toStringz(str), &outcolors, &nColors) != 0;
117 		
118 		colors = new Color[nColors];
119 		for(size_t i = 0; i < nColors; i++)
120 		{
121 			colors[i] = ObjectG.getDObject!(Color)(cast(GdkColor*) &outcolors[i]);
122 		}
123 		
124 		return p;
125 	}
126 
127 	/**
128 	 * Encodes a palette as a string, useful for persistent storage.
129 	 *
130 	 * Params:
131 	 *     colors = an array of colors
132 	 *     nColors = length of the array
133 	 *
134 	 * Return: allocated string encoding the palette
135 	 */
136 	public static string paletteToString(Color[] colors)
137 	{
138 		GdkColor[] colorsArray = new GdkColor[colors.length];
139 		for ( int i = 0; i < colors.length; i++ )
140 		{
141 			colorsArray[i] = *(colors[i].getColorStruct());
142 		}
143 		
144 		auto retStr = gtk_color_selection_palette_to_string(colorsArray.ptr, cast(int)colors.length);
145 		
146 		scope(exit) Str.freeString(retStr);
147 		return Str.toString(retStr);
148 	}
149 
150 	/**
151 	 * Installs a global function to be called whenever the user
152 	 * tries to modify the palette in a color selection.
153 	 *
154 	 * This function should save the new palette contents, and update
155 	 * the #GtkSettings:gtk-color-palette GtkSettings property so all
156 	 * GtkColorSelection widgets will be modified.
157 	 *
158 	 * Params:
159 	 *     func = a function to call when the custom palette needs saving
160 	 *
161 	 * Return: the previous change palette hook (that was replaced)
162 	 *
163 	 * Since: 2.2
164 	 */
165 	public static GtkColorSelectionChangePaletteWithScreenFunc setChangePaletteWithScreenHook(GtkColorSelectionChangePaletteWithScreenFunc func)
166 	{
167 		return gtk_color_selection_set_change_palette_with_screen_hook(func);
168 	}
169 
170 	/**
171 	 * Returns the current alpha value.
172 	 *
173 	 * Return: an integer between 0 and 65535
174 	 */
175 	public ushort getCurrentAlpha()
176 	{
177 		return gtk_color_selection_get_current_alpha(gtkColorSelection);
178 	}
179 
180 	/**
181 	 * Sets @color to be the current color in the GtkColorSelection widget.
182 	 *
183 	 * Deprecated: Use gtk_color_selection_get_current_rgba() instead.
184 	 *
185 	 * Params:
186 	 *     color = a #GdkColor to fill in with the current color
187 	 */
188 	public void getCurrentColor(out Color color)
189 	{
190 		GdkColor* outcolor = gMalloc!GdkColor();
191 		
192 		gtk_color_selection_get_current_color(gtkColorSelection, outcolor);
193 		
194 		color = ObjectG.getDObject!(Color)(outcolor, true);
195 	}
196 
197 	/**
198 	 * Sets @rgba to be the current color in the GtkColorSelection widget.
199 	 *
200 	 * Params:
201 	 *     rgba = a #GdkRGBA to fill in with the current color
202 	 *
203 	 * Since: 3.0
204 	 */
205 	public void getCurrentRgba(out RGBA rgba)
206 	{
207 		GdkRGBA* outrgba = gMalloc!GdkRGBA();
208 		
209 		gtk_color_selection_get_current_rgba(gtkColorSelection, outrgba);
210 		
211 		rgba = ObjectG.getDObject!(RGBA)(outrgba, true);
212 	}
213 
214 	/**
215 	 * Determines whether the colorsel has an opacity control.
216 	 *
217 	 * Return: %TRUE if the @colorsel has an opacity control,
218 	 *     %FALSE if it does't
219 	 */
220 	public bool getHasOpacityControl()
221 	{
222 		return gtk_color_selection_get_has_opacity_control(gtkColorSelection) != 0;
223 	}
224 
225 	/**
226 	 * Determines whether the color selector has a color palette.
227 	 *
228 	 * Return: %TRUE if the selector has a palette, %FALSE if it hasn't
229 	 */
230 	public bool getHasPalette()
231 	{
232 		return gtk_color_selection_get_has_palette(gtkColorSelection) != 0;
233 	}
234 
235 	/**
236 	 * Returns the previous alpha value.
237 	 *
238 	 * Return: an integer between 0 and 65535
239 	 */
240 	public ushort getPreviousAlpha()
241 	{
242 		return gtk_color_selection_get_previous_alpha(gtkColorSelection);
243 	}
244 
245 	/**
246 	 * Fills @color in with the original color value.
247 	 *
248 	 * Deprecated: Use gtk_color_selection_get_previous_rgba() instead.
249 	 *
250 	 * Params:
251 	 *     color = a #GdkColor to fill in with the original color value
252 	 */
253 	public void getPreviousColor(out Color color)
254 	{
255 		GdkColor* outcolor = gMalloc!GdkColor();
256 		
257 		gtk_color_selection_get_previous_color(gtkColorSelection, outcolor);
258 		
259 		color = ObjectG.getDObject!(Color)(outcolor, true);
260 	}
261 
262 	/**
263 	 * Fills @rgba in with the original color value.
264 	 *
265 	 * Params:
266 	 *     rgba = a #GdkRGBA to fill in with the original color value
267 	 *
268 	 * Since: 3.0
269 	 */
270 	public void getPreviousRgba(out RGBA rgba)
271 	{
272 		GdkRGBA* outrgba = gMalloc!GdkRGBA();
273 		
274 		gtk_color_selection_get_previous_rgba(gtkColorSelection, outrgba);
275 		
276 		rgba = ObjectG.getDObject!(RGBA)(outrgba, true);
277 	}
278 
279 	/**
280 	 * Gets the current state of the @colorsel.
281 	 *
282 	 * Return: %TRUE if the user is currently dragging
283 	 *     a color around, and %FALSE if the selection has stopped
284 	 */
285 	public bool isAdjusting()
286 	{
287 		return gtk_color_selection_is_adjusting(gtkColorSelection) != 0;
288 	}
289 
290 	/**
291 	 * Sets the current opacity to be @alpha.
292 	 *
293 	 * The first time this is called, it will also set
294 	 * the original opacity to be @alpha too.
295 	 *
296 	 * Params:
297 	 *     alpha = an integer between 0 and 65535
298 	 */
299 	public void setCurrentAlpha(ushort alpha)
300 	{
301 		gtk_color_selection_set_current_alpha(gtkColorSelection, alpha);
302 	}
303 
304 	/**
305 	 * Sets the current color to be @color.
306 	 *
307 	 * The first time this is called, it will also set
308 	 * the original color to be @color too.
309 	 *
310 	 * Deprecated: Use gtk_color_selection_set_current_rgba() instead.
311 	 *
312 	 * Params:
313 	 *     color = a #GdkColor to set the current color with
314 	 */
315 	public void setCurrentColor(Color color)
316 	{
317 		gtk_color_selection_set_current_color(gtkColorSelection, (color is null) ? null : color.getColorStruct());
318 	}
319 
320 	/**
321 	 * Sets the current color to be @rgba.
322 	 *
323 	 * The first time this is called, it will also set
324 	 * the original color to be @rgba too.
325 	 *
326 	 * Params:
327 	 *     rgba = A #GdkRGBA to set the current color with
328 	 *
329 	 * Since: 3.0
330 	 */
331 	public void setCurrentRgba(RGBA rgba)
332 	{
333 		gtk_color_selection_set_current_rgba(gtkColorSelection, (rgba is null) ? null : rgba.getRGBAStruct());
334 	}
335 
336 	/**
337 	 * Sets the @colorsel to use or not use opacity.
338 	 *
339 	 * Params:
340 	 *     hasOpacity = %TRUE if @colorsel can set the opacity, %FALSE otherwise
341 	 */
342 	public void setHasOpacityControl(bool hasOpacity)
343 	{
344 		gtk_color_selection_set_has_opacity_control(gtkColorSelection, hasOpacity);
345 	}
346 
347 	/**
348 	 * Shows and hides the palette based upon the value of @has_palette.
349 	 *
350 	 * Params:
351 	 *     hasPalette = %TRUE if palette is to be visible, %FALSE otherwise
352 	 */
353 	public void setHasPalette(bool hasPalette)
354 	{
355 		gtk_color_selection_set_has_palette(gtkColorSelection, hasPalette);
356 	}
357 
358 	/**
359 	 * Sets the “previous” alpha to be @alpha.
360 	 *
361 	 * This function should be called with some hesitations,
362 	 * as it might seem confusing to have that alpha change.
363 	 *
364 	 * Params:
365 	 *     alpha = an integer between 0 and 65535
366 	 */
367 	public void setPreviousAlpha(ushort alpha)
368 	{
369 		gtk_color_selection_set_previous_alpha(gtkColorSelection, alpha);
370 	}
371 
372 	/**
373 	 * Sets the “previous” color to be @color.
374 	 *
375 	 * This function should be called with some hesitations,
376 	 * as it might seem confusing to have that color change.
377 	 * Calling gtk_color_selection_set_current_color() will also
378 	 * set this color the first time it is called.
379 	 *
380 	 * Deprecated: Use gtk_color_selection_set_previous_rgba() instead.
381 	 *
382 	 * Params:
383 	 *     color = a #GdkColor to set the previous color with
384 	 */
385 	public void setPreviousColor(Color color)
386 	{
387 		gtk_color_selection_set_previous_color(gtkColorSelection, (color is null) ? null : color.getColorStruct());
388 	}
389 
390 	/**
391 	 * Sets the “previous” color to be @rgba.
392 	 *
393 	 * This function should be called with some hesitations,
394 	 * as it might seem confusing to have that color change.
395 	 * Calling gtk_color_selection_set_current_rgba() will also
396 	 * set this color the first time it is called.
397 	 *
398 	 * Params:
399 	 *     rgba = a #GdkRGBA to set the previous color with
400 	 *
401 	 * Since: 3.0
402 	 */
403 	public void setPreviousRgba(RGBA rgba)
404 	{
405 		gtk_color_selection_set_previous_rgba(gtkColorSelection, (rgba is null) ? null : rgba.getRGBAStruct());
406 	}
407 
408 	int[string] connectedSignals;
409 
410 	void delegate(ColorSelection)[] onColorChangedListeners;
411 	/**
412 	 * This signal is emitted when the color changes in the #GtkColorSelection
413 	 * according to its update policy.
414 	 */
415 	void addOnColorChanged(void delegate(ColorSelection) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
416 	{
417 		if ( "color-changed" !in connectedSignals )
418 		{
419 			Signals.connectData(
420 				this,
421 				"color-changed",
422 				cast(GCallback)&callBackColorChanged,
423 				cast(void*)this,
424 				null,
425 				connectFlags);
426 			connectedSignals["color-changed"] = 1;
427 		}
428 		onColorChangedListeners ~= dlg;
429 	}
430 	extern(C) static void callBackColorChanged(GtkColorSelection* colorselectionStruct, ColorSelection _colorselection)
431 	{
432 		foreach ( void delegate(ColorSelection) dlg; _colorselection.onColorChangedListeners )
433 		{
434 			dlg(_colorselection);
435 		}
436 	}
437 }