module Win32Misc where

import StdDIS
import GDITypes
import Win32Types


----------------------------------------------------------------
-- Resources 
-- (should probably be distributed between 
--  Win32{Icon,Cursor,Accelerator,Menu,...}.gc)
----------------------------------------------------------------

type Accelerator = LPCSTR
-- intToAccelerator :: Int -> Accelerator
-- intToAccelerator i = makeIntResource (toWord i)

-- cursor and icon should not be const pointer; GSL ???
type Cursor = LPSTR
-- intToCursor :: Int -> Cursor
-- intToCursor i = makeIntResource (toWord i)

type Icon = LPSTR
-- intToIcon :: Int -> Icon
-- intToIcon i = makeIntResource (toWord i)

loadAccelerators :: MbHINSTANCE -> Accelerator -> IO HACCEL
loadAccelerators arg1 arg2 =
  (case arg1 of {
      Nothing -> (return (nullHANDLE));
      (Just arg1) -> (return ((arg1)))
   }) >>= \ (arg1) ->
  prim_loadAccelerators arg1 arg2
  >>= \ gc_result ->
  access_prim_loadAccelerators_res1 (gc_result :: Addr) >>= \ res1 ->
  access_prim_loadAccelerators_gc_failed (gc_result :: Addr) >>= \ gc_failed ->
  access_prim_loadAccelerators_gc_failstring (gc_result :: Addr) >>= \ gc_failstring ->
  if ( gc_failed /= (0::Int))
  then unmarshall_string_ gc_failstring >>=  ioError  . userError
  else (return (res1))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_loadAccelerators" prim_loadAccelerators :: Addr -> Addr -> IO (Addr)
foreign import ccall unsafe "access_prim_loadAccelerators_res1" access_prim_loadAccelerators_res1 :: Addr -> IO (Addr)
foreign import ccall unsafe "access_prim_loadAccelerators_gc_failed" access_prim_loadAccelerators_gc_failed :: Addr -> IO (Int)
foreign import ccall unsafe "access_prim_loadAccelerators_gc_failstring" access_prim_loadAccelerators_gc_failstring :: Addr -> IO (Addr)

loadCursor :: MbHINSTANCE -> Cursor -> IO HCURSOR
loadCursor arg1 arg2 =
  (case arg1 of {
      Nothing -> (return (nullHANDLE));
      (Just arg1) -> (return ((arg1)))
   }) >>= \ (arg1) ->
  prim_loadCursor arg1 arg2
  >>= \ gc_result ->
  access_prim_loadCursor_res1 (gc_result :: Addr) >>= \ res1 ->
  access_prim_loadCursor_gc_failed (gc_result :: Addr) >>= \ gc_failed ->
  access_prim_loadCursor_gc_failstring (gc_result :: Addr) >>= \ gc_failstring ->
  if ( gc_failed /= (0::Int))
  then unmarshall_string_ gc_failstring >>=  ioError  . userError
  else (return (res1))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_loadCursor" prim_loadCursor :: Addr -> Addr -> IO (Addr)
foreign import ccall unsafe "access_prim_loadCursor_res1" access_prim_loadCursor_res1 :: Addr -> IO (Addr)
foreign import ccall unsafe "access_prim_loadCursor_gc_failed" access_prim_loadCursor_gc_failed :: Addr -> IO (Int)
foreign import ccall unsafe "access_prim_loadCursor_gc_failstring" access_prim_loadCursor_gc_failstring :: Addr -> IO (Addr)

loadIcon :: MbHINSTANCE -> Icon -> IO HICON
loadIcon arg1 arg2 =
  (case arg1 of {
      Nothing -> (return (nullHANDLE));
      (Just arg1) -> (return ((arg1)))
   }) >>= \ (arg1) ->
  prim_loadIcon arg1 arg2
  >>= \ gc_result ->
  access_prim_loadIcon_res1 (gc_result :: Addr) >>= \ res1 ->
  access_prim_loadIcon_gc_failed (gc_result :: Addr) >>= \ gc_failed ->
  access_prim_loadIcon_gc_failstring (gc_result :: Addr) >>= \ gc_failstring ->
  if ( gc_failed /= (0::Int))
  then unmarshall_string_ gc_failstring >>=  ioError  . userError
  else (return (res1))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_loadIcon" prim_loadIcon :: Addr -> Addr -> IO (Addr)
foreign import ccall unsafe "access_prim_loadIcon_res1" access_prim_loadIcon_res1 :: Addr -> IO (Addr)
foreign import ccall unsafe "access_prim_loadIcon_gc_failed" access_prim_loadIcon_gc_failed :: Addr -> IO (Int)
foreign import ccall unsafe "access_prim_loadIcon_gc_failstring" access_prim_loadIcon_gc_failstring :: Addr -> IO (Addr)

iDC_ARROW :: Cursor
iDC_ARROW =
  unsafePerformIO(
    prim_iDC_ARROW
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_iDC_ARROW" prim_iDC_ARROW :: IO (Addr)
iDC_IBEAM :: Cursor
iDC_IBEAM =
  unsafePerformIO(
    prim_iDC_IBEAM
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_iDC_IBEAM" prim_iDC_IBEAM :: IO (Addr)
iDC_WAIT :: Cursor
iDC_WAIT =
  unsafePerformIO(
    prim_iDC_WAIT
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_iDC_WAIT" prim_iDC_WAIT :: IO (Addr)
iDC_CROSS :: Cursor
iDC_CROSS =
  unsafePerformIO(
    prim_iDC_CROSS
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_iDC_CROSS" prim_iDC_CROSS :: IO (Addr)
iDC_UPARROW :: Cursor
iDC_UPARROW =
  unsafePerformIO(
    prim_iDC_UPARROW
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_iDC_UPARROW" prim_iDC_UPARROW :: IO (Addr)
iDC_SIZENWSE :: Cursor
iDC_SIZENWSE =
  unsafePerformIO(
    prim_iDC_SIZENWSE
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_iDC_SIZENWSE" prim_iDC_SIZENWSE :: IO (Addr)
iDC_SIZENESW :: Cursor
iDC_SIZENESW =
  unsafePerformIO(
    prim_iDC_SIZENESW
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_iDC_SIZENESW" prim_iDC_SIZENESW :: IO (Addr)
iDC_SIZEWE :: Cursor
iDC_SIZEWE =
  unsafePerformIO(
    prim_iDC_SIZEWE
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_iDC_SIZEWE" prim_iDC_SIZEWE :: IO (Addr)
iDC_SIZENS :: Cursor
iDC_SIZENS =
  unsafePerformIO(
    prim_iDC_SIZENS
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_iDC_SIZENS" prim_iDC_SIZENS :: IO (Addr)

iDI_APPLICATION :: Icon
iDI_APPLICATION =
  unsafePerformIO(
    prim_iDI_APPLICATION
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_iDI_APPLICATION" prim_iDI_APPLICATION :: IO (Addr)
iDI_HAND :: Icon
iDI_HAND =
  unsafePerformIO(
    prim_iDI_HAND
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_iDI_HAND" prim_iDI_HAND :: IO (Addr)
iDI_QUESTION :: Icon
iDI_QUESTION =
  unsafePerformIO(
    prim_iDI_QUESTION
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_iDI_QUESTION" prim_iDI_QUESTION :: IO (Addr)
iDI_EXCLAMATION :: Icon
iDI_EXCLAMATION =
  unsafePerformIO(
    prim_iDI_EXCLAMATION
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_iDI_EXCLAMATION" prim_iDI_EXCLAMATION :: IO (Addr)
iDI_ASTERISK :: Icon
iDI_ASTERISK =
  unsafePerformIO(
    prim_iDI_ASTERISK
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_iDI_ASTERISK" prim_iDI_ASTERISK :: IO (Addr)

----------------------------------------------------------------
-- Message Boxes
----------------------------------------------------------------

type MBStyle = UINT

mB_OK :: MBStyle
mB_OK =
  unsafePerformIO(
    prim_mB_OK
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_mB_OK" prim_mB_OK :: IO (Word32)
mB_OKCANCEL :: MBStyle
mB_OKCANCEL =
  unsafePerformIO(
    prim_mB_OKCANCEL
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_mB_OKCANCEL" prim_mB_OKCANCEL :: IO (Word32)
mB_ABORTRETRYIGNORE :: MBStyle
mB_ABORTRETRYIGNORE =
  unsafePerformIO(
    prim_mB_ABORTRETRYIGNORE
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_mB_ABORTRETRYIGNORE" prim_mB_ABORTRETRYIGNORE :: IO (Word32)
mB_YESNOCANCEL :: MBStyle
mB_YESNOCANCEL =
  unsafePerformIO(
    prim_mB_YESNOCANCEL
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_mB_YESNOCANCEL" prim_mB_YESNOCANCEL :: IO (Word32)
mB_YESNO :: MBStyle
mB_YESNO =
  unsafePerformIO(
    prim_mB_YESNO
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_mB_YESNO" prim_mB_YESNO :: IO (Word32)
mB_RETRYCANCEL :: MBStyle
mB_RETRYCANCEL =
  unsafePerformIO(
    prim_mB_RETRYCANCEL
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_mB_RETRYCANCEL" prim_mB_RETRYCANCEL :: IO (Word32)
mB_ICONHAND :: MBStyle
mB_ICONHAND =
  unsafePerformIO(
    prim_mB_ICONHAND
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_mB_ICONHAND" prim_mB_ICONHAND :: IO (Word32)
mB_ICONQUESTION :: MBStyle
mB_ICONQUESTION =
  unsafePerformIO(
    prim_mB_ICONQUESTION
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_mB_ICONQUESTION" prim_mB_ICONQUESTION :: IO (Word32)
mB_ICONEXCLAMATION :: MBStyle
mB_ICONEXCLAMATION =
  unsafePerformIO(
    prim_mB_ICONEXCLAMATION
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_mB_ICONEXCLAMATION" prim_mB_ICONEXCLAMATION :: IO (Word32)
mB_ICONASTERISK :: MBStyle
mB_ICONASTERISK =
  unsafePerformIO(
    prim_mB_ICONASTERISK
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_mB_ICONASTERISK" prim_mB_ICONASTERISK :: IO (Word32)
mB_ICONINFORMATION :: MBStyle
mB_ICONINFORMATION =
  unsafePerformIO(
    prim_mB_ICONINFORMATION
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_mB_ICONINFORMATION" prim_mB_ICONINFORMATION :: IO (Word32)
mB_ICONSTOP :: MBStyle
mB_ICONSTOP =
  unsafePerformIO(
    prim_mB_ICONSTOP
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_mB_ICONSTOP" prim_mB_ICONSTOP :: IO (Word32)
mB_DEFBUTTON1 :: MBStyle
mB_DEFBUTTON1 =
  unsafePerformIO(
    prim_mB_DEFBUTTON1
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_mB_DEFBUTTON1" prim_mB_DEFBUTTON1 :: IO (Word32)
mB_DEFBUTTON2 :: MBStyle
mB_DEFBUTTON2 =
  unsafePerformIO(
    prim_mB_DEFBUTTON2
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_mB_DEFBUTTON2" prim_mB_DEFBUTTON2 :: IO (Word32)
mB_DEFBUTTON3 :: MBStyle
mB_DEFBUTTON3 =
  unsafePerformIO(
    prim_mB_DEFBUTTON3
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_mB_DEFBUTTON3" prim_mB_DEFBUTTON3 :: IO (Word32)
mB_APPLMODAL :: MBStyle
mB_APPLMODAL =
  unsafePerformIO(
    prim_mB_APPLMODAL
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_mB_APPLMODAL" prim_mB_APPLMODAL :: IO (Word32)
mB_SYSTEMMODAL :: MBStyle
mB_SYSTEMMODAL =
  unsafePerformIO(
    prim_mB_SYSTEMMODAL
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_mB_SYSTEMMODAL" prim_mB_SYSTEMMODAL :: IO (Word32)
mB_TASKMODAL :: MBStyle
mB_TASKMODAL =
  unsafePerformIO(
    prim_mB_TASKMODAL
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_mB_TASKMODAL" prim_mB_TASKMODAL :: IO (Word32)
mB_SETFOREGROUND :: MBStyle
mB_SETFOREGROUND =
  unsafePerformIO(
    prim_mB_SETFOREGROUND
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_mB_SETFOREGROUND" prim_mB_SETFOREGROUND :: IO (Word32)

type MBStatus = UINT

iDABORT :: MBStatus
iDABORT =
  unsafePerformIO(
    prim_iDABORT
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_iDABORT" prim_iDABORT :: IO (Word32)
iDCANCEL :: MBStatus
iDCANCEL =
  unsafePerformIO(
    prim_iDCANCEL
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_iDCANCEL" prim_iDCANCEL :: IO (Word32)
iDIGNORE :: MBStatus
iDIGNORE =
  unsafePerformIO(
    prim_iDIGNORE
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_iDIGNORE" prim_iDIGNORE :: IO (Word32)
iDNO :: MBStatus
iDNO =
  unsafePerformIO(
    prim_iDNO
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_iDNO" prim_iDNO :: IO (Word32)
iDOK :: MBStatus
iDOK =
  unsafePerformIO(
    prim_iDOK
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_iDOK" prim_iDOK :: IO (Word32)
iDRETRY :: MBStatus
iDRETRY =
  unsafePerformIO(
    prim_iDRETRY
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_iDRETRY" prim_iDRETRY :: IO (Word32)
iDYES :: MBStatus
iDYES =
  unsafePerformIO(
    prim_iDYES
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_iDYES" prim_iDYES :: IO (Word32)

-- Note: if the error is ever raised, we're in a very sad way!
messageBox :: HWND -> String -> String -> MBStyle -> IO MBStatus
messageBox arg1 gc_arg1 gc_arg2 arg4 =
  (marshall_string_ gc_arg1) >>= \ (arg2) ->
  (marshall_string_ gc_arg2) >>= \ (arg3) ->
  prim_messageBox arg1 arg2 arg3 arg4
  >>= \ gc_result ->
  access_prim_messageBox_res1 (gc_result :: Addr) >>= \ res1 ->
  access_prim_messageBox_gc_failed (gc_result :: Addr) >>= \ gc_failed ->
  access_prim_messageBox_gc_failstring (gc_result :: Addr) >>= \ gc_failstring ->
  if ( gc_failed /= (0::Int))
  then unmarshall_string_ gc_failstring >>=  ioError  . userError
  else (return (res1))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_messageBox" prim_messageBox :: Addr -> Addr -> Addr -> Word32 -> IO (Addr)
foreign import ccall unsafe "access_prim_messageBox_res1" access_prim_messageBox_res1 :: Addr -> IO (Word32)
foreign import ccall unsafe "access_prim_messageBox_gc_failed" access_prim_messageBox_gc_failed :: Addr -> IO (Int)
foreign import ccall unsafe "access_prim_messageBox_gc_failstring" access_prim_messageBox_gc_failstring :: Addr -> IO (Addr)

----------------------------------------------------------------
--
----------------------------------------------------------------

-- %fun GetModuleHandle :: MbString -> IO HMODULE
-- %fail { res1 == 0 } { ErrorWin("GetModuleHandle") }

type StdHandleId   = DWORD

sTD_INPUT_HANDLE :: StdHandleId
sTD_INPUT_HANDLE =
  unsafePerformIO(
    prim_sTD_INPUT_HANDLE
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_sTD_INPUT_HANDLE" prim_sTD_INPUT_HANDLE :: IO (Word32)
sTD_OUTPUT_HANDLE :: StdHandleId
sTD_OUTPUT_HANDLE =
  unsafePerformIO(
    prim_sTD_OUTPUT_HANDLE
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_sTD_OUTPUT_HANDLE" prim_sTD_OUTPUT_HANDLE :: IO (Word32)
sTD_ERROR_HANDLE :: StdHandleId
sTD_ERROR_HANDLE =
  unsafePerformIO(
    prim_sTD_ERROR_HANDLE
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_sTD_ERROR_HANDLE" prim_sTD_ERROR_HANDLE :: IO (Word32)

getStdHandle :: StdHandleId -> IO HANDLE
getStdHandle arg1 =
  prim_getStdHandle arg1
  >>= \ gc_result ->
  access_prim_getStdHandle_res1 (gc_result :: Addr) >>= \ res1 ->
  access_prim_getStdHandle_gc_failed (gc_result :: Addr) >>= \ gc_failed ->
  access_prim_getStdHandle_gc_failstring (gc_result :: Addr) >>= \ gc_failstring ->
  if ( gc_failed /= (0::Int))
  then unmarshall_string_ gc_failstring >>=  ioError  . userError
  else (return (res1))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_getStdHandle" prim_getStdHandle :: Word32 -> IO (Addr)
foreign import ccall unsafe "access_prim_getStdHandle_res1" access_prim_getStdHandle_res1 :: Addr -> IO (Addr)
foreign import ccall unsafe "access_prim_getStdHandle_gc_failed" access_prim_getStdHandle_gc_failed :: Addr -> IO (Int)
foreign import ccall unsafe "access_prim_getStdHandle_gc_failstring" access_prim_getStdHandle_gc_failstring :: Addr -> IO (Addr)

----------------------------------------------------------------
-- Rotatable Ellipse hack
--
-- Win95 (Win32?) doesn't support rotating ellipses - so we 
-- implement them with polygons.
--
-- We use a fixed number of edges rather than varying the number 
-- according to the radius of the ellipse.  
-- If anyone feels like improving the code (to vary the number),
-- they should place a fixed upper bound on the number of edges
-- since it takes a relatively long time to draw 1000 edges.
----------------------------------------------------------------


-- #define SIN_Cache_Size 20

transformedEllipse :: HDC -> POINT -> POINT -> POINT -> IO ()
transformedEllipse hdc gc_arg1 gc_arg5 gc_arg9 =
  case gc_arg1 of { (gc_arg2,gc_arg3) ->
  case gc_arg5 of { (gc_arg6,gc_arg7) ->
  case gc_arg9 of { (gc_arg10,gc_arg11) ->
  prim_transformedEllipse hdc gc_arg2 gc_arg3 gc_arg6 gc_arg7 gc_arg10 gc_arg11
  >>= \ gc_result ->
  access_prim_transformedEllipse_gc_failed (gc_result :: Addr) >>= \ gc_failed ->
  access_prim_transformedEllipse_gc_failstring (gc_result :: Addr) >>= \ gc_failstring ->
  if ( gc_failed /= (0::Int))
  then unmarshall_string_ gc_failstring >>=  ioError  . userError
  else (return (()))}}}
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_transformedEllipse" prim_transformedEllipse :: Addr -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> IO (Addr)
foreign import ccall unsafe "access_prim_transformedEllipse_gc_failed" access_prim_transformedEllipse_gc_failed :: Addr -> IO (Int)
foreign import ccall unsafe "access_prim_transformedEllipse_gc_failstring" access_prim_transformedEllipse_gc_failstring :: Addr -> IO (Addr)


----------------------------------------------------------------
-- Cursor
----------------------------------------------------------------

-- %fun getCursorPos :: IO POINT
-- %code BOOL success = GetCursorPos(p);
-- %fail { !success } { ErrorString/Win("GetCursorPos") }
-- %result (point p)
-- 
-- %fun SetCursorPos :: POINT -> IO ()
-- %code BOOL success = SetCursorPos(arg1->x,arg1->y);
-- %fail { !success } { ErrorString/Win("SetCursorPos") }
--
-- %fun ClipCursor :: RECT -> IO ()
-- %call (declare {RECT} arg1 in (rect {arg1}))
-- %code BOOL success = ClipCursor(&arg1);
-- %fail { !success } { ErrorString/Win("ClipCursor") }
--
-- %fun getClipCursor :: IO RECT
-- %code BOOL success = GetClipCursor(&res1) } )
-- %fail { !success } { ErrorString/Win("GetClipCursor") }
-- %result (declare {RECT} res1 in (rect {res1}))

----------------------------------------------------------------
-- Exit/shutdown
----------------------------------------------------------------

type ExitOption = UINT

eWX_FORCE :: ExitOption
eWX_FORCE =
  unsafePerformIO(
    prim_eWX_FORCE
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_eWX_FORCE" prim_eWX_FORCE :: IO (Word32)
eWX_LOGOFF :: ExitOption
eWX_LOGOFF =
  unsafePerformIO(
    prim_eWX_LOGOFF
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_eWX_LOGOFF" prim_eWX_LOGOFF :: IO (Word32)
eWX_POWEROFF :: ExitOption
eWX_POWEROFF =
  unsafePerformIO(
    prim_eWX_POWEROFF
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_eWX_POWEROFF" prim_eWX_POWEROFF :: IO (Word32)
eWX_REBOOT :: ExitOption
eWX_REBOOT =
  unsafePerformIO(
    prim_eWX_REBOOT
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_eWX_REBOOT" prim_eWX_REBOOT :: IO (Word32)
eWX_SHUTDOWN :: ExitOption
eWX_SHUTDOWN =
  unsafePerformIO(
    prim_eWX_SHUTDOWN
    >>= \  res1  ->
    (return (res1)))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_eWX_SHUTDOWN" prim_eWX_SHUTDOWN :: IO (Word32)

-- %fun exitWindowsEx :: ExitOption -> IO ()
-- %code ExitWindowEx(arg1,0);
-- %fail { !success } { ErrorWin("ExitWindowsEx") }
--
-- %fun exitWindows :: IO ()
-- %code ExitWindows(0,0)
-- %fail { !success } { ErrorWin("ExitWindows") }

----------------------------------------------------------------
-- Beeping
----------------------------------------------------------------

type MbBeep = Maybe UINT

type Duration   = Int

type MbDuration   = Maybe Duration

messageBeep :: MbBeep -> IO ()
messageBeep arg1 =
  (case arg1 of {
      Nothing -> (return (0xFFFFFFFF));
      (Just arg1) -> (return ((arg1)))
   }) >>= \ (arg1) ->
  prim_messageBeep arg1
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_messageBeep" prim_messageBeep :: Word32 -> IO ()

beep :: WORD -> MbDuration -> IO ()
beep arg1 arg2 =
  (case arg2 of {
      Nothing -> (return (-1));
      (Just arg2) -> (return ((arg2)))
   }) >>= \ (arg2) ->
  prim_beep arg1 arg2
  >>= \ gc_result ->
  access_prim_beep_gc_failed (gc_result :: Addr) >>= \ gc_failed ->
  access_prim_beep_gc_failstring (gc_result :: Addr) >>= \ gc_failstring ->
  if ( gc_failed /= (0::Int))
  then unmarshall_string_ gc_failstring >>=  ioError  . userError
  else (return (()))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_beep" prim_beep :: Word16 -> Int -> IO (Addr)
foreign import ccall unsafe "access_prim_beep_gc_failed" access_prim_beep_gc_failed :: Addr -> IO (Int)
foreign import ccall unsafe "access_prim_beep_gc_failstring" access_prim_beep_gc_failstring :: Addr -> IO (Addr)

----------------------------------------------------------------
-- Timers
----------------------------------------------------------------

type TimerId   = UINT

-- ToDo: support the other two forms of timer initialisation

-- Cause WM_TIMER events to be sent to window callback
setWinTimer :: HWND -> TimerId -> UINT -> IO TimerId
setWinTimer arg1 arg2 arg3 =
  prim_setWinTimer arg1 arg2 arg3
  >>= \ gc_result ->
  access_prim_setWinTimer_res1 (gc_result :: Addr) >>= \ res1 ->
  access_prim_setWinTimer_gc_failed (gc_result :: Addr) >>= \ gc_failed ->
  access_prim_setWinTimer_gc_failstring (gc_result :: Addr) >>= \ gc_failstring ->
  if ( gc_failed /= (0::Int))
  then unmarshall_string_ gc_failstring >>=  ioError  . userError
  else (return (res1))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_setWinTimer" prim_setWinTimer :: Addr -> Word32 -> Word32 -> IO (Addr)
foreign import ccall unsafe "access_prim_setWinTimer_res1" access_prim_setWinTimer_res1 :: Addr -> IO (Word32)
foreign import ccall unsafe "access_prim_setWinTimer_gc_failed" access_prim_setWinTimer_gc_failed :: Addr -> IO (Int)
foreign import ccall unsafe "access_prim_setWinTimer_gc_failstring" access_prim_setWinTimer_gc_failstring :: Addr -> IO (Addr)

killTimer :: MbHWND -> TimerId -> IO ()
killTimer arg1 arg2 =
  (case arg1 of {
      Nothing -> (return (nullHANDLE));
      (Just arg1) -> (return ((arg1)))
   }) >>= \ (arg1) ->
  prim_killTimer arg1 arg2
  >>= \ gc_result ->
  access_prim_killTimer_gc_failed (gc_result :: Addr) >>= \ gc_failed ->
  access_prim_killTimer_gc_failstring (gc_result :: Addr) >>= \ gc_failstring ->
  if ( gc_failed /= (0::Int))
  then unmarshall_string_ gc_failstring >>=  ioError  . userError
  else (return (()))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_killTimer" prim_killTimer :: Addr -> Word32 -> IO (Addr)
foreign import ccall unsafe "access_prim_killTimer_gc_failed" access_prim_killTimer_gc_failed :: Addr -> IO (Int)
foreign import ccall unsafe "access_prim_killTimer_gc_failstring" access_prim_killTimer_gc_failstring :: Addr -> IO (Addr)

-- For documentation purposes:
type MilliSeconds = DWORD

timeGetTime :: IO MilliSeconds
timeGetTime =
  prim_timeGetTime
  >>= \  res1  ->
  (return (res1))
foreign import  ccall unsafe "Win32Misc_stub_ffi.h prim_timeGetTime" prim_timeGetTime :: IO (Word32)

----------------------------------------------------------------

-- %fun ezCreateFont :: Unknown
-- %result BITMAP({ getBitmapInfo(x) })

----------------------------------------------------------------
-- End
----------------------------------------------------------------
