Skip to main content

gtk/auto/
target_list.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::TextBuffer;
6use glib::{prelude::*, translate::*};
7use std::mem;
8
9glib::wrapper! {
10    /// A [`TargetList`][crate::TargetList]-struct is a reference counted list
11    /// of `GtkTargetPair` and should be treated as
12    /// opaque.
13    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
14    pub struct TargetList(Shared<ffi::GtkTargetList>);
15
16    match fn {
17        ref => |ptr| ffi::gtk_target_list_ref(ptr),
18        unref => |ptr| ffi::gtk_target_list_unref(ptr),
19        type_ => || ffi::gtk_target_list_get_type(),
20    }
21}
22
23impl TargetList {
24    /// Appends another target to a [`TargetList`][crate::TargetList].
25    /// ## `target`
26    /// the interned atom representing the target
27    /// ## `flags`
28    /// the flags for this target
29    /// ## `info`
30    /// an ID that will be passed back to the application
31    #[doc(alias = "gtk_target_list_add")]
32    pub fn add(&self, target: &gdk::Atom, flags: u32, info: u32) {
33        unsafe {
34            ffi::gtk_target_list_add(self.to_glib_none().0, target.to_glib_none().0, flags, info);
35        }
36    }
37
38    /// Appends the image targets supported by [`SelectionData`][crate::SelectionData] to
39    /// the target list. All targets are added with the same `info`.
40    /// ## `info`
41    /// an ID that will be passed back to the application
42    /// ## `writable`
43    /// whether to add only targets for which GTK+ knows
44    ///  how to convert a pixbuf into the format
45    #[doc(alias = "gtk_target_list_add_image_targets")]
46    pub fn add_image_targets(&self, info: u32, writable: bool) {
47        unsafe {
48            ffi::gtk_target_list_add_image_targets(
49                self.to_glib_none().0,
50                info,
51                writable.into_glib(),
52            );
53        }
54    }
55
56    /// Appends the rich text targets registered with
57    /// `gtk_text_buffer_register_serialize_format()` or
58    /// `gtk_text_buffer_register_deserialize_format()` to the target list. All
59    /// targets are added with the same `info`.
60    /// ## `info`
61    /// an ID that will be passed back to the application
62    /// ## `deserializable`
63    /// if [`true`], then deserializable rich text formats
64    ///  will be added, serializable formats otherwise.
65    /// ## `buffer`
66    /// a [`TextBuffer`][crate::TextBuffer].
67    #[doc(alias = "gtk_target_list_add_rich_text_targets")]
68    pub fn add_rich_text_targets(
69        &self,
70        info: u32,
71        deserializable: bool,
72        buffer: &impl IsA<TextBuffer>,
73    ) {
74        unsafe {
75            ffi::gtk_target_list_add_rich_text_targets(
76                self.to_glib_none().0,
77                info,
78                deserializable.into_glib(),
79                buffer.as_ref().to_glib_none().0,
80            );
81        }
82    }
83
84    /// Appends the text targets supported by [`SelectionData`][crate::SelectionData] to
85    /// the target list. All targets are added with the same `info`.
86    /// ## `info`
87    /// an ID that will be passed back to the application
88    #[doc(alias = "gtk_target_list_add_text_targets")]
89    pub fn add_text_targets(&self, info: u32) {
90        unsafe {
91            ffi::gtk_target_list_add_text_targets(self.to_glib_none().0, info);
92        }
93    }
94
95    /// Appends the URI targets supported by [`SelectionData`][crate::SelectionData] to
96    /// the target list. All targets are added with the same `info`.
97    ///
98    /// Since 3.24.37, this includes the application/vnd.portal.files
99    /// target when possible, to allow sending files between sandboxed
100    /// apps via the FileTransfer portal.
101    /// ## `info`
102    /// an ID that will be passed back to the application
103    #[doc(alias = "gtk_target_list_add_uri_targets")]
104    pub fn add_uri_targets(&self, info: u32) {
105        unsafe {
106            ffi::gtk_target_list_add_uri_targets(self.to_glib_none().0, info);
107        }
108    }
109
110    /// Looks up a given target in a [`TargetList`][crate::TargetList].
111    /// ## `target`
112    /// an interned atom representing the target to search for
113    ///
114    /// # Returns
115    ///
116    /// [`true`] if the target was found, otherwise [`false`]
117    ///
118    /// ## `info`
119    /// a pointer to the location to store
120    ///  application info for target, or [`None`]
121    #[doc(alias = "gtk_target_list_find")]
122    pub fn find(&self, target: &gdk::Atom) -> Option<u32> {
123        unsafe {
124            let mut info = mem::MaybeUninit::uninit();
125            let ret = from_glib(ffi::gtk_target_list_find(
126                self.to_glib_none().0,
127                target.to_glib_none().0,
128                info.as_mut_ptr(),
129            ));
130            if ret {
131                Some(info.assume_init())
132            } else {
133                None
134            }
135        }
136    }
137
138    /// Removes a target from a target list.
139    /// ## `target`
140    /// the interned atom representing the target
141    #[doc(alias = "gtk_target_list_remove")]
142    pub fn remove(&self, target: &gdk::Atom) {
143        unsafe {
144            ffi::gtk_target_list_remove(self.to_glib_none().0, target.to_glib_none().0);
145        }
146    }
147}