summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--redo/common_unix.go22
-rw-r--r--redo/controls.go5
-rw-r--r--redo/controls_unix.go12
-rw-r--r--redo/uitask_unix.go6
-rw-r--r--redo/window.go5
-rw-r--r--redo/window_unix.go20
6 files changed, 47 insertions, 23 deletions
diff --git a/redo/common_unix.go b/redo/common_unix.go
new file mode 100644
index 0000000..e495063
--- /dev/null
+++ b/redo/common_unix.go
@@ -0,0 +1,22 @@
+// 7 july 2014
+
+package ui
+
+import (
+ "unsafe"
+)
+
+// #include "gtk_unix.h"
+import "C"
+
+func fromgstr(s *C.gchar) string {
+ return C.GoString((*C.char)(unsafe.Pointer(s)))
+}
+
+func togstr(s string) *C.gchar {
+ return (*C.gchar)(unsafe.Pointer(C.CString(s)))
+}
+
+func freegstr(s *C.gchar) {
+ C.free(unsafe.Pointer(s))
+}
diff --git a/redo/controls.go b/redo/controls.go
index bc4f823..b40256a 100644
--- a/redo/controls.go
+++ b/redo/controls.go
@@ -32,6 +32,7 @@ func NewButton(text string) *Request {
// Example:
// b := ui.GetNewButton(ui.Do, "OK")
func GetNewButton(c Doer, text string) Button {
- c <- newButton(text)
- return (<-c.resp).(Button)
+ req := newButton(text)
+ c <- req
+ return (<-req.resp).(Button)
}
diff --git a/redo/controls_unix.go b/redo/controls_unix.go
index a091488..008888f 100644
--- a/redo/controls_unix.go
+++ b/redo/controls_unix.go
@@ -13,15 +13,15 @@ type widgetbase struct {
widget *C.GtkWidget
}
-func newWidget(w *C.GtkWidget) *widget {
- return &widget{
+func newWidget(w *C.GtkWidget) *widgetbase {
+ return &widgetbase{
widget: w,
}
}
type button struct {
*widgetbase
- button *C.GtkButton
+ button *C.GtkButton
}
func newButton(text string) *Request {
@@ -32,15 +32,15 @@ func newButton(text string) *Request {
defer freegstr(ctext)
widget := C.gtk_button_new_with_label(ctext)
c <- &button{
- widget: newWidget(widget),
- button: (*C.GtkButton)(unsafe.Pointer(widget)),
+ widgetbase: newWidget(widget),
+ button: (*C.GtkButton)(unsafe.Pointer(widget)),
}
},
resp: c,
}
}
-func (b *Button) OnClicked(func e(c Doer)) *Request {
+func (b *button) OnClicked(e func(c Doer)) *Request {
// TODO
return nil
}
diff --git a/redo/uitask_unix.go b/redo/uitask_unix.go
index 211349b..69e2350 100644
--- a/redo/uitask_unix.go
+++ b/redo/uitask_unix.go
@@ -12,8 +12,8 @@ import (
import "C"
func uiinit() error {
- // TODO replace with the eerror-checking version
- C.gtk_init()
+ // TODO replace with the error-checking version
+ C.gtk_init(nil, nil)
return nil
}
@@ -29,6 +29,6 @@ func issue(req *Request) {
func doissue(data C.gpointer) C.gboolean {
req := (*Request)(unsafe.Pointer(data))
req.op()
- close(req.done)
+ close(req.resp)
return C.FALSE // don't repeat
}
diff --git a/redo/window.go b/redo/window.go
index 27160c2..fd5c437 100644
--- a/redo/window.go
+++ b/redo/window.go
@@ -41,6 +41,7 @@ func NewWindow(title string, width int, height int) *Request {
// Example:
// w := ui.GetNewWindow(ui.Do, "Main Window")
func GetNewWindow(c Doer, title string, width int, height int) Window {
- c <- newWindow(title, width, height)
- return (<-c.resp).(Window)
+ req := newWindow(title, width, height)
+ c <- req
+ return (<-req.resp).(Window)
}
diff --git a/redo/window_unix.go b/redo/window_unix.go
index dddcad1..6e93fa7 100644
--- a/redo/window_unix.go
+++ b/redo/window_unix.go
@@ -21,24 +21,24 @@ func newWindow(title string, width int, height int) *Request {
return &Request{
op: func() {
widget := C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL)
- ctext := togstr(text)
- defer freegstr(ctext)
+ ctitle := togstr(title)
+ defer freegstr(ctitle)
w := &window{
widget: widget,
container: (*C.GtkContainer)(unsafe.Pointer(widget)),
bin: (*C.GtkBin)(unsafe.Pointer(widget)),
window: (*C.GtkWindow)(unsafe.Pointer(widget)),
}
- C.gtk_window_set_title(w.window, ctext)
+ C.gtk_window_set_title(w.window, ctitle)
// TODO size
// TODO content
- c <- w
+ c <- w
},
resp: c,
}
}
-func (w *window) SetControl(c Control) *Request {
+func (w *window) SetControl(control Control) *Request {
c := make(chan interface{})
return &Request{
op: func() {
@@ -46,7 +46,7 @@ func (w *window) SetControl(c Control) *Request {
// TODO reparent
c <- struct{}{}
},
- done: c,
+ resp: c,
}
}
@@ -64,9 +64,9 @@ func (w *window) SetTitle(title string) *Request {
c := make(chan interface{})
return &Request{
op: func() {
- ctext := togstr(text)
- defer freegstr(ctext)
- C.gtk_window_set_title(w.window, ctext)
+ ctitle := togstr(title)
+ defer freegstr(ctitle)
+ C.gtk_window_set_title(w.window, ctitle)
c <- struct{}{}
},
resp: c,
@@ -107,7 +107,7 @@ func (w *window) Close() *Request {
}
}
-func (w *window) OnClosing(func e(c Doer) bool) *Request {
+func (w *window) OnClosing(e func(c Doer) bool) *Request {
// TODO
return nil
}