summaryrefslogtreecommitdiff
path: root/redo/controls_unix.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-07-15 20:48:16 -0400
committerPietro Gagliardi <[email protected]>2014-07-15 20:48:16 -0400
commit5ebd89984ac63c30a68a325a430038979badc3a0 (patch)
tree7493574d046fb9a048edf610e6d60fafae58e8df /redo/controls_unix.go
parent474436e9f6e84f26edd08bfcff16d62a3cd40175 (diff)
Added parenting/unparenting of controls to the GTK+ backend and the test program.
Diffstat (limited to 'redo/controls_unix.go')
-rw-r--r--redo/controls_unix.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/redo/controls_unix.go b/redo/controls_unix.go
index 1be152b..e48aab2 100644
--- a/redo/controls_unix.go
+++ b/redo/controls_unix.go
@@ -13,6 +13,8 @@ import "C"
type widgetbase struct {
widget *C.GtkWidget
+ parentw *window
+ floating bool
}
func newWidget(w *C.GtkWidget) *widgetbase {
@@ -21,6 +23,29 @@ func newWidget(w *C.GtkWidget) *widgetbase {
}
}
+// these few methods are embedded by all the various Controls since they all will do the same thing
+
+func (w *widgetbase) unparent() {
+ if w.parentw != nil {
+ // add another reference so it doesn't get removed by accident
+ C.g_object_ref(C.gpointer(unsafe.Pointer(w.widget)))
+ // we unref this in parent() below
+ w.floating = true
+ C.gtk_container_remove(w.parentw.layoutc, w.widget)
+ w.parentw = nil
+ }
+}
+
+func (w *widgetbase) parent(win *window) {
+ C.gtk_container_add(win.layoutc, w.widget)
+ w.parentw = win
+ // was previously parented; unref our saved ref
+ if w.floating {
+ C.g_object_unref(C.gpointer(unsafe.Pointer(w.widget)))
+ w.floating = false
+ }
+}
+
type button struct {
*widgetbase
button *C.GtkButton