// Package gtk was automatically generated by github.com/bnema/puregotk DO NOT EDIT package gtk import ( "structs" "unsafe" "github.com/ebitengine/purego" "github.com/bnema/puregotk/pkg/core" "github.com/bnema/puregotk/v4/gio" "github.com/bnema/puregotk/v4/glib" "github.com/bnema/puregotk/v4/gobject" "github.com/bnema/puregotk/v4/gobject/types" ) // User function that is called to map an @item of the original model to // an item expected by the map model. // // The returned items must conform to the item type of the model they are // used with. type MapListModelMapFunc func(uintptr, uintptr) uintptr type MapListModelClass struct { _ structs.HostLayout ParentClass gobject.ObjectClass } func (x *MapListModelClass) GoPointer() uintptr { return uintptr(unsafe.Pointer(x)) } // A list model that maps the items in another model to different items. // // `GtkMapListModel` uses a [callback@Gtk.MapListModelMapFunc]. // // Example: Create a list of `GtkEventControllers` // ```c // static gpointer // map_to_controllers (gpointer widget, // // gpointer data) // // { // gpointer result = gtk_widget_observe_controllers (widget); // g_object_unref (widget); // return result; // } // // widgets = gtk_widget_observe_children (widget); // // controllers = gtk_map_list_model_new (widgets, // // map_to_controllers, // NULL, NULL); // // model = gtk_flatten_list_model_new (GTK_TYPE_EVENT_CONTROLLER, // // controllers); // // ``` // // `GtkMapListModel` will attempt to discard the mapped objects as soon as // they are no longer needed and recreate them if necessary. // // `GtkMapListModel` passes through sections from the underlying model. type MapListModel struct { gobject.Object } var xMapListModelGLibType func() types.GType func MapListModelGLibType() types.GType { return xMapListModelGLibType() } func MapListModelNewFromInternalPtr(ptr uintptr) *MapListModel { cls := &MapListModel{} cls.Ptr = ptr return cls } var xNewMapListModel func(uintptr, uintptr, uintptr, uintptr) uintptr // Creates a new `GtkMapListModel` for the given arguments. func NewMapListModel(ModelVar gio.ListModel, MapFuncVar *MapListModelMapFunc, UserDataVar uintptr, UserDestroyVar *glib.DestroyNotify) *MapListModel { var cls *MapListModel var MapFuncVarRef uintptr if MapFuncVar != nil { MapFuncVarPtr := uintptr(unsafe.Pointer(MapFuncVar)) if cbRefPtr, ok := glib.GetCallback(MapFuncVarPtr); ok { MapFuncVarRef = cbRefPtr } else { fcb := func(arg0 uintptr, arg1 uintptr) uintptr { cbFn := *MapFuncVar return cbFn(arg0, arg1) } MapFuncVarRef = purego.NewCallback(fcb) glib.SaveCallbackWithClosure(MapFuncVarPtr, MapFuncVarRef, MapFuncVar) } } var UserDestroyVarRef uintptr if UserDestroyVar != nil { UserDestroyVarPtr := uintptr(unsafe.Pointer(UserDestroyVar)) if cbRefPtr, ok := glib.GetCallback(UserDestroyVarPtr); ok { UserDestroyVarRef = cbRefPtr } else { fcb := func(arg0 uintptr) { cbFn := *UserDestroyVar cbFn(arg0) } UserDestroyVarRef = purego.NewCallback(fcb) glib.SaveCallbackWithClosure(UserDestroyVarPtr, UserDestroyVarRef, UserDestroyVar) } } cret := xNewMapListModel(ModelVar.GoPointer(), MapFuncVarRef, UserDataVar, UserDestroyVarRef) if cret == 0 { return nil } cls = &MapListModel{} cls.Ptr = cret return cls } var xMapListModelGetModel func(uintptr) uintptr // Gets the model that is currently being mapped or %NULL if none. func (x *MapListModel) GetModel() *gio.ListModelBase { var cls *gio.ListModelBase cret := xMapListModelGetModel(x.GoPointer()) if cret == 0 { return nil } gobject.IncreaseRef(cret) cls = &gio.ListModelBase{} cls.Ptr = cret return cls } var xMapListModelHasMap func(uintptr) bool // Checks if a map function is currently set on @self. func (x *MapListModel) HasMap() bool { cret := xMapListModelHasMap(x.GoPointer()) return cret } var xMapListModelSetMapFunc func(uintptr, uintptr, uintptr, uintptr) // Sets the function used to map items. // // The function will be called whenever an item needs to be mapped // and must return the item to use for the given input item. // // Note that `GtkMapListModel` may call this function multiple times // on the same item, because it may delete items it doesn't need anymore. // // GTK makes no effort to ensure that @map_func conforms to the item type // of @self. It assumes that the caller knows what they are doing and the map // function returns items of the appropriate type. func (x *MapListModel) SetMapFunc(MapFuncVar *MapListModelMapFunc, UserDataVar uintptr, UserDestroyVar *glib.DestroyNotify) { var MapFuncVarRef uintptr if MapFuncVar != nil { MapFuncVarPtr := uintptr(unsafe.Pointer(MapFuncVar)) if cbRefPtr, ok := glib.GetCallback(MapFuncVarPtr); ok { MapFuncVarRef = cbRefPtr } else { fcb := func(arg0 uintptr, arg1 uintptr) uintptr { cbFn := *MapFuncVar return cbFn(arg0, arg1) } MapFuncVarRef = purego.NewCallback(fcb) glib.SaveCallbackWithClosure(MapFuncVarPtr, MapFuncVarRef, MapFuncVar) } } var UserDestroyVarRef uintptr if UserDestroyVar != nil { UserDestroyVarPtr := uintptr(unsafe.Pointer(UserDestroyVar)) if cbRefPtr, ok := glib.GetCallback(UserDestroyVarPtr); ok { UserDestroyVarRef = cbRefPtr } else { fcb := func(arg0 uintptr) { cbFn := *UserDestroyVar cbFn(arg0) } UserDestroyVarRef = purego.NewCallback(fcb) glib.SaveCallbackWithClosure(UserDestroyVarPtr, UserDestroyVarRef, UserDestroyVar) } } xMapListModelSetMapFunc(x.GoPointer(), MapFuncVarRef, UserDataVar, UserDestroyVarRef) } var xMapListModelSetModel func(uintptr, uintptr) // Sets the model to be mapped. // // GTK makes no effort to ensure that @model conforms to the item type // expected by the map function. It assumes that the caller knows what // they are doing and have set up an appropriate map function. func (x *MapListModel) SetModel(ModelVar gio.ListModel) { xMapListModelSetModel(x.GoPointer(), ModelVar.GoPointer()) } func (c *MapListModel) GoPointer() uintptr { if c == nil { return 0 } return c.Ptr } func (c *MapListModel) SetGoPointer(ptr uintptr) { c.Ptr = ptr } // GetPropertyHasMap gets the "has-map" property. // If a map is set for this model func (x *MapListModel) GetPropertyHasMap() bool { var v gobject.Value x.GetProperty("has-map", &v) return v.GetBoolean() } // GetPropertyNItems gets the "n-items" property. // The number of items. See [method@Gio.ListModel.get_n_items]. func (x *MapListModel) GetPropertyNItems() uint { var v gobject.Value x.GetProperty("n-items", &v) return v.GetUint() } // Get the item at @position. // // If @position is greater than the number of items in @list, %NULL is // returned. // // %NULL is never returned for an index that is smaller than the length // of the list. // // See also: g_list_model_get_n_items() func (x *MapListModel) GetItem(PositionVar uint) uintptr { cret := gio.XGListModelGetItem(x.GoPointer(), PositionVar) return cret } // Gets the type of the items in @list. // // All items returned from g_list_model_get_item() are of the type // returned by this function, or a subtype, or if the type is an // interface, they are an implementation of that interface. // // The item type of a #GListModel can not change during the life of the // model. func (x *MapListModel) GetItemType() types.GType { cret := gio.XGListModelGetItemType(x.GoPointer()) return cret } // Gets the number of items in @list. // // Depending on the model implementation, calling this function may be // less efficient than iterating the list with increasing values for // @position until g_list_model_get_item() returns %NULL. func (x *MapListModel) GetNItems() uint { cret := gio.XGListModelGetNItems(x.GoPointer()) return cret } // Get the item at @position. // // If @position is greater than the number of items in @list, %NULL is // returned. // // %NULL is never returned for an index that is smaller than the length // of the list. // // This function is meant to be used by language bindings in place // of g_list_model_get_item(). // // See also: g_list_model_get_n_items() func (x *MapListModel) GetObject(PositionVar uint) *gobject.Object { var cls *gobject.Object cret := gio.XGListModelGetObject(x.GoPointer(), PositionVar) if cret == 0 { return nil } cls = &gobject.Object{} cls.Ptr = cret return cls } // Emits the #GListModel::items-changed signal on @list. // // This function should only be called by classes implementing // #GListModel. It has to be called after the internal representation // of @list has been updated, because handlers connected to this signal // might query the new state of the list. // // Implementations must only make changes to the model (as visible to // its consumer) in places that will not cause problems for that // consumer. For models that are driven directly by a write API (such // as #GListStore), changes can be reported in response to uses of that // API. For models that represent remote data, changes should only be // made from a fresh mainloop dispatch. It is particularly not // permitted to make changes in response to a call to the #GListModel // consumer API. // // Stated another way: in general, it is assumed that code making a // series of accesses to the model via the API, without returning to the // mainloop, and without calling other code, will continue to view the // same contents of the model. func (x *MapListModel) ItemsChanged(PositionVar uint, RemovedVar uint, AddedVar uint) { gio.XGListModelItemsChanged(x.GoPointer(), PositionVar, RemovedVar, AddedVar) } // Query the section that covers the given position. The number of // items in the section can be computed by `out_end - out_start`. // // If the position is larger than the number of items, a single // range from n_items to G_MAXUINT will be returned. func (x *MapListModel) GetSection(PositionVar uint, OutStartVar *uint, OutEndVar *uint) { XGtkSectionModelGetSection(x.GoPointer(), PositionVar, OutStartVar, OutEndVar) } // This function emits the [signal@Gtk.SectionModel::sections-changed] // signal to notify about changes to sections. // // It must cover all positions that used to be a section start or that // are now a section start. It does not have to cover all positions for // which the section has changed. // // The [signal@Gio.ListModel::items-changed] implies the effect of the // [signal@Gtk.SectionModel::sections-changed] signal for all the items // it covers. // // It is recommended that when changes to the items cause section changes // in a larger range, that the larger range is included in the emission // of the [signal@Gio.ListModel::items-changed] instead of emitting // two signals. func (x *MapListModel) SectionsChanged(PositionVar uint, NItemsVar uint) { XGtkSectionModelSectionsChanged(x.GoPointer(), PositionVar, NItemsVar) } func init() { core.SetPackageName("GTK", "gtk4") core.SetSharedLibraries("GTK", []string{"libgtk-4.so.1"}) var libs []uintptr for _, libPath := range core.GetPaths("GTK") { lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL) if err != nil { panic(err) } libs = append(libs, lib) } core.PuregoSafeRegister(&xMapListModelGLibType, libs, "gtk_map_list_model_get_type") core.PuregoSafeRegister(&xNewMapListModel, libs, "gtk_map_list_model_new") core.PuregoSafeRegister(&xMapListModelGetModel, libs, "gtk_map_list_model_get_model") core.PuregoSafeRegister(&xMapListModelHasMap, libs, "gtk_map_list_model_has_map") core.PuregoSafeRegister(&xMapListModelSetMapFunc, libs, "gtk_map_list_model_set_map_func") core.PuregoSafeRegister(&xMapListModelSetModel, libs, "gtk_map_list_model_set_model") }