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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
// 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 glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;

glib::wrapper! {
    /// The ATK interface which represents the toplevel
    ///  container for document content.
    ///
    /// The AtkDocument interface should be supported by any object whose
    /// content is a representation or view of a document. The AtkDocument
    /// interface should appear on the toplevel container for the document
    /// content; however AtkDocument instances may be nested (i.e. an
    /// AtkDocument may be a descendant of another AtkDocument) in those
    /// cases where one document contains "embedded content" which can
    /// reasonably be considered a document in its own right.
    ///
    /// # Implements
    ///
    /// [`DocumentExt`][trait@crate::prelude::DocumentExt]
    #[doc(alias = "AtkDocument")]
    pub struct Document(Interface<ffi::AtkDocument, ffi::AtkDocumentIface>);

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

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

/// Trait containing all [`struct@Document`] methods.
///
/// # Implementors
///
/// [`Document`][struct@crate::Document], [`NoOpObject`][struct@crate::NoOpObject]
pub trait DocumentExt: 'static {
    /// Retrieves the value of the given `attribute_name` inside `self`.
    /// ## `attribute_name`
    /// a character string representing the name of the attribute
    ///  whose value is being queried.
    ///
    /// # Returns
    ///
    /// a string value associated with the named
    ///  attribute for this document, or [`None`] if a value for
    ///  `attribute_name` has not been specified for this document.
    #[doc(alias = "atk_document_get_attribute_value")]
    #[doc(alias = "get_attribute_value")]
    fn attribute_value(&self, attribute_name: &str) -> Option<glib::GString>;

    /// Retrieves the current page number inside `self`.
    ///
    /// # Returns
    ///
    /// the current page number inside `self`, or -1 if
    ///  not implemented, not know by the implementor, or irrelevant.
    #[doc(alias = "atk_document_get_current_page_number")]
    #[doc(alias = "get_current_page_number")]
    fn current_page_number(&self) -> i32;

    //#[doc(alias = "atk_document_get_document")]
    //#[doc(alias = "get_document")]
    //fn document(&self) -> /*Unimplemented*/Option<Basic: Pointer>;

    /// Gets a string indicating the document type.
    ///
    /// # Deprecated
    ///
    /// Since 2.12. Please use `atk_document_get_attributes()` to
    /// ask for the document type if it applies.
    ///
    /// # Returns
    ///
    /// a string indicating the document type
    #[doc(alias = "atk_document_get_document_type")]
    #[doc(alias = "get_document_type")]
    fn document_type(&self) -> Option<glib::GString>;

    /// Retrieves the total number of pages inside `self`.
    ///
    /// # Returns
    ///
    /// total page count of `self`, or -1 if not implemented,
    ///  not know by the implementor or irrelevant.
    #[doc(alias = "atk_document_get_page_count")]
    #[doc(alias = "get_page_count")]
    fn page_count(&self) -> i32;

    /// Sets the value for the given `attribute_name` inside `self`.
    /// ## `attribute_name`
    /// a character string representing the name of the attribute
    ///  whose value is being set.
    /// ## `attribute_value`
    /// a string value to be associated with `attribute_name`.
    ///
    /// # Returns
    ///
    /// [`true`] if `attribute_value` is successfully associated
    ///  with `attribute_name` for this `self`, and [`false`] if if the
    ///  document does not allow the attribute to be modified
    #[doc(alias = "atk_document_set_attribute_value")]
    fn set_attribute_value(&self, attribute_name: &str, attribute_value: &str) -> bool;

    /// The 'load-complete' signal is emitted when a pending load of
    /// a static document has completed. This signal is to be
    /// expected by ATK clients if and when AtkDocument implementors
    /// expose ATK_STATE_BUSY. If the state of an AtkObject which
    /// implements AtkDocument does not include ATK_STATE_BUSY, it
    /// should be safe for clients to assume that the AtkDocument's
    /// static contents are fully loaded into the container.
    /// (Dynamic document contents should be exposed via other
    /// signals.)
    #[doc(alias = "load-complete")]
    fn connect_load_complete<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    /// The 'load-stopped' signal is emitted when a pending load of
    /// document contents is cancelled, paused, or otherwise
    /// interrupted by the user or application logic. It should not
    /// however be emitted while waiting for a resource (for instance
    /// while blocking on a file or network read) unless a
    /// user-significant timeout has occurred.
    #[doc(alias = "load-stopped")]
    fn connect_load_stopped<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    /// The 'page-changed' signal is emitted when the current page of
    /// a document changes, e.g. pressing page up/down in a document
    /// viewer.
    /// ## `page_number`
    /// the new page number. If this value is unknown
    /// or not applicable, -1 should be provided.
    #[doc(alias = "page-changed")]
    fn connect_page_changed<F: Fn(&Self, i32) + 'static>(&self, f: F) -> SignalHandlerId;

    /// The 'reload' signal is emitted when the contents of a
    /// document is refreshed from its source. Once 'reload' has
    /// been emitted, a matching 'load-complete' or 'load-stopped'
    /// signal should follow, which clients may await before
    /// interrogating ATK for the latest document content.
    #[doc(alias = "reload")]
    fn connect_reload<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}

impl<O: IsA<Document>> DocumentExt for O {
    fn attribute_value(&self, attribute_name: &str) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::atk_document_get_attribute_value(
                self.as_ref().to_glib_none().0,
                attribute_name.to_glib_none().0,
            ))
        }
    }

    fn current_page_number(&self) -> i32 {
        unsafe { ffi::atk_document_get_current_page_number(self.as_ref().to_glib_none().0) }
    }

    //fn document(&self) -> /*Unimplemented*/Option<Basic: Pointer> {
    //    unsafe { TODO: call ffi:atk_document_get_document() }
    //}

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

    fn page_count(&self) -> i32 {
        unsafe { ffi::atk_document_get_page_count(self.as_ref().to_glib_none().0) }
    }

    fn set_attribute_value(&self, attribute_name: &str, attribute_value: &str) -> bool {
        unsafe {
            from_glib(ffi::atk_document_set_attribute_value(
                self.as_ref().to_glib_none().0,
                attribute_name.to_glib_none().0,
                attribute_value.to_glib_none().0,
            ))
        }
    }

    fn connect_load_complete<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn load_complete_trampoline<P: IsA<Document>, F: Fn(&P) + 'static>(
            this: *mut ffi::AtkDocument,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Document::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"load-complete\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    load_complete_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_load_stopped<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn load_stopped_trampoline<P: IsA<Document>, F: Fn(&P) + 'static>(
            this: *mut ffi::AtkDocument,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Document::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"load-stopped\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    load_stopped_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_page_changed<F: Fn(&Self, i32) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn page_changed_trampoline<P: IsA<Document>, F: Fn(&P, i32) + 'static>(
            this: *mut ffi::AtkDocument,
            page_number: libc::c_int,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                Document::from_glib_borrow(this).unsafe_cast_ref(),
                page_number,
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"page-changed\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    page_changed_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_reload<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn reload_trampoline<P: IsA<Document>, F: Fn(&P) + 'static>(
            this: *mut ffi::AtkDocument,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Document::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"reload\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    reload_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

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