66 #else |
66 #else |
67 return gtk_hbox_new(FALSE, spacing); |
67 return gtk_hbox_new(FALSE, spacing); |
68 #endif |
68 #endif |
69 } |
69 } |
70 |
70 |
|
71 GtkWidget* ui_subcontainer_create( |
|
72 UiSubContainerType type, |
|
73 UiObject *newobj, |
|
74 int spacing, |
|
75 int columnspacing, |
|
76 int rowspacing, |
|
77 int margin) |
|
78 { |
|
79 GtkWidget *sub = NULL; |
|
80 GtkWidget *add = NULL; |
|
81 switch(type) { |
|
82 default: { |
|
83 sub = ui_gtk_vbox_new(spacing); |
|
84 add = ui_box_set_margin(sub, margin); |
|
85 newobj->container = ui_box_container(newobj, sub, type); |
|
86 newobj->widget = sub; |
|
87 break; |
|
88 } |
|
89 case UI_CONTAINER_HBOX: { |
|
90 sub = ui_gtk_hbox_new(spacing); |
|
91 add = ui_box_set_margin(sub, margin); |
|
92 newobj->container = ui_box_container(newobj, sub, type); |
|
93 newobj->widget = sub; |
|
94 break; |
|
95 } |
|
96 case UI_CONTAINER_GRID: { |
|
97 sub = ui_create_grid_widget(columnspacing, rowspacing); |
|
98 add = ui_box_set_margin(sub, margin); |
|
99 newobj->container = ui_grid_container(newobj, sub); |
|
100 newobj->widget = sub; |
|
101 break; |
|
102 } |
|
103 case UI_CONTAINER_NO_SUB: { |
|
104 break; |
|
105 } |
|
106 } |
|
107 return add; |
|
108 } |
71 |
109 |
72 |
110 |
73 /* -------------------- Box Container -------------------- */ |
111 /* -------------------- Box Container -------------------- */ |
74 UiContainer* ui_box_container(UiObject *obj, GtkWidget *box, UiSubContainerType type) { |
112 UiContainer* ui_box_container(UiObject *obj, GtkWidget *box, UiSubContainerType type) { |
75 UiBoxContainer *ct = cxCalloc( |
113 UiBoxContainer *ct = cxCalloc( |
199 ui_reset_layout(ct->layout); |
237 ui_reset_layout(ct->layout); |
200 ct->current = widget; |
238 ct->current = widget; |
201 } |
239 } |
202 #endif |
240 #endif |
203 |
241 |
|
242 UiContainer* ui_frame_container(UiObject *obj, GtkWidget *frame) { |
|
243 UiContainer *ct = cxCalloc( |
|
244 obj->ctx->allocator, |
|
245 1, |
|
246 sizeof(UiContainer)); |
|
247 ct->widget = frame; |
|
248 ct->add = ui_frame_container_add; |
|
249 return ct; |
|
250 } |
|
251 |
|
252 void ui_frame_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) { |
|
253 FRAME_SET_CHILD(ct->widget, widget); |
|
254 } |
|
255 |
|
256 UiContainer* ui_expander_container(UiObject *obj, GtkWidget *expander) { |
|
257 UiContainer *ct = cxCalloc( |
|
258 obj->ctx->allocator, |
|
259 1, |
|
260 sizeof(UiContainer)); |
|
261 ct->widget = expander; |
|
262 ct->add = ui_expander_container_add; |
|
263 return ct; |
|
264 } |
|
265 |
|
266 void ui_expander_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) { |
|
267 EXPANDER_SET_CHILD(ct->widget, widget); |
|
268 } |
|
269 |
|
270 void ui_scrolledwindow_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) { |
|
271 // TODO: check if the widget implements GtkScrollable |
|
272 SCROLLEDWINDOW_SET_CHILD(ct->widget, widget); |
|
273 ui_reset_layout(ct->layout); |
|
274 ct->current = widget; |
|
275 } |
|
276 |
204 UiContainer* ui_scrolledwindow_container(UiObject *obj, GtkWidget *scrolledwindow) { |
277 UiContainer* ui_scrolledwindow_container(UiObject *obj, GtkWidget *scrolledwindow) { |
205 UiContainer *ct = cxCalloc( |
278 UiContainer *ct = cxCalloc( |
206 obj->ctx->allocator, |
279 obj->ctx->allocator, |
207 1, |
280 1, |
208 sizeof(UiContainer)); |
281 sizeof(UiContainer)); |
209 ct->widget = scrolledwindow; |
282 ct->widget = scrolledwindow; |
210 ct->add = ui_scrolledwindow_container_add; |
283 ct->add = ui_scrolledwindow_container_add; |
211 return ct; |
284 return ct; |
212 } |
|
213 |
|
214 void ui_scrolledwindow_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) { |
|
215 // TODO: check if the widget implements GtkScrollable |
|
216 SCROLLEDWINDOW_SET_CHILD(ct->widget, widget); |
|
217 ui_reset_layout(ct->layout); |
|
218 ct->current = widget; |
|
219 } |
285 } |
220 |
286 |
221 UiContainer* ui_tabview_container(UiObject *obj, GtkWidget *tabview) { |
287 UiContainer* ui_tabview_container(UiObject *obj, GtkWidget *tabview) { |
222 UiTabViewContainer *ct = cxCalloc( |
288 UiTabViewContainer *ct = cxCalloc( |
223 obj->ctx->allocator, |
289 obj->ctx->allocator, |
316 uic_obj_add(obj, newobj); |
382 uic_obj_add(obj, newobj); |
317 |
383 |
318 return widget; |
384 return widget; |
319 } |
385 } |
320 |
386 |
|
387 UIWIDGET ui_frame_create(UiObject *obj, UiFrameArgs args) { |
|
388 UiObject* current = uic_current_obj(obj); |
|
389 UI_APPLY_LAYOUT1(current, args); |
|
390 |
|
391 GtkWidget *frame = gtk_frame_new(args.label); |
|
392 UiObject *newobj = uic_object_new(obj, frame); |
|
393 GtkWidget *sub = ui_subcontainer_create(args.subcontainer, newobj, args.spacing, args.columnspacing, args.rowspacing, args.margin); |
|
394 if(sub) { |
|
395 FRAME_SET_CHILD(frame, sub); |
|
396 } else { |
|
397 newobj->widget = frame; |
|
398 newobj->container = ui_frame_container(obj, frame); |
|
399 } |
|
400 current->container->add(current->container, frame, FALSE); |
|
401 uic_obj_add(obj, newobj); |
|
402 |
|
403 return frame; |
|
404 } |
|
405 |
|
406 UIEXPORT UIWIDGET ui_expander_create(UiObject *obj, UiFrameArgs args) { |
|
407 UiObject* current = uic_current_obj(obj); |
|
408 UI_APPLY_LAYOUT1(current, args); |
|
409 |
|
410 GtkWidget *expander = gtk_expander_new(args.label); |
|
411 gtk_expander_set_expanded(GTK_EXPANDER(expander), args.isexpanded); |
|
412 UiObject *newobj = uic_object_new(obj, expander); |
|
413 GtkWidget *sub = ui_subcontainer_create(args.subcontainer, newobj, args.spacing, args.columnspacing, args.rowspacing, args.margin); |
|
414 if(sub) { |
|
415 EXPANDER_SET_CHILD(expander, sub); |
|
416 } else { |
|
417 newobj->widget = expander; |
|
418 newobj->container = ui_expander_container(obj, expander); |
|
419 } |
|
420 current->container->add(current->container, expander, FALSE); |
|
421 uic_obj_add(obj, newobj); |
|
422 |
|
423 return expander; |
|
424 } |
|
425 |
321 |
426 |
322 UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiFrameArgs args) { |
427 UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiFrameArgs args) { |
323 UiObject* current = uic_current_obj(obj); |
428 UiObject* current = uic_current_obj(obj); |
324 UI_APPLY_LAYOUT1(current, args); |
429 UI_APPLY_LAYOUT1(current, args); |
325 |
430 |
326 GtkWidget *sw = SCROLLEDWINDOW_NEW(); |
431 GtkWidget *sw = SCROLLEDWINDOW_NEW(); |
327 ui_set_name_and_style(sw, args.name, args.style_class); |
432 ui_set_name_and_style(sw, args.name, args.style_class); |
|
433 GtkWidget *widget = ui_box_set_margin(sw, args.margin); |
|
434 current->container->add(current->container, widget, TRUE); |
|
435 |
328 UiObject *newobj = uic_object_new(obj, sw); |
436 UiObject *newobj = uic_object_new(obj, sw); |
329 newobj->container = ui_scrolledwindow_container(obj, sw); |
437 GtkWidget *sub = ui_subcontainer_create(args.subcontainer, newobj, args.spacing, args.columnspacing, args.rowspacing, args.margin); |
|
438 if(sub) { |
|
439 SCROLLEDWINDOW_SET_CHILD(sw, sub); |
|
440 } else { |
|
441 newobj->widget = sw; |
|
442 newobj->container = ui_scrolledwindow_container(obj, sw); |
|
443 } |
|
444 |
330 uic_obj_add(obj, newobj); |
445 uic_obj_add(obj, newobj); |
331 |
446 |
332 return sw; |
447 return sw; |
333 } |
448 } |
334 |
449 |