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