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.SourceCompletion;
26 
27 private import glib.ErrorG;
28 private import glib.GException;
29 private import glib.ListG;
30 private import gobject.ObjectG;
31 private import gobject.Signals;
32 private import gsv.SourceCompletionContext;
33 private import gsv.SourceCompletionInfo;
34 private import gsv.SourceCompletionProviderIF;
35 private import gsv.SourceView;
36 private import gsvc.gsv;
37 public  import gsvc.gsvtypes;
38 private import gtk.BuildableIF;
39 private import gtk.BuildableT;
40 private import gtk.TextIter;
41 private import std.algorithm;
42 
43 
44 /** */
45 public class SourceCompletion : ObjectG, BuildableIF
46 {
47 	/** the main Gtk struct */
48 	protected GtkSourceCompletion* gtkSourceCompletion;
49 
50 	/** Get the main Gtk struct */
51 	public GtkSourceCompletion* getSourceCompletionStruct(bool transferOwnership = false)
52 	{
53 		if (transferOwnership)
54 			ownedRef = false;
55 		return gtkSourceCompletion;
56 	}
57 
58 	/** the main Gtk struct as a void* */
59 	protected override void* getStruct()
60 	{
61 		return cast(void*)gtkSourceCompletion;
62 	}
63 
64 	protected override void setStruct(GObject* obj)
65 	{
66 		gtkSourceCompletion = cast(GtkSourceCompletion*)obj;
67 		super.setStruct(obj);
68 	}
69 
70 	/**
71 	 * Sets our main struct and passes it to the parent class.
72 	 */
73 	public this (GtkSourceCompletion* gtkSourceCompletion, bool ownedRef = false)
74 	{
75 		this.gtkSourceCompletion = gtkSourceCompletion;
76 		super(cast(GObject*)gtkSourceCompletion, ownedRef);
77 	}
78 
79 	// add the Buildable capabilities
80 	mixin BuildableT!(GtkSourceCompletion);
81 
82 
83 	/** */
84 	public static GType getType()
85 	{
86 		return gtk_source_completion_get_type();
87 	}
88 
89 	/**
90 	 * Add a new #GtkSourceCompletionProvider to the completion object. This will
91 	 * add a reference @provider, so make sure to unref your own copy when you
92 	 * no longer need it.
93 	 *
94 	 * Params:
95 	 *     provider = a #GtkSourceCompletionProvider.
96 	 *
97 	 * Returns: %TRUE if @provider was successfully added, otherwise if @error
98 	 *     is provided, it will be set with the error and %FALSE is returned.
99 	 *
100 	 * Throws: GException on failure.
101 	 */
102 	public bool addProvider(SourceCompletionProviderIF provider)
103 	{
104 		GError* err = null;
105 		
106 		auto p = gtk_source_completion_add_provider(gtkSourceCompletion, (provider is null) ? null : provider.getSourceCompletionProviderStruct(), &err) != 0;
107 		
108 		if (err !is null)
109 		{
110 			throw new GException( new ErrorG(err) );
111 		}
112 		
113 		return p;
114 	}
115 
116 	/**
117 	 * Block interactive completion. This can be used to disable interactive
118 	 * completion when inserting or deleting text from the buffer associated with
119 	 * the completion. Use gtk_source_completion_unblock_interactive() to enable
120 	 * interactive completion again.
121 	 *
122 	 * This function may be called multiple times. It will continue to block
123 	 * interactive completion until gtk_source_completion_unblock_interactive()
124 	 * has been called the same number of times.
125 	 */
126 	public void blockInteractive()
127 	{
128 		gtk_source_completion_block_interactive(gtkSourceCompletion);
129 	}
130 
131 	/**
132 	 * Create a new #GtkSourceCompletionContext for @completion. The position where
133 	 * the completion occurs can be specified by @position. If @position is %NULL,
134 	 * the current cursor position will be used.
135 	 *
136 	 * Params:
137 	 *     position = a #GtkTextIter, or %NULL.
138 	 *
139 	 * Returns: a new #GtkSourceCompletionContext.
140 	 *     The reference being returned is a 'floating' reference,
141 	 *     so if you invoke gtk_source_completion_show() with this context
142 	 *     you don't need to unref it.
143 	 */
144 	public SourceCompletionContext createContext(TextIter position)
145 	{
146 		auto p = gtk_source_completion_create_context(gtkSourceCompletion, (position is null) ? null : position.getTextIterStruct());
147 		
148 		if(p is null)
149 		{
150 			return null;
151 		}
152 		
153 		return ObjectG.getDObject!(SourceCompletionContext)(cast(GtkSourceCompletionContext*) p);
154 	}
155 
156 	/**
157 	 * The info widget is the window where the completion displays optional extra
158 	 * information of the proposal.
159 	 *
160 	 * Returns: The #GtkSourceCompletionInfo window
161 	 *     associated with @completion.
162 	 */
163 	public SourceCompletionInfo getInfoWindow()
164 	{
165 		auto p = gtk_source_completion_get_info_window(gtkSourceCompletion);
166 		
167 		if(p is null)
168 		{
169 			return null;
170 		}
171 		
172 		return ObjectG.getDObject!(SourceCompletionInfo)(cast(GtkSourceCompletionInfo*) p);
173 	}
174 
175 	/**
176 	 * Get list of providers registered on @completion. The returned list is owned
177 	 * by the completion and should not be freed.
178 	 *
179 	 * Returns: list of #GtkSourceCompletionProvider.
180 	 */
181 	public ListG getProviders()
182 	{
183 		auto p = gtk_source_completion_get_providers(gtkSourceCompletion);
184 		
185 		if(p is null)
186 		{
187 			return null;
188 		}
189 		
190 		return new ListG(cast(GList*) p);
191 	}
192 
193 	/**
194 	 * The #GtkSourceView associated with @completion, or %NULL if the view has been
195 	 * destroyed.
196 	 *
197 	 * Returns: The #GtkSourceView associated with
198 	 *     @completion, or %NULL.
199 	 */
200 	public SourceView getView()
201 	{
202 		auto p = gtk_source_completion_get_view(gtkSourceCompletion);
203 		
204 		if(p is null)
205 		{
206 			return null;
207 		}
208 		
209 		return ObjectG.getDObject!(SourceView)(cast(GtkSourceView*) p);
210 	}
211 
212 	/**
213 	 * Hides the completion if it is active (visible).
214 	 */
215 	public void hide()
216 	{
217 		gtk_source_completion_hide(gtkSourceCompletion);
218 	}
219 
220 	/**
221 	 * Move the completion window to a specific iter.
222 	 *
223 	 * Deprecated: Use gtk_source_completion_provider_get_start_iter() instead.
224 	 *
225 	 * Params:
226 	 *     iter = a #GtkTextIter.
227 	 */
228 	public void moveWindow(TextIter iter)
229 	{
230 		gtk_source_completion_move_window(gtkSourceCompletion, (iter is null) ? null : iter.getTextIterStruct());
231 	}
232 
233 	/**
234 	 * Remove @provider from the completion.
235 	 *
236 	 * Params:
237 	 *     provider = a #GtkSourceCompletionProvider.
238 	 *
239 	 * Returns: %TRUE if @provider was successfully removed, otherwise if @error
240 	 *     is provided, it will be set with the error and %FALSE is returned.
241 	 *
242 	 * Throws: GException on failure.
243 	 */
244 	public bool removeProvider(SourceCompletionProviderIF provider)
245 	{
246 		GError* err = null;
247 		
248 		auto p = gtk_source_completion_remove_provider(gtkSourceCompletion, (provider is null) ? null : provider.getSourceCompletionProviderStruct(), &err) != 0;
249 		
250 		if (err !is null)
251 		{
252 			throw new GException( new ErrorG(err) );
253 		}
254 		
255 		return p;
256 	}
257 
258 	/**
259 	 * Starts a new completion with the specified #GtkSourceCompletionContext and
260 	 * a list of potential candidate providers for completion.
261 	 *
262 	 * It can be convenient for showing a completion on-the-fly, without the need to
263 	 * add or remove providers to the #GtkSourceCompletion.
264 	 *
265 	 * Another solution is to add providers with
266 	 * gtk_source_completion_add_provider(), and implement
267 	 * gtk_source_completion_provider_match() for each provider.
268 	 *
269 	 * Params:
270 	 *     providers = a list of #GtkSourceCompletionProvider, or %NULL.
271 	 *     context = The #GtkSourceCompletionContext
272 	 *         with which to start the completion.
273 	 *
274 	 * Returns: %TRUE if it was possible to the show completion window.
275 	 */
276 	public bool show(ListG providers, SourceCompletionContext context)
277 	{
278 		return gtk_source_completion_show(gtkSourceCompletion, (providers is null) ? null : providers.getListGStruct(), (context is null) ? null : context.getSourceCompletionContextStruct()) != 0;
279 	}
280 
281 	/**
282 	 * Unblock interactive completion. This can be used after using
283 	 * gtk_source_completion_block_interactive() to enable interactive completion
284 	 * again.
285 	 */
286 	public void unblockInteractive()
287 	{
288 		gtk_source_completion_unblock_interactive(gtkSourceCompletion);
289 	}
290 
291 	protected class OnActivateProposalDelegateWrapper
292 	{
293 		void delegate(SourceCompletion) dlg;
294 		gulong handlerId;
295 		
296 		this(void delegate(SourceCompletion) dlg)
297 		{
298 			this.dlg = dlg;
299 			onActivateProposalListeners ~= this;
300 		}
301 		
302 		void remove(OnActivateProposalDelegateWrapper source)
303 		{
304 			foreach(index, wrapper; onActivateProposalListeners)
305 			{
306 				if (wrapper.handlerId == source.handlerId)
307 				{
308 					onActivateProposalListeners[index] = null;
309 					onActivateProposalListeners = std.algorithm.remove(onActivateProposalListeners, index);
310 					break;
311 				}
312 			}
313 		}
314 	}
315 	OnActivateProposalDelegateWrapper[] onActivateProposalListeners;
316 
317 	/**
318 	 * The #GtkSourceCompletion::activate-proposal signal is a
319 	 * keybinding signal which gets emitted when the user initiates
320 	 * a proposal activation.
321 	 *
322 	 * Applications should not connect to it, but may emit it with
323 	 * g_signal_emit_by_name() if they need to control the proposal
324 	 * activation programmatically.
325 	 */
326 	gulong addOnActivateProposal(void delegate(SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
327 	{
328 		auto wrapper = new OnActivateProposalDelegateWrapper(dlg);
329 		wrapper.handlerId = Signals.connectData(
330 			this,
331 			"activate-proposal",
332 			cast(GCallback)&callBackActivateProposal,
333 			cast(void*)wrapper,
334 			cast(GClosureNotify)&callBackActivateProposalDestroy,
335 			connectFlags);
336 		return wrapper.handlerId;
337 	}
338 	
339 	extern(C) static void callBackActivateProposal(GtkSourceCompletion* sourcecompletionStruct, OnActivateProposalDelegateWrapper wrapper)
340 	{
341 		wrapper.dlg(wrapper.outer);
342 	}
343 	
344 	extern(C) static void callBackActivateProposalDestroy(OnActivateProposalDelegateWrapper wrapper, GClosure* closure)
345 	{
346 		wrapper.remove(wrapper);
347 	}
348 
349 	protected class OnHideDelegateWrapper
350 	{
351 		void delegate(SourceCompletion) dlg;
352 		gulong handlerId;
353 		
354 		this(void delegate(SourceCompletion) dlg)
355 		{
356 			this.dlg = dlg;
357 			onHideListeners ~= this;
358 		}
359 		
360 		void remove(OnHideDelegateWrapper source)
361 		{
362 			foreach(index, wrapper; onHideListeners)
363 			{
364 				if (wrapper.handlerId == source.handlerId)
365 				{
366 					onHideListeners[index] = null;
367 					onHideListeners = std.algorithm.remove(onHideListeners, index);
368 					break;
369 				}
370 			}
371 		}
372 	}
373 	OnHideDelegateWrapper[] onHideListeners;
374 
375 	/**
376 	 * Emitted when the completion window is hidden. The default handler
377 	 * will actually hide the window.
378 	 */
379 	gulong addOnHide(void delegate(SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
380 	{
381 		auto wrapper = new OnHideDelegateWrapper(dlg);
382 		wrapper.handlerId = Signals.connectData(
383 			this,
384 			"hide",
385 			cast(GCallback)&callBackHide,
386 			cast(void*)wrapper,
387 			cast(GClosureNotify)&callBackHideDestroy,
388 			connectFlags);
389 		return wrapper.handlerId;
390 	}
391 	
392 	extern(C) static void callBackHide(GtkSourceCompletion* sourcecompletionStruct, OnHideDelegateWrapper wrapper)
393 	{
394 		wrapper.dlg(wrapper.outer);
395 	}
396 	
397 	extern(C) static void callBackHideDestroy(OnHideDelegateWrapper wrapper, GClosure* closure)
398 	{
399 		wrapper.remove(wrapper);
400 	}
401 
402 	protected class OnMoveCursorDelegateWrapper
403 	{
404 		void delegate(GtkScrollStep, int, SourceCompletion) dlg;
405 		gulong handlerId;
406 		
407 		this(void delegate(GtkScrollStep, int, SourceCompletion) dlg)
408 		{
409 			this.dlg = dlg;
410 			onMoveCursorListeners ~= this;
411 		}
412 		
413 		void remove(OnMoveCursorDelegateWrapper source)
414 		{
415 			foreach(index, wrapper; onMoveCursorListeners)
416 			{
417 				if (wrapper.handlerId == source.handlerId)
418 				{
419 					onMoveCursorListeners[index] = null;
420 					onMoveCursorListeners = std.algorithm.remove(onMoveCursorListeners, index);
421 					break;
422 				}
423 			}
424 		}
425 	}
426 	OnMoveCursorDelegateWrapper[] onMoveCursorListeners;
427 
428 	/**
429 	 * The #GtkSourceCompletion::move-cursor signal is a keybinding
430 	 * signal which gets emitted when the user initiates a cursor
431 	 * movement.
432 	 *
433 	 * The <keycap>Up</keycap>, <keycap>Down</keycap>,
434 	 * <keycap>PageUp</keycap>, <keycap>PageDown</keycap>,
435 	 * <keycap>Home</keycap> and <keycap>End</keycap> keys are bound to the
436 	 * normal behavior expected by those keys.
437 	 *
438 	 * When @step is equal to %GTK_SCROLL_PAGES, the page size is defined by
439 	 * the #GtkSourceCompletion:proposal-page-size property. It is used for
440 	 * the <keycap>PageDown</keycap> and <keycap>PageUp</keycap> keys.
441 	 *
442 	 * Applications should not connect to it, but may emit it with
443 	 * g_signal_emit_by_name() if they need to control the cursor
444 	 * programmatically.
445 	 *
446 	 * Params:
447 	 *     step = The #GtkScrollStep by which to move the cursor
448 	 *     num = The amount of steps to move the cursor
449 	 */
450 	gulong addOnMoveCursor(void delegate(GtkScrollStep, int, SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
451 	{
452 		auto wrapper = new OnMoveCursorDelegateWrapper(dlg);
453 		wrapper.handlerId = Signals.connectData(
454 			this,
455 			"move-cursor",
456 			cast(GCallback)&callBackMoveCursor,
457 			cast(void*)wrapper,
458 			cast(GClosureNotify)&callBackMoveCursorDestroy,
459 			connectFlags);
460 		return wrapper.handlerId;
461 	}
462 	
463 	extern(C) static void callBackMoveCursor(GtkSourceCompletion* sourcecompletionStruct, GtkScrollStep step, int num, OnMoveCursorDelegateWrapper wrapper)
464 	{
465 		wrapper.dlg(step, num, wrapper.outer);
466 	}
467 	
468 	extern(C) static void callBackMoveCursorDestroy(OnMoveCursorDelegateWrapper wrapper, GClosure* closure)
469 	{
470 		wrapper.remove(wrapper);
471 	}
472 
473 	protected class OnMovePageDelegateWrapper
474 	{
475 		void delegate(GtkScrollStep, int, SourceCompletion) dlg;
476 		gulong handlerId;
477 		
478 		this(void delegate(GtkScrollStep, int, SourceCompletion) dlg)
479 		{
480 			this.dlg = dlg;
481 			onMovePageListeners ~= this;
482 		}
483 		
484 		void remove(OnMovePageDelegateWrapper source)
485 		{
486 			foreach(index, wrapper; onMovePageListeners)
487 			{
488 				if (wrapper.handlerId == source.handlerId)
489 				{
490 					onMovePageListeners[index] = null;
491 					onMovePageListeners = std.algorithm.remove(onMovePageListeners, index);
492 					break;
493 				}
494 			}
495 		}
496 	}
497 	OnMovePageDelegateWrapper[] onMovePageListeners;
498 
499 	/**
500 	 * The #GtkSourceCompletion::move-page signal is a keybinding
501 	 * signal which gets emitted when the user initiates a page
502 	 * movement (i.e. switches between provider pages).
503 	 *
504 	 * <keycombo><keycap>Control</keycap><keycap>Left</keycap></keycombo>
505 	 * is for going to the previous provider.
506 	 * <keycombo><keycap>Control</keycap><keycap>Right</keycap></keycombo>
507 	 * is for going to the next provider.
508 	 * <keycombo><keycap>Control</keycap><keycap>Home</keycap></keycombo>
509 	 * is for displaying all the providers.
510 	 * <keycombo><keycap>Control</keycap><keycap>End</keycap></keycombo>
511 	 * is for going to the last provider.
512 	 *
513 	 * When @step is equal to #GTK_SCROLL_PAGES, the page size is defined by
514 	 * the #GtkSourceCompletion:provider-page-size property.
515 	 *
516 	 * Applications should not connect to it, but may emit it with
517 	 * g_signal_emit_by_name() if they need to control the page selection
518 	 * programmatically.
519 	 *
520 	 * Params:
521 	 *     step = The #GtkScrollStep by which to move the page
522 	 *     num = The amount of steps to move the page
523 	 */
524 	gulong addOnMovePage(void delegate(GtkScrollStep, int, SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
525 	{
526 		auto wrapper = new OnMovePageDelegateWrapper(dlg);
527 		wrapper.handlerId = Signals.connectData(
528 			this,
529 			"move-page",
530 			cast(GCallback)&callBackMovePage,
531 			cast(void*)wrapper,
532 			cast(GClosureNotify)&callBackMovePageDestroy,
533 			connectFlags);
534 		return wrapper.handlerId;
535 	}
536 	
537 	extern(C) static void callBackMovePage(GtkSourceCompletion* sourcecompletionStruct, GtkScrollStep step, int num, OnMovePageDelegateWrapper wrapper)
538 	{
539 		wrapper.dlg(step, num, wrapper.outer);
540 	}
541 	
542 	extern(C) static void callBackMovePageDestroy(OnMovePageDelegateWrapper wrapper, GClosure* closure)
543 	{
544 		wrapper.remove(wrapper);
545 	}
546 
547 	protected class OnPopulateContextDelegateWrapper
548 	{
549 		void delegate(SourceCompletionContext, SourceCompletion) dlg;
550 		gulong handlerId;
551 		
552 		this(void delegate(SourceCompletionContext, SourceCompletion) dlg)
553 		{
554 			this.dlg = dlg;
555 			onPopulateContextListeners ~= this;
556 		}
557 		
558 		void remove(OnPopulateContextDelegateWrapper source)
559 		{
560 			foreach(index, wrapper; onPopulateContextListeners)
561 			{
562 				if (wrapper.handlerId == source.handlerId)
563 				{
564 					onPopulateContextListeners[index] = null;
565 					onPopulateContextListeners = std.algorithm.remove(onPopulateContextListeners, index);
566 					break;
567 				}
568 			}
569 		}
570 	}
571 	OnPopulateContextDelegateWrapper[] onPopulateContextListeners;
572 
573 	/**
574 	 * Emitted just before starting to populate the completion with providers.
575 	 * You can use this signal to add additional attributes in the context.
576 	 *
577 	 * Params:
578 	 *     context = The #GtkSourceCompletionContext for the current completion
579 	 */
580 	gulong addOnPopulateContext(void delegate(SourceCompletionContext, SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
581 	{
582 		auto wrapper = new OnPopulateContextDelegateWrapper(dlg);
583 		wrapper.handlerId = Signals.connectData(
584 			this,
585 			"populate-context",
586 			cast(GCallback)&callBackPopulateContext,
587 			cast(void*)wrapper,
588 			cast(GClosureNotify)&callBackPopulateContextDestroy,
589 			connectFlags);
590 		return wrapper.handlerId;
591 	}
592 	
593 	extern(C) static void callBackPopulateContext(GtkSourceCompletion* sourcecompletionStruct, GtkSourceCompletionContext* context, OnPopulateContextDelegateWrapper wrapper)
594 	{
595 		wrapper.dlg(ObjectG.getDObject!(SourceCompletionContext)(context), wrapper.outer);
596 	}
597 	
598 	extern(C) static void callBackPopulateContextDestroy(OnPopulateContextDelegateWrapper wrapper, GClosure* closure)
599 	{
600 		wrapper.remove(wrapper);
601 	}
602 
603 	protected class OnShowDelegateWrapper
604 	{
605 		void delegate(SourceCompletion) dlg;
606 		gulong handlerId;
607 		
608 		this(void delegate(SourceCompletion) dlg)
609 		{
610 			this.dlg = dlg;
611 			onShowListeners ~= this;
612 		}
613 		
614 		void remove(OnShowDelegateWrapper source)
615 		{
616 			foreach(index, wrapper; onShowListeners)
617 			{
618 				if (wrapper.handlerId == source.handlerId)
619 				{
620 					onShowListeners[index] = null;
621 					onShowListeners = std.algorithm.remove(onShowListeners, index);
622 					break;
623 				}
624 			}
625 		}
626 	}
627 	OnShowDelegateWrapper[] onShowListeners;
628 
629 	/**
630 	 * Emitted when the completion window is shown. The default handler
631 	 * will actually show the window.
632 	 */
633 	gulong addOnShow(void delegate(SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
634 	{
635 		auto wrapper = new OnShowDelegateWrapper(dlg);
636 		wrapper.handlerId = Signals.connectData(
637 			this,
638 			"show",
639 			cast(GCallback)&callBackShow,
640 			cast(void*)wrapper,
641 			cast(GClosureNotify)&callBackShowDestroy,
642 			connectFlags);
643 		return wrapper.handlerId;
644 	}
645 	
646 	extern(C) static void callBackShow(GtkSourceCompletion* sourcecompletionStruct, OnShowDelegateWrapper wrapper)
647 	{
648 		wrapper.dlg(wrapper.outer);
649 	}
650 	
651 	extern(C) static void callBackShowDestroy(OnShowDelegateWrapper wrapper, GClosure* closure)
652 	{
653 		wrapper.remove(wrapper);
654 	}
655 }