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