Copyright | Will Thompson Iñaki García Etxebarria and Jonas Platte |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria |
Safe Haskell | None |
Language | Haskell2010 |
SelectionModel
is an interface that extends the ListModel
interface by adding
support for selections. 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 mode 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 SelectionModel
supports a single boolean per row indicating if a row is selected
or not. This can be queried via selectionModelIsSelected
. When the selected
state of one or more rows changes, the model will emit the
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 itemsChanged signal are selected
or not is up to the implementation.
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.
Synopsis
- newtype SelectionModel = SelectionModel (ManagedPtr SelectionModel)
- noSelectionModel :: Maybe SelectionModel
- class (GObject o, IsDescendantOf SelectionModel o) => IsSelectionModel o
- toSelectionModel :: (MonadIO m, IsSelectionModel o) => o -> m SelectionModel
- selectionModelIsSelected :: (HasCallStack, MonadIO m, IsSelectionModel a) => a -> Word32 -> m Bool
- selectionModelQueryRange :: (HasCallStack, MonadIO m, IsSelectionModel a) => a -> Word32 -> m (Word32, Word32, 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 ()
- 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 C_SelectionModelSelectionChangedCallback = Ptr () -> Word32 -> Word32 -> Ptr () -> IO ()
- type SelectionModelSelectionChangedCallback = Word32 -> Word32 -> IO ()
- afterSelectionModelSelectionChanged :: (IsSelectionModel a, MonadIO m) => a -> SelectionModelSelectionChangedCallback -> m SignalHandlerId
- genClosure_SelectionModelSelectionChanged :: MonadIO m => SelectionModelSelectionChangedCallback -> m (GClosure C_SelectionModelSelectionChangedCallback)
- mk_SelectionModelSelectionChangedCallback :: C_SelectionModelSelectionChangedCallback -> IO (FunPtr C_SelectionModelSelectionChangedCallback)
- noSelectionModelSelectionChangedCallback :: Maybe SelectionModelSelectionChangedCallback
- onSelectionModelSelectionChanged :: (IsSelectionModel a, MonadIO m) => a -> SelectionModelSelectionChangedCallback -> m SignalHandlerId
- wrap_SelectionModelSelectionChangedCallback :: SelectionModelSelectionChangedCallback -> C_SelectionModelSelectionChangedCallback
Exported types
newtype SelectionModel Source #
Memory-managed wrapper type.
Instances
Eq SelectionModel Source # | |
Defined in GI.Gtk.Interfaces.SelectionModel (==) :: SelectionModel -> SelectionModel -> Bool # (/=) :: SelectionModel -> SelectionModel -> Bool # | |
IsGValue SelectionModel Source # | Convert |
Defined in GI.Gtk.Interfaces.SelectionModel toGValue :: SelectionModel -> IO GValue # fromGValue :: GValue -> IO SelectionModel # | |
GObject SelectionModel Source # | |
Defined in GI.Gtk.Interfaces.SelectionModel gobjectType :: IO GType # | |
HasParentTypes SelectionModel Source # | |
Defined in GI.Gtk.Interfaces.SelectionModel | |
type ParentTypes SelectionModel Source # | |
Defined in GI.Gtk.Interfaces.SelectionModel |
noSelectionModel :: Maybe SelectionModel Source #
A convenience alias for Nothing
:: Maybe
SelectionModel
.
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
(GObject o, IsDescendantOf SelectionModel o) => IsSelectionModel o Source # | |
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
Overloaded methods
isSelected
selectionModelIsSelected Source #
:: (HasCallStack, MonadIO m, IsSelectionModel a) | |
=> a |
|
-> Word32 |
|
-> m Bool | Returns: |
Checks if the given item is selected.
queryRange
selectionModelQueryRange Source #
:: (HasCallStack, MonadIO m, IsSelectionModel a) | |
=> a |
|
-> Word32 |
|
-> m (Word32, Word32, Bool) |
This function allows to query the selection status of multiple elements at once. It is passed a position and returns a range of elements of uniform selection status.
If position
is greater than the number of items in model
, nItems
is set to 0.
Otherwise the returned range is guaranteed to include the passed-in position, so
nItems
will be >= 1.
Positions directly adjacent to the returned range may have the same selection status as the returned range.
This is an optimization function to make iterating over a model faster when few items are selected. However, it is valid behavior for implementations to use a naive implementation that only ever returns a single element.
selectAll
selectionModelSelectAll Source #
:: (HasCallStack, MonadIO m, IsSelectionModel a) | |
=> a |
|
-> m Bool |
Requests to select all items in the model.
selectItem
selectionModelSelectItem Source #
:: (HasCallStack, MonadIO m, IsSelectionModel a) | |
=> a |
|
-> Word32 |
|
-> Bool |
|
-> m Bool |
Requests to select an item in the model.
selectRange
selectionModelSelectRange Source #
:: (HasCallStack, MonadIO m, IsSelectionModel a) | |
=> a |
|
-> Word32 |
|
-> Word32 |
|
-> Bool |
|
-> m Bool |
Requests to select a range of items in the model.
selectionChanged
selectionModelSelectionChanged Source #
:: (HasCallStack, MonadIO m, IsSelectionModel a) | |
=> a |
|
-> Word32 |
|
-> Word32 |
|
-> m () |
Helper function for implementations of SelectionModel
.
Call this when a the selection changes to emit the selectionChanged
signal.
unselectAll
selectionModelUnselectAll Source #
:: (HasCallStack, MonadIO m, IsSelectionModel a) | |
=> a |
|
-> m Bool |
Requests to unselect all items in the model.
unselectItem
selectionModelUnselectItem Source #
:: (HasCallStack, MonadIO m, IsSelectionModel a) | |
=> a |
|
-> Word32 |
|
-> m Bool |
Requests to unselect an item in the model.
unselectRange
selectionModelUnselectRange Source #
:: (HasCallStack, MonadIO m, IsSelectionModel a) | |
=> a |
|
-> Word32 |
|
-> Word32 |
|
-> m Bool |
Requests to unselect a range of items in the model.
Signals
selectionChanged
type C_SelectionModelSelectionChangedCallback = Ptr () -> Word32 -> Word32 -> Ptr () -> IO () Source #
Type for the callback on the (unwrapped) C side.
type SelectionModelSelectionChangedCallback Source #
= Word32 |
|
-> Word32 |
|
-> 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 -> 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
genClosure_SelectionModelSelectionChanged :: MonadIO m => SelectionModelSelectionChangedCallback -> m (GClosure C_SelectionModelSelectionChangedCallback) Source #
Wrap the callback into a GClosure
.
mk_SelectionModelSelectionChangedCallback :: C_SelectionModelSelectionChangedCallback -> IO (FunPtr C_SelectionModelSelectionChangedCallback) Source #
Generate a function pointer callable from C code, from a C_SelectionModelSelectionChangedCallback
.
noSelectionModelSelectionChangedCallback :: Maybe SelectionModelSelectionChangedCallback Source #
A convenience synonym for
.Nothing
:: Maybe
SelectionModelSelectionChangedCallback
onSelectionModelSelectionChanged :: (IsSelectionModel a, MonadIO m) => 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