gtk4/auto/
color_chooser.rs1#![allow(deprecated)]
5
6use crate::ffi;
7use glib::{
8 object::ObjectType as _,
9 prelude::*,
10 signal::{connect_raw, SignalHandlerId},
11 translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16 #[doc(alias = "GtkColorChooser")]
17 pub struct ColorChooser(Interface<ffi::GtkColorChooser, ffi::GtkColorChooserInterface>);
18
19 match fn {
20 type_ => || ffi::gtk_color_chooser_get_type(),
21 }
22}
23
24impl ColorChooser {
25 pub const NONE: Option<&'static ColorChooser> = None;
26}
27
28pub trait ColorChooserExt: IsA<ColorChooser> + 'static {
29 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
30 #[allow(deprecated)]
31 #[doc(alias = "gtk_color_chooser_get_rgba")]
32 #[doc(alias = "get_rgba")]
33 fn rgba(&self) -> gdk::RGBA {
34 unsafe {
35 let mut color = gdk::RGBA::uninitialized();
36 ffi::gtk_color_chooser_get_rgba(
37 self.as_ref().to_glib_none().0,
38 color.to_glib_none_mut().0,
39 );
40 color
41 }
42 }
43
44 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
45 #[allow(deprecated)]
46 #[doc(alias = "gtk_color_chooser_get_use_alpha")]
47 #[doc(alias = "get_use_alpha")]
48 #[doc(alias = "use-alpha")]
49 fn uses_alpha(&self) -> bool {
50 unsafe {
51 from_glib(ffi::gtk_color_chooser_get_use_alpha(
52 self.as_ref().to_glib_none().0,
53 ))
54 }
55 }
56
57 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
58 #[allow(deprecated)]
59 #[doc(alias = "gtk_color_chooser_set_rgba")]
60 #[doc(alias = "rgba")]
61 fn set_rgba(&self, color: &gdk::RGBA) {
62 unsafe {
63 ffi::gtk_color_chooser_set_rgba(self.as_ref().to_glib_none().0, color.to_glib_none().0);
64 }
65 }
66
67 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
68 #[allow(deprecated)]
69 #[doc(alias = "gtk_color_chooser_set_use_alpha")]
70 #[doc(alias = "use-alpha")]
71 fn set_use_alpha(&self, use_alpha: bool) {
72 unsafe {
73 ffi::gtk_color_chooser_set_use_alpha(
74 self.as_ref().to_glib_none().0,
75 use_alpha.into_glib(),
76 );
77 }
78 }
79
80 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
81 #[doc(alias = "color-activated")]
82 fn connect_color_activated<F: Fn(&Self, &gdk::RGBA) + 'static>(&self, f: F) -> SignalHandlerId {
83 unsafe extern "C" fn color_activated_trampoline<
84 P: IsA<ColorChooser>,
85 F: Fn(&P, &gdk::RGBA) + 'static,
86 >(
87 this: *mut ffi::GtkColorChooser,
88 color: *mut gdk::ffi::GdkRGBA,
89 f: glib::ffi::gpointer,
90 ) {
91 let f: &F = &*(f as *const F);
92 f(
93 ColorChooser::from_glib_borrow(this).unsafe_cast_ref(),
94 &from_glib_borrow(color),
95 )
96 }
97 unsafe {
98 let f: Box_<F> = Box_::new(f);
99 connect_raw(
100 self.as_ptr() as *mut _,
101 c"color-activated".as_ptr() as *const _,
102 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
103 color_activated_trampoline::<Self, F> as *const (),
104 )),
105 Box_::into_raw(f),
106 )
107 }
108 }
109
110 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
111 #[doc(alias = "rgba")]
112 fn connect_rgba_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
113 unsafe extern "C" fn notify_rgba_trampoline<P: IsA<ColorChooser>, F: Fn(&P) + 'static>(
114 this: *mut ffi::GtkColorChooser,
115 _param_spec: glib::ffi::gpointer,
116 f: glib::ffi::gpointer,
117 ) {
118 let f: &F = &*(f as *const F);
119 f(ColorChooser::from_glib_borrow(this).unsafe_cast_ref())
120 }
121 unsafe {
122 let f: Box_<F> = Box_::new(f);
123 connect_raw(
124 self.as_ptr() as *mut _,
125 c"notify::rgba".as_ptr() as *const _,
126 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
127 notify_rgba_trampoline::<Self, F> as *const (),
128 )),
129 Box_::into_raw(f),
130 )
131 }
132 }
133
134 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
135 #[doc(alias = "use-alpha")]
136 fn connect_use_alpha_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
137 unsafe extern "C" fn notify_use_alpha_trampoline<
138 P: IsA<ColorChooser>,
139 F: Fn(&P) + 'static,
140 >(
141 this: *mut ffi::GtkColorChooser,
142 _param_spec: glib::ffi::gpointer,
143 f: glib::ffi::gpointer,
144 ) {
145 let f: &F = &*(f as *const F);
146 f(ColorChooser::from_glib_borrow(this).unsafe_cast_ref())
147 }
148 unsafe {
149 let f: Box_<F> = Box_::new(f);
150 connect_raw(
151 self.as_ptr() as *mut _,
152 c"notify::use-alpha".as_ptr() as *const _,
153 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
154 notify_use_alpha_trampoline::<Self, F> as *const (),
155 )),
156 Box_::into_raw(f),
157 )
158 }
159 }
160}
161
162impl<O: IsA<ColorChooser>> ColorChooserExt for O {}