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/gobject/types"
12)
13
14// The list of virtual functions for the `GtkSelectionModel` interface.
15// No function must be implemented, but unless `GtkSelectionModel::is_selected()`
16// is implemented, it will not be possible to select items in the set.
17//
18// The model does not need to implement any functions to support either
19// selecting or unselecting items. Of course, if the model does not do that,
20// it means that users cannot select or unselect items in a list widget
21// using the model.
22//
23// All selection functions fall back to `GtkSelectionModel::set_selection()`
24// so it is sufficient to implement just that function for full selection
25// support.
26type SelectionModelInterface struct {
27 _ structs.HostLayout
28
29 GIface uintptr
30
31 xIsSelected uintptr
32
33 xGetSelectionInRange uintptr
34
35 xSelectItem uintptr
36
37 xUnselectItem uintptr
38
39 xSelectRange uintptr
40
41 xUnselectRange uintptr
42
43 xSelectAll uintptr
44
45 xUnselectAll uintptr
46
47 xSetSelection uintptr
48}
49
50func (x *SelectionModelInterface) GoPointer() uintptr {
51 return uintptr(unsafe.Pointer(x))
52}
53
54// OverrideIsSelected sets the "is_selected" callback function.
55// Return if the item at the given position is selected.
56func (x *SelectionModelInterface) OverrideIsSelected(cb func(SelectionModel, uint) bool) {
57 if cb == nil {
58 x.xIsSelected = 0
59 } else {
60 x.xIsSelected = purego.NewCallback(func(ModelVarp uintptr, PositionVarp uint) bool {
61 return cb(&SelectionModelBase{Ptr: ModelVarp}, PositionVarp)
62 })
63 }
64}
65
66// GetIsSelected gets the "is_selected" callback function.
67// Return if the item at the given position is selected.
68func (x *SelectionModelInterface) GetIsSelected() func(SelectionModel, uint) bool {
69 if x.xIsSelected == 0 {
70 return nil
71 }
72 var rawCallback func(ModelVarp uintptr, PositionVarp uint) bool
73 purego.RegisterFunc(&rawCallback, x.xIsSelected)
74 return func(ModelVar SelectionModel, PositionVar uint) bool {
75 return rawCallback(ModelVar.GoPointer(), PositionVar)
76 }
77}
78
79// OverrideGetSelectionInRange sets the "get_selection_in_range" callback function.
80// Return a bitset with all currently selected
81//
82// items in the given range. By default, this function will call
83// `GtkSelectionModel::is_selected()` on all items in the given range.
84func (x *SelectionModelInterface) OverrideGetSelectionInRange(cb func(SelectionModel, uint, uint) *Bitset) {
85 if cb == nil {
86 x.xGetSelectionInRange = 0
87 } else {
88 x.xGetSelectionInRange = purego.NewCallback(func(ModelVarp uintptr, PositionVarp uint, NItemsVarp uint) *Bitset {
89 return cb(&SelectionModelBase{Ptr: ModelVarp}, PositionVarp, NItemsVarp)
90 })
91 }
92}
93
94// GetGetSelectionInRange gets the "get_selection_in_range" callback function.
95// Return a bitset with all currently selected
96//
97// items in the given range. By default, this function will call
98// `GtkSelectionModel::is_selected()` on all items in the given range.
99func (x *SelectionModelInterface) GetGetSelectionInRange() func(SelectionModel, uint, uint) *Bitset {
100 if x.xGetSelectionInRange == 0 {
101 return nil
102 }
103 var rawCallback func(ModelVarp uintptr, PositionVarp uint, NItemsVarp uint) *Bitset
104 purego.RegisterFunc(&rawCallback, x.xGetSelectionInRange)
105 return func(ModelVar SelectionModel, PositionVar uint, NItemsVar uint) *Bitset {
106 return rawCallback(ModelVar.GoPointer(), PositionVar, NItemsVar)
107 }
108}
109
110// OverrideSelectItem sets the "select_item" callback function.
111// Select the item in the given position. If the operation
112//
113// is known to fail, return %FALSE.
114func (x *SelectionModelInterface) OverrideSelectItem(cb func(SelectionModel, uint, bool) bool) {
115 if cb == nil {
116 x.xSelectItem = 0
117 } else {
118 x.xSelectItem = purego.NewCallback(func(ModelVarp uintptr, PositionVarp uint, UnselectRestVarp bool) bool {
119 return cb(&SelectionModelBase{Ptr: ModelVarp}, PositionVarp, UnselectRestVarp)
120 })
121 }
122}
123
124// GetSelectItem gets the "select_item" callback function.
125// Select the item in the given position. If the operation
126//
127// is known to fail, return %FALSE.
128func (x *SelectionModelInterface) GetSelectItem() func(SelectionModel, uint, bool) bool {
129 if x.xSelectItem == 0 {
130 return nil
131 }
132 var rawCallback func(ModelVarp uintptr, PositionVarp uint, UnselectRestVarp bool) bool
133 purego.RegisterFunc(&rawCallback, x.xSelectItem)
134 return func(ModelVar SelectionModel, PositionVar uint, UnselectRestVar bool) bool {
135 return rawCallback(ModelVar.GoPointer(), PositionVar, UnselectRestVar)
136 }
137}
138
139// OverrideUnselectItem sets the "unselect_item" callback function.
140// Unselect the item in the given position. If the
141//
142// operation is known to fail, return %FALSE.
143func (x *SelectionModelInterface) OverrideUnselectItem(cb func(SelectionModel, uint) bool) {
144 if cb == nil {
145 x.xUnselectItem = 0
146 } else {
147 x.xUnselectItem = purego.NewCallback(func(ModelVarp uintptr, PositionVarp uint) bool {
148 return cb(&SelectionModelBase{Ptr: ModelVarp}, PositionVarp)
149 })
150 }
151}
152
153// GetUnselectItem gets the "unselect_item" callback function.
154// Unselect the item in the given position. If the
155//
156// operation is known to fail, return %FALSE.
157func (x *SelectionModelInterface) GetUnselectItem() func(SelectionModel, uint) bool {
158 if x.xUnselectItem == 0 {
159 return nil
160 }
161 var rawCallback func(ModelVarp uintptr, PositionVarp uint) bool
162 purego.RegisterFunc(&rawCallback, x.xUnselectItem)
163 return func(ModelVar SelectionModel, PositionVar uint) bool {
164 return rawCallback(ModelVar.GoPointer(), PositionVar)
165 }
166}
167
168// OverrideSelectRange sets the "select_range" callback function.
169// Select all items in the given range. If the operation
170//
171// is unsupported or known to fail for all items, return %FALSE.
172func (x *SelectionModelInterface) OverrideSelectRange(cb func(SelectionModel, uint, uint, bool) bool) {
173 if cb == nil {
174 x.xSelectRange = 0
175 } else {
176 x.xSelectRange = purego.NewCallback(func(ModelVarp uintptr, PositionVarp uint, NItemsVarp uint, UnselectRestVarp bool) bool {
177 return cb(&SelectionModelBase{Ptr: ModelVarp}, PositionVarp, NItemsVarp, UnselectRestVarp)
178 })
179 }
180}
181
182// GetSelectRange gets the "select_range" callback function.
183// Select all items in the given range. If the operation
184//
185// is unsupported or known to fail for all items, return %FALSE.
186func (x *SelectionModelInterface) GetSelectRange() func(SelectionModel, uint, uint, bool) bool {
187 if x.xSelectRange == 0 {
188 return nil
189 }
190 var rawCallback func(ModelVarp uintptr, PositionVarp uint, NItemsVarp uint, UnselectRestVarp bool) bool
191 purego.RegisterFunc(&rawCallback, x.xSelectRange)
192 return func(ModelVar SelectionModel, PositionVar uint, NItemsVar uint, UnselectRestVar bool) bool {
193 return rawCallback(ModelVar.GoPointer(), PositionVar, NItemsVar, UnselectRestVar)
194 }
195}
196
197// OverrideUnselectRange sets the "unselect_range" callback function.
198// Unselect all items in the given range. If the
199//
200// operation is unsupported or known to fail for all items, return
201// %FALSE.
202func (x *SelectionModelInterface) OverrideUnselectRange(cb func(SelectionModel, uint, uint) bool) {
203 if cb == nil {
204 x.xUnselectRange = 0
205 } else {
206 x.xUnselectRange = purego.NewCallback(func(ModelVarp uintptr, PositionVarp uint, NItemsVarp uint) bool {
207 return cb(&SelectionModelBase{Ptr: ModelVarp}, PositionVarp, NItemsVarp)
208 })
209 }
210}
211
212// GetUnselectRange gets the "unselect_range" callback function.
213// Unselect all items in the given range. If the
214//
215// operation is unsupported or known to fail for all items, return
216// %FALSE.
217func (x *SelectionModelInterface) GetUnselectRange() func(SelectionModel, uint, uint) bool {
218 if x.xUnselectRange == 0 {
219 return nil
220 }
221 var rawCallback func(ModelVarp uintptr, PositionVarp uint, NItemsVarp uint) bool
222 purego.RegisterFunc(&rawCallback, x.xUnselectRange)
223 return func(ModelVar SelectionModel, PositionVar uint, NItemsVar uint) bool {
224 return rawCallback(ModelVar.GoPointer(), PositionVar, NItemsVar)
225 }
226}
227
228// OverrideSelectAll sets the "select_all" callback function.
229// Select all items in the model. If the operation is
230//
231// unsupported or known to fail for all items, return %FALSE.
232func (x *SelectionModelInterface) OverrideSelectAll(cb func(SelectionModel) bool) {
233 if cb == nil {
234 x.xSelectAll = 0
235 } else {
236 x.xSelectAll = purego.NewCallback(func(ModelVarp uintptr) bool {
237 return cb(&SelectionModelBase{Ptr: ModelVarp})
238 })
239 }
240}
241
242// GetSelectAll gets the "select_all" callback function.
243// Select all items in the model. If the operation is
244//
245// unsupported or known to fail for all items, return %FALSE.
246func (x *SelectionModelInterface) GetSelectAll() func(SelectionModel) bool {
247 if x.xSelectAll == 0 {
248 return nil
249 }
250 var rawCallback func(ModelVarp uintptr) bool
251 purego.RegisterFunc(&rawCallback, x.xSelectAll)
252 return func(ModelVar SelectionModel) bool {
253 return rawCallback(ModelVar.GoPointer())
254 }
255}
256
257// OverrideUnselectAll sets the "unselect_all" callback function.
258// Unselect all items in the model. If the operation is
259//
260// unsupported or known to fail for all items, return %FALSE.
261func (x *SelectionModelInterface) OverrideUnselectAll(cb func(SelectionModel) bool) {
262 if cb == nil {
263 x.xUnselectAll = 0
264 } else {
265 x.xUnselectAll = purego.NewCallback(func(ModelVarp uintptr) bool {
266 return cb(&SelectionModelBase{Ptr: ModelVarp})
267 })
268 }
269}
270
271// GetUnselectAll gets the "unselect_all" callback function.
272// Unselect all items in the model. If the operation is
273//
274// unsupported or known to fail for all items, return %FALSE.
275func (x *SelectionModelInterface) GetUnselectAll() func(SelectionModel) bool {
276 if x.xUnselectAll == 0 {
277 return nil
278 }
279 var rawCallback func(ModelVarp uintptr) bool
280 purego.RegisterFunc(&rawCallback, x.xUnselectAll)
281 return func(ModelVar SelectionModel) bool {
282 return rawCallback(ModelVar.GoPointer())
283 }
284}
285
286// OverrideSetSelection sets the "set_selection" callback function.
287// Set selection state of all items in mask to selected.
288//
289// See gtk_selection_model_set_selection() for a detailed explanation
290// of this function.
291func (x *SelectionModelInterface) OverrideSetSelection(cb func(SelectionModel, *Bitset, *Bitset) bool) {
292 if cb == nil {
293 x.xSetSelection = 0
294 } else {
295 x.xSetSelection = purego.NewCallback(func(ModelVarp uintptr, SelectedVarp *Bitset, MaskVarp *Bitset) bool {
296 return cb(&SelectionModelBase{Ptr: ModelVarp}, SelectedVarp, MaskVarp)
297 })
298 }
299}
300
301// GetSetSelection gets the "set_selection" callback function.
302// Set selection state of all items in mask to selected.
303//
304// See gtk_selection_model_set_selection() for a detailed explanation
305// of this function.
306func (x *SelectionModelInterface) GetSetSelection() func(SelectionModel, *Bitset, *Bitset) bool {
307 if x.xSetSelection == 0 {
308 return nil
309 }
310 var rawCallback func(ModelVarp uintptr, SelectedVarp *Bitset, MaskVarp *Bitset) bool
311 purego.RegisterFunc(&rawCallback, x.xSetSelection)
312 return func(ModelVar SelectionModel, SelectedVar *Bitset, MaskVar *Bitset) bool {
313 return rawCallback(ModelVar.GoPointer(), SelectedVar, MaskVar)
314 }
315}
316
317// An interface that adds support for selection to list models.
318//
319// This support is then used by widgets using list models to add the ability
320// to select and unselect various items.
321//
322// GTK provides default implementations of the most common selection modes such
323// as [class@Gtk.SingleSelection], so you will only need to implement this
324// interface if you want detailed control about how selections should be handled.
325//
326// A `GtkSelectionModel` supports a single boolean per item indicating if an item is
327// selected or not. This can be queried via [method@Gtk.SelectionModel.is_selected].
328// When the selected state of one or more items changes, the model will emit the
329// [signal@Gtk.SelectionModel::selection-changed] signal by calling the
330// [method@Gtk.SelectionModel.selection_changed] function. The positions given
331// in that signal may have their selection state changed, though that is not a
332// requirement. If new items added to the model via the
333// [signal@Gio.ListModel::items-changed] signal are selected or not is up to the
334// implementation.
335//
336// Note that items added via [signal@Gio.ListModel::items-changed] may already
337// be selected and no [signal@Gtk.SelectionModel::selection-changed] will be
338// emitted for them. So to track which items are selected, it is necessary to
339// listen to both signals.
340//
341// Additionally, the interface can expose functionality to select and unselect
342// items. If these functions are implemented, GTK's list widgets will allow users
343// to select and unselect items. However, `GtkSelectionModel`s are free to only
344// implement them partially or not at all. In that case the widgets will not
345// support the unimplemented operations.
346//
347// When selecting or unselecting is supported by a model, the return values of
348// the selection functions do *not* indicate if selection or unselection happened.
349// They are only meant to indicate complete failure, like when this mode of
350// selecting is not supported by the model.
351//
352// Selections may happen asynchronously, so the only reliable way to find out
353// when an item was selected is to listen to the signals that indicate selection.
354type SelectionModel interface {
355 GoPointer() uintptr
356 SetGoPointer(uintptr)
357 GetSelection() *Bitset
358 GetSelectionInRange(PositionVar uint, NItemsVar uint) *Bitset
359 IsSelected(PositionVar uint) bool
360 SelectAll() bool
361 SelectItem(PositionVar uint, UnselectRestVar bool) bool
362 SelectRange(PositionVar uint, NItemsVar uint, UnselectRestVar bool) bool
363 SelectionChanged(PositionVar uint, NItemsVar uint)
364 SetSelection(SelectedVar *Bitset, MaskVar *Bitset) bool
365 UnselectAll() bool
366 UnselectItem(PositionVar uint) bool
367 UnselectRange(PositionVar uint, NItemsVar uint) bool
368}
369
370var xSelectionModelGLibType func() types.GType
371
372func SelectionModelGLibType() types.GType {
373 return xSelectionModelGLibType()
374}
375
376type SelectionModelBase struct {
377 Ptr uintptr
378}
379
380func (x *SelectionModelBase) GoPointer() uintptr {
381 if x == nil {
382 return 0
383 }
384 return x.Ptr
385}
386
387func (x *SelectionModelBase) SetGoPointer(ptr uintptr) {
388 x.Ptr = ptr
389}
390
391// Gets the set containing all currently selected items in the model.
392//
393// This function may be slow, so if you are only interested in single item,
394// consider using [method@Gtk.SelectionModel.is_selected] or if you are only
395// interested in a few, consider [method@Gtk.SelectionModel.get_selection_in_range].
396func (x *SelectionModelBase) GetSelection() *Bitset {
397
398 cret := XGtkSelectionModelGetSelection(x.GoPointer())
399 return cret
400}
401
402// Gets the set of selected items in a range.
403//
404// This function is an optimization for
405// [method@Gtk.SelectionModel.get_selection] when you are only
406// interested in part of the model's selected state. A common use
407// case is in response to the [signal@Gtk.SelectionModel::selection-changed]
408// signal.
409func (x *SelectionModelBase) GetSelectionInRange(PositionVar uint, NItemsVar uint) *Bitset {
410
411 cret := XGtkSelectionModelGetSelectionInRange(x.GoPointer(), PositionVar, NItemsVar)
412 return cret
413}
414
415// Checks if the given item is selected.
416func (x *SelectionModelBase) IsSelected(PositionVar uint) bool {
417
418 cret := XGtkSelectionModelIsSelected(x.GoPointer(), PositionVar)
419 return cret
420}
421
422// Requests to select all items in the model.
423func (x *SelectionModelBase) SelectAll() bool {
424
425 cret := XGtkSelectionModelSelectAll(x.GoPointer())
426 return cret
427}
428
429// Requests to select an item in the model.
430func (x *SelectionModelBase) SelectItem(PositionVar uint, UnselectRestVar bool) bool {
431
432 cret := XGtkSelectionModelSelectItem(x.GoPointer(), PositionVar, UnselectRestVar)
433 return cret
434}
435
436// Requests to select a range of items in the model.
437func (x *SelectionModelBase) SelectRange(PositionVar uint, NItemsVar uint, UnselectRestVar bool) bool {
438
439 cret := XGtkSelectionModelSelectRange(x.GoPointer(), PositionVar, NItemsVar, UnselectRestVar)
440 return cret
441}
442
443// Helper function for implementations of `GtkSelectionModel`.
444//
445// Call this when the selection changes to emit the
446// [signal@Gtk.SelectionModel::selection-changed] signal.
447func (x *SelectionModelBase) SelectionChanged(PositionVar uint, NItemsVar uint) {
448
449 XGtkSelectionModelSelectionChanged(x.GoPointer(), PositionVar, NItemsVar)
450
451}
452
453// Make selection changes.
454//
455// This is the most advanced selection updating method that allows
456// the most fine-grained control over selection changes. If you can,
457// you should try the simpler versions, as implementations are more
458// likely to implement support for those.
459//
460// Requests that the selection state of all positions set in @mask
461// be updated to the respective value in the @selected bitmask.
462//
463// In pseudocode, it would look something like this:
464//
465// ```c
466// for (i = 0; i < n_items; i++)
467//
468// {
469// // don't change values not in the mask
470// if (!gtk_bitset_contains (mask, i))
471// continue;
472//
473// if (gtk_bitset_contains (selected, i))
474// select_item (i);
475// else
476// unselect_item (i);
477// }
478//
479// gtk_selection_model_selection_changed (model,
480//
481// first_changed_item,
482// n_changed_items);
483//
484// ```
485//
486// @mask and @selected must not be modified. They may refer to the
487// same bitset, which would mean that every item in the set should
488// be selected.
489func (x *SelectionModelBase) SetSelection(SelectedVar *Bitset, MaskVar *Bitset) bool {
490
491 cret := XGtkSelectionModelSetSelection(x.GoPointer(), SelectedVar, MaskVar)
492 return cret
493}
494
495// Requests to unselect all items in the model.
496func (x *SelectionModelBase) UnselectAll() bool {
497
498 cret := XGtkSelectionModelUnselectAll(x.GoPointer())
499 return cret
500}
501
502// Requests to unselect an item in the model.
503func (x *SelectionModelBase) UnselectItem(PositionVar uint) bool {
504
505 cret := XGtkSelectionModelUnselectItem(x.GoPointer(), PositionVar)
506 return cret
507}
508
509// Requests to unselect a range of items in the model.
510func (x *SelectionModelBase) UnselectRange(PositionVar uint, NItemsVar uint) bool {
511
512 cret := XGtkSelectionModelUnselectRange(x.GoPointer(), PositionVar, NItemsVar)
513 return cret
514}
515
516var XGtkSelectionModelGetSelection func(uintptr) *Bitset
517var XGtkSelectionModelGetSelectionInRange func(uintptr, uint, uint) *Bitset
518var XGtkSelectionModelIsSelected func(uintptr, uint) bool
519var XGtkSelectionModelSelectAll func(uintptr) bool
520var XGtkSelectionModelSelectItem func(uintptr, uint, bool) bool
521var XGtkSelectionModelSelectRange func(uintptr, uint, uint, bool) bool
522var XGtkSelectionModelSelectionChanged func(uintptr, uint, uint)
523var XGtkSelectionModelSetSelection func(uintptr, *Bitset, *Bitset) bool
524var XGtkSelectionModelUnselectAll func(uintptr) bool
525var XGtkSelectionModelUnselectItem func(uintptr, uint) bool
526var XGtkSelectionModelUnselectRange func(uintptr, uint, uint) bool
527
528func init() {
529 core.SetPackageName("GTK", "gtk4")
530 core.SetSharedLibraries("GTK", []string{"libgtk-4.so.1"})
531 var libs []uintptr
532 for _, libPath := range core.GetPaths("GTK") {
533 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
534 if err != nil {
535 panic(err)
536 }
537 libs = append(libs, lib)
538 }
539
540 core.PuregoSafeRegister(&xSelectionModelGLibType, libs, "gtk_selection_model_get_type")
541
542 core.PuregoSafeRegister(&XGtkSelectionModelGetSelection, libs, "gtk_selection_model_get_selection")
543 core.PuregoSafeRegister(&XGtkSelectionModelGetSelectionInRange, libs, "gtk_selection_model_get_selection_in_range")
544 core.PuregoSafeRegister(&XGtkSelectionModelIsSelected, libs, "gtk_selection_model_is_selected")
545 core.PuregoSafeRegister(&XGtkSelectionModelSelectAll, libs, "gtk_selection_model_select_all")
546 core.PuregoSafeRegister(&XGtkSelectionModelSelectItem, libs, "gtk_selection_model_select_item")
547 core.PuregoSafeRegister(&XGtkSelectionModelSelectRange, libs, "gtk_selection_model_select_range")
548 core.PuregoSafeRegister(&XGtkSelectionModelSelectionChanged, libs, "gtk_selection_model_selection_changed")
549 core.PuregoSafeRegister(&XGtkSelectionModelSetSelection, libs, "gtk_selection_model_set_selection")
550 core.PuregoSafeRegister(&XGtkSelectionModelUnselectAll, libs, "gtk_selection_model_unselect_all")
551 core.PuregoSafeRegister(&XGtkSelectionModelUnselectItem, libs, "gtk_selection_model_unselect_item")
552 core.PuregoSafeRegister(&XGtkSelectionModelUnselectRange, libs, "gtk_selection_model_unselect_range")
553
554}