Made the default action for Window.Closing reject the close request.

This commit is contained in:
Pietro Gagliardi 2014-07-01 09:44:57 -04:00
parent 969700f790
commit abb642071d
2 changed files with 7 additions and 2 deletions

View File

@ -27,7 +27,7 @@ import "C"
func our_window_delete_event_callback(widget *C.GtkWidget, event *C.GdkEvent, what C.gpointer) C.gboolean {
// called when the user tries to close the window
s := (*sysData)(unsafe.Pointer(what))
return togbool(s.close()) // ! because TRUE means don't close
return togbool(!s.close()) // ! because TRUE means don't close
}
var window_delete_event_callback = C.GCallback(C.our_window_delete_event_callback)

View File

@ -12,7 +12,7 @@ type Window struct {
// Return true to allow the window to be closed; false otherwise.
// You cannot change this field after the Window has been created.
// [TODO close vs. hide]
// TODO nil
// If Closing is nil, a default which rejects the close will be used.
Closing func() bool
created bool
@ -86,6 +86,11 @@ func (w *Window) create(control Control, show bool) {
}
w.sysData.spaced = w.spaced
w.sysData.close = w.Closing
if w.sysData.close == nil {
w.sysData.close = func() bool {
return false
}
}
err := w.sysData.make(nil)
if err != nil {
panic(fmt.Errorf("error opening window: %v", err))