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// The type of a function that can be registered with gdk_content_register_serializer().
17//
18// When the function gets called to operate on content, it can call functions on the
19// @serializer object to obtain the mime type, output stream, user data, etc. for its
20// operation.
21type ContentSerializeFunc func(uintptr)
22
23var xContentRegisterSerializer func(types.GType, string, uintptr, uintptr, uintptr)
24
25// Registers a function to serialize objects of a given type.
26//
27// Since 4.20, when looking up a serializer to use, GTK will
28// use the last registered serializer for a given mime type,
29// so applications can override the built-in serializers.
30func ContentRegisterSerializer(TypeVar types.GType, MimeTypeVar string, SerializeVar *ContentSerializeFunc, DataVar uintptr, NotifyVar *glib.DestroyNotify) {
31
32 var SerializeVarRef uintptr
33 if SerializeVar != nil {
34 SerializeVarPtr := uintptr(unsafe.Pointer(SerializeVar))
35 if cbRefPtr, ok := glib.GetCallback(SerializeVarPtr); ok {
36 SerializeVarRef = cbRefPtr
37 } else {
38 fcb := func(arg0 uintptr) {
39 cbFn := *SerializeVar
40 cbFn(arg0)
41 }
42 SerializeVarRef = purego.NewCallback(fcb)
43 glib.SaveCallbackWithClosure(SerializeVarPtr, SerializeVarRef, SerializeVar)
44 }
45 }
46
47 var NotifyVarRef uintptr
48 if NotifyVar != nil {
49 NotifyVarPtr := uintptr(unsafe.Pointer(NotifyVar))
50 if cbRefPtr, ok := glib.GetCallback(NotifyVarPtr); ok {
51 NotifyVarRef = cbRefPtr
52 } else {
53 fcb := func(arg0 uintptr) {
54 cbFn := *NotifyVar
55 cbFn(arg0)
56 }
57 NotifyVarRef = purego.NewCallback(fcb)
58 glib.SaveCallbackWithClosure(NotifyVarPtr, NotifyVarRef, NotifyVar)
59 }
60 }
61
62 xContentRegisterSerializer(TypeVar, MimeTypeVar, SerializeVarRef, DataVar, NotifyVarRef)
63
64}
65
66var xContentSerializeAsync func(uintptr, string, *gobject.Value, int, uintptr, uintptr, uintptr)
67
68// Serialize content and write it to the given output stream, asynchronously.
69//
70// The default I/O priority is %G_PRIORITY_DEFAULT (i.e. 0), and lower numbers
71// indicate a higher priority.
72func ContentSerializeAsync(StreamVar *gio.OutputStream, MimeTypeVar string, ValueVar *gobject.Value, IoPriorityVar int, CancellableVar *gio.Cancellable, CallbackVar *gio.AsyncReadyCallback, UserDataVar uintptr) {
73
74 var CallbackVarRef uintptr
75 if CallbackVar != nil {
76 CallbackVarPtr := uintptr(unsafe.Pointer(CallbackVar))
77 if cbRefPtr, ok := glib.GetCallback(CallbackVarPtr); ok {
78 CallbackVarRef = cbRefPtr
79 } else {
80 fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) {
81 cbFn := *CallbackVar
82 cbFn(arg0, arg1, arg2)
83 }
84 CallbackVarRef = purego.NewCallback(fcb)
85 glib.SaveCallbackWithClosure(CallbackVarPtr, CallbackVarRef, CallbackVar)
86 }
87 }
88
89 xContentSerializeAsync(StreamVar.GoPointer(), MimeTypeVar, ValueVar, IoPriorityVar, CancellableVar.GoPointer(), CallbackVarRef, UserDataVar)
90
91}
92
93var xContentSerializeFinish func(uintptr, **glib.Error) bool
94
95// Finishes a content serialization operation.
96func ContentSerializeFinish(ResultVar gio.AsyncResult) (bool, error) {
97 var cerr *glib.Error
98
99 cret := xContentSerializeFinish(ResultVar.GoPointer(), &cerr)
100 if cerr == nil {
101 return cret, nil
102 }
103 return cret, cerr
104
105}
106
107// Serializes content for inter-application data transfers.
108//
109// The `GdkContentSerializer` transforms an object that is identified
110// by a GType into a serialized form (i.e. a byte stream) that is
111// identified by a mime type.
112//
113// GTK provides serializers and deserializers for common data types
114// such as text, colors, images or file lists. To register your own
115// serialization functions, use [func@Gdk.content_register_serializer].
116//
117// Also see [class@Gdk.ContentDeserializer].
118type ContentSerializer struct {
119 gobject.Object
120}
121
122var xContentSerializerGLibType func() types.GType
123
124func ContentSerializerGLibType() types.GType {
125 return xContentSerializerGLibType()
126}
127
128func ContentSerializerNewFromInternalPtr(ptr uintptr) *ContentSerializer {
129 cls := &ContentSerializer{}
130 cls.Ptr = ptr
131 return cls
132}
133
134var xContentSerializerGetCancellable func(uintptr) uintptr
135
136// Gets the cancellable for the current operation.
137//
138// This is the `GCancellable` that was passed to [func@content_serialize_async].
139func (x *ContentSerializer) GetCancellable() *gio.Cancellable {
140 var cls *gio.Cancellable
141
142 cret := xContentSerializerGetCancellable(x.GoPointer())
143
144 if cret == 0 {
145 return nil
146 }
147 gobject.IncreaseRef(cret)
148 cls = &gio.Cancellable{}
149 cls.Ptr = cret
150 return cls
151}
152
153var xContentSerializerGetGtype func(uintptr) types.GType
154
155// Gets the `GType` to of the object to serialize.
156func (x *ContentSerializer) GetGtype() types.GType {
157
158 cret := xContentSerializerGetGtype(x.GoPointer())
159 return cret
160}
161
162var xContentSerializerGetMimeType func(uintptr) string
163
164// Gets the mime type to serialize to.
165func (x *ContentSerializer) GetMimeType() string {
166
167 cret := xContentSerializerGetMimeType(x.GoPointer())
168 return cret
169}
170
171var xContentSerializerGetOutputStream func(uintptr) uintptr
172
173// Gets the output stream for the current operation.
174//
175// This is the stream that was passed to [func@content_serialize_async].
176func (x *ContentSerializer) GetOutputStream() *gio.OutputStream {
177 var cls *gio.OutputStream
178
179 cret := xContentSerializerGetOutputStream(x.GoPointer())
180
181 if cret == 0 {
182 return nil
183 }
184 gobject.IncreaseRef(cret)
185 cls = &gio.OutputStream{}
186 cls.Ptr = cret
187 return cls
188}
189
190var xContentSerializerGetPriority func(uintptr) int
191
192// Gets the I/O priority for the current operation.
193//
194// This is the priority that was passed to [func@content_serialize_async].
195func (x *ContentSerializer) GetPriority() int {
196
197 cret := xContentSerializerGetPriority(x.GoPointer())
198 return cret
199}
200
201var xContentSerializerGetTaskData func(uintptr) uintptr
202
203// Gets the data that was associated with the current operation.
204//
205// See [method@Gdk.ContentSerializer.set_task_data].
206func (x *ContentSerializer) GetTaskData() uintptr {
207
208 cret := xContentSerializerGetTaskData(x.GoPointer())
209 return cret
210}
211
212var xContentSerializerGetUserData func(uintptr) uintptr
213
214// Gets the user data that was passed when the serializer was registered.
215func (x *ContentSerializer) GetUserData() uintptr {
216
217 cret := xContentSerializerGetUserData(x.GoPointer())
218 return cret
219}
220
221var xContentSerializerGetValue func(uintptr) *gobject.Value
222
223// Gets the `GValue` to read the object to serialize from.
224func (x *ContentSerializer) GetValue() *gobject.Value {
225
226 cret := xContentSerializerGetValue(x.GoPointer())
227 return cret
228}
229
230var xContentSerializerReturnError func(uintptr, *glib.Error)
231
232// Indicate that the serialization has ended with an error.
233//
234// This function consumes @error.
235func (x *ContentSerializer) ReturnError(ErrorVar *glib.Error) {
236
237 xContentSerializerReturnError(x.GoPointer(), ErrorVar)
238
239}
240
241var xContentSerializerReturnSuccess func(uintptr)
242
243// Indicate that the serialization has been successfully completed.
244func (x *ContentSerializer) ReturnSuccess() {
245
246 xContentSerializerReturnSuccess(x.GoPointer())
247
248}
249
250var xContentSerializerSetTaskData func(uintptr, uintptr, uintptr)
251
252// Associate data with the current serialization operation.
253func (x *ContentSerializer) SetTaskData(DataVar uintptr, NotifyVar *glib.DestroyNotify) {
254
255 var NotifyVarRef uintptr
256 if NotifyVar != nil {
257 NotifyVarPtr := uintptr(unsafe.Pointer(NotifyVar))
258 if cbRefPtr, ok := glib.GetCallback(NotifyVarPtr); ok {
259 NotifyVarRef = cbRefPtr
260 } else {
261 fcb := func(arg0 uintptr) {
262 cbFn := *NotifyVar
263 cbFn(arg0)
264 }
265 NotifyVarRef = purego.NewCallback(fcb)
266 glib.SaveCallbackWithClosure(NotifyVarPtr, NotifyVarRef, NotifyVar)
267 }
268 }
269
270 xContentSerializerSetTaskData(x.GoPointer(), DataVar, NotifyVarRef)
271
272}
273
274func (c *ContentSerializer) GoPointer() uintptr {
275 if c == nil {
276 return 0
277 }
278 return c.Ptr
279}
280
281func (c *ContentSerializer) SetGoPointer(ptr uintptr) {
282 c.Ptr = ptr
283}
284
285// Gets the source object from a [iface@Gio.AsyncResult].
286func (x *ContentSerializer) GetSourceObject() *gobject.Object {
287 var cls *gobject.Object
288
289 cret := gio.XGAsyncResultGetSourceObject(x.GoPointer())
290
291 if cret == 0 {
292 return nil
293 }
294 cls = &gobject.Object{}
295 cls.Ptr = cret
296 return cls
297}
298
299// Checks if @res has the given @source_tag (generally a function
300// pointer indicating the function @res was created by).
301func (x *ContentSerializer) IsTagged(SourceTagVar uintptr) bool {
302
303 cret := gio.XGAsyncResultIsTagged(x.GoPointer(), SourceTagVar)
304 return cret
305}
306
307// If @res is a [class@Gio.SimpleAsyncResult], this is equivalent to
308// [method@Gio.SimpleAsyncResult.propagate_error]. Otherwise it returns
309// `FALSE`.
310//
311// This can be used for legacy error handling in async `*_finish()`
312// wrapper functions that traditionally handled [class@Gio.SimpleAsyncResult]
313// error returns themselves rather than calling into the virtual method.
314// This should not be used in new code; [iface@Gio.AsyncResult] errors that are
315// set by virtual methods should also be extracted by virtual methods,
316// to enable subclasses to chain up correctly.
317func (x *ContentSerializer) LegacyPropagateError() (bool, error) {
318 var cerr *glib.Error
319
320 cret := gio.XGAsyncResultLegacyPropagateError(x.GoPointer())
321 if cerr == nil {
322 return cret, nil
323 }
324 return cret, cerr
325
326}
327
328func init() {
329 core.SetPackageName("GDK", "gtk4")
330 core.SetSharedLibraries("GDK", []string{"libgtk-4.so.1"})
331 var libs []uintptr
332 for _, libPath := range core.GetPaths("GDK") {
333 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
334 if err != nil {
335 panic(err)
336 }
337 libs = append(libs, lib)
338 }
339
340 core.PuregoSafeRegister(&xContentRegisterSerializer, libs, "gdk_content_register_serializer")
341 core.PuregoSafeRegister(&xContentSerializeAsync, libs, "gdk_content_serialize_async")
342 core.PuregoSafeRegister(&xContentSerializeFinish, libs, "gdk_content_serialize_finish")
343
344 core.PuregoSafeRegister(&xContentSerializerGLibType, libs, "gdk_content_serializer_get_type")
345
346 core.PuregoSafeRegister(&xContentSerializerGetCancellable, libs, "gdk_content_serializer_get_cancellable")
347 core.PuregoSafeRegister(&xContentSerializerGetGtype, libs, "gdk_content_serializer_get_gtype")
348 core.PuregoSafeRegister(&xContentSerializerGetMimeType, libs, "gdk_content_serializer_get_mime_type")
349 core.PuregoSafeRegister(&xContentSerializerGetOutputStream, libs, "gdk_content_serializer_get_output_stream")
350 core.PuregoSafeRegister(&xContentSerializerGetPriority, libs, "gdk_content_serializer_get_priority")
351 core.PuregoSafeRegister(&xContentSerializerGetTaskData, libs, "gdk_content_serializer_get_task_data")
352 core.PuregoSafeRegister(&xContentSerializerGetUserData, libs, "gdk_content_serializer_get_user_data")
353 core.PuregoSafeRegister(&xContentSerializerGetValue, libs, "gdk_content_serializer_get_value")
354 core.PuregoSafeRegister(&xContentSerializerReturnError, libs, "gdk_content_serializer_return_error")
355 core.PuregoSafeRegister(&xContentSerializerReturnSuccess, libs, "gdk_content_serializer_return_success")
356 core.PuregoSafeRegister(&xContentSerializerSetTaskData, libs, "gdk_content_serializer_set_task_data")
357
358}