1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module atk.Relation;
26 
27 private import atk.ObjectAtk;
28 private import glib.ConstructionException;
29 private import glib.PtrArray;
30 private import glib.Str;
31 private import gobject.ObjectG;
32 private import gtkc.atk;
33 public  import gtkc.atktypes;
34 
35 
36 /**
37  * An AtkRelation describes a relation between an object and one or
38  * more other objects. The actual relations that an object has with
39  * other objects are defined as an AtkRelationSet, which is a set of
40  * AtkRelations.
41  */
42 public class Relation : ObjectG
43 {
44 	/** the main Gtk struct */
45 	protected AtkRelation* atkRelation;
46 
47 	/** Get the main Gtk struct */
48 	public AtkRelation* getRelationStruct()
49 	{
50 		return atkRelation;
51 	}
52 
53 	/** the main Gtk struct as a void* */
54 	protected override void* getStruct()
55 	{
56 		return cast(void*)atkRelation;
57 	}
58 
59 	protected override void setStruct(GObject* obj)
60 	{
61 		atkRelation = cast(AtkRelation*)obj;
62 		super.setStruct(obj);
63 	}
64 
65 	/**
66 	 * Sets our main struct and passes it to the parent class.
67 	 */
68 	public this (AtkRelation* atkRelation, bool ownedRef = false)
69 	{
70 		this.atkRelation = atkRelation;
71 		super(cast(GObject*)atkRelation, ownedRef);
72 	}
73 
74 	/**
75 	 */
76 
77 	public static GType getType()
78 	{
79 		return atk_relation_get_type();
80 	}
81 
82 	/**
83 	 * Create a new relation for the specified key and the specified list
84 	 * of targets.  See also atk_object_add_relationship().
85 	 *
86 	 * Params:
87 	 *     targets = an array of pointers to
88 	 *         #AtkObjects
89 	 *     nTargets = number of #AtkObjects pointed to by @targets
90 	 *     relationship = an #AtkRelationType with which to create the new
91 	 *         #AtkRelation
92 	 *
93 	 * Return: a pointer to a new #AtkRelation
94 	 *
95 	 * Throws: ConstructionException GTK+ fails to create the object.
96 	 */
97 	public this(ObjectAtk[] targets, AtkRelationType relationship)
98 	{
99 		AtkObject*[] targetsArray = new AtkObject*[targets.length];
100 		for ( int i = 0; i < targets.length; i++ )
101 		{
102 			targetsArray[i] = targets[i].getObjectAtkStruct();
103 		}
104 		
105 		auto p = atk_relation_new(targetsArray.ptr, cast(int)targets.length, relationship);
106 		
107 		if(p is null)
108 		{
109 			throw new ConstructionException("null returned by new");
110 		}
111 		
112 		this(cast(AtkRelation*) p, true);
113 	}
114 
115 	/**
116 	 * Adds the specified AtkObject to the target for the relation, if it is
117 	 * not already present.  See also atk_object_add_relationship().
118 	 *
119 	 * Params:
120 	 *     target = an #AtkObject
121 	 *
122 	 * Since: 1.9
123 	 */
124 	public void addTarget(ObjectAtk target)
125 	{
126 		atk_relation_add_target(atkRelation, (target is null) ? null : target.getObjectAtkStruct());
127 	}
128 
129 	/**
130 	 * Gets the type of @relation
131 	 *
132 	 * Return: the type of @relation
133 	 */
134 	public AtkRelationType getRelationType()
135 	{
136 		return atk_relation_get_relation_type(atkRelation);
137 	}
138 
139 	/**
140 	 * Gets the target list of @relation
141 	 *
142 	 * Return: the target list of @relation
143 	 */
144 	public PtrArray getTarget()
145 	{
146 		auto p = atk_relation_get_target(atkRelation);
147 		
148 		if(p is null)
149 		{
150 			return null;
151 		}
152 		
153 		return new PtrArray(cast(GPtrArray*) p);
154 	}
155 
156 	/**
157 	 * Remove the specified AtkObject from the target for the relation.
158 	 *
159 	 * Params:
160 	 *     target = an #AtkObject
161 	 *
162 	 * Return: TRUE if the removal is successful.
163 	 */
164 	public bool removeTarget(ObjectAtk target)
165 	{
166 		return atk_relation_remove_target(atkRelation, (target is null) ? null : target.getObjectAtkStruct()) != 0;
167 	}
168 
169 	/**
170 	 * Get the #AtkRelationType type corresponding to a relation name.
171 	 *
172 	 * Params:
173 	 *     name = a string which is the (non-localized) name of an ATK relation type.
174 	 *
175 	 * Return: the #AtkRelationType enumerated type corresponding to the specified name,
176 	 *     or #ATK_RELATION_NULL if no matching relation type is found.
177 	 */
178 	public static AtkRelationType typeForName(string name)
179 	{
180 		return atk_relation_type_for_name(Str.toStringz(name));
181 	}
182 
183 	/**
184 	 * Gets the description string describing the #AtkRelationType @type.
185 	 *
186 	 * Params:
187 	 *     type = The #AtkRelationType whose name is required
188 	 *
189 	 * Return: the string describing the AtkRelationType
190 	 */
191 	public static string typeGetName(AtkRelationType type)
192 	{
193 		return Str.toString(atk_relation_type_get_name(type));
194 	}
195 
196 	/**
197 	 * Associate @name with a new #AtkRelationType
198 	 *
199 	 * Params:
200 	 *     name = a name string
201 	 *
202 	 * Return: an #AtkRelationType associated with @name
203 	 */
204 	public static AtkRelationType typeRegister(string name)
205 	{
206 		return atk_relation_type_register(Str.toStringz(name));
207 	}
208 }