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