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