blob: 133ce12b0bbf79e2dacdd86bfb9827a79bf11da5 (
plain)
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
|
package glib
// #include <gio/gio.h>
// #include <glib.h>
// #include <glib-object.h>
// #include "glib.go.h"
import "C"
import "unsafe"
type BindingFlags int
const (
BINDING_DEFAULT BindingFlags = C.G_BINDING_DEFAULT
BINDING_BIDIRECTIONAL BindingFlags = C.G_BINDING_BIDIRECTIONAL
BINDING_SYNC_CREATE = C.G_BINDING_SYNC_CREATE
BINDING_INVERT_BOOLEAN = C.G_BINDING_INVERT_BOOLEAN
)
type Binding struct {
*Object
}
func (v *Binding) native() *C.GBinding {
if v == nil || v.GObject == nil {
return nil
}
return C.toGBinding(unsafe.Pointer(v.GObject))
}
func marshalBinding(p uintptr) (interface{}, error) {
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
return &Binding{wrapObject(unsafe.Pointer(c))}, nil
}
// Creates a binding between source property on source and target property on
// target . Whenever the source property is changed the target_property is
// updated using the same value.
func BindProperty(source *Object, sourceProperty string,
target *Object, targetProperty string,
flags BindingFlags) *Binding {
srcStr := (*C.gchar)(C.CString(sourceProperty))
defer C.free(unsafe.Pointer(srcStr))
tgtStr := (*C.gchar)(C.CString(targetProperty))
defer C.free(unsafe.Pointer(tgtStr))
obj := C.g_object_bind_property(
C.gpointer(source.GObject), srcStr,
C.gpointer(target.GObject), tgtStr,
C.GBindingFlags(flags),
)
if obj == nil {
return nil
}
return &Binding{wrapObject(unsafe.Pointer(obj))}
}
// Explicitly releases the binding between the source and the target property
// expressed by Binding
func (v *Binding) Unbind() {
C.g_binding_unbind(v.native())
}
// Retrieves the GObject instance used as the source of the binding
func (v *Binding) GetSource() *Object {
obj := C.g_binding_get_source(v.native())
if obj == nil {
return nil
}
return wrapObject(unsafe.Pointer(obj))
}
// Retrieves the name of the property of “source” used as the source of
// the binding.
func (v *Binding) GetSourceProperty() string {
s := C.g_binding_get_source_property(v.native())
return C.GoString((*C.char)(s))
}
// Retrieves the GObject instance used as the target of the binding.
func (v *Binding) GetTarget() *Object {
obj := C.g_binding_get_target(v.native())
if obj == nil {
return nil
}
return wrapObject(unsafe.Pointer(obj))
}
// Retrieves the name of the property of “target” used as the target of
// the binding.
func (v *Binding) GetTargetProperty() string {
s := C.g_binding_get_target_property(v.native())
return C.GoString((*C.char)(s))
}
// Retrieves the flags passed when constructing the GBinding.
func (v *Binding) GetFlags() BindingFlags {
flags := C.g_binding_get_flags(v.native())
return BindingFlags(flags)
}
|