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 DragSourceClass struct {
18 _ structs.HostLayout
19}
20
21func (x *DragSourceClass) GoPointer() uintptr {
22 return uintptr(unsafe.Pointer(x))
23}
24
25// An event controller to initiate Drag-And-Drop operations.
26//
27// `GtkDragSource` can be set up with the necessary
28// ingredients for a DND operation ahead of time. This includes
29// the source for the data that is being transferred, in the form
30// of a [class@Gdk.ContentProvider], the desired action, and the icon to
31// use during the drag operation. After setting it up, the drag
32// source must be added to a widget as an event controller, using
33// [method@Gtk.Widget.add_controller].
34//
35// ```c
36// static void
37// my_widget_init (MyWidget *self)
38//
39// {
40// GtkDragSource *drag_source = gtk_drag_source_new ();
41//
42// g_signal_connect (drag_source, "prepare", G_CALLBACK (on_drag_prepare), self);
43// g_signal_connect (drag_source, "drag-begin", G_CALLBACK (on_drag_begin), self);
44//
45// gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (drag_source));
46// }
47//
48// ```
49//
50// Setting up the content provider and icon ahead of time only makes
51// sense when the data does not change. More commonly, you will want
52// to set them up just in time. To do so, `GtkDragSource` has
53// [signal@Gtk.DragSource::prepare] and [signal@Gtk.DragSource::drag-begin]
54// signals.
55//
56// The ::prepare signal is emitted before a drag is started, and
57// can be used to set the content provider and actions that the
58// drag should be started with.
59//
60// ```c
61// static GdkContentProvider *
62// on_drag_prepare (GtkDragSource *source,
63//
64// double x,
65// double y,
66// MyWidget *self)
67//
68// {
69// // This widget supports two types of content: GFile objects
70// // and GdkPixbuf objects; GTK will handle the serialization
71// // of these types automatically
72// GFile *file = my_widget_get_file (self);
73// GdkPixbuf *pixbuf = my_widget_get_pixbuf (self);
74//
75// return gdk_content_provider_new_union ((GdkContentProvider *[2]) {
76// gdk_content_provider_new_typed (G_TYPE_FILE, file),
77// gdk_content_provider_new_typed (GDK_TYPE_PIXBUF, pixbuf),
78// }, 2);
79// }
80//
81// ```
82//
83// The ::drag-begin signal is emitted after the `GdkDrag` object has
84// been created, and can be used to set up the drag icon.
85//
86// ```c
87// static void
88// on_drag_begin (GtkDragSource *source,
89//
90// GdkDrag *drag,
91// MyWidget *self)
92//
93// {
94// // Set the widget as the drag icon
95// GdkPaintable *paintable = gtk_widget_paintable_new (GTK_WIDGET (self));
96// gtk_drag_source_set_icon (source, paintable, 0, 0);
97// g_object_unref (paintable);
98// }
99//
100// ```
101//
102// During the DND operation, `GtkDragSource` emits signals that
103// can be used to obtain updates about the status of the operation,
104// but it is not normally necessary to connect to any signals,
105// except for one case: when the supported actions include
106// %GDK_ACTION_MOVE, you need to listen for the
107// [signal@Gtk.DragSource::drag-end] signal and delete the
108// data after it has been transferred.
109type DragSource struct {
110 GestureSingle
111}
112
113var xDragSourceGLibType func() types.GType
114
115func DragSourceGLibType() types.GType {
116 return xDragSourceGLibType()
117}
118
119func DragSourceNewFromInternalPtr(ptr uintptr) *DragSource {
120 cls := &DragSource{}
121 cls.Ptr = ptr
122 return cls
123}
124
125var xNewDragSource func() uintptr
126
127// Creates a new `GtkDragSource` object.
128func NewDragSource() *DragSource {
129 var cls *DragSource
130
131 cret := xNewDragSource()
132
133 if cret == 0 {
134 return nil
135 }
136 cls = &DragSource{}
137 cls.Ptr = cret
138 return cls
139}
140
141var xDragSourceDragCancel func(uintptr)
142
143// Cancels a currently ongoing drag operation.
144func (x *DragSource) DragCancel() {
145
146 xDragSourceDragCancel(x.GoPointer())
147
148}
149
150var xDragSourceGetActions func(uintptr) gdk.DragAction
151
152// Gets the actions that are currently set on the `GtkDragSource`.
153func (x *DragSource) GetActions() gdk.DragAction {
154
155 cret := xDragSourceGetActions(x.GoPointer())
156 return cret
157}
158
159var xDragSourceGetContent func(uintptr) uintptr
160
161// Gets the current content provider of a `GtkDragSource`.
162func (x *DragSource) GetContent() *gdk.ContentProvider {
163 var cls *gdk.ContentProvider
164
165 cret := xDragSourceGetContent(x.GoPointer())
166
167 if cret == 0 {
168 return nil
169 }
170 gobject.IncreaseRef(cret)
171 cls = &gdk.ContentProvider{}
172 cls.Ptr = cret
173 return cls
174}
175
176var xDragSourceGetDrag func(uintptr) uintptr
177
178// Returns the underlying `GdkDrag` object for an ongoing drag.
179func (x *DragSource) GetDrag() *gdk.Drag {
180 var cls *gdk.Drag
181
182 cret := xDragSourceGetDrag(x.GoPointer())
183
184 if cret == 0 {
185 return nil
186 }
187 gobject.IncreaseRef(cret)
188 cls = &gdk.Drag{}
189 cls.Ptr = cret
190 return cls
191}
192
193var xDragSourceSetActions func(uintptr, gdk.DragAction)
194
195// Sets the actions on the `GtkDragSource`.
196//
197// During a DND operation, the actions are offered to potential
198// drop targets. If @actions include %GDK_ACTION_MOVE, you need
199// to listen to the [signal@Gtk.DragSource::drag-end] signal and
200// handle @delete_data being %TRUE.
201//
202// This function can be called before a drag is started,
203// or in a handler for the [signal@Gtk.DragSource::prepare] signal.
204func (x *DragSource) SetActions(ActionsVar gdk.DragAction) {
205
206 xDragSourceSetActions(x.GoPointer(), ActionsVar)
207
208}
209
210var xDragSourceSetContent func(uintptr, uintptr)
211
212// Sets a content provider on a `GtkDragSource`.
213//
214// When the data is requested in the cause of a DND operation,
215// it will be obtained from the content provider.
216//
217// This function can be called before a drag is started,
218// or in a handler for the [signal@Gtk.DragSource::prepare] signal.
219//
220// You may consider setting the content provider back to
221// %NULL in a [signal@Gtk.DragSource::drag-end] signal handler.
222func (x *DragSource) SetContent(ContentVar *gdk.ContentProvider) {
223
224 xDragSourceSetContent(x.GoPointer(), ContentVar.GoPointer())
225
226}
227
228var xDragSourceSetIcon func(uintptr, uintptr, int, int)
229
230// Sets a paintable to use as icon during DND operations.
231//
232// The hotspot coordinates determine the point on the icon
233// that gets aligned with the hotspot of the cursor.
234//
235// If @paintable is %NULL, a default icon is used.
236//
237// This function can be called before a drag is started, or in
238// a [signal@Gtk.DragSource::prepare] or
239// [signal@Gtk.DragSource::drag-begin] signal handler.
240func (x *DragSource) SetIcon(PaintableVar gdk.Paintable, HotXVar int, HotYVar int) {
241
242 xDragSourceSetIcon(x.GoPointer(), PaintableVar.GoPointer(), HotXVar, HotYVar)
243
244}
245
246func (c *DragSource) GoPointer() uintptr {
247 if c == nil {
248 return 0
249 }
250 return c.Ptr
251}
252
253func (c *DragSource) SetGoPointer(ptr uintptr) {
254 c.Ptr = ptr
255}
256
257// Emitted on the drag source when a drag is started.
258//
259// It can be used to e.g. set a custom drag icon with
260// [method@Gtk.DragSource.set_icon].
261func (x *DragSource) ConnectDragBegin(cb *func(DragSource, uintptr)) uint {
262 cbPtr := uintptr(unsafe.Pointer(cb))
263 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
264 handlerID := gobject.SignalConnect(x.GoPointer(), "drag-begin", cbRefPtr)
265 glib.SaveHandlerMapping(handlerID, cbPtr)
266 return handlerID
267 }
268
269 fcb := func(clsPtr uintptr, DragVarp uintptr) {
270 fa := DragSource{}
271 fa.Ptr = clsPtr
272 cbFn := *cb
273
274 cbFn(fa, DragVarp)
275
276 }
277 cbRefPtr := purego.NewCallback(fcb)
278 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
279 handlerID := gobject.SignalConnect(x.GoPointer(), "drag-begin", cbRefPtr)
280 glib.SaveHandlerMapping(handlerID, cbPtr)
281 return handlerID
282}
283
284// Emitted on the drag source when a drag has failed.
285//
286// The signal handler may handle a failed drag operation based on
287// the type of error. It should return %TRUE if the failure has been handled
288// and the default "drag operation failed" animation should not be shown.
289func (x *DragSource) ConnectDragCancel(cb *func(DragSource, uintptr, gdk.DragCancelReason) bool) uint {
290 cbPtr := uintptr(unsafe.Pointer(cb))
291 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
292 handlerID := gobject.SignalConnect(x.GoPointer(), "drag-cancel", cbRefPtr)
293 glib.SaveHandlerMapping(handlerID, cbPtr)
294 return handlerID
295 }
296
297 fcb := func(clsPtr uintptr, DragVarp uintptr, ReasonVarp gdk.DragCancelReason) bool {
298 fa := DragSource{}
299 fa.Ptr = clsPtr
300 cbFn := *cb
301
302 return cbFn(fa, DragVarp, ReasonVarp)
303
304 }
305 cbRefPtr := purego.NewCallback(fcb)
306 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
307 handlerID := gobject.SignalConnect(x.GoPointer(), "drag-cancel", cbRefPtr)
308 glib.SaveHandlerMapping(handlerID, cbPtr)
309 return handlerID
310}
311
312// Emitted on the drag source when a drag is finished.
313//
314// A typical reason to connect to this signal is to undo
315// things done in [signal@Gtk.DragSource::prepare] or
316// [signal@Gtk.DragSource::drag-begin] handlers.
317func (x *DragSource) ConnectDragEnd(cb *func(DragSource, uintptr, bool)) uint {
318 cbPtr := uintptr(unsafe.Pointer(cb))
319 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
320 handlerID := gobject.SignalConnect(x.GoPointer(), "drag-end", cbRefPtr)
321 glib.SaveHandlerMapping(handlerID, cbPtr)
322 return handlerID
323 }
324
325 fcb := func(clsPtr uintptr, DragVarp uintptr, DeleteDataVarp bool) {
326 fa := DragSource{}
327 fa.Ptr = clsPtr
328 cbFn := *cb
329
330 cbFn(fa, DragVarp, DeleteDataVarp)
331
332 }
333 cbRefPtr := purego.NewCallback(fcb)
334 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
335 handlerID := gobject.SignalConnect(x.GoPointer(), "drag-end", cbRefPtr)
336 glib.SaveHandlerMapping(handlerID, cbPtr)
337 return handlerID
338}
339
340// Emitted when a drag is about to be initiated.
341//
342// It returns the `GdkContentProvider` to use for the drag that is about
343// to start. The default handler for this signal returns the value of
344// the [property@Gtk.DragSource:content] property, so if you set up that
345// property ahead of time, you don't need to connect to this signal.
346func (x *DragSource) ConnectPrepare(cb *func(DragSource, float64, float64) gdk.ContentProvider) uint {
347 cbPtr := uintptr(unsafe.Pointer(cb))
348 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
349 handlerID := gobject.SignalConnect(x.GoPointer(), "prepare", cbRefPtr)
350 glib.SaveHandlerMapping(handlerID, cbPtr)
351 return handlerID
352 }
353
354 fcb := func(clsPtr uintptr, XVarp float64, YVarp float64) uintptr {
355 fa := DragSource{}
356 fa.Ptr = clsPtr
357 cbFn := *cb
358
359 PrepareCls := cbFn(fa, XVarp, YVarp)
360 return PrepareCls.Ptr
361
362 }
363 cbRefPtr := purego.NewCallback(fcb)
364 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
365 handlerID := gobject.SignalConnect(x.GoPointer(), "prepare", cbRefPtr)
366 glib.SaveHandlerMapping(handlerID, cbPtr)
367 return handlerID
368}
369
370func init() {
371 core.SetPackageName("GTK", "gtk4")
372 core.SetSharedLibraries("GTK", []string{"libgtk-4.so.1"})
373 var libs []uintptr
374 for _, libPath := range core.GetPaths("GTK") {
375 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
376 if err != nil {
377 panic(err)
378 }
379 libs = append(libs, lib)
380 }
381
382 core.PuregoSafeRegister(&xDragSourceGLibType, libs, "gtk_drag_source_get_type")
383
384 core.PuregoSafeRegister(&xNewDragSource, libs, "gtk_drag_source_new")
385
386 core.PuregoSafeRegister(&xDragSourceDragCancel, libs, "gtk_drag_source_drag_cancel")
387 core.PuregoSafeRegister(&xDragSourceGetActions, libs, "gtk_drag_source_get_actions")
388 core.PuregoSafeRegister(&xDragSourceGetContent, libs, "gtk_drag_source_get_content")
389 core.PuregoSafeRegister(&xDragSourceGetDrag, libs, "gtk_drag_source_get_drag")
390 core.PuregoSafeRegister(&xDragSourceSetActions, libs, "gtk_drag_source_set_actions")
391 core.PuregoSafeRegister(&xDragSourceSetContent, libs, "gtk_drag_source_set_content")
392 core.PuregoSafeRegister(&xDragSourceSetIcon, libs, "gtk_drag_source_set_icon")
393
394}