1// Package gtk was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gtk
3
4import (
5 "unsafe"
6
7 "github.com/ebitengine/purego"
8
9 "github.com/bnema/puregotk/pkg/core"
10 "github.com/bnema/puregotk/v4/glib"
11 "github.com/bnema/puregotk/v4/gobject"
12 "github.com/bnema/puregotk/v4/gobject/types"
13)
14
15// A function used by gtk_tree_selection_selected_foreach() to map all
16// selected rows. It will be called on every selected row in the view.
17type TreeSelectionForeachFunc func(uintptr, *TreePath, *TreeIter, uintptr)
18
19// A function used by gtk_tree_selection_set_select_function() to filter
20// whether or not a row may be selected. It is called whenever a row's
21// state might change.
22//
23// A return value of %TRUE indicates to @selection that it is okay to
24// change the selection.
25type TreeSelectionFunc func(uintptr, uintptr, *TreePath, bool, uintptr) bool
26
27// The selection object for GtkTreeView
28//
29// The `GtkTreeSelection` object is a helper object to manage the selection
30// for a `GtkTreeView` widget. The `GtkTreeSelection` object is
31// automatically created when a new `GtkTreeView` widget is created, and
32// cannot exist independently of this widget. The primary reason the
33// `GtkTreeSelection` objects exists is for cleanliness of code and API.
34// That is, there is no conceptual reason all these functions could not be
35// methods on the `GtkTreeView` widget instead of a separate function.
36//
37// The `GtkTreeSelection` object is gotten from a `GtkTreeView` by calling
38// gtk_tree_view_get_selection(). It can be manipulated to check the
39// selection status of the tree, as well as select and deselect individual
40// rows. Selection is done completely view side. As a result, multiple
41// views of the same model can have completely different selections.
42// Additionally, you cannot change the selection of a row on the model that
43// is not currently displayed by the view without expanding its parents
44// first.
45//
46// One of the important things to remember when monitoring the selection of
47// a view is that the `GtkTreeSelection`::changed signal is mostly a hint.
48// That is, it may only emit one signal when a range of rows is selected.
49// Additionally, it may on occasion emit a `GtkTreeSelection`::changed signal
50// when nothing has happened (mostly as a result of programmers calling
51// select_row on an already selected row).
52type TreeSelection struct {
53 gobject.Object
54}
55
56var xTreeSelectionGLibType func() types.GType
57
58func TreeSelectionGLibType() types.GType {
59 return xTreeSelectionGLibType()
60}
61
62func TreeSelectionNewFromInternalPtr(ptr uintptr) *TreeSelection {
63 cls := &TreeSelection{}
64 cls.Ptr = ptr
65 return cls
66}
67
68var xTreeSelectionCountSelectedRows func(uintptr) int
69
70// Returns the number of rows that have been selected in @tree.
71func (x *TreeSelection) CountSelectedRows() int {
72
73 cret := xTreeSelectionCountSelectedRows(x.GoPointer())
74 return cret
75}
76
77var xTreeSelectionGetMode func(uintptr) SelectionMode
78
79// Gets the selection mode for @selection. See
80// gtk_tree_selection_set_mode().
81func (x *TreeSelection) GetMode() SelectionMode {
82
83 cret := xTreeSelectionGetMode(x.GoPointer())
84 return cret
85}
86
87var xTreeSelectionGetSelectFunction func(uintptr) uintptr
88
89// Returns the current selection function.
90func (x *TreeSelection) GetSelectFunction() uintptr {
91
92 cret := xTreeSelectionGetSelectFunction(x.GoPointer())
93 return cret
94}
95
96var xTreeSelectionGetSelected func(uintptr, **TreeModel, *TreeIter) bool
97
98// Sets @iter to the currently selected node if @selection is set to
99// %GTK_SELECTION_SINGLE or %GTK_SELECTION_BROWSE. @iter may be NULL if you
100// just want to test if @selection has any selected nodes. @model is filled
101// with the current model as a convenience. This function will not work if you
102// use @selection is %GTK_SELECTION_MULTIPLE.
103func (x *TreeSelection) GetSelected(ModelVar **TreeModel, IterVar *TreeIter) bool {
104
105 cret := xTreeSelectionGetSelected(x.GoPointer(), ModelVar, IterVar)
106 return cret
107}
108
109var xTreeSelectionGetSelectedRows func(uintptr, **TreeModel) *glib.List
110
111// Creates a list of path of all selected rows. Additionally, if you are
112// planning on modifying the model after calling this function, you may
113// want to convert the returned list into a list of `GtkTreeRowReference`s.
114// To do this, you can use gtk_tree_row_reference_new().
115//
116// To free the return value, use:
117//
118// ```c
119// g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);
120// ```
121func (x *TreeSelection) GetSelectedRows(ModelVar **TreeModel) *glib.List {
122
123 cret := xTreeSelectionGetSelectedRows(x.GoPointer(), ModelVar)
124 return cret
125}
126
127var xTreeSelectionGetTreeView func(uintptr) uintptr
128
129// Returns the tree view associated with @selection.
130func (x *TreeSelection) GetTreeView() *TreeView {
131 var cls *TreeView
132
133 cret := xTreeSelectionGetTreeView(x.GoPointer())
134
135 if cret == 0 {
136 return nil
137 }
138 gobject.IncreaseRef(cret)
139 cls = &TreeView{}
140 cls.Ptr = cret
141 return cls
142}
143
144var xTreeSelectionGetUserData func(uintptr) uintptr
145
146// Returns the user data for the selection function.
147func (x *TreeSelection) GetUserData() uintptr {
148
149 cret := xTreeSelectionGetUserData(x.GoPointer())
150 return cret
151}
152
153var xTreeSelectionIterIsSelected func(uintptr, *TreeIter) bool
154
155// Returns %TRUE if the row at @iter is currently selected.
156func (x *TreeSelection) IterIsSelected(IterVar *TreeIter) bool {
157
158 cret := xTreeSelectionIterIsSelected(x.GoPointer(), IterVar)
159 return cret
160}
161
162var xTreeSelectionPathIsSelected func(uintptr, *TreePath) bool
163
164// Returns %TRUE if the row pointed to by @path is currently selected. If @path
165// does not point to a valid location, %FALSE is returned
166func (x *TreeSelection) PathIsSelected(PathVar *TreePath) bool {
167
168 cret := xTreeSelectionPathIsSelected(x.GoPointer(), PathVar)
169 return cret
170}
171
172var xTreeSelectionSelectAll func(uintptr)
173
174// Selects all the nodes. @selection must be set to %GTK_SELECTION_MULTIPLE
175// mode.
176func (x *TreeSelection) SelectAll() {
177
178 xTreeSelectionSelectAll(x.GoPointer())
179
180}
181
182var xTreeSelectionSelectIter func(uintptr, *TreeIter)
183
184// Selects the specified iterator.
185func (x *TreeSelection) SelectIter(IterVar *TreeIter) {
186
187 xTreeSelectionSelectIter(x.GoPointer(), IterVar)
188
189}
190
191var xTreeSelectionSelectPath func(uintptr, *TreePath)
192
193// Select the row at @path.
194func (x *TreeSelection) SelectPath(PathVar *TreePath) {
195
196 xTreeSelectionSelectPath(x.GoPointer(), PathVar)
197
198}
199
200var xTreeSelectionSelectRange func(uintptr, *TreePath, *TreePath)
201
202// Selects a range of nodes, determined by @start_path and @end_path inclusive.
203// @selection must be set to %GTK_SELECTION_MULTIPLE mode.
204func (x *TreeSelection) SelectRange(StartPathVar *TreePath, EndPathVar *TreePath) {
205
206 xTreeSelectionSelectRange(x.GoPointer(), StartPathVar, EndPathVar)
207
208}
209
210var xTreeSelectionSelectedForeach func(uintptr, uintptr, uintptr)
211
212// Calls a function for each selected node. Note that you cannot modify
213// the tree or selection from within this function. As a result,
214// gtk_tree_selection_get_selected_rows() might be more useful.
215func (x *TreeSelection) SelectedForeach(FuncVar *TreeSelectionForeachFunc, DataVar uintptr) {
216
217 var FuncVarRef uintptr
218 if FuncVar != nil {
219 FuncVarPtr := uintptr(unsafe.Pointer(FuncVar))
220 if cbRefPtr, ok := glib.GetCallback(FuncVarPtr); ok {
221 FuncVarRef = cbRefPtr
222 } else {
223 fcb := func(arg0 uintptr, arg1 *TreePath, arg2 *TreeIter, arg3 uintptr) {
224 cbFn := *FuncVar
225 cbFn(arg0, arg1, arg2, arg3)
226 }
227 FuncVarRef = purego.NewCallback(fcb)
228 glib.SaveCallbackWithClosure(FuncVarPtr, FuncVarRef, FuncVar)
229 }
230 }
231
232 xTreeSelectionSelectedForeach(x.GoPointer(), FuncVarRef, DataVar)
233
234}
235
236var xTreeSelectionSetMode func(uintptr, SelectionMode)
237
238// Sets the selection mode of the @selection. If the previous type was
239// %GTK_SELECTION_MULTIPLE, then the anchor is kept selected, if it was
240// previously selected.
241func (x *TreeSelection) SetMode(TypeVar SelectionMode) {
242
243 xTreeSelectionSetMode(x.GoPointer(), TypeVar)
244
245}
246
247var xTreeSelectionSetSelectFunction func(uintptr, uintptr, uintptr, uintptr)
248
249// Sets the selection function.
250//
251// If set, this function is called before any node is selected or unselected,
252// giving some control over which nodes are selected. The select function
253// should return %TRUE if the state of the node may be toggled, and %FALSE
254// if the state of the node should be left unchanged.
255func (x *TreeSelection) SetSelectFunction(FuncVar *TreeSelectionFunc, DataVar uintptr, DestroyVar *glib.DestroyNotify) {
256
257 var FuncVarRef uintptr
258 if FuncVar != nil {
259 FuncVarPtr := uintptr(unsafe.Pointer(FuncVar))
260 if cbRefPtr, ok := glib.GetCallback(FuncVarPtr); ok {
261 FuncVarRef = cbRefPtr
262 } else {
263 fcb := func(arg0 uintptr, arg1 uintptr, arg2 *TreePath, arg3 bool, arg4 uintptr) bool {
264 cbFn := *FuncVar
265 return cbFn(arg0, arg1, arg2, arg3, arg4)
266 }
267 FuncVarRef = purego.NewCallback(fcb)
268 glib.SaveCallbackWithClosure(FuncVarPtr, FuncVarRef, FuncVar)
269 }
270 }
271
272 var DestroyVarRef uintptr
273 if DestroyVar != nil {
274 DestroyVarPtr := uintptr(unsafe.Pointer(DestroyVar))
275 if cbRefPtr, ok := glib.GetCallback(DestroyVarPtr); ok {
276 DestroyVarRef = cbRefPtr
277 } else {
278 fcb := func(arg0 uintptr) {
279 cbFn := *DestroyVar
280 cbFn(arg0)
281 }
282 DestroyVarRef = purego.NewCallback(fcb)
283 glib.SaveCallbackWithClosure(DestroyVarPtr, DestroyVarRef, DestroyVar)
284 }
285 }
286
287 xTreeSelectionSetSelectFunction(x.GoPointer(), FuncVarRef, DataVar, DestroyVarRef)
288
289}
290
291var xTreeSelectionUnselectAll func(uintptr)
292
293// Unselects all the nodes.
294func (x *TreeSelection) UnselectAll() {
295
296 xTreeSelectionUnselectAll(x.GoPointer())
297
298}
299
300var xTreeSelectionUnselectIter func(uintptr, *TreeIter)
301
302// Unselects the specified iterator.
303func (x *TreeSelection) UnselectIter(IterVar *TreeIter) {
304
305 xTreeSelectionUnselectIter(x.GoPointer(), IterVar)
306
307}
308
309var xTreeSelectionUnselectPath func(uintptr, *TreePath)
310
311// Unselects the row at @path.
312func (x *TreeSelection) UnselectPath(PathVar *TreePath) {
313
314 xTreeSelectionUnselectPath(x.GoPointer(), PathVar)
315
316}
317
318var xTreeSelectionUnselectRange func(uintptr, *TreePath, *TreePath)
319
320// Unselects a range of nodes, determined by @start_path and @end_path
321// inclusive.
322func (x *TreeSelection) UnselectRange(StartPathVar *TreePath, EndPathVar *TreePath) {
323
324 xTreeSelectionUnselectRange(x.GoPointer(), StartPathVar, EndPathVar)
325
326}
327
328func (c *TreeSelection) GoPointer() uintptr {
329 if c == nil {
330 return 0
331 }
332 return c.Ptr
333}
334
335func (c *TreeSelection) SetGoPointer(ptr uintptr) {
336 c.Ptr = ptr
337}
338
339// Emitted whenever the selection has (possibly) changed. Please note that
340// this signal is mostly a hint. It may only be emitted once when a range
341// of rows are selected, and it may occasionally be emitted when nothing
342// has happened.
343func (x *TreeSelection) ConnectChanged(cb *func(TreeSelection)) uint {
344 cbPtr := uintptr(unsafe.Pointer(cb))
345 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
346 handlerID := gobject.SignalConnect(x.GoPointer(), "changed", cbRefPtr)
347 glib.SaveHandlerMapping(handlerID, cbPtr)
348 return handlerID
349 }
350
351 fcb := func(clsPtr uintptr) {
352 fa := TreeSelection{}
353 fa.Ptr = clsPtr
354 cbFn := *cb
355
356 cbFn(fa)
357
358 }
359 cbRefPtr := purego.NewCallback(fcb)
360 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
361 handlerID := gobject.SignalConnect(x.GoPointer(), "changed", cbRefPtr)
362 glib.SaveHandlerMapping(handlerID, cbPtr)
363 return handlerID
364}
365
366func init() {
367 core.SetPackageName("GTK", "gtk4")
368 core.SetSharedLibraries("GTK", []string{"libgtk-4.so.1"})
369 var libs []uintptr
370 for _, libPath := range core.GetPaths("GTK") {
371 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
372 if err != nil {
373 panic(err)
374 }
375 libs = append(libs, lib)
376 }
377
378 core.PuregoSafeRegister(&xTreeSelectionGLibType, libs, "gtk_tree_selection_get_type")
379
380 core.PuregoSafeRegister(&xTreeSelectionCountSelectedRows, libs, "gtk_tree_selection_count_selected_rows")
381 core.PuregoSafeRegister(&xTreeSelectionGetMode, libs, "gtk_tree_selection_get_mode")
382 core.PuregoSafeRegister(&xTreeSelectionGetSelectFunction, libs, "gtk_tree_selection_get_select_function")
383 core.PuregoSafeRegister(&xTreeSelectionGetSelected, libs, "gtk_tree_selection_get_selected")
384 core.PuregoSafeRegister(&xTreeSelectionGetSelectedRows, libs, "gtk_tree_selection_get_selected_rows")
385 core.PuregoSafeRegister(&xTreeSelectionGetTreeView, libs, "gtk_tree_selection_get_tree_view")
386 core.PuregoSafeRegister(&xTreeSelectionGetUserData, libs, "gtk_tree_selection_get_user_data")
387 core.PuregoSafeRegister(&xTreeSelectionIterIsSelected, libs, "gtk_tree_selection_iter_is_selected")
388 core.PuregoSafeRegister(&xTreeSelectionPathIsSelected, libs, "gtk_tree_selection_path_is_selected")
389 core.PuregoSafeRegister(&xTreeSelectionSelectAll, libs, "gtk_tree_selection_select_all")
390 core.PuregoSafeRegister(&xTreeSelectionSelectIter, libs, "gtk_tree_selection_select_iter")
391 core.PuregoSafeRegister(&xTreeSelectionSelectPath, libs, "gtk_tree_selection_select_path")
392 core.PuregoSafeRegister(&xTreeSelectionSelectRange, libs, "gtk_tree_selection_select_range")
393 core.PuregoSafeRegister(&xTreeSelectionSelectedForeach, libs, "gtk_tree_selection_selected_foreach")
394 core.PuregoSafeRegister(&xTreeSelectionSetMode, libs, "gtk_tree_selection_set_mode")
395 core.PuregoSafeRegister(&xTreeSelectionSetSelectFunction, libs, "gtk_tree_selection_set_select_function")
396 core.PuregoSafeRegister(&xTreeSelectionUnselectAll, libs, "gtk_tree_selection_unselect_all")
397 core.PuregoSafeRegister(&xTreeSelectionUnselectIter, libs, "gtk_tree_selection_unselect_iter")
398 core.PuregoSafeRegister(&xTreeSelectionUnselectPath, libs, "gtk_tree_selection_unselect_path")
399 core.PuregoSafeRegister(&xTreeSelectionUnselectRange, libs, "gtk_tree_selection_unselect_range")
400
401}