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 pango.PgAttributeList;
26 
27 private import glib.ConstructionException;
28 private import glib.ListSG;
29 private import gobject.ObjectG;
30 private import gtkd.Loader;
31 private import pango.PgAttribute;
32 private import pango.PgAttributeIterator;
33 private import pango.c.functions;
34 public  import pango.c.types;
35 
36 
37 /**
38  * A `PangoAttrList` represents a list of attributes that apply to a section
39  * of text.
40  * 
41  * The attributes in a `PangoAttrList` are, in general, allowed to overlap in
42  * an arbitrary fashion. However, if the attributes are manipulated only through
43  * [method@Pango.AttrList.change], the overlap between properties will meet
44  * stricter criteria.
45  * 
46  * Since the `PangoAttrList` structure is stored as a linear list, it is not
47  * suitable for storing attributes for large amounts of text. In general, you
48  * should not use a single `PangoAttrList` for more than one paragraph of text.
49  */
50 public class PgAttributeList
51 {
52 	/** the main Gtk struct */
53 	protected PangoAttrList* pangoAttrList;
54 	protected bool ownedRef;
55 
56 	/** Get the main Gtk struct */
57 	public PangoAttrList* getPgAttributeListStruct(bool transferOwnership = false)
58 	{
59 		if (transferOwnership)
60 			ownedRef = false;
61 		return pangoAttrList;
62 	}
63 
64 	/** the main Gtk struct as a void* */
65 	protected void* getStruct()
66 	{
67 		return cast(void*)pangoAttrList;
68 	}
69 
70 	/**
71 	 * Sets our main struct and passes it to the parent class.
72 	 */
73 	public this (PangoAttrList* pangoAttrList, bool ownedRef = false)
74 	{
75 		this.pangoAttrList = pangoAttrList;
76 		this.ownedRef = ownedRef;
77 	}
78 
79 	~this ()
80 	{
81 		if ( Linker.isLoaded(LIBRARY_PANGO) && ownedRef )
82 			pango_attr_list_unref(pangoAttrList);
83 	}
84 
85 
86 	/** */
87 	public static GType getType()
88 	{
89 		return pango_attr_list_get_type();
90 	}
91 
92 	/**
93 	 * Create a new empty attribute list with a reference count of one.
94 	 *
95 	 * Returns: the newly allocated `PangoAttrList`,
96 	 *     which should be freed with [method@Pango.AttrList.unref].
97 	 *
98 	 * Throws: ConstructionException GTK+ fails to create the object.
99 	 */
100 	public this()
101 	{
102 		auto __p = pango_attr_list_new();
103 
104 		if(__p is null)
105 		{
106 			throw new ConstructionException("null returned by new");
107 		}
108 
109 		this(cast(PangoAttrList*) __p);
110 	}
111 
112 	/**
113 	 * Insert the given attribute into the `PangoAttrList`.
114 	 *
115 	 * It will replace any attributes of the same type on that segment
116 	 * and be merged with any adjoining attributes that are identical.
117 	 *
118 	 * This function is slower than [method@Pango.AttrList.insert] for
119 	 * creating an attribute list in order (potentially much slower for
120 	 * large lists). However, [method@Pango.AttrList.insert] is not
121 	 * suitable for continually changing a set of attributes since it
122 	 * never removes or combines existing attributes.
123 	 *
124 	 * Params:
125 	 *     attr = the attribute to insert. Ownership of this
126 	 *         value is assumed by the list.
127 	 */
128 	public void change(PgAttribute attr)
129 	{
130 		pango_attr_list_change(pangoAttrList, (attr is null) ? null : attr.getPgAttributeStruct());
131 	}
132 
133 	/**
134 	 * Copy @list and return an identical new list.
135 	 *
136 	 * Returns: the newly allocated `PangoAttrList`,
137 	 *     with a reference count of one, which should be freed with
138 	 *     [method@Pango.AttrList.unref]. Returns %NULL if @list was %NULL.
139 	 */
140 	public PgAttributeList copy()
141 	{
142 		auto __p = pango_attr_list_copy(pangoAttrList);
143 
144 		if(__p is null)
145 		{
146 			return null;
147 		}
148 
149 		return ObjectG.getDObject!(PgAttributeList)(cast(PangoAttrList*) __p, true);
150 	}
151 
152 	/**
153 	 * Checks whether @list and @other_list contain the same attributes and
154 	 * whether those attributes apply to the same ranges. Beware that this
155 	 * will return wrong values if any list contains duplicates.
156 	 *
157 	 * Params:
158 	 *     otherList = the other `PangoAttrList`
159 	 *
160 	 * Returns: %TRUE if the lists are equal, %FALSE if they aren't.
161 	 *
162 	 * Since: 1.46
163 	 */
164 	public bool equal(PgAttributeList otherList)
165 	{
166 		return pango_attr_list_equal(pangoAttrList, (otherList is null) ? null : otherList.getPgAttributeListStruct()) != 0;
167 	}
168 
169 	/**
170 	 * Given a `PangoAttrList` and callback function, removes any elements
171 	 * of @list for which @func returns %TRUE and inserts them into a new list.
172 	 *
173 	 * Params:
174 	 *     func = callback function; returns %TRUE
175 	 *         if an attribute should be filtered out.
176 	 *     data = Data to be passed to @func
177 	 *
178 	 * Returns: the new `PangoAttrList` or
179 	 *     %NULL if no attributes of the given types were found.
180 	 *
181 	 * Since: 1.2
182 	 */
183 	public PgAttributeList filter(PangoAttrFilterFunc func, void* data)
184 	{
185 		auto __p = pango_attr_list_filter(pangoAttrList, func, data);
186 
187 		if(__p is null)
188 		{
189 			return null;
190 		}
191 
192 		return ObjectG.getDObject!(PgAttributeList)(cast(PangoAttrList*) __p, true);
193 	}
194 
195 	/**
196 	 * Gets a list of all attributes in @list.
197 	 *
198 	 * Returns: a list of all attributes in @list. To free this value, call
199 	 *     [mehod@Pango.Attribute.destroy] on each value and g_slist_free()
200 	 *     on the list.
201 	 *
202 	 * Since: 1.44
203 	 */
204 	public ListSG getAttributes()
205 	{
206 		auto __p = pango_attr_list_get_attributes(pangoAttrList);
207 
208 		if(__p is null)
209 		{
210 			return null;
211 		}
212 
213 		return new ListSG(cast(GSList*) __p, true);
214 	}
215 
216 	/**
217 	 * Create a iterator initialized to the beginning of the list.
218 	 * @list must not be modified until this iterator is freed.
219 	 *
220 	 * Returns: the newly allocated `PangoAttrIterator`,
221 	 *     which should be freed with [method@Pango.AttrIterator.destroy].
222 	 */
223 	public PgAttributeIterator getIterator()
224 	{
225 		auto __p = pango_attr_list_get_iterator(pangoAttrList);
226 
227 		if(__p is null)
228 		{
229 			return null;
230 		}
231 
232 		return ObjectG.getDObject!(PgAttributeIterator)(cast(PangoAttrIterator*) __p, true);
233 	}
234 
235 	/**
236 	 * Insert the given attribute into the `PangoAttrList`.
237 	 *
238 	 * It will be inserted after all other attributes with a
239 	 * matching @start_index.
240 	 *
241 	 * Params:
242 	 *     attr = the attribute to insert. Ownership of this
243 	 *         value is assumed by the list.
244 	 */
245 	public void insert(PgAttribute attr)
246 	{
247 		pango_attr_list_insert(pangoAttrList, (attr is null) ? null : attr.getPgAttributeStruct());
248 	}
249 
250 	/**
251 	 * Insert the given attribute into the `PangoAttrList`.
252 	 *
253 	 * It will be inserted before all other attributes with a
254 	 * matching @start_index.
255 	 *
256 	 * Params:
257 	 *     attr = the attribute to insert. Ownership of this
258 	 *         value is assumed by the list.
259 	 */
260 	public void insertBefore(PgAttribute attr)
261 	{
262 		pango_attr_list_insert_before(pangoAttrList, (attr is null) ? null : attr.getPgAttributeStruct());
263 	}
264 
265 	alias doref = ref_;
266 	/**
267 	 * Increase the reference count of the given attribute list by one.
268 	 *
269 	 * Returns: The attribute list passed in
270 	 *
271 	 * Since: 1.10
272 	 */
273 	public PgAttributeList ref_()
274 	{
275 		auto __p = pango_attr_list_ref(pangoAttrList);
276 
277 		if(__p is null)
278 		{
279 			return null;
280 		}
281 
282 		return ObjectG.getDObject!(PgAttributeList)(cast(PangoAttrList*) __p, true);
283 	}
284 
285 	/**
286 	 * This function opens up a hole in @list, fills it in with attributes
287 	 * from the left, and then merges @other on top of the hole.
288 	 *
289 	 * This operation is equivalent to stretching every attribute
290 	 * that applies at position @pos in @list by an amount @len,
291 	 * and then calling [method@Pango.AttrList.change] with a copy
292 	 * of each attribute in @other in sequence (offset in position
293 	 * by @pos).
294 	 *
295 	 * This operation proves useful for, for instance, inserting
296 	 * a pre-edit string in the middle of an edit buffer.
297 	 *
298 	 * Params:
299 	 *     other = another `PangoAttrList`
300 	 *     pos = the position in @list at which to insert @other
301 	 *     len = the length of the spliced segment. (Note that this
302 	 *         must be specified since the attributes in @other may only
303 	 *         be present at some subsection of this range)
304 	 */
305 	public void splice(PgAttributeList other, int pos, int len)
306 	{
307 		pango_attr_list_splice(pangoAttrList, (other is null) ? null : other.getPgAttributeListStruct(), pos, len);
308 	}
309 
310 	/**
311 	 * Decrease the reference count of the given attribute list by one.
312 	 * If the result is zero, free the attribute list and the attributes
313 	 * it contains.
314 	 */
315 	public void unref()
316 	{
317 		pango_attr_list_unref(pangoAttrList);
318 	}
319 
320 	/**
321 	 * Update indices of attributes in @list for a change in the
322 	 * text they refer to.
323 	 *
324 	 * The change that this function applies is removing @remove
325 	 * bytes at position @pos and inserting @add bytes instead.
326 	 *
327 	 * Attributes that fall entirely in the (@pos, @pos + @remove)
328 	 * range are removed.
329 	 *
330 	 * Attributes that start or end inside the (@pos, @pos + @remove)
331 	 * range are shortened to reflect the removal.
332 	 *
333 	 * Attributes start and end positions are updated if they are
334 	 * behind @pos + @remove.
335 	 *
336 	 * Params:
337 	 *     pos = the position of the change
338 	 *     remove = the number of removed bytes
339 	 *     add = the number of added bytes
340 	 *
341 	 * Since: 1.44
342 	 */
343 	public void update(int pos, int remove, int add)
344 	{
345 		pango_attr_list_update(pangoAttrList, pos, remove, add);
346 	}
347 }