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 gsv.Region;
26 
27 private import glib.ConstructionException;
28 private import glib.MemorySlice;
29 private import glib.Str;
30 private import gobject.ObjectG;
31 private import gsv.RegionIter;
32 private import gsv.c.functions;
33 public  import gsv.c.types;
34 public  import gsvc.gsvtypes;
35 private import gtk.TextBuffer;
36 private import gtk.TextIter;
37 
38 
39 /** */
40 public class Region : ObjectG
41 {
42 	/** the main Gtk struct */
43 	protected GtkSourceRegion* gtkSourceRegion;
44 
45 	/** Get the main Gtk struct */
46 	public GtkSourceRegion* getRegionStruct(bool transferOwnership = false)
47 	{
48 		if (transferOwnership)
49 			ownedRef = false;
50 		return gtkSourceRegion;
51 	}
52 
53 	/** the main Gtk struct as a void* */
54 	protected override void* getStruct()
55 	{
56 		return cast(void*)gtkSourceRegion;
57 	}
58 
59 	/**
60 	 * Sets our main struct and passes it to the parent class.
61 	 */
62 	public this (GtkSourceRegion* gtkSourceRegion, bool ownedRef = false)
63 	{
64 		this.gtkSourceRegion = gtkSourceRegion;
65 		super(cast(GObject*)gtkSourceRegion, ownedRef);
66 	}
67 
68 
69 	/** */
70 	public static GType getType()
71 	{
72 		return gtk_source_region_get_type();
73 	}
74 
75 	/**
76 	 *
77 	 * Params:
78 	 *     buffer = a #GtkTextBuffer.
79 	 * Returns: a new #GtkSourceRegion object for @buffer.
80 	 *
81 	 * Since: 3.22
82 	 *
83 	 * Throws: ConstructionException GTK+ fails to create the object.
84 	 */
85 	public this(TextBuffer buffer)
86 	{
87 		auto p = gtk_source_region_new((buffer is null) ? null : buffer.getTextBufferStruct());
88 
89 		if(p is null)
90 		{
91 			throw new ConstructionException("null returned by new");
92 		}
93 
94 		this(cast(GtkSourceRegion*) p, true);
95 	}
96 
97 	/**
98 	 * Adds @region_to_add to @region. @region_to_add is not modified.
99 	 *
100 	 * Params:
101 	 *     regionToAdd = the #GtkSourceRegion to add to @region, or %NULL.
102 	 *
103 	 * Since: 3.22
104 	 */
105 	public void addRegion(Region regionToAdd)
106 	{
107 		gtk_source_region_add_region(gtkSourceRegion, (regionToAdd is null) ? null : regionToAdd.getRegionStruct());
108 	}
109 
110 	/**
111 	 * Adds the subregion delimited by @_start and @_end to @region.
112 	 *
113 	 * Params:
114 	 *     Start = the start of the subregion.
115 	 *     End = the end of the subregion.
116 	 *
117 	 * Since: 3.22
118 	 */
119 	public void addSubregion(TextIter Start, TextIter End)
120 	{
121 		gtk_source_region_add_subregion(gtkSourceRegion, (Start is null) ? null : Start.getTextIterStruct(), (End is null) ? null : End.getTextIterStruct());
122 	}
123 
124 	/**
125 	 * Gets the @start and @end bounds of the @region.
126 	 *
127 	 * Params:
128 	 *     start = iterator to initialize with the start of @region,
129 	 *         or %NULL.
130 	 *     end = iterator to initialize with the end of @region,
131 	 *         or %NULL.
132 	 *
133 	 * Returns: %TRUE if @start and @end have been set successfully (if non-%NULL),
134 	 *     or %FALSE if the @region is empty.
135 	 *
136 	 * Since: 3.22
137 	 */
138 	public bool getBounds(out TextIter start, out TextIter end)
139 	{
140 		GtkTextIter* outstart = sliceNew!GtkTextIter();
141 		GtkTextIter* outend = sliceNew!GtkTextIter();
142 
143 		auto p = gtk_source_region_get_bounds(gtkSourceRegion, outstart, outend) != 0;
144 
145 		start = ObjectG.getDObject!(TextIter)(outstart, true);
146 		end = ObjectG.getDObject!(TextIter)(outend, true);
147 
148 		return p;
149 	}
150 
151 	/**
152 	 * Returns: the #GtkTextBuffer.
153 	 *
154 	 * Since: 3.22
155 	 */
156 	public TextBuffer getBuffer()
157 	{
158 		auto p = gtk_source_region_get_buffer(gtkSourceRegion);
159 
160 		if(p is null)
161 		{
162 			return null;
163 		}
164 
165 		return ObjectG.getDObject!(TextBuffer)(cast(GtkTextBuffer*) p);
166 	}
167 
168 	/**
169 	 * Initializes a #GtkSourceRegionIter to the first subregion of @region. If
170 	 * @region is empty, @iter will be initialized to the end iterator.
171 	 *
172 	 * Params:
173 	 *     iter = iterator to initialize to the first subregion.
174 	 *
175 	 * Since: 3.22
176 	 */
177 	public void getStartRegionIter(out RegionIter iter)
178 	{
179 		GtkSourceRegionIter* outiter = sliceNew!GtkSourceRegionIter();
180 
181 		gtk_source_region_get_start_region_iter(gtkSourceRegion, outiter);
182 
183 		iter = ObjectG.getDObject!(RegionIter)(outiter, true);
184 	}
185 
186 	/**
187 	 * Returns the intersection between @region1 and @region2. @region1 and
188 	 * @region2 are not modified.
189 	 *
190 	 * Params:
191 	 *     region2 = a #GtkSourceRegion, or %NULL.
192 	 *
193 	 * Returns: the intersection as a #GtkSourceRegion
194 	 *     object.
195 	 *
196 	 * Since: 3.22
197 	 */
198 	public Region intersectRegion(Region region2)
199 	{
200 		auto p = gtk_source_region_intersect_region(gtkSourceRegion, (region2 is null) ? null : region2.getRegionStruct());
201 
202 		if(p is null)
203 		{
204 			return null;
205 		}
206 
207 		return ObjectG.getDObject!(Region)(cast(GtkSourceRegion*) p, true);
208 	}
209 
210 	/**
211 	 * Returns the intersection between @region and the subregion delimited by
212 	 * @_start and @_end. @region is not modified.
213 	 *
214 	 * Params:
215 	 *     Start = the start of the subregion.
216 	 *     End = the end of the subregion.
217 	 *
218 	 * Returns: the intersection as a new
219 	 *     #GtkSourceRegion.
220 	 *
221 	 * Since: 3.22
222 	 */
223 	public Region intersectSubregion(TextIter Start, TextIter End)
224 	{
225 		auto p = gtk_source_region_intersect_subregion(gtkSourceRegion, (Start is null) ? null : Start.getTextIterStruct(), (End is null) ? null : End.getTextIterStruct());
226 
227 		if(p is null)
228 		{
229 			return null;
230 		}
231 
232 		return ObjectG.getDObject!(Region)(cast(GtkSourceRegion*) p, true);
233 	}
234 
235 	/**
236 	 * Returns whether the @region is empty. A %NULL @region is considered empty.
237 	 *
238 	 * Returns: whether the @region is empty.
239 	 *
240 	 * Since: 3.22
241 	 */
242 	public bool isEmpty()
243 	{
244 		return gtk_source_region_is_empty(gtkSourceRegion) != 0;
245 	}
246 
247 	/**
248 	 * Subtracts @region_to_subtract from @region. @region_to_subtract is not
249 	 * modified.
250 	 *
251 	 * Params:
252 	 *     regionToSubtract = the #GtkSourceRegion to subtract from
253 	 *         @region, or %NULL.
254 	 *
255 	 * Since: 3.22
256 	 */
257 	public void subtractRegion(Region regionToSubtract)
258 	{
259 		gtk_source_region_subtract_region(gtkSourceRegion, (regionToSubtract is null) ? null : regionToSubtract.getRegionStruct());
260 	}
261 
262 	/**
263 	 * Subtracts the subregion delimited by @_start and @_end from @region.
264 	 *
265 	 * Params:
266 	 *     Start = the start of the subregion.
267 	 *     End = the end of the subregion.
268 	 *
269 	 * Since: 3.22
270 	 */
271 	public void subtractSubregion(TextIter Start, TextIter End)
272 	{
273 		gtk_source_region_subtract_subregion(gtkSourceRegion, (Start is null) ? null : Start.getTextIterStruct(), (End is null) ? null : End.getTextIterStruct());
274 	}
275 
276 	/**
277 	 * Gets a string represention of @region, for debugging purposes.
278 	 *
279 	 * The returned string contains the character offsets of the subregions. It
280 	 * doesn't include a newline character at the end of the string.
281 	 *
282 	 * Returns: a string represention of @region. Free
283 	 *     with g_free() when no longer needed.
284 	 *
285 	 * Since: 3.22
286 	 */
287 	public override string toString()
288 	{
289 		auto retStr = gtk_source_region_to_string(gtkSourceRegion);
290 
291 		scope(exit) Str.freeString(retStr);
292 		return Str.toString(retStr);
293 	}
294 }