/
gtksourcespacedrawer.go
476 lines (405 loc) · 14.3 KB
/
gtksourcespacedrawer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
// Code generated by girgen. DO NOT EDIT.
package gtksource
import (
"fmt"
"runtime"
"strings"
"unsafe"
"github.com/diamondburned/gotk4/pkg/core/gextras"
coreglib "github.com/diamondburned/gotk4/pkg/core/glib"
"github.com/diamondburned/gotk4/pkg/gio/v2"
"github.com/diamondburned/gotk4/pkg/glib/v2"
)
// #include <stdlib.h>
// #include <glib-object.h>
// #include <gtksourceview/gtksource.h>
import "C"
// GType values.
var (
GTypeSpaceLocationFlags = coreglib.Type(C.gtk_source_space_location_flags_get_type())
GTypeSpaceTypeFlags = coreglib.Type(C.gtk_source_space_type_flags_get_type())
GTypeSpaceDrawer = coreglib.Type(C.gtk_source_space_drawer_get_type())
)
func init() {
coreglib.RegisterGValueMarshalers([]coreglib.TypeMarshaler{
coreglib.TypeMarshaler{T: GTypeSpaceLocationFlags, F: marshalSpaceLocationFlags},
coreglib.TypeMarshaler{T: GTypeSpaceTypeFlags, F: marshalSpaceTypeFlags},
coreglib.TypeMarshaler{T: GTypeSpaceDrawer, F: marshalSpaceDrawer},
})
}
// SpaceLocationFlags contains flags for white space locations.
//
// If a line contains only white spaces (no text), the white spaces match both
// GTK_SOURCE_SPACE_LOCATION_LEADING and GTK_SOURCE_SPACE_LOCATION_TRAILING.
type SpaceLocationFlags C.guint
const (
// SourceSpaceLocationNone: no flags.
SourceSpaceLocationNone SpaceLocationFlags = 0b0
// SourceSpaceLocationLeading: leading white spaces on a line, i.e.
// the indentation.
SourceSpaceLocationLeading SpaceLocationFlags = 0b1
// SourceSpaceLocationInsideText: white spaces inside a line of text.
SourceSpaceLocationInsideText SpaceLocationFlags = 0b10
// SourceSpaceLocationTrailing: trailing white spaces on a line.
SourceSpaceLocationTrailing SpaceLocationFlags = 0b100
// SourceSpaceLocationAll: white spaces anywhere.
SourceSpaceLocationAll SpaceLocationFlags = 0b111
)
func marshalSpaceLocationFlags(p uintptr) (interface{}, error) {
return SpaceLocationFlags(coreglib.ValueFromNative(unsafe.Pointer(p)).Flags()), nil
}
// String returns the names in string for SpaceLocationFlags.
func (s SpaceLocationFlags) String() string {
if s == 0 {
return "SpaceLocationFlags(0)"
}
var builder strings.Builder
builder.Grow(131)
for s != 0 {
next := s & (s - 1)
bit := s - next
switch bit {
case SourceSpaceLocationNone:
builder.WriteString("None|")
case SourceSpaceLocationLeading:
builder.WriteString("Leading|")
case SourceSpaceLocationInsideText:
builder.WriteString("InsideText|")
case SourceSpaceLocationTrailing:
builder.WriteString("Trailing|")
case SourceSpaceLocationAll:
builder.WriteString("All|")
default:
builder.WriteString(fmt.Sprintf("SpaceLocationFlags(0b%b)|", bit))
}
s = next
}
return strings.TrimSuffix(builder.String(), "|")
}
// Has returns true if s contains other.
func (s SpaceLocationFlags) Has(other SpaceLocationFlags) bool {
return (s & other) == other
}
// SpaceTypeFlags contains flags for white space types.
type SpaceTypeFlags C.guint
const (
// SourceSpaceTypeNone: no flags.
SourceSpaceTypeNone SpaceTypeFlags = 0b0
// SourceSpaceTypeSpace: space character.
SourceSpaceTypeSpace SpaceTypeFlags = 0b1
// SourceSpaceTypeTab: tab character.
SourceSpaceTypeTab SpaceTypeFlags = 0b10
// SourceSpaceTypeNewline: line break character. If the
// SourceBuffer:implicit-trailing-newline property is TRUE,
// SourceSpaceDrawer also draws a line break at the end of the buffer.
SourceSpaceTypeNewline SpaceTypeFlags = 0b100
// SourceSpaceTypeNbsp: non-breaking space character.
SourceSpaceTypeNbsp SpaceTypeFlags = 0b1000
// SourceSpaceTypeAll: all white spaces.
SourceSpaceTypeAll SpaceTypeFlags = 0b1111
)
func marshalSpaceTypeFlags(p uintptr) (interface{}, error) {
return SpaceTypeFlags(coreglib.ValueFromNative(unsafe.Pointer(p)).Flags()), nil
}
// String returns the names in string for SpaceTypeFlags.
func (s SpaceTypeFlags) String() string {
if s == 0 {
return "SpaceTypeFlags(0)"
}
var builder strings.Builder
builder.Grow(121)
for s != 0 {
next := s & (s - 1)
bit := s - next
switch bit {
case SourceSpaceTypeNone:
builder.WriteString("None|")
case SourceSpaceTypeSpace:
builder.WriteString("Space|")
case SourceSpaceTypeTab:
builder.WriteString("Tab|")
case SourceSpaceTypeNewline:
builder.WriteString("Newline|")
case SourceSpaceTypeNbsp:
builder.WriteString("Nbsp|")
case SourceSpaceTypeAll:
builder.WriteString("All|")
default:
builder.WriteString(fmt.Sprintf("SpaceTypeFlags(0b%b)|", bit))
}
s = next
}
return strings.TrimSuffix(builder.String(), "|")
}
// Has returns true if s contains other.
func (s SpaceTypeFlags) Has(other SpaceTypeFlags) bool {
return (s & other) == other
}
// SpaceDrawerOverrides contains methods that are overridable.
type SpaceDrawerOverrides struct {
}
func defaultSpaceDrawerOverrides(v *SpaceDrawer) SpaceDrawerOverrides {
return SpaceDrawerOverrides{}
}
// SpaceDrawer: represent white space characters with symbols.
//
// SourceSpaceDrawer provides a way to visualize white spaces, by drawing
// symbols.
//
// Call view.GetSpaceDrawer to get the GtkSourceSpaceDrawer instance of a
// certain view.
//
// By default, no white spaces are drawn because the spacedrawer:enable-matrix
// is FALSE.
//
// To draw white spaces, spacedrawer.SetTypesForLocations can be called to set
// the spacedrawer:matrix property (by default all space types are enabled at
// all locations). Then call spacedrawer.SetEnableMatrix.
//
// For a finer-grained method, there is also the tag's tag:draw-spaces property.
//
// # Example
//
// To draw non-breaking spaces everywhere and draw all types of trailing spaces
// except newlines:
//
// gtk_source_space_drawer_set_types_for_locations (space_drawer,
// GTK_SOURCE_SPACE_LOCATION_ALL,
// GTK_SOURCE_SPACE_TYPE_NBSP);
//
// gtk_source_space_drawer_set_types_for_locations (space_drawer,
// GTK_SOURCE_SPACE_LOCATION_TRAILING,
// GTK_SOURCE_SPACE_TYPE_ALL &
// ~GTK_SOURCE_SPACE_TYPE_NEWLINE);
//
// gtk_source_space_drawer_set_enable_matrix (space_drawer, TRUE);
//
// Use-case: draw unwanted white spaces
//
// A possible use-case is to draw only unwanted white spaces. Examples:
//
// - Draw all trailing spaces.
//
// - If the indentation and alignment must be done with spaces, draw tabs.
//
// And non-breaking spaces can always be drawn, everywhere, to distinguish them
// from normal spaces.
type SpaceDrawer struct {
_ [0]func() // equal guard
*coreglib.Object
}
var (
_ coreglib.Objector = (*SpaceDrawer)(nil)
)
func init() {
coreglib.RegisterClassInfo[*SpaceDrawer, *SpaceDrawerClass, SpaceDrawerOverrides](
GTypeSpaceDrawer,
initSpaceDrawerClass,
wrapSpaceDrawer,
defaultSpaceDrawerOverrides,
)
}
func initSpaceDrawerClass(gclass unsafe.Pointer, overrides SpaceDrawerOverrides, classInitFunc func(*SpaceDrawerClass)) {
if classInitFunc != nil {
class := (*SpaceDrawerClass)(gextras.NewStructNative(gclass))
classInitFunc(class)
}
}
func wrapSpaceDrawer(obj *coreglib.Object) *SpaceDrawer {
return &SpaceDrawer{
Object: obj,
}
}
func marshalSpaceDrawer(p uintptr) (interface{}, error) {
return wrapSpaceDrawer(coreglib.ValueFromNative(unsafe.Pointer(p)).Object()), nil
}
// NewSpaceDrawer creates a new SourceSpaceDrawer object.
//
// Useful for storing space drawing settings independently of a view.
//
// The function returns the following values:
//
// - spaceDrawer: new SourceSpaceDrawer.
//
func NewSpaceDrawer() *SpaceDrawer {
var _cret *C.GtkSourceSpaceDrawer // in
_cret = C.gtk_source_space_drawer_new()
var _spaceDrawer *SpaceDrawer // out
_spaceDrawer = wrapSpaceDrawer(coreglib.AssumeOwnership(unsafe.Pointer(_cret)))
return _spaceDrawer
}
// BindMatrixSetting binds the spacedrawer:matrix property to a gio.Settings
// key.
//
// The gio.Settings key must be of the same type as the spacedrawer:matrix
// property, that is, "au".
//
// The gio.Settings.Bind() function cannot be used, because the default GIO
// mapping functions don't support glib.Variant properties (maybe it will
// be supported by a future GIO version, in which case this function can be
// deprecated).
//
// The function takes the following parameters:
//
// - settings #GSettings object.
// - key settings key to bind.
// - flags for the binding.
//
func (drawer *SpaceDrawer) BindMatrixSetting(settings *gio.Settings, key string, flags gio.SettingsBindFlags) {
var _arg0 *C.GtkSourceSpaceDrawer // out
var _arg1 *C.GSettings // out
var _arg2 *C.gchar // out
var _arg3 C.GSettingsBindFlags // out
_arg0 = (*C.GtkSourceSpaceDrawer)(unsafe.Pointer(coreglib.InternObject(drawer).Native()))
_arg1 = (*C.GSettings)(unsafe.Pointer(coreglib.InternObject(settings).Native()))
_arg2 = (*C.gchar)(unsafe.Pointer(C.CString(key)))
defer C.free(unsafe.Pointer(_arg2))
_arg3 = C.GSettingsBindFlags(flags)
C.gtk_source_space_drawer_bind_matrix_setting(_arg0, _arg1, _arg2, _arg3)
runtime.KeepAlive(drawer)
runtime.KeepAlive(settings)
runtime.KeepAlive(key)
runtime.KeepAlive(flags)
}
// The function returns the following values:
//
// - ok: whether the SourceSpaceDrawer:matrix property is enabled.
//
func (drawer *SpaceDrawer) EnableMatrix() bool {
var _arg0 *C.GtkSourceSpaceDrawer // out
var _cret C.gboolean // in
_arg0 = (*C.GtkSourceSpaceDrawer)(unsafe.Pointer(coreglib.InternObject(drawer).Native()))
_cret = C.gtk_source_space_drawer_get_enable_matrix(_arg0)
runtime.KeepAlive(drawer)
var _ok bool // out
if _cret != 0 {
_ok = true
}
return _ok
}
// Matrix gets the value of the spacedrawer:matrix property, as a glib.Variant.
//
// An empty array can be returned in case the matrix is a zero matrix.
//
// The spacedrawer.GetTypesForLocations function may be more convenient to use.
//
// The function returns the following values:
//
// - variant value as a new floating #GVariant instance.
//
func (drawer *SpaceDrawer) Matrix() *glib.Variant {
var _arg0 *C.GtkSourceSpaceDrawer // out
var _cret *C.GVariant // in
_arg0 = (*C.GtkSourceSpaceDrawer)(unsafe.Pointer(coreglib.InternObject(drawer).Native()))
_cret = C.gtk_source_space_drawer_get_matrix(_arg0)
runtime.KeepAlive(drawer)
var _variant *glib.Variant // out
_variant = (*glib.Variant)(gextras.NewStructNative(unsafe.Pointer(_cret)))
runtime.SetFinalizer(
gextras.StructIntern(unsafe.Pointer(_variant)),
func(intern *struct{ C unsafe.Pointer }) {
C.g_variant_unref((*C.GVariant)(intern.C))
},
)
return _variant
}
// TypesForLocations: if only one location is specified, this function returns
// what kind of white spaces are drawn at that location.
//
// The value is retrieved from the spacedrawer:matrix property.
//
// If several locations are specified, this function returns the logical AND
// for those locations. Which means that if a certain kind of white space is
// present in the return value, then that kind of white space is drawn at all
// the specified locations.
//
// The function takes the following parameters:
//
// - locations: one or several SourceSpaceLocationFlags.
//
// The function returns the following values:
//
// - spaceTypeFlags: combination of SourceSpaceTypeFlags.
//
func (drawer *SpaceDrawer) TypesForLocations(locations SpaceLocationFlags) SpaceTypeFlags {
var _arg0 *C.GtkSourceSpaceDrawer // out
var _arg1 C.GtkSourceSpaceLocationFlags // out
var _cret C.GtkSourceSpaceTypeFlags // in
_arg0 = (*C.GtkSourceSpaceDrawer)(unsafe.Pointer(coreglib.InternObject(drawer).Native()))
_arg1 = C.GtkSourceSpaceLocationFlags(locations)
_cret = C.gtk_source_space_drawer_get_types_for_locations(_arg0, _arg1)
runtime.KeepAlive(drawer)
runtime.KeepAlive(locations)
var _spaceTypeFlags SpaceTypeFlags // out
_spaceTypeFlags = SpaceTypeFlags(_cret)
return _spaceTypeFlags
}
// SetEnableMatrix sets whether the spacedrawer:matrix property is enabled.
//
// The function takes the following parameters:
//
// - enableMatrix: new value.
//
func (drawer *SpaceDrawer) SetEnableMatrix(enableMatrix bool) {
var _arg0 *C.GtkSourceSpaceDrawer // out
var _arg1 C.gboolean // out
_arg0 = (*C.GtkSourceSpaceDrawer)(unsafe.Pointer(coreglib.InternObject(drawer).Native()))
if enableMatrix {
_arg1 = C.TRUE
}
C.gtk_source_space_drawer_set_enable_matrix(_arg0, _arg1)
runtime.KeepAlive(drawer)
runtime.KeepAlive(enableMatrix)
}
// SetMatrix sets a new value to the spacedrawer:matrix property, as a
// glib.Variant.
//
// If matrix is NULL, then an empty array is set.
//
// If matrix is floating, it is consumed.
//
// The spacedrawer.SetTypesForLocations function may be more convenient to use.
//
// The function takes the following parameters:
//
// - matrix (optional): new matrix value, or NULL.
//
func (drawer *SpaceDrawer) SetMatrix(matrix *glib.Variant) {
var _arg0 *C.GtkSourceSpaceDrawer // out
var _arg1 *C.GVariant // out
_arg0 = (*C.GtkSourceSpaceDrawer)(unsafe.Pointer(coreglib.InternObject(drawer).Native()))
if matrix != nil {
_arg1 = (*C.GVariant)(gextras.StructNative(unsafe.Pointer(matrix)))
}
C.gtk_source_space_drawer_set_matrix(_arg0, _arg1)
runtime.KeepAlive(drawer)
runtime.KeepAlive(matrix)
}
// SetTypesForLocations modifies the spacedrawer:matrix property at the
// specified locations.
//
// The function takes the following parameters:
//
// - locations: one or several SourceSpaceLocationFlags.
// - types: combination of SourceSpaceTypeFlags.
//
func (drawer *SpaceDrawer) SetTypesForLocations(locations SpaceLocationFlags, types SpaceTypeFlags) {
var _arg0 *C.GtkSourceSpaceDrawer // out
var _arg1 C.GtkSourceSpaceLocationFlags // out
var _arg2 C.GtkSourceSpaceTypeFlags // out
_arg0 = (*C.GtkSourceSpaceDrawer)(unsafe.Pointer(coreglib.InternObject(drawer).Native()))
_arg1 = C.GtkSourceSpaceLocationFlags(locations)
_arg2 = C.GtkSourceSpaceTypeFlags(types)
C.gtk_source_space_drawer_set_types_for_locations(_arg0, _arg1, _arg2)
runtime.KeepAlive(drawer)
runtime.KeepAlive(locations)
runtime.KeepAlive(types)
}
// SpaceDrawerClass: instance of this type is always passed by reference.
type SpaceDrawerClass struct {
*spaceDrawerClass
}
// spaceDrawerClass is the struct that's finalized.
type spaceDrawerClass struct {
native *C.GtkSourceSpaceDrawerClass
}