1// Package gdk was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gdk
3
4import (
5 "unsafe"
6
7 "github.com/ebitengine/purego"
8
9 "github.com/bnema/puregotk/pkg/core"
10 "github.com/bnema/puregotk/v4/gio"
11 "github.com/bnema/puregotk/v4/glib"
12 "github.com/bnema/puregotk/v4/gobject"
13 "github.com/bnema/puregotk/v4/gobject/types"
14)
15
16// Represents the target of an ongoing DND operation.
17//
18// Possible drop sites get informed about the status of the ongoing drag
19// operation with events of type `GDK_DRAG_ENTER`, `GDK_DRAG_LEAVE`,
20// `GDK_DRAG_MOTION` and `GDK_DROP_START`. The `GdkDrop` object can be obtained
21// from these [class@Gdk.Event] types using [method@Gdk.DNDEvent.get_drop].
22//
23// The actual data transfer is initiated from the target side via an async
24// read, using one of the `GdkDrop` methods for this purpose:
25// [method@Gdk.Drop.read_async] or [method@Gdk.Drop.read_value_async].
26//
27// GTK provides a higher level abstraction based on top of these functions,
28// and so they are not normally needed in GTK applications. See the
29// "Drag and Drop" section of the GTK documentation for more information.
30type Drop struct {
31 gobject.Object
32}
33
34var xDropGLibType func() types.GType
35
36func DropGLibType() types.GType {
37 return xDropGLibType()
38}
39
40func DropNewFromInternalPtr(ptr uintptr) *Drop {
41 cls := &Drop{}
42 cls.Ptr = ptr
43 return cls
44}
45
46var xDropFinish func(uintptr, DragAction)
47
48// Ends the drag operation after a drop.
49//
50// The @action must be a single action selected from the actions
51// available via [method@Gdk.Drop.get_actions].
52func (x *Drop) Finish(ActionVar DragAction) {
53
54 xDropFinish(x.GoPointer(), ActionVar)
55
56}
57
58var xDropGetActions func(uintptr) DragAction
59
60// Returns the possible actions for this `GdkDrop`.
61//
62// If this value contains multiple actions - i.e.
63// [func@Gdk.DragAction.is_unique] returns false for the result -
64// [method@Gdk.Drop.finish] must choose the action to use when
65// accepting the drop. This will only happen if you passed
66// `GDK_ACTION_ASK` as one of the possible actions in
67// [method@Gdk.Drop.status]. `GDK_ACTION_ASK` itself will not
68// be included in the actions returned by this function.
69//
70// This value may change over the lifetime of the [class@Gdk.Drop]
71// both as a response to source side actions as well as to calls to
72// [method@Gdk.Drop.status] or [method@Gdk.Drop.finish]. The source
73// side will not change this value anymore once a drop has started.
74func (x *Drop) GetActions() DragAction {
75
76 cret := xDropGetActions(x.GoPointer())
77 return cret
78}
79
80var xDropGetDevice func(uintptr) uintptr
81
82// Returns the `GdkDevice` performing the drop.
83func (x *Drop) GetDevice() *Device {
84 var cls *Device
85
86 cret := xDropGetDevice(x.GoPointer())
87
88 if cret == 0 {
89 return nil
90 }
91 gobject.IncreaseRef(cret)
92 cls = &Device{}
93 cls.Ptr = cret
94 return cls
95}
96
97var xDropGetDisplay func(uintptr) uintptr
98
99// Gets the `GdkDisplay` that @self was created for.
100func (x *Drop) GetDisplay() *Display {
101 var cls *Display
102
103 cret := xDropGetDisplay(x.GoPointer())
104
105 if cret == 0 {
106 return nil
107 }
108 gobject.IncreaseRef(cret)
109 cls = &Display{}
110 cls.Ptr = cret
111 return cls
112}
113
114var xDropGetDrag func(uintptr) uintptr
115
116// If this is an in-app drag-and-drop operation, returns the `GdkDrag`
117// that corresponds to this drop.
118//
119// If it is not, `NULL` is returned.
120func (x *Drop) GetDrag() *Drag {
121 var cls *Drag
122
123 cret := xDropGetDrag(x.GoPointer())
124
125 if cret == 0 {
126 return nil
127 }
128 gobject.IncreaseRef(cret)
129 cls = &Drag{}
130 cls.Ptr = cret
131 return cls
132}
133
134var xDropGetFormats func(uintptr) *ContentFormats
135
136// Returns the `GdkContentFormats` that the drop offers the data
137// to be read in.
138func (x *Drop) GetFormats() *ContentFormats {
139
140 cret := xDropGetFormats(x.GoPointer())
141 return cret
142}
143
144var xDropGetSurface func(uintptr) uintptr
145
146// Returns the `GdkSurface` performing the drop.
147func (x *Drop) GetSurface() *Surface {
148 var cls *Surface
149
150 cret := xDropGetSurface(x.GoPointer())
151
152 if cret == 0 {
153 return nil
154 }
155 gobject.IncreaseRef(cret)
156 cls = &Surface{}
157 cls.Ptr = cret
158 return cls
159}
160
161var xDropReadAsync func(uintptr, []string, int, uintptr, uintptr, uintptr)
162
163// Asynchronously read the dropped data from a `GdkDrop`
164// in a format that complies with one of the mime types.
165func (x *Drop) ReadAsync(MimeTypesVar []string, IoPriorityVar int, CancellableVar *gio.Cancellable, CallbackVar *gio.AsyncReadyCallback, UserDataVar uintptr) {
166
167 var CallbackVarRef uintptr
168 if CallbackVar != nil {
169 CallbackVarPtr := uintptr(unsafe.Pointer(CallbackVar))
170 if cbRefPtr, ok := glib.GetCallback(CallbackVarPtr); ok {
171 CallbackVarRef = cbRefPtr
172 } else {
173 fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) {
174 cbFn := *CallbackVar
175 cbFn(arg0, arg1, arg2)
176 }
177 CallbackVarRef = purego.NewCallback(fcb)
178 glib.SaveCallbackWithClosure(CallbackVarPtr, CallbackVarRef, CallbackVar)
179 }
180 }
181
182 xDropReadAsync(x.GoPointer(), MimeTypesVar, IoPriorityVar, CancellableVar.GoPointer(), CallbackVarRef, UserDataVar)
183
184}
185
186var xDropReadFinish func(uintptr, uintptr, *string, **glib.Error) uintptr
187
188// Finishes an async drop read operation.
189//
190// Note that you must not use blocking read calls on the returned stream
191// in the GTK thread, since some platforms might require communication with
192// GTK to complete the data transfer. You can use async APIs such as
193// g_input_stream_read_bytes_async().
194//
195// See [method@Gdk.Drop.read_async].
196func (x *Drop) ReadFinish(ResultVar gio.AsyncResult, OutMimeTypeVar *string) (*gio.InputStream, error) {
197 var cls *gio.InputStream
198 var cerr *glib.Error
199
200 cret := xDropReadFinish(x.GoPointer(), ResultVar.GoPointer(), OutMimeTypeVar, &cerr)
201
202 if cret == 0 {
203 return nil, cerr
204 }
205 cls = &gio.InputStream{}
206 cls.Ptr = cret
207 if cerr == nil {
208 return cls, nil
209 }
210 return cls, cerr
211
212}
213
214var xDropReadValueAsync func(uintptr, types.GType, int, uintptr, uintptr, uintptr)
215
216// Asynchronously request the drag operation's contents converted
217// to the given @type.
218//
219// For local drag-and-drop operations that are available in the given
220// `GType`, the value will be copied directly. Otherwise, GDK will
221// try to use [func@Gdk.content_deserialize_async] to convert the data.
222func (x *Drop) ReadValueAsync(TypeVar types.GType, IoPriorityVar int, CancellableVar *gio.Cancellable, CallbackVar *gio.AsyncReadyCallback, UserDataVar uintptr) {
223
224 var CallbackVarRef uintptr
225 if CallbackVar != nil {
226 CallbackVarPtr := uintptr(unsafe.Pointer(CallbackVar))
227 if cbRefPtr, ok := glib.GetCallback(CallbackVarPtr); ok {
228 CallbackVarRef = cbRefPtr
229 } else {
230 fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) {
231 cbFn := *CallbackVar
232 cbFn(arg0, arg1, arg2)
233 }
234 CallbackVarRef = purego.NewCallback(fcb)
235 glib.SaveCallbackWithClosure(CallbackVarPtr, CallbackVarRef, CallbackVar)
236 }
237 }
238
239 xDropReadValueAsync(x.GoPointer(), TypeVar, IoPriorityVar, CancellableVar.GoPointer(), CallbackVarRef, UserDataVar)
240
241}
242
243var xDropReadValueFinish func(uintptr, uintptr, **glib.Error) *gobject.Value
244
245// Finishes an async drop read.
246//
247// See [method@Gdk.Drop.read_value_async].
248func (x *Drop) ReadValueFinish(ResultVar gio.AsyncResult) (*gobject.Value, error) {
249 var cerr *glib.Error
250
251 cret := xDropReadValueFinish(x.GoPointer(), ResultVar.GoPointer(), &cerr)
252 if cerr == nil {
253 return cret, nil
254 }
255 return cret, cerr
256
257}
258
259var xDropStatus func(uintptr, DragAction, DragAction)
260
261// Selects all actions that are potentially supported by the destination.
262//
263// When calling this function, do not restrict the passed in actions to
264// the ones provided by [method@Gdk.Drop.get_actions]. Those actions may
265// change in the future, even depending on the actions you provide here.
266//
267// The @preferred action is a hint to the drag-and-drop mechanism about which
268// action to use when multiple actions are possible.
269//
270// This function should be called by drag destinations in response to
271// `GDK_DRAG_ENTER` or `GDK_DRAG_MOTION` events. If the destination does
272// not yet know the exact actions it supports, it should set any possible
273// actions first and then later call this function again.
274func (x *Drop) Status(ActionsVar DragAction, PreferredVar DragAction) {
275
276 xDropStatus(x.GoPointer(), ActionsVar, PreferredVar)
277
278}
279
280func (c *Drop) GoPointer() uintptr {
281 if c == nil {
282 return 0
283 }
284 return c.Ptr
285}
286
287func (c *Drop) SetGoPointer(ptr uintptr) {
288 c.Ptr = ptr
289}
290
291// SetPropertyFormats sets the "formats" property.
292// The possible formats that the drop can provide its data in.
293func (x *Drop) SetPropertyFormats(value uintptr) {
294 var v gobject.Value
295 v.Init(gobject.TypePointerVal)
296 v.SetPointer(value)
297 x.SetProperty("formats", &v)
298}
299
300// GetPropertyFormats gets the "formats" property.
301// The possible formats that the drop can provide its data in.
302func (x *Drop) GetPropertyFormats() uintptr {
303 var v gobject.Value
304 x.GetProperty("formats", &v)
305 return v.GetPointer()
306}
307
308func init() {
309 core.SetPackageName("GDK", "gtk4")
310 core.SetSharedLibraries("GDK", []string{"libgtk-4.so.1"})
311 var libs []uintptr
312 for _, libPath := range core.GetPaths("GDK") {
313 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
314 if err != nil {
315 panic(err)
316 }
317 libs = append(libs, lib)
318 }
319
320 core.PuregoSafeRegister(&xDropGLibType, libs, "gdk_drop_get_type")
321
322 core.PuregoSafeRegister(&xDropFinish, libs, "gdk_drop_finish")
323 core.PuregoSafeRegister(&xDropGetActions, libs, "gdk_drop_get_actions")
324 core.PuregoSafeRegister(&xDropGetDevice, libs, "gdk_drop_get_device")
325 core.PuregoSafeRegister(&xDropGetDisplay, libs, "gdk_drop_get_display")
326 core.PuregoSafeRegister(&xDropGetDrag, libs, "gdk_drop_get_drag")
327 core.PuregoSafeRegister(&xDropGetFormats, libs, "gdk_drop_get_formats")
328 core.PuregoSafeRegister(&xDropGetSurface, libs, "gdk_drop_get_surface")
329 core.PuregoSafeRegister(&xDropReadAsync, libs, "gdk_drop_read_async")
330 core.PuregoSafeRegister(&xDropReadFinish, libs, "gdk_drop_read_finish")
331 core.PuregoSafeRegister(&xDropReadValueAsync, libs, "gdk_drop_read_value_async")
332 core.PuregoSafeRegister(&xDropReadValueFinish, libs, "gdk_drop_read_value_finish")
333 core.PuregoSafeRegister(&xDropStatus, libs, "gdk_drop_status")
334
335}