1#![allow(deprecated)]
5
6#[cfg(feature = "v4_20")]
7#[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
8use crate::WindowGravity;
9use crate::{
10 ffi, Accessible, AccessibleRole, Align, Application, Buildable, ConstraintTarget,
11 LayoutManager, Native, Overflow, Root, ShortcutManager, ShortcutsWindow, Widget, Window,
12};
13use glib::{
14 prelude::*,
15 signal::{connect_raw, SignalHandlerId},
16 translate::*,
17};
18use std::boxed::Box as Box_;
19
20glib::wrapper! {
21 #[doc(alias = "GtkApplicationWindow")]
22 pub struct ApplicationWindow(Object<ffi::GtkApplicationWindow, ffi::GtkApplicationWindowClass>) @extends Window, Widget, @implements Accessible, Buildable, ConstraintTarget, Native, Root, ShortcutManager, gio::ActionGroup, gio::ActionMap;
23
24 match fn {
25 type_ => || ffi::gtk_application_window_get_type(),
26 }
27}
28
29impl ApplicationWindow {
30 pub const NONE: Option<&'static ApplicationWindow> = None;
31
32 #[doc(alias = "gtk_application_window_new")]
33 pub fn new(application: &impl IsA<Application>) -> ApplicationWindow {
34 skip_assert_initialized!();
35 unsafe {
36 Widget::from_glib_none(ffi::gtk_application_window_new(
37 application.as_ref().to_glib_none().0,
38 ))
39 .unsafe_cast()
40 }
41 }
42
43 pub fn builder() -> ApplicationWindowBuilder {
48 ApplicationWindowBuilder::new()
49 }
50}
51
52impl Default for ApplicationWindow {
53 fn default() -> Self {
54 glib::object::Object::new::<Self>()
55 }
56}
57
58#[must_use = "The builder must be built to be used"]
63pub struct ApplicationWindowBuilder {
64 builder: glib::object::ObjectBuilder<'static, ApplicationWindow>,
65}
66
67impl ApplicationWindowBuilder {
68 fn new() -> Self {
69 Self {
70 builder: glib::object::Object::builder(),
71 }
72 }
73
74 pub fn show_menubar(self, show_menubar: bool) -> Self {
75 Self {
76 builder: self.builder.property("show-menubar", show_menubar),
77 }
78 }
79
80 pub fn application(self, application: &impl IsA<Application>) -> Self {
81 Self {
82 builder: self
83 .builder
84 .property("application", application.clone().upcast()),
85 }
86 }
87
88 pub fn child(self, child: &impl IsA<Widget>) -> Self {
89 Self {
90 builder: self.builder.property("child", child.clone().upcast()),
91 }
92 }
93
94 pub fn decorated(self, decorated: bool) -> Self {
95 Self {
96 builder: self.builder.property("decorated", decorated),
97 }
98 }
99
100 pub fn default_height(self, default_height: i32) -> Self {
101 Self {
102 builder: self.builder.property("default-height", default_height),
103 }
104 }
105
106 pub fn default_widget(self, default_widget: &impl IsA<Widget>) -> Self {
107 Self {
108 builder: self
109 .builder
110 .property("default-widget", default_widget.clone().upcast()),
111 }
112 }
113
114 pub fn default_width(self, default_width: i32) -> Self {
115 Self {
116 builder: self.builder.property("default-width", default_width),
117 }
118 }
119
120 pub fn deletable(self, deletable: bool) -> Self {
121 Self {
122 builder: self.builder.property("deletable", deletable),
123 }
124 }
125
126 pub fn destroy_with_parent(self, destroy_with_parent: bool) -> Self {
127 Self {
128 builder: self
129 .builder
130 .property("destroy-with-parent", destroy_with_parent),
131 }
132 }
133
134 pub fn display(self, display: &impl IsA<gdk::Display>) -> Self {
135 Self {
136 builder: self.builder.property("display", display.clone().upcast()),
137 }
138 }
139
140 pub fn focus_visible(self, focus_visible: bool) -> Self {
141 Self {
142 builder: self.builder.property("focus-visible", focus_visible),
143 }
144 }
145
146 pub fn focus_widget(self, focus_widget: &impl IsA<Widget>) -> Self {
147 Self {
148 builder: self
149 .builder
150 .property("focus-widget", focus_widget.clone().upcast()),
151 }
152 }
153
154 pub fn fullscreened(self, fullscreened: bool) -> Self {
155 Self {
156 builder: self.builder.property("fullscreened", fullscreened),
157 }
158 }
159
160 #[cfg(feature = "v4_20")]
161 #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
162 pub fn gravity(self, gravity: WindowGravity) -> Self {
163 Self {
164 builder: self.builder.property("gravity", gravity),
165 }
166 }
167
168 #[cfg(feature = "v4_2")]
169 #[cfg_attr(docsrs, doc(cfg(feature = "v4_2")))]
170 pub fn handle_menubar_accel(self, handle_menubar_accel: bool) -> Self {
171 Self {
172 builder: self
173 .builder
174 .property("handle-menubar-accel", handle_menubar_accel),
175 }
176 }
177
178 pub fn hide_on_close(self, hide_on_close: bool) -> Self {
179 Self {
180 builder: self.builder.property("hide-on-close", hide_on_close),
181 }
182 }
183
184 pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
185 Self {
186 builder: self.builder.property("icon-name", icon_name.into()),
187 }
188 }
189
190 pub fn maximized(self, maximized: bool) -> Self {
191 Self {
192 builder: self.builder.property("maximized", maximized),
193 }
194 }
195
196 pub fn mnemonics_visible(self, mnemonics_visible: bool) -> Self {
197 Self {
198 builder: self
199 .builder
200 .property("mnemonics-visible", mnemonics_visible),
201 }
202 }
203
204 pub fn modal(self, modal: bool) -> Self {
205 Self {
206 builder: self.builder.property("modal", modal),
207 }
208 }
209
210 pub fn resizable(self, resizable: bool) -> Self {
211 Self {
212 builder: self.builder.property("resizable", resizable),
213 }
214 }
215
216 pub fn startup_id(self, startup_id: impl Into<glib::GString>) -> Self {
217 Self {
218 builder: self.builder.property("startup-id", startup_id.into()),
219 }
220 }
221
222 pub fn title(self, title: impl Into<glib::GString>) -> Self {
223 Self {
224 builder: self.builder.property("title", title.into()),
225 }
226 }
227
228 #[cfg(feature = "v4_6")]
229 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
230 pub fn titlebar(self, titlebar: &impl IsA<Widget>) -> Self {
231 Self {
232 builder: self.builder.property("titlebar", titlebar.clone().upcast()),
233 }
234 }
235
236 pub fn transient_for(self, transient_for: &impl IsA<Window>) -> Self {
237 Self {
238 builder: self
239 .builder
240 .property("transient-for", transient_for.clone().upcast()),
241 }
242 }
243
244 pub fn can_focus(self, can_focus: bool) -> Self {
245 Self {
246 builder: self.builder.property("can-focus", can_focus),
247 }
248 }
249
250 pub fn can_target(self, can_target: bool) -> Self {
251 Self {
252 builder: self.builder.property("can-target", can_target),
253 }
254 }
255
256 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
257 Self {
258 builder: self.builder.property("css-classes", css_classes.into()),
259 }
260 }
261
262 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
263 Self {
264 builder: self.builder.property("css-name", css_name.into()),
265 }
266 }
267
268 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
269 Self {
270 builder: self.builder.property("cursor", cursor.clone()),
271 }
272 }
273
274 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
275 Self {
276 builder: self.builder.property("focus-on-click", focus_on_click),
277 }
278 }
279
280 pub fn focusable(self, focusable: bool) -> Self {
281 Self {
282 builder: self.builder.property("focusable", focusable),
283 }
284 }
285
286 pub fn halign(self, halign: Align) -> Self {
287 Self {
288 builder: self.builder.property("halign", halign),
289 }
290 }
291
292 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
293 Self {
294 builder: self.builder.property("has-tooltip", has_tooltip),
295 }
296 }
297
298 pub fn height_request(self, height_request: i32) -> Self {
299 Self {
300 builder: self.builder.property("height-request", height_request),
301 }
302 }
303
304 pub fn hexpand(self, hexpand: bool) -> Self {
305 Self {
306 builder: self.builder.property("hexpand", hexpand),
307 }
308 }
309
310 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
311 Self {
312 builder: self.builder.property("hexpand-set", hexpand_set),
313 }
314 }
315
316 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
317 Self {
318 builder: self
319 .builder
320 .property("layout-manager", layout_manager.clone().upcast()),
321 }
322 }
323
324 #[cfg(feature = "v4_18")]
325 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
326 pub fn limit_events(self, limit_events: bool) -> Self {
327 Self {
328 builder: self.builder.property("limit-events", limit_events),
329 }
330 }
331
332 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
333 Self {
334 builder: self.builder.property("margin-bottom", margin_bottom),
335 }
336 }
337
338 pub fn margin_end(self, margin_end: i32) -> Self {
339 Self {
340 builder: self.builder.property("margin-end", margin_end),
341 }
342 }
343
344 pub fn margin_start(self, margin_start: i32) -> Self {
345 Self {
346 builder: self.builder.property("margin-start", margin_start),
347 }
348 }
349
350 pub fn margin_top(self, margin_top: i32) -> Self {
351 Self {
352 builder: self.builder.property("margin-top", margin_top),
353 }
354 }
355
356 pub fn name(self, name: impl Into<glib::GString>) -> Self {
357 Self {
358 builder: self.builder.property("name", name.into()),
359 }
360 }
361
362 pub fn opacity(self, opacity: f64) -> Self {
363 Self {
364 builder: self.builder.property("opacity", opacity),
365 }
366 }
367
368 pub fn overflow(self, overflow: Overflow) -> Self {
369 Self {
370 builder: self.builder.property("overflow", overflow),
371 }
372 }
373
374 pub fn receives_default(self, receives_default: bool) -> Self {
375 Self {
376 builder: self.builder.property("receives-default", receives_default),
377 }
378 }
379
380 pub fn sensitive(self, sensitive: bool) -> Self {
381 Self {
382 builder: self.builder.property("sensitive", sensitive),
383 }
384 }
385
386 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
387 Self {
388 builder: self
389 .builder
390 .property("tooltip-markup", tooltip_markup.into()),
391 }
392 }
393
394 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
395 Self {
396 builder: self.builder.property("tooltip-text", tooltip_text.into()),
397 }
398 }
399
400 pub fn valign(self, valign: Align) -> Self {
401 Self {
402 builder: self.builder.property("valign", valign),
403 }
404 }
405
406 pub fn vexpand(self, vexpand: bool) -> Self {
407 Self {
408 builder: self.builder.property("vexpand", vexpand),
409 }
410 }
411
412 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
413 Self {
414 builder: self.builder.property("vexpand-set", vexpand_set),
415 }
416 }
417
418 pub fn visible(self, visible: bool) -> Self {
419 Self {
420 builder: self.builder.property("visible", visible),
421 }
422 }
423
424 pub fn width_request(self, width_request: i32) -> Self {
425 Self {
426 builder: self.builder.property("width-request", width_request),
427 }
428 }
429
430 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
431 Self {
432 builder: self.builder.property("accessible-role", accessible_role),
433 }
434 }
435
436 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
439 pub fn build(self) -> ApplicationWindow {
440 assert_initialized_main_thread!();
441 self.builder.build()
442 }
443}
444
445pub trait ApplicationWindowExt: IsA<ApplicationWindow> + 'static {
446 #[cfg_attr(feature = "v4_18", deprecated = "Since 4.18")]
447 #[allow(deprecated)]
448 #[doc(alias = "gtk_application_window_get_help_overlay")]
449 #[doc(alias = "get_help_overlay")]
450 fn help_overlay(&self) -> Option<ShortcutsWindow> {
451 unsafe {
452 from_glib_none(ffi::gtk_application_window_get_help_overlay(
453 self.as_ref().to_glib_none().0,
454 ))
455 }
456 }
457
458 #[doc(alias = "gtk_application_window_get_id")]
459 #[doc(alias = "get_id")]
460 fn id(&self) -> u32 {
461 unsafe { ffi::gtk_application_window_get_id(self.as_ref().to_glib_none().0) }
462 }
463
464 #[doc(alias = "gtk_application_window_get_show_menubar")]
465 #[doc(alias = "get_show_menubar")]
466 #[doc(alias = "show-menubar")]
467 fn shows_menubar(&self) -> bool {
468 unsafe {
469 from_glib(ffi::gtk_application_window_get_show_menubar(
470 self.as_ref().to_glib_none().0,
471 ))
472 }
473 }
474
475 #[cfg_attr(feature = "v4_18", deprecated = "Since 4.18")]
476 #[allow(deprecated)]
477 #[doc(alias = "gtk_application_window_set_help_overlay")]
478 fn set_help_overlay(&self, help_overlay: Option<&ShortcutsWindow>) {
479 unsafe {
480 ffi::gtk_application_window_set_help_overlay(
481 self.as_ref().to_glib_none().0,
482 help_overlay.to_glib_none().0,
483 );
484 }
485 }
486
487 #[doc(alias = "gtk_application_window_set_show_menubar")]
488 #[doc(alias = "show-menubar")]
489 fn set_show_menubar(&self, show_menubar: bool) {
490 unsafe {
491 ffi::gtk_application_window_set_show_menubar(
492 self.as_ref().to_glib_none().0,
493 show_menubar.into_glib(),
494 );
495 }
496 }
497
498 #[doc(alias = "show-menubar")]
499 fn connect_show_menubar_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
500 unsafe extern "C" fn notify_show_menubar_trampoline<
501 P: IsA<ApplicationWindow>,
502 F: Fn(&P) + 'static,
503 >(
504 this: *mut ffi::GtkApplicationWindow,
505 _param_spec: glib::ffi::gpointer,
506 f: glib::ffi::gpointer,
507 ) {
508 let f: &F = &*(f as *const F);
509 f(ApplicationWindow::from_glib_borrow(this).unsafe_cast_ref())
510 }
511 unsafe {
512 let f: Box_<F> = Box_::new(f);
513 connect_raw(
514 self.as_ptr() as *mut _,
515 c"notify::show-menubar".as_ptr() as *const _,
516 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
517 notify_show_menubar_trampoline::<Self, F> as *const (),
518 )),
519 Box_::into_raw(f),
520 )
521 }
522 }
523}
524
525impl<O: IsA<ApplicationWindow>> ApplicationWindowExt for O {}