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.PgAttributeIterator;
26 
27 private import glib.ListSG;
28 private import gobject.ObjectG;
29 private import pango.PgAttribute;
30 private import pango.PgFontDescription;
31 private import pango.PgLanguage;
32 private import pango.c.functions;
33 public  import pango.c.types;
34 
35 
36 /**
37  * A `PangoAttrIterator` is used to iterate through a `PangoAttrList`.
38  * 
39  * A new iterator is created with [method@Pango.AttrList.get_iterator].
40  * Once the iterator is created, it can be advanced through the style
41  * changes in the text using [method@Pango.AttrIterator.next]. At each
42  * style change, the range of the current style segment and the attributes
43  * currently in effect can be queried.
44  */
45 public class PgAttributeIterator
46 {
47 	/** the main Gtk struct */
48 	protected PangoAttrIterator* pangoAttrIterator;
49 	protected bool ownedRef;
50 
51 	/** Get the main Gtk struct */
52 	public PangoAttrIterator* getPgAttributeIteratorStruct(bool transferOwnership = false)
53 	{
54 		if (transferOwnership)
55 			ownedRef = false;
56 		return pangoAttrIterator;
57 	}
58 
59 	/** the main Gtk struct as a void* */
60 	protected void* getStruct()
61 	{
62 		return cast(void*)pangoAttrIterator;
63 	}
64 
65 	/**
66 	 * Sets our main struct and passes it to the parent class.
67 	 */
68 	public this (PangoAttrIterator* pangoAttrIterator, bool ownedRef = false)
69 	{
70 		this.pangoAttrIterator = pangoAttrIterator;
71 		this.ownedRef = ownedRef;
72 	}
73 
74 
75 	/** */
76 	public static GType getType()
77 	{
78 		return pango_attr_iterator_get_type();
79 	}
80 
81 	/**
82 	 * Copy a `PangoAttrIterator`.
83 	 *
84 	 * Returns: the newly allocated `PangoAttrIterator`,
85 	 *     which should be freed with [method@Pango.AttrIterator.destroy].
86 	 */
87 	public PgAttributeIterator copy()
88 	{
89 		auto __p = pango_attr_iterator_copy(pangoAttrIterator);
90 
91 		if(__p is null)
92 		{
93 			return null;
94 		}
95 
96 		return ObjectG.getDObject!(PgAttributeIterator)(cast(PangoAttrIterator*) __p, true);
97 	}
98 
99 	/**
100 	 * Destroy a `PangoAttrIterator` and free all associated memory.
101 	 */
102 	public void destroy()
103 	{
104 		pango_attr_iterator_destroy(pangoAttrIterator);
105 	}
106 
107 	/**
108 	 * Find the current attribute of a particular type at the iterator
109 	 * location. When multiple attributes of the same type overlap,
110 	 * the attribute whose range starts closest to the current location
111 	 * is used.
112 	 *
113 	 * Params:
114 	 *     type = the type of attribute to find
115 	 *
116 	 * Returns: the current attribute of
117 	 *     the given type, or %NULL if no attribute of that type applies to
118 	 *     the current location.
119 	 */
120 	public PgAttribute get(PangoAttrType type)
121 	{
122 		auto __p = pango_attr_iterator_get(pangoAttrIterator, type);
123 
124 		if(__p is null)
125 		{
126 			return null;
127 		}
128 
129 		return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) __p);
130 	}
131 
132 	/**
133 	 * Gets a list of all attributes at the current position of the
134 	 * iterator.
135 	 *
136 	 * Returns: a list of all attributes for the current range. To free this value,
137 	 *     call [method@Pango.Attribute.destroy] on each value and g_slist_free()
138 	 *     on the list.
139 	 *
140 	 * Since: 1.2
141 	 */
142 	public ListSG getAttrs()
143 	{
144 		auto __p = pango_attr_iterator_get_attrs(pangoAttrIterator);
145 
146 		if(__p is null)
147 		{
148 			return null;
149 		}
150 
151 		return new ListSG(cast(GSList*) __p, true);
152 	}
153 
154 	/**
155 	 * Get the font and other attributes at the current iterator position.
156 	 *
157 	 * Params:
158 	 *     desc = a `PangoFontDescription` to fill in with the current values.
159 	 *         The family name in this structure will be set using
160 	 *         [method@Pango.FontDescription.set_family_static] using values from
161 	 *         an attribute in the `PangoAttrList` associated with the iterator,
162 	 *         so if you plan to keep it around, you must call:
163 	 *         pango_font_description_set_family (desc, pango_font_description_get_family (desc)).
164 	 *     language = if non-%NULL, location to store language tag
165 	 *         for item, or %NULL if none is found.
166 	 *     extraAttrs = if non-%NULL, location in which to store a list of non-font attributes
167 	 *         at the the current position; only the highest priority value of each
168 	 *         attribute will be added to this list. In order to free this value, you
169 	 *         must call [method@Pango.Attribute.destroy] on each member.
170 	 */
171 	public void getFont(PgFontDescription desc, out PgLanguage language, out ListSG extraAttrs)
172 	{
173 		PangoLanguage* outlanguage = null;
174 		GSList* outextraAttrs = null;
175 
176 		pango_attr_iterator_get_font(pangoAttrIterator, (desc is null) ? null : desc.getPgFontDescriptionStruct(), &outlanguage, &outextraAttrs);
177 
178 		language = ObjectG.getDObject!(PgLanguage)(outlanguage);
179 		extraAttrs = new ListSG(outextraAttrs);
180 	}
181 
182 	/**
183 	 * Advance the iterator until the next change of style.
184 	 *
185 	 * Returns: %FALSE if the iterator is at the end of the list,
186 	 *     otherwise %TRUE
187 	 */
188 	public bool next()
189 	{
190 		return pango_attr_iterator_next(pangoAttrIterator) != 0;
191 	}
192 
193 	/**
194 	 * Get the range of the current segment. Note that the
195 	 * stored return values are signed, not unsigned like
196 	 * the values in `PangoAttribute`. To deal with this API
197 	 * oversight, stored return values that wouldn't fit into
198 	 * a signed integer are clamped to %G_MAXINT.
199 	 *
200 	 * Params:
201 	 *     start = location to store the start of the range
202 	 *     end = location to store the end of the range
203 	 */
204 	public void range(out int start, out int end)
205 	{
206 		pango_attr_iterator_range(pangoAttrIterator, &start, &end);
207 	}
208 }