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