{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)

A 'GI.Poppler.Structs.Color.Color' describes a RGB color. Color components
are values between 0 and 65535
-}

module GI.Poppler.Structs.Color
    ( 

-- * Exported types
    Color(..)                               ,
    newZeroColor                            ,
    noColor                                 ,


 -- * Methods
-- ** copy #method:copy#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    ColorCopyMethodInfo                     ,
#endif
    colorCopy                               ,


-- ** free #method:free#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    ColorFreeMethodInfo                     ,
#endif
    colorFree                               ,


-- ** new #method:new#
    colorNew                                ,




 -- * Properties
-- ** blue #attr:blue#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    color_blue                              ,
#endif
    getColorBlue                            ,
    setColorBlue                            ,


-- ** green #attr:green#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    color_green                             ,
#endif
    getColorGreen                           ,
    setColorGreen                           ,


-- ** red #attr:red#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    color_red                               ,
#endif
    getColorRed                             ,
    setColorRed                             ,




    ) where

import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P

import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP


newtype Color = Color (ManagedPtr Color)
foreign import ccall "poppler_color_get_type" c_poppler_color_get_type :: 
    IO GType

instance BoxedObject Color where
    boxedType _ = c_poppler_color_get_type

-- | Construct a `Color` struct initialized to zero.
newZeroColor :: MonadIO m => m Color
newZeroColor = liftIO $ callocBoxedBytes 6 >>= wrapBoxed Color

instance tag ~ 'AttrSet => Constructible Color tag where
    new _ attrs = do
        o <- newZeroColor
        GI.Attributes.set o attrs
        return o


noColor :: Maybe Color
noColor = Nothing

getColorRed :: MonadIO m => Color -> m Word16
getColorRed s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 0) :: IO Word16
    return val

setColorRed :: MonadIO m => Color -> Word16 -> m ()
setColorRed s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 0) (val :: Word16)

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data ColorRedFieldInfo
instance AttrInfo ColorRedFieldInfo where
    type AttrAllowedOps ColorRedFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint ColorRedFieldInfo = (~) Word16
    type AttrBaseTypeConstraint ColorRedFieldInfo = (~) Color
    type AttrGetType ColorRedFieldInfo = Word16
    type AttrLabel ColorRedFieldInfo = "red"
    type AttrOrigin ColorRedFieldInfo = Color
    attrGet _ = getColorRed
    attrSet _ = setColorRed
    attrConstruct = undefined
    attrClear _ = undefined

color_red :: AttrLabelProxy "red"
color_red = AttrLabelProxy

#endif


getColorGreen :: MonadIO m => Color -> m Word16
getColorGreen s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 2) :: IO Word16
    return val

setColorGreen :: MonadIO m => Color -> Word16 -> m ()
setColorGreen s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 2) (val :: Word16)

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data ColorGreenFieldInfo
instance AttrInfo ColorGreenFieldInfo where
    type AttrAllowedOps ColorGreenFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint ColorGreenFieldInfo = (~) Word16
    type AttrBaseTypeConstraint ColorGreenFieldInfo = (~) Color
    type AttrGetType ColorGreenFieldInfo = Word16
    type AttrLabel ColorGreenFieldInfo = "green"
    type AttrOrigin ColorGreenFieldInfo = Color
    attrGet _ = getColorGreen
    attrSet _ = setColorGreen
    attrConstruct = undefined
    attrClear _ = undefined

color_green :: AttrLabelProxy "green"
color_green = AttrLabelProxy

#endif


getColorBlue :: MonadIO m => Color -> m Word16
getColorBlue s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 4) :: IO Word16
    return val

setColorBlue :: MonadIO m => Color -> Word16 -> m ()
setColorBlue s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 4) (val :: Word16)

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data ColorBlueFieldInfo
instance AttrInfo ColorBlueFieldInfo where
    type AttrAllowedOps ColorBlueFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint ColorBlueFieldInfo = (~) Word16
    type AttrBaseTypeConstraint ColorBlueFieldInfo = (~) Color
    type AttrGetType ColorBlueFieldInfo = Word16
    type AttrLabel ColorBlueFieldInfo = "blue"
    type AttrOrigin ColorBlueFieldInfo = Color
    attrGet _ = getColorBlue
    attrSet _ = setColorBlue
    attrConstruct = undefined
    attrClear _ = undefined

color_blue :: AttrLabelProxy "blue"
color_blue = AttrLabelProxy

#endif



#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
instance O.HasAttributeList Color
type instance O.AttributeList Color = ColorAttributeList
type ColorAttributeList = ('[ '("red", ColorRedFieldInfo), '("green", ColorGreenFieldInfo), '("blue", ColorBlueFieldInfo)] :: [(Symbol, *)])
#endif

-- method Color::new
-- method type : Constructor
-- Args : []
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Poppler", name = "Color"}))
-- throws : False
-- Skip return : False

foreign import ccall "poppler_color_new" poppler_color_new :: 
    IO (Ptr Color)

{- |
Creates a new 'GI.Poppler.Structs.Color.Color'
-}
colorNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m Color
    {- ^ __Returns:__ a new 'GI.Poppler.Structs.Color.Color', use 'GI.Poppler.Structs.Color.colorFree' to free it -}
colorNew  = liftIO $ do
    result <- poppler_color_new
    checkUnexpectedReturnNULL "colorNew" result
    result' <- (wrapBoxed Color) result
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
#endif

-- method Color::copy
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "color", argType = TInterface (Name {namespace = "Poppler", name = "Color"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #PopplerColor to copy", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Poppler", name = "Color"}))
-- throws : False
-- Skip return : False

foreign import ccall "poppler_color_copy" poppler_color_copy :: 
    Ptr Color ->                            -- color : TInterface (Name {namespace = "Poppler", name = "Color"})
    IO (Ptr Color)

{- |
Creates a copy of /@color@/
-}
colorCopy ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Color
    {- ^ /@color@/: a 'GI.Poppler.Structs.Color.Color' to copy -}
    -> m Color
    {- ^ __Returns:__ a new allocated copy of /@color@/ -}
colorCopy color = liftIO $ do
    color' <- unsafeManagedPtrGetPtr color
    result <- poppler_color_copy color'
    checkUnexpectedReturnNULL "colorCopy" result
    result' <- (wrapBoxed Color) result
    touchManagedPtr color
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data ColorCopyMethodInfo
instance (signature ~ (m Color), MonadIO m) => O.MethodInfo ColorCopyMethodInfo Color signature where
    overloadedMethod _ = colorCopy

#endif

-- method Color::free
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "color", argType = TInterface (Name {namespace = "Poppler", name = "Color"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #PopplerColor", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "poppler_color_free" poppler_color_free :: 
    Ptr Color ->                            -- color : TInterface (Name {namespace = "Poppler", name = "Color"})
    IO ()

{- |
Frees the given 'GI.Poppler.Structs.Color.Color'
-}
colorFree ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Color
    {- ^ /@color@/: a 'GI.Poppler.Structs.Color.Color' -}
    -> m ()
colorFree color = liftIO $ do
    color' <- unsafeManagedPtrGetPtr color
    poppler_color_free color'
    touchManagedPtr color
    return ()

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data ColorFreeMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo ColorFreeMethodInfo Color signature where
    overloadedMethod _ = colorFree

#endif

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
type family ResolveColorMethod (t :: Symbol) (o :: *) :: * where
    ResolveColorMethod "copy" o = ColorCopyMethodInfo
    ResolveColorMethod "free" o = ColorFreeMethodInfo
    ResolveColorMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveColorMethod t Color, O.MethodInfo info Color p) => O.IsLabelProxy t (Color -> p) where
    fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveColorMethod t Color, O.MethodInfo info Color p) => O.IsLabel t (Color -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#else
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif
#endif

#endif