2 * This file is part of duit.
4 * duit is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * duit is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with duit; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = gtk-Clipboards.html
28 * strct = GtkClipboard
51 * - GObject* -> ObjectG
52 * - GdkDisplay* -> Display
53 * - GdkPixbuf* -> Pixbuf
54 * - GtkClipboard* -> Clipboard
60 private import gtk
.gtktypes
;
62 private import lib
.gtk
;
64 private import glib
.Str
;
65 private import gtk
.Clipboard
;
66 private import gdk
.Display
;
67 private import gobject
.ObjectG
;
68 private import gdk
.Pixbuf
;
72 * The GtkClipboard object represents a clipboard of data shared
73 * between different processes or between different widgets in
74 * the same process. Each clipboard is identified by a name encoded as a
75 * GdkAtom. (Conversion to and from strings can be done with
76 * gdk_atom_intern() and gdk_atom_name().) The default clipboard
77 * corresponds to the "CLIPBOARD" atom; another commonly used clipboard
78 * is the "PRIMARY" clipboard, which, in X, traditionally contains
79 * the currently selected text.
80 * To support having a number of different formats on the clipboard
81 * at the same time, the clipboard mechanism allows providing
82 * callbacks instead of the actual data. When you set the contents
83 * of the clipboard, you can either supply the data directly (via
84 * functions like gtk_clipboard_set_text()), or you can supply a
85 * callback to be called at a later time when the data is needed (via
86 * gtk_clipboard_set_with_data() or gtk_clipboard_set_with_owner().)
87 * Providing a callback also avoids having to make copies of the data
88 * when it is not needed.
89 * gtk_clipboard_set_with_data() and gtk_clipboard_set_with_owner()
90 * are quite similar; the choice between the two depends mostly on
91 * which is more convenient in a particular situation.
92 * The former is most useful when you want to have a blob of data
93 * with callbacks to convert it into the various data types that you
94 * advertise. When the clear_func you provided is called, you
95 * simply free the data blob. The latter is more useful when the
96 * contents of clipboard reflect the internal state of a GObject
97 * (As an example, for the PRIMARY clipboard, when an entry widget
98 * provides the clipboard's contents the contents are simply the
99 * text within the selected region.) If the contents change, the
100 * entry widget can call gtk_clipboard_set_with_owner() to update
101 * the timestamp for clipboard ownership, without having to worry
102 * about clear_func being called.
103 * Requesting the data from the clipboard is essentially
104 * asynchronous. If the contents of the clipboard are provided within
105 * the same process, then a direct function call will be made to
106 * retrieve the data, but if they are provided by another process,
107 * then the data needs to be retrieved from the other process, which
108 * may take some time. To avoid blocking the user interface, the call
109 * to request the selection, gtk_clipboard_request_contents() takes a
110 * callback that will be called when the contents are received (or
111 * when the request fails.) If you don't want to deal with providing
112 * a separate callback, you can also use gtk_clipboard_wait_for_contents().
113 * What this does is run the GLib main loop recursively waiting for
114 * the contents. This can simplify the code flow, but you still have
115 * to be aware that other callbacks in your program can be called
116 * while this recursive mainloop is running.
117 * Along with the functions to get the clipboard contents as an
118 * arbitrary data chunk, there are also functions to retrieve
119 * it as text, gtk_clipboard_request_text() and
120 * gtk_clipboard_wait_for_text(). These functions take care of
121 * determining which formats are advertised by the clipboard
122 * provider, asking for the clipboard in the best available format
123 * and converting the results into the UTF-8 encoding. (The standard
124 * form for representing strings in GTK+.)
126 private import gobject
.ObjectG
;
127 public class Clipboard
: ObjectG
130 /** the main Gtk struct */
131 protected GtkClipboard
* gtkClipboard
;
134 public GtkClipboard
* getClipboardStruct()
140 /** the main Gtk struct as a void* */
141 protected void* getStruct()
143 return cast(void*)gtkClipboard
;
147 * Sets our main struct and passes it to the parent class
149 public this (GtkClipboard
* gtkClipboard
)
151 super(cast(GObject
*)gtkClipboard
);
152 this.gtkClipboard
= gtkClipboard
;
158 // imports for the signal processing
159 private import gobject
.Signals
;
160 private import gdk
.gdktypes
;
161 int[char[]] connectedSignals
;
163 void delegate(GdkEvent
*, Clipboard
)[] onOwnerChangeListeners
;
164 void addOnOwnerChange(void delegate(GdkEvent
*, Clipboard
) dlg
)
166 if ( !("owner-change" in connectedSignals
) )
171 cast(GCallback
)&callBackOwnerChange
,
174 cast(ConnectFlags
)0);
175 connectedSignals
["owner-change"] = 1;
177 onOwnerChangeListeners
~= dlg
;
179 extern(C
) static void callBackOwnerChange(GtkClipboard
* clipboardStruct
, GdkEvent
* event
, Clipboard clipboard
)
181 bit consumed
= false;
183 foreach ( void delegate(GdkEvent
*, Clipboard
) dlg
; clipboard
.onOwnerChangeListeners
)
185 dlg(event
, clipboard
);
201 * Returns the clipboard object for the given selection.
202 * See gtk_clipboard_get_for_display() for complete details.
204 * a GdkAtom which identifies the clipboard
207 * the appropriate clipboard object. If no
208 * clipboard already exists, a new one will
209 * be created. Once a clipboard object has
210 * been created, it is persistent and, since
211 * it is owned by GTK+, must not be freed or
214 public static Clipboard
get(GdkAtom selection
)
216 // GtkClipboard* gtk_clipboard_get (GdkAtom selection);
217 return new Clipboard( gtk_clipboard_get(selection
) );
221 * Returns the clipboard object for the given selection.
222 * Cut/copy/paste menu items and keyboard shortcuts should use
223 * the default clipboard, returned by passing GDK_SELECTION_CLIPBOARD for selection.
224 * (GDK_NONE is supported as a synonym for GDK_SELECTION_CLIPBOARD
225 * for backwards compatibility reasons.)
226 * The currently-selected object or text should be provided on the clipboard
227 * identified by GDK_SELECTION_PRIMARY. Cut/copy/paste menu items
228 * conceptually copy the contents of the GDK_SELECTION_PRIMARY clipboard
229 * to the default clipboard, i.e. they copy the selection to what the
230 * user sees as the clipboard.
231 * (Passing GDK_NONE is the same as using gdk_atom_intern
232 * ("CLIPBOARD", FALSE). See
233 * http://www.freedesktop.org/Standards/clipboards-spec
234 * for a detailed discussion of the "CLIPBOARD" vs. "PRIMARY"
235 * selections under the X window system. On Win32 the
236 * GDK_SELECTION_PRIMARY clipboard is essentially ignored.)
237 * It's possible to have arbitrary named clipboards; if you do invent
238 * new clipboards, you should prefix the selection name with an
239 * underscore (because the ICCCM requires that nonstandard atoms are
240 * underscore-prefixed), and namespace it as well. For example,
241 * if your application called "Foo" has a special-purpose
242 * clipboard, you might call it "_FOO_SPECIAL_CLIPBOARD".
244 * the display for which the clipboard is to be retrieved or created
246 * a GdkAtom which identifies the clipboard
249 * the appropriate clipboard object. If no
250 * clipboard already exists, a new one will
251 * be created. Once a clipboard object has
252 * been created, it is persistent and, since
253 * it is owned by GTK+, must not be freed or
257 public static Clipboard
getForDisplay(Display display
, GdkAtom selection
)
259 // GtkClipboard* gtk_clipboard_get_for_display (GdkDisplay *display, GdkAtom selection);
260 return new Clipboard( gtk_clipboard_get_for_display((display
is null) ?
null : display
.getDisplayStruct(), selection
) );
264 * Gets the GdkDisplay associated with clipboard
268 * the GdkDisplay associated with clipboard
271 public Display
getDisplay()
273 // GdkDisplay* gtk_clipboard_get_display (GtkClipboard *clipboard);
274 return new Display( gtk_clipboard_get_display(gtkClipboard
) );
278 * Virtually sets the contents of the specified clipboard by providing
279 * a list of supported formats for the clipboard data and a function
280 * to call to get the actual data when it is requested.
284 * array containing information about the available forms for the
287 * number of elements in targets
289 * function to call to get the actual clipboard data
291 * when the clipboard contents are set again, this function will
292 * be called, and get_func will not be subsequently called.
294 * user data to pass to get_func and clear_func.
296 * TRUE if setting the clipboard data succeeded. If setting
297 * the clipboard data failed the provided callback functions
300 public int setWithData(GtkTargetEntry
* targets
, uint nTargets
, GtkClipboardGetFunc getFunc
, GtkClipboardClearFunc clearFunc
, void* userData
)
302 // gboolean gtk_clipboard_set_with_data (GtkClipboard *clipboard, const GtkTargetEntry *targets, guint n_targets, GtkClipboardGetFunc get_func, GtkClipboardClearFunc clear_func, gpointer user_data);
303 return gtk_clipboard_set_with_data(gtkClipboard
, targets
, nTargets
, getFunc
, clearFunc
, userData
);
307 * Virtually sets the contents of the specified clipboard by providing
308 * a list of supported formats for the clipboard data and a function
309 * to call to get the actual data when it is requested.
310 * The difference between this function and gtk_clipboard_set_with_data()
311 * is that instead of an generic user_data pointer, a GObject is passed
316 * array containing information about the available forms for the
319 * number of elements in targets
321 * function to call to get the actual clipboard data
323 * when the clipboard contents are set again, this function will
324 * be called, and get_func will not be subsequently called.
326 * an object that "owns" the data. This object will be passed
327 * to the callbacks when called.
329 * TRUE if setting the clipboard data succeeded. If setting
330 * the clipboard data failed the provided callback functions
333 public int setWithOwner(GtkTargetEntry
* targets
, uint nTargets
, GtkClipboardGetFunc getFunc
, GtkClipboardClearFunc clearFunc
, ObjectG owner
)
335 // gboolean gtk_clipboard_set_with_owner (GtkClipboard *clipboard, const GtkTargetEntry *targets, guint n_targets, GtkClipboardGetFunc get_func, GtkClipboardClearFunc clear_func, GObject *owner);
336 return gtk_clipboard_set_with_owner(gtkClipboard
, targets
, nTargets
, getFunc
, clearFunc
, (owner
is null) ?
null : owner
.getObjectGStruct());
340 * If the clipboard contents callbacks were set with
341 * gtk_clipboard_set_with_owner(), and the gtk_clipboard_set_with_data() or
342 * gtk_clipboard_clear() has not subsequently called, returns the owner set
343 * by gtk_clipboard_set_with_owner().
347 * the owner of the clipboard, if any; otherwise NULL.
349 public ObjectG
getOwner()
351 // GObject* gtk_clipboard_get_owner (GtkClipboard *clipboard);
352 return new ObjectG( gtk_clipboard_get_owner(gtkClipboard
) );
356 * Clears the contents of the clipboard. Generally this should only
357 * be called between the time you call gtk_clipboard_set_with_owner()
358 * or gtk_clipboard_set_with_data(),
359 * and when the clear_func you supplied is called. Otherwise, the
360 * clipboard may be owned by someone else.
366 // void gtk_clipboard_clear (GtkClipboard *clipboard);
367 gtk_clipboard_clear(gtkClipboard
);
371 * Sets the contents of the clipboard to the given UTF-8 string. GTK+ will
372 * make a copy of the text and take responsibility for responding
373 * for requests for the text, and for converting the text into
374 * the requested format.
376 * a GtkClipboard object
380 * length of text, in bytes, or -1, in which case
381 * the length will be determined with strlen().
383 public void setText(char[] text
, int len
)
385 // void gtk_clipboard_set_text (GtkClipboard *clipboard, const gchar *text, gint len);
386 gtk_clipboard_set_text(gtkClipboard
, Str
.toStringz(text
), len
);
390 * Sets the contents of the clipboard to the given GdkPixbuf.
391 * GTK+ will take responsibility for responding for requests
392 * for the image, and for converting the image into the
395 * a GtkClipboard object
400 public void setImage(Pixbuf pixbuf
)
402 // void gtk_clipboard_set_image (GtkClipboard *clipboard, GdkPixbuf *pixbuf);
403 gtk_clipboard_set_image(gtkClipboard
, (pixbuf
is null) ?
null : pixbuf
.getPixbufStruct());
407 * Requests the contents of clipboard as the given target.
408 * When the results of the result are later received the supplied callback
413 * an atom representing the form into which the clipboard
414 * owner should convert the selection.
416 * A function to call when the results are received
417 * (or the retrieval fails). If the retrieval fails
418 * the length field of selection_data will be
421 * user data to pass to callback
423 public void requestContents(GdkAtom target
, GtkClipboardReceivedFunc callback
, void* userData
)
425 // void gtk_clipboard_request_contents (GtkClipboard *clipboard, GdkAtom target, GtkClipboardReceivedFunc callback, gpointer user_data);
426 gtk_clipboard_request_contents(gtkClipboard
, target
, callback
, userData
);
430 * Requests the contents of the clipboard as text. When the text is
431 * later received, it will be converted to UTF-8 if necessary, and
432 * callback will be called.
433 * The text parameter to callback will contain the resulting text if
434 * the request succeeded, or NULL if it failed. This could happen for
435 * various reasons, in particular if the clipboard was empty or if the
436 * contents of the clipboard could not be converted into text form.
440 * a function to call when the text is received,
441 * or the retrieval fails. (It will always be called
442 * one way or the other.)
444 * user data to pass to callback.
446 public void requestText(GtkClipboardTextReceivedFunc callback
, void* userData
)
448 // void gtk_clipboard_request_text (GtkClipboard *clipboard, GtkClipboardTextReceivedFunc callback, gpointer user_data);
449 gtk_clipboard_request_text(gtkClipboard
, callback
, userData
);
453 * Requests the contents of the clipboard as image. When the image is
454 * later received, it will be converted to a GdkPixbuf, and
455 * callback will be called.
456 * The pixbuf parameter to callback will contain the resulting
457 * GdkPixbuf if the request succeeded, or NULL if it failed. This
458 * could happen for various reasons, in particular if the clipboard
459 * was empty or if the contents of the clipboard could not be
460 * converted into an image.
464 * a function to call when the image is received,
465 * or the retrieval fails. (It will always be called
466 * one way or the other.)
468 * user data to pass to callback.
471 public void requestImage(GtkClipboardImageReceivedFunc callback
, void* userData
)
473 // void gtk_clipboard_request_image (GtkClipboard *clipboard, GtkClipboardImageReceivedFunc callback, gpointer user_data);
474 gtk_clipboard_request_image(gtkClipboard
, callback
, userData
);
478 * Requests the contents of the clipboard as list of supported targets.
479 * When the list is later received, callback will be called.
480 * The targets parameter to callback will contain the resulting targets if
481 * the request succeeded, or NULL if it failed.
485 * a function to call when the targets are received,
486 * or the retrieval fails. (It will always be called
487 * one way or the other.)
489 * user data to pass to callback.
492 public void requestTargets(GtkClipboardTargetsReceivedFunc callback
, void* userData
)
494 // void gtk_clipboard_request_targets (GtkClipboard *clipboard, GtkClipboardTargetsReceivedFunc callback, gpointer user_data);
495 gtk_clipboard_request_targets(gtkClipboard
, callback
, userData
);
499 * Requests the contents of the clipboard as rich text. When the rich
500 * text is later received, callback will be called.
501 * The text parameter to callback will contain the resulting rich
502 * text if the request succeeded, or NULL if it failed. The length
503 * parameter will contain text's length. This function can fail for
504 * various reasons, in particular if the clipboard was empty or if the
505 * contents of the clipboard could not be converted into rich text form.
511 * a function to call when the text is received,
512 * or the retrieval fails. (It will always be called
513 * one way or the other.)
515 * user data to pass to callback.
518 public void requestRichText(GtkTextBuffer
* buffer
, GtkClipboardRichTextReceivedFunc callback
, void* userData
)
520 // void gtk_clipboard_request_rich_text (GtkClipboard *clipboard, GtkTextBuffer *buffer, GtkClipboardRichTextReceivedFunc callback, gpointer user_data);
521 gtk_clipboard_request_rich_text(gtkClipboard
, buffer
, callback
, userData
);
525 * Requests the contents of the clipboard using the given target.
526 * This function waits for the data to be received using the main
527 * loop, so events, timeouts, etc, may be dispatched during the wait.
531 * an atom representing the form into which the clipboard
532 * owner should convert the selection.
534 * a newly-allocated GtkSelectionData object or NULL
535 * if retrieving the given target failed. If non-NULL,
536 * this value must be freed with gtk_selection_data_free()
537 * when you are finished with it.
539 public GtkSelectionData
* waitForContents(GdkAtom target
)
541 // GtkSelectionData* gtk_clipboard_wait_for_contents (GtkClipboard *clipboard, GdkAtom target);
542 return gtk_clipboard_wait_for_contents(gtkClipboard
, target
);
546 * Requests the contents of the clipboard as text and converts
547 * the result to UTF-8 if necessary. This function waits for
548 * the data to be received using the main loop, so events,
549 * timeouts, etc, may be dispatched during the wait.
553 * a newly-allocated UTF-8 string which must
554 * be freed with g_free(), or NULL if retrieving
555 * the selection data failed. (This could happen
556 * for various reasons, in particular if the
557 * clipboard was empty or if the contents of the
558 * clipboard could not be converted into text form.)
560 public char[] waitForText()
562 // gchar* gtk_clipboard_wait_for_text (GtkClipboard *clipboard);
563 return Str
.toString(gtk_clipboard_wait_for_text(gtkClipboard
) );
567 * Requests the contents of the clipboard as image and converts
568 * the result to a GdkPixbuf. This function waits for
569 * the data to be received using the main loop, so events,
570 * timeouts, etc, may be dispatched during the wait.
574 * a newly-allocated GdkPixbuf object which must
575 * be disposed with g_object_unref(), or NULL if
576 * retrieving the selection data failed. (This
577 * could happen for various reasons, in particular
578 * if the clipboard was empty or if the contents of
579 * the clipboard could not be converted into an image.)
582 public Pixbuf
waitForImage()
584 // GdkPixbuf* gtk_clipboard_wait_for_image (GtkClipboard *clipboard);
585 return new Pixbuf( gtk_clipboard_wait_for_image(gtkClipboard
) );
589 * Requests the contents of the clipboard as rich text. This function
590 * waits for the data to be received using the main loop, so events,
591 * timeouts, etc, may be dispatched during the wait.
597 * return location for the format of the returned data
599 * return location for the length of the returned data
601 * a newly-allocated binary block of data which must
602 * be freed with g_free(), or NULL if retrieving
603 * the selection data failed. (This could happen
604 * for various reasons, in particular if the
605 * clipboard was empty or if the contents of the
606 * clipboard could not be converted into text form.)
609 public byte* waitForRichText(GtkTextBuffer
* buffer
, GdkAtom
* format
, uint* length
)
611 // guint8* gtk_clipboard_wait_for_rich_text (GtkClipboard *clipboard, GtkTextBuffer *buffer, GdkAtom *format, gsize *length);
612 return gtk_clipboard_wait_for_rich_text(gtkClipboard
, buffer
, format
, length
);
616 * Test to see if there is text available to be pasted
617 * This is done by requesting the TARGETS atom and checking
618 * if it contains any of the supported text targets. This function
619 * waits for the data to be received using the main loop, so events,
620 * timeouts, etc, may be dispatched during the wait.
621 * This function is a little faster than calling
622 * gtk_clipboard_wait_for_text() since it doesn't need to retrieve
627 * TRUE is there is text available, FALSE otherwise.
629 public int waitIsTextAvailable()
631 // gboolean gtk_clipboard_wait_is_text_available (GtkClipboard *clipboard);
632 return gtk_clipboard_wait_is_text_available(gtkClipboard
);
636 * Test to see if there is an image available to be pasted
637 * This is done by requesting the TARGETS atom and checking
638 * if it contains any of the supported image targets. This function
639 * waits for the data to be received using the main loop, so events,
640 * timeouts, etc, may be dispatched during the wait.
641 * This function is a little faster than calling
642 * gtk_clipboard_wait_for_image() since it doesn't need to retrieve
643 * the actual image data.
647 * TRUE is there is an image available, FALSE otherwise.
650 public int waitIsImageAvailable()
652 // gboolean gtk_clipboard_wait_is_image_available (GtkClipboard *clipboard);
653 return gtk_clipboard_wait_is_image_available(gtkClipboard
);
657 * Test to see if there is rich text available to be pasted
658 * This is done by requesting the TARGETS atom and checking
659 * if it contains any of the supported rich text targets. This function
660 * waits for the data to be received using the main loop, so events,
661 * timeouts, etc, may be dispatched during the wait.
662 * This function is a little faster than calling
663 * gtk_clipboard_wait_for_rich_text() since it doesn't need to retrieve
670 * TRUE is there is rich text available, FALSE otherwise.
673 public int waitIsRichTextAvailable(GtkTextBuffer
* buffer
)
675 // gboolean gtk_clipboard_wait_is_rich_text_available (GtkClipboard *clipboard, GtkTextBuffer *buffer);
676 return gtk_clipboard_wait_is_rich_text_available(gtkClipboard
, buffer
);
680 * Returns a list of targets that are present on the clipboard, or NULL
681 * if there aren't any targets available. The returned list must be
682 * freed with g_free().
683 * This function waits for the data to be received using the main
684 * loop, so events, timeouts, etc, may be dispatched during the wait.
688 * location to store an array of targets. The result
689 * stored here must be freed with g_free().
691 * location to store number of items in targets.
693 * TRUE if any targets are present on the clipboard,
697 public int waitForTargets(GdkAtom
** targets
, int* nTargets
)
699 // gboolean gtk_clipboard_wait_for_targets (GtkClipboard *clipboard, GdkAtom **targets, gint *n_targets);
700 return gtk_clipboard_wait_for_targets(gtkClipboard
, targets
, nTargets
);
704 * Checks if a clipboard supports pasting data of a given type. This
705 * function can be used to determine if a "Paste" menu item should be
706 * insensitive or not.
707 * If you want to see if there's text available on the clipboard, use
708 * gtk_clipboard_wait_is_text_available() instead.
712 * A GdkAtom indicating which target to look for.
714 * TRUE if the target is available, FALSE otherwise.
717 public int waitIsTargetAvailable(GdkAtom target
)
719 // gboolean gtk_clipboard_wait_is_target_available (GtkClipboard *clipboard, GdkAtom target);
720 return gtk_clipboard_wait_is_target_available(gtkClipboard
, target
);
724 * Hints that the clipboard data should be stored somewhere when the
725 * application exits or when gtk_clipboard_store() is called.
726 * This value is reset when the clipboard owner changes.
727 * Where the clipboard data is stored is platform dependent,
728 * see gdk_display_store_clipboard() for more information.
732 * array containing information about which forms should be stored
733 * or NULL to indicate that all forms should be stored.
735 * number of elements in targets
738 public void setCanStore(GtkTargetEntry
* targets
, int nTargets
)
740 // void gtk_clipboard_set_can_store (GtkClipboard *clipboard, const GtkTargetEntry *targets, gint n_targets);
741 gtk_clipboard_set_can_store(gtkClipboard
, targets
, nTargets
);
745 * Stores the current clipboard data somewhere so that it will stay
746 * around after the application has quit.
751 * The "owner-change" signal
752 * void user_function (GtkClipboard *clipboard,
754 * gpointer user_data) : Run first
756 * the object which received the signal.
759 * user data set when the signal handler was connected.
762 * GtkClipboard provides a high-level wrapper around the
763 * lower level routines that deal with X selections. It is
764 * also possibly to directly manipulate the X selections,
765 * though it is seldom necessary to do so.
769 // void gtk_clipboard_store (GtkClipboard *clipboard);
770 gtk_clipboard_store(gtkClipboard
);