{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MonoLocalBinds #-}
module Data.GI.Gtk.ModelView.TreeModel (
module Export,
ColumnId,
makeColumnIdInt,
makeColumnIdBool,
makeColumnIdString,
makeColumnIdPixbuf,
invalidColumnId,
columnIdToNumber,
stringToTreePath,
treeModelGetValue,
treeModelGetIter
) where
import Prelude ()
import Prelude.Compat
import Data.Int (Int32)
import Data.Text (Text)
import Data.GI.Base.GValue (GValue(..), fromGValue, get_object)
import Data.GI.Base.ManagedPtr (withManagedPtr, newObject)
import Foreign.Ptr (Ptr)
import GI.GdkPixbuf.Objects.Pixbuf (Pixbuf(..))
import GI.Gtk.Structs.TreeIter (TreeIter)
import GI.Gtk.Interfaces.TreeModel as Export hiding (treeModelGetValue, treeModelGetIter)
import qualified GI.Gtk.Interfaces.TreeModel as GI (treeModelGetValue, treeModelGetIter)
import Data.GI.Gtk.ModelView.Types (stringToTreePath,
ColumnId(..),
ColumnAccess(..))
import Control.Monad.IO.Class (MonadIO)
import GI.Gtk.Structs.TreePath (treePathGetDepth, TreePath(..))
import Data.Maybe (fromJust)
makeColumnIdInt :: Int32 -> ColumnId row Int32
makeColumnIdInt :: forall row. Int32 -> ColumnId row Int32
makeColumnIdInt = (GValue -> IO Int32)
-> ((row -> Int32) -> ColumnAccess row)
-> Int32
-> ColumnId row Int32
forall row ty.
(GValue -> IO ty)
-> ((row -> ty) -> ColumnAccess row) -> Int32 -> ColumnId row ty
ColumnId GValue -> IO Int32
forall a (m :: * -> *). (IsGValue a, MonadIO m) => GValue -> m a
fromGValue (row -> Int32) -> ColumnAccess row
forall row. (row -> Int32) -> ColumnAccess row
CAInt
makeColumnIdBool :: Int32 -> ColumnId row Bool
makeColumnIdBool :: forall row. Int32 -> ColumnId row Bool
makeColumnIdBool = (GValue -> IO Bool)
-> ((row -> Bool) -> ColumnAccess row)
-> Int32
-> ColumnId row Bool
forall row ty.
(GValue -> IO ty)
-> ((row -> ty) -> ColumnAccess row) -> Int32 -> ColumnId row ty
ColumnId GValue -> IO Bool
forall a (m :: * -> *). (IsGValue a, MonadIO m) => GValue -> m a
fromGValue (row -> Bool) -> ColumnAccess row
forall row. (row -> Bool) -> ColumnAccess row
CABool
makeColumnIdString :: Int32 -> ColumnId row Text
makeColumnIdString :: forall row. Int32 -> ColumnId row Text
makeColumnIdString = (GValue -> IO Text)
-> ((row -> Text) -> ColumnAccess row)
-> Int32
-> ColumnId row Text
forall row ty.
(GValue -> IO ty)
-> ((row -> ty) -> ColumnAccess row) -> Int32 -> ColumnId row ty
ColumnId (\GValue
v -> Maybe Text -> Text
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe Text -> Text) -> IO (Maybe Text) -> IO Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GValue -> IO (Maybe Text)
forall a (m :: * -> *). (IsGValue a, MonadIO m) => GValue -> m a
fromGValue GValue
v) (row -> Text) -> ColumnAccess row
forall row. (row -> Text) -> ColumnAccess row
CAString
makeColumnIdPixbuf :: Int32 -> ColumnId row Pixbuf
makeColumnIdPixbuf :: forall row. Int32 -> ColumnId row Pixbuf
makeColumnIdPixbuf = (GValue -> IO Pixbuf)
-> ((row -> Pixbuf) -> ColumnAccess row)
-> Int32
-> ColumnId row Pixbuf
forall row ty.
(GValue -> IO ty)
-> ((row -> ty) -> ColumnAccess row) -> Int32 -> ColumnId row ty
ColumnId GValue -> IO Pixbuf
gvalueToPixbuf (row -> Pixbuf) -> ColumnAccess row
forall row. (row -> Pixbuf) -> ColumnAccess row
CAPixbuf
where gvalueToPixbuf :: GValue -> IO Pixbuf
gvalueToPixbuf :: GValue -> IO Pixbuf
gvalueToPixbuf GValue
gv = GValue -> (Ptr GValue -> IO Pixbuf) -> IO Pixbuf
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv ((Ptr GValue -> IO Pixbuf) -> IO Pixbuf)
-> (Ptr GValue -> IO Pixbuf) -> IO Pixbuf
forall a b. (a -> b) -> a -> b
$ \Ptr GValue
gvPtr -> do
Ptr Pixbuf
objPtr <- Ptr GValue -> IO (Ptr Pixbuf)
forall a. GObject a => Ptr GValue -> IO (Ptr a)
get_object Ptr GValue
gvPtr :: IO (Ptr Pixbuf)
(ManagedPtr Pixbuf -> Pixbuf) -> Ptr Pixbuf -> IO Pixbuf
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
newObject ManagedPtr Pixbuf -> Pixbuf
Pixbuf Ptr Pixbuf
objPtr
columnIdToNumber :: ColumnId row ty -> Int32
columnIdToNumber :: forall row ty. ColumnId row ty -> Int32
columnIdToNumber (ColumnId GValue -> IO ty
_ (row -> ty) -> ColumnAccess row
_ Int32
i) = Int32
i
invalidColumnId :: ColumnId row ty
invalidColumnId :: forall row ty. ColumnId row ty
invalidColumnId = (GValue -> IO ty)
-> ((row -> ty) -> ColumnAccess row) -> Int32 -> ColumnId row ty
forall row ty.
(GValue -> IO ty)
-> ((row -> ty) -> ColumnAccess row) -> Int32 -> ColumnId row ty
ColumnId ([Char] -> GValue -> IO ty
forall a. HasCallStack => [Char] -> a
error [Char]
"invalidColumnId: no GValue extractor")
([Char] -> (row -> ty) -> ColumnAccess row
forall a. HasCallStack => [Char] -> a
error [Char]
"invalidColumnId: no access type") (-Int32
1)
instance Eq (ColumnId row ty) where
(ColumnId GValue -> IO ty
_ (row -> ty) -> ColumnAccess row
_ Int32
i1) == :: ColumnId row ty -> ColumnId row ty -> Bool
== (ColumnId GValue -> IO ty
_ (row -> ty) -> ColumnAccess row
_ Int32
i2) = Int32
i1Int32 -> Int32 -> Bool
forall a. Eq a => a -> a -> Bool
==Int32
i2
instance Show (ColumnId row ty) where
show :: ColumnId row ty -> [Char]
show (ColumnId GValue -> IO ty
_ (row -> ty) -> ColumnAccess row
_ Int32
i) = Int32 -> [Char]
forall a. Show a => a -> [Char]
show Int32
i
treeModelGetValue :: IsTreeModel self => self
-> TreeIter
-> ColumnId row ty
-> IO ty
treeModelGetValue :: forall self row ty.
IsTreeModel self =>
self -> TreeIter -> ColumnId row ty -> IO ty
treeModelGetValue self
self TreeIter
iter (ColumnId GValue -> IO ty
getter (row -> ty) -> ColumnAccess row
_ Int32
colId) =
self -> TreeIter -> Int32 -> IO GValue
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsTreeModel a) =>
a -> TreeIter -> Int32 -> m GValue
GI.treeModelGetValue self
self TreeIter
iter Int32
colId IO GValue -> (GValue -> IO ty) -> IO ty
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= GValue -> IO ty
getter
treeModelGetIter :: (MonadIO m, IsTreeModel model) => model -> TreePath -> m (Maybe TreeIter)
treeModelGetIter :: forall (m :: * -> *) model.
(MonadIO m, IsTreeModel model) =>
model -> TreePath -> m (Maybe TreeIter)
treeModelGetIter model
model TreePath
path =
TreePath -> m Int32
forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
TreePath -> m Int32
treePathGetDepth TreePath
path m Int32 -> (Int32 -> m (Maybe TreeIter)) -> m (Maybe TreeIter)
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Int32
0 -> Maybe TreeIter -> m (Maybe TreeIter)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe TreeIter
forall a. Maybe a
Nothing
Int32
_ -> model -> TreePath -> m (Bool, TreeIter)
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsTreeModel a) =>
a -> TreePath -> m (Bool, TreeIter)
GI.treeModelGetIter model
model TreePath
path m (Bool, TreeIter)
-> ((Bool, TreeIter) -> m (Maybe TreeIter)) -> m (Maybe TreeIter)
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
(Bool
True, TreeIter
iter) -> Maybe TreeIter -> m (Maybe TreeIter)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe TreeIter -> m (Maybe TreeIter))
-> Maybe TreeIter -> m (Maybe TreeIter)
forall a b. (a -> b) -> a -> b
$ TreeIter -> Maybe TreeIter
forall a. a -> Maybe a
Just TreeIter
iter
(Bool, TreeIter)
_ -> Maybe TreeIter -> m (Maybe TreeIter)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe TreeIter
forall a. Maybe a
Nothing