{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- An event related to a scrolling motion.

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

module GI.Gdk.Objects.ScrollEvent
    ( 

-- * Exported types
    ScrollEvent(..)                         ,
    IsScrollEvent                           ,
    toScrollEvent                           ,


 -- * Methods
-- | 
-- 
--  === __Click to display all available methods, including inherited ones__
-- ==== Methods
-- [isStop]("GI.Gdk.Objects.ScrollEvent#g:method:isStop"), [ref]("GI.Gdk.Objects.Event#g:method:ref"), [triggersContextMenu]("GI.Gdk.Objects.Event#g:method:triggersContextMenu"), [unref]("GI.Gdk.Objects.Event#g:method:unref").
-- 
-- ==== Getters
-- [getAxes]("GI.Gdk.Objects.Event#g:method:getAxes"), [getAxis]("GI.Gdk.Objects.Event#g:method:getAxis"), [getDeltas]("GI.Gdk.Objects.ScrollEvent#g:method:getDeltas"), [getDevice]("GI.Gdk.Objects.Event#g:method:getDevice"), [getDeviceTool]("GI.Gdk.Objects.Event#g:method:getDeviceTool"), [getDirection]("GI.Gdk.Objects.ScrollEvent#g:method:getDirection"), [getDisplay]("GI.Gdk.Objects.Event#g:method:getDisplay"), [getEventSequence]("GI.Gdk.Objects.Event#g:method:getEventSequence"), [getEventType]("GI.Gdk.Objects.Event#g:method:getEventType"), [getHistory]("GI.Gdk.Objects.Event#g:method:getHistory"), [getModifierState]("GI.Gdk.Objects.Event#g:method:getModifierState"), [getPointerEmulated]("GI.Gdk.Objects.Event#g:method:getPointerEmulated"), [getPosition]("GI.Gdk.Objects.Event#g:method:getPosition"), [getSeat]("GI.Gdk.Objects.Event#g:method:getSeat"), [getSurface]("GI.Gdk.Objects.Event#g:method:getSurface"), [getTime]("GI.Gdk.Objects.Event#g:method:getTime").
-- 
-- ==== Setters
-- /None/.

#if defined(ENABLE_OVERLOADING)
    ResolveScrollEventMethod                ,
#endif

-- ** getDeltas #method:getDeltas#

#if defined(ENABLE_OVERLOADING)
    ScrollEventGetDeltasMethodInfo          ,
#endif
    scrollEventGetDeltas                    ,


-- ** getDirection #method:getDirection#

#if defined(ENABLE_OVERLOADING)
    ScrollEventGetDirectionMethodInfo       ,
#endif
    scrollEventGetDirection                 ,


-- ** isStop #method:isStop#

#if defined(ENABLE_OVERLOADING)
    ScrollEventIsStopMethodInfo             ,
#endif
    scrollEventIsStop                       ,




    ) 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.GArray as B.GArray
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 GHC.Records as R

import {-# SOURCE #-} qualified GI.Gdk.Enums as Gdk.Enums
import {-# SOURCE #-} qualified GI.Gdk.Objects.Event as Gdk.Event

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

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

foreign import ccall "gdk_scroll_event_get_type"
    c_gdk_scroll_event_get_type :: IO B.Types.GType

instance B.Types.TypedObject ScrollEvent where
    glibType :: IO GType
glibType = IO GType
c_gdk_scroll_event_get_type

-- | Type class for types which can be safely cast to `ScrollEvent`, for instance with `toScrollEvent`.
class (SP.BoxedPtr o, SP.TypedObject o, O.IsDescendantOf ScrollEvent o) => IsScrollEvent o
instance (SP.BoxedPtr o, SP.TypedObject o, O.IsDescendantOf ScrollEvent o) => IsScrollEvent o

instance O.HasParentTypes ScrollEvent
type instance O.ParentTypes ScrollEvent = '[Gdk.Event.Event]

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

--- XXX Missing getter and/or setter, so no GValue instance could be generated.
#if defined(ENABLE_OVERLOADING)
type family ResolveScrollEventMethod (t :: Symbol) (o :: *) :: * where
    ResolveScrollEventMethod "isStop" o = ScrollEventIsStopMethodInfo
    ResolveScrollEventMethod "ref" o = Gdk.Event.EventRefMethodInfo
    ResolveScrollEventMethod "triggersContextMenu" o = Gdk.Event.EventTriggersContextMenuMethodInfo
    ResolveScrollEventMethod "unref" o = Gdk.Event.EventUnrefMethodInfo
    ResolveScrollEventMethod "getAxes" o = Gdk.Event.EventGetAxesMethodInfo
    ResolveScrollEventMethod "getAxis" o = Gdk.Event.EventGetAxisMethodInfo
    ResolveScrollEventMethod "getDeltas" o = ScrollEventGetDeltasMethodInfo
    ResolveScrollEventMethod "getDevice" o = Gdk.Event.EventGetDeviceMethodInfo
    ResolveScrollEventMethod "getDeviceTool" o = Gdk.Event.EventGetDeviceToolMethodInfo
    ResolveScrollEventMethod "getDirection" o = ScrollEventGetDirectionMethodInfo
    ResolveScrollEventMethod "getDisplay" o = Gdk.Event.EventGetDisplayMethodInfo
    ResolveScrollEventMethod "getEventSequence" o = Gdk.Event.EventGetEventSequenceMethodInfo
    ResolveScrollEventMethod "getEventType" o = Gdk.Event.EventGetEventTypeMethodInfo
    ResolveScrollEventMethod "getHistory" o = Gdk.Event.EventGetHistoryMethodInfo
    ResolveScrollEventMethod "getModifierState" o = Gdk.Event.EventGetModifierStateMethodInfo
    ResolveScrollEventMethod "getPointerEmulated" o = Gdk.Event.EventGetPointerEmulatedMethodInfo
    ResolveScrollEventMethod "getPosition" o = Gdk.Event.EventGetPositionMethodInfo
    ResolveScrollEventMethod "getSeat" o = Gdk.Event.EventGetSeatMethodInfo
    ResolveScrollEventMethod "getSurface" o = Gdk.Event.EventGetSurfaceMethodInfo
    ResolveScrollEventMethod "getTime" o = Gdk.Event.EventGetTimeMethodInfo
    ResolveScrollEventMethod l o = O.MethodResolutionFailed l o

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

#if MIN_VERSION_base(4,13,0)
instance (info ~ ResolveScrollEventMethod t ScrollEvent, O.OverloadedMethod info ScrollEvent p, R.HasField t ScrollEvent p) => R.HasField t ScrollEvent p where
    getField = O.overloadedMethod @info

#endif

instance (info ~ ResolveScrollEventMethod t ScrollEvent, O.OverloadedMethodInfo info ScrollEvent) => OL.IsLabel t (O.MethodProxy info ScrollEvent) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.MethodProxy
#else
    fromLabel _ = O.MethodProxy
#endif

#endif

-- XXX Wrapping a foreign struct/union with no known destructor or size, leak?
instance BoxedPtr ScrollEvent where
    boxedPtrCopy :: ScrollEvent -> IO ScrollEvent
boxedPtrCopy = ScrollEvent -> IO ScrollEvent
forall (m :: * -> *) a. Monad m => a -> m a
return
    boxedPtrFree :: ScrollEvent -> IO ()
boxedPtrFree = \ScrollEvent
_x -> () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()


-- method ScrollEvent::get_deltas
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "event"
--           , argType =
--               TInterface Name { namespace = "Gdk" , name = "ScrollEvent" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a scroll event" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "delta_x"
--           , argType = TBasicType TDouble
--           , direction = DirectionOut
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "return location for x scroll delta"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferEverything
--           }
--       , Arg
--           { argCName = "delta_y"
--           , argType = TBasicType TDouble
--           , direction = DirectionOut
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "return location for y scroll delta"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferEverything
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gdk_scroll_event_get_deltas" gdk_scroll_event_get_deltas :: 
    Ptr ScrollEvent ->                      -- event : TInterface (Name {namespace = "Gdk", name = "ScrollEvent"})
    Ptr CDouble ->                          -- delta_x : TBasicType TDouble
    Ptr CDouble ->                          -- delta_y : TBasicType TDouble
    IO ()

-- | Extracts the scroll deltas of a scroll event.
-- 
-- The deltas will be zero unless the scroll direction
-- is 'GI.Gdk.Enums.ScrollDirectionSmooth'.
scrollEventGetDeltas ::
    (B.CallStack.HasCallStack, MonadIO m, IsScrollEvent a) =>
    a
    -- ^ /@event@/: a scroll event
    -> m ((Double, Double))
scrollEventGetDeltas :: forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsScrollEvent a) =>
a -> m (Double, Double)
scrollEventGetDeltas a
event = IO (Double, Double) -> m (Double, Double)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Double, Double) -> m (Double, Double))
-> IO (Double, Double) -> m (Double, Double)
forall a b. (a -> b) -> a -> b
$ do
    Ptr ScrollEvent
event' <- a -> IO (Ptr ScrollEvent)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
event
    Ptr CDouble
deltaX <- IO (Ptr CDouble)
forall a. Storable a => IO (Ptr a)
allocMem :: IO (Ptr CDouble)
    Ptr CDouble
deltaY <- IO (Ptr CDouble)
forall a. Storable a => IO (Ptr a)
allocMem :: IO (Ptr CDouble)
    Ptr ScrollEvent -> Ptr CDouble -> Ptr CDouble -> IO ()
gdk_scroll_event_get_deltas Ptr ScrollEvent
event' Ptr CDouble
deltaX Ptr CDouble
deltaY
    CDouble
deltaX' <- Ptr CDouble -> IO CDouble
forall a. Storable a => Ptr a -> IO a
peek Ptr CDouble
deltaX
    let deltaX'' :: Double
deltaX'' = CDouble -> Double
forall a b. (Real a, Fractional b) => a -> b
realToFrac CDouble
deltaX'
    CDouble
deltaY' <- Ptr CDouble -> IO CDouble
forall a. Storable a => Ptr a -> IO a
peek Ptr CDouble
deltaY
    let deltaY'' :: Double
deltaY'' = CDouble -> Double
forall a b. (Real a, Fractional b) => a -> b
realToFrac CDouble
deltaY'
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
event
    Ptr CDouble -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CDouble
deltaX
    Ptr CDouble -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CDouble
deltaY
    (Double, Double) -> IO (Double, Double)
forall (m :: * -> *) a. Monad m => a -> m a
return (Double
deltaX'', Double
deltaY'')

#if defined(ENABLE_OVERLOADING)
data ScrollEventGetDeltasMethodInfo
instance (signature ~ (m ((Double, Double))), MonadIO m, IsScrollEvent a) => O.OverloadedMethod ScrollEventGetDeltasMethodInfo a signature where
    overloadedMethod = scrollEventGetDeltas

instance O.OverloadedMethodInfo ScrollEventGetDeltasMethodInfo a where
    overloadedMethodInfo = O.MethodInfo {
        O.overloadedMethodName = "GI.Gdk.Objects.ScrollEvent.scrollEventGetDeltas",
        O.overloadedMethodURL = "https://hackage.haskell.org/package/gi-gdk-4.0.3/docs/GI-Gdk-Objects-ScrollEvent.html#v:scrollEventGetDeltas"
        }


#endif

-- method ScrollEvent::get_direction
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "event"
--           , argType =
--               TInterface Name { namespace = "Gdk" , name = "ScrollEvent" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a scroll event" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just
--               (TInterface Name { namespace = "Gdk" , name = "ScrollDirection" })
-- throws : False
-- Skip return : False

foreign import ccall "gdk_scroll_event_get_direction" gdk_scroll_event_get_direction :: 
    Ptr ScrollEvent ->                      -- event : TInterface (Name {namespace = "Gdk", name = "ScrollEvent"})
    IO CUInt

-- | Extracts the direction of a scroll event.
scrollEventGetDirection ::
    (B.CallStack.HasCallStack, MonadIO m, IsScrollEvent a) =>
    a
    -- ^ /@event@/: a scroll event
    -> m Gdk.Enums.ScrollDirection
    -- ^ __Returns:__ the scroll direction of /@event@/
scrollEventGetDirection :: forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsScrollEvent a) =>
a -> m ScrollDirection
scrollEventGetDirection a
event = IO ScrollDirection -> m ScrollDirection
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ScrollDirection -> m ScrollDirection)
-> IO ScrollDirection -> m ScrollDirection
forall a b. (a -> b) -> a -> b
$ do
    Ptr ScrollEvent
event' <- a -> IO (Ptr ScrollEvent)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
event
    CUInt
result <- Ptr ScrollEvent -> IO CUInt
gdk_scroll_event_get_direction Ptr ScrollEvent
event'
    let result' :: ScrollDirection
result' = (Int -> ScrollDirection
forall a. Enum a => Int -> a
toEnum (Int -> ScrollDirection)
-> (CUInt -> Int) -> CUInt -> ScrollDirection
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CUInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral) CUInt
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
event
    ScrollDirection -> IO ScrollDirection
forall (m :: * -> *) a. Monad m => a -> m a
return ScrollDirection
result'

#if defined(ENABLE_OVERLOADING)
data ScrollEventGetDirectionMethodInfo
instance (signature ~ (m Gdk.Enums.ScrollDirection), MonadIO m, IsScrollEvent a) => O.OverloadedMethod ScrollEventGetDirectionMethodInfo a signature where
    overloadedMethod = scrollEventGetDirection

instance O.OverloadedMethodInfo ScrollEventGetDirectionMethodInfo a where
    overloadedMethodInfo = O.MethodInfo {
        O.overloadedMethodName = "GI.Gdk.Objects.ScrollEvent.scrollEventGetDirection",
        O.overloadedMethodURL = "https://hackage.haskell.org/package/gi-gdk-4.0.3/docs/GI-Gdk-Objects-ScrollEvent.html#v:scrollEventGetDirection"
        }


#endif

-- method ScrollEvent::is_stop
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "event"
--           , argType =
--               TInterface Name { namespace = "Gdk" , name = "ScrollEvent" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a scroll event" , 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 "gdk_scroll_event_is_stop" gdk_scroll_event_is_stop :: 
    Ptr ScrollEvent ->                      -- event : TInterface (Name {namespace = "Gdk", name = "ScrollEvent"})
    IO CInt

-- | Check whether a scroll event is a stop scroll event. Scroll sequences
-- with smooth scroll information may provide a stop scroll event once the
-- interaction with the device finishes, e.g. by lifting a finger. This
-- stop scroll event is the signal that a widget may trigger kinetic
-- scrolling based on the current velocity.
-- 
-- Stop scroll events always have a delta of 0\/0.
scrollEventIsStop ::
    (B.CallStack.HasCallStack, MonadIO m, IsScrollEvent a) =>
    a
    -- ^ /@event@/: a scroll event
    -> m Bool
    -- ^ __Returns:__ 'P.True' if the event is a scroll stop event
scrollEventIsStop :: forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsScrollEvent a) =>
a -> m Bool
scrollEventIsStop a
event = IO Bool -> m Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ do
    Ptr ScrollEvent
event' <- a -> IO (Ptr ScrollEvent)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
event
    CInt
result <- Ptr ScrollEvent -> IO CInt
gdk_scroll_event_is_stop Ptr ScrollEvent
event'
    let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
0) CInt
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
event
    Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
result'

#if defined(ENABLE_OVERLOADING)
data ScrollEventIsStopMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsScrollEvent a) => O.OverloadedMethod ScrollEventIsStopMethodInfo a signature where
    overloadedMethod = scrollEventIsStop

instance O.OverloadedMethodInfo ScrollEventIsStopMethodInfo a where
    overloadedMethodInfo = O.MethodInfo {
        O.overloadedMethodName = "GI.Gdk.Objects.ScrollEvent.scrollEventIsStop",
        O.overloadedMethodURL = "https://hackage.haskell.org/package/gi-gdk-4.0.3/docs/GI-Gdk-Objects-ScrollEvent.html#v:scrollEventIsStop"
        }


#endif