1use crate::ffi;
7#[cfg(feature = "v1_4")]
8#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
9use crate::Breakpoint;
10#[cfg(feature = "v1_5")]
11#[cfg_attr(docsrs, doc(cfg(feature = "v1_5")))]
12use crate::Dialog;
13use glib::{
14 prelude::*,
15 signal::{connect_raw, SignalHandlerId},
16 translate::*,
17};
18use std::boxed::Box as Box_;
19
20glib::wrapper! {
21 #[doc(alias = "AdwApplicationWindow")]
22 pub struct ApplicationWindow(Object<ffi::AdwApplicationWindow, ffi::AdwApplicationWindowClass>) @extends gtk::ApplicationWindow, gtk::Window, gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Native, gtk::Root, gtk::ShortcutManager, gio::ActionGroup, gio::ActionMap;
23
24 match fn {
25 type_ => || ffi::adw_application_window_get_type(),
26 }
27}
28
29impl ApplicationWindow {
30 pub const NONE: Option<&'static ApplicationWindow> = None;
31
32 #[doc(alias = "adw_application_window_new")]
33 pub fn new(app: &impl IsA<gtk::Application>) -> ApplicationWindow {
34 assert_initialized_main_thread!();
35 unsafe {
36 gtk::Widget::from_glib_none(ffi::adw_application_window_new(
37 app.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 #[cfg(feature = "v1_7")]
75 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
76 pub fn adaptive_preview(self, adaptive_preview: bool) -> Self {
77 Self {
78 builder: self.builder.property("adaptive-preview", adaptive_preview),
79 }
80 }
81
82 pub fn content(self, content: &impl IsA<gtk::Widget>) -> Self {
83 Self {
84 builder: self.builder.property("content", content.clone().upcast()),
85 }
86 }
87
88 pub fn show_menubar(self, show_menubar: bool) -> Self {
89 Self {
90 builder: self.builder.property("show-menubar", show_menubar),
91 }
92 }
93
94 pub fn application(self, application: &impl IsA<gtk::Application>) -> Self {
95 Self {
96 builder: self
97 .builder
98 .property("application", application.clone().upcast()),
99 }
100 }
101
102 pub fn decorated(self, decorated: bool) -> Self {
103 Self {
104 builder: self.builder.property("decorated", decorated),
105 }
106 }
107
108 pub fn default_height(self, default_height: i32) -> Self {
109 Self {
110 builder: self.builder.property("default-height", default_height),
111 }
112 }
113
114 pub fn default_widget(self, default_widget: &impl IsA<gtk::Widget>) -> Self {
115 Self {
116 builder: self
117 .builder
118 .property("default-widget", default_widget.clone().upcast()),
119 }
120 }
121
122 pub fn default_width(self, default_width: i32) -> Self {
123 Self {
124 builder: self.builder.property("default-width", default_width),
125 }
126 }
127
128 pub fn deletable(self, deletable: bool) -> Self {
129 Self {
130 builder: self.builder.property("deletable", deletable),
131 }
132 }
133
134 pub fn destroy_with_parent(self, destroy_with_parent: bool) -> Self {
135 Self {
136 builder: self
137 .builder
138 .property("destroy-with-parent", destroy_with_parent),
139 }
140 }
141
142 pub fn display(self, display: &gdk::Display) -> Self {
143 Self {
144 builder: self.builder.property("display", display.clone()),
145 }
146 }
147
148 pub fn focus_visible(self, focus_visible: bool) -> Self {
149 Self {
150 builder: self.builder.property("focus-visible", focus_visible),
151 }
152 }
153
154 pub fn focus_widget(self, focus_widget: &impl IsA<gtk::Widget>) -> Self {
155 Self {
156 builder: self
157 .builder
158 .property("focus-widget", focus_widget.clone().upcast()),
159 }
160 }
161
162 pub fn fullscreened(self, fullscreened: bool) -> Self {
163 Self {
164 builder: self.builder.property("fullscreened", fullscreened),
165 }
166 }
167
168 #[cfg(feature = "gtk_v4_20")]
169 #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_20")))]
170 pub fn gravity(self, gravity: gtk::WindowGravity) -> Self {
171 Self {
172 builder: self.builder.property("gravity", gravity),
173 }
174 }
175
176 #[cfg(feature = "gtk_v4_2")]
177 #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_2")))]
178 pub fn handle_menubar_accel(self, handle_menubar_accel: bool) -> Self {
179 Self {
180 builder: self
181 .builder
182 .property("handle-menubar-accel", handle_menubar_accel),
183 }
184 }
185
186 pub fn hide_on_close(self, hide_on_close: bool) -> Self {
187 Self {
188 builder: self.builder.property("hide-on-close", hide_on_close),
189 }
190 }
191
192 pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
193 Self {
194 builder: self.builder.property("icon-name", icon_name.into()),
195 }
196 }
197
198 pub fn maximized(self, maximized: bool) -> Self {
199 Self {
200 builder: self.builder.property("maximized", maximized),
201 }
202 }
203
204 pub fn mnemonics_visible(self, mnemonics_visible: bool) -> Self {
205 Self {
206 builder: self
207 .builder
208 .property("mnemonics-visible", mnemonics_visible),
209 }
210 }
211
212 pub fn modal(self, modal: bool) -> Self {
213 Self {
214 builder: self.builder.property("modal", modal),
215 }
216 }
217
218 pub fn resizable(self, resizable: bool) -> Self {
219 Self {
220 builder: self.builder.property("resizable", resizable),
221 }
222 }
223
224 pub fn startup_id(self, startup_id: impl Into<glib::GString>) -> Self {
225 Self {
226 builder: self.builder.property("startup-id", startup_id.into()),
227 }
228 }
229
230 pub fn title(self, title: impl Into<glib::GString>) -> Self {
231 Self {
232 builder: self.builder.property("title", title.into()),
233 }
234 }
235
236 #[cfg(feature = "gtk_v4_6")]
237 #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_6")))]
238 pub fn titlebar(self, titlebar: &impl IsA<gtk::Widget>) -> Self {
239 Self {
240 builder: self.builder.property("titlebar", titlebar.clone().upcast()),
241 }
242 }
243
244 pub fn transient_for(self, transient_for: &impl IsA<gtk::Window>) -> Self {
245 Self {
246 builder: self
247 .builder
248 .property("transient-for", transient_for.clone().upcast()),
249 }
250 }
251
252 pub fn can_focus(self, can_focus: bool) -> Self {
253 Self {
254 builder: self.builder.property("can-focus", can_focus),
255 }
256 }
257
258 pub fn can_target(self, can_target: bool) -> Self {
259 Self {
260 builder: self.builder.property("can-target", can_target),
261 }
262 }
263
264 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
265 Self {
266 builder: self.builder.property("css-classes", css_classes.into()),
267 }
268 }
269
270 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
271 Self {
272 builder: self.builder.property("css-name", css_name.into()),
273 }
274 }
275
276 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
277 Self {
278 builder: self.builder.property("cursor", cursor.clone()),
279 }
280 }
281
282 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
283 Self {
284 builder: self.builder.property("focus-on-click", focus_on_click),
285 }
286 }
287
288 pub fn focusable(self, focusable: bool) -> Self {
289 Self {
290 builder: self.builder.property("focusable", focusable),
291 }
292 }
293
294 pub fn halign(self, halign: gtk::Align) -> Self {
295 Self {
296 builder: self.builder.property("halign", halign),
297 }
298 }
299
300 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
301 Self {
302 builder: self.builder.property("has-tooltip", has_tooltip),
303 }
304 }
305
306 pub fn height_request(self, height_request: i32) -> Self {
307 Self {
308 builder: self.builder.property("height-request", height_request),
309 }
310 }
311
312 pub fn hexpand(self, hexpand: bool) -> Self {
313 Self {
314 builder: self.builder.property("hexpand", hexpand),
315 }
316 }
317
318 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
319 Self {
320 builder: self.builder.property("hexpand-set", hexpand_set),
321 }
322 }
323
324 pub fn layout_manager(self, layout_manager: &impl IsA<gtk::LayoutManager>) -> Self {
325 Self {
326 builder: self
327 .builder
328 .property("layout-manager", layout_manager.clone().upcast()),
329 }
330 }
331
332 #[cfg(feature = "gtk_v4_18")]
333 #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_18")))]
334 pub fn limit_events(self, limit_events: bool) -> Self {
335 Self {
336 builder: self.builder.property("limit-events", limit_events),
337 }
338 }
339
340 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
341 Self {
342 builder: self.builder.property("margin-bottom", margin_bottom),
343 }
344 }
345
346 pub fn margin_end(self, margin_end: i32) -> Self {
347 Self {
348 builder: self.builder.property("margin-end", margin_end),
349 }
350 }
351
352 pub fn margin_start(self, margin_start: i32) -> Self {
353 Self {
354 builder: self.builder.property("margin-start", margin_start),
355 }
356 }
357
358 pub fn margin_top(self, margin_top: i32) -> Self {
359 Self {
360 builder: self.builder.property("margin-top", margin_top),
361 }
362 }
363
364 pub fn name(self, name: impl Into<glib::GString>) -> Self {
365 Self {
366 builder: self.builder.property("name", name.into()),
367 }
368 }
369
370 pub fn opacity(self, opacity: f64) -> Self {
371 Self {
372 builder: self.builder.property("opacity", opacity),
373 }
374 }
375
376 pub fn overflow(self, overflow: gtk::Overflow) -> Self {
377 Self {
378 builder: self.builder.property("overflow", overflow),
379 }
380 }
381
382 pub fn receives_default(self, receives_default: bool) -> Self {
383 Self {
384 builder: self.builder.property("receives-default", receives_default),
385 }
386 }
387
388 pub fn sensitive(self, sensitive: bool) -> Self {
389 Self {
390 builder: self.builder.property("sensitive", sensitive),
391 }
392 }
393
394 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
395 Self {
396 builder: self
397 .builder
398 .property("tooltip-markup", tooltip_markup.into()),
399 }
400 }
401
402 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
403 Self {
404 builder: self.builder.property("tooltip-text", tooltip_text.into()),
405 }
406 }
407
408 pub fn valign(self, valign: gtk::Align) -> Self {
409 Self {
410 builder: self.builder.property("valign", valign),
411 }
412 }
413
414 pub fn vexpand(self, vexpand: bool) -> Self {
415 Self {
416 builder: self.builder.property("vexpand", vexpand),
417 }
418 }
419
420 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
421 Self {
422 builder: self.builder.property("vexpand-set", vexpand_set),
423 }
424 }
425
426 pub fn visible(self, visible: bool) -> Self {
427 Self {
428 builder: self.builder.property("visible", visible),
429 }
430 }
431
432 pub fn width_request(self, width_request: i32) -> Self {
433 Self {
434 builder: self.builder.property("width-request", width_request),
435 }
436 }
437
438 pub fn accessible_role(self, accessible_role: gtk::AccessibleRole) -> Self {
439 Self {
440 builder: self.builder.property("accessible-role", accessible_role),
441 }
442 }
443
444 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
447 pub fn build(self) -> ApplicationWindow {
448 assert_initialized_main_thread!();
449 self.builder.build()
450 }
451}
452
453pub trait AdwApplicationWindowExt: IsA<ApplicationWindow> + 'static {
454 #[cfg(feature = "v1_4")]
455 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
456 #[doc(alias = "adw_application_window_add_breakpoint")]
457 fn add_breakpoint(&self, breakpoint: Breakpoint) {
458 unsafe {
459 ffi::adw_application_window_add_breakpoint(
460 self.as_ref().to_glib_none().0,
461 breakpoint.into_glib_ptr(),
462 );
463 }
464 }
465
466 #[cfg(feature = "v1_7")]
467 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
468 #[doc(alias = "adw_application_window_get_adaptive_preview")]
469 #[doc(alias = "get_adaptive_preview")]
470 #[doc(alias = "adaptive-preview")]
471 fn is_adaptive_preview(&self) -> bool {
472 unsafe {
473 from_glib(ffi::adw_application_window_get_adaptive_preview(
474 self.as_ref().to_glib_none().0,
475 ))
476 }
477 }
478
479 #[doc(alias = "adw_application_window_get_content")]
480 #[doc(alias = "get_content")]
481 fn content(&self) -> Option<gtk::Widget> {
482 unsafe {
483 from_glib_none(ffi::adw_application_window_get_content(
484 self.as_ref().to_glib_none().0,
485 ))
486 }
487 }
488
489 #[cfg(feature = "v1_4")]
490 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
491 #[doc(alias = "adw_application_window_get_current_breakpoint")]
492 #[doc(alias = "get_current_breakpoint")]
493 #[doc(alias = "current-breakpoint")]
494 fn current_breakpoint(&self) -> Option<Breakpoint> {
495 unsafe {
496 from_glib_none(ffi::adw_application_window_get_current_breakpoint(
497 self.as_ref().to_glib_none().0,
498 ))
499 }
500 }
501
502 #[cfg(feature = "v1_5")]
503 #[cfg_attr(docsrs, doc(cfg(feature = "v1_5")))]
504 #[doc(alias = "adw_application_window_get_dialogs")]
505 #[doc(alias = "get_dialogs")]
506 fn dialogs(&self) -> gio::ListModel {
507 unsafe {
508 from_glib_full(ffi::adw_application_window_get_dialogs(
509 self.as_ref().to_glib_none().0,
510 ))
511 }
512 }
513
514 #[cfg(feature = "v1_5")]
515 #[cfg_attr(docsrs, doc(cfg(feature = "v1_5")))]
516 #[doc(alias = "adw_application_window_get_visible_dialog")]
517 #[doc(alias = "get_visible_dialog")]
518 #[doc(alias = "visible-dialog")]
519 fn visible_dialog(&self) -> Option<Dialog> {
520 unsafe {
521 from_glib_none(ffi::adw_application_window_get_visible_dialog(
522 self.as_ref().to_glib_none().0,
523 ))
524 }
525 }
526
527 #[cfg(feature = "v1_7")]
528 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
529 #[doc(alias = "adw_application_window_set_adaptive_preview")]
530 #[doc(alias = "adaptive-preview")]
531 fn set_adaptive_preview(&self, adaptive_preview: bool) {
532 unsafe {
533 ffi::adw_application_window_set_adaptive_preview(
534 self.as_ref().to_glib_none().0,
535 adaptive_preview.into_glib(),
536 );
537 }
538 }
539
540 #[doc(alias = "adw_application_window_set_content")]
541 #[doc(alias = "content")]
542 fn set_content(&self, content: Option<&impl IsA<gtk::Widget>>) {
543 unsafe {
544 ffi::adw_application_window_set_content(
545 self.as_ref().to_glib_none().0,
546 content.map(|p| p.as_ref()).to_glib_none().0,
547 );
548 }
549 }
550
551 #[cfg(feature = "v1_7")]
552 #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
553 #[doc(alias = "adaptive-preview")]
554 fn connect_adaptive_preview_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
555 unsafe extern "C" fn notify_adaptive_preview_trampoline<
556 P: IsA<ApplicationWindow>,
557 F: Fn(&P) + 'static,
558 >(
559 this: *mut ffi::AdwApplicationWindow,
560 _param_spec: glib::ffi::gpointer,
561 f: glib::ffi::gpointer,
562 ) {
563 let f: &F = &*(f as *const F);
564 f(ApplicationWindow::from_glib_borrow(this).unsafe_cast_ref())
565 }
566 unsafe {
567 let f: Box_<F> = Box_::new(f);
568 connect_raw(
569 self.as_ptr() as *mut _,
570 c"notify::adaptive-preview".as_ptr() as *const _,
571 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
572 notify_adaptive_preview_trampoline::<Self, F> as *const (),
573 )),
574 Box_::into_raw(f),
575 )
576 }
577 }
578
579 #[doc(alias = "content")]
580 fn connect_content_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
581 unsafe extern "C" fn notify_content_trampoline<
582 P: IsA<ApplicationWindow>,
583 F: Fn(&P) + 'static,
584 >(
585 this: *mut ffi::AdwApplicationWindow,
586 _param_spec: glib::ffi::gpointer,
587 f: glib::ffi::gpointer,
588 ) {
589 let f: &F = &*(f as *const F);
590 f(ApplicationWindow::from_glib_borrow(this).unsafe_cast_ref())
591 }
592 unsafe {
593 let f: Box_<F> = Box_::new(f);
594 connect_raw(
595 self.as_ptr() as *mut _,
596 c"notify::content".as_ptr() as *const _,
597 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
598 notify_content_trampoline::<Self, F> as *const (),
599 )),
600 Box_::into_raw(f),
601 )
602 }
603 }
604
605 #[cfg(feature = "v1_4")]
606 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
607 #[doc(alias = "current-breakpoint")]
608 fn connect_current_breakpoint_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
609 unsafe extern "C" fn notify_current_breakpoint_trampoline<
610 P: IsA<ApplicationWindow>,
611 F: Fn(&P) + 'static,
612 >(
613 this: *mut ffi::AdwApplicationWindow,
614 _param_spec: glib::ffi::gpointer,
615 f: glib::ffi::gpointer,
616 ) {
617 let f: &F = &*(f as *const F);
618 f(ApplicationWindow::from_glib_borrow(this).unsafe_cast_ref())
619 }
620 unsafe {
621 let f: Box_<F> = Box_::new(f);
622 connect_raw(
623 self.as_ptr() as *mut _,
624 c"notify::current-breakpoint".as_ptr() as *const _,
625 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
626 notify_current_breakpoint_trampoline::<Self, F> as *const (),
627 )),
628 Box_::into_raw(f),
629 )
630 }
631 }
632
633 #[cfg(feature = "v1_5")]
634 #[cfg_attr(docsrs, doc(cfg(feature = "v1_5")))]
635 #[doc(alias = "dialogs")]
636 fn connect_dialogs_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
637 unsafe extern "C" fn notify_dialogs_trampoline<
638 P: IsA<ApplicationWindow>,
639 F: Fn(&P) + 'static,
640 >(
641 this: *mut ffi::AdwApplicationWindow,
642 _param_spec: glib::ffi::gpointer,
643 f: glib::ffi::gpointer,
644 ) {
645 let f: &F = &*(f as *const F);
646 f(ApplicationWindow::from_glib_borrow(this).unsafe_cast_ref())
647 }
648 unsafe {
649 let f: Box_<F> = Box_::new(f);
650 connect_raw(
651 self.as_ptr() as *mut _,
652 c"notify::dialogs".as_ptr() as *const _,
653 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
654 notify_dialogs_trampoline::<Self, F> as *const (),
655 )),
656 Box_::into_raw(f),
657 )
658 }
659 }
660
661 #[cfg(feature = "v1_5")]
662 #[cfg_attr(docsrs, doc(cfg(feature = "v1_5")))]
663 #[doc(alias = "visible-dialog")]
664 fn connect_visible_dialog_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
665 unsafe extern "C" fn notify_visible_dialog_trampoline<
666 P: IsA<ApplicationWindow>,
667 F: Fn(&P) + 'static,
668 >(
669 this: *mut ffi::AdwApplicationWindow,
670 _param_spec: glib::ffi::gpointer,
671 f: glib::ffi::gpointer,
672 ) {
673 let f: &F = &*(f as *const F);
674 f(ApplicationWindow::from_glib_borrow(this).unsafe_cast_ref())
675 }
676 unsafe {
677 let f: Box_<F> = Box_::new(f);
678 connect_raw(
679 self.as_ptr() as *mut _,
680 c"notify::visible-dialog".as_ptr() as *const _,
681 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
682 notify_visible_dialog_trampoline::<Self, F> as *const (),
683 )),
684 Box_::into_raw(f),
685 )
686 }
687 }
688}
689
690impl<O: IsA<ApplicationWindow>> AdwApplicationWindowExt for O {}