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 	public static GType getType()
126 	{
127 		return gtk_symbolic_color_get_type();
128 	}
129 
130 	/**
131 	 * Creates a symbolic color pointing to a literal color.
132 	 *
133 	 * Deprecated: #GtkSymbolicColor is deprecated.
134 	 *
135 	 * Params:
136 	 *     color = a #GdkRGBA
137 	 *
138 	 * Return: a newly created #GtkSymbolicColor
139 	 *
140 	 * Since: 3.0
141 	 *
142 	 * Throws: ConstructionException GTK+ fails to create the object.
143 	 */
144 	public this(RGBA color)
145 	{
146 		auto p = gtk_symbolic_color_new_literal((color is null) ? null : color.getRGBAStruct());
147 		
148 		if(p is null)
149 		{
150 			throw new ConstructionException("null returned by new_literal");
151 		}
152 		
153 		this(cast(GtkSymbolicColor*) p);
154 	}
155 
156 	/**
157 	 * Creates a symbolic color defined as a mix of another
158 	 * two colors. a mix factor of 0 would resolve to @color1,
159 	 * while a factor of 1 would resolve to @color2.
160 	 *
161 	 * Deprecated: #GtkSymbolicColor is deprecated.
162 	 *
163 	 * Params:
164 	 *     color1 = color to mix
165 	 *     color2 = another color to mix
166 	 *     factor = mix factor
167 	 *
168 	 * Return: A newly created #GtkSymbolicColor
169 	 *
170 	 * Since: 3.0
171 	 *
172 	 * Throws: ConstructionException GTK+ fails to create the object.
173 	 */
174 	public this(SymbolicColor color1, SymbolicColor color2, double factor)
175 	{
176 		auto p = gtk_symbolic_color_new_mix((color1 is null) ? null : color1.getSymbolicColorStruct(), (color2 is null) ? null : color2.getSymbolicColorStruct(), factor);
177 		
178 		if(p is null)
179 		{
180 			throw new ConstructionException("null returned by new_mix");
181 		}
182 		
183 		this(cast(GtkSymbolicColor*) p);
184 	}
185 
186 	/**
187 	 * Creates a symbolic color pointing to an unresolved named
188 	 * color. See gtk_style_context_lookup_color() and
189 	 * gtk_style_properties_lookup_color().
190 	 *
191 	 * Deprecated: #GtkSymbolicColor is deprecated.
192 	 *
193 	 * Params:
194 	 *     name = color name
195 	 *
196 	 * Return: a newly created #GtkSymbolicColor
197 	 *
198 	 * Since: 3.0
199 	 *
200 	 * Throws: ConstructionException GTK+ fails to create the object.
201 	 */
202 	public this(string name)
203 	{
204 		auto p = gtk_symbolic_color_new_name(Str.toStringz(name));
205 		
206 		if(p is null)
207 		{
208 			throw new ConstructionException("null returned by new_name");
209 		}
210 		
211 		this(cast(GtkSymbolicColor*) p);
212 	}
213 
214 	/**
215 	 * Creates a symbolic color based on the current win32
216 	 * theme.
217 	 *
218 	 * Note that while this call is available on all platforms
219 	 * the actual value returned is not reliable on non-win32
220 	 * platforms.
221 	 *
222 	 * Deprecated: #GtkSymbolicColor is deprecated.
223 	 *
224 	 * Params:
225 	 *     themeClass = The theme class to pull color from
226 	 *     id = The color id
227 	 *
228 	 * Return: A newly created #GtkSymbolicColor
229 	 *
230 	 * Since: 3.4
231 	 *
232 	 * Throws: ConstructionException GTK+ fails to create the object.
233 	 */
234 	public this(string themeClass, int id)
235 	{
236 		auto p = gtk_symbolic_color_new_win32(Str.toStringz(themeClass), id);
237 		
238 		if(p is null)
239 		{
240 			throw new ConstructionException("null returned by new_win32");
241 		}
242 		
243 		this(cast(GtkSymbolicColor*) p);
244 	}
245 
246 	/**
247 	 * Increases the reference count of @color
248 	 *
249 	 * Deprecated: #GtkSymbolicColor is deprecated.
250 	 *
251 	 * Return: the same @color
252 	 *
253 	 * Since: 3.0
254 	 */
255 	public SymbolicColor doref()
256 	{
257 		auto p = gtk_symbolic_color_ref(gtkSymbolicColor);
258 		
259 		if(p is null)
260 		{
261 			return null;
262 		}
263 		
264 		return ObjectG.getDObject!(SymbolicColor)(cast(GtkSymbolicColor*) p);
265 	}
266 
267 	/**
268 	 * If @color is resolvable, @resolved_color will be filled in
269 	 * with the resolved color, and %TRUE will be returned. Generally,
270 	 * if @color can’t be resolved, it is due to it being defined on
271 	 * top of a named color that doesn’t exist in @props.
272 	 *
273 	 * When @props is %NULL, resolving of named colors will fail, so if
274 	 * your @color is or references such a color, this function will
275 	 * return %FALSE.
276 	 *
277 	 * Deprecated: #GtkSymbolicColor is deprecated.
278 	 *
279 	 * Params:
280 	 *     props = #GtkStyleProperties to use when resolving
281 	 *         named colors, or %NULL
282 	 *     resolvedColor = return location for the resolved color
283 	 *
284 	 * Return: %TRUE if the color has been resolved
285 	 *
286 	 * Since: 3.0
287 	 */
288 	public bool resolve(StyleProperties props, out RGBA resolvedColor)
289 	{
290 		GdkRGBA* outresolvedColor = new GdkRGBA;
291 		
292 		auto p = gtk_symbolic_color_resolve(gtkSymbolicColor, (props is null) ? null : props.getStylePropertiesStruct(), outresolvedColor) != 0;
293 		
294 		resolvedColor = ObjectG.getDObject!(RGBA)(outresolvedColor);
295 		
296 		return p;
297 	}
298 
299 	/**
300 	 * Converts the given @color to a string representation. This is useful
301 	 * both for debugging and for serialization of strings. The format of
302 	 * the string may change between different versions of GTK, but it is
303 	 * guaranteed that the GTK css parser is able to read the string and
304 	 * create the same symbolic color from it.
305 	 *
306 	 * Deprecated: #GtkSymbolicColor is deprecated.
307 	 *
308 	 * Return: a new string representing @color
309 	 */
310 	public override string toString()
311 	{
312 		return Str.toString(gtk_symbolic_color_to_string(gtkSymbolicColor));
313 	}
314 
315 	/**
316 	 * Decreases the reference count of @color, freeing its memory if the
317 	 * reference count reaches 0.
318 	 *
319 	 * Deprecated: #GtkSymbolicColor is deprecated.
320 	 *
321 	 * Since: 3.0
322 	 */
323 	public void unref()
324 	{
325 		gtk_symbolic_color_unref(gtkSymbolicColor);
326 	}
327 }