Thu, 01 Jan 2015 14:13:37 +0100
added vbox container (Motif)
application/main.c | file | annotate | diff | comparison | revisions | |
ui/motif/button.c | file | annotate | diff | comparison | revisions | |
ui/motif/container.c | file | annotate | diff | comparison | revisions | |
ui/motif/container.h | file | annotate | diff | comparison | revisions | |
ui/motif/list.c | file | annotate | diff | comparison | revisions | |
ui/motif/text.c | file | annotate | diff | comparison | revisions | |
ui/motif/tree.c | file | annotate | diff | comparison | revisions | |
ui/motif/window.c | file | annotate | diff | comparison | revisions |
--- a/application/main.c Thu Jan 01 11:23:43 2015 +0100 +++ b/application/main.c Thu Jan 01 14:13:37 2015 +0100 @@ -117,12 +117,8 @@ //ui_sidebar(window); ui_table(window, list, model); - ui_button(window, "Test", NULL, NULL); - ui_button(window, "Test", NULL, NULL); - ui_button(window, "Test", NULL, NULL); - ui_button(window, "Test", NULL, NULL); - ui_button(window, "Test", NULL, NULL); - ui_button(window, "Test", NULL, NULL); + ui_button(window, "Test1", NULL, NULL); + ui_button(window, "Test2", NULL, NULL); //ui_end(window); /* UiTabbedPane *view = ui_tabbed_document_view(window);
--- a/ui/motif/button.c Thu Jan 01 11:23:43 2015 +0100 +++ b/ui/motif/button.c Thu Jan 01 14:13:37 2015 +0100 @@ -41,11 +41,12 @@ int n = 0; Arg args[16]; + + Widget parent = ct->prepare(ct, args, &n, FALSE); XtSetArg(args[n], XmNlabelString, str); n++; - - Widget parent = ct->add(ct, args, &n); Widget button = XmCreatePushButton(parent, "button", args, n); + ct->add(ct, button); if(f) { UiEventData *event = ucx_mempool_malloc(
--- 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);
--- a/ui/motif/container.h Thu Jan 01 11:23:43 2015 +0100 +++ b/ui/motif/container.h Thu Jan 01 14:13:37 2015 +0100 @@ -31,19 +31,47 @@ #include "../ui/toolkit.h" #include <ucx/list.h> +#include <string.h> #ifdef __cplusplus extern "C" { #endif +#define ui_reset_layout(layout) memset(&(layout), 0, sizeof(UiLayout)) + typedef struct MotifTabbedPane MotifTabbedPane; typedef struct UiTab UiTab; +typedef struct UiBoxContainer UiBoxContainer; -typedef Widget (*ui_container_add_f)(UiContainer*, Arg*, int*); +typedef Widget (*ui_container_add_f)(UiContainer*, Arg*, int*, UiBool); + +typedef struct UiLayout UiLayout; +typedef enum UiLayoutBool UiLayoutBool; + + +enum UiLayoutBool { + UI_LAYOUT_UNDEFINED = 0, + UI_LAYOUT_TRUE, + UI_LAYOUT_FALSE, +}; + +struct UiLayout { + UiLayoutBool fill; +}; struct UiContainer { - Widget widget; - Widget (*add)(UiContainer*, Arg *, int*); + Widget widget; + Widget (*prepare)(UiContainer*, Arg *, int*, UiBool); + void (*add)(UiContainer*, Widget); + UiLayout layout; +}; + +struct UiBoxContainer { + UiContainer container; + Widget prev_widget; + Widget filled_widget; + UiBool cur_fill; + UiBool has_fill; }; struct MotifTabbedPane { @@ -61,7 +89,13 @@ UiContainer* ui_frame_container(UiObject *obj, Widget frame); -Widget ui_frame_container_add(UiContainer *ct, Arg *args, int *n); +Widget ui_frame_container_prepare(UiContainer *ct, Arg *args, int *n, UiBool fill); +void ui_frame_container_add(UiContainer *ct, Widget widget); + +UiContainer* ui_vbox_container(UiObject *obj, Widget box); +Widget ui_vbox_container_prepare(UiContainer *ct, Arg *args, int *n, UiBool fill); +void ui_vbox_container_add(UiContainer *ct, Widget widget); + void ui_tab_button_callback(Widget widget, UiTab *tab, XtPointer d); void ui_change_tab(MotifTabbedPane *pane, UiTab *tab);
--- a/ui/motif/list.c Thu Jan 01 11:23:43 2015 +0100 +++ b/ui/motif/list.c Thu Jan 01 14:13:37 2015 +0100 @@ -58,8 +58,9 @@ n++; UiContainer *ct = uic_get_current_container(obj); - Widget parent = ct->add(ct, args, &n); - Widget widget= XmCreateScrolledList(parent, "listview", args, n); + Widget parent = ct->prepare(ct, args, &n, TRUE); + Widget widget = XmCreateScrolledList(parent, "listview", args, n); + ct->add(ct, widget); XtManageChild(widget); UiListView *listview = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiListView));
--- a/ui/motif/text.c Thu Jan 01 11:23:43 2015 +0100 +++ b/ui/motif/text.c Thu Jan 01 14:13:37 2015 +0100 @@ -42,8 +42,9 @@ XtSetArg(args[n], XmNeditMode, XmMULTI_LINE_EDIT); n++; - Widget parent = ct->add(ct, args, &n); + Widget parent = ct->prepare(ct, args, &n, TRUE); Widget text_area = XmCreateScrolledText(parent, "text_area", args, n); + ct->add(ct, text_area); XtManageChild(text_area); UiTextArea *uitext = ucx_mempool_malloc(
--- a/ui/motif/tree.c Thu Jan 01 11:23:43 2015 +0100 +++ b/ui/motif/tree.c Thu Jan 01 14:13:37 2015 +0100 @@ -41,18 +41,19 @@ UIWIDGET ui_table(UiObject *obj, UiList *model, UiModelInfo *modelinfo) { // TODO: check if modelinfo is complete - Arg args[16]; + Arg args[32]; int n = 0; // create scrolled window UiContainer *ct = uic_get_current_container(obj); - Widget parent = ct->add(ct, args, &n); + Widget parent = ct->prepare(ct, args, &n, TRUE); XtSetArg(args[n], XmNscrollingPolicy, XmAUTOMATIC); n++; XtSetArg(args[n], XmNshadowThickness, 0); n++; Widget scrollw = XmCreateScrolledWindow(parent, "scroll_win", args, n); + ct->add(ct, scrollw); XtManageChild(scrollw); // create table headers
--- a/ui/motif/window.c Thu Jan 01 11:23:43 2015 +0100 +++ b/ui/motif/window.c Thu Jan 01 14:13:37 2015 +0100 @@ -101,6 +101,7 @@ Widget toolbar = ui_create_toolbar(obj, form); + // window content XtSetArg(args[0], XmNshadowType, XmSHADOW_ETCHED_OUT); XtSetArg(args[1], XmNshadowThickness, 0); @@ -115,11 +116,13 @@ XtSetArg(args[5], XmNtopAttachment, XmATTACH_FORM); n = 6; } - Widget frame = XmCreateFrame(form, "toolbar_frame", args, n); + Widget frame = XmCreateFrame(form, "content_frame", args, n); XtManageChild(frame); - obj->container = ui_frame_container(obj, frame); - + Widget content_form = XmCreateForm(frame, "content_form", NULL, 0); + XtManageChild(content_form); + obj->container = ui_vbox_container(obj, content_form); + //obj->container = ui_frame_container(obj, frame); XtManageChild(form);