{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- Represents a generic native object.

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

module GI.Ggit.Objects.Native
    ( 

-- * Exported types
    Native(..)                              ,
    IsNative                                ,
    toNative                                ,


 -- * Methods
-- ** Overloaded methods #method:Overloaded methods#

#if defined(ENABLE_OVERLOADING)
    ResolveNativeMethod                     ,
#endif




 -- * Properties
-- ** native #attr:native#
-- | /No description available in the introspection data./

#if defined(ENABLE_OVERLOADING)
    NativeNativePropertyInfo                ,
#endif
    constructNativeNative                   ,
#if defined(ENABLE_OVERLOADING)
    nativeNative                            ,
#endif




    ) 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.BasicTypes as B.Types
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.GI.Base.Signals as B.Signals
import qualified Control.Monad.IO.Class as MIO
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.Ggit.Objects.ObjectFactoryBase as Ggit.ObjectFactoryBase

-- | Memory-managed wrapper type.
newtype Native = Native (SP.ManagedPtr Native)
    deriving (Native -> Native -> Bool
(Native -> Native -> Bool)
-> (Native -> Native -> Bool) -> Eq Native
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Native -> Native -> Bool
$c/= :: Native -> Native -> Bool
== :: Native -> Native -> Bool
$c== :: Native -> Native -> Bool
Eq)

instance SP.ManagedPtrNewtype Native where
    toManagedPtr :: Native -> ManagedPtr Native
toManagedPtr (Native ManagedPtr Native
p) = ManagedPtr Native
p

foreign import ccall "ggit_native_get_type"
    c_ggit_native_get_type :: IO B.Types.GType

instance B.Types.TypedObject Native where
    glibType :: IO GType
glibType = IO GType
c_ggit_native_get_type

instance B.Types.GObject Native

-- | Convert 'Native' to and from 'Data.GI.Base.GValue.GValue' with 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
instance B.GValue.IsGValue Native where
    toGValue :: Native -> IO GValue
toGValue Native
o = do
        GType
gtype <- IO GType
c_ggit_native_get_type
        Native -> (Ptr Native -> IO GValue) -> IO GValue
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr Native
o (GType -> (GValue -> Ptr Native -> IO ()) -> Ptr Native -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
B.GValue.buildGValue GType
gtype GValue -> Ptr Native -> IO ()
forall a. GObject a => GValue -> Ptr a -> IO ()
B.GValue.set_object)
        
    fromGValue :: GValue -> IO Native
fromGValue GValue
gv = do
        Ptr Native
ptr <- GValue -> IO (Ptr Native)
forall b. GObject b => GValue -> IO (Ptr b)
B.GValue.get_object GValue
gv :: IO (Ptr Native)
        (ManagedPtr Native -> Native) -> Ptr Native -> IO Native
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
B.ManagedPtr.newObject ManagedPtr Native -> Native
Native Ptr Native
ptr
        
    

-- | Type class for types which can be safely cast to `Native`, for instance with `toNative`.
class (SP.GObject o, O.IsDescendantOf Native o) => IsNative o
instance (SP.GObject o, O.IsDescendantOf Native o) => IsNative o

instance O.HasParentTypes Native
type instance O.ParentTypes Native = '[Ggit.ObjectFactoryBase.ObjectFactoryBase, GObject.Object.Object]

-- | Cast to `Native`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toNative :: (MonadIO m, IsNative o) => o -> m Native
toNative :: o -> m Native
toNative = IO Native -> m Native
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Native -> m Native) -> (o -> IO Native) -> o -> m Native
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ManagedPtr Native -> Native) -> o -> IO Native
forall o o'.
(HasCallStack, ManagedPtrNewtype o, TypedObject o,
 ManagedPtrNewtype o', TypedObject o') =>
(ManagedPtr o' -> o') -> o -> IO o'
unsafeCastTo ManagedPtr Native -> Native
Native

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

instance (info ~ ResolveNativeMethod t Native, O.MethodInfo info Native p) => OL.IsLabel t (Native -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod @info
#else
    fromLabel _ = O.overloadedMethod @info
#endif

#endif

-- VVV Prop "native"
   -- Type: TBasicType TPtr
   -- Flags: [PropertyWritable,PropertyConstructOnly]
   -- Nullable: (Nothing,Nothing)

-- | Construct a `GValueConstruct` with valid value for the “@native@” property. This is rarely needed directly, but it is used by `Data.GI.Base.Constructible.new`.
constructNativeNative :: (IsNative o, MIO.MonadIO m) => Ptr () -> m (GValueConstruct o)
constructNativeNative :: Ptr () -> m (GValueConstruct o)
constructNativeNative Ptr ()
val = IO (GValueConstruct o) -> m (GValueConstruct o)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
MIO.liftIO (IO (GValueConstruct o) -> m (GValueConstruct o))
-> IO (GValueConstruct o) -> m (GValueConstruct o)
forall a b. (a -> b) -> a -> b
$ String -> Ptr () -> IO (GValueConstruct o)
forall b o. String -> Ptr b -> IO (GValueConstruct o)
B.Properties.constructObjectPropertyPtr String
"native" Ptr ()
val

#if defined(ENABLE_OVERLOADING)
data NativeNativePropertyInfo
instance AttrInfo NativeNativePropertyInfo where
    type AttrAllowedOps NativeNativePropertyInfo = '[ 'AttrConstruct]
    type AttrBaseTypeConstraint NativeNativePropertyInfo = IsNative
    type AttrSetTypeConstraint NativeNativePropertyInfo = (~) (Ptr ())
    type AttrTransferTypeConstraint NativeNativePropertyInfo = (~) (Ptr ())
    type AttrTransferType NativeNativePropertyInfo = Ptr ()
    type AttrGetType NativeNativePropertyInfo = ()
    type AttrLabel NativeNativePropertyInfo = "native"
    type AttrOrigin NativeNativePropertyInfo = Native
    attrGet = undefined
    attrSet = undefined
    attrTransfer _ v = do
        return v
    attrConstruct = constructNativeNative
    attrClear = undefined
#endif

#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList Native
type instance O.AttributeList Native = NativeAttributeList
type NativeAttributeList = ('[ '("native", NativeNativePropertyInfo)] :: [(Symbol, *)])
#endif

#if defined(ENABLE_OVERLOADING)
nativeNative :: AttrLabelProxy "native"
nativeNative = AttrLabelProxy

#endif

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

#endif