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/types"
13)
14
15// A GtkTreeIterCompareFunc should return a negative integer, zero, or a positive
16// integer if @a sorts before @b, @a sorts with @b, or @a sorts after @b
17// respectively.
18//
19// If two iters compare as equal, their order in the sorted model
20// is undefined. In order to ensure that the `GtkTreeSortable` behaves as
21// expected, the GtkTreeIterCompareFunc must define a partial order on
22// the model, i.e. it must be reflexive, antisymmetric and transitive.
23//
24// For example, if @model is a product catalogue, then a compare function
25// for the “price” column could be one which returns
26// `price_of(@a) - price_of(@b)`.
27type TreeIterCompareFunc func(uintptr, *TreeIter, *TreeIter, uintptr) int
28
29type TreeSortableIface struct {
30 _ structs.HostLayout
31
32 GIface uintptr
33
34 xSortColumnChanged uintptr
35
36 xGetSortColumnId uintptr
37
38 xSetSortColumnId uintptr
39
40 xSetSortFunc uintptr
41
42 xSetDefaultSortFunc uintptr
43
44 xHasDefaultSortFunc uintptr
45}
46
47func (x *TreeSortableIface) GoPointer() uintptr {
48 return uintptr(unsafe.Pointer(x))
49}
50
51// OverrideSortColumnChanged sets the "sort_column_changed" callback function.
52// Signal emitted when the sort column or sort
53//
54// order of sortable is changed.
55func (x *TreeSortableIface) OverrideSortColumnChanged(cb func(TreeSortable)) {
56 if cb == nil {
57 x.xSortColumnChanged = 0
58 } else {
59 x.xSortColumnChanged = purego.NewCallback(func(SortableVarp uintptr) {
60 cb(&TreeSortableBase{Ptr: SortableVarp})
61 })
62 }
63}
64
65// GetSortColumnChanged gets the "sort_column_changed" callback function.
66// Signal emitted when the sort column or sort
67//
68// order of sortable is changed.
69func (x *TreeSortableIface) GetSortColumnChanged() func(TreeSortable) {
70 if x.xSortColumnChanged == 0 {
71 return nil
72 }
73 var rawCallback func(SortableVarp uintptr)
74 purego.RegisterFunc(&rawCallback, x.xSortColumnChanged)
75 return func(SortableVar TreeSortable) {
76 rawCallback(SortableVar.GoPointer())
77 }
78}
79
80// OverrideGetSortColumnId sets the "get_sort_column_id" callback function.
81// Fills in sort_column_id and order with the
82//
83// current sort column and the order.
84func (x *TreeSortableIface) OverrideGetSortColumnId(cb func(TreeSortable, *int, *SortType) bool) {
85 if cb == nil {
86 x.xGetSortColumnId = 0
87 } else {
88 x.xGetSortColumnId = purego.NewCallback(func(SortableVarp uintptr, SortColumnIdVarp *int, OrderVarp *SortType) bool {
89 return cb(&TreeSortableBase{Ptr: SortableVarp}, SortColumnIdVarp, OrderVarp)
90 })
91 }
92}
93
94// GetGetSortColumnId gets the "get_sort_column_id" callback function.
95// Fills in sort_column_id and order with the
96//
97// current sort column and the order.
98func (x *TreeSortableIface) GetGetSortColumnId() func(TreeSortable, *int, *SortType) bool {
99 if x.xGetSortColumnId == 0 {
100 return nil
101 }
102 var rawCallback func(SortableVarp uintptr, SortColumnIdVarp *int, OrderVarp *SortType) bool
103 purego.RegisterFunc(&rawCallback, x.xGetSortColumnId)
104 return func(SortableVar TreeSortable, SortColumnIdVar *int, OrderVar *SortType) bool {
105 return rawCallback(SortableVar.GoPointer(), SortColumnIdVar, OrderVar)
106 }
107}
108
109// OverrideSetSortColumnId sets the "set_sort_column_id" callback function.
110// Sets the current sort column to be
111//
112// sort_column_id.
113func (x *TreeSortableIface) OverrideSetSortColumnId(cb func(TreeSortable, int, SortType)) {
114 if cb == nil {
115 x.xSetSortColumnId = 0
116 } else {
117 x.xSetSortColumnId = purego.NewCallback(func(SortableVarp uintptr, SortColumnIdVarp int, OrderVarp SortType) {
118 cb(&TreeSortableBase{Ptr: SortableVarp}, SortColumnIdVarp, OrderVarp)
119 })
120 }
121}
122
123// GetSetSortColumnId gets the "set_sort_column_id" callback function.
124// Sets the current sort column to be
125//
126// sort_column_id.
127func (x *TreeSortableIface) GetSetSortColumnId() func(TreeSortable, int, SortType) {
128 if x.xSetSortColumnId == 0 {
129 return nil
130 }
131 var rawCallback func(SortableVarp uintptr, SortColumnIdVarp int, OrderVarp SortType)
132 purego.RegisterFunc(&rawCallback, x.xSetSortColumnId)
133 return func(SortableVar TreeSortable, SortColumnIdVar int, OrderVar SortType) {
134 rawCallback(SortableVar.GoPointer(), SortColumnIdVar, OrderVar)
135 }
136}
137
138// OverrideSetSortFunc sets the "set_sort_func" callback function.
139// Sets the comparison function used when sorting to
140//
141// be sort_func.
142func (x *TreeSortableIface) OverrideSetSortFunc(cb func(TreeSortable, int, *TreeIterCompareFunc, uintptr, *glib.DestroyNotify)) {
143 if cb == nil {
144 x.xSetSortFunc = 0
145 } else {
146 x.xSetSortFunc = purego.NewCallback(func(SortableVarp uintptr, SortColumnIdVarp int, SortFuncVarp uintptr, UserDataVarp uintptr, DestroyVarp uintptr) {
147 cb(&TreeSortableBase{Ptr: SortableVarp}, SortColumnIdVarp, (*TreeIterCompareFunc)(unsafe.Pointer(SortFuncVarp)), UserDataVarp, (*glib.DestroyNotify)(unsafe.Pointer(DestroyVarp)))
148 })
149 }
150}
151
152// GetSetSortFunc gets the "set_sort_func" callback function.
153// Sets the comparison function used when sorting to
154//
155// be sort_func.
156func (x *TreeSortableIface) GetSetSortFunc() func(TreeSortable, int, *TreeIterCompareFunc, uintptr, *glib.DestroyNotify) {
157 if x.xSetSortFunc == 0 {
158 return nil
159 }
160 var rawCallback func(SortableVarp uintptr, SortColumnIdVarp int, SortFuncVarp uintptr, UserDataVarp uintptr, DestroyVarp uintptr)
161 purego.RegisterFunc(&rawCallback, x.xSetSortFunc)
162 return func(SortableVar TreeSortable, SortColumnIdVar int, SortFuncVar *TreeIterCompareFunc, UserDataVar uintptr, DestroyVar *glib.DestroyNotify) {
163 rawCallback(SortableVar.GoPointer(), SortColumnIdVar, glib.NewCallback(SortFuncVar), UserDataVar, glib.NewCallbackNullable(DestroyVar))
164 }
165}
166
167// OverrideSetDefaultSortFunc sets the "set_default_sort_func" callback function.
168// Sets the default comparison function used
169//
170// when sorting to be sort_func.
171func (x *TreeSortableIface) OverrideSetDefaultSortFunc(cb func(TreeSortable, *TreeIterCompareFunc, uintptr, *glib.DestroyNotify)) {
172 if cb == nil {
173 x.xSetDefaultSortFunc = 0
174 } else {
175 x.xSetDefaultSortFunc = purego.NewCallback(func(SortableVarp uintptr, SortFuncVarp uintptr, UserDataVarp uintptr, DestroyVarp uintptr) {
176 cb(&TreeSortableBase{Ptr: SortableVarp}, (*TreeIterCompareFunc)(unsafe.Pointer(SortFuncVarp)), UserDataVarp, (*glib.DestroyNotify)(unsafe.Pointer(DestroyVarp)))
177 })
178 }
179}
180
181// GetSetDefaultSortFunc gets the "set_default_sort_func" callback function.
182// Sets the default comparison function used
183//
184// when sorting to be sort_func.
185func (x *TreeSortableIface) GetSetDefaultSortFunc() func(TreeSortable, *TreeIterCompareFunc, uintptr, *glib.DestroyNotify) {
186 if x.xSetDefaultSortFunc == 0 {
187 return nil
188 }
189 var rawCallback func(SortableVarp uintptr, SortFuncVarp uintptr, UserDataVarp uintptr, DestroyVarp uintptr)
190 purego.RegisterFunc(&rawCallback, x.xSetDefaultSortFunc)
191 return func(SortableVar TreeSortable, SortFuncVar *TreeIterCompareFunc, UserDataVar uintptr, DestroyVar *glib.DestroyNotify) {
192 rawCallback(SortableVar.GoPointer(), glib.NewCallback(SortFuncVar), UserDataVar, glib.NewCallbackNullable(DestroyVar))
193 }
194}
195
196// OverrideHasDefaultSortFunc sets the "has_default_sort_func" callback function.
197// %TRUE if the model has a default sort
198// function.
199func (x *TreeSortableIface) OverrideHasDefaultSortFunc(cb func(TreeSortable) bool) {
200 if cb == nil {
201 x.xHasDefaultSortFunc = 0
202 } else {
203 x.xHasDefaultSortFunc = purego.NewCallback(func(SortableVarp uintptr) bool {
204 return cb(&TreeSortableBase{Ptr: SortableVarp})
205 })
206 }
207}
208
209// GetHasDefaultSortFunc gets the "has_default_sort_func" callback function.
210// %TRUE if the model has a default sort
211// function.
212func (x *TreeSortableIface) GetHasDefaultSortFunc() func(TreeSortable) bool {
213 if x.xHasDefaultSortFunc == 0 {
214 return nil
215 }
216 var rawCallback func(SortableVarp uintptr) bool
217 purego.RegisterFunc(&rawCallback, x.xHasDefaultSortFunc)
218 return func(SortableVar TreeSortable) bool {
219 return rawCallback(SortableVar.GoPointer())
220 }
221}
222
223// The interface for sortable models used by GtkTreeView
224//
225// `GtkTreeSortable` is an interface to be implemented by tree models which
226// support sorting. The `GtkTreeView` uses the methods provided by this interface
227// to sort the model.
228type TreeSortable interface {
229 GoPointer() uintptr
230 SetGoPointer(uintptr)
231 GetSortColumnId(SortColumnIdVar *int, OrderVar *SortType) bool
232 HasDefaultSortFunc() bool
233 SetDefaultSortFunc(SortFuncVar *TreeIterCompareFunc, UserDataVar uintptr, DestroyVar *glib.DestroyNotify)
234 SetSortColumnId(SortColumnIdVar int, OrderVar SortType)
235 SetSortFunc(SortColumnIdVar int, SortFuncVar *TreeIterCompareFunc, UserDataVar uintptr, DestroyVar *glib.DestroyNotify)
236 SortColumnChanged()
237}
238
239var xTreeSortableGLibType func() types.GType
240
241func TreeSortableGLibType() types.GType {
242 return xTreeSortableGLibType()
243}
244
245type TreeSortableBase struct {
246 Ptr uintptr
247}
248
249func (x *TreeSortableBase) GoPointer() uintptr {
250 if x == nil {
251 return 0
252 }
253 return x.Ptr
254}
255
256func (x *TreeSortableBase) SetGoPointer(ptr uintptr) {
257 x.Ptr = ptr
258}
259
260// Fills in @sort_column_id and @order with the current sort column and the
261// order. It returns %TRUE unless the @sort_column_id is
262// %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID or
263// %GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID.
264func (x *TreeSortableBase) GetSortColumnId(SortColumnIdVar *int, OrderVar *SortType) bool {
265
266 cret := XGtkTreeSortableGetSortColumnId(x.GoPointer(), SortColumnIdVar, OrderVar)
267 return cret
268}
269
270// Returns %TRUE if the model has a default sort function. This is used
271// primarily by GtkTreeViewColumns in order to determine if a model can
272// go back to the default state, or not.
273func (x *TreeSortableBase) HasDefaultSortFunc() bool {
274
275 cret := XGtkTreeSortableHasDefaultSortFunc(x.GoPointer())
276 return cret
277}
278
279// Sets the default comparison function used when sorting to be @sort_func.
280// If the current sort column id of @sortable is
281// %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, then the model will sort using
282// this function.
283//
284// If @sort_func is %NULL, then there will be no default comparison function.
285// This means that once the model has been sorted, it can’t go back to the
286// default state. In this case, when the current sort column id of @sortable
287// is %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, the model will be unsorted.
288func (x *TreeSortableBase) SetDefaultSortFunc(SortFuncVar *TreeIterCompareFunc, UserDataVar uintptr, DestroyVar *glib.DestroyNotify) {
289
290 XGtkTreeSortableSetDefaultSortFunc(x.GoPointer(), glib.NewCallback(SortFuncVar), UserDataVar, glib.NewCallbackNullable(DestroyVar))
291
292}
293
294// Sets the current sort column to be @sort_column_id. The @sortable will
295// resort itself to reflect this change, after emitting a
296// `GtkTreeSortable::sort-column-changed` signal. @sort_column_id may either be
297// a regular column id, or one of the following special values:
298//
299// - %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID: the default sort function
300// will be used, if it is set
301//
302// - %GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID: no sorting will occur
303func (x *TreeSortableBase) SetSortColumnId(SortColumnIdVar int, OrderVar SortType) {
304
305 XGtkTreeSortableSetSortColumnId(x.GoPointer(), SortColumnIdVar, OrderVar)
306
307}
308
309// Sets the comparison function used when sorting to be @sort_func. If the
310// current sort column id of @sortable is the same as @sort_column_id, then
311// the model will sort using this function.
312func (x *TreeSortableBase) SetSortFunc(SortColumnIdVar int, SortFuncVar *TreeIterCompareFunc, UserDataVar uintptr, DestroyVar *glib.DestroyNotify) {
313
314 XGtkTreeSortableSetSortFunc(x.GoPointer(), SortColumnIdVar, glib.NewCallback(SortFuncVar), UserDataVar, glib.NewCallbackNullable(DestroyVar))
315
316}
317
318// Emits a `GtkTreeSortable::sort-column-changed` signal on @sortable.
319func (x *TreeSortableBase) SortColumnChanged() {
320
321 XGtkTreeSortableSortColumnChanged(x.GoPointer())
322
323}
324
325var XGtkTreeSortableGetSortColumnId func(uintptr, *int, *SortType) bool
326var XGtkTreeSortableHasDefaultSortFunc func(uintptr) bool
327var XGtkTreeSortableSetDefaultSortFunc func(uintptr, uintptr, uintptr, uintptr)
328var XGtkTreeSortableSetSortColumnId func(uintptr, int, SortType)
329var XGtkTreeSortableSetSortFunc func(uintptr, int, uintptr, uintptr, uintptr)
330var XGtkTreeSortableSortColumnChanged func(uintptr)
331
332const (
333 // Uses the default sort function in a [iface@Gtk.TreeSortable].
334 //
335 // See also: [method@Gtk.TreeSortable.set_sort_column_id]
336 TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID int = -1
337 // Disables sorting in a [iface@Gtk.TreeSortable].
338 //
339 // See also: [method@Gtk.TreeSortable.set_sort_column_id]
340 TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID int = -2
341)
342
343func init() {
344 core.SetPackageName("GTK", "gtk4")
345 core.SetSharedLibraries("GTK", []string{"libgtk-4.so.1"})
346 var libs []uintptr
347 for _, libPath := range core.GetPaths("GTK") {
348 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
349 if err != nil {
350 panic(err)
351 }
352 libs = append(libs, lib)
353 }
354
355 core.PuregoSafeRegister(&xTreeSortableGLibType, libs, "gtk_tree_sortable_get_type")
356
357 core.PuregoSafeRegister(&XGtkTreeSortableGetSortColumnId, libs, "gtk_tree_sortable_get_sort_column_id")
358 core.PuregoSafeRegister(&XGtkTreeSortableHasDefaultSortFunc, libs, "gtk_tree_sortable_has_default_sort_func")
359 core.PuregoSafeRegister(&XGtkTreeSortableSetDefaultSortFunc, libs, "gtk_tree_sortable_set_default_sort_func")
360 core.PuregoSafeRegister(&XGtkTreeSortableSetSortColumnId, libs, "gtk_tree_sortable_set_sort_column_id")
361 core.PuregoSafeRegister(&XGtkTreeSortableSetSortFunc, libs, "gtk_tree_sortable_set_sort_func")
362 core.PuregoSafeRegister(&XGtkTreeSortableSortColumnChanged, libs, "gtk_tree_sortable_sort_column_changed")
363
364}