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

module GI.WebKit2WebExtension.Objects.WebEditor
    ( 

-- * Exported types
    WebEditor(..)                           ,
    IsWebEditor                             ,
    toWebEditor                             ,
    noWebEditor                             ,


 -- * Methods
-- ** getPage #method:getPage#
    WebEditorGetPageMethodInfo              ,
    webEditorGetPage                        ,




 -- * Signals
-- ** selectionChanged #signal:selectionChanged#
    C_WebEditorSelectionChangedCallback     ,
    WebEditorSelectionChangedCallback       ,
    WebEditorSelectionChangedSignalInfo     ,
    afterWebEditorSelectionChanged          ,
    genClosure_WebEditorSelectionChanged    ,
    mk_WebEditorSelectionChangedCallback    ,
    noWebEditorSelectionChangedCallback     ,
    onWebEditorSelectionChanged             ,
    wrap_WebEditorSelectionChangedCallback  ,




    ) 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.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 qualified GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.WebKit2WebExtension.Objects.WebPage as WebKit2WebExtension.WebPage

newtype WebEditor = WebEditor (ManagedPtr WebEditor)
foreign import ccall "webkit_web_editor_get_type"
    c_webkit_web_editor_get_type :: IO GType

instance GObject WebEditor where
    gobjectType _ = c_webkit_web_editor_get_type
    

class GObject o => IsWebEditor o
#if MIN_VERSION_base(4,9,0)
instance {-# OVERLAPPABLE #-} (GObject a, O.UnknownAncestorError WebEditor a) =>
    IsWebEditor a
#endif
instance IsWebEditor WebEditor
instance GObject.Object.IsObject WebEditor

toWebEditor :: IsWebEditor o => o -> IO WebEditor
toWebEditor = unsafeCastTo WebEditor

noWebEditor :: Maybe WebEditor
noWebEditor = Nothing

type family ResolveWebEditorMethod (t :: Symbol) (o :: *) :: * where
    ResolveWebEditorMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveWebEditorMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveWebEditorMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveWebEditorMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveWebEditorMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveWebEditorMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveWebEditorMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveWebEditorMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveWebEditorMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveWebEditorMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolveWebEditorMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    ResolveWebEditorMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveWebEditorMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveWebEditorMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveWebEditorMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveWebEditorMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveWebEditorMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveWebEditorMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveWebEditorMethod "getPage" o = WebEditorGetPageMethodInfo
    ResolveWebEditorMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveWebEditorMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveWebEditorMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveWebEditorMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveWebEditorMethod l o = O.MethodResolutionFailed l o

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

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveWebEditorMethod t WebEditor, O.MethodInfo info WebEditor p) => O.IsLabel t (WebEditor -> p) where
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif

-- signal WebEditor::selection-changed
type WebEditorSelectionChangedCallback =
    IO ()

noWebEditorSelectionChangedCallback :: Maybe WebEditorSelectionChangedCallback
noWebEditorSelectionChangedCallback = Nothing

type C_WebEditorSelectionChangedCallback =
    Ptr () ->                               -- object
    Ptr () ->                               -- user_data
    IO ()

foreign import ccall "wrapper"
    mk_WebEditorSelectionChangedCallback :: C_WebEditorSelectionChangedCallback -> IO (FunPtr C_WebEditorSelectionChangedCallback)

genClosure_WebEditorSelectionChanged :: WebEditorSelectionChangedCallback -> IO Closure
genClosure_WebEditorSelectionChanged cb = do
    let cb' = wrap_WebEditorSelectionChangedCallback cb
    mk_WebEditorSelectionChangedCallback cb' >>= newCClosure


wrap_WebEditorSelectionChangedCallback ::
    WebEditorSelectionChangedCallback ->
    Ptr () ->
    Ptr () ->
    IO ()
wrap_WebEditorSelectionChangedCallback _cb _ _ = do
    _cb 


onWebEditorSelectionChanged :: (IsWebEditor a, MonadIO m) => a -> WebEditorSelectionChangedCallback -> m SignalHandlerId
onWebEditorSelectionChanged obj cb = liftIO $ do
    let cb' = wrap_WebEditorSelectionChangedCallback cb
    cb'' <- mk_WebEditorSelectionChangedCallback cb'
    connectSignalFunPtr obj "selection-changed" cb'' SignalConnectBefore

afterWebEditorSelectionChanged :: (IsWebEditor a, MonadIO m) => a -> WebEditorSelectionChangedCallback -> m SignalHandlerId
afterWebEditorSelectionChanged obj cb = liftIO $ do
    let cb' = wrap_WebEditorSelectionChangedCallback cb
    cb'' <- mk_WebEditorSelectionChangedCallback cb'
    connectSignalFunPtr obj "selection-changed" cb'' SignalConnectAfter


instance O.HasAttributeList WebEditor
type instance O.AttributeList WebEditor = WebEditorAttributeList
type WebEditorAttributeList = ('[ ] :: [(Symbol, *)])

data WebEditorSelectionChangedSignalInfo
instance SignalInfo WebEditorSelectionChangedSignalInfo where
    type HaskellCallbackType WebEditorSelectionChangedSignalInfo = WebEditorSelectionChangedCallback
    connectSignal _ obj cb connectMode = do
        let cb' = wrap_WebEditorSelectionChangedCallback cb
        cb'' <- mk_WebEditorSelectionChangedCallback cb'
        connectSignalFunPtr obj "selection-changed" cb'' connectMode

type instance O.SignalList WebEditor = WebEditorSignalList
type WebEditorSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo), '("selectionChanged", WebEditorSelectionChangedSignalInfo)] :: [(Symbol, *)])

-- method WebEditor::get_page
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "editor", argType = TInterface (Name {namespace = "WebKit2WebExtension", name = "WebEditor"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #WebKitWebEditor", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "WebKit2WebExtension", name = "WebPage"}))
-- throws : False
-- Skip return : False

foreign import ccall "webkit_web_editor_get_page" webkit_web_editor_get_page :: 
    Ptr WebEditor ->                        -- editor : TInterface (Name {namespace = "WebKit2WebExtension", name = "WebEditor"})
    IO (Ptr WebKit2WebExtension.WebPage.WebPage)

{- |
Gets the 'GI.WebKit2WebExtension.Objects.WebPage.WebPage' that is associated with the 'GI.WebKit2WebExtension.Objects.WebEditor.WebEditor' that can
be used to access the 'GI.WebKit2WebExtension.Objects.DOMDocument.DOMDocument' currently loaded into it.

@since 2.10
-}
webEditorGetPage ::
    (B.CallStack.HasCallStack, MonadIO m, IsWebEditor a) =>
    a
    {- ^ /@editor@/: a 'GI.WebKit2WebExtension.Objects.WebEditor.WebEditor' -}
    -> m WebKit2WebExtension.WebPage.WebPage
    {- ^ __Returns:__ the associated 'GI.WebKit2WebExtension.Objects.WebPage.WebPage' -}
webEditorGetPage editor = liftIO $ do
    editor' <- unsafeManagedPtrCastPtr editor
    result <- webkit_web_editor_get_page editor'
    checkUnexpectedReturnNULL "webEditorGetPage" result
    result' <- (newObject WebKit2WebExtension.WebPage.WebPage) result
    touchManagedPtr editor
    return result'

data WebEditorGetPageMethodInfo
instance (signature ~ (m WebKit2WebExtension.WebPage.WebPage), MonadIO m, IsWebEditor a) => O.MethodInfo WebEditorGetPageMethodInfo a signature where
    overloadedMethod _ = webEditorGetPage