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