## GtkEntryCompletion

GtkEntryCompletion — completion functionality for GtkEntry

## Synopsis

    #include <gtk/gtk.h>

    struct      GtkEntryCompletion;
    gboolean    (*GtkEntryCompletionMatchFunc)  (GtkEntryCompletion *completion,
                                                 const gchar *key,
                                                 GtkTreeIter *iter,
                                                 gpointer user_data);
    GtkEntryCompletion* gtk_entry_completion_new
                                                (void);
    GtkWidget*  gtk_entry_completion_get_entry  (GtkEntryCompletion *completion);
    void        gtk_entry_completion_set_model  (GtkEntryCompletion *completion,
                                                 GtkTreeModel *model);
    GtkTreeModel* gtk_entry_completion_get_model
                                                (GtkEntryCompletion *completion);
    void        gtk_entry_completion_set_match_func
                                                (GtkEntryCompletion *completion,
                                                 GtkEntryCompletionMatchFunc func,
                                                 gpointer func_data,
                                                 GDestroyNotify func_notify);
    void        gtk_entry_completion_set_minimum_key_length
                                                (GtkEntryCompletion *completion,
                                                 gint length);
    gint        gtk_entry_completion_get_minimum_key_length
                                                (GtkEntryCompletion *completion);
    void        gtk_entry_completion_complete   (GtkEntryCompletion *completion);
    void        gtk_entry_completion_insert_action_text
                                                (GtkEntryCompletion *completion,
                                                 gint index,
                                                 const gchar *text);
    void        gtk_entry_completion_insert_action_markup
                                                (GtkEntryCompletion *completion,
                                                 gint index,
                                                 const gchar *markup);
    void        gtk_entry_completion_delete_action
                                                (GtkEntryCompletion *completion,
                                                 gint index);
    void        gtk_entry_completion_set_text_column
                                                (GtkEntryCompletion *completion,
                                                 gint column);

## Object Hierarchy

      GObject
       +----GtkEntryCompletion

## Implemented Interfaces

GtkEntryCompletion implements GtkCellLayout.

## Properties

      "minimum-key-length"   gint                 : Read / Write
      "model"                GtkTreeModel         : Read / Write

## Signal Prototypes

    "action-activated"
                void        user_function      (GtkEntryCompletion *widget,
                                                gint index,
                                                gpointer user_data);
    "match-selected"
                gboolean    user_function      (GtkEntryCompletion *widget,
                                                GtkTreeModel *model,
                                                GtkTreeIter *iter,
                                                gpointer user_data);

## 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.

## Details

### struct GtkEntryCompletion

    struct GtkEntryCompletion;

The GtkEntryCompletion struct contains only private data.

### 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`.

`completion` : | the GtkEntryCompletion
`key` : | the string to match
`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.

Since 2.4

### gtk_entry_completion_get_entry ()

    GtkWidget*  gtk_entry_completion_get_entry  (GtkEntryCompletion *completion);

Gets the entry `completion` has been attached to.

`completion` : | A GtkEntryCompletion.
Returns : | The entry `completion` has been attached to.

Since 2.4

### 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.

`completion` : | A GtkEntryCompletion.
`model` : | The GtkTreeModel.

Since 2.4

### 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.

`completion` : | A GtkEntryCompletion.
Returns : | A GtkTreeModel, or `NULL` if none is currently being used.

Since 2.4

### 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.

`completion` : | A GtkEntryCompletion.
`func` : | The GtkEntryCompletionMatchFunc to use.
`func_data` : | The user data for `func`.
`func_notify` : | Destroy notifier for `func_data`.

Since 2.4.

### 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).

`completion` : | A GtkEntryCompletion.
`length` : | The minimum length of the key in order to start completing.

Since 2.4

### 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`.

`completion` : | A GtkEntryCompletion.
Returns : | The currently used minimum key length.

Since 2.4

### 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.

`completion` : | A GtkEntryCompletion.

Since 2.4

### 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()`.

`completion` : | A GtkEntryCompletion.
`index` : | The index of the item to insert.
`text` : | Text of the item to insert.

Since 2.4

### 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`.

`completion` : | A GtkEntryCompletion.
`index` : | The index of the item to insert.
`markup` : | Markup of the item to insert.

Since 2.4

### 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.

`completion` : | A GtkEntryCompletion.
`index` : | The index of the item to Delete.

Since 2.4

### 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.

`completion` : | A GtkEntryCompletion.
`column` : | The column in the model of `completion` to get strings from.

Since 2.4

## Properties

"`minimum-key-length`" (gint : Read / Write) | Minimum length of the search key in order to look up matches.
"`model`" (GtkTreeModel : Read / Write) | The model to find matches in.

## Signals

### The "action-activated" signal

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

The ::action-activated signal is emitted when an action is activated.

`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.

### The "match-selected" signal

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

The ::match-selected signal is 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`.

`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