Sun, 15 Dec 2024 22:13:05 +0100
implement menu item callbacks (Motif)
application/main.c | file | annotate | diff | comparison | revisions | |
ui/motif/menu.c | file | annotate | diff | comparison | revisions |
--- 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();
--- 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) {