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