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.SourceSearchContext;
26 
27 private import gio.AsyncResultIF;
28 private import gio.Cancellable;
29 private import glib.ConstructionException;
30 private import glib.ErrorG;
31 private import glib.GException;
32 private import glib.MemorySlice;
33 private import glib.Str;
34 private import gobject.ObjectG;
35 private import gsv.SourceBuffer;
36 private import gsv.SourceSearchSettings;
37 private import gsv.SourceStyle;
38 private import gsv.c.functions;
39 public  import gsv.c.types;
40 public  import gsvc.gsvtypes;
41 private import gtk.TextIter;
42 
43 
44 /** */
45 public class SourceSearchContext : ObjectG
46 {
47 	/** the main Gtk struct */
48 	protected GtkSourceSearchContext* gtkSourceSearchContext;
49 
50 	/** Get the main Gtk struct */
51 	public GtkSourceSearchContext* getSourceSearchContextStruct(bool transferOwnership = false)
52 	{
53 		if (transferOwnership)
54 			ownedRef = false;
55 		return gtkSourceSearchContext;
56 	}
57 
58 	/** the main Gtk struct as a void* */
59 	protected override void* getStruct()
60 	{
61 		return cast(void*)gtkSourceSearchContext;
62 	}
63 
64 	/**
65 	 * Sets our main struct and passes it to the parent class.
66 	 */
67 	public this (GtkSourceSearchContext* gtkSourceSearchContext, bool ownedRef = false)
68 	{
69 		this.gtkSourceSearchContext = gtkSourceSearchContext;
70 		super(cast(GObject*)gtkSourceSearchContext, ownedRef);
71 	}
72 
73 
74 	/** */
75 	public static GType getType()
76 	{
77 		return gtk_source_search_context_get_type();
78 	}
79 
80 	/**
81 	 * Creates a new search context, associated with @buffer, and customized with
82 	 * @settings. If @settings is %NULL, a new #GtkSourceSearchSettings object will
83 	 * be created, that you can retrieve with
84 	 * gtk_source_search_context_get_settings().
85 	 *
86 	 * Params:
87 	 *     buffer = a #GtkSourceBuffer.
88 	 *     settings = a #GtkSourceSearchSettings, or %NULL.
89 	 *
90 	 * Returns: a new search context.
91 	 *
92 	 * Since: 3.10
93 	 *
94 	 * Throws: ConstructionException GTK+ fails to create the object.
95 	 */
96 	public this(SourceBuffer buffer, SourceSearchSettings settings)
97 	{
98 		auto p = gtk_source_search_context_new((buffer is null) ? null : buffer.getSourceBufferStruct(), (settings is null) ? null : settings.getSourceSearchSettingsStruct());
99 
100 		if(p is null)
101 		{
102 			throw new ConstructionException("null returned by new");
103 		}
104 
105 		this(cast(GtkSourceSearchContext*) p, true);
106 	}
107 
108 	/**
109 	 * Synchronous backward search. It is recommended to use the asynchronous
110 	 * functions instead, to not block the user interface. However, if you are sure
111 	 * that the @buffer is small, this function is more convenient to use.
112 	 *
113 	 * If the #GtkSourceSearchSettings:wrap-around property is %FALSE, this function
114 	 * doesn't try to wrap around.
115 	 *
116 	 * The @has_wrapped_around out parameter is set independently of whether a match
117 	 * is found. So if this function returns %FALSE, @has_wrapped_around will have
118 	 * the same value as the #GtkSourceSearchSettings:wrap-around property.
119 	 *
120 	 * Params:
121 	 *     iter = start of search.
122 	 *     matchStart = return location for start of match, or %NULL.
123 	 *     matchEnd = return location for end of match, or %NULL.
124 	 *     hasWrappedAround = return location to know whether the
125 	 *         search has wrapped around, or %NULL.
126 	 *
127 	 * Returns: whether a match was found.
128 	 *
129 	 * Since: 4.0
130 	 */
131 	public bool backward(TextIter iter, out TextIter matchStart, out TextIter matchEnd, out bool hasWrappedAround)
132 	{
133 		GtkTextIter* outmatchStart = sliceNew!GtkTextIter();
134 		GtkTextIter* outmatchEnd = sliceNew!GtkTextIter();
135 		int outhasWrappedAround;
136 
137 		auto p = gtk_source_search_context_backward(gtkSourceSearchContext, (iter is null) ? null : iter.getTextIterStruct(), outmatchStart, outmatchEnd, &outhasWrappedAround) != 0;
138 
139 		matchStart = ObjectG.getDObject!(TextIter)(outmatchStart, true);
140 		matchEnd = ObjectG.getDObject!(TextIter)(outmatchEnd, true);
141 		hasWrappedAround = (outhasWrappedAround == 1);
142 
143 		return p;
144 	}
145 
146 	/**
147 	 * The asynchronous version of gtk_source_search_context_backward().
148 	 *
149 	 * See the documentation of gtk_source_search_context_backward() for more
150 	 * details.
151 	 *
152 	 * See the #GAsyncResult documentation to know how to use this function.
153 	 *
154 	 * If the operation is cancelled, the @callback will only be called if
155 	 * @cancellable was not %NULL. gtk_source_search_context_backward_async() takes
156 	 * ownership of @cancellable, so you can unref it after calling this function.
157 	 *
158 	 * Params:
159 	 *     iter = start of search.
160 	 *     cancellable = a #GCancellable, or %NULL.
161 	 *     callback = a #GAsyncReadyCallback to call when the operation is finished.
162 	 *     userData = the data to pass to the @callback function.
163 	 *
164 	 * Since: 3.10
165 	 */
166 	public void backwardAsync(TextIter iter, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
167 	{
168 		gtk_source_search_context_backward_async(gtkSourceSearchContext, (iter is null) ? null : iter.getTextIterStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
169 	}
170 
171 	/**
172 	 * Finishes a backward search started with
173 	 * gtk_source_search_context_backward_async().
174 	 *
175 	 * See the documentation of gtk_source_search_context_backward() for more
176 	 * details.
177 	 *
178 	 * Params:
179 	 *     result = a #GAsyncResult.
180 	 *     matchStart = return location for start of match, or %NULL.
181 	 *     matchEnd = return location for end of match, or %NULL.
182 	 *     hasWrappedAround = return location to know whether the
183 	 *         search has wrapped around, or %NULL.
184 	 *
185 	 * Returns: whether a match was found.
186 	 *
187 	 * Since: 4.0
188 	 *
189 	 * Throws: GException on failure.
190 	 */
191 	public bool backwardFinish(AsyncResultIF result, out TextIter matchStart, out TextIter matchEnd, out bool hasWrappedAround)
192 	{
193 		GtkTextIter* outmatchStart = sliceNew!GtkTextIter();
194 		GtkTextIter* outmatchEnd = sliceNew!GtkTextIter();
195 		int outhasWrappedAround;
196 		GError* err = null;
197 
198 		auto p = gtk_source_search_context_backward_finish(gtkSourceSearchContext, (result is null) ? null : result.getAsyncResultStruct(), outmatchStart, outmatchEnd, &outhasWrappedAround, &err) != 0;
199 
200 		if (err !is null)
201 		{
202 			throw new GException( new ErrorG(err) );
203 		}
204 
205 		matchStart = ObjectG.getDObject!(TextIter)(outmatchStart, true);
206 		matchEnd = ObjectG.getDObject!(TextIter)(outmatchEnd, true);
207 		hasWrappedAround = (outhasWrappedAround == 1);
208 
209 		return p;
210 	}
211 
212 	/**
213 	 * Synchronous forward search. It is recommended to use the asynchronous
214 	 * functions instead, to not block the user interface. However, if you are sure
215 	 * that the @buffer is small, this function is more convenient to use.
216 	 *
217 	 * If the #GtkSourceSearchSettings:wrap-around property is %FALSE, this function
218 	 * doesn't try to wrap around.
219 	 *
220 	 * The @has_wrapped_around out parameter is set independently of whether a match
221 	 * is found. So if this function returns %FALSE, @has_wrapped_around will have
222 	 * the same value as the #GtkSourceSearchSettings:wrap-around property.
223 	 *
224 	 * Params:
225 	 *     iter = start of search.
226 	 *     matchStart = return location for start of match, or %NULL.
227 	 *     matchEnd = return location for end of match, or %NULL.
228 	 *     hasWrappedAround = return location to know whether the
229 	 *         search has wrapped around, or %NULL.
230 	 *
231 	 * Returns: whether a match was found.
232 	 *
233 	 * Since: 4.0
234 	 */
235 	public bool forward(TextIter iter, out TextIter matchStart, out TextIter matchEnd, out bool hasWrappedAround)
236 	{
237 		GtkTextIter* outmatchStart = sliceNew!GtkTextIter();
238 		GtkTextIter* outmatchEnd = sliceNew!GtkTextIter();
239 		int outhasWrappedAround;
240 
241 		auto p = gtk_source_search_context_forward(gtkSourceSearchContext, (iter is null) ? null : iter.getTextIterStruct(), outmatchStart, outmatchEnd, &outhasWrappedAround) != 0;
242 
243 		matchStart = ObjectG.getDObject!(TextIter)(outmatchStart, true);
244 		matchEnd = ObjectG.getDObject!(TextIter)(outmatchEnd, true);
245 		hasWrappedAround = (outhasWrappedAround == 1);
246 
247 		return p;
248 	}
249 
250 	/**
251 	 * The asynchronous version of gtk_source_search_context_forward().
252 	 *
253 	 * See the documentation of gtk_source_search_context_forward() for more
254 	 * details.
255 	 *
256 	 * See the #GAsyncResult documentation to know how to use this function.
257 	 *
258 	 * If the operation is cancelled, the @callback will only be called if
259 	 * @cancellable was not %NULL. gtk_source_search_context_forward_async() takes
260 	 * ownership of @cancellable, so you can unref it after calling this function.
261 	 *
262 	 * Params:
263 	 *     iter = start of search.
264 	 *     cancellable = a #GCancellable, or %NULL.
265 	 *     callback = a #GAsyncReadyCallback to call when the operation is finished.
266 	 *     userData = the data to pass to the @callback function.
267 	 *
268 	 * Since: 3.10
269 	 */
270 	public void forwardAsync(TextIter iter, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
271 	{
272 		gtk_source_search_context_forward_async(gtkSourceSearchContext, (iter is null) ? null : iter.getTextIterStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
273 	}
274 
275 	/**
276 	 * Finishes a forward search started with
277 	 * gtk_source_search_context_forward_async().
278 	 *
279 	 * See the documentation of gtk_source_search_context_forward() for more
280 	 * details.
281 	 *
282 	 * Params:
283 	 *     result = a #GAsyncResult.
284 	 *     matchStart = return location for start of match, or %NULL.
285 	 *     matchEnd = return location for end of match, or %NULL.
286 	 *     hasWrappedAround = return location to know whether the
287 	 *         search has wrapped around, or %NULL.
288 	 *
289 	 * Returns: whether a match was found.
290 	 *
291 	 * Since: 4.0
292 	 *
293 	 * Throws: GException on failure.
294 	 */
295 	public bool forwardFinish(AsyncResultIF result, out TextIter matchStart, out TextIter matchEnd, out bool hasWrappedAround)
296 	{
297 		GtkTextIter* outmatchStart = sliceNew!GtkTextIter();
298 		GtkTextIter* outmatchEnd = sliceNew!GtkTextIter();
299 		int outhasWrappedAround;
300 		GError* err = null;
301 
302 		auto p = gtk_source_search_context_forward_finish(gtkSourceSearchContext, (result is null) ? null : result.getAsyncResultStruct(), outmatchStart, outmatchEnd, &outhasWrappedAround, &err) != 0;
303 
304 		if (err !is null)
305 		{
306 			throw new GException( new ErrorG(err) );
307 		}
308 
309 		matchStart = ObjectG.getDObject!(TextIter)(outmatchStart, true);
310 		matchEnd = ObjectG.getDObject!(TextIter)(outmatchEnd, true);
311 		hasWrappedAround = (outhasWrappedAround == 1);
312 
313 		return p;
314 	}
315 
316 	/**
317 	 * Returns: the associated buffer.
318 	 *
319 	 * Since: 3.10
320 	 */
321 	public SourceBuffer getBuffer()
322 	{
323 		auto p = gtk_source_search_context_get_buffer(gtkSourceSearchContext);
324 
325 		if(p is null)
326 		{
327 			return null;
328 		}
329 
330 		return ObjectG.getDObject!(SourceBuffer)(cast(GtkSourceBuffer*) p);
331 	}
332 
333 	/**
334 	 * Returns: whether to highlight the search occurrences.
335 	 *
336 	 * Since: 3.10
337 	 */
338 	public bool getHighlight()
339 	{
340 		return gtk_source_search_context_get_highlight(gtkSourceSearchContext) != 0;
341 	}
342 
343 	/**
344 	 * Returns: the #GtkSourceStyle to apply on search matches.
345 	 *
346 	 * Since: 3.16
347 	 */
348 	public SourceStyle getMatchStyle()
349 	{
350 		auto p = gtk_source_search_context_get_match_style(gtkSourceSearchContext);
351 
352 		if(p is null)
353 		{
354 			return null;
355 		}
356 
357 		return ObjectG.getDObject!(SourceStyle)(cast(GtkSourceStyle*) p);
358 	}
359 
360 	/**
361 	 * Gets the position of a search occurrence. If the buffer is not already fully
362 	 * scanned, the position may be unknown, and -1 is returned. If 0 is returned,
363 	 * it means that this part of the buffer has already been scanned, and that
364 	 * @match_start and @match_end don't delimit an occurrence.
365 	 *
366 	 * Params:
367 	 *     matchStart = the start of the occurrence.
368 	 *     matchEnd = the end of the occurrence.
369 	 *
370 	 * Returns: the position of the search occurrence. The first occurrence has the
371 	 *     position 1 (not 0). Returns 0 if @match_start and @match_end don't delimit
372 	 *     an occurrence. Returns -1 if the position is not yet known.
373 	 *
374 	 * Since: 3.10
375 	 */
376 	public int getOccurrencePosition(TextIter matchStart, TextIter matchEnd)
377 	{
378 		return gtk_source_search_context_get_occurrence_position(gtkSourceSearchContext, (matchStart is null) ? null : matchStart.getTextIterStruct(), (matchEnd is null) ? null : matchEnd.getTextIterStruct());
379 	}
380 
381 	/**
382 	 * Gets the total number of search occurrences. If the buffer is not already
383 	 * fully scanned, the total number of occurrences is unknown, and -1 is
384 	 * returned.
385 	 *
386 	 * Returns: the total number of search occurrences, or -1 if unknown.
387 	 *
388 	 * Since: 3.10
389 	 */
390 	public int getOccurrencesCount()
391 	{
392 		return gtk_source_search_context_get_occurrences_count(gtkSourceSearchContext);
393 	}
394 
395 	/**
396 	 * Regular expression patterns must follow certain rules. If
397 	 * #GtkSourceSearchSettings:search-text breaks a rule, the error can be retrieved
398 	 * with this function. The error domain is #G_REGEX_ERROR.
399 	 *
400 	 * Free the return value with g_error_free().
401 	 *
402 	 * Returns: the #GError, or %NULL if the pattern is valid.
403 	 *
404 	 * Since: 3.10
405 	 */
406 	public ErrorG getRegexError()
407 	{
408 		auto p = gtk_source_search_context_get_regex_error(gtkSourceSearchContext);
409 
410 		if(p is null)
411 		{
412 			return null;
413 		}
414 
415 		return new ErrorG(cast(GError*) p, true);
416 	}
417 
418 	/**
419 	 * Returns: the search settings.
420 	 *
421 	 * Since: 3.10
422 	 */
423 	public SourceSearchSettings getSettings()
424 	{
425 		auto p = gtk_source_search_context_get_settings(gtkSourceSearchContext);
426 
427 		if(p is null)
428 		{
429 			return null;
430 		}
431 
432 		return ObjectG.getDObject!(SourceSearchSettings)(cast(GtkSourceSearchSettings*) p);
433 	}
434 
435 	/**
436 	 * Replaces a search match by another text. If @match_start and @match_end
437 	 * doesn't correspond to a search match, %FALSE is returned.
438 	 *
439 	 * @match_start and @match_end iters are revalidated to point to the replacement
440 	 * text boundaries.
441 	 *
442 	 * For a regular expression replacement, you can check if @replace is valid by
443 	 * calling g_regex_check_replacement(). The @replace text can contain
444 	 * backreferences; read the g_regex_replace() documentation for more details.
445 	 *
446 	 * Params:
447 	 *     matchStart = the start of the match to replace.
448 	 *     matchEnd = the end of the match to replace.
449 	 *     replace = the replacement text.
450 	 *     replaceLength = the length of @replace in bytes, or -1.
451 	 *
452 	 * Returns: whether the match has been replaced.
453 	 *
454 	 * Since: 4.0
455 	 *
456 	 * Throws: GException on failure.
457 	 */
458 	public bool replace(TextIter matchStart, TextIter matchEnd, string replace, int replaceLength)
459 	{
460 		GError* err = null;
461 
462 		auto p = gtk_source_search_context_replace(gtkSourceSearchContext, (matchStart is null) ? null : matchStart.getTextIterStruct(), (matchEnd is null) ? null : matchEnd.getTextIterStruct(), Str.toStringz(replace), replaceLength, &err) != 0;
463 
464 		if (err !is null)
465 		{
466 			throw new GException( new ErrorG(err) );
467 		}
468 
469 		return p;
470 	}
471 
472 	/**
473 	 * Replaces all search matches by another text. It is a synchronous function, so
474 	 * it can block the user interface.
475 	 *
476 	 * For a regular expression replacement, you can check if @replace is valid by
477 	 * calling g_regex_check_replacement(). The @replace text can contain
478 	 * backreferences; read the g_regex_replace() documentation for more details.
479 	 *
480 	 * Params:
481 	 *     replace = the replacement text.
482 	 *     replaceLength = the length of @replace in bytes, or -1.
483 	 *
484 	 * Returns: the number of replaced matches.
485 	 *
486 	 * Since: 3.10
487 	 *
488 	 * Throws: GException on failure.
489 	 */
490 	public uint replaceAll(string replace, int replaceLength)
491 	{
492 		GError* err = null;
493 
494 		auto p = gtk_source_search_context_replace_all(gtkSourceSearchContext, Str.toStringz(replace), replaceLength, &err);
495 
496 		if (err !is null)
497 		{
498 			throw new GException( new ErrorG(err) );
499 		}
500 
501 		return p;
502 	}
503 
504 	/**
505 	 * Enables or disables the search occurrences highlighting.
506 	 *
507 	 * Params:
508 	 *     highlight = the setting.
509 	 *
510 	 * Since: 3.10
511 	 */
512 	public void setHighlight(bool highlight)
513 	{
514 		gtk_source_search_context_set_highlight(gtkSourceSearchContext, highlight);
515 	}
516 
517 	/**
518 	 * Set the style to apply on search matches. If @match_style is %NULL, default
519 	 * theme's scheme 'match-style' will be used.
520 	 * To enable or disable the search highlighting, use
521 	 * gtk_source_search_context_set_highlight().
522 	 *
523 	 * Params:
524 	 *     matchStyle = a #GtkSourceStyle, or %NULL.
525 	 *
526 	 * Since: 3.16
527 	 */
528 	public void setMatchStyle(SourceStyle matchStyle)
529 	{
530 		gtk_source_search_context_set_match_style(gtkSourceSearchContext, (matchStyle is null) ? null : matchStyle.getSourceStyleStruct());
531 	}
532 }