From 13d4e1d258359b0c45df95ea0c359bd50e07ef85 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 16 Feb 2014 18:57:50 -0500 Subject: [PATCH] Added the GTK+ equivalent of Window.Title() and Button.Text() in preparation for adding the GTK+ implementation of Combobox. --- gtkcalls_unix.go | 10 ++++++++++ sysdata_unix.go | 12 ++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/gtkcalls_unix.go b/gtkcalls_unix.go index aba4732..642b34b 100644 --- a/gtkcalls_unix.go +++ b/gtkcalls_unix.go @@ -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())) } diff --git a/sysdata_unix.go b/sysdata_unix.go index f2aef50..0cadc65 100644 --- a/sysdata_unix.go +++ b/sysdata_unix.go @@ -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 {