| 31 #include <inttypes.h> |
31 #include <inttypes.h> |
| 32 |
32 |
| 33 #include "container.h" |
33 #include "container.h" |
| 34 #include "../common/context.h" |
34 #include "../common/context.h" |
| 35 #include "../common/object.h" |
35 #include "../common/object.h" |
| |
36 #include "../common/container.h" |
| 36 |
37 |
| 37 #include <cx/array_list.h> |
38 #include <cx/array_list.h> |
| 38 |
39 |
| 39 #include "Grid.h" |
40 #include "Grid.h" |
| 40 |
41 |
| 41 |
42 |
| |
43 |
| |
44 Widget ui_container_prepare(UiContainerPrivate *container, UiLayout *layout, Arg *args, int *n) { |
| |
45 if(layout->margin != 0) { |
| |
46 layout->margin_left = layout->margin; |
| |
47 layout->margin_right = layout->margin; |
| |
48 layout->margin_top = layout->margin; |
| |
49 layout->margin_bottom = layout->margin; |
| |
50 } |
| |
51 return container->prepare(container, layout, args, n); |
| |
52 } |
| |
53 |
| |
54 void ui_container_add(UiContainerPrivate *container, Widget widget) { |
| |
55 container->add(container, widget); |
| |
56 } |
| 42 |
57 |
| 43 |
58 |
| 44 /* ---------------------------- Box Container ---------------------------- */ |
59 /* ---------------------------- Box Container ---------------------------- */ |
| 45 |
60 |
| 46 static UIWIDGET box_create(UiObject *obj, UiContainerArgs *args, UiBoxOrientation orientation) { |
61 static UIWIDGET box_create(UiObject *obj, UiContainerArgs *args, UiBoxOrientation orientation) { |
| 47 UiContainerPrivate *ctn = ui_obj_container(obj); |
62 UiContainerPrivate *ctn = ui_obj_container(obj); |
| 48 UI_APPLY_LAYOUT(ctn->layout, args); |
63 UiLayout layout = UI_ARGS2LAYOUT(args); |
| 49 |
64 |
| 50 Arg xargs[16]; |
65 Arg xargs[16]; |
| 51 int n = 0; |
66 int n = 0; |
| 52 |
67 |
| 53 if(orientation == UI_BOX_VERTICAL) { |
68 if(orientation == UI_BOX_VERTICAL) { |
| 54 //XtSetArg(xargs[n], gridRowSpacing, args->spacing); n++; |
69 //XtSetArg(xargs[n], gridRowSpacing, args->spacing); n++; |
| 55 } else { |
70 } else { |
| 56 //XtSetArg(xargs[n], gridColumnSpacing, args->spacing); n++; |
71 //XtSetArg(xargs[n], gridColumnSpacing, args->spacing); n++; |
| 57 } |
72 } |
| 58 |
73 |
| 59 Widget parent = ctn->prepare(ctn, xargs, &n); |
74 Widget parent = ui_container_prepare(ctn, &layout, xargs, &n); |
| 60 Widget grid = XtCreateManagedWidget(args->name ? args->name : "boxcontainer", gridClass, parent, xargs, n); |
75 Widget grid = XtCreateManagedWidget(args->name ? args->name : "boxcontainer", gridClass, parent, xargs, n); |
| 61 ctn->add(ctn, grid); |
76 ctn->add(ctn, grid); |
| 62 |
77 |
| 63 UiContainerX *container = ui_box_container(obj, grid, orientation); |
78 UiContainerX *container = ui_box_container(obj, grid, orientation); |
| 64 uic_object_push_container(obj, container); |
79 uic_object_push_container(obj, container); |
| 84 ctn->container.widget = grid; |
99 ctn->container.widget = grid; |
| 85 ctn->n = 0; |
100 ctn->n = 0; |
| 86 return (UiContainerX*)ctn; |
101 return (UiContainerX*)ctn; |
| 87 } |
102 } |
| 88 |
103 |
| 89 static Widget ui_box_container_prepare(UiBoxContainer *box, Arg *args, int *n) { |
104 static Widget ui_box_container_prepare(UiBoxContainer *box, UiLayout *layout, Arg *args, int *n) { |
| 90 int a = *n; |
105 int a = *n; |
| 91 box->n++; |
106 box->n++; |
| 92 return box->container.widget; |
107 return box->container.widget; |
| 93 } |
108 } |
| 94 |
109 |
| 95 Widget ui_vbox_prepare(UiContainerPrivate *ctn, Arg *args, int *n) { |
110 Widget ui_vbox_prepare(UiContainerPrivate *ctn, UiLayout *layout, Arg *args, int *n) { |
| 96 UiBoxContainer *box = (UiBoxContainer*)ctn; |
111 UiBoxContainer *box = (UiBoxContainer*)ctn; |
| 97 int a = *n; |
112 int a = *n; |
| 98 XtSetArg(args[a], gridRow, box->n); a++; |
113 XtSetArg(args[a], gridRow, box->n); a++; |
| 99 if(box->container.layout.fill == UI_ON) { |
114 if(layout->fill) { |
| 100 XtSetArg(args[a], gridVExpand, TRUE); a++; |
115 XtSetArg(args[a], gridVExpand, TRUE); a++; |
| 101 XtSetArg(args[a], gridVFill, TRUE); a++; |
116 XtSetArg(args[a], gridVFill, TRUE); a++; |
| 102 } |
117 } |
| 103 XtSetArg(args[a], gridHExpand, TRUE); a++; |
118 XtSetArg(args[a], gridHExpand, TRUE); a++; |
| 104 XtSetArg(args[a], gridHFill, TRUE); a++; |
119 XtSetArg(args[a], gridHFill, TRUE); a++; |
| 105 *n = a; |
120 *n = a; |
| 106 return ui_box_container_prepare(box, args, n); |
121 return ui_box_container_prepare(box, layout, args, n); |
| 107 } |
122 } |
| 108 |
123 |
| 109 Widget ui_hbox_prepare(UiContainerPrivate *ctn, Arg *args, int *n) { |
124 Widget ui_hbox_prepare(UiContainerPrivate *ctn, UiLayout *layout, Arg *args, int *n) { |
| 110 UiBoxContainer *box = (UiBoxContainer*)ctn; |
125 UiBoxContainer *box = (UiBoxContainer*)ctn; |
| 111 int a = *n; |
126 int a = *n; |
| 112 XtSetArg(args[a], gridColumn, box->n); a++; |
127 XtSetArg(args[a], gridColumn, box->n); a++; |
| 113 if(box->container.layout.fill == UI_ON) { |
128 if(layout->fill) { |
| 114 XtSetArg(args[a], gridHExpand, TRUE); a++; |
129 XtSetArg(args[a], gridHExpand, TRUE); a++; |
| 115 XtSetArg(args[a], gridHFill, TRUE); a++; |
130 XtSetArg(args[a], gridHFill, TRUE); a++; |
| 116 } |
131 } |
| 117 XtSetArg(args[a], gridVExpand, TRUE); a++; |
132 XtSetArg(args[a], gridVExpand, TRUE); a++; |
| 118 XtSetArg(args[a], gridVFill, TRUE); a++; |
133 XtSetArg(args[a], gridVFill, TRUE); a++; |
| 119 *n = a; |
134 *n = a; |
| 120 return ui_box_container_prepare(box, args, n); |
135 return ui_box_container_prepare(box, layout, args, n); |
| 121 } |
136 } |
| 122 |
137 |
| 123 void ui_box_container_add(UiContainerPrivate *ctn, Widget widget) { |
138 void ui_box_container_add(UiContainerPrivate *ctn, Widget widget) { |
| 124 ui_reset_layout(ctn->layout); |
139 |
| 125 |
|
| 126 } |
140 } |
| 127 |
141 |
| 128 |
142 |
| 129 /* ---------------------------- Grid Container ---------------------------- */ |
143 /* ---------------------------- Grid Container ---------------------------- */ |
| 130 |
144 |
| 132 UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs *args) { |
146 UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs *args) { |
| 133 Arg xargs[16]; |
147 Arg xargs[16]; |
| 134 int n = 0; |
148 int n = 0; |
| 135 |
149 |
| 136 UiContainerPrivate *ctn = ui_obj_container(obj); |
150 UiContainerPrivate *ctn = ui_obj_container(obj); |
| 137 UI_APPLY_LAYOUT(ctn->layout, args); |
151 UiLayout layout = UI_ARGS2LAYOUT(args); |
| 138 |
152 |
| 139 Widget parent = ctn->prepare(ctn, xargs, &n); |
153 Widget parent = ui_container_prepare(ctn, &layout, xargs, &n); |
| 140 XtSetArg(xargs[n], gridMargin, args->margin); n++; |
154 XtSetArg(xargs[n], gridMargin, args->margin); n++; |
| 141 XtSetArg(xargs[n], gridColumnSpacing, args->columnspacing); n++; |
155 XtSetArg(xargs[n], gridColumnSpacing, args->columnspacing); n++; |
| 142 XtSetArg(xargs[n], gridRowSpacing, args->rowspacing); n++; |
156 XtSetArg(xargs[n], gridRowSpacing, args->rowspacing); n++; |
| 143 Widget grid = XtCreateManagedWidget(args->name ? args->name : "gridcontainer", gridClass, parent, xargs, n); |
157 Widget grid = XtCreateManagedWidget(args->name ? args->name : "gridcontainer", gridClass, parent, xargs, n); |
| 144 ctn->add(ctn, grid); |
158 ui_container_add(ctn, grid); |
| 145 |
159 |
| 146 UiContainerX *container = ui_grid_container(obj, grid, args->def_hexpand, args->def_vexpand, args->def_hfill, args->def_vfill); |
160 UiContainerX *container = ui_grid_container(obj, grid, args->def_hexpand, args->def_vexpand, args->def_hfill, args->def_vfill); |
| 147 uic_object_push_container(obj, container); |
161 uic_object_push_container(obj, container); |
| 148 |
162 |
| 149 return grid; |
163 return grid; |
| 169 ctn->def_hfill = def_hfill; |
183 ctn->def_hfill = def_hfill; |
| 170 ctn->def_vfill = def_vfill; |
184 ctn->def_vfill = def_vfill; |
| 171 return (UiContainerX*)ctn; |
185 return (UiContainerX*)ctn; |
| 172 } |
186 } |
| 173 |
187 |
| 174 Widget ui_grid_container_prepare(UiContainerPrivate *ctn, Arg *args, int *n) { |
188 Widget ui_grid_container_prepare(UiContainerPrivate *ctn, UiLayout *layout, Arg *args, int *n) { |
| 175 UiGridContainer *grid = (UiGridContainer*)ctn; |
189 UiGridContainer *grid = (UiGridContainer*)ctn; |
| 176 if(ctn->layout.newline) { |
190 if(ctn->container.newline) { |
| 177 grid->y++; |
191 grid->y++; |
| 178 grid->x = 0; |
192 grid->x = 0; |
| 179 } |
193 } |
| 180 |
194 |
| 181 int a = *n; |
195 int a = *n; |
| 182 XtSetArg(args[a], gridColumn, grid->x); a++; |
196 XtSetArg(args[a], gridColumn, grid->x); a++; |
| 183 XtSetArg(args[a], gridRow, grid->y); a++; |
197 XtSetArg(args[a], gridRow, grid->y); a++; |
| 184 if(ctn->layout.colspan > 0) { |
198 if(layout->colspan > 0) { |
| 185 XtSetArg(args[a], gridColspan, ctn->layout.colspan); a++; |
199 XtSetArg(args[a], gridColspan, layout->colspan); a++; |
| 186 } |
200 } |
| 187 if(ctn->layout.rowspan > 0) { |
201 if(layout->rowspan > 0) { |
| 188 XtSetArg(args[a], gridRowspan, ctn->layout.rowspan); a++; |
202 XtSetArg(args[a], gridRowspan, layout->rowspan); a++; |
| 189 } |
203 } |
| 190 |
204 |
| 191 int hexpand = FALSE; |
205 uic_layout_setup_expand_fill(layout, grid->def_hexpand, grid->def_vexpand, grid->def_hfill, grid->def_vfill); |
| 192 int vexpand = FALSE; |
206 |
| 193 int hfill = FALSE; |
207 if(layout->hfill) { |
| 194 int vfill = FALSE; |
|
| 195 if(!ctn->layout.override_defaults) { |
|
| 196 if(grid->def_hexpand) { |
|
| 197 hexpand = TRUE; |
|
| 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) { |
|
| 230 XtSetArg(args[a], gridHFill, TRUE); a++; |
208 XtSetArg(args[a], gridHFill, TRUE); a++; |
| 231 } |
209 } |
| 232 if(vfill) { |
210 if(layout->vfill) { |
| 233 XtSetArg(args[a], gridVFill, TRUE); a++; |
211 XtSetArg(args[a], gridVFill, TRUE); a++; |
| 234 } |
212 } |
| 235 if(hexpand) { |
213 if(layout->hexpand) { |
| 236 XtSetArg(args[a], gridHExpand, TRUE); a++; |
214 XtSetArg(args[a], gridHExpand, TRUE); a++; |
| 237 } |
215 } |
| 238 if(vexpand) { |
216 if(layout->vexpand) { |
| 239 XtSetArg(args[a], gridVExpand, TRUE); a++; |
217 XtSetArg(args[a], gridVExpand, TRUE); a++; |
| 240 } |
218 } |
| 241 |
219 |
| 242 *n = a; |
220 *n = a; |
| 243 return ctn->widget; |
221 return ctn->widget; |
| 244 } |
222 } |
| 245 |
223 |
| 246 void ui_grid_container_add(UiContainerPrivate *ctn, Widget widget) { |
224 void ui_grid_container_add(UiContainerPrivate *ctn, Widget widget) { |
| 247 UiGridContainer *grid = (UiGridContainer*)ctn; |
225 UiGridContainer *grid = (UiGridContainer*)ctn; |
| 248 grid->x++; |
226 grid->x++; |
| 249 ui_reset_layout(ctn->layout); |
227 grid->container.container.newline = FALSE; |
| 250 } |
228 } |
| 251 |
229 |
| 252 |
230 |
| 253 /* -------------------------- TabView Container -------------------------- */ |
231 /* -------------------------- TabView Container -------------------------- */ |
| 254 |
232 |
| 311 UIWIDGET ui_tabview_create(UiObject *obj, UiTabViewArgs *args) { |
289 UIWIDGET ui_tabview_create(UiObject *obj, UiTabViewArgs *args) { |
| 312 Arg xargs[16]; |
290 Arg xargs[16]; |
| 313 int n = 0; |
291 int n = 0; |
| 314 |
292 |
| 315 UiContainerPrivate *ctn = ui_obj_container(obj); |
293 UiContainerPrivate *ctn = ui_obj_container(obj); |
| 316 UI_APPLY_LAYOUT(ctn->layout, args); |
294 UiLayout layout = UI_ARGS2LAYOUT(args); |
| 317 |
295 |
| 318 // create widgets |
296 // create widgets |
| 319 // form |
297 // form |
| 320 // - tabbar (Drawing Area) |
298 // - tabbar (Drawing Area) |
| 321 // - content (Frame) |
299 // - content (Frame) |
| 322 UiMotifTabView *tabview = malloc(sizeof(UiMotifTabView)); |
300 UiMotifTabView *tabview = malloc(sizeof(UiMotifTabView)); |
| 323 memset(tabview, 0, sizeof(UiMotifTabView)); |
301 memset(tabview, 0, sizeof(UiMotifTabView)); |
| 324 char *name = args->name ? (char*)args->name : "tabview"; |
302 char *name = args->name ? (char*)args->name : "tabview"; |
| 325 XtSetArg(xargs[n], XmNuserData, tabview); n++; |
303 XtSetArg(xargs[n], XmNuserData, tabview); n++; |
| 326 Widget parent = ctn->prepare(ctn, xargs, &n); |
304 Widget parent = ui_container_prepare(ctn, &layout, xargs, &n); |
| 327 Widget form = XmCreateForm(parent, name, xargs, n); |
305 Widget form = XmCreateForm(parent, name, xargs, n); |
| 328 XtManageChild(form); |
306 XtManageChild(form); |
| |
307 ui_container_add(ctn, parent); |
| 329 |
308 |
| 330 n = 0; |
309 n = 0; |
| 331 XtSetArg(xargs[n], XmNleftAttachment, XmATTACH_FORM); n++; |
310 XtSetArg(xargs[n], XmNleftAttachment, XmATTACH_FORM); n++; |
| 332 XtSetArg(xargs[n], XmNrightAttachment, XmATTACH_FORM); n++; |
311 XtSetArg(xargs[n], XmNrightAttachment, XmATTACH_FORM); n++; |
| 333 XtSetArg(xargs[n], XmNtopAttachment, XmATTACH_FORM); n++; |
312 XtSetArg(xargs[n], XmNtopAttachment, XmATTACH_FORM); n++; |
| 567 tabview->current_tab = tab; |
546 tabview->current_tab = tab; |
| 568 tabview->current_index = (int)cxListFind(tabview->tabs, tab);; |
547 tabview->current_index = (int)cxListFind(tabview->tabs, tab);; |
| 569 XtManageChild(tab->child); |
548 XtManageChild(tab->child); |
| 570 } |
549 } |
| 571 |
550 |
| 572 Widget ui_tabview_container_prepare(UiContainerPrivate *ctn, Arg *args, int *n) { |
551 Widget ui_tabview_container_prepare(UiContainerPrivate *ctn, UiLayout *layout, Arg *args, int *n) { |
| 573 UiTabViewContainer *ct = (UiTabViewContainer*)ctn; |
552 UiTabViewContainer *ct = (UiTabViewContainer*)ctn; |
| 574 UiMotifTabView *tabview = ct->tabview; |
553 UiMotifTabView *tabview = ct->tabview; |
| 575 int a = *n; |
554 int a = *n; |
| 576 XtSetArg(args[a], XmNleftAttachment, XmATTACH_FORM); a++; |
555 XtSetArg(args[a], XmNleftAttachment, XmATTACH_FORM); a++; |
| 577 XtSetArg(args[a], XmNrightAttachment, XmATTACH_FORM); a++; |
556 XtSetArg(args[a], XmNrightAttachment, XmATTACH_FORM); a++; |
| 605 return (UiContainerX*)ctn; |
584 return (UiContainerX*)ctn; |
| 606 } |
585 } |
| 607 |
586 |
| 608 UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiFrameArgs *args) { |
587 UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiFrameArgs *args) { |
| 609 UiContainerPrivate *ctn = ui_obj_container(obj); |
588 UiContainerPrivate *ctn = ui_obj_container(obj); |
| 610 UI_APPLY_LAYOUT(ctn->layout, args); |
589 UiLayout layout = UI_ARGS2LAYOUT(args); |
| 611 |
590 |
| 612 Arg xargs[16]; |
591 Arg xargs[16]; |
| 613 int n = 0; |
592 int n = 0; |
| 614 |
593 |
| 615 XtSetArg(xargs[n], XmNscrollingPolicy, XmAUTOMATIC); n++; |
594 XtSetArg(xargs[n], XmNscrollingPolicy, XmAUTOMATIC); n++; |
| 616 |
595 |
| 617 Widget parent = ctn->prepare(ctn, xargs, &n); |
596 Widget parent = ui_container_prepare(ctn, &layout, xargs, &n); |
| 618 Widget scrolledwindow = XmCreateScrolledWindow(parent, "scrolledwindow", xargs, n); |
597 Widget scrolledwindow = XmCreateScrolledWindow(parent, "scrolledwindow", xargs, n); |
| 619 ctn->add(ctn, scrolledwindow); |
598 ui_container_add(ctn, scrolledwindow); |
| 620 |
599 |
| 621 UiContainerX *container = ui_scrolledwindow_container(obj, scrolledwindow); |
600 UiContainerX *container = ui_scrolledwindow_container(obj, scrolledwindow); |
| 622 uic_object_push_container(obj, container); |
601 uic_object_push_container(obj, container); |
| 623 |
602 |
| 624 return scrolledwindow; |
603 return scrolledwindow; |