1// Package gtk was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gtk
3
4import (
5 "structs"
6 "unsafe"
7
8 "github.com/ebitengine/purego"
9
10 "github.com/bnema/puregotk/pkg/core"
11 "github.com/bnema/puregotk/v4/gio"
12 "github.com/bnema/puregotk/v4/glib"
13 "github.com/bnema/puregotk/v4/gobject"
14 "github.com/bnema/puregotk/v4/gobject/types"
15)
16
17// User function that is called to map an @item of the original model to
18// an item expected by the map model.
19//
20// The returned items must conform to the item type of the model they are
21// used with.
22type MapListModelMapFunc func(uintptr, uintptr) uintptr
23
24type MapListModelClass struct {
25 _ structs.HostLayout
26
27 ParentClass gobject.ObjectClass
28}
29
30func (x *MapListModelClass) GoPointer() uintptr {
31 return uintptr(unsafe.Pointer(x))
32}
33
34// A list model that maps the items in another model to different items.
35//
36// `GtkMapListModel` uses a [callback@Gtk.MapListModelMapFunc].
37//
38// Example: Create a list of `GtkEventControllers`
39// ```c
40// static gpointer
41// map_to_controllers (gpointer widget,
42//
43// gpointer data)
44//
45// {
46// gpointer result = gtk_widget_observe_controllers (widget);
47// g_object_unref (widget);
48// return result;
49// }
50//
51// widgets = gtk_widget_observe_children (widget);
52//
53// controllers = gtk_map_list_model_new (widgets,
54//
55// map_to_controllers,
56// NULL, NULL);
57//
58// model = gtk_flatten_list_model_new (GTK_TYPE_EVENT_CONTROLLER,
59//
60// controllers);
61//
62// ```
63//
64// `GtkMapListModel` will attempt to discard the mapped objects as soon as
65// they are no longer needed and recreate them if necessary.
66//
67// `GtkMapListModel` passes through sections from the underlying model.
68type MapListModel struct {
69 gobject.Object
70}
71
72var xMapListModelGLibType func() types.GType
73
74func MapListModelGLibType() types.GType {
75 return xMapListModelGLibType()
76}
77
78func MapListModelNewFromInternalPtr(ptr uintptr) *MapListModel {
79 cls := &MapListModel{}
80 cls.Ptr = ptr
81 return cls
82}
83
84var xNewMapListModel func(uintptr, uintptr, uintptr, uintptr) uintptr
85
86// Creates a new `GtkMapListModel` for the given arguments.
87func NewMapListModel(ModelVar gio.ListModel, MapFuncVar *MapListModelMapFunc, UserDataVar uintptr, UserDestroyVar *glib.DestroyNotify) *MapListModel {
88 var cls *MapListModel
89
90 var MapFuncVarRef uintptr
91 if MapFuncVar != nil {
92 MapFuncVarPtr := uintptr(unsafe.Pointer(MapFuncVar))
93 if cbRefPtr, ok := glib.GetCallback(MapFuncVarPtr); ok {
94 MapFuncVarRef = cbRefPtr
95 } else {
96 fcb := func(arg0 uintptr, arg1 uintptr) uintptr {
97 cbFn := *MapFuncVar
98 return cbFn(arg0, arg1)
99 }
100 MapFuncVarRef = purego.NewCallback(fcb)
101 glib.SaveCallbackWithClosure(MapFuncVarPtr, MapFuncVarRef, MapFuncVar)
102 }
103 }
104
105 var UserDestroyVarRef uintptr
106 if UserDestroyVar != nil {
107 UserDestroyVarPtr := uintptr(unsafe.Pointer(UserDestroyVar))
108 if cbRefPtr, ok := glib.GetCallback(UserDestroyVarPtr); ok {
109 UserDestroyVarRef = cbRefPtr
110 } else {
111 fcb := func(arg0 uintptr) {
112 cbFn := *UserDestroyVar
113 cbFn(arg0)
114 }
115 UserDestroyVarRef = purego.NewCallback(fcb)
116 glib.SaveCallbackWithClosure(UserDestroyVarPtr, UserDestroyVarRef, UserDestroyVar)
117 }
118 }
119
120 cret := xNewMapListModel(ModelVar.GoPointer(), MapFuncVarRef, UserDataVar, UserDestroyVarRef)
121
122 if cret == 0 {
123 return nil
124 }
125 cls = &MapListModel{}
126 cls.Ptr = cret
127 return cls
128}
129
130var xMapListModelGetModel func(uintptr) uintptr
131
132// Gets the model that is currently being mapped or %NULL if none.
133func (x *MapListModel) GetModel() *gio.ListModelBase {
134 var cls *gio.ListModelBase
135
136 cret := xMapListModelGetModel(x.GoPointer())
137
138 if cret == 0 {
139 return nil
140 }
141 gobject.IncreaseRef(cret)
142 cls = &gio.ListModelBase{}
143 cls.Ptr = cret
144 return cls
145}
146
147var xMapListModelHasMap func(uintptr) bool
148
149// Checks if a map function is currently set on @self.
150func (x *MapListModel) HasMap() bool {
151
152 cret := xMapListModelHasMap(x.GoPointer())
153 return cret
154}
155
156var xMapListModelSetMapFunc func(uintptr, uintptr, uintptr, uintptr)
157
158// Sets the function used to map items.
159//
160// The function will be called whenever an item needs to be mapped
161// and must return the item to use for the given input item.
162//
163// Note that `GtkMapListModel` may call this function multiple times
164// on the same item, because it may delete items it doesn't need anymore.
165//
166// GTK makes no effort to ensure that @map_func conforms to the item type
167// of @self. It assumes that the caller knows what they are doing and the map
168// function returns items of the appropriate type.
169func (x *MapListModel) SetMapFunc(MapFuncVar *MapListModelMapFunc, UserDataVar uintptr, UserDestroyVar *glib.DestroyNotify) {
170
171 var MapFuncVarRef uintptr
172 if MapFuncVar != nil {
173 MapFuncVarPtr := uintptr(unsafe.Pointer(MapFuncVar))
174 if cbRefPtr, ok := glib.GetCallback(MapFuncVarPtr); ok {
175 MapFuncVarRef = cbRefPtr
176 } else {
177 fcb := func(arg0 uintptr, arg1 uintptr) uintptr {
178 cbFn := *MapFuncVar
179 return cbFn(arg0, arg1)
180 }
181 MapFuncVarRef = purego.NewCallback(fcb)
182 glib.SaveCallbackWithClosure(MapFuncVarPtr, MapFuncVarRef, MapFuncVar)
183 }
184 }
185
186 var UserDestroyVarRef uintptr
187 if UserDestroyVar != nil {
188 UserDestroyVarPtr := uintptr(unsafe.Pointer(UserDestroyVar))
189 if cbRefPtr, ok := glib.GetCallback(UserDestroyVarPtr); ok {
190 UserDestroyVarRef = cbRefPtr
191 } else {
192 fcb := func(arg0 uintptr) {
193 cbFn := *UserDestroyVar
194 cbFn(arg0)
195 }
196 UserDestroyVarRef = purego.NewCallback(fcb)
197 glib.SaveCallbackWithClosure(UserDestroyVarPtr, UserDestroyVarRef, UserDestroyVar)
198 }
199 }
200
201 xMapListModelSetMapFunc(x.GoPointer(), MapFuncVarRef, UserDataVar, UserDestroyVarRef)
202
203}
204
205var xMapListModelSetModel func(uintptr, uintptr)
206
207// Sets the model to be mapped.
208//
209// GTK makes no effort to ensure that @model conforms to the item type
210// expected by the map function. It assumes that the caller knows what
211// they are doing and have set up an appropriate map function.
212func (x *MapListModel) SetModel(ModelVar gio.ListModel) {
213
214 xMapListModelSetModel(x.GoPointer(), ModelVar.GoPointer())
215
216}
217
218func (c *MapListModel) GoPointer() uintptr {
219 if c == nil {
220 return 0
221 }
222 return c.Ptr
223}
224
225func (c *MapListModel) SetGoPointer(ptr uintptr) {
226 c.Ptr = ptr
227}
228
229// GetPropertyHasMap gets the "has-map" property.
230// If a map is set for this model
231func (x *MapListModel) GetPropertyHasMap() bool {
232 var v gobject.Value
233 x.GetProperty("has-map", &v)
234 return v.GetBoolean()
235}
236
237// GetPropertyNItems gets the "n-items" property.
238// The number of items. See [method@Gio.ListModel.get_n_items].
239func (x *MapListModel) GetPropertyNItems() uint {
240 var v gobject.Value
241 x.GetProperty("n-items", &v)
242 return v.GetUint()
243}
244
245// Get the item at @position.
246//
247// If @position is greater than the number of items in @list, %NULL is
248// returned.
249//
250// %NULL is never returned for an index that is smaller than the length
251// of the list.
252//
253// See also: g_list_model_get_n_items()
254func (x *MapListModel) GetItem(PositionVar uint) uintptr {
255
256 cret := gio.XGListModelGetItem(x.GoPointer(), PositionVar)
257 return cret
258}
259
260// Gets the type of the items in @list.
261//
262// All items returned from g_list_model_get_item() are of the type
263// returned by this function, or a subtype, or if the type is an
264// interface, they are an implementation of that interface.
265//
266// The item type of a #GListModel can not change during the life of the
267// model.
268func (x *MapListModel) GetItemType() types.GType {
269
270 cret := gio.XGListModelGetItemType(x.GoPointer())
271 return cret
272}
273
274// Gets the number of items in @list.
275//
276// Depending on the model implementation, calling this function may be
277// less efficient than iterating the list with increasing values for
278// @position until g_list_model_get_item() returns %NULL.
279func (x *MapListModel) GetNItems() uint {
280
281 cret := gio.XGListModelGetNItems(x.GoPointer())
282 return cret
283}
284
285// Get the item at @position.
286//
287// If @position is greater than the number of items in @list, %NULL is
288// returned.
289//
290// %NULL is never returned for an index that is smaller than the length
291// of the list.
292//
293// This function is meant to be used by language bindings in place
294// of g_list_model_get_item().
295//
296// See also: g_list_model_get_n_items()
297func (x *MapListModel) GetObject(PositionVar uint) *gobject.Object {
298 var cls *gobject.Object
299
300 cret := gio.XGListModelGetObject(x.GoPointer(), PositionVar)
301
302 if cret == 0 {
303 return nil
304 }
305 cls = &gobject.Object{}
306 cls.Ptr = cret
307 return cls
308}
309
310// Emits the #GListModel::items-changed signal on @list.
311//
312// This function should only be called by classes implementing
313// #GListModel. It has to be called after the internal representation
314// of @list has been updated, because handlers connected to this signal
315// might query the new state of the list.
316//
317// Implementations must only make changes to the model (as visible to
318// its consumer) in places that will not cause problems for that
319// consumer. For models that are driven directly by a write API (such
320// as #GListStore), changes can be reported in response to uses of that
321// API. For models that represent remote data, changes should only be
322// made from a fresh mainloop dispatch. It is particularly not
323// permitted to make changes in response to a call to the #GListModel
324// consumer API.
325//
326// Stated another way: in general, it is assumed that code making a
327// series of accesses to the model via the API, without returning to the
328// mainloop, and without calling other code, will continue to view the
329// same contents of the model.
330func (x *MapListModel) ItemsChanged(PositionVar uint, RemovedVar uint, AddedVar uint) {
331
332 gio.XGListModelItemsChanged(x.GoPointer(), PositionVar, RemovedVar, AddedVar)
333
334}
335
336// Query the section that covers the given position. The number of
337// items in the section can be computed by `out_end - out_start`.
338//
339// If the position is larger than the number of items, a single
340// range from n_items to G_MAXUINT will be returned.
341func (x *MapListModel) GetSection(PositionVar uint, OutStartVar *uint, OutEndVar *uint) {
342
343 XGtkSectionModelGetSection(x.GoPointer(), PositionVar, OutStartVar, OutEndVar)
344
345}
346
347// This function emits the [signal@Gtk.SectionModel::sections-changed]
348// signal to notify about changes to sections.
349//
350// It must cover all positions that used to be a section start or that
351// are now a section start. It does not have to cover all positions for
352// which the section has changed.
353//
354// The [signal@Gio.ListModel::items-changed] implies the effect of the
355// [signal@Gtk.SectionModel::sections-changed] signal for all the items
356// it covers.
357//
358// It is recommended that when changes to the items cause section changes
359// in a larger range, that the larger range is included in the emission
360// of the [signal@Gio.ListModel::items-changed] instead of emitting
361// two signals.
362func (x *MapListModel) SectionsChanged(PositionVar uint, NItemsVar uint) {
363
364 XGtkSectionModelSectionsChanged(x.GoPointer(), PositionVar, NItemsVar)
365
366}
367
368func init() {
369 core.SetPackageName("GTK", "gtk4")
370 core.SetSharedLibraries("GTK", []string{"libgtk-4.so.1"})
371 var libs []uintptr
372 for _, libPath := range core.GetPaths("GTK") {
373 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
374 if err != nil {
375 panic(err)
376 }
377 libs = append(libs, lib)
378 }
379
380 core.PuregoSafeRegister(&xMapListModelGLibType, libs, "gtk_map_list_model_get_type")
381
382 core.PuregoSafeRegister(&xNewMapListModel, libs, "gtk_map_list_model_new")
383
384 core.PuregoSafeRegister(&xMapListModelGetModel, libs, "gtk_map_list_model_get_model")
385 core.PuregoSafeRegister(&xMapListModelHasMap, libs, "gtk_map_list_model_has_map")
386 core.PuregoSafeRegister(&xMapListModelSetMapFunc, libs, "gtk_map_list_model_set_map_func")
387 core.PuregoSafeRegister(&xMapListModelSetModel, libs, "gtk_map_list_model_set_model")
388
389}