I have a timetable to display in a table.
Here is a sample of my current solution:
import Graphics.UI.Gtk
import Control.Monad.IO.Class
main = do
initGUI
window <- windowNew
view <- treeViewNew
store <- listStoreNew initialData
treeViewSetModel view store
containerAdd window view
prepareCols view store
window `on` deleteEvent $ liftIO mainQuit >> return False
widgetShowAll window
mainGUI
initialData :: [[String]]
initialData = [["foo", "bar"], ["baz", "42"]]
prepareCols :: TreeView -> ListStore [String] -> IO ()
prepareCols view store = do
size <- listStoreGetSize store
mapM_ (addColumn view store) [0..size-1]
addColumn :: TreeView -> ListStore [String] -> Int -> IO ()
addColumn view store i = addTextColumn view store (!! i) $ show i
addTextColumn :: (TreeViewClass view
, TreeModelClass (model row)
, TypedTreeModelClass model
)
=> view -> model row -> (row -> String) -> String -> IO ()
addTextColumn view model f name = do
col <- treeViewColumnNew
rend <- cellRendererTextNew
treeViewColumnSetTitle col name
treeViewColumnPackStart col rend True
cellLayoutSetAttributes col rend model (\row -> [ cellText := f row ])
treeViewColumnSetExpand col True
treeViewAppendColumn view col
return ()
Now I would like to make every cell right-clickable, but gtk2hs only offers to make a row activable, without information which cell was activated, or make the column header clickable.
What would be the way to go in gtk2hs, for a table that responds to click events with information, about which row and column was clicked (For the column a numeric index would be perfect, so I can use this index to modify the list I started with), without resorting to nasty things, like using a Table
and deleting/adding labels to it at runtime.
Im using gtk2hs (gtk3) version 0.12.5.6