diff -r 81c4f73236a4 -r c3f2f16fa4b8 ui/motif/container.c --- a/ui/motif/container.c Sat Oct 04 14:54:25 2025 +0200 +++ b/ui/motif/container.c Sun Oct 19 21:20:08 2025 +0200 @@ -33,6 +33,7 @@ #include "container.h" #include "../common/context.h" #include "../common/object.h" +#include "../common/container.h" #include @@ -40,12 +41,26 @@ +Widget ui_container_prepare(UiContainerPrivate *container, UiLayout *layout, Arg *args, int *n) { + if(layout->margin != 0) { + layout->margin_left = layout->margin; + layout->margin_right = layout->margin; + layout->margin_top = layout->margin; + layout->margin_bottom = layout->margin; + } + return container->prepare(container, layout, args, n); +} + +void ui_container_add(UiContainerPrivate *container, Widget widget) { + container->add(container, widget); +} + /* ---------------------------- Box Container ---------------------------- */ static UIWIDGET box_create(UiObject *obj, UiContainerArgs *args, UiBoxOrientation orientation) { UiContainerPrivate *ctn = ui_obj_container(obj); - UI_APPLY_LAYOUT(ctn->layout, args); + UiLayout layout = UI_ARGS2LAYOUT(args); Arg xargs[16]; int n = 0; @@ -56,7 +71,7 @@ //XtSetArg(xargs[n], gridColumnSpacing, args->spacing); n++; } - Widget parent = ctn->prepare(ctn, xargs, &n); + Widget parent = ui_container_prepare(ctn, &layout, xargs, &n); Widget grid = XtCreateManagedWidget(args->name ? args->name : "boxcontainer", gridClass, parent, xargs, n); ctn->add(ctn, grid); @@ -86,43 +101,42 @@ return (UiContainerX*)ctn; } -static Widget ui_box_container_prepare(UiBoxContainer *box, Arg *args, int *n) { +static Widget ui_box_container_prepare(UiBoxContainer *box, UiLayout *layout, Arg *args, int *n) { int a = *n; box->n++; return box->container.widget; } -Widget ui_vbox_prepare(UiContainerPrivate *ctn, Arg *args, int *n) { +Widget ui_vbox_prepare(UiContainerPrivate *ctn, UiLayout *layout, Arg *args, int *n) { UiBoxContainer *box = (UiBoxContainer*)ctn; int a = *n; XtSetArg(args[a], gridRow, box->n); a++; - if(box->container.layout.fill == UI_ON) { + if(layout->fill) { XtSetArg(args[a], gridVExpand, TRUE); a++; XtSetArg(args[a], gridVFill, TRUE); a++; } XtSetArg(args[a], gridHExpand, TRUE); a++; XtSetArg(args[a], gridHFill, TRUE); a++; *n = a; - return ui_box_container_prepare(box, args, n); + return ui_box_container_prepare(box, layout, args, n); } -Widget ui_hbox_prepare(UiContainerPrivate *ctn, Arg *args, int *n) { +Widget ui_hbox_prepare(UiContainerPrivate *ctn, UiLayout *layout, Arg *args, int *n) { UiBoxContainer *box = (UiBoxContainer*)ctn; int a = *n; XtSetArg(args[a], gridColumn, box->n); a++; - if(box->container.layout.fill == UI_ON) { + if(layout->fill) { XtSetArg(args[a], gridHExpand, TRUE); a++; XtSetArg(args[a], gridHFill, TRUE); a++; } XtSetArg(args[a], gridVExpand, TRUE); a++; XtSetArg(args[a], gridVFill, TRUE); a++; *n = a; - return ui_box_container_prepare(box, args, n); + return ui_box_container_prepare(box, layout, args, n); } void ui_box_container_add(UiContainerPrivate *ctn, Widget widget) { - ui_reset_layout(ctn->layout); - + } @@ -134,14 +148,14 @@ int n = 0; UiContainerPrivate *ctn = ui_obj_container(obj); - UI_APPLY_LAYOUT(ctn->layout, args); + UiLayout layout = UI_ARGS2LAYOUT(args); - Widget parent = ctn->prepare(ctn, xargs, &n); + Widget parent = ui_container_prepare(ctn, &layout, xargs, &n); XtSetArg(xargs[n], gridMargin, args->margin); n++; XtSetArg(xargs[n], gridColumnSpacing, args->columnspacing); n++; XtSetArg(xargs[n], gridRowSpacing, args->rowspacing); n++; Widget grid = XtCreateManagedWidget(args->name ? args->name : "gridcontainer", gridClass, parent, xargs, n); - ctn->add(ctn, grid); + ui_container_add(ctn, grid); UiContainerX *container = ui_grid_container(obj, grid, args->def_hexpand, args->def_vexpand, args->def_hfill, args->def_vfill); uic_object_push_container(obj, container); @@ -171,9 +185,9 @@ return (UiContainerX*)ctn; } -Widget ui_grid_container_prepare(UiContainerPrivate *ctn, Arg *args, int *n) { +Widget ui_grid_container_prepare(UiContainerPrivate *ctn, UiLayout *layout, Arg *args, int *n) { UiGridContainer *grid = (UiGridContainer*)ctn; - if(ctn->layout.newline) { + if(ctn->container.newline) { grid->y++; grid->x = 0; } @@ -181,61 +195,25 @@ int a = *n; XtSetArg(args[a], gridColumn, grid->x); a++; XtSetArg(args[a], gridRow, grid->y); a++; - if(ctn->layout.colspan > 0) { - XtSetArg(args[a], gridColspan, ctn->layout.colspan); a++; - } - if(ctn->layout.rowspan > 0) { - XtSetArg(args[a], gridRowspan, ctn->layout.rowspan); a++; + if(layout->colspan > 0) { + XtSetArg(args[a], gridColspan, layout->colspan); a++; } - - int hexpand = FALSE; - int vexpand = FALSE; - int hfill = FALSE; - int vfill = FALSE; - if(!ctn->layout.override_defaults) { - if(grid->def_hexpand) { - hexpand = TRUE; - hfill = TRUE; - } else if(grid->def_hfill) { - hfill = TRUE; - } - if(grid->def_vexpand) { - vexpand = TRUE; - vfill = TRUE; - } else if(grid->def_vfill) { - vfill = TRUE; - } + if(layout->rowspan > 0) { + XtSetArg(args[a], gridRowspan, layout->rowspan); a++; } - if(ctn->layout.hexpand) { - hexpand = TRUE; - hfill = TRUE; - } else if(ctn->layout.hfill) { - hfill = TRUE; - } - if(ctn->layout.vexpand) { - vexpand = TRUE; - vfill = TRUE; - } else if(ctn->layout.vfill) { - vfill = TRUE; - } - if(ctn->layout.fill == UI_ON) { - hexpand = TRUE; - vexpand = TRUE; - hfill = TRUE; - vfill = TRUE; - } + uic_layout_setup_expand_fill(layout, grid->def_hexpand, grid->def_vexpand, grid->def_hfill, grid->def_vfill); - if(hfill) { + if(layout->hfill) { XtSetArg(args[a], gridHFill, TRUE); a++; } - if(vfill) { + if(layout->vfill) { XtSetArg(args[a], gridVFill, TRUE); a++; } - if(hexpand) { + if(layout->hexpand) { XtSetArg(args[a], gridHExpand, TRUE); a++; } - if(vexpand) { + if(layout->vexpand) { XtSetArg(args[a], gridVExpand, TRUE); a++; } @@ -246,7 +224,7 @@ void ui_grid_container_add(UiContainerPrivate *ctn, Widget widget) { UiGridContainer *grid = (UiGridContainer*)ctn; grid->x++; - ui_reset_layout(ctn->layout); + grid->container.container.newline = FALSE; } @@ -313,7 +291,7 @@ int n = 0; UiContainerPrivate *ctn = ui_obj_container(obj); - UI_APPLY_LAYOUT(ctn->layout, args); + UiLayout layout = UI_ARGS2LAYOUT(args); // create widgets // form @@ -323,9 +301,10 @@ memset(tabview, 0, sizeof(UiMotifTabView)); char *name = args->name ? (char*)args->name : "tabview"; XtSetArg(xargs[n], XmNuserData, tabview); n++; - Widget parent = ctn->prepare(ctn, xargs, &n); + Widget parent = ui_container_prepare(ctn, &layout, xargs, &n); Widget form = XmCreateForm(parent, name, xargs, n); XtManageChild(form); + ui_container_add(ctn, parent); n = 0; XtSetArg(xargs[n], XmNleftAttachment, XmATTACH_FORM); n++; @@ -569,7 +548,7 @@ XtManageChild(tab->child); } -Widget ui_tabview_container_prepare(UiContainerPrivate *ctn, Arg *args, int *n) { +Widget ui_tabview_container_prepare(UiContainerPrivate *ctn, UiLayout *layout, Arg *args, int *n) { UiTabViewContainer *ct = (UiTabViewContainer*)ctn; UiMotifTabView *tabview = ct->tabview; int a = *n; @@ -583,12 +562,12 @@ } void ui_tabview_container_add(UiContainerPrivate *ctn, Widget widget) { - ui_reset_layout(ctn->layout); + } /* -------------------- ScrolledWindow -------------------- */ -Widget ui_scrolledwindow_prepare(UiContainerPrivate *ctn, Arg *args, int *n) { +Widget ui_scrolledwindow_prepare(UiContainerPrivate *ctn, UiLayout *layout, Arg *args, int *n) { return ctn->widget; } @@ -607,16 +586,16 @@ UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiFrameArgs *args) { UiContainerPrivate *ctn = ui_obj_container(obj); - UI_APPLY_LAYOUT(ctn->layout, args); + UiLayout layout = UI_ARGS2LAYOUT(args); Arg xargs[16]; int n = 0; XtSetArg(xargs[n], XmNscrollingPolicy, XmAUTOMATIC); n++; - Widget parent = ctn->prepare(ctn, xargs, &n); + Widget parent = ui_container_prepare(ctn, &layout, xargs, &n); Widget scrolledwindow = XmCreateScrolledWindow(parent, "scrolledwindow", xargs, n); - ctn->add(ctn, scrolledwindow); + ui_container_add(ctn, scrolledwindow); UiContainerX *container = ui_scrolledwindow_container(obj, scrolledwindow); uic_object_push_container(obj, container); @@ -640,15 +619,3 @@ return 1; } - -/* - * -------------------- Layout Functions -------------------- - * - * functions for setting layout attributes for the current container - * - */ - -void ui_newline(UiObject *obj) { - UiContainerPrivate *ct = ui_obj_container(obj); - ct->layout.newline = TRUE; -}