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/gdk"
12 "github.com/bnema/puregotk/v4/glib"
13 "github.com/bnema/puregotk/v4/gobject"
14 "github.com/bnema/puregotk/v4/gobject/types"
15)
16
17type DropTargetAsyncClass struct {
18 _ structs.HostLayout
19}
20
21func (x *DropTargetAsyncClass) GoPointer() uintptr {
22 return uintptr(unsafe.Pointer(x))
23}
24
25// An event controller to receive Drag-and-Drop operations, asynchronously.
26//
27// It is the more complete but also more complex method of handling drop
28// operations compared to [class@Gtk.DropTarget], and you should only use
29// it if `GtkDropTarget` doesn't provide all the features you need.
30//
31// To use a `GtkDropTargetAsync` to receive drops on a widget, you create
32// a `GtkDropTargetAsync` object, configure which data formats and actions
33// you support, connect to its signals, and then attach it to the widget
34// with [method@Gtk.Widget.add_controller].
35//
36// During a drag operation, the first signal that a `GtkDropTargetAsync`
37// emits is [signal@Gtk.DropTargetAsync::accept], which is meant to determine
38// whether the target is a possible drop site for the ongoing drop. The
39// default handler for the ::accept signal accepts the drop if it finds
40// a compatible data format and an action that is supported on both sides.
41//
42// If it is, and the widget becomes a target, you will receive a
43// [signal@Gtk.DropTargetAsync::drag-enter] signal, followed by
44// [signal@Gtk.DropTargetAsync::drag-motion] signals as the pointer moves,
45// optionally a [signal@Gtk.DropTargetAsync::drop] signal when a drop happens,
46// and finally a [signal@Gtk.DropTargetAsync::drag-leave] signal when the
47// pointer moves off the widget.
48//
49// The ::drag-enter and ::drag-motion handler return a `GdkDragAction`
50// to update the status of the ongoing operation. The ::drop handler
51// should decide if it ultimately accepts the drop and if it does, it
52// should initiate the data transfer and finish the operation by calling
53// [method@Gdk.Drop.finish].
54//
55// Between the ::drag-enter and ::drag-leave signals the widget is a
56// current drop target, and will receive the %GTK_STATE_FLAG_DROP_ACTIVE
57// state, which can be used by themes to style the widget as a drop target.
58type DropTargetAsync struct {
59 EventController
60}
61
62var xDropTargetAsyncGLibType func() types.GType
63
64func DropTargetAsyncGLibType() types.GType {
65 return xDropTargetAsyncGLibType()
66}
67
68func DropTargetAsyncNewFromInternalPtr(ptr uintptr) *DropTargetAsync {
69 cls := &DropTargetAsync{}
70 cls.Ptr = ptr
71 return cls
72}
73
74var xNewDropTargetAsync func(*gdk.ContentFormats, gdk.DragAction) uintptr
75
76// Creates a new `GtkDropTargetAsync` object.
77func NewDropTargetAsync(FormatsVar *gdk.ContentFormats, ActionsVar gdk.DragAction) *DropTargetAsync {
78 var cls *DropTargetAsync
79
80 cret := xNewDropTargetAsync(FormatsVar, ActionsVar)
81
82 if cret == 0 {
83 return nil
84 }
85 cls = &DropTargetAsync{}
86 cls.Ptr = cret
87 return cls
88}
89
90var xDropTargetAsyncGetActions func(uintptr) gdk.DragAction
91
92// Gets the actions that this drop target supports.
93func (x *DropTargetAsync) GetActions() gdk.DragAction {
94
95 cret := xDropTargetAsyncGetActions(x.GoPointer())
96 return cret
97}
98
99var xDropTargetAsyncGetFormats func(uintptr) *gdk.ContentFormats
100
101// Gets the data formats that this drop target accepts.
102//
103// If the result is %NULL, all formats are expected to be supported.
104func (x *DropTargetAsync) GetFormats() *gdk.ContentFormats {
105
106 cret := xDropTargetAsyncGetFormats(x.GoPointer())
107 return cret
108}
109
110var xDropTargetAsyncRejectDrop func(uintptr, uintptr)
111
112// Sets the @drop as not accepted on this drag site.
113//
114// This function should be used when delaying the decision
115// on whether to accept a drag or not until after reading
116// the data.
117func (x *DropTargetAsync) RejectDrop(DropVar *gdk.Drop) {
118
119 xDropTargetAsyncRejectDrop(x.GoPointer(), DropVar.GoPointer())
120
121}
122
123var xDropTargetAsyncSetActions func(uintptr, gdk.DragAction)
124
125// Sets the actions that this drop target supports.
126func (x *DropTargetAsync) SetActions(ActionsVar gdk.DragAction) {
127
128 xDropTargetAsyncSetActions(x.GoPointer(), ActionsVar)
129
130}
131
132var xDropTargetAsyncSetFormats func(uintptr, *gdk.ContentFormats)
133
134// Sets the data formats that this drop target will accept.
135func (x *DropTargetAsync) SetFormats(FormatsVar *gdk.ContentFormats) {
136
137 xDropTargetAsyncSetFormats(x.GoPointer(), FormatsVar)
138
139}
140
141func (c *DropTargetAsync) GoPointer() uintptr {
142 if c == nil {
143 return 0
144 }
145 return c.Ptr
146}
147
148func (c *DropTargetAsync) SetGoPointer(ptr uintptr) {
149 c.Ptr = ptr
150}
151
152// SetPropertyFormats sets the "formats" property.
153// The `GdkContentFormats` that determines the supported data formats.
154func (x *DropTargetAsync) SetPropertyFormats(value uintptr) {
155 var v gobject.Value
156 v.Init(gobject.TypePointerVal)
157 v.SetPointer(value)
158 x.SetProperty("formats", &v)
159}
160
161// GetPropertyFormats gets the "formats" property.
162// The `GdkContentFormats` that determines the supported data formats.
163func (x *DropTargetAsync) GetPropertyFormats() uintptr {
164 var v gobject.Value
165 x.GetProperty("formats", &v)
166 return v.GetPointer()
167}
168
169// Emitted on the drop site when a drop operation is about to begin.
170//
171// If the drop is not accepted, %FALSE will be returned and the drop target
172// will ignore the drop. If %TRUE is returned, the drop is accepted for now
173// but may be rejected later via a call to [method@Gtk.DropTargetAsync.reject_drop]
174// or ultimately by returning %FALSE from a [signal@Gtk.DropTargetAsync::drop]
175// handler.
176//
177// The default handler for this signal decides whether to accept the drop
178// based on the formats provided by the @drop.
179//
180// If the decision whether the drop will be accepted or rejected needs
181// further processing, such as inspecting the data, this function should
182// return %TRUE and proceed as is @drop was accepted and if it decides to
183// reject the drop later, it should call [method@Gtk.DropTargetAsync.reject_drop].
184func (x *DropTargetAsync) ConnectAccept(cb *func(DropTargetAsync, uintptr) bool) uint {
185 cbPtr := uintptr(unsafe.Pointer(cb))
186 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
187 handlerID := gobject.SignalConnect(x.GoPointer(), "accept", cbRefPtr)
188 glib.SaveHandlerMapping(handlerID, cbPtr)
189 return handlerID
190 }
191
192 fcb := func(clsPtr uintptr, DropVarp uintptr) bool {
193 fa := DropTargetAsync{}
194 fa.Ptr = clsPtr
195 cbFn := *cb
196
197 return cbFn(fa, DropVarp)
198
199 }
200 cbRefPtr := purego.NewCallback(fcb)
201 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
202 handlerID := gobject.SignalConnect(x.GoPointer(), "accept", cbRefPtr)
203 glib.SaveHandlerMapping(handlerID, cbPtr)
204 return handlerID
205}
206
207// Emitted on the drop site when the pointer enters the widget.
208//
209// It can be used to set up custom highlighting.
210func (x *DropTargetAsync) ConnectDragEnter(cb *func(DropTargetAsync, uintptr, float64, float64) gdk.DragAction) uint {
211 cbPtr := uintptr(unsafe.Pointer(cb))
212 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
213 handlerID := gobject.SignalConnect(x.GoPointer(), "drag-enter", cbRefPtr)
214 glib.SaveHandlerMapping(handlerID, cbPtr)
215 return handlerID
216 }
217
218 fcb := func(clsPtr uintptr, DropVarp uintptr, XVarp float64, YVarp float64) gdk.DragAction {
219 fa := DropTargetAsync{}
220 fa.Ptr = clsPtr
221 cbFn := *cb
222
223 return cbFn(fa, DropVarp, XVarp, YVarp)
224
225 }
226 cbRefPtr := purego.NewCallback(fcb)
227 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
228 handlerID := gobject.SignalConnect(x.GoPointer(), "drag-enter", cbRefPtr)
229 glib.SaveHandlerMapping(handlerID, cbPtr)
230 return handlerID
231}
232
233// Emitted on the drop site when the pointer leaves the widget.
234//
235// Its main purpose it to undo things done in
236// `GtkDropTargetAsync`::drag-enter.
237func (x *DropTargetAsync) ConnectDragLeave(cb *func(DropTargetAsync, uintptr)) uint {
238 cbPtr := uintptr(unsafe.Pointer(cb))
239 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
240 handlerID := gobject.SignalConnect(x.GoPointer(), "drag-leave", cbRefPtr)
241 glib.SaveHandlerMapping(handlerID, cbPtr)
242 return handlerID
243 }
244
245 fcb := func(clsPtr uintptr, DropVarp uintptr) {
246 fa := DropTargetAsync{}
247 fa.Ptr = clsPtr
248 cbFn := *cb
249
250 cbFn(fa, DropVarp)
251
252 }
253 cbRefPtr := purego.NewCallback(fcb)
254 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
255 handlerID := gobject.SignalConnect(x.GoPointer(), "drag-leave", cbRefPtr)
256 glib.SaveHandlerMapping(handlerID, cbPtr)
257 return handlerID
258}
259
260// Emitted while the pointer is moving over the drop target.
261func (x *DropTargetAsync) ConnectDragMotion(cb *func(DropTargetAsync, uintptr, float64, float64) gdk.DragAction) uint {
262 cbPtr := uintptr(unsafe.Pointer(cb))
263 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
264 handlerID := gobject.SignalConnect(x.GoPointer(), "drag-motion", cbRefPtr)
265 glib.SaveHandlerMapping(handlerID, cbPtr)
266 return handlerID
267 }
268
269 fcb := func(clsPtr uintptr, DropVarp uintptr, XVarp float64, YVarp float64) gdk.DragAction {
270 fa := DropTargetAsync{}
271 fa.Ptr = clsPtr
272 cbFn := *cb
273
274 return cbFn(fa, DropVarp, XVarp, YVarp)
275
276 }
277 cbRefPtr := purego.NewCallback(fcb)
278 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
279 handlerID := gobject.SignalConnect(x.GoPointer(), "drag-motion", cbRefPtr)
280 glib.SaveHandlerMapping(handlerID, cbPtr)
281 return handlerID
282}
283
284// Emitted on the drop site when the user drops the data onto the widget.
285//
286// The signal handler must determine whether the pointer position is in a
287// drop zone or not. If it is not in a drop zone, it returns %FALSE and no
288// further processing is necessary.
289//
290// Otherwise, the handler returns %TRUE. In this case, this handler will
291// accept the drop. The handler must ensure that [method@Gdk.Drop.finish]
292// is called to let the source know that the drop is done. The call to
293// [method@Gdk.Drop.finish] must only be done when all data has been received.
294//
295// To receive the data, use one of the read functions provided by
296// [class@Gdk.Drop] such as [method@Gdk.Drop.read_async] or
297// [method@Gdk.Drop.read_value_async].
298func (x *DropTargetAsync) ConnectDrop(cb *func(DropTargetAsync, uintptr, float64, float64) bool) uint {
299 cbPtr := uintptr(unsafe.Pointer(cb))
300 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
301 handlerID := gobject.SignalConnect(x.GoPointer(), "drop", cbRefPtr)
302 glib.SaveHandlerMapping(handlerID, cbPtr)
303 return handlerID
304 }
305
306 fcb := func(clsPtr uintptr, DropVarp uintptr, XVarp float64, YVarp float64) bool {
307 fa := DropTargetAsync{}
308 fa.Ptr = clsPtr
309 cbFn := *cb
310
311 return cbFn(fa, DropVarp, XVarp, YVarp)
312
313 }
314 cbRefPtr := purego.NewCallback(fcb)
315 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
316 handlerID := gobject.SignalConnect(x.GoPointer(), "drop", cbRefPtr)
317 glib.SaveHandlerMapping(handlerID, cbPtr)
318 return handlerID
319}
320
321func init() {
322 core.SetPackageName("GTK", "gtk4")
323 core.SetSharedLibraries("GTK", []string{"libgtk-4.so.1"})
324 var libs []uintptr
325 for _, libPath := range core.GetPaths("GTK") {
326 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
327 if err != nil {
328 panic(err)
329 }
330 libs = append(libs, lib)
331 }
332
333 core.PuregoSafeRegister(&xDropTargetAsyncGLibType, libs, "gtk_drop_target_async_get_type")
334
335 core.PuregoSafeRegister(&xNewDropTargetAsync, libs, "gtk_drop_target_async_new")
336
337 core.PuregoSafeRegister(&xDropTargetAsyncGetActions, libs, "gtk_drop_target_async_get_actions")
338 core.PuregoSafeRegister(&xDropTargetAsyncGetFormats, libs, "gtk_drop_target_async_get_formats")
339 core.PuregoSafeRegister(&xDropTargetAsyncRejectDrop, libs, "gtk_drop_target_async_reject_drop")
340 core.PuregoSafeRegister(&xDropTargetAsyncSetActions, libs, "gtk_drop_target_async_set_actions")
341 core.PuregoSafeRegister(&xDropTargetAsyncSetFormats, libs, "gtk_drop_target_async_set_formats")
342
343}