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