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.PgScriptIter;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 public  import gtkc.pangotypes;
31 private import gtkd.Loader;
32 private import pango.c.functions;
33 public  import pango.c.types;
34 
35 
36 /**
37  * A #PangoScriptIter is used to iterate through a string
38  * and identify ranges in different scripts.
39  */
40 public class PgScriptIter
41 {
42 	/** the main Gtk struct */
43 	protected PangoScriptIter* pangoScriptIter;
44 	protected bool ownedRef;
45 
46 	/** Get the main Gtk struct */
47 	public PangoScriptIter* getPgScriptIterStruct(bool transferOwnership = false)
48 	{
49 		if (transferOwnership)
50 			ownedRef = false;
51 		return pangoScriptIter;
52 	}
53 
54 	/** the main Gtk struct as a void* */
55 	protected void* getStruct()
56 	{
57 		return cast(void*)pangoScriptIter;
58 	}
59 
60 	/**
61 	 * Sets our main struct and passes it to the parent class.
62 	 */
63 	public this (PangoScriptIter* pangoScriptIter, bool ownedRef = false)
64 	{
65 		this.pangoScriptIter = pangoScriptIter;
66 		this.ownedRef = ownedRef;
67 	}
68 
69 	~this ()
70 	{
71 		if ( Linker.isLoaded(LIBRARY_PANGO) && ownedRef )
72 			pango_script_iter_free(pangoScriptIter);
73 	}
74 
75 
76 	/**
77 	 * Frees a #PangoScriptIter created with pango_script_iter_new().
78 	 *
79 	 * Since: 1.4
80 	 */
81 	public void free()
82 	{
83 		pango_script_iter_free(pangoScriptIter);
84 		ownedRef = false;
85 	}
86 
87 	/**
88 	 * Gets information about the range to which @iter currently points.
89 	 * The range is the set of locations p where *start <= p < *end.
90 	 * (That is, it doesn't include the character stored at *end)
91 	 *
92 	 * Params:
93 	 *     start = location to store start position of the range, or %NULL
94 	 *     end = location to store end position of the range, or %NULL
95 	 *     script = location to store script for range, or %NULL
96 	 *
97 	 * Since: 1.4
98 	 */
99 	public void getRange(out string start, out string end, out PangoScript script)
100 	{
101 		char* outstart = null;
102 		char* outend = null;
103 
104 		pango_script_iter_get_range(pangoScriptIter, &outstart, &outend, &script);
105 
106 		start = Str.toString(outstart);
107 		end = Str.toString(outend);
108 	}
109 
110 	/**
111 	 * Advances a #PangoScriptIter to the next range. If @iter
112 	 * is already at the end, it is left unchanged and %FALSE
113 	 * is returned.
114 	 *
115 	 * Returns: %TRUE if @iter was successfully advanced.
116 	 *
117 	 * Since: 1.4
118 	 */
119 	public bool next()
120 	{
121 		return pango_script_iter_next(pangoScriptIter) != 0;
122 	}
123 
124 	/**
125 	 * Create a new #PangoScriptIter, used to break a string of
126 	 * Unicode text into runs by Unicode script. No copy is made of
127 	 * @text, so the caller needs to make sure it remains valid until
128 	 * the iterator is freed with pango_script_iter_free().
129 	 *
130 	 * Params:
131 	 *     text = a UTF-8 string
132 	 *     length = length of @text, or -1 if @text is nul-terminated.
133 	 *
134 	 * Returns: the new script iterator, initialized
135 	 *     to point at the first range in the text, which should be
136 	 *     freed with pango_script_iter_free(). If the string is
137 	 *     empty, it will point at an empty range.
138 	 *
139 	 * Since: 1.4
140 	 *
141 	 * Throws: ConstructionException GTK+ fails to create the object.
142 	 */
143 	public this(string text, int length)
144 	{
145 		auto p = pango_script_iter_new(Str.toStringz(text), length);
146 
147 		if(p is null)
148 		{
149 			throw new ConstructionException("null returned by new");
150 		}
151 
152 		this(cast(PangoScriptIter*) p);
153 	}
154 }