Skip to main content

atk/auto/
component.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
5#[cfg(feature = "v2_30")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v2_30")))]
7use crate::ScrollType;
8use crate::{CoordType, Layer, Object, Rectangle, ffi};
9use glib::{
10    object::ObjectType as _,
11    prelude::*,
12    signal::{SignalHandlerId, connect_raw},
13    translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18    /// The ATK interface provided by UI components
19    /// which occupy a physical area on the screen.
20    /// which the user can activate/interact with.
21    ///
22    /// [`Component`][crate::Component] should be implemented by most if not all UI elements
23    /// with an actual on-screen presence, i.e. components which can be
24    /// said to have a screen-coordinate bounding box. Virtually all
25    /// widgets will need to have [`Component`][crate::Component] implementations provided
26    /// for their corresponding [`Object`][crate::Object] class. In short, only UI
27    /// elements which are *not* GUI elements will omit this ATK interface.
28    ///
29    /// A possible exception might be textual information with a
30    /// transparent background, in which case text glyph bounding box
31    /// information is provided by [`Text`][crate::Text].
32    ///
33    /// ## Signals
34    ///
35    ///
36    /// #### `bounds-changed`
37    ///  The 'bounds-changed" signal is emitted when the position or
38    /// size of the component changes.
39    ///
40    ///
41    ///
42    /// # Implements
43    ///
44    /// [`ComponentExt`][trait@crate::prelude::ComponentExt]
45    #[doc(alias = "AtkComponent")]
46    pub struct Component(Interface<ffi::AtkComponent, ffi::AtkComponentIface>);
47
48    match fn {
49        type_ => || ffi::atk_component_get_type(),
50    }
51}
52
53impl Component {
54    pub const NONE: Option<&'static Component> = None;
55}
56
57/// Trait containing all [`struct@Component`] methods.
58///
59/// # Implementors
60///
61/// [`Component`][struct@crate::Component], [`NoOpObject`][struct@crate::NoOpObject], [`Plug`][struct@crate::Plug], [`Socket`][struct@crate::Socket]
62pub trait ComponentExt: IsA<Component> + 'static {
63    /// Checks whether the specified point is within the extent of the `self`.
64    ///
65    /// Toolkit implementor note: ATK provides a default implementation for
66    /// this virtual method. In general there are little reason to
67    /// re-implement it.
68    /// ## `x`
69    /// x coordinate
70    /// ## `y`
71    /// y coordinate
72    /// ## `coord_type`
73    /// specifies whether the coordinates are relative to the screen
74    /// or to the components top level window
75    ///
76    /// # Returns
77    ///
78    /// [`true`] or [`false`] indicating whether the specified point is within
79    /// the extent of the `self` or not
80    #[doc(alias = "atk_component_contains")]
81    fn contains(&self, x: i32, y: i32, coord_type: CoordType) -> bool {
82        unsafe {
83            from_glib(ffi::atk_component_contains(
84                self.as_ref().to_glib_none().0,
85                x,
86                y,
87                coord_type.into_glib(),
88            ))
89        }
90    }
91
92    /// Returns the alpha value (i.e. the opacity) for this
93    /// `self`, on a scale from 0 (fully transparent) to 1.0
94    /// (fully opaque).
95    ///
96    /// # Returns
97    ///
98    /// An alpha value from 0 to 1.0, inclusive.
99    #[doc(alias = "atk_component_get_alpha")]
100    #[doc(alias = "get_alpha")]
101    fn alpha(&self) -> f64 {
102        unsafe { ffi::atk_component_get_alpha(self.as_ref().to_glib_none().0) }
103    }
104
105    /// Gets the rectangle which gives the extent of the `self`.
106    ///
107    /// If the extent can not be obtained (e.g. a non-embedded plug or missing
108    /// support), all of x, y, width, height are set to -1.
109    /// ## `coord_type`
110    /// specifies whether the coordinates are relative to the screen
111    /// or to the components top level window
112    ///
113    /// # Returns
114    ///
115    ///
116    /// ## `x`
117    /// address of `gint` to put x coordinate
118    ///
119    /// ## `y`
120    /// address of `gint` to put y coordinate
121    ///
122    /// ## `width`
123    /// address of `gint` to put width
124    ///
125    /// ## `height`
126    /// address of `gint` to put height
127    #[doc(alias = "atk_component_get_extents")]
128    #[doc(alias = "get_extents")]
129    fn extents(&self, coord_type: CoordType) -> (i32, i32, i32, i32) {
130        unsafe {
131            let mut x = std::mem::MaybeUninit::uninit();
132            let mut y = std::mem::MaybeUninit::uninit();
133            let mut width = std::mem::MaybeUninit::uninit();
134            let mut height = std::mem::MaybeUninit::uninit();
135            ffi::atk_component_get_extents(
136                self.as_ref().to_glib_none().0,
137                x.as_mut_ptr(),
138                y.as_mut_ptr(),
139                width.as_mut_ptr(),
140                height.as_mut_ptr(),
141                coord_type.into_glib(),
142            );
143            (
144                x.assume_init(),
145                y.assume_init(),
146                width.assume_init(),
147                height.assume_init(),
148            )
149        }
150    }
151
152    /// Gets the layer of the component.
153    ///
154    /// # Returns
155    ///
156    /// an [`Layer`][crate::Layer] which is the layer of the component
157    #[doc(alias = "atk_component_get_layer")]
158    #[doc(alias = "get_layer")]
159    fn layer(&self) -> Layer {
160        unsafe { from_glib(ffi::atk_component_get_layer(self.as_ref().to_glib_none().0)) }
161    }
162
163    /// Gets the zorder of the component. The value G_MININT will be returned
164    /// if the layer of the component is not ATK_LAYER_MDI or ATK_LAYER_WINDOW.
165    ///
166    /// # Returns
167    ///
168    /// a gint which is the zorder of the component, i.e. the depth at
169    /// which the component is shown in relation to other components in the same
170    /// container.
171    #[doc(alias = "atk_component_get_mdi_zorder")]
172    #[doc(alias = "get_mdi_zorder")]
173    fn mdi_zorder(&self) -> i32 {
174        unsafe { ffi::atk_component_get_mdi_zorder(self.as_ref().to_glib_none().0) }
175    }
176
177    /// Gets the position of `self` in the form of
178    /// a point specifying `self`'s top-left corner.
179    ///
180    /// If the position can not be obtained (e.g. a non-embedded plug or missing
181    /// support), x and y are set to -1.
182    ///
183    /// # Deprecated
184    ///
185    /// Since 2.12. Use [`extents()`][Self::extents()] instead.
186    /// ## `coord_type`
187    /// specifies whether the coordinates are relative to the screen
188    /// or to the components top level window
189    ///
190    /// # Returns
191    ///
192    ///
193    /// ## `x`
194    /// address of `gint` to put x coordinate position
195    ///
196    /// ## `y`
197    /// address of `gint` to put y coordinate position
198    #[doc(alias = "atk_component_get_position")]
199    #[doc(alias = "get_position")]
200    fn position(&self, coord_type: CoordType) -> (i32, i32) {
201        unsafe {
202            let mut x = std::mem::MaybeUninit::uninit();
203            let mut y = std::mem::MaybeUninit::uninit();
204            ffi::atk_component_get_position(
205                self.as_ref().to_glib_none().0,
206                x.as_mut_ptr(),
207                y.as_mut_ptr(),
208                coord_type.into_glib(),
209            );
210            (x.assume_init(), y.assume_init())
211        }
212    }
213
214    /// Gets the size of the `self` in terms of width and height.
215    ///
216    /// If the size can not be obtained (e.g. a non-embedded plug or missing
217    /// support), width and height are set to -1.
218    ///
219    /// # Deprecated
220    ///
221    /// Since 2.12. Use [`extents()`][Self::extents()] instead.
222    ///
223    /// # Returns
224    ///
225    ///
226    /// ## `width`
227    /// address of `gint` to put width of `self`
228    ///
229    /// ## `height`
230    /// address of `gint` to put height of `self`
231    #[doc(alias = "atk_component_get_size")]
232    #[doc(alias = "get_size")]
233    fn size(&self) -> (i32, i32) {
234        unsafe {
235            let mut width = std::mem::MaybeUninit::uninit();
236            let mut height = std::mem::MaybeUninit::uninit();
237            ffi::atk_component_get_size(
238                self.as_ref().to_glib_none().0,
239                width.as_mut_ptr(),
240                height.as_mut_ptr(),
241            );
242            (width.assume_init(), height.assume_init())
243        }
244    }
245
246    /// Grabs focus for this `self`.
247    ///
248    /// # Returns
249    ///
250    /// [`true`] if successful, [`false`] otherwise.
251    #[doc(alias = "atk_component_grab_focus")]
252    fn grab_focus(&self) -> bool {
253        unsafe {
254            from_glib(ffi::atk_component_grab_focus(
255                self.as_ref().to_glib_none().0,
256            ))
257        }
258    }
259
260    /// Gets a reference to the accessible child, if one exists, at the
261    /// coordinate point specified by `x` and `y`.
262    /// ## `x`
263    /// x coordinate
264    /// ## `y`
265    /// y coordinate
266    /// ## `coord_type`
267    /// specifies whether the coordinates are relative to the screen
268    /// or to the components top level window
269    ///
270    /// # Returns
271    ///
272    /// a reference to the accessible
273    /// child, if one exists
274    #[doc(alias = "atk_component_ref_accessible_at_point")]
275    fn ref_accessible_at_point(&self, x: i32, y: i32, coord_type: CoordType) -> Option<Object> {
276        unsafe {
277            from_glib_full(ffi::atk_component_ref_accessible_at_point(
278                self.as_ref().to_glib_none().0,
279                x,
280                y,
281                coord_type.into_glib(),
282            ))
283        }
284    }
285
286    /// Makes `self` visible on the screen by scrolling all necessary parents.
287    ///
288    /// Contrary to atk_component_set_position, this does not actually move
289    /// `self` in its parent, this only makes the parents scroll so that the
290    /// object shows up on the screen, given its current position within the parents.
291    /// ## `type_`
292    /// specify where the object should be made visible.
293    ///
294    /// # Returns
295    ///
296    /// whether scrolling was successful.
297    #[cfg(feature = "v2_30")]
298    #[cfg_attr(docsrs, doc(cfg(feature = "v2_30")))]
299    #[doc(alias = "atk_component_scroll_to")]
300    fn scroll_to(&self, type_: ScrollType) -> bool {
301        unsafe {
302            from_glib(ffi::atk_component_scroll_to(
303                self.as_ref().to_glib_none().0,
304                type_.into_glib(),
305            ))
306        }
307    }
308
309    /// Move the top-left of `self` to a given position of the screen by
310    /// scrolling all necessary parents.
311    /// ## `coords`
312    /// specify whether coordinates are relative to the screen or to the
313    /// parent object.
314    /// ## `x`
315    /// x-position where to scroll to
316    /// ## `y`
317    /// y-position where to scroll to
318    ///
319    /// # Returns
320    ///
321    /// whether scrolling was successful.
322    #[cfg(feature = "v2_30")]
323    #[cfg_attr(docsrs, doc(cfg(feature = "v2_30")))]
324    #[doc(alias = "atk_component_scroll_to_point")]
325    fn scroll_to_point(&self, coords: CoordType, x: i32, y: i32) -> bool {
326        unsafe {
327            from_glib(ffi::atk_component_scroll_to_point(
328                self.as_ref().to_glib_none().0,
329                coords.into_glib(),
330                x,
331                y,
332            ))
333        }
334    }
335
336    /// Sets the extents of `self`.
337    /// ## `x`
338    /// x coordinate
339    /// ## `y`
340    /// y coordinate
341    /// ## `width`
342    /// width to set for `self`
343    /// ## `height`
344    /// height to set for `self`
345    /// ## `coord_type`
346    /// specifies whether the coordinates are relative to the screen
347    /// or to the components top level window
348    ///
349    /// # Returns
350    ///
351    /// [`true`] or [`false`] whether the extents were set or not
352    #[doc(alias = "atk_component_set_extents")]
353    fn set_extents(&self, x: i32, y: i32, width: i32, height: i32, coord_type: CoordType) -> bool {
354        unsafe {
355            from_glib(ffi::atk_component_set_extents(
356                self.as_ref().to_glib_none().0,
357                x,
358                y,
359                width,
360                height,
361                coord_type.into_glib(),
362            ))
363        }
364    }
365
366    /// Sets the position of `self`.
367    ///
368    /// Contrary to atk_component_scroll_to, this does not trigger any scrolling,
369    /// this just moves `self` in its parent.
370    /// ## `x`
371    /// x coordinate
372    /// ## `y`
373    /// y coordinate
374    /// ## `coord_type`
375    /// specifies whether the coordinates are relative to the screen
376    /// or to the component's top level window
377    ///
378    /// # Returns
379    ///
380    /// [`true`] or [`false`] whether or not the position was set or not
381    #[doc(alias = "atk_component_set_position")]
382    fn set_position(&self, x: i32, y: i32, coord_type: CoordType) -> bool {
383        unsafe {
384            from_glib(ffi::atk_component_set_position(
385                self.as_ref().to_glib_none().0,
386                x,
387                y,
388                coord_type.into_glib(),
389            ))
390        }
391    }
392
393    /// Set the size of the `self` in terms of width and height.
394    /// ## `width`
395    /// width to set for `self`
396    /// ## `height`
397    /// height to set for `self`
398    ///
399    /// # Returns
400    ///
401    /// [`true`] or [`false`] whether the size was set or not
402    #[doc(alias = "atk_component_set_size")]
403    fn set_size(&self, width: i32, height: i32) -> bool {
404        unsafe {
405            from_glib(ffi::atk_component_set_size(
406                self.as_ref().to_glib_none().0,
407                width,
408                height,
409            ))
410        }
411    }
412
413    /// The 'bounds-changed" signal is emitted when the position or
414    /// size of the component changes.
415    /// ## `arg1`
416    /// The AtkRectangle giving the new position and size.
417    #[doc(alias = "bounds-changed")]
418    fn connect_bounds_changed<F: Fn(&Self, &Rectangle) + 'static>(&self, f: F) -> SignalHandlerId {
419        unsafe extern "C" fn bounds_changed_trampoline<
420            P: IsA<Component>,
421            F: Fn(&P, &Rectangle) + 'static,
422        >(
423            this: *mut ffi::AtkComponent,
424            arg1: *mut ffi::AtkRectangle,
425            f: glib::ffi::gpointer,
426        ) {
427            unsafe {
428                let f: &F = &*(f as *const F);
429                f(
430                    Component::from_glib_borrow(this).unsafe_cast_ref(),
431                    &from_glib_borrow(arg1),
432                )
433            }
434        }
435        unsafe {
436            let f: Box_<F> = Box_::new(f);
437            connect_raw(
438                self.as_ptr() as *mut _,
439                c"bounds-changed".as_ptr(),
440                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
441                    bounds_changed_trampoline::<Self, F> as *const (),
442                )),
443                Box_::into_raw(f),
444            )
445        }
446    }
447}
448
449impl<O: IsA<Component>> ComponentExt for O {}