module Graphics.UI.WXCore.Dialogs
(
errorDialog, warningDialog, infoDialog
, confirmDialog, proceedDialog
, tipWindowMessage, tipWindowMessageBounded
, fileOpenDialog
, filesOpenDialog
, fileSaveDialog
, dirOpenDialog
, fontDialog
, colorDialog
, passwordDialog
, textDialog
, numberDialog
, messageDialog
, fileDialog
) where
import Data.List( intersperse )
import Graphics.UI.WXCore.WxcTypes
import Graphics.UI.WXCore.WxcDefs
import Graphics.UI.WXCore.WxcClasses
import Graphics.UI.WXCore.Types
import Graphics.UI.WXCore.Draw
tipWindowMessage :: Window a -> String -> IO ()
tipWindowMessage parent message
= tipWindowCreate parent message 100 >> return ()
tipWindowMessageBounded :: Window a -> String -> Rect -> IO ()
tipWindowMessageBounded parent message boundingBox
= do tipWindow <- tipWindowCreate parent message 100
tipWindowSetBoundingRect tipWindow boundingBox
return ()
filesOpenDialog :: Window a -> Bool -> Bool -> String -> [(String,[String])] -> FilePath -> FilePath -> IO [FilePath]
filesOpenDialog parent rememberCurrentDir allowReadOnly message wildcards directory filename
= fileDialog parent result flags message wildcards directory filename
where
flags
= wxOPEN .+. wxMULTIPLE
.+. (if rememberCurrentDir then wxCHANGE_DIR else 0)
.+. (if allowReadOnly then 0 else wxHIDE_READONLY)
result fd r
= if (r /= wxID_OK)
then return []
else fileDialogGetPaths fd
fileOpenDialog :: Window a -> Bool -> Bool -> String -> [(String,[String])] -> FilePath -> FilePath -> IO (Maybe FilePath)
fileOpenDialog parent rememberCurrentDir allowReadOnly message wildcards directory filename
= fileDialog parent result flags message wildcards directory filename
where
flags
= wxOPEN .+. (if rememberCurrentDir then wxCHANGE_DIR else 0) .+. (if allowReadOnly then 0 else wxHIDE_READONLY)
result fd r
= if (r /= wxID_OK)
then return Nothing
else do fname <- fileDialogGetPath fd
return (Just fname)
fileSaveDialog :: Window a -> Bool -> Bool -> String -> [(String,[String])] -> FilePath -> FilePath -> IO (Maybe FilePath)
fileSaveDialog parent rememberCurrentDir overwritePrompt message wildcards directory filename
= fileDialog parent result flags message wildcards directory filename
where
flags
= wxSAVE .+. (if rememberCurrentDir then wxCHANGE_DIR else 0) .+. (if overwritePrompt then wxOVERWRITE_PROMPT else 0)
result fd r
= if (r /= wxID_OK)
then return Nothing
else do fname <- fileDialogGetPath fd
return (Just fname)
fileDialog :: Window a -> (FileDialog () -> Style -> IO b) -> Style -> String -> [(String,[String])] -> FilePath -> FilePath -> IO b
fileDialog parent processResult flags message wildcards directory filename
= bracket
(fileDialogCreate parent message directory filename (formatWildCards wildcards) pointNull flags)
(windowDestroy)
(\fd -> do r <- dialogShowModal fd
processResult fd r)
where
formatWildCards wildcards'
= concat (intersperse "|"
[desc ++ "|" ++ concat (intersperse ";" patterns) | (desc,patterns) <- wildcards'])
fontDialog :: Window a -> FontStyle -> IO (Maybe FontStyle)
fontDialog parent fontStyle
= withFontStyle fontStyle $ \font ->
bracket (getFontFromUser parent font)
(fontDelete)
(\f -> do ok <- fontIsOk f
if ok
then do info <- fontGetFontStyle f
return (Just info)
else return Nothing)
colorDialog :: Window a -> Color -> IO (Maybe Color)
colorDialog parent color
= do c <- getColourFromUser parent color
if (colorIsOk c)
then return (Just c)
else return Nothing
passwordDialog :: Window a -> String -> String -> String -> IO String
passwordDialog parent message caption defaultText
= getPasswordFromUser message caption defaultText parent
textDialog :: Window a -> String -> String -> String -> IO String
textDialog parent message caption defaultText
= getTextFromUser message caption defaultText parent pointNull False
numberDialog :: Window a -> String -> String -> String -> Int -> Int -> Int -> IO (Maybe Int)
numberDialog parent message prompt caption value minval maxval
= let minval' = if minval < 0 then 0 else minval
maxval' = if maxval < minval' then minval' else maxval
value' | value < minval' = minval'
| value > maxval' = maxval'
| otherwise = value
in do i <- getNumberFromUser message prompt caption value' minval' maxval' parent pointNull
if (i == 1)
then return Nothing
else return (Just i)
dirOpenDialog :: Window a -> Bool -> FilePath -> FilePath -> IO (Maybe FilePath)
dirOpenDialog parent allowNewDir message directory
= bracket
(dirDialogCreate parent message directory pointNull flags)
(windowDestroy)
(\dd -> do r <- dialogShowModal dd
if (r /= wxID_OK)
then return Nothing
else do path <- dirDialogGetPath dd
return (Just path))
where
flags
= if allowNewDir then 0x80 else 0
proceedDialog :: Window a -> String -> String -> IO Bool
proceedDialog parent caption msg
= do r <- messageDialog parent caption msg (wxOK .+. wxCANCEL .+. wxICON_EXCLAMATION)
return (r==wxID_OK)
confirmDialog :: Window a -> String -> String -> Bool -> IO Bool
confirmDialog parent caption msg yesDefault
= do r <- messageDialog parent caption msg
(wxYES_NO .+. (if yesDefault then wxYES_DEFAULT else wxNO_DEFAULT) .+. wxICON_QUESTION)
return (r==wxID_YES)
warningDialog :: Window a -> String -> String -> IO ()
warningDialog parent caption msg
= unitIO (messageDialog parent caption msg (wxOK .+. wxICON_EXCLAMATION))
errorDialog :: Window a -> String -> String -> IO ()
errorDialog parent caption msg
= unitIO (messageDialog parent caption msg (wxOK .+. wxICON_HAND))
infoDialog :: Window a -> String -> String -> IO ()
infoDialog parent caption msg
= unitIO (messageDialog parent caption msg (wxOK .+. wxICON_INFORMATION))
messageDialog :: Window a -> String -> String -> BitFlag -> IO BitFlag
messageDialog parent caption msg flags
= do m <- messageDialogCreate parent msg caption flags
r <- messageDialogShowModal m
messageDialogDelete m
return r