gtk/auto/
selection_data.rs1use crate::TextBuffer;
6use glib::{prelude::*, translate::*};
7use std::{mem, ptr};
8
9glib::wrapper! {
10 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
11 pub struct SelectionData(Boxed<ffi::GtkSelectionData>);
12
13 match fn {
14 copy => |ptr| ffi::gtk_selection_data_copy(ptr),
15 free => |ptr| ffi::gtk_selection_data_free(ptr),
16 type_ => || ffi::gtk_selection_data_get_type(),
17 }
18}
19
20impl SelectionData {
21 #[doc(alias = "gtk_selection_data_get_data_type")]
22 #[doc(alias = "get_data_type")]
23 pub fn data_type(&self) -> gdk::Atom {
24 unsafe { from_glib_none(ffi::gtk_selection_data_get_data_type(self.to_glib_none().0)) }
25 }
26
27 #[doc(alias = "gtk_selection_data_get_display")]
28 #[doc(alias = "get_display")]
29 pub fn display(&self) -> Option<gdk::Display> {
30 unsafe { from_glib_none(ffi::gtk_selection_data_get_display(self.to_glib_none().0)) }
31 }
32
33 #[doc(alias = "gtk_selection_data_get_format")]
34 #[doc(alias = "get_format")]
35 pub fn format(&self) -> i32 {
36 unsafe { ffi::gtk_selection_data_get_format(self.to_glib_none().0) }
37 }
38
39 #[doc(alias = "gtk_selection_data_get_length")]
40 #[doc(alias = "get_length")]
41 pub fn length(&self) -> i32 {
42 unsafe { ffi::gtk_selection_data_get_length(self.to_glib_none().0) }
43 }
44
45 #[doc(alias = "gtk_selection_data_get_pixbuf")]
46 #[doc(alias = "get_pixbuf")]
47 pub fn pixbuf(&self) -> Option<gdk_pixbuf::Pixbuf> {
48 unsafe { from_glib_full(ffi::gtk_selection_data_get_pixbuf(self.to_glib_none().0)) }
49 }
50
51 #[doc(alias = "gtk_selection_data_get_selection")]
52 #[doc(alias = "get_selection")]
53 pub fn selection(&self) -> gdk::Atom {
54 unsafe { from_glib_none(ffi::gtk_selection_data_get_selection(self.to_glib_none().0)) }
55 }
56
57 #[doc(alias = "gtk_selection_data_get_target")]
58 #[doc(alias = "get_target")]
59 pub fn target(&self) -> gdk::Atom {
60 unsafe { from_glib_none(ffi::gtk_selection_data_get_target(self.to_glib_none().0)) }
61 }
62
63 #[doc(alias = "gtk_selection_data_get_targets")]
64 #[doc(alias = "get_targets")]
65 pub fn targets(&self) -> Option<Vec<gdk::Atom>> {
66 unsafe {
67 let mut targets = ptr::null_mut();
68 let mut n_atoms = mem::MaybeUninit::uninit();
69 let ret = from_glib(ffi::gtk_selection_data_get_targets(
70 self.to_glib_none().0,
71 &mut targets,
72 n_atoms.as_mut_ptr(),
73 ));
74 if ret {
75 Some(FromGlibContainer::from_glib_container_num(
76 targets,
77 n_atoms.assume_init() as _,
78 ))
79 } else {
80 None
81 }
82 }
83 }
84
85 #[doc(alias = "gtk_selection_data_get_text")]
86 #[doc(alias = "get_text")]
87 pub fn text(&self) -> Option<glib::GString> {
88 unsafe { from_glib_full(ffi::gtk_selection_data_get_text(self.to_glib_none().0)) }
89 }
90
91 #[doc(alias = "gtk_selection_data_get_uris")]
92 #[doc(alias = "get_uris")]
93 pub fn uris(&self) -> Vec<glib::GString> {
94 unsafe {
95 FromGlibPtrContainer::from_glib_full(ffi::gtk_selection_data_get_uris(
96 self.to_glib_none().0,
97 ))
98 }
99 }
100
101 #[doc(alias = "gtk_selection_data_set")]
102 pub fn set(&self, type_: &gdk::Atom, format: i32, data: &[u8]) {
103 let length = data.len() as _;
104 unsafe {
105 ffi::gtk_selection_data_set(
106 mut_override(self.to_glib_none().0),
107 type_.to_glib_none().0,
108 format,
109 data.to_glib_none().0,
110 length,
111 );
112 }
113 }
114
115 #[doc(alias = "gtk_selection_data_set_pixbuf")]
116 pub fn set_pixbuf(&self, pixbuf: &gdk_pixbuf::Pixbuf) -> bool {
117 unsafe {
118 from_glib(ffi::gtk_selection_data_set_pixbuf(
119 mut_override(self.to_glib_none().0),
120 pixbuf.to_glib_none().0,
121 ))
122 }
123 }
124
125 #[doc(alias = "gtk_selection_data_set_text")]
126 pub fn set_text(&self, str: &str) -> bool {
127 let len = str.len() as _;
128 unsafe {
129 from_glib(ffi::gtk_selection_data_set_text(
130 mut_override(self.to_glib_none().0),
131 str.to_glib_none().0,
132 len,
133 ))
134 }
135 }
136
137 #[doc(alias = "gtk_selection_data_set_uris")]
138 pub fn set_uris(&self, uris: &[&str]) -> bool {
139 unsafe {
140 from_glib(ffi::gtk_selection_data_set_uris(
141 mut_override(self.to_glib_none().0),
142 uris.to_glib_none().0,
143 ))
144 }
145 }
146
147 #[doc(alias = "gtk_selection_data_targets_include_image")]
148 pub fn targets_include_image(&self, writable: bool) -> bool {
149 unsafe {
150 from_glib(ffi::gtk_selection_data_targets_include_image(
151 self.to_glib_none().0,
152 writable.into_glib(),
153 ))
154 }
155 }
156
157 #[doc(alias = "gtk_selection_data_targets_include_rich_text")]
158 pub fn targets_include_rich_text(&self, buffer: &impl IsA<TextBuffer>) -> bool {
159 unsafe {
160 from_glib(ffi::gtk_selection_data_targets_include_rich_text(
161 self.to_glib_none().0,
162 buffer.as_ref().to_glib_none().0,
163 ))
164 }
165 }
166
167 #[doc(alias = "gtk_selection_data_targets_include_text")]
168 pub fn targets_include_text(&self) -> bool {
169 unsafe {
170 from_glib(ffi::gtk_selection_data_targets_include_text(
171 self.to_glib_none().0,
172 ))
173 }
174 }
175
176 #[doc(alias = "gtk_selection_data_targets_include_uri")]
177 pub fn targets_include_uri(&self) -> bool {
178 unsafe {
179 from_glib(ffi::gtk_selection_data_targets_include_uri(
180 self.to_glib_none().0,
181 ))
182 }
183 }
184}