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.TargetList;
26 
27 private import glib.ConstructionException;
28 private import gobject.ObjectG;
29 private import gtk.TargetEntry;
30 private import gtk.TextBuffer;
31 private import gtk.c.functions;
32 public  import gtk.c.types;
33 public  import gtkc.gtktypes;
34 private import gtkd.Loader;
35 
36 
37 /**
38  * A #GtkTargetList-struct is a reference counted list
39  * of #GtkTargetPair and should be treated as
40  * opaque.
41  */
42 public class TargetList
43 {
44 	/** the main Gtk struct */
45 	protected GtkTargetList* gtkTargetList;
46 	protected bool ownedRef;
47 
48 	/** Get the main Gtk struct */
49 	public GtkTargetList* getTargetListStruct(bool transferOwnership = false)
50 	{
51 		if (transferOwnership)
52 			ownedRef = false;
53 		return gtkTargetList;
54 	}
55 
56 	/** the main Gtk struct as a void* */
57 	protected void* getStruct()
58 	{
59 		return cast(void*)gtkTargetList;
60 	}
61 
62 	/**
63 	 * Sets our main struct and passes it to the parent class.
64 	 */
65 	public this (GtkTargetList* gtkTargetList, bool ownedRef = false)
66 	{
67 		this.gtkTargetList = gtkTargetList;
68 		this.ownedRef = ownedRef;
69 	}
70 
71 	~this ()
72 	{
73 		if ( Linker.isLoaded(LIBRARY_GTK) && ownedRef )
74 			gtk_target_list_unref(gtkTargetList);
75 	}
76 
77 
78 	/** */
79 	public static GType getType()
80 	{
81 		return gtk_target_list_get_type();
82 	}
83 
84 	/**
85 	 * Creates a new #GtkTargetList from an array of #GtkTargetEntry.
86 	 *
87 	 * Params:
88 	 *     targets = Pointer to an array
89 	 *         of #GtkTargetEntry
90 	 *
91 	 * Returns: the new #GtkTargetList.
92 	 *
93 	 * Throws: ConstructionException GTK+ fails to create the object.
94 	 */
95 	public this(TargetEntry[] targets)
96 	{
97 		GtkTargetEntry[] targetsArray = new GtkTargetEntry[targets.length];
98 		for ( int i = 0; i < targets.length; i++ )
99 		{
100 			targetsArray[i] = *(targets[i].getTargetEntryStruct());
101 		}
102 
103 		auto p = gtk_target_list_new(targetsArray.ptr, cast(uint)targets.length);
104 
105 		if(p is null)
106 		{
107 			throw new ConstructionException("null returned by new");
108 		}
109 
110 		this(cast(GtkTargetList*) p);
111 	}
112 
113 	/**
114 	 * Appends another target to a #GtkTargetList.
115 	 *
116 	 * Params:
117 	 *     target = the interned atom representing the target
118 	 *     flags = the flags for this target
119 	 *     info = an ID that will be passed back to the application
120 	 */
121 	public void add(GdkAtom target, uint flags, uint info)
122 	{
123 		gtk_target_list_add(gtkTargetList, target, flags, info);
124 	}
125 
126 	/**
127 	 * Appends the image targets supported by #GtkSelectionData to
128 	 * the target list. All targets are added with the same @info.
129 	 *
130 	 * Params:
131 	 *     info = an ID that will be passed back to the application
132 	 *     writable = whether to add only targets for which GTK+ knows
133 	 *         how to convert a pixbuf into the format
134 	 *
135 	 * Since: 2.6
136 	 */
137 	public void addImageTargets(uint info, bool writable)
138 	{
139 		gtk_target_list_add_image_targets(gtkTargetList, info, writable);
140 	}
141 
142 	/**
143 	 * Appends the rich text targets registered with
144 	 * gtk_text_buffer_register_serialize_format() or
145 	 * gtk_text_buffer_register_deserialize_format() to the target list. All
146 	 * targets are added with the same @info.
147 	 *
148 	 * Params:
149 	 *     info = an ID that will be passed back to the application
150 	 *     deserializable = if %TRUE, then deserializable rich text formats
151 	 *         will be added, serializable formats otherwise.
152 	 *     buffer = a #GtkTextBuffer.
153 	 *
154 	 * Since: 2.10
155 	 */
156 	public void addRichTextTargets(uint info, bool deserializable, TextBuffer buffer)
157 	{
158 		gtk_target_list_add_rich_text_targets(gtkTargetList, info, deserializable, (buffer is null) ? null : buffer.getTextBufferStruct());
159 	}
160 
161 	/**
162 	 * Prepends a table of #GtkTargetEntry to a target list.
163 	 *
164 	 * Params:
165 	 *     targets = the table of #GtkTargetEntry
166 	 */
167 	public void addTable(TargetEntry[] targets)
168 	{
169 		GtkTargetEntry[] targetsArray = new GtkTargetEntry[targets.length];
170 		for ( int i = 0; i < targets.length; i++ )
171 		{
172 			targetsArray[i] = *(targets[i].getTargetEntryStruct());
173 		}
174 
175 		gtk_target_list_add_table(gtkTargetList, targetsArray.ptr, cast(uint)targets.length);
176 	}
177 
178 	/**
179 	 * Appends the text targets supported by #GtkSelectionData to
180 	 * the target list. All targets are added with the same @info.
181 	 *
182 	 * Params:
183 	 *     info = an ID that will be passed back to the application
184 	 *
185 	 * Since: 2.6
186 	 */
187 	public void addTextTargets(uint info)
188 	{
189 		gtk_target_list_add_text_targets(gtkTargetList, info);
190 	}
191 
192 	/**
193 	 * Appends the URI targets supported by #GtkSelectionData to
194 	 * the target list. All targets are added with the same @info.
195 	 *
196 	 * Params:
197 	 *     info = an ID that will be passed back to the application
198 	 *
199 	 * Since: 2.6
200 	 */
201 	public void addUriTargets(uint info)
202 	{
203 		gtk_target_list_add_uri_targets(gtkTargetList, info);
204 	}
205 
206 	/**
207 	 * Looks up a given target in a #GtkTargetList.
208 	 *
209 	 * Params:
210 	 *     target = an interned atom representing the target to search for
211 	 *     info = a pointer to the location to store
212 	 *         application info for target, or %NULL
213 	 *
214 	 * Returns: %TRUE if the target was found, otherwise %FALSE
215 	 */
216 	public bool find(GdkAtom target, out uint info)
217 	{
218 		return gtk_target_list_find(gtkTargetList, target, &info) != 0;
219 	}
220 
221 	alias doref = ref_;
222 	/**
223 	 * Increases the reference count of a #GtkTargetList by one.
224 	 *
225 	 * Returns: the passed in #GtkTargetList.
226 	 */
227 	public TargetList ref_()
228 	{
229 		auto p = gtk_target_list_ref(gtkTargetList);
230 
231 		if(p is null)
232 		{
233 			return null;
234 		}
235 
236 		return ObjectG.getDObject!(TargetList)(cast(GtkTargetList*) p, true);
237 	}
238 
239 	/**
240 	 * Removes a target from a target list.
241 	 *
242 	 * Params:
243 	 *     target = the interned atom representing the target
244 	 */
245 	public void remove(GdkAtom target)
246 	{
247 		gtk_target_list_remove(gtkTargetList, target);
248 	}
249 
250 	/**
251 	 * Decreases the reference count of a #GtkTargetList by one.
252 	 * If the resulting reference count is zero, frees the list.
253 	 */
254 	public void unref()
255 	{
256 		gtk_target_list_unref(gtkTargetList);
257 	}
258 
259 	/**
260 	 * This function frees a target table as returned by
261 	 * gtk_target_table_new_from_list()
262 	 *
263 	 * Params:
264 	 *     targets = a #GtkTargetEntry array
265 	 *
266 	 * Since: 2.10
267 	 */
268 	public static void targetTableFree(TargetEntry[] targets)
269 	{
270 		GtkTargetEntry[] targetsArray = new GtkTargetEntry[targets.length];
271 		for ( int i = 0; i < targets.length; i++ )
272 		{
273 			targetsArray[i] = *(targets[i].getTargetEntryStruct());
274 		}
275 
276 		gtk_target_table_free(targetsArray.ptr, cast(int)targets.length);
277 	}
278 
279 	/**
280 	 * This function creates an #GtkTargetEntry array that contains the
281 	 * same targets as the passed %list. The returned table is newly
282 	 * allocated and should be freed using gtk_target_table_free() when no
283 	 * longer needed.
284 	 *
285 	 * Params:
286 	 *     list = a #GtkTargetList
287 	 *
288 	 * Returns: the new table.
289 	 *
290 	 * Since: 2.10
291 	 */
292 	public static TargetEntry[] targetTableNewFromList(TargetList list)
293 	{
294 		int nTargets;
295 
296 		auto p = gtk_target_table_new_from_list((list is null) ? null : list.getTargetListStruct(), &nTargets);
297 
298 		if(p is null)
299 		{
300 			return null;
301 		}
302 
303 		TargetEntry[] arr = new TargetEntry[nTargets];
304 		for(int i = 0; i < nTargets; i++)
305 		{
306 			arr[i] = ObjectG.getDObject!(TargetEntry)(cast(GtkTargetEntry*) &p[i]);
307 		}
308 
309 		return arr;
310 	}
311 
312 	/**
313 	 * Determines if any of the targets in @targets can be used to
314 	 * provide a #GdkPixbuf.
315 	 *
316 	 * Params:
317 	 *     targets = an array of #GdkAtoms
318 	 *     writable = whether to accept only targets for which GTK+ knows
319 	 *         how to convert a pixbuf into the format
320 	 *
321 	 * Returns: %TRUE if @targets include a suitable target for images,
322 	 *     otherwise %FALSE.
323 	 *
324 	 * Since: 2.10
325 	 */
326 	public static bool includeImage(GdkAtom[] targets, bool writable)
327 	{
328 		return gtk_targets_include_image(targets.ptr, cast(int)targets.length, writable) != 0;
329 	}
330 
331 	/**
332 	 * Determines if any of the targets in @targets can be used to
333 	 * provide rich text.
334 	 *
335 	 * Params:
336 	 *     targets = an array of #GdkAtoms
337 	 *     buffer = a #GtkTextBuffer
338 	 *
339 	 * Returns: %TRUE if @targets include a suitable target for rich text,
340 	 *     otherwise %FALSE.
341 	 *
342 	 * Since: 2.10
343 	 */
344 	public static bool includeRichTex(GdkAtom[] targets, TextBuffer buffer)
345 	{
346 		return gtk_targets_include_rich_text(targets.ptr, cast(int)targets.length, (buffer is null) ? null : buffer.getTextBufferStruct()) != 0;
347 	}
348 
349 	/**
350 	 * Determines if any of the targets in @targets can be used to
351 	 * provide text.
352 	 *
353 	 * Params:
354 	 *     targets = an array of #GdkAtoms
355 	 *
356 	 * Returns: %TRUE if @targets include a suitable target for text,
357 	 *     otherwise %FALSE.
358 	 *
359 	 * Since: 2.10
360 	 */
361 	public static bool includeText(GdkAtom[] targets)
362 	{
363 		return gtk_targets_include_text(targets.ptr, cast(int)targets.length) != 0;
364 	}
365 
366 	/**
367 	 * Determines if any of the targets in @targets can be used to
368 	 * provide an uri list.
369 	 *
370 	 * Params:
371 	 *     targets = an array of #GdkAtoms
372 	 *
373 	 * Returns: %TRUE if @targets include a suitable target for uri lists,
374 	 *     otherwise %FALSE.
375 	 *
376 	 * Since: 2.10
377 	 */
378 	public static bool includeUri(GdkAtom[] targets)
379 	{
380 		return gtk_targets_include_uri(targets.ptr, cast(int)targets.length) != 0;
381 	}
382 }