SelectionModelProtocol
public protocol SelectionModelProtocol : ListModelProtocol
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 [classGtk.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 [methodGtk.SelectionModel.is_selected
].
When the selected state of one or more items changes, the model will emit the
[signalGtk.SelectionModel::selection-changed
] signal by calling the
[methodGtk.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 items-changed
signal
are selected or not is up to the implementation.
Note that items added via items-changed
may already be selected and no
[Gtk.SelectionModelselection-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.
The SelectionModelProtocol
protocol exposes the methods and properties of an underlying GtkSelectionModel
instance.
The default implementation of these can be found in the protocol extension below.
For a concrete class that implements these methods and properties, see SelectionModel
.
Alternatively, use SelectionModelRef
as a lighweight, unowned
reference if you already have an instance you just want to use.
-
Untyped pointer to the underlying
GtkSelectionModel
instance.Declaration
Swift
var ptr: UnsafeMutableRawPointer! { get }
-
selection_model_ptr
Default implementationTyped pointer to the underlying
GtkSelectionModel
instance.Default Implementation
Return the stored, untyped pointer as a typed pointer to the
GtkSelectionModel
instance.Declaration
Swift
var selection_model_ptr: UnsafeMutablePointer<GtkSelectionModel>! { get }
-
Required Initialiser for types conforming to
SelectionModelProtocol
Declaration
Swift
init(raw: UnsafeMutableRawPointer)
-
connect(signal:
Extension methodflags: handler: ) Connect a Swift signal handler to the given, typed
SelectionModelSignalName
signalDeclaration
Swift
@discardableResult @inlinable func connect(signal s: SelectionModelSignalName, flags f: ConnectFlags = ConnectFlags(0), handler h: @escaping SignalHandler) -> Int
Parameters
signal
The signal to connect
flags
The connection flags to use
data
A pointer to user data to provide to the callback
destroyData
A
GClosureNotify
C function to destroy the data pointed to byuserData
handler
The Swift signal handler (function or callback) to invoke on the given signal
Return Value
The signal handler ID (always greater than 0 for successful connections)
-
connect(signal:
Extension methodflags: data: destroyData: signalHandler: ) Connect a C signal handler to the given, typed
SelectionModelSignalName
signalDeclaration
Swift
@discardableResult @inlinable func connect(signal s: SelectionModelSignalName, flags f: ConnectFlags = ConnectFlags(0), data userData: gpointer!, destroyData destructor: GClosureNotify? = nil, signalHandler h: @escaping GCallback) -> Int
Parameters
signal
The signal to connect
flags
The connection flags to use
data
A pointer to user data to provide to the callback
destroyData
A
GClosureNotify
C function to destroy the data pointed to byuserData
signalHandler
The C function to be called on the given signal
Return Value
The signal handler ID (always greater than 0 for successful connections)
-
onSelectionChanged(flags:
Extension methodhandler: ) Emitted when the selection state of some of the items in
model
changes.Note that this signal does not specify the new selection state of the items, they need to be queried manually. It is also not necessary for a model to change the selection state of any of the items in the selection model, though it would be rather useless to emit such a signal.
Note
This represents the underlyingselection-changed
signalDeclaration
Swift
@discardableResult @inlinable func onSelectionChanged(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: SelectionModelRef, _ position: UInt, _ nItems: UInt) -> Void) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
position
The first item that may have changed
nItems
number of items with changes
handler
The signal handler to call Run the given callback whenever the
selectionChanged
signal is emitted -
selectionChangedSignal
Extension methodTyped
selection-changed
signal for using theconnect(signal:)
methodsDeclaration
Swift
static var selectionChangedSignal: SelectionModelSignalName { get }
-
getSelection()
Extension methodGets 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 [methodGtk.SelectionModel.get_selection_in_range
].Declaration
Swift
@inlinable func getSelection() -> BitsetRef!
-
getSelectionInRange(position:
Extension methodnItems: ) 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 [signalGtk.SelectionModel::selection-changed
] signal.Declaration
Swift
@inlinable func getSelectionInRange(position: Int, nItems: Int) -> BitsetRef!
-
isSelected(position:
Extension method) Checks if the given item is selected.
Declaration
Swift
@inlinable func isSelected(position: Int) -> Bool
-
selectAll()
Extension methodRequests to select all items in the model.
Declaration
Swift
@inlinable func selectAll() -> Bool
-
selectItem(position:
Extension methodunselectRest: ) Requests to select an item in the model.
Declaration
Swift
@inlinable func selectItem(position: Int, unselectRest: Bool) -> Bool
-
selectRange(position:
Extension methodnItems: unselectRest: ) Requests to select a range of items in the model.
Declaration
Swift
@inlinable func selectRange(position: Int, nItems: Int, unselectRest: Bool) -> Bool
-
selectionChanged(position:
Extension methodnItems: ) Helper function for implementations of
GtkSelectionModel
.Call this when a the selection changes to emit the [signal
Gtk.SelectionModel::selection-changed
] signal.Declaration
Swift
@inlinable func selectionChanged(position: Int, nItems: Int)
-
setSelection(selected:
Extension methodmask: ) 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 theselected
bitmask.In pseudocode, it would look something like this:
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
andselected
must not be modified. They may refer to the same bitset, which would mean that every item in the set should be selected.Declaration
Swift
@inlinable func setSelection<BitsetT>(selected: BitsetT, mask: BitsetT) -> Bool where BitsetT : BitsetProtocol
-
unselectAll()
Extension methodRequests to unselect all items in the model.
Declaration
Swift
@inlinable func unselectAll() -> Bool
-
unselectItem(position:
Extension method) Requests to unselect an item in the model.
Declaration
Swift
@inlinable func unselectItem(position: Int) -> Bool
-
unselectRange(position:
Extension methodnItems: ) Requests to unselect a range of items in the model.
Declaration
Swift
@inlinable func unselectRange(position: Int, nItems: Int) -> Bool
-
selection
Extension methodGets 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 [methodGtk.SelectionModel.get_selection_in_range
].Declaration
Swift
@inlinable var selection: BitsetRef! { get }