summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-07-25 19:44:32 -0400
committerPietro Gagliardi <[email protected]>2014-07-25 19:44:32 -0400
commitd1702d33e055fb254cfacb1ad7d3d3f60314bba6 (patch)
tree34aaaa02191d3ba81907b11a885bbd57a7da74c2
parent010c97d686f8e10f940c98b62ffb5a6735f73490 (diff)
Updated the GTK+ backend to have the new parenting and sizing changes. Now to implement Tab! ...though I should probably implement the changes on Mac OS X first.
-rw-r--r--redo/controls_unix.go37
-rw-r--r--redo/sizing_unix.go7
-rw-r--r--redo/window_unix.go22
3 files changed, 31 insertions, 35 deletions
diff --git a/redo/controls_unix.go b/redo/controls_unix.go
index 9011d50..21c01e4 100644
--- a/redo/controls_unix.go
+++ b/redo/controls_unix.go
@@ -15,8 +15,6 @@ import "C"
type widgetbase struct {
widget *C.GtkWidget
- parentw *window
- floating bool
}
func newWidget(w *C.GtkWidget) *widgetbase {
@@ -27,31 +25,18 @@ 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)
- // redraw since we changed controls (by queueing a resize; thanks Jasper in irc.gimp.net/#gtk+)
- C.gtk_widget_queue_resize(w.parentw.layoutw)
- w.parentw = nil
- }
+func (w *widgetbase) setParent(c *C.GtkContainer) {
+ C.gtk_container_add(c, w.widget)
+ // make sure the new widget is shown
+ C.gtk_widget_show_all(w.widget)
}
-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
- }
- // make sure the new widget is shown
+func (w *widgetbase) containerShow() {
C.gtk_widget_show_all(w.widget)
- // redraw since we changed controls (see above)
- C.gtk_widget_queue_resize(win.layoutw)
+}
+
+func (w *widgetbase) containerHide() {
+ C.gtk_widget_hide(w.widget)
}
type button struct {
@@ -135,3 +120,7 @@ func (c *checkbox) Checked() bool {
func (c *checkbox) SetChecked(checked bool) {
C.gtk_toggle_button_set_active(c.toggle, togbool(checked))
}
+
+//TODO
+func newTab() Tab{return newButton("tab")}
+func(*button)Append(string,Control){}
diff --git a/redo/sizing_unix.go b/redo/sizing_unix.go
index caa9c8c..5b19f9e 100644
--- a/redo/sizing_unix.go
+++ b/redo/sizing_unix.go
@@ -35,11 +35,12 @@ func (w *window) beginResize() (d *sizing) {
return d
}
-func (w *window) endResize(d *sizing) {
- C.gtk_widget_queue_draw(w.widget)
+func (c *container) endResize(d *sizing) {
+ // TODO
+// C.gtk_widget_queue_draw(w.widget)
}
-func (w *window) translateAllocationCoords(allocations []*allocation, winwidth, winheight int) {
+func (c *container) translateAllocationCoords(allocations []*allocation, winwidth, winheight int) {
// no need for coordinate conversion with gtk+
}
diff --git a/redo/window_unix.go b/redo/window_unix.go
index 26675e7..6ab68b1 100644
--- a/redo/window_unix.go
+++ b/redo/window_unix.go
@@ -16,7 +16,7 @@ import "C"
type window struct {
widget *C.GtkWidget
- container *C.GtkContainer
+ wc *C.GtkContainer
bin *C.GtkBin
window *C.GtkWindow
@@ -24,28 +24,32 @@ type window struct {
layoutc *C.GtkContainer
layout *C.GtkLayout
- child Control
-
closing *event
- spaced bool
+ *container
+}
+
+type controlParent interface {
+ setParent(*C.GtkContainer)
}
-func newWindow(title string, width int, height int) *window {
+func newWindow(title string, width int, height int, control Control) *window {
widget := C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL)
ctitle := togstr(title)
defer freegstr(ctitle)
layoutw := C.gtk_layout_new(nil, nil)
w := &window{
widget: widget,
- container: (*C.GtkContainer)(unsafe.Pointer(widget)),
+ wc: (*C.GtkContainer)(unsafe.Pointer(widget)),
bin: (*C.GtkBin)(unsafe.Pointer(widget)),
window: (*C.GtkWindow)(unsafe.Pointer(widget)),
layoutw: layoutw,
layoutc: (*C.GtkContainer)(unsafe.Pointer(layoutw)),
layout: (*C.GtkLayout)(unsafe.Pointer(layoutw)),
closing: newEvent(),
+ container: new(container),
}
+ w.container.beginResize = w.beginResize
C.gtk_window_set_title(w.window, ctitle)
g_signal_connect(
C.gpointer(unsafe.Pointer(w.window)),
@@ -62,7 +66,9 @@ func newWindow(title string, width int, height int) *window {
C.GCallback(C.windowResizing),
C.gpointer(unsafe.Pointer(w)))
C.gtk_window_resize(w.window, C.gint(width), C.gint(height))
- C.gtk_container_add(w.container, layoutw)
+ C.gtk_container_add(w.wc, layoutw)
+ w.child = control
+ w.child.setParent(w.layoutc)
return w
}
@@ -105,6 +111,6 @@ func windowClosing(wid *C.GtkWidget, e *C.GdkEvent, data C.gpointer) C.gboolean
//export windowResizing
func windowResizing(wid *C.GtkWidget, r *C.GdkRectangle, data C.gpointer) {
w := (*window)(unsafe.Pointer(data))
- w.doresize(int(r.width), int(r.height))
+ w.resize(int(r.width), int(r.height))
fmt.Printf("new size %d x %d\n", r.width, r.height)
}