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 gobject.ObjectG;
29 public  import gtkc.pangotypes;
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  * The #PangoAttrList structure represents a list of attributes
39  * that apply to a section of text. The attributes are, in general,
40  * allowed to overlap in an arbitrary fashion, however, if the
41  * attributes are manipulated only through pango_attr_list_change(),
42  * the overlap between properties will meet stricter criteria.
43  * 
44  * Since the #PangoAttrList structure is stored as a linear list,
45  * it is not suitable for storing attributes for large amounts
46  * of text. In general, you should not use a single #PangoAttrList
47  * for more than one paragraph of text.
48  */
49 public class PgAttributeList
50 {
51 	/** the main Gtk struct */
52 	protected PangoAttrList* pangoAttrList;
53 	protected bool ownedRef;
54 
55 	/** Get the main Gtk struct */
56 	public PangoAttrList* getPgAttributeListStruct(bool transferOwnership = false)
57 	{
58 		if (transferOwnership)
59 			ownedRef = false;
60 		return pangoAttrList;
61 	}
62 
63 	/** the main Gtk struct as a void* */
64 	protected void* getStruct()
65 	{
66 		return cast(void*)pangoAttrList;
67 	}
68 
69 	/**
70 	 * Sets our main struct and passes it to the parent class.
71 	 */
72 	public this (PangoAttrList* pangoAttrList, bool ownedRef = false)
73 	{
74 		this.pangoAttrList = pangoAttrList;
75 		this.ownedRef = ownedRef;
76 	}
77 
78 	~this ()
79 	{
80 		if ( Linker.isLoaded(LIBRARY_PANGO) && ownedRef )
81 			pango_attr_list_unref(pangoAttrList);
82 	}
83 
84 
85 	/** */
86 	public static GType getType()
87 	{
88 		return pango_attr_list_get_type();
89 	}
90 
91 	/**
92 	 * Create a new empty attribute list with a reference count of one.
93 	 *
94 	 * Returns: the newly allocated #PangoAttrList,
95 	 *     which should be freed with pango_attr_list_unref().
96 	 *
97 	 * Throws: ConstructionException GTK+ fails to create the object.
98 	 */
99 	public this()
100 	{
101 		auto p = pango_attr_list_new();
102 
103 		if(p is null)
104 		{
105 			throw new ConstructionException("null returned by new");
106 		}
107 
108 		this(cast(PangoAttrList*) p);
109 	}
110 
111 	/**
112 	 * Insert the given attribute into the #PangoAttrList. It will
113 	 * replace any attributes of the same type on that segment
114 	 * and be merged with any adjoining attributes that are identical.
115 	 *
116 	 * This function is slower than pango_attr_list_insert() for
117 	 * creating a attribute list in order (potentially much slower
118 	 * for large lists). However, pango_attr_list_insert() is not
119 	 * suitable for continually changing a set of attributes
120 	 * since it never removes or combines existing attributes.
121 	 *
122 	 * Params:
123 	 *     attr = the attribute to insert. Ownership of this
124 	 *         value is assumed by the list.
125 	 */
126 	public void change(PgAttribute attr)
127 	{
128 		pango_attr_list_change(pangoAttrList, (attr is null) ? null : attr.getPgAttributeStruct());
129 	}
130 
131 	/**
132 	 * Copy @list and return an identical new list.
133 	 *
134 	 * Returns: the newly allocated #PangoAttrList, with a
135 	 *     reference count of one, which should
136 	 *     be freed with pango_attr_list_unref().
137 	 *     Returns %NULL if @list was %NULL.
138 	 */
139 	public PgAttributeList copy()
140 	{
141 		auto p = pango_attr_list_copy(pangoAttrList);
142 
143 		if(p is null)
144 		{
145 			return null;
146 		}
147 
148 		return ObjectG.getDObject!(PgAttributeList)(cast(PangoAttrList*) p, true);
149 	}
150 
151 	/**
152 	 * Given a #PangoAttrList and callback function, removes any elements
153 	 * of @list for which @func returns %TRUE and inserts them into
154 	 * a new list.
155 	 *
156 	 * Params:
157 	 *     func = callback function; returns %TRUE
158 	 *         if an attribute should be filtered out.
159 	 *     data = Data to be passed to @func
160 	 *
161 	 * Returns: the new #PangoAttrList or
162 	 *     %NULL if no attributes of the given types were found.
163 	 *
164 	 * Since: 1.2
165 	 */
166 	public PgAttributeList filter(PangoAttrFilterFunc func, void* data)
167 	{
168 		auto p = pango_attr_list_filter(pangoAttrList, func, data);
169 
170 		if(p is null)
171 		{
172 			return null;
173 		}
174 
175 		return ObjectG.getDObject!(PgAttributeList)(cast(PangoAttrList*) p, true);
176 	}
177 
178 	/**
179 	 * Create a iterator initialized to the beginning of the list.
180 	 * @list must not be modified until this iterator is freed.
181 	 *
182 	 * Returns: the newly allocated #PangoAttrIterator, which should
183 	 *     be freed with pango_attr_iterator_destroy().
184 	 */
185 	public PgAttributeIterator getIterator()
186 	{
187 		auto p = pango_attr_list_get_iterator(pangoAttrList);
188 
189 		if(p is null)
190 		{
191 			return null;
192 		}
193 
194 		return ObjectG.getDObject!(PgAttributeIterator)(cast(PangoAttrIterator*) p, true);
195 	}
196 
197 	/**
198 	 * Insert the given attribute into the #PangoAttrList. It will
199 	 * be inserted after all other attributes with a matching
200 	 * @start_index.
201 	 *
202 	 * Params:
203 	 *     attr = the attribute to insert. Ownership of this
204 	 *         value is assumed by the list.
205 	 */
206 	public void insert(PgAttribute attr)
207 	{
208 		pango_attr_list_insert(pangoAttrList, (attr is null) ? null : attr.getPgAttributeStruct());
209 	}
210 
211 	/**
212 	 * Insert the given attribute into the #PangoAttrList. It will
213 	 * be inserted before all other attributes with a matching
214 	 * @start_index.
215 	 *
216 	 * Params:
217 	 *     attr = the attribute to insert. Ownership of this
218 	 *         value is assumed by the list.
219 	 */
220 	public void insertBefore(PgAttribute attr)
221 	{
222 		pango_attr_list_insert_before(pangoAttrList, (attr is null) ? null : attr.getPgAttributeStruct());
223 	}
224 
225 	alias doref = ref_;
226 	/**
227 	 * Increase the reference count of the given attribute list by one.
228 	 *
229 	 * Returns: The attribute list passed in
230 	 *
231 	 * Since: 1.10
232 	 */
233 	public PgAttributeList ref_()
234 	{
235 		auto p = pango_attr_list_ref(pangoAttrList);
236 
237 		if(p is null)
238 		{
239 			return null;
240 		}
241 
242 		return ObjectG.getDObject!(PgAttributeList)(cast(PangoAttrList*) p, true);
243 	}
244 
245 	/**
246 	 * This function opens up a hole in @list, fills it in with attributes from
247 	 * the left, and then merges @other on top of the hole.
248 	 *
249 	 * This operation is equivalent to stretching every attribute
250 	 * that applies at position @pos in @list by an amount @len,
251 	 * and then calling pango_attr_list_change() with a copy
252 	 * of each attribute in @other in sequence (offset in position by @pos).
253 	 *
254 	 * This operation proves useful for, for instance, inserting
255 	 * a pre-edit string in the middle of an edit buffer.
256 	 *
257 	 * Params:
258 	 *     other = another #PangoAttrList
259 	 *     pos = the position in @list at which to insert @other
260 	 *     len = the length of the spliced segment. (Note that this
261 	 *         must be specified since the attributes in @other
262 	 *         may only be present at some subsection of this range)
263 	 */
264 	public void splice(PgAttributeList other, int pos, int len)
265 	{
266 		pango_attr_list_splice(pangoAttrList, (other is null) ? null : other.getPgAttributeListStruct(), pos, len);
267 	}
268 
269 	/**
270 	 * Decrease the reference count of the given attribute list by one.
271 	 * If the result is zero, free the attribute list and the attributes
272 	 * it contains.
273 	 */
274 	public void unref()
275 	{
276 		pango_attr_list_unref(pangoAttrList);
277 	}
278 }