ui/motif/container.c

changeset 61
7ee124a58fe3
parent 60
7cd1b8890302
child 62
70d2aee84432
equal deleted inserted replaced
60:7cd1b8890302 61:7ee124a58fe3
61 void ui_frame_container_add(UiContainer *ct, Widget widget) { 61 void ui_frame_container_add(UiContainer *ct, Widget widget) {
62 62
63 } 63 }
64 64
65 65
66 UiContainer* ui_vbox_container(UiObject *obj, Widget box) { 66 UiContainer* ui_box_container(UiObject *obj, Widget box, UiBoxOrientation orientation) {
67 UiContainer *ct = ucx_mempool_calloc( 67 UiBoxContainer *ct = ucx_mempool_calloc(
68 obj->ctx->mempool, 68 obj->ctx->mempool,
69 1, 69 1,
70 sizeof(UiBoxContainer)); 70 sizeof(UiBoxContainer));
71 ct->widget = box; 71 ct->container.widget = box;
72 ct->prepare = ui_vbox_container_prepare; 72 ct->container.prepare = ui_box_container_prepare;
73 ct->add = ui_vbox_container_add; 73 ct->container.add = ui_box_container_add;
74 return ct; 74 ct->orientation = orientation;
75 } 75 return (UiContainer*)ct;
76 76 }
77 Widget ui_vbox_container_prepare(UiContainer *ct, Arg *args, int *n, UiBool fill) { 77
78 Widget ui_box_container_prepare(UiContainer *ct, Arg *args, int *n, UiBool fill) {
78 UiBoxContainer *bc = (UiBoxContainer*)ct; 79 UiBoxContainer *bc = (UiBoxContainer*)ct;
79 if(ct->layout.fill != UI_LAYOUT_UNDEFINED) { 80 if(ct->layout.fill != UI_LAYOUT_UNDEFINED) {
80 fill = ui_lb2bool(ct->layout.fill); 81 fill = ui_lb2bool(ct->layout.fill);
81 } 82 }
82 83
85 fill = FALSE; 86 fill = FALSE;
86 } 87 }
87 if(fill) { 88 if(fill) {
88 bc->has_fill = TRUE; 89 bc->has_fill = TRUE;
89 } 90 }
90 //UiBool expand = fill;
91 91
92 int a = *n; 92 int a = *n;
93 XtSetArg(args[a], XmNleftAttachment, XmATTACH_FORM); a++; 93 // determine fixed and dynamic attachments
94 XtSetArg(args[a], XmNrightAttachment, XmATTACH_FORM); a++; 94 void *f1;
95 void *f2;
96 void *d1;
97 void *d2;
98 void *w1;
99 void *w2;
100 if(bc->orientation == UI_BOX_VERTICAL) {
101 f1 = XmNleftAttachment;
102 f2 = XmNrightAttachment;
103 d1 = XmNtopAttachment;
104 d2 = XmNbottomAttachment;
105 w1 = XmNtopWidget;
106 w2 = XmNbottomWidget;
107
108 } else {
109 f1 = XmNtopAttachment;
110 f2 = XmNbottomAttachment;
111 d1 = XmNleftAttachment;
112 d2 = XmNrightAttachment;
113 w1 = XmNleftWidget;
114 w2 = XmNrightWidget;
115 }
116 XtSetArg(args[a], f1, XmATTACH_FORM); a++;
117 XtSetArg(args[a], f2, XmATTACH_FORM); a++;
118
95 if(fill) { 119 if(fill) {
96 XtSetArg(args[a], XmNbottomAttachment, XmATTACH_FORM); a++; 120 XtSetArg(args[a], d2, XmATTACH_FORM); a++;
97 bc->cur_fill = TRUE;
98 } 121 }
99 if(bc->prev_widget) { 122 if(bc->prev_widget) {
100 XtSetArg(args[a], XmNtopAttachment, XmATTACH_WIDGET); a++; 123 XtSetArg(args[a], d1, XmATTACH_WIDGET); a++;
101 XtSetArg(args[a], XmNtopWidget, bc->prev_widget); a++; 124 XtSetArg(args[a], w1, bc->prev_widget); a++;
102 } else { 125 } else {
103 XtSetArg(args[a], XmNtopAttachment, XmATTACH_FORM); a++; 126 XtSetArg(args[a], d1, XmATTACH_FORM); a++;
104 } 127 }
105 128
106 *n += a; 129 *n += a;
107 return ct->widget; 130 return ct->widget;
108 } 131 }
109 132
110 void ui_vbox_container_add(UiContainer *ct, Widget widget) { 133 void ui_box_container_add(UiContainer *ct, Widget widget) {
111 UiBoxContainer *bc = (UiBoxContainer*)ct; 134 UiBoxContainer *bc = (UiBoxContainer*)ct;
135 // determine dynamic attachments
136 void *d1;
137 void *d2;
138 void *w1;
139 void *w2;
140 if(bc->orientation == UI_BOX_VERTICAL) {
141 d1 = XmNtopAttachment;
142 d2 = XmNbottomAttachment;
143 w1 = XmNtopWidget;
144 w2 = XmNbottomWidget;
145
146 } else {
147 d1 = XmNleftAttachment;
148 d2 = XmNrightAttachment;
149 w1 = XmNleftWidget;
150 w2 = XmNrightWidget;
151 }
152
112 if(bc->prev_widget) { 153 if(bc->prev_widget) {
113 int v = 0; 154 int v = 0;
114 XtVaGetValues(bc->prev_widget, XmNbottomAttachment, &v, 0); 155 XtVaGetValues(bc->prev_widget, d2, &v, 0);
115 if(v == XmATTACH_FORM) { 156 if(v == XmATTACH_FORM) {
116 XtVaSetValues( 157 XtVaSetValues(
117 bc->prev_widget, 158 bc->prev_widget,
118 XmNbottomAttachment, 159 d2,
119 XmATTACH_WIDGET, 160 XmATTACH_WIDGET,
120 XmNbottomWidget, 161 w2,
121 widget, 162 widget,
122 0); 163 0);
123 XtVaSetValues( 164 XtVaSetValues(
124 widget, 165 widget,
125 XmNtopAttachment, 166 d1,
126 XmATTACH_NONE, 167 XmATTACH_NONE,
127 XmNbottomAttachment, 168 d2,
128 XmATTACH_FORM, 169 XmATTACH_FORM,
129 0); 170 0);
130 } 171 }
131 } 172 }
132 bc->prev_widget = widget; 173 bc->prev_widget = widget;
133 if(bc->cur_fill) { 174
134 bc->filled_widget = widget; 175 ui_reset_layout(ct->layout);
135 } 176 }
136 } 177
137 178 UIWIDGET ui_box(UiObject *obj, UiBoxOrientation orientation) {
179 UiContainer *ct = uic_get_current_container(obj);
180
181 Arg args[16];
182 int n = 0;
183 Widget parent = ct->prepare(ct, args, &n, TRUE);
184 Widget form = XmCreateForm(parent, "vbox", args, n);
185 ct->add(ct, form);
186 XtManageChild(form);
187
188 UiObject *newobj = uic_object_new(obj, form);
189 newobj->container = ui_box_container(obj, form, orientation);
190 uic_obj_add(obj, newobj);
191
192 return form;
193 }
194
195 UIWIDGET ui_vbox(UiObject *obj) {
196 return ui_box(obj, UI_BOX_VERTICAL);
197 }
198
199 UIWIDGET ui_hbox(UiObject *obj) {
200 return ui_box(obj, UI_BOX_HORIZONTAL);
201 }
138 202
139 UIWIDGET ui_sidebar(UiObject *obj) { 203 UIWIDGET ui_sidebar(UiObject *obj) {
140 UiContainer *ct = uic_get_current_container(obj); 204 UiContainer *ct = uic_get_current_container(obj);
141 205
142 Arg args[8]; 206 Arg args[16];
143 int n = 0; 207 int n = 0;
144 XtSetArg(args[n], XmNorientation, XmHORIZONTAL); 208 XtSetArg(args[n], XmNorientation, XmHORIZONTAL);
145 n++; 209 n++;
146 210
147 Widget parent = ct->prepare(ct, args, &n, TRUE); 211 Widget parent = ct->prepare(ct, args, &n, TRUE);
148 Widget pane = XmCreatePanedWindow(parent, "pane", args, n); 212 Widget pane = XmCreatePanedWindow(parent, "pane", args, n);
213 ct->add(ct, pane);
149 XtManageChild(pane); 214 XtManageChild(pane);
150 215
151 // add sidebar widget 216 // add sidebar widget
152 XtSetArg(args[0], XmNshadowType, XmSHADOW_ETCHED_OUT); 217 XtSetArg(args[0], XmNshadowType, XmSHADOW_ETCHED_OUT);
153 XtSetArg(args[1], XmNshadowThickness, 0); 218 XtSetArg(args[1], XmNshadowThickness, 0);
370 } 435 }
371 436
372 void ui_tab_detach_document(UiContext *ctx, void *document) { 437 void ui_tab_detach_document(UiContext *ctx, void *document) {
373 uic_context_detach_document(ctx->parent, document); 438 uic_context_detach_document(ctx->parent, document);
374 } 439 }
440
441
442 /*
443 * -------------------- Layout Functions --------------------
444 *
445 * functions for setting layout attributes for the current container
446 *
447 */
448
449 void ui_layout_fill(UiObject *obj, UiBool fill) {
450 UiContainer *ct = uic_get_current_container(obj);
451 ct->layout.fill = ui_bool2lb(fill);
452 }

mercurial