module DataTreeView.Row(CellData,cellData,unCellData,
ColorName,CellAttr,txt,bgcolor,bgcolor',fgcolor,fgcolor',scale,Row(..),
addToAll,convertAttrs,seqListSpine, standardScale) where
import Control.DeepSeq
import Graphics.UI.Gtk
import Data.Typeable
import Data.Monoid
import DataTreeView.StrictTypes
import Data.Data
import Data.Word
seqListSpine :: [t1] -> t -> t
seqListSpine [] x = x
seqListSpine (_:xs) x = xs `seqListSpine` x
type CellData = StrictList CellAttr
cellData :: [CellAttr] -> CellData
cellData = strictList
unCellData :: CellData -> [CellAttr]
unCellData = fromStrictList
type ColorName = String
data CellAttr =
Txt !String
| Bgcolor !ColorName
| Bgcolor' !Word16 !Word16 !Word16
| Fgcolor !String
| Fgcolor' !Word16 !Word16 !Word16
| Scale !Double
deriving(Show,Typeable,Data,Eq,Ord)
txt :: String -> CellAttr
txt x = rnf x `seq` Txt x
bgcolor :: ColorName -> CellAttr
bgcolor x = rnf x `seq` Bgcolor x
bgcolor' :: Word16 -> Word16 -> Word16 -> CellAttr
bgcolor' = Bgcolor'
fgcolor :: ColorName -> CellAttr
fgcolor x = rnf x `seq` Fgcolor x
fgcolor' :: Word16 -> Word16 -> Word16 -> CellAttr
fgcolor' = Fgcolor'
scale :: Double -> CellAttr
scale = Scale
standardScale :: Double
standardScale = 0.75
data Row = Row {
rowCV :: !CellData
, rowFieldName :: !CellData
, rowCustomInfo :: !CellData
, rowTypeName :: !CellData
} deriving(Show,Typeable,Data)
addToAll :: Row -> [CellAttr] -> Row
addToAll r (cellData -> x)
= r { rowCV = rowCV r `mappend` x
, rowFieldName = rowFieldName r `mappend` x
, rowCustomInfo = rowCustomInfo r `mappend` x
, rowTypeName = rowTypeName r `mappend` x
}
convertAttrs :: CellRendererTextClass c => CellData -> [AttrOp c]
convertAttrs = fmap convertAttr . fromStrictList
where
convertAttr (Txt x) = cellText :~ (++x)
convertAttr (Fgcolor x) = cellTextForeground := x
convertAttr (Fgcolor' r g b) = cellTextForegroundColor := Color r g b
convertAttr (Bgcolor x) = cellTextBackground := x
convertAttr (Bgcolor' r g b) = cellTextBackgroundColor := Color r g b
convertAttr (Scale x) = cellTextScale :~ (*x)