ui/motif/container.c

changeset 64
6ef2c7f73a30
parent 63
46a42f0c4f93
child 65
4697592e24ba
equal deleted inserted replaced
63:46a42f0c4f93 64:6ef2c7f73a30
300 } 300 }
301 301
302 ucx_list_free(rowdim); 302 ucx_list_free(rowdim);
303 } 303 }
304 304
305 UiContainer* ui_tabview_container(UiObject *obj, Widget frame) {
306 UiTabViewContainer *ct = ucx_mempool_calloc(
307 obj->ctx->mempool,
308 1,
309 sizeof(UiTabViewContainer));
310 ct->context = obj->ctx;
311 ct->container.widget = frame;
312 ct->container.prepare = ui_tabview_container_prepare;
313 ct->container.add = ui_tabview_container_add;
314 return (UiContainer*)ct;
315 }
316
317 Widget ui_tabview_container_prepare(UiContainer *ct, Arg *args, int *n, UiBool fill) {
318 int a = *n;
319 XtSetArg(args[a], XmNleftAttachment, XmATTACH_FORM); a++;
320 XtSetArg(args[a], XmNrightAttachment, XmATTACH_FORM); a++;
321 XtSetArg(args[a], XmNtopAttachment, XmATTACH_FORM); a++;
322 XtSetArg(args[a], XmNbottomAttachment, XmATTACH_FORM); a++;
323 *n = a;
324 return ct->widget;
325 }
326
327 void ui_tabview_container_add(UiContainer *ct, Widget widget) {
328 UiTabViewContainer *tabview = (UiTabViewContainer*)ct;
329
330 if(tabview->current) {
331 XtUnmanageChild(tabview->current);
332 }
333 if(tabview->tabs) {
334 // not the first tab, so unmanage the new widget
335 //XtUnmanageChild(widget);
336 } else {
337 tabview->current = widget;
338 }
339 tabview->current = widget;
340
341 tabview->tabs = ucx_list_append(tabview->tabs, widget);
342
343 ui_reset_layout(ct->layout);
344 }
345
305 UIWIDGET ui_box(UiObject *obj, UiBoxOrientation orientation) { 346 UIWIDGET ui_box(UiObject *obj, UiBoxOrientation orientation) {
306 UiContainer *ct = uic_get_current_container(obj); 347 UiContainer *ct = uic_get_current_container(obj);
307 348
308 Arg args[16]; 349 Arg args[16];
309 int n = 0; 350 int n = 0;
378 uic_obj_add(obj, right); 419 uic_obj_add(obj, right);
379 uic_obj_add(obj, left); 420 uic_obj_add(obj, left);
380 421
381 return sidebar; 422 return sidebar;
382 } 423 }
424
425 UIWIDGET ui_tabview(UiObject *obj) {
426 UiContainer *ct = uic_get_current_container(obj);
427
428 // create a simple frame as container widget
429 // when tabs are selected, the current child will be replaced by the
430 // the new tab widget
431 Arg args[16];
432 int n = 0;
433 XtSetArg(args[n], XmNshadowType, XmSHADOW_ETCHED_OUT);
434 n++;
435 XtSetArg(args[n], XmNshadowThickness, 0);
436 n++;
437 Widget parent = ct->prepare(ct, args, &n, TRUE);
438 Widget form = XmCreateForm(parent, "tabview", args, n);
439 ct->add(ct, form);
440 XtManageChild(form);
441
442 UiObject *tabviewobj = uic_object_new(obj, form);
443 tabviewobj->container = ui_tabview_container(obj, form);
444 uic_obj_add(obj, tabviewobj);
445
446 XtVaSetValues(form, XmNuserData, tabviewobj->container, NULL);
447
448 return form;
449 }
450
451 void ui_tab(UiObject *obj, char *title) {
452 UiContainer *ct = uic_get_current_container(obj);
453 ct->layout.label = title;
454
455 ui_vbox(obj);
456 }
457
458 void ui_select_tab(UIWIDGET tabview, int tab) {
459 UiTabViewContainer *ct = NULL;
460 XtVaGetValues(tabview, XmNuserData, &ct, NULL);
461 if(ct) {
462 XtUnmanageChild(ct->current);
463 UcxList *elm = ucx_list_get(ct->tabs, tab);
464 if(elm) {
465 XtManageChild(elm->data);
466 ct->current = elm->data;
467 } else {
468 fprintf(stderr, "UiError: front tab index: %d\n", tab);
469 }
470 } else {
471 fprintf(stderr, "UiError: widget is not a tabview\n");
472 }
473 }
474
475
476 /* document tabview */
383 477
384 UiTabbedPane* ui_tabbed_document_view(UiObject *obj) { 478 UiTabbedPane* ui_tabbed_document_view(UiObject *obj) {
385 int n = 0; 479 int n = 0;
386 Arg args[16]; 480 Arg args[16];
387 481

mercurial