module support_edit

// ********************************************************************************
// Clean tutorial example program.
//
// This program can be used to test the different ControlAttributes for a 
// EditControl in a Dialog.
// ********************************************************************************

import StdEnv, StdIO

Start :: *World -> *World
Start world
# (id, world) = openId world 
# edits = let w = PixelWidth 200 in [
        EditControl "Activate"      w                3 [ControlActivate (count 1 id)],
        EditControl "Deactivate"    w                3 [ControlDeactivate (count -1 id)],
        EditControl "Hide"          w                3 [ControlHide],
        EditControl "Id"            (PixelWidth 500) 3 [ControlId id],
        EditControl "Keyboard"      w                3 [ControlKeyboard (\ks . getKeyboardStateKeyState ks <> KeyUp) Able (kbfunc id)],
        EditControl "Pos"           w                3 [ControlPos (Left, zero)],
        EditControl "Resize"        w                3 [], //todo
        EditControl "SelectState"   w                3 [ControlSelectState Able],
        EditControl "SelectState"   w                3 [ControlSelectState Unable],
        EditControl "Tip"           w                3 [ControlTip "Some tip"]
    ]
# controls = ListLS edits
# dialog = Dialog "Support - EditControl" controls [WindowClose (noLS closeProcess)]
= startIO NDI Void (initialise dialog) [] world
where
    initialise dialog pst
    # (error,pst)       = openDialog 0 dialog pst
    | error <> NoError  = closeProcess pst
    | otherwise         = pst

    count :: Int Id (Int, PSt .l) -> (Int, PSt .l)
    count dx id (count,pst=:{io}) = (count + dx, appPIO (setControlText id (toString (count+dx))) pst)

    modf :: Id Modifiers -> (Int, PSt .l) -> (Int, PSt .l)
    modf id mods = \(count,pst=:{io}) . (count, appPIO (setControlText id (toString mods)) pst)

    kbfunc :: Id KeyboardState -> (Int, PSt .l) -> (Int, PSt .l)
    kbfunc id st = \(c,pst) . (c, appPIO (setControlText id (toString st)) pst)