Fixed most compilation errors and added GTK+ string helper functions to common_unix.go.
This commit is contained in:
parent
dccf548ffa
commit
d874148760
|
@ -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))
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue