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.Clipboard;
26 
27 private import gdk.Display;
28 private import gdk.Event;
29 private import gdkpixbuf.Pixbuf;
30 private import glib.Str;
31 private import gobject.ObjectG;
32 private import gobject.Signals;
33 private import gtk.SelectionData;
34 private import gtk.TargetEntry;
35 private import gtk.TextBuffer;
36 private import gtk.c.functions;
37 public  import gtk.c.types;
38 public  import gtkc.gtktypes;
39 private import std.algorithm;
40 
41 
42 /**
43  * The #GtkClipboard object represents a clipboard of data shared
44  * between different processes or between different widgets in
45  * the same process. Each clipboard is identified by a name encoded as a
46  * #GdkAtom. (Conversion to and from strings can be done with
47  * gdk_atom_intern() and gdk_atom_name().) The default clipboard
48  * corresponds to the “CLIPBOARD” atom; another commonly used clipboard
49  * is the “PRIMARY” clipboard, which, in X, traditionally contains
50  * the currently selected text.
51  * 
52  * To support having a number of different formats on the clipboard
53  * at the same time, the clipboard mechanism allows providing
54  * callbacks instead of the actual data.  When you set the contents
55  * of the clipboard, you can either supply the data directly (via
56  * functions like gtk_clipboard_set_text()), or you can supply a
57  * callback to be called at a later time when the data is needed (via
58  * gtk_clipboard_set_with_data() or gtk_clipboard_set_with_owner().)
59  * Providing a callback also avoids having to make copies of the data
60  * when it is not needed.
61  * 
62  * gtk_clipboard_set_with_data() and gtk_clipboard_set_with_owner()
63  * are quite similar; the choice between the two depends mostly on
64  * which is more convenient in a particular situation.
65  * The former is most useful when you want to have a blob of data
66  * with callbacks to convert it into the various data types that you
67  * advertise. When the @clear_func you provided is called, you
68  * simply free the data blob. The latter is more useful when the
69  * contents of clipboard reflect the internal state of a #GObject
70  * (As an example, for the PRIMARY clipboard, when an entry widget
71  * provides the clipboard’s contents the contents are simply the
72  * text within the selected region.) If the contents change, the
73  * entry widget can call gtk_clipboard_set_with_owner() to update
74  * the timestamp for clipboard ownership, without having to worry
75  * about @clear_func being called.
76  * 
77  * Requesting the data from the clipboard is essentially
78  * asynchronous. If the contents of the clipboard are provided within
79  * the same process, then a direct function call will be made to
80  * retrieve the data, but if they are provided by another process,
81  * then the data needs to be retrieved from the other process, which
82  * may take some time. To avoid blocking the user interface, the call
83  * to request the selection, gtk_clipboard_request_contents() takes a
84  * callback that will be called when the contents are received (or
85  * when the request fails.) If you don’t want to deal with providing
86  * a separate callback, you can also use gtk_clipboard_wait_for_contents().
87  * What this does is run the GLib main loop recursively waiting for
88  * the contents. This can simplify the code flow, but you still have
89  * to be aware that other callbacks in your program can be called
90  * while this recursive mainloop is running.
91  * 
92  * Along with the functions to get the clipboard contents as an
93  * arbitrary data chunk, there are also functions to retrieve
94  * it as text, gtk_clipboard_request_text() and
95  * gtk_clipboard_wait_for_text(). These functions take care of
96  * determining which formats are advertised by the clipboard
97  * provider, asking for the clipboard in the best available format
98  * and converting the results into the UTF-8 encoding. (The standard
99  * form for representing strings in GTK+.)
100  */
101 public class Clipboard : ObjectG
102 {
103 	/** the main Gtk struct */
104 	protected GtkClipboard* gtkClipboard;
105 
106 	/** Get the main Gtk struct */
107 	public GtkClipboard* getClipboardStruct(bool transferOwnership = false)
108 	{
109 		if (transferOwnership)
110 			ownedRef = false;
111 		return gtkClipboard;
112 	}
113 
114 	/** the main Gtk struct as a void* */
115 	protected override void* getStruct()
116 	{
117 		return cast(void*)gtkClipboard;
118 	}
119 
120 	protected override void setStruct(GObject* obj)
121 	{
122 		gtkClipboard = cast(GtkClipboard*)obj;
123 		super.setStruct(obj);
124 	}
125 
126 	/**
127 	 * Sets our main struct and passes it to the parent class.
128 	 */
129 	public this (GtkClipboard* gtkClipboard, bool ownedRef = false)
130 	{
131 		this.gtkClipboard = gtkClipboard;
132 		super(cast(GObject*)gtkClipboard, ownedRef);
133 	}
134 
135 
136 	/** */
137 	public static GType getType()
138 	{
139 		return gtk_clipboard_get_type();
140 	}
141 
142 	/**
143 	 * Returns the clipboard object for the given selection.
144 	 * See gtk_clipboard_get_for_display() for complete details.
145 	 *
146 	 * Params:
147 	 *     selection = a #GdkAtom which identifies the clipboard to use
148 	 *
149 	 * Returns: the appropriate clipboard object. If no clipboard
150 	 *     already exists, a new one will be created. Once a clipboard
151 	 *     object has been created, it is persistent and, since it is
152 	 *     owned by GTK+, must not be freed or unreffed.
153 	 */
154 	public static Clipboard get(GdkAtom selection)
155 	{
156 		auto p = gtk_clipboard_get(selection);
157 
158 		if(p is null)
159 		{
160 			return null;
161 		}
162 
163 		return ObjectG.getDObject!(Clipboard)(cast(GtkClipboard*) p);
164 	}
165 
166 	/**
167 	 * Returns the default clipboard object for use with cut/copy/paste menu items
168 	 * and keyboard shortcuts.
169 	 *
170 	 * Params:
171 	 *     display = the #GdkDisplay for which the clipboard is to be retrieved.
172 	 *
173 	 * Returns: the default clipboard object.
174 	 *
175 	 * Since: 3.16
176 	 */
177 	public static Clipboard getDefault(Display display)
178 	{
179 		auto p = gtk_clipboard_get_default((display is null) ? null : display.getDisplayStruct());
180 
181 		if(p is null)
182 		{
183 			return null;
184 		}
185 
186 		return ObjectG.getDObject!(Clipboard)(cast(GtkClipboard*) p);
187 	}
188 
189 	/**
190 	 * Returns the clipboard object for the given selection.
191 	 * Cut/copy/paste menu items and keyboard shortcuts should use
192 	 * the default clipboard, returned by passing %GDK_SELECTION_CLIPBOARD for @selection.
193 	 * (%GDK_NONE is supported as a synonym for GDK_SELECTION_CLIPBOARD
194 	 * for backwards compatibility reasons.)
195 	 * The currently-selected object or text should be provided on the clipboard
196 	 * identified by #GDK_SELECTION_PRIMARY. Cut/copy/paste menu items
197 	 * conceptually copy the contents of the #GDK_SELECTION_PRIMARY clipboard
198 	 * to the default clipboard, i.e. they copy the selection to what the
199 	 * user sees as the clipboard.
200 	 *
201 	 * (Passing #GDK_NONE is the same as using `gdk_atom_intern
202 	 * ("CLIPBOARD", FALSE)`.
203 	 *
204 	 * See the
205 	 * [FreeDesktop Clipboard Specification](http://www.freedesktop.org/Standards/clipboards-spec)
206 	 * for a detailed discussion of the “CLIPBOARD” vs. “PRIMARY”
207 	 * selections under the X window system. On Win32 the
208 	 * #GDK_SELECTION_PRIMARY clipboard is essentially ignored.)
209 	 *
210 	 * It’s possible to have arbitrary named clipboards; if you do invent
211 	 * new clipboards, you should prefix the selection name with an
212 	 * underscore (because the ICCCM requires that nonstandard atoms are
213 	 * underscore-prefixed), and namespace it as well. For example,
214 	 * if your application called “Foo” has a special-purpose
215 	 * clipboard, you might call it “_FOO_SPECIAL_CLIPBOARD”.
216 	 *
217 	 * Params:
218 	 *     display = the #GdkDisplay for which the clipboard is to be retrieved or created.
219 	 *     selection = a #GdkAtom which identifies the clipboard to use.
220 	 *
221 	 * Returns: the appropriate clipboard object. If no
222 	 *     clipboard already exists, a new one will be created. Once a clipboard
223 	 *     object has been created, it is persistent and, since it is owned by
224 	 *     GTK+, must not be freed or unrefd.
225 	 *
226 	 * Since: 2.2
227 	 */
228 	public static Clipboard getForDisplay(Display display, GdkAtom selection)
229 	{
230 		auto p = gtk_clipboard_get_for_display((display is null) ? null : display.getDisplayStruct(), selection);
231 
232 		if(p is null)
233 		{
234 			return null;
235 		}
236 
237 		return ObjectG.getDObject!(Clipboard)(cast(GtkClipboard*) p);
238 	}
239 
240 	/**
241 	 * Clears the contents of the clipboard. Generally this should only
242 	 * be called between the time you call gtk_clipboard_set_with_owner()
243 	 * or gtk_clipboard_set_with_data(),
244 	 * and when the @clear_func you supplied is called. Otherwise, the
245 	 * clipboard may be owned by someone else.
246 	 */
247 	public void clear()
248 	{
249 		gtk_clipboard_clear(gtkClipboard);
250 	}
251 
252 	/**
253 	 * Gets the #GdkDisplay associated with @clipboard
254 	 *
255 	 * Returns: the #GdkDisplay associated with @clipboard
256 	 *
257 	 * Since: 2.2
258 	 */
259 	public Display getDisplay()
260 	{
261 		auto p = gtk_clipboard_get_display(gtkClipboard);
262 
263 		if(p is null)
264 		{
265 			return null;
266 		}
267 
268 		return ObjectG.getDObject!(Display)(cast(GdkDisplay*) p);
269 	}
270 
271 	/**
272 	 * If the clipboard contents callbacks were set with
273 	 * gtk_clipboard_set_with_owner(), and the gtk_clipboard_set_with_data() or
274 	 * gtk_clipboard_clear() has not subsequently called, returns the owner set
275 	 * by gtk_clipboard_set_with_owner().
276 	 *
277 	 * Returns: the owner of the clipboard, if any;
278 	 *     otherwise %NULL.
279 	 */
280 	public ObjectG getOwner()
281 	{
282 		auto p = gtk_clipboard_get_owner(gtkClipboard);
283 
284 		if(p is null)
285 		{
286 			return null;
287 		}
288 
289 		return ObjectG.getDObject!(ObjectG)(cast(GObject*) p);
290 	}
291 
292 	/**
293 	 * Gets the selection that this clipboard is for.
294 	 *
295 	 * Returns: the selection
296 	 *
297 	 * Since: 3.22
298 	 */
299 	public GdkAtom getSelection()
300 	{
301 		return gtk_clipboard_get_selection(gtkClipboard);
302 	}
303 
304 	/**
305 	 * Requests the contents of clipboard as the given target.
306 	 * When the results of the result are later received the supplied callback
307 	 * will be called.
308 	 *
309 	 * Params:
310 	 *     target = an atom representing the form into which the clipboard
311 	 *         owner should convert the selection.
312 	 *     callback = A function to call when the results are received
313 	 *         (or the retrieval fails). If the retrieval fails the length field of
314 	 *         @selection_data will be negative.
315 	 *     userData = user data to pass to @callback
316 	 */
317 	public void requestContents(GdkAtom target, GtkClipboardReceivedFunc callback, void* userData)
318 	{
319 		gtk_clipboard_request_contents(gtkClipboard, target, callback, userData);
320 	}
321 
322 	/**
323 	 * Requests the contents of the clipboard as image. When the image is
324 	 * later received, it will be converted to a #GdkPixbuf, and
325 	 * @callback will be called.
326 	 *
327 	 * The @pixbuf parameter to @callback will contain the resulting
328 	 * #GdkPixbuf if the request succeeded, or %NULL if it failed. This
329 	 * could happen for various reasons, in particular if the clipboard
330 	 * was empty or if the contents of the clipboard could not be
331 	 * converted into an image.
332 	 *
333 	 * Params:
334 	 *     callback = a function to call when the image is received,
335 	 *         or the retrieval fails. (It will always be called one way or the other.)
336 	 *     userData = user data to pass to @callback.
337 	 *
338 	 * Since: 2.6
339 	 */
340 	public void requestImage(GtkClipboardImageReceivedFunc callback, void* userData)
341 	{
342 		gtk_clipboard_request_image(gtkClipboard, callback, userData);
343 	}
344 
345 	/**
346 	 * Requests the contents of the clipboard as rich text. When the rich
347 	 * text is later received, @callback will be called.
348 	 *
349 	 * The @text parameter to @callback will contain the resulting rich
350 	 * text if the request succeeded, or %NULL if it failed. The @length
351 	 * parameter will contain @text’s length. This function can fail for
352 	 * various reasons, in particular if the clipboard was empty or if the
353 	 * contents of the clipboard could not be converted into rich text form.
354 	 *
355 	 * Params:
356 	 *     buffer = a #GtkTextBuffer
357 	 *     callback = a function to call when the text is received,
358 	 *         or the retrieval fails. (It will always be called one way or the other.)
359 	 *     userData = user data to pass to @callback.
360 	 *
361 	 * Since: 2.10
362 	 */
363 	public void requestRichText(TextBuffer buffer, GtkClipboardRichTextReceivedFunc callback, void* userData)
364 	{
365 		gtk_clipboard_request_rich_text(gtkClipboard, (buffer is null) ? null : buffer.getTextBufferStruct(), callback, userData);
366 	}
367 
368 	/**
369 	 * Requests the contents of the clipboard as list of supported targets.
370 	 * When the list is later received, @callback will be called.
371 	 *
372 	 * The @targets parameter to @callback will contain the resulting targets if
373 	 * the request succeeded, or %NULL if it failed.
374 	 *
375 	 * Params:
376 	 *     callback = a function to call when the targets are
377 	 *         received, or the retrieval fails. (It will always be called
378 	 *         one way or the other.)
379 	 *     userData = user data to pass to @callback.
380 	 *
381 	 * Since: 2.4
382 	 */
383 	public void requestTargets(GtkClipboardTargetsReceivedFunc callback, void* userData)
384 	{
385 		gtk_clipboard_request_targets(gtkClipboard, callback, userData);
386 	}
387 
388 	/**
389 	 * Requests the contents of the clipboard as text. When the text is
390 	 * later received, it will be converted to UTF-8 if necessary, and
391 	 * @callback will be called.
392 	 *
393 	 * The @text parameter to @callback will contain the resulting text if
394 	 * the request succeeded, or %NULL if it failed. This could happen for
395 	 * various reasons, in particular if the clipboard was empty or if the
396 	 * contents of the clipboard could not be converted into text form.
397 	 *
398 	 * Params:
399 	 *     callback = a function to call when the text is received,
400 	 *         or the retrieval fails. (It will always be called one way or the other.)
401 	 *     userData = user data to pass to @callback.
402 	 */
403 	public void requestText(GtkClipboardTextReceivedFunc callback, void* userData)
404 	{
405 		gtk_clipboard_request_text(gtkClipboard, callback, userData);
406 	}
407 
408 	/**
409 	 * Requests the contents of the clipboard as URIs. When the URIs are
410 	 * later received @callback will be called.
411 	 *
412 	 * The @uris parameter to @callback will contain the resulting array of
413 	 * URIs if the request succeeded, or %NULL if it failed. This could happen
414 	 * for various reasons, in particular if the clipboard was empty or if the
415 	 * contents of the clipboard could not be converted into URI form.
416 	 *
417 	 * Params:
418 	 *     callback = a function to call when the URIs are received,
419 	 *         or the retrieval fails. (It will always be called one way or the other.)
420 	 *     userData = user data to pass to @callback.
421 	 *
422 	 * Since: 2.14
423 	 */
424 	public void requestUris(GtkClipboardURIReceivedFunc callback, void* userData)
425 	{
426 		gtk_clipboard_request_uris(gtkClipboard, callback, userData);
427 	}
428 
429 	/**
430 	 * Hints that the clipboard data should be stored somewhere when the
431 	 * application exits or when gtk_clipboard_store () is called.
432 	 *
433 	 * This value is reset when the clipboard owner changes.
434 	 * Where the clipboard data is stored is platform dependent,
435 	 * see gdk_display_store_clipboard () for more information.
436 	 *
437 	 * Params:
438 	 *     targets = array containing
439 	 *         information about which forms should be stored or %NULL
440 	 *         to indicate that all forms should be stored.
441 	 *
442 	 * Since: 2.6
443 	 */
444 	public void setCanStore(TargetEntry[] targets)
445 	{
446 		GtkTargetEntry[] targetsArray = new GtkTargetEntry[targets.length];
447 		for ( int i = 0; i < targets.length; i++ )
448 		{
449 			targetsArray[i] = *(targets[i].getTargetEntryStruct());
450 		}
451 
452 		gtk_clipboard_set_can_store(gtkClipboard, targetsArray.ptr, cast(int)targets.length);
453 	}
454 
455 	/**
456 	 * Sets the contents of the clipboard to the given #GdkPixbuf.
457 	 * GTK+ will take responsibility for responding for requests
458 	 * for the image, and for converting the image into the
459 	 * requested format.
460 	 *
461 	 * Params:
462 	 *     pixbuf = a #GdkPixbuf
463 	 *
464 	 * Since: 2.6
465 	 */
466 	public void setImage(Pixbuf pixbuf)
467 	{
468 		gtk_clipboard_set_image(gtkClipboard, (pixbuf is null) ? null : pixbuf.getPixbufStruct());
469 	}
470 
471 	/**
472 	 * Sets the contents of the clipboard to the given UTF-8 string. GTK+ will
473 	 * make a copy of the text and take responsibility for responding
474 	 * for requests for the text, and for converting the text into
475 	 * the requested format.
476 	 *
477 	 * Params:
478 	 *     text = a UTF-8 string.
479 	 *     len = length of @text, in bytes, or -1, in which case
480 	 *         the length will be determined with strlen().
481 	 */
482 	public void setText(string text, int len)
483 	{
484 		gtk_clipboard_set_text(gtkClipboard, Str.toStringz(text), len);
485 	}
486 
487 	/**
488 	 * Virtually sets the contents of the specified clipboard by providing
489 	 * a list of supported formats for the clipboard data and a function
490 	 * to call to get the actual data when it is requested.
491 	 *
492 	 * Params:
493 	 *     targets = array containing information
494 	 *         about the available forms for the clipboard data
495 	 *     getFunc = function to call to get the actual clipboard data
496 	 *     clearFunc = when the clipboard contents are set again,
497 	 *         this function will be called, and @get_func will not be subsequently
498 	 *         called.
499 	 *     userData = user data to pass to @get_func and @clear_func.
500 	 *
501 	 * Returns: %TRUE if setting the clipboard data succeeded.
502 	 *     If setting the clipboard data failed the provided callback
503 	 *     functions will be ignored.
504 	 */
505 	public bool setWithData(TargetEntry[] targets, GtkClipboardGetFunc getFunc, GtkClipboardClearFunc clearFunc, void* userData)
506 	{
507 		GtkTargetEntry[] targetsArray = new GtkTargetEntry[targets.length];
508 		for ( int i = 0; i < targets.length; i++ )
509 		{
510 			targetsArray[i] = *(targets[i].getTargetEntryStruct());
511 		}
512 
513 		return gtk_clipboard_set_with_data(gtkClipboard, targetsArray.ptr, cast(uint)targets.length, getFunc, clearFunc, userData) != 0;
514 	}
515 
516 	/**
517 	 * Virtually sets the contents of the specified clipboard by providing
518 	 * a list of supported formats for the clipboard data and a function
519 	 * to call to get the actual data when it is requested.
520 	 *
521 	 * The difference between this function and gtk_clipboard_set_with_data()
522 	 * is that instead of an generic @user_data pointer, a #GObject is passed
523 	 * in.
524 	 *
525 	 * Params:
526 	 *     targets = array containing information
527 	 *         about the available forms for the clipboard data
528 	 *     getFunc = function to call to get the actual clipboard data
529 	 *     clearFunc = when the clipboard contents are set again,
530 	 *         this function will be called, and @get_func will not be subsequently
531 	 *         called
532 	 *     owner = an object that “owns” the data. This object will be passed
533 	 *         to the callbacks when called
534 	 *
535 	 * Returns: %TRUE if setting the clipboard data succeeded.
536 	 *     If setting the clipboard data failed the provided callback
537 	 *     functions will be ignored.
538 	 */
539 	public bool setWithOwner(TargetEntry[] targets, GtkClipboardGetFunc getFunc, GtkClipboardClearFunc clearFunc, ObjectG owner)
540 	{
541 		GtkTargetEntry[] targetsArray = new GtkTargetEntry[targets.length];
542 		for ( int i = 0; i < targets.length; i++ )
543 		{
544 			targetsArray[i] = *(targets[i].getTargetEntryStruct());
545 		}
546 
547 		return gtk_clipboard_set_with_owner(gtkClipboard, targetsArray.ptr, cast(uint)targets.length, getFunc, clearFunc, (owner is null) ? null : owner.getObjectGStruct()) != 0;
548 	}
549 
550 	/**
551 	 * Stores the current clipboard data somewhere so that it will stay
552 	 * around after the application has quit.
553 	 *
554 	 * Since: 2.6
555 	 */
556 	public void store()
557 	{
558 		gtk_clipboard_store(gtkClipboard);
559 	}
560 
561 	/**
562 	 * Requests the contents of the clipboard using the given target.
563 	 * This function waits for the data to be received using the main
564 	 * loop, so events, timeouts, etc, may be dispatched during the wait.
565 	 *
566 	 * Params:
567 	 *     target = an atom representing the form into which the clipboard
568 	 *         owner should convert the selection.
569 	 *
570 	 * Returns: a newly-allocated #GtkSelectionData object or %NULL
571 	 *     if retrieving the given target failed. If non-%NULL,
572 	 *     this value must be freed with gtk_selection_data_free()
573 	 *     when you are finished with it.
574 	 */
575 	public SelectionData waitForContents(GdkAtom target)
576 	{
577 		auto p = gtk_clipboard_wait_for_contents(gtkClipboard, target);
578 
579 		if(p is null)
580 		{
581 			return null;
582 		}
583 
584 		return ObjectG.getDObject!(SelectionData)(cast(GtkSelectionData*) p, true);
585 	}
586 
587 	/**
588 	 * Requests the contents of the clipboard as image and converts
589 	 * the result to a #GdkPixbuf. This function waits for
590 	 * the data to be received using the main loop, so events,
591 	 * timeouts, etc, may be dispatched during the wait.
592 	 *
593 	 * Returns: a newly-allocated #GdkPixbuf
594 	 *     object which must be disposed with g_object_unref(), or
595 	 *     %NULL if retrieving the selection data failed. (This could
596 	 *     happen for various reasons, in particular if the clipboard
597 	 *     was empty or if the contents of the clipboard could not be
598 	 *     converted into an image.)
599 	 *
600 	 * Since: 2.6
601 	 */
602 	public Pixbuf waitForImage()
603 	{
604 		auto p = gtk_clipboard_wait_for_image(gtkClipboard);
605 
606 		if(p is null)
607 		{
608 			return null;
609 		}
610 
611 		return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p, true);
612 	}
613 
614 	/**
615 	 * Requests the contents of the clipboard as rich text.  This function
616 	 * waits for the data to be received using the main loop, so events,
617 	 * timeouts, etc, may be dispatched during the wait.
618 	 *
619 	 * Params:
620 	 *     buffer = a #GtkTextBuffer
621 	 *     format = return location for the format of the returned data
622 	 *
623 	 * Returns: a
624 	 *     newly-allocated binary block of data which must be
625 	 *     freed with g_free(), or %NULL if retrieving the
626 	 *     selection data failed. (This could happen for various
627 	 *     reasons, in particular if the clipboard was empty or
628 	 *     if the contents of the clipboard could not be
629 	 *     converted into text form.)
630 	 *
631 	 * Since: 2.10
632 	 */
633 	public ubyte[] waitForRichText(TextBuffer buffer, out GdkAtom format)
634 	{
635 		size_t length;
636 
637 		auto p = gtk_clipboard_wait_for_rich_text(gtkClipboard, (buffer is null) ? null : buffer.getTextBufferStruct(), &format, &length);
638 
639 		return p[0 .. length];
640 	}
641 
642 	/**
643 	 * Returns a list of targets that are present on the clipboard, or %NULL
644 	 * if there aren’t any targets available. The returned list must be
645 	 * freed with g_free().
646 	 * This function waits for the data to be received using the main
647 	 * loop, so events, timeouts, etc, may be dispatched during the wait.
648 	 *
649 	 * Params:
650 	 *     targets = location
651 	 *         to store an array of targets. The result stored here must
652 	 *         be freed with g_free().
653 	 *
654 	 * Returns: %TRUE if any targets are present on the clipboard,
655 	 *     otherwise %FALSE.
656 	 *
657 	 * Since: 2.4
658 	 */
659 	public bool waitForTargets(out GdkAtom[] targets)
660 	{
661 		GdkAtom* outtargets = null;
662 		int nTargets;
663 
664 		auto p = gtk_clipboard_wait_for_targets(gtkClipboard, &outtargets, &nTargets) != 0;
665 
666 		targets = outtargets[0 .. nTargets];
667 
668 		return p;
669 	}
670 
671 	/**
672 	 * Requests the contents of the clipboard as text and converts
673 	 * the result to UTF-8 if necessary. This function waits for
674 	 * the data to be received using the main loop, so events,
675 	 * timeouts, etc, may be dispatched during the wait.
676 	 *
677 	 * Returns: a newly-allocated UTF-8 string which must
678 	 *     be freed with g_free(), or %NULL if retrieving
679 	 *     the selection data failed. (This could happen
680 	 *     for various reasons, in particular if the
681 	 *     clipboard was empty or if the contents of the
682 	 *     clipboard could not be converted into text form.)
683 	 */
684 	public string waitForText()
685 	{
686 		auto retStr = gtk_clipboard_wait_for_text(gtkClipboard);
687 
688 		scope(exit) Str.freeString(retStr);
689 		return Str.toString(retStr);
690 	}
691 
692 	/**
693 	 * Requests the contents of the clipboard as URIs. This function waits
694 	 * for the data to be received using the main loop, so events,
695 	 * timeouts, etc, may be dispatched during the wait.
696 	 *
697 	 * Returns: a newly-allocated %NULL-terminated array of strings which must
698 	 *     be freed with g_strfreev(), or %NULL if retrieving the
699 	 *     selection data failed. (This could happen for various reasons,
700 	 *     in particular if the clipboard was empty or if the contents of
701 	 *     the clipboard could not be converted into URI form.)
702 	 *
703 	 * Since: 2.14
704 	 */
705 	public string[] waitForUris()
706 	{
707 		auto retStr = gtk_clipboard_wait_for_uris(gtkClipboard);
708 
709 		scope(exit) Str.freeStringArray(retStr);
710 		return Str.toStringArray(retStr);
711 	}
712 
713 	/**
714 	 * Test to see if there is an image available to be pasted
715 	 * This is done by requesting the TARGETS atom and checking
716 	 * if it contains any of the supported image targets. This function
717 	 * waits for the data to be received using the main loop, so events,
718 	 * timeouts, etc, may be dispatched during the wait.
719 	 *
720 	 * This function is a little faster than calling
721 	 * gtk_clipboard_wait_for_image() since it doesn’t need to retrieve
722 	 * the actual image data.
723 	 *
724 	 * Returns: %TRUE is there is an image available, %FALSE otherwise.
725 	 *
726 	 * Since: 2.6
727 	 */
728 	public bool waitIsImageAvailable()
729 	{
730 		return gtk_clipboard_wait_is_image_available(gtkClipboard) != 0;
731 	}
732 
733 	/**
734 	 * Test to see if there is rich text available to be pasted
735 	 * This is done by requesting the TARGETS atom and checking
736 	 * if it contains any of the supported rich text targets. This function
737 	 * waits for the data to be received using the main loop, so events,
738 	 * timeouts, etc, may be dispatched during the wait.
739 	 *
740 	 * This function is a little faster than calling
741 	 * gtk_clipboard_wait_for_rich_text() since it doesn’t need to retrieve
742 	 * the actual text.
743 	 *
744 	 * Params:
745 	 *     buffer = a #GtkTextBuffer
746 	 *
747 	 * Returns: %TRUE is there is rich text available, %FALSE otherwise.
748 	 *
749 	 * Since: 2.10
750 	 */
751 	public bool waitIsRichTextAvailable(TextBuffer buffer)
752 	{
753 		return gtk_clipboard_wait_is_rich_text_available(gtkClipboard, (buffer is null) ? null : buffer.getTextBufferStruct()) != 0;
754 	}
755 
756 	/**
757 	 * Checks if a clipboard supports pasting data of a given type. This
758 	 * function can be used to determine if a “Paste” menu item should be
759 	 * insensitive or not.
760 	 *
761 	 * If you want to see if there’s text available on the clipboard, use
762 	 * gtk_clipboard_wait_is_text_available () instead.
763 	 *
764 	 * Params:
765 	 *     target = A #GdkAtom indicating which target to look for.
766 	 *
767 	 * Returns: %TRUE if the target is available, %FALSE otherwise.
768 	 *
769 	 * Since: 2.6
770 	 */
771 	public bool waitIsTargetAvailable(GdkAtom target)
772 	{
773 		return gtk_clipboard_wait_is_target_available(gtkClipboard, target) != 0;
774 	}
775 
776 	/**
777 	 * Test to see if there is text available to be pasted
778 	 * This is done by requesting the TARGETS atom and checking
779 	 * if it contains any of the supported text targets. This function
780 	 * waits for the data to be received using the main loop, so events,
781 	 * timeouts, etc, may be dispatched during the wait.
782 	 *
783 	 * This function is a little faster than calling
784 	 * gtk_clipboard_wait_for_text() since it doesn’t need to retrieve
785 	 * the actual text.
786 	 *
787 	 * Returns: %TRUE is there is text available, %FALSE otherwise.
788 	 */
789 	public bool waitIsTextAvailable()
790 	{
791 		return gtk_clipboard_wait_is_text_available(gtkClipboard) != 0;
792 	}
793 
794 	/**
795 	 * Test to see if there is a list of URIs available to be pasted
796 	 * This is done by requesting the TARGETS atom and checking
797 	 * if it contains the URI targets. This function
798 	 * waits for the data to be received using the main loop, so events,
799 	 * timeouts, etc, may be dispatched during the wait.
800 	 *
801 	 * This function is a little faster than calling
802 	 * gtk_clipboard_wait_for_uris() since it doesn’t need to retrieve
803 	 * the actual URI data.
804 	 *
805 	 * Returns: %TRUE is there is an URI list available, %FALSE otherwise.
806 	 *
807 	 * Since: 2.14
808 	 */
809 	public bool waitIsUrisAvailable()
810 	{
811 		return gtk_clipboard_wait_is_uris_available(gtkClipboard) != 0;
812 	}
813 
814 	protected class OnOwnerChangeDelegateWrapper
815 	{
816 		void delegate(GdkEventOwnerChange*, Clipboard) dlg;
817 		gulong handlerId;
818 
819 		this(void delegate(GdkEventOwnerChange*, Clipboard) dlg)
820 		{
821 			this.dlg = dlg;
822 			onOwnerChangeListeners ~= this;
823 		}
824 
825 		void remove(OnOwnerChangeDelegateWrapper source)
826 		{
827 			foreach(index, wrapper; onOwnerChangeListeners)
828 			{
829 				if (wrapper.handlerId == source.handlerId)
830 				{
831 					onOwnerChangeListeners[index] = null;
832 					onOwnerChangeListeners = std.algorithm.remove(onOwnerChangeListeners, index);
833 					break;
834 				}
835 			}
836 		}
837 	}
838 	OnOwnerChangeDelegateWrapper[] onOwnerChangeListeners;
839 
840 	/**
841 	 * The ::owner-change signal is emitted when GTK+ receives an
842 	 * event that indicates that the ownership of the selection
843 	 * associated with @clipboard has changed.
844 	 *
845 	 * Params:
846 	 *     event = the @GdkEventOwnerChange event
847 	 *
848 	 * Since: 2.6
849 	 */
850 	gulong addOnOwnerChange(void delegate(GdkEventOwnerChange*, Clipboard) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
851 	{
852 		auto wrapper = new OnOwnerChangeDelegateWrapper(dlg);
853 		wrapper.handlerId = Signals.connectData(
854 			this,
855 			"owner-change",
856 			cast(GCallback)&callBackOwnerChange,
857 			cast(void*)wrapper,
858 			cast(GClosureNotify)&callBackOwnerChangeDestroy,
859 			connectFlags);
860 		return wrapper.handlerId;
861 	}
862 
863 	extern(C) static void callBackOwnerChange(GtkClipboard* clipboardStruct, GdkEventOwnerChange* event, OnOwnerChangeDelegateWrapper wrapper)
864 	{
865 		wrapper.dlg(event, wrapper.outer);
866 	}
867 
868 	extern(C) static void callBackOwnerChangeDestroy(OnOwnerChangeDelegateWrapper wrapper, GClosure* closure)
869 	{
870 		wrapper.remove(wrapper);
871 	}
872 
873 	protected class OnOwnerChangeGenericDelegateWrapper
874 	{
875 		void delegate(Event, Clipboard) dlg;
876 		gulong handlerId;
877 
878 		this(void delegate(Event, Clipboard) dlg)
879 		{
880 			this.dlg = dlg;
881 			onOwnerChangeGenericListeners ~= this;
882 		}
883 
884 		void remove(OnOwnerChangeGenericDelegateWrapper source)
885 		{
886 			foreach(index, wrapper; onOwnerChangeGenericListeners)
887 			{
888 				if (wrapper.handlerId == source.handlerId)
889 				{
890 					onOwnerChangeGenericListeners[index] = null;
891 					onOwnerChangeGenericListeners = std.algorithm.remove(onOwnerChangeGenericListeners, index);
892 					break;
893 				}
894 			}
895 		}
896 	}
897 	OnOwnerChangeGenericDelegateWrapper[] onOwnerChangeGenericListeners;
898 
899 	/**
900 	 * The ::owner-change signal is emitted when GTK+ receives an
901 	 * event that indicates that the ownership of the selection
902 	 * associated with @clipboard has changed.
903 	 *
904 	 * Params:
905 	 *     event = the @GdkEventOwnerChange event
906 	 *
907 	 * Since: 2.6
908 	 */
909 	gulong addOnOwnerChange(void delegate(Event, Clipboard) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
910 	{
911 		auto wrapper = new OnOwnerChangeGenericDelegateWrapper(dlg);
912 		wrapper.handlerId = Signals.connectData(
913 			this,
914 			"owner-change",
915 			cast(GCallback)&callBackOwnerChangeGeneric,
916 			cast(void*)wrapper,
917 			cast(GClosureNotify)&callBackOwnerChangeGenericDestroy,
918 			connectFlags);
919 		return wrapper.handlerId;
920 	}
921 
922 	extern(C) static void callBackOwnerChangeGeneric(GtkClipboard* clipboardStruct, GdkEvent* event, OnOwnerChangeGenericDelegateWrapper wrapper)
923 	{
924 		wrapper.dlg(ObjectG.getDObject!(Event)(event), wrapper.outer);
925 	}
926 
927 	extern(C) static void callBackOwnerChangeGenericDestroy(OnOwnerChangeGenericDelegateWrapper wrapper, GClosure* closure)
928 	{
929 		wrapper.remove(wrapper);
930 	}
931 }