From c40b7b5599236a8e85f7bf610bfaebd4a609da0a Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 16 Feb 2014 16:23:49 -0500 Subject: [PATCH] Added basic signal connection. I'm going to need to build a different callback system, though... --- gtkcalls_unix.go | 4 ++++ sysdata_unix.go | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/gtkcalls_unix.go b/gtkcalls_unix.go index d09fd61..f56e6fc 100644 --- a/gtkcalls_unix.go +++ b/gtkcalls_unix.go @@ -21,6 +21,10 @@ import "C" type ( gtkWidget C.GtkWidget + + // these are needed for signals + gdkEvent C.GdkEvent + gpointer C.gpointer ) func fromgbool(b C.gboolean) bool { diff --git a/sysdata_unix.go b/sysdata_unix.go index 363e3c8..3466a8a 100644 --- a/sysdata_unix.go +++ b/sysdata_unix.go @@ -18,12 +18,24 @@ type sysData struct { type classData struct { make func() *gtkWidget setText func(widget *gtkWidget, text string) + // ... + signals map[string]func(*sysData) interface{} } var classTypes = [nctypes]*classData{ c_window: &classData{ make: gtk_window_new, setText: gtk_window_set_title, + signals: map[string]func(*sysData) interface{}{ + "delete-event": func(w *sysData) interface{} { + return func(*gtkWidget, *gdkEvent, gpointer) bool { + if w.event != nil { + w.event <- struct{}{} + } + return true // do not close the window + } + }, + }, }, c_button: &classData{ // make: gtk_button_new, @@ -57,6 +69,9 @@ println(s.widget) uitask <- func() { fixed := gtk_fixed_new() gtk_container_add(s.widget, fixed) + for signal, generator := range ct.signals { + g_signal_connect(s.widget, signal, generator(s)) + } ret <- fixed } s.container = <-ret