-- GENERATED by C->Haskell Compiler, version 0.28.6 Switcheroo, 25 November 2017 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}
{-# LANGUAGE CPP, ExistentialQuantification, TypeSynonymInstances, FlexibleInstances, MultiParamTypeClasses, FlexibleContexts, ScopedTypeVariables #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Graphics.UI.FLTK.LowLevel.ColorChooser
    (
     -- * Constructor
     colorChooserNew,
     colorChooserCustom,
     rgb2Hsv,
     hsv2Rgb,
     flcColorChooser,
     CustomColorChooserFuncs(..)
     -- * Hierarchy
     --
     -- $hierarchy

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





import C2HS hiding (cFromEnum, cFromBool, cToBool,cToEnum)
import Graphics.UI.FLTK.LowLevel.Widget

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
import Data.List
import Graphics.UI.FLTK.LowLevel.Fl_Enumerations
import Control.Applicative

data CustomColorChooserFuncs a =
  CustomColorChooserFuncs
  {
    getModeCustom :: Ref a -> IO ColorChooserMode
  , setModeCustom :: Ref a -> ColorChooserMode -> IO ()
  , hueCustom :: Ref a -> IO Between0And6
  , saturationCustom :: Ref a -> IO Between0And1
  , valueCustom :: Ref a -> IO Between0And1
  , rCustom :: Ref a -> IO Between0And1
  , gCustom :: Ref a -> IO Between0And1
  , bCustom :: Ref a -> IO Between0And1
  , hsvCustom :: Ref a -> (Between0And6,Between0And1,Between0And1) -> IO Int
  , rgbCustom :: Ref a -> (Between0And1,Between0And1,Between0And1) -> IO Int
  }

toGetBetween0And6Prim :: (Ref a -> IO Between0And6) -> IO (FunPtr GetDoublePrim)
toGetBetween0And6Prim f =
  mkGetDouble (\ptr -> do
                  pp <- wrapNonNull ptr "Null pointer: toGetBetween0And6Prim"
                  (Between0And6 res) <- f (castTo (wrapInRef pp))
                  return (realToFrac res))

toGetBetween0And1Prim :: (Ref a -> IO Between0And1) -> IO (FunPtr GetDoublePrim)
toGetBetween0And1Prim f =
  mkGetDouble (\ptr -> do
                  pp <- wrapNonNull ptr "Null pointer: toGetBetween0And1Prim"
                  (Between0And1 res) <- f (castTo (wrapInRef pp))
                  return (realToFrac res))

toGetModePrim :: (Ref a -> IO ColorChooserMode) -> IO (FunPtr GetIntPrim)
toGetModePrim f =
  mkGetInt (\ptr -> do
               pp <- wrapNonNull ptr "Null pointer: toGetModePrim"
               mode <- f (castTo (wrapInRef pp))
               return (fromIntegral (fromEnum mode)))

toSetModePrim :: (Ref a -> ColorChooserMode -> IO ()) -> IO (FunPtr SetIntPrim)
toSetModePrim f =
  mkSetInt (\ptr m -> do
               pp <- wrapNonNull ptr "Null pointer: toSetModePrim"
               f (castTo (wrapInRef pp)) (cToEnum (fromIntegral m)))

toHsvPrim :: (Ref a -> (Between0And6,Between0And1,Between0And1) -> IO Int)-> IO (FunPtr ColorSetPrim)
toHsvPrim f =
  mkColorSetPrim (\ptr (CDouble h) (CDouble s) (CDouble v) -> do
                     pp <- wrapNonNull ptr "Null pointer: toHsvPrim"
                     ret <- f (castTo (wrapInRef pp)) (Between0And6 h,Between0And1 s,Between0And1 v)
                     return (fromIntegral ret))

toRgbPrim :: (Ref a -> (Between0And1,Between0And1,Between0And1) -> IO Int) -> IO (FunPtr ColorSetPrim)
toRgbPrim f =
  mkColorSetPrim (\ptr (CDouble r) (CDouble g) (CDouble b) -> do
                     pp <- wrapNonNull ptr "Null pointer: toRgbPrim"
                     ret <- f (castTo (wrapInRef pp)) (Between0And1 r,Between0And1 g,Between0And1 b)
                     return (fromIntegral ret))

fillCustomColorChooserFunctionStruct :: forall a. (Parent a ColorChooser) => CustomColorChooserFuncs a -> IO (Ptr ())
fillCustomColorChooserFunctionStruct funcs = do
  structPtr <- mallocBytes 80
{-# LINE 94 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

  toGetModePrim (getModeCustom funcs) >>= (\ptr val -> do {C2HSImp.pokeByteOff ptr 0 (val :: (C2HSImp.FunPtr ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))))}) structPtr
  toSetModePrim (setModeCustom funcs) >>= (\ptr val -> do {C2HSImp.pokeByteOff ptr 8 (val :: (C2HSImp.FunPtr ((C2HSImp.Ptr ()) -> (C2HSImp.CInt -> (IO ())))))}) structPtr
  toGetBetween0And6Prim (hueCustom funcs) >>= (\ptr val -> do {C2HSImp.pokeByteOff ptr 16 (val :: (C2HSImp.FunPtr ((C2HSImp.Ptr ()) -> (IO C2HSImp.CDouble))))}) structPtr
  toGetBetween0And1Prim (saturationCustom funcs) >>= (\ptr val -> do {C2HSImp.pokeByteOff ptr 24 (val :: (C2HSImp.FunPtr ((C2HSImp.Ptr ()) -> (IO C2HSImp.CDouble))))}) structPtr
  toGetBetween0And1Prim (valueCustom funcs) >>= (\ptr val -> do {C2HSImp.pokeByteOff ptr 32 (val :: (C2HSImp.FunPtr ((C2HSImp.Ptr ()) -> (IO C2HSImp.CDouble))))}) structPtr
  toGetBetween0And1Prim (rCustom funcs) >>= (\ptr val -> do {C2HSImp.pokeByteOff ptr 40 (val :: (C2HSImp.FunPtr ((C2HSImp.Ptr ()) -> (IO C2HSImp.CDouble))))}) structPtr
  toGetBetween0And1Prim (gCustom funcs) >>= (\ptr val -> do {C2HSImp.pokeByteOff ptr 48 (val :: (C2HSImp.FunPtr ((C2HSImp.Ptr ()) -> (IO C2HSImp.CDouble))))}) structPtr
  toGetBetween0And1Prim (bCustom funcs) >>= (\ptr val -> do {C2HSImp.pokeByteOff ptr 56 (val :: (C2HSImp.FunPtr ((C2HSImp.Ptr ()) -> (IO C2HSImp.CDouble))))}) structPtr
  toHsvPrim (hsvCustom funcs) >>= (\ptr val -> do {C2HSImp.pokeByteOff ptr 64 (val :: (C2HSImp.FunPtr ((C2HSImp.Ptr ()) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (IO C2HSImp.CInt)))))))}) structPtr
  toRgbPrim (rgbCustom funcs) >>= (\ptr val -> do {C2HSImp.pokeByteOff ptr 72 (val :: (C2HSImp.FunPtr ((C2HSImp.Ptr ()) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (IO C2HSImp.CInt)))))))}) structPtr
  return structPtr

overriddenWidgetNewWithLabel' :: (Int) -> (Int) -> (Int) -> (Int) -> (CString) -> (Ptr ()) -> (Ptr ()) -> IO ((Ptr ()))
overriddenWidgetNewWithLabel' a1 a2 a3 a4 a5 a6 a7 =
  let {a1' = fromIntegral a1} in
  let {a2' = fromIntegral a2} in
  let {a3' = fromIntegral a3} in
  let {a4' = fromIntegral a4} in
  (flip ($)) a5 $ \a5' ->
  let {a6' = id a6} in
  let {a7' = id a7} in
  overriddenWidgetNewWithLabel''_ a1' a2' a3' a4' a5' a6' a7' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 107 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

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

{-# LINE 108 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

colorChooserCustom ::
       Rectangle                         -- ^ The bounds of this ColorChooser
    -> Maybe T.Text                      -- ^ The ColorChooser label
    -> Maybe (Ref ColorChooser -> IO ())           -- ^ Optional custom drawing function
    -> Maybe (CustomColorChooserFuncs ColorChooser)
    -> Maybe (CustomWidgetFuncs ColorChooser)      -- ^ Optional custom widget functions
    -> IO (Ref ColorChooser)
colorChooserCustom rectangle l' draw' colorChooserFuncs' funcs' =
    let (x_pos, y_pos, width, height) = fromRectangle rectangle
    in do
    widgetFuncsPtr <- customWidgetFunctionStruct draw' (maybe defaultCustomWidgetFuncs id funcs')
    colorChooserFuncsPtr <- maybe (return nullPtr) fillCustomColorChooserFunctionStruct colorChooserFuncs'
    colorChooser <-
      maybe
        (overriddenWidgetNew' x_pos y_pos width height (castPtr widgetFuncsPtr) (castPtr colorChooserFuncsPtr))
        (\l -> copyTextToCString l >>= \l' -> overriddenWidgetNewWithLabel' x_pos y_pos width height l' (castPtr widgetFuncsPtr) (castPtr colorChooserFuncsPtr))
        l'
    ref <- toRef colorChooser
    setFlag ref WidgetFlagCopiedLabel
    setFlag ref WidgetFlagCopiedTooltip
    return ref

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

{-# LINE 131 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

colorchooserNewWithLabel' :: (Int) -> (Int) -> (Int) -> (Int) -> (CString) -> IO ((Ptr ()))
colorchooserNewWithLabel' 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
  (flip ($)) a5 $ \a5' ->
  colorchooserNewWithLabel''_ a1' a2' a3' a4' a5' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 132 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

colorChooserNew :: Rectangle -> Maybe T.Text -> IO (Ref ColorChooser)
colorChooserNew rectangle l'=
    let (x_pos, y_pos, width, height) = fromRectangle rectangle
    in case l' of
        Nothing -> colorchooserNew' x_pos y_pos width height >>= toRef
        Just l -> do
          l' <- copyTextToCString l
          ref <- colorchooserNewWithLabel' x_pos y_pos width height l' >>= toRef
          setFlag ref WidgetFlagCopiedLabel
          setFlag ref WidgetFlagCopiedTooltip
          return ref
mode' :: (Ptr ()) -> IO ((Int))
mode' a1 =
  let {a1' = id a1} in
  mode''_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 144 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

instance (impl ~ ( IO (ColorChooserMode))) => Op (GetMode ()) ColorChooser orig impl where
  runOp _ _ color_chooser = withRef color_chooser $ \color_chooserPtr -> mode' color_chooserPtr >>= return . toEnum

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

{-# LINE 148 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

instance (impl ~ (ColorChooserMode ->  IO ())) => Op (SetMode ()) ColorChooser orig impl where
  runOp _ _ color_chooser mode = withRef color_chooser $ \color_chooserPtr -> setMode' color_chooserPtr (fromEnum mode)

hue' :: (Ptr ()) -> IO ((Double))
hue' a1 =
  let {a1' = id a1} in
  hue''_ a1' >>= \res ->
  let {res' = realToFrac res} in
  return (res')

{-# LINE 152 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

instance (impl ~ ( IO (Either OutOfRange Between0And6))) => Op (GetHue ()) ColorChooser orig impl where
  runOp _ _ color_chooser = withRef color_chooser $ \color_chooserPtr -> do
    h'' <- hue' color_chooserPtr
    if ((h'' < 0.0) || (h'' >= 6.0))
     then return (Left OutOfRange)
     else return (Right (Between0And6 h''))


saturation' :: (Ptr ()) -> IO ((Double))
saturation' a1 =
  let {a1' = id a1} in
  saturation''_ a1' >>= \res ->
  let {res' = realToFrac res} in
  return (res')

{-# LINE 161 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

instance (impl ~ ( IO (Either OutOfRange Between0And1))) => Op (GetSaturation ()) ColorChooser orig impl where
  runOp _ _ color_chooser = withRef color_chooser $ \color_chooserPtr -> do
    s'' <- saturation' color_chooserPtr
    if ((s'' < 0.0) || (s'' > 1.0))
     then return (Left OutOfRange)
     else return (Right (Between0And1 s''))

value' :: (Ptr ()) -> IO ((Double))
value' a1 =
  let {a1' = id a1} in
  value''_ a1' >>= \res ->
  let {res' = realToFrac res} in
  return (res')

{-# LINE 169 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

instance (impl ~ ( IO (Either OutOfRange Between0And1))) => Op (GetValue ()) ColorChooser orig impl where
  runOp _ _ color_chooser = withRef color_chooser $ \color_chooserPtr -> do
    v'' <- value' color_chooserPtr
    if ((v'' < 0.0) || (v'' > 1.0))
     then return (Left OutOfRange)
     else return (Right (Between0And1 v''))

r' :: (Ptr ()) -> IO ((Double))
r' a1 =
  let {a1' = id a1} in
  r''_ a1' >>= \res ->
  let {res' = realToFrac res} in
  return (res')

{-# LINE 177 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

instance (impl ~ ( IO (Either OutOfRange Between0And1))) => Op (GetR ()) ColorChooser orig impl where
  runOp _ _ color_chooser = withRef color_chooser $ \color_chooserPtr -> do
    r'' <- r' color_chooserPtr
    if ((r'' < 0.0) || (r'' > 1.0))
     then return (Left OutOfRange)
     else return (Right (Between0And1 r''))

g' :: (Ptr ()) -> IO ((Double))
g' a1 =
  let {a1' = id a1} in
  g''_ a1' >>= \res ->
  let {res' = realToFrac res} in
  return (res')

{-# LINE 185 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

instance (impl ~ ( IO (Either OutOfRange Between0And1))) => Op (GetG ()) ColorChooser orig impl where
  runOp _ _ color_chooser = withRef color_chooser $ \color_chooserPtr -> do
    g'' <- g' color_chooserPtr
    if ((g'' < 0.0) || (g'' > 1.0))
     then return (Left OutOfRange)
     else return (Right (Between0And1 g''))

b' :: (Ptr ()) -> IO ((Double))
b' a1 =
  let {a1' = id a1} in
  b''_ a1' >>= \res ->
  let {res' = realToFrac res} in
  return (res')

{-# LINE 193 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

instance (impl ~ ( IO (Either OutOfRange Between0And1))) => Op (GetB ()) ColorChooser orig impl where
  runOp _ _ color_chooser = withRef color_chooser $ \color_chooserPtr -> do
    b'' <- b' color_chooserPtr
    if ((b'' < 0.0) || (b'' > 1.0))
     then return (Left OutOfRange)
     else return (Right (Between0And1 b''))

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

{-# LINE 201 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

instance (impl ~ ((Between0And6, Between0And1, Between0And1) ->  IO (Either NoChange ()))) => Op (SetHsv ()) ColorChooser orig impl where
  runOp _ _ color_chooser (Between0And6 h'', Between0And1 s'', Between0And1 v'') =
    withRef color_chooser $ \color_chooserPtr -> do
      ret <- hsv' color_chooserPtr h'' s'' v''
      if (ret == 0) then return (Left NoChange) else return (Right ())

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

{-# LINE 208 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

instance (impl ~ ((Between0And1, Between0And1, Between0And1) ->  IO (Either NoChange ()))) => Op (SetRgb ()) ColorChooser orig impl where
  runOp _ _ color_chooser (Between0And1 r'', Between0And1 g'', Between0And1 b'') =
    withRef color_chooser $ \color_chooserPtr -> do
      ret <- rgb' color_chooserPtr r'' g'' b''
      if (ret == 0) then return (Left NoChange) else return (Right ())

instance (impl ~ (IO ( Either OutOfRange (Between0And1, Between0And1, Between0And1)))) => Op (GetRgb()) ColorChooser orig impl where
  runOp _ _ color_chooser = do
    _r <- getR color_chooser
    _g <- getG color_chooser
    _b <- getB color_chooser
    return (do
      r <- _r
      g <- _g
      b <- _b
      return (r,g,b))

instance (impl ~ (IO ( Either OutOfRange (Between0And6, Between0And1, Between0And1)))) => Op (GetHsv()) ColorChooser orig impl where
  runOp _ _ color_chooser = do
    _h <- getHue color_chooser
    _s <- getSaturation color_chooser
    _v <- getValue color_chooser
    return (do
      h <- _h
      s <- _s
      v <- _v
      return (h,s,v))

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

{-# LINE 237 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

instance (impl ~ (  IO ())) => Op (Draw ()) ColorChooser orig impl where
  runOp _ _ colorChooser = withRef colorChooser $ \colorChooserPtr -> draw' colorChooserPtr
drawSuper' :: (Ptr ()) -> IO ((()))
drawSuper' a1 =
  let {a1' = id a1} in
  drawSuper''_ a1' >>= \res ->
  let {res' = supressWarningAboutRes res} in
  return (res')

{-# LINE 240 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

instance (impl ~ ( IO ())) => Op (DrawSuper ()) ColorChooser orig impl where
  runOp _ _ colorChooser = withRef colorChooser $ \colorChooserPtr -> drawSuper' colorChooserPtr
colorChooserHandle' :: (Ptr ()) -> (CInt) -> IO ((Int))
colorChooserHandle' a1 a2 =
  let {a1' = id a1} in
  let {a2' = id a2} in
  colorChooserHandle''_ a1' a2' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 243 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

instance (impl ~ (Event -> IO (Either UnknownEvent ()))) => Op (Handle ()) ColorChooser orig impl where
  runOp _ _ colorChooser event = withRef colorChooser (\p -> colorChooserHandle' p (fromIntegral . fromEnum $ event)) >>= return  . successOrUnknownEvent
handleSuper' :: (Ptr ()) -> (Int) -> IO ((Int))
handleSuper' a1 a2 =
  let {a1' = id a1} in
  let {a2' = fromIntegral a2} in
  handleSuper''_ a1' a2' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 246 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

instance (impl ~ (Event ->  IO (Either UnknownEvent ()))) => Op (HandleSuper ()) ColorChooser orig impl where
  runOp _ _ colorChooser event = withRef colorChooser $ \colorChooserPtr -> handleSuper' colorChooserPtr (fromIntegral (fromEnum event)) >>= return . successOrUnknownEvent
resize' :: (Ptr ()) -> (Int) -> (Int) -> (Int) -> (Int) -> IO ((()))
resize' a1 a2 a3 a4 a5 =
  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
  resize''_ a1' a2' a3' a4' a5' >>= \res ->
  let {res' = supressWarningAboutRes res} in
  return (res')

{-# LINE 249 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

instance (impl ~ (Rectangle -> IO ())) => Op (Resize ()) ColorChooser orig impl where
  runOp _ _ colorChooser rectangle = withRef colorChooser $ \colorChooserPtr -> do
                                 let (x_pos,y_pos,w_pos,h_pos) = fromRectangle rectangle
                                 resize' colorChooserPtr x_pos y_pos w_pos h_pos
resizeSuper' :: (Ptr ()) -> (Int) -> (Int) -> (Int) -> (Int) -> IO ((()))
resizeSuper' a1 a2 a3 a4 a5 =
  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
  resizeSuper''_ a1' a2' a3' a4' a5' >>= \res ->
  let {res' = supressWarningAboutRes res} in
  return (res')

{-# LINE 254 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

instance (impl ~ (Rectangle -> IO ())) => Op (ResizeSuper ()) ColorChooser orig impl where
  runOp _ _ colorChooser rectangle =
    let (x_pos, y_pos, width, height) = fromRectangle rectangle
    in withRef colorChooser $ \colorChooserPtr -> resizeSuper' colorChooserPtr x_pos y_pos width height
hide' :: (Ptr ()) -> IO ()
hide' a1 =
  let {a1' = id a1} in
  hide''_ a1' >>
  return ()

{-# LINE 259 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

instance (impl ~ (  IO ())) => Op (Hide ()) ColorChooser orig impl where
  runOp _ _ colorChooser = withRef colorChooser $ \colorChooserPtr -> hide' colorChooserPtr
hideSuper' :: (Ptr ()) -> IO ((()))
hideSuper' a1 =
  let {a1' = id a1} in
  hideSuper''_ a1' >>= \res ->
  let {res' = supressWarningAboutRes res} in
  return (res')

{-# LINE 262 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

instance (impl ~ ( IO ())) => Op (HideSuper ()) ColorChooser orig impl where
  runOp _ _ colorChooser = withRef colorChooser $ \colorChooserPtr -> hideSuper' colorChooserPtr
show' :: (Ptr ()) -> IO ()
show' a1 =
  let {a1' = id a1} in
  show''_ a1' >>
  return ()

{-# LINE 265 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

instance (impl ~ (  IO ())) => Op (ShowWidget ()) ColorChooser orig impl where
  runOp _ _ colorChooser = withRef colorChooser $ \colorChooserPtr -> show' colorChooserPtr
showSuper' :: (Ptr ()) -> IO ((()))
showSuper' a1 =
  let {a1' = id a1} in
  showSuper''_ a1' >>= \res ->
  let {res' = supressWarningAboutRes res} in
  return (res')

{-# LINE 268 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

instance (impl ~ ( IO ())) => Op (ShowWidgetSuper ()) ColorChooser orig impl where
  runOp _ _ colorChooser = withRef colorChooser $ \colorChooserPtr -> showSuper' colorChooserPtr


hsv2rgb' :: (Double) -> (Double) -> (Double) -> (Ptr CDouble) -> (Ptr CDouble) -> (Ptr CDouble) -> IO ()
hsv2rgb' a1 a2 a3 a4 a5 a6 =
  let {a1' = realToFrac a1} in
  let {a2' = realToFrac a2} in
  let {a3' = realToFrac a3} in
  let {a4' = id a4} in
  let {a5' = id a5} in
  let {a6' = id a6} in
  hsv2rgb''_ a1' a2' a3' a4' a5' a6' >>
  return ()

{-# LINE 273 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

hsv2Rgb :: (Between0And6, Between0And1, Between0And1) ->  IO (Maybe (Between0And1, Between0And1, Between0And1))
hsv2Rgb (Between0And6 h'', Between0And1 s'', Between0And1 v'') =
  alloca $ \rPtr ->
  alloca $ \gPtr ->
  alloca $ \bPtr -> do
    hsv2rgb' h'' s'' v'' rPtr gPtr bPtr
    r'' <- peek rPtr
    g'' <- peek gPtr
    b'' <- peek bPtr
    return (Just (Between0And1 (realToFrac r''),Between0And1 (realToFrac g''),Between0And1 (realToFrac b'')))

rgb2hsv' :: (Double) -> (Double) -> (Double) -> (Ptr CDouble) -> (Ptr CDouble) -> (Ptr CDouble) -> IO ()
rgb2hsv' a1 a2 a3 a4 a5 a6 =
  let {a1' = realToFrac a1} in
  let {a2' = realToFrac a2} in
  let {a3' = realToFrac a3} in
  let {a4' = id a4} in
  let {a5' = id a5} in
  let {a6' = id a6} in
  rgb2hsv''_ a1' a2' a3' a4' a5' a6' >>
  return ()

{-# LINE 285 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

rgb2Hsv :: (Between0And1, Between0And1, Between0And1) ->  IO (Maybe (Between0And6, Between0And1, Between0And1))
rgb2Hsv (Between0And1 h'', Between0And1 s'', Between0And1 v'') =
  alloca $ \hPtr ->
  alloca $ \sPtr ->
  alloca $ \vPtr -> do
    rgb2hsv' h'' s'' v'' hPtr sPtr vPtr
    let (nullPtrs, nonNullPtrs) = partition ((==) nullPtr) [hPtr, sPtr, vPtr]
    if (not (null nullPtrs))
     then mapM_ free nonNullPtrs >> return Nothing
     else do
       h''' <- peek hPtr
       s''' <- peek sPtr
       v''' <- peek vPtr
       return (Just (Between0And6 (realToFrac h'''),Between0And1 (realToFrac s'''),Between0And1 (realToFrac v''')))

flc_color_chooser_with_m' :: (CString) -> (Ptr CDouble) -> (Ptr CDouble) -> (Ptr CDouble) -> (Int) -> IO ((Int))
flc_color_chooser_with_m' a1 a2 a3 a4 a5 =
  (flip ($)) a1 $ \a1' ->
  let {a2' = id a2} in
  let {a3' = id a3} in
  let {a4' = id a4} in
  let {a5' = fromIntegral a5} in
  flc_color_chooser_with_m''_ a1' a2' a3' a4' a5' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 301 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

flc_color_chooser_with_uchar_m' :: (CString) -> (Ptr CUChar) -> (Ptr CUChar) -> (Ptr CUChar) -> (Int) -> IO ((Int))
flc_color_chooser_with_uchar_m' a1 a2 a3 a4 a5 =
  (flip ($)) a1 $ \a1' ->
  let {a2' = id a2} in
  let {a3' = id a3} in
  let {a4' = id a4} in
  let {a5' = fromIntegral a5} in
  flc_color_chooser_with_uchar_m''_ a1' a2' a3' a4' a5' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 302 "src/Graphics/UI/FLTK/LowLevel/ColorChooser.chs" #-}

flcColorChooser :: T.Text ->
                   ColorChooserRGB ->
                   Maybe ColorChooserMode ->
                   IO (Maybe ColorChooserRGB)
flcColorChooser name (Decimals (Between0And1 r'', Between0And1 g'', Between0And1 b'')) mode =
  alloca $ \r''Ptr ->
  alloca $ \g''Ptr ->
  alloca $ \b''Ptr -> do
    poke r''Ptr $ realToFrac r''
    poke g''Ptr $ realToFrac g''
    poke b''Ptr $ realToFrac b''
    ret <- copyTextToCString name >>= \n' -> flc_color_chooser_with_m' n' r''Ptr g''Ptr b''Ptr (maybe (-1) fromEnum mode)
    if (ret == 0)
     then return Nothing
     else do
      newR <- peek r''Ptr
      newG <- peek g''Ptr
      newB <- peek b''Ptr
      return (Just (Decimals
                     (Between0And1 (realToFrac newR),
                      Between0And1 (realToFrac newG),
                      Between0And1 (realToFrac newB))))
flcColorChooser name (Words (r,g,b)) mode =
  alloca $ \r''Ptr ->
  alloca $ \g''Ptr ->
  alloca $ \b''Ptr -> do
    poke r''Ptr (fromIntegral r)
    poke g''Ptr (fromIntegral g)
    poke b''Ptr (fromIntegral b)
    ret <- copyTextToCString name >>= \n' -> flc_color_chooser_with_uchar_m' n' r''Ptr g''Ptr b''Ptr (maybe (-1) fromEnum mode)
    if (ret == 0)
     then return Nothing
     else do
      newR <- peek r''Ptr
      newG <- peek g''Ptr
      newB <- peek b''Ptr
      return (Just (Words ((fromIntegral newR), (fromIntegral newG), (fromIntegral newB))))

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

-- $functions
-- @
-- draw :: 'Ref' 'ColorChooser' -> 'IO' ()
--
-- drawSuper :: 'Ref' 'ColorChooser' -> 'IO' ()
--
-- getB :: 'Ref' 'ColorChooser' -> 'IO' ('Either' 'OutOfRange' 'Between0And1')
--
-- getG :: 'Ref' 'ColorChooser' -> 'IO' ('Either' 'OutOfRange' 'Between0And1')
--
-- getHue :: 'Ref' 'ColorChooser' -> 'IO' ('Either' 'OutOfRange' 'Between0And6')
--
-- getMode :: 'Ref' 'ColorChooser' -> 'IO' ('ColorChooserMode')
--
-- getR :: 'Ref' 'ColorChooser' -> 'IO' ('Either' 'OutOfRange' 'Between0And1')
--
-- getSaturation :: 'Ref' 'ColorChooser' -> 'IO' ('Either' 'OutOfRange' 'Between0And1')
--
-- getValue :: 'Ref' 'ColorChooser' -> 'IO' ('Either' 'OutOfRange' 'Between0And1')
--
-- handle :: 'Ref' 'ColorChooser' -> 'Event' -> 'IO' ('Either' 'UnknownEvent' ())
--
-- handleSuper :: 'Ref' 'ColorChooser' -> 'Event' -> 'IO' ('Either' 'UnknownEvent' ())
--
-- hide :: 'Ref' 'ColorChooser' -> 'IO' ()
--
-- hideSuper :: 'Ref' 'ColorChooser' -> 'IO' ()
--
-- resize :: 'Ref' 'ColorChooser' -> 'Rectangle' -> 'IO' ()
--
-- resizeSuper :: 'Ref' 'ColorChooser' -> 'Rectangle' -> 'IO' ()
--
-- setHsv :: 'Ref' 'ColorChooser' -> ('Between0And6', 'Between0And1', 'Between0And1') -> 'IO' ('Either' 'NoChange' ())
--
-- setMode :: 'Ref' 'ColorChooser' -> 'ColorChooserMode' -> 'IO' ()
--
-- setRgb :: 'Ref' 'ColorChooser' -> ('Between0And1', 'Between0And1', 'Between0And1') -> 'IO' ('Either' 'NoChange' ())
--
-- showWidget :: 'Ref' 'ColorChooser' -> 'IO' ()
--
-- showWidgetSuper :: 'Ref' 'ColorChooser' -> 'IO' ()
--
-- @

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

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

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

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

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

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

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

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

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

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

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

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

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/ColorChooser.chs.h Fl_Color_Chooser_hsv"
  hsv''_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (IO C2HSImp.CInt)))))

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/ColorChooser.chs.h Fl_Color_Chooser_rgb"
  rgb''_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (IO C2HSImp.CInt)))))

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/ColorChooser.chs.h Fl_Color_Chooser_draw"
  draw''_ :: ((C2HSImp.Ptr ()) -> (IO ()))

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/ColorChooser.chs.h Fl_Color_Chooser_draw_super"
  drawSuper''_ :: ((C2HSImp.Ptr ()) -> (IO ()))

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

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

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

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

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/ColorChooser.chs.h Fl_Color_Chooser_hide"
  hide''_ :: ((C2HSImp.Ptr ()) -> (IO ()))

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/ColorChooser.chs.h Fl_Color_Chooser_hide_super"
  hideSuper''_ :: ((C2HSImp.Ptr ()) -> (IO ()))

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/ColorChooser.chs.h Fl_Color_Chooser_show"
  show''_ :: ((C2HSImp.Ptr ()) -> (IO ()))

foreign import ccall safe "Graphics/UI/FLTK/LowLevel/ColorChooser.chs.h Fl_Color_Chooser_show_super"
  showSuper''_ :: ((C2HSImp.Ptr ()) -> (IO ()))

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

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

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

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