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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::CoordType;
use glib::object::IsA;
use glib::translate::*;
use std::fmt;
use std::mem;

glib::wrapper! {
    /// The ATK Interface implemented by components
    ///  which expose image or pixmap content on-screen.
    ///
    /// [`Image`][crate::Image] should be implemented by [`Object`][crate::Object] subtypes on behalf of
    /// components which display image/pixmap information onscreen, and
    /// which provide information (other than just widget borders, etc.)
    /// via that image content. For instance, icons, buttons with icons,
    /// toolbar elements, and image viewing panes typically should
    /// implement [`Image`][crate::Image].
    ///
    /// [`Image`][crate::Image] primarily provides two types of information: coordinate
    /// information (useful for screen review mode of screenreaders, and
    /// for use by onscreen magnifiers), and descriptive information. The
    /// descriptive information is provided for alternative, text-only
    /// presentation of the most significant information present in the
    /// image.
    ///
    /// # Implements
    ///
    /// [`AtkImageExt`][trait@crate::prelude::AtkImageExt]
    #[doc(alias = "AtkImage")]
    pub struct Image(Interface<ffi::AtkImage, ffi::AtkImageIface>);

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

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

/// Trait containing all [`struct@Image`] methods.
///
/// # Implementors
///
/// [`Image`][struct@crate::Image], [`NoOpObject`][struct@crate::NoOpObject]
pub trait AtkImageExt: 'static {
    /// Get a textual description of this image.
    ///
    /// # Returns
    ///
    /// a string representing the image description
    #[doc(alias = "atk_image_get_image_description")]
    #[doc(alias = "get_image_description")]
    fn image_description(&self) -> Option<glib::GString>;

    /// Retrieves the locale identifier associated to the [`Image`][crate::Image].
    ///
    /// # Returns
    ///
    /// a string corresponding to the POSIX
    ///  `LC_MESSAGES` locale used by the image description, or
    ///  [`None`] if the image does not specify a locale.
    #[doc(alias = "atk_image_get_image_locale")]
    #[doc(alias = "get_image_locale")]
    fn image_locale(&self) -> Option<glib::GString>;

    /// Gets the position of the image in the form of a point specifying the
    /// images top-left corner.
    ///
    /// If the position can not be obtained (e.g. missing support), x and y are set
    /// to -1.
    /// ## `coord_type`
    /// specifies whether the coordinates are relative to the screen
    /// or to the components top level window
    ///
    /// # Returns
    ///
    ///
    /// ## `x`
    /// address of `gint` to put x coordinate position; otherwise, -1 if value cannot be obtained.
    ///
    /// ## `y`
    /// address of `gint` to put y coordinate position; otherwise, -1 if value cannot be obtained.
    #[doc(alias = "atk_image_get_image_position")]
    #[doc(alias = "get_image_position")]
    fn image_position(&self, coord_type: CoordType) -> (i32, i32);

    /// Get the width and height in pixels for the specified image.
    /// The values of `width` and `height` are returned as -1 if the
    /// values cannot be obtained (for instance, if the object is not onscreen).
    ///
    /// If the size can not be obtained (e.g. missing support), x and y are set
    /// to -1.
    ///
    /// # Returns
    ///
    ///
    /// ## `width`
    /// filled with the image width, or -1 if the value cannot be obtained.
    ///
    /// ## `height`
    /// filled with the image height, or -1 if the value cannot be obtained.
    #[doc(alias = "atk_image_get_image_size")]
    #[doc(alias = "get_image_size")]
    fn image_size(&self) -> (i32, i32);

    /// Sets the textual description for this image.
    /// ## `description`
    /// a string description to set for `self`
    ///
    /// # Returns
    ///
    /// boolean TRUE, or FALSE if operation could
    /// not be completed.
    #[doc(alias = "atk_image_set_image_description")]
    fn set_image_description(&self, description: &str) -> bool;
}

impl<O: IsA<Image>> AtkImageExt for O {
    fn image_description(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::atk_image_get_image_description(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn image_locale(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::atk_image_get_image_locale(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn image_position(&self, coord_type: CoordType) -> (i32, i32) {
        unsafe {
            let mut x = mem::MaybeUninit::uninit();
            let mut y = mem::MaybeUninit::uninit();
            ffi::atk_image_get_image_position(
                self.as_ref().to_glib_none().0,
                x.as_mut_ptr(),
                y.as_mut_ptr(),
                coord_type.into_glib(),
            );
            (x.assume_init(), y.assume_init())
        }
    }

    fn image_size(&self) -> (i32, i32) {
        unsafe {
            let mut width = mem::MaybeUninit::uninit();
            let mut height = mem::MaybeUninit::uninit();
            ffi::atk_image_get_image_size(
                self.as_ref().to_glib_none().0,
                width.as_mut_ptr(),
                height.as_mut_ptr(),
            );
            (width.assume_init(), height.assume_init())
        }
    }

    fn set_image_description(&self, description: &str) -> bool {
        unsafe {
            from_glib(ffi::atk_image_set_image_description(
                self.as_ref().to_glib_none().0,
                description.to_glib_none().0,
            ))
        }
    }
}

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