-- GENERATED by C->Haskell Compiler, version 0.28.1 Switcheroo, 1 April 2016 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "src/Graphics/UI/FLTK/LowLevel/Counter.chs" #-}
{-# LANGUAGE CPP, ExistentialQuantification, TypeSynonymInstances, FlexibleInstances, MultiParamTypeClasses, FlexibleContexts, ScopedTypeVariables #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Graphics.UI.FLTK.LowLevel.Counter
    (
     -- * Constructor
     counterNew,
     CounterType(..)
     -- * Hierarchy
     --
     -- $hierarchy

     -- * Functions
     --
     -- $Counterfunctions
     --
    )
where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Ptr as C2HSImp






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 qualified Data.Text as T
data CounterType = NormalCounterType
                 | SimpleCounterType
  deriving (Show,Eq)
instance Enum CounterType where
  succ NormalCounterType = SimpleCounterType
  succ SimpleCounterType = error "CounterType.succ: SimpleCounterType has no successor"

  pred SimpleCounterType = NormalCounterType
  pred NormalCounterType = error "CounterType.pred: NormalCounterType 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 SimpleCounterType

  fromEnum NormalCounterType = 0
  fromEnum SimpleCounterType = 1

  toEnum 0 = NormalCounterType
  toEnum 1 = SimpleCounterType
  toEnum unmatched = error ("CounterType.toEnum: Cannot match " ++ show unmatched)

{-# LINE 35 "src/Graphics/UI/FLTK/LowLevel/Counter.chs" #-}

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

{-# LINE 36 "src/Graphics/UI/FLTK/LowLevel/Counter.chs" #-}

counterNewWithLabel' :: (Int) -> (Int) -> (Int) -> (Int) -> (T.Text) -> IO ((Ptr ()))
counterNewWithLabel' 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 
  let {a5' = unsafeToCString a5} in 
  counterNewWithLabel''_ a1' a2' a3' a4' a5' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 37 "src/Graphics/UI/FLTK/LowLevel/Counter.chs" #-}

counterNew :: Rectangle -> Maybe T.Text -> IO (Ref Counter)
counterNew rectangle l'=
    let (x_pos, y_pos, width, height) = fromRectangle rectangle
    in case l' of
        Nothing -> counterNew' x_pos y_pos width height >>=
                             toRef
        Just l -> counterNewWithLabel' x_pos y_pos width height l >>=
                               toRef

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

{-# LINE 47 "src/Graphics/UI/FLTK/LowLevel/Counter.chs" #-}

instance (impl ~ (IO ())) => Op (Destroy ()) Counter orig impl where
  runOp _ _ win = swapRef win $ \winPtr -> do
    counterDestroy' winPtr
    return nullPtr

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

{-# LINE 53 "src/Graphics/UI/FLTK/LowLevel/Counter.chs" #-}

instance (impl ~ (Event -> IO (Either UnknownEvent ()))) => Op (Handle ()) Counter orig impl where
  runOp _ _ counter event = withRef counter (\p -> counterHandle' p (fromIntegral . fromEnum $ event)) >>= return . successOrUnknownEvent
lstep' :: (Ptr ()) -> (Double) -> IO ()
lstep' a1 a2 =
  let {a1' = id a1} in 
  let {a2' = realToFrac a2} in 
  lstep''_ a1' a2' >>
  return ()

{-# LINE 56 "src/Graphics/UI/FLTK/LowLevel/Counter.chs" #-}

instance (impl ~ (Double ->  IO ())) => Op (SetLstep ()) Counter orig impl where
  runOp _ _ counter lstep = withRef counter $ \counterPtr -> lstep' counterPtr lstep
setTextfont' :: (Ptr ()) -> (Font) -> IO ()
setTextfont' a1 a2 =
  let {a1' = id a1} in 
  let {a2' = cFromFont a2} in 
  setTextfont''_ a1' a2' >>
  return ()

{-# LINE 59 "src/Graphics/UI/FLTK/LowLevel/Counter.chs" #-}

instance (impl ~ (Font ->  IO ())) => Op (SetTextfont ()) Counter orig impl where
  runOp _ _ counter text = withRef counter $ \counterPtr -> setTextfont' counterPtr text
textfont' :: (Ptr ()) -> IO ((Font))
textfont' a1 =
  let {a1' = id a1} in 
  textfont''_ a1' >>= \res ->
  let {res' = cToFont res} in
  return (res')

{-# LINE 62 "src/Graphics/UI/FLTK/LowLevel/Counter.chs" #-}

instance (impl ~ ( IO (Font))) => Op (GetTextfont ()) Counter orig impl where
  runOp _ _ counter = withRef counter $ \counterPtr -> textfont' counterPtr
setTextsize' :: (Ptr ()) -> (CInt) -> IO ()
setTextsize' a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  setTextsize''_ a1' a2' >>
  return ()

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

instance (impl ~ (FontSize ->  IO ())) => Op (SetTextsize ()) Counter orig impl where
  runOp _ _ counter (FontSize text) = withRef counter $ \counterPtr -> setTextsize' counterPtr text
textsize' :: (Ptr ()) -> IO ((CInt))
textsize' a1 =
  let {a1' = id a1} in 
  textsize''_ a1' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 68 "src/Graphics/UI/FLTK/LowLevel/Counter.chs" #-}

instance (impl ~ ( IO (FontSize))) => Op (GetTextsize ()) Counter orig impl where
  runOp _ _ counter = withRef counter $ \counterPtr -> textsize' counterPtr >>= return . FontSize
setTextcolor' :: (Ptr ()) -> (Color) -> IO ()
setTextcolor' a1 a2 =
  let {a1' = id a1} in 
  let {a2' = cFromColor a2} in 
  setTextcolor''_ a1' a2' >>
  return ()

{-# LINE 71 "src/Graphics/UI/FLTK/LowLevel/Counter.chs" #-}

instance (impl ~ (Color ->  IO ())) => Op (SetTextcolor ()) Counter orig impl where
  runOp _ _ counter text = withRef counter $ \counterPtr -> setTextcolor' counterPtr text
textcolor' :: (Ptr ()) -> IO ((Color))
textcolor' a1 =
  let {a1' = id a1} in 
  textcolor''_ a1' >>= \res ->
  let {res' = cToColor res} in
  return (res')

{-# LINE 74 "src/Graphics/UI/FLTK/LowLevel/Counter.chs" #-}

instance (impl ~ ( IO (Color))) => Op (GetTextcolor ()) Counter orig impl where
  runOp _ _ counter = withRef counter $ \counterPtr -> textcolor' counterPtr
setType' :: (Ptr ()) -> (Word8) -> IO ((()))
setType' a1 a2 =
  let {a1' = id a1} in 
  let {a2' = fromIntegral a2} in 
  setType''_ a1' a2' >>= \res ->
  let {res' = supressWarningAboutRes res} in
  return (res')

{-# LINE 77 "src/Graphics/UI/FLTK/LowLevel/Counter.chs" #-}

instance (impl ~ (CounterType ->  IO ())) => Op (SetType ()) Counter orig impl where
  runOp _ _ widget t = withRef widget $ \widgetPtr -> setType' widgetPtr (fromInteger $ toInteger $ fromEnum t)
type' :: (Ptr ()) -> IO ((Word8))
type' a1 =
  let {a1' = id a1} in 
  type''_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

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

instance (impl ~ IO (CounterType)) => Op (GetType_ ()) Counter orig impl where
  runOp _ _ widget = withRef widget $ \widgetPtr -> type' widgetPtr >>= return . toEnum . fromInteger . toInteger

-- $Counterfunctions
--
-- @
-- destroy :: 'Ref' 'Counter' -> 'IO' ()
--
-- getTextcolor :: 'Ref' 'Counter' -> 'IO' 'Color'
--
-- getTextfont :: 'Ref' 'Counter' -> 'IO' 'Font'
--
-- getTextsize :: 'Ref' 'Counter' -> 'IO' 'FontSize'
--
-- handle :: 'Ref' 'Counter' -> ('Event' -> 'IO' ('Either' 'UnknownEvent' ()))
--
-- setLstep :: 'Ref' 'Counter' -> 'Double' -> 'IO' ()
--
-- setTextcolor :: 'Ref' 'Counter' -> 'Color' -> 'IO' ()
--
-- setTextfont :: 'Ref' 'Counter' -> 'Font' -> 'IO' ()
--
-- setTextsize :: 'Ref' 'Counter' -> 'FontSize' -> 'IO' ()
--
-- @

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

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/Counter.chs.h Fl_Counter_New"
  counterNew''_ :: (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (IO (C2HSImp.Ptr ()))))))

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/Counter.chs.h Fl_Counter_New_WithLabel"
  counterNewWithLabel''_ :: (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr C2HSImp.CChar) -> (IO (C2HSImp.Ptr ())))))))

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/Counter.chs.h Fl_Counter_Destroy"
  counterDestroy''_ :: ((C2HSImp.Ptr ()) -> (IO ()))

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/Counter.chs.h Fl_Counter_handle"
  counterHandle''_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/Counter.chs.h Fl_Counter_lstep"
  lstep''_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CDouble -> (IO ())))

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/Counter.chs.h Fl_Counter_set_textfont"
  setTextfont''_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CInt -> (IO ())))

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/Counter.chs.h Fl_Counter_textfont"
  textfont''_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/Counter.chs.h Fl_Counter_set_textsize"
  setTextsize''_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CInt -> (IO ())))

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/Counter.chs.h Fl_Counter_textsize"
  textsize''_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/Counter.chs.h Fl_Counter_set_textcolor"
  setTextcolor''_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> (IO ())))

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/Counter.chs.h Fl_Counter_textcolor"
  textcolor''_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUInt))

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/Counter.chs.h Fl_Widget_set_type"
  setType''_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CUChar -> (IO ())))

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/Counter.chs.h Fl_Widget_type"
  type''_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUChar))