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.SourceCompletionContext;
26 
27 private import glib.ListG;
28 private import gobject.ObjectG;
29 private import gobject.Signals;
30 private import gsv.SourceCompletionProposalIF;
31 private import gsv.SourceCompletionProviderIF;
32 private import gsv.c.functions;
33 public  import gsv.c.types;
34 public  import gsvc.gsvtypes;
35 private import gtk.TextIter;
36 private import std.algorithm;
37 
38 
39 /** */
40 public class SourceCompletionContext : ObjectG
41 {
42 	/** the main Gtk struct */
43 	protected GtkSourceCompletionContext* gtkSourceCompletionContext;
44 
45 	/** Get the main Gtk struct */
46 	public GtkSourceCompletionContext* getSourceCompletionContextStruct(bool transferOwnership = false)
47 	{
48 		if (transferOwnership)
49 			ownedRef = false;
50 		return gtkSourceCompletionContext;
51 	}
52 
53 	/** the main Gtk struct as a void* */
54 	protected override void* getStruct()
55 	{
56 		return cast(void*)gtkSourceCompletionContext;
57 	}
58 
59 	protected override void setStruct(GObject* obj)
60 	{
61 		gtkSourceCompletionContext = cast(GtkSourceCompletionContext*)obj;
62 		super.setStruct(obj);
63 	}
64 
65 	/**
66 	 * Sets our main struct and passes it to the parent class.
67 	 */
68 	public this (GtkSourceCompletionContext* gtkSourceCompletionContext, bool ownedRef = false)
69 	{
70 		this.gtkSourceCompletionContext = gtkSourceCompletionContext;
71 		super(cast(GObject*)gtkSourceCompletionContext, ownedRef);
72 	}
73 
74 
75 	/** */
76 	public static GType getType()
77 	{
78 		return gtk_source_completion_context_get_type();
79 	}
80 
81 	/**
82 	 * Providers can use this function to add proposals to the completion. They
83 	 * can do so asynchronously by means of the @finished argument. Providers must
84 	 * ensure that they always call this function with @finished set to %TRUE
85 	 * once each population (even if no proposals need to be added).
86 	 * Population occurs when the gtk_source_completion_provider_populate()
87 	 * function is called.
88 	 *
89 	 * Params:
90 	 *     provider = a #GtkSourceCompletionProvider.
91 	 *     proposals = The list of proposals to add.
92 	 *     finished = Whether the provider is finished adding proposals.
93 	 */
94 	public void addProposals(SourceCompletionProviderIF provider, ListG proposals, bool finished)
95 	{
96 		gtk_source_completion_context_add_proposals(gtkSourceCompletionContext, (provider is null) ? null : provider.getSourceCompletionProviderStruct(), (proposals is null) ? null : proposals.getListGStruct(), finished);
97 	}
98 
99 	/**
100 	 * Get the context activation.
101 	 *
102 	 * Returns: The context activation.
103 	 */
104 	public GtkSourceCompletionActivation getActivation()
105 	{
106 		return gtk_source_completion_context_get_activation(gtkSourceCompletionContext);
107 	}
108 
109 	/**
110 	 * Get the iter at which the completion was invoked. Providers can use this
111 	 * to determine how and if to match proposals.
112 	 *
113 	 * Params:
114 	 *     iter = a #GtkTextIter.
115 	 *
116 	 * Returns: %TRUE if @iter is correctly set, %FALSE otherwise.
117 	 */
118 	public bool getIter(out TextIter iter)
119 	{
120 		GtkTextIter* outiter = gMalloc!GtkTextIter();
121 
122 		auto p = gtk_source_completion_context_get_iter(gtkSourceCompletionContext, outiter) != 0;
123 
124 		iter = ObjectG.getDObject!(TextIter)(outiter, true);
125 
126 		return p;
127 	}
128 
129 	protected class OnCancelledDelegateWrapper
130 	{
131 		void delegate(SourceCompletionContext) dlg;
132 		gulong handlerId;
133 
134 		this(void delegate(SourceCompletionContext) dlg)
135 		{
136 			this.dlg = dlg;
137 			onCancelledListeners ~= this;
138 		}
139 
140 		void remove(OnCancelledDelegateWrapper source)
141 		{
142 			foreach(index, wrapper; onCancelledListeners)
143 			{
144 				if (wrapper.handlerId == source.handlerId)
145 				{
146 					onCancelledListeners[index] = null;
147 					onCancelledListeners = std.algorithm.remove(onCancelledListeners, index);
148 					break;
149 				}
150 			}
151 		}
152 	}
153 	OnCancelledDelegateWrapper[] onCancelledListeners;
154 
155 	/**
156 	 * Emitted when the current population of proposals has been cancelled.
157 	 * Providers adding proposals asynchronously should connect to this signal
158 	 * to know when to cancel running proposal queries.
159 	 */
160 	gulong addOnCancelled(void delegate(SourceCompletionContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
161 	{
162 		auto wrapper = new OnCancelledDelegateWrapper(dlg);
163 		wrapper.handlerId = Signals.connectData(
164 			this,
165 			"cancelled",
166 			cast(GCallback)&callBackCancelled,
167 			cast(void*)wrapper,
168 			cast(GClosureNotify)&callBackCancelledDestroy,
169 			connectFlags);
170 		return wrapper.handlerId;
171 	}
172 
173 	extern(C) static void callBackCancelled(GtkSourceCompletionContext* sourcecompletioncontextStruct, OnCancelledDelegateWrapper wrapper)
174 	{
175 		wrapper.dlg(wrapper.outer);
176 	}
177 
178 	extern(C) static void callBackCancelledDestroy(OnCancelledDelegateWrapper wrapper, GClosure* closure)
179 	{
180 		wrapper.remove(wrapper);
181 	}
182 }