diff -r eb6611be50c7 -r 7cd1b8890302 ui/motif/container.c --- a/ui/motif/container.c Thu Jan 01 11:23:43 2015 +0100 +++ b/ui/motif/container.c Thu Jan 01 14:13:37 2015 +0100 @@ -33,19 +33,108 @@ #include "../common/context.h" #include "../common/object.h" +static UiBool ui_lb2bool(UiLayoutBool b) { + return b == UI_LAYOUT_TRUE ? TRUE : FALSE; +} + +static UiLayoutBool ui_bool2lb(UiBool b) { + return b ? UI_LAYOUT_TRUE : UI_LAYOUT_FALSE; +} + + UiContainer* ui_frame_container(UiObject *obj, Widget frame) { - UiContainer *ct = ucx_mempool_malloc( + UiContainer *ct = ucx_mempool_calloc( obj->ctx->mempool, + 1, sizeof(UiContainer)); ct->widget = frame; + ct->prepare = ui_frame_container_prepare; ct->add = ui_frame_container_add; return ct; } -Widget ui_frame_container_add(UiContainer *ct, Arg *args, int *n) { +Widget ui_frame_container_prepare(UiContainer *ct, Arg *args, int *n, UiBool fill) { + ui_reset_layout(ct->layout); return ct->widget; } +void ui_frame_container_add(UiContainer *ct, Widget widget) { + +} + + +UiContainer* ui_vbox_container(UiObject *obj, Widget box) { + UiContainer *ct = ucx_mempool_calloc( + obj->ctx->mempool, + 1, + sizeof(UiBoxContainer)); + ct->widget = box; + ct->prepare = ui_vbox_container_prepare; + ct->add = ui_vbox_container_add; + return ct; +} + +Widget ui_vbox_container_prepare(UiContainer *ct, Arg *args, int *n, UiBool fill) { + UiBoxContainer *bc = (UiBoxContainer*)ct; + if(ct->layout.fill != UI_LAYOUT_UNDEFINED) { + fill = ui_lb2bool(ct->layout.fill); + } + + if(bc->has_fill && fill) { + fprintf(stderr, "UiError: container has 2 filled widgets"); + fill = FALSE; + } + if(fill) { + bc->has_fill = TRUE; + } + //UiBool expand = fill; + + int a = *n; + XtSetArg(args[a], XmNleftAttachment, XmATTACH_FORM); a++; + XtSetArg(args[a], XmNrightAttachment, XmATTACH_FORM); a++; + if(fill) { + XtSetArg(args[a], XmNbottomAttachment, XmATTACH_FORM); a++; + bc->cur_fill = TRUE; + } + if(bc->prev_widget) { + XtSetArg(args[a], XmNtopAttachment, XmATTACH_WIDGET); a++; + XtSetArg(args[a], XmNtopWidget, bc->prev_widget); a++; + } else { + XtSetArg(args[a], XmNtopAttachment, XmATTACH_FORM); a++; + } + + *n += a; + return ct->widget; +} + +void ui_vbox_container_add(UiContainer *ct, Widget widget) { + UiBoxContainer *bc = (UiBoxContainer*)ct; + if(bc->prev_widget) { + int v = 0; + XtVaGetValues(bc->prev_widget, XmNbottomAttachment, &v, 0); + if(v == XmATTACH_FORM) { + XtVaSetValues( + bc->prev_widget, + XmNbottomAttachment, + XmATTACH_WIDGET, + XmNbottomWidget, + widget, + 0); + XtVaSetValues( + widget, + XmNtopAttachment, + XmATTACH_NONE, + XmNbottomAttachment, + XmATTACH_FORM, + 0); + } + } + bc->prev_widget = widget; + if(bc->cur_fill) { + bc->filled_widget = widget; + } +} + UIWIDGET ui_sidebar(UiObject *obj) { UiContainer *ct = uic_get_current_container(obj); @@ -55,7 +144,7 @@ XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++; - Widget parent = ct->add(ct, args, &n); + Widget parent = ct->prepare(ct, args, &n, TRUE); Widget pane = XmCreatePanedWindow(parent, "pane", args, n); XtManageChild(pane); @@ -87,7 +176,7 @@ Arg args[16]; UiContainer *ct = uic_get_current_container(obj); - Widget parent = ct->add(ct, args, &n); + Widget parent = ct->prepare(ct, args, &n, TRUE); Widget tabview = XmCreateForm(parent, "tabview_form", args, n); XtManageChild(tabview);