v0.2.1 c0399be

gtkdroptarget.go RawHistoryFolder

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 DropTargetClass struct {
18	_ structs.HostLayout
19}
20
21func (x *DropTargetClass) GoPointer() uintptr {
22	return uintptr(unsafe.Pointer(x))
23}
24
25// An event controller to receive Drag-and-Drop operations.
26//
27// The most basic way to use a `GtkDropTarget` to receive drops on a
28// widget is to create it via [ctor@Gtk.DropTarget.new], passing in the
29// `GType` of the data you want to receive and connect to the
30// [signal@Gtk.DropTarget::drop] signal to receive the data:
31//
32// ```c
33// static gboolean
34// on_drop (GtkDropTarget *target,
35//
36//	const GValue  *value,
37//	double         x,
38//	double         y,
39//	gpointer       data)
40//
41//	{
42//	  MyWidget *self = data;
43//
44//	  // Call the appropriate setter depending on the type of data
45//	  // that we received
46//	  if (G_VALUE_HOLDS (value, G_TYPE_FILE))
47//	    my_widget_set_file (self, g_value_get_object (value));
48//	  else if (G_VALUE_HOLDS (value, GDK_TYPE_PIXBUF))
49//	    my_widget_set_pixbuf (self, g_value_get_object (value));
50//	  else
51//	    return FALSE;
52//
53//	  return TRUE;
54//	}
55//
56// static void
57// my_widget_init (MyWidget *self)
58//
59//	{
60//	  GtkDropTarget *target =
61//	    gtk_drop_target_new (G_TYPE_INVALID, GDK_ACTION_COPY);
62//
63//	  // This widget accepts two types of drop types: GFile objects
64//	  // and GdkPixbuf objects
65//	  gtk_drop_target_set_gtypes (target, (GType [2]) {
66//	    G_TYPE_FILE,
67//	    GDK_TYPE_PIXBUF,
68//	  }, 2);
69//
70//	  g_signal_connect (target, "drop", G_CALLBACK (on_drop), self);
71//	  gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (target));
72//	}
73//
74// ```
75//
76// `GtkDropTarget` supports more options, such as:
77//
78//   - rejecting potential drops via the [signal@Gtk.DropTarget::accept] signal
79//     and the [method@Gtk.DropTarget.reject] function to let other drop
80//     targets handle the drop
81//   - tracking an ongoing drag operation before the drop via the
82//     [signal@Gtk.DropTarget::enter], [signal@Gtk.DropTarget::motion] and
83//     [signal@Gtk.DropTarget::leave] signals
84//   - configuring how to receive data by setting the
85//     [property@Gtk.DropTarget:preload] property and listening for its
86//     availability via the [property@Gtk.DropTarget:value] property
87//
88// However, `GtkDropTarget` is ultimately modeled in a synchronous way
89// and only supports data transferred via `GType`. If you want full control
90// over an ongoing drop, the [class@Gtk.DropTargetAsync] object gives you
91// this ability.
92//
93// While a pointer is dragged over the drop target's widget and the drop
94// has not been rejected, that widget will receive the
95// %GTK_STATE_FLAG_DROP_ACTIVE state, which can be used to style the widget.
96//
97// If you are not interested in receiving the drop, but just want to update
98// UI state during a Drag-and-Drop operation (e.g. switching tabs), you can
99// use [class@Gtk.DropControllerMotion].
100type DropTarget struct {
101	EventController
102}
103
104var xDropTargetGLibType func() types.GType
105
106func DropTargetGLibType() types.GType {
107	return xDropTargetGLibType()
108}
109
110func DropTargetNewFromInternalPtr(ptr uintptr) *DropTarget {
111	cls := &DropTarget{}
112	cls.Ptr = ptr
113	return cls
114}
115
116var xNewDropTarget func(types.GType, gdk.DragAction) uintptr
117
118// Creates a new `GtkDropTarget` object.
119//
120// If the drop target should support more than 1 type, pass
121// %G_TYPE_INVALID for @type and then call
122// [method@Gtk.DropTarget.set_gtypes].
123func NewDropTarget(TypeVar types.GType, ActionsVar gdk.DragAction) *DropTarget {
124	var cls *DropTarget
125
126	cret := xNewDropTarget(TypeVar, ActionsVar)
127
128	if cret == 0 {
129		return nil
130	}
131	cls = &DropTarget{}
132	cls.Ptr = cret
133	return cls
134}
135
136var xDropTargetGetActions func(uintptr) gdk.DragAction
137
138// Gets the actions that this drop target supports.
139func (x *DropTarget) GetActions() gdk.DragAction {
140
141	cret := xDropTargetGetActions(x.GoPointer())
142	return cret
143}
144
145var xDropTargetGetCurrentDrop func(uintptr) uintptr
146
147// Gets the currently handled drop operation.
148//
149// If no drop operation is going on, %NULL is returned.
150func (x *DropTarget) GetCurrentDrop() *gdk.Drop {
151	var cls *gdk.Drop
152
153	cret := xDropTargetGetCurrentDrop(x.GoPointer())
154
155	if cret == 0 {
156		return nil
157	}
158	gobject.IncreaseRef(cret)
159	cls = &gdk.Drop{}
160	cls.Ptr = cret
161	return cls
162}
163
164var xDropTargetGetDrop func(uintptr) uintptr
165
166// Gets the currently handled drop operation.
167//
168// If no drop operation is going on, %NULL is returned.
169func (x *DropTarget) GetDrop() *gdk.Drop {
170	var cls *gdk.Drop
171
172	cret := xDropTargetGetDrop(x.GoPointer())
173
174	if cret == 0 {
175		return nil
176	}
177	gobject.IncreaseRef(cret)
178	cls = &gdk.Drop{}
179	cls.Ptr = cret
180	return cls
181}
182
183var xDropTargetGetFormats func(uintptr) *gdk.ContentFormats
184
185// Gets the data formats that this drop target accepts.
186//
187// If the result is %NULL, all formats are expected to be supported.
188func (x *DropTarget) GetFormats() *gdk.ContentFormats {
189
190	cret := xDropTargetGetFormats(x.GoPointer())
191	return cret
192}
193
194var xDropTargetGetGtypes func(uintptr, *uint) uintptr
195
196// Gets the list of supported `GType`s that can be dropped on the target.
197//
198// If no types have been set, `NULL` will be returned.
199func (x *DropTarget) GetGtypes(NTypesVar *uint) uintptr {
200
201	cret := xDropTargetGetGtypes(x.GoPointer(), NTypesVar)
202	return cret
203}
204
205var xDropTargetGetPreload func(uintptr) bool
206
207// Gets whether data should be preloaded on hover.
208func (x *DropTarget) GetPreload() bool {
209
210	cret := xDropTargetGetPreload(x.GoPointer())
211	return cret
212}
213
214var xDropTargetGetValue func(uintptr) *gobject.Value
215
216// Gets the current drop data, as a `GValue`.
217func (x *DropTarget) GetValue() *gobject.Value {
218
219	cret := xDropTargetGetValue(x.GoPointer())
220	return cret
221}
222
223var xDropTargetReject func(uintptr)
224
225// Rejects the ongoing drop operation.
226//
227// If no drop operation is ongoing, i.e when [property@Gtk.DropTarget:current-drop]
228// is %NULL, this function does nothing.
229//
230// This function should be used when delaying the decision
231// on whether to accept a drag or not until after reading
232// the data.
233func (x *DropTarget) Reject() {
234
235	xDropTargetReject(x.GoPointer())
236
237}
238
239var xDropTargetSetActions func(uintptr, gdk.DragAction)
240
241// Sets the actions that this drop target supports.
242func (x *DropTarget) SetActions(ActionsVar gdk.DragAction) {
243
244	xDropTargetSetActions(x.GoPointer(), ActionsVar)
245
246}
247
248var xDropTargetSetGtypes func(uintptr, []types.GType, uint)
249
250// Sets the supported `GType`s for this drop target.
251func (x *DropTarget) SetGtypes(TypesVar []types.GType, NTypesVar uint) {
252
253	xDropTargetSetGtypes(x.GoPointer(), TypesVar, NTypesVar)
254
255}
256
257var xDropTargetSetPreload func(uintptr, bool)
258
259// Sets whether data should be preloaded on hover.
260func (x *DropTarget) SetPreload(PreloadVar bool) {
261
262	xDropTargetSetPreload(x.GoPointer(), PreloadVar)
263
264}
265
266func (c *DropTarget) GoPointer() uintptr {
267	if c == nil {
268		return 0
269	}
270	return c.Ptr
271}
272
273func (c *DropTarget) SetGoPointer(ptr uintptr) {
274	c.Ptr = ptr
275}
276
277// SetPropertyFormats sets the "formats" property.
278// The `GdkContentFormats` that determine the supported data formats.
279func (x *DropTarget) SetPropertyFormats(value uintptr) {
280	var v gobject.Value
281	v.Init(gobject.TypePointerVal)
282	v.SetPointer(value)
283	x.SetProperty("formats", &v)
284}
285
286// GetPropertyFormats gets the "formats" property.
287// The `GdkContentFormats` that determine the supported data formats.
288func (x *DropTarget) GetPropertyFormats() uintptr {
289	var v gobject.Value
290	x.GetProperty("formats", &v)
291	return v.GetPointer()
292}
293
294// SetPropertyPreload sets the "preload" property.
295// Whether the drop data should be preloaded when the pointer is only
296// hovering over the widget but has not been released.
297//
298// Setting this property allows finer grained reaction to an ongoing
299// drop at the cost of loading more data.
300//
301// The default value for this property is %FALSE to avoid downloading
302// huge amounts of data by accident.
303//
304// For example, if somebody drags a full document of gigabytes of text
305// from a text editor across a widget with a preloading drop target,
306// this data will be downloaded, even if the data is ultimately dropped
307// elsewhere.
308//
309// For a lot of data formats, the amount of data is very small (like
310// %GDK_TYPE_RGBA), so enabling this property does not hurt at all.
311// And for local-only Drag-and-Drop operations, no data transfer is done,
312// so enabling it there is free.
313func (x *DropTarget) SetPropertyPreload(value bool) {
314	var v gobject.Value
315	v.Init(gobject.TypeBooleanVal)
316	v.SetBoolean(value)
317	x.SetProperty("preload", &v)
318}
319
320// GetPropertyPreload gets the "preload" property.
321// Whether the drop data should be preloaded when the pointer is only
322// hovering over the widget but has not been released.
323//
324// Setting this property allows finer grained reaction to an ongoing
325// drop at the cost of loading more data.
326//
327// The default value for this property is %FALSE to avoid downloading
328// huge amounts of data by accident.
329//
330// For example, if somebody drags a full document of gigabytes of text
331// from a text editor across a widget with a preloading drop target,
332// this data will be downloaded, even if the data is ultimately dropped
333// elsewhere.
334//
335// For a lot of data formats, the amount of data is very small (like
336// %GDK_TYPE_RGBA), so enabling this property does not hurt at all.
337// And for local-only Drag-and-Drop operations, no data transfer is done,
338// so enabling it there is free.
339func (x *DropTarget) GetPropertyPreload() bool {
340	var v gobject.Value
341	x.GetProperty("preload", &v)
342	return v.GetBoolean()
343}
344
345// GetPropertyValue gets the "value" property.
346// The value for this drop operation.
347//
348// This is %NULL if the data has not been loaded yet or no drop
349// operation is going on.
350//
351// Data may be available before the [signal@Gtk.DropTarget::drop]
352// signal gets emitted - for example when the [property@Gtk.DropTarget:preload]
353// property is set. You can use the ::notify signal to be notified
354// of available data.
355func (x *DropTarget) GetPropertyValue() uintptr {
356	var v gobject.Value
357	x.GetProperty("value", &v)
358	return v.GetPointer()
359}
360
361// Emitted on the drop site when a drop operation is about to begin.
362//
363// If the drop is not accepted, %FALSE will be returned and the drop target
364// will ignore the drop. If %TRUE is returned, the drop is accepted for now
365// but may be rejected later via a call to [method@Gtk.DropTarget.reject]
366// or ultimately by returning %FALSE from a [signal@Gtk.DropTarget::drop]
367// handler.
368//
369// The default handler for this signal decides whether to accept the drop
370// based on the formats provided by the @drop.
371//
372// If the decision whether the drop will be accepted or rejected depends
373// on the data, this function should return %TRUE, the
374// [property@Gtk.DropTarget:preload] property should be set and the value
375// should be inspected via the ::notify:value signal, calling
376// [method@Gtk.DropTarget.reject] if required.
377func (x *DropTarget) ConnectAccept(cb *func(DropTarget, uintptr) bool) uint {
378	cbPtr := uintptr(unsafe.Pointer(cb))
379	if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
380		handlerID := gobject.SignalConnect(x.GoPointer(), "accept", cbRefPtr)
381		glib.SaveHandlerMapping(handlerID, cbPtr)
382		return handlerID
383	}
384
385	fcb := func(clsPtr uintptr, DropVarp uintptr) bool {
386		fa := DropTarget{}
387		fa.Ptr = clsPtr
388		cbFn := *cb
389
390		return cbFn(fa, DropVarp)
391
392	}
393	cbRefPtr := purego.NewCallback(fcb)
394	glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
395	handlerID := gobject.SignalConnect(x.GoPointer(), "accept", cbRefPtr)
396	glib.SaveHandlerMapping(handlerID, cbPtr)
397	return handlerID
398}
399
400// Emitted on the drop site when the user drops the data onto the widget.
401//
402// The signal handler must determine whether the pointer position is in
403// a drop zone or not. If it is not in a drop zone, it returns %FALSE
404// and no further processing is necessary.
405//
406// Otherwise, the handler returns %TRUE. In this case, this handler will
407// accept the drop. The handler is responsible for using the given @value
408// and performing the drop operation.
409func (x *DropTarget) ConnectDrop(cb *func(DropTarget, uintptr, float64, float64) bool) uint {
410	cbPtr := uintptr(unsafe.Pointer(cb))
411	if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
412		handlerID := gobject.SignalConnect(x.GoPointer(), "drop", cbRefPtr)
413		glib.SaveHandlerMapping(handlerID, cbPtr)
414		return handlerID
415	}
416
417	fcb := func(clsPtr uintptr, ValueVarp uintptr, XVarp float64, YVarp float64) bool {
418		fa := DropTarget{}
419		fa.Ptr = clsPtr
420		cbFn := *cb
421
422		return cbFn(fa, ValueVarp, XVarp, YVarp)
423
424	}
425	cbRefPtr := purego.NewCallback(fcb)
426	glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
427	handlerID := gobject.SignalConnect(x.GoPointer(), "drop", cbRefPtr)
428	glib.SaveHandlerMapping(handlerID, cbPtr)
429	return handlerID
430}
431
432// Emitted on the drop site when the pointer enters the widget.
433//
434// It can be used to set up custom highlighting.
435func (x *DropTarget) ConnectEnter(cb *func(DropTarget, float64, float64) gdk.DragAction) uint {
436	cbPtr := uintptr(unsafe.Pointer(cb))
437	if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
438		handlerID := gobject.SignalConnect(x.GoPointer(), "enter", cbRefPtr)
439		glib.SaveHandlerMapping(handlerID, cbPtr)
440		return handlerID
441	}
442
443	fcb := func(clsPtr uintptr, XVarp float64, YVarp float64) gdk.DragAction {
444		fa := DropTarget{}
445		fa.Ptr = clsPtr
446		cbFn := *cb
447
448		return cbFn(fa, XVarp, YVarp)
449
450	}
451	cbRefPtr := purego.NewCallback(fcb)
452	glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
453	handlerID := gobject.SignalConnect(x.GoPointer(), "enter", cbRefPtr)
454	glib.SaveHandlerMapping(handlerID, cbPtr)
455	return handlerID
456}
457
458// Emitted on the drop site when the pointer leaves the widget.
459//
460// Its main purpose it to undo things done in
461// [signal@Gtk.DropTarget::enter].
462func (x *DropTarget) ConnectLeave(cb *func(DropTarget)) uint {
463	cbPtr := uintptr(unsafe.Pointer(cb))
464	if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
465		handlerID := gobject.SignalConnect(x.GoPointer(), "leave", cbRefPtr)
466		glib.SaveHandlerMapping(handlerID, cbPtr)
467		return handlerID
468	}
469
470	fcb := func(clsPtr uintptr) {
471		fa := DropTarget{}
472		fa.Ptr = clsPtr
473		cbFn := *cb
474
475		cbFn(fa)
476
477	}
478	cbRefPtr := purego.NewCallback(fcb)
479	glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
480	handlerID := gobject.SignalConnect(x.GoPointer(), "leave", cbRefPtr)
481	glib.SaveHandlerMapping(handlerID, cbPtr)
482	return handlerID
483}
484
485// Emitted while the pointer is moving over the drop target.
486func (x *DropTarget) ConnectMotion(cb *func(DropTarget, float64, float64) gdk.DragAction) uint {
487	cbPtr := uintptr(unsafe.Pointer(cb))
488	if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
489		handlerID := gobject.SignalConnect(x.GoPointer(), "motion", cbRefPtr)
490		glib.SaveHandlerMapping(handlerID, cbPtr)
491		return handlerID
492	}
493
494	fcb := func(clsPtr uintptr, XVarp float64, YVarp float64) gdk.DragAction {
495		fa := DropTarget{}
496		fa.Ptr = clsPtr
497		cbFn := *cb
498
499		return cbFn(fa, XVarp, YVarp)
500
501	}
502	cbRefPtr := purego.NewCallback(fcb)
503	glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
504	handlerID := gobject.SignalConnect(x.GoPointer(), "motion", cbRefPtr)
505	glib.SaveHandlerMapping(handlerID, cbPtr)
506	return handlerID
507}
508
509func init() {
510	core.SetPackageName("GTK", "gtk4")
511	core.SetSharedLibraries("GTK", []string{"libgtk-4.so.1"})
512	var libs []uintptr
513	for _, libPath := range core.GetPaths("GTK") {
514		lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
515		if err != nil {
516			panic(err)
517		}
518		libs = append(libs, lib)
519	}
520
521	core.PuregoSafeRegister(&xDropTargetGLibType, libs, "gtk_drop_target_get_type")
522
523	core.PuregoSafeRegister(&xNewDropTarget, libs, "gtk_drop_target_new")
524
525	core.PuregoSafeRegister(&xDropTargetGetActions, libs, "gtk_drop_target_get_actions")
526	core.PuregoSafeRegister(&xDropTargetGetCurrentDrop, libs, "gtk_drop_target_get_current_drop")
527	core.PuregoSafeRegister(&xDropTargetGetDrop, libs, "gtk_drop_target_get_drop")
528	core.PuregoSafeRegister(&xDropTargetGetFormats, libs, "gtk_drop_target_get_formats")
529	core.PuregoSafeRegister(&xDropTargetGetGtypes, libs, "gtk_drop_target_get_gtypes")
530	core.PuregoSafeRegister(&xDropTargetGetPreload, libs, "gtk_drop_target_get_preload")
531	core.PuregoSafeRegister(&xDropTargetGetValue, libs, "gtk_drop_target_get_value")
532	core.PuregoSafeRegister(&xDropTargetReject, libs, "gtk_drop_target_reject")
533	core.PuregoSafeRegister(&xDropTargetSetActions, libs, "gtk_drop_target_set_actions")
534	core.PuregoSafeRegister(&xDropTargetSetGtypes, libs, "gtk_drop_target_set_gtypes")
535	core.PuregoSafeRegister(&xDropTargetSetPreload, libs, "gtk_drop_target_set_preload")
536
537}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 102

↑↓ moveenter openesc close