haskell-gi-base-0.26.4: Foundation for libraries generated by haskell-gi
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.GI.Base.GObject

Description

This module constains helpers for dealing with GObject-derived types.

Synopsis

Constructing new GObjects

constructGObject :: forall o m. (GObject o, MonadIO m) => (ManagedPtr o -> o) -> [AttrOp o 'AttrConstruct] -> m o Source #

Construct a GObject given the constructor and a list of settable attributes. See new for a more general version.

new' :: (HasCallStack, MonadIO m, GObject o) => (ManagedPtr o -> o) -> [m (GValueConstruct o)] -> m o Source #

Construct the given GObject, given a set of actions constructing desired GValues to set at construction time.

User data

gobjectGetUserData :: (HasCallStack, GObject o) => o -> GQuark a -> IO (Maybe a) Source #

Get the value of a given key for the object.

gobjectSetUserData :: (HasCallStack, GObject o) => o -> GQuark a -> a -> IO () Source #

Set the value of the user data for the given GObject to a StablePtr to the given Haskell object. The StablePtr will be freed when the object is destroyed, or the value is replaced.

gobjectModifyUserData :: (HasCallStack, GObject o) => o -> GQuark a -> (Maybe a -> a) -> IO () Source #

A combination of gobjectGetUserData and gobjectSetUserData, for convenience.

Deriving new object types

class GObject a => DerivedGObject a where Source #

This typeclass contains the data necessary for defining a new GObject type from Haskell.

Associated Types

type GObjectParentType a Source #

The parent type

type GObjectPrivateData a Source #

Type of the private data for each instance.

Methods

objectTypeName :: Text Source #

Name of the type, it should be unique.

objectClassInit :: GObjectClass -> IO () Source #

Code to run when the class is inited. This is a good place to register signals and properties for the type.

objectInstanceInit :: GObjectClass -> a -> IO (GObjectPrivateData a) Source #

Code to run when each instance of the type is constructed. Returns the private data to be associated with the new instance (use gobjectGetPrivateData and gobjectSetPrivateData to manipulate this further).

registerGType :: forall o. (HasCallStack, DerivedGObject o, GObject (GObjectParentType o), GObject o) => (ManagedPtr o -> o) -> IO GType Source #

Register the given type into the GObject type system and return the resulting GType, if it has not been registered already. If the type has been registered already the existing GType will be returned instead.

Note that for this function to work the type must be an instance of DerivedGObject.

gobjectGetPrivateData :: forall o. (HasCallStack, DerivedGObject o) => o -> IO (GObjectPrivateData o) Source #

Get the private data associated with the given object.

gobjectSetPrivateData :: forall o. (HasCallStack, DerivedGObject o) => o -> GObjectPrivateData o -> IO () Source #

Set the private data associated with the given object.

gobjectModifyPrivateData :: forall o. (HasCallStack, DerivedGObject o) => o -> (GObjectPrivateData o -> GObjectPrivateData o) -> IO () Source #

Modify the private data for the given object.

newtype GObjectClass Source #

Wrapper around GObjectClass on the C-side.

Constructors

GObjectClass (Ptr GObjectClass) 

gtypeFromClass :: GObjectClass -> IO GType Source #

Find the GType associated to a given GObjectClass.

gtypeFromInstance :: GObject o => o -> IO GType Source #

Find the GType for a given GObject.

Installing properties for derived objects

gobjectInstallProperty :: DerivedGObject o => GObjectClass -> PropertyInfo o a -> IO () Source #

Add a Haskell object-valued property to the given object class.

gobjectInstallCIntProperty :: DerivedGObject o => GObjectClass -> CIntPropertyInfo o -> IO () Source #

Add a CInt-valued property to the given object class.

gobjectInstallCStringProperty :: DerivedGObject o => GObjectClass -> CStringPropertyInfo o -> IO () Source #

Add a CString-valued property to the given object class.