{- |
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 'GI.Pango.Objects.Fontset.Fontset' represents a set of 'GI.Pango.Objects.Font.Font' to use
when rendering text. It is the result of resolving a
'GI.Pango.Structs.FontDescription.FontDescription' against a particular 'GI.Pango.Objects.Context.Context'.
It has operations for finding the component font for
a particular Unicode character, and for finding a composite
set of metrics for the entire fontset.
-}

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

module GI.Pango.Objects.Fontset
    (

-- * Exported types
    Fontset(..)                             ,
    IsFontset                               ,
    toFontset                               ,
    noFontset                               ,


 -- * Methods
-- ** foreach #method:foreach#

#if ENABLE_OVERLOADING
    FontsetForeachMethodInfo                ,
#endif
    fontsetForeach                          ,


-- ** getFont #method:getFont#

#if ENABLE_OVERLOADING
    FontsetGetFontMethodInfo                ,
#endif
    fontsetGetFont                          ,


-- ** getMetrics #method:getMetrics#

#if ENABLE_OVERLOADING
    FontsetGetMetricsMethodInfo             ,
#endif
    fontsetGetMetrics                       ,




    ) 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

import qualified GI.GObject.Objects.Object as GObject.Object
import qualified GI.Pango.Callbacks as Pango.Callbacks
import {-# SOURCE #-} qualified GI.Pango.Objects.Font as Pango.Font
import {-# SOURCE #-} qualified GI.Pango.Structs.FontMetrics as Pango.FontMetrics

-- | Memory-managed wrapper type.
newtype Fontset = Fontset (ManagedPtr Fontset)
foreign import ccall "pango_fontset_get_type"
    c_pango_fontset_get_type :: IO GType

instance GObject Fontset where
    gobjectType _ = c_pango_fontset_get_type


-- | Type class for types which can be safely cast to `Fontset`, for instance with `toFontset`.
class GObject o => IsFontset o
#if MIN_VERSION_base(4,9,0)
instance {-# OVERLAPPABLE #-} (GObject a, O.UnknownAncestorError Fontset a) =>
    IsFontset a
#endif
instance IsFontset Fontset
instance GObject.Object.IsObject Fontset

-- | Cast to `Fontset`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toFontset :: (MonadIO m, IsFontset o) => o -> m Fontset
toFontset = liftIO . unsafeCastTo Fontset

-- | A convenience alias for `Nothing` :: `Maybe` `Fontset`.
noFontset :: Maybe Fontset
noFontset = Nothing

#if ENABLE_OVERLOADING
type family ResolveFontsetMethod (t :: Symbol) (o :: *) :: * where
    ResolveFontsetMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveFontsetMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveFontsetMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveFontsetMethod "foreach" o = FontsetForeachMethodInfo
    ResolveFontsetMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveFontsetMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveFontsetMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveFontsetMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveFontsetMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveFontsetMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveFontsetMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveFontsetMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveFontsetMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveFontsetMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveFontsetMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveFontsetMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveFontsetMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveFontsetMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveFontsetMethod "getFont" o = FontsetGetFontMethodInfo
    ResolveFontsetMethod "getMetrics" o = FontsetGetMetricsMethodInfo
    ResolveFontsetMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveFontsetMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveFontsetMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveFontsetMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveFontsetMethod l o = O.MethodResolutionFailed l o

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

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

#if ENABLE_OVERLOADING
instance O.HasAttributeList Fontset
type instance O.AttributeList Fontset = FontsetAttributeList
type FontsetAttributeList = ('[ ] :: [(Symbol, *)])
#endif

#if ENABLE_OVERLOADING
#endif

#if ENABLE_OVERLOADING
type instance O.SignalList Fontset = FontsetSignalList
type FontsetSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

-- method Fontset::foreach
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "fontset", argType = TInterface (Name {namespace = "Pango", name = "Fontset"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #PangoFontset", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "func", argType = TInterface (Name {namespace = "Pango", name = "FontsetForeachFunc"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "Callback function", sinceVersion = Nothing}, argScope = ScopeTypeCall, argClosure = 2, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "data", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "data to pass to the callback function", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "pango_fontset_foreach" pango_fontset_foreach ::
    Ptr Fontset ->                          -- fontset : TInterface (Name {namespace = "Pango", name = "Fontset"})
    FunPtr Pango.Callbacks.C_FontsetForeachFunc -> -- func : TInterface (Name {namespace = "Pango", name = "FontsetForeachFunc"})
    Ptr () ->                               -- data : TBasicType TPtr
    IO ()

{- |
Iterates through all the fonts in a fontset, calling /@func@/ for
each one. If /@func@/ returns 'True', that stops the iteration.

/Since: 1.4/
-}
fontsetForeach ::
    (B.CallStack.HasCallStack, MonadIO m, IsFontset a) =>
    a
    {- ^ /@fontset@/: a 'GI.Pango.Objects.Fontset.Fontset' -}
    -> Pango.Callbacks.FontsetForeachFunc
    {- ^ /@func@/: Callback function -}
    -> m ()
fontsetForeach fontset func = liftIO $ do
    fontset' <- unsafeManagedPtrCastPtr fontset
    func' <- Pango.Callbacks.mk_FontsetForeachFunc (Pango.Callbacks.wrap_FontsetForeachFunc Nothing (Pango.Callbacks.drop_closures_FontsetForeachFunc func))
    let data_ = nullPtr
    pango_fontset_foreach fontset' func' data_
    safeFreeFunPtr $ castFunPtrToPtr func'
    touchManagedPtr fontset
    return ()

#if ENABLE_OVERLOADING
data FontsetForeachMethodInfo
instance (signature ~ (Pango.Callbacks.FontsetForeachFunc -> m ()), MonadIO m, IsFontset a) => O.MethodInfo FontsetForeachMethodInfo a signature where
    overloadedMethod _ = fontsetForeach

#endif

-- method Fontset::get_font
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "fontset", argType = TInterface (Name {namespace = "Pango", name = "Fontset"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #PangoFontset", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "wc", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a Unicode character", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Pango", name = "Font"}))
-- throws : False
-- Skip return : False

foreign import ccall "pango_fontset_get_font" pango_fontset_get_font ::
    Ptr Fontset ->                          -- fontset : TInterface (Name {namespace = "Pango", name = "Fontset"})
    Word32 ->                               -- wc : TBasicType TUInt
    IO (Ptr Pango.Font.Font)

{- |
Returns the font in the fontset that contains the best glyph for the
Unicode character /@wc@/.
-}
fontsetGetFont ::
    (B.CallStack.HasCallStack, MonadIO m, IsFontset a) =>
    a
    {- ^ /@fontset@/: a 'GI.Pango.Objects.Fontset.Fontset' -}
    -> Word32
    {- ^ /@wc@/: a Unicode character -}
    -> m Pango.Font.Font
    {- ^ __Returns:__ a 'GI.Pango.Objects.Font.Font'. The caller must call
         g_object_unref when finished with the font. -}
fontsetGetFont fontset wc = liftIO $ do
    fontset' <- unsafeManagedPtrCastPtr fontset
    result <- pango_fontset_get_font fontset' wc
    checkUnexpectedReturnNULL "fontsetGetFont" result
    result' <- (wrapObject Pango.Font.Font) result
    touchManagedPtr fontset
    return result'

#if ENABLE_OVERLOADING
data FontsetGetFontMethodInfo
instance (signature ~ (Word32 -> m Pango.Font.Font), MonadIO m, IsFontset a) => O.MethodInfo FontsetGetFontMethodInfo a signature where
    overloadedMethod _ = fontsetGetFont

#endif

-- method Fontset::get_metrics
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "fontset", argType = TInterface (Name {namespace = "Pango", name = "Fontset"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #PangoFontset", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Pango", name = "FontMetrics"}))
-- throws : False
-- Skip return : False

foreign import ccall "pango_fontset_get_metrics" pango_fontset_get_metrics ::
    Ptr Fontset ->                          -- fontset : TInterface (Name {namespace = "Pango", name = "Fontset"})
    IO (Ptr Pango.FontMetrics.FontMetrics)

{- |
Get overall metric information for the fonts in the fontset.
-}
fontsetGetMetrics ::
    (B.CallStack.HasCallStack, MonadIO m, IsFontset a) =>
    a
    {- ^ /@fontset@/: a 'GI.Pango.Objects.Fontset.Fontset' -}
    -> m Pango.FontMetrics.FontMetrics
    {- ^ __Returns:__ a 'GI.Pango.Structs.FontMetrics.FontMetrics' object. The caller must call 'GI.Pango.Structs.FontMetrics.fontMetricsUnref'
  when finished using the object. -}
fontsetGetMetrics fontset = liftIO $ do
    fontset' <- unsafeManagedPtrCastPtr fontset
    result <- pango_fontset_get_metrics fontset'
    checkUnexpectedReturnNULL "fontsetGetMetrics" result
    result' <- (wrapBoxed Pango.FontMetrics.FontMetrics) result
    touchManagedPtr fontset
    return result'

#if ENABLE_OVERLOADING
data FontsetGetMetricsMethodInfo
instance (signature ~ (m Pango.FontMetrics.FontMetrics), MonadIO m, IsFontset a) => O.MethodInfo FontsetGetMetricsMethodInfo a signature where
    overloadedMethod _ = fontsetGetMetrics

#endif