Added the GTK+ equivalent of Window.Title() and Button.Text() in preparation for adding the GTK+ implementation of Combobox.

This commit is contained in:
Pietro Gagliardi 2014-02-16 18:57:50 -05:00
parent 161e874d8a
commit 13d4e1d258
2 changed files with 20 additions and 2 deletions

View File

@ -15,6 +15,8 @@ import (
// void gSignalConnect(GtkWidget *widget, char *signal, GCallback callback, void *data) { g_signal_connect(widget, signal, callback, data); }
import "C"
// BIG TODO reduce the amount of explicit casting
type (
gtkWidget C.GtkWidget
)
@ -76,6 +78,10 @@ func gtk_window_set_title(window *gtkWidget, title string) {
(*C.gchar)(unsafe.Pointer(ctitle)))
}
func gtk_window_get_title(window *gtkWidget) string {
return C.GoString((*C.char)(unsafe.Pointer(C.gtk_window_get_title((*C.GtkWindow)(unsafe.Pointer(window))))))
}
func gtk_window_resize(window *gtkWidget, width int, height int) {
C.gtk_window_resize((*C.GtkWindow)(unsafe.Pointer(window)), C.gint(width), C.gint(height))
}
@ -115,6 +121,10 @@ func gtk_button_set_label(button *gtkWidget, label string) {
(*C.gchar)(unsafe.Pointer(clabel)))
}
func gtk_button_get_label(button *gtkWidget) string {
return C.GoString((*C.char)(unsafe.Pointer(C.gtk_button_get_label((*C.GtkButton)(unsafe.Pointer(button))))))
}
func gtk_check_button_new() *gtkWidget {
return (*gtkWidget)(unsafe.Pointer(C.gtk_check_button_new()))
}

View File

@ -18,6 +18,7 @@ type sysData struct {
type classData struct {
make func() *gtkWidget
setText func(widget *gtkWidget, text string)
text func(widget *gtkWidget) string
// ...
signals map[string]func(*sysData) func() bool
}
@ -26,6 +27,7 @@ var classTypes = [nctypes]*classData{
c_window: &classData{
make: gtk_window_new,
setText: gtk_window_set_title,
text: gtk_window_get_title,
signals: map[string]func(*sysData) func() bool{
"delete-event": func(w *sysData) func() bool {
return func() bool {
@ -53,6 +55,7 @@ var classTypes = [nctypes]*classData{
c_button: &classData{
make: gtk_button_new,
setText: gtk_button_set_label,
text: gtk_button_get_label,
signals: map[string]func(*sysData) func() bool{
"clicked": func(w *sysData) func() bool {
return func() bool {
@ -176,8 +179,13 @@ func (s *sysData) isChecked() bool {
}
func (s *sysData) text() string {
// TODO
return ""
if classTypes[s.ctype] == nil || classTypes[s.ctype].text == nil { println(s.ctype,"unsupported text()"); return "" }
ret := make(chan string)
defer close(ret)
uitask <- func() {
ret <- classTypes[s.ctype].text(s.widget)
}
return <-ret
}
func (s *sysData) append(what string) error {