1use atk_sys;
6use glib::object::IsA;
7use glib::translate::*;
8use std::fmt;
9use Object;
10use Relation;
11use RelationType;
12
13glib_wrapper! {
14 pub struct RelationSet(Object<atk_sys::AtkRelationSet, atk_sys::AtkRelationSetClass, RelationSetClass>);
15
16 match fn {
17 get_type => || atk_sys::atk_relation_set_get_type(),
18 }
19}
20
21impl RelationSet {
22 pub fn new() -> RelationSet {
23 assert_initialized_main_thread!();
24 unsafe { from_glib_full(atk_sys::atk_relation_set_new()) }
25 }
26}
27
28impl Default for RelationSet {
29 fn default() -> Self {
30 Self::new()
31 }
32}
33
34pub const NONE_RELATION_SET: Option<&RelationSet> = None;
35
36pub trait RelationSetExt: 'static {
37 fn add<P: IsA<Relation>>(&self, relation: &P);
38
39 fn add_relation_by_type<P: IsA<Object>>(&self, relationship: RelationType, target: &P);
40
41 fn contains(&self, relationship: RelationType) -> bool;
42
43 fn contains_target<P: IsA<Object>>(&self, relationship: RelationType, target: &P) -> bool;
44
45 fn get_n_relations(&self) -> i32;
46
47 fn get_relation(&self, i: i32) -> Option<Relation>;
48
49 fn get_relation_by_type(&self, relationship: RelationType) -> Option<Relation>;
50
51 fn remove<P: IsA<Relation>>(&self, relation: &P);
52}
53
54impl<O: IsA<RelationSet>> RelationSetExt for O {
55 fn add<P: IsA<Relation>>(&self, relation: &P) {
56 unsafe {
57 atk_sys::atk_relation_set_add(
58 self.as_ref().to_glib_none().0,
59 relation.as_ref().to_glib_none().0,
60 );
61 }
62 }
63
64 fn add_relation_by_type<P: IsA<Object>>(&self, relationship: RelationType, target: &P) {
65 unsafe {
66 atk_sys::atk_relation_set_add_relation_by_type(
67 self.as_ref().to_glib_none().0,
68 relationship.to_glib(),
69 target.as_ref().to_glib_none().0,
70 );
71 }
72 }
73
74 fn contains(&self, relationship: RelationType) -> bool {
75 unsafe {
76 from_glib(atk_sys::atk_relation_set_contains(
77 self.as_ref().to_glib_none().0,
78 relationship.to_glib(),
79 ))
80 }
81 }
82
83 fn contains_target<P: IsA<Object>>(&self, relationship: RelationType, target: &P) -> bool {
84 unsafe {
85 from_glib(atk_sys::atk_relation_set_contains_target(
86 self.as_ref().to_glib_none().0,
87 relationship.to_glib(),
88 target.as_ref().to_glib_none().0,
89 ))
90 }
91 }
92
93 fn get_n_relations(&self) -> i32 {
94 unsafe { atk_sys::atk_relation_set_get_n_relations(self.as_ref().to_glib_none().0) }
95 }
96
97 fn get_relation(&self, i: i32) -> Option<Relation> {
98 unsafe {
99 from_glib_none(atk_sys::atk_relation_set_get_relation(
100 self.as_ref().to_glib_none().0,
101 i,
102 ))
103 }
104 }
105
106 fn get_relation_by_type(&self, relationship: RelationType) -> Option<Relation> {
107 unsafe {
108 from_glib_none(atk_sys::atk_relation_set_get_relation_by_type(
109 self.as_ref().to_glib_none().0,
110 relationship.to_glib(),
111 ))
112 }
113 }
114
115 fn remove<P: IsA<Relation>>(&self, relation: &P) {
116 unsafe {
117 atk_sys::atk_relation_set_remove(
118 self.as_ref().to_glib_none().0,
119 relation.as_ref().to_glib_none().0,
120 );
121 }
122 }
123}
124
125impl fmt::Display for RelationSet {
126 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
127 write!(f, "RelationSet")
128 }
129}