Below is a Haskell program which launches a wxHaskell notebook.
It works, except that I cannot manage to handle a page change event so as to get the index of the newly selected page. I get the previous one instead (see comment "PROBLEM" in the code below).
There is a warning about this behaviour in the C wxNotebook Class Reference documentation (see section on getSelection) as well as in the "Detailed Description" section of the wxBookCtrlEvent Class Reference documetnation but I do not understand at all how to make use of it.
Could anyone please show me some working code for a notebook where one gets the new page index when a new page is selected by the user (by clicking on its title)?
A secondary question: I do not understand what the argument 0 is next to --???.
Thank you in advance!
module Main where
import Graphics.UI.WX
import Graphics.UI.WXCore
main :: IO ()
main =
start $
do
f <- frame []
nbk <- notebook f []
pages <- sequence [ do
p <- panel nbk []
return $ tab ("Page "++show i) (container p $ label ("Page " ++ show i))
| i <- [0..3]]
set f [layout := fill $ tabs nbk pages,clientSize := sz 300 100]
let h event = case event of
wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED ->
do
i <- notebookGetSelection nbk -- PROBLEM: gives the OLD index
infoDialog f "Event otification" $ "Notebook selected page: " ++ show i
propagateEvent
windowOnEvent nbk
[wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED]
0 -- ???
h