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

GtkGradient is a boxed type that represents a gradient.
It is the result of parsing a
[gradient expression][gtkcssprovider-gradients].
To obtain the gradient represented by a GtkGradient, it has to
be resolved with gtk_gradient_resolve(), which replaces all
symbolic color references by the colors they refer to (in a given
context) and constructs a #cairo_pattern_t value.

It is not normally necessary to deal directly with #GtkGradients,
since they are mostly used behind the scenes by #GtkStyleContext and
#GtkCssProvider.

#GtkGradient is deprecated. It was used internally by GTK’s CSS engine
to represent gradients. As its handling is not conforming to modern
web standards, it is not used anymore. If you want to use gradients in
your own code, please use Cairo directly.
-}

module GI.Gtk.Structs.Gradient
    ( 

-- * Exported types
    Gradient(..)                            ,
    noGradient                              ,


 -- * Methods
-- ** gradientAddColorStop
    gradientAddColorStop                    ,


-- ** gradientNewLinear
    gradientNewLinear                       ,


-- ** gradientNewRadial
    gradientNewRadial                       ,


-- ** gradientRef
    gradientRef                             ,


-- ** gradientResolve
    gradientResolve                         ,


-- ** gradientResolveForContext
    gradientResolveForContext               ,


-- ** gradientToString
    gradientToString                        ,


-- ** gradientUnref
    gradientUnref                           ,




    ) where

import Prelude ()
import Data.GI.Base.ShortPrelude

import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map

import GI.Gtk.Types
import GI.Gtk.Callbacks
import qualified GI.Cairo as Cairo

newtype Gradient = Gradient (ForeignPtr Gradient)
foreign import ccall "gtk_gradient_get_type" c_gtk_gradient_get_type :: 
    IO GType

instance BoxedObject Gradient where
    boxedType _ = c_gtk_gradient_get_type

noGradient :: Maybe Gradient
noGradient = Nothing

-- method Gradient::new_linear
-- method type : Constructor
-- Args : [Arg {argName = "x0", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "y0", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "x1", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "y1", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "x0", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "y0", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "x1", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "y1", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Gtk" "Gradient"
-- throws : False
-- Skip return : False

foreign import ccall "gtk_gradient_new_linear" gtk_gradient_new_linear :: 
    CDouble ->                              -- x0 : TBasicType TDouble
    CDouble ->                              -- y0 : TBasicType TDouble
    CDouble ->                              -- x1 : TBasicType TDouble
    CDouble ->                              -- y1 : TBasicType TDouble
    IO (Ptr Gradient)

{-# DEPRECATED gradientNewLinear ["(Since version 3.8)","#GtkGradient is deprecated."]#-}
gradientNewLinear ::
    (MonadIO m) =>
    Double ->                               -- x0
    Double ->                               -- y0
    Double ->                               -- x1
    Double ->                               -- y1
    m Gradient
gradientNewLinear x0 y0 x1 y1 = liftIO $ do
    let x0' = realToFrac x0
    let y0' = realToFrac y0
    let x1' = realToFrac x1
    let y1' = realToFrac y1
    result <- gtk_gradient_new_linear x0' y0' x1' y1'
    checkUnexpectedReturnNULL "gtk_gradient_new_linear" result
    result' <- (wrapBoxed Gradient) result
    return result'

-- method Gradient::new_radial
-- method type : Constructor
-- Args : [Arg {argName = "x0", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "y0", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "radius0", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "x1", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "y1", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "radius1", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "x0", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "y0", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "radius0", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "x1", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "y1", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "radius1", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Gtk" "Gradient"
-- throws : False
-- Skip return : False

foreign import ccall "gtk_gradient_new_radial" gtk_gradient_new_radial :: 
    CDouble ->                              -- x0 : TBasicType TDouble
    CDouble ->                              -- y0 : TBasicType TDouble
    CDouble ->                              -- radius0 : TBasicType TDouble
    CDouble ->                              -- x1 : TBasicType TDouble
    CDouble ->                              -- y1 : TBasicType TDouble
    CDouble ->                              -- radius1 : TBasicType TDouble
    IO (Ptr Gradient)

{-# DEPRECATED gradientNewRadial ["(Since version 3.8)","#GtkGradient is deprecated."]#-}
gradientNewRadial ::
    (MonadIO m) =>
    Double ->                               -- x0
    Double ->                               -- y0
    Double ->                               -- radius0
    Double ->                               -- x1
    Double ->                               -- y1
    Double ->                               -- radius1
    m Gradient
gradientNewRadial x0 y0 radius0 x1 y1 radius1 = liftIO $ do
    let x0' = realToFrac x0
    let y0' = realToFrac y0
    let radius0' = realToFrac radius0
    let x1' = realToFrac x1
    let y1' = realToFrac y1
    let radius1' = realToFrac radius1
    result <- gtk_gradient_new_radial x0' y0' radius0' x1' y1' radius1'
    checkUnexpectedReturnNULL "gtk_gradient_new_radial" result
    result' <- (wrapBoxed Gradient) result
    return result'

-- method Gradient::add_color_stop
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gtk" "Gradient", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "offset", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "color", argType = TInterface "Gtk" "SymbolicColor", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gtk" "Gradient", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "offset", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "color", argType = TInterface "Gtk" "SymbolicColor", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "gtk_gradient_add_color_stop" gtk_gradient_add_color_stop :: 
    Ptr Gradient ->                         -- _obj : TInterface "Gtk" "Gradient"
    CDouble ->                              -- offset : TBasicType TDouble
    Ptr SymbolicColor ->                    -- color : TInterface "Gtk" "SymbolicColor"
    IO ()

{-# DEPRECATED gradientAddColorStop ["(Since version 3.8)","#GtkGradient is deprecated."]#-}
gradientAddColorStop ::
    (MonadIO m) =>
    Gradient ->                             -- _obj
    Double ->                               -- offset
    SymbolicColor ->                        -- color
    m ()
gradientAddColorStop _obj offset color = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    let offset' = realToFrac offset
    let color' = unsafeManagedPtrGetPtr color
    gtk_gradient_add_color_stop _obj' offset' color'
    touchManagedPtr _obj
    touchManagedPtr color
    return ()

-- method Gradient::ref
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gtk" "Gradient", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gtk" "Gradient", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Gtk" "Gradient"
-- throws : False
-- Skip return : False

foreign import ccall "gtk_gradient_ref" gtk_gradient_ref :: 
    Ptr Gradient ->                         -- _obj : TInterface "Gtk" "Gradient"
    IO (Ptr Gradient)

{-# DEPRECATED gradientRef ["(Since version 3.8)","#GtkGradient is deprecated."]#-}
gradientRef ::
    (MonadIO m) =>
    Gradient ->                             -- _obj
    m Gradient
gradientRef _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- gtk_gradient_ref _obj'
    checkUnexpectedReturnNULL "gtk_gradient_ref" result
    result' <- (wrapBoxed Gradient) result
    touchManagedPtr _obj
    return result'

-- method Gradient::resolve
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gtk" "Gradient", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "props", argType = TInterface "Gtk" "StyleProperties", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "resolved_gradient", argType = TInterface "cairo" "Pattern", direction = DirectionOut, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferEverything}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gtk" "Gradient", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "props", argType = TInterface "Gtk" "StyleProperties", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TBoolean
-- throws : False
-- Skip return : False

foreign import ccall "gtk_gradient_resolve" gtk_gradient_resolve :: 
    Ptr Gradient ->                         -- _obj : TInterface "Gtk" "Gradient"
    Ptr StyleProperties ->                  -- props : TInterface "Gtk" "StyleProperties"
    Ptr (Ptr Cairo.Pattern) ->              -- resolved_gradient : TInterface "cairo" "Pattern"
    IO CInt

{-# DEPRECATED gradientResolve ["(Since version 3.8)","#GtkGradient is deprecated."]#-}
gradientResolve ::
    (MonadIO m, StylePropertiesK a) =>
    Gradient ->                             -- _obj
    a ->                                    -- props
    m (Bool,Cairo.Pattern)
gradientResolve _obj props = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    let props' = unsafeManagedPtrCastPtr props
    resolved_gradient <- allocMem :: IO (Ptr (Ptr Cairo.Pattern))
    result <- gtk_gradient_resolve _obj' props' resolved_gradient
    let result' = (/= 0) result
    resolved_gradient' <- peek resolved_gradient
    resolved_gradient'' <- (wrapBoxed Cairo.Pattern) resolved_gradient'
    touchManagedPtr _obj
    touchManagedPtr props
    freeMem resolved_gradient
    return (result', resolved_gradient'')

-- method Gradient::resolve_for_context
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gtk" "Gradient", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "context", argType = TInterface "Gtk" "StyleContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gtk" "Gradient", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "context", argType = TInterface "Gtk" "StyleContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "cairo" "Pattern"
-- throws : False
-- Skip return : False

foreign import ccall "gtk_gradient_resolve_for_context" gtk_gradient_resolve_for_context :: 
    Ptr Gradient ->                         -- _obj : TInterface "Gtk" "Gradient"
    Ptr StyleContext ->                     -- context : TInterface "Gtk" "StyleContext"
    IO (Ptr Cairo.Pattern)


gradientResolveForContext ::
    (MonadIO m, StyleContextK a) =>
    Gradient ->                             -- _obj
    a ->                                    -- context
    m Cairo.Pattern
gradientResolveForContext _obj context = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    let context' = unsafeManagedPtrCastPtr context
    result <- gtk_gradient_resolve_for_context _obj' context'
    checkUnexpectedReturnNULL "gtk_gradient_resolve_for_context" result
    result' <- (wrapBoxed Cairo.Pattern) result
    touchManagedPtr _obj
    touchManagedPtr context
    return result'

-- method Gradient::to_string
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gtk" "Gradient", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gtk" "Gradient", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUTF8
-- throws : False
-- Skip return : False

foreign import ccall "gtk_gradient_to_string" gtk_gradient_to_string :: 
    Ptr Gradient ->                         -- _obj : TInterface "Gtk" "Gradient"
    IO CString

{-# DEPRECATED gradientToString ["(Since version 3.8)","#GtkGradient is deprecated."]#-}
gradientToString ::
    (MonadIO m) =>
    Gradient ->                             -- _obj
    m T.Text
gradientToString _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- gtk_gradient_to_string _obj'
    checkUnexpectedReturnNULL "gtk_gradient_to_string" result
    result' <- cstringToText result
    freeMem result
    touchManagedPtr _obj
    return result'

-- method Gradient::unref
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gtk" "Gradient", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gtk" "Gradient", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "gtk_gradient_unref" gtk_gradient_unref :: 
    Ptr Gradient ->                         -- _obj : TInterface "Gtk" "Gradient"
    IO ()

{-# DEPRECATED gradientUnref ["(Since version 3.8)","#GtkGradient is deprecated."]#-}
gradientUnref ::
    (MonadIO m) =>
    Gradient ->                             -- _obj
    m ()
gradientUnref _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    gtk_gradient_unref _obj'
    touchManagedPtr _obj
    return ()