Skip to main content

gtk/auto/
clipboard.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{SelectionData, TextBuffer};
6use glib::{prelude::*, translate::*};
7use std::{boxed::Box as Box_, fmt, mem, ptr};
8
9glib::wrapper! {
10    /// The [`Clipboard`][crate::Clipboard] object represents a clipboard of data shared
11    /// between different processes or between different widgets in
12    /// the same process. Each clipboard is identified by a name encoded as a
13    /// [`gdk::Atom`][crate::gdk::Atom]. (Conversion to and from strings can be done with
14    /// [`gdk::Atom::intern()`][crate::gdk::Atom::intern()] and [`gdk::Atom::name()`][crate::gdk::Atom::name()].) The default clipboard
15    /// corresponds to the “CLIPBOARD” atom; another commonly used clipboard
16    /// is the “PRIMARY” clipboard, which, in X, traditionally contains
17    /// the currently selected text.
18    ///
19    /// To support having a number of different formats on the clipboard
20    /// at the same time, the clipboard mechanism allows providing
21    /// callbacks instead of the actual data. When you set the contents
22    /// of the clipboard, you can either supply the data directly (via
23    /// functions like [`set_text()`][Self::set_text()]), or you can supply a
24    /// callback to be called at a later time when the data is needed (via
25    /// `gtk_clipboard_set_with_data()` or `gtk_clipboard_set_with_owner()`.)
26    /// Providing a callback also avoids having to make copies of the data
27    /// when it is not needed.
28    ///
29    /// `gtk_clipboard_set_with_data()` and `gtk_clipboard_set_with_owner()`
30    /// are quite similar; the choice between the two depends mostly on
31    /// which is more convenient in a particular situation.
32    /// The former is most useful when you want to have a blob of data
33    /// with callbacks to convert it into the various data types that you
34    /// advertise. When the `clear_func` you provided is called, you
35    /// simply free the data blob. The latter is more useful when the
36    /// contents of clipboard reflect the internal state of a [`glib::Object`][crate::glib::Object]
37    /// (As an example, for the PRIMARY clipboard, when an entry widget
38    /// provides the clipboard’s contents the contents are simply the
39    /// text within the selected region.) If the contents change, the
40    /// entry widget can call `gtk_clipboard_set_with_owner()` to update
41    /// the timestamp for clipboard ownership, without having to worry
42    /// about `clear_func` being called.
43    ///
44    /// Requesting the data from the clipboard is essentially
45    /// asynchronous. If the contents of the clipboard are provided within
46    /// the same process, then a direct function call will be made to
47    /// retrieve the data, but if they are provided by another process,
48    /// then the data needs to be retrieved from the other process, which
49    /// may take some time. To avoid blocking the user interface, the call
50    /// to request the selection, [`request_contents()`][Self::request_contents()] takes a
51    /// callback that will be called when the contents are received (or
52    /// when the request fails.) If you don’t want to deal with providing
53    /// a separate callback, you can also use [`wait_for_contents()`][Self::wait_for_contents()].
54    /// What this does is run the GLib main loop recursively waiting for
55    /// the contents. This can simplify the code flow, but you still have
56    /// to be aware that other callbacks in your program can be called
57    /// while this recursive mainloop is running.
58    ///
59    /// Along with the functions to get the clipboard contents as an
60    /// arbitrary data chunk, there are also functions to retrieve
61    /// it as text, [`request_text()`][Self::request_text()] and
62    /// [`wait_for_text()`][Self::wait_for_text()]. These functions take care of
63    /// determining which formats are advertised by the clipboard
64    /// provider, asking for the clipboard in the best available format
65    /// and converting the results into the UTF-8 encoding. (The standard
66    /// form for representing strings in GTK+.)
67    ///
68    /// ## Signals
69    ///
70    ///
71    /// #### `owner-change`
72    ///  The ::owner-change signal is emitted when GTK+ receives an
73    /// event that indicates that the ownership of the selection
74    /// associated with `clipboard` has changed.
75    ///
76    ///
77    ///
78    /// # Implements
79    ///
80    /// [`trait@glib::ObjectExt`]
81    #[doc(alias = "GtkClipboard")]
82    pub struct Clipboard(Object<ffi::GtkClipboard>);
83
84    match fn {
85        type_ => || ffi::gtk_clipboard_get_type(),
86    }
87}
88
89impl Clipboard {
90    /// Clears the contents of the clipboard. Generally this should only
91    /// be called between the time you call `gtk_clipboard_set_with_owner()`
92    /// or `gtk_clipboard_set_with_data()`,
93    /// and when the `clear_func` you supplied is called. Otherwise, the
94    /// clipboard may be owned by someone else.
95    #[doc(alias = "gtk_clipboard_clear")]
96    pub fn clear(&self) {
97        unsafe {
98            ffi::gtk_clipboard_clear(self.to_glib_none().0);
99        }
100    }
101
102    /// Gets the [`gdk::Display`][crate::gdk::Display] associated with `self`
103    ///
104    /// # Returns
105    ///
106    /// the [`gdk::Display`][crate::gdk::Display] associated with `self`
107    #[doc(alias = "gtk_clipboard_get_display")]
108    #[doc(alias = "get_display")]
109    pub fn display(&self) -> Option<gdk::Display> {
110        unsafe { from_glib_none(ffi::gtk_clipboard_get_display(self.to_glib_none().0)) }
111    }
112
113    /// If the clipboard contents callbacks were set with
114    /// `gtk_clipboard_set_with_owner()`, and the `gtk_clipboard_set_with_data()` or
115    /// [`clear()`][Self::clear()] has not subsequently called, returns the owner set
116    /// by `gtk_clipboard_set_with_owner()`.
117    ///
118    /// # Returns
119    ///
120    /// the owner of the clipboard, if any;
121    ///  otherwise [`None`].
122    #[doc(alias = "gtk_clipboard_get_owner")]
123    #[doc(alias = "get_owner")]
124    pub fn owner(&self) -> Option<glib::Object> {
125        unsafe { from_glib_none(ffi::gtk_clipboard_get_owner(self.to_glib_none().0)) }
126    }
127
128    /// Gets the selection that this clipboard is for.
129    ///
130    /// # Returns
131    ///
132    /// the selection
133    #[doc(alias = "gtk_clipboard_get_selection")]
134    #[doc(alias = "get_selection")]
135    pub fn selection(&self) -> Option<gdk::Atom> {
136        unsafe { from_glib_none(ffi::gtk_clipboard_get_selection(self.to_glib_none().0)) }
137    }
138
139    /// Requests the contents of clipboard as the given target.
140    /// When the results of the result are later received the supplied callback
141    /// will be called.
142    /// ## `target`
143    /// an atom representing the form into which the clipboard
144    ///  owner should convert the selection.
145    /// ## `callback`
146    /// A function to call when the results are received
147    ///  (or the retrieval fails). If the retrieval fails the length field of
148    ///  `selection_data` will be negative.
149    #[doc(alias = "gtk_clipboard_request_contents")]
150    pub fn request_contents<P: FnOnce(&Clipboard, &SelectionData) + 'static>(
151        &self,
152        target: &gdk::Atom,
153        callback: P,
154    ) {
155        let callback_data: Box_<P> = Box_::new(callback);
156        unsafe extern "C" fn callback_func<P: FnOnce(&Clipboard, &SelectionData) + 'static>(
157            clipboard: *mut ffi::GtkClipboard,
158            selection_data: *mut ffi::GtkSelectionData,
159            data: glib::ffi::gpointer,
160        ) {
161            let clipboard = from_glib_borrow(clipboard);
162            let selection_data = from_glib_borrow(selection_data);
163            let callback: Box_<P> = Box_::from_raw(data as *mut _);
164            (*callback)(&clipboard, &selection_data)
165        }
166        let callback = Some(callback_func::<P> as _);
167        let super_callback0: Box_<P> = callback_data;
168        unsafe {
169            ffi::gtk_clipboard_request_contents(
170                self.to_glib_none().0,
171                target.to_glib_none().0,
172                callback,
173                Box_::into_raw(super_callback0) as *mut _,
174            );
175        }
176    }
177
178    /// Requests the contents of the clipboard as image. When the image is
179    /// later received, it will be converted to a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf], and
180    /// `callback` will be called.
181    ///
182    /// The `pixbuf` parameter to `callback` will contain the resulting
183    /// [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf] if the request succeeded, or [`None`] if it failed. This
184    /// could happen for various reasons, in particular if the clipboard
185    /// was empty or if the contents of the clipboard could not be
186    /// converted into an image.
187    /// ## `callback`
188    /// a function to call when the image is received,
189    ///  or the retrieval fails. (It will always be called one way or the other.)
190    #[doc(alias = "gtk_clipboard_request_image")]
191    pub fn request_image<P: FnOnce(&Clipboard, Option<&gdk_pixbuf::Pixbuf>) + 'static>(
192        &self,
193        callback: P,
194    ) {
195        let callback_data: Box_<P> = Box_::new(callback);
196        unsafe extern "C" fn callback_func<
197            P: FnOnce(&Clipboard, Option<&gdk_pixbuf::Pixbuf>) + 'static,
198        >(
199            clipboard: *mut ffi::GtkClipboard,
200            pixbuf: *mut gdk_pixbuf::ffi::GdkPixbuf,
201            data: glib::ffi::gpointer,
202        ) {
203            let clipboard = from_glib_borrow(clipboard);
204            let pixbuf: Borrowed<Option<gdk_pixbuf::Pixbuf>> = from_glib_borrow(pixbuf);
205            let callback: Box_<P> = Box_::from_raw(data as *mut _);
206            (*callback)(&clipboard, pixbuf.as_ref().as_ref())
207        }
208        let callback = Some(callback_func::<P> as _);
209        let super_callback0: Box_<P> = callback_data;
210        unsafe {
211            ffi::gtk_clipboard_request_image(
212                self.to_glib_none().0,
213                callback,
214                Box_::into_raw(super_callback0) as *mut _,
215            );
216        }
217    }
218
219    /// Requests the contents of the clipboard as rich text. When the rich
220    /// text is later received, `callback` will be called.
221    ///
222    /// The `text` parameter to `callback` will contain the resulting rich
223    /// text if the request succeeded, or [`None`] if it failed. The `length`
224    /// parameter will contain `text`’s length. This function can fail for
225    /// various reasons, in particular if the clipboard was empty or if the
226    /// contents of the clipboard could not be converted into rich text form.
227    /// ## `buffer`
228    /// a [`TextBuffer`][crate::TextBuffer]
229    /// ## `callback`
230    /// a function to call when the text is received,
231    ///  or the retrieval fails. (It will always be called one way or the other.)
232    #[doc(alias = "gtk_clipboard_request_rich_text")]
233    pub fn request_rich_text<P: FnOnce(&Clipboard, &gdk::Atom, Option<&str>, usize) + 'static>(
234        &self,
235        buffer: &impl IsA<TextBuffer>,
236        callback: P,
237    ) {
238        let callback_data: Box_<P> = Box_::new(callback);
239        unsafe extern "C" fn callback_func<
240            P: FnOnce(&Clipboard, &gdk::Atom, Option<&str>, usize) + 'static,
241        >(
242            clipboard: *mut ffi::GtkClipboard,
243            format: gdk::ffi::GdkAtom,
244            text: *const libc::c_char,
245            length: libc::size_t,
246            data: glib::ffi::gpointer,
247        ) {
248            let clipboard = from_glib_borrow(clipboard);
249            let format = from_glib_borrow(format);
250            let text: Borrowed<Option<glib::GString>> = from_glib_borrow(text);
251            let callback: Box_<P> = Box_::from_raw(data as *mut _);
252            (*callback)(
253                &clipboard,
254                &format,
255                (*text).as_ref().map(|s| s.as_str()),
256                length,
257            )
258        }
259        let callback = Some(callback_func::<P> as _);
260        let super_callback0: Box_<P> = callback_data;
261        unsafe {
262            ffi::gtk_clipboard_request_rich_text(
263                self.to_glib_none().0,
264                buffer.as_ref().to_glib_none().0,
265                callback,
266                Box_::into_raw(super_callback0) as *mut _,
267            );
268        }
269    }
270
271    /// Requests the contents of the clipboard as text. When the text is
272    /// later received, it will be converted to UTF-8 if necessary, and
273    /// `callback` will be called.
274    ///
275    /// The `text` parameter to `callback` will contain the resulting text if
276    /// the request succeeded, or [`None`] if it failed. This could happen for
277    /// various reasons, in particular if the clipboard was empty or if the
278    /// contents of the clipboard could not be converted into text form.
279    /// ## `callback`
280    /// a function to call when the text is received,
281    ///  or the retrieval fails. (It will always be called one way or the other.)
282    #[doc(alias = "gtk_clipboard_request_text")]
283    pub fn request_text<P: FnOnce(&Clipboard, Option<&str>) + 'static>(&self, callback: P) {
284        let callback_data: Box_<P> = Box_::new(callback);
285        unsafe extern "C" fn callback_func<P: FnOnce(&Clipboard, Option<&str>) + 'static>(
286            clipboard: *mut ffi::GtkClipboard,
287            text: *const libc::c_char,
288            data: glib::ffi::gpointer,
289        ) {
290            let clipboard = from_glib_borrow(clipboard);
291            let text: Borrowed<Option<glib::GString>> = from_glib_borrow(text);
292            let callback: Box_<P> = Box_::from_raw(data as *mut _);
293            (*callback)(&clipboard, (*text).as_ref().map(|s| s.as_str()))
294        }
295        let callback = Some(callback_func::<P> as _);
296        let super_callback0: Box_<P> = callback_data;
297        unsafe {
298            ffi::gtk_clipboard_request_text(
299                self.to_glib_none().0,
300                callback,
301                Box_::into_raw(super_callback0) as *mut _,
302            );
303        }
304    }
305
306    /// Sets the contents of the clipboard to the given [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf].
307    /// GTK+ will take responsibility for responding for requests
308    /// for the image, and for converting the image into the
309    /// requested format.
310    /// ## `pixbuf`
311    /// a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf]
312    #[doc(alias = "gtk_clipboard_set_image")]
313    pub fn set_image(&self, pixbuf: &gdk_pixbuf::Pixbuf) {
314        unsafe {
315            ffi::gtk_clipboard_set_image(self.to_glib_none().0, pixbuf.to_glib_none().0);
316        }
317    }
318
319    /// Sets the contents of the clipboard to the given UTF-8 string. GTK+ will
320    /// make a copy of the text and take responsibility for responding
321    /// for requests for the text, and for converting the text into
322    /// the requested format.
323    /// ## `text`
324    /// a UTF-8 string.
325    /// ## `len`
326    /// length of `text`, in bytes, or -1, in which case
327    ///  the length will be determined with `strlen()`.
328    #[doc(alias = "gtk_clipboard_set_text")]
329    pub fn set_text(&self, text: &str) {
330        let len = text.len() as _;
331        unsafe {
332            ffi::gtk_clipboard_set_text(self.to_glib_none().0, text.to_glib_none().0, len);
333        }
334    }
335
336    /// Stores the current clipboard data somewhere so that it will stay
337    /// around after the application has quit.
338    #[doc(alias = "gtk_clipboard_store")]
339    pub fn store(&self) {
340        unsafe {
341            ffi::gtk_clipboard_store(self.to_glib_none().0);
342        }
343    }
344
345    /// Requests the contents of the clipboard using the given target.
346    /// This function waits for the data to be received using the main
347    /// loop, so events, timeouts, etc, may be dispatched during the wait.
348    /// ## `target`
349    /// an atom representing the form into which the clipboard
350    ///  owner should convert the selection.
351    ///
352    /// # Returns
353    ///
354    /// a newly-allocated [`SelectionData`][crate::SelectionData] object or [`None`]
355    ///  if retrieving the given target failed. If non-[`None`],
356    ///  this value must be freed with `gtk_selection_data_free()`
357    ///  when you are finished with it.
358    #[doc(alias = "gtk_clipboard_wait_for_contents")]
359    pub fn wait_for_contents(&self, target: &gdk::Atom) -> Option<SelectionData> {
360        unsafe {
361            from_glib_full(ffi::gtk_clipboard_wait_for_contents(
362                self.to_glib_none().0,
363                target.to_glib_none().0,
364            ))
365        }
366    }
367
368    /// Requests the contents of the clipboard as image and converts
369    /// the result to a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf]. This function waits for
370    /// the data to be received using the main loop, so events,
371    /// timeouts, etc, may be dispatched during the wait.
372    ///
373    /// # Returns
374    ///
375    /// a newly-allocated [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf]
376    ///  object which must be disposed with `g_object_unref()`, or
377    ///  [`None`] if retrieving the selection data failed. (This could
378    ///  happen for various reasons, in particular if the clipboard
379    ///  was empty or if the contents of the clipboard could not be
380    ///  converted into an image.)
381    #[doc(alias = "gtk_clipboard_wait_for_image")]
382    pub fn wait_for_image(&self) -> Option<gdk_pixbuf::Pixbuf> {
383        unsafe { from_glib_full(ffi::gtk_clipboard_wait_for_image(self.to_glib_none().0)) }
384    }
385
386    /// Requests the contents of the clipboard as rich text. This function
387    /// waits for the data to be received using the main loop, so events,
388    /// timeouts, etc, may be dispatched during the wait.
389    /// ## `buffer`
390    /// a [`TextBuffer`][crate::TextBuffer]
391    ///
392    /// # Returns
393    ///
394    /// a
395    ///  newly-allocated binary block of data which must be
396    ///  freed with `g_free()`, or [`None`] if retrieving the
397    ///  selection data failed. (This could happen for various
398    ///  reasons, in particular if the clipboard was empty or
399    ///  if the contents of the clipboard could not be
400    ///  converted into text form.)
401    ///
402    /// ## `format`
403    /// return location for the format of the returned data
404    #[doc(alias = "gtk_clipboard_wait_for_rich_text")]
405    pub fn wait_for_rich_text(&self, buffer: &impl IsA<TextBuffer>) -> (Vec<u8>, gdk::Atom) {
406        unsafe {
407            let mut format = gdk::Atom::uninitialized();
408            let mut length = mem::MaybeUninit::uninit();
409            let ret = FromGlibContainer::from_glib_full_num(
410                ffi::gtk_clipboard_wait_for_rich_text(
411                    self.to_glib_none().0,
412                    buffer.as_ref().to_glib_none().0,
413                    format.to_glib_none_mut().0,
414                    length.as_mut_ptr(),
415                ),
416                length.assume_init() as _,
417            );
418            (ret, format)
419        }
420    }
421
422    /// Returns a list of targets that are present on the clipboard, or [`None`]
423    /// if there aren’t any targets available. The returned list must be
424    /// freed with `g_free()`.
425    /// This function waits for the data to be received using the main
426    /// loop, so events, timeouts, etc, may be dispatched during the wait.
427    ///
428    /// # Returns
429    ///
430    /// [`true`] if any targets are present on the clipboard,
431    ///  otherwise [`false`].
432    ///
433    /// ## `targets`
434    /// location
435    ///  to store an array of targets. The result stored here must
436    ///  be freed with `g_free()`.
437    #[doc(alias = "gtk_clipboard_wait_for_targets")]
438    pub fn wait_for_targets(&self) -> Option<Vec<gdk::Atom>> {
439        unsafe {
440            let mut targets = ptr::null_mut();
441            let mut n_targets = mem::MaybeUninit::uninit();
442            let ret = from_glib(ffi::gtk_clipboard_wait_for_targets(
443                self.to_glib_none().0,
444                &mut targets,
445                n_targets.as_mut_ptr(),
446            ));
447            if ret {
448                Some(FromGlibContainer::from_glib_container_num(
449                    targets,
450                    n_targets.assume_init() as _,
451                ))
452            } else {
453                None
454            }
455        }
456    }
457
458    /// Requests the contents of the clipboard as text and converts
459    /// the result to UTF-8 if necessary. This function waits for
460    /// the data to be received using the main loop, so events,
461    /// timeouts, etc, may be dispatched during the wait.
462    ///
463    /// # Returns
464    ///
465    /// a newly-allocated UTF-8 string which must
466    ///  be freed with `g_free()`, or [`None`] if retrieving
467    ///  the selection data failed. (This could happen
468    ///  for various reasons, in particular if the
469    ///  clipboard was empty or if the contents of the
470    ///  clipboard could not be converted into text form.)
471    #[doc(alias = "gtk_clipboard_wait_for_text")]
472    pub fn wait_for_text(&self) -> Option<glib::GString> {
473        unsafe { from_glib_full(ffi::gtk_clipboard_wait_for_text(self.to_glib_none().0)) }
474    }
475
476    /// Requests the contents of the clipboard as URIs. This function waits
477    /// for the data to be received using the main loop, so events,
478    /// timeouts, etc, may be dispatched during the wait.
479    ///
480    /// # Returns
481    ///
482    ///
483    ///  a newly-allocated [`None`]-terminated array of strings which must
484    ///  be freed with `g_strfreev()`, or [`None`] if retrieving the
485    ///  selection data failed. (This could happen for various reasons,
486    ///  in particular if the clipboard was empty or if the contents of
487    ///  the clipboard could not be converted into URI form.)
488    #[doc(alias = "gtk_clipboard_wait_for_uris")]
489    pub fn wait_for_uris(&self) -> Vec<glib::GString> {
490        unsafe {
491            FromGlibPtrContainer::from_glib_full(ffi::gtk_clipboard_wait_for_uris(
492                self.to_glib_none().0,
493            ))
494        }
495    }
496
497    /// Test to see if there is an image available to be pasted
498    /// This is done by requesting the TARGETS atom and checking
499    /// if it contains any of the supported image targets. This function
500    /// waits for the data to be received using the main loop, so events,
501    /// timeouts, etc, may be dispatched during the wait.
502    ///
503    /// This function is a little faster than calling
504    /// [`wait_for_image()`][Self::wait_for_image()] since it doesn’t need to retrieve
505    /// the actual image data.
506    ///
507    /// # Returns
508    ///
509    /// [`true`] is there is an image available, [`false`] otherwise.
510    #[doc(alias = "gtk_clipboard_wait_is_image_available")]
511    pub fn wait_is_image_available(&self) -> bool {
512        unsafe {
513            from_glib(ffi::gtk_clipboard_wait_is_image_available(
514                self.to_glib_none().0,
515            ))
516        }
517    }
518
519    /// Test to see if there is rich text available to be pasted
520    /// This is done by requesting the TARGETS atom and checking
521    /// if it contains any of the supported rich text targets. This function
522    /// waits for the data to be received using the main loop, so events,
523    /// timeouts, etc, may be dispatched during the wait.
524    ///
525    /// This function is a little faster than calling
526    /// [`wait_for_rich_text()`][Self::wait_for_rich_text()] since it doesn’t need to retrieve
527    /// the actual text.
528    /// ## `buffer`
529    /// a [`TextBuffer`][crate::TextBuffer]
530    ///
531    /// # Returns
532    ///
533    /// [`true`] is there is rich text available, [`false`] otherwise.
534    #[doc(alias = "gtk_clipboard_wait_is_rich_text_available")]
535    pub fn wait_is_rich_text_available(&self, buffer: &impl IsA<TextBuffer>) -> bool {
536        unsafe {
537            from_glib(ffi::gtk_clipboard_wait_is_rich_text_available(
538                self.to_glib_none().0,
539                buffer.as_ref().to_glib_none().0,
540            ))
541        }
542    }
543
544    /// Checks if a clipboard supports pasting data of a given type. This
545    /// function can be used to determine if a “Paste” menu item should be
546    /// insensitive or not.
547    ///
548    /// If you want to see if there’s text available on the clipboard, use
549    /// gtk_clipboard_wait_is_text_available () instead.
550    /// ## `target`
551    /// A [`gdk::Atom`][crate::gdk::Atom] indicating which target to look for.
552    ///
553    /// # Returns
554    ///
555    /// [`true`] if the target is available, [`false`] otherwise.
556    #[doc(alias = "gtk_clipboard_wait_is_target_available")]
557    pub fn wait_is_target_available(&self, target: &gdk::Atom) -> bool {
558        unsafe {
559            from_glib(ffi::gtk_clipboard_wait_is_target_available(
560                self.to_glib_none().0,
561                target.to_glib_none().0,
562            ))
563        }
564    }
565
566    /// Test to see if there is text available to be pasted
567    /// This is done by requesting the TARGETS atom and checking
568    /// if it contains any of the supported text targets. This function
569    /// waits for the data to be received using the main loop, so events,
570    /// timeouts, etc, may be dispatched during the wait.
571    ///
572    /// This function is a little faster than calling
573    /// [`wait_for_text()`][Self::wait_for_text()] since it doesn’t need to retrieve
574    /// the actual text.
575    ///
576    /// # Returns
577    ///
578    /// [`true`] is there is text available, [`false`] otherwise.
579    #[doc(alias = "gtk_clipboard_wait_is_text_available")]
580    pub fn wait_is_text_available(&self) -> bool {
581        unsafe {
582            from_glib(ffi::gtk_clipboard_wait_is_text_available(
583                self.to_glib_none().0,
584            ))
585        }
586    }
587
588    /// Test to see if there is a list of URIs available to be pasted
589    /// This is done by requesting the TARGETS atom and checking
590    /// if it contains the URI targets. This function
591    /// waits for the data to be received using the main loop, so events,
592    /// timeouts, etc, may be dispatched during the wait.
593    ///
594    /// This function is a little faster than calling
595    /// [`wait_for_uris()`][Self::wait_for_uris()] since it doesn’t need to retrieve
596    /// the actual URI data.
597    ///
598    /// # Returns
599    ///
600    /// [`true`] is there is an URI list available, [`false`] otherwise.
601    #[doc(alias = "gtk_clipboard_wait_is_uris_available")]
602    pub fn wait_is_uris_available(&self) -> bool {
603        unsafe {
604            from_glib(ffi::gtk_clipboard_wait_is_uris_available(
605                self.to_glib_none().0,
606            ))
607        }
608    }
609
610    /// Returns the clipboard object for the given selection.
611    /// See [`for_display()`][Self::for_display()] for complete details.
612    /// ## `selection`
613    /// a [`gdk::Atom`][crate::gdk::Atom] which identifies the clipboard to use
614    ///
615    /// # Returns
616    ///
617    /// the appropriate clipboard object. If no clipboard
618    ///  already exists, a new one will be created. Once a clipboard
619    ///  object has been created, it is persistent and, since it is
620    ///  owned by GTK+, must not be freed or unreffed.
621    #[doc(alias = "gtk_clipboard_get")]
622    pub fn get(selection: &gdk::Atom) -> Clipboard {
623        assert_initialized_main_thread!();
624        unsafe { from_glib_none(ffi::gtk_clipboard_get(selection.to_glib_none().0)) }
625    }
626
627    /// Returns the default clipboard object for use with cut/copy/paste menu items
628    /// and keyboard shortcuts.
629    /// ## `display`
630    /// the [`gdk::Display`][crate::gdk::Display] for which the clipboard is to be retrieved.
631    ///
632    /// # Returns
633    ///
634    /// the default clipboard object.
635    #[doc(alias = "gtk_clipboard_get_default")]
636    #[doc(alias = "get_default")]
637    #[allow(clippy::should_implement_trait)]
638    pub fn default(display: &gdk::Display) -> Option<Clipboard> {
639        assert_initialized_main_thread!();
640        unsafe { from_glib_none(ffi::gtk_clipboard_get_default(display.to_glib_none().0)) }
641    }
642
643    /// Returns the clipboard object for the given selection.
644    /// Cut/copy/paste menu items and keyboard shortcuts should use
645    /// the default clipboard, returned by passing `GDK_SELECTION_CLIPBOARD` for `selection`.
646    /// (`GDK_NONE` is supported as a synonym for GDK_SELECTION_CLIPBOARD
647    /// for backwards compatibility reasons.)
648    /// The currently-selected object or text should be provided on the clipboard
649    /// identified by `GDK_SELECTION_PRIMARY`. Cut/copy/paste menu items
650    /// conceptually copy the contents of the `GDK_SELECTION_PRIMARY` clipboard
651    /// to the default clipboard, i.e. they copy the selection to what the
652    /// user sees as the clipboard.
653    ///
654    /// (Passing `GDK_NONE` is the same as using `gdk_atom_intern
655    /// ("CLIPBOARD", FALSE)`.
656    ///
657    /// See the
658    /// [FreeDesktop Clipboard Specification](http://www.freedesktop.org/Standards/clipboards-spec)
659    /// for a detailed discussion of the “CLIPBOARD” vs. “PRIMARY”
660    /// selections under the X window system. On Win32 the
661    /// `GDK_SELECTION_PRIMARY` clipboard is essentially ignored.)
662    ///
663    /// It’s possible to have arbitrary named clipboards; if you do invent
664    /// new clipboards, you should prefix the selection name with an
665    /// underscore (because the ICCCM requires that nonstandard atoms are
666    /// underscore-prefixed), and namespace it as well. For example,
667    /// if your application called “Foo” has a special-purpose
668    /// clipboard, you might call it “_FOO_SPECIAL_CLIPBOARD”.
669    /// ## `display`
670    /// the [`gdk::Display`][crate::gdk::Display] for which the clipboard is to be retrieved or created.
671    /// ## `selection`
672    /// a [`gdk::Atom`][crate::gdk::Atom] which identifies the clipboard to use.
673    ///
674    /// # Returns
675    ///
676    /// the appropriate clipboard object. If no
677    ///  clipboard already exists, a new one will be created. Once a clipboard
678    ///  object has been created, it is persistent and, since it is owned by
679    ///  GTK+, must not be freed or unrefd.
680    #[doc(alias = "gtk_clipboard_get_for_display")]
681    #[doc(alias = "get_for_display")]
682    pub fn for_display(display: &gdk::Display, selection: &gdk::Atom) -> Clipboard {
683        assert_initialized_main_thread!();
684        unsafe {
685            from_glib_none(ffi::gtk_clipboard_get_for_display(
686                display.to_glib_none().0,
687                selection.to_glib_none().0,
688            ))
689        }
690    }
691
692    //#[doc(alias = "owner-change")]
693    //pub fn connect_owner_change<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId {
694    //    Ignored event: Gdk.EventOwnerChange
695    //}
696}
697
698impl fmt::Display for Clipboard {
699    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
700        f.write_str("Clipboard")
701    }
702}