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/glib"
12 "github.com/bnema/puregotk/v4/gobject"
13 "github.com/bnema/puregotk/v4/gobject/types"
14)
15
16type SignalListItemFactoryClass struct {
17 _ structs.HostLayout
18}
19
20func (x *SignalListItemFactoryClass) GoPointer() uintptr {
21 return uintptr(unsafe.Pointer(x))
22}
23
24// Emits signals to manage listitems.
25//
26// Signals are emitted for every listitem in the same order:
27//
28// 1. [signal@Gtk.SignalListItemFactory::setup] is emitted to set up permanent
29// things on the listitem. This usually means constructing the widgets used in
30// the row and adding them to the listitem.
31//
32// 2. [signal@Gtk.SignalListItemFactory::bind] is emitted to bind the item passed
33// via [property@Gtk.ListItem:item] to the widgets that have been created in
34// step 1 or to add item-specific widgets. Signals are connected to listen to
35// changes - both to changes in the item to update the widgets or to changes
36// in the widgets to update the item. After this signal has been called, the
37// listitem may be shown in a list widget.
38//
39// 3. [signal@Gtk.SignalListItemFactory::unbind] is emitted to undo everything
40// done in step 2. Usually this means disconnecting signal handlers. Once this
41// signal has been called, the listitem will no longer be used in a list
42// widget.
43//
44// 4. [signal@Gtk.SignalListItemFactory::bind] and
45// [signal@Gtk.SignalListItemFactory::unbind] may be emitted multiple times
46// again to bind the listitem for use with new items. By reusing listitems,
47// potentially costly setup can be avoided. However, it means code needs to
48// make sure to properly clean up the listitem in step 3 so that no information
49// from the previous use leaks into the next one.
50//
51// 5. [signal@Gtk.SignalListItemFactory::teardown] is emitted to allow undoing
52// the effects of [signal@Gtk.SignalListItemFactory::setup]. After this signal
53// was emitted on a listitem, the listitem will be destroyed and not be used again.
54//
55// Note that during the signal emissions, changing properties on the listitems
56// passed will not trigger notify signals as the listitem's notifications are
57// frozen. See [method@GObject.Object.freeze_notify] for details.
58//
59// For tracking changes in other properties in the listitem, the
60// ::notify signal is recommended. The signal can be connected in the
61// [signal@Gtk.SignalListItemFactory::setup] signal and removed again during
62// [signal@Gtk.SignalListItemFactory::teardown].
63type SignalListItemFactory struct {
64 ListItemFactory
65}
66
67var xSignalListItemFactoryGLibType func() types.GType
68
69func SignalListItemFactoryGLibType() types.GType {
70 return xSignalListItemFactoryGLibType()
71}
72
73func SignalListItemFactoryNewFromInternalPtr(ptr uintptr) *SignalListItemFactory {
74 cls := &SignalListItemFactory{}
75 cls.Ptr = ptr
76 return cls
77}
78
79var xNewSignalListItemFactory func() uintptr
80
81// Creates a new `GtkSignalListItemFactory`.
82//
83// You need to connect signal handlers before you use it.
84func NewSignalListItemFactory() *SignalListItemFactory {
85 var cls *SignalListItemFactory
86
87 cret := xNewSignalListItemFactory()
88
89 if cret == 0 {
90 return nil
91 }
92 cls = &SignalListItemFactory{}
93 cls.Ptr = cret
94 return cls
95}
96
97func (c *SignalListItemFactory) GoPointer() uintptr {
98 if c == nil {
99 return 0
100 }
101 return c.Ptr
102}
103
104func (c *SignalListItemFactory) SetGoPointer(ptr uintptr) {
105 c.Ptr = ptr
106}
107
108// Emitted when an object has been bound to an item.
109//
110// The handler for this signal must set
111// to populate the listitem with widgets.
112//
113// After this signal was emitted, the object might be shown in
114// a [class@Gtk.ListView] or other widget.
115//
116// The [signal@Gtk.SignalListItemFactory::unbind] signal is the
117// opposite of this signal and can be used to undo everything done
118// in this signal.
119func (x *SignalListItemFactory) ConnectBind(cb *func(SignalListItemFactory, uintptr)) uint {
120 cbPtr := uintptr(unsafe.Pointer(cb))
121 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
122 handlerID := gobject.SignalConnect(x.GoPointer(), "bind", cbRefPtr)
123 glib.SaveHandlerMapping(handlerID, cbPtr)
124 return handlerID
125 }
126
127 fcb := func(clsPtr uintptr, ObjectVarp uintptr) {
128 fa := SignalListItemFactory{}
129 fa.Ptr = clsPtr
130 cbFn := *cb
131
132 cbFn(fa, ObjectVarp)
133
134 }
135 cbRefPtr := purego.NewCallback(fcb)
136 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
137 handlerID := gobject.SignalConnect(x.GoPointer(), "bind", cbRefPtr)
138 glib.SaveHandlerMapping(handlerID, cbPtr)
139 return handlerID
140}
141
142// Emitted when a newly created listitem needs to be prepared for use.
143//
144// It is the first signal emitted for every listitem.
145//
146// The handler for this signal must call [method@Gtk.ListItem.set_child]
147// to populate the listitem with widgets.
148//
149// The [signal@Gtk.SignalListItemFactory::teardown] signal is the opposite
150// of this signal and can be used to undo everything done in this signal.
151func (x *SignalListItemFactory) ConnectSetup(cb *func(SignalListItemFactory, uintptr)) uint {
152 cbPtr := uintptr(unsafe.Pointer(cb))
153 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
154 handlerID := gobject.SignalConnect(x.GoPointer(), "setup", cbRefPtr)
155 glib.SaveHandlerMapping(handlerID, cbPtr)
156 return handlerID
157 }
158
159 fcb := func(clsPtr uintptr, ObjectVarp uintptr) {
160 fa := SignalListItemFactory{}
161 fa.Ptr = clsPtr
162 cbFn := *cb
163
164 cbFn(fa, ObjectVarp)
165
166 }
167 cbRefPtr := purego.NewCallback(fcb)
168 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
169 handlerID := gobject.SignalConnect(x.GoPointer(), "setup", cbRefPtr)
170 glib.SaveHandlerMapping(handlerID, cbPtr)
171 return handlerID
172}
173
174// Emitted when an object is about to be destroyed.
175//
176// It is the last signal ever emitted for this @object.
177//
178// This signal is the opposite of the [signal@Gtk.SignalListItemFactory::setup]
179// signal and should be used to undo everything done in that signal.
180func (x *SignalListItemFactory) ConnectTeardown(cb *func(SignalListItemFactory, uintptr)) uint {
181 cbPtr := uintptr(unsafe.Pointer(cb))
182 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
183 handlerID := gobject.SignalConnect(x.GoPointer(), "teardown", cbRefPtr)
184 glib.SaveHandlerMapping(handlerID, cbPtr)
185 return handlerID
186 }
187
188 fcb := func(clsPtr uintptr, ObjectVarp uintptr) {
189 fa := SignalListItemFactory{}
190 fa.Ptr = clsPtr
191 cbFn := *cb
192
193 cbFn(fa, ObjectVarp)
194
195 }
196 cbRefPtr := purego.NewCallback(fcb)
197 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
198 handlerID := gobject.SignalConnect(x.GoPointer(), "teardown", cbRefPtr)
199 glib.SaveHandlerMapping(handlerID, cbPtr)
200 return handlerID
201}
202
203// Emitted when an object has been unbound from its item.
204//
205// This happens for example when a listitem was removed from use
206// in a list widget and its [property@Gtk.ListItem:item] is about
207// to be unset.
208//
209// This signal is the opposite of the [signal@Gtk.SignalListItemFactory::bind]
210// signal and should be used to undo everything done in that signal.
211func (x *SignalListItemFactory) ConnectUnbind(cb *func(SignalListItemFactory, uintptr)) uint {
212 cbPtr := uintptr(unsafe.Pointer(cb))
213 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
214 handlerID := gobject.SignalConnect(x.GoPointer(), "unbind", cbRefPtr)
215 glib.SaveHandlerMapping(handlerID, cbPtr)
216 return handlerID
217 }
218
219 fcb := func(clsPtr uintptr, ObjectVarp uintptr) {
220 fa := SignalListItemFactory{}
221 fa.Ptr = clsPtr
222 cbFn := *cb
223
224 cbFn(fa, ObjectVarp)
225
226 }
227 cbRefPtr := purego.NewCallback(fcb)
228 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
229 handlerID := gobject.SignalConnect(x.GoPointer(), "unbind", cbRefPtr)
230 glib.SaveHandlerMapping(handlerID, cbPtr)
231 return handlerID
232}
233
234func init() {
235 core.SetPackageName("GTK", "gtk4")
236 core.SetSharedLibraries("GTK", []string{"libgtk-4.so.1"})
237 var libs []uintptr
238 for _, libPath := range core.GetPaths("GTK") {
239 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
240 if err != nil {
241 panic(err)
242 }
243 libs = append(libs, lib)
244 }
245
246 core.PuregoSafeRegister(&xSignalListItemFactoryGLibType, libs, "gtk_signal_list_item_factory_get_type")
247
248 core.PuregoSafeRegister(&xNewSignalListItemFactory, libs, "gtk_signal_list_item_factory_new")
249
250}