gtk/auto/selection_data.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 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
10 pub struct SelectionData(Boxed<ffi::GtkSelectionData>);
11
12 match fn {
13 copy => |ptr| ffi::gtk_selection_data_copy(ptr),
14 free => |ptr| ffi::gtk_selection_data_free(ptr),
15 type_ => || ffi::gtk_selection_data_get_type(),
16 }
17}
18
19impl SelectionData {
20 /// Retrieves the data type of the selection.
21 ///
22 /// # Returns
23 ///
24 /// the data type of the selection.
25 #[doc(alias = "gtk_selection_data_get_data_type")]
26 #[doc(alias = "get_data_type")]
27 pub fn data_type(&self) -> gdk::Atom {
28 unsafe { from_glib_none(ffi::gtk_selection_data_get_data_type(self.to_glib_none().0)) }
29 }
30
31 /// Retrieves the display of the selection.
32 ///
33 /// # Returns
34 ///
35 /// the display of the selection.
36 #[doc(alias = "gtk_selection_data_get_display")]
37 #[doc(alias = "get_display")]
38 pub fn display(&self) -> Option<gdk::Display> {
39 unsafe { from_glib_none(ffi::gtk_selection_data_get_display(self.to_glib_none().0)) }
40 }
41
42 /// Retrieves the format of the selection.
43 ///
44 /// # Returns
45 ///
46 /// the format of the selection.
47 #[doc(alias = "gtk_selection_data_get_format")]
48 #[doc(alias = "get_format")]
49 pub fn format(&self) -> i32 {
50 unsafe { ffi::gtk_selection_data_get_format(self.to_glib_none().0) }
51 }
52
53 /// Retrieves the length of the raw data of the selection.
54 ///
55 /// # Returns
56 ///
57 /// the length of the data of the selection.
58 #[doc(alias = "gtk_selection_data_get_length")]
59 #[doc(alias = "get_length")]
60 pub fn length(&self) -> i32 {
61 unsafe { ffi::gtk_selection_data_get_length(self.to_glib_none().0) }
62 }
63
64 /// Gets the contents of the selection data as a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf].
65 ///
66 /// # Returns
67 ///
68 /// if the selection data
69 /// contained a recognized image type and it could be converted to a
70 /// [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf], a newly allocated pixbuf is returned, otherwise
71 /// [`None`]. If the result is non-[`None`] it must be freed with
72 /// `g_object_unref()`.
73 #[doc(alias = "gtk_selection_data_get_pixbuf")]
74 #[doc(alias = "get_pixbuf")]
75 pub fn pixbuf(&self) -> Option<gdk_pixbuf::Pixbuf> {
76 unsafe { from_glib_full(ffi::gtk_selection_data_get_pixbuf(self.to_glib_none().0)) }
77 }
78
79 /// Retrieves the selection [`gdk::Atom`][crate::gdk::Atom] of the selection data.
80 ///
81 /// # Returns
82 ///
83 /// the selection [`gdk::Atom`][crate::gdk::Atom] of the selection data.
84 #[doc(alias = "gtk_selection_data_get_selection")]
85 #[doc(alias = "get_selection")]
86 pub fn selection(&self) -> gdk::Atom {
87 unsafe { from_glib_none(ffi::gtk_selection_data_get_selection(self.to_glib_none().0)) }
88 }
89
90 /// Retrieves the target of the selection.
91 ///
92 /// # Returns
93 ///
94 /// the target of the selection.
95 #[doc(alias = "gtk_selection_data_get_target")]
96 #[doc(alias = "get_target")]
97 pub fn target(&self) -> gdk::Atom {
98 unsafe { from_glib_none(ffi::gtk_selection_data_get_target(self.to_glib_none().0)) }
99 }
100
101 /// Gets the contents of `self` as an array of targets.
102 /// This can be used to interpret the results of getting
103 /// the standard TARGETS target that is always supplied for
104 /// any selection.
105 ///
106 /// # Returns
107 ///
108 /// [`true`] if `self` contains a valid
109 /// array of targets, otherwise [`false`].
110 ///
111 /// ## `targets`
112 ///
113 /// location to store an array of targets. The result stored
114 /// here must be freed with `g_free()`.
115 #[doc(alias = "gtk_selection_data_get_targets")]
116 #[doc(alias = "get_targets")]
117 pub fn targets(&self) -> Option<Vec<gdk::Atom>> {
118 unsafe {
119 let mut targets = std::ptr::null_mut();
120 let mut n_atoms = std::mem::MaybeUninit::uninit();
121 let ret = from_glib(ffi::gtk_selection_data_get_targets(
122 self.to_glib_none().0,
123 &mut targets,
124 n_atoms.as_mut_ptr(),
125 ));
126 if ret {
127 Some(FromGlibContainer::from_glib_container_num(
128 targets,
129 n_atoms.assume_init() as _,
130 ))
131 } else {
132 None
133 }
134 }
135 }
136
137 /// Gets the contents of the selection data as a UTF-8 string.
138 ///
139 /// # Returns
140 ///
141 /// if the selection data contained a
142 /// recognized text type and it could be converted to UTF-8, a newly
143 /// allocated string containing the converted text, otherwise [`None`].
144 /// If the result is non-[`None`] it must be freed with `g_free()`.
145 #[doc(alias = "gtk_selection_data_get_text")]
146 #[doc(alias = "get_text")]
147 pub fn text(&self) -> Option<glib::GString> {
148 unsafe { from_glib_full(ffi::gtk_selection_data_get_text(self.to_glib_none().0)) }
149 }
150
151 /// Gets the contents of the selection data as array of URIs.
152 ///
153 /// Since 3.24.37, this may involve using the FileTransfer
154 /// portal to send files between sandboxed apps.
155 ///
156 /// # Returns
157 ///
158 /// if
159 /// the selection data contains a list of
160 /// URIs, a newly allocated [`None`]-terminated string array
161 /// containing the URIs, otherwise [`None`]. If the result is
162 /// non-[`None`] it must be freed with `g_strfreev()`.
163 #[doc(alias = "gtk_selection_data_get_uris")]
164 #[doc(alias = "get_uris")]
165 pub fn uris(&self) -> Vec<glib::GString> {
166 unsafe {
167 FromGlibPtrContainer::from_glib_full(ffi::gtk_selection_data_get_uris(
168 self.to_glib_none().0,
169 ))
170 }
171 }
172
173 /// Stores new data into a [`SelectionData`][crate::SelectionData] object. Should
174 /// only be called from a selection handler callback.
175 /// Zero-terminates the stored data.
176 /// ## `type_`
177 /// the type of selection data
178 /// ## `format`
179 /// format (number of bits in a unit)
180 /// ## `data`
181 /// pointer to the data (will be copied)
182 #[doc(alias = "gtk_selection_data_set")]
183 pub fn set(&self, type_: &gdk::Atom, format: i32, data: &[u8]) {
184 let length = data.len() as _;
185 unsafe {
186 ffi::gtk_selection_data_set(
187 mut_override(self.to_glib_none().0),
188 type_.to_glib_none().0,
189 format,
190 data.to_glib_none().0,
191 length,
192 );
193 }
194 }
195
196 /// target.
197 /// ## `pixbuf`
198 /// a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf]
199 ///
200 /// # Returns
201 ///
202 /// [`true`] if the selection was successfully set,
203 /// otherwise [`false`].
204 #[doc(alias = "gtk_selection_data_set_pixbuf")]
205 pub fn set_pixbuf(&self, pixbuf: &gdk_pixbuf::Pixbuf) -> bool {
206 unsafe {
207 from_glib(ffi::gtk_selection_data_set_pixbuf(
208 mut_override(self.to_glib_none().0),
209 pixbuf.to_glib_none().0,
210 ))
211 }
212 }
213
214 /// target.
215 /// ## `str`
216 /// a UTF-8 string
217 /// ## `len`
218 /// the length of `str`, or -1 if `str` is nul-terminated.
219 ///
220 /// # Returns
221 ///
222 /// [`true`] if the selection was successfully set,
223 /// otherwise [`false`].
224 #[doc(alias = "gtk_selection_data_set_text")]
225 pub fn set_text(&self, str: &str) -> bool {
226 let len = str.len() as _;
227 unsafe {
228 from_glib(ffi::gtk_selection_data_set_text(
229 mut_override(self.to_glib_none().0),
230 str.to_glib_none().0,
231 len,
232 ))
233 }
234 }
235
236 /// target.
237 ///
238 /// Since 3.24.37, this may involve using the FileTransfer
239 /// portal to send files between sandboxed apps.
240 /// ## `uris`
241 /// a [`None`]-terminated array of
242 /// strings holding URIs
243 ///
244 /// # Returns
245 ///
246 /// [`true`] if the selection was successfully set,
247 /// otherwise [`false`].
248 #[doc(alias = "gtk_selection_data_set_uris")]
249 pub fn set_uris(&self, uris: &[&str]) -> bool {
250 unsafe {
251 from_glib(ffi::gtk_selection_data_set_uris(
252 mut_override(self.to_glib_none().0),
253 uris.to_glib_none().0,
254 ))
255 }
256 }
257
258 /// Given a [`SelectionData`][crate::SelectionData] object holding a list of targets,
259 /// determines if any of the targets in `targets` can be used to
260 /// provide a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf].
261 /// ## `writable`
262 /// whether to accept only targets for which GTK+ knows
263 /// how to convert a pixbuf into the format
264 ///
265 /// # Returns
266 ///
267 /// [`true`] if `self` holds a list of targets,
268 /// and a suitable target for images is included, otherwise [`false`].
269 #[doc(alias = "gtk_selection_data_targets_include_image")]
270 pub fn targets_include_image(&self, writable: bool) -> bool {
271 unsafe {
272 from_glib(ffi::gtk_selection_data_targets_include_image(
273 self.to_glib_none().0,
274 writable.into_glib(),
275 ))
276 }
277 }
278
279 /// Given a [`SelectionData`][crate::SelectionData] object holding a list of targets,
280 /// determines if any of the targets in `targets` can be used to
281 /// provide rich text.
282 /// ## `buffer`
283 /// a [`TextBuffer`][crate::TextBuffer]
284 ///
285 /// # Returns
286 ///
287 /// [`true`] if `self` holds a list of targets,
288 /// and a suitable target for rich text is included,
289 /// otherwise [`false`].
290 #[doc(alias = "gtk_selection_data_targets_include_rich_text")]
291 pub fn targets_include_rich_text(&self, buffer: &impl IsA<TextBuffer>) -> bool {
292 unsafe {
293 from_glib(ffi::gtk_selection_data_targets_include_rich_text(
294 self.to_glib_none().0,
295 buffer.as_ref().to_glib_none().0,
296 ))
297 }
298 }
299
300 /// Given a [`SelectionData`][crate::SelectionData] object holding a list of targets,
301 /// determines if any of the targets in `targets` can be used to
302 /// provide text.
303 ///
304 /// # Returns
305 ///
306 /// [`true`] if `self` holds a list of targets,
307 /// and a suitable target for text is included, otherwise [`false`].
308 #[doc(alias = "gtk_selection_data_targets_include_text")]
309 pub fn targets_include_text(&self) -> bool {
310 unsafe {
311 from_glib(ffi::gtk_selection_data_targets_include_text(
312 self.to_glib_none().0,
313 ))
314 }
315 }
316
317 /// Given a [`SelectionData`][crate::SelectionData] object holding a list of targets,
318 /// determines if any of the targets in `targets` can be used to
319 /// provide a list or URIs.
320 ///
321 /// # Returns
322 ///
323 /// [`true`] if `self` holds a list of targets,
324 /// and a suitable target for URI lists is included, otherwise [`false`].
325 #[doc(alias = "gtk_selection_data_targets_include_uri")]
326 pub fn targets_include_uri(&self) -> bool {
327 unsafe {
328 from_glib(ffi::gtk_selection_data_targets_include_uri(
329 self.to_glib_none().0,
330 ))
331 }
332 }
333}