{- |
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 struct that specifies a border around a rectangular area
that can be of different width on each side.
-}

#define ENABLE_OVERLOADING (MIN_VERSION_haskell_gi_overloading(1,0,0) \
       && !defined(__HADDOCK_VERSION__))

module GI.Gtk.Structs.Border
    (

-- * Exported types
    Border(..)                              ,
    newZeroBorder                           ,
    noBorder                                ,


 -- * Methods
-- ** copy #method:copy#

#if ENABLE_OVERLOADING
    BorderCopyMethodInfo                    ,
#endif
    borderCopy                              ,


-- ** free #method:free#

#if ENABLE_OVERLOADING
    BorderFreeMethodInfo                    ,
#endif
    borderFree                              ,


-- ** new #method:new#

    borderNew                               ,




 -- * Properties
-- ** bottom #attr:bottom#
{- | The width of the bottom border
-}
#if ENABLE_OVERLOADING
    border_bottom                           ,
#endif
    getBorderBottom                         ,
    setBorderBottom                         ,


-- ** left #attr:left#
{- | The width of the left border
-}
#if ENABLE_OVERLOADING
    border_left                             ,
#endif
    getBorderLeft                           ,
    setBorderLeft                           ,


-- ** right #attr:right#
{- | The width of the right border
-}
#if ENABLE_OVERLOADING
    border_right                            ,
#endif
    getBorderRight                          ,
    setBorderRight                          ,


-- ** top #attr:top#
{- | The width of the top border
-}
#if ENABLE_OVERLOADING
    border_top                              ,
#endif
    getBorderTop                            ,
    setBorderTop                            ,




    ) 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.GValue as B.GValue
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


-- | Memory-managed wrapper type.
newtype Border = Border (ManagedPtr Border)
foreign import ccall "gtk_border_get_type" c_gtk_border_get_type ::
    IO GType

instance BoxedObject Border where
    boxedType _ = c_gtk_border_get_type

-- | Construct a `Border` struct initialized to zero.
newZeroBorder :: MonadIO m => m Border
newZeroBorder = liftIO $ callocBoxedBytes 8 >>= wrapBoxed Border

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


-- | A convenience alias for `Nothing` :: `Maybe` `Border`.
noBorder :: Maybe Border
noBorder = Nothing

{- |
Get the value of the “@left@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' border #left
@
-}
getBorderLeft :: MonadIO m => Border -> m Int16
getBorderLeft s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 0) :: IO Int16
    return val

{- |
Set the value of the “@left@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.set' border [ #left 'Data.GI.Base.Attributes.:=' value ]
@
-}
setBorderLeft :: MonadIO m => Border -> Int16 -> m ()
setBorderLeft s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 0) (val :: Int16)

#if ENABLE_OVERLOADING
data BorderLeftFieldInfo
instance AttrInfo BorderLeftFieldInfo where
    type AttrAllowedOps BorderLeftFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint BorderLeftFieldInfo = (~) Int16
    type AttrBaseTypeConstraint BorderLeftFieldInfo = (~) Border
    type AttrGetType BorderLeftFieldInfo = Int16
    type AttrLabel BorderLeftFieldInfo = "left"
    type AttrOrigin BorderLeftFieldInfo = Border
    attrGet _ = getBorderLeft
    attrSet _ = setBorderLeft
    attrConstruct = undefined
    attrClear _ = undefined

border_left :: AttrLabelProxy "left"
border_left = AttrLabelProxy

#endif


{- |
Get the value of the “@right@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' border #right
@
-}
getBorderRight :: MonadIO m => Border -> m Int16
getBorderRight s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 2) :: IO Int16
    return val

{- |
Set the value of the “@right@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.set' border [ #right 'Data.GI.Base.Attributes.:=' value ]
@
-}
setBorderRight :: MonadIO m => Border -> Int16 -> m ()
setBorderRight s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 2) (val :: Int16)

#if ENABLE_OVERLOADING
data BorderRightFieldInfo
instance AttrInfo BorderRightFieldInfo where
    type AttrAllowedOps BorderRightFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint BorderRightFieldInfo = (~) Int16
    type AttrBaseTypeConstraint BorderRightFieldInfo = (~) Border
    type AttrGetType BorderRightFieldInfo = Int16
    type AttrLabel BorderRightFieldInfo = "right"
    type AttrOrigin BorderRightFieldInfo = Border
    attrGet _ = getBorderRight
    attrSet _ = setBorderRight
    attrConstruct = undefined
    attrClear _ = undefined

border_right :: AttrLabelProxy "right"
border_right = AttrLabelProxy

#endif


{- |
Get the value of the “@top@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' border #top
@
-}
getBorderTop :: MonadIO m => Border -> m Int16
getBorderTop s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 4) :: IO Int16
    return val

{- |
Set the value of the “@top@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.set' border [ #top 'Data.GI.Base.Attributes.:=' value ]
@
-}
setBorderTop :: MonadIO m => Border -> Int16 -> m ()
setBorderTop s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 4) (val :: Int16)

#if ENABLE_OVERLOADING
data BorderTopFieldInfo
instance AttrInfo BorderTopFieldInfo where
    type AttrAllowedOps BorderTopFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint BorderTopFieldInfo = (~) Int16
    type AttrBaseTypeConstraint BorderTopFieldInfo = (~) Border
    type AttrGetType BorderTopFieldInfo = Int16
    type AttrLabel BorderTopFieldInfo = "top"
    type AttrOrigin BorderTopFieldInfo = Border
    attrGet _ = getBorderTop
    attrSet _ = setBorderTop
    attrConstruct = undefined
    attrClear _ = undefined

border_top :: AttrLabelProxy "top"
border_top = AttrLabelProxy

#endif


{- |
Get the value of the “@bottom@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' border #bottom
@
-}
getBorderBottom :: MonadIO m => Border -> m Int16
getBorderBottom s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 6) :: IO Int16
    return val

{- |
Set the value of the “@bottom@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.set' border [ #bottom 'Data.GI.Base.Attributes.:=' value ]
@
-}
setBorderBottom :: MonadIO m => Border -> Int16 -> m ()
setBorderBottom s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 6) (val :: Int16)

#if ENABLE_OVERLOADING
data BorderBottomFieldInfo
instance AttrInfo BorderBottomFieldInfo where
    type AttrAllowedOps BorderBottomFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint BorderBottomFieldInfo = (~) Int16
    type AttrBaseTypeConstraint BorderBottomFieldInfo = (~) Border
    type AttrGetType BorderBottomFieldInfo = Int16
    type AttrLabel BorderBottomFieldInfo = "bottom"
    type AttrOrigin BorderBottomFieldInfo = Border
    attrGet _ = getBorderBottom
    attrSet _ = setBorderBottom
    attrConstruct = undefined
    attrClear _ = undefined

border_bottom :: AttrLabelProxy "bottom"
border_bottom = AttrLabelProxy

#endif



#if ENABLE_OVERLOADING
instance O.HasAttributeList Border
type instance O.AttributeList Border = BorderAttributeList
type BorderAttributeList = ('[ '("left", BorderLeftFieldInfo), '("right", BorderRightFieldInfo), '("top", BorderTopFieldInfo), '("bottom", BorderBottomFieldInfo)] :: [(Symbol, *)])
#endif

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

foreign import ccall "gtk_border_new" gtk_border_new ::
    IO (Ptr Border)

{- |
Allocates a new 'GI.Gtk.Structs.Border.Border'-struct and initializes its elements to zero.

/Since: 2.14/
-}
borderNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m Border
    {- ^ __Returns:__ a newly allocated 'GI.Gtk.Structs.Border.Border'-struct.
 Free with 'GI.Gtk.Structs.Border.borderFree' -}
borderNew  = liftIO $ do
    result <- gtk_border_new
    checkUnexpectedReturnNULL "borderNew" result
    result' <- (wrapBoxed Border) result
    return result'

#if ENABLE_OVERLOADING
#endif

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

foreign import ccall "gtk_border_copy" gtk_border_copy ::
    Ptr Border ->                           -- border_ : TInterface (Name {namespace = "Gtk", name = "Border"})
    IO (Ptr Border)

{- |
Copies a 'GI.Gtk.Structs.Border.Border'-struct.
-}
borderCopy ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Border
    {- ^ /@border_@/: a 'GI.Gtk.Structs.Border.Border'-struct -}
    -> m Border
    {- ^ __Returns:__ a copy of /@border_@/. -}
borderCopy border_ = liftIO $ do
    border_' <- unsafeManagedPtrGetPtr border_
    result <- gtk_border_copy border_'
    checkUnexpectedReturnNULL "borderCopy" result
    result' <- (wrapBoxed Border) result
    touchManagedPtr border_
    return result'

#if ENABLE_OVERLOADING
data BorderCopyMethodInfo
instance (signature ~ (m Border), MonadIO m) => O.MethodInfo BorderCopyMethodInfo Border signature where
    overloadedMethod _ = borderCopy

#endif

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

foreign import ccall "gtk_border_free" gtk_border_free ::
    Ptr Border ->                           -- border_ : TInterface (Name {namespace = "Gtk", name = "Border"})
    IO ()

{- |
Frees a 'GI.Gtk.Structs.Border.Border'-struct.
-}
borderFree ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Border
    {- ^ /@border_@/: a 'GI.Gtk.Structs.Border.Border'-struct -}
    -> m ()
borderFree border_ = liftIO $ do
    border_' <- unsafeManagedPtrGetPtr border_
    gtk_border_free border_'
    touchManagedPtr border_
    return ()

#if ENABLE_OVERLOADING
data BorderFreeMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo BorderFreeMethodInfo Border signature where
    overloadedMethod _ = borderFree

#endif

#if ENABLE_OVERLOADING
type family ResolveBorderMethod (t :: Symbol) (o :: *) :: * where
    ResolveBorderMethod "copy" o = BorderCopyMethodInfo
    ResolveBorderMethod "free" o = BorderFreeMethodInfo
    ResolveBorderMethod l o = O.MethodResolutionFailed l o

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

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveBorderMethod t Border, O.MethodInfo info Border p) => O.IsLabel t (Border -> 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