From: Axel S. <si...@co...> - 2008-10-05 10:25:09
|
Sun Oct 5 06:06:34 EDT 2008 A....@ke... * Add TreeRowReference back to the TreeList directory. hunk ./Makefile.am 545 + gtk/Graphics/UI/Gtk/TreeList/TreeRowReference.chs.pp \ addfile ./gtk/Graphics/UI/Gtk/TreeList/TreeRowReference.chs.pp hunk ./gtk/Graphics/UI/Gtk/TreeList/TreeRowReference.chs.pp 1 +-- -*-haskell-*- +-- GIMP Toolkit (GTK) Class TreeRowReference +-- +-- Author : Duncan Coutts +-- +-- Created: 14 April 2005 +-- +-- Copyright (C) 2005 Axel Simon, Duncan Coutts +-- +-- This library is free software; you can redistribute it and/or +-- modify it under the terms of the GNU Lesser General Public +-- License as published by the Free Software Foundation; either +-- version 2.1 of the License, or (at your option) any later version. +-- +-- This library is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +-- Lesser General Public License for more details. +-- +-- | +-- Maintainer : gtk...@li... +-- Stability : provisional +-- Portability : portable (depends on GHC) +-- +-- A persistent index into a tree model. +-- +module Graphics.UI.Gtk.TreeList.TreeRowReference ( +-- * Detail +-- +-- | A 'RowReference' is an index into a +-- 'Graphics.UI.Gtk.TreeList.TreeModel.TreeModel' that is persistent even if +-- rows are inserted, deleted or reordered. +-- + +-- * Types + TreeRowReference, + +-- * Constructors + treeRowReferenceNew, + +-- * Methods + treeRowReferenceGetPath, + treeRowReferenceValid, + ) where + +import Control.Monad (liftM) + +import System.Glib.FFI +{#import Graphics.UI.Gtk.Types#} +{#import Graphics.UI.Gtk.TreeList.TreePath#} + +{# context lib="gtk" prefix="gtk" #} + +-- | Tree Row Reference : like a 'TreePath' it points to a subtree or node, but +-- it is persistent. It identifies the same node (so long as it exists) even +-- when items are added, removed, or reordered. +-- +{#pointer * TreeRowReference foreign newtype#} + +-------------------- +-- Constructors + +-- | Creates a row reference based on a path. This reference will keep pointing +-- to the node pointed to by the given path, so long as it exists. Returns @Nothing@ if there is no node at the given path. +-- +treeRowReferenceNew :: TreeModelClass self => self + -> TreePath + -> IO (Maybe TreeRowReference) +treeRowReferenceNew self path = withTreePath path $ \path -> do + rowRefPtr <- [_$_] + {#call unsafe gtk_tree_row_reference_new#} (toTreeModel self) path + if rowRefPtr==nullPtr then return Nothing else + liftM (Just . TreeRowReference) $ + newForeignPtr rowRefPtr tree_row_reference_free + +-------------------- +-- Methods + +-- | Returns a path that the row reference currently points to. +-- +-- * The returned path may be the empty list if the reference was invalid. +-- +treeRowReferenceGetPath :: TreeRowReference -> IO TreePath +treeRowReferenceGetPath ref = + {# call unsafe tree_row_reference_get_path #} ref + >>= fromTreePath -- path must be freed + +-- | Returns True if the reference refers to a current valid path. +-- +treeRowReferenceValid :: TreeRowReference -> IO Bool +treeRowReferenceValid self = + liftM toBool $ + {# call unsafe tree_row_reference_valid #} + self + +foreign import ccall unsafe ">k_tree_row_reference_free" + tree_row_reference_free :: FinalizerPtr TreeRowReference + |