-- GENERATED by C->Haskell Compiler, version 0.18.2 The shapeless maps, 31 Oct 2014 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "src/Graphics/UI/FLTK/LowLevel/Clock.chs" #-}
{-# LANGUAGE CPP, TypeSynonymInstances, FlexibleInstances, MultiParamTypeClasses, FlexibleContexts #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Graphics.UI.FLTK.LowLevel.Clock
  (
    ClockType(..),
    clockNew,
    clockNewWithType,
    Hour(..),
    Minute(..),
    Second(..),
    ClockByTime (..),
    ClockSinceEpoch(..),
    ClockSetTimeType(..)
    -- * Hierarchy
    --
    -- $hierarchy

    -- * Clock
    --
    -- $Clockfunctions
  )
where



import C2HS hiding (cFromEnum, cFromBool, cToBool,cToEnum)
import Foreign.C.Types
import Graphics.UI.FLTK.LowLevel.Fl_Enumerations
import Graphics.UI.FLTK.LowLevel.Fl_Types
import Graphics.UI.FLTK.LowLevel.Utils
import Graphics.UI.FLTK.LowLevel.Hierarchy
import Graphics.UI.FLTK.LowLevel.Dispatch
import Data.Char
data ClockType = SquareClock
               | AnalogClock
               | DigitalClock
               | RoundClock
instance Enum ClockType where
  succ SquareClock = RoundClock
  succ AnalogClock = RoundClock
  succ DigitalClock = RoundClock
  succ RoundClock = error "ClockType.succ: RoundClock has no successor"

  pred RoundClock = SquareClock
  pred SquareClock = error "ClockType.pred: SquareClock has no predecessor"
  pred AnalogClock = error "ClockType.pred: AnalogClock has no predecessor"
  pred DigitalClock = error "ClockType.pred: DigitalClock has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from RoundClock

  fromEnum SquareClock = 0
  fromEnum AnalogClock = 0
  fromEnum DigitalClock = 0
  fromEnum RoundClock = 1

  toEnum 0 = SquareClock
  toEnum 1 = RoundClock
  toEnum unmatched = error ("ClockType.toEnum: Cannot match " ++ show unmatched)

{-# LINE 41 "src/Graphics/UI/FLTK/LowLevel/Clock.chs" #-}

newtype Hour = Hour Int
newtype Minute = Minute Int
newtype Second = Second Int
data ClockByTime = ClockByTime Hour Minute Second
data ClockSinceEpoch = ClockSinceEpoch Second
data ClockSetTimeType = ClockSetByTime ClockByTime | ClockSetSinceEpoch ClockSinceEpoch
clockNew' :: (Int) -> (Int) -> (Int) -> (Int) -> IO ((Ptr ()))
clockNew' a1 a2 a3 a4 =
  let {a1' = fromIntegral a1} in 
  let {a2' = fromIntegral a2} in 
  let {a3' = fromIntegral a3} in 
  let {a4' = fromIntegral a4} in 
  clockNew''_ a1' a2' a3' a4' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 48 "src/Graphics/UI/FLTK/LowLevel/Clock.chs" #-}

clockNewWithLabel' :: (Int) -> (Int) -> (Int) -> (Int) -> (String) -> IO ((Ptr ()))
clockNewWithLabel' a1 a2 a3 a4 a5 =
  let {a1' = fromIntegral a1} in 
  let {a2' = fromIntegral a2} in 
  let {a3' = fromIntegral a3} in 
  let {a4' = fromIntegral a4} in 
  withCString a5 $ \a5' -> 
  clockNewWithLabel''_ a1' a2' a3' a4' a5' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 49 "src/Graphics/UI/FLTK/LowLevel/Clock.chs" #-}

clockNewWithClockType' :: (CUChar) -> (Int) -> (Int) -> (Int) -> (Int) -> (String) -> IO ((Ptr ()))
clockNewWithClockType' a1 a2 a3 a4 a5 a6 =
  let {a1' = id a1} in 
  let {a2' = fromIntegral a2} in 
  let {a3' = fromIntegral a3} in 
  let {a4' = fromIntegral a4} in 
  let {a5' = fromIntegral a5} in 
  withCString a6 $ \a6' -> 
  clockNewWithClockType''_ a1' a2' a3' a4' a5' a6' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 50 "src/Graphics/UI/FLTK/LowLevel/Clock.chs" #-}

clockNew :: Rectangle -> Maybe String -> IO (Ref Clock)
clockNew rectangle l' =
    let (x_pos, y_pos, width, height) = fromRectangle rectangle
    in case l' of
        Nothing -> clockNew' x_pos y_pos width height >>=
                             toRef
        Just l -> clockNewWithLabel' x_pos y_pos width height l >>=
                             toRef
clockNewWithType :: ClockType -> Rectangle -> String -> IO (Ref Clock)
clockNewWithType clocktype' rectangle' label' =
    let (x_pos, y_pos, width, height) = fromRectangle rectangle'
    in
     clockNewWithClockType' (castCharToCUChar . chr . fromEnum $ clocktype') x_pos y_pos width height label'  >>= toRef

setValueWithhms' :: (Ptr ()) -> (Int) -> (Int) -> (Int) -> IO ()
setValueWithhms' a1 a2 a3 a4 =
  let {a1' = id a1} in 
  let {a2' = fromIntegral a2} in 
  let {a3' = fromIntegral a3} in 
  let {a4' = fromIntegral a4} in 
  setValueWithhms''_ a1' a2' a3' a4' >>
  return ()

{-# LINE 65 "src/Graphics/UI/FLTK/LowLevel/Clock.chs" #-}

setValue' :: (Ptr ()) -> (CULong) -> IO ()
setValue' a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  setValue''_ a1' a2' >>
  return ()

{-# LINE 66 "src/Graphics/UI/FLTK/LowLevel/Clock.chs" #-}

instance (impl ~ (ClockSetTimeType -> IO ())) => Op (SetValue()) Clock orig impl where
  runOp _ _ clock' clockvalue = withRef clock' $ \clockPtr ->
    case clockvalue of
     ClockSetByTime (ClockByTime (Hour h)(Minute m) (Second s)) -> setValueWithhms' clockPtr h m s
     ClockSetSinceEpoch (ClockSinceEpoch (Second s)) -> setValue' clockPtr (fromIntegral s)

getValue' :: (Ptr ()) -> IO ((CULong))
getValue' a1 =
  let {a1' = id a1} in 
  getValue''_ a1' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 73 "src/Graphics/UI/FLTK/LowLevel/Clock.chs" #-}

instance (impl ~ (IO ClockSinceEpoch)) => Op (GetValueSinceEpoch ()) Clock orig impl where
  runOp _ _ clock' = withRef clock' $ \clockPtr ->
    getValue' clockPtr >>= return . ClockSinceEpoch . Second . fromIntegral

clockHour' :: (Ptr ()) -> IO ((Int))
clockHour' a1 =
  let {a1' = id a1} in 
  clockHour''_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 78 "src/Graphics/UI/FLTK/LowLevel/Clock.chs" #-}

clockMinute' :: (Ptr ()) -> IO ((Int))
clockMinute' a1 =
  let {a1' = id a1} in 
  clockMinute''_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 79 "src/Graphics/UI/FLTK/LowLevel/Clock.chs" #-}

clockSecond' :: (Ptr ()) -> IO ((Int))
clockSecond' a1 =
  let {a1' = id a1} in 
  clockSecond''_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 80 "src/Graphics/UI/FLTK/LowLevel/Clock.chs" #-}

instance (impl ~ (IO ClockByTime)) => Op (GetValue ()) Clock orig impl where
  runOp _ _ clock' = withRef clock' $ \clockPtr -> do
    hour' <- clockHour' clockPtr
    minute' <- clockMinute' clockPtr
    second' <- clockSecond' clockPtr
    return $ ClockByTime (Hour hour') (Minute minute') (Second second')

menu_Handle' :: (Ptr ()) -> (CInt) -> IO ((Int))
menu_Handle' a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  menu_Handle''_ a1' a2' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 88 "src/Graphics/UI/FLTK/LowLevel/Clock.chs" #-}

instance (impl ~ (Event -> IO Int)) => Op (Handle ()) Clock orig impl where
  runOp _ _ menu_ event = withRef menu_ (\p -> menu_Handle' p (fromIntegral . fromEnum $ event))

-- $Clockfunctions
--
-- @
--
-- getValue :: 'Ref' 'Clock' -> 'IO' 'ClockByTime'
--
-- getValueSinceEpoch :: 'Ref' 'Clock' -> 'IO' 'ClockSinceEpoch'
--
-- handle :: 'Ref' 'Clock' -> 'Event' -> 'IO' 'Int'
--
-- setValue :: 'Ref' 'Clock' -> 'ClockSetTimeType' -> 'IO' ()

-- $hierarchy
-- @
-- "Graphics.UI.FLTK.LowLevel.Widget"
--  |
--  v
-- "Graphics.UI.FLTK.LowLevel.Clock"
-- @

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/Clock.chs.h Fl_Clock_New"
  clockNew''_ :: (CInt -> (CInt -> (CInt -> (CInt -> (IO (Ptr ()))))))

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/Clock.chs.h Fl_Clock_New_WithLabel"
  clockNewWithLabel''_ :: (CInt -> (CInt -> (CInt -> (CInt -> ((Ptr CChar) -> (IO (Ptr ())))))))

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/Clock.chs.h Fl_Clock_New_WithClockType"
  clockNewWithClockType''_ :: (CUChar -> (CInt -> (CInt -> (CInt -> (CInt -> ((Ptr CChar) -> (IO (Ptr ()))))))))

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/Clock.chs.h Fl_Clock_set_value_with_hms"
  setValueWithhms''_ :: ((Ptr ()) -> (CInt -> (CInt -> (CInt -> (IO ())))))

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/Clock.chs.h Fl_Clock_set_value"
  setValue''_ :: ((Ptr ()) -> (CULong -> (IO ())))

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/Clock.chs.h Fl_Clock_value"
  getValue''_ :: ((Ptr ()) -> (IO CULong))

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/Clock.chs.h Fl_Clock_hour"
  clockHour''_ :: ((Ptr ()) -> (IO CInt))

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/Clock.chs.h Fl_Clock_minute"
  clockMinute''_ :: ((Ptr ()) -> (IO CInt))

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/Clock.chs.h Fl_Clock_second"
  clockSecond''_ :: ((Ptr ()) -> (IO CInt))

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/Clock.chs.h Fl_Clock_handle"
  menu_Handle''_ :: ((Ptr ()) -> (CInt -> (IO CInt)))