Skip to content

Commit

Permalink
Merge pull request #11 from JupiterRider/main
Browse files Browse the repository at this point in the history
Add "OPEN_CB" callback for IupMenu
  • Loading branch information
gen2brain authored Apr 8, 2023
2 parents 1bdd927 + 49c1a7d commit 4858a32
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
35 changes: 35 additions & 0 deletions iup/bind_callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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().(MenuOpenFunc)

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())
}

//--------------------
2 changes: 2 additions & 0 deletions iup/bind_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down

0 comments on commit 4858a32

Please sign in to comment.