# HG changeset patch # User Olaf Wintermann # Date 1734297185 -3600 # Node ID f0fee61a70bee76d381dd9a96810c6ada50c7b9a # Parent 89ad8467c39fe621e72d80831e125299c922442a implement menu item callbacks (Motif) diff -r 89ad8467c39f -r f0fee61a70be application/main.c --- a/application/main.c Sun Dec 15 11:59:30 2024 +0100 +++ b/application/main.c Sun Dec 15 22:13:05 2024 +0100 @@ -551,13 +551,19 @@ ui_show(obj); } +void action_test(UiEvent *event, void *data) { + printf("action test\n"); +} + int main(int argc, char** argv) { ui_init("app1", argc, argv); ui_onstartup(application_startup, NULL); // menu ui_menu("File") { - ui_menuitem(.label = "Test"); + ui_menuitem(.label = "Test 1", .onclick = action_test); + ui_menuitem(.label = "Test 2", .onclick = action_test); + ui_menuitem(.label = "Test 3", .onclick = action_test); } ui_main(); diff -r 89ad8467c39f -r f0fee61a70be ui/motif/menu.c --- a/ui/motif/menu.c Sun Dec 15 11:59:30 2024 +0100 +++ b/ui/motif/menu.c Sun Dec 15 22:13:05 2024 +0100 @@ -129,6 +129,24 @@ if(s) { XmStringFree(s); } + + if(it->callback) { + UiEventData *eventdata = malloc(sizeof(UiEventData)); + eventdata->callback = it->callback; + eventdata->userdata = it->userdata; + eventdata->obj = obj; + eventdata->value = 0; + XtAddCallback( + mitem, + XmNactivateCallback, + (XtCallbackProc)ui_push_button_callback, + eventdata); + XtAddCallback( + mitem, + XmNdestroyCallback, + (XtCallbackProc)ui_destroy_eventdata, + eventdata); + } } void add_menuseparator_widget(Widget p, int i, UiMenuItemI *item, UiObject *obj) {