module CheckBut (checkBut) where

import Tcl


checkBut = 
     do	w <- window []

	f1 <- frame w []
	packAdd f1 []

 	l  <- label w [text msg, borderwidth 4,font "Helvetica 14"]
	packAdd l [inFrame f1,packV,packPadX 20,packPadY 10]
       
        f2 <- frame w []
	mapM_ (mkButton w f2 l) cbuttons
	packAdd f2 [inFrame f1,packV]

     	return ()

             
mkButton w f l (nm, com) = 
     do c <- checkbutton w [text nm, indicatoron True, width 10]
        cset c [command (com l c)]
	packAdd c [inFrame f,packH]
	return c

cbuttons :: [(String, Label -> Checkbutton -> GUI ())]
cbuttons = [("bold", bold)
	   ,("blueText", blueText)
	   ,("sink", sink)
           ]

bold :: Label -> Checkbutton -> GUI ()
bold l c = 
     do b <- getCheck c
	case b of
	  True  -> cset l [font "Helvetica 14 bold"]
	  False -> cset l [font "Helvetica 14"]
	return ()

blueText :: Label -> Checkbutton -> GUI ()
blueText l c = 
     do b <- getCheck c
	case b of
	  True  -> cset l [foreground "blue"]
	  False -> cset l [foreground "black"]
	return ()

sink :: Label -> Checkbutton -> GUI ()
sink l c = 
     do b <- getCheck c
	case b of
	  True  -> cset l [relief Sunken]
	  False -> cset l [relief Flat]
	return ()
 

msg = "Click on the checkbuttons to change this label"


