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