{-# LINE 2 "./System/Glib/GObject.chs" #-}-- -*-haskell-*--- GIMP Toolkit (GTK) GObject---- Author : Axel Simon---- Created: 9 April 2001---- Copyright (C) 2001 Axel Simon---- This library is free software; you can redistribute it and/or-- modify it under the terms of the GNU Lesser General Public-- License as published by the Free Software Foundation; either-- version 2.1 of the License, or (at your option) any later version.---- This library is distributed in the hope that it will be useful,-- but WITHOUT ANY WARRANTY; without even the implied warranty of-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU-- Lesser General Public License for more details.---- |-- Maintainer : gtk2hs-users@lists.sourceforge.net-- Stability : provisional-- Portability : portable (depends on GHC)---- The base object type for all glib objects--moduleSystem.Glib.GObject(-- * TypesmoduleSystem.Glib.Types,-- * Low level binding functions-- | All these functions are internal and are only interesting to people-- writing bindings to GObject-style C libraries.objectNew,objectRef,objectRefSink,makeNewGObject,constructNewGObject,wrapNewGObject,-- ** GType queriesgTypeGObject,isA,-- ** Callback supportDestroyNotify,destroyFunPtr,destroyStablePtr,-- ** User-Defined AttributesQuark,quarkFromString,objectCreateAttribute,objectSetAttribute,objectGetAttributeUnsafe)whereimportControl.Monad(liftM,when)importData.IORef(newIORef,readIORef,writeIORef)importSystem.Glib.FFIimportSystem.Glib.UTFStringimportSystem.Glib.Types{-# LINE 68 "./System/Glib/GObject.chs" #-}importSystem.Glib.GValue(GValue)importSystem.Glib.GType(GType,typeInstanceIsA)importSystem.Glib.GTypeConstants(object)importSystem.Glib.GParameterimportSystem.Glib.Attributes(newNamedAttr,Attr)importForeign.StablePtrimportControl.Concurrent.MVar(MVar,newMVar,modifyMVar){-# LINE 77 "./System/Glib/GObject.chs" #-}typeGParm=Ptr(GParameter){-# LINE 79 "./System/Glib/GObject.chs" #-}-- | Construct a new object (should rairly be used directly)--objectNew::GType->[(String,GValue)]->IO(PtrGObject)objectNewobjTypeparameters=liftMcastPtr$--caller must makeNewGObject as we don't know--if it this a GObject or a GtkObjectwithArray(mapGParameterparameters)$\paramArrayPtr->g_object_newvobjType(fromIntegral$lengthparameters)paramArrayPtr-- | Reference and sink an object.objectRefSink::GObjectClassobj=>Ptrobj->IO()objectRefSinkobj=dog_object_ref_sink(castPtrobj)return()-- | Increase the reference counter of an object--objectRef::GObjectClassobj=>Ptrobj->IO()objectRefobj=dog_object_ref(castPtrobj)return()-- | The type constant to check if an instance is of 'GObject' type.gTypeGObject::GTypegTypeGObject=object-- | This function wraps any object that does not derive from Object.-- It should be used whenever a function returns a pointer to an existing-- 'GObject' (as opposed to a function that constructs a new object).---- * The first argument is the contructor of the specific object.--makeNewGObject::GObjectClassobj=>(ForeignPtrobj->obj,FinalizerPtrobj)-- ^ constructor for the Haskell object and finalizer C function->IO(Ptrobj)-- ^ action which yields a pointer to the C object->IOobjmakeNewGObject(constr,objectUnref)generator=doobjPtr<-generatorwhen(objPtr==nullPtr)(fail"makeNewGObject: object is NULL")objectRefobjPtrobj<-newForeignPtrobjPtrobjectUnrefreturn$!constrobjtypeDestroyNotify=FunPtr(((Ptr())->(IO()))){-# LINE 129 "./System/Glib/GObject.chs" #-}foreignimportccall"wrapper"mkDestroyNotifyPtr::IO()->IODestroyNotify-- | This function wraps any newly created objects that derives from-- GInitiallyUnowned also known as objects with-- \"floating-references\". The object will be refSink (for glib-- versions >= 2.10). On non-floating objects, this function behaves-- exactly the same as "makeNewGObject".--constructNewGObject::GObjectClassobj=>(ForeignPtrobj->obj,FinalizerPtrobj)->IO(Ptrobj)->IOobjconstructNewGObject(constr,objectUnref)generator=doobjPtr<-generator-- change the exisiting floating reference into a proper reference;-- the name is confusing, what the function does is ref,sink,unrefobjectRefSinkobjPtrobj<-newForeignPtrobjPtrobjectUnrefreturn$!constrobj-- | This function wraps any newly created object that does not derived-- from GInitiallyUnowned (that is a GObject with no floating-- reference). Since newly created 'GObject's have a reference count of-- one, they don't need ref'ing.--wrapNewGObject::GObjectClassobj=>(ForeignPtrobj->obj,FinalizerPtrobj)->IO(Ptrobj)->IOobjwrapNewGObject(constr,objectUnref)generator=doobjPtr<-generatorwhen(objPtr==nullPtr)(fail"wrapNewGObject: object is NULL")obj<-newForeignPtrobjPtrobjectUnrefreturn$!constrobj-- | Many methods in classes derived from GObject take a callback function and-- a destructor function which is called to free that callback function when-- it is no longer required. This constants is an address of a functions in-- C land that will free a function pointer.foreignimportccallunsafe"&freeHaskellFunctionPtr"destroyFunPtr::DestroyNotifytypeQuark=(CUInt){-# LINE 170 "./System/Glib/GObject.chs" #-}-- | A counter for generating unique names.{-# NOINLINE uniqueCnt #-}uniqueCnt::MVarIntuniqueCnt=unsafePerformIO$newMVar0-- | Create a unique id based on the given string.quarkFromString::String->IOQuarkquarkFromStringname=withUTFStringnameg_quark_from_string{-# LINE 179 "./System/Glib/GObject.chs" #-}-- | Add an attribute to this object.---- * The function returns a new attribute that can be set or retrieved from-- any 'GObject'. The attribute is wrapped in a 'Maybe' type to reflect-- the circumstance when the attribute is not set or if it should be unset.--objectCreateAttribute::GObjectClasso=>IO(Attro(Maybea))objectCreateAttribute=docnt<-modifyMVaruniqueCnt(\cnt->return(cnt+1,cnt))letpropName="Gtk2HsAttr"++showcntattr<-quarkFromStringpropNamereturn(newNamedAttrpropName(objectGetAttributeUnsafeattr)(objectSetAttributeattr))-- | The address of a function freeing a 'StablePtr'. See 'destroyFunPtr'.foreignimportccallunsafe"&hs_free_stable_ptr"destroyStablePtr::DestroyNotify-- | Set the value of an association.--objectSetAttribute::GObjectClasso=>Quark->o->Maybea->IO()objectSetAttributeattrobjNothing=do(\(GObjectarg1)arg2arg3->withForeignPtrarg1$\argPtr1->g_object_set_qdataargPtr1arg2arg3)(toGObjectobj)attrnullPtrobjectSetAttributeattrobj(Justval)=dosPtr<-newStablePtrval(\(GObjectarg1)arg2arg3arg4->withForeignPtrarg1$\argPtr1->g_object_set_qdata_fullargPtr1arg2arg3arg4)(toGObjectobj)attr(castStablePtrToPtrsPtr)destroyStablePtr-- | Get the value of an association.---- * Note that this function may crash the Haskell run-time since the-- returned type can be forced to be anything. See 'objectCreateAttribute'-- for a safe wrapper around this funciton.--objectGetAttributeUnsafe::GObjectClasso=>Quark->o->IO(Maybea)objectGetAttributeUnsafeattrobj=dosPtr<-(\(GObjectarg1)arg2->withForeignPtrarg1$\argPtr1->g_object_get_qdataargPtr1arg2)(toGObjectobj)attrifsPtr==nullPtrthenreturnNothingelseliftMJust$!deRefStablePtr(castPtrToStablePtrsPtr)-- | Determine if this is an instance of a particular GTK type--isA::GObjectClasso=>o->GType->BoolisAobjgType=typeInstanceIsA((unsafeForeignPtrToPtr.castForeignPtr.unGObject.toGObject)obj)gType-- at this point we would normally implement the notify signal handler;-- I've moved this definition into the Object class of the gtk package-- since there's a quite a bit of machinery missing here (generated signal-- register functions and the problem of recursive modules)foreignimportccallsafe"g_object_newv"g_object_newv::(CUInt->(CUInt->((PtrGParameter)->(IO(Ptr())))))foreignimportccallunsafe"g_object_ref_sink"g_object_ref_sink::((Ptr())->(IO(Ptr())))foreignimportccallunsafe"g_object_ref"g_object_ref::((Ptr())->(IO(Ptr())))foreignimportccallunsafe"g_quark_from_string"g_quark_from_string::((PtrCChar)->(IOCUInt))foreignimportccallsafe"g_object_set_qdata"g_object_set_qdata::((PtrGObject)->(CUInt->((Ptr())->(IO()))))foreignimportccallsafe"g_object_set_qdata_full"g_object_set_qdata_full::((PtrGObject)->(CUInt->((Ptr())->((FunPtr((Ptr())->(IO())))->(IO())))))foreignimportccallunsafe"g_object_get_qdata"g_object_get_qdata::((PtrGObject)->(CUInt->(IO(Ptr()))))