ui/motif/container.c

changeset 60
7cd1b8890302
parent 59
eb6611be50c7
child 61
7ee124a58fe3
equal deleted inserted replaced
59:eb6611be50c7 60:7cd1b8890302
31 31
32 #include "container.h" 32 #include "container.h"
33 #include "../common/context.h" 33 #include "../common/context.h"
34 #include "../common/object.h" 34 #include "../common/object.h"
35 35
36 static UiBool ui_lb2bool(UiLayoutBool b) {
37 return b == UI_LAYOUT_TRUE ? TRUE : FALSE;
38 }
39
40 static UiLayoutBool ui_bool2lb(UiBool b) {
41 return b ? UI_LAYOUT_TRUE : UI_LAYOUT_FALSE;
42 }
43
44
36 UiContainer* ui_frame_container(UiObject *obj, Widget frame) { 45 UiContainer* ui_frame_container(UiObject *obj, Widget frame) {
37 UiContainer *ct = ucx_mempool_malloc( 46 UiContainer *ct = ucx_mempool_calloc(
38 obj->ctx->mempool, 47 obj->ctx->mempool,
48 1,
39 sizeof(UiContainer)); 49 sizeof(UiContainer));
40 ct->widget = frame; 50 ct->widget = frame;
51 ct->prepare = ui_frame_container_prepare;
41 ct->add = ui_frame_container_add; 52 ct->add = ui_frame_container_add;
42 return ct; 53 return ct;
43 } 54 }
44 55
45 Widget ui_frame_container_add(UiContainer *ct, Arg *args, int *n) { 56 Widget ui_frame_container_prepare(UiContainer *ct, Arg *args, int *n, UiBool fill) {
57 ui_reset_layout(ct->layout);
46 return ct->widget; 58 return ct->widget;
59 }
60
61 void ui_frame_container_add(UiContainer *ct, Widget widget) {
62
63 }
64
65
66 UiContainer* ui_vbox_container(UiObject *obj, Widget box) {
67 UiContainer *ct = ucx_mempool_calloc(
68 obj->ctx->mempool,
69 1,
70 sizeof(UiBoxContainer));
71 ct->widget = box;
72 ct->prepare = ui_vbox_container_prepare;
73 ct->add = ui_vbox_container_add;
74 return ct;
75 }
76
77 Widget ui_vbox_container_prepare(UiContainer *ct, Arg *args, int *n, UiBool fill) {
78 UiBoxContainer *bc = (UiBoxContainer*)ct;
79 if(ct->layout.fill != UI_LAYOUT_UNDEFINED) {
80 fill = ui_lb2bool(ct->layout.fill);
81 }
82
83 if(bc->has_fill && fill) {
84 fprintf(stderr, "UiError: container has 2 filled widgets");
85 fill = FALSE;
86 }
87 if(fill) {
88 bc->has_fill = TRUE;
89 }
90 //UiBool expand = fill;
91
92 int a = *n;
93 XtSetArg(args[a], XmNleftAttachment, XmATTACH_FORM); a++;
94 XtSetArg(args[a], XmNrightAttachment, XmATTACH_FORM); a++;
95 if(fill) {
96 XtSetArg(args[a], XmNbottomAttachment, XmATTACH_FORM); a++;
97 bc->cur_fill = TRUE;
98 }
99 if(bc->prev_widget) {
100 XtSetArg(args[a], XmNtopAttachment, XmATTACH_WIDGET); a++;
101 XtSetArg(args[a], XmNtopWidget, bc->prev_widget); a++;
102 } else {
103 XtSetArg(args[a], XmNtopAttachment, XmATTACH_FORM); a++;
104 }
105
106 *n += a;
107 return ct->widget;
108 }
109
110 void ui_vbox_container_add(UiContainer *ct, Widget widget) {
111 UiBoxContainer *bc = (UiBoxContainer*)ct;
112 if(bc->prev_widget) {
113 int v = 0;
114 XtVaGetValues(bc->prev_widget, XmNbottomAttachment, &v, 0);
115 if(v == XmATTACH_FORM) {
116 XtVaSetValues(
117 bc->prev_widget,
118 XmNbottomAttachment,
119 XmATTACH_WIDGET,
120 XmNbottomWidget,
121 widget,
122 0);
123 XtVaSetValues(
124 widget,
125 XmNtopAttachment,
126 XmATTACH_NONE,
127 XmNbottomAttachment,
128 XmATTACH_FORM,
129 0);
130 }
131 }
132 bc->prev_widget = widget;
133 if(bc->cur_fill) {
134 bc->filled_widget = widget;
135 }
47 } 136 }
48 137
49 138
50 UIWIDGET ui_sidebar(UiObject *obj) { 139 UIWIDGET ui_sidebar(UiObject *obj) {
51 UiContainer *ct = uic_get_current_container(obj); 140 UiContainer *ct = uic_get_current_container(obj);
53 Arg args[8]; 142 Arg args[8];
54 int n = 0; 143 int n = 0;
55 XtSetArg(args[n], XmNorientation, XmHORIZONTAL); 144 XtSetArg(args[n], XmNorientation, XmHORIZONTAL);
56 n++; 145 n++;
57 146
58 Widget parent = ct->add(ct, args, &n); 147 Widget parent = ct->prepare(ct, args, &n, TRUE);
59 Widget pane = XmCreatePanedWindow(parent, "pane", args, n); 148 Widget pane = XmCreatePanedWindow(parent, "pane", args, n);
60 XtManageChild(pane); 149 XtManageChild(pane);
61 150
62 // add sidebar widget 151 // add sidebar widget
63 XtSetArg(args[0], XmNshadowType, XmSHADOW_ETCHED_OUT); 152 XtSetArg(args[0], XmNshadowType, XmSHADOW_ETCHED_OUT);
85 UiTabbedPane* ui_tabbed_document_view(UiObject *obj) { 174 UiTabbedPane* ui_tabbed_document_view(UiObject *obj) {
86 int n = 0; 175 int n = 0;
87 Arg args[16]; 176 Arg args[16];
88 177
89 UiContainer *ct = uic_get_current_container(obj); 178 UiContainer *ct = uic_get_current_container(obj);
90 Widget parent = ct->add(ct, args, &n); 179 Widget parent = ct->prepare(ct, args, &n, TRUE);
91 180
92 Widget tabview = XmCreateForm(parent, "tabview_form", args, n); 181 Widget tabview = XmCreateForm(parent, "tabview_form", args, n);
93 XtManageChild(tabview); 182 XtManageChild(tabview);
94 183
95 XtSetArg(args[0], XmNorientation, XmHORIZONTAL); 184 XtSetArg(args[0], XmNorientation, XmHORIZONTAL);

mercurial