// Package gobject was automatically generated by github.com/bnema/puregotk DO NOT EDIT package gobject import ( "fmt" "structs" "unsafe" "github.com/ebitengine/purego" "github.com/bnema/puregotk/pkg/core" "github.com/bnema/puregotk/v4/glib" "github.com/bnema/puregotk/v4/gobject/types" ) // The type of the @finalize function of #GObjectClass. type ObjectFinalizeFunc func(uintptr) // The type of the @get_property function of #GObjectClass. type ObjectGetPropertyFunc func(uintptr, uint, *Value, uintptr) // The type of the @set_property function of #GObjectClass. type ObjectSetPropertyFunc func(uintptr, uint, *Value, uintptr) // A callback function used for notification when the state // of a toggle reference changes. // // See also: g_object_add_toggle_ref() type ToggleNotify func(uintptr, uintptr, bool) // A #GWeakNotify function can be added to an object as a callback that gets // triggered when the object is finalized. // // Since the object is already being disposed when the #GWeakNotify is called, // there's not much you could do with the object, apart from e.g. using its // address as hash-index or the like. // // In particular, this means it’s invalid to call g_object_ref(), // g_weak_ref_init(), g_weak_ref_set(), g_object_add_toggle_ref(), // g_object_weak_ref(), g_object_add_weak_pointer() or any function which calls // them on the object from this callback. type WeakNotify func(uintptr, uintptr) // The class structure for the GInitiallyUnowned type. type InitiallyUnownedClass struct { _ structs.HostLayout GTypeClass uintptr ConstructProperties *glib.SList xConstructor uintptr xSetProperty uintptr xGetProperty uintptr xDispose uintptr xFinalize uintptr xDispatchPropertiesChanged uintptr xNotify uintptr xConstructed uintptr Flags uint NConstructProperties uint Pspecs uintptr NPspecs uint Pdummy [3]uintptr } func (x *InitiallyUnownedClass) GoPointer() uintptr { return uintptr(unsafe.Pointer(x)) } // OverrideConstructor sets the "constructor" callback function. // the @constructor function is called by g_object_new () to // // complete the object initialization after all the construction properties are // set. The first thing a @constructor implementation must do is chain up to the // @constructor of the parent class. Overriding @constructor should be rarely // needed, e.g. to handle construct properties, or to implement singletons. func (x *InitiallyUnownedClass) OverrideConstructor(cb func(types.GType, uint, *ObjectConstructParam) *Object) { if cb == nil { x.xConstructor = 0 } else { x.xConstructor = purego.NewCallback(func(TypeVarp types.GType, NConstructPropertiesVarp uint, ConstructPropertiesVarp *ObjectConstructParam) uintptr { ret := cb(TypeVarp, NConstructPropertiesVarp, ConstructPropertiesVarp) if ret == nil { return 0 } return ret.GoPointer() }) } } // GetConstructor gets the "constructor" callback function. // the @constructor function is called by g_object_new () to // // complete the object initialization after all the construction properties are // set. The first thing a @constructor implementation must do is chain up to the // @constructor of the parent class. Overriding @constructor should be rarely // needed, e.g. to handle construct properties, or to implement singletons. func (x *InitiallyUnownedClass) GetConstructor() func(types.GType, uint, *ObjectConstructParam) *Object { if x.xConstructor == 0 { return nil } var rawCallback func(TypeVarp types.GType, NConstructPropertiesVarp uint, ConstructPropertiesVarp *ObjectConstructParam) uintptr purego.RegisterFunc(&rawCallback, x.xConstructor) return func(TypeVar types.GType, NConstructPropertiesVar uint, ConstructPropertiesVar *ObjectConstructParam) *Object { rawRet := rawCallback(TypeVar, NConstructPropertiesVar, ConstructPropertiesVar) if rawRet == 0 { return nil } ret := &Object{} ret.Ptr = rawRet return ret } } // OverrideSetProperty sets the "set_property" callback function. // the generic setter for all properties of this type. Should be // // overridden for every type with properties. If implementations of // @set_property don't emit property change notification explicitly, this will // be done implicitly by the type system. However, if the notify signal is // emitted explicitly, the type system will not emit it a second time. func (x *InitiallyUnownedClass) OverrideSetProperty(cb func(*Object, uint, *Value, *ParamSpec)) { if cb == nil { x.xSetProperty = 0 } else { x.xSetProperty = purego.NewCallback(func(ObjectVarp uintptr, PropertyIdVarp uint, ValueVarp *Value, PspecVarp uintptr) { cb(ObjectNewFromInternalPtr(ObjectVarp), PropertyIdVarp, ValueVarp, ParamSpecNewFromInternalPtr(PspecVarp)) }) } } // GetSetProperty gets the "set_property" callback function. // the generic setter for all properties of this type. Should be // // overridden for every type with properties. If implementations of // @set_property don't emit property change notification explicitly, this will // be done implicitly by the type system. However, if the notify signal is // emitted explicitly, the type system will not emit it a second time. func (x *InitiallyUnownedClass) GetSetProperty() func(*Object, uint, *Value, *ParamSpec) { if x.xSetProperty == 0 { return nil } var rawCallback func(ObjectVarp uintptr, PropertyIdVarp uint, ValueVarp *Value, PspecVarp uintptr) purego.RegisterFunc(&rawCallback, x.xSetProperty) return func(ObjectVar *Object, PropertyIdVar uint, ValueVar *Value, PspecVar *ParamSpec) { rawCallback(ObjectVar.GoPointer(), PropertyIdVar, ValueVar, PspecVar.GoPointer()) } } // OverrideGetProperty sets the "get_property" callback function. // the generic getter for all properties of this type. Should be // // overridden for every type with properties. func (x *InitiallyUnownedClass) OverrideGetProperty(cb func(*Object, uint, *Value, *ParamSpec)) { if cb == nil { x.xGetProperty = 0 } else { x.xGetProperty = purego.NewCallback(func(ObjectVarp uintptr, PropertyIdVarp uint, ValueVarp *Value, PspecVarp uintptr) { cb(ObjectNewFromInternalPtr(ObjectVarp), PropertyIdVarp, ValueVarp, ParamSpecNewFromInternalPtr(PspecVarp)) }) } } // GetGetProperty gets the "get_property" callback function. // the generic getter for all properties of this type. Should be // // overridden for every type with properties. func (x *InitiallyUnownedClass) GetGetProperty() func(*Object, uint, *Value, *ParamSpec) { if x.xGetProperty == 0 { return nil } var rawCallback func(ObjectVarp uintptr, PropertyIdVarp uint, ValueVarp *Value, PspecVarp uintptr) purego.RegisterFunc(&rawCallback, x.xGetProperty) return func(ObjectVar *Object, PropertyIdVar uint, ValueVar *Value, PspecVar *ParamSpec) { rawCallback(ObjectVar.GoPointer(), PropertyIdVar, ValueVar, PspecVar.GoPointer()) } } // OverrideDispose sets the "dispose" callback function. // the @dispose function is supposed to drop all references to other // // objects, but keep the instance otherwise intact, so that client method // invocations still work. It may be run multiple times (due to reference // loops). Before returning, @dispose should chain up to the @dispose method // of the parent class. func (x *InitiallyUnownedClass) OverrideDispose(cb func(*Object)) { if cb == nil { x.xDispose = 0 } else { x.xDispose = purego.NewCallback(func(ObjectVarp uintptr) { cb(ObjectNewFromInternalPtr(ObjectVarp)) }) } } // GetDispose gets the "dispose" callback function. // the @dispose function is supposed to drop all references to other // // objects, but keep the instance otherwise intact, so that client method // invocations still work. It may be run multiple times (due to reference // loops). Before returning, @dispose should chain up to the @dispose method // of the parent class. func (x *InitiallyUnownedClass) GetDispose() func(*Object) { if x.xDispose == 0 { return nil } var rawCallback func(ObjectVarp uintptr) purego.RegisterFunc(&rawCallback, x.xDispose) return func(ObjectVar *Object) { rawCallback(ObjectVar.GoPointer()) } } // OverrideFinalize sets the "finalize" callback function. // instance finalization function, should finish the finalization of // // the instance begun in @dispose and chain up to the @finalize method of the // parent class. func (x *InitiallyUnownedClass) OverrideFinalize(cb func(*Object)) { if cb == nil { x.xFinalize = 0 } else { x.xFinalize = purego.NewCallback(func(ObjectVarp uintptr) { cb(ObjectNewFromInternalPtr(ObjectVarp)) }) } } // GetFinalize gets the "finalize" callback function. // instance finalization function, should finish the finalization of // // the instance begun in @dispose and chain up to the @finalize method of the // parent class. func (x *InitiallyUnownedClass) GetFinalize() func(*Object) { if x.xFinalize == 0 { return nil } var rawCallback func(ObjectVarp uintptr) purego.RegisterFunc(&rawCallback, x.xFinalize) return func(ObjectVar *Object) { rawCallback(ObjectVar.GoPointer()) } } // OverrideDispatchPropertiesChanged sets the "dispatch_properties_changed" callback function. // emits property change notification for a bunch // // of properties. Overriding @dispatch_properties_changed should be rarely // needed. func (x *InitiallyUnownedClass) OverrideDispatchPropertiesChanged(cb func(*Object, uint, **ParamSpec)) { if cb == nil { x.xDispatchPropertiesChanged = 0 } else { x.xDispatchPropertiesChanged = purego.NewCallback(func(ObjectVarp uintptr, NPspecsVarp uint, PspecsVarp uintptr) { cb(ObjectNewFromInternalPtr(ObjectVarp), NPspecsVarp, (**ParamSpec)(unsafe.Pointer(PspecsVarp))) }) } } // GetDispatchPropertiesChanged gets the "dispatch_properties_changed" callback function. // emits property change notification for a bunch // // of properties. Overriding @dispatch_properties_changed should be rarely // needed. func (x *InitiallyUnownedClass) GetDispatchPropertiesChanged() func(*Object, uint, **ParamSpec) { if x.xDispatchPropertiesChanged == 0 { return nil } var rawCallback func(ObjectVarp uintptr, NPspecsVarp uint, PspecsVarp uintptr) purego.RegisterFunc(&rawCallback, x.xDispatchPropertiesChanged) return func(ObjectVar *Object, NPspecsVar uint, PspecsVar **ParamSpec) { rawCallback(ObjectVar.GoPointer(), NPspecsVar, *ConvertPtr(PspecsVar)) } } // OverrideNotify sets the "notify" callback function. // the class closure for the notify signal func (x *InitiallyUnownedClass) OverrideNotify(cb func(*Object, *ParamSpec)) { if cb == nil { x.xNotify = 0 } else { x.xNotify = purego.NewCallback(func(ObjectVarp uintptr, PspecVarp uintptr) { cb(ObjectNewFromInternalPtr(ObjectVarp), ParamSpecNewFromInternalPtr(PspecVarp)) }) } } // GetNotify gets the "notify" callback function. // the class closure for the notify signal func (x *InitiallyUnownedClass) GetNotify() func(*Object, *ParamSpec) { if x.xNotify == 0 { return nil } var rawCallback func(ObjectVarp uintptr, PspecVarp uintptr) purego.RegisterFunc(&rawCallback, x.xNotify) return func(ObjectVar *Object, PspecVar *ParamSpec) { rawCallback(ObjectVar.GoPointer(), PspecVar.GoPointer()) } } // OverrideConstructed sets the "constructed" callback function. // the @constructed function is called by g_object_new() as the // // final step of the object creation process. At the point of the call, all // construction properties have been set on the object. The purpose of this // call is to allow for object initialisation steps that can only be performed // after construction properties have been set. @constructed implementors // should chain up to the @constructed call of their parent class to allow it // to complete its initialisation. func (x *InitiallyUnownedClass) OverrideConstructed(cb func(*Object)) { if cb == nil { x.xConstructed = 0 } else { x.xConstructed = purego.NewCallback(func(ObjectVarp uintptr) { cb(ObjectNewFromInternalPtr(ObjectVarp)) }) } } // GetConstructed gets the "constructed" callback function. // the @constructed function is called by g_object_new() as the // // final step of the object creation process. At the point of the call, all // construction properties have been set on the object. The purpose of this // call is to allow for object initialisation steps that can only be performed // after construction properties have been set. @constructed implementors // should chain up to the @constructed call of their parent class to allow it // to complete its initialisation. func (x *InitiallyUnownedClass) GetConstructed() func(*Object) { if x.xConstructed == 0 { return nil } var rawCallback func(ObjectVarp uintptr) purego.RegisterFunc(&rawCallback, x.xConstructed) return func(ObjectVar *Object) { rawCallback(ObjectVar.GoPointer()) } } // The class structure for the GObject type. // // |[<!-- language="C" --> // // Example of implementing a singleton using a constructor. // static MySingleton *the_singleton = NULL; // // static GObject* // my_singleton_constructor (GType type, // // guint n_construct_params, // GObjectConstructParam *construct_params) // // { // GObject *object; // // if (!the_singleton) // { // object = G_OBJECT_CLASS (parent_class)->constructor (type, // n_construct_params, // construct_params); // the_singleton = MY_SINGLETON (object); // } // else // object = g_object_ref (G_OBJECT (the_singleton)); // // return object; // } // // ]| type ObjectClass struct { _ structs.HostLayout GTypeClass uintptr ConstructProperties *glib.SList xConstructor uintptr xSetProperty uintptr xGetProperty uintptr xDispose uintptr xFinalize uintptr xDispatchPropertiesChanged uintptr xNotify uintptr xConstructed uintptr Flags uint NConstructProperties uint Pspecs uintptr NPspecs uint Pdummy [3]uintptr } func (x *ObjectClass) GoPointer() uintptr { return uintptr(unsafe.Pointer(x)) } var xObjectClassFindProperty func(uintptr, string) uintptr // Looks up the #GParamSpec for a property of a class. func (x *ObjectClass) FindProperty(PropertyNameVar string) *ParamSpec { var cls *ParamSpec cret := xObjectClassFindProperty(x.GoPointer(), PropertyNameVar) if cret == 0 { return nil } IncreaseRef(cret) cls = &ParamSpec{} cls.Ptr = cret return cls } var xObjectClassInstallProperties func(uintptr, uint, uintptr) // Installs new properties from an array of #GParamSpecs. // // All properties should be installed during the class initializer. It // is possible to install properties after that, but doing so is not // recommend, and specifically, is not guaranteed to be thread-safe vs. // use of properties on the same type on other threads. // // The property id of each property is the index of each #GParamSpec in // the @pspecs array. // // The property id of 0 is treated specially by #GObject and it should not // be used to store a #GParamSpec. // // This function should be used if you plan to use a static array of // #GParamSpecs and g_object_notify_by_pspec(). For instance, this // class initialization: // // |[<!-- language="C" --> // // typedef enum { // PROP_FOO = 1, // PROP_BAR, // N_PROPERTIES // } MyObjectProperty; // // static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, }; // // static void // my_object_class_init (MyObjectClass *klass) // // { // GObjectClass *gobject_class = G_OBJECT_CLASS (klass); // // obj_properties[PROP_FOO] = // g_param_spec_int ("foo", NULL, NULL, // -1, G_MAXINT, // 0, // G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); // // obj_properties[PROP_BAR] = // g_param_spec_string ("bar", NULL, NULL, // NULL, // G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); // // gobject_class->set_property = my_object_set_property; // gobject_class->get_property = my_object_get_property; // g_object_class_install_properties (gobject_class, // G_N_ELEMENTS (obj_properties), // obj_properties); // } // // ]| // // allows calling g_object_notify_by_pspec() to notify of property changes: // // |[<!-- language="C" --> // void // my_object_set_foo (MyObject *self, gint foo) // // { // if (self->foo != foo) // { // self->foo = foo; // g_object_notify_by_pspec (G_OBJECT (self), obj_properties[PROP_FOO]); // } // } // // ]| func (x *ObjectClass) InstallProperties(NPspecsVar uint, PspecsVar uintptr) { xObjectClassInstallProperties(x.GoPointer(), NPspecsVar, PspecsVar) } var xObjectClassInstallProperty func(uintptr, uint, uintptr) // Installs a new property. // // All properties should be installed during the class initializer. It // is possible to install properties after that, but doing so is not // recommend, and specifically, is not guaranteed to be thread-safe vs. // use of properties on the same type on other threads. // // Note that it is possible to redefine a property in a derived class, // by installing a property with the same name. This can be useful at times, // e.g. to change the range of allowed values or the default value. func (x *ObjectClass) InstallProperty(PropertyIdVar uint, PspecVar *ParamSpec) { xObjectClassInstallProperty(x.GoPointer(), PropertyIdVar, PspecVar.GoPointer()) } var xObjectClassListProperties func(uintptr, *uint) uintptr // Get an array of #GParamSpec* for all properties of a class. func (x *ObjectClass) ListProperties(NPropertiesVar *uint) uintptr { cret := xObjectClassListProperties(x.GoPointer(), NPropertiesVar) return cret } var xObjectClassOverrideProperty func(uintptr, uint, string) // Registers @property_id as referring to a property with the name // @name in a parent class or in an interface implemented by @oclass. // This allows this class to "override" a property implementation in // a parent class or to provide the implementation of a property from // an interface. // // Internally, overriding is implemented by creating a property of type // #GParamSpecOverride; generally operations that query the properties of // the object class, such as g_object_class_find_property() or // g_object_class_list_properties() will return the overridden // property. However, in one case, the @construct_properties argument of // the @constructor virtual function, the #GParamSpecOverride is passed // instead, so that the @param_id field of the #GParamSpec will be // correct. For virtually all uses, this makes no difference. If you // need to get the overridden property, you can call // g_param_spec_get_redirect_target(). func (x *ObjectClass) OverrideProperty(PropertyIdVar uint, NameVar string) { xObjectClassOverrideProperty(x.GoPointer(), PropertyIdVar, NameVar) } // OverrideConstructor sets the "constructor" callback function. // the @constructor function is called by g_object_new () to // // complete the object initialization after all the construction properties are // set. The first thing a @constructor implementation must do is chain up to the // @constructor of the parent class. Overriding @constructor should be rarely // needed, e.g. to handle construct properties, or to implement singletons. func (x *ObjectClass) OverrideConstructor(cb func(types.GType, uint, *ObjectConstructParam) *Object) { if cb == nil { x.xConstructor = 0 } else { x.xConstructor = purego.NewCallback(func(TypeVarp types.GType, NConstructPropertiesVarp uint, ConstructPropertiesVarp *ObjectConstructParam) uintptr { ret := cb(TypeVarp, NConstructPropertiesVarp, ConstructPropertiesVarp) if ret == nil { return 0 } return ret.GoPointer() }) } } // GetConstructor gets the "constructor" callback function. // the @constructor function is called by g_object_new () to // // complete the object initialization after all the construction properties are // set. The first thing a @constructor implementation must do is chain up to the // @constructor of the parent class. Overriding @constructor should be rarely // needed, e.g. to handle construct properties, or to implement singletons. func (x *ObjectClass) GetConstructor() func(types.GType, uint, *ObjectConstructParam) *Object { if x.xConstructor == 0 { return nil } var rawCallback func(TypeVarp types.GType, NConstructPropertiesVarp uint, ConstructPropertiesVarp *ObjectConstructParam) uintptr purego.RegisterFunc(&rawCallback, x.xConstructor) return func(TypeVar types.GType, NConstructPropertiesVar uint, ConstructPropertiesVar *ObjectConstructParam) *Object { rawRet := rawCallback(TypeVar, NConstructPropertiesVar, ConstructPropertiesVar) if rawRet == 0 { return nil } ret := &Object{} ret.Ptr = rawRet return ret } } // OverrideSetProperty sets the "set_property" callback function. // The type of the @set_property function of #GObjectClass. func (x *ObjectClass) OverrideSetProperty(cb func(*Object, uint, *Value, *ParamSpec)) { if cb == nil { x.xSetProperty = 0 } else { x.xSetProperty = purego.NewCallback(func(ObjectVarp uintptr, PropertyIdVarp uint, ValueVarp *Value, PspecVarp uintptr) { cb(ObjectNewFromInternalPtr(ObjectVarp), PropertyIdVarp, ValueVarp, ParamSpecNewFromInternalPtr(PspecVarp)) }) } } // GetSetProperty gets the "set_property" callback function. // The type of the @set_property function of #GObjectClass. func (x *ObjectClass) GetSetProperty() func(*Object, uint, *Value, *ParamSpec) { if x.xSetProperty == 0 { return nil } var rawCallback func(ObjectVarp uintptr, PropertyIdVarp uint, ValueVarp *Value, PspecVarp uintptr) purego.RegisterFunc(&rawCallback, x.xSetProperty) return func(ObjectVar *Object, PropertyIdVar uint, ValueVar *Value, PspecVar *ParamSpec) { rawCallback(ObjectVar.GoPointer(), PropertyIdVar, ValueVar, PspecVar.GoPointer()) } } // OverrideGetProperty sets the "get_property" callback function. // The type of the @get_property function of #GObjectClass. func (x *ObjectClass) OverrideGetProperty(cb func(*Object, uint, *Value, *ParamSpec)) { if cb == nil { x.xGetProperty = 0 } else { x.xGetProperty = purego.NewCallback(func(ObjectVarp uintptr, PropertyIdVarp uint, ValueVarp *Value, PspecVarp uintptr) { cb(ObjectNewFromInternalPtr(ObjectVarp), PropertyIdVarp, ValueVarp, ParamSpecNewFromInternalPtr(PspecVarp)) }) } } // GetGetProperty gets the "get_property" callback function. // The type of the @get_property function of #GObjectClass. func (x *ObjectClass) GetGetProperty() func(*Object, uint, *Value, *ParamSpec) { if x.xGetProperty == 0 { return nil } var rawCallback func(ObjectVarp uintptr, PropertyIdVarp uint, ValueVarp *Value, PspecVarp uintptr) purego.RegisterFunc(&rawCallback, x.xGetProperty) return func(ObjectVar *Object, PropertyIdVar uint, ValueVar *Value, PspecVar *ParamSpec) { rawCallback(ObjectVar.GoPointer(), PropertyIdVar, ValueVar, PspecVar.GoPointer()) } } // OverrideDispose sets the "dispose" callback function. // the @dispose function is supposed to drop all references to other // // objects, but keep the instance otherwise intact, so that client method // invocations still work. It may be run multiple times (due to reference // loops). Before returning, @dispose should chain up to the @dispose method // of the parent class. func (x *ObjectClass) OverrideDispose(cb func(*Object)) { if cb == nil { x.xDispose = 0 } else { x.xDispose = purego.NewCallback(func(ObjectVarp uintptr) { cb(ObjectNewFromInternalPtr(ObjectVarp)) }) } } // GetDispose gets the "dispose" callback function. // the @dispose function is supposed to drop all references to other // // objects, but keep the instance otherwise intact, so that client method // invocations still work. It may be run multiple times (due to reference // loops). Before returning, @dispose should chain up to the @dispose method // of the parent class. func (x *ObjectClass) GetDispose() func(*Object) { if x.xDispose == 0 { return nil } var rawCallback func(ObjectVarp uintptr) purego.RegisterFunc(&rawCallback, x.xDispose) return func(ObjectVar *Object) { rawCallback(ObjectVar.GoPointer()) } } // OverrideFinalize sets the "finalize" callback function. // The type of the @finalize function of #GObjectClass. func (x *ObjectClass) OverrideFinalize(cb func(*Object)) { if cb == nil { x.xFinalize = 0 } else { x.xFinalize = purego.NewCallback(func(ObjectVarp uintptr) { cb(ObjectNewFromInternalPtr(ObjectVarp)) }) } } // GetFinalize gets the "finalize" callback function. // The type of the @finalize function of #GObjectClass. func (x *ObjectClass) GetFinalize() func(*Object) { if x.xFinalize == 0 { return nil } var rawCallback func(ObjectVarp uintptr) purego.RegisterFunc(&rawCallback, x.xFinalize) return func(ObjectVar *Object) { rawCallback(ObjectVar.GoPointer()) } } // OverrideDispatchPropertiesChanged sets the "dispatch_properties_changed" callback function. // emits property change notification for a bunch // // of properties. Overriding @dispatch_properties_changed should be rarely // needed. func (x *ObjectClass) OverrideDispatchPropertiesChanged(cb func(*Object, uint, **ParamSpec)) { if cb == nil { x.xDispatchPropertiesChanged = 0 } else { x.xDispatchPropertiesChanged = purego.NewCallback(func(ObjectVarp uintptr, NPspecsVarp uint, PspecsVarp uintptr) { cb(ObjectNewFromInternalPtr(ObjectVarp), NPspecsVarp, (**ParamSpec)(unsafe.Pointer(PspecsVarp))) }) } } // GetDispatchPropertiesChanged gets the "dispatch_properties_changed" callback function. // emits property change notification for a bunch // // of properties. Overriding @dispatch_properties_changed should be rarely // needed. func (x *ObjectClass) GetDispatchPropertiesChanged() func(*Object, uint, **ParamSpec) { if x.xDispatchPropertiesChanged == 0 { return nil } var rawCallback func(ObjectVarp uintptr, NPspecsVarp uint, PspecsVarp uintptr) purego.RegisterFunc(&rawCallback, x.xDispatchPropertiesChanged) return func(ObjectVar *Object, NPspecsVar uint, PspecsVar **ParamSpec) { rawCallback(ObjectVar.GoPointer(), NPspecsVar, *ConvertPtr(PspecsVar)) } } // OverrideNotify sets the "notify" callback function. // the class closure for the notify signal func (x *ObjectClass) OverrideNotify(cb func(*Object, *ParamSpec)) { if cb == nil { x.xNotify = 0 } else { x.xNotify = purego.NewCallback(func(ObjectVarp uintptr, PspecVarp uintptr) { cb(ObjectNewFromInternalPtr(ObjectVarp), ParamSpecNewFromInternalPtr(PspecVarp)) }) } } // GetNotify gets the "notify" callback function. // the class closure for the notify signal func (x *ObjectClass) GetNotify() func(*Object, *ParamSpec) { if x.xNotify == 0 { return nil } var rawCallback func(ObjectVarp uintptr, PspecVarp uintptr) purego.RegisterFunc(&rawCallback, x.xNotify) return func(ObjectVar *Object, PspecVar *ParamSpec) { rawCallback(ObjectVar.GoPointer(), PspecVar.GoPointer()) } } // OverrideConstructed sets the "constructed" callback function. // the @constructed function is called by g_object_new() as the // // final step of the object creation process. At the point of the call, all // construction properties have been set on the object. The purpose of this // call is to allow for object initialisation steps that can only be performed // after construction properties have been set. @constructed implementors // should chain up to the @constructed call of their parent class to allow it // to complete its initialisation. func (x *ObjectClass) OverrideConstructed(cb func(*Object)) { if cb == nil { x.xConstructed = 0 } else { x.xConstructed = purego.NewCallback(func(ObjectVarp uintptr) { cb(ObjectNewFromInternalPtr(ObjectVarp)) }) } } // GetConstructed gets the "constructed" callback function. // the @constructed function is called by g_object_new() as the // // final step of the object creation process. At the point of the call, all // construction properties have been set on the object. The purpose of this // call is to allow for object initialisation steps that can only be performed // after construction properties have been set. @constructed implementors // should chain up to the @constructed call of their parent class to allow it // to complete its initialisation. func (x *ObjectClass) GetConstructed() func(*Object) { if x.xConstructed == 0 { return nil } var rawCallback func(ObjectVarp uintptr) purego.RegisterFunc(&rawCallback, x.xConstructed) return func(ObjectVar *Object) { rawCallback(ObjectVar.GoPointer()) } } // The GObjectConstructParam struct is an auxiliary structure used to hand // #GParamSpec/#GValue pairs to the @constructor of a #GObjectClass. type ObjectConstructParam struct { _ structs.HostLayout Pspec *ParamSpec Value *Value } func (x *ObjectConstructParam) GoPointer() uintptr { return uintptr(unsafe.Pointer(x)) } // A structure containing a weak reference to a #GObject. // // A `GWeakRef` can either be empty (i.e. point to %NULL), or point to an // object for as long as at least one "strong" reference to that object // exists. Before the object's #GObjectClass.dispose method is called, // every #GWeakRef associated with becomes empty (i.e. points to %NULL). // // Like #GValue, #GWeakRef can be statically allocated, stack- or // heap-allocated, or embedded in larger structures. // // Unlike g_object_weak_ref() and g_object_add_weak_pointer(), this weak // reference is thread-safe: converting a weak pointer to a reference is // atomic with respect to invalidation of weak pointers to destroyed // objects. // // If the object's #GObjectClass.dispose method results in additional // references to the object being held (‘re-referencing’), any #GWeakRefs taken // before it was disposed will continue to point to %NULL. Any #GWeakRefs taken // during disposal and after re-referencing, or after disposal has returned due // to the re-referencing, will continue to point to the object until its refcount // goes back to zero, at which point they too will be invalidated. // // It is invalid to take a #GWeakRef on an object during #GObjectClass.dispose // without first having or creating a strong reference to the object. type WeakRef struct { _ structs.HostLayout } func (x *WeakRef) GoPointer() uintptr { return uintptr(unsafe.Pointer(x)) } var xWeakRefClear func(uintptr) // Frees resources associated with a non-statically-allocated #GWeakRef. // After this call, the #GWeakRef is left in an undefined state. // // You should only call this on a #GWeakRef that previously had // g_weak_ref_init() called on it. func (x *WeakRef) Clear() { xWeakRefClear(x.GoPointer()) } var xWeakRefGet func(uintptr) uintptr // If @weak_ref is not empty, atomically acquire a strong // reference to the object it points to, and return that reference. // // This function is needed because of the potential race between taking // the pointer value and g_object_ref() on it, if the object was losing // its last reference at the same time in a different thread. // // The caller should release the resulting reference in the usual way, // by using g_object_unref(). func (x *WeakRef) Get() *Object { var cls *Object cret := xWeakRefGet(x.GoPointer()) if cret == 0 { return nil } cls = &Object{} cls.Ptr = cret return cls } var xWeakRefInit func(uintptr, uintptr) // Initialise a non-statically-allocated #GWeakRef. // // This function also calls g_weak_ref_set() with @object on the // freshly-initialised weak reference. // // This function should always be matched with a call to // g_weak_ref_clear(). It is not necessary to use this function for a // #GWeakRef in static storage because it will already be // properly initialised. Just use g_weak_ref_set() directly. func (x *WeakRef) Init(ObjectVar *Object) { xWeakRefInit(x.GoPointer(), ObjectVar.GoPointer()) } var xWeakRefSet func(uintptr, uintptr) // Change the object to which @weak_ref points, or set it to // %NULL. // // You must own a strong reference on @object while calling this // function. func (x *WeakRef) Set(ObjectVar *Object) { xWeakRefSet(x.GoPointer(), ObjectVar.GoPointer()) } var xCclosureNewObject func(uintptr, uintptr) *Closure // A variant of g_cclosure_new() which uses @object as @user_data and // calls g_object_watch_closure() on @object and the created // closure. This function is useful when you have a callback closely // associated with a #GObject, and want the callback to no longer run // after the object is is freed. func CclosureNewObject(CallbackFuncVar *Callback, ObjectVar *Object) *Closure { var CallbackFuncVarRef uintptr if CallbackFuncVar != nil { CallbackFuncVarPtr := uintptr(unsafe.Pointer(CallbackFuncVar)) if cbRefPtr, ok := glib.GetCallback(CallbackFuncVarPtr); ok { CallbackFuncVarRef = cbRefPtr } else { fcb := func() { cbFn := *CallbackFuncVar cbFn() } CallbackFuncVarRef = purego.NewCallback(fcb) glib.SaveCallbackWithClosure(CallbackFuncVarPtr, CallbackFuncVarRef, CallbackFuncVar) } } cret := xCclosureNewObject(CallbackFuncVarRef, ObjectVar.GoPointer()) return cret } var xCclosureNewObjectSwap func(uintptr, uintptr) *Closure // A variant of g_cclosure_new_swap() which uses @object as @user_data // and calls g_object_watch_closure() on @object and the created // closure. This function is useful when you have a callback closely // associated with a #GObject, and want the callback to no longer run // after the object is is freed. func CclosureNewObjectSwap(CallbackFuncVar *Callback, ObjectVar *Object) *Closure { var CallbackFuncVarRef uintptr if CallbackFuncVar != nil { CallbackFuncVarPtr := uintptr(unsafe.Pointer(CallbackFuncVar)) if cbRefPtr, ok := glib.GetCallback(CallbackFuncVarPtr); ok { CallbackFuncVarRef = cbRefPtr } else { fcb := func() { cbFn := *CallbackFuncVar cbFn() } CallbackFuncVarRef = purego.NewCallback(fcb) glib.SaveCallbackWithClosure(CallbackFuncVarPtr, CallbackFuncVarRef, CallbackFuncVar) } } cret := xCclosureNewObjectSwap(CallbackFuncVarRef, ObjectVar.GoPointer()) return cret } var xClearObject func(uintptr) // Clears a reference to a #GObject. // // @object_ptr must not be %NULL. // // If the reference is %NULL then this function does nothing. // Otherwise, the reference count of the object is decreased and the // pointer is set to %NULL. // // A macro is also included that allows this function to be used without // pointer casts. func ClearObject(ObjectPtrVar **Object) { xClearObject(*ConvertPtr(ObjectPtrVar)) } var xSignalConnectObject func(*TypeInstance, string, uintptr, uintptr, ConnectFlags) uint // This is similar to g_signal_connect_data(), but uses a closure which // ensures that the @gobject stays alive during the call to @c_handler // by temporarily adding a reference count to @gobject. // // When the @gobject is destroyed the signal handler will be automatically // disconnected. Note that this is not currently threadsafe (ie: // emitting a signal while @gobject is being destroyed in another thread // is not safe). // // This function cannot fail. If the given signal name doesn’t exist, // a critical warning is emitted. No validation is performed on the // "detail" string when specified in @detailed_signal, other than a // non-empty check. // // Refer to the [signals documentation](signals.html) for more // details. func SignalConnectObject(InstanceVar *TypeInstance, DetailedSignalVar string, CHandlerVar *Callback, GobjectVar *Object, ConnectFlagsVar ConnectFlags) uint { var CHandlerVarRef uintptr if CHandlerVar != nil { CHandlerVarPtr := uintptr(unsafe.Pointer(CHandlerVar)) if cbRefPtr, ok := glib.GetCallback(CHandlerVarPtr); ok { CHandlerVarRef = cbRefPtr } else { fcb := func() { cbFn := *CHandlerVar cbFn() } CHandlerVarRef = purego.NewCallback(fcb) glib.SaveCallbackWithClosure(CHandlerVarPtr, CHandlerVarRef, CHandlerVar) } } cret := xSignalConnectObject(InstanceVar, DetailedSignalVar, CHandlerVarRef, GobjectVar.GoPointer(), ConnectFlagsVar) return cret } // A type for objects that have an initially floating reference. // // All the fields in the `GInitiallyUnowned` structure are private to the // implementation and should never be accessed directly. type InitiallyUnowned struct { Object } var xInitiallyUnownedGLibType func() types.GType func InitiallyUnownedGLibType() types.GType { return xInitiallyUnownedGLibType() } func InitiallyUnownedNewFromInternalPtr(ptr uintptr) *InitiallyUnowned { cls := &InitiallyUnowned{} cls.Ptr = ptr return cls } func (c *InitiallyUnowned) GoPointer() uintptr { if c == nil { return 0 } return c.Ptr } func (c *InitiallyUnowned) SetGoPointer(ptr uintptr) { c.Ptr = ptr } // The base object type. // // `GObject` is the fundamental type providing the common attributes and // methods for all object types in GTK, Pango and other libraries // based on GObject. The `GObject` class provides methods for object // construction and destruction, property access methods, and signal // support. Signals are described in detail [here][gobject-Signals]. // // For a tutorial on implementing a new `GObject` class, see [How to define and // implement a new GObject](tutorial.html#how-to-define-and-implement-a-new-gobject). // For a list of naming conventions for GObjects and their methods, see the // [GType conventions](concepts.html#conventions). For the high-level concepts // behind GObject, read // [Instantiatable classed types: Objects](concepts.html#instantiatable-classed-types-objects). // // Since GLib 2.72, all `GObject`s are guaranteed to be aligned to at least the // alignment of the largest basic GLib type (typically this is `guint64` or // `gdouble`). If you need larger alignment for an element in a `GObject`, you // should allocate it on the heap (aligned), or arrange for your `GObject` to be // appropriately padded. This guarantee applies to the `GObject` (or derived) // struct, the `GObjectClass` (or derived) struct, and any private data allocated // by `G_ADD_PRIVATE()`. type Object struct { Ptr uintptr } var xObjectGLibType func() types.GType func ObjectGLibType() types.GType { return xObjectGLibType() } func ObjectNewFromInternalPtr(ptr uintptr) *Object { cls := &Object{} cls.Ptr = ptr return cls } var xNewObject func(types.GType, string, ...interface{}) uintptr // Creates a new instance of a #GObject subtype and sets its properties. // // Construction parameters (see %G_PARAM_CONSTRUCT, %G_PARAM_CONSTRUCT_ONLY) // which are not explicitly specified are set to their default values. Any // private data for the object is guaranteed to be initialized with zeros, as // per g_type_create_instance(). // // Note that in C, small integer types in variable argument lists are promoted // up to `gint` or `guint` as appropriate, and read back accordingly. `gint` is // 32 bits on every platform on which GLib is currently supported. This means that // you can use C expressions of type `gint` with g_object_new() and properties of // type `gint` or `guint` or smaller. Specifically, you can use integer literals // with these property types. // // When using property types of `gint64` or `guint64`, you must ensure that the // value that you provide is 64 bit. This means that you should use a cast or // make use of the %G_GINT64_CONSTANT or %G_GUINT64_CONSTANT macros. // // Similarly, `gfloat` is promoted to `gdouble`, so you must ensure that the value // you provide is a `gdouble`, even for a property of type `gfloat`. // // Since GLib 2.72, all #GObjects are guaranteed to be aligned to at least the // alignment of the largest basic GLib type (typically this is `guint64` or // `gdouble`). If you need larger alignment for an element in a #GObject, you // should allocate it on the heap (aligned), or arrange for your #GObject to be // appropriately padded. func NewObject(ObjectTypeVar types.GType, FirstPropertyNameVar string, varArgs ...interface{}) *Object { var cls *Object cret := xNewObject(ObjectTypeVar, FirstPropertyNameVar, varArgs...) if cret == 0 { return nil } cls = &Object{} cls.Ptr = cret return cls } var xNewObjectValist func(types.GType, string, []interface{}) uintptr // Creates a new instance of a #GObject subtype and sets its properties. // // Construction parameters (see %G_PARAM_CONSTRUCT, %G_PARAM_CONSTRUCT_ONLY) // which are not explicitly specified are set to their default values. func NewObjectValist(ObjectTypeVar types.GType, FirstPropertyNameVar string, VarArgsVar []interface{}) *Object { var cls *Object cret := xNewObjectValist(ObjectTypeVar, FirstPropertyNameVar, VarArgsVar) if cret == 0 { return nil } cls = &Object{} cls.Ptr = cret return cls } var xNewObjectWithProperties func(types.GType, uint, []string, []Value) uintptr // Creates a new instance of a #GObject subtype and sets its properties using // the provided arrays. Both arrays must have exactly @n_properties elements, // and the names and values correspond by index. // // Construction parameters (see %G_PARAM_CONSTRUCT, %G_PARAM_CONSTRUCT_ONLY) // which are not explicitly specified are set to their default values. func NewObjectWithProperties(ObjectTypeVar types.GType, NPropertiesVar uint, NamesVar []string, ValuesVar []Value) *Object { var cls *Object cret := xNewObjectWithProperties(ObjectTypeVar, NPropertiesVar, NamesVar, ValuesVar) if cret == 0 { return nil } cls = &Object{} cls.Ptr = cret return cls } var xNewObjectv func(types.GType, uint, []Parameter) uintptr // Creates a new instance of a #GObject subtype and sets its properties. // // Construction parameters (see %G_PARAM_CONSTRUCT, %G_PARAM_CONSTRUCT_ONLY) // which are not explicitly specified are set to their default values. func NewObjectv(ObjectTypeVar types.GType, NParametersVar uint, ParametersVar []Parameter) *Object { var cls *Object cret := xNewObjectv(ObjectTypeVar, NParametersVar, ParametersVar) if cret == 0 { return nil } cls = &Object{} cls.Ptr = cret return cls } var xObjectAddToggleRef func(uintptr, uintptr, uintptr) // Increases the reference count of the object by one and sets a // callback to be called when all other references to the object are // dropped, or when this is already the last reference to the object // and another reference is established. // // This functionality is intended for binding @object to a proxy // object managed by another memory manager. This is done with two // paired references: the strong reference added by // g_object_add_toggle_ref() and a reverse reference to the proxy // object which is either a strong reference or weak reference. // // The setup is that when there are no other references to @object, // only a weak reference is held in the reverse direction from @object // to the proxy object, but when there are other references held to // @object, a strong reference is held. The @notify callback is called // when the reference from @object to the proxy object should be // "toggled" from strong to weak (@is_last_ref true) or weak to strong // (@is_last_ref false). // // Since a (normal) reference must be held to the object before // calling g_object_add_toggle_ref(), the initial state of the reverse // link is always strong. // // Multiple toggle references may be added to the same gobject, // however if there are multiple toggle references to an object, none // of them will ever be notified until all but one are removed. For // this reason, you should only ever use a toggle reference if there // is important state in the proxy object. // // Note that if you unref the object on another thread, then @notify might // still be invoked after g_object_remove_toggle_ref(), and the object argument // might be a dangling pointer. If the object is destroyed on other threads, // you must take care of that yourself. // // A g_object_add_toggle_ref() must be released with g_object_remove_toggle_ref(). func (x *Object) AddToggleRef(NotifyVar *ToggleNotify, DataVar uintptr) { var NotifyVarRef uintptr if NotifyVar != nil { NotifyVarPtr := uintptr(unsafe.Pointer(NotifyVar)) if cbRefPtr, ok := glib.GetCallback(NotifyVarPtr); ok { NotifyVarRef = cbRefPtr } else { fcb := func(arg0 uintptr, arg1 uintptr, arg2 bool) { cbFn := *NotifyVar cbFn(arg0, arg1, arg2) } NotifyVarRef = purego.NewCallback(fcb) glib.SaveCallbackWithClosure(NotifyVarPtr, NotifyVarRef, NotifyVar) } } xObjectAddToggleRef(x.GoPointer(), NotifyVarRef, DataVar) } var xObjectAddWeakPointer func(uintptr, uintptr) // Adds a weak reference from weak_pointer to @object to indicate that // the pointer located at @weak_pointer_location is only valid during // the lifetime of @object. When the @object is finalized, // @weak_pointer will be set to %NULL. // // Note that as with g_object_weak_ref(), the weak references created by // this method are not thread-safe: they cannot safely be used in one // thread if the object's last g_object_unref() might happen in another // thread. Use #GWeakRef if thread-safety is required. func (x *Object) AddWeakPointer(WeakPointerLocationVar uintptr) { xObjectAddWeakPointer(x.GoPointer(), WeakPointerLocationVar) } var xObjectBindProperty func(uintptr, string, uintptr, string, BindingFlags) uintptr // Creates a binding between @source_property on @source and @target_property // on @target. // // Whenever the @source_property is changed the @target_property is // updated using the same value. For instance: // // |[<!-- language="C" --> // // g_object_bind_property (action, "active", widget, "sensitive", 0); // // ]| // // Will result in the "sensitive" property of the widget #GObject instance to be // updated with the same value of the "active" property of the action #GObject // instance. // // If @flags contains %G_BINDING_BIDIRECTIONAL then the binding will be mutual: // if @target_property on @target changes then the @source_property on @source // will be updated as well. // // The binding will automatically be removed when either the @source or the // @target instances are finalized. To remove the binding without affecting the // @source and the @target you can just call g_object_unref() on the returned // #GBinding instance. // // Removing the binding by calling g_object_unref() on it must only be done if // the binding, @source and @target are only used from a single thread and it // is clear that both @source and @target outlive the binding. Especially it // is not safe to rely on this if the binding, @source or @target can be // finalized from different threads. Keep another reference to the binding and // use g_binding_unbind() instead to be on the safe side. // // A #GObject can have multiple bindings. func (x *Object) BindProperty(SourcePropertyVar string, TargetVar *Object, TargetPropertyVar string, FlagsVar BindingFlags) *Binding { var cls *Binding cret := xObjectBindProperty(x.GoPointer(), SourcePropertyVar, TargetVar.GoPointer(), TargetPropertyVar, FlagsVar) if cret == 0 { return nil } IncreaseRef(cret) cls = &Binding{} cls.Ptr = cret return cls } var xObjectBindPropertyFull func(uintptr, string, uintptr, string, BindingFlags, uintptr, uintptr, uintptr, uintptr) uintptr // Complete version of g_object_bind_property(). // // Creates a binding between @source_property on @source and @target_property // on @target, allowing you to set the transformation functions to be used by // the binding. // // If @flags contains %G_BINDING_BIDIRECTIONAL then the binding will be mutual: // if @target_property on @target changes then the @source_property on @source // will be updated as well. The @transform_from function is only used in case // of bidirectional bindings, otherwise it will be ignored // // The binding will automatically be removed when either the @source or the // @target instances are finalized. This will release the reference that is // being held on the #GBinding instance; if you want to hold on to the // #GBinding instance, you will need to hold a reference to it. // // To remove the binding, call g_binding_unbind(). // // A #GObject can have multiple bindings. // // The same @user_data parameter will be used for both @transform_to // and @transform_from transformation functions; the @notify function will // be called once, when the binding is removed. If you need different data // for each transformation function, please use // g_object_bind_property_with_closures() instead. func (x *Object) BindPropertyFull(SourcePropertyVar string, TargetVar *Object, TargetPropertyVar string, FlagsVar BindingFlags, TransformToVar *BindingTransformFunc, TransformFromVar *BindingTransformFunc, UserDataVar uintptr, NotifyVar *glib.DestroyNotify) *Binding { var cls *Binding var TransformToVarRef uintptr if TransformToVar != nil { TransformToVarPtr := uintptr(unsafe.Pointer(TransformToVar)) if cbRefPtr, ok := glib.GetCallback(TransformToVarPtr); ok { TransformToVarRef = cbRefPtr } else { fcb := func(arg0 uintptr, arg1 *Value, arg2 *Value, arg3 uintptr) bool { cbFn := *TransformToVar return cbFn(arg0, arg1, arg2, arg3) } TransformToVarRef = purego.NewCallback(fcb) glib.SaveCallbackWithClosure(TransformToVarPtr, TransformToVarRef, TransformToVar) } } var TransformFromVarRef uintptr if TransformFromVar != nil { TransformFromVarPtr := uintptr(unsafe.Pointer(TransformFromVar)) if cbRefPtr, ok := glib.GetCallback(TransformFromVarPtr); ok { TransformFromVarRef = cbRefPtr } else { fcb := func(arg0 uintptr, arg1 *Value, arg2 *Value, arg3 uintptr) bool { cbFn := *TransformFromVar return cbFn(arg0, arg1, arg2, arg3) } TransformFromVarRef = purego.NewCallback(fcb) glib.SaveCallbackWithClosure(TransformFromVarPtr, TransformFromVarRef, TransformFromVar) } } var NotifyVarRef uintptr if NotifyVar != nil { NotifyVarPtr := uintptr(unsafe.Pointer(NotifyVar)) if cbRefPtr, ok := glib.GetCallback(NotifyVarPtr); ok { NotifyVarRef = cbRefPtr } else { fcb := func(arg0 uintptr) { cbFn := *NotifyVar cbFn(arg0) } NotifyVarRef = purego.NewCallback(fcb) glib.SaveCallbackWithClosure(NotifyVarPtr, NotifyVarRef, NotifyVar) } } cret := xObjectBindPropertyFull(x.GoPointer(), SourcePropertyVar, TargetVar.GoPointer(), TargetPropertyVar, FlagsVar, TransformToVarRef, TransformFromVarRef, UserDataVar, NotifyVarRef) if cret == 0 { return nil } IncreaseRef(cret) cls = &Binding{} cls.Ptr = cret return cls } var xObjectBindPropertyWithClosures func(uintptr, string, uintptr, string, BindingFlags, *Closure, *Closure) uintptr // Creates a binding between @source_property on @source and @target_property // on @target, allowing you to set the transformation functions to be used by // the binding. // // This function is the language bindings friendly version of // g_object_bind_property_full(), using #GClosures instead of // function pointers. func (x *Object) BindPropertyWithClosures(SourcePropertyVar string, TargetVar *Object, TargetPropertyVar string, FlagsVar BindingFlags, TransformToVar *Closure, TransformFromVar *Closure) *Binding { var cls *Binding cret := xObjectBindPropertyWithClosures(x.GoPointer(), SourcePropertyVar, TargetVar.GoPointer(), TargetPropertyVar, FlagsVar, TransformToVar, TransformFromVar) if cret == 0 { return nil } IncreaseRef(cret) cls = &Binding{} cls.Ptr = cret return cls } var xObjectConnect func(uintptr, string, ...interface{}) uintptr // A convenience function to connect multiple signals at once. // // The signal specs expected by this function have the form // `modifier::signal_name`, where `modifier` can be one of the // following: // // - `signal`: equivalent to `g_signal_connect_data (..., NULL, G_CONNECT_DEFAULT)` // - `object-signal`, `object_signal`: equivalent to `g_signal_connect_object (..., G_CONNECT_DEFAULT)` // - `swapped-signal`, `swapped_signal`: equivalent to `g_signal_connect_data (..., NULL, G_CONNECT_SWAPPED)` // - `swapped_object_signal`, `swapped-object-signal`: equivalent to `g_signal_connect_object (..., G_CONNECT_SWAPPED)` // - `signal_after`, `signal-after`: equivalent to `g_signal_connect_data (..., NULL, G_CONNECT_AFTER)` // - `object_signal_after`, `object-signal-after`: equivalent to `g_signal_connect_object (..., G_CONNECT_AFTER)` // - `swapped_signal_after`, `swapped-signal-after`: equivalent to `g_signal_connect_data (..., NULL, G_CONNECT_SWAPPED | G_CONNECT_AFTER)` // - `swapped_object_signal_after`, `swapped-object-signal-after`: equivalent to `g_signal_connect_object (..., G_CONNECT_SWAPPED | G_CONNECT_AFTER)` // // ```c // menu->toplevel = g_object_connect (g_object_new (GTK_TYPE_WINDOW, // // "type", GTK_WINDOW_POPUP, // "child", menu, // NULL), // "signal::event", gtk_menu_window_event, menu, // "signal::size_request", gtk_menu_window_size_request, menu, // "signal::destroy", gtk_widget_destroyed, &menu->toplevel, // NULL); // // ``` func (x *Object) Connect(SignalSpecVar string, varArgs ...interface{}) *Object { var cls *Object cret := xObjectConnect(x.GoPointer(), SignalSpecVar, varArgs...) if cret == 0 { return nil } IncreaseRef(cret) cls = &Object{} cls.Ptr = cret return cls } var xObjectDisconnect func(uintptr, string, ...interface{}) // A convenience function to disconnect multiple signals at once. // // The signal specs expected by this function have the form // "any_signal", which means to disconnect any signal with matching // callback and data, or "any_signal::signal_name", which only // disconnects the signal named "signal_name". func (x *Object) Disconnect(SignalSpecVar string, varArgs ...interface{}) { xObjectDisconnect(x.GoPointer(), SignalSpecVar, varArgs...) } var xObjectDupData func(uintptr, string, uintptr, uintptr) uintptr // This is a variant of g_object_get_data() which returns // a 'duplicate' of the value. @dup_func defines the // meaning of 'duplicate' in this context, it could e.g. // take a reference on a ref-counted object. // // If the @key is not set on the object then @dup_func // will be called with a %NULL argument. // // Note that @dup_func is called while user data of @object // is locked. // // This function can be useful to avoid races when multiple // threads are using object data on the same key on the same // object. func (x *Object) DupData(KeyVar string, DupFuncVar *glib.DuplicateFunc, UserDataVar uintptr) uintptr { var DupFuncVarRef uintptr if DupFuncVar != nil { DupFuncVarPtr := uintptr(unsafe.Pointer(DupFuncVar)) if cbRefPtr, ok := glib.GetCallback(DupFuncVarPtr); ok { DupFuncVarRef = cbRefPtr } else { fcb := func(arg0 uintptr, arg1 uintptr) uintptr { cbFn := *DupFuncVar return cbFn(arg0, arg1) } DupFuncVarRef = purego.NewCallback(fcb) glib.SaveCallbackWithClosure(DupFuncVarPtr, DupFuncVarRef, DupFuncVar) } } cret := xObjectDupData(x.GoPointer(), KeyVar, DupFuncVarRef, UserDataVar) return cret } var xObjectDupQdata func(uintptr, glib.Quark, uintptr, uintptr) uintptr // This is a variant of g_object_get_qdata() which returns // a 'duplicate' of the value. @dup_func defines the // meaning of 'duplicate' in this context, it could e.g. // take a reference on a ref-counted object. // // If the @quark is not set on the object then @dup_func // will be called with a %NULL argument. // // Note that @dup_func is called while user data of @object // is locked. // // This function can be useful to avoid races when multiple // threads are using object data on the same key on the same // object. func (x *Object) DupQdata(QuarkVar glib.Quark, DupFuncVar *glib.DuplicateFunc, UserDataVar uintptr) uintptr { var DupFuncVarRef uintptr if DupFuncVar != nil { DupFuncVarPtr := uintptr(unsafe.Pointer(DupFuncVar)) if cbRefPtr, ok := glib.GetCallback(DupFuncVarPtr); ok { DupFuncVarRef = cbRefPtr } else { fcb := func(arg0 uintptr, arg1 uintptr) uintptr { cbFn := *DupFuncVar return cbFn(arg0, arg1) } DupFuncVarRef = purego.NewCallback(fcb) glib.SaveCallbackWithClosure(DupFuncVarPtr, DupFuncVarRef, DupFuncVar) } } cret := xObjectDupQdata(x.GoPointer(), QuarkVar, DupFuncVarRef, UserDataVar) return cret } var xObjectForceFloating func(uintptr) // This function is intended for #GObject implementations to re-enforce // a [floating][floating-ref] object reference. Doing this is seldom // required: all #GInitiallyUnowneds are created with a floating reference // which usually just needs to be sunken by calling g_object_ref_sink(). func (x *Object) ForceFloating() { xObjectForceFloating(x.GoPointer()) } var xObjectFreezeNotify func(uintptr) // Increases the freeze count on @object. If the freeze count is // non-zero, the emission of "notify" signals on @object is // stopped. The signals are queued until the freeze count is decreased // to zero. Duplicate notifications are squashed so that at most one // #GObject::notify signal is emitted for each property modified while the // object is frozen. // // This is necessary for accessors that modify multiple properties to prevent // premature notification while the object is still being modified. func (x *Object) FreezeNotify() { xObjectFreezeNotify(x.GoPointer()) } var xObjectGet func(uintptr, string, ...interface{}) // Gets properties of an object. // // In general, a copy is made of the property contents and the caller // is responsible for freeing the memory in the appropriate manner for // the type, for instance by calling g_free() or g_object_unref(). // // Here is an example of using g_object_get() to get the contents // of three properties: an integer, a string and an object: // |[<!-- language="C" --> // // gint intval; // guint64 uint64val; // gchar *strval; // GObject *objval; // // g_object_get (my_object, // "int-property", &intval, // "uint64-property", &uint64val, // "str-property", &strval, // "obj-property", &objval, // NULL); // // // Do something with intval, uint64val, strval, objval // // g_free (strval); // g_object_unref (objval); // // ]| func (x *Object) Get(FirstPropertyNameVar string, varArgs ...interface{}) { xObjectGet(x.GoPointer(), FirstPropertyNameVar, varArgs...) } var xObjectGetData func(uintptr, string) uintptr // Gets a named field from the objects table of associations (see g_object_set_data()). func (x *Object) GetData(KeyVar string) uintptr { cret := xObjectGetData(x.GoPointer(), KeyVar) return cret } var xObjectGetProperty func(uintptr, string, *Value) // Gets a property of an object. // // The @value can be: // // - an empty #GValue initialized by %G_VALUE_INIT, which will be // automatically initialized with the expected type of the property // (since GLib 2.60) // - a #GValue initialized with the expected type of the property // - a #GValue initialized with a type to which the expected type // of the property can be transformed // // In general, a copy is made of the property contents and the caller is // responsible for freeing the memory by calling g_value_unset(). // // Note that g_object_get_property() is really intended for language // bindings, g_object_get() is much more convenient for C programming. func (x *Object) GetProperty(PropertyNameVar string, ValueVar *Value) { xObjectGetProperty(x.GoPointer(), PropertyNameVar, ValueVar) } var xObjectGetQdata func(uintptr, glib.Quark) uintptr // This function gets back user data pointers stored via // g_object_set_qdata(). func (x *Object) GetQdata(QuarkVar glib.Quark) uintptr { cret := xObjectGetQdata(x.GoPointer(), QuarkVar) return cret } var xObjectGetValist func(uintptr, string, []interface{}) // Gets properties of an object. // // In general, a copy is made of the property contents and the caller // is responsible for freeing the memory in the appropriate manner for // the type, for instance by calling g_free() or g_object_unref(). // // See g_object_get(). func (x *Object) GetValist(FirstPropertyNameVar string, VarArgsVar []interface{}) { xObjectGetValist(x.GoPointer(), FirstPropertyNameVar, VarArgsVar) } var xObjectGetv func(uintptr, uint, []string, []Value) // Gets @n_properties properties for an @object. // Obtained properties will be set to @values. All properties must be valid. // Warnings will be emitted and undefined behaviour may result if invalid // properties are passed in. func (x *Object) Getv(NPropertiesVar uint, NamesVar []string, ValuesVar []Value) { xObjectGetv(x.GoPointer(), NPropertiesVar, NamesVar, ValuesVar) } var xObjectIsFloating func(uintptr) bool // Checks whether @object has a [floating][floating-ref] reference. func (x *Object) IsFloating() bool { cret := xObjectIsFloating(x.GoPointer()) return cret } var xObjectNotify func(uintptr, string) // Emits a "notify" signal for the property @property_name on @object. // // When possible, eg. when signaling a property change from within the class // that registered the property, you should use g_object_notify_by_pspec() // instead. // // Note that emission of the notify signal may be blocked with // g_object_freeze_notify(). In this case, the signal emissions are queued // and will be emitted (in reverse order) when g_object_thaw_notify() is // called. func (x *Object) Notify(PropertyNameVar string) { xObjectNotify(x.GoPointer(), PropertyNameVar) } var xObjectNotifyByPspec func(uintptr, uintptr) // Emits a "notify" signal for the property specified by @pspec on @object. // // This function omits the property name lookup, hence it is faster than // g_object_notify(). // // One way to avoid using g_object_notify() from within the // class that registered the properties, and using g_object_notify_by_pspec() // instead, is to store the GParamSpec used with // g_object_class_install_property() inside a static array, e.g.: // // |[<!-- language="C" --> // // typedef enum // { // PROP_FOO = 1, // PROP_LAST // } MyObjectProperty; // // static GParamSpec *properties[PROP_LAST]; // // static void // my_object_class_init (MyObjectClass *klass) // { // properties[PROP_FOO] = g_param_spec_int ("foo", NULL, NULL, // 0, 100, // 50, // G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); // g_object_class_install_property (gobject_class, // PROP_FOO, // properties[PROP_FOO]); // } // // ]| // // and then notify a change on the "foo" property with: // // |[<!-- language="C" --> // // g_object_notify_by_pspec (self, properties[PROP_FOO]); // // ]| func (x *Object) NotifyByPspec(PspecVar *ParamSpec) { xObjectNotifyByPspec(x.GoPointer(), PspecVar.GoPointer()) } var xObjectRef func(uintptr) uintptr // Increases the reference count of @object. // // Since GLib 2.56, if `GLIB_VERSION_MAX_ALLOWED` is 2.56 or greater, the type // of @object will be propagated to the return type (using the GCC typeof() // extension), so any casting the caller needs to do on the return type must be // explicit. func (x *Object) Ref() *Object { var cls *Object cret := xObjectRef(x.GoPointer()) if cret == 0 { return nil } cls = &Object{} cls.Ptr = cret return cls } var xObjectRefSink func(uintptr) uintptr // Increase the reference count of @object, and possibly remove the // [floating][floating-ref] reference, if @object has a floating reference. // // In other words, if the object is floating, then this call "assumes // ownership" of the floating reference, converting it to a normal // reference by clearing the floating flag while leaving the reference // count unchanged. If the object is not floating, then this call // adds a new normal reference increasing the reference count by one. // // Since GLib 2.56, the type of @object will be propagated to the return type // under the same conditions as for g_object_ref(). func (x *Object) RefSink() *Object { var cls *Object cret := xObjectRefSink(x.GoPointer()) if cret == 0 { return nil } IncreaseRef(cret) cls = &Object{} cls.Ptr = cret return cls } var xObjectRemoveToggleRef func(uintptr, uintptr, uintptr) // Removes a reference added with g_object_add_toggle_ref(). The // reference count of the object is decreased by one. // // Note that if you unref the object on another thread, then @notify might // still be invoked after g_object_remove_toggle_ref(), and the object argument // might be a dangling pointer. If the object is destroyed on other threads, // you must take care of that yourself. func (x *Object) RemoveToggleRef(NotifyVar *ToggleNotify, DataVar uintptr) { var NotifyVarRef uintptr if NotifyVar != nil { NotifyVarPtr := uintptr(unsafe.Pointer(NotifyVar)) if cbRefPtr, ok := glib.GetCallback(NotifyVarPtr); ok { NotifyVarRef = cbRefPtr } else { fcb := func(arg0 uintptr, arg1 uintptr, arg2 bool) { cbFn := *NotifyVar cbFn(arg0, arg1, arg2) } NotifyVarRef = purego.NewCallback(fcb) glib.SaveCallbackWithClosure(NotifyVarPtr, NotifyVarRef, NotifyVar) } } xObjectRemoveToggleRef(x.GoPointer(), NotifyVarRef, DataVar) } var xObjectRemoveWeakPointer func(uintptr, uintptr) // Removes a weak reference from @object that was previously added // using g_object_add_weak_pointer(). The @weak_pointer_location has // to match the one used with g_object_add_weak_pointer(). func (x *Object) RemoveWeakPointer(WeakPointerLocationVar uintptr) { xObjectRemoveWeakPointer(x.GoPointer(), WeakPointerLocationVar) } var xObjectReplaceData func(uintptr, string, uintptr, uintptr, uintptr, *glib.DestroyNotify) bool // Compares the user data for the key @key on @object with // @oldval, and if they are the same, replaces @oldval with // @newval. // // This is like a typical atomic compare-and-exchange // operation, for user data on an object. // // If the previous value was replaced then ownership of the // old value (@oldval) is passed to the caller, including // the registered destroy notify for it (passed out in @old_destroy). // It’s up to the caller to free this as needed, which may // or may not include using @old_destroy as sometimes replacement // should not destroy the object in the normal way. // // See g_object_set_data() for guidance on using a small, bounded set of values // for @key. func (x *Object) ReplaceData(KeyVar string, OldvalVar uintptr, NewvalVar uintptr, DestroyVar *glib.DestroyNotify, OldDestroyVar *glib.DestroyNotify) bool { var DestroyVarRef uintptr if DestroyVar != nil { DestroyVarPtr := uintptr(unsafe.Pointer(DestroyVar)) if cbRefPtr, ok := glib.GetCallback(DestroyVarPtr); ok { DestroyVarRef = cbRefPtr } else { fcb := func(arg0 uintptr) { cbFn := *DestroyVar cbFn(arg0) } DestroyVarRef = purego.NewCallback(fcb) glib.SaveCallbackWithClosure(DestroyVarPtr, DestroyVarRef, DestroyVar) } } cret := xObjectReplaceData(x.GoPointer(), KeyVar, OldvalVar, NewvalVar, DestroyVarRef, OldDestroyVar) return cret } var xObjectReplaceQdata func(uintptr, glib.Quark, uintptr, uintptr, uintptr, *glib.DestroyNotify) bool // Compares the user data for the key @quark on @object with // @oldval, and if they are the same, replaces @oldval with // @newval. // // This is like a typical atomic compare-and-exchange // operation, for user data on an object. // // If the previous value was replaced then ownership of the // old value (@oldval) is passed to the caller, including // the registered destroy notify for it (passed out in @old_destroy). // It’s up to the caller to free this as needed, which may // or may not include using @old_destroy as sometimes replacement // should not destroy the object in the normal way. func (x *Object) ReplaceQdata(QuarkVar glib.Quark, OldvalVar uintptr, NewvalVar uintptr, DestroyVar *glib.DestroyNotify, OldDestroyVar *glib.DestroyNotify) bool { var DestroyVarRef uintptr if DestroyVar != nil { DestroyVarPtr := uintptr(unsafe.Pointer(DestroyVar)) if cbRefPtr, ok := glib.GetCallback(DestroyVarPtr); ok { DestroyVarRef = cbRefPtr } else { fcb := func(arg0 uintptr) { cbFn := *DestroyVar cbFn(arg0) } DestroyVarRef = purego.NewCallback(fcb) glib.SaveCallbackWithClosure(DestroyVarPtr, DestroyVarRef, DestroyVar) } } cret := xObjectReplaceQdata(x.GoPointer(), QuarkVar, OldvalVar, NewvalVar, DestroyVarRef, OldDestroyVar) return cret } var xObjectRunDispose func(uintptr) // Releases all references to other objects. This can be used to break // reference cycles. // // This function should only be called from object system implementations. func (x *Object) RunDispose() { xObjectRunDispose(x.GoPointer()) } var xObjectSet func(uintptr, string, ...interface{}) // Sets properties on an object. // // The same caveats about passing integer literals as varargs apply as with // g_object_new(). In particular, any integer literals set as the values for // properties of type #gint64 or #guint64 must be 64 bits wide, using the // %G_GINT64_CONSTANT or %G_GUINT64_CONSTANT macros. // // Note that the "notify" signals are queued and only emitted (in // reverse order) after all properties have been set. See // g_object_freeze_notify(). func (x *Object) Set(FirstPropertyNameVar string, varArgs ...interface{}) { xObjectSet(x.GoPointer(), FirstPropertyNameVar, varArgs...) } var xObjectSetData func(uintptr, string, uintptr) // Each object carries around a table of associations from // strings to pointers. This function lets you set an association. // // If the object already had an association with that name, // the old association will be destroyed. // // Internally, the @key is converted to a #GQuark using g_quark_from_string(). // This means a copy of @key is kept permanently (even after @object has been // finalized) — so it is recommended to only use a small, bounded set of values // for @key in your program, to avoid the #GQuark storage growing unbounded. func (x *Object) SetData(KeyVar string, DataVar uintptr) { xObjectSetData(x.GoPointer(), KeyVar, DataVar) } var xObjectSetDataFull func(uintptr, string, uintptr, uintptr) // Like g_object_set_data() except it adds notification // for when the association is destroyed, either by setting it // to a different value or when the object is destroyed. // // Note that the @destroy callback is not called if @data is %NULL. func (x *Object) SetDataFull(KeyVar string, DataVar uintptr, DestroyVar *glib.DestroyNotify) { var DestroyVarRef uintptr if DestroyVar != nil { DestroyVarPtr := uintptr(unsafe.Pointer(DestroyVar)) if cbRefPtr, ok := glib.GetCallback(DestroyVarPtr); ok { DestroyVarRef = cbRefPtr } else { fcb := func(arg0 uintptr) { cbFn := *DestroyVar cbFn(arg0) } DestroyVarRef = purego.NewCallback(fcb) glib.SaveCallbackWithClosure(DestroyVarPtr, DestroyVarRef, DestroyVar) } } xObjectSetDataFull(x.GoPointer(), KeyVar, DataVar, DestroyVarRef) } var xObjectSetProperty func(uintptr, string, *Value) // Sets a property on an object. func (x *Object) SetProperty(PropertyNameVar string, ValueVar *Value) { xObjectSetProperty(x.GoPointer(), PropertyNameVar, ValueVar) } var xObjectSetQdata func(uintptr, glib.Quark, uintptr) // This sets an opaque, named pointer on an object. // The name is specified through a #GQuark (retrieved e.g. via // g_quark_from_static_string()), and the pointer // can be gotten back from the @object with g_object_get_qdata() // until the @object is finalized. // Setting a previously set user data pointer, overrides (frees) // the old pointer set, using #NULL as pointer essentially // removes the data stored. func (x *Object) SetQdata(QuarkVar glib.Quark, DataVar uintptr) { xObjectSetQdata(x.GoPointer(), QuarkVar, DataVar) } var xObjectSetQdataFull func(uintptr, glib.Quark, uintptr, uintptr) // This function works like g_object_set_qdata(), but in addition, // a void (*destroy) (gpointer) function may be specified which is // called with @data as argument when the @object is finalized, or // the data is being overwritten by a call to g_object_set_qdata() // with the same @quark. func (x *Object) SetQdataFull(QuarkVar glib.Quark, DataVar uintptr, DestroyVar *glib.DestroyNotify) { var DestroyVarRef uintptr if DestroyVar != nil { DestroyVarPtr := uintptr(unsafe.Pointer(DestroyVar)) if cbRefPtr, ok := glib.GetCallback(DestroyVarPtr); ok { DestroyVarRef = cbRefPtr } else { fcb := func(arg0 uintptr) { cbFn := *DestroyVar cbFn(arg0) } DestroyVarRef = purego.NewCallback(fcb) glib.SaveCallbackWithClosure(DestroyVarPtr, DestroyVarRef, DestroyVar) } } xObjectSetQdataFull(x.GoPointer(), QuarkVar, DataVar, DestroyVarRef) } var xObjectSetValist func(uintptr, string, []interface{}) // Sets properties on an object. func (x *Object) SetValist(FirstPropertyNameVar string, VarArgsVar []interface{}) { xObjectSetValist(x.GoPointer(), FirstPropertyNameVar, VarArgsVar) } var xObjectSetv func(uintptr, uint, []string, []Value) // Sets @n_properties properties for an @object. // Properties to be set will be taken from @values. All properties must be // valid. Warnings will be emitted and undefined behaviour may result if invalid // properties are passed in. func (x *Object) Setv(NPropertiesVar uint, NamesVar []string, ValuesVar []Value) { xObjectSetv(x.GoPointer(), NPropertiesVar, NamesVar, ValuesVar) } var xObjectStealData func(uintptr, string) uintptr // Remove a specified datum from the object's data associations, // without invoking the association's destroy handler. func (x *Object) StealData(KeyVar string) uintptr { cret := xObjectStealData(x.GoPointer(), KeyVar) return cret } var xObjectStealQdata func(uintptr, glib.Quark) uintptr // This function gets back user data pointers stored via // g_object_set_qdata() and removes the @data from object // without invoking its destroy() function (if any was // set). // Usually, calling this function is only required to update // user data pointers with a destroy notifier, for example: // |[<!-- language="C" --> // void // object_add_to_user_list (GObject *object, // // const gchar *new_string) // // { // // the quark, naming the object data // GQuark quark_string_list = g_quark_from_static_string ("my-string-list"); // // retrieve the old string list // GList *list = g_object_steal_qdata (object, quark_string_list); // // // prepend new string // list = g_list_prepend (list, g_strdup (new_string)); // // this changed 'list', so we need to set it again // g_object_set_qdata_full (object, quark_string_list, list, free_string_list); // } // // static void // free_string_list (gpointer data) // // { // GList *node, *list = data; // // for (node = list; node; node = node->next) // g_free (node->data); // g_list_free (list); // } // // ]| // Using g_object_get_qdata() in the above example, instead of // g_object_steal_qdata() would have left the destroy function set, // and thus the partial string list would have been freed upon // g_object_set_qdata_full(). func (x *Object) StealQdata(QuarkVar glib.Quark) uintptr { cret := xObjectStealQdata(x.GoPointer(), QuarkVar) return cret } var xObjectTakeRef func(uintptr) uintptr // If @object is floating, sink it. Otherwise, do nothing. // // In other words, this function will convert a floating reference (if // present) into a full reference. // // Typically you want to use g_object_ref_sink() in order to // automatically do the correct thing with respect to floating or // non-floating references, but there is one specific scenario where // this function is helpful. // // The situation where this function is helpful is when creating an API // that allows the user to provide a callback function that returns a // GObject. We certainly want to allow the user the flexibility to // return a non-floating reference from this callback (for the case // where the object that is being returned already exists). // // At the same time, the API style of some popular GObject-based // libraries (such as Gtk) make it likely that for newly-created GObject // instances, the user can be saved some typing if they are allowed to // return a floating reference. // // Using this function on the return value of the user's callback allows // the user to do whichever is more convenient for them. The caller will // always receives exactly one full reference to the value: either the // one that was returned in the first place, or a floating reference // that has been converted to a full reference. // // This function has an odd interaction when combined with // g_object_ref_sink() running at the same time in another thread on // the same #GObject instance. If g_object_ref_sink() runs first then // the result will be that the floating reference is converted to a hard // reference. If g_object_take_ref() runs first then the result will be // that the floating reference is converted to a hard reference and an // additional reference on top of that one is added. It is best to avoid // this situation. func (x *Object) TakeRef() *Object { var cls *Object cret := xObjectTakeRef(x.GoPointer()) if cret == 0 { return nil } cls = &Object{} cls.Ptr = cret return cls } var xObjectThawNotify func(uintptr) // Reverts the effect of a previous call to // g_object_freeze_notify(). The freeze count is decreased on @object // and when it reaches zero, queued "notify" signals are emitted. // // Duplicate notifications for each property are squashed so that at most one // #GObject::notify signal is emitted for each property, in the reverse order // in which they have been queued. // // It is an error to call this function when the freeze count is zero. func (x *Object) ThawNotify() { xObjectThawNotify(x.GoPointer()) } var xObjectUnref func(uintptr) // Decreases the reference count of @object. When its reference count // drops to 0, the object is finalized (i.e. its memory is freed). // // If the pointer to the #GObject may be reused in future (for example, if it is // an instance variable of another object), it is recommended to clear the // pointer to %NULL rather than retain a dangling pointer to a potentially // invalid #GObject instance. Use g_clear_object() for this. func (x *Object) Unref() { xObjectUnref(x.GoPointer()) } var xObjectWatchClosure func(uintptr, *Closure) // This function essentially limits the life time of the @closure to // the life time of the object. That is, when the object is finalized, // the @closure is invalidated by calling g_closure_invalidate() on // it, in order to prevent invocations of the closure with a finalized // (nonexisting) object. Also, g_object_ref() and g_object_unref() are // added as marshal guards to the @closure, to ensure that an extra // reference count is held on @object during invocation of the // @closure. Usually, this function will be called on closures that // use this @object as closure data. func (x *Object) WatchClosure(ClosureVar *Closure) { xObjectWatchClosure(x.GoPointer(), ClosureVar) } var xObjectWeakRef func(uintptr, uintptr, uintptr) // Adds a weak reference callback to an object. Weak references are // used for notification when an object is disposed. They are called // "weak references" because they allow you to safely hold a pointer // to an object without calling g_object_ref() (g_object_ref() adds a // strong reference, that is, forces the object to stay alive). // // Note that the weak references created by this method are not // thread-safe: they cannot safely be used in one thread if the // object's last g_object_unref() might happen in another thread. // Use #GWeakRef if thread-safety is required. func (x *Object) WeakRef(NotifyVar *WeakNotify, DataVar uintptr) { var NotifyVarRef uintptr if NotifyVar != nil { NotifyVarPtr := uintptr(unsafe.Pointer(NotifyVar)) if cbRefPtr, ok := glib.GetCallback(NotifyVarPtr); ok { NotifyVarRef = cbRefPtr } else { fcb := func(arg0 uintptr, arg1 uintptr) { cbFn := *NotifyVar cbFn(arg0, arg1) } NotifyVarRef = purego.NewCallback(fcb) glib.SaveCallbackWithClosure(NotifyVarPtr, NotifyVarRef, NotifyVar) } } xObjectWeakRef(x.GoPointer(), NotifyVarRef, DataVar) } var xObjectWeakUnref func(uintptr, uintptr, uintptr) // Removes a weak reference callback to an object. func (x *Object) WeakUnref(NotifyVar *WeakNotify, DataVar uintptr) { var NotifyVarRef uintptr if NotifyVar != nil { NotifyVarPtr := uintptr(unsafe.Pointer(NotifyVar)) if cbRefPtr, ok := glib.GetCallback(NotifyVarPtr); ok { NotifyVarRef = cbRefPtr } else { fcb := func(arg0 uintptr, arg1 uintptr) { cbFn := *NotifyVar cbFn(arg0, arg1) } NotifyVarRef = purego.NewCallback(fcb) glib.SaveCallbackWithClosure(NotifyVarPtr, NotifyVarRef, NotifyVar) } } xObjectWeakUnref(x.GoPointer(), NotifyVarRef, DataVar) } func (c *Object) GoPointer() uintptr { if c == nil { return 0 } return c.Ptr } func (c *Object) SetGoPointer(ptr uintptr) { c.Ptr = ptr } // The notify signal is emitted on an object when one of its properties has // its value set through g_object_set_property(), g_object_set(), et al. // // Note that getting this signal doesn’t itself guarantee that the value of // the property has actually changed. When it is emitted is determined by the // derived GObject class. If the implementor did not create the property with // %G_PARAM_EXPLICIT_NOTIFY, then any call to g_object_set_property() results // in ::notify being emitted, even if the new value is the same as the old. // If they did pass %G_PARAM_EXPLICIT_NOTIFY, then this signal is emitted only // when they explicitly call g_object_notify() or g_object_notify_by_pspec(), // and common practice is to do that only when the value has actually changed. // // This signal is typically used to obtain change notification for a // single property, by specifying the property name as a detail in the // g_signal_connect() call, like this: // // |[<!-- language="C" --> // g_signal_connect (text_view->buffer, "notify::paste-target-list", // // G_CALLBACK (gtk_text_view_target_list_notify), // text_view) // // ]| // // It is important to note that you must use // [canonical parameter names][class@GObject.ParamSpec#parameter-names] as // detail strings for the notify signal. func (x *Object) ConnectNotify(cb *func(Object, uintptr)) uint { cbPtr := uintptr(unsafe.Pointer(cb)) if cbRefPtr, ok := glib.GetCallback(cbPtr); ok { handlerID := SignalConnect(x.GoPointer(), "notify", cbRefPtr) glib.SaveHandlerMapping(handlerID, cbPtr) return handlerID } fcb := func(clsPtr uintptr, PspecVarp uintptr) { fa := Object{} fa.Ptr = clsPtr cbFn := *cb cbFn(fa, PspecVarp) } cbRefPtr := purego.NewCallback(fcb) glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb) handlerID := SignalConnect(x.GoPointer(), "notify", cbRefPtr) glib.SaveHandlerMapping(handlerID, cbPtr) return handlerID } // ConnectNotifyWithDetail connects to the "notify" signal with a detail string. // The detail is appended as "notify::". func (x *Object) ConnectNotifyWithDetail(detail string, cb *func(Object, uintptr)) uint { cbPtr := uintptr(unsafe.Pointer(cb)) signalName := fmt.Sprintf("notify::%s", detail) if cbRefPtr, ok := glib.GetCallback(cbPtr); ok { handlerID := SignalConnect(x.GoPointer(), signalName, cbRefPtr) glib.SaveHandlerMapping(handlerID, cbPtr) return handlerID } fcb := func(clsPtr uintptr, PspecVarp uintptr) { fa := Object{} fa.Ptr = clsPtr cbFn := *cb cbFn(fa, PspecVarp) } cbRefPtr := purego.NewCallback(fcb) glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb) handlerID := SignalConnect(x.GoPointer(), signalName, cbRefPtr) glib.SaveHandlerMapping(handlerID, cbPtr) return handlerID } var xObjectCompatControl func(uint, uintptr) uint func ObjectCompatControl(WhatVar uint, DataVar uintptr) uint { cret := xObjectCompatControl(WhatVar, DataVar) return cret } var xObjectInterfaceFindProperty func(*TypeInterface, string) uintptr // Find the #GParamSpec with the given name for an // interface. Generally, the interface vtable passed in as @g_iface // will be the default vtable from g_type_default_interface_ref(), or, // if you know the interface has already been loaded, // g_type_default_interface_peek(). func ObjectInterfaceFindProperty(GIfaceVar *TypeInterface, PropertyNameVar string) *ParamSpec { var cls *ParamSpec cret := xObjectInterfaceFindProperty(GIfaceVar, PropertyNameVar) if cret == 0 { return nil } IncreaseRef(cret) cls = &ParamSpec{} cls.Ptr = cret return cls } var xObjectInterfaceInstallProperty func(*TypeInterface, uintptr) // Add a property to an interface; this is only useful for interfaces // that are added to GObject-derived types. Adding a property to an // interface forces all objects classes with that interface to have a // compatible property. The compatible property could be a newly // created #GParamSpec, but normally // g_object_class_override_property() will be used so that the object // class only needs to provide an implementation and inherits the // property description, default value, bounds, and so forth from the // interface property. // // This function is meant to be called from the interface's default // vtable initialization function (the @class_init member of // #GTypeInfo.) It must not be called after after @class_init has // been called for any object types implementing this interface. // // If @pspec is a floating reference, it will be consumed. func ObjectInterfaceInstallProperty(GIfaceVar *TypeInterface, PspecVar *ParamSpec) { xObjectInterfaceInstallProperty(GIfaceVar, PspecVar.GoPointer()) } var xObjectInterfaceListProperties func(*TypeInterface, *uint) uintptr // Lists the properties of an interface.Generally, the interface // vtable passed in as @g_iface will be the default vtable from // g_type_default_interface_ref(), or, if you know the interface has // already been loaded, g_type_default_interface_peek(). func ObjectInterfaceListProperties(GIfaceVar *TypeInterface, NPropertiesPVar *uint) uintptr { cret := xObjectInterfaceListProperties(GIfaceVar, NPropertiesPVar) return cret } func init() { core.SetPackageName("GOBJECT", "gobject-2.0") core.SetSharedLibraries("GOBJECT", []string{"libgobject-2.0.so.0"}) var libs []uintptr for _, libPath := range core.GetPaths("GOBJECT") { lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL) if err != nil { panic(err) } libs = append(libs, lib) } core.PuregoSafeRegister(&xCclosureNewObject, libs, "g_cclosure_new_object") core.PuregoSafeRegister(&xCclosureNewObjectSwap, libs, "g_cclosure_new_object_swap") core.PuregoSafeRegister(&xClearObject, libs, "g_clear_object") core.PuregoSafeRegister(&xSignalConnectObject, libs, "g_signal_connect_object") core.PuregoSafeRegister(&xObjectClassFindProperty, libs, "g_object_class_find_property") core.PuregoSafeRegister(&xObjectClassInstallProperties, libs, "g_object_class_install_properties") core.PuregoSafeRegister(&xObjectClassInstallProperty, libs, "g_object_class_install_property") core.PuregoSafeRegister(&xObjectClassListProperties, libs, "g_object_class_list_properties") core.PuregoSafeRegister(&xObjectClassOverrideProperty, libs, "g_object_class_override_property") core.PuregoSafeRegister(&xWeakRefClear, libs, "g_weak_ref_clear") core.PuregoSafeRegister(&xWeakRefGet, libs, "g_weak_ref_get") core.PuregoSafeRegister(&xWeakRefInit, libs, "g_weak_ref_init") core.PuregoSafeRegister(&xWeakRefSet, libs, "g_weak_ref_set") core.PuregoSafeRegister(&xInitiallyUnownedGLibType, libs, "g_initially_unowned_get_type") core.PuregoSafeRegister(&xObjectGLibType, libs, "g_object_get_type") core.PuregoSafeRegister(&xNewObject, libs, "g_object_new") core.PuregoSafeRegister(&xNewObjectValist, libs, "g_object_new_valist") core.PuregoSafeRegister(&xNewObjectWithProperties, libs, "g_object_new_with_properties") core.PuregoSafeRegister(&xNewObjectv, libs, "g_object_newv") core.PuregoSafeRegister(&xObjectAddToggleRef, libs, "g_object_add_toggle_ref") core.PuregoSafeRegister(&xObjectAddWeakPointer, libs, "g_object_add_weak_pointer") core.PuregoSafeRegister(&xObjectBindProperty, libs, "g_object_bind_property") core.PuregoSafeRegister(&xObjectBindPropertyFull, libs, "g_object_bind_property_full") core.PuregoSafeRegister(&xObjectBindPropertyWithClosures, libs, "g_object_bind_property_with_closures") core.PuregoSafeRegister(&xObjectConnect, libs, "g_object_connect") core.PuregoSafeRegister(&xObjectDisconnect, libs, "g_object_disconnect") core.PuregoSafeRegister(&xObjectDupData, libs, "g_object_dup_data") core.PuregoSafeRegister(&xObjectDupQdata, libs, "g_object_dup_qdata") core.PuregoSafeRegister(&xObjectForceFloating, libs, "g_object_force_floating") core.PuregoSafeRegister(&xObjectFreezeNotify, libs, "g_object_freeze_notify") core.PuregoSafeRegister(&xObjectGet, libs, "g_object_get") core.PuregoSafeRegister(&xObjectGetData, libs, "g_object_get_data") core.PuregoSafeRegister(&xObjectGetProperty, libs, "g_object_get_property") core.PuregoSafeRegister(&xObjectGetQdata, libs, "g_object_get_qdata") core.PuregoSafeRegister(&xObjectGetValist, libs, "g_object_get_valist") core.PuregoSafeRegister(&xObjectGetv, libs, "g_object_getv") core.PuregoSafeRegister(&xObjectIsFloating, libs, "g_object_is_floating") core.PuregoSafeRegister(&xObjectNotify, libs, "g_object_notify") core.PuregoSafeRegister(&xObjectNotifyByPspec, libs, "g_object_notify_by_pspec") core.PuregoSafeRegister(&xObjectRef, libs, "g_object_ref") core.PuregoSafeRegister(&xObjectRefSink, libs, "g_object_ref_sink") core.PuregoSafeRegister(&xObjectRemoveToggleRef, libs, "g_object_remove_toggle_ref") core.PuregoSafeRegister(&xObjectRemoveWeakPointer, libs, "g_object_remove_weak_pointer") core.PuregoSafeRegister(&xObjectReplaceData, libs, "g_object_replace_data") core.PuregoSafeRegister(&xObjectReplaceQdata, libs, "g_object_replace_qdata") core.PuregoSafeRegister(&xObjectRunDispose, libs, "g_object_run_dispose") core.PuregoSafeRegister(&xObjectSet, libs, "g_object_set") core.PuregoSafeRegister(&xObjectSetData, libs, "g_object_set_data") core.PuregoSafeRegister(&xObjectSetDataFull, libs, "g_object_set_data_full") core.PuregoSafeRegister(&xObjectSetProperty, libs, "g_object_set_property") core.PuregoSafeRegister(&xObjectSetQdata, libs, "g_object_set_qdata") core.PuregoSafeRegister(&xObjectSetQdataFull, libs, "g_object_set_qdata_full") core.PuregoSafeRegister(&xObjectSetValist, libs, "g_object_set_valist") core.PuregoSafeRegister(&xObjectSetv, libs, "g_object_setv") core.PuregoSafeRegister(&xObjectStealData, libs, "g_object_steal_data") core.PuregoSafeRegister(&xObjectStealQdata, libs, "g_object_steal_qdata") core.PuregoSafeRegister(&xObjectTakeRef, libs, "g_object_take_ref") core.PuregoSafeRegister(&xObjectThawNotify, libs, "g_object_thaw_notify") core.PuregoSafeRegister(&xObjectUnref, libs, "g_object_unref") core.PuregoSafeRegister(&xObjectWatchClosure, libs, "g_object_watch_closure") core.PuregoSafeRegister(&xObjectWeakRef, libs, "g_object_weak_ref") core.PuregoSafeRegister(&xObjectWeakUnref, libs, "g_object_weak_unref") core.PuregoSafeRegister(&xObjectCompatControl, libs, "g_object_compat_control") core.PuregoSafeRegister(&xObjectInterfaceFindProperty, libs, "g_object_interface_find_property") core.PuregoSafeRegister(&xObjectInterfaceInstallProperty, libs, "g_object_interface_install_property") core.PuregoSafeRegister(&xObjectInterfaceListProperties, libs, "g_object_interface_list_properties") }