From 938e28acafd0ead223b021caf5880ee63f3a7f33 Mon Sep 17 00:00:00 2001 From: JupiterRider <60042618+JupiterRider@users.noreply.github.com> Date: Sat, 8 Apr 2023 13:05:19 +0200 Subject: [PATCH 1/2] Add IupMenu OPEN_CB callback --- iup/bind_callbacks.go | 35 +++++++++++++++++++++++++++++++++++ iup/bind_events.go | 2 ++ 2 files changed, 37 insertions(+) diff --git a/iup/bind_callbacks.go b/iup/bind_callbacks.go index 898e102..c6b4ccd 100644 --- a/iup/bind_callbacks.go +++ b/iup/bind_callbacks.go @@ -389,6 +389,11 @@ extern int goIupMultiUnselectionCB(void *ih, int* ids, int n); static void goIupSetMultiUnselectionFunc(Ihandle *ih) { IupSetCallback(ih, "MULTIUNSELECTION_CB", (Icallback) goIupMultiUnselectionCB); } + +extern int goIupMenuOpenCB(void *); +static void goIupSetMenuOpenFunc(Ihandle *ih) { + IupSetCallback(ih, "OPEN_CB", (Icallback) goIupMenuOpenCB); +} */ import "C" @@ -2570,3 +2575,33 @@ func setMultiUnselectionFunc(ih Ihandle, f MultiUnselectionFunc) { } //-------------------- + +// MenuOpenFunc for OPEN_CB callback. +// Called just before the menu is opened. +// +// https://www.tecgraf.puc-rio.br/iup/en/call/iup_open_cb.html +type MenuOpenFunc func(ih Ihandle) int + +//export goIupMenuOpenCB +func goIupMenuOpenCB(ih unsafe.Pointer) C.int { + uuid := GetAttribute((Ihandle)(ih), "UUID") + h, ok := callbacks.Load("OPEN_CB_" + uuid) + if !ok { + panic("cannot load callback " + "OPEN_CB_" + uuid) + } + + ch := h.(cgo.Handle) + f := ch.Value().(ActionFunc) + + return C.int(f((Ihandle)(ih))) +} + +// setMenuOpenFunc for OPEN_CB. +func setMenuOpenFunc(ih Ihandle, f MenuOpenFunc) { + ch := cgo.NewHandle(f) + callbacks.Store("OPEN_CB_"+ih.GetAttribute("UUID"), ch) + + C.goIupSetMenuOpenFunc(ih.ptr()) +} + +//-------------------- diff --git a/iup/bind_events.go b/iup/bind_events.go index 6749bb9..0aede0c 100644 --- a/iup/bind_events.go +++ b/iup/bind_events.go @@ -258,6 +258,8 @@ func SetCallback(ih Ihandle, name string, fn interface{}) { setMultiSelectionFunc(ih, fn.(MultiSelectionFunc)) case "MULTIUNSELECTION_CB": setMultiUnselectionFunc(ih, fn.(MultiUnselectionFunc)) + case "OPEN_CB": + setMenuOpenFunc(ih, fn.(MenuOpenFunc)) } } From 49c1a7d4035f76778d28944f5ad2951b9332d5f8 Mon Sep 17 00:00:00 2001 From: JupiterRider <60042618+JupiterRider@users.noreply.github.com> Date: Sat, 8 Apr 2023 13:41:23 +0200 Subject: [PATCH 2/2] Fix wrong type assertion --- iup/bind_callbacks.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iup/bind_callbacks.go b/iup/bind_callbacks.go index c6b4ccd..3c11dc2 100644 --- a/iup/bind_callbacks.go +++ b/iup/bind_callbacks.go @@ -2591,7 +2591,7 @@ func goIupMenuOpenCB(ih unsafe.Pointer) C.int { } ch := h.(cgo.Handle) - f := ch.Value().(ActionFunc) + f := ch.Value().(MenuOpenFunc) return C.int(f((Ihandle)(ih))) }