Package ch.bailu.gtk.gtk
Class SelectionModel
java.lang.Object
ch.bailu.gtk.type.Type
ch.bailu.gtk.type.Pointer
ch.bailu.gtk.gobject.Object
ch.bailu.gtk.type.Interface
ch.bailu.gtk.gtk.SelectionModel
- All Implemented Interfaces:
PointerInterface
`GtkSelectionModel` is an interface that add support for selection to list models.
This support is then used by widgets using list models to add the ability
to select and unselect various items.
GTK provides default implementations of the most common selection modes such
as [class@Gtk.SingleSelection], so you will only need to implement this
interface if you want detailed control about how selections should be handled.
A `GtkSelectionModel` supports a single boolean per item indicating if an item is
selected or not. This can be queried via [method@Gtk.SelectionModel.is_selected].
When the selected state of one or more items changes, the model will emit the
[signal@Gtk.SelectionModel::selection-changed] signal by calling the
[method@Gtk.SelectionModel.selection_changed] function. The positions given
in that signal may have their selection state changed, though that is not a
requirement. If new items added to the model via the
[signal@Gio.ListModel::items-changed] signal are selected or not is up to the
implementation.
Note that items added via [signal@Gio.ListModel::items-changed] may already
be selected and no [signal@Gtk.SelectionModel::selection-changed] will be
emitted for them. So to track which items are selected, it is necessary to
listen to both signals.
Additionally, the interface can expose functionality to select and unselect
items. If these functions are implemented, GTK's list widgets will allow users
to select and unselect items. However, `GtkSelectionModel`s are free to only
implement them partially or not at all. In that case the widgets will not
support the unimplemented operations.
When selecting or unselecting is supported by a model, the return values of
the selection functions do *not* indicate if selection or unselection happened.
They are only meant to indicate complete failure, like when this mode of
selecting is not supported by the model.
Selections may happen asynchronously, so the only reliable way to find out
when an item was selected is to listen to the signals that indicate selection.
This support is then used by widgets using list models to add the ability
to select and unselect various items.
GTK provides default implementations of the most common selection modes such
as [class@Gtk.SingleSelection], so you will only need to implement this
interface if you want detailed control about how selections should be handled.
A `GtkSelectionModel` supports a single boolean per item indicating if an item is
selected or not. This can be queried via [method@Gtk.SelectionModel.is_selected].
When the selected state of one or more items changes, the model will emit the
[signal@Gtk.SelectionModel::selection-changed] signal by calling the
[method@Gtk.SelectionModel.selection_changed] function. The positions given
in that signal may have their selection state changed, though that is not a
requirement. If new items added to the model via the
[signal@Gio.ListModel::items-changed] signal are selected or not is up to the
implementation.
Note that items added via [signal@Gio.ListModel::items-changed] may already
be selected and no [signal@Gtk.SelectionModel::selection-changed] will be
emitted for them. So to track which items are selected, it is necessary to
listen to both signals.
Additionally, the interface can expose functionality to select and unselect
items. If these functions are implemented, GTK's list widgets will allow users
to select and unselect items. However, `GtkSelectionModel`s are free to only
implement them partially or not at all. In that case the widgets will not
support the unimplemented operations.
When selecting or unselecting is supported by a model, the return values of
the selection functions do *not* indicate if selection or unselection happened.
They are only meant to indicate complete failure, like when this mode of
selecting is not supported by the model.
Selections may happen asynchronously, so the only reliable way to find out
when an item was selected is to listen to the signals that indicate selection.
-
Nested Class Summary
Nested classes/interfaces inherited from class ch.bailu.gtk.gobject.Object
Object.OnBindingTransformFunc, Object.OnDestroyNotify, Object.OnDuplicateFunc, Object.OnNotify, Object.OnToggleNotify, Object.OnWeakNotify
-
Field Summary
Fields inherited from class ch.bailu.gtk.gobject.Object
SIGNAL_ON_NOTIFY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic ClassHandler
static int
static long
static TypeSystem.TypeSize
Gets the set containing all currently selected items in the model.getSelectionInRange
(int position, int n_items) Gets the set of selected items in a range.static long
static TypeSystem.TypeSize
boolean
isSelected
(int position) Checks if the given item is selected.Connect to signal "selection-changed".boolean
Requests to select all items in the model.void
selectionChanged
(int position, int n_items) Helper function for implementations of `GtkSelectionModel`.boolean
selectItem
(int position, boolean unselect_rest) Requests to select an item in the model.boolean
selectRange
(int position, int n_items, boolean unselect_rest) Requests to select a range of items in the model.boolean
setSelection
(Bitset selected, Bitset mask) Make selection changes.boolean
Requests to unselect all items in the model.boolean
unselectItem
(int position) Requests to unselect an item in the model.boolean
unselectRange
(int position, int n_items) Requests to unselect a range of items in the model.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_SELECTION_CHANGED
- See Also:
-
-
Constructor Details
-
SelectionModel
-
-
Method Details
-
getClassHandler
-
getSelection
Gets the set containing all currently selected items in the model.
This function may be slow, so if you are only interested in single item,
consider using [method@Gtk.SelectionModel.is_selected] or if you are only
interested in a few, consider [method@Gtk.SelectionModel.get_selection_in_range].- Returns:
- a `GtkBitset` containing all the values currently selected in @model. If no items are selected, the bitset is empty. The bitset must not be modified.
-
getSelectionInRange
Gets the set of selected items in a range.
This function is an optimization for
[method@Gtk.SelectionModel.get_selection] when you are only
interested in part of the model's selected state. A common use
case is in response to the [signal@Gtk.SelectionModel::selection-changed]
signal.- Parameters:
position
- start of the queired rangen_items
- number of items in the queried range- Returns:
- A `GtkBitset` that matches the selection state for the given range with all other values being undefined. The bitset must not be modified.
-
isSelected
public boolean isSelected(int position) Checks if the given item is selected.- Parameters:
position
- the position of the item to query- Returns:
- %TRUE if the item is selected
-
selectAll
public boolean selectAll()Requests to select all items in the model.- Returns:
- %TRUE if this action was supported and no fallback should be tried. This does not mean that all items are now selected.
-
selectItem
public boolean selectItem(int position, boolean unselect_rest) Requests to select an item in the model.- Parameters:
position
- the position of the item to selectunselect_rest
- whether previously selected items should be unselected- Returns:
- %TRUE if this action was supported and no fallback should be tried. This does not mean the item was selected.
-
selectRange
public boolean selectRange(int position, int n_items, boolean unselect_rest) Requests to select a range of items in the model.- Parameters:
position
- the first item to selectn_items
- the number of items to selectunselect_rest
- whether previously selected items should be unselected- Returns:
- %TRUE if this action was supported and no fallback should be tried. This does not mean the range was selected.
-
selectionChanged
public void selectionChanged(int position, int n_items) Helper function for implementations of `GtkSelectionModel`.
Call this when a the selection changes to emit the
[signal@Gtk.SelectionModel::selection-changed] signal.- Parameters:
position
- the first changed itemn_items
- the number of changed items
-
setSelection
Make selection changes.
This is the most advanced selection updating method that allows
the most fine-grained control over selection changes. If you can,
you should try the simpler versions, as implementations are more
likely to implement support for those.
Requests that the selection state of all positions set in @mask
be updated to the respective value in the @selected bitmask.
In pseudocode, it would look something like this:
```c
for (i = 0; i < n_items; i++)
{
// don't change values not in the mask
if (!gtk_bitset_contains (mask, i))
continue;
if (gtk_bitset_contains (selected, i))
select_item (i);
else
unselect_item (i);
}
gtk_selection_model_selection_changed (model,
first_changed_item,
n_changed_items);
```
@mask and @selected must not be modified. They may refer to the
same bitset, which would mean that every item in the set should
be selected.- Parameters:
selected
- bitmask specifying if items should be selected or unselectedmask
- bitmask specifying which items should be updated- Returns:
- %TRUE if this action was supported and no fallback should be tried. This does not mean that all items were updated according to the inputs.
-
unselectAll
public boolean unselectAll()Requests to unselect all items in the model.- Returns:
- %TRUE if this action was supported and no fallback should be tried. This does not mean that all items are now unselected.
-
unselectItem
public boolean unselectItem(int position) Requests to unselect an item in the model.- Parameters:
position
- the position of the item to unselect- Returns:
- %TRUE if this action was supported and no fallback should be tried. This does not mean the item was unselected.
-
unselectRange
public boolean unselectRange(int position, int n_items) Requests to unselect a range of items in the model.- Parameters:
position
- the first item to unselectn_items
- the number of items to unselect- Returns:
- %TRUE if this action was supported and no fallback should be tried. This does not mean the range was unselected.
-
onSelectionChanged
Connect to signal "selection-changed".
SeeSelectionModel.OnSelectionChanged.onSelectionChanged(int, int)
for signal description.
FieldSIGNAL_ON_SELECTION_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.
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-