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.SourceCompletionProposalT;
26 
27 public  import gdkpixbuf.Pixbuf;
28 public  import gio.Icon;
29 public  import gio.IconIF;
30 public  import glib.Str;
31 public  import gobject.ObjectG;
32 public  import gobject.Signals;
33 public  import gsvc.gsv;
34 public  import gsvc.gsvtypes;
35 public  import gtkc.gdktypes;
36 public  import std.algorithm;
37 
38 
39 /** */
40 public template SourceCompletionProposalT(TStruct)
41 {
42 	/** Get the main Gtk struct */
43 	public GtkSourceCompletionProposal* getSourceCompletionProposalStruct()
44 	{
45 		return cast(GtkSourceCompletionProposal*)getStruct();
46 	}
47 
48 
49 	/**
50 	 * Emits the "changed" signal on @proposal. This should be called by
51 	 * implementations whenever the name, icon or info of the proposal has
52 	 * changed.
53 	 */
54 	public void changed()
55 	{
56 		gtk_source_completion_proposal_changed(getSourceCompletionProposalStruct());
57 	}
58 
59 	/**
60 	 * Get whether two proposal objects are the same.  This is used to (together
61 	 * with gtk_source_completion_proposal_hash()) to match proposals in the
62 	 * completion model. By default, it uses direct equality (g_direct_equal()).
63 	 *
64 	 * Params:
65 	 *     other = a #GtkSourceCompletionProposal.
66 	 *
67 	 * Return: %TRUE if @proposal and @object are the same proposal
68 	 */
69 	public bool equal(SourceCompletionProposalIF other)
70 	{
71 		return gtk_source_completion_proposal_equal(getSourceCompletionProposalStruct(), (other is null) ? null : other.getSourceCompletionProposalStruct()) != 0;
72 	}
73 
74 	/**
75 	 * Gets the #GIcon for the icon of @proposal.
76 	 *
77 	 * Return: A #GIcon with the icon of @proposal.
78 	 *
79 	 * Since: 3.18
80 	 */
81 	public IconIF getGicon()
82 	{
83 		auto p = gtk_source_completion_proposal_get_gicon(getSourceCompletionProposalStruct());
84 		
85 		if(p is null)
86 		{
87 			return null;
88 		}
89 		
90 		return ObjectG.getDObject!(Icon, IconIF)(cast(GIcon*) p);
91 	}
92 
93 	/**
94 	 * Gets the #GdkPixbuf for the icon of @proposal.
95 	 *
96 	 * Return: A #GdkPixbuf with the icon of @proposal.
97 	 */
98 	public Pixbuf getIcon()
99 	{
100 		auto p = gtk_source_completion_proposal_get_icon(getSourceCompletionProposalStruct());
101 		
102 		if(p is null)
103 		{
104 			return null;
105 		}
106 		
107 		return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p);
108 	}
109 
110 	/**
111 	 * Gets the icon name of @proposal.
112 	 *
113 	 * Return: The icon name of @proposal.
114 	 *
115 	 * Since: 3.18
116 	 */
117 	public string getIconName()
118 	{
119 		return Str.toString(gtk_source_completion_proposal_get_icon_name(getSourceCompletionProposalStruct()));
120 	}
121 
122 	/**
123 	 * Gets extra information associated to the proposal. This information will be
124 	 * used to present the user with extra, detailed information about the
125 	 * selected proposal. The returned string must be freed with g_free().
126 	 *
127 	 * Return: a newly-allocated string containing
128 	 *     extra information of @proposal or %NULL if no extra information is associated
129 	 *     to @proposal.
130 	 */
131 	public string getInfo()
132 	{
133 		auto retStr = gtk_source_completion_proposal_get_info(getSourceCompletionProposalStruct());
134 		
135 		scope(exit) Str.freeString(retStr);
136 		return Str.toString(retStr);
137 	}
138 
139 	/**
140 	 * Gets the label of @proposal. The label is shown in the list of proposals as
141 	 * plain text. If you need any markup (such as bold or italic text), you have
142 	 * to implement gtk_source_completion_proposal_get_markup(). The returned string
143 	 * must be freed with g_free().
144 	 *
145 	 * Return: a new string containing the label of @proposal.
146 	 */
147 	public string getLabel()
148 	{
149 		auto retStr = gtk_source_completion_proposal_get_label(getSourceCompletionProposalStruct());
150 		
151 		scope(exit) Str.freeString(retStr);
152 		return Str.toString(retStr);
153 	}
154 
155 	/**
156 	 * Gets the label of @proposal with markup. The label is shown in the list of
157 	 * proposals and may contain markup. This will be used instead of
158 	 * gtk_source_completion_proposal_get_label() if implemented. The returned string
159 	 * must be freed with g_free().
160 	 *
161 	 * Return: a new string containing the label of @proposal with markup.
162 	 */
163 	public string getMarkup()
164 	{
165 		auto retStr = gtk_source_completion_proposal_get_markup(getSourceCompletionProposalStruct());
166 		
167 		scope(exit) Str.freeString(retStr);
168 		return Str.toString(retStr);
169 	}
170 
171 	/**
172 	 * Gets the text of @proposal. The text that is inserted into
173 	 * the text buffer when the proposal is activated by the default activation.
174 	 * You are free to implement a custom activation handler in the provider and
175 	 * not implement this function. For more information, see
176 	 * gtk_source_completion_provider_activate_proposal(). The returned string must
177 	 * be freed with g_free().
178 	 *
179 	 * Return: a new string containing the text of @proposal.
180 	 */
181 	public string getText()
182 	{
183 		auto retStr = gtk_source_completion_proposal_get_text(getSourceCompletionProposalStruct());
184 		
185 		scope(exit) Str.freeString(retStr);
186 		return Str.toString(retStr);
187 	}
188 
189 	/**
190 	 * Get the hash value of @proposal. This is used to (together with
191 	 * gtk_source_completion_proposal_equal()) to match proposals in the completion
192 	 * model. By default, it uses a direct hash (g_direct_hash()).
193 	 *
194 	 * Return: The hash value of @proposal.
195 	 */
196 	public uint hash()
197 	{
198 		return gtk_source_completion_proposal_hash(getSourceCompletionProposalStruct());
199 	}
200 
201 	protected class OnChangedDelegateWrapper
202 	{
203 		void delegate(SourceCompletionProposalIF) dlg;
204 		gulong handlerId;
205 		ConnectFlags flags;
206 		this(void delegate(SourceCompletionProposalIF) dlg, gulong handlerId, ConnectFlags flags)
207 		{
208 			this.dlg = dlg;
209 			this.handlerId = handlerId;
210 			this.flags = flags;
211 		}
212 	}
213 	protected OnChangedDelegateWrapper[] onChangedListeners;
214 
215 	/**
216 	 * Emitted when the proposal has changed. The completion popup
217 	 * will react to this by updating the shown information.
218 	 */
219 	gulong addOnChanged(void delegate(SourceCompletionProposalIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
220 	{
221 		onChangedListeners ~= new OnChangedDelegateWrapper(dlg, 0, connectFlags);
222 		onChangedListeners[onChangedListeners.length - 1].handlerId = Signals.connectData(
223 			this,
224 			"changed",
225 			cast(GCallback)&callBackChanged,
226 			cast(void*)onChangedListeners[onChangedListeners.length - 1],
227 			cast(GClosureNotify)&callBackChangedDestroy,
228 			connectFlags);
229 		return onChangedListeners[onChangedListeners.length - 1].handlerId;
230 	}
231 	
232 	extern(C) static void callBackChanged(GtkSourceCompletionProposal* sourcecompletionproposalStruct,OnChangedDelegateWrapper wrapper)
233 	{
234 		wrapper.dlg(wrapper.outer);
235 	}
236 	
237 	extern(C) static void callBackChangedDestroy(OnChangedDelegateWrapper wrapper, GClosure* closure)
238 	{
239 		wrapper.outer.internalRemoveOnChanged(wrapper);
240 	}
241 
242 	protected void internalRemoveOnChanged(OnChangedDelegateWrapper source)
243 	{
244 		foreach(index, wrapper; onChangedListeners)
245 		{
246 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
247 			{
248 				onChangedListeners[index] = null;
249 				onChangedListeners = std.algorithm.remove(onChangedListeners, index);
250 				break;
251 			}
252 		}
253 	}
254 	
255 }