| 37 #include <cx/array_list.h> |
37 #include <cx/array_list.h> |
| 38 |
38 |
| 39 #include "Grid.h" |
39 #include "Grid.h" |
| 40 |
40 |
| 41 |
41 |
| 42 UIWIDGET ui_customwidget_create(UiObject *obj, ui_createwidget_func create_widget, void *userdata, UiWidgetArgs args) { |
42 |
| 43 Arg xargs[64]; |
|
| 44 int n = 0; |
|
| 45 |
|
| 46 UiContainerPrivate *ctn = ui_obj_container(obj); |
|
| 47 UI_APPLY_LAYOUT(ctn->layout, args); |
|
| 48 |
|
| 49 Widget parent = ctn->prepare(ctn, xargs, &n); |
|
| 50 Widget widget = create_widget(obj, args, userdata, parent, xargs, n); |
|
| 51 XtManageChild(widget); |
|
| 52 ctn->add(ctn, widget); |
|
| 53 |
|
| 54 return widget; |
|
| 55 } |
|
| 56 |
43 |
| 57 /* ---------------------------- Box Container ---------------------------- */ |
44 /* ---------------------------- Box Container ---------------------------- */ |
| 58 |
45 |
| 59 static UIWIDGET box_create(UiObject *obj, UiContainerArgs args, UiBoxOrientation orientation) { |
46 static UIWIDGET box_create(UiObject *obj, UiContainerArgs args, UiBoxOrientation orientation) { |
| 60 UiContainerPrivate *ctn = ui_obj_container(obj); |
47 UiContainerPrivate *ctn = ui_obj_container(obj); |
| 154 XtSetArg(xargs[n], gridColumnSpacing, args.columnspacing); n++; |
141 XtSetArg(xargs[n], gridColumnSpacing, args.columnspacing); n++; |
| 155 XtSetArg(xargs[n], gridRowSpacing, args.rowspacing); n++; |
142 XtSetArg(xargs[n], gridRowSpacing, args.rowspacing); n++; |
| 156 Widget grid = XtCreateManagedWidget(args.name ? args.name : "gridcontainer", gridClass, parent, xargs, n); |
143 Widget grid = XtCreateManagedWidget(args.name ? args.name : "gridcontainer", gridClass, parent, xargs, n); |
| 157 ctn->add(ctn, grid); |
144 ctn->add(ctn, grid); |
| 158 |
145 |
| 159 UiContainerX *container = ui_grid_container(obj, grid); |
146 UiContainerX *container = ui_grid_container(obj, grid, args.def_hexpand, args.def_vexpand, args.def_hfill, args.def_vfill); |
| 160 uic_object_push_container(obj, container); |
147 uic_object_push_container(obj, container); |
| 161 |
148 |
| 162 return grid; |
149 return grid; |
| 163 } |
150 } |
| 164 |
151 |
| 165 UiContainerX* ui_grid_container(UiObject *obj, Widget grid) { |
152 UiContainerX* ui_grid_container( |
| |
153 UiObject *obj, |
| |
154 Widget grid, |
| |
155 UiBool def_hexpand, |
| |
156 UiBool def_vexpand, |
| |
157 UiBool def_hfill, |
| |
158 UiBool def_vfill) |
| |
159 { |
| 166 UiGridContainer *ctn = ui_malloc(obj->ctx, sizeof(UiGridContainer)); |
160 UiGridContainer *ctn = ui_malloc(obj->ctx, sizeof(UiGridContainer)); |
| 167 memset(ctn, 0, sizeof(UiBoxContainer)); |
161 memset(ctn, 0, sizeof(UiBoxContainer)); |
| 168 ctn->container.prepare = ui_grid_container_prepare; |
162 ctn->container.prepare = ui_grid_container_prepare; |
| 169 ctn->container.add = ui_grid_container_add; |
163 ctn->container.add = ui_grid_container_add; |
| 170 ctn->container.widget = grid; |
164 ctn->container.widget = grid; |
| 171 ctn->x = 0; |
165 ctn->x = 0; |
| 172 ctn->y = 0; |
166 ctn->y = 0; |
| |
167 ctn->def_hexpand = def_hexpand; |
| |
168 ctn->def_vexpand = def_vexpand; |
| |
169 ctn->def_hfill = def_hfill; |
| |
170 ctn->def_vfill = def_vfill; |
| 173 return (UiContainerX*)ctn; |
171 return (UiContainerX*)ctn; |
| 174 } |
172 } |
| 175 |
173 |
| 176 Widget ui_grid_container_prepare(UiContainerPrivate *ctn, Arg *args, int *n) { |
174 Widget ui_grid_container_prepare(UiContainerPrivate *ctn, Arg *args, int *n) { |
| 177 UiGridContainer *grid = (UiGridContainer*)ctn; |
175 UiGridContainer *grid = (UiGridContainer*)ctn; |
| 188 } |
186 } |
| 189 if(ctn->layout.rowspan > 0) { |
187 if(ctn->layout.rowspan > 0) { |
| 190 XtSetArg(args[a], gridRowspan, ctn->layout.rowspan); a++; |
188 XtSetArg(args[a], gridRowspan, ctn->layout.rowspan); a++; |
| 191 } |
189 } |
| 192 |
190 |
| 193 if(grid->container.layout.fill == UI_ON) { |
191 int hexpand = FALSE; |
| 194 grid->container.layout.hfill = TRUE; |
192 int vexpand = FALSE; |
| 195 grid->container.layout.vfill = TRUE; |
193 int hfill = FALSE; |
| 196 grid->container.layout.hexpand = TRUE; |
194 int vfill = FALSE; |
| 197 grid->container.layout.vexpand = TRUE; |
195 if(!ctn->layout.override_defaults) { |
| 198 } |
196 if(grid->def_hexpand) { |
| 199 |
197 hexpand = TRUE; |
| 200 if(grid->container.layout.hfill) { |
198 hfill = TRUE; |
| |
199 } else if(grid->def_hfill) { |
| |
200 hfill = TRUE; |
| |
201 } |
| |
202 if(grid->def_vexpand) { |
| |
203 vexpand = TRUE; |
| |
204 vfill = TRUE; |
| |
205 } else if(grid->def_vfill) { |
| |
206 vfill = TRUE; |
| |
207 } |
| |
208 } |
| |
209 |
| |
210 if(ctn->layout.hexpand) { |
| |
211 hexpand = TRUE; |
| |
212 hfill = TRUE; |
| |
213 } else if(ctn->layout.hfill) { |
| |
214 hfill = TRUE; |
| |
215 } |
| |
216 if(ctn->layout.vexpand) { |
| |
217 vexpand = TRUE; |
| |
218 vfill = TRUE; |
| |
219 } else if(ctn->layout.vfill) { |
| |
220 vfill = TRUE; |
| |
221 } |
| |
222 if(ctn->layout.fill == UI_ON) { |
| |
223 hexpand = TRUE; |
| |
224 vexpand = TRUE; |
| |
225 hfill = TRUE; |
| |
226 vfill = TRUE; |
| |
227 } |
| |
228 |
| |
229 if(hfill) { |
| 201 XtSetArg(args[a], gridHFill, TRUE); a++; |
230 XtSetArg(args[a], gridHFill, TRUE); a++; |
| 202 } |
231 } |
| 203 if(grid->container.layout.vfill) { |
232 if(vfill) { |
| 204 XtSetArg(args[a], gridVFill, TRUE); a++; |
233 XtSetArg(args[a], gridVFill, TRUE); a++; |
| 205 } |
234 } |
| 206 if(grid->container.layout.hexpand) { |
235 if(hexpand) { |
| 207 XtSetArg(args[a], gridHExpand, TRUE); a++; |
236 XtSetArg(args[a], gridHExpand, TRUE); a++; |
| 208 } |
237 } |
| 209 if(grid->container.layout.vexpand) { |
238 if(vexpand) { |
| 210 XtSetArg(args[a], gridVExpand, TRUE); a++; |
239 XtSetArg(args[a], gridVExpand, TRUE); a++; |
| 211 } |
240 } |
| 212 |
241 |
| 213 *n = a; |
242 *n = a; |
| 214 return ctn->widget; |
243 return ctn->widget; |
| 555 |
584 |
| 556 void ui_tabview_container_add(UiContainerPrivate *ctn, Widget widget) { |
585 void ui_tabview_container_add(UiContainerPrivate *ctn, Widget widget) { |
| 557 ui_reset_layout(ctn->layout); |
586 ui_reset_layout(ctn->layout); |
| 558 } |
587 } |
| 559 |
588 |
| 560 |
589 /* -------------------- ScrolledWindow -------------------- */ |
| |
590 |
| |
591 Widget ui_scrolledwindow_prepare(UiContainerPrivate *ctn, Arg *args, int *n) { |
| |
592 return ctn->widget; |
| |
593 } |
| |
594 |
| |
595 void ui_scrolledwindow_add(UiContainerPrivate *ctn, Widget widget) { |
| |
596 |
| |
597 } |
| |
598 |
| |
599 static UiContainerX* ui_scrolledwindow_container(UiObject *obj, Widget scrolledwindow) { |
| |
600 UiContainerPrivate *ctn = ui_malloc(obj->ctx, sizeof(UiContainerPrivate)); |
| |
601 memset(ctn, 0, sizeof(UiContainerPrivate)); |
| |
602 ctn->prepare = ui_scrolledwindow_prepare; |
| |
603 ctn->add = ui_scrolledwindow_add; |
| |
604 ctn->widget = scrolledwindow; |
| |
605 return (UiContainerX*)ctn; |
| |
606 } |
| |
607 |
| |
608 UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiFrameArgs args) { |
| |
609 UiContainerPrivate *ctn = ui_obj_container(obj); |
| |
610 UI_APPLY_LAYOUT(ctn->layout, args); |
| |
611 |
| |
612 Arg xargs[16]; |
| |
613 int n = 0; |
| |
614 |
| |
615 XtSetArg(xargs[n], XmNscrollingPolicy, XmAUTOMATIC); n++; |
| |
616 |
| |
617 Widget parent = ctn->prepare(ctn, xargs, &n); |
| |
618 Widget scrolledwindow = XmCreateScrolledWindow(parent, "scrolledwindow", xargs, n); |
| |
619 ctn->add(ctn, scrolledwindow); |
| |
620 |
| |
621 UiContainerX *container = ui_scrolledwindow_container(obj, scrolledwindow); |
| |
622 uic_object_push_container(obj, container); |
| |
623 |
| |
624 return scrolledwindow; |
| |
625 } |
| 561 |
626 |
| 562 /* -------------------- Container Helper Functions -------------------- */ |
627 /* -------------------- Container Helper Functions -------------------- */ |
| 563 |
628 |
| 564 void ui_container_begin_close(UiObject *obj) { |
629 void ui_container_begin_close(UiObject *obj) { |
| 565 UiContainerPrivate *ct = ui_obj_container(obj); |
630 UiContainerPrivate *ct = ui_obj_container(obj); |