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