CtkComboBoxText

CtkComboBoxText — A simple, text-only combo box

Functions

Types and Values

Object Hierarchy

    GObject
    ╰── GInitiallyUnowned
        ╰── CtkWidget
            ╰── CtkContainer
                ╰── CtkBin
                    ╰── CtkComboBox
                        ╰── CtkComboBoxText

Implemented Interfaces

CtkComboBoxText implements AtkImplementorIface, CtkBuildable, CtkCellLayout and CtkCellEditable.

Includes

#include <ctk/ctk.h>

Description

A CtkComboBoxText is a simple variant of CtkComboBox that hides the model-view complexity for simple text-only use cases.

To create a CtkComboBoxText, use ctk_combo_box_text_new() or ctk_combo_box_text_new_with_entry().

You can add items to a CtkComboBoxText with ctk_combo_box_text_append_text(), ctk_combo_box_text_insert_text() or ctk_combo_box_text_prepend_text() and remove options with ctk_combo_box_text_remove().

If the CtkComboBoxText contains an entry (via the “has-entry” property), its contents can be retrieved using ctk_combo_box_text_get_active_text(). The entry itself can be accessed by calling ctk_bin_get_child() on the combo box.

You should not call ctk_combo_box_set_model() or attempt to pack more cells into this combo box via its CtkCellLayout interface.

CtkComboBoxText as CtkBuildable

The CtkComboBoxText implementation of the CtkBuildable interface supports adding items directly using the <items> element and specifying <item> elements for each item. Each <item> element can specify the “id” corresponding to the appended text and also supports the regular translation attributes “translatable”, “context” and “comments”.

Here is a UI definition fragment specifying CtkComboBoxText items:

1
2
3
4
5
6
7
<object class="CtkComboBoxText">
  <items>
    <item translatable="yes" id="factory">Factory</item>
    <item translatable="yes" id="home">Home</item>
    <item translatable="yes" id="subway">Subway</item>
  </items>
</object>


CSS nodes

1
2
3
4
5
combobox
╰── box.linked
    ├── entry.combo
    ├── button.combo
    ╰── window.popup

CtkComboBoxText has a single CSS node with name combobox. It adds the style class .combo to the main CSS nodes of its entry and button children, and the .linked class to the node of its internal box.

Functions

ctk_combo_box_text_new ()

CtkWidget *
ctk_combo_box_text_new (void);

Creates a new CtkComboBoxText, which is a CtkComboBox just displaying strings.

Returns

A new CtkComboBoxText

Since: 2.24


ctk_combo_box_text_new_with_entry ()

CtkWidget *
ctk_combo_box_text_new_with_entry (void);

Creates a new CtkComboBoxText, which is a CtkComboBox just displaying strings. The combo box created by this function has an entry.

Returns

a new CtkComboBoxText

Since: 2.24


ctk_combo_box_text_append ()

void
ctk_combo_box_text_append (CtkComboBoxText *combo_box,
                           const gchar *id,
                           const gchar *text);

Appends text to the list of strings stored in combo_box . If id is non-NULL then it is used as the ID of the row.

This is the same as calling ctk_combo_box_text_insert() with a position of -1.

Parameters

combo_box

A CtkComboBoxText

 

id

a string ID for this value, or NULL.

[allow-none]

text

A string

 

Since: 2.24


ctk_combo_box_text_prepend ()

void
ctk_combo_box_text_prepend (CtkComboBoxText *combo_box,
                            const gchar *id,
                            const gchar *text);

Prepends text to the list of strings stored in combo_box . If id is non-NULL then it is used as the ID of the row.

This is the same as calling ctk_combo_box_text_insert() with a position of 0.

Parameters

combo_box

A CtkComboBox

 

id

a string ID for this value, or NULL.

[allow-none]

text

a string

 

Since: 2.24


ctk_combo_box_text_insert ()

void
ctk_combo_box_text_insert (CtkComboBoxText *combo_box,
                           gint position,
                           const gchar *id,
                           const gchar *text);

Inserts text at position in the list of strings stored in combo_box . If id is non-NULL then it is used as the ID of the row. See “id-column”.

If position is negative then text is appended.

Parameters

combo_box

A CtkComboBoxText

 

position

An index to insert text

 

id

a string ID for this value, or NULL.

[allow-none]

text

A string to display

 

Since: 3.0


ctk_combo_box_text_append_text ()

void
ctk_combo_box_text_append_text (CtkComboBoxText *combo_box,
                                const gchar *text);

Appends text to the list of strings stored in combo_box .

This is the same as calling ctk_combo_box_text_insert_text() with a position of -1.

Parameters

combo_box

A CtkComboBoxText

 

text

A string

 

Since: 2.24


ctk_combo_box_text_prepend_text ()

void
ctk_combo_box_text_prepend_text (CtkComboBoxText *combo_box,
                                 const gchar *text);

Prepends text to the list of strings stored in combo_box .

This is the same as calling ctk_combo_box_text_insert_text() with a position of 0.

Parameters

combo_box

A CtkComboBox

 

text

A string

 

Since: 2.24


ctk_combo_box_text_insert_text ()

void
ctk_combo_box_text_insert_text (CtkComboBoxText *combo_box,
                                gint position,
                                const gchar *text);

Inserts text at position in the list of strings stored in combo_box .

If position is negative then text is appended.

This is the same as calling ctk_combo_box_text_insert() with a NULL ID string.

Parameters

combo_box

A CtkComboBoxText

 

position

An index to insert text

 

text

A string

 

Since: 2.24


ctk_combo_box_text_remove ()

void
ctk_combo_box_text_remove (CtkComboBoxText *combo_box,
                           gint position);

Removes the string at position from combo_box .

Parameters

combo_box

A CtkComboBox

 

position

Index of the item to remove

 

Since: 2.24


ctk_combo_box_text_remove_all ()

void
ctk_combo_box_text_remove_all (CtkComboBoxText *combo_box);

Removes all the text entries from the combo box.

Parameters

combo_box

A CtkComboBoxText

 

Since: 3.0


ctk_combo_box_text_get_active_text ()

gchar *
ctk_combo_box_text_get_active_text (CtkComboBoxText *combo_box);

Returns the currently active string in combo_box , or NULL if none is selected. If combo_box contains an entry, this function will return its contents (which will not necessarily be an item from the list).

Parameters

combo_box

A CtkComboBoxText

 

Returns

a newly allocated string containing the currently active text. Must be freed with g_free().

[transfer full]

Since: 2.24

Types and Values

struct CtkComboBoxText

struct CtkComboBoxText;

See Also

CtkComboBox