gi-gtk4-4.0.12: Gtk 4.x bindings

Copyright | Will Thompson and Iñaki García Etxebarria
License | LGPL-2.1
Maintainer | Iñaki García Etxebarria
Safe Haskell | None
Language | Haskell2010

GI.Gtk.Interfaces.SelectionModel

Contents

- Exported types
- Methods
  - getSelection
  - getSelectionInRange
  - isSelected
  - selectAll
  - selectItem
  - selectRange
  - selectionChanged
  - setSelection
  - unselectAll
  - unselectItem
  - unselectRange
- Signals
  - selectionChanged

Description

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 `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 `selectionModelIsSelected`. When the selected state of one or more items changes, the model will emit the SelectionModel::selectionChanged signal by calling the `selectionModelSelectionChanged` 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 ListModel::itemsChanged signal are selected or not is up to the implementation.

Note that items added via ListModel::itemsChanged may already be selected and no SelectionModel::selectionChanged 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.

Synopsis

- newtype SelectionModel = SelectionModel (ManagedPtr SelectionModel)
- class (GObject o, IsDescendantOf SelectionModel o) => IsSelectionModel o
- toSelectionModel :: (MonadIO m, IsSelectionModel o) => o -> m SelectionModel
- selectionModelGetSelection :: (HasCallStack, MonadIO m, IsSelectionModel a) => a -> m Bitset
- selectionModelGetSelectionInRange :: (HasCallStack, MonadIO m, IsSelectionModel a) => a -> Word32 -> Word32 -> m Bitset
- selectionModelIsSelected :: (HasCallStack, MonadIO m, IsSelectionModel a) => a -> Word32 -> m Bool
- selectionModelSelectAll :: (HasCallStack, MonadIO m, IsSelectionModel a) => a -> m Bool
- selectionModelSelectItem :: (HasCallStack, MonadIO m, IsSelectionModel a) => a -> Word32 -> Bool -> m Bool
- selectionModelSelectRange :: (HasCallStack, MonadIO m, IsSelectionModel a) => a -> Word32 -> Word32 -> Bool -> m Bool
- selectionModelSelectionChanged :: (HasCallStack, MonadIO m, IsSelectionModel a) => a -> Word32 -> Word32 -> m ()
- selectionModelSetSelection :: (HasCallStack, MonadIO m, IsSelectionModel a) => a -> Bitset -> Bitset -> m Bool
- selectionModelUnselectAll :: (HasCallStack, MonadIO m, IsSelectionModel a) => a -> m Bool
- selectionModelUnselectItem :: (HasCallStack, MonadIO m, IsSelectionModel a) => a -> Word32 -> m Bool
- selectionModelUnselectRange :: (HasCallStack, MonadIO m, IsSelectionModel a) => a -> Word32 -> Word32 -> m Bool
- type SelectionModelSelectionChangedCallback = Word32 -> Word32 -> IO ()
- afterSelectionModelSelectionChanged :: (IsSelectionModel a, MonadIO m) => a -> ((?self :: a) => SelectionModelSelectionChangedCallback) -> m SignalHandlerId
- onSelectionModelSelectionChanged :: (IsSelectionModel a, MonadIO m) => a -> ((?self :: a) => SelectionModelSelectionChangedCallback) -> m SignalHandlerId

# Exported types

newtype SelectionModel Source #

Memory-managed wrapper type.

Constructors

SelectionModel (ManagedPtr SelectionModel) |

#### Instances

Instances details

Eq SelectionModel Source # |
Instance details Defined in GI.Gtk.Interfaces.SelectionModel Methods (==) :: SelectionModel -> SelectionModel -> Bool Source # (/=) :: SelectionModel -> SelectionModel -> Bool Source #
GObject SelectionModel Source # |
Instance details Defined in GI.Gtk.Interfaces.SelectionModel
ManagedPtrNewtype SelectionModel Source # |
Instance details Defined in GI.Gtk.Interfaces.SelectionModel Methods toManagedPtr :: SelectionModel -> ManagedPtr SelectionModel Source #
TypedObject SelectionModel Source # |
Instance details Defined in GI.Gtk.Interfaces.SelectionModel Methods glibType :: IO GType Source #
HasParentTypes SelectionModel Source # |
Instance details Defined in GI.Gtk.Interfaces.SelectionModel
IsGValue (Maybe SelectionModel) Source # | Convert `SelectionModel` to and from `GValue`. See `toGValue` and `fromGValue`.
Instance details Defined in GI.Gtk.Interfaces.SelectionModel Methods gvalueGType_ :: IO GType Source # gvalueSet_ :: Ptr GValue -> Maybe SelectionModel -> IO () Source # gvalueGet_ :: Ptr GValue -> IO (Maybe SelectionModel) Source #
type ParentTypes SelectionModel Source # |
Instance details Defined in GI.Gtk.Interfaces.SelectionModel type ParentTypes SelectionModel = '[ListModel, Object]

class (GObject o, IsDescendantOf SelectionModel o) => IsSelectionModel o Source #

Type class for types which can be safely cast to `SelectionModel`, for instance with `toSelectionModel`.

#### Instances

Instances details

(GObject o, IsDescendantOf SelectionModel o) => IsSelectionModel o Source # |
Instance details Defined in GI.Gtk.Interfaces.SelectionModel

toSelectionModel :: (MonadIO m, IsSelectionModel o) => o -> m SelectionModel Source #

Cast to `SelectionModel`, for types for which this is known to be safe. For general casts, use `castTo`.

# Methods

### Click to display all available methods, including inherited ones

Expand

#### Methods

bindProperty, bindPropertyFull, forceFloating, freezeNotify, getv, isFloating, isSelected, itemsChanged, notify, notifyByPspec, ref, refSink, runDispose, selectAll, selectItem, selectRange, selectionChanged, stealData, stealQdata, thawNotify, unref, unselectAll, unselectItem, unselectRange, watchClosure.

#### Getters

getData, getItem, getItemType, getNItems, getProperty, getQdata, getSelection, getSelectionInRange.

#### Setters

setData, setDataFull, setProperty, setSelection.

## getSelection

selectionModelGetSelection Source #

Arguments

:: (HasCallStack, MonadIO m, IsSelectionModel a) |
=> a | `model`: a `GtkSelectionModel`
-> m Bitset | 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.

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 `selectionModelIsSelected` or if you are only interested in a few, consider `selectionModelGetSelectionInRange`.

## getSelectionInRange

selectionModelGetSelectionInRange Source #

Arguments

:: (HasCallStack, MonadIO m, IsSelectionModel a) |
=> a | `model`: a `GtkSelectionModel`
-> Word32 | `position`: start of the queried range
-> Word32 | `nItems`: number of items in the queried range
-> m Bitset | Returns: A `GtkBitset` that matches the selection state for the given range with all other values being undefined. The bitset must not be modified.

Gets the set of selected items in a range.

This function is an optimization for `selectionModelGetSelection` when you are only interested in part of the model's selected state. A common use case is in response to the SelectionModel::selectionChanged signal.

## isSelected

selectionModelIsSelected Source #

Arguments

:: (HasCallStack, MonadIO m, IsSelectionModel a) |
=> a | `model`: a `GtkSelectionModel`
-> Word32 | `position`: the position of the item to query
-> m Bool | Returns: `True` if the item is selected

Checks if the given item is selected.

## selectAll

selectionModelSelectAll Source #

Arguments

:: (HasCallStack, MonadIO m, IsSelectionModel a) |
=> a | `model`: a `GtkSelectionModel`
-> m Bool | Returns: `True` if this action was supported and no fallback should be tried. This does not mean that all items are now selected.

Requests to select all items in the model.

## selectItem

selectionModelSelectItem Source #

Arguments

:: (HasCallStack, MonadIO m, IsSelectionModel a) |
=> a | `model`: a `GtkSelectionModel`
-> Word32 | `position`: the position of the item to select
-> Bool | `unselectRest`: whether previously selected items should be unselected
-> m Bool | Returns: `True` if this action was supported and no fallback should be tried. This does not mean the item was selected.

Requests to select an item in the model.

## selectRange

selectionModelSelectRange Source #

Arguments

:: (HasCallStack, MonadIO m, IsSelectionModel a) |
=> a | `model`: a `GtkSelectionModel`
-> Word32 | `position`: the first item to select
-> Word32 | `nItems`: the number of items to select
-> Bool | `unselectRest`: whether previously selected items should be unselected
-> m Bool | Returns: `True` if this action was supported and no fallback should be tried. This does not mean the range was selected.

Requests to select a range of items in the model.

## selectionChanged

selectionModelSelectionChanged Source #

Arguments

:: (HasCallStack, MonadIO m, IsSelectionModel a) |
=> a | `model`: a `GtkSelectionModel`
-> Word32 | `position`: the first changed item
-> Word32 | `nItems`: the number of changed items
-> m () |

Helper function for implementations of `GtkSelectionModel`.

Call this when the selection changes to emit the SelectionModel::selectionChanged signal.

## setSelection

selectionModelSetSelection Source #

Arguments

:: (HasCallStack, MonadIO m, IsSelectionModel a) |
=> a | `model`: a `GtkSelectionModel`
-> Bitset | `selected`: bitmask specifying if items should be selected or unselected
-> Bitset | `mask`: bitmask specifying which items should be updated
-> m Bool | 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.

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 code

    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.

## unselectAll

selectionModelUnselectAll Source #

Arguments

:: (HasCallStack, MonadIO m, IsSelectionModel a) |
=> a | `model`: a `GtkSelectionModel`
-> m Bool | Returns: `True` if this action was supported and no fallback should be tried. This does not mean that all items are now unselected.

Requests to unselect all items in the model.

## unselectItem

selectionModelUnselectItem Source #

Arguments

:: (HasCallStack, MonadIO m, IsSelectionModel a) |
=> a | `model`: a `GtkSelectionModel`
-> Word32 | `position`: the position of the item to unselect
-> m Bool | Returns: `True` if this action was supported and no fallback should be tried. This does not mean the item was unselected.

Requests to unselect an item in the model.

## unselectRange

selectionModelUnselectRange Source #

Arguments

:: (HasCallStack, MonadIO m, IsSelectionModel a) |
=> a | `model`: a `GtkSelectionModel`
-> Word32 | `position`: the first item to unselect
-> Word32 | `nItems`: the number of items to unselect
-> m Bool | Returns: `True` if this action was supported and no fallback should be tried. This does not mean the range was unselected.

Requests to unselect a range of items in the model.

# Signals

## selectionChanged

type SelectionModelSelectionChangedCallback Source #

Arguments

= Word32 | `position`: The first item that may have changed
-> Word32 | `nItems`: number of items with changes
-> IO () |

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.

afterSelectionModelSelectionChanged :: (IsSelectionModel a, MonadIO m) => a -> ((?self :: a) => SelectionModelSelectionChangedCallback) -> m SignalHandlerId Source #

Connect a signal handler for the selectionChanged signal, to be run after the default handler. When overloading is enabled, this is equivalent to

    after selectionModel #selectionChanged callback

By default the object invoking the signal is not passed to the callback. If you need to access it, you can use the implit `?self` parameter. Note that this requires activating the `ImplicitParams` GHC extension.

onSelectionModelSelectionChanged :: (IsSelectionModel a, MonadIO m) => a -> ((?self :: a) => SelectionModelSelectionChangedCallback) -> m SignalHandlerId Source #

Connect a signal handler for the selectionChanged signal, to be run before the default handler. When overloading is enabled, this is equivalent to

    on selectionModel #selectionChanged callback