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