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