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