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