Package ch.bailu.gtk.gtk
Class ComboBox
- All Implemented Interfaces:
PointerInterface
- Direct Known Subclasses:
ComboBoxText
A `GtkComboBox` is a widget that allows the user to choose from a list of
valid choices.
![An example GtkComboBox](combo-box.png)
The `GtkComboBox` displays the selected choice; when activated, the
`GtkComboBox` displays a popup which allows the user to make a new choice.
The `GtkComboBox` uses the model-view pattern; the list of valid choices
is specified in the form of a tree model, and the display of the choices
can be adapted to the data in the model by using cell renderers, as you
would in a tree view. This is possible since `GtkComboBox` implements the
[iface@Gtk.CellLayout] interface. The tree model holding the valid
choices is not restricted to a flat list, it can be a real tree, and the
popup will reflect the tree structure.
To allow the user to enter values not in the model, the
[property@Gtk.ComboBox:has-entry] property allows the `GtkComboBox` to
contain a [class@Gtk.Entry]. This entry can be accessed by calling
[method@Gtk.ComboBox.get_child] on the combo box.
For a simple list of textual choices, the model-view API of `GtkComboBox`
can be a bit overwhelming. In this case, [class@Gtk.ComboBoxText] offers
a simple alternative. Both `GtkComboBox` and `GtkComboBoxText` can contain
an entry.
## CSS nodes
```
combobox
├── box.linked
│ ╰── button.combo
│ ╰── box
│ ├── cellview
│ ╰── arrow
╰── window.popup
```
A normal combobox contains a box with the .linked class, a button
with the .combo class and inside those buttons, there are a cellview and
an arrow.
```
combobox
├── box.linked
│ ├── entry.combo
│ ╰── button.combo
│ ╰── box
│ ╰── arrow
╰── window.popup
```
A `GtkComboBox` with an entry has a single CSS node with name combobox.
It contains a box with the .linked class. That box contains an entry and
a button, both with the .combo class added. The button also contains another
node with name arrow.
# Accessibility
`GtkComboBox` uses the %GTK_ACCESSIBLE_ROLE_COMBO_BOX role.
valid choices.
![An example GtkComboBox](combo-box.png)
The `GtkComboBox` displays the selected choice; when activated, the
`GtkComboBox` displays a popup which allows the user to make a new choice.
The `GtkComboBox` uses the model-view pattern; the list of valid choices
is specified in the form of a tree model, and the display of the choices
can be adapted to the data in the model by using cell renderers, as you
would in a tree view. This is possible since `GtkComboBox` implements the
[iface@Gtk.CellLayout] interface. The tree model holding the valid
choices is not restricted to a flat list, it can be a real tree, and the
popup will reflect the tree structure.
To allow the user to enter values not in the model, the
[property@Gtk.ComboBox:has-entry] property allows the `GtkComboBox` to
contain a [class@Gtk.Entry]. This entry can be accessed by calling
[method@Gtk.ComboBox.get_child] on the combo box.
For a simple list of textual choices, the model-view API of `GtkComboBox`
can be a bit overwhelming. In this case, [class@Gtk.ComboBoxText] offers
a simple alternative. Both `GtkComboBox` and `GtkComboBoxText` can contain
an entry.
## CSS nodes
```
combobox
├── box.linked
│ ╰── button.combo
│ ╰── box
│ ├── cellview
│ ╰── arrow
╰── window.popup
```
A normal combobox contains a box with the .linked class, a button
with the .combo class and inside those buttons, there are a cellview and
an arrow.
```
combobox
├── box.linked
│ ├── entry.combo
│ ╰── button.combo
│ ╰── box
│ ╰── arrow
╰── window.popup
```
A `GtkComboBox` with an entry has a single CSS node with name combobox.
It contains a box with the .linked class. That box contains an entry and
a button, both with the .combo class added. The button also contains another
node with name arrow.
# Accessibility
`GtkComboBox` uses the %GTK_ACCESSIBLE_ROLE_COMBO_BOX role.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
static interface
static interface
static interface
static interface
static interface
static interface
Nested classes/interfaces inherited from class ch.bailu.gtk.gtk.Widget
Widget.OnDestroy, Widget.OnDirectionChanged, Widget.OnHide, Widget.OnKeynavFailed, Widget.OnMap, Widget.OnMnemonicActivate, Widget.OnMoveFocus, Widget.OnQueryTooltip, Widget.OnRealize, Widget.OnShow, Widget.OnStateFlagsChanged, Widget.OnTickCallback, Widget.OnUnmap, Widget.OnUnrealize
Nested classes/interfaces inherited from class ch.bailu.gtk.gobject.Object
Object.OnBindingTransformFunc, Object.OnDuplicateFunc, Object.OnNotify, Object.OnToggleNotify, Object.OnWeakNotify
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
static final String
Fields inherited from class ch.bailu.gtk.gtk.Widget
SIGNAL_ON_DESTROY, SIGNAL_ON_DIRECTION_CHANGED, SIGNAL_ON_HIDE, SIGNAL_ON_KEYNAV_FAILED, SIGNAL_ON_MAP, SIGNAL_ON_MNEMONIC_ACTIVATE, SIGNAL_ON_MOVE_FOCUS, SIGNAL_ON_QUERY_TOOLTIP, SIGNAL_ON_REALIZE, SIGNAL_ON_SHOW, SIGNAL_ON_STATE_FLAGS_CHANGED, SIGNAL_ON_UNMAP, SIGNAL_ON_UNREALIZE
Fields inherited from class ch.bailu.gtk.gobject.Object
SIGNAL_ON_NOTIFY
-
Constructor Summary
ConstructorDescriptionComboBox()
Creates a new empty `GtkComboBox`.ComboBox
(PointerContainer pointer) -
Method Summary
Modifier and TypeMethodDescriptionImplements interfaceAccessible
.Implements interfaceBuildable
.Implements interfaceCellEditable
.Implements interfaceCellLayout
.Implements interfaceConstraintTarget
.int
Returns the index of the currently active item.Returns the ID of the active row of @combo_box.boolean
getActiveIter
(TreeIter iter) Sets @iter to point to the currently active item.int
Returns whether the combo box sets the dropdown button
sensitive or not when there are no items in the model.getChild()
Gets the child widget of @combo_box.static ClassHandler
int
Returns the column which @combo_box is using to get the strings
from to display in the internal entry.boolean
Returns whether the combo box has an entry.int
Returns the column which @combo_box is using to get string IDs
for values from.static int
getModel()
Returns the `GtkTreeModel` of @combo_box.static long
static TypeSystem.TypeSize
boolean
Gets whether the popup uses a fixed width.static long
static TypeSystem.TypeSize
static ComboBox
Creates a new empty `GtkComboBox` with an entry.static ComboBox
Creates a new empty `GtkComboBox` with an entry and a model.static ComboBox
newWithModelComboBox
(TreeModel model) Creates a new `GtkComboBox` with a model.onActivate
(ComboBox.OnActivate signal) Connect to signal "activate".onChanged
(ComboBox.OnChanged signal) Connect to signal "changed".Connect to signal "format-entry-text".onMoveActive
(ComboBox.OnMoveActive signal) Connect to signal "move-active".onPopdown
(ComboBox.OnPopdown signal) Connect to signal "popdown".onPopup
(ComboBox.OnPopup signal) Connect to signal "popup".void
popdown()
Hides the menu or dropdown list of @combo_box.void
popup()
Pops up the menu or dropdown list of @combo_box.void
popupForDevice
(Device device) Pops up the menu of @combo_box.void
setActive
(int index_) Sets the active item of @combo_box to be the item at @index.boolean
setActiveId
(Str active_id) Changes the active row of @combo_box to the one that has an ID equal to
@active_id.boolean
setActiveId
(String active_id) Changes the active row of @combo_box to the one that has an ID equal to
@active_id.void
setActiveIter
(TreeIter iter) Sets the current active item to be the one referenced by @iter.void
setButtonSensitivity
(int sensitivity) Sets whether the dropdown button of the combo box should update
its sensitivity depending on the model contents.void
Sets the child widget of @combo_box.void
setEntryTextColumn
(int text_column) Sets the model column which @combo_box should use to get strings
from to be @text_column.void
setIdColumn
(int id_column) Sets the model column which @combo_box should use to get string IDs
for values from.void
Sets the model used by @combo_box to be @model.void
setPopupFixedWidth
(boolean fixed) Specifies whether the popup’s width should be a fixed width.void
setRowSeparatorFunc
(ComboBox.OnTreeViewRowSeparatorFunc func, Pointer data, ComboBox.OnDestroyNotify destroy) Sets the row separator function, which is used to determine
whether a row should be drawn as a separator.Methods inherited from class ch.bailu.gtk.gtk.Widget
actionSetEnabled, actionSetEnabled, activate, activateAction, activateAction, activateActionVariant, activateActionVariant, activateDefault, addController, addCssClass, addCssClass, addMnemonicLabel, addTickCallback, allocate, childFocus, computeBounds, computeExpand, computePoint, computeTransform, contains, createPangoContext, createPangoLayout, createPangoLayout, disposeTemplate, dragCheckThreshold, errorBell, getAllocatedBaseline, getAllocatedHeight, getAllocatedWidth, getAllocation, getAncestor, getCanFocus, getCanTarget, getChildVisible, getClipboard, getCssClasses, getCssName, getCursor, getDefaultDirection, getDirection, getDisplay, getFirstChild, getFocusable, getFocusChild, getFocusOnClick, getFontMap, getFontOptions, getFrameClock, getHalign, getHasTooltip, getHeight, getHexpand, getHexpandSet, getLastChild, getLayoutManager, getMapped, getMarginBottom, getMarginEnd, getMarginStart, getMarginTop, getName, getNative, getNextSibling, getOpacity, getOverflow, getPangoContext, getParent, getPreferredSize, getPrevSibling, getPrimaryClipboard, getRealized, getReceivesDefault, getRequestMode, getRoot, getScaleFactor, getSensitive, getSettings, getSize, getSizeRequest, getStateFlags, getStyleContext, getTemplateChild, getTemplateChild, getTooltipMarkup, getTooltipText, getValign, getVexpand, getVexpandSet, getVisible, getWidth, grabFocus, hasCssClass, hasCssClass, hasDefault, hasFocus, hasVisibleFocus, hide, inDestruction, initTemplate, insertActionGroup, insertActionGroup, insertAfter, insertBefore, isAncestor, isDrawable, isFocus, isSensitive, isVisible, keynavFailed, listMnemonicLabels, map, measure, mnemonicActivate, observeChildren, observeControllers, onDestroy, onDirectionChanged, onHide, onKeynavFailed, onMap, onMnemonicActivate, onMoveFocus, onQueryTooltip, onRealize, onShow, onStateFlagsChanged, onUnmap, onUnrealize, pick, queueAllocate, queueDraw, queueResize, realize, removeController, removeCssClass, removeCssClass, removeMnemonicLabel, removeTickCallback, setCanFocus, setCanTarget, setChildVisible, setCssClasses, setCursor, setCursorFromName, setCursorFromName, setDefaultDirection, setDirection, setFocusable, setFocusChild, setFocusOnClick, setFontMap, setFontOptions, setHalign, setHasTooltip, setHexpand, setHexpandSet, setLayoutManager, setMarginBottom, setMarginEnd, setMarginStart, setMarginTop, setName, setName, setOpacity, setOverflow, setParent, setReceivesDefault, setSensitive, setSizeRequest, setStateFlags, setTooltipMarkup, setTooltipMarkup, setTooltipText, setTooltipText, setValign, setVexpand, setVexpandSet, setVisible, shouldLayout, show, sizeAllocate, snapshotChild, triggerTooltipQuery, unmap, unparent, unrealize, unsetStateFlags
Methods inherited from class ch.bailu.gtk.gobject.Object
addToggleRef, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, disconnect, disconnect, dupData, dupData, dupQdata, forceFloating, freezeNotify, get, get, getData, getData, getProperty, getProperty, getQdata, interfaceFindProperty, interfaceInstallProperty, isFloating, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, replaceData, replaceData, replaceQdata, runDispose, set, set, setData, setData, setDataFull, setDataFull, setProperty, setProperty, setQdata, setQdataFull, stealData, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref
Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Field Details
-
SIGNAL_ON_ACTIVATE
- See Also:
-
SIGNAL_ON_CHANGED
- See Also:
-
SIGNAL_ON_FORMAT_ENTRY_TEXT
- See Also:
-
SIGNAL_ON_MOVE_ACTIVE
- See Also:
-
SIGNAL_ON_POPDOWN
- See Also:
-
SIGNAL_ON_POPUP
- See Also:
-
-
Constructor Details
-
ComboBox
-
ComboBox
public ComboBox()Creates a new empty `GtkComboBox`.
-
-
Method Details
-
getClassHandler
-
newWithEntryComboBox
Creates a new empty `GtkComboBox` with an entry.
In order to use a combo box with entry, you need to tell it
which column of the model contains the text for the entry
by calling [method@Gtk.ComboBox.set_entry_text_column].- Returns:
- A new `GtkComboBox`
-
newWithModelComboBox
Creates a new `GtkComboBox` with a model.- Parameters:
model
- a `GtkTreeModel`- Returns:
- A new `GtkComboBox`
-
newWithModelAndEntryComboBox
Creates a new empty `GtkComboBox` with an entry and a model.
See also [ctor@Gtk.ComboBox.new_with_entry].- Parameters:
model
- A `GtkTreeModel`- Returns:
- A new `GtkComboBox`
-
getActive
public int getActive()Returns the index of the currently active item.
If the model is a non-flat treemodel, and the active item is not
an immediate child of the root of the tree, this function returns
`gtk_tree_path_get_indices (path)[0]`, where `path` is the
[struct@Gtk.TreePath] of the active item.- Returns:
- An integer which is the index of the currently active item, or -1 if there’s no active item
-
getActiveId
Returns the ID of the active row of @combo_box.
This value is taken from the active row and the column specified
by the [property@Gtk.ComboBox:id-column] property of @combo_box
(see [method@Gtk.ComboBox.set_id_column]).
The returned value is an interned string which means that you can
compare the pointer by value to other interned strings and that you
must not free it.
If the [property@Gtk.ComboBox:id-column] property of @combo_box is
not set, or if no row is active, or if the active row has a %NULL
ID value, then %NULL is returned.- Returns:
- the ID of the active row
-
getActiveIter
Sets @iter to point to the currently active item.
If no item is active, @iter is left unchanged.- Parameters:
iter
- A `GtkTreeIter`- Returns:
- %TRUE if @iter was set, %FALSE otherwise
-
getButtonSensitivity
public int getButtonSensitivity()Returns whether the combo box sets the dropdown button
sensitive or not when there are no items in the model.- Returns:
- %GTK_SENSITIVITY_ON if the dropdown button is sensitive when the model is empty, %GTK_SENSITIVITY_OFF if the button is always insensitive or %GTK_SENSITIVITY_AUTO if it is only sensitive as long as the model has one item to be selected.
-
getChild
Gets the child widget of @combo_box.- Returns:
- the child widget of @combo_box
-
getEntryTextColumn
public int getEntryTextColumn()Returns the column which @combo_box is using to get the strings
from to display in the internal entry.- Returns:
- A column in the data source model of @combo_box.
-
getHasEntry
public boolean getHasEntry()Returns whether the combo box has an entry.- Returns:
- whether there is an entry in @combo_box.
-
getIdColumn
public int getIdColumn()Returns the column which @combo_box is using to get string IDs
for values from.- Returns:
- A column in the data source model of @combo_box.
-
getModel
Returns the `GtkTreeModel` of @combo_box.- Returns:
- A `GtkTreeModel` which was passed during construction.
-
getPopupFixedWidth
public boolean getPopupFixedWidth()Gets whether the popup uses a fixed width.- Returns:
- %TRUE if the popup uses a fixed width
-
popdown
public void popdown()Hides the menu or dropdown list of @combo_box.
This function is mostly intended for use by accessibility technologies;
applications should have little use for it. -
popup
public void popup()Pops up the menu or dropdown list of @combo_box.
This function is mostly intended for use by accessibility technologies;
applications should have little use for it.
Before calling this, @combo_box must be mapped, or nothing will happen. -
popupForDevice
Pops up the menu of @combo_box.
Note that currently this does not do anything with the device, as it was
previously only used for list-mode combo boxes, and those were removed
in GTK 4. However, it is retained in case similar functionality is added
back later.- Parameters:
device
- a `GdkDevice`
-
setActive
public void setActive(int index_) Sets the active item of @combo_box to be the item at @index.- Parameters:
index_
- An index in the model passed during construction, or -1 to have no active item
-
setActiveId
Changes the active row of @combo_box to the one that has an ID equal to
@active_id.
If @active_id is %NULL, the active row is unset. Rows having
a %NULL ID string cannot be made active by this function.
If the [property@Gtk.ComboBox:id-column] property of @combo_box is
unset or if no row has the given ID then the function does nothing
and returns %FALSE.- Parameters:
active_id
- the ID of the row to select- Returns:
- %TRUE if a row with a matching ID was found. If a %NULL @active_id was given to unset the active row, the function always returns %TRUE.
-
setActiveId
Changes the active row of @combo_box to the one that has an ID equal to
@active_id.
If @active_id is %NULL, the active row is unset. Rows having
a %NULL ID string cannot be made active by this function.
If the [property@Gtk.ComboBox:id-column] property of @combo_box is
unset or if no row has the given ID then the function does nothing
and returns %FALSE.- Parameters:
active_id
- the ID of the row to select- Returns:
- %TRUE if a row with a matching ID was found. If a %NULL @active_id was given to unset the active row, the function always returns %TRUE.
-
setActiveIter
Sets the current active item to be the one referenced by @iter.
If @iter is %NULL, the active item is unset.- Parameters:
iter
- The `GtkTreeIter`
-
setButtonSensitivity
public void setButtonSensitivity(int sensitivity) Sets whether the dropdown button of the combo box should update
its sensitivity depending on the model contents.- Parameters:
sensitivity
- specify the sensitivity of the dropdown button
-
setChild
Sets the child widget of @combo_box.- Parameters:
child
- the child widget
-
setEntryTextColumn
public void setEntryTextColumn(int text_column) Sets the model column which @combo_box should use to get strings
from to be @text_column.
For this column no separate
[class@Gtk.CellRenderer] is needed.
The column @text_column in the model of @combo_box must be of
type %G_TYPE_STRING.
This is only relevant if @combo_box has been created with
[property@Gtk.ComboBox:has-entry] as %TRUE.- Parameters:
text_column
- A column in @model to get the strings from for the internal entry
-
setIdColumn
public void setIdColumn(int id_column) Sets the model column which @combo_box should use to get string IDs
for values from.
The column @id_column in the model of @combo_box must be of type
%G_TYPE_STRING.- Parameters:
id_column
- A column in @model to get string IDs for values from
-
setModel
Sets the model used by @combo_box to be @model.
Will unset a previously set model (if applicable). If model is %NULL,
then it will unset the model.
Note that this function does not clear the cell renderers, you have to
call [method@Gtk.CellLayout.clear] yourself if you need to set up different
cell renderers for the new model.- Parameters:
model
- A `GtkTreeModel`
-
setPopupFixedWidth
public void setPopupFixedWidth(boolean fixed) Specifies whether the popup’s width should be a fixed width.
If @fixed is %TRUE, the popup's width is set to match the
allocated width of the combo box.- Parameters:
fixed
- whether to use a fixed popup width
-
setRowSeparatorFunc
public void setRowSeparatorFunc(ComboBox.OnTreeViewRowSeparatorFunc func, @Nullable Pointer data, ComboBox.OnDestroyNotify destroy) Sets the row separator function, which is used to determine
whether a row should be drawn as a separator.
If the row separator function is %NULL, no separators are drawn.
This is the default value.- Parameters:
func
- a `GtkTreeViewRowSeparatorFunc`data
- user data to pass to @funcdestroy
- destroy notifier for @data
-
onActivate
Connect to signal "activate".
SeeComboBox.OnActivate.onActivate()
for signal description.
FieldSIGNAL_ON_ACTIVATE
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onChanged
Connect to signal "changed".
SeeComboBox.OnChanged.onChanged()
for signal description.
FieldSIGNAL_ON_CHANGED
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onFormatEntryText
Connect to signal "format-entry-text".
SeeComboBox.OnFormatEntryText.onFormatEntryText(ch.bailu.gtk.type.Str)
for signal description.
FieldSIGNAL_ON_FORMAT_ENTRY_TEXT
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onMoveActive
Connect to signal "move-active".
SeeComboBox.OnMoveActive.onMoveActive(int)
for signal description.
FieldSIGNAL_ON_MOVE_ACTIVE
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onPopdown
Connect to signal "popdown".
SeeComboBox.OnPopdown.onPopdown()
for signal description.
FieldSIGNAL_ON_POPDOWN
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onPopup
Connect to signal "popup".
SeeComboBox.OnPopup.onPopup()
for signal description.
FieldSIGNAL_ON_POPUP
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
asAccessible
Implements interfaceAccessible
. Call this to get access to interface functions.- Overrides:
asAccessible
in classWidget
- Returns:
Accessible
-
asBuildable
Implements interfaceBuildable
. Call this to get access to interface functions.- Overrides:
asBuildable
in classWidget
- Returns:
Buildable
-
asCellEditable
Implements interfaceCellEditable
. Call this to get access to interface functions.- Returns:
CellEditable
-
asCellLayout
Implements interfaceCellLayout
. Call this to get access to interface functions.- Returns:
CellLayout
-
asConstraintTarget
Implements interfaceConstraintTarget
. Call this to get access to interface functions.- Overrides:
asConstraintTarget
in classWidget
- Returns:
ConstraintTarget
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-