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 gtkc.pango;
30 public  import gtkc.pangotypes;
31 private import pango.PgAttribute;
32 private import pango.PgFontDescription;
33 private import pango.PgLanguage;
34 
35 
36 /**
37  * The #PangoAttrIterator structure is used to represent an
38  * iterator through a #PangoAttrList. A new iterator is created
39  * with pango_attr_list_get_iterator(). Once the iterator
40  * is created, it can be advanced through the style changes
41  * in the text using pango_attr_iterator_next(). At each
42  * style change, the range of the current style segment and the
43  * attributes 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 	 * Copy a #PangoAttrIterator
77 	 *
78 	 * Returns: the newly allocated
79 	 *     #PangoAttrIterator, which should be freed with
80 	 *     pango_attr_iterator_destroy().
81 	 */
82 	public PgAttributeIterator copy()
83 	{
84 		auto p = pango_attr_iterator_copy(pangoAttrIterator);
85 		
86 		if(p is null)
87 		{
88 			return null;
89 		}
90 		
91 		return ObjectG.getDObject!(PgAttributeIterator)(cast(PangoAttrIterator*) p, true);
92 	}
93 
94 	/**
95 	 * Destroy a #PangoAttrIterator and free all associated memory.
96 	 */
97 	public void destroy()
98 	{
99 		pango_attr_iterator_destroy(pangoAttrIterator);
100 	}
101 
102 	/**
103 	 * Find the current attribute of a particular type at the iterator
104 	 * location. When multiple attributes of the same type overlap,
105 	 * the attribute whose range starts closest to the current location
106 	 * is used.
107 	 *
108 	 * Params:
109 	 *     type = the type of attribute to find.
110 	 *
111 	 * Returns: the current attribute of the given type,
112 	 *     or %NULL if no attribute of that type applies to the
113 	 *     current location.
114 	 */
115 	public PgAttribute get(PangoAttrType type)
116 	{
117 		auto p = pango_attr_iterator_get(pangoAttrIterator, type);
118 		
119 		if(p is null)
120 		{
121 			return null;
122 		}
123 		
124 		return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p);
125 	}
126 
127 	/**
128 	 * Gets a list of all attributes at the current position of the
129 	 * iterator.
130 	 *
131 	 * Returns: a list of
132 	 *     all attributes for the current range.
133 	 *     To free this value, call pango_attribute_destroy() on
134 	 *     each value and g_slist_free() on the list.
135 	 *
136 	 * Since: 1.2
137 	 */
138 	public ListSG getAttrs()
139 	{
140 		auto p = pango_attr_iterator_get_attrs(pangoAttrIterator);
141 		
142 		if(p is null)
143 		{
144 			return null;
145 		}
146 		
147 		return new ListSG(cast(GSList*) p, true);
148 	}
149 
150 	/**
151 	 * Get the font and other attributes at the current iterator position.
152 	 *
153 	 * Params:
154 	 *     desc = a #PangoFontDescription to fill in with the current values.
155 	 *         The family name in this structure will be set using
156 	 *         pango_font_description_set_family_static() using values from
157 	 *         an attribute in the #PangoAttrList associated with the iterator,
158 	 *         so if you plan to keep it around, you must call:
159 	 *         <literal>pango_font_description_set_family (desc, pango_font_description_get_family (desc))</literal>.
160 	 *     language = if non-%NULL, location to store language tag for item, or %NULL
161 	 *         if none is found.
162 	 *     extraAttrs = if non-%NULL,
163 	 *         location in which to store a list of non-font
164 	 *         attributes at the the current position; only the highest priority
165 	 *         value of each attribute will be added to this list. In order
166 	 *         to free this value, you must call pango_attribute_destroy() on
167 	 *         each member.
168 	 */
169 	public void getFont(PgFontDescription desc, out PgLanguage language, out ListSG extraAttrs)
170 	{
171 		PangoLanguage* outlanguage = null;
172 		GSList* outextraAttrs = null;
173 		
174 		pango_attr_iterator_get_font(pangoAttrIterator, (desc is null) ? null : desc.getPgFontDescriptionStruct(), &outlanguage, &outextraAttrs);
175 		
176 		language = ObjectG.getDObject!(PgLanguage)(outlanguage);
177 		extraAttrs = new ListSG(outextraAttrs);
178 	}
179 
180 	/**
181 	 * Advance the iterator until the next change of style.
182 	 *
183 	 * Returns: %FALSE if the iterator is at the end of the list, otherwise %TRUE
184 	 */
185 	public bool next()
186 	{
187 		return pango_attr_iterator_next(pangoAttrIterator) != 0;
188 	}
189 
190 	/**
191 	 * Get the range of the current segment. Note that the
192 	 * stored return values are signed, not unsigned like
193 	 * the values in #PangoAttribute. To deal with this API
194 	 * oversight, stored return values that wouldn't fit into
195 	 * a signed integer are clamped to %G_MAXINT.
196 	 *
197 	 * Params:
198 	 *     start = location to store the start of the range
199 	 *     end = location to store the end of the range
200 	 */
201 	public void range(out int start, out int end)
202 	{
203 		pango_attr_iterator_range(pangoAttrIterator, &start, &end);
204 	}
205 }