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