Sun, 23 Nov 2025 10:49:24 +0100
add ui_window_menubar_set_visible (Motif)
| ui/gtk/toolkit.c | file | annotate | diff | comparison | revisions | |
| ui/motif/toolkit.c | file | annotate | diff | comparison | revisions | |
| ui/motif/window.c | file | annotate | diff | comparison | revisions | |
| ui/motif/window.h | file | annotate | diff | comparison | revisions | |
| ui/ui/toolkit.h | file | annotate | diff | comparison | revisions |
--- a/ui/gtk/toolkit.c Sun Nov 23 10:39:51 2025 +0100 +++ b/ui/gtk/toolkit.c Sun Nov 23 10:49:24 2025 +0100 @@ -263,7 +263,7 @@ #endif } -void ui_set_visible(UIWIDGET widget, int visible) { +void ui_set_visible(UIWIDGET widget, UiBool visible) { #if GTK_MAJOR_VERSION >= 4 gtk_widget_set_visible(widget, visible); #else
--- a/ui/motif/toolkit.c Sun Nov 23 10:39:51 2025 +0100 +++ b/ui/motif/toolkit.c Sun Nov 23 10:49:24 2025 +0100 @@ -202,7 +202,7 @@ } } -void ui_set_visible(UIWIDGET widget, int visible) { +void ui_set_visible(UIWIDGET widget, UiBool visible) { if(visible) { XtManageChild(widget); } else {
--- a/ui/motif/window.c Sun Nov 23 10:39:51 2025 +0100 +++ b/ui/motif/window.c Sun Nov 23 10:49:24 2025 +0100 @@ -87,6 +87,13 @@ ui_get_window_default_width(&window_width, &window_height); } + UiMotifAppWindow *appwindow = cxZalloc(a, sizeof(UiMotifAppWindow)); + // Because we store appwindow as userdata in the widget, we use this + // magic field to check, if the pointer is actually the correct type. + // This is a dubious technique, but this is only the last defense + // mechanism against someone using the API wrong. + appwindow->magic = UI_MOTIF_APP_WINDOW; + Arg args[16]; int n = 0; XtSetArg(args[n], XmNtitle, title); n++; @@ -94,6 +101,7 @@ XtSetArg(args[n], XmNminHeight, 50); n++; XtSetArg(args[n], XmNwidth, window_width); n++; XtSetArg(args[n], XmNheight, window_height); n++; + XtSetArg(args[n], XmNuserData, appwindow); n++; Widget toplevel = XtAppCreateShell( ui_appname(), @@ -123,7 +131,7 @@ // menu if(!simple) { - ui_create_menubar(obj, window); + appwindow->menubar = ui_create_menubar(obj, window); } // content frame @@ -166,7 +174,17 @@ } void ui_window_menubar_set_visible(UiObject *obj, UiBool visible) { - + UiMotifAppWindow *window = NULL; + XtVaGetValues(obj->widget, XmNuserData, &window, NULL); + if(window) { + if(window->magic != UI_MOTIF_APP_WINDOW) { + fprintf(stderr, "Error: obj is not an app window\n"); + return; + } + if(window->menubar) { + ui_set_visible(window->menubar, visible); + } + } } static void filedialog_event(UiEventData *event, int result, UiFileList flist) {
--- a/ui/motif/window.h Sun Nov 23 10:39:51 2025 +0100 +++ b/ui/motif/window.h Sun Nov 23 10:49:24 2025 +0100 @@ -34,10 +34,13 @@ #ifdef __cplusplus extern "C" { #endif + +#define UI_MOTIF_APP_WINDOW 0xabcd -typedef struct UiMainWindow { +typedef struct UiMotifAppWindow { + int magic; Widget menubar; -} UiMainWindow; +} UiMotifAppWindow; #ifdef __cplusplus
--- a/ui/ui/toolkit.h Sun Nov 23 10:39:51 2025 +0100 +++ b/ui/ui/toolkit.h Sun Nov 23 10:49:24 2025 +0100 @@ -562,6 +562,8 @@ UIEXPORT void ui_attach_document(UiContext *ctx, void *document); UIEXPORT void ui_detach_document(UiContext *ctx, void *document); +UIEXPORT void ui_set_visible(UIWIDGET widget, UiBool visible); + UIEXPORT void ui_widget_set_groups(UiContext *ctx, UIWIDGET widget, ui_enablefunc enable, ...); UIEXPORT void ui_widget_set_groups2(UiContext *ctx, UIWIDGET widget, ui_enablefunc enable, const int *groups, int ngroups); UIEXPORT void ui_widget_set_visibility_states(UiContext *ctx, UIWIDGET widget, const int *states, int nstates);