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.SymbolicColor;
26 
27 private import gdk.RGBA;
28 private import glib.ConstructionException;
29 private import glib.Str;
30 private import gobject.ObjectG;
31 private import gtk.StyleProperties;
32 private import gtkc.Loader;
33 private import gtkc.gtk;
34 public  import gtkc.gtktypes;
35 private import gtkc.paths;
36 
37 
38 /**
39  * GtkSymbolicColor is a boxed type that represents a symbolic color.
40  * It is the result of parsing a
41  * [color expression][gtkcssprovider-symbolic-colors].
42  * To obtain the color represented by a GtkSymbolicColor, it has to
43  * be resolved with gtk_symbolic_color_resolve(), which replaces all
44  * symbolic color references by the colors they refer to (in a given
45  * context) and evaluates mix, shade and other expressions, resulting
46  * in a #GdkRGBA value.
47  * 
48  * It is not normally necessary to deal directly with #GtkSymbolicColors,
49  * since they are mostly used behind the scenes by #GtkStyleContext and
50  * #GtkCssProvider.
51  * 
52  * #GtkSymbolicColor is deprecated. Symbolic colors are considered an
53  * implementation detail of GTK+.
54  */
55 public class SymbolicColor
56 {
57 	/** the main Gtk struct */
58 	protected GtkSymbolicColor* gtkSymbolicColor;
59 
60 	/** Get the main Gtk struct */
61 	public GtkSymbolicColor* getSymbolicColorStruct()
62 	{
63 		return gtkSymbolicColor;
64 	}
65 
66 	/** the main Gtk struct as a void* */
67 	protected void* getStruct()
68 	{
69 		return cast(void*)gtkSymbolicColor;
70 	}
71 
72 	/**
73 	 * Sets our main struct and passes it to the parent class.
74 	 */
75 	public this (GtkSymbolicColor* gtkSymbolicColor)
76 	{
77 		this.gtkSymbolicColor = gtkSymbolicColor;
78 	}
79 
80 	~this ()
81 	{
82 		if (  Linker.isLoaded(LIBRARY.GTK) && gtkSymbolicColor !is null )
83 		{
84 			gtk_symbolic_color_unref(gtkSymbolicColor);
85 		}
86 	}
87 	
88 	/**
89 	 * Creates a symbolic color defined as a shade of another color.
90 	 * A factor > 1.0 would resolve to a brighter or more transparent color,
91 	 * while < 1.0 would resolve to a darker or more opaque color.
92 	 *
93 	 * Params:
94 	 *     color    = another GtkSymbolicColor.
95 	 *     factor   = shading factor to apply to color.
96 	 *     useAlpha = if true change the relative alpha value of the color,
97 	 *                otherwise change the shade.
98 	 *
99 	 * Throws: ConstructionException GTK+ fails to create the object.
100 	 */
101 	public this (SymbolicColor color, double factor, bool useAlpha = true)
102 	{
103 		GtkSymbolicColor* p;
104 		
105 		if ( useAlpha )
106 		{
107 			p = gtk_symbolic_color_new_alpha((color is null) ? null : color.getSymbolicColorStruct(), factor);
108 		}
109 		else
110 		{
111 			p = gtk_symbolic_color_new_shade((color is null) ? null : color.getSymbolicColorStruct(), factor);
112 		}
113 		
114 		if(p is null)
115 		{
116 			throw new ConstructionException("null returned by gtk_symbolic_color_new_shade((color is null) ? null : color.getSymbolicColorStruct(), factor)");
117 		}
118 		
119 		this(cast(GtkSymbolicColor*) p);
120 	}
121 
122 	/**
123 	 */
124 
125 	/** */
126 	public static GType getType()
127 	{
128 		return gtk_symbolic_color_get_type();
129 	}
130 
131 	/**
132 	 * Creates a symbolic color pointing to a literal color.
133 	 *
134 	 * Deprecated: #GtkSymbolicColor is deprecated.
135 	 *
136 	 * Params:
137 	 *     color = a #GdkRGBA
138 	 *
139 	 * Return: a newly created #GtkSymbolicColor
140 	 *
141 	 * Since: 3.0
142 	 *
143 	 * Throws: ConstructionException GTK+ fails to create the object.
144 	 */
145 	public this(RGBA color)
146 	{
147 		auto p = gtk_symbolic_color_new_literal((color is null) ? null : color.getRGBAStruct());
148 		
149 		if(p is null)
150 		{
151 			throw new ConstructionException("null returned by new_literal");
152 		}
153 		
154 		this(cast(GtkSymbolicColor*) p);
155 	}
156 
157 	/**
158 	 * Creates a symbolic color defined as a mix of another
159 	 * two colors. a mix factor of 0 would resolve to @color1,
160 	 * while a factor of 1 would resolve to @color2.
161 	 *
162 	 * Deprecated: #GtkSymbolicColor is deprecated.
163 	 *
164 	 * Params:
165 	 *     color1 = color to mix
166 	 *     color2 = another color to mix
167 	 *     factor = mix factor
168 	 *
169 	 * Return: A newly created #GtkSymbolicColor
170 	 *
171 	 * Since: 3.0
172 	 *
173 	 * Throws: ConstructionException GTK+ fails to create the object.
174 	 */
175 	public this(SymbolicColor color1, SymbolicColor color2, double factor)
176 	{
177 		auto p = gtk_symbolic_color_new_mix((color1 is null) ? null : color1.getSymbolicColorStruct(), (color2 is null) ? null : color2.getSymbolicColorStruct(), factor);
178 		
179 		if(p is null)
180 		{
181 			throw new ConstructionException("null returned by new_mix");
182 		}
183 		
184 		this(cast(GtkSymbolicColor*) p);
185 	}
186 
187 	/**
188 	 * Creates a symbolic color pointing to an unresolved named
189 	 * color. See gtk_style_context_lookup_color() and
190 	 * gtk_style_properties_lookup_color().
191 	 *
192 	 * Deprecated: #GtkSymbolicColor is deprecated.
193 	 *
194 	 * Params:
195 	 *     name = color name
196 	 *
197 	 * Return: a newly created #GtkSymbolicColor
198 	 *
199 	 * Since: 3.0
200 	 *
201 	 * Throws: ConstructionException GTK+ fails to create the object.
202 	 */
203 	public this(string name)
204 	{
205 		auto p = gtk_symbolic_color_new_name(Str.toStringz(name));
206 		
207 		if(p is null)
208 		{
209 			throw new ConstructionException("null returned by new_name");
210 		}
211 		
212 		this(cast(GtkSymbolicColor*) p);
213 	}
214 
215 	/**
216 	 * Creates a symbolic color based on the current win32
217 	 * theme.
218 	 *
219 	 * Note that while this call is available on all platforms
220 	 * the actual value returned is not reliable on non-win32
221 	 * platforms.
222 	 *
223 	 * Deprecated: #GtkSymbolicColor is deprecated.
224 	 *
225 	 * Params:
226 	 *     themeClass = The theme class to pull color from
227 	 *     id = The color id
228 	 *
229 	 * Return: A newly created #GtkSymbolicColor
230 	 *
231 	 * Since: 3.4
232 	 *
233 	 * Throws: ConstructionException GTK+ fails to create the object.
234 	 */
235 	public this(string themeClass, int id)
236 	{
237 		auto p = gtk_symbolic_color_new_win32(Str.toStringz(themeClass), id);
238 		
239 		if(p is null)
240 		{
241 			throw new ConstructionException("null returned by new_win32");
242 		}
243 		
244 		this(cast(GtkSymbolicColor*) p);
245 	}
246 
247 	/**
248 	 * Increases the reference count of @color
249 	 *
250 	 * Deprecated: #GtkSymbolicColor is deprecated.
251 	 *
252 	 * Return: the same @color
253 	 *
254 	 * Since: 3.0
255 	 */
256 	public SymbolicColor doref()
257 	{
258 		auto p = gtk_symbolic_color_ref(gtkSymbolicColor);
259 		
260 		if(p is null)
261 		{
262 			return null;
263 		}
264 		
265 		return ObjectG.getDObject!(SymbolicColor)(cast(GtkSymbolicColor*) p);
266 	}
267 
268 	/**
269 	 * If @color is resolvable, @resolved_color will be filled in
270 	 * with the resolved color, and %TRUE will be returned. Generally,
271 	 * if @color can’t be resolved, it is due to it being defined on
272 	 * top of a named color that doesn’t exist in @props.
273 	 *
274 	 * When @props is %NULL, resolving of named colors will fail, so if
275 	 * your @color is or references such a color, this function will
276 	 * return %FALSE.
277 	 *
278 	 * Deprecated: #GtkSymbolicColor is deprecated.
279 	 *
280 	 * Params:
281 	 *     props = #GtkStyleProperties to use when resolving
282 	 *         named colors, or %NULL
283 	 *     resolvedColor = return location for the resolved color
284 	 *
285 	 * Return: %TRUE if the color has been resolved
286 	 *
287 	 * Since: 3.0
288 	 */
289 	public bool resolve(StyleProperties props, out RGBA resolvedColor)
290 	{
291 		GdkRGBA* outresolvedColor = gMalloc!GdkRGBA();
292 		
293 		auto p = gtk_symbolic_color_resolve(gtkSymbolicColor, (props is null) ? null : props.getStylePropertiesStruct(), outresolvedColor) != 0;
294 		
295 		resolvedColor = ObjectG.getDObject!(RGBA)(outresolvedColor);
296 		
297 		return p;
298 	}
299 
300 	/**
301 	 * Converts the given @color to a string representation. This is useful
302 	 * both for debugging and for serialization of strings. The format of
303 	 * the string may change between different versions of GTK, but it is
304 	 * guaranteed that the GTK css parser is able to read the string and
305 	 * create the same symbolic color from it.
306 	 *
307 	 * Deprecated: #GtkSymbolicColor is deprecated.
308 	 *
309 	 * Return: a new string representing @color
310 	 */
311 	public override string toString()
312 	{
313 		return Str.toString(gtk_symbolic_color_to_string(gtkSymbolicColor));
314 	}
315 
316 	/**
317 	 * Decreases the reference count of @color, freeing its memory if the
318 	 * reference count reaches 0.
319 	 *
320 	 * Deprecated: #GtkSymbolicColor is deprecated.
321 	 *
322 	 * Since: 3.0
323 	 */
324 	public void unref()
325 	{
326 		gtk_symbolic_color_unref(gtkSymbolicColor);
327 	}
328 }