1#[cfg(feature = "v4_10")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
7use crate::AccessiblePlatformState;
8use crate::{ffi, Accessible, Buildable, ConstraintTarget, Widget};
9use glib::{
10 object::ObjectType as _,
11 prelude::*,
12 signal::{connect_raw, SignalHandlerId},
13 translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18 #[doc(alias = "GtkEditable")]
19 pub struct Editable(Interface<ffi::GtkEditable, ffi::GtkEditableInterface>) @requires Widget, Accessible, Buildable, ConstraintTarget;
20
21 match fn {
22 type_ => || ffi::gtk_editable_get_type(),
23 }
24}
25
26impl Editable {
27 pub const NONE: Option<&'static Editable> = None;
28}
29
30pub trait EditableExt: IsA<Editable> + 'static {
31 #[cfg(feature = "v4_10")]
32 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
33 #[doc(alias = "gtk_editable_delegate_get_accessible_platform_state")]
34 fn delegate_get_accessible_platform_state(&self, state: AccessiblePlatformState) -> bool {
35 unsafe {
36 from_glib(ffi::gtk_editable_delegate_get_accessible_platform_state(
37 self.as_ref().to_glib_none().0,
38 state.into_glib(),
39 ))
40 }
41 }
42
43 #[doc(alias = "gtk_editable_delete_selection")]
44 fn delete_selection(&self) {
45 unsafe {
46 ffi::gtk_editable_delete_selection(self.as_ref().to_glib_none().0);
47 }
48 }
49
50 #[doc(alias = "gtk_editable_delete_text")]
51 fn delete_text(&self, start_pos: i32, end_pos: i32) {
52 unsafe {
53 ffi::gtk_editable_delete_text(self.as_ref().to_glib_none().0, start_pos, end_pos);
54 }
55 }
56
57 #[doc(alias = "gtk_editable_finish_delegate")]
58 fn finish_delegate(&self) {
59 unsafe {
60 ffi::gtk_editable_finish_delegate(self.as_ref().to_glib_none().0);
61 }
62 }
63
64 #[doc(alias = "gtk_editable_get_alignment")]
65 #[doc(alias = "get_alignment")]
66 #[doc(alias = "xalign")]
67 fn alignment(&self) -> f32 {
68 unsafe { ffi::gtk_editable_get_alignment(self.as_ref().to_glib_none().0) }
69 }
70
71 #[doc(alias = "gtk_editable_get_chars")]
72 #[doc(alias = "get_chars")]
73 fn chars(&self, start_pos: i32, end_pos: i32) -> glib::GString {
74 unsafe {
75 from_glib_full(ffi::gtk_editable_get_chars(
76 self.as_ref().to_glib_none().0,
77 start_pos,
78 end_pos,
79 ))
80 }
81 }
82
83 #[doc(alias = "gtk_editable_get_delegate")]
84 #[doc(alias = "get_delegate")]
85 #[must_use]
86 fn delegate(&self) -> Option<Editable> {
87 unsafe {
88 from_glib_none(ffi::gtk_editable_get_delegate(
89 self.as_ref().to_glib_none().0,
90 ))
91 }
92 }
93
94 #[doc(alias = "gtk_editable_get_editable")]
95 #[doc(alias = "get_editable")]
96 #[doc(alias = "editable")]
97 fn is_editable(&self) -> bool {
98 unsafe {
99 from_glib(ffi::gtk_editable_get_editable(
100 self.as_ref().to_glib_none().0,
101 ))
102 }
103 }
104
105 #[doc(alias = "gtk_editable_get_enable_undo")]
106 #[doc(alias = "get_enable_undo")]
107 #[doc(alias = "enable-undo")]
108 fn enables_undo(&self) -> bool {
109 unsafe {
110 from_glib(ffi::gtk_editable_get_enable_undo(
111 self.as_ref().to_glib_none().0,
112 ))
113 }
114 }
115
116 #[doc(alias = "gtk_editable_get_max_width_chars")]
117 #[doc(alias = "get_max_width_chars")]
118 #[doc(alias = "max-width-chars")]
119 fn max_width_chars(&self) -> i32 {
120 unsafe { ffi::gtk_editable_get_max_width_chars(self.as_ref().to_glib_none().0) }
121 }
122
123 #[doc(alias = "gtk_editable_get_position")]
124 #[doc(alias = "get_position")]
125 #[doc(alias = "cursor-position")]
126 fn position(&self) -> i32 {
127 unsafe { ffi::gtk_editable_get_position(self.as_ref().to_glib_none().0) }
128 }
129
130 #[doc(alias = "gtk_editable_get_selection_bounds")]
131 #[doc(alias = "get_selection_bounds")]
132 fn selection_bounds(&self) -> Option<(i32, i32)> {
133 unsafe {
134 let mut start_pos = std::mem::MaybeUninit::uninit();
135 let mut end_pos = std::mem::MaybeUninit::uninit();
136 let ret = from_glib(ffi::gtk_editable_get_selection_bounds(
137 self.as_ref().to_glib_none().0,
138 start_pos.as_mut_ptr(),
139 end_pos.as_mut_ptr(),
140 ));
141 if ret {
142 Some((start_pos.assume_init(), end_pos.assume_init()))
143 } else {
144 None
145 }
146 }
147 }
148
149 #[doc(alias = "gtk_editable_get_text")]
150 #[doc(alias = "get_text")]
151 fn text(&self) -> glib::GString {
152 unsafe { from_glib_none(ffi::gtk_editable_get_text(self.as_ref().to_glib_none().0)) }
153 }
154
155 #[doc(alias = "gtk_editable_get_width_chars")]
156 #[doc(alias = "get_width_chars")]
157 #[doc(alias = "width-chars")]
158 fn width_chars(&self) -> i32 {
159 unsafe { ffi::gtk_editable_get_width_chars(self.as_ref().to_glib_none().0) }
160 }
161
162 #[doc(alias = "gtk_editable_init_delegate")]
163 fn init_delegate(&self) {
164 unsafe {
165 ffi::gtk_editable_init_delegate(self.as_ref().to_glib_none().0);
166 }
167 }
168
169 #[doc(alias = "gtk_editable_insert_text")]
170 fn insert_text(&self, text: &str, position: &mut i32) {
171 let length = text.len() as _;
172 unsafe {
173 ffi::gtk_editable_insert_text(
174 self.as_ref().to_glib_none().0,
175 text.to_glib_none().0,
176 length,
177 position,
178 );
179 }
180 }
181
182 #[doc(alias = "gtk_editable_select_region")]
183 fn select_region(&self, start_pos: i32, end_pos: i32) {
184 unsafe {
185 ffi::gtk_editable_select_region(self.as_ref().to_glib_none().0, start_pos, end_pos);
186 }
187 }
188
189 #[doc(alias = "gtk_editable_set_alignment")]
190 #[doc(alias = "xalign")]
191 fn set_alignment(&self, xalign: f32) {
192 unsafe {
193 ffi::gtk_editable_set_alignment(self.as_ref().to_glib_none().0, xalign);
194 }
195 }
196
197 #[doc(alias = "gtk_editable_set_editable")]
198 #[doc(alias = "editable")]
199 fn set_editable(&self, is_editable: bool) {
200 unsafe {
201 ffi::gtk_editable_set_editable(self.as_ref().to_glib_none().0, is_editable.into_glib());
202 }
203 }
204
205 #[doc(alias = "gtk_editable_set_enable_undo")]
206 #[doc(alias = "enable-undo")]
207 fn set_enable_undo(&self, enable_undo: bool) {
208 unsafe {
209 ffi::gtk_editable_set_enable_undo(
210 self.as_ref().to_glib_none().0,
211 enable_undo.into_glib(),
212 );
213 }
214 }
215
216 #[doc(alias = "gtk_editable_set_max_width_chars")]
217 #[doc(alias = "max-width-chars")]
218 fn set_max_width_chars(&self, n_chars: i32) {
219 unsafe {
220 ffi::gtk_editable_set_max_width_chars(self.as_ref().to_glib_none().0, n_chars);
221 }
222 }
223
224 #[doc(alias = "gtk_editable_set_position")]
225 #[doc(alias = "cursor-position")]
226 fn set_position(&self, position: i32) {
227 unsafe {
228 ffi::gtk_editable_set_position(self.as_ref().to_glib_none().0, position);
229 }
230 }
231
232 #[doc(alias = "gtk_editable_set_text")]
233 #[doc(alias = "text")]
234 fn set_text(&self, text: &str) {
235 unsafe {
236 ffi::gtk_editable_set_text(self.as_ref().to_glib_none().0, text.to_glib_none().0);
237 }
238 }
239
240 #[doc(alias = "gtk_editable_set_width_chars")]
241 #[doc(alias = "width-chars")]
242 fn set_width_chars(&self, n_chars: i32) {
243 unsafe {
244 ffi::gtk_editable_set_width_chars(self.as_ref().to_glib_none().0, n_chars);
245 }
246 }
247
248 #[doc(alias = "selection-bound")]
249 fn selection_bound(&self) -> i32 {
250 ObjectExt::property(self.as_ref(), "selection-bound")
251 }
252
253 #[doc(alias = "changed")]
254 fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
255 unsafe extern "C" fn changed_trampoline<P: IsA<Editable>, F: Fn(&P) + 'static>(
256 this: *mut ffi::GtkEditable,
257 f: glib::ffi::gpointer,
258 ) {
259 let f: &F = &*(f as *const F);
260 f(Editable::from_glib_borrow(this).unsafe_cast_ref())
261 }
262 unsafe {
263 let f: Box_<F> = Box_::new(f);
264 connect_raw(
265 self.as_ptr() as *mut _,
266 c"changed".as_ptr() as *const _,
267 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
268 changed_trampoline::<Self, F> as *const (),
269 )),
270 Box_::into_raw(f),
271 )
272 }
273 }
274
275 #[doc(alias = "delete-text")]
276 fn connect_delete_text<F: Fn(&Self, i32, i32) + 'static>(&self, f: F) -> SignalHandlerId {
277 unsafe extern "C" fn delete_text_trampoline<
278 P: IsA<Editable>,
279 F: Fn(&P, i32, i32) + 'static,
280 >(
281 this: *mut ffi::GtkEditable,
282 start_pos: std::ffi::c_int,
283 end_pos: std::ffi::c_int,
284 f: glib::ffi::gpointer,
285 ) {
286 let f: &F = &*(f as *const F);
287 f(
288 Editable::from_glib_borrow(this).unsafe_cast_ref(),
289 start_pos,
290 end_pos,
291 )
292 }
293 unsafe {
294 let f: Box_<F> = Box_::new(f);
295 connect_raw(
296 self.as_ptr() as *mut _,
297 c"delete-text".as_ptr() as *const _,
298 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
299 delete_text_trampoline::<Self, F> as *const (),
300 )),
301 Box_::into_raw(f),
302 )
303 }
304 }
305
306 #[doc(alias = "cursor-position")]
307 fn connect_cursor_position_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
308 unsafe extern "C" fn notify_cursor_position_trampoline<
309 P: IsA<Editable>,
310 F: Fn(&P) + 'static,
311 >(
312 this: *mut ffi::GtkEditable,
313 _param_spec: glib::ffi::gpointer,
314 f: glib::ffi::gpointer,
315 ) {
316 let f: &F = &*(f as *const F);
317 f(Editable::from_glib_borrow(this).unsafe_cast_ref())
318 }
319 unsafe {
320 let f: Box_<F> = Box_::new(f);
321 connect_raw(
322 self.as_ptr() as *mut _,
323 c"notify::cursor-position".as_ptr() as *const _,
324 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
325 notify_cursor_position_trampoline::<Self, F> as *const (),
326 )),
327 Box_::into_raw(f),
328 )
329 }
330 }
331
332 #[doc(alias = "editable")]
333 fn connect_editable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
334 unsafe extern "C" fn notify_editable_trampoline<P: IsA<Editable>, F: Fn(&P) + 'static>(
335 this: *mut ffi::GtkEditable,
336 _param_spec: glib::ffi::gpointer,
337 f: glib::ffi::gpointer,
338 ) {
339 let f: &F = &*(f as *const F);
340 f(Editable::from_glib_borrow(this).unsafe_cast_ref())
341 }
342 unsafe {
343 let f: Box_<F> = Box_::new(f);
344 connect_raw(
345 self.as_ptr() as *mut _,
346 c"notify::editable".as_ptr() as *const _,
347 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
348 notify_editable_trampoline::<Self, F> as *const (),
349 )),
350 Box_::into_raw(f),
351 )
352 }
353 }
354
355 #[doc(alias = "enable-undo")]
356 fn connect_enable_undo_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
357 unsafe extern "C" fn notify_enable_undo_trampoline<
358 P: IsA<Editable>,
359 F: Fn(&P) + 'static,
360 >(
361 this: *mut ffi::GtkEditable,
362 _param_spec: glib::ffi::gpointer,
363 f: glib::ffi::gpointer,
364 ) {
365 let f: &F = &*(f as *const F);
366 f(Editable::from_glib_borrow(this).unsafe_cast_ref())
367 }
368 unsafe {
369 let f: Box_<F> = Box_::new(f);
370 connect_raw(
371 self.as_ptr() as *mut _,
372 c"notify::enable-undo".as_ptr() as *const _,
373 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
374 notify_enable_undo_trampoline::<Self, F> as *const (),
375 )),
376 Box_::into_raw(f),
377 )
378 }
379 }
380
381 #[doc(alias = "max-width-chars")]
382 fn connect_max_width_chars_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
383 unsafe extern "C" fn notify_max_width_chars_trampoline<
384 P: IsA<Editable>,
385 F: Fn(&P) + 'static,
386 >(
387 this: *mut ffi::GtkEditable,
388 _param_spec: glib::ffi::gpointer,
389 f: glib::ffi::gpointer,
390 ) {
391 let f: &F = &*(f as *const F);
392 f(Editable::from_glib_borrow(this).unsafe_cast_ref())
393 }
394 unsafe {
395 let f: Box_<F> = Box_::new(f);
396 connect_raw(
397 self.as_ptr() as *mut _,
398 c"notify::max-width-chars".as_ptr() as *const _,
399 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
400 notify_max_width_chars_trampoline::<Self, F> as *const (),
401 )),
402 Box_::into_raw(f),
403 )
404 }
405 }
406
407 #[doc(alias = "selection-bound")]
408 fn connect_selection_bound_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
409 unsafe extern "C" fn notify_selection_bound_trampoline<
410 P: IsA<Editable>,
411 F: Fn(&P) + 'static,
412 >(
413 this: *mut ffi::GtkEditable,
414 _param_spec: glib::ffi::gpointer,
415 f: glib::ffi::gpointer,
416 ) {
417 let f: &F = &*(f as *const F);
418 f(Editable::from_glib_borrow(this).unsafe_cast_ref())
419 }
420 unsafe {
421 let f: Box_<F> = Box_::new(f);
422 connect_raw(
423 self.as_ptr() as *mut _,
424 c"notify::selection-bound".as_ptr() as *const _,
425 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
426 notify_selection_bound_trampoline::<Self, F> as *const (),
427 )),
428 Box_::into_raw(f),
429 )
430 }
431 }
432
433 #[doc(alias = "text")]
434 fn connect_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
435 unsafe extern "C" fn notify_text_trampoline<P: IsA<Editable>, F: Fn(&P) + 'static>(
436 this: *mut ffi::GtkEditable,
437 _param_spec: glib::ffi::gpointer,
438 f: glib::ffi::gpointer,
439 ) {
440 let f: &F = &*(f as *const F);
441 f(Editable::from_glib_borrow(this).unsafe_cast_ref())
442 }
443 unsafe {
444 let f: Box_<F> = Box_::new(f);
445 connect_raw(
446 self.as_ptr() as *mut _,
447 c"notify::text".as_ptr() as *const _,
448 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
449 notify_text_trampoline::<Self, F> as *const (),
450 )),
451 Box_::into_raw(f),
452 )
453 }
454 }
455
456 #[doc(alias = "width-chars")]
457 fn connect_width_chars_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
458 unsafe extern "C" fn notify_width_chars_trampoline<
459 P: IsA<Editable>,
460 F: Fn(&P) + 'static,
461 >(
462 this: *mut ffi::GtkEditable,
463 _param_spec: glib::ffi::gpointer,
464 f: glib::ffi::gpointer,
465 ) {
466 let f: &F = &*(f as *const F);
467 f(Editable::from_glib_borrow(this).unsafe_cast_ref())
468 }
469 unsafe {
470 let f: Box_<F> = Box_::new(f);
471 connect_raw(
472 self.as_ptr() as *mut _,
473 c"notify::width-chars".as_ptr() as *const _,
474 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
475 notify_width_chars_trampoline::<Self, F> as *const (),
476 )),
477 Box_::into_raw(f),
478 )
479 }
480 }
481
482 #[doc(alias = "xalign")]
483 fn connect_xalign_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
484 unsafe extern "C" fn notify_xalign_trampoline<P: IsA<Editable>, F: Fn(&P) + 'static>(
485 this: *mut ffi::GtkEditable,
486 _param_spec: glib::ffi::gpointer,
487 f: glib::ffi::gpointer,
488 ) {
489 let f: &F = &*(f as *const F);
490 f(Editable::from_glib_borrow(this).unsafe_cast_ref())
491 }
492 unsafe {
493 let f: Box_<F> = Box_::new(f);
494 connect_raw(
495 self.as_ptr() as *mut _,
496 c"notify::xalign".as_ptr() as *const _,
497 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
498 notify_xalign_trampoline::<Self, F> as *const (),
499 )),
500 Box_::into_raw(f),
501 )
502 }
503 }
504}
505
506impl<O: IsA<Editable>> EditableExt for O {}