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