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

/No description available in the introspection data./
-}

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

module GI.Gtk.Interfaces.TreeDragDest
    (

-- * Exported types
    TreeDragDest(..)                        ,
    noTreeDragDest                          ,
    IsTreeDragDest                          ,


 -- * Methods
-- ** dragDataReceived #method:dragDataReceived#

#if ENABLE_OVERLOADING
    TreeDragDestDragDataReceivedMethodInfo  ,
#endif
    treeDragDestDragDataReceived            ,


-- ** rowDropPossible #method:rowDropPossible#

#if ENABLE_OVERLOADING
    TreeDragDestRowDropPossibleMethodInfo   ,
#endif
    treeDragDestRowDropPossible             ,




    ) 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 {-# SOURCE #-} qualified GI.Gtk.Structs.SelectionData as Gtk.SelectionData
import {-# SOURCE #-} qualified GI.Gtk.Structs.TreePath as Gtk.TreePath

-- interface TreeDragDest 
-- | Memory-managed wrapper type.
newtype TreeDragDest = TreeDragDest (ManagedPtr TreeDragDest)
-- | A convenience alias for `Nothing` :: `Maybe` `TreeDragDest`.
noTreeDragDest :: Maybe TreeDragDest
noTreeDragDest = Nothing

#if ENABLE_OVERLOADING
type instance O.SignalList TreeDragDest = TreeDragDestSignalList
type TreeDragDestSignalList = ('[ ] :: [(Symbol, *)])

#endif

-- | Type class for types which implement `TreeDragDest`.
class ManagedPtrNewtype a => IsTreeDragDest a
instance IsTreeDragDest TreeDragDest
-- XXX Wrapping a foreign struct/union with no known destructor or size, leak?
instance WrappedPtr TreeDragDest where
    wrappedPtrCalloc = return nullPtr
    wrappedPtrCopy = return
    wrappedPtrFree = Nothing


#if ENABLE_OVERLOADING
type family ResolveTreeDragDestMethod (t :: Symbol) (o :: *) :: * where
    ResolveTreeDragDestMethod "dragDataReceived" o = TreeDragDestDragDataReceivedMethodInfo
    ResolveTreeDragDestMethod "rowDropPossible" o = TreeDragDestRowDropPossibleMethodInfo
    ResolveTreeDragDestMethod l o = O.MethodResolutionFailed l o

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

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

-- method TreeDragDest::drag_data_received
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "drag_dest", argType = TInterface (Name {namespace = "Gtk", name = "TreeDragDest"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkTreeDragDest", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "dest", argType = TInterface (Name {namespace = "Gtk", name = "TreePath"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "row to drop in front of", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "selection_data", argType = TInterface (Name {namespace = "Gtk", name = "SelectionData"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "data to drop", 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 "gtk_tree_drag_dest_drag_data_received" gtk_tree_drag_dest_drag_data_received ::
    Ptr TreeDragDest ->                     -- drag_dest : TInterface (Name {namespace = "Gtk", name = "TreeDragDest"})
    Ptr Gtk.TreePath.TreePath ->            -- dest : TInterface (Name {namespace = "Gtk", name = "TreePath"})
    Ptr Gtk.SelectionData.SelectionData ->  -- selection_data : TInterface (Name {namespace = "Gtk", name = "SelectionData"})
    IO CInt

{- |
Asks the 'GI.Gtk.Interfaces.TreeDragDest.TreeDragDest' to insert a row before the path /@dest@/,
deriving the contents of the row from /@selectionData@/. If /@dest@/ is
outside the tree so that inserting before it is impossible, 'False'
will be returned. Also, 'False' may be returned if the new row is
not created for some model-specific reason.  Should robustly handle
a /@dest@/ no longer found in the model!
-}
treeDragDestDragDataReceived ::
    (B.CallStack.HasCallStack, MonadIO m, IsTreeDragDest a) =>
    a
    {- ^ /@dragDest@/: a 'GI.Gtk.Interfaces.TreeDragDest.TreeDragDest' -}
    -> Gtk.TreePath.TreePath
    {- ^ /@dest@/: row to drop in front of -}
    -> Gtk.SelectionData.SelectionData
    {- ^ /@selectionData@/: data to drop -}
    -> m Bool
    {- ^ __Returns:__ whether a new row was created before position /@dest@/ -}
treeDragDestDragDataReceived dragDest dest selectionData = liftIO $ do
    dragDest' <- unsafeManagedPtrCastPtr dragDest
    dest' <- unsafeManagedPtrGetPtr dest
    selectionData' <- unsafeManagedPtrGetPtr selectionData
    result <- gtk_tree_drag_dest_drag_data_received dragDest' dest' selectionData'
    let result' = (/= 0) result
    touchManagedPtr dragDest
    touchManagedPtr dest
    touchManagedPtr selectionData
    return result'

#if ENABLE_OVERLOADING
data TreeDragDestDragDataReceivedMethodInfo
instance (signature ~ (Gtk.TreePath.TreePath -> Gtk.SelectionData.SelectionData -> m Bool), MonadIO m, IsTreeDragDest a) => O.MethodInfo TreeDragDestDragDataReceivedMethodInfo a signature where
    overloadedMethod _ = treeDragDestDragDataReceived

#endif

-- method TreeDragDest::row_drop_possible
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "drag_dest", argType = TInterface (Name {namespace = "Gtk", name = "TreeDragDest"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkTreeDragDest", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "dest_path", argType = TInterface (Name {namespace = "Gtk", name = "TreePath"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "destination row", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "selection_data", argType = TInterface (Name {namespace = "Gtk", name = "SelectionData"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the data being dragged", 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 "gtk_tree_drag_dest_row_drop_possible" gtk_tree_drag_dest_row_drop_possible ::
    Ptr TreeDragDest ->                     -- drag_dest : TInterface (Name {namespace = "Gtk", name = "TreeDragDest"})
    Ptr Gtk.TreePath.TreePath ->            -- dest_path : TInterface (Name {namespace = "Gtk", name = "TreePath"})
    Ptr Gtk.SelectionData.SelectionData ->  -- selection_data : TInterface (Name {namespace = "Gtk", name = "SelectionData"})
    IO CInt

{- |
Determines whether a drop is possible before the given /@destPath@/,
at the same depth as /@destPath@/. i.e., can we drop the data in
/@selectionData@/ at that location. /@destPath@/ does not have to
exist; the return value will almost certainly be 'False' if the
parent of /@destPath@/ doesn’t exist, though.
-}
treeDragDestRowDropPossible ::
    (B.CallStack.HasCallStack, MonadIO m, IsTreeDragDest a) =>
    a
    {- ^ /@dragDest@/: a 'GI.Gtk.Interfaces.TreeDragDest.TreeDragDest' -}
    -> Gtk.TreePath.TreePath
    {- ^ /@destPath@/: destination row -}
    -> Gtk.SelectionData.SelectionData
    {- ^ /@selectionData@/: the data being dragged -}
    -> m Bool
    {- ^ __Returns:__ 'True' if a drop is possible before /@destPath@/ -}
treeDragDestRowDropPossible dragDest destPath selectionData = liftIO $ do
    dragDest' <- unsafeManagedPtrCastPtr dragDest
    destPath' <- unsafeManagedPtrGetPtr destPath
    selectionData' <- unsafeManagedPtrGetPtr selectionData
    result <- gtk_tree_drag_dest_row_drop_possible dragDest' destPath' selectionData'
    let result' = (/= 0) result
    touchManagedPtr dragDest
    touchManagedPtr destPath
    touchManagedPtr selectionData
    return result'

#if ENABLE_OVERLOADING
data TreeDragDestRowDropPossibleMethodInfo
instance (signature ~ (Gtk.TreePath.TreePath -> Gtk.SelectionData.SelectionData -> m Bool), MonadIO m, IsTreeDragDest a) => O.MethodInfo TreeDragDestRowDropPossibleMethodInfo a signature where
    overloadedMethod _ = treeDragDestRowDropPossible

#endif