module Graphics.UI.WXCore.Controls
(
textCtrlMakeLogActiveTarget
, logDeleteAndSetActiveTarget
, TreeCookie
, treeCtrlGetChildCookie, treeCtrlGetNextChild2
, treeCtrlWithChildren, treeCtrlGetChildren
, treeCtrlGetSelections2
, listBoxGetSelectionList
, execClipBoardData
, wxcAppUSleep
) where
import Graphics.UI.WXCore.WxcTypes
import Graphics.UI.WXCore.WxcDefs
import Graphics.UI.WXCore.WxcClasses
import Graphics.UI.WXCore.Types
import Foreign.Storable
import Foreign.Marshal.Array
import Foreign.Marshal.Utils
treeCtrlGetSelections2 :: TreeCtrl a -> IO [TreeItem]
treeCtrlGetSelections2 treeCtrl
= do xs <- treeCtrlGetSelections treeCtrl
return (map treeItemFromInt xs)
data TreeCookie = TreeCookie (Var Cookie)
data Cookie = Cookie TreeItem
| CookieFirst TreeItem
| CookieInvalid
treeCtrlGetChildCookie :: TreeCtrl a -> TreeItem -> IO TreeCookie
treeCtrlGetChildCookie treeCtrl parent
= do pcookie <- varCreate (CookieFirst parent)
return (TreeCookie pcookie)
treeCtrlGetNextChild2 :: TreeCtrl a -> TreeCookie -> IO (Maybe TreeItem)
treeCtrlGetNextChild2 treeCtrl treeCookie@(TreeCookie pcookie)
= do cookie <- varGet pcookie
case cookie of
CookieInvalid -> return Nothing
CookieFirst item -> with 0 $ \pint ->
do first <- treeCtrlGetFirstChild treeCtrl item pint
if (treeItemIsOk first)
then do varSet pcookie (Cookie first)
return (Just first)
else do varSet pcookie (CookieInvalid)
return Nothing
Cookie item ->
do next <- treeCtrlGetNextSibling treeCtrl item
if (treeItemIsOk next)
then do varSet pcookie (Cookie next)
return (Just next)
else do varSet pcookie (CookieInvalid)
return Nothing
treeCtrlWithChildren :: TreeCtrl a -> TreeItem -> (TreeItem -> IO b) -> IO [b]
treeCtrlWithChildren treeCtrl parent f
= do cookie <- treeCtrlGetChildCookie treeCtrl parent
let walk acc = do mbitem <- treeCtrlGetNextChild2 treeCtrl cookie
case mbitem of
Nothing -> return (reverse acc)
Just item -> do x <- f item
walk (x:acc)
walk []
treeCtrlGetChildren :: TreeCtrl a -> TreeItem -> IO [TreeItem]
treeCtrlGetChildren treeCtrl item
= treeCtrlWithChildren treeCtrl item return
listBoxGetSelectionList :: ListBox a -> IO [Int]
listBoxGetSelectionList listBox
= do n <- listBoxGetSelections listBox ptrNull 0
let count = abs n
allocaArray count $ \carr ->
do listBoxGetSelections listBox carr count
xs <- peekArray count carr
return (map fromCInt xs)
logDeleteAndSetActiveTarget :: Log a -> IO ()
logDeleteAndSetActiveTarget log
= do oldlog <- logSetActiveTarget log
when (not (objectIsNull oldlog)) (logDelete oldlog)
textCtrlMakeLogActiveTarget :: TextCtrl a -> IO ()
textCtrlMakeLogActiveTarget textCtrl
= do log <- logTextCtrlCreate textCtrl
logDeleteAndSetActiveTarget log
execClipBoardData :: Clipboard a -> (Clipboard a -> IO b) -> IO b
execClipBoardData cl event = bracket_ (clipboardOpen cl) (clipboardClose cl) (event cl)
wxcAppUSleep :: Int -> IO ()
wxcAppUSleep = wxcAppMilliSleep