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
// 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::Component;
use crate::Object;
use glib::object::Cast;
use glib::object::IsA;
use glib::translate::*;
use std::fmt;

glib::wrapper! {
    /// Together with [`Plug`][crate::Plug], [`Socket`][crate::Socket] provides the ability to embed
    /// accessibles from one process into another in a fashion that is
    /// transparent to assistive technologies. [`Socket`][crate::Socket] works as the
    /// container of [`Plug`][crate::Plug], embedding it using the method
    /// [`AtkSocketExt::embed()`][crate::prelude::AtkSocketExt::embed()]. Any accessible contained in the [`Plug`][crate::Plug] will
    /// appear to the assistive technologies as being inside the
    /// application that created the [`Socket`][crate::Socket].
    ///
    /// The communication between a [`Socket`][crate::Socket] and a [`Plug`][crate::Plug] is done by
    /// the IPC layer of the accessibility framework, normally implemented
    /// by the D-Bus based implementation of AT-SPI (at-spi2). If that is
    /// the case, at-spi-atk2 is the responsible to implement the abstract
    /// methods [`AtkPlugExt::id()`][crate::prelude::AtkPlugExt::id()] and [`AtkSocketExt::embed()`][crate::prelude::AtkSocketExt::embed()], so an ATK
    /// implementor shouldn't reimplement them. The process that contains
    /// the [`Plug`][crate::Plug] is responsible to send the ID returned by
    /// `atk_plug_id()` to the process that contains the [`Socket`][crate::Socket], so it
    /// could call the method [`AtkSocketExt::embed()`][crate::prelude::AtkSocketExt::embed()] in order to embed it.
    ///
    /// For the same reasons, an implementor doesn't need to implement
    /// [`AtkObjectExt::n_accessible_children()`][crate::prelude::AtkObjectExt::n_accessible_children()] and
    /// [`AtkObjectExt::ref_accessible_child()`][crate::prelude::AtkObjectExt::ref_accessible_child()]. All the logic related to those
    /// functions will be implemented by the IPC layer.
    ///
    /// # Implements
    ///
    /// [`AtkSocketExt`][trait@crate::prelude::AtkSocketExt], [`AtkObjectExt`][trait@crate::prelude::AtkObjectExt], [`trait@glib::ObjectExt`], [`ComponentExt`][trait@crate::prelude::ComponentExt]
    #[doc(alias = "AtkSocket")]
    pub struct Socket(Object<ffi::AtkSocket, ffi::AtkSocketClass>) @extends Object, @implements Component;

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

impl Socket {
    /// Creates a new [`Socket`][crate::Socket].
    ///
    /// # Returns
    ///
    /// the newly created [`Socket`][crate::Socket] instance
    #[doc(alias = "atk_socket_new")]
    pub fn new() -> Socket {
        assert_initialized_main_thread!();
        unsafe { Object::from_glib_full(ffi::atk_socket_new()).unsafe_cast() }
    }
}

impl Default for Socket {
    fn default() -> Self {
        Self::new()
    }
}

pub const NONE_SOCKET: Option<&Socket> = None;

/// Trait containing all [`struct@Socket`] methods.
///
/// # Implementors
///
/// [`Socket`][struct@crate::Socket]
pub trait AtkSocketExt: 'static {
    /// Embeds the children of an [`Plug`][crate::Plug] as the children of the
    /// [`Socket`][crate::Socket]. The plug may be in the same process or in a different
    /// process.
    ///
    /// The class item used by this function should be filled in by the IPC
    /// layer (usually at-spi2-atk). The implementor of the AtkSocket
    /// should call this function and pass the id for the plug as returned
    /// by [`AtkPlugExt::id()`][crate::prelude::AtkPlugExt::id()]. It is the responsibility of the application
    /// to pass the plug id on to the process implementing the [`Socket`][crate::Socket]
    /// as needed.
    /// ## `plug_id`
    /// the ID of an [`Plug`][crate::Plug]
    #[doc(alias = "atk_socket_embed")]
    fn embed(&self, plug_id: &str);

    /// Determines whether or not the socket has an embedded plug.
    ///
    /// # Returns
    ///
    /// TRUE if a plug is embedded in the socket
    #[doc(alias = "atk_socket_is_occupied")]
    fn is_occupied(&self) -> bool;
}

impl<O: IsA<Socket>> AtkSocketExt for O {
    fn embed(&self, plug_id: &str) {
        unsafe {
            ffi::atk_socket_embed(self.as_ref().to_glib_none().0, plug_id.to_glib_none().0);
        }
    }

    fn is_occupied(&self) -> bool {
        unsafe { from_glib(ffi::atk_socket_is_occupied(self.as_ref().to_glib_none().0)) }
    }
}

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