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  * Conversion parameters:
26  * inFile  = 
27  * outPack = gtk
28  * outFile = SelectionData
29  * strct   = GtkSelectionData
30  * realStrct=
31  * ctorStrct=
32  * clss    = SelectionData
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gtk_selection_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- gdk.Display
48  * 	- gdk.Pixbuf
49  * 	- gtk.TextBuffer
50  * 	- gtk.Widget
51  * 	- gtkc.Loader
52  * 	- gtkc.paths
53  * structWrap:
54  * 	- GdkDisplay* -> Display
55  * 	- GdkPixbuf* -> Pixbuf
56  * 	- GtkSelectionData* -> SelectionData
57  * 	- GtkTextBuffer* -> TextBuffer
58  * 	- GtkWidget* -> Widget
59  * module aliases:
60  * local aliases:
61  * overrides:
62  */
63 
64 module gtk.SelectionData;
65 
66 public  import gtkc.gtktypes;
67 
68 private import gtkc.gtk;
69 private import glib.ConstructionException;
70 private import gobject.ObjectG;
71 
72 
73 private import glib.Str;
74 private import gdk.Display;
75 private import gdk.Pixbuf;
76 private import gtk.TextBuffer;
77 private import gtk.Widget;
78 private import gtkc.Loader;
79 private import gtkc.paths;
80 
81 
82 
83 private import gobject.Boxed;
84 
85 /**
86  * The selection mechanism provides the basis for different types
87  * of communication between processes. In particular, drag and drop and
88  * GtkClipboard work via selections. You will very seldom or
89  * never need to use most of the functions in this section directly;
90  * GtkClipboard provides a nicer interface to the same functionality.
91  *
92  * Some of the datatypes defined this section are used in
93  * the GtkClipboard and drag-and-drop API's as well. The
94  * GtkTargetEntry structure and GtkTargetList objects represent
95  * lists of data types that are supported when sending or
96  * receiving data. The GtkSelectionData object is used to
97  * store a chunk of data along with the data type and other
98  * associated information.
99  */
100 public class SelectionData : Boxed
101 {
102 	
103 	/** the main Gtk struct */
104 	protected GtkSelectionData* gtkSelectionData;
105 	
106 	
107 	public GtkSelectionData* getSelectionDataStruct()
108 	{
109 		return gtkSelectionData;
110 	}
111 	
112 	
113 	/** the main Gtk struct as a void* */
114 	protected void* getStruct()
115 	{
116 		return cast(void*)gtkSelectionData;
117 	}
118 	
119 	/**
120 	 * Sets our main struct and passes it to the parent class
121 	 */
122 	public this (GtkSelectionData* gtkSelectionData)
123 	{
124 		this.gtkSelectionData = gtkSelectionData;
125 	}
126 	
127 	~this ()
128 	{
129 		if (  Linker.isLoaded(LIBRARY.GTK) && gtkSelectionData !is null )
130 		{
131 			gtk_selection_data_free(gtkSelectionData);
132 		}
133 	}
134 	
135 	/**
136 	 */
137 	
138 	/**
139 	 * Claims ownership of a given selection for a particular widget,
140 	 * or, if widget is NULL, release ownership of the selection.
141 	 * Params:
142 	 * widget = a GtkWidget, or NULL. [allow-none]
143 	 * selection = an interned atom representing the selection to claim
144 	 * time = timestamp with which to claim the selection
145 	 * Returns: TRUE if the operation succeeded
146 	 */
147 	public static int ownerSet(Widget widget, GdkAtom selection, uint time)
148 	{
149 		// gboolean gtk_selection_owner_set (GtkWidget *widget,  GdkAtom selection,  guint32 time_);
150 		return gtk_selection_owner_set((widget is null) ? null : widget.getWidgetStruct(), selection, time);
151 	}
152 	
153 	/**
154 	 * Claim ownership of a given selection for a particular widget, or,
155 	 * if widget is NULL, release ownership of the selection.
156 	 * Since 2.2
157 	 * Params:
158 	 * display = the GdkDisplay where the selection is set
159 	 * widget = new selection owner (a GtkWidget), or NULL. [allow-none]
160 	 * selection = an interned atom representing the selection to claim.
161 	 * time = timestamp with which to claim the selection
162 	 * Returns: TRUE if the operation succeeded
163 	 */
164 	public static int ownerSetForDisplay(Display display, Widget widget, GdkAtom selection, uint time)
165 	{
166 		// gboolean gtk_selection_owner_set_for_display (GdkDisplay *display,  GtkWidget *widget,  GdkAtom selection,  guint32 time_);
167 		return gtk_selection_owner_set_for_display((display is null) ? null : display.getDisplayStruct(), (widget is null) ? null : widget.getWidgetStruct(), selection, time);
168 	}
169 	
170 	/**
171 	 * Appends a specified target to the list of supported targets for a
172 	 * given widget and selection.
173 	 * Params:
174 	 * widget = a GtkTarget
175 	 * selection = the selection
176 	 * target = target to add.
177 	 * info = A unsigned integer which will be passed back to the application.
178 	 */
179 	public static void addTarget(Widget widget, GdkAtom selection, GdkAtom target, uint info)
180 	{
181 		// void gtk_selection_add_target (GtkWidget *widget,  GdkAtom selection,  GdkAtom target,  guint info);
182 		gtk_selection_add_target((widget is null) ? null : widget.getWidgetStruct(), selection, target, info);
183 	}
184 	
185 	/**
186 	 * Prepends a table of targets to the list of supported targets
187 	 * for a given widget and selection.
188 	 * Params:
189 	 * widget = a GtkWidget
190 	 * selection = the selection
191 	 * targets = a table of targets to add. [array length=ntargets]
192 	 */
193 	public static void addTargets(Widget widget, GdkAtom selection, GtkTargetEntry[] targets)
194 	{
195 		// void gtk_selection_add_targets (GtkWidget *widget,  GdkAtom selection,  const GtkTargetEntry *targets,  guint ntargets);
196 		gtk_selection_add_targets((widget is null) ? null : widget.getWidgetStruct(), selection, targets.ptr, cast(int) targets.length);
197 	}
198 	
199 	/**
200 	 * Remove all targets registered for the given selection for the
201 	 * widget.
202 	 * Params:
203 	 * widget = a GtkWidget
204 	 * selection = an atom representing a selection
205 	 */
206 	public static void clearTargets(Widget widget, GdkAtom selection)
207 	{
208 		// void gtk_selection_clear_targets (GtkWidget *widget,  GdkAtom selection);
209 		gtk_selection_clear_targets((widget is null) ? null : widget.getWidgetStruct(), selection);
210 	}
211 	
212 	/**
213 	 * Requests the contents of a selection. When received,
214 	 * a "selection-received" signal will be generated.
215 	 * Params:
216 	 * widget = The widget which acts as requestor
217 	 * selection = Which selection to get
218 	 * target = Form of information desired (e.g., STRING)
219 	 * time = Time of request (usually of triggering event)
220 	 * In emergency, you could use GDK_CURRENT_TIME
221 	 * Returns: TRUE if requested succeeded. FALSE if we could not process request. (e.g., there was already a request in process for this widget).
222 	 */
223 	public static int convert(Widget widget, GdkAtom selection, GdkAtom target, uint time)
224 	{
225 		// gboolean gtk_selection_convert (GtkWidget *widget,  GdkAtom selection,  GdkAtom target,  guint32 time_);
226 		return gtk_selection_convert((widget is null) ? null : widget.getWidgetStruct(), selection, target, time);
227 	}
228 	
229 	/**
230 	 * Stores new data into a GtkSelectionData object. Should
231 	 * only be called from a selection handler callback.
232 	 * Zero-terminates the stored data.
233 	 * Params:
234 	 * type = the type of selection data
235 	 * format = format (number of bits in a unit)
236 	 * data = pointer to the data (will be copied). [array length=length]
237 	 */
238 	public void dataSet(GdkAtom type, int format, char[] data)
239 	{
240 		// void gtk_selection_data_set (GtkSelectionData *selection_data,  GdkAtom type,  gint format,  const guchar *data,  gint length);
241 		gtk_selection_data_set(gtkSelectionData, type, format, data.ptr, cast(int) data.length);
242 	}
243 	
244 	/**
245 	 * Sets the contents of the selection from a UTF-8 encoded string.
246 	 * The string is converted to the form determined by
247 	 * selection_data->target.
248 	 * Params:
249 	 * str = a UTF-8 string
250 	 * Returns: TRUE if the selection was successfully set, otherwise FALSE.
251 	 */
252 	public int dataSetText(string str)
253 	{
254 		// gboolean gtk_selection_data_set_text (GtkSelectionData *selection_data,  const gchar *str,  gint len);
255 		return gtk_selection_data_set_text(gtkSelectionData, cast(char*)str.ptr, cast(int) str.length);
256 	}
257 	
258 	/**
259 	 * Gets the contents of the selection data as a UTF-8 string.
260 	 * Returns: if the selection data contained a recognized text type and it could be converted to UTF-8, a newly allocated string containing the converted text, otherwise NULL. If the result is non-NULL it must be freed with g_free(). [type utf8]
261 	 */
262 	public char* dataGetText()
263 	{
264 		// guchar * gtk_selection_data_get_text (const GtkSelectionData *selection_data);
265 		return gtk_selection_data_get_text(gtkSelectionData);
266 	}
267 	
268 	/**
269 	 * Sets the contents of the selection from a GdkPixbuf
270 	 * The pixbuf is converted to the form determined by
271 	 * selection_data->target.
272 	 * Since 2.6
273 	 * Params:
274 	 * pixbuf = a GdkPixbuf
275 	 * Returns: TRUE if the selection was successfully set, otherwise FALSE.
276 	 */
277 	public int dataSetPixbuf(Pixbuf pixbuf)
278 	{
279 		// gboolean gtk_selection_data_set_pixbuf (GtkSelectionData *selection_data,  GdkPixbuf *pixbuf);
280 		return gtk_selection_data_set_pixbuf(gtkSelectionData, (pixbuf is null) ? null : pixbuf.getPixbufStruct());
281 	}
282 	
283 	/**
284 	 * Gets the contents of the selection data as a GdkPixbuf.
285 	 * Since 2.6
286 	 * Returns: if the selection data contained a recognized image type and it could be converted to a GdkPixbuf, a newly allocated pixbuf is returned, otherwise NULL. If the result is non-NULL it must be freed with g_object_unref(). [transfer full]
287 	 */
288 	public Pixbuf dataGetPixbuf()
289 	{
290 		// GdkPixbuf * gtk_selection_data_get_pixbuf (const GtkSelectionData *selection_data);
291 		auto p = gtk_selection_data_get_pixbuf(gtkSelectionData);
292 		
293 		if(p is null)
294 		{
295 			return null;
296 		}
297 		
298 		return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p);
299 	}
300 	
301 	/**
302 	 * Sets the contents of the selection from a list of URIs.
303 	 * The string is converted to the form determined by
304 	 * selection_data->target.
305 	 * Since 2.6
306 	 * Params:
307 	 * uris = a NULL-terminated array of
308 	 * strings holding URIs. [array zero-terminated=1]
309 	 * Returns: TRUE if the selection was successfully set, otherwise FALSE.
310 	 */
311 	public int dataSetUris(string[] uris)
312 	{
313 		// gboolean gtk_selection_data_set_uris (GtkSelectionData *selection_data,  gchar **uris);
314 		return gtk_selection_data_set_uris(gtkSelectionData, Str.toStringzArray(uris));
315 	}
316 	
317 	/**
318 	 * Gets the contents of the selection data as array of URIs.
319 	 * Since 2.6
320 	 * Returns: if the selection data contains a list of URIs, a newly allocated NULL-terminated string array containing the URIs, otherwise NULL. If the result is non-NULL it must be freed with g_strfreev(). [array zero-terminated=1][element-type utf8][transfer full]
321 	 */
322 	public string[] dataGetUris()
323 	{
324 		// gchar ** gtk_selection_data_get_uris (const GtkSelectionData *selection_data);
325 		return Str.toStringArray(gtk_selection_data_get_uris(gtkSelectionData));
326 	}
327 	
328 	/**
329 	 * Gets the contents of selection_data as an array of targets.
330 	 * This can be used to interpret the results of getting
331 	 * the standard TARGETS target that is always supplied for
332 	 * any selection.
333 	 * Params:
334 	 * targets = location to store an array of targets. The result stored
335 	 * here must be freed with g_free(). [out][array length=n_atoms][transfer container]
336 	 * Returns: TRUE if selection_data contains a valid array of targets, otherwise FALSE.
337 	 */
338 	public int dataGetTargets(out GdkAtom[] targets)
339 	{
340 		// gboolean gtk_selection_data_get_targets (const GtkSelectionData *selection_data,  GdkAtom **targets,  gint *n_atoms);
341 		GdkAtom* outtargets = null;
342 		int nAtoms;
343 		
344 		auto p = gtk_selection_data_get_targets(gtkSelectionData, &outtargets, &nAtoms);
345 		
346 		targets = outtargets[0 .. nAtoms];
347 		return p;
348 	}
349 	
350 	/**
351 	 * Given a GtkSelectionData object holding a list of targets,
352 	 * determines if any of the targets in targets can be used to
353 	 * provide a GdkPixbuf.
354 	 * Since 2.6
355 	 * Params:
356 	 * writable = whether to accept only targets for which GTK+ knows
357 	 * how to convert a pixbuf into the format
358 	 * Returns: TRUE if selection_data holds a list of targets, and a suitable target for images is included, otherwise FALSE.
359 	 */
360 	public int dataTargetsIncludeImage(int writable)
361 	{
362 		// gboolean gtk_selection_data_targets_include_image  (const GtkSelectionData *selection_data,  gboolean writable);
363 		return gtk_selection_data_targets_include_image(gtkSelectionData, writable);
364 	}
365 	
366 	/**
367 	 * Given a GtkSelectionData object holding a list of targets,
368 	 * determines if any of the targets in targets can be used to
369 	 * provide text.
370 	 * Returns: TRUE if selection_data holds a list of targets, and a suitable target for text is included, otherwise FALSE.
371 	 */
372 	public int dataTargetsIncludeText()
373 	{
374 		// gboolean gtk_selection_data_targets_include_text  (const GtkSelectionData *selection_data);
375 		return gtk_selection_data_targets_include_text(gtkSelectionData);
376 	}
377 	
378 	/**
379 	 * Given a GtkSelectionData object holding a list of targets,
380 	 * determines if any of the targets in targets can be used to
381 	 * provide a list or URIs.
382 	 * Since 2.10
383 	 * Returns: TRUE if selection_data holds a list of targets, and a suitable target for URI lists is included, otherwise FALSE.
384 	 */
385 	public int dataTargetsIncludeUri()
386 	{
387 		// gboolean gtk_selection_data_targets_include_uri  (const GtkSelectionData *selection_data);
388 		return gtk_selection_data_targets_include_uri(gtkSelectionData);
389 	}
390 	
391 	/**
392 	 * Given a GtkSelectionData object holding a list of targets,
393 	 * determines if any of the targets in targets can be used to
394 	 * provide rich text.
395 	 * Since 2.10
396 	 * Params:
397 	 * buffer = a GtkTextBuffer
398 	 * Returns: TRUE if selection_data holds a list of targets, and a suitable target for rich text is included, otherwise FALSE.
399 	 */
400 	public int dataTargetsIncludeRichText(TextBuffer buffer)
401 	{
402 		// gboolean gtk_selection_data_targets_include_rich_text  (const GtkSelectionData *selection_data,  GtkTextBuffer *buffer);
403 		return gtk_selection_data_targets_include_rich_text(gtkSelectionData, (buffer is null) ? null : buffer.getTextBufferStruct());
404 	}
405 	
406 	/**
407 	 * Retrieves the selection GdkAtom of the selection data.
408 	 * Since 2.16
409 	 * Returns: the selection GdkAtom of the selection data. [transfer none]
410 	 */
411 	public GdkAtom dataGetSelection()
412 	{
413 		// GdkAtom gtk_selection_data_get_selection (const GtkSelectionData *selection_data);
414 		return gtk_selection_data_get_selection(gtkSelectionData);
415 	}
416 	
417 	/**
418 	 * Retrieves the raw data of the selection.
419 	 * Since 2.14
420 	 * Returns: the raw data of the selection.
421 	 */
422 	public char* dataGetData()
423 	{
424 		// const guchar * gtk_selection_data_get_data (const GtkSelectionData *selection_data);
425 		return gtk_selection_data_get_data(gtkSelectionData);
426 	}
427 	
428 	/**
429 	 * Retrieves the length of the raw data of the selection.
430 	 * Since 2.14
431 	 * Returns: the length of the data of the selection.
432 	 */
433 	public int dataGetLength()
434 	{
435 		// gint gtk_selection_data_get_length (const GtkSelectionData *selection_data);
436 		return gtk_selection_data_get_length(gtkSelectionData);
437 	}
438 	
439 	/**
440 	 * Retrieves the raw data of the selection along with its length.
441 	 * Returns: the raw data of the selection Rename to: gtk_selection_data_get_data. [array length=length] Since 3.0
442 	 */
443 	public char[] dataGetDataWithLength()
444 	{
445 		// const guchar * gtk_selection_data_get_data_with_length  (const GtkSelectionData *selection_data,  gint *length);
446 		int length;
447 		auto p = gtk_selection_data_get_data_with_length(gtkSelectionData, &length);
448 		
449 		if(p is null)
450 		{
451 			return null;
452 		}
453 		
454 		return p[0 .. length];
455 	}
456 	
457 	/**
458 	 * Retrieves the data type of the selection.
459 	 * Since 2.14
460 	 * Returns: the data type of the selection. [transfer none]
461 	 */
462 	public GdkAtom dataGetDataType()
463 	{
464 		// GdkAtom gtk_selection_data_get_data_type (const GtkSelectionData *selection_data);
465 		return gtk_selection_data_get_data_type(gtkSelectionData);
466 	}
467 	
468 	/**
469 	 * Retrieves the display of the selection.
470 	 * Since 2.14
471 	 * Returns: the display of the selection. [transfer none]
472 	 */
473 	public Display dataGetDisplay()
474 	{
475 		// GdkDisplay * gtk_selection_data_get_display (const GtkSelectionData *selection_data);
476 		auto p = gtk_selection_data_get_display(gtkSelectionData);
477 		
478 		if(p is null)
479 		{
480 			return null;
481 		}
482 		
483 		return ObjectG.getDObject!(Display)(cast(GdkDisplay*) p);
484 	}
485 	
486 	/**
487 	 * Retrieves the format of the selection.
488 	 * Since 2.14
489 	 * Returns: the format of the selection.
490 	 */
491 	public int dataGetFormat()
492 	{
493 		// gint gtk_selection_data_get_format (const GtkSelectionData *selection_data);
494 		return gtk_selection_data_get_format(gtkSelectionData);
495 	}
496 	
497 	/**
498 	 * Retrieves the target of the selection.
499 	 * Since 2.14
500 	 * Returns: the target of the selection. [transfer none]
501 	 */
502 	public GdkAtom dataGetTarget()
503 	{
504 		// GdkAtom gtk_selection_data_get_target (const GtkSelectionData *selection_data);
505 		return gtk_selection_data_get_target(gtkSelectionData);
506 	}
507 	
508 	/**
509 	 * Removes all handlers and unsets ownership of all
510 	 * selections for a widget. Called when widget is being
511 	 * destroyed. This function will not generally be
512 	 * called by applications.
513 	 * Params:
514 	 * widget = a GtkWidget
515 	 */
516 	public static void removeAll(Widget widget)
517 	{
518 		// void gtk_selection_remove_all (GtkWidget *widget);
519 		gtk_selection_remove_all((widget is null) ? null : widget.getWidgetStruct());
520 	}
521 	
522 	/**
523 	 * Makes a copy of a GtkSelectionData structure and its data.
524 	 * Params:
525 	 * data = a pointer to a GtkSelectionData structure.
526 	 * Returns: a pointer to a copy of data.
527 	 */
528 	public SelectionData dataCopy()
529 	{
530 		// GtkSelectionData * gtk_selection_data_copy (const GtkSelectionData *data);
531 		auto p = gtk_selection_data_copy(gtkSelectionData);
532 		
533 		if(p is null)
534 		{
535 			return null;
536 		}
537 		
538 		return ObjectG.getDObject!(SelectionData)(cast(GtkSelectionData*) p);
539 	}
540 	
541 	/**
542 	 * Frees a GtkSelectionData structure returned from
543 	 * gtk_selection_data_copy().
544 	 * Params:
545 	 * data = a pointer to a GtkSelectionData structure.
546 	 */
547 	public void dataFree()
548 	{
549 		// void gtk_selection_data_free (GtkSelectionData *data);
550 		gtk_selection_data_free(gtkSelectionData);
551 	}
552 }