{- |
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.GtkSource.Objects.Mark
    ( 

-- * Exported types
    Mark(..)                                ,
    IsMark                                  ,
    toMark                                  ,
    noMark                                  ,


 -- * Methods
-- ** getCategory #method:getCategory#
    MarkGetCategoryMethodInfo               ,
    markGetCategory                         ,


-- ** new #method:new#
    markNew                                 ,


-- ** next #method:next#
    MarkNextMethodInfo                      ,
    markNext                                ,


-- ** prev #method:prev#
    MarkPrevMethodInfo                      ,
    markPrev                                ,




 -- * Properties
-- ** category #attr:category#
    MarkCategoryPropertyInfo                ,
    constructMarkCategory                   ,
    getMarkCategory                         ,
    markCategory                            ,




    ) 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 qualified GI.Gtk.Objects.TextMark as Gtk.TextMark

newtype Mark = Mark (ManagedPtr Mark)
foreign import ccall "gtk_source_mark_get_type"
    c_gtk_source_mark_get_type :: IO GType

instance GObject Mark where
    gobjectType _ = c_gtk_source_mark_get_type
    

class GObject o => IsMark o
#if MIN_VERSION_base(4,9,0)
instance {-# OVERLAPPABLE #-} (GObject a, O.UnknownAncestorError Mark a) =>
    IsMark a
#endif
instance IsMark Mark
instance Gtk.TextMark.IsTextMark Mark
instance GObject.Object.IsObject Mark

toMark :: IsMark o => o -> IO Mark
toMark = unsafeCastTo Mark

noMark :: Maybe Mark
noMark = Nothing

type family ResolveMarkMethod (t :: Symbol) (o :: *) :: * where
    ResolveMarkMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveMarkMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveMarkMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveMarkMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveMarkMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveMarkMethod "next" o = MarkNextMethodInfo
    ResolveMarkMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveMarkMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveMarkMethod "prev" o = MarkPrevMethodInfo
    ResolveMarkMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveMarkMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveMarkMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolveMarkMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    ResolveMarkMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveMarkMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveMarkMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveMarkMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveMarkMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveMarkMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveMarkMethod "getBuffer" o = Gtk.TextMark.TextMarkGetBufferMethodInfo
    ResolveMarkMethod "getCategory" o = MarkGetCategoryMethodInfo
    ResolveMarkMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveMarkMethod "getDeleted" o = Gtk.TextMark.TextMarkGetDeletedMethodInfo
    ResolveMarkMethod "getLeftGravity" o = Gtk.TextMark.TextMarkGetLeftGravityMethodInfo
    ResolveMarkMethod "getName" o = Gtk.TextMark.TextMarkGetNameMethodInfo
    ResolveMarkMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveMarkMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveMarkMethod "getVisible" o = Gtk.TextMark.TextMarkGetVisibleMethodInfo
    ResolveMarkMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveMarkMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveMarkMethod "setVisible" o = Gtk.TextMark.TextMarkSetVisibleMethodInfo
    ResolveMarkMethod l o = O.MethodResolutionFailed l o

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

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

-- VVV Prop "category"
   -- Type: TBasicType TUTF8
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly]
   -- Nullable: (Just False,Nothing)

getMarkCategory :: (MonadIO m, IsMark o) => o -> m T.Text
getMarkCategory obj = liftIO $ checkUnexpectedNothing "getMarkCategory" $ getObjectPropertyString obj "category"

constructMarkCategory :: (IsMark o) => T.Text -> IO (GValueConstruct o)
constructMarkCategory val = constructObjectPropertyString "category" (Just val)

data MarkCategoryPropertyInfo
instance AttrInfo MarkCategoryPropertyInfo where
    type AttrAllowedOps MarkCategoryPropertyInfo = '[ 'AttrConstruct, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint MarkCategoryPropertyInfo = (~) T.Text
    type AttrBaseTypeConstraint MarkCategoryPropertyInfo = IsMark
    type AttrGetType MarkCategoryPropertyInfo = T.Text
    type AttrLabel MarkCategoryPropertyInfo = "category"
    type AttrOrigin MarkCategoryPropertyInfo = Mark
    attrGet _ = getMarkCategory
    attrSet _ = undefined
    attrConstruct _ = constructMarkCategory
    attrClear _ = undefined

instance O.HasAttributeList Mark
type instance O.AttributeList Mark = MarkAttributeList
type MarkAttributeList = ('[ '("category", MarkCategoryPropertyInfo), '("leftGravity", Gtk.TextMark.TextMarkLeftGravityPropertyInfo), '("name", Gtk.TextMark.TextMarkNamePropertyInfo)] :: [(Symbol, *)])

markCategory :: AttrLabelProxy "category"
markCategory = AttrLabelProxy

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

-- method Mark::new
-- method type : Constructor
-- Args : [Arg {argCName = "name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "Name of the #GtkSourceMark, can be NULL when not using a name", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "category", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "is used to classify marks according to common characteristics\n(e.g. all the marks representing a bookmark could belong to the \"bookmark\"\ncategory, or all the marks representing a compilation error could belong to\n\"error\" category).", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "GtkSource", name = "Mark"}))
-- throws : False
-- Skip return : False

foreign import ccall "gtk_source_mark_new" gtk_source_mark_new :: 
    CString ->                              -- name : TBasicType TUTF8
    CString ->                              -- category : TBasicType TUTF8
    IO (Ptr Mark)

{- |
Creates a text mark. Add it to a buffer using 'GI.Gtk.Objects.TextBuffer.textBufferAddMark'.
If name is NULL, the mark is anonymous; otherwise, the mark can be retrieved
by name using 'GI.Gtk.Objects.TextBuffer.textBufferGetMark'.
Normally marks are created using the utility function
'GI.GtkSource.Objects.Buffer.bufferCreateSourceMark'.

@since 2.2
-}
markNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    {- ^ /@name@/: Name of the 'GI.GtkSource.Objects.Mark.Mark', can be NULL when not using a name -}
    -> T.Text
    {- ^ /@category@/: is used to classify marks according to common characteristics
(e.g. all the marks representing a bookmark could belong to the \"bookmark\"
category, or all the marks representing a compilation error could belong to
\"error\" category). -}
    -> m Mark
    {- ^ __Returns:__ a new 'GI.GtkSource.Objects.Mark.Mark' that can be added using 'GI.Gtk.Objects.TextBuffer.textBufferAddMark'. -}
markNew name category = liftIO $ do
    name' <- textToCString name
    category' <- textToCString category
    result <- gtk_source_mark_new name' category'
    checkUnexpectedReturnNULL "markNew" result
    result' <- (wrapObject Mark) result
    freeMem name'
    freeMem category'
    return result'

-- method Mark::get_category
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "mark", argType = TInterface (Name {namespace = "GtkSource", name = "Mark"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkSourceMark.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "gtk_source_mark_get_category" gtk_source_mark_get_category :: 
    Ptr Mark ->                             -- mark : TInterface (Name {namespace = "GtkSource", name = "Mark"})
    IO CString

{- |
Returns the mark category.

@since 2.2
-}
markGetCategory ::
    (B.CallStack.HasCallStack, MonadIO m, IsMark a) =>
    a
    {- ^ /@mark@/: a 'GI.GtkSource.Objects.Mark.Mark'. -}
    -> m T.Text
    {- ^ __Returns:__ the category of the 'GI.GtkSource.Objects.Mark.Mark'. -}
markGetCategory mark = liftIO $ do
    mark' <- unsafeManagedPtrCastPtr mark
    result <- gtk_source_mark_get_category mark'
    checkUnexpectedReturnNULL "markGetCategory" result
    result' <- cstringToText result
    touchManagedPtr mark
    return result'

data MarkGetCategoryMethodInfo
instance (signature ~ (m T.Text), MonadIO m, IsMark a) => O.MethodInfo MarkGetCategoryMethodInfo a signature where
    overloadedMethod _ = markGetCategory

-- method Mark::next
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "mark", argType = TInterface (Name {namespace = "GtkSource", name = "Mark"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkSourceMark.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "category", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "a string specifying the mark category, or %NULL.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "GtkSource", name = "Mark"}))
-- throws : False
-- Skip return : False

foreign import ccall "gtk_source_mark_next" gtk_source_mark_next :: 
    Ptr Mark ->                             -- mark : TInterface (Name {namespace = "GtkSource", name = "Mark"})
    CString ->                              -- category : TBasicType TUTF8
    IO (Ptr Mark)

{- |
Returns the next 'GI.GtkSource.Objects.Mark.Mark' in the buffer or 'Nothing' if the mark
was not added to a buffer. If there is no next mark, 'Nothing' will be returned.

If /@category@/ is 'Nothing', looks for marks of any category.

@since 2.2
-}
markNext ::
    (B.CallStack.HasCallStack, MonadIO m, IsMark a) =>
    a
    {- ^ /@mark@/: a 'GI.GtkSource.Objects.Mark.Mark'. -}
    -> Maybe (T.Text)
    {- ^ /@category@/: a string specifying the mark category, or 'Nothing'. -}
    -> m (Maybe Mark)
    {- ^ __Returns:__ the next 'GI.GtkSource.Objects.Mark.Mark', or 'Nothing'. -}
markNext mark category = liftIO $ do
    mark' <- unsafeManagedPtrCastPtr mark
    maybeCategory <- case category of
        Nothing -> return nullPtr
        Just jCategory -> do
            jCategory' <- textToCString jCategory
            return jCategory'
    result <- gtk_source_mark_next mark' maybeCategory
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (newObject Mark) result'
        return result''
    touchManagedPtr mark
    freeMem maybeCategory
    return maybeResult

data MarkNextMethodInfo
instance (signature ~ (Maybe (T.Text) -> m (Maybe Mark)), MonadIO m, IsMark a) => O.MethodInfo MarkNextMethodInfo a signature where
    overloadedMethod _ = markNext

-- method Mark::prev
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "mark", argType = TInterface (Name {namespace = "GtkSource", name = "Mark"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkSourceMark.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "category", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a string specifying the mark category, or %NULL.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "GtkSource", name = "Mark"}))
-- throws : False
-- Skip return : False

foreign import ccall "gtk_source_mark_prev" gtk_source_mark_prev :: 
    Ptr Mark ->                             -- mark : TInterface (Name {namespace = "GtkSource", name = "Mark"})
    CString ->                              -- category : TBasicType TUTF8
    IO (Ptr Mark)

{- |
Returns the previous 'GI.GtkSource.Objects.Mark.Mark' in the buffer or 'Nothing' if the mark
was not added to a buffer. If there is no previous mark, 'Nothing' is returned.

If /@category@/ is 'Nothing', looks for marks of any category

@since 2.2
-}
markPrev ::
    (B.CallStack.HasCallStack, MonadIO m, IsMark a) =>
    a
    {- ^ /@mark@/: a 'GI.GtkSource.Objects.Mark.Mark'. -}
    -> T.Text
    {- ^ /@category@/: a string specifying the mark category, or 'Nothing'. -}
    -> m (Maybe Mark)
    {- ^ __Returns:__ the previous 'GI.GtkSource.Objects.Mark.Mark', or 'Nothing'. -}
markPrev mark category = liftIO $ do
    mark' <- unsafeManagedPtrCastPtr mark
    category' <- textToCString category
    result <- gtk_source_mark_prev mark' category'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (newObject Mark) result'
        return result''
    touchManagedPtr mark
    freeMem category'
    return maybeResult

data MarkPrevMethodInfo
instance (signature ~ (T.Text -> m (Maybe Mark)), MonadIO m, IsMark a) => O.MethodInfo MarkPrevMethodInfo a signature where
    overloadedMethod _ = markPrev