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 gtkc.Loader;
32 private import gtkc.gtk;
33 public  import gtkc.gtktypes;
34 private import gtkc.paths;
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 
47 	/** Get the main Gtk struct */
48 	public GtkTargetList* getTargetListStruct()
49 	{
50 		return gtkTargetList;
51 	}
52 
53 	/** the main Gtk struct as a void* */
54 	protected void* getStruct()
55 	{
56 		return cast(void*)gtkTargetList;
57 	}
58 
59 	/**
60 	 * Sets our main struct and passes it to the parent class.
61 	 */
62 	public this (GtkTargetList* gtkTargetList)
63 	{
64 		this.gtkTargetList = gtkTargetList;
65 	}
66 
67 	~this ()
68 	{
69 		if (  Linker.isLoaded(LIBRARY.GTK) && gtkTargetList !is null )
70 		{
71 			gtk_target_list_unref(gtkTargetList);
72 		}
73 	}
74 
75 	/**
76 	 */
77 
78 	public static GType getType()
79 	{
80 		return gtk_target_list_get_type();
81 	}
82 
83 	/**
84 	 * Creates a new #GtkTargetList from an array of #GtkTargetEntry.
85 	 *
86 	 * Params:
87 	 *     targets = Pointer to an array
88 	 *         of #GtkTargetEntry
89 	 *     ntargets = number of entries in @targets.
90 	 *
91 	 * Return: 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 	 *     ntargets = number of targets in the table
167 	 */
168 	public void addTable(TargetEntry[] targets)
169 	{
170 		GtkTargetEntry[] targetsArray = new GtkTargetEntry[targets.length];
171 		for ( int i = 0; i < targets.length; i++ )
172 		{
173 			targetsArray[i] = *(targets[i].getTargetEntryStruct());
174 		}
175 		
176 		gtk_target_list_add_table(gtkTargetList, targetsArray.ptr, cast(uint)targets.length);
177 	}
178 
179 	/**
180 	 * Appends the text targets supported by #GtkSelectionData to
181 	 * the target list. All targets are added with the same @info.
182 	 *
183 	 * Params:
184 	 *     info = an ID that will be passed back to the application
185 	 *
186 	 * Since: 2.6
187 	 */
188 	public void addTextTargets(uint info)
189 	{
190 		gtk_target_list_add_text_targets(gtkTargetList, info);
191 	}
192 
193 	/**
194 	 * Appends the URI targets supported by #GtkSelectionData to
195 	 * the target list. All targets are added with the same @info.
196 	 *
197 	 * Params:
198 	 *     info = an ID that will be passed back to the application
199 	 *
200 	 * Since: 2.6
201 	 */
202 	public void addUriTargets(uint info)
203 	{
204 		gtk_target_list_add_uri_targets(gtkTargetList, info);
205 	}
206 
207 	/**
208 	 * Looks up a given target in a #GtkTargetList.
209 	 *
210 	 * Params:
211 	 *     target = an interned atom representing the target to search for
212 	 *     info = a pointer to the location to store
213 	 *         application info for target, or %NULL
214 	 *
215 	 * Return: %TRUE if the target was found, otherwise %FALSE
216 	 */
217 	public bool find(GdkAtom target, out uint info)
218 	{
219 		return gtk_target_list_find(gtkTargetList, target, &info) != 0;
220 	}
221 
222 	/**
223 	 * Increases the reference count of a #GtkTargetList by one.
224 	 *
225 	 * Return: the passed in #GtkTargetList.
226 	 */
227 	public TargetList doref()
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);
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 	 *     nTargets = the number of entries in the array
266 	 *
267 	 * Since: 2.10
268 	 */
269 	public static void targetTableFree(TargetEntry[] targets)
270 	{
271 		GtkTargetEntry[] targetsArray = new GtkTargetEntry[targets.length];
272 		for ( int i = 0; i < targets.length; i++ )
273 		{
274 			targetsArray[i] = *(targets[i].getTargetEntryStruct());
275 		}
276 		
277 		gtk_target_table_free(targetsArray.ptr, cast(int)targets.length);
278 	}
279 
280 	/**
281 	 * This function creates an #GtkTargetEntry array that contains the
282 	 * same targets as the passed %list. The returned table is newly
283 	 * allocated and should be freed using gtk_target_table_free() when no
284 	 * longer needed.
285 	 *
286 	 * Params:
287 	 *     list = a #GtkTargetList
288 	 *     nTargets = return location for the number ot targets in the table
289 	 *
290 	 * Return: the new table.
291 	 *
292 	 * Since: 2.10
293 	 */
294 	public static TargetEntry[] targetTableNewFromList(TargetList list)
295 	{
296 		int nTargets;
297 		
298 		auto p = gtk_target_table_new_from_list((list is null) ? null : list.getTargetListStruct(), &nTargets);
299 		
300 		if(p is null)
301 		{
302 			return null;
303 		}
304 		
305 		TargetEntry[] arr = new TargetEntry[nTargets];
306 		for(int i = 0; i < nTargets; i++)
307 		{
308 			arr[i] = ObjectG.getDObject!(TargetEntry)(cast(GtkTargetEntry*) &p[i]);
309 		}
310 		
311 		return arr;
312 	}
313 
314 	/**
315 	 * Determines if any of the targets in @targets can be used to
316 	 * provide a #GdkPixbuf.
317 	 *
318 	 * Params:
319 	 *     targets = an array of #GdkAtoms
320 	 *     nTargets = the length of @targets
321 	 *     writable = whether to accept only targets for which GTK+ knows
322 	 *         how to convert a pixbuf into the format
323 	 *
324 	 * Return: %TRUE if @targets include a suitable target for images,
325 	 *     otherwise %FALSE.
326 	 *
327 	 * Since: 2.10
328 	 */
329 	public static bool includeImage(GdkAtom[] targets, bool writable)
330 	{
331 		return gtk_targets_include_image(targets.ptr, cast(int)targets.length, writable) != 0;
332 	}
333 
334 	/**
335 	 * Determines if any of the targets in @targets can be used to
336 	 * provide rich text.
337 	 *
338 	 * Params:
339 	 *     targets = an array of #GdkAtoms
340 	 *     nTargets = the length of @targets
341 	 *     buffer = a #GtkTextBuffer
342 	 *
343 	 * Return: %TRUE if @targets include a suitable target for rich text,
344 	 *     otherwise %FALSE.
345 	 *
346 	 * Since: 2.10
347 	 */
348 	public static bool includeRichTex(GdkAtom[] targets, TextBuffer buffer)
349 	{
350 		return gtk_targets_include_rich_text(targets.ptr, cast(int)targets.length, (buffer is null) ? null : buffer.getTextBufferStruct()) != 0;
351 	}
352 
353 	/**
354 	 * Determines if any of the targets in @targets can be used to
355 	 * provide text.
356 	 *
357 	 * Params:
358 	 *     targets = an array of #GdkAtoms
359 	 *     nTargets = the length of @targets
360 	 *
361 	 * Return: %TRUE if @targets include a suitable target for text,
362 	 *     otherwise %FALSE.
363 	 *
364 	 * Since: 2.10
365 	 */
366 	public static bool includeText(GdkAtom[] targets)
367 	{
368 		return gtk_targets_include_text(targets.ptr, cast(int)targets.length) != 0;
369 	}
370 
371 	/**
372 	 * Determines if any of the targets in @targets can be used to
373 	 * provide an uri list.
374 	 *
375 	 * Params:
376 	 *     targets = an array of #GdkAtoms
377 	 *     nTargets = the length of @targets
378 	 *
379 	 * Return: %TRUE if @targets include a suitable target for uri lists,
380 	 *     otherwise %FALSE.
381 	 *
382 	 * Since: 2.10
383 	 */
384 	public static bool includeUri(GdkAtom[] targets)
385 	{
386 		return gtk_targets_include_uri(targets.ptr, cast(int)targets.length) != 0;
387 	}
388 }