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