{- | Copyright : Will Thompson, Iñaki García Etxebarria and Jonas Platte License : LGPL-2.1 Maintainer : Iñaki García Etxebarria (garetxe@gmail.com) A structure used to describe a text range. -} module GI.Atk.Structs.TextRange ( -- * Exported types TextRange(..) , newZeroTextRange , noTextRange , -- * Properties -- ** Bounds textRangeReadBounds , -- ** Content textRangeReadContent , -- ** EndOffset textRangeReadEndOffset , -- ** StartOffset textRangeReadStartOffset , ) where import Prelude () import Data.GI.Base.ShortPrelude import qualified Data.Text as T import qualified Data.ByteString.Char8 as B import qualified Data.Map as Map import GI.Atk.Types import GI.Atk.Callbacks newtype TextRange = TextRange (ForeignPtr TextRange) foreign import ccall "atk_text_range_get_type" c_atk_text_range_get_type :: IO GType instance BoxedObject TextRange where boxedType _ = c_atk_text_range_get_type -- | Construct a `TextRange` struct initialized to zero. newZeroTextRange :: MonadIO m => m TextRange newZeroTextRange = liftIO $ callocBoxedBytes 32 >>= wrapBoxed TextRange noTextRange :: Maybe TextRange noTextRange = Nothing textRangeReadBounds :: TextRange -> IO TextRectangle textRangeReadBounds s = withManagedPtr s $ \ptr -> do val <- peek (ptr `plusPtr` 0) :: IO (Ptr TextRectangle) val' <- (newPtr 16 TextRectangle) val return val' textRangeReadStartOffset :: TextRange -> IO Int32 textRangeReadStartOffset s = withManagedPtr s $ \ptr -> do val <- peek (ptr `plusPtr` 16) :: IO Int32 return val textRangeReadEndOffset :: TextRange -> IO Int32 textRangeReadEndOffset s = withManagedPtr s $ \ptr -> do val <- peek (ptr `plusPtr` 20) :: IO Int32 return val textRangeReadContent :: TextRange -> IO T.Text textRangeReadContent s = withManagedPtr s $ \ptr -> do val <- peek (ptr `plusPtr` 24) :: IO CString val' <- cstringToText val return val' type family ResolveTextRangeMethod (t :: Symbol) (o :: *) :: * where ResolveTextRangeMethod l o = MethodResolutionFailed l o instance (info ~ ResolveTextRangeMethod t TextRange, MethodInfo info TextRange p) => IsLabelProxy t (TextRange -> p) where fromLabelProxy _ = overloadedMethod (MethodProxy :: MethodProxy info) #if MIN_VERSION_base(4,9,0) instance (info ~ ResolveTextRangeMethod t TextRange, MethodInfo info TextRange p) => IsLabel t (TextRange -> p) where fromLabel _ = overloadedMethod (MethodProxy :: MethodProxy info) #endif