Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: SelectionModel

[40:7] extends: object

An interface that adds 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, GtkSelectionModels 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.

Members

  • handleObj
  • lib
  • retainedCallbacks
  • signalHandlerNames
  • signalSetterHandlers

Methods

  • SelectionModel (Handle = null)

    Creates a new SelectionModel by wrapping a native handle or another wrapper.

    • @p Handle is the native handle or another wrapper whose handle to adopt.
  • toNativeHandle (Source)

    Normalizes a constructor argument into a raw pointer carrier. Accepts a raw NativeHandle, a raw NativeBuffer returned from fn.call(...), another generated wrapper exposing handle(), or null. Returns null when the argument carries no pointer.

    • @p Source is the raw handle, raw buffer, wrapper, or null.
    • @r A raw pointer carrier or null when no pointer is present.
  • getLib ()

    Returns the opened native library for this generated wrapper.

    • @r The opened native library.
  • handle ()

    Returns the wrapped NativeHandle.

    • @r The wrapped NativeHandle.
  • isNull ()

    Returns true when the wrapped handle is null.

    • @r A bool.
  • describe ()

    Returns a small string for debugging generated wrappers.

    • @r A string.
  • connectSignal (string Name, CallbackObj)

    Connects one generated callback wrapper to a named signal.

    • @p Name is the signal name.
    • @p CallbackObj is the generated callback wrapper to connect.
    • @r The connected handler id.
  • disconnectSignalHandler (int HandlerId)

    Disconnects one retained signal handler id.

    • @p HandlerId is the signal handler id to disconnect.
    • @r None.
  • setOnSelectionchanged (callback Fn, UserData = null)

    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.

    • @p Fn is the Aussom callback.
    • @p Fn is called with (SelectionModel Self, int Position, int N_items).
    • @p UserData is retained and passed through to the generated callback wrapper when provided.
    • @r The connected handler id.
  • get_selection ()

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

  • get_selection_in_range (int position, int n_items)

    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.

    • @p position is start of the queried range.
    • @p n_items is number of items in the queried range.
  • is_selected (int position)

    Checks if the given item is selected.

    • @p position is the position of the item to query.
  • select_all ()

    Requests to select all items in the model.

  • select_item (int position, bool unselect_rest)

    Requests to select an item in the model.

    • @p position is the position of the item to select.
    • @p unselect_rest is whether previously selected items should be unselected.
  • select_range (int position, int n_items, bool unselect_rest)

    Requests to select a range of items in the model.

    • @p position is the first item to select.
    • @p n_items is the number of items to select.
    • @p unselect_rest is whether previously selected items should be unselected.
  • selection_changed (int position, int n_items)

    Helper function for implementations of GtkSelectionModel. Call this when the selection changes to emit the [signal@Gtk.SelectionModel::selection-changed] signal.

    • @p position is the first changed item.
    • @p n_items is the number of changed items.
    • @r None.
  • set_selection (object selected, object mask)

    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.

    • @p selected is bitmask specifying if items should be selected or unselected.
    • @p mask is bitmask specifying which items should be updated.
  • unselect_all ()

    Requests to unselect all items in the model.

  • unselect_item (int position)

    Requests to unselect an item in the model.

    • @p position is the position of the item to unselect.
  • unselect_range (int position, int n_items)

    Requests to unselect a range of items in the model.

    • @p position is the first item to unselect.
    • @p n_items is the number of items to unselect.

class: SelectionModelSelectionchangedCallback

[320:7] extends: object

Generated low-level callback wrapper for GIR callback selection-changed.

Members

  • callbackObj
  • userFn
  • userData
  • hasUserData

Methods

  • SelectionModelSelectionchangedCallback (callback Fn, UserData = null)

    Creates one native callback wrapper. The wrapper owns a trampoline that converts native pointers into generated wrapper objects before invoking Fn.

    • @p Fn is the Aussom callback implementation.
    • @p UserData is retained and passed through to Fn on each invocation when provided.
  • trampoline (nativeSelf, position, n_items, nativeUserData)

    Internal trampoline. Converts native pointer arguments into generated wrapper instances, then invokes the user's callback.

  • callback ()

    Returns the wrapped NativeCallback.

  • handle ()

    Returns the callback as a NativeHandle.

  • close ()

    Closes the underlying NativeCallback.

  • isClosed ()

    Returns true when the callback has been closed.

class: SelectionModelMeta

[390:14] static extends: object

Generated metadata helpers for SelectionModel interface surfaces.

Methods

  • signals ()

    Returns signal metadata for SelectionModel.

    • @r A list.