gtk-0.12.2: Binding to the Gtk+ graphical user interface library.

Portability | portable (depends on GHC)
Stability | provisional
Maintainer | gtk2hs-users@lists.sourceforge.net

Graphics.UI.Gtk.ModelView.CustomStore

Contents

- The definition of a row-based store.

Description

Allows a custom data structure to be used with the `TreeView` and other widgets that follow the model-view-controller paradigm. The two models `Graphics.UI.Gtk.ModelView.ListStore.ListStore` and `Graphics.UI.Gtk.ModelView.TreeStore.TreeStore` are based on the `CustomStore`. Even if no application-specific tree model should be implemented, this module is relevant in that it provides the functions `customStoreSetColumn` and `customStoreGetRow` functions.

Synopsis

- data CustomStore private row
- data TreeModelFlags
  - = TreeModelItersPersist
  - | TreeModelListOnly
- data TreeModelIface row = TreeModelIface {
  - treeModelIfaceGetFlags :: IO [TreeModelFlags]
  - treeModelIfaceGetIter :: TreePath -> IO (Maybe TreeIter)
  - treeModelIfaceGetPath :: TreeIter -> IO TreePath
  - treeModelIfaceGetRow :: TreeIter -> IO row
  - treeModelIfaceIterNext :: TreeIter -> IO (Maybe TreeIter)
  - treeModelIfaceIterChildren :: Maybe TreeIter -> IO (Maybe TreeIter)
  - treeModelIfaceIterHasChild :: TreeIter -> IO Bool
  - treeModelIfaceIterNChildren :: Maybe TreeIter -> IO Int
  - treeModelIfaceIterNthChild :: Maybe TreeIter -> Int -> IO (Maybe TreeIter)
  - treeModelIfaceIterParent :: TreeIter -> IO (Maybe TreeIter)
  - treeModelIfaceRefNode :: TreeIter -> IO ()
  - treeModelIfaceUnrefNode :: TreeIter -> IO ()
  }
- data DragSourceIface model row = DragSourceIface {
  - treeDragSourceRowDraggable :: model row -> TreePath -> IO Bool
  - treeDragSourceDragDataGet :: model row -> TreePath -> SelectionDataM Bool
  - treeDragSourceDragDataDelete :: model row -> TreePath -> IO Bool
  }
- data DragDestIface model row = DragDestIface {
  - treeDragDestRowDropPossible :: model row -> TreePath -> SelectionDataM Bool
  - treeDragDestDragDataReceived :: model row -> TreePath -> SelectionDataM Bool
  }
- customStoreNew :: (TreeModelClass (model row), TypedTreeModelClass model) => private -> (CustomStore private row -> model row) -> TreeModelIface row -> Maybe (DragSourceIface model row) -> Maybe (DragDestIface model row) -> IO (model row)
- customStoreGetRow :: TypedTreeModelClass model => model row -> TreeIter -> IO row
- customStoreSetColumn :: TypedTreeModelClass model => model row -> ColumnId row ty -> (row -> ty) -> IO ()
- customStoreGetPrivate :: CustomStore private row -> private
- customStoreGetStamp :: CustomStore private row -> IO CInt
- customStoreInvalidateIters :: CustomStore private row -> IO ()

# The definition of a row-based store.

data CustomStore private row

A `CustomStore` is an instance of a Gtk+ `TreeModel` and can thus be used for any widget that stores data in a `TreeModel`. The user may either create an instance of a `CustomStore` or use one of the pre-defined models `Graphics.UI.Gtk.ModelView.ListStore.ListStore` of `Graphics.UI.Gtk.ModelView.TreeStore.TreeStore`.

Instances

GObjectClass (CustomStore private row) |
TreeModelClass (CustomStore private row) |

data TreeModelFlags

These flags indicate various properties of a `Graphics.UI.Gtk.ModelView.TreeModel.TreeModel`.

- If a model has `TreeModelItersPersist` set, iterators remain valid after a `Graphics.UI.Gtk.ModelView.TreeModel.TreeModel` signal was emitted.
- The `TreeModelListOnly` flag is set if the rows are arranged in a simple flat list. This is set in the `Graphics.UI.Gtk.ModelView.ListStore.ListStore` implementation.

Constructors

TreeModelItersPersist |
TreeModelListOnly |

Instances

Bounded TreeModelFlags |
Enum TreeModelFlags |
Flags TreeModelFlags |

data TreeModelIface row

The `TreeModelIface` structure contains all functions that are required to implement an application-specific `TreeModel`.

Constructors

TreeModelIface |
Fields treeModelIfaceGetFlags :: IO [TreeModelFlags] Return the flags that are valid for this model. treeModelIfaceGetIter :: TreePath -> IO (Maybe TreeIter) Convert an path into the tree into a more concise `TreeIter`. Return `Nothing` if the path does not exit. treeModelIfaceGetPath :: TreeIter -> IO TreePath Convert an iterator to a path. The iterator will always be valid. treeModelIfaceGetRow :: TreeIter -> IO row Retrieve a row at the given iterator. treeModelIfaceIterNext :: TreeIter -> IO (Maybe TreeIter) Advance the given iterator to the next node at the same level. Return `Nothing` if there is no next node at this level. treeModelIfaceIterChildren :: Maybe TreeIter -> IO (Maybe TreeIter) Advance the given iterator to the first child of this iterator. Return `Notihing` if the node at this iterator has no children. treeModelIfaceIterHasChild :: TreeIter -> IO Bool Check if the node at the given iterator has children. treeModelIfaceIterNChildren :: Maybe TreeIter -> IO Int Query the number of children the the node at the given iteratore has. treeModelIfaceIterNthChild :: Maybe TreeIter -> Int -> IO (Maybe TreeIter) Ask for an iterator to the `n`th child. Return `Nothing` if no such child exists. treeModelIfaceIterParent :: TreeIter -> IO (Maybe TreeIter) Ask for an iterator to the parent of the node. treeModelIfaceRefNode :: TreeIter -> IO () Increase a reference count for this node. A positive reference count indicates that the node is used (that is, most likely it is visible) in at least one widget. Tracking reference counts for nodes is optional but may be useful to infer when a given row can be discarded if it was retrieved from an external source. treeModelIfaceUnrefNode :: TreeIter -> IO () Decrement the reference count of the given node.

data DragSourceIface model row

A structure containing functions that enable this widget to be used as a source in drag-and-drop.

Constructors

DragSourceIface |
Fields treeDragSourceRowDraggable :: model row -> TreePath -> IO Bool Determine if the row at the given path is draggable. Return `False` if for some reason this row should not be dragged by the user. treeDragSourceDragDataGet :: model row -> TreePath -> SelectionDataM Bool Fill in the `SelectionDataM` structure with information on the given node using `Graphics.UI.Gtk.General.Selection.selectionDataSet`. treeDragSourceDragDataDelete :: model row -> TreePath -> IO Bool The widget is informed that the row at the given path should be deleted as the result of this drag.

data DragDestIface model row

A structure containing functions that enable this widget to be used as a target in drag-and-drop.

Constructors

DragDestIface |
Fields treeDragDestRowDropPossible :: model row -> TreePath -> SelectionDataM Bool Tell the drag-and-drop mechanism if the row can be dropped at the given path. treeDragDestDragDataReceived :: model row -> TreePath -> SelectionDataM Bool The data in the `SelectionDataM` structure should be read using `Graphics.UI.Gtk.General.Selection.selectionDataGet` and its information be used to insert a new row at the given path.

customStoreNew

Arguments

:: (TreeModelClass (model row), TypedTreeModelClass model) |
=> private | Any private data the store needs to store. Usually an `IORef`.
-> (CustomStore private row -> model row) |
-> TreeModelIface row | Functions necessary to implement the `TreeModel` interface.
-> Maybe (DragSourceIface model row) | Functions to enable this store to generate drag events.
-> Maybe (DragDestIface model row) | Functions to enable this store to receive drag events.
-> IO (model row) |

Create a new store that implements the `TreeModelIface` interface and optionally the `DragSourceIface` and the `DragDestIface`. If the latter two are set to `Nothing` a dummy interface is substituted that rejects every drag and drop.

customStoreGetRow :: TypedTreeModelClass model => model row -> TreeIter -> IO row

Extract a row of the given model at the given `TreeIter`.

customStoreSetColumn

Arguments

:: TypedTreeModelClass model |
=> model row | the store in which to allocate a new column
-> ColumnId row ty | the column that should be set
-> (row -> ty) | the function that sets the property
-> IO () |

Set or update a column mapping. This function should be used before the model is installed into a widget since the number of defined columns are only checked once by widgets.

customStoreGetPrivate :: CustomStore private row -> private

Return the private data stored in this `CustomStore`. The private data is meant as a container for the data stored in this model.

customStoreGetStamp :: CustomStore private row -> IO CInt

Query the current value of the stamp that is used to create `TreeIter` iterators. The stamp is compared each time a view accesses this store. If the stamp doesn't match, a warning is emitted. The stamp should be updated each time a the data in the model changes. The rationale is that a view should never use a stale `TreeIter`, i.e., one that refers to an old model.

customStoreInvalidateIters :: CustomStore private row -> IO ()

Create a new stamp. See `customStoreGetStamp`.