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  * Conversion parameters:
26  * inFile  = glib-Automatic-String-Completion.html
27  * outPack = glib
28  * outFile = StringCompletion
29  * strct   = GCompletion
30  * realStrct=
31  * ctorStrct=
32  * clss    = StringCompletion
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_completion_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.ListG
47  * 	- glib.Str
48  * structWrap:
49  * 	- GList* -> ListG
50  * module aliases:
51  * local aliases:
52  * overrides:
53  */
54 
55 module glib.StringCompletion;
56 
57 public  import gtkc.glibtypes;
58 
59 private import gtkc.glib;
60 private import glib.ConstructionException;
61 
62 private import glib.ListG;
63 private import glib.Str;
64 
65 
66 
67 /**
68  * GCompletion provides support for automatic completion of a string
69  * using any group of target strings. It is typically used for file
70  * name completion as is common in many UNIX shells.
71  *
72  * A GCompletion is created using g_completion_new(). Target items are
73  * added and removed with g_completion_add_items(),
74  * g_completion_remove_items() and g_completion_clear_items(). A
75  * completion attempt is requested with g_completion_complete() or
76  * g_completion_complete_utf8(). When no longer needed, the
77  * GCompletion is freed with g_completion_free().
78  *
79  * Items in the completion can be simple strings (e.g. filenames), or
80  * pointers to arbitrary data structures. If data structures are used
81  * you must provide a GCompletionFunc in g_completion_new(), which
82  * retrieves the item's string from the data structure. You can change
83  * the way in which strings are compared by setting a different
84  * GCompletionStrncmpFunc in g_completion_set_compare().
85  *
86  * GCompletion has been marked as deprecated, since this API is rarely
87  * used and not very actively maintained.
88  */
89 public class StringCompletion
90 {
91 	
92 	/** the main Gtk struct */
93 	protected GCompletion* gCompletion;
94 	
95 	
96 	/** Get the main Gtk struct */
97 	public GCompletion* getStringCompletionStruct()
98 	{
99 		return gCompletion;
100 	}
101 	
102 	
103 	/** the main Gtk struct as a void* */
104 	protected void* getStruct()
105 	{
106 		return cast(void*)gCompletion;
107 	}
108 	
109 	/**
110 	 * Sets our main struct and passes it to the parent class
111 	 */
112 	public this (GCompletion* gCompletion)
113 	{
114 		this.gCompletion = gCompletion;
115 	}
116 	
117 	/**
118 	 */
119 	
120 	/**
121 	 * Creates a new GCompletion.
122 	 * Params:
123 	 * func = the function to be called to return the string representing
124 	 * an item in the GCompletion, or NULL if strings are going to
125 	 * be used as the GCompletion items.
126 	 * Throws: ConstructionException GTK+ fails to create the object.
127 	 */
128 	public this (GCompletionFunc func)
129 	{
130 		// GCompletion * g_completion_new (GCompletionFunc func);
131 		auto p = g_completion_new(func);
132 		if(p is null)
133 		{
134 			throw new ConstructionException("null returned by g_completion_new(func)");
135 		}
136 		this(cast(GCompletion*) p);
137 	}
138 	
139 	/**
140 	 * Warning
141 	 * g_completion_add_items has been deprecated since version 2.26 and should not be used in newly-written code. Rarely used API
142 	 * Adds items to the GCompletion.
143 	 * Params:
144 	 * items = the list of items to add. [transfer none]
145 	 */
146 	public void addItems(ListG items)
147 	{
148 		// void g_completion_add_items (GCompletion *cmp,  GList *items);
149 		g_completion_add_items(gCompletion, (items is null) ? null : items.getListGStruct());
150 	}
151 	
152 	/**
153 	 * Warning
154 	 * g_completion_remove_items has been deprecated since version 2.26 and should not be used in newly-written code. Rarely used API
155 	 * Removes items from a GCompletion. The items are not freed, so if the memory
156 	 * was dynamically allocated, free items with g_list_free_full() after calling
157 	 * this function.
158 	 * Params:
159 	 * items = the items to remove. [transfer none]
160 	 */
161 	public void removeItems(ListG items)
162 	{
163 		// void g_completion_remove_items (GCompletion *cmp,  GList *items);
164 		g_completion_remove_items(gCompletion, (items is null) ? null : items.getListGStruct());
165 	}
166 	
167 	/**
168 	 * Warning
169 	 * g_completion_clear_items has been deprecated since version 2.26 and should not be used in newly-written code. Rarely used API
170 	 * Removes all items from the GCompletion. The items are not freed, so if the
171 	 * memory was dynamically allocated, it should be freed after calling this
172 	 * function.
173 	 */
174 	public void clearItems()
175 	{
176 		// void g_completion_clear_items (GCompletion *cmp);
177 		g_completion_clear_items(gCompletion);
178 	}
179 	
180 	/**
181 	 * Warning
182 	 * g_completion_complete has been deprecated since version 2.26 and should not be used in newly-written code. Rarely used API
183 	 * Attempts to complete the string prefix using the GCompletion
184 	 * target items.
185 	 * Params:
186 	 * prefix = the prefix string, typically typed by the user, which is
187 	 * compared with each of the items.
188 	 * newPrefix = if non-NULL, returns the longest prefix which is
189 	 * common to all items that matched prefix, or NULL if
190 	 * no items matched prefix. This string should be freed
191 	 * when no longer needed.
192 	 * Returns: the list of items whose strings begin with prefix. This should not be changed. [transfer none]
193 	 */
194 	public ListG complete(string prefix, out string newPrefix)
195 	{
196 		// GList * g_completion_complete (GCompletion *cmp,  const gchar *prefix,  gchar **new_prefix);
197 		char* outnewPrefix = null;
198 		
199 		auto p = g_completion_complete(gCompletion, Str.toStringz(prefix), &outnewPrefix);
200 		
201 		newPrefix = Str.toString(outnewPrefix);
202 		
203 		if(p is null)
204 		{
205 			return null;
206 		}
207 		
208 		return new ListG(cast(GList*) p);
209 	}
210 	
211 	/**
212 	 * Warning
213 	 * g_completion_complete_utf8 has been deprecated since version 2.26 and should not be used in newly-written code. Rarely used API
214 	 * Attempts to complete the string prefix using the GCompletion target items.
215 	 * In contrast to g_completion_complete(), this function returns the largest common
216 	 * prefix that is a valid UTF-8 string, omitting a possible common partial
217 	 * character.
218 	 * You should use this function instead of g_completion_complete() if your
219 	 * items are UTF-8 strings.
220 	 * Since 2.4
221 	 * Params:
222 	 * prefix = the prefix string, typically used by the user, which is compared
223 	 * with each of the items
224 	 * newPrefix = if non-NULL, returns the longest prefix which is common to all
225 	 * items that matched prefix, or NULL if no items matched prefix.
226 	 * This string should be freed when no longer needed.
227 	 * Returns: the list of items whose strings begin with prefix. This should not be changed. [element-type utf8][transfer none]
228 	 */
229 	public ListG completeUtf8(string prefix, out string newPrefix)
230 	{
231 		// GList * g_completion_complete_utf8 (GCompletion *cmp,  const gchar *prefix,  gchar **new_prefix);
232 		char* outnewPrefix = null;
233 		
234 		auto p = g_completion_complete_utf8(gCompletion, Str.toStringz(prefix), &outnewPrefix);
235 		
236 		newPrefix = Str.toString(outnewPrefix);
237 		
238 		if(p is null)
239 		{
240 			return null;
241 		}
242 		
243 		return new ListG(cast(GList*) p);
244 	}
245 	
246 	/**
247 	 * Warning
248 	 * g_completion_set_compare has been deprecated since version 2.26 and should not be used in newly-written code. Rarely used API
249 	 * Sets the function to use for string comparisons. The default string
250 	 * comparison function is strncmp().
251 	 * Params:
252 	 * cmp = a GCompletion.
253 	 * strncmpFunc = the string comparison function.
254 	 */
255 	public void setCompare(GCompletionStrncmpFunc strncmpFunc)
256 	{
257 		// void g_completion_set_compare (GCompletion *cmp,  GCompletionStrncmpFunc strncmp_func);
258 		g_completion_set_compare(gCompletion, strncmpFunc);
259 	}
260 	
261 	/**
262 	 * Warning
263 	 * g_completion_free has been deprecated since version 2.26 and should not be used in newly-written code. Rarely used API
264 	 * Frees all memory used by the GCompletion. The items are not freed, so if
265 	 * the memory was dynamically allocated, it should be freed after calling this
266 	 * function.
267 	 */
268 	public void free()
269 	{
270 		// void g_completion_free (GCompletion *cmp);
271 		g_completion_free(gCompletion);
272 	}
273 }