-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidget.go
75 lines (63 loc) · 1.85 KB
/
widget.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
package gotk3extra
// #cgo pkg-config: gdk-3.0 gio-2.0 glib-2.0 gobject-2.0 gtk+-3.0
// #include <stdlib.h>
// #include <gtk/gtk.h>
// #include "widget.go.h"
// #cgo CFLAGS: -Wno-deprecated-declarations
import "C"
import (
"unsafe"
"github.com/gotk3/gotk3/glib"
"github.com/gotk3/gotk3/gtk"
)
// WrapWidget can be used to create a GTK widget instance from the given object.
func WrapWidget(obj *glib.Object) *gtk.Widget {
if obj == nil {
return nil
}
return >k.Widget{glib.InitiallyUnowned{obj}}
}
func nativeWidget(v *gtk.Widget) *C.GtkWidget {
if v == nil || v.GObject == nil {
return nil
}
p := unsafe.Pointer(v.GObject)
return C.toGtkWidget(p)
}
// GetParent is a wrapper around gtk_widget_get_parent().
func GetParent(v *gtk.Widget) (gtk.IWidget, error) {
c := C.gtk_widget_get_parent(nativeWidget(v))
if c == nil {
return nil, nilPtrErr
}
return CastWidget(c)
}
// GetWidgetBuildableName is a wrapper around GetBuildableName().
// It can be used to get the "buildable id" of any widget.
func GetWidgetBuildableName(v *gtk.Widget) (string, error) {
if v == nil || v.Object == nil {
return "", nilPtrErr
}
return GetBuildableName(v.Object)
}
// GetWidgetTemplateChild is a wrapper around gtk_widget_get_template_child().
// This will only report children which were previously declared with
// gtk_widget_class_bind_template_child_full() or one of its variants.
// In other case, it will return an error.
func GetWidgetTemplateChild(vv gtk.IWidget, name string) (*glib.Object, error) {
if vv == nil {
return nil, nilPtrErr
}
v := vv.ToWidget()
if v.Object == nil {
return nil, nilPtrErr
}
widget := nativeWidget(v)
gtype := C.GType(v.Object.TypeFromInstance())
c := C.gtk_widget_get_template_child(widget, gtype, (*C.gchar)(C.CString(name)))
obj := glib.Take(unsafe.Pointer(c))
if obj == nil {
return nil, nilPtrErr
}
return obj, nil
}