## GtkEntryCompletion GtkEntryCompletion — Completion functionality for GtkEntry |

## Functions

gboolean | (*GtkEntryCompletionMatchFunc) ()
GtkEntryCompletion * | gtk_entry_completion_new ()
GtkEntryCompletion * | gtk_entry_completion_new_with_area ()
GtkWidget * | gtk_entry_completion_get_entry ()
void | gtk_entry_completion_set_model ()
GtkTreeModel * | gtk_entry_completion_get_model ()
void | gtk_entry_completion_set_match_func ()
void | gtk_entry_completion_set_minimum_key_length ()
gint | gtk_entry_completion_get_minimum_key_length ()
gchar * | gtk_entry_completion_compute_prefix ()
void | gtk_entry_completion_complete ()
const gchar * | gtk_entry_completion_get_completion_prefix ()
void | gtk_entry_completion_insert_prefix ()
void | gtk_entry_completion_insert_action_text ()
void | gtk_entry_completion_insert_action_markup ()
void | gtk_entry_completion_delete_action ()
void | gtk_entry_completion_set_text_column ()
gint | gtk_entry_completion_get_text_column ()
void | gtk_entry_completion_set_inline_completion ()
gboolean | gtk_entry_completion_get_inline_completion ()
void | gtk_entry_completion_set_inline_selection ()
gboolean | gtk_entry_completion_get_inline_selection ()
void | gtk_entry_completion_set_popup_completion ()
gboolean | gtk_entry_completion_get_popup_completion ()
void | gtk_entry_completion_set_popup_set_width ()
gboolean | gtk_entry_completion_get_popup_set_width ()
void | gtk_entry_completion_set_popup_single_match ()
gboolean | gtk_entry_completion_get_popup_single_match ()

## Properties

GtkCellArea * | cell-area | Read / Write / Construct Only
gboolean | inline-completion | Read / Write
gboolean | inline-selection | Read / Write
gint | minimum-key-length | Read / Write
GtkTreeModel * | model | Read / Write
gboolean | popup-completion | Read / Write
gboolean | popup-set-width | Read / Write
gboolean | popup-single-match | Read / Write
gint | text-column | Read / Write

## Signals

void | action-activated | Run Last
gboolean | cursor-on-match | Run Last
gboolean | insert-prefix | Run Last
gboolean | match-selected | Run Last
void | no-matches | Run Last

## Types and Values

| GtkEntryCompletion

## Object Hierarchy

        GObject
        ╰── GtkEntryCompletion

## Implemented Interfaces

GtkEntryCompletion implements GtkCellLayout and GtkBuildable.

## Includes

    #include <gtk/gtk.h>

## Description

GtkEntryCompletion is an auxiliary object to be used in conjunction with GtkEntry to provide the completion functionality. It implements the GtkCellLayout interface, to allow the user to add extra cells to the GtkTreeView with completion matches.

“Completion functionality” means that when the user modifies the text in the entry, GtkEntryCompletion checks which rows in the model match the current content of the entry, and displays a list of matches. By default, the matching is done by comparing the entry text case-insensitively against the text column of the model (see `gtk_entry_completion_set_text_column()`), but this can be overridden with a custom match function (see `gtk_entry_completion_set_match_func()`).

When the user selects a completion, the content of the entry is updated. By default, the content of the entry is replaced by the text column of the model, but this can be overridden by connecting to the “match-selected” signal and updating the entry in the signal handler. Note that you should return `TRUE` from the signal handler to suppress the default behaviour.

To add completion functionality to an entry, use `gtk_entry_set_completion()`.

In addition to regular completion matches, which will be inserted into the entry when they are selected, GtkEntryCompletion also allows to display “actions” in the popup window. Their appearance is similar to menuitems, to differentiate them clearly from completion strings. When an action is selected, the “action-activated” signal is emitted.

GtkEntryCompletion uses a GtkTreeModelFilter model to represent the subset of the entire model that is currently matching. While the GtkEntryCompletion signals “match-selected” and “cursor-on-match” take the original model and an iter pointing to that model as arguments, other callbacks and signals (such as GtkCellLayoutDataFuncs or “apply-attributes”) will generally take the filter model as argument. As long as you are only calling `gtk_tree_model_get()`, this will make no difference to you. If for some reason, you need the original model, use `gtk_tree_model_filter_get_model()`. Don’t forget to use `gtk_tree_model_filter_convert_iter_to_child_iter()` to obtain a matching iter.

## Functions

### GtkEntryCompletionMatchFunc ()

    gboolean
    (*GtkEntryCompletionMatchFunc) (GtkEntryCompletion *completion,
                                    const gchar *key,
                                    GtkTreeIter *iter,
                                    gpointer user_data);

A function which decides whether the row indicated by `iter` matches a given `key` , and should be displayed as a possible completion for `key` . Note that `key` is normalized and case-folded (see `g_utf8_normalize()` and `g_utf8_casefold()`). If this is not appropriate, match functions have access to the unmodified key via `gtk_editable_get_text (GTK_EDITABLE (`gtk_entry_completion_get_entry()`))`.

#### Parameters

completion | the GtkEntryCompletion |
key | the string to match, normalized and case-folded |
iter | a GtkTreeIter indicating the row to match |
user_data | user data given to `gtk_entry_completion_set_match_func()` |

#### Returns

`TRUE` if `iter` should be displayed as a possible completion for `key`

### gtk_entry_completion_new ()

    GtkEntryCompletion *
    gtk_entry_completion_new (void);

Creates a new GtkEntryCompletion object.

#### Returns

A newly created GtkEntryCompletion object

### gtk_entry_completion_new_with_area ()

    GtkEntryCompletion *
    gtk_entry_completion_new_with_area (GtkCellArea *area);

Creates a new GtkEntryCompletion object using the specified `area` to layout cells in the underlying GtkTreeViewColumn for the drop-down menu.

#### Parameters

area | the GtkCellArea used to layout cells |

#### Returns

A newly created GtkEntryCompletion object

### gtk_entry_completion_get_entry ()

    GtkWidget *
    gtk_entry_completion_get_entry (GtkEntryCompletion *completion);

Gets the entry `completion` has been attached to.

#### Parameters

completion | a GtkEntryCompletion |

#### Returns

The entry `completion` has been attached to.

[transfer none]

### gtk_entry_completion_set_model ()

    void
    gtk_entry_completion_set_model (GtkEntryCompletion *completion,
                                    GtkTreeModel *model);

Sets the model for a GtkEntryCompletion. If `completion` already has a model set, it will remove it before setting the new model. If model is `NULL`, then it will unset the model.

#### Parameters

completion | a GtkEntryCompletion |
model | the GtkTreeModel. | [allow-none]

### gtk_entry_completion_get_model ()

    GtkTreeModel *
    gtk_entry_completion_get_model (GtkEntryCompletion *completion);

Returns the model the GtkEntryCompletion is using as data source. Returns `NULL` if the model is unset.

#### Parameters

completion | a GtkEntryCompletion |

#### Returns

A GtkTreeModel, or `NULL` if none is currently being used.

[nullable][transfer none]

### gtk_entry_completion_set_match_func ()

    void
    gtk_entry_completion_set_match_func (GtkEntryCompletion *completion,
                                         GtkEntryCompletionMatchFunc func,
                                         gpointer func_data,
                                         GDestroyNotify func_notify);

Sets the match function for `completion` to be `func` . The match function is used to determine if a row should or should not be in the completion list.

#### Parameters

completion | a GtkEntryCompletion |
func | the GtkEntryCompletionMatchFunc to use |
func_data | user data for `func` |
func_notify | destroy notify for `func_data` . |

### gtk_entry_completion_set_minimum_key_length ()

    void
    gtk_entry_completion_set_minimum_key_length
                                   (GtkEntryCompletion *completion,
                                    gint length);

Requires the length of the search key for `completion` to be at least `length` . This is useful for long lists, where completing using a small key takes a lot of time and will come up with meaningless results anyway (ie, a too large dataset).

#### Parameters

completion | a GtkEntryCompletion |
length | the minimum length of the key in order to start completing |

### gtk_entry_completion_get_minimum_key_length ()

    gint
    gtk_entry_completion_get_minimum_key_length
                                   (GtkEntryCompletion *completion);

Returns the minimum key length as set for `completion` .

#### Parameters

completion | a GtkEntryCompletion |

#### Returns

The currently used minimum key length

### gtk_entry_completion_compute_prefix ()

    gchar *
    gtk_entry_completion_compute_prefix (GtkEntryCompletion *completion,
                                         const char *key);

Computes the common prefix that is shared by all rows in `completion` that start with `key` . If no row matches `key` , `NULL` will be returned. Note that a text column must have been set for this function to work, see `gtk_entry_completion_set_text_column()` for details.

#### Parameters

completion | the entry completion |
key | The text to complete for |

#### Returns

The common prefix all rows starting with `key` or `NULL` if no row matches `key` .

[nullable][transfer full]

### gtk_entry_completion_complete ()

    void
    gtk_entry_completion_complete (GtkEntryCompletion *completion);

Requests a completion operation, or in other words a refiltering of the current list with completions, using the current key. The completion list view will be updated accordingly.

#### Parameters

completion | a GtkEntryCompletion |

### gtk_entry_completion_get_completion_prefix ()

    const gchar *
    gtk_entry_completion_get_completion_prefix
                                   (GtkEntryCompletion *completion);

Get the original text entered by the user that triggered the completion or `NULL` if there’s no completion ongoing.

#### Parameters

completion | a GtkEntryCompletion |

#### Returns

the prefix for the current completion

### gtk_entry_completion_insert_prefix ()

    void
    gtk_entry_completion_insert_prefix (GtkEntryCompletion *completion);

Requests a prefix insertion.

#### Parameters

completion | a GtkEntryCompletion |

### gtk_entry_completion_insert_action_text ()

    void
    gtk_entry_completion_insert_action_text
                                   (GtkEntryCompletion *completion,
                                    gint index_,
                                    const gchar *text);

Inserts an action in `completion` ’s action item list at position `index_` with text `text` . If you want the action item to have markup, use `gtk_entry_completion_insert_action_markup()`.

Note that `index_` is a relative position in the list of actions and the position of an action can change when deleting a different action.

#### Parameters

completion | a GtkEntryCompletion |
index_ | the index of the item to insert |
text | text of the item to insert |

### gtk_entry_completion_insert_action_markup ()

    void
    gtk_entry_completion_insert_action_markup
                                   (GtkEntryCompletion *completion,
                                    gint index_,
                                    const gchar *markup);

Inserts an action in `completion` ’s action item list at position `index_` with markup `markup` .

#### Parameters

completion | a GtkEntryCompletion |
index_ | the index of the item to insert |
markup | markup of the item to insert |

### gtk_entry_completion_delete_action ()

    void
    gtk_entry_completion_delete_action (GtkEntryCompletion *completion,
                                        gint index_);

Deletes the action at `index_` from `completion` ’s action list.

Note that `index_` is a relative position and the position of an action may have changed since it was inserted.

#### Parameters

completion | a GtkEntryCompletion |
index_ | the index of the item to delete |

### gtk_entry_completion_set_text_column ()

    void
    gtk_entry_completion_set_text_column (GtkEntryCompletion *completion,
                                          gint column);

Convenience function for setting up the most used case of this code: a completion list with just strings. This function will set up `completion` to have a list displaying all (and just) strings in the completion list, and to get those strings from `column` in the model of `completion` .

This functions creates and adds a GtkCellRendererText for the selected column. If you need to set the text column, but don't want the cell renderer, use `g_object_set()` to set the “text-column” property directly.

#### Parameters

completion | a GtkEntryCompletion |
column | the column in the model of `completion` to get strings from |

### gtk_entry_completion_get_text_column ()

    gint
    gtk_entry_completion_get_text_column (GtkEntryCompletion *completion);

Returns the column in the model of `completion` to get strings from.

#### Parameters

completion | a GtkEntryCompletion |

#### Returns

the column containing the strings

### gtk_entry_completion_set_inline_completion ()

    void
    gtk_entry_completion_set_inline_completion
                                   (GtkEntryCompletion *completion,
                                    gboolean inline_completion);

Sets whether the common prefix of the possible completions should be automatically inserted in the entry.

#### Parameters

completion | a GtkEntryCompletion |
inline_completion | `TRUE` to do inline completion |

### gtk_entry_completion_get_inline_completion ()

    gboolean
    gtk_entry_completion_get_inline_completion
                                   (GtkEntryCompletion *completion);

Returns whether the common prefix of the possible completions should be automatically inserted in the entry.

#### Parameters

completion | a GtkEntryCompletion |

#### Returns

`TRUE` if inline completion is turned on

### gtk_entry_completion_set_inline_selection ()

    void
    gtk_entry_completion_set_inline_selection
                                   (GtkEntryCompletion *completion,
                                    gboolean inline_selection);

Sets whether it is possible to cycle through the possible completions inside the entry.

#### Parameters

completion | a GtkEntryCompletion |
inline_selection | `TRUE` to do inline selection |

### gtk_entry_completion_get_inline_selection ()

    gboolean
    gtk_entry_completion_get_inline_selection
                                   (GtkEntryCompletion *completion);

Returns `TRUE` if inline-selection mode is turned on.

#### Parameters

completion | a GtkEntryCompletion |

#### Returns

`TRUE` if inline-selection mode is on

### gtk_entry_completion_set_popup_completion ()

    void
    gtk_entry_completion_set_popup_completion
                                   (GtkEntryCompletion *completion,
                                    gboolean popup_completion);

Sets whether the completions should be presented in a popup window.

#### Parameters

completion | a GtkEntryCompletion |
popup_completion | `TRUE` to do popup completion |

### gtk_entry_completion_get_popup_completion ()

    gboolean
    gtk_entry_completion_get_popup_completion
                                   (GtkEntryCompletion *completion);

Returns whether the completions should be presented in a popup window.

#### Parameters

completion | a GtkEntryCompletion |

#### Returns

`TRUE` if popup completion is turned on

### gtk_entry_completion_set_popup_set_width ()

    void
    gtk_entry_completion_set_popup_set_width
                                   (GtkEntryCompletion *completion,
                                    gboolean popup_set_width);

Sets whether the completion popup window will be resized to be the same width as the entry.

#### Parameters

completion | a GtkEntryCompletion |
popup_set_width | `TRUE` to make the width of the popup the same as the entry |

### gtk_entry_completion_get_popup_set_width ()

    gboolean
    gtk_entry_completion_get_popup_set_width
                                   (GtkEntryCompletion *completion);

Returns whether the completion popup window will be resized to the width of the entry.

#### Parameters

completion | a GtkEntryCompletion |

#### Returns

`TRUE` if the popup window will be resized to the width of the entry

### gtk_entry_completion_set_popup_single_match ()

    void
    gtk_entry_completion_set_popup_single_match
                                   (GtkEntryCompletion *completion,
                                    gboolean popup_single_match);

Sets whether the completion popup window will appear even if there is only a single match. You may want to set this to `FALSE` if you are using inline completion.

#### Parameters

completion | a GtkEntryCompletion |
popup_single_match | `TRUE` if the popup should appear even for a single match |

### gtk_entry_completion_get_popup_single_match ()

    gboolean
    gtk_entry_completion_get_popup_single_match
                                   (GtkEntryCompletion *completion);

Returns whether the completion popup window will appear even if there is only a single match.

#### Parameters

completion | a GtkEntryCompletion |

#### Returns

`TRUE` if the popup window will appear regardless of the number of matches

## Types and Values

### GtkEntryCompletion

    typedef struct _GtkEntryCompletion GtkEntryCompletion;

## Property Details

### The `“cell-area”` property

      “cell-area”                GtkCellArea *

The GtkCellArea used to layout cell renderers in the treeview column.

If no area is specified when creating the entry completion with `gtk_entry_completion_new_with_area()` a horizontally oriented GtkCellAreaBox will be used.

Owner: GtkEntryCompletion

Flags: Read / Write / Construct Only

### The `“inline-completion”` property

      “inline-completion”        gboolean

Determines whether the common prefix of the possible completions should be inserted automatically in the entry. Note that this requires text-column to be set, even if you are using a custom match function.

Owner: GtkEntryCompletion

Flags: Read / Write

Default value: FALSE

### The `“inline-selection”` property

      “inline-selection”         gboolean

Determines whether the possible completions on the popup will appear in the entry as you navigate through them.

Owner: GtkEntryCompletion

Flags: Read / Write

Default value: FALSE

### The `“minimum-key-length”` property

      “minimum-key-length”       gint

Minimum length of the search key in order to look up matches.

Owner: GtkEntryCompletion

Flags: Read / Write

Allowed values: >= 0

Default value: 1

### The `“model”` property

      “model”                    GtkTreeModel *

The model to find matches in.

Owner: GtkEntryCompletion

Flags: Read / Write

### The `“popup-completion”` property

      “popup-completion”         gboolean

Determines whether the possible completions should be shown in a popup window.

Owner: GtkEntryCompletion

Flags: Read / Write

Default value: TRUE

### The `“popup-set-width”` property

      “popup-set-width”          gboolean

Determines whether the completions popup window will be resized to the width of the entry.

Owner: GtkEntryCompletion

Flags: Read / Write

Default value: TRUE

### The `“popup-single-match”` property

      “popup-single-match”       gboolean

Determines whether the completions popup window will shown for a single possible completion. You probably want to set this to `FALSE` if you are using inline completion.

Owner: GtkEntryCompletion

Flags: Read / Write

Default value: TRUE

### The `“text-column”` property

      “text-column”              gint

The column of the model containing the strings. Note that the strings must be UTF-8.

Owner: GtkEntryCompletion

Flags: Read / Write

Allowed values: >= -1

Default value: -1

## Signal Details

### The `“action-activated”` signal

    void
    user_function (GtkEntryCompletion *widget,
                   gint                index,
                   gpointer            user_data)

Gets emitted when an action is activated.

#### Parameters

widget | the object which received the signal |
index | the index of the activated action |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

### The `“cursor-on-match”` signal

    gboolean
    user_function (GtkEntryCompletion *widget,
                   GtkTreeModel       *model,
                   GtkTreeIter        *iter,
                   gpointer            user_data)

Gets emitted when a match from the cursor is on a match of the list. The default behaviour is to replace the contents of the entry with the contents of the text column in the row pointed to by `iter` .

Note that `model` is the model that was passed to `gtk_entry_completion_set_model()`.

#### Parameters

widget | the object which received the signal |
model | the GtkTreeModel containing the matches |
iter | a GtkTreeIter positioned at the selected match |
user_data | user data set when the signal handler was connected. |

#### Returns

`TRUE` if the signal has been handled

Flags: Run Last

### The `“insert-prefix”` signal

    gboolean
    user_function (GtkEntryCompletion *widget,
                   gchar              *prefix,
                   gpointer            user_data)

Gets emitted when the inline autocompletion is triggered. The default behaviour is to make the entry display the whole prefix and select the newly inserted part.

Applications may connect to this signal in order to insert only a smaller part of the `prefix` into the entry - e.g. the entry used in the GtkFileChooser inserts only the part of the prefix up to the next '/'.

#### Parameters

widget | the object which received the signal |
prefix | the common prefix of all possible completions |
user_data | user data set when the signal handler was connected. |

#### Returns

`TRUE` if the signal has been handled

Flags: Run Last

### The `“match-selected”` signal

    gboolean
    user_function (GtkEntryCompletion *widget,
                   GtkTreeModel       *model,
                   GtkTreeIter        *iter,
                   gpointer            user_data)

Gets emitted when a match from the list is selected. The default behaviour is to replace the contents of the entry with the contents of the text column in the row pointed to by `iter` .

Note that `model` is the model that was passed to `gtk_entry_completion_set_model()`.

#### Parameters

widget | the object which received the signal |
model | the GtkTreeModel containing the matches |
iter | a GtkTreeIter positioned at the selected match |
user_data | user data set when the signal handler was connected. |

#### Returns

`TRUE` if the signal has been handled

Flags: Run Last

### The `“no-matches”` signal

    void
    user_function (GtkEntryCompletion *widget,
                   gpointer            user_data)

Gets emitted when the filter model has zero number of rows in completion_complete method. (In other words when GtkEntryCompletion is out of suggestions)

#### Parameters

widget | the object which received the signal |
user_data | user data set when the signal handler was connected. |

Flags: Run Last