1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT

use crate::Accessible;
use crate::Buildable;
use crate::ConstraintTarget;
use crate::Widget;
use glib::object::IsA;
use glib::translate::*;
use std::fmt;
use std::mem;

glib::wrapper! {
    /// [`Native`][crate::Native] is the interface implemented by all widgets that have
    /// their own [`gdk::Surface`][crate::gdk::Surface].
    ///
    /// The obvious example of a [`Native`][crate::Native] is [`Window`][crate::Window].
    ///
    /// Every widget that is not itself a [`Native`][crate::Native] is contained in one,
    /// and you can get it with [`WidgetExt::native()`][crate::prelude::WidgetExt::native()].
    ///
    /// To get the surface of a [`Native`][crate::Native], use [`NativeExt::surface()`][crate::prelude::NativeExt::surface()].
    /// It is also possible to find the [`Native`][crate::Native] to which a surface
    /// belongs, with [`for_surface()`][Self::for_surface()].
    ///
    /// In addition to a [`gdk::Surface`][crate::gdk::Surface], a [`Native`][crate::Native] also provides
    /// a [`gsk::Renderer`][crate::gsk::Renderer] for rendering on that surface. To get the
    /// renderer, use [`NativeExt::renderer()`][crate::prelude::NativeExt::renderer()].
    ///
    /// # Implements
    ///
    /// [`NativeExt`][trait@crate::prelude::NativeExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual]
    #[doc(alias = "GtkNative")]
    pub struct Native(Interface<ffi::GtkNative, ffi::GtkNativeInterface>) @requires Widget, Accessible, Buildable, ConstraintTarget;

    match fn {
        type_ => || ffi::gtk_native_get_type(),
    }
}

impl Native {
    pub const NONE: Option<&'static Native> = None;

    /// Finds the [`Native`][crate::Native] associated with the surface.
    /// ## `surface`
    /// a [`gdk::Surface`][crate::gdk::Surface]
    ///
    /// # Returns
    ///
    /// the [`Native`][crate::Native] that is associated with @surface
    #[doc(alias = "gtk_native_get_for_surface")]
    #[doc(alias = "get_for_surface")]
    pub fn for_surface(surface: &impl IsA<gdk::Surface>) -> Option<Native> {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_none(ffi::gtk_native_get_for_surface(
                surface.as_ref().to_glib_none().0,
            ))
        }
    }
}

/// Trait containing all [`struct@Native`] methods.
///
/// # Implementors
///
/// [`AboutDialog`][struct@crate::AboutDialog], [`AppChooserDialog`][struct@crate::AppChooserDialog], [`ApplicationWindow`][struct@crate::ApplicationWindow], [`Assistant`][struct@crate::Assistant], [`ColorChooserDialog`][struct@crate::ColorChooserDialog], [`Dialog`][struct@crate::Dialog], [`DragIcon`][struct@crate::DragIcon], [`EmojiChooser`][struct@crate::EmojiChooser], [`FileChooserDialog`][struct@crate::FileChooserDialog], [`FontChooserDialog`][struct@crate::FontChooserDialog], [`MessageDialog`][struct@crate::MessageDialog], [`Native`][struct@crate::Native], [`PageSetupUnixDialog`][struct@crate::PageSetupUnixDialog], [`PopoverMenu`][struct@crate::PopoverMenu], [`Popover`][struct@crate::Popover], [`PrintUnixDialog`][struct@crate::PrintUnixDialog], [`Root`][struct@crate::Root], [`ShortcutsWindow`][struct@crate::ShortcutsWindow], [`Window`][struct@crate::Window]
pub trait NativeExt: 'static {
    /// Returns the renderer that is used for this [`Native`][crate::Native].
    ///
    /// # Returns
    ///
    /// the renderer for @self
    #[doc(alias = "gtk_native_get_renderer")]
    #[doc(alias = "get_renderer")]
    fn renderer(&self) -> gsk::Renderer;

    /// Returns the surface of this [`Native`][crate::Native].
    ///
    /// # Returns
    ///
    /// the surface of @self
    #[doc(alias = "gtk_native_get_surface")]
    #[doc(alias = "get_surface")]
    fn surface(&self) -> gdk::Surface;

    /// Retrieves the surface transform of @self.
    ///
    /// This is the translation from @self's surface coordinates into
    /// @self's widget coordinates.
    ///
    /// # Returns
    ///
    ///
    /// ## `x`
    /// return location for the x coordinate
    ///
    /// ## `y`
    /// return location for the y coordinate
    #[doc(alias = "gtk_native_get_surface_transform")]
    #[doc(alias = "get_surface_transform")]
    fn surface_transform(&self) -> (f64, f64);
}

impl<O: IsA<Native>> NativeExt for O {
    fn renderer(&self) -> gsk::Renderer {
        unsafe { from_glib_none(ffi::gtk_native_get_renderer(self.as_ref().to_glib_none().0)) }
    }

    fn surface(&self) -> gdk::Surface {
        unsafe { from_glib_none(ffi::gtk_native_get_surface(self.as_ref().to_glib_none().0)) }
    }

    fn surface_transform(&self) -> (f64, f64) {
        unsafe {
            let mut x = mem::MaybeUninit::uninit();
            let mut y = mem::MaybeUninit::uninit();
            ffi::gtk_native_get_surface_transform(
                self.as_ref().to_glib_none().0,
                x.as_mut_ptr(),
                y.as_mut_ptr(),
            );
            (x.assume_init(), y.assume_init())
        }
    }
}

impl fmt::Display for Native {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("Native")
    }
}