{- |
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.WebKit.Objects.DOMAttr
    ( 

-- * Exported types
    DOMAttr(..)                             ,
    DOMAttrK                                ,
    toDOMAttr                               ,
    noDOMAttr                               ,


 -- * Methods
-- ** dOMAttrGetIsId
    dOMAttrGetIsId                          ,


-- ** dOMAttrGetName
    dOMAttrGetName                          ,


-- ** dOMAttrGetOwnerElement
    dOMAttrGetOwnerElement                  ,


-- ** dOMAttrGetSpecified
    dOMAttrGetSpecified                     ,


-- ** dOMAttrGetValue
    dOMAttrGetValue                         ,


-- ** dOMAttrSetValue
    dOMAttrSetValue                         ,




 -- * Properties
-- ** IsId
    DOMAttrIsIdPropertyInfo                 ,
    getDOMAttrIsId                          ,


-- ** Name
    DOMAttrNamePropertyInfo                 ,
    getDOMAttrName                          ,


-- ** OwnerElement
    DOMAttrOwnerElementPropertyInfo         ,
    getDOMAttrOwnerElement                  ,


-- ** Specified
    DOMAttrSpecifiedPropertyInfo            ,
    getDOMAttrSpecified                     ,


-- ** Value
    DOMAttrValuePropertyInfo                ,
    constructDOMAttrValue                   ,
    getDOMAttrValue                         ,
    setDOMAttrValue                         ,




    ) 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.WebKit.Types
import GI.WebKit.Callbacks
import qualified GI.GObject as GObject

newtype DOMAttr = DOMAttr (ForeignPtr DOMAttr)
foreign import ccall "webkit_dom_attr_get_type"
    c_webkit_dom_attr_get_type :: IO GType

type instance ParentTypes DOMAttr = DOMAttrParentTypes
type DOMAttrParentTypes = '[DOMNode, DOMObject, GObject.Object, DOMEventTarget]

instance GObject DOMAttr where
    gobjectIsInitiallyUnowned _ = False
    gobjectType _ = c_webkit_dom_attr_get_type
    

class GObject o => DOMAttrK o
instance (GObject o, IsDescendantOf DOMAttr o) => DOMAttrK o

toDOMAttr :: DOMAttrK o => o -> IO DOMAttr
toDOMAttr = unsafeCastTo DOMAttr

noDOMAttr :: Maybe DOMAttr
noDOMAttr = Nothing

-- VVV Prop "is-id"
   -- Type: TBasicType TBoolean
   -- Flags: [PropertyReadable]

getDOMAttrIsId :: (MonadIO m, DOMAttrK o) => o -> m Bool
getDOMAttrIsId obj = liftIO $ getObjectPropertyBool obj "is-id"

data DOMAttrIsIdPropertyInfo
instance AttrInfo DOMAttrIsIdPropertyInfo where
    type AttrAllowedOps DOMAttrIsIdPropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint DOMAttrIsIdPropertyInfo = (~) ()
    type AttrBaseTypeConstraint DOMAttrIsIdPropertyInfo = DOMAttrK
    type AttrGetType DOMAttrIsIdPropertyInfo = Bool
    type AttrLabel DOMAttrIsIdPropertyInfo = "DOMAttr::is-id"
    attrGet _ = getDOMAttrIsId
    attrSet _ = undefined
    attrConstruct _ = undefined

-- VVV Prop "name"
   -- Type: TBasicType TUTF8
   -- Flags: [PropertyReadable]

getDOMAttrName :: (MonadIO m, DOMAttrK o) => o -> m T.Text
getDOMAttrName obj = liftIO $ getObjectPropertyString obj "name"

data DOMAttrNamePropertyInfo
instance AttrInfo DOMAttrNamePropertyInfo where
    type AttrAllowedOps DOMAttrNamePropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint DOMAttrNamePropertyInfo = (~) ()
    type AttrBaseTypeConstraint DOMAttrNamePropertyInfo = DOMAttrK
    type AttrGetType DOMAttrNamePropertyInfo = T.Text
    type AttrLabel DOMAttrNamePropertyInfo = "DOMAttr::name"
    attrGet _ = getDOMAttrName
    attrSet _ = undefined
    attrConstruct _ = undefined

-- VVV Prop "owner-element"
   -- Type: TInterface "WebKit" "DOMElement"
   -- Flags: [PropertyReadable]

getDOMAttrOwnerElement :: (MonadIO m, DOMAttrK o) => o -> m DOMElement
getDOMAttrOwnerElement obj = liftIO $ getObjectPropertyObject obj "owner-element" DOMElement

data DOMAttrOwnerElementPropertyInfo
instance AttrInfo DOMAttrOwnerElementPropertyInfo where
    type AttrAllowedOps DOMAttrOwnerElementPropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint DOMAttrOwnerElementPropertyInfo = (~) ()
    type AttrBaseTypeConstraint DOMAttrOwnerElementPropertyInfo = DOMAttrK
    type AttrGetType DOMAttrOwnerElementPropertyInfo = DOMElement
    type AttrLabel DOMAttrOwnerElementPropertyInfo = "DOMAttr::owner-element"
    attrGet _ = getDOMAttrOwnerElement
    attrSet _ = undefined
    attrConstruct _ = undefined

-- VVV Prop "specified"
   -- Type: TBasicType TBoolean
   -- Flags: [PropertyReadable]

getDOMAttrSpecified :: (MonadIO m, DOMAttrK o) => o -> m Bool
getDOMAttrSpecified obj = liftIO $ getObjectPropertyBool obj "specified"

data DOMAttrSpecifiedPropertyInfo
instance AttrInfo DOMAttrSpecifiedPropertyInfo where
    type AttrAllowedOps DOMAttrSpecifiedPropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint DOMAttrSpecifiedPropertyInfo = (~) ()
    type AttrBaseTypeConstraint DOMAttrSpecifiedPropertyInfo = DOMAttrK
    type AttrGetType DOMAttrSpecifiedPropertyInfo = Bool
    type AttrLabel DOMAttrSpecifiedPropertyInfo = "DOMAttr::specified"
    attrGet _ = getDOMAttrSpecified
    attrSet _ = undefined
    attrConstruct _ = undefined

-- VVV Prop "value"
   -- Type: TBasicType TUTF8
   -- Flags: [PropertyReadable,PropertyWritable]

getDOMAttrValue :: (MonadIO m, DOMAttrK o) => o -> m T.Text
getDOMAttrValue obj = liftIO $ getObjectPropertyString obj "value"

setDOMAttrValue :: (MonadIO m, DOMAttrK o) => o -> T.Text -> m ()
setDOMAttrValue obj val = liftIO $ setObjectPropertyString obj "value" val

constructDOMAttrValue :: T.Text -> IO ([Char], GValue)
constructDOMAttrValue val = constructObjectPropertyString "value" val

data DOMAttrValuePropertyInfo
instance AttrInfo DOMAttrValuePropertyInfo where
    type AttrAllowedOps DOMAttrValuePropertyInfo = '[ 'AttrSet, 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint DOMAttrValuePropertyInfo = (~) T.Text
    type AttrBaseTypeConstraint DOMAttrValuePropertyInfo = DOMAttrK
    type AttrGetType DOMAttrValuePropertyInfo = T.Text
    type AttrLabel DOMAttrValuePropertyInfo = "DOMAttr::value"
    attrGet _ = getDOMAttrValue
    attrSet _ = setDOMAttrValue
    attrConstruct _ = constructDOMAttrValue

type instance AttributeList DOMAttr = DOMAttrAttributeList
type DOMAttrAttributeList = ('[ '("base-uri", DOMNodeBaseUriPropertyInfo), '("child-nodes", DOMNodeChildNodesPropertyInfo), '("core-object", DOMObjectCoreObjectPropertyInfo), '("first-child", DOMNodeFirstChildPropertyInfo), '("is-id", DOMAttrIsIdPropertyInfo), '("last-child", DOMNodeLastChildPropertyInfo), '("local-name", DOMNodeLocalNamePropertyInfo), '("name", DOMAttrNamePropertyInfo), '("namespace-uri", DOMNodeNamespaceUriPropertyInfo), '("next-sibling", DOMNodeNextSiblingPropertyInfo), '("node-name", DOMNodeNodeNamePropertyInfo), '("node-type", DOMNodeNodeTypePropertyInfo), '("node-value", DOMNodeNodeValuePropertyInfo), '("owner-document", DOMNodeOwnerDocumentPropertyInfo), '("owner-element", DOMAttrOwnerElementPropertyInfo), '("parent-element", DOMNodeParentElementPropertyInfo), '("parent-node", DOMNodeParentNodePropertyInfo), '("prefix", DOMNodePrefixPropertyInfo), '("previous-sibling", DOMNodePreviousSiblingPropertyInfo), '("specified", DOMAttrSpecifiedPropertyInfo), '("text-content", DOMNodeTextContentPropertyInfo), '("value", DOMAttrValuePropertyInfo)] :: [(Symbol, *)])

type instance SignalList DOMAttr = DOMAttrSignalList
type DOMAttrSignalList = ('[ '("notify", GObject.ObjectNotifySignalInfo), '("notify::[property]", GObjectNotifySignalInfo)] :: [(Symbol, *)])

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

foreign import ccall "webkit_dom_attr_get_is_id" webkit_dom_attr_get_is_id :: 
    Ptr DOMAttr ->                          -- _obj : TInterface "WebKit" "DOMAttr"
    IO CInt


dOMAttrGetIsId ::
    (MonadIO m, DOMAttrK a) =>
    a ->                                    -- _obj
    m Bool
dOMAttrGetIsId _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- webkit_dom_attr_get_is_id _obj'
    let result' = (/= 0) result
    touchManagedPtr _obj
    return result'

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

foreign import ccall "webkit_dom_attr_get_name" webkit_dom_attr_get_name :: 
    Ptr DOMAttr ->                          -- _obj : TInterface "WebKit" "DOMAttr"
    IO CString


dOMAttrGetName ::
    (MonadIO m, DOMAttrK a) =>
    a ->                                    -- _obj
    m T.Text
dOMAttrGetName _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- webkit_dom_attr_get_name _obj'
    checkUnexpectedReturnNULL "webkit_dom_attr_get_name" result
    result' <- cstringToText result
    freeMem result
    touchManagedPtr _obj
    return result'

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

foreign import ccall "webkit_dom_attr_get_owner_element" webkit_dom_attr_get_owner_element :: 
    Ptr DOMAttr ->                          -- _obj : TInterface "WebKit" "DOMAttr"
    IO (Ptr DOMElement)


dOMAttrGetOwnerElement ::
    (MonadIO m, DOMAttrK a) =>
    a ->                                    -- _obj
    m DOMElement
dOMAttrGetOwnerElement _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- webkit_dom_attr_get_owner_element _obj'
    checkUnexpectedReturnNULL "webkit_dom_attr_get_owner_element" result
    result' <- (newObject DOMElement) result
    touchManagedPtr _obj
    return result'

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

foreign import ccall "webkit_dom_attr_get_specified" webkit_dom_attr_get_specified :: 
    Ptr DOMAttr ->                          -- _obj : TInterface "WebKit" "DOMAttr"
    IO CInt


dOMAttrGetSpecified ::
    (MonadIO m, DOMAttrK a) =>
    a ->                                    -- _obj
    m Bool
dOMAttrGetSpecified _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- webkit_dom_attr_get_specified _obj'
    let result' = (/= 0) result
    touchManagedPtr _obj
    return result'

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

foreign import ccall "webkit_dom_attr_get_value" webkit_dom_attr_get_value :: 
    Ptr DOMAttr ->                          -- _obj : TInterface "WebKit" "DOMAttr"
    IO CString


dOMAttrGetValue ::
    (MonadIO m, DOMAttrK a) =>
    a ->                                    -- _obj
    m T.Text
dOMAttrGetValue _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- webkit_dom_attr_get_value _obj'
    checkUnexpectedReturnNULL "webkit_dom_attr_get_value" result
    result' <- cstringToText result
    freeMem result
    touchManagedPtr _obj
    return result'

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

foreign import ccall "webkit_dom_attr_set_value" webkit_dom_attr_set_value :: 
    Ptr DOMAttr ->                          -- _obj : TInterface "WebKit" "DOMAttr"
    CString ->                              -- value : TBasicType TUTF8
    Ptr (Ptr GError) ->                     -- error
    IO ()


dOMAttrSetValue ::
    (MonadIO m, DOMAttrK a) =>
    a ->                                    -- _obj
    T.Text ->                               -- value
    m ()
dOMAttrSetValue _obj value = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    value' <- textToCString value
    onException (do
        propagateGError $ webkit_dom_attr_set_value _obj' value'
        touchManagedPtr _obj
        freeMem value'
        return ()
     ) (do
        freeMem value'
     )