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(bool transferOwnership = false)
49 	{
50 		if (transferOwnership)
51 			ownedRef = false;
52 		return atkRelation;
53 	}
54 
55 	/** the main Gtk struct as a void* */
56 	protected override void* getStruct()
57 	{
58 		return cast(void*)atkRelation;
59 	}
60 
61 	protected override void setStruct(GObject* obj)
62 	{
63 		atkRelation = cast(AtkRelation*)obj;
64 		super.setStruct(obj);
65 	}
66 
67 	/**
68 	 * Sets our main struct and passes it to the parent class.
69 	 */
70 	public this (AtkRelation* atkRelation, bool ownedRef = false)
71 	{
72 		this.atkRelation = atkRelation;
73 		super(cast(GObject*)atkRelation, ownedRef);
74 	}
75 
76 
77 	/** */
78 	public static GType getType()
79 	{
80 		return atk_relation_get_type();
81 	}
82 
83 	/**
84 	 * Create a new relation for the specified key and the specified list
85 	 * of targets.  See also atk_object_add_relationship().
86 	 *
87 	 * Params:
88 	 *     targets = an array of pointers to
89 	 *         #AtkObjects
90 	 *     nTargets = number of #AtkObjects pointed to by @targets
91 	 *     relationship = an #AtkRelationType with which to create the new
92 	 *         #AtkRelation
93 	 *
94 	 * Returns: a pointer to a new #AtkRelation
95 	 *
96 	 * Throws: ConstructionException GTK+ fails to create the object.
97 	 */
98 	public this(ObjectAtk[] targets, AtkRelationType relationship)
99 	{
100 		AtkObject*[] targetsArray = new AtkObject*[targets.length];
101 		for ( int i = 0; i < targets.length; i++ )
102 		{
103 			targetsArray[i] = targets[i].getObjectAtkStruct();
104 		}
105 		
106 		auto p = atk_relation_new(targetsArray.ptr, cast(int)targets.length, relationship);
107 		
108 		if(p is null)
109 		{
110 			throw new ConstructionException("null returned by new");
111 		}
112 		
113 		this(cast(AtkRelation*) p, true);
114 	}
115 
116 	/**
117 	 * Adds the specified AtkObject to the target for the relation, if it is
118 	 * not already present.  See also atk_object_add_relationship().
119 	 *
120 	 * Params:
121 	 *     target = an #AtkObject
122 	 *
123 	 * Since: 1.9
124 	 */
125 	public void addTarget(ObjectAtk target)
126 	{
127 		atk_relation_add_target(atkRelation, (target is null) ? null : target.getObjectAtkStruct());
128 	}
129 
130 	/**
131 	 * Gets the type of @relation
132 	 *
133 	 * Returns: the type of @relation
134 	 */
135 	public AtkRelationType getRelationType()
136 	{
137 		return atk_relation_get_relation_type(atkRelation);
138 	}
139 
140 	/**
141 	 * Gets the target list of @relation
142 	 *
143 	 * Returns: the target list of @relation
144 	 */
145 	public PtrArray getTarget()
146 	{
147 		auto p = atk_relation_get_target(atkRelation);
148 		
149 		if(p is null)
150 		{
151 			return null;
152 		}
153 		
154 		return new PtrArray(cast(GPtrArray*) p);
155 	}
156 
157 	/**
158 	 * Remove the specified AtkObject from the target for the relation.
159 	 *
160 	 * Params:
161 	 *     target = an #AtkObject
162 	 *
163 	 * Returns: TRUE if the removal is successful.
164 	 */
165 	public bool removeTarget(ObjectAtk target)
166 	{
167 		return atk_relation_remove_target(atkRelation, (target is null) ? null : target.getObjectAtkStruct()) != 0;
168 	}
169 
170 	/**
171 	 * Get the #AtkRelationType type corresponding to a relation name.
172 	 *
173 	 * Params:
174 	 *     name = a string which is the (non-localized) name of an ATK relation type.
175 	 *
176 	 * Returns: the #AtkRelationType enumerated type corresponding to the specified name,
177 	 *     or #ATK_RELATION_NULL if no matching relation type is found.
178 	 */
179 	public static AtkRelationType typeForName(string name)
180 	{
181 		return atk_relation_type_for_name(Str.toStringz(name));
182 	}
183 
184 	/**
185 	 * Gets the description string describing the #AtkRelationType @type.
186 	 *
187 	 * Params:
188 	 *     type = The #AtkRelationType whose name is required
189 	 *
190 	 * Returns: the string describing the AtkRelationType
191 	 */
192 	public static string typeGetName(AtkRelationType type)
193 	{
194 		return Str.toString(atk_relation_type_get_name(type));
195 	}
196 
197 	/**
198 	 * Associate @name with a new #AtkRelationType
199 	 *
200 	 * Params:
201 	 *     name = a name string
202 	 *
203 	 * Returns: an #AtkRelationType associated with @name
204 	 */
205 	public static AtkRelationType typeRegister(string name)
206 	{
207 		return atk_relation_type_register(Str.toStringz(name));
208 	}
209 }