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

See also 'GI.Gtk.Objects.PrintSettings.printSettingsSetPageRanges'.
-}

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

module GI.Gtk.Structs.PageRange
    (

-- * Exported types
    PageRange(..)                           ,
    newZeroPageRange                        ,
    noPageRange                             ,


 -- * Properties
-- ** end #attr:end#
{- | end of page range.
-}
    getPageRangeEnd                         ,
#if ENABLE_OVERLOADING
    pageRange_end                           ,
#endif
    setPageRangeEnd                         ,


-- ** start #attr:start#
{- | start of page range.
-}
    getPageRangeStart                       ,
#if ENABLE_OVERLOADING
    pageRange_start                         ,
#endif
    setPageRangeStart                       ,




    ) 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 PageRange = PageRange (ManagedPtr PageRange)
instance WrappedPtr PageRange where
    wrappedPtrCalloc = callocBytes 8
    wrappedPtrCopy = \p -> withManagedPtr p (copyBytes 8 >=> wrapPtr PageRange)
    wrappedPtrFree = Just ptr_to_g_free

-- | Construct a `PageRange` struct initialized to zero.
newZeroPageRange :: MonadIO m => m PageRange
newZeroPageRange = liftIO $ wrappedPtrCalloc >>= wrapPtr PageRange

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


-- | A convenience alias for `Nothing` :: `Maybe` `PageRange`.
noPageRange :: Maybe PageRange
noPageRange = Nothing

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

@
'Data.GI.Base.Attributes.get' pageRange #start
@
-}
getPageRangeStart :: MonadIO m => PageRange -> m Int32
getPageRangeStart s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 0) :: IO Int32
    return val

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

@
'Data.GI.Base.Attributes.set' pageRange [ #start 'Data.GI.Base.Attributes.:=' value ]
@
-}
setPageRangeStart :: MonadIO m => PageRange -> Int32 -> m ()
setPageRangeStart s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 0) (val :: Int32)

#if ENABLE_OVERLOADING
data PageRangeStartFieldInfo
instance AttrInfo PageRangeStartFieldInfo where
    type AttrAllowedOps PageRangeStartFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint PageRangeStartFieldInfo = (~) Int32
    type AttrBaseTypeConstraint PageRangeStartFieldInfo = (~) PageRange
    type AttrGetType PageRangeStartFieldInfo = Int32
    type AttrLabel PageRangeStartFieldInfo = "start"
    type AttrOrigin PageRangeStartFieldInfo = PageRange
    attrGet _ = getPageRangeStart
    attrSet _ = setPageRangeStart
    attrConstruct = undefined
    attrClear _ = undefined

pageRange_start :: AttrLabelProxy "start"
pageRange_start = AttrLabelProxy

#endif


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

@
'Data.GI.Base.Attributes.get' pageRange #end
@
-}
getPageRangeEnd :: MonadIO m => PageRange -> m Int32
getPageRangeEnd s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 4) :: IO Int32
    return val

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

@
'Data.GI.Base.Attributes.set' pageRange [ #end 'Data.GI.Base.Attributes.:=' value ]
@
-}
setPageRangeEnd :: MonadIO m => PageRange -> Int32 -> m ()
setPageRangeEnd s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 4) (val :: Int32)

#if ENABLE_OVERLOADING
data PageRangeEndFieldInfo
instance AttrInfo PageRangeEndFieldInfo where
    type AttrAllowedOps PageRangeEndFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint PageRangeEndFieldInfo = (~) Int32
    type AttrBaseTypeConstraint PageRangeEndFieldInfo = (~) PageRange
    type AttrGetType PageRangeEndFieldInfo = Int32
    type AttrLabel PageRangeEndFieldInfo = "end"
    type AttrOrigin PageRangeEndFieldInfo = PageRange
    attrGet _ = getPageRangeEnd
    attrSet _ = setPageRangeEnd
    attrConstruct = undefined
    attrClear _ = undefined

pageRange_end :: AttrLabelProxy "end"
pageRange_end = AttrLabelProxy

#endif



#if ENABLE_OVERLOADING
instance O.HasAttributeList PageRange
type instance O.AttributeList PageRange = PageRangeAttributeList
type PageRangeAttributeList = ('[ '("start", PageRangeStartFieldInfo), '("end", PageRangeEndFieldInfo)] :: [(Symbol, *)])
#endif

#if ENABLE_OVERLOADING
type family ResolvePageRangeMethod (t :: Symbol) (o :: *) :: * where
    ResolvePageRangeMethod l o = O.MethodResolutionFailed l o

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

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