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

module GI.Atk.Interfaces.Value
    ( 

-- * Exported types
    Value(..)                               ,
    noValue                                 ,
    ValueK                                  ,


 -- * Methods
-- ** valueGetCurrentValue
    valueGetCurrentValue                    ,


-- ** valueGetIncrement
    valueGetIncrement                       ,


-- ** valueGetMaximumValue
    valueGetMaximumValue                    ,


-- ** valueGetMinimumIncrement
    valueGetMinimumIncrement                ,


-- ** valueGetMinimumValue
    valueGetMinimumValue                    ,


-- ** valueGetRange
    valueGetRange                           ,


-- ** valueGetSubRanges
    valueGetSubRanges                       ,


-- ** valueGetValueAndText
    valueGetValueAndText                    ,


-- ** valueSetCurrentValue
    valueSetCurrentValue                    ,


-- ** valueSetValue
    valueSetValue                           ,




 -- * Signals
-- ** ValueChanged
    ValueValueChangedCallback               ,
    ValueValueChangedCallbackC              ,
    ValueValueChangedSignalInfo             ,
    afterValueValueChanged                  ,
    mkValueValueChangedCallback             ,
    noValueValueChangedCallback             ,
    onValueValueChanged                     ,
    valueValueChangedCallbackWrapper        ,
    valueValueChangedClosure                ,




    ) 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.Atk.Types
import GI.Atk.Callbacks

-- interface Value 

newtype Value = Value (ForeignPtr Value)
noValue :: Maybe Value
noValue = Nothing

-- signal Value::value-changed
type ValueValueChangedCallback =
    Double ->
    T.Text ->
    IO ()

noValueValueChangedCallback :: Maybe ValueValueChangedCallback
noValueValueChangedCallback = Nothing

type ValueValueChangedCallbackC =
    Ptr () ->                               -- object
    CDouble ->
    CString ->
    Ptr () ->                               -- user_data
    IO ()

foreign import ccall "wrapper"
    mkValueValueChangedCallback :: ValueValueChangedCallbackC -> IO (FunPtr ValueValueChangedCallbackC)

valueValueChangedClosure :: ValueValueChangedCallback -> IO Closure
valueValueChangedClosure cb = newCClosure =<< mkValueValueChangedCallback wrapped
    where wrapped = valueValueChangedCallbackWrapper cb

valueValueChangedCallbackWrapper ::
    ValueValueChangedCallback ->
    Ptr () ->
    CDouble ->
    CString ->
    Ptr () ->
    IO ()
valueValueChangedCallbackWrapper _cb _ value text _ = do
    let value' = realToFrac value
    text' <- cstringToText text
    _cb  value' text'

onValueValueChanged :: (GObject a, MonadIO m) => a -> ValueValueChangedCallback -> m SignalHandlerId
onValueValueChanged obj cb = liftIO $ connectValueValueChanged obj cb SignalConnectBefore
afterValueValueChanged :: (GObject a, MonadIO m) => a -> ValueValueChangedCallback -> m SignalHandlerId
afterValueValueChanged obj cb = connectValueValueChanged obj cb SignalConnectAfter

connectValueValueChanged :: (GObject a, MonadIO m) =>
                            a -> ValueValueChangedCallback -> SignalConnectMode -> m SignalHandlerId
connectValueValueChanged obj cb after = liftIO $ do
    cb' <- mkValueValueChangedCallback (valueValueChangedCallbackWrapper cb)
    connectSignalFunPtr obj "value-changed" cb' after

type instance AttributeList Value = ValueAttributeList
type ValueAttributeList = ('[ ] :: [(Symbol, *)])

data ValueValueChangedSignalInfo
instance SignalInfo ValueValueChangedSignalInfo where
    type HaskellCallbackType ValueValueChangedSignalInfo = ValueValueChangedCallback
    connectSignal _ = connectValueValueChanged

type instance SignalList Value = ValueSignalList
type ValueSignalList = ('[ '("value-changed", ValueValueChangedSignalInfo)] :: [(Symbol, *)])

class ForeignPtrNewtype a => ValueK a
instance (ForeignPtrNewtype o, IsDescendantOf Value o) => ValueK o
type instance ParentTypes Value = ValueParentTypes
type ValueParentTypes = '[]

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

foreign import ccall "atk_value_get_current_value" atk_value_get_current_value :: 
    Ptr Value ->                            -- _obj : TInterface "Atk" "Value"
    Ptr GValue ->                           -- value : TInterface "GObject" "Value"
    IO ()

{-# DEPRECATED valueGetCurrentValue ["Since 2.12. Use atk_value_get_value_and_text()","instead."]#-}
valueGetCurrentValue ::
    (MonadIO m, ValueK a) =>
    a ->                                    -- _obj
    GValue ->                               -- value
    m ()
valueGetCurrentValue _obj value = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    let value' = unsafeManagedPtrGetPtr value
    atk_value_get_current_value _obj' value'
    touchManagedPtr _obj
    touchManagedPtr value
    return ()

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

foreign import ccall "atk_value_get_increment" atk_value_get_increment :: 
    Ptr Value ->                            -- _obj : TInterface "Atk" "Value"
    IO CDouble


valueGetIncrement ::
    (MonadIO m, ValueK a) =>
    a ->                                    -- _obj
    m Double
valueGetIncrement _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- atk_value_get_increment _obj'
    let result' = realToFrac result
    touchManagedPtr _obj
    return result'

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

foreign import ccall "atk_value_get_maximum_value" atk_value_get_maximum_value :: 
    Ptr Value ->                            -- _obj : TInterface "Atk" "Value"
    Ptr GValue ->                           -- value : TInterface "GObject" "Value"
    IO ()

{-# DEPRECATED valueGetMaximumValue ["Since 2.12. Use atk_value_get_range() instead."]#-}
valueGetMaximumValue ::
    (MonadIO m, ValueK a) =>
    a ->                                    -- _obj
    GValue ->                               -- value
    m ()
valueGetMaximumValue _obj value = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    let value' = unsafeManagedPtrGetPtr value
    atk_value_get_maximum_value _obj' value'
    touchManagedPtr _obj
    touchManagedPtr value
    return ()

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

foreign import ccall "atk_value_get_minimum_increment" atk_value_get_minimum_increment :: 
    Ptr Value ->                            -- _obj : TInterface "Atk" "Value"
    Ptr GValue ->                           -- value : TInterface "GObject" "Value"
    IO ()

{-# DEPRECATED valueGetMinimumIncrement ["Since 2.12. Use atk_value_get_increment() instead."]#-}
valueGetMinimumIncrement ::
    (MonadIO m, ValueK a) =>
    a ->                                    -- _obj
    GValue ->                               -- value
    m ()
valueGetMinimumIncrement _obj value = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    let value' = unsafeManagedPtrGetPtr value
    atk_value_get_minimum_increment _obj' value'
    touchManagedPtr _obj
    touchManagedPtr value
    return ()

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

foreign import ccall "atk_value_get_minimum_value" atk_value_get_minimum_value :: 
    Ptr Value ->                            -- _obj : TInterface "Atk" "Value"
    Ptr GValue ->                           -- value : TInterface "GObject" "Value"
    IO ()

{-# DEPRECATED valueGetMinimumValue ["Since 2.12. Use atk_value_get_range() instead."]#-}
valueGetMinimumValue ::
    (MonadIO m, ValueK a) =>
    a ->                                    -- _obj
    GValue ->                               -- value
    m ()
valueGetMinimumValue _obj value = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    let value' = unsafeManagedPtrGetPtr value
    atk_value_get_minimum_value _obj' value'
    touchManagedPtr _obj
    touchManagedPtr value
    return ()

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

foreign import ccall "atk_value_get_range" atk_value_get_range :: 
    Ptr Value ->                            -- _obj : TInterface "Atk" "Value"
    IO (Ptr Range)


valueGetRange ::
    (MonadIO m, ValueK a) =>
    a ->                                    -- _obj
    m Range
valueGetRange _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- atk_value_get_range _obj'
    checkUnexpectedReturnNULL "atk_value_get_range" result
    result' <- (wrapBoxed Range) result
    touchManagedPtr _obj
    return result'

-- method Value::get_sub_ranges
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Atk" "Value", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Atk" "Value", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TGSList (TInterface "Atk" "Range")
-- throws : False
-- Skip return : False

foreign import ccall "atk_value_get_sub_ranges" atk_value_get_sub_ranges :: 
    Ptr Value ->                            -- _obj : TInterface "Atk" "Value"
    IO (Ptr (GSList (Ptr Range)))


valueGetSubRanges ::
    (MonadIO m, ValueK a) =>
    a ->                                    -- _obj
    m [Range]
valueGetSubRanges _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- atk_value_get_sub_ranges _obj'
    checkUnexpectedReturnNULL "atk_value_get_sub_ranges" result
    result' <- unpackGSList result
    result'' <- mapM (wrapBoxed Range) result'
    g_slist_free result
    touchManagedPtr _obj
    return result''

-- method Value::get_value_and_text
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Atk" "Value", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "value", argType = TBasicType TDouble, direction = DirectionOut, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferEverything},Arg {argName = "text", argType = TBasicType TUTF8, direction = DirectionOut, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferEverything}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Atk" "Value", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "atk_value_get_value_and_text" atk_value_get_value_and_text :: 
    Ptr Value ->                            -- _obj : TInterface "Atk" "Value"
    Ptr CDouble ->                          -- value : TBasicType TDouble
    Ptr CString ->                          -- text : TBasicType TUTF8
    IO ()


valueGetValueAndText ::
    (MonadIO m, ValueK a) =>
    a ->                                    -- _obj
    m (Double,T.Text)
valueGetValueAndText _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    value <- allocMem :: IO (Ptr CDouble)
    text <- allocMem :: IO (Ptr CString)
    atk_value_get_value_and_text _obj' value text
    value' <- peek value
    let value'' = realToFrac value'
    text' <- peek text
    text'' <- cstringToText text'
    freeMem text'
    touchManagedPtr _obj
    freeMem value
    freeMem text
    return (value'', text'')

-- method Value::set_current_value
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Atk" "Value", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "value", argType = TInterface "GObject" "Value", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Atk" "Value", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "value", argType = TInterface "GObject" "Value", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TBoolean
-- throws : False
-- Skip return : False

foreign import ccall "atk_value_set_current_value" atk_value_set_current_value :: 
    Ptr Value ->                            -- _obj : TInterface "Atk" "Value"
    Ptr GValue ->                           -- value : TInterface "GObject" "Value"
    IO CInt

{-# DEPRECATED valueSetCurrentValue ["Since 2.12. Use atk_value_set_value() instead."]#-}
valueSetCurrentValue ::
    (MonadIO m, ValueK a) =>
    a ->                                    -- _obj
    GValue ->                               -- value
    m Bool
valueSetCurrentValue _obj value = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    let value' = unsafeManagedPtrGetPtr value
    result <- atk_value_set_current_value _obj' value'
    let result' = (/= 0) result
    touchManagedPtr _obj
    touchManagedPtr value
    return result'

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

foreign import ccall "atk_value_set_value" atk_value_set_value :: 
    Ptr Value ->                            -- _obj : TInterface "Atk" "Value"
    CDouble ->                              -- new_value : TBasicType TDouble
    IO ()


valueSetValue ::
    (MonadIO m, ValueK a) =>
    a ->                                    -- _obj
    Double ->                               -- new_value
    m ()
valueSetValue _obj new_value = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    let new_value' = realToFrac new_value
    atk_value_set_value _obj' new_value'
    touchManagedPtr _obj
    return ()