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  = GtkEntryCompletion.html
27  * outPack = gtk
28  * outFile = EntryCompletion
29  * strct   = GtkEntryCompletion
30  * realStrct=
31  * ctorStrct=
32  * clss    = EntryCompletion
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * 	- CellLayoutIF
40  * prefixes:
41  * 	- gtk_entry_completion_
42  * 	- gtk_
43  * omit structs:
44  * omit prefixes:
45  * omit code:
46  * omit signals:
47  * imports:
48  * 	- glib.Str
49  * 	- gtk.Widget
50  * 	- gtk.TreeModel
51  * 	- gtk.TreeModelIF
52  * 	- gtk.CellLayoutIF
53  * 	- gtk.CellLayoutT
54  * structWrap:
55  * 	- GtkTreeModel* -> TreeModelIF
56  * 	- GtkWidget* -> Widget
57  * module aliases:
58  * local aliases:
59  * overrides:
60  */
61 
62 module gtk.EntryCompletion;
63 
64 public  import gtkc.gtktypes;
65 
66 private import gtkc.gtk;
67 private import glib.ConstructionException;
68 private import gobject.ObjectG;
69 
70 private import gobject.Signals;
71 public  import gtkc.gdktypes;
72 
73 private import glib.Str;
74 private import gtk.Widget;
75 private import gtk.TreeModel;
76 private import gtk.TreeModelIF;
77 private import gtk.CellLayoutIF;
78 private import gtk.CellLayoutT;
79 
80 
81 
82 private import gobject.ObjectG;
83 
84 /**
85  * Description
86  * GtkEntryCompletion is an auxiliary object to be used in conjunction with
87  * GtkEntry to provide the completion functionality. It implements the
88  * GtkCellLayout interface, to allow the user to add extra cells to the
89  * GtkTreeView with completion matches.
90  * "Completion functionality" means that when the user modifies the text
91  * in the entry, GtkEntryCompletion checks which rows in the model match
92  * the current content of the entry, and displays a list of matches.
93  * By default, the matching is done by comparing the entry text
94  * case-insensitively against the text column of the model (see
95  * gtk_entry_completion_set_text_column()), but this can be overridden with
96  * a custom match function (see gtk_entry_completion_set_match_func()).
97  * When the user selects a completion, the content of the entry is updated.
98  * By default, the content of the entry is replaced by the text column of the
99  * model, but this can be overridden by connecting to the ::match-selected signal
100  * and updating the entry in the signal handler. Note that you should return
101  * TRUE from the signal handler to suppress the default behaviour.
102  * To add completion functionality to an entry, use gtk_entry_set_completion().
103  * In addition to regular completion matches, which will be inserted into the
104  * entry when they are selected, GtkEntryCompletion also allows to display
105  * "actions" in the popup window. Their appearance is similar to menuitems,
106  * to differentiate them clearly from completion strings. When an action is
107  * selected, the ::action-activated signal is emitted.
108  */
109 public class EntryCompletion : ObjectG, CellLayoutIF
110 {
111 	
112 	/** the main Gtk struct */
113 	protected GtkEntryCompletion* gtkEntryCompletion;
114 	
115 	
116 	public GtkEntryCompletion* getEntryCompletionStruct()
117 	{
118 		return gtkEntryCompletion;
119 	}
120 	
121 	
122 	/** the main Gtk struct as a void* */
123 	protected override void* getStruct()
124 	{
125 		return cast(void*)gtkEntryCompletion;
126 	}
127 	
128 	/**
129 	 * Sets our main struct and passes it to the parent class
130 	 */
131 	public this (GtkEntryCompletion* gtkEntryCompletion)
132 	{
133 		super(cast(GObject*)gtkEntryCompletion);
134 		this.gtkEntryCompletion = gtkEntryCompletion;
135 	}
136 	
137 	protected override void setStruct(GObject* obj)
138 	{
139 		super.setStruct(obj);
140 		gtkEntryCompletion = cast(GtkEntryCompletion*)obj;
141 	}
142 	
143 	// add the CellLayout capabilities
144 	mixin CellLayoutT!(GtkEntryCompletion);
145 	
146 	/**
147 	 */
148 	int[string] connectedSignals;
149 	
150 	void delegate(gint, EntryCompletion)[] onActionActivatedListeners;
151 	/**
152 	 * Gets emitted when an action is activated.
153 	 * Since 2.4
154 	 */
155 	void addOnActionActivated(void delegate(gint, EntryCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
156 	{
157 		if ( !("action-activated" in connectedSignals) )
158 		{
159 			Signals.connectData(
160 			getStruct(),
161 			"action-activated",
162 			cast(GCallback)&callBackActionActivated,
163 			cast(void*)this,
164 			null,
165 			connectFlags);
166 			connectedSignals["action-activated"] = 1;
167 		}
168 		onActionActivatedListeners ~= dlg;
169 	}
170 	extern(C) static void callBackActionActivated(GtkEntryCompletion* widgetStruct, gint index, EntryCompletion _entryCompletion)
171 	{
172 		foreach ( void delegate(gint, EntryCompletion) dlg ; _entryCompletion.onActionActivatedListeners )
173 		{
174 			dlg(index, _entryCompletion);
175 		}
176 	}
177 	
178 	bool delegate(TreeModelIF, GtkTreeIter*, EntryCompletion)[] onCursorOnMatchListeners;
179 	/**
180 	 * Gets emitted when a match from the cursor is on a match
181 	 * of the list.The default behaviour is to replace the contents
182 	 * of the entry with the contents of the text column in the row
183 	 * pointed to by iter.
184 	 * TRUE if the signal has been handled
185 	 * Since 2.12
186 	 */
187 	void addOnCursorOnMatch(bool delegate(TreeModelIF, GtkTreeIter*, EntryCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
188 	{
189 		if ( !("cursor-on-match" in connectedSignals) )
190 		{
191 			Signals.connectData(
192 			getStruct(),
193 			"cursor-on-match",
194 			cast(GCallback)&callBackCursorOnMatch,
195 			cast(void*)this,
196 			null,
197 			connectFlags);
198 			connectedSignals["cursor-on-match"] = 1;
199 		}
200 		onCursorOnMatchListeners ~= dlg;
201 	}
202 	extern(C) static gboolean callBackCursorOnMatch(GtkEntryCompletion* widgetStruct, GtkTreeModel* model, GtkTreeIter* iter, EntryCompletion _entryCompletion)
203 	{
204 		foreach ( bool delegate(TreeModelIF, GtkTreeIter*, EntryCompletion) dlg ; _entryCompletion.onCursorOnMatchListeners )
205 		{
206 			if ( dlg(ObjectG.getDObject!(TreeModel, TreeModelIF)(model), iter, _entryCompletion) )
207 			{
208 				return 1;
209 			}
210 		}
211 		
212 		return 0;
213 	}
214 	
215 	bool delegate(string, EntryCompletion)[] onInsertPrefixListeners;
216 	/**
217 	 * Gets emitted when the inline autocompletion is triggered.
218 	 * The default behaviour is to make the entry display the
219 	 * whole prefix and select the newly inserted part.
220 	 * Applications may connect to this signal in order to insert only a
221 	 * smaller part of the prefix into the entry - e.g. the entry used in
222 	 * the GtkFileChooser inserts only the part of the prefix up to the
223 	 * next '/'.
224 	 * TRUE if the signal has been handled
225 	 * Since 2.6
226 	 */
227 	void addOnInsertPrefix(bool delegate(string, EntryCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
228 	{
229 		if ( !("insert-prefix" in connectedSignals) )
230 		{
231 			Signals.connectData(
232 			getStruct(),
233 			"insert-prefix",
234 			cast(GCallback)&callBackInsertPrefix,
235 			cast(void*)this,
236 			null,
237 			connectFlags);
238 			connectedSignals["insert-prefix"] = 1;
239 		}
240 		onInsertPrefixListeners ~= dlg;
241 	}
242 	extern(C) static gboolean callBackInsertPrefix(GtkEntryCompletion* widgetStruct, gchar* prefix, EntryCompletion _entryCompletion)
243 	{
244 		foreach ( bool delegate(string, EntryCompletion) dlg ; _entryCompletion.onInsertPrefixListeners )
245 		{
246 			if ( dlg(Str.toString(prefix), _entryCompletion) )
247 			{
248 				return 1;
249 			}
250 		}
251 		
252 		return 0;
253 	}
254 	
255 	bool delegate(TreeModelIF, GtkTreeIter*, EntryCompletion)[] onMatchSelectedListeners;
256 	/**
257 	 * Gets emitted when a match from the list is selected.
258 	 * The default behaviour is to replace the contents of the
259 	 * entry with the contents of the text column in the row
260 	 * pointed to by iter.
261 	 * TRUE if the signal has been handled
262 	 * Since 2.4
263 	 */
264 	void addOnMatchSelected(bool delegate(TreeModelIF, GtkTreeIter*, EntryCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
265 	{
266 		if ( !("match-selected" in connectedSignals) )
267 		{
268 			Signals.connectData(
269 			getStruct(),
270 			"match-selected",
271 			cast(GCallback)&callBackMatchSelected,
272 			cast(void*)this,
273 			null,
274 			connectFlags);
275 			connectedSignals["match-selected"] = 1;
276 		}
277 		onMatchSelectedListeners ~= dlg;
278 	}
279 	extern(C) static gboolean callBackMatchSelected(GtkEntryCompletion* widgetStruct, GtkTreeModel* model, GtkTreeIter* iter, EntryCompletion _entryCompletion)
280 	{
281 		foreach ( bool delegate(TreeModelIF, GtkTreeIter*, EntryCompletion) dlg ; _entryCompletion.onMatchSelectedListeners )
282 		{
283 			if ( dlg(ObjectG.getDObject!(TreeModel, TreeModelIF)(model), iter, _entryCompletion) )
284 			{
285 				return 1;
286 			}
287 		}
288 		
289 		return 0;
290 	}
291 	
292 	
293 	/**
294 	 * Creates a new GtkEntryCompletion object.
295 	 * Since 2.4
296 	 * Throws: ConstructionException GTK+ fails to create the object.
297 	 */
298 	public this ()
299 	{
300 		// GtkEntryCompletion * gtk_entry_completion_new (void);
301 		auto p = gtk_entry_completion_new();
302 		if(p is null)
303 		{
304 			throw new ConstructionException("null returned by gtk_entry_completion_new()");
305 		}
306 		this(cast(GtkEntryCompletion*) p);
307 	}
308 	
309 	/**
310 	 * Gets the entry completion has been attached to.
311 	 * Since 2.4
312 	 * Returns: The entry completion has been attached to. [transfer none]
313 	 */
314 	public Widget getEntry()
315 	{
316 		// GtkWidget * gtk_entry_completion_get_entry (GtkEntryCompletion *completion);
317 		auto p = gtk_entry_completion_get_entry(gtkEntryCompletion);
318 		
319 		if(p is null)
320 		{
321 			return null;
322 		}
323 		
324 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
325 	}
326 	
327 	/**
328 	 * Sets the model for a GtkEntryCompletion. If completion already has
329 	 * a model set, it will remove it before setting the new model.
330 	 * If model is NULL, then it will unset the model.
331 	 * Since 2.4
332 	 * Params:
333 	 * model = The GtkTreeModel. [allow-none]
334 	 */
335 	public void setModel(TreeModelIF model)
336 	{
337 		// void gtk_entry_completion_set_model (GtkEntryCompletion *completion,  GtkTreeModel *model);
338 		gtk_entry_completion_set_model(gtkEntryCompletion, (model is null) ? null : model.getTreeModelTStruct());
339 	}
340 	
341 	/**
342 	 * Returns the model the GtkEntryCompletion is using as data source.
343 	 * Returns NULL if the model is unset.
344 	 * Since 2.4
345 	 * Returns: A GtkTreeModel, or NULL if none is currently being used. [transfer none]
346 	 */
347 	public TreeModelIF getModel()
348 	{
349 		// GtkTreeModel * gtk_entry_completion_get_model (GtkEntryCompletion *completion);
350 		auto p = gtk_entry_completion_get_model(gtkEntryCompletion);
351 		
352 		if(p is null)
353 		{
354 			return null;
355 		}
356 		
357 		return ObjectG.getDObject!(TreeModel, TreeModelIF)(cast(GtkTreeModel*) p);
358 	}
359 	
360 	/**
361 	 * Sets the match function for completion to be func. The match function
362 	 * is used to determine if a row should or should not be in the completion
363 	 * list.
364 	 * Since 2.4
365 	 * Params:
366 	 * func = The GtkEntryCompletionMatchFunc to use.
367 	 * funcData = The user data for func.
368 	 * funcNotify = Destroy notifier for func_data.
369 	 */
370 	public void setMatchFunc(GtkEntryCompletionMatchFunc func, void* funcData, GDestroyNotify funcNotify)
371 	{
372 		// void gtk_entry_completion_set_match_func (GtkEntryCompletion *completion,  GtkEntryCompletionMatchFunc func,  gpointer func_data,  GDestroyNotify func_notify);
373 		gtk_entry_completion_set_match_func(gtkEntryCompletion, func, funcData, funcNotify);
374 	}
375 	
376 	/**
377 	 * Requires the length of the search key for completion to be at least
378 	 * length. This is useful for long lists, where completing using a small
379 	 * key takes a lot of time and will come up with meaningless results anyway
380 	 * (ie, a too large dataset).
381 	 * Since 2.4
382 	 * Params:
383 	 * length = The minimum length of the key in order to start completing.
384 	 */
385 	public void setMinimumKeyLength(int length)
386 	{
387 		// void gtk_entry_completion_set_minimum_key_length  (GtkEntryCompletion *completion,  gint length);
388 		gtk_entry_completion_set_minimum_key_length(gtkEntryCompletion, length);
389 	}
390 	
391 	/**
392 	 * Returns the minimum key length as set for completion.
393 	 * Since 2.4
394 	 * Returns: The currently used minimum key length.
395 	 */
396 	public int getMinimumKeyLength()
397 	{
398 		// gint gtk_entry_completion_get_minimum_key_length  (GtkEntryCompletion *completion);
399 		return gtk_entry_completion_get_minimum_key_length(gtkEntryCompletion);
400 	}
401 	
402 	/**
403 	 * Requests a completion operation, or in other words a refiltering of the
404 	 * current list with completions, using the current key. The completion list
405 	 * view will be updated accordingly.
406 	 * Since 2.4
407 	 */
408 	public void complete()
409 	{
410 		// void gtk_entry_completion_complete (GtkEntryCompletion *completion);
411 		gtk_entry_completion_complete(gtkEntryCompletion);
412 	}
413 	
414 	/**
415 	 * Get the original text entered by the user that triggered
416 	 * the completion or NULL if there's no completion ongoing.
417 	 * Since 2.12
418 	 * Returns: the prefix for the current completion
419 	 */
420 	public string getCompletionPrefix()
421 	{
422 		// const gchar * gtk_entry_completion_get_completion_prefix  (GtkEntryCompletion *completion);
423 		return Str.toString(gtk_entry_completion_get_completion_prefix(gtkEntryCompletion));
424 	}
425 	
426 	/**
427 	 * Requests a prefix insertion.
428 	 * Since 2.6
429 	 */
430 	public void insertPrefix()
431 	{
432 		// void gtk_entry_completion_insert_prefix (GtkEntryCompletion *completion);
433 		gtk_entry_completion_insert_prefix(gtkEntryCompletion);
434 	}
435 	
436 	/**
437 	 * Inserts an action in completion's action item list at position index_
438 	 * with text text. If you want the action item to have markup, use
439 	 * gtk_entry_completion_insert_action_markup().
440 	 * Since 2.4
441 	 * Params:
442 	 * index = The index of the item to insert.
443 	 * text = Text of the item to insert.
444 	 */
445 	public void insertActionText(int index, string text)
446 	{
447 		// void gtk_entry_completion_insert_action_text  (GtkEntryCompletion *completion,  gint index_,  const gchar *text);
448 		gtk_entry_completion_insert_action_text(gtkEntryCompletion, index, Str.toStringz(text));
449 	}
450 	
451 	/**
452 	 * Inserts an action in completion's action item list at position index_
453 	 * with markup markup.
454 	 * Since 2.4
455 	 * Params:
456 	 * index = The index of the item to insert.
457 	 * markup = Markup of the item to insert.
458 	 */
459 	public void insertActionMarkup(int index, string markup)
460 	{
461 		// void gtk_entry_completion_insert_action_markup  (GtkEntryCompletion *completion,  gint index_,  const gchar *markup);
462 		gtk_entry_completion_insert_action_markup(gtkEntryCompletion, index, Str.toStringz(markup));
463 	}
464 	
465 	/**
466 	 * Deletes the action at index_ from completion's action list.
467 	 * Since 2.4
468 	 * Params:
469 	 * index = The index of the item to Delete.
470 	 */
471 	public void deleteAction(int index)
472 	{
473 		// void gtk_entry_completion_delete_action (GtkEntryCompletion *completion,  gint index_);
474 		gtk_entry_completion_delete_action(gtkEntryCompletion, index);
475 	}
476 	
477 	/**
478 	 * Convenience function for setting up the most used case of this code: a
479 	 * completion list with just strings. This function will set up completion
480 	 * to have a list displaying all (and just) strings in the completion list,
481 	 * and to get those strings from column in the model of completion.
482 	 * This functions creates and adds a GtkCellRendererText for the selected
483 	 * column. If you need to set the text column, but don't want the cell
484 	 * renderer, use g_object_set() to set the ::text_column property directly.
485 	 * Since 2.4
486 	 * Params:
487 	 * column = The column in the model of completion to get strings from.
488 	 */
489 	public void setTextColumn(int column)
490 	{
491 		// void gtk_entry_completion_set_text_column  (GtkEntryCompletion *completion,  gint column);
492 		gtk_entry_completion_set_text_column(gtkEntryCompletion, column);
493 	}
494 	
495 	/**
496 	 * Returns the column in the model of completion to get strings from.
497 	 * Since 2.6
498 	 * Returns: the column containing the strings
499 	 */
500 	public int getTextColumn()
501 	{
502 		// gint gtk_entry_completion_get_text_column  (GtkEntryCompletion *completion);
503 		return gtk_entry_completion_get_text_column(gtkEntryCompletion);
504 	}
505 	
506 	/**
507 	 * Sets whether the common prefix of the possible completions should
508 	 * be automatically inserted in the entry.
509 	 * Since 2.6
510 	 * Params:
511 	 * inlineCompletion = TRUE to do inline completion
512 	 */
513 	public void setInlineCompletion(int inlineCompletion)
514 	{
515 		// void gtk_entry_completion_set_inline_completion  (GtkEntryCompletion *completion,  gboolean inline_completion);
516 		gtk_entry_completion_set_inline_completion(gtkEntryCompletion, inlineCompletion);
517 	}
518 	
519 	/**
520 	 * Returns whether the common prefix of the possible completions should
521 	 * be automatically inserted in the entry.
522 	 * Since 2.6
523 	 * Returns: TRUE if inline completion is turned on
524 	 */
525 	public int getInlineCompletion()
526 	{
527 		// gboolean gtk_entry_completion_get_inline_completion  (GtkEntryCompletion *completion);
528 		return gtk_entry_completion_get_inline_completion(gtkEntryCompletion);
529 	}
530 	
531 	/**
532 	 * Sets whether it is possible to cycle through the possible completions
533 	 * inside the entry.
534 	 * Since 2.12
535 	 * Params:
536 	 * inlineSelection = TRUE to do inline selection
537 	 */
538 	public void setInlineSelection(int inlineSelection)
539 	{
540 		// void gtk_entry_completion_set_inline_selection  (GtkEntryCompletion *completion,  gboolean inline_selection);
541 		gtk_entry_completion_set_inline_selection(gtkEntryCompletion, inlineSelection);
542 	}
543 	
544 	/**
545 	 * Returns TRUE if inline-selection mode is turned on.
546 	 * Since 2.12
547 	 * Returns: TRUE if inline-selection mode is on
548 	 */
549 	public int getInlineSelection()
550 	{
551 		// gboolean gtk_entry_completion_get_inline_selection  (GtkEntryCompletion *completion);
552 		return gtk_entry_completion_get_inline_selection(gtkEntryCompletion);
553 	}
554 	
555 	/**
556 	 * Sets whether the completions should be presented in a popup window.
557 	 * Since 2.6
558 	 * Params:
559 	 * popupCompletion = TRUE to do popup completion
560 	 */
561 	public void setPopupCompletion(int popupCompletion)
562 	{
563 		// void gtk_entry_completion_set_popup_completion  (GtkEntryCompletion *completion,  gboolean popup_completion);
564 		gtk_entry_completion_set_popup_completion(gtkEntryCompletion, popupCompletion);
565 	}
566 	
567 	/**
568 	 * Returns whether the completions should be presented in a popup window.
569 	 * Since 2.6
570 	 * Returns: TRUE if popup completion is turned on
571 	 */
572 	public int getPopupCompletion()
573 	{
574 		// gboolean gtk_entry_completion_get_popup_completion  (GtkEntryCompletion *completion);
575 		return gtk_entry_completion_get_popup_completion(gtkEntryCompletion);
576 	}
577 	
578 	/**
579 	 * Sets whether the completion popup window will be resized to be the same
580 	 * width as the entry.
581 	 * Since 2.8
582 	 * Params:
583 	 * popupSetWidth = TRUE to make the width of the popup the same as the entry
584 	 */
585 	public void setPopupSetWidth(int popupSetWidth)
586 	{
587 		// void gtk_entry_completion_set_popup_set_width  (GtkEntryCompletion *completion,  gboolean popup_set_width);
588 		gtk_entry_completion_set_popup_set_width(gtkEntryCompletion, popupSetWidth);
589 	}
590 	
591 	/**
592 	 * Returns whether the completion popup window will be resized to the
593 	 * width of the entry.
594 	 * Since 2.8
595 	 * Returns: TRUE if the popup window will be resized to the width of the entry
596 	 */
597 	public int getPopupSetWidth()
598 	{
599 		// gboolean gtk_entry_completion_get_popup_set_width  (GtkEntryCompletion *completion);
600 		return gtk_entry_completion_get_popup_set_width(gtkEntryCompletion);
601 	}
602 	
603 	/**
604 	 * Sets whether the completion popup window will appear even if there is
605 	 * only a single match. You may want to set this to FALSE if you
606 	 * are using inline
607 	 * completion.
608 	 * Since 2.8
609 	 * Params:
610 	 * popupSingleMatch = TRUE if the popup should appear even for a single
611 	 * match
612 	 */
613 	public void setPopupSingleMatch(int popupSingleMatch)
614 	{
615 		// void gtk_entry_completion_set_popup_single_match  (GtkEntryCompletion *completion,  gboolean popup_single_match);
616 		gtk_entry_completion_set_popup_single_match(gtkEntryCompletion, popupSingleMatch);
617 	}
618 	
619 	/**
620 	 * Returns whether the completion popup window will appear even if there is
621 	 * only a single match.
622 	 * Since 2.8
623 	 * Returns: TRUE if the popup window will appear regardless of the number of matches.
624 	 */
625 	public int getPopupSingleMatch()
626 	{
627 		// gboolean gtk_entry_completion_get_popup_single_match  (GtkEntryCompletion *completion);
628 		return gtk_entry_completion_get_popup_single_match(gtkEntryCompletion);
629 	}
630 }