alternative to assert
[gtkD.git] / gtkD / src / gtk / EntryCompletion.d
blob7184e4eb324ca98d4ebd6eb18fdf5d858ccb2995
1 /*
2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = GtkEntryCompletion.html
26 * outPack = gtk
27 * outFile = EntryCompletion
28 * strct = GtkEntryCompletion
29 * realStrct=
30 * ctorStrct=
31 * clss = EntryCompletion
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - gtk_entry_completion_
40 * - gtk_
41 * omit structs:
42 * omit prefixes:
43 * omit code:
44 * imports:
45 * - glib.Str
46 * - gtk.Widget
47 * - gtk.TreeModel
48 * structWrap:
49 * - GtkTreeModel* -> TreeModel
50 * - GtkWidget* -> Widget
51 * module aliases:
52 * local aliases:
55 module gtk.EntryCompletion;
57 version(noAssert)
59 version(Tango)
61 import tango.io.Stdout; // use the tango loging?
65 private import gtkc.gtktypes;
67 private import gtkc.gtk;
70 private import glib.Str;
71 private import gtk.Widget;
72 private import gtk.TreeModel;
77 /**
78 * Description
79 * GtkEntryCompletion is an auxiliary object to be used in conjunction with
80 * GtkEntry to provide the completion functionality. It implements the
81 * GtkCellLayout interface, to allow the user to add extra cells to the
82 * GtkTreeView with completion matches.
83 * "Completion functionality" means that when the user modifies the text
84 * in the entry, GtkEntryCompletion checks which rows in the model match
85 * the current content of the entry, and displays a list of matches.
86 * By default, the matching is done by comparing the entry text
87 * case-insensitively against the text column of the model (see
88 * gtk_entry_completion_set_text_column()), but this can be overridden with
89 * a custom match function (see gtk_entry_completion_set_match_func()).
90 * When the user selects a completion, the content of the entry is updated.
91 * By default, the content of the entry is replaced by the text column of the
92 * model, but this can be overridden by connecting to the ::match-selected signal
93 * and updating the entry in the signal handler. Note that you should return
94 * TRUE from the signal handler to suppress the default behaviour.
95 * To add completion functionality to an entry, use gtk_entry_set_completion().
96 * In addition to regular completion matches, which will be inserted into the
97 * entry when they are selected, GtkEntryCompletion also allows to display
98 * "actions" in the popup window. Their appearance is similar to menuitems,
99 * to differentiate them clearly from completion strings. When an action is
100 * selected, the ::action-activated signal is emitted.
102 private import gobject.ObjectG;
103 public class EntryCompletion : ObjectG
106 /** the main Gtk struct */
107 protected GtkEntryCompletion* gtkEntryCompletion;
110 public GtkEntryCompletion* getEntryCompletionStruct()
112 return gtkEntryCompletion;
116 /** the main Gtk struct as a void* */
117 protected void* getStruct()
119 return cast(void*)gtkEntryCompletion;
123 * Sets our main struct and passes it to the parent class
125 public this (GtkEntryCompletion* gtkEntryCompletion)
127 version(noAssert)
129 if ( gtkEntryCompletion is null )
131 int zero = 0;
132 version(Tango)
134 Stdout("struct gtkEntryCompletion is null on constructor").newline;
136 else
138 printf("struct gtkEntryCompletion is null on constructor");
140 zero = zero / zero;
143 else
145 assert(gtkEntryCompletion !is null, "struct gtkEntryCompletion is null on constructor");
147 super(cast(GObject*)gtkEntryCompletion);
148 this.gtkEntryCompletion = gtkEntryCompletion;
154 // imports for the signal processing
155 private import gobject.Signals;
156 private import gtkc.gdktypes;
157 int[char[]] connectedSignals;
159 void delegate(gint, EntryCompletion)[] onActionActivatedListeners;
160 void addOnActionActivated(void delegate(gint, EntryCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
162 if ( !("action-activated" in connectedSignals) )
164 Signals.connectData(
165 getStruct(),
166 "action-activated",
167 cast(GCallback)&callBackActionActivated,
168 cast(void*)this,
169 null,
170 connectFlags);
171 connectedSignals["action-activated"] = 1;
173 onActionActivatedListeners ~= dlg;
175 extern(C) static void callBackActionActivated(GtkEntryCompletion* widgetStruct, gint index, EntryCompletion entryCompletion)
177 bool consumed = false;
179 foreach ( void delegate(gint, EntryCompletion) dlg ; entryCompletion.onActionActivatedListeners )
181 dlg(index, entryCompletion);
184 return consumed;
187 gboolean delegate(char[], EntryCompletion)[] onInsertPrefixListeners;
188 void addOnInsertPrefix(gboolean delegate(char[], EntryCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
190 if ( !("insert-prefix" in connectedSignals) )
192 Signals.connectData(
193 getStruct(),
194 "insert-prefix",
195 cast(GCallback)&callBackInsertPrefix,
196 cast(void*)this,
197 null,
198 connectFlags);
199 connectedSignals["insert-prefix"] = 1;
201 onInsertPrefixListeners ~= dlg;
203 extern(C) static void callBackInsertPrefix(GtkEntryCompletion* widgetStruct, gchar* prefix, EntryCompletion entryCompletion)
205 bool consumed = false;
207 foreach ( gboolean delegate(char[], EntryCompletion) dlg ; entryCompletion.onInsertPrefixListeners )
209 dlg(Str.toString(prefix), entryCompletion);
212 return consumed;
215 gboolean delegate(TreeModel, GtkTreeIter*, EntryCompletion)[] onMatchSelectedListeners;
216 void addOnMatchSelected(gboolean delegate(TreeModel, GtkTreeIter*, EntryCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
218 if ( !("match-selected" in connectedSignals) )
220 Signals.connectData(
221 getStruct(),
222 "match-selected",
223 cast(GCallback)&callBackMatchSelected,
224 cast(void*)this,
225 null,
226 connectFlags);
227 connectedSignals["match-selected"] = 1;
229 onMatchSelectedListeners ~= dlg;
231 extern(C) static void callBackMatchSelected(GtkEntryCompletion* widgetStruct, GtkTreeModel* model, GtkTreeIter* iter, EntryCompletion entryCompletion)
233 bool consumed = false;
235 foreach ( gboolean delegate(TreeModel, GtkTreeIter*, EntryCompletion) dlg ; entryCompletion.onMatchSelectedListeners )
237 dlg(new TreeModel(model), iter, entryCompletion);
240 return consumed;
247 * Creates a new GtkEntryCompletion object.
248 * Returns:
249 * A newly created GtkEntryCompletion object.
250 * Since 2.4
252 public this ()
254 // GtkEntryCompletion* gtk_entry_completion_new (void);
255 this(cast(GtkEntryCompletion*)gtk_entry_completion_new() );
259 * Gets the entry completion has been attached to.
260 * completion:
261 * A GtkEntryCompletion.
262 * Returns:
263 * The entry completion has been attached to.
264 * Since 2.4
266 public Widget getEntry()
268 // GtkWidget* gtk_entry_completion_get_entry (GtkEntryCompletion *completion);
269 return new Widget( gtk_entry_completion_get_entry(gtkEntryCompletion) );
273 * Sets the model for a GtkEntryCompletion. If completion already has
274 * a model set, it will remove it before setting the new model.
275 * If model is NULL, then it will unset the model.
276 * completion:
277 * A GtkEntryCompletion.
278 * model:
279 * The GtkTreeModel.
280 * Since 2.4
282 public void setModel(TreeModel model)
284 // void gtk_entry_completion_set_model (GtkEntryCompletion *completion, GtkTreeModel *model);
285 gtk_entry_completion_set_model(gtkEntryCompletion, (model is null) ? null : model.getTreeModelStruct());
289 * Returns the model the GtkEntryCompletion is using as data source.
290 * Returns NULL if the model is unset.
291 * completion:
292 * A GtkEntryCompletion.
293 * Returns:
294 * A GtkTreeModel, or NULL if none is currently being used.
295 * Since 2.4
297 public TreeModel getModel()
299 // GtkTreeModel* gtk_entry_completion_get_model (GtkEntryCompletion *completion);
300 return new TreeModel( gtk_entry_completion_get_model(gtkEntryCompletion) );
304 * Sets the match function for completion to be func. The match function
305 * is used to determine if a row should or should not be in the completion
306 * list.
307 * completion:
308 * A GtkEntryCompletion.
309 * func:
310 * The GtkEntryCompletionMatchFunc to use.
311 * func_data:
312 * The user data for func.
313 * func_notify:
314 * Destroy notifier for func_data.
315 * Since 2.4
317 public void setMatchFunc(GtkEntryCompletionMatchFunc func, void* funcData, GDestroyNotify funcNotify)
319 // void gtk_entry_completion_set_match_func (GtkEntryCompletion *completion, GtkEntryCompletionMatchFunc func, gpointer func_data, GDestroyNotify func_notify);
320 gtk_entry_completion_set_match_func(gtkEntryCompletion, func, funcData, funcNotify);
324 * Requires the length of the search key for completion to be at least
325 * length. This is useful for long lists, where completing using a small
326 * key takes a lot of time and will come up with meaningless results anyway
327 * (ie, a too large dataset).
328 * completion:
329 * A GtkEntryCompletion.
330 * length:
331 * The minimum length of the key in order to start completing.
332 * Since 2.4
334 public void setMinimumKeyLength(int length)
336 // void gtk_entry_completion_set_minimum_key_length (GtkEntryCompletion *completion, gint length);
337 gtk_entry_completion_set_minimum_key_length(gtkEntryCompletion, length);
341 * Returns the minimum key length as set for completion.
342 * completion:
343 * A GtkEntryCompletion.
344 * Returns:
345 * The currently used minimum key length.
346 * Since 2.4
348 public int getMinimumKeyLength()
350 // gint gtk_entry_completion_get_minimum_key_length (GtkEntryCompletion *completion);
351 return gtk_entry_completion_get_minimum_key_length(gtkEntryCompletion);
355 * Requests a completion operation, or in other words a refiltering of the
356 * current list with completions, using the current key. The completion list
357 * view will be updated accordingly.
358 * completion:
359 * A GtkEntryCompletion.
360 * Since 2.4
362 public void complete()
364 // void gtk_entry_completion_complete (GtkEntryCompletion *completion);
365 gtk_entry_completion_complete(gtkEntryCompletion);
369 * Requests a prefix insertion.
370 * completion:
371 * a GtkEntryCompletion
372 * Since 2.6
374 public void insertPrefix()
376 // void gtk_entry_completion_insert_prefix (GtkEntryCompletion *completion);
377 gtk_entry_completion_insert_prefix(gtkEntryCompletion);
381 * Inserts an action in completion's action item list at position index_
382 * with text text. If you want the action item to have markup, use
383 * gtk_entry_completion_insert_action_markup().
384 * completion:
385 * A GtkEntryCompletion.
386 * index_:
387 * The index of the item to insert.
388 * text:
389 * Text of the item to insert.
390 * Since 2.4
392 public void insertActionText(int index, char[] text)
394 // void gtk_entry_completion_insert_action_text (GtkEntryCompletion *completion, gint index_, const gchar *text);
395 gtk_entry_completion_insert_action_text(gtkEntryCompletion, index, Str.toStringz(text));
399 * Inserts an action in completion's action item list at position index_
400 * with markup markup.
401 * completion:
402 * A GtkEntryCompletion.
403 * index_:
404 * The index of the item to insert.
405 * markup:
406 * Markup of the item to insert.
407 * Since 2.4
409 public void insertActionMarkup(int index, char[] markup)
411 // void gtk_entry_completion_insert_action_markup (GtkEntryCompletion *completion, gint index_, const gchar *markup);
412 gtk_entry_completion_insert_action_markup(gtkEntryCompletion, index, Str.toStringz(markup));
416 * Deletes the action at index_ from completion's action list.
417 * completion:
418 * A GtkEntryCompletion.
419 * index_:
420 * The index of the item to Delete.
421 * Since 2.4
423 public void deleteAction(int index)
425 // void gtk_entry_completion_delete_action (GtkEntryCompletion *completion, gint index_);
426 gtk_entry_completion_delete_action(gtkEntryCompletion, index);
430 * Convenience function for setting up the most used case of this code: a
431 * completion list with just strings. This function will set up completion
432 * to have a list displaying all (and just) strings in the completion list,
433 * and to get those strings from column in the model of completion.
434 * This functions creates and adds a GtkCellRendererText for the selected
435 * column. If you need to set the text column, but don't want the cell
436 * renderer, use g_object_set() to set the ::text_column property directly.
437 * completion:
438 * A GtkEntryCompletion.
439 * column:
440 * The column in the model of completion to get strings from.
441 * Since 2.4
443 public void setTextColumn(int column)
445 // void gtk_entry_completion_set_text_column (GtkEntryCompletion *completion, gint column);
446 gtk_entry_completion_set_text_column(gtkEntryCompletion, column);
450 * Returns the column in the model of completion to get strings from.
451 * completion:
452 * a GtkEntryCompletion
453 * Returns:
454 * the column containing the strings
455 * Since 2.6
457 public int getTextColumn()
459 // gint gtk_entry_completion_get_text_column (GtkEntryCompletion *completion);
460 return gtk_entry_completion_get_text_column(gtkEntryCompletion);
464 * Sets whether the common prefix of the possible completions should
465 * be automatically inserted in the entry.
466 * completion:
467 * a GtkEntryCompletion
468 * inline_completion:
469 * TRUE to do inline completion
470 * Since 2.6
472 public void setInlineCompletion(int inlineCompletion)
474 // void gtk_entry_completion_set_inline_completion (GtkEntryCompletion *completion, gboolean inline_completion);
475 gtk_entry_completion_set_inline_completion(gtkEntryCompletion, inlineCompletion);
479 * Returns whether the common prefix of the possible completions should
480 * be automatically inserted in the entry.
481 * completion:
482 * a GtkEntryCompletion
483 * Returns:
484 * TRUE if inline completion is turned on
485 * Since 2.6
487 public int getInlineCompletion()
489 // gboolean gtk_entry_completion_get_inline_completion (GtkEntryCompletion *completion);
490 return gtk_entry_completion_get_inline_completion(gtkEntryCompletion);
494 * Sets whether the completions should be presented in a popup window.
495 * completion:
496 * a GtkEntryCompletion
497 * popup_completion:
498 * TRUE to do popup completion
499 * Since 2.6
501 public void setPopupCompletion(int popupCompletion)
503 // void gtk_entry_completion_set_popup_completion (GtkEntryCompletion *completion, gboolean popup_completion);
504 gtk_entry_completion_set_popup_completion(gtkEntryCompletion, popupCompletion);
508 * Returns whether the completions should be presented in a popup window.
509 * completion:
510 * a GtkEntryCompletion
511 * Returns:
512 * TRUE if popup completion is turned on
513 * Since 2.6
515 public int getPopupCompletion()
517 // gboolean gtk_entry_completion_get_popup_completion (GtkEntryCompletion *completion);
518 return gtk_entry_completion_get_popup_completion(gtkEntryCompletion);
522 * Sets whether the completion popup window will be resized to be the same
523 * width as the entry.
524 * completion:
525 * a GtkEntryCompletion
526 * popup_set_width:
527 * TRUE to make the width of the popup the same as the entry
528 * Since 2.8
530 public void setPopupSetWidth(int popupSetWidth)
532 // void gtk_entry_completion_set_popup_set_width (GtkEntryCompletion *completion, gboolean popup_set_width);
533 gtk_entry_completion_set_popup_set_width(gtkEntryCompletion, popupSetWidth);
537 * Returns whether the completion popup window will be resized to the
538 * width of the entry.
539 * completion:
540 * a GtkEntryCompletion
541 * Returns:
542 * TRUE if the popup window will be resized to the width of
543 * the entry
544 * Since 2.8
546 public int getPopupSetWidth()
548 // gboolean gtk_entry_completion_get_popup_set_width (GtkEntryCompletion *completion);
549 return gtk_entry_completion_get_popup_set_width(gtkEntryCompletion);
553 * Sets whether the completion popup window will appear even if there is
554 * only a single match. You may want to set this to FALSE if you
555 * are using inline
556 * completion.
557 * completion:
558 * a GtkEntryCompletion
559 * popup_single_match:
560 * TRUE if the popup should appear even for a single
561 * match
562 * Since 2.8
564 public void setPopupSingleMatch(int popupSingleMatch)
566 // void gtk_entry_completion_set_popup_single_match (GtkEntryCompletion *completion, gboolean popup_single_match);
567 gtk_entry_completion_set_popup_single_match(gtkEntryCompletion, popupSingleMatch);
571 * Returns whether the completion popup window will appear even if there is
572 * only a single match.
573 * completion:
574 * a GtkEntryCompletion
575 * Returns:
576 * TRUE if the popup window will appear regardless of the
577 * number of matches.
578 * Since 2.8
579 * Property Details
580 * The "inline-completion" property
581 * "inline-completion" gboolean : Read / Write
582 * Determines whether the common prefix of the possible completions
583 * should be inserted automatically in the entry. Note that this
584 * requires text-column to be set, even if you are using a custom
585 * match function.
586 * Default value: FALSE
587 * Since 2.6
589 public int getPopupSingleMatch()
591 // gboolean gtk_entry_completion_get_popup_single_match (GtkEntryCompletion *completion);
592 return gtk_entry_completion_get_popup_single_match(gtkEntryCompletion);