2014-02-16 15:43:48 -06:00
|
|
|
// +build !windows,!darwin,!plan9
|
|
|
|
|
|
|
|
// 16 february 2014
|
2014-02-19 10:41:10 -06:00
|
|
|
package ui
|
2014-02-16 15:43:48 -06:00
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
|
|
|
cgo doesn't support calling Go functions by default; we have to mark them for export. Not a problem, except arguments to GTK+ callbacks depend on the callback itself. Since we're generating callback functions as simple closures of one type, this file will wrap the generated callbacks in the appropriate callback type. We pass the actual generated pointer to the extra data parameter of the callback.
|
2014-02-16 16:09:58 -06:00
|
|
|
|
|
|
|
while we're at it the callback for our idle function will be handled here too for cleanliness purposes
|
2014-02-16 15:43:48 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
// #cgo pkg-config: gtk+-3.0
|
|
|
|
// #include <gtk/gtk.h>
|
2014-02-16 16:09:58 -06:00
|
|
|
// extern gboolean our_callback(gpointer);
|
2014-02-16 17:04:57 -06:00
|
|
|
// extern gboolean our_window_callback(GtkWidget *, GdkEvent *, gpointer);
|
2014-02-16 16:30:58 -06:00
|
|
|
// extern void our_clicked_callback(GtkButton *, gpointer);
|
2014-02-16 15:43:48 -06:00
|
|
|
import "C"
|
|
|
|
|
2014-02-16 16:09:58 -06:00
|
|
|
//export our_callback
|
|
|
|
func our_callback(what C.gpointer) C.gboolean {
|
2014-02-16 15:43:48 -06:00
|
|
|
f := *(*func() bool)(unsafe.Pointer(what))
|
|
|
|
return togbool(f())
|
|
|
|
}
|
|
|
|
|
2014-02-16 17:04:57 -06:00
|
|
|
//export our_window_callback
|
|
|
|
func our_window_callback(widget *C.GtkWidget, event *C.GdkEvent, what C.gpointer) C.gboolean {
|
2014-02-16 16:09:58 -06:00
|
|
|
return our_callback(what)
|
|
|
|
}
|
|
|
|
|
2014-02-16 16:30:58 -06:00
|
|
|
//export our_clicked_callback
|
|
|
|
func our_clicked_callback(button *C.GtkButton, what C.gpointer) {
|
|
|
|
our_callback(what)
|
|
|
|
}
|
|
|
|
|
2014-02-16 15:43:48 -06:00
|
|
|
var callbacks = map[string]C.GCallback{
|
2014-02-16 16:09:58 -06:00
|
|
|
"idle": C.GCallback(C.our_callback),
|
2014-02-16 17:04:57 -06:00
|
|
|
"delete-event": C.GCallback(C.our_window_callback),
|
|
|
|
"configure-event": C.GCallback(C.our_window_callback),
|
2014-02-16 16:30:58 -06:00
|
|
|
"clicked": C.GCallback(C.our_clicked_callback),
|
2014-02-16 15:43:48 -06:00
|
|
|
}
|