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