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