module TclHandle where
import qualified TclPrimImpl as T
import TclWidgets

-- getting handles on widgets

totcl_wwidget :: String -> w -> GUI (WWidget w)
totcl_wwidget s w = withGUIInfo $ T.totcl_wwidget s w

toWindow :: String -> GUI Window
toWindow s = totcl_wwidget s TkTop

totcl_pwidget :: String -> w -> GUI (PWidget w)
totcl_pwidget s w = withGUIInfo $ T.totcl_pwidget s w

toMessage :: String -> GUI Message
toMessage s = totcl_pwidget s TkMessg
 
toButton :: String -> GUI Button
toButton s = totcl_pwidget s TkBut

toMenu :: String -> GUI Menu
toMenu s = totcl_wwidget s TkMen

toFrame :: String -> GUI Frame
toFrame s = totcl_pwidget s TkFra

toScrollbar :: String -> GUI Scrollbar
toScrollbar s = totcl_pwidget s TkScr

toLabel :: String -> GUI Label
toLabel s = totcl_pwidget s TkLab

toCanvas :: String -> GUI Canvas
toCanvas s = totcl_pwidget s TkCan

toRadiobutton :: String -> GUI Radiobutton
toRadiobutton s = totcl_pwidget s TkRB

toCheckbutton :: String -> GUI Checkbutton
toCheckbutton s = do
 c <- totcl_pwidget s TkChe
 cset c ["offvalue" %% "False",
	 "onvalue"  %% "True",
	 "variable" %% (varCheck c)]
 return c

toEntry :: String -> GUI Entry
toEntry s = totcl_pwidget s TkEnt

toScale :: String -> GUI Scale
toScale s = totcl_pwidget s TkSca

toListbox :: String -> GUI Listbox
toListbox s = totcl_pwidget s TkLis

toEdit :: String -> GUI Edit
toEdit s = totcl_pwidget s Edi

totcl_tgwidget :: Edit -> TagId -> w -> GUI (TWidget w)
totcl_tgwidget s t w = liftIO $ T.totcl_tgwidget s t w

toTag :: Edit -> TagId -> GUI Tag
toTag s tgid = 
 totcl_tgwidget s tgid TkTag

toMenubutton :: String -> GUI Menubutton
toMenubutton s = totcl_pwidget s TkMB


totcl_mwidget :: Menu -> WTag -> Int -> w -> GUI (MWidget w)
totcl_mwidget men n w x = liftIO $ T.totcl_mwidget men n w x

toCascade :: Menu -> WTag -> Int -> GUI Cascade
toCascade m tag n = totcl_mwidget m tag n TkCB
 
toMButton :: Menu -> WTag -> Int -> GUI MButton
toMButton m  tag n = totcl_mwidget m  tag n TkMBut

toMRadiobutton :: Menu -> WTag -> Int -> GUI MRadiobutton
toMRadiobutton m tag n = totcl_mwidget m  tag n TkMRB

toMCheckbutton :: Menu -> WTag -> Int -> GUI MCheckbutton
toMCheckbutton m  tag n = do
 c <- totcl_mwidget m  tag n TkMChe
 cset c ["offvalue" %% "False",
		"onvalue"  %% "True",
		"variable" %% (varMCheck c)]
 return c

toSeparator :: Menu -> WTag -> Int -> GUI Separator
toSeparator m tag n = totcl_mwidget m tag n TkSep

