{- |
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.WebKit2.Objects.EditorState
    ( 

-- * Exported types
    EditorState(..)                         ,
    IsEditorState                           ,
    toEditorState                           ,
    noEditorState                           ,


 -- * Methods
-- ** getTypingAttributes #method:getTypingAttributes#
    EditorStateGetTypingAttributesMethodInfo,
    editorStateGetTypingAttributes          ,




 -- * Properties
-- ** typingAttributes #attr:typingAttributes#
    EditorStateTypingAttributesPropertyInfo ,
    editorStateTypingAttributes             ,
    getEditorStateTypingAttributes          ,




    ) 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

newtype EditorState = EditorState (ManagedPtr EditorState)
foreign import ccall "webkit_editor_state_get_type"
    c_webkit_editor_state_get_type :: IO GType

instance GObject EditorState where
    gobjectType _ = c_webkit_editor_state_get_type
    

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

toEditorState :: IsEditorState o => o -> IO EditorState
toEditorState = unsafeCastTo EditorState

noEditorState :: Maybe EditorState
noEditorState = Nothing

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

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

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

-- VVV Prop "typing-attributes"
   -- Type: TBasicType TUInt
   -- Flags: [PropertyReadable]
   -- Nullable: (Just False,Nothing)

getEditorStateTypingAttributes :: (MonadIO m, IsEditorState o) => o -> m Word32
getEditorStateTypingAttributes obj = liftIO $ getObjectPropertyUInt32 obj "typing-attributes"

data EditorStateTypingAttributesPropertyInfo
instance AttrInfo EditorStateTypingAttributesPropertyInfo where
    type AttrAllowedOps EditorStateTypingAttributesPropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint EditorStateTypingAttributesPropertyInfo = (~) ()
    type AttrBaseTypeConstraint EditorStateTypingAttributesPropertyInfo = IsEditorState
    type AttrGetType EditorStateTypingAttributesPropertyInfo = Word32
    type AttrLabel EditorStateTypingAttributesPropertyInfo = "typing-attributes"
    type AttrOrigin EditorStateTypingAttributesPropertyInfo = EditorState
    attrGet _ = getEditorStateTypingAttributes
    attrSet _ = undefined
    attrConstruct _ = undefined
    attrClear _ = undefined

instance O.HasAttributeList EditorState
type instance O.AttributeList EditorState = EditorStateAttributeList
type EditorStateAttributeList = ('[ '("typingAttributes", EditorStateTypingAttributesPropertyInfo)] :: [(Symbol, *)])

editorStateTypingAttributes :: AttrLabelProxy "typingAttributes"
editorStateTypingAttributes = AttrLabelProxy

type instance O.SignalList EditorState = EditorStateSignalList
type EditorStateSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

-- method EditorState::get_typing_attributes
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "editor_state", argType = TInterface (Name {namespace = "WebKit2", name = "EditorState"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #WebKitEditorState", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUInt)
-- throws : False
-- Skip return : False

foreign import ccall "webkit_editor_state_get_typing_attributes" webkit_editor_state_get_typing_attributes :: 
    Ptr EditorState ->                      -- editor_state : TInterface (Name {namespace = "WebKit2", name = "EditorState"})
    IO Word32

{- |
Gets the typing attributes at the current cursor position.
If there is a selection, this returns the typing attributes
of the the selected text. Note that in case of a selection,
typing attributes are considered active only when they are
present throughout the selection.

@since 2.10
-}
editorStateGetTypingAttributes ::
    (B.CallStack.HasCallStack, MonadIO m, IsEditorState a) =>
    a
    {- ^ /@editorState@/: a 'GI.WebKit2.Objects.EditorState.EditorState' -}
    -> m Word32
    {- ^ __Returns:__ a bitmask of 'GI.WebKit2.Flags.EditorTypingAttributes' flags -}
editorStateGetTypingAttributes editorState = liftIO $ do
    editorState' <- unsafeManagedPtrCastPtr editorState
    result <- webkit_editor_state_get_typing_attributes editorState'
    touchManagedPtr editorState
    return result

data EditorStateGetTypingAttributesMethodInfo
instance (signature ~ (m Word32), MonadIO m, IsEditorState a) => O.MethodInfo EditorStateGetTypingAttributesMethodInfo a signature where
    overloadedMethod _ = editorStateGetTypingAttributes