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