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

The 'GI.Pango.Objects.FontFamily.FontFamily' structure is used to represent a family of related
font faces. The faces in a family share a common design, but differ in
slant, weight, width and other aspects.
-}

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

module GI.Pango.Objects.FontFamily
    (

-- * Exported types
    FontFamily(..)                          ,
    IsFontFamily                            ,
    toFontFamily                            ,
    noFontFamily                            ,


 -- * Methods
-- ** getName #method:getName#

#if ENABLE_OVERLOADING
    FontFamilyGetNameMethodInfo             ,
#endif
    fontFamilyGetName                       ,


-- ** isMonospace #method:isMonospace#

#if ENABLE_OVERLOADING
    FontFamilyIsMonospaceMethodInfo         ,
#endif
    fontFamilyIsMonospace                   ,


-- ** isVariable #method:isVariable#

#if ENABLE_OVERLOADING
    FontFamilyIsVariableMethodInfo          ,
#endif
    fontFamilyIsVariable                    ,


-- ** listFaces #method:listFaces#

#if ENABLE_OVERLOADING
    FontFamilyListFacesMethodInfo           ,
#endif
    fontFamilyListFaces                     ,




    ) 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.GClosure as B.GClosure
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.GI.Base.Properties as B.Properties
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 GHC.OverloadedLabels as OL

import qualified GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Pango.Objects.FontFace as Pango.FontFace

-- | Memory-managed wrapper type.
newtype FontFamily = FontFamily (ManagedPtr FontFamily)
foreign import ccall "pango_font_family_get_type"
    c_pango_font_family_get_type :: IO GType

instance GObject FontFamily where
    gobjectType = c_pango_font_family_get_type


-- | Type class for types which can be safely cast to `FontFamily`, for instance with `toFontFamily`.
class (GObject o, O.IsDescendantOf FontFamily o) => IsFontFamily o
instance (GObject o, O.IsDescendantOf FontFamily o) => IsFontFamily o

instance O.HasParentTypes FontFamily
type instance O.ParentTypes FontFamily = '[GObject.Object.Object]

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

-- | A convenience alias for `Nothing` :: `Maybe` `FontFamily`.
noFontFamily :: Maybe FontFamily
noFontFamily = Nothing

#if ENABLE_OVERLOADING
type family ResolveFontFamilyMethod (t :: Symbol) (o :: *) :: * where
    ResolveFontFamilyMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveFontFamilyMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveFontFamilyMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveFontFamilyMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveFontFamilyMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveFontFamilyMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveFontFamilyMethod "isMonospace" o = FontFamilyIsMonospaceMethodInfo
    ResolveFontFamilyMethod "isVariable" o = FontFamilyIsVariableMethodInfo
    ResolveFontFamilyMethod "listFaces" o = FontFamilyListFacesMethodInfo
    ResolveFontFamilyMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveFontFamilyMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveFontFamilyMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveFontFamilyMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveFontFamilyMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveFontFamilyMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveFontFamilyMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveFontFamilyMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveFontFamilyMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveFontFamilyMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveFontFamilyMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveFontFamilyMethod "getName" o = FontFamilyGetNameMethodInfo
    ResolveFontFamilyMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveFontFamilyMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveFontFamilyMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveFontFamilyMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveFontFamilyMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveFontFamilyMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveFontFamilyMethod t FontFamily, O.MethodInfo info FontFamily p) => OL.IsLabel t (FontFamily -> 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

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

#if ENABLE_OVERLOADING
#endif

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

#endif

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

foreign import ccall "pango_font_family_get_name" pango_font_family_get_name ::
    Ptr FontFamily ->                       -- family : TInterface (Name {namespace = "Pango", name = "FontFamily"})
    IO CString

{- |
Gets the name of the family. The name is unique among all
fonts for the font backend and can be used in a 'GI.Pango.Structs.FontDescription.FontDescription'
to specify that a face from this family is desired.
-}
fontFamilyGetName ::
    (B.CallStack.HasCallStack, MonadIO m, IsFontFamily a) =>
    a
    {- ^ /@family@/: a 'GI.Pango.Objects.FontFamily.FontFamily' -}
    -> m T.Text
    {- ^ __Returns:__ the name of the family. This string is owned
  by the family object and must not be modified or freed. -}
fontFamilyGetName family = liftIO $ do
    family' <- unsafeManagedPtrCastPtr family
    result <- pango_font_family_get_name family'
    checkUnexpectedReturnNULL "fontFamilyGetName" result
    result' <- cstringToText result
    touchManagedPtr family
    return result'

#if ENABLE_OVERLOADING
data FontFamilyGetNameMethodInfo
instance (signature ~ (m T.Text), MonadIO m, IsFontFamily a) => O.MethodInfo FontFamilyGetNameMethodInfo a signature where
    overloadedMethod _ = fontFamilyGetName

#endif

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

foreign import ccall "pango_font_family_is_monospace" pango_font_family_is_monospace ::
    Ptr FontFamily ->                       -- family : TInterface (Name {namespace = "Pango", name = "FontFamily"})
    IO CInt

{- |
A monospace font is a font designed for text display where the the
characters form a regular grid. For Western languages this would
mean that the advance width of all characters are the same, but
this categorization also includes Asian fonts which include
double-width characters: characters that occupy two grid cells.
'GI.GLib.Functions.unicharIswide' returns a result that indicates whether a
character is typically double-width in a monospace font.

The best way to find out the grid-cell size is to call
'GI.Pango.Structs.FontMetrics.fontMetricsGetApproximateDigitWidth', since the results
of 'GI.Pango.Structs.FontMetrics.fontMetricsGetApproximateCharWidth' may be affected
by double-width characters.

/Since: 1.4/
-}
fontFamilyIsMonospace ::
    (B.CallStack.HasCallStack, MonadIO m, IsFontFamily a) =>
    a
    {- ^ /@family@/: a 'GI.Pango.Objects.FontFamily.FontFamily' -}
    -> m Bool
    {- ^ __Returns:__ 'True' if the family is monospace. -}
fontFamilyIsMonospace family = liftIO $ do
    family' <- unsafeManagedPtrCastPtr family
    result <- pango_font_family_is_monospace family'
    let result' = (/= 0) result
    touchManagedPtr family
    return result'

#if ENABLE_OVERLOADING
data FontFamilyIsMonospaceMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsFontFamily a) => O.MethodInfo FontFamilyIsMonospaceMethodInfo a signature where
    overloadedMethod _ = fontFamilyIsMonospace

#endif

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

foreign import ccall "pango_font_family_is_variable" pango_font_family_is_variable ::
    Ptr FontFamily ->                       -- family : TInterface (Name {namespace = "Pango", name = "FontFamily"})
    IO CInt

{- |
A variable font is a font which has axes that can be modified to
produce different faces.

/Since: 1.44/
-}
fontFamilyIsVariable ::
    (B.CallStack.HasCallStack, MonadIO m, IsFontFamily a) =>
    a
    {- ^ /@family@/: a 'GI.Pango.Objects.FontFamily.FontFamily' -}
    -> m Bool
    {- ^ __Returns:__ 'True' if the family is variable -}
fontFamilyIsVariable family = liftIO $ do
    family' <- unsafeManagedPtrCastPtr family
    result <- pango_font_family_is_variable family'
    let result' = (/= 0) result
    touchManagedPtr family
    return result'

#if ENABLE_OVERLOADING
data FontFamilyIsVariableMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsFontFamily a) => O.MethodInfo FontFamilyIsVariableMethodInfo a signature where
    overloadedMethod _ = fontFamilyIsVariable

#endif

-- method FontFamily::list_faces
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "family", argType = TInterface (Name {namespace = "Pango", name = "FontFamily"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #PangoFontFamily", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "faces", argType = TCArray False (-1) 2 (TInterface (Name {namespace = "Pango", name = "FontFace"})), direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "\n  location to store an array of pointers to #PangoFontFace objects,\n  or %NULL. This array should be freed with g_free() when it is no\n  longer needed.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferContainer},Arg {argCName = "n_faces", argType = TBasicType TInt, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "location to store number of elements in @faces.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : [Arg {argCName = "n_faces", argType = TBasicType TInt, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "location to store number of elements in @faces.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "pango_font_family_list_faces" pango_font_family_list_faces ::
    Ptr FontFamily ->                       -- family : TInterface (Name {namespace = "Pango", name = "FontFamily"})
    Ptr (Ptr (Ptr Pango.FontFace.FontFace)) -> -- faces : TCArray False (-1) 2 (TInterface (Name {namespace = "Pango", name = "FontFace"}))
    Ptr Int32 ->                            -- n_faces : TBasicType TInt
    IO ()

{- |
Lists the different font faces that make up /@family@/. The faces
in a family share a common design, but differ in slant, weight,
width and other aspects.
-}
fontFamilyListFaces ::
    (B.CallStack.HasCallStack, MonadIO m, IsFontFamily a) =>
    a
    {- ^ /@family@/: a 'GI.Pango.Objects.FontFamily.FontFamily' -}
    -> m ([Pango.FontFace.FontFace])
fontFamilyListFaces family = liftIO $ do
    family' <- unsafeManagedPtrCastPtr family
    faces <- allocMem :: IO (Ptr (Ptr (Ptr Pango.FontFace.FontFace)))
    nFaces <- allocMem :: IO (Ptr Int32)
    pango_font_family_list_faces family' faces nFaces
    nFaces' <- peek nFaces
    faces' <- peek faces
    faces'' <- (unpackPtrArrayWithLength nFaces') faces'
    faces''' <- mapM (newObject Pango.FontFace.FontFace) faces''
    freeMem faces'
    touchManagedPtr family
    freeMem faces
    freeMem nFaces
    return faces'''

#if ENABLE_OVERLOADING
data FontFamilyListFacesMethodInfo
instance (signature ~ (m ([Pango.FontFace.FontFace])), MonadIO m, IsFontFamily a) => O.MethodInfo FontFamilyListFacesMethodInfo a signature where
    overloadedMethod _ = fontFamilyListFaces

#endif