gtk4/auto/
application_window.rs

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