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 gdk.ContentFormats;
26 
27 private import gdk.c.functions;
28 public  import gdk.c.types;
29 private import glib.ConstructionException;
30 private import glib.Str;
31 private import glib.StringG;
32 private import glib.c.functions;
33 private import gobject.ObjectG;
34 private import gtkd.Loader;
35 
36 
37 /**
38  * The `GdkContentFormats` structure is used to advertise and negotiate the
39  * format of content.
40  * 
41  * You will encounter `GdkContentFormats` when interacting with objects
42  * controlling operations that pass data between different widgets, window
43  * or application, like [class@Gdk.Drag], [class@Gdk.Drop],
44  * [class@Gdk.Clipboard] or [class@Gdk.ContentProvider].
45  * 
46  * GDK supports content in 2 forms: `GType` and mime type.
47  * Using `GTypes` is meant only for in-process content transfers. Mime types
48  * are meant to be used for data passing both in-process and out-of-process.
49  * The details of how data is passed is described in the documentation of
50  * the actual implementations. To transform between the two forms,
51  * [class@Gdk.ContentSerializer] and [class@Gdk.ContentDeserializer] are used.
52  * 
53  * A `GdkContentFormats` describes a set of possible formats content can be
54  * exchanged in. It is assumed that this set is ordered. `GTypes` are more
55  * important than mime types. Order between different `GTypes` or mime types
56  * is the order they were added in, most important first. Functions that
57  * care about order, such as [method@Gdk.ContentFormats.union], will describe
58  * in their documentation how they interpret that order, though in general the
59  * order of the first argument is considered the primary order of the result,
60  * followed by the order of further arguments.
61  * 
62  * For debugging purposes, the function [method@Gdk.ContentFormats.to_string]
63  * exists. It will print a comma-separated list of formats from most important
64  * to least important.
65  * 
66  * `GdkContentFormats` is an immutable struct. After creation, you cannot change
67  * the types it represents. Instead, new `GdkContentFormats` have to be created.
68  * The [struct@Gdk.ContentFormatsBuilder]` structure is meant to help in this
69  * endeavor.
70  */
71 public class ContentFormats
72 {
73 	/** the main Gtk struct */
74 	protected GdkContentFormats* gdkContentFormats;
75 	protected bool ownedRef;
76 
77 	/** Get the main Gtk struct */
78 	public GdkContentFormats* getContentFormatsStruct(bool transferOwnership = false)
79 	{
80 		if (transferOwnership)
81 			ownedRef = false;
82 		return gdkContentFormats;
83 	}
84 
85 	/** the main Gtk struct as a void* */
86 	protected void* getStruct()
87 	{
88 		return cast(void*)gdkContentFormats;
89 	}
90 
91 	/**
92 	 * Sets our main struct and passes it to the parent class.
93 	 */
94 	public this (GdkContentFormats* gdkContentFormats, bool ownedRef = false)
95 	{
96 		this.gdkContentFormats = gdkContentFormats;
97 		this.ownedRef = ownedRef;
98 	}
99 
100 	~this ()
101 	{
102 		if ( Linker.isLoaded(LIBRARY_GDK) && ownedRef )
103 			gdk_content_formats_unref(gdkContentFormats);
104 	}
105 
106 
107 	/** */
108 	public static GType getType()
109 	{
110 		return gdk_content_formats_get_type();
111 	}
112 
113 	/**
114 	 * Creates a new `GdkContentFormats` from an array of mime types.
115 	 *
116 	 * The mime types must be valid and different from each other or the
117 	 * behavior of the return value is undefined. If you cannot guarantee
118 	 * this, use `GdkContentFormatsBuilder` instead.
119 	 *
120 	 * Params:
121 	 *     mimeTypes = Pointer to an
122 	 *         array of mime types
123 	 *
124 	 * Returns: the new `GdkContentFormats`.
125 	 *
126 	 * Throws: ConstructionException GTK+ fails to create the object.
127 	 */
128 	public this(string[] mimeTypes)
129 	{
130 		auto __p = gdk_content_formats_new(Str.toStringzArray(mimeTypes), cast(uint)mimeTypes.length);
131 
132 		if(__p is null)
133 		{
134 			throw new ConstructionException("null returned by new");
135 		}
136 
137 		this(cast(GdkContentFormats*) __p);
138 	}
139 
140 	/**
141 	 * Creates a new `GdkContentFormats` for a given `GType`.
142 	 *
143 	 * Params:
144 	 *     type = a `GType`
145 	 *
146 	 * Returns: a new `GdkContentFormats`
147 	 *
148 	 * Throws: ConstructionException GTK+ fails to create the object.
149 	 */
150 	public this(GType type)
151 	{
152 		auto __p = gdk_content_formats_new_for_gtype(type);
153 
154 		if(__p is null)
155 		{
156 			throw new ConstructionException("null returned by new_for_gtype");
157 		}
158 
159 		this(cast(GdkContentFormats*) __p);
160 	}
161 
162 	/**
163 	 * Checks if a given `GType` is part of the given @formats.
164 	 *
165 	 * Params:
166 	 *     type = the `GType` to search for
167 	 *
168 	 * Returns: %TRUE if the #GType was found
169 	 */
170 	public bool containGtype(GType type)
171 	{
172 		return gdk_content_formats_contain_gtype(gdkContentFormats, type) != 0;
173 	}
174 
175 	/**
176 	 * Checks if a given mime type is part of the given @formats.
177 	 *
178 	 * Params:
179 	 *     mimeType = the mime type to search for
180 	 *
181 	 * Returns: %TRUE if the mime_type was found
182 	 */
183 	public bool containMimeType(string mimeType)
184 	{
185 		return gdk_content_formats_contain_mime_type(gdkContentFormats, Str.toStringz(mimeType)) != 0;
186 	}
187 
188 	/**
189 	 * Gets the `GTypes` included in @formats.
190 	 *
191 	 * Note that @formats may not contain any #GTypes, in particular when
192 	 * they are empty. In that case %NULL will be returned.
193 	 *
194 	 * Returns: %G_TYPE_INVALID-terminated array of types included in @formats or
195 	 *     %NULL if none.
196 	 */
197 	public GType[] getGtypes()
198 	{
199 		size_t nGtypes;
200 
201 		auto __p = gdk_content_formats_get_gtypes(gdkContentFormats, &nGtypes);
202 
203 		return __p[0 .. nGtypes];
204 	}
205 
206 	/**
207 	 * Gets the mime types included in @formats.
208 	 *
209 	 * Note that @formats may not contain any mime types, in particular
210 	 * when they are empty. In that case %NULL will be returned.
211 	 *
212 	 * Returns: %NULL-terminated array of
213 	 *     interned strings of mime types included in @formats or %NULL
214 	 *     if none.
215 	 */
216 	public string[] getMimeTypes()
217 	{
218 		size_t nMimeTypes;
219 
220 		return Str.toStringArray(gdk_content_formats_get_mime_types(gdkContentFormats, &nMimeTypes));
221 	}
222 
223 	/**
224 	 * Checks if @first and @second have any matching formats.
225 	 *
226 	 * Params:
227 	 *     second = the `GdkContentFormats` to intersect with
228 	 *
229 	 * Returns: %TRUE if a matching format was found.
230 	 */
231 	public bool match(ContentFormats second)
232 	{
233 		return gdk_content_formats_match(gdkContentFormats, (second is null) ? null : second.getContentFormatsStruct()) != 0;
234 	}
235 
236 	/**
237 	 * Finds the first `GType` from @first that is also contained
238 	 * in @second.
239 	 *
240 	 * If no matching `GType` is found, %G_TYPE_INVALID is returned.
241 	 *
242 	 * Params:
243 	 *     second = the `GdkContentFormats` to intersect with
244 	 *
245 	 * Returns: The first common `GType` or %G_TYPE_INVALID if none.
246 	 */
247 	public GType matchGtype(ContentFormats second)
248 	{
249 		return gdk_content_formats_match_gtype(gdkContentFormats, (second is null) ? null : second.getContentFormatsStruct());
250 	}
251 
252 	/**
253 	 * Finds the first mime type from @first that is also contained
254 	 * in @second.
255 	 *
256 	 * If no matching mime type is found, %NULL is returned.
257 	 *
258 	 * Params:
259 	 *     second = the `GdkContentFormats` to intersect with
260 	 *
261 	 * Returns: The first common mime type or %NULL if none.
262 	 */
263 	public string matchMimeType(ContentFormats second)
264 	{
265 		return Str.toString(gdk_content_formats_match_mime_type(gdkContentFormats, (second is null) ? null : second.getContentFormatsStruct()));
266 	}
267 
268 	/**
269 	 * Prints the given @formats into a string for human consumption.
270 	 *
271 	 * This is meant for debugging and logging.
272 	 *
273 	 * The form of the representation may change at any time and is
274 	 * not guaranteed to stay identical.
275 	 *
276 	 * Params:
277 	 *     string_ = a `GString` to print into
278 	 */
279 	public void print(StringG string_)
280 	{
281 		gdk_content_formats_print(gdkContentFormats, (string_ is null) ? null : string_.getStringGStruct());
282 	}
283 
284 	alias doref = ref_;
285 	/**
286 	 * Increases the reference count of a `GdkContentFormats` by one.
287 	 *
288 	 * Returns: the passed in `GdkContentFormats`.
289 	 */
290 	public ContentFormats ref_()
291 	{
292 		auto __p = gdk_content_formats_ref(gdkContentFormats);
293 
294 		if(__p is null)
295 		{
296 			return null;
297 		}
298 
299 		return ObjectG.getDObject!(ContentFormats)(cast(GdkContentFormats*) __p, true);
300 	}
301 
302 	/**
303 	 * Prints the given @formats into a human-readable string.
304 	 *
305 	 * This is a small wrapper around [method@Gdk.ContentFormats.print]
306 	 * to help when debugging.
307 	 *
308 	 * Returns: a new string
309 	 */
310 	public override string toString()
311 	{
312 		auto retStr = gdk_content_formats_to_string(gdkContentFormats);
313 
314 		scope(exit) Str.freeString(retStr);
315 		return Str.toString(retStr);
316 	}
317 
318 	alias unio = union_;
319 	/**
320 	 * Append all missing types from @second to @first, in the order
321 	 * they had in @second.
322 	 *
323 	 * Params:
324 	 *     second = the `GdkContentFormats` to merge from
325 	 *
326 	 * Returns: a new `GdkContentFormats`
327 	 */
328 	public ContentFormats union_(ContentFormats second)
329 	{
330 		auto __p = gdk_content_formats_union(gdkContentFormats, (second is null) ? null : second.getContentFormatsStruct());
331 
332 		if(__p is null)
333 		{
334 			return null;
335 		}
336 
337 		return ObjectG.getDObject!(ContentFormats)(cast(GdkContentFormats*) __p, true);
338 	}
339 
340 	/**
341 	 * Add GTypes for mime types in @formats for which deserializers are
342 	 * registered.
343 	 *
344 	 * Returns: a new `GdkContentFormats`
345 	 */
346 	public ContentFormats unionDeserializeGtypes()
347 	{
348 		auto __p = gdk_content_formats_union_deserialize_gtypes(gdkContentFormats);
349 
350 		if(__p is null)
351 		{
352 			return null;
353 		}
354 
355 		return ObjectG.getDObject!(ContentFormats)(cast(GdkContentFormats*) __p, true);
356 	}
357 
358 	/**
359 	 * Add mime types for GTypes in @formats for which deserializers are
360 	 * registered.
361 	 *
362 	 * Returns: a new `GdkContentFormats`
363 	 */
364 	public ContentFormats unionDeserializeMimeTypes()
365 	{
366 		auto __p = gdk_content_formats_union_deserialize_mime_types(gdkContentFormats);
367 
368 		if(__p is null)
369 		{
370 			return null;
371 		}
372 
373 		return ObjectG.getDObject!(ContentFormats)(cast(GdkContentFormats*) __p, true);
374 	}
375 
376 	/**
377 	 * Add GTypes for the mime types in @formats for which serializers are
378 	 * registered.
379 	 *
380 	 * Returns: a new `GdkContentFormats`
381 	 */
382 	public ContentFormats unionSerializeGtypes()
383 	{
384 		auto __p = gdk_content_formats_union_serialize_gtypes(gdkContentFormats);
385 
386 		if(__p is null)
387 		{
388 			return null;
389 		}
390 
391 		return ObjectG.getDObject!(ContentFormats)(cast(GdkContentFormats*) __p, true);
392 	}
393 
394 	/**
395 	 * Add mime types for GTypes in @formats for which serializers are
396 	 * registered.
397 	 *
398 	 * Returns: a new `GdkContentFormats`
399 	 */
400 	public ContentFormats unionSerializeMimeTypes()
401 	{
402 		auto __p = gdk_content_formats_union_serialize_mime_types(gdkContentFormats);
403 
404 		if(__p is null)
405 		{
406 			return null;
407 		}
408 
409 		return ObjectG.getDObject!(ContentFormats)(cast(GdkContentFormats*) __p, true);
410 	}
411 
412 	/**
413 	 * Decreases the reference count of a `GdkContentFormats` by one.
414 	 *
415 	 * If the resulting reference count is zero, frees the formats.
416 	 */
417 	public void unref()
418 	{
419 		gdk_content_formats_unref(gdkContentFormats);
420 	}
421 }