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
// 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::IsA;
use glib::translate::*;
use std::fmt;
use Object;
use Relation;
use RelationType;

glib_wrapper! {
    pub struct RelationSet(Object<atk_sys::AtkRelationSet, atk_sys::AtkRelationSetClass, RelationSetClass>);

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

impl RelationSet {
    pub fn new() -> RelationSet {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(atk_sys::atk_relation_set_new()) }
    }
}

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

pub const NONE_RELATION_SET: Option<&RelationSet> = None;

pub trait RelationSetExt: 'static {
    fn add<P: IsA<Relation>>(&self, relation: &P);

    fn add_relation_by_type<P: IsA<Object>>(&self, relationship: RelationType, target: &P);

    fn contains(&self, relationship: RelationType) -> bool;

    fn contains_target<P: IsA<Object>>(&self, relationship: RelationType, target: &P) -> bool;

    fn get_n_relations(&self) -> i32;

    fn get_relation(&self, i: i32) -> Option<Relation>;

    fn get_relation_by_type(&self, relationship: RelationType) -> Option<Relation>;

    fn remove<P: IsA<Relation>>(&self, relation: &P);
}

impl<O: IsA<RelationSet>> RelationSetExt for O {
    fn add<P: IsA<Relation>>(&self, relation: &P) {
        unsafe {
            atk_sys::atk_relation_set_add(
                self.as_ref().to_glib_none().0,
                relation.as_ref().to_glib_none().0,
            );
        }
    }

    fn add_relation_by_type<P: IsA<Object>>(&self, relationship: RelationType, target: &P) {
        unsafe {
            atk_sys::atk_relation_set_add_relation_by_type(
                self.as_ref().to_glib_none().0,
                relationship.to_glib(),
                target.as_ref().to_glib_none().0,
            );
        }
    }

    fn contains(&self, relationship: RelationType) -> bool {
        unsafe {
            from_glib(atk_sys::atk_relation_set_contains(
                self.as_ref().to_glib_none().0,
                relationship.to_glib(),
            ))
        }
    }

    fn contains_target<P: IsA<Object>>(&self, relationship: RelationType, target: &P) -> bool {
        unsafe {
            from_glib(atk_sys::atk_relation_set_contains_target(
                self.as_ref().to_glib_none().0,
                relationship.to_glib(),
                target.as_ref().to_glib_none().0,
            ))
        }
    }

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

    fn get_relation(&self, i: i32) -> Option<Relation> {
        unsafe {
            from_glib_none(atk_sys::atk_relation_set_get_relation(
                self.as_ref().to_glib_none().0,
                i,
            ))
        }
    }

    fn get_relation_by_type(&self, relationship: RelationType) -> Option<Relation> {
        unsafe {
            from_glib_none(atk_sys::atk_relation_set_get_relation_by_type(
                self.as_ref().to_glib_none().0,
                relationship.to_glib(),
            ))
        }
    }

    fn remove<P: IsA<Relation>>(&self, relation: &P) {
        unsafe {
            atk_sys::atk_relation_set_remove(
                self.as_ref().to_glib_none().0,
                relation.as_ref().to_glib_none().0,
            );
        }
    }
}

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