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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
// 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 atk_sys;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib_sys;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem;
use std::mem::transmute;
use CoordType;
use Layer;
use Object;
use Rectangle;
#[cfg(any(feature = "v2_30", feature = "dox"))]
use ScrollType;

glib_wrapper! {
    /// `Component` should be implemented by most if not all UI elements
    /// with an actual on-screen presence, i.e. components which can be
    /// said to have a screen-coordinate bounding box. Virtually all
    /// widgets will need to have `Component` implementations provided
    /// for their corresponding `Object` class. In short, only UI
    /// elements which are *not* GUI elements will omit this ATK interface.
    ///
    /// A possible exception might be textual information with a
    /// transparent background, in which case text glyph bounding box
    /// information is provided by `Text`.
    ///
    /// # Implements
    ///
    /// [`ComponentExt`](trait.ComponentExt.html)
    pub struct Component(Interface<atk_sys::AtkComponent>);

    match fn {
        get_type => || atk_sys::atk_component_get_type(),
    }
}

pub const NONE_COMPONENT: Option<&Component> = None;

/// Trait containing all `Component` methods.
///
/// # Implementors
///
/// [`Component`](struct.Component.html), [`NoOpObject`](struct.NoOpObject.html), [`Plug`](struct.Plug.html), [`Socket`](struct.Socket.html)
pub trait ComponentExt: 'static {
    /// Checks whether the specified point is within the extent of the `self`.
    ///
    /// Toolkit implementor note: ATK provides a default implementation for
    /// this virtual method. In general there are little reason to
    /// re-implement it.
    /// ## `x`
    /// x coordinate
    /// ## `y`
    /// y coordinate
    /// ## `coord_type`
    /// specifies whether the coordinates are relative to the screen
    /// or to the components top level window
    ///
    /// # Returns
    ///
    /// `true` or `false` indicating whether the specified point is within
    /// the extent of the `self` or not
    fn contains(&self, x: i32, y: i32, coord_type: CoordType) -> bool;

    /// Returns the alpha value (i.e. the opacity) for this
    /// `self`, on a scale from 0 (fully transparent) to 1.0
    /// (fully opaque).
    ///
    /// # Returns
    ///
    /// An alpha value from 0 to 1.0, inclusive.
    fn get_alpha(&self) -> f64;

    /// Gets the rectangle which gives the extent of the `self`.
    /// ## `x`
    /// address of `gint` to put x coordinate
    /// ## `y`
    /// address of `gint` to put y coordinate
    /// ## `width`
    /// address of `gint` to put width
    /// ## `height`
    /// address of `gint` to put height
    /// ## `coord_type`
    /// specifies whether the coordinates are relative to the screen
    /// or to the components top level window
    fn get_extents(&self, coord_type: CoordType) -> (i32, i32, i32, i32);

    /// Gets the layer of the component.
    ///
    /// # Returns
    ///
    /// an `Layer` which is the layer of the component
    fn get_layer(&self) -> Layer;

    /// Gets the zorder of the component. The value G_MININT will be returned
    /// if the layer of the component is not ATK_LAYER_MDI or ATK_LAYER_WINDOW.
    ///
    /// # Returns
    ///
    /// a gint which is the zorder of the component, i.e. the depth at
    /// which the component is shown in relation to other components in the same
    /// container.
    fn get_mdi_zorder(&self) -> i32;

    /// Gets the position of `self` in the form of
    /// a point specifying `self`'s top-left corner.
    ///
    /// # Deprecated
    ///
    /// Since 2.12. Use `Component::get_extents` instead.
    /// ## `x`
    /// address of `gint` to put x coordinate position
    /// ## `y`
    /// address of `gint` to put y coordinate position
    /// ## `coord_type`
    /// specifies whether the coordinates are relative to the screen
    /// or to the components top level window
    fn get_position(&self, coord_type: CoordType) -> (i32, i32);

    /// Gets the size of the `self` in terms of width and height.
    ///
    /// # Deprecated
    ///
    /// Since 2.12. Use `Component::get_extents` instead.
    /// ## `width`
    /// address of `gint` to put width of `self`
    /// ## `height`
    /// address of `gint` to put height of `self`
    fn get_size(&self) -> (i32, i32);

    /// Grabs focus for this `self`.
    ///
    /// # Returns
    ///
    /// `true` if successful, `false` otherwise.
    fn grab_focus(&self) -> bool;

    /// Gets a reference to the accessible child, if one exists, at the
    /// coordinate point specified by `x` and `y`.
    /// ## `x`
    /// x coordinate
    /// ## `y`
    /// y coordinate
    /// ## `coord_type`
    /// specifies whether the coordinates are relative to the screen
    /// or to the components top level window
    ///
    /// # Returns
    ///
    /// a reference to the accessible
    /// child, if one exists
    fn ref_accessible_at_point(&self, x: i32, y: i32, coord_type: CoordType) -> Option<Object>;

    /// Makes `self` visible on the screen by scrolling all necessary parents.
    ///
    /// Contrary to atk_component_set_position, this does not actually move
    /// `self` in its parent, this only makes the parents scroll so that the
    /// object shows up on the screen, given its current position within the parents.
    ///
    /// Feature: `v2_30`
    ///
    /// ## `type_`
    /// specify where the object should be made visible.
    ///
    /// # Returns
    ///
    /// whether scrolling was successful.
    #[cfg(any(feature = "v2_30", feature = "dox"))]
    fn scroll_to(&self, type_: ScrollType) -> bool;

    /// Makes an object visible on the screen at a given position by scrolling all
    /// necessary parents.
    ///
    /// Feature: `v2_30`
    ///
    /// ## `coords`
    /// specify whether coordinates are relative to the screen or to the
    /// parent object.
    /// ## `x`
    /// x-position where to scroll to
    /// ## `y`
    /// y-position where to scroll to
    ///
    /// # Returns
    ///
    /// whether scrolling was successful.
    #[cfg(any(feature = "v2_30", feature = "dox"))]
    fn scroll_to_point(&self, coords: CoordType, x: i32, y: i32) -> bool;

    /// Sets the extents of `self`.
    /// ## `x`
    /// x coordinate
    /// ## `y`
    /// y coordinate
    /// ## `width`
    /// width to set for `self`
    /// ## `height`
    /// height to set for `self`
    /// ## `coord_type`
    /// specifies whether the coordinates are relative to the screen
    /// or to the components top level window
    ///
    /// # Returns
    ///
    /// `true` or `false` whether the extents were set or not
    fn set_extents(&self, x: i32, y: i32, width: i32, height: i32, coord_type: CoordType) -> bool;

    /// Sets the position of `self`.
    ///
    /// Contrary to atk_component_scroll_to, this does not trigger any scrolling,
    /// this just moves `self` in its parent.
    /// ## `x`
    /// x coordinate
    /// ## `y`
    /// y coordinate
    /// ## `coord_type`
    /// specifies whether the coordinates are relative to the screen
    /// or to the component's top level window
    ///
    /// # Returns
    ///
    /// `true` or `false` whether or not the position was set or not
    fn set_position(&self, x: i32, y: i32, coord_type: CoordType) -> bool;

    /// Set the size of the `self` in terms of width and height.
    /// ## `width`
    /// width to set for `self`
    /// ## `height`
    /// height to set for `self`
    ///
    /// # Returns
    ///
    /// `true` or `false` whether the size was set or not
    fn set_size(&self, width: i32, height: i32) -> bool;

    /// The 'bounds-changed" signal is emitted when the bposition or
    /// size of the component changes.
    /// ## `arg1`
    /// The AtkRectangle giving the new position and size.
    fn connect_bounds_changed<F: Fn(&Self, &Rectangle) + 'static>(&self, f: F) -> SignalHandlerId;
}

impl<O: IsA<Component>> ComponentExt for O {
    fn contains(&self, x: i32, y: i32, coord_type: CoordType) -> bool {
        unsafe {
            from_glib(atk_sys::atk_component_contains(
                self.as_ref().to_glib_none().0,
                x,
                y,
                coord_type.to_glib(),
            ))
        }
    }

    fn get_alpha(&self) -> f64 {
        unsafe { atk_sys::atk_component_get_alpha(self.as_ref().to_glib_none().0) }
    }

    fn get_extents(&self, coord_type: CoordType) -> (i32, i32, i32, i32) {
        unsafe {
            let mut x = mem::MaybeUninit::uninit();
            let mut y = mem::MaybeUninit::uninit();
            let mut width = mem::MaybeUninit::uninit();
            let mut height = mem::MaybeUninit::uninit();
            atk_sys::atk_component_get_extents(
                self.as_ref().to_glib_none().0,
                x.as_mut_ptr(),
                y.as_mut_ptr(),
                width.as_mut_ptr(),
                height.as_mut_ptr(),
                coord_type.to_glib(),
            );
            let x = x.assume_init();
            let y = y.assume_init();
            let width = width.assume_init();
            let height = height.assume_init();
            (x, y, width, height)
        }
    }

    fn get_layer(&self) -> Layer {
        unsafe {
            from_glib(atk_sys::atk_component_get_layer(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_mdi_zorder(&self) -> i32 {
        unsafe { atk_sys::atk_component_get_mdi_zorder(self.as_ref().to_glib_none().0) }
    }

    fn get_position(&self, coord_type: CoordType) -> (i32, i32) {
        unsafe {
            let mut x = mem::MaybeUninit::uninit();
            let mut y = mem::MaybeUninit::uninit();
            atk_sys::atk_component_get_position(
                self.as_ref().to_glib_none().0,
                x.as_mut_ptr(),
                y.as_mut_ptr(),
                coord_type.to_glib(),
            );
            let x = x.assume_init();
            let y = y.assume_init();
            (x, y)
        }
    }

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

    fn grab_focus(&self) -> bool {
        unsafe {
            from_glib(atk_sys::atk_component_grab_focus(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn ref_accessible_at_point(&self, x: i32, y: i32, coord_type: CoordType) -> Option<Object> {
        unsafe {
            from_glib_full(atk_sys::atk_component_ref_accessible_at_point(
                self.as_ref().to_glib_none().0,
                x,
                y,
                coord_type.to_glib(),
            ))
        }
    }

    #[cfg(any(feature = "v2_30", feature = "dox"))]
    fn scroll_to(&self, type_: ScrollType) -> bool {
        unsafe {
            from_glib(atk_sys::atk_component_scroll_to(
                self.as_ref().to_glib_none().0,
                type_.to_glib(),
            ))
        }
    }

    #[cfg(any(feature = "v2_30", feature = "dox"))]
    fn scroll_to_point(&self, coords: CoordType, x: i32, y: i32) -> bool {
        unsafe {
            from_glib(atk_sys::atk_component_scroll_to_point(
                self.as_ref().to_glib_none().0,
                coords.to_glib(),
                x,
                y,
            ))
        }
    }

    fn set_extents(&self, x: i32, y: i32, width: i32, height: i32, coord_type: CoordType) -> bool {
        unsafe {
            from_glib(atk_sys::atk_component_set_extents(
                self.as_ref().to_glib_none().0,
                x,
                y,
                width,
                height,
                coord_type.to_glib(),
            ))
        }
    }

    fn set_position(&self, x: i32, y: i32, coord_type: CoordType) -> bool {
        unsafe {
            from_glib(atk_sys::atk_component_set_position(
                self.as_ref().to_glib_none().0,
                x,
                y,
                coord_type.to_glib(),
            ))
        }
    }

    fn set_size(&self, width: i32, height: i32) -> bool {
        unsafe {
            from_glib(atk_sys::atk_component_set_size(
                self.as_ref().to_glib_none().0,
                width,
                height,
            ))
        }
    }

    fn connect_bounds_changed<F: Fn(&Self, &Rectangle) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn bounds_changed_trampoline<P, F: Fn(&P, &Rectangle) + 'static>(
            this: *mut atk_sys::AtkComponent,
            arg1: *mut atk_sys::AtkRectangle,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Component>,
        {
            let f: &F = &*(f as *const F);
            f(
                &Component::from_glib_borrow(this).unsafe_cast_ref(),
                &from_glib_borrow(arg1),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"bounds-changed\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    bounds_changed_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl fmt::Display for Component {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "Component")
    }
}