{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- t'GI.Gtk.Objects.EventControllerLegacy.EventControllerLegacy' is an event controller that gives you
-- direct access to the event stream. It should only be used as a
-- last resort if none of the other event controllers or gestures
-- do the job.

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

module GI.Gtk.Objects.EventControllerLegacy
    ( 

-- * Exported types
    EventControllerLegacy(..)               ,
    IsEventControllerLegacy                 ,
    toEventControllerLegacy                 ,
    noEventControllerLegacy                 ,


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

#if defined(ENABLE_OVERLOADING)
    ResolveEventControllerLegacyMethod      ,
#endif


-- ** new #method:new#

    eventControllerLegacyNew                ,




 -- * Signals
-- ** event #signal:event#

    C_EventControllerLegacyEventCallback    ,
    EventControllerLegacyEventCallback      ,
#if defined(ENABLE_OVERLOADING)
    EventControllerLegacyEventSignalInfo    ,
#endif
    afterEventControllerLegacyEvent         ,
    genClosure_EventControllerLegacyEvent   ,
    mk_EventControllerLegacyEventCallback   ,
    noEventControllerLegacyEventCallback    ,
    onEventControllerLegacyEvent            ,
    wrap_EventControllerLegacyEventCallback ,




    ) 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.GI.Base.Signals as B.Signals
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 qualified GI.Gdk.Objects.Event as Gdk.Event
import {-# SOURCE #-} qualified GI.Gtk.Objects.EventController as Gtk.EventController

-- | Memory-managed wrapper type.
newtype EventControllerLegacy = EventControllerLegacy (ManagedPtr EventControllerLegacy)
    deriving (EventControllerLegacy -> EventControllerLegacy -> Bool
(EventControllerLegacy -> EventControllerLegacy -> Bool)
-> (EventControllerLegacy -> EventControllerLegacy -> Bool)
-> Eq EventControllerLegacy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EventControllerLegacy -> EventControllerLegacy -> Bool
$c/= :: EventControllerLegacy -> EventControllerLegacy -> Bool
== :: EventControllerLegacy -> EventControllerLegacy -> Bool
$c== :: EventControllerLegacy -> EventControllerLegacy -> Bool
Eq)
foreign import ccall "gtk_event_controller_legacy_get_type"
    c_gtk_event_controller_legacy_get_type :: IO GType

instance GObject EventControllerLegacy where
    gobjectType :: IO GType
gobjectType = IO GType
c_gtk_event_controller_legacy_get_type
    

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

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

instance O.HasParentTypes EventControllerLegacy
type instance O.ParentTypes EventControllerLegacy = '[Gtk.EventController.EventController, GObject.Object.Object]

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

-- | A convenience alias for `Nothing` :: `Maybe` `EventControllerLegacy`.
noEventControllerLegacy :: Maybe EventControllerLegacy
noEventControllerLegacy :: Maybe EventControllerLegacy
noEventControllerLegacy = Maybe EventControllerLegacy
forall a. Maybe a
Nothing

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

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

#endif

-- signal EventControllerLegacy::event
-- | Emitted for each GDK event delivered to /@controller@/.
type EventControllerLegacyEventCallback =
    Gdk.Event.Event
    -- ^ /@event@/: the @/GdkEvent/@ which triggered this signal
    -> IO Bool
    -- ^ __Returns:__ 'P.True' to stop other handlers from being invoked for the event
    --    and the emission of this signal. 'P.False' to propagate the event further.

-- | A convenience synonym for @`Nothing` :: `Maybe` `EventControllerLegacyEventCallback`@.
noEventControllerLegacyEventCallback :: Maybe EventControllerLegacyEventCallback
noEventControllerLegacyEventCallback :: Maybe EventControllerLegacyEventCallback
noEventControllerLegacyEventCallback = Maybe EventControllerLegacyEventCallback
forall a. Maybe a
Nothing

-- | Type for the callback on the (unwrapped) C side.
type C_EventControllerLegacyEventCallback =
    Ptr () ->                               -- object
    Ptr Gdk.Event.Event ->
    Ptr () ->                               -- user_data
    IO CInt

-- | Generate a function pointer callable from C code, from a `C_EventControllerLegacyEventCallback`.
foreign import ccall "wrapper"
    mk_EventControllerLegacyEventCallback :: C_EventControllerLegacyEventCallback -> IO (FunPtr C_EventControllerLegacyEventCallback)

-- | Wrap the callback into a `GClosure`.
genClosure_EventControllerLegacyEvent :: MonadIO m => EventControllerLegacyEventCallback -> m (GClosure C_EventControllerLegacyEventCallback)
genClosure_EventControllerLegacyEvent :: EventControllerLegacyEventCallback
-> m (GClosure C_EventControllerLegacyEventCallback)
genClosure_EventControllerLegacyEvent cb :: EventControllerLegacyEventCallback
cb = IO (GClosure C_EventControllerLegacyEventCallback)
-> m (GClosure C_EventControllerLegacyEventCallback)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (GClosure C_EventControllerLegacyEventCallback)
 -> m (GClosure C_EventControllerLegacyEventCallback))
-> IO (GClosure C_EventControllerLegacyEventCallback)
-> m (GClosure C_EventControllerLegacyEventCallback)
forall a b. (a -> b) -> a -> b
$ do
    let cb' :: C_EventControllerLegacyEventCallback
cb' = EventControllerLegacyEventCallback
-> C_EventControllerLegacyEventCallback
wrap_EventControllerLegacyEventCallback EventControllerLegacyEventCallback
cb
    C_EventControllerLegacyEventCallback
-> IO (FunPtr C_EventControllerLegacyEventCallback)
mk_EventControllerLegacyEventCallback C_EventControllerLegacyEventCallback
cb' IO (FunPtr C_EventControllerLegacyEventCallback)
-> (FunPtr C_EventControllerLegacyEventCallback
    -> IO (GClosure C_EventControllerLegacyEventCallback))
-> IO (GClosure C_EventControllerLegacyEventCallback)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= FunPtr C_EventControllerLegacyEventCallback
-> IO (GClosure C_EventControllerLegacyEventCallback)
forall (m :: * -> *) a. MonadIO m => FunPtr a -> m (GClosure a)
B.GClosure.newGClosure


-- | Wrap a `EventControllerLegacyEventCallback` into a `C_EventControllerLegacyEventCallback`.
wrap_EventControllerLegacyEventCallback ::
    EventControllerLegacyEventCallback ->
    C_EventControllerLegacyEventCallback
wrap_EventControllerLegacyEventCallback :: EventControllerLegacyEventCallback
-> C_EventControllerLegacyEventCallback
wrap_EventControllerLegacyEventCallback _cb :: EventControllerLegacyEventCallback
_cb _ event :: Ptr Event
event _ = do
    Event
event' <- ((ManagedPtr Event -> Event) -> Ptr Event -> IO Event
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
newObject ManagedPtr Event -> Event
Gdk.Event.Event) Ptr Event
event
    Bool
result <- EventControllerLegacyEventCallback
_cb  Event
event'
    let result' :: CInt
result' = (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt) -> (Bool -> Int) -> Bool -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Int
forall a. Enum a => a -> Int
fromEnum) Bool
result
    CInt -> IO CInt
forall (m :: * -> *) a. Monad m => a -> m a
return CInt
result'


-- | Connect a signal handler for the [event](#signal:event) signal, to be run before the default handler.
-- When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to
-- 
-- @
-- 'Data.GI.Base.Signals.on' eventControllerLegacy #event callback
-- @
-- 
-- 
onEventControllerLegacyEvent :: (IsEventControllerLegacy a, MonadIO m) => a -> EventControllerLegacyEventCallback -> m SignalHandlerId
onEventControllerLegacyEvent :: a -> EventControllerLegacyEventCallback -> m SignalHandlerId
onEventControllerLegacyEvent obj :: a
obj cb :: EventControllerLegacyEventCallback
cb = IO SignalHandlerId -> m SignalHandlerId
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO SignalHandlerId -> m SignalHandlerId)
-> IO SignalHandlerId -> m SignalHandlerId
forall a b. (a -> b) -> a -> b
$ do
    let cb' :: C_EventControllerLegacyEventCallback
cb' = EventControllerLegacyEventCallback
-> C_EventControllerLegacyEventCallback
wrap_EventControllerLegacyEventCallback EventControllerLegacyEventCallback
cb
    FunPtr C_EventControllerLegacyEventCallback
cb'' <- C_EventControllerLegacyEventCallback
-> IO (FunPtr C_EventControllerLegacyEventCallback)
mk_EventControllerLegacyEventCallback C_EventControllerLegacyEventCallback
cb'
    a
-> Text
-> FunPtr C_EventControllerLegacyEventCallback
-> SignalConnectMode
-> Maybe Text
-> IO SignalHandlerId
forall o a.
GObject o =>
o
-> Text
-> FunPtr a
-> SignalConnectMode
-> Maybe Text
-> IO SignalHandlerId
connectSignalFunPtr a
obj "event" FunPtr C_EventControllerLegacyEventCallback
cb'' SignalConnectMode
SignalConnectBefore Maybe Text
forall a. Maybe a
Nothing

-- | Connect a signal handler for the [event](#signal:event) signal, to be run after the default handler.
-- When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to
-- 
-- @
-- 'Data.GI.Base.Signals.after' eventControllerLegacy #event callback
-- @
-- 
-- 
afterEventControllerLegacyEvent :: (IsEventControllerLegacy a, MonadIO m) => a -> EventControllerLegacyEventCallback -> m SignalHandlerId
afterEventControllerLegacyEvent :: a -> EventControllerLegacyEventCallback -> m SignalHandlerId
afterEventControllerLegacyEvent obj :: a
obj cb :: EventControllerLegacyEventCallback
cb = IO SignalHandlerId -> m SignalHandlerId
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO SignalHandlerId -> m SignalHandlerId)
-> IO SignalHandlerId -> m SignalHandlerId
forall a b. (a -> b) -> a -> b
$ do
    let cb' :: C_EventControllerLegacyEventCallback
cb' = EventControllerLegacyEventCallback
-> C_EventControllerLegacyEventCallback
wrap_EventControllerLegacyEventCallback EventControllerLegacyEventCallback
cb
    FunPtr C_EventControllerLegacyEventCallback
cb'' <- C_EventControllerLegacyEventCallback
-> IO (FunPtr C_EventControllerLegacyEventCallback)
mk_EventControllerLegacyEventCallback C_EventControllerLegacyEventCallback
cb'
    a
-> Text
-> FunPtr C_EventControllerLegacyEventCallback
-> SignalConnectMode
-> Maybe Text
-> IO SignalHandlerId
forall o a.
GObject o =>
o
-> Text
-> FunPtr a
-> SignalConnectMode
-> Maybe Text
-> IO SignalHandlerId
connectSignalFunPtr a
obj "event" FunPtr C_EventControllerLegacyEventCallback
cb'' SignalConnectMode
SignalConnectAfter Maybe Text
forall a. Maybe a
Nothing


#if defined(ENABLE_OVERLOADING)
data EventControllerLegacyEventSignalInfo
instance SignalInfo EventControllerLegacyEventSignalInfo where
    type HaskellCallbackType EventControllerLegacyEventSignalInfo = EventControllerLegacyEventCallback
    connectSignal obj cb connectMode detail = do
        let cb' = wrap_EventControllerLegacyEventCallback cb
        cb'' <- mk_EventControllerLegacyEventCallback cb'
        connectSignalFunPtr obj "event" cb'' connectMode detail

#endif

#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList EventControllerLegacy
type instance O.AttributeList EventControllerLegacy = EventControllerLegacyAttributeList
type EventControllerLegacyAttributeList = ('[ '("propagationPhase", Gtk.EventController.EventControllerPropagationPhasePropertyInfo), '("widget", Gtk.EventController.EventControllerWidgetPropertyInfo)] :: [(Symbol, *)])
#endif

#if defined(ENABLE_OVERLOADING)
#endif

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

#endif

-- method EventControllerLegacy::new
-- method type : Constructor
-- Args: []
-- Lengths: []
-- returnType: Just
--               (TInterface
--                  Name { namespace = "Gtk" , name = "EventControllerLegacy" })
-- throws : False
-- Skip return : False

foreign import ccall "gtk_event_controller_legacy_new" gtk_event_controller_legacy_new :: 
    IO (Ptr EventControllerLegacy)

-- | Creates a new legacy event controller.
eventControllerLegacyNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m EventControllerLegacy
    -- ^ __Returns:__ the newly created event controller.
eventControllerLegacyNew :: m EventControllerLegacy
eventControllerLegacyNew  = IO EventControllerLegacy -> m EventControllerLegacy
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO EventControllerLegacy -> m EventControllerLegacy)
-> IO EventControllerLegacy -> m EventControllerLegacy
forall a b. (a -> b) -> a -> b
$ do
    Ptr EventControllerLegacy
result <- IO (Ptr EventControllerLegacy)
gtk_event_controller_legacy_new
    Text -> Ptr EventControllerLegacy -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL "eventControllerLegacyNew" Ptr EventControllerLegacy
result
    EventControllerLegacy
result' <- ((ManagedPtr EventControllerLegacy -> EventControllerLegacy)
-> Ptr EventControllerLegacy -> IO EventControllerLegacy
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
wrapObject ManagedPtr EventControllerLegacy -> EventControllerLegacy
EventControllerLegacy) Ptr EventControllerLegacy
result
    EventControllerLegacy -> IO EventControllerLegacy
forall (m :: * -> *) a. Monad m => a -> m a
return EventControllerLegacy
result'

#if defined(ENABLE_OVERLOADING)
#endif