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:
|
// Example:
|
||||||
// b := ui.GetNewButton(ui.Do, "OK")
|
// b := ui.GetNewButton(ui.Do, "OK")
|
||||||
func GetNewButton(c Doer, text string) Button {
|
func GetNewButton(c Doer, text string) Button {
|
||||||
c <- newButton(text)
|
req := newButton(text)
|
||||||
return (<-c.resp).(Button)
|
c <- req
|
||||||
|
return (<-req.resp).(Button)
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,8 @@ type widgetbase struct {
|
||||||
widget *C.GtkWidget
|
widget *C.GtkWidget
|
||||||
}
|
}
|
||||||
|
|
||||||
func newWidget(w *C.GtkWidget) *widget {
|
func newWidget(w *C.GtkWidget) *widgetbase {
|
||||||
return &widget{
|
return &widgetbase{
|
||||||
widget: w,
|
widget: w,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ func newButton(text string) *Request {
|
||||||
defer freegstr(ctext)
|
defer freegstr(ctext)
|
||||||
widget := C.gtk_button_new_with_label(ctext)
|
widget := C.gtk_button_new_with_label(ctext)
|
||||||
c <- &button{
|
c <- &button{
|
||||||
widget: newWidget(widget),
|
widgetbase: newWidget(widget),
|
||||||
button: (*C.GtkButton)(unsafe.Pointer(widget)),
|
button: (*C.GtkButton)(unsafe.Pointer(widget)),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -40,7 +40,7 @@ func newButton(text string) *Request {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Button) OnClicked(func e(c Doer)) *Request {
|
func (b *button) OnClicked(e func(c Doer)) *Request {
|
||||||
// TODO
|
// TODO
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,8 @@ import (
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
func uiinit() error {
|
func uiinit() error {
|
||||||
// TODO replace with the eerror-checking version
|
// TODO replace with the error-checking version
|
||||||
C.gtk_init()
|
C.gtk_init(nil, nil)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,6 @@ func issue(req *Request) {
|
||||||
func doissue(data C.gpointer) C.gboolean {
|
func doissue(data C.gpointer) C.gboolean {
|
||||||
req := (*Request)(unsafe.Pointer(data))
|
req := (*Request)(unsafe.Pointer(data))
|
||||||
req.op()
|
req.op()
|
||||||
close(req.done)
|
close(req.resp)
|
||||||
return C.FALSE // don't repeat
|
return C.FALSE // don't repeat
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ func NewWindow(title string, width int, height int) *Request {
|
||||||
// Example:
|
// Example:
|
||||||
// w := ui.GetNewWindow(ui.Do, "Main Window")
|
// w := ui.GetNewWindow(ui.Do, "Main Window")
|
||||||
func GetNewWindow(c Doer, title string, width int, height int) Window {
|
func GetNewWindow(c Doer, title string, width int, height int) Window {
|
||||||
c <- newWindow(title, width, height)
|
req := newWindow(title, width, height)
|
||||||
return (<-c.resp).(Window)
|
c <- req
|
||||||
|
return (<-req.resp).(Window)
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,15 +21,15 @@ func newWindow(title string, width int, height int) *Request {
|
||||||
return &Request{
|
return &Request{
|
||||||
op: func() {
|
op: func() {
|
||||||
widget := C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL)
|
widget := C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL)
|
||||||
ctext := togstr(text)
|
ctitle := togstr(title)
|
||||||
defer freegstr(ctext)
|
defer freegstr(ctitle)
|
||||||
w := &window{
|
w := &window{
|
||||||
widget: widget,
|
widget: widget,
|
||||||
container: (*C.GtkContainer)(unsafe.Pointer(widget)),
|
container: (*C.GtkContainer)(unsafe.Pointer(widget)),
|
||||||
bin: (*C.GtkBin)(unsafe.Pointer(widget)),
|
bin: (*C.GtkBin)(unsafe.Pointer(widget)),
|
||||||
window: (*C.GtkWindow)(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 size
|
||||||
// TODO content
|
// TODO content
|
||||||
c <- w
|
c <- w
|
||||||
|
@ -38,7 +38,7 @@ func newWindow(title string, width int, height int) *Request {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) SetControl(c Control) *Request {
|
func (w *window) SetControl(control Control) *Request {
|
||||||
c := make(chan interface{})
|
c := make(chan interface{})
|
||||||
return &Request{
|
return &Request{
|
||||||
op: func() {
|
op: func() {
|
||||||
|
@ -46,7 +46,7 @@ func (w *window) SetControl(c Control) *Request {
|
||||||
// TODO reparent
|
// TODO reparent
|
||||||
c <- struct{}{}
|
c <- struct{}{}
|
||||||
},
|
},
|
||||||
done: c,
|
resp: c,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,9 +64,9 @@ func (w *window) SetTitle(title string) *Request {
|
||||||
c := make(chan interface{})
|
c := make(chan interface{})
|
||||||
return &Request{
|
return &Request{
|
||||||
op: func() {
|
op: func() {
|
||||||
ctext := togstr(text)
|
ctitle := togstr(title)
|
||||||
defer freegstr(ctext)
|
defer freegstr(ctitle)
|
||||||
C.gtk_window_set_title(w.window, ctext)
|
C.gtk_window_set_title(w.window, ctitle)
|
||||||
c <- struct{}{}
|
c <- struct{}{}
|
||||||
},
|
},
|
||||||
resp: c,
|
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
|
// TODO
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue