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 public  import gtkc.gdktypes;
42 
43 
44 public class SourceCompletion : ObjectG, BuildableIF
45 {
46 	/** the main Gtk struct */
47 	protected GtkSourceCompletion* gtkSourceCompletion;
48 
49 	/** Get the main Gtk struct */
50 	public GtkSourceCompletion* getSourceCompletionStruct()
51 	{
52 		return gtkSourceCompletion;
53 	}
54 
55 	/** the main Gtk struct as a void* */
56 	protected override void* getStruct()
57 	{
58 		return cast(void*)gtkSourceCompletion;
59 	}
60 
61 	protected override void setStruct(GObject* obj)
62 	{
63 		gtkSourceCompletion = cast(GtkSourceCompletion*)obj;
64 		super.setStruct(obj);
65 	}
66 
67 	/**
68 	 * Sets our main struct and passes it to the parent class.
69 	 */
70 	public this (GtkSourceCompletion* gtkSourceCompletion, bool ownedRef = false)
71 	{
72 		this.gtkSourceCompletion = gtkSourceCompletion;
73 		super(cast(GObject*)gtkSourceCompletion, ownedRef);
74 	}
75 
76 	// add the Buildable capabilities
77 	mixin BuildableT!(GtkSourceCompletion);
78 
79 	/**
80 	 */
81 
82 	public static GType getType()
83 	{
84 		return gtk_source_completion_get_type();
85 	}
86 
87 	/**
88 	 * Add a new #GtkSourceCompletionProvider to the completion object. This will
89 	 * add a reference @provider, so make sure to unref your own copy when you
90 	 * no longer need it.
91 	 *
92 	 * Params:
93 	 *     provider = a #GtkSourceCompletionProvider.
94 	 *
95 	 * Return: %TRUE if @provider was successfully added, otherwise if @error
96 	 *     is provided, it will be set with the error and %FALSE is returned.
97 	 *
98 	 * Throws: GException on failure.
99 	 */
100 	public bool addProvider(SourceCompletionProviderIF provider)
101 	{
102 		GError* err = null;
103 		
104 		auto p = gtk_source_completion_add_provider(gtkSourceCompletion, (provider is null) ? null : provider.getSourceCompletionProviderStruct(), &err) != 0;
105 		
106 		if (err !is null)
107 		{
108 			throw new GException( new ErrorG(err) );
109 		}
110 		
111 		return p;
112 	}
113 
114 	/**
115 	 * Block interactive completion. This can be used to disable interactive
116 	 * completion when inserting or deleting text from the buffer associated with
117 	 * the completion. Use gtk_source_completion_unblock_interactive() to enable
118 	 * interactive completion again.
119 	 *
120 	 * This function may be called multiple times. It will continue to block
121 	 * interactive completion until gtk_source_completion_unblock_interactive()
122 	 * has been called the same number of times.
123 	 */
124 	public void blockInteractive()
125 	{
126 		gtk_source_completion_block_interactive(gtkSourceCompletion);
127 	}
128 
129 	/**
130 	 * Create a new #GtkSourceCompletionContext for @completion. The position where
131 	 * the completion occurs can be specified by @position. If @position is %NULL,
132 	 * the current cursor position will be used.
133 	 *
134 	 * Params:
135 	 *     position = a #GtkTextIter, or %NULL.
136 	 *
137 	 * Return: a new #GtkSourceCompletionContext.
138 	 *     The reference being returned is a 'floating' reference,
139 	 *     so if you invoke gtk_source_completion_show() with this context
140 	 *     you don't need to unref it.
141 	 */
142 	public SourceCompletionContext createContext(TextIter position)
143 	{
144 		auto p = gtk_source_completion_create_context(gtkSourceCompletion, (position is null) ? null : position.getTextIterStruct());
145 		
146 		if(p is null)
147 		{
148 			return null;
149 		}
150 		
151 		return ObjectG.getDObject!(SourceCompletionContext)(cast(GtkSourceCompletionContext*) p);
152 	}
153 
154 	/**
155 	 * The info widget is the window where the completion displays optional extra
156 	 * information of the proposal.
157 	 *
158 	 * Return: The #GtkSourceCompletionInfo window
159 	 *     associated with @completion.
160 	 */
161 	public SourceCompletionInfo getInfoWindow()
162 	{
163 		auto p = gtk_source_completion_get_info_window(gtkSourceCompletion);
164 		
165 		if(p is null)
166 		{
167 			return null;
168 		}
169 		
170 		return ObjectG.getDObject!(SourceCompletionInfo)(cast(GtkSourceCompletionInfo*) p);
171 	}
172 
173 	/**
174 	 * Get list of providers registered on @completion. The returned list is owned
175 	 * by the completion and should not be freed.
176 	 *
177 	 * Return: list of #GtkSourceCompletionProvider.
178 	 */
179 	public ListG getProviders()
180 	{
181 		auto p = gtk_source_completion_get_providers(gtkSourceCompletion);
182 		
183 		if(p is null)
184 		{
185 			return null;
186 		}
187 		
188 		return new ListG(cast(GList*) p);
189 	}
190 
191 	/**
192 	 * The #GtkSourceView associated with @completion, or %NULL if the view has been
193 	 * destroyed.
194 	 *
195 	 * Return: The #GtkSourceView associated with @completion, or %NULL.
196 	 */
197 	public SourceView getView()
198 	{
199 		auto p = gtk_source_completion_get_view(gtkSourceCompletion);
200 		
201 		if(p is null)
202 		{
203 			return null;
204 		}
205 		
206 		return ObjectG.getDObject!(SourceView)(cast(GtkSourceView*) p);
207 	}
208 
209 	/**
210 	 * Hides the completion if it is active (visible).
211 	 */
212 	public void hide()
213 	{
214 		gtk_source_completion_hide(gtkSourceCompletion);
215 	}
216 
217 	/**
218 	 * Move the completion window to a specific iter.
219 	 *
220 	 * Deprecated: Use gtk_source_completion_provider_get_start_iter() instead.
221 	 *
222 	 * Params:
223 	 *     iter = a #GtkTextIter.
224 	 */
225 	public void moveWindow(TextIter iter)
226 	{
227 		gtk_source_completion_move_window(gtkSourceCompletion, (iter is null) ? null : iter.getTextIterStruct());
228 	}
229 
230 	/**
231 	 * Remove @provider from the completion.
232 	 *
233 	 * Params:
234 	 *     provider = a #GtkSourceCompletionProvider.
235 	 *
236 	 * Return: %TRUE if @provider was successfully removed, otherwise if @error
237 	 *     is provided, it will be set with the error and %FALSE is returned.
238 	 *
239 	 * Throws: GException on failure.
240 	 */
241 	public bool removeProvider(SourceCompletionProviderIF provider)
242 	{
243 		GError* err = null;
244 		
245 		auto p = gtk_source_completion_remove_provider(gtkSourceCompletion, (provider is null) ? null : provider.getSourceCompletionProviderStruct(), &err) != 0;
246 		
247 		if (err !is null)
248 		{
249 			throw new GException( new ErrorG(err) );
250 		}
251 		
252 		return p;
253 	}
254 
255 	/**
256 	 * Starts a new completion with the specified #GtkSourceCompletionContext and
257 	 * a list of potential candidate providers for completion.
258 	 *
259 	 * It can be convenient for showing a completion on-the-fly, without the need to
260 	 * add or remove providers to the #GtkSourceCompletion.
261 	 *
262 	 * Another solution is to add providers with
263 	 * gtk_source_completion_add_provider(), and implement
264 	 * gtk_source_completion_provider_match() for each provider.
265 	 *
266 	 * Params:
267 	 *     providers = a list of #GtkSourceCompletionProvider, or %NULL.
268 	 *     context = The #GtkSourceCompletionContext
269 	 *         with which to start the completion.
270 	 *
271 	 * Return: %TRUE if it was possible to the show completion window.
272 	 */
273 	public bool show(ListG providers, SourceCompletionContext context)
274 	{
275 		return gtk_source_completion_show(gtkSourceCompletion, (providers is null) ? null : providers.getListGStruct(), (context is null) ? null : context.getSourceCompletionContextStruct()) != 0;
276 	}
277 
278 	/**
279 	 * Unblock interactive completion. This can be used after using
280 	 * gtk_source_completion_block_interactive() to enable interactive completion
281 	 * again.
282 	 */
283 	public void unblockInteractive()
284 	{
285 		gtk_source_completion_unblock_interactive(gtkSourceCompletion);
286 	}
287 
288 	int[string] connectedSignals;
289 
290 	void delegate(SourceCompletion)[] onActivateProposalListeners;
291 	/**
292 	 * The #GtkSourceCompletion::activate-proposal signal is a
293 	 * keybinding signal which gets emitted when the user initiates
294 	 * a proposal activation.
295 	 *
296 	 * Applications should not connect to it, but may emit it with
297 	 * g_signal_emit_by_name() if they need to control the proposal
298 	 * activation programmatically.
299 	 */
300 	void addOnActivateProposal(void delegate(SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
301 	{
302 		if ( "activate-proposal" !in connectedSignals )
303 		{
304 			Signals.connectData(
305 				this,
306 				"activate-proposal",
307 				cast(GCallback)&callBackActivateProposal,
308 				cast(void*)this,
309 				null,
310 				connectFlags);
311 			connectedSignals["activate-proposal"] = 1;
312 		}
313 		onActivateProposalListeners ~= dlg;
314 	}
315 	extern(C) static void callBackActivateProposal(GtkSourceCompletion* sourcecompletionStruct, SourceCompletion _sourcecompletion)
316 	{
317 		foreach ( void delegate(SourceCompletion) dlg; _sourcecompletion.onActivateProposalListeners )
318 		{
319 			dlg(_sourcecompletion);
320 		}
321 	}
322 
323 	void delegate(SourceCompletion)[] onHideListeners;
324 	/**
325 	 * Emitted when the completion window is hidden. The default handler
326 	 * will actually hide the window.
327 	 */
328 	void addOnHide(void delegate(SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
329 	{
330 		if ( "hide" !in connectedSignals )
331 		{
332 			Signals.connectData(
333 				this,
334 				"hide",
335 				cast(GCallback)&callBackHide,
336 				cast(void*)this,
337 				null,
338 				connectFlags);
339 			connectedSignals["hide"] = 1;
340 		}
341 		onHideListeners ~= dlg;
342 	}
343 	extern(C) static void callBackHide(GtkSourceCompletion* sourcecompletionStruct, SourceCompletion _sourcecompletion)
344 	{
345 		foreach ( void delegate(SourceCompletion) dlg; _sourcecompletion.onHideListeners )
346 		{
347 			dlg(_sourcecompletion);
348 		}
349 	}
350 
351 	void delegate(GtkScrollStep, int, SourceCompletion)[] onMoveCursorListeners;
352 	/**
353 	 * The #GtkSourceCompletion::move-cursor signal is a keybinding
354 	 * signal which gets emitted when the user initiates a cursor
355 	 * movement.
356 	 *
357 	 * The <keycap>Up</keycap>, <keycap>Down</keycap>,
358 	 * <keycap>PageUp</keycap>, <keycap>PageDown</keycap>,
359 	 * <keycap>Home</keycap> and <keycap>End</keycap> keys are bound to the
360 	 * normal behavior expected by those keys.
361 	 *
362 	 * When @step is equal to %GTK_SCROLL_PAGES, the page size is defined by
363 	 * the #GtkSourceCompletion:proposal-page-size property. It is used for
364 	 * the <keycap>PageDown</keycap> and <keycap>PageUp</keycap> keys.
365 	 *
366 	 * Applications should not connect to it, but may emit it with
367 	 * g_signal_emit_by_name() if they need to control the cursor
368 	 * programmatically.
369 	 *
370 	 * Params:
371 	 *     step = The #GtkScrollStep by which to move the cursor
372 	 *     num = The amount of steps to move the cursor
373 	 */
374 	void addOnMoveCursor(void delegate(GtkScrollStep, int, SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
375 	{
376 		if ( "move-cursor" !in connectedSignals )
377 		{
378 			Signals.connectData(
379 				this,
380 				"move-cursor",
381 				cast(GCallback)&callBackMoveCursor,
382 				cast(void*)this,
383 				null,
384 				connectFlags);
385 			connectedSignals["move-cursor"] = 1;
386 		}
387 		onMoveCursorListeners ~= dlg;
388 	}
389 	extern(C) static void callBackMoveCursor(GtkSourceCompletion* sourcecompletionStruct, GtkScrollStep step, int num, SourceCompletion _sourcecompletion)
390 	{
391 		foreach ( void delegate(GtkScrollStep, int, SourceCompletion) dlg; _sourcecompletion.onMoveCursorListeners )
392 		{
393 			dlg(step, num, _sourcecompletion);
394 		}
395 	}
396 
397 	void delegate(GtkScrollStep, int, SourceCompletion)[] onMovePageListeners;
398 	/**
399 	 * The #GtkSourceCompletion::move-page signal is a keybinding
400 	 * signal which gets emitted when the user initiates a page
401 	 * movement (i.e. switches between provider pages).
402 	 *
403 	 * <keycombo><keycap>Control</keycap><keycap>Left</keycap></keycombo>
404 	 * is for going to the previous provider.
405 	 * <keycombo><keycap>Control</keycap><keycap>Right</keycap></keycombo>
406 	 * is for going to the next provider.
407 	 * <keycombo><keycap>Control</keycap><keycap>Home</keycap></keycombo>
408 	 * is for displaying all the providers.
409 	 * <keycombo><keycap>Control</keycap><keycap>End</keycap></keycombo>
410 	 * is for going to the last provider.
411 	 *
412 	 * When @step is equal to #GTK_SCROLL_PAGES, the page size is defined by
413 	 * the #GtkSourceCompletion:provider-page-size property.
414 	 *
415 	 * Applications should not connect to it, but may emit it with
416 	 * g_signal_emit_by_name() if they need to control the page selection
417 	 * programmatically.
418 	 *
419 	 * Params:
420 	 *     step = The #GtkScrollStep by which to move the page
421 	 *     num = The amount of steps to move the page
422 	 */
423 	void addOnMovePage(void delegate(GtkScrollStep, int, SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
424 	{
425 		if ( "move-page" !in connectedSignals )
426 		{
427 			Signals.connectData(
428 				this,
429 				"move-page",
430 				cast(GCallback)&callBackMovePage,
431 				cast(void*)this,
432 				null,
433 				connectFlags);
434 			connectedSignals["move-page"] = 1;
435 		}
436 		onMovePageListeners ~= dlg;
437 	}
438 	extern(C) static void callBackMovePage(GtkSourceCompletion* sourcecompletionStruct, GtkScrollStep step, int num, SourceCompletion _sourcecompletion)
439 	{
440 		foreach ( void delegate(GtkScrollStep, int, SourceCompletion) dlg; _sourcecompletion.onMovePageListeners )
441 		{
442 			dlg(step, num, _sourcecompletion);
443 		}
444 	}
445 
446 	void delegate(SourceCompletionContext, SourceCompletion)[] onPopulateContextListeners;
447 	/**
448 	 * Emitted just before starting to populate the completion with providers.
449 	 * You can use this signal to add additional attributes in the context.
450 	 *
451 	 * Params:
452 	 *     context = The #GtkSourceCompletionContext for the current completion
453 	 */
454 	void addOnPopulateContext(void delegate(SourceCompletionContext, SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
455 	{
456 		if ( "populate-context" !in connectedSignals )
457 		{
458 			Signals.connectData(
459 				this,
460 				"populate-context",
461 				cast(GCallback)&callBackPopulateContext,
462 				cast(void*)this,
463 				null,
464 				connectFlags);
465 			connectedSignals["populate-context"] = 1;
466 		}
467 		onPopulateContextListeners ~= dlg;
468 	}
469 	extern(C) static void callBackPopulateContext(GtkSourceCompletion* sourcecompletionStruct, GtkSourceCompletionContext* context, SourceCompletion _sourcecompletion)
470 	{
471 		foreach ( void delegate(SourceCompletionContext, SourceCompletion) dlg; _sourcecompletion.onPopulateContextListeners )
472 		{
473 			dlg(ObjectG.getDObject!(SourceCompletionContext)(context), _sourcecompletion);
474 		}
475 	}
476 
477 	void delegate(SourceCompletion)[] onShowListeners;
478 	/**
479 	 * Emitted when the completion window is shown. The default handler
480 	 * will actually show the window.
481 	 */
482 	void addOnShow(void delegate(SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
483 	{
484 		if ( "show" !in connectedSignals )
485 		{
486 			Signals.connectData(
487 				this,
488 				"show",
489 				cast(GCallback)&callBackShow,
490 				cast(void*)this,
491 				null,
492 				connectFlags);
493 			connectedSignals["show"] = 1;
494 		}
495 		onShowListeners ~= dlg;
496 	}
497 	extern(C) static void callBackShow(GtkSourceCompletion* sourcecompletionStruct, SourceCompletion _sourcecompletion)
498 	{
499 		foreach ( void delegate(SourceCompletion) dlg; _sourcecompletion.onShowListeners )
500 		{
501 			dlg(_sourcecompletion);
502 		}
503 	}
504 }