1use crate::{
6 ffi, Accessible, AccessibleRole, Align, Buildable, ConstraintTarget, LayoutManager, Overflow,
7 Widget,
8};
9use glib::{
10 prelude::*,
11 signal::{connect_raw, SignalHandlerId},
12 translate::*,
13};
14use std::boxed::Box as Box_;
15
16glib::wrapper! {
17 #[doc(alias = "GtkWindowHandle")]
18 pub struct WindowHandle(Object<ffi::GtkWindowHandle, ffi::GtkWindowHandleClass>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget;
19
20 match fn {
21 type_ => || ffi::gtk_window_handle_get_type(),
22 }
23}
24
25impl WindowHandle {
26 #[doc(alias = "gtk_window_handle_new")]
27 pub fn new() -> WindowHandle {
28 assert_initialized_main_thread!();
29 unsafe { Widget::from_glib_none(ffi::gtk_window_handle_new()).unsafe_cast() }
30 }
31
32 pub fn builder() -> WindowHandleBuilder {
37 WindowHandleBuilder::new()
38 }
39
40 #[doc(alias = "gtk_window_handle_get_child")]
41 #[doc(alias = "get_child")]
42 pub fn child(&self) -> Option<Widget> {
43 unsafe { from_glib_none(ffi::gtk_window_handle_get_child(self.to_glib_none().0)) }
44 }
45
46 #[doc(alias = "gtk_window_handle_set_child")]
47 #[doc(alias = "child")]
48 pub fn set_child(&self, child: Option<&impl IsA<Widget>>) {
49 unsafe {
50 ffi::gtk_window_handle_set_child(
51 self.to_glib_none().0,
52 child.map(|p| p.as_ref()).to_glib_none().0,
53 );
54 }
55 }
56
57 #[doc(alias = "child")]
58 pub fn connect_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
59 unsafe extern "C" fn notify_child_trampoline<F: Fn(&WindowHandle) + 'static>(
60 this: *mut ffi::GtkWindowHandle,
61 _param_spec: glib::ffi::gpointer,
62 f: glib::ffi::gpointer,
63 ) {
64 let f: &F = &*(f as *const F);
65 f(&from_glib_borrow(this))
66 }
67 unsafe {
68 let f: Box_<F> = Box_::new(f);
69 connect_raw(
70 self.as_ptr() as *mut _,
71 b"notify::child\0".as_ptr() as *const _,
72 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
73 notify_child_trampoline::<F> as *const (),
74 )),
75 Box_::into_raw(f),
76 )
77 }
78 }
79}
80
81impl Default for WindowHandle {
82 fn default() -> Self {
83 Self::new()
84 }
85}
86
87#[must_use = "The builder must be built to be used"]
92pub struct WindowHandleBuilder {
93 builder: glib::object::ObjectBuilder<'static, WindowHandle>,
94}
95
96impl WindowHandleBuilder {
97 fn new() -> Self {
98 Self {
99 builder: glib::object::Object::builder(),
100 }
101 }
102
103 pub fn child(self, child: &impl IsA<Widget>) -> Self {
104 Self {
105 builder: self.builder.property("child", child.clone().upcast()),
106 }
107 }
108
109 pub fn can_focus(self, can_focus: bool) -> Self {
110 Self {
111 builder: self.builder.property("can-focus", can_focus),
112 }
113 }
114
115 pub fn can_target(self, can_target: bool) -> Self {
116 Self {
117 builder: self.builder.property("can-target", can_target),
118 }
119 }
120
121 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
122 Self {
123 builder: self.builder.property("css-classes", css_classes.into()),
124 }
125 }
126
127 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
128 Self {
129 builder: self.builder.property("css-name", css_name.into()),
130 }
131 }
132
133 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
134 Self {
135 builder: self.builder.property("cursor", cursor.clone()),
136 }
137 }
138
139 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
140 Self {
141 builder: self.builder.property("focus-on-click", focus_on_click),
142 }
143 }
144
145 pub fn focusable(self, focusable: bool) -> Self {
146 Self {
147 builder: self.builder.property("focusable", focusable),
148 }
149 }
150
151 pub fn halign(self, halign: Align) -> Self {
152 Self {
153 builder: self.builder.property("halign", halign),
154 }
155 }
156
157 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
158 Self {
159 builder: self.builder.property("has-tooltip", has_tooltip),
160 }
161 }
162
163 pub fn height_request(self, height_request: i32) -> Self {
164 Self {
165 builder: self.builder.property("height-request", height_request),
166 }
167 }
168
169 pub fn hexpand(self, hexpand: bool) -> Self {
170 Self {
171 builder: self.builder.property("hexpand", hexpand),
172 }
173 }
174
175 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
176 Self {
177 builder: self.builder.property("hexpand-set", hexpand_set),
178 }
179 }
180
181 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
182 Self {
183 builder: self
184 .builder
185 .property("layout-manager", layout_manager.clone().upcast()),
186 }
187 }
188
189 #[cfg(feature = "v4_18")]
190 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
191 pub fn limit_events(self, limit_events: bool) -> Self {
192 Self {
193 builder: self.builder.property("limit-events", limit_events),
194 }
195 }
196
197 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
198 Self {
199 builder: self.builder.property("margin-bottom", margin_bottom),
200 }
201 }
202
203 pub fn margin_end(self, margin_end: i32) -> Self {
204 Self {
205 builder: self.builder.property("margin-end", margin_end),
206 }
207 }
208
209 pub fn margin_start(self, margin_start: i32) -> Self {
210 Self {
211 builder: self.builder.property("margin-start", margin_start),
212 }
213 }
214
215 pub fn margin_top(self, margin_top: i32) -> Self {
216 Self {
217 builder: self.builder.property("margin-top", margin_top),
218 }
219 }
220
221 pub fn name(self, name: impl Into<glib::GString>) -> Self {
222 Self {
223 builder: self.builder.property("name", name.into()),
224 }
225 }
226
227 pub fn opacity(self, opacity: f64) -> Self {
228 Self {
229 builder: self.builder.property("opacity", opacity),
230 }
231 }
232
233 pub fn overflow(self, overflow: Overflow) -> Self {
234 Self {
235 builder: self.builder.property("overflow", overflow),
236 }
237 }
238
239 pub fn receives_default(self, receives_default: bool) -> Self {
240 Self {
241 builder: self.builder.property("receives-default", receives_default),
242 }
243 }
244
245 pub fn sensitive(self, sensitive: bool) -> Self {
246 Self {
247 builder: self.builder.property("sensitive", sensitive),
248 }
249 }
250
251 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
252 Self {
253 builder: self
254 .builder
255 .property("tooltip-markup", tooltip_markup.into()),
256 }
257 }
258
259 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
260 Self {
261 builder: self.builder.property("tooltip-text", tooltip_text.into()),
262 }
263 }
264
265 pub fn valign(self, valign: Align) -> Self {
266 Self {
267 builder: self.builder.property("valign", valign),
268 }
269 }
270
271 pub fn vexpand(self, vexpand: bool) -> Self {
272 Self {
273 builder: self.builder.property("vexpand", vexpand),
274 }
275 }
276
277 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
278 Self {
279 builder: self.builder.property("vexpand-set", vexpand_set),
280 }
281 }
282
283 pub fn visible(self, visible: bool) -> Self {
284 Self {
285 builder: self.builder.property("visible", visible),
286 }
287 }
288
289 pub fn width_request(self, width_request: i32) -> Self {
290 Self {
291 builder: self.builder.property("width-request", width_request),
292 }
293 }
294
295 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
296 Self {
297 builder: self.builder.property("accessible-role", accessible_role),
298 }
299 }
300
301 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
304 pub fn build(self) -> WindowHandle {
305 assert_initialized_main_thread!();
306 self.builder.build()
307 }
308}