ui/motif/container.c

branch
newapi
changeset 407
8ea123dd89db
parent 406
0ebf9d7b23e8
child 408
b06e43f1edd4
equal deleted inserted replaced
406:0ebf9d7b23e8 407:8ea123dd89db
34 #include "../common/context.h" 34 #include "../common/context.h"
35 #include "../common/object.h" 35 #include "../common/object.h"
36 36
37 #include "Grid.h" 37 #include "Grid.h"
38 38
39 /* ---------------------------- Box Container ---------------------------- */
40
41 static UIWIDGET box_create(UiObject *obj, UiContainerArgs args, UiBoxOrientation orientation) {
42 UiContainerPrivate *ctn = ui_obj_container(obj);
43 UI_APPLY_LAYOUT(ctn->layout, args);
44
45 Arg xargs[16];
46 int n = 0;
47
48 if(orientation == UI_BOX_VERTICAL) {
49 //XtSetArg(xargs[n], gridRowSpacing, args.spacing); n++;
50 } else {
51 //XtSetArg(xargs[n], gridColumnSpacing, args.spacing); n++;
52 }
53
54 Widget parent = ctn->prepare(ctn, xargs, &n);
55 Widget grid = XtCreateManagedWidget(args.name ? args.name : "boxcontainer", gridClass, parent, xargs, n);
56 ctn->add(ctn, grid);
57
58 UiContainerX *container = ui_box_container(obj, grid, orientation);
59 uic_object_push_container(obj, container);
60
61 return grid;
62 }
63
64 // public
65 UIWIDGET ui_vbox_create(UiObject *obj, UiContainerArgs args) {
66 return box_create(obj, args, UI_BOX_VERTICAL);
67 }
68
69 // public
70 UIWIDGET ui_hbox_create(UiObject *obj, UiContainerArgs args) {
71 return box_create(obj, args, UI_BOX_HORIZONTAL);
72 }
73
39 UiContainerX* ui_box_container(UiObject *obj, Widget grid, UiBoxOrientation orientation) { 74 UiContainerX* ui_box_container(UiObject *obj, Widget grid, UiBoxOrientation orientation) {
40 UiBoxContainer *ctn = ui_malloc(obj->ctx, sizeof(UiBoxContainer)); 75 UiBoxContainer *ctn = ui_malloc(obj->ctx, sizeof(UiBoxContainer));
41 memset(ctn, 0, sizeof(UiBoxContainer)); 76 memset(ctn, 0, sizeof(UiBoxContainer));
42 ctn->container.prepare = orientation == UI_BOX_VERTICAL ? ui_vbox_prepare : ui_hbox_prepare; 77 ctn->container.prepare = orientation == UI_BOX_VERTICAL ? ui_vbox_prepare : ui_hbox_prepare;
43 ctn->container.add = ui_box_container_add; 78 ctn->container.add = ui_box_container_add;
67 } 102 }
68 103
69 Widget ui_hbox_prepare(UiContainerPrivate *ctn, Arg *args, int *n) { 104 Widget ui_hbox_prepare(UiContainerPrivate *ctn, Arg *args, int *n) {
70 UiBoxContainer *box = (UiBoxContainer*)ctn; 105 UiBoxContainer *box = (UiBoxContainer*)ctn;
71 int a = *n; 106 int a = *n;
72 XtSetArg(args[a], gridRow, box->n); a++; 107 XtSetArg(args[a], gridColumn, box->n); a++;
73 if(box->container.layout.fill == UI_ON) { 108 if(box->container.layout.fill == UI_ON) {
74 XtSetArg(args[a], gridHExpand, TRUE); a++; 109 XtSetArg(args[a], gridHExpand, TRUE); a++;
110 XtSetArg(args[a], gridHFill, TRUE); a++;
75 } 111 }
76 XtSetArg(args[a], gridVExpand, TRUE); a++; 112 XtSetArg(args[a], gridVExpand, TRUE); a++;
113 XtSetArg(args[a], gridVFill, TRUE); a++;
77 *n = a; 114 *n = a;
78 return ui_box_container_prepare(box, args, n); 115 return ui_box_container_prepare(box, args, n);
79 } 116 }
80 117
81 void ui_box_container_add(UiContainerPrivate *ctn, Widget widget) { 118 void ui_box_container_add(UiContainerPrivate *ctn, Widget widget) {
82 ui_reset_layout(ctn->layout); 119 ui_reset_layout(ctn->layout);
83 120
84 } 121 }
122
123
124 /* ---------------------------- Grid Container ---------------------------- */
125
126 // public
127 UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs args) {
128 Arg xargs[16];
129 int n = 0;
130
131 UiContainerPrivate *ctn = ui_obj_container(obj);
132 UI_APPLY_LAYOUT(ctn->layout, args);
133
134 Widget parent = ctn->prepare(ctn, xargs, &n);
135 Widget grid = XtCreateManagedWidget(args.name ? args.name : "gridcontainer", gridClass, parent, xargs, n);
136 ctn->add(ctn, grid);
137
138 UiContainerX *container = ui_grid_container(obj, grid);
139 uic_object_push_container(obj, container);
140
141 return grid;
142 }
143
144 UiContainerX* ui_grid_container(UiObject *obj, Widget grid) {
145 UiGridContainer *ctn = ui_malloc(obj->ctx, sizeof(UiGridContainer));
146 memset(ctn, 0, sizeof(UiBoxContainer));
147 ctn->container.prepare = ui_grid_container_prepare;
148 ctn->container.add = ui_grid_container_add;
149 ctn->container.widget = grid;
150 ctn->x = 0;
151 ctn->y = 0;
152 return (UiContainerX*)ctn;
153 }
154
155 Widget ui_grid_container_prepare(UiContainerPrivate *ctn, Arg *args, int *n) {
156 UiGridContainer *grid = (UiGridContainer*)ctn;
157 if(ctn->layout.newline) {
158 grid->y++;
159 grid->x = 0;
160 }
161
162 int a = *n;
163 XtSetArg(args[a], gridColumn, grid->x); a++;
164 XtSetArg(args[a], gridRow, grid->y); a++;
165 if(ctn->layout.colspan > 0) {
166 XtSetArg(args[a], gridColspan, ctn->layout.colspan); a++;
167 }
168 if(ctn->layout.rowspan > 0) {
169 XtSetArg(args[a], gridRowspan, ctn->layout.rowspan); a++;
170 }
171
172 if(grid->container.layout.fill == UI_ON) {
173 grid->container.layout.hfill = TRUE;
174 grid->container.layout.vfill = TRUE;
175 grid->container.layout.hexpand = TRUE;
176 grid->container.layout.vexpand = TRUE;
177 }
178
179 if(grid->container.layout.hfill) {
180 XtSetArg(args[a], gridHFill, TRUE); a++;
181 }
182 if(grid->container.layout.vfill) {
183 XtSetArg(args[a], gridVFill, TRUE); a++;
184 }
185 if(grid->container.layout.hexpand) {
186 XtSetArg(args[a], gridHExpand, TRUE); a++;
187 }
188 if(grid->container.layout.vexpand) {
189 XtSetArg(args[a], gridVExpand, TRUE); a++;
190 }
191
192 *n = a;
193 return ctn->widget;
194 }
195
196 void ui_grid_container_add(UiContainerPrivate *ctn, Widget widget) {
197 UiGridContainer *grid = (UiGridContainer*)ctn;
198 grid->x++;
199 ui_reset_layout(ctn->layout);
200 }
201
202
203 /* -------------------- Container Helper Functions -------------------- */
204
205 void ui_container_begin_close(UiObject *obj) {
206 UiContainerPrivate *ct = ui_obj_container(obj);
207 ct->container.close = 1;
208 }
209
210 int ui_container_finish(UiObject *obj) {
211 UiContainerPrivate *ct = ui_obj_container(obj);
212 if(ct->container.close) {
213 ui_end_new(obj);
214 return 0;
215 }
216 return 1;
217 }
218
219
220 /*
221 * -------------------- Layout Functions --------------------
222 *
223 * functions for setting layout attributes for the current container
224 *
225 */
226
227 void ui_newline(UiObject *obj) {
228 UiContainerPrivate *ct = ui_obj_container(obj);
229 ct->layout.newline = TRUE;
230 }

mercurial