gtk4/auto/
string_object.rs1use crate::ffi;
6use glib::{
7 prelude::*,
8 signal::{SignalHandlerId, connect_raw},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 #[doc(alias = "GtkStringObject")]
32 pub struct StringObject(Object<ffi::GtkStringObject, ffi::GtkStringObjectClass>);
33
34 match fn {
35 type_ => || ffi::gtk_string_object_get_type(),
36 }
37}
38
39impl StringObject {
40 #[doc(alias = "gtk_string_object_new")]
48 pub fn new(string: &str) -> StringObject {
49 assert_initialized_main_thread!();
50 unsafe { from_glib_full(ffi::gtk_string_object_new(string.to_glib_none().0)) }
51 }
52
53 #[doc(alias = "gtk_string_object_get_string")]
59 #[doc(alias = "get_string")]
60 pub fn string(&self) -> glib::GString {
61 unsafe { from_glib_none(ffi::gtk_string_object_get_string(self.to_glib_none().0)) }
62 }
63
64 #[doc(alias = "string")]
65 pub fn connect_string_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
66 unsafe extern "C" fn notify_string_trampoline<F: Fn(&StringObject) + 'static>(
67 this: *mut ffi::GtkStringObject,
68 _param_spec: glib::ffi::gpointer,
69 f: glib::ffi::gpointer,
70 ) {
71 unsafe {
72 let f: &F = &*(f as *const F);
73 f(&from_glib_borrow(this))
74 }
75 }
76 unsafe {
77 let f: Box_<F> = Box_::new(f);
78 connect_raw(
79 self.as_ptr() as *mut _,
80 c"notify::string".as_ptr() as *const _,
81 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
82 notify_string_trampoline::<F> as *const (),
83 )),
84 Box_::into_raw(f),
85 )
86 }
87 }
88}