ui/motif/container.c

changeset 475
8e06a446d552
parent 461
b480e133b576
child 480
7dfd5e546b99
equal deleted inserted replaced
474:971dd0f3a117 475:8e06a446d552
224 /* -------------------------- TabView Container -------------------------- */ 224 /* -------------------------- TabView Container -------------------------- */
225 225
226 static void ui_tabbar_resize(Widget widget, XtPointer udata, XtPointer cdata) { 226 static void ui_tabbar_resize(Widget widget, XtPointer udata, XtPointer cdata) {
227 UiMotifTabView *tabview = udata; 227 UiMotifTabView *tabview = udata;
228 228
229 if(tabview->tabview == UI_TABVIEW_INVISIBLE) {
230 return;
231 }
232
229 int width = 0; 233 int width = 0;
230 int height = 0; 234 int height = 0;
231 XtVaGetValues(widget, XmNwidth, &width, XmNheight, &height, NULL); 235 XtVaGetValues(widget, XmNwidth, &width, XmNheight, &height, NULL);
232 int numbuttons = cxListSize(tabview->tabs); 236 int numbuttons = cxListSize(tabview->tabs);
233 if(numbuttons == 0) { 237 if(numbuttons == 0) {
324 tabview->tabview = args.tabview; 328 tabview->tabview = args.tabview;
325 tabview->subcontainer = args.subcontainer; 329 tabview->subcontainer = args.subcontainer;
326 tabview->select = ui_motif_tabview_select; 330 tabview->select = ui_motif_tabview_select;
327 tabview->add = ui_motif_tabview_add_tab; 331 tabview->add = ui_motif_tabview_add_tab;
328 tabview->remove = ui_motif_tabview_remove; 332 tabview->remove = ui_motif_tabview_remove;
329 tabview->tabs = cxArrayListCreate(obj->ctx->allocator, NULL, sizeof(UiTab), 8); 333 tabview->tabs = cxArrayListCreate(obj->ctx->allocator, cx_cmp_ptr, sizeof(UiTab), 8);
334 tabview->current_index = -1;
330 335
331 UiTabViewContainer *ct = ui_malloc(obj->ctx, sizeof(UiTabViewContainer)); 336 UiTabViewContainer *ct = ui_malloc(obj->ctx, sizeof(UiTabViewContainer));
332 ct->container.widget = form; 337 ct->container.widget = form;
333 ct->container.type = UI_CONTAINER_TABVIEW; 338 ct->container.type = UI_CONTAINER_TABVIEW;
334 ct->container.prepare = ui_tabview_container_prepare; 339 ct->container.prepare = ui_tabview_container_prepare;
335 ct->container.add = ui_tabview_container_add; 340 ct->container.add = ui_tabview_container_add;
336 ct->tabview = tabview; 341 ct->tabview = tabview;
337 342
343 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args.value, args.varname, UI_VAR_INTEGER);
344 if(var) {
345 UiInteger *i = var->value;
346 i->obj = tabview;
347 i->get = ui_tabview_get;
348 i->set = ui_tabview_set;
349 }
350
338 uic_object_push_container(obj, (UiContainerX*)ct); 351 uic_object_push_container(obj, (UiContainerX*)ct);
339 352
340 return form; 353 return form;
354 }
355
356 int64_t ui_tabview_get(UiInteger *i) {
357 UiMotifTabView *tabview = i->obj;
358 i->value = tabview->current_index;
359 return i->value;
360 }
361
362 void ui_tabview_set(UiInteger *i, int64_t value) {
363 UiMotifTabView *tabview = i->obj;
364 if(value < cxListSize(tabview->tabs)) {
365 ui_motif_tabview_select(tabview, value);
366 i->value = value;
367 }
341 } 368 }
342 369
343 void ui_tab_create(UiObject *obj, const char* title) { 370 void ui_tab_create(UiObject *obj, const char* title) {
344 UiContainerPrivate *ctn = ui_obj_container(obj); 371 UiContainerPrivate *ctn = ui_obj_container(obj);
345 if(ctn->type != UI_CONTAINER_TABVIEW) { 372 if(ctn->type != UI_CONTAINER_TABVIEW) {
414 } 441 }
415 442
416 void ui_motif_tabview_select(UiMotifTabView *tabview, int tab) { 443 void ui_motif_tabview_select(UiMotifTabView *tabview, int tab) {
417 UiTab *t = cxListAt(tabview->tabs, tab); 444 UiTab *t = cxListAt(tabview->tabs, tab);
418 if(t) { 445 if(t) {
446 tabview->current_index = tab;
419 ui_motif_tabview_change_tab(tabview, t); 447 ui_motif_tabview_change_tab(tabview, t);
420 } 448 }
421 } 449 }
422 450
423 static void ui_tab_button_callback(Widget widget, UiTab *tab, XtPointer d) { 451 static void ui_tab_button_callback(Widget widget, UiTab *tab, XtPointer d) {
437 XtSetArg(args[n], XmNshadowThickness, 0); n++; 465 XtSetArg(args[n], XmNshadowThickness, 0); n++;
438 XtSetArg(args[n], XmNhighlightThickness, 0); n++; 466 XtSetArg(args[n], XmNhighlightThickness, 0); n++;
439 XtSetArg(args[n], XmNuserData, tabview); n++; 467 XtSetArg(args[n], XmNuserData, tabview); n++;
440 468
441 Widget button = XmCreatePushButton(tabview->tabbar, "tab_button", args, n); 469 Widget button = XmCreatePushButton(tabview->tabbar, "tab_button", args, n);
442 XtManageChild(button); 470 if(tabview->tabview != UI_TABVIEW_INVISIBLE) {
471 XtManageChild(button);
472 }
443 473
444 if(tabview->height == 0) { 474 if(tabview->height == 0) {
445 Dimension h; 475 Dimension h;
446 XtVaGetValues( 476 XtVaGetValues(
447 button, 477 button,
487 } else { 517 } else {
488 if(index < cxListSize(tabview->tabs)) { 518 if(index < cxListSize(tabview->tabs)) {
489 ui_motif_tabview_select(tabview, index+1); 519 ui_motif_tabview_select(tabview, index+1);
490 } else { 520 } else {
491 tabview->current_tab = NULL; 521 tabview->current_tab = NULL;
522 tabview->current_index = -1;
492 } 523 }
493 } 524 }
494 } 525 }
495 XtDestroyWidget(tab->tab_button); 526 XtDestroyWidget(tab->tab_button);
496 XtDestroyWidget(tab->child); 527 XtDestroyWidget(tab->child);
503 XtVaSetValues(tabview->current_tab->tab_button, XmNshadowThickness, 0, XmNbackground, tabview->bg1, NULL); 534 XtVaSetValues(tabview->current_tab->tab_button, XmNshadowThickness, 0, XmNbackground, tabview->bg1, NULL);
504 XtUnmanageChild(tabview->current_tab->child); 535 XtUnmanageChild(tabview->current_tab->child);
505 } 536 }
506 XtVaSetValues(tab->tab_button, XmNshadowThickness, 1, XmNbackground, tabview->bg2, NULL); 537 XtVaSetValues(tab->tab_button, XmNshadowThickness, 1, XmNbackground, tabview->bg2, NULL);
507 tabview->current_tab = tab; 538 tabview->current_tab = tab;
539 tabview->current_index = (int)cxListFind(tabview->tabs, tab);;
508 XtManageChild(tab->child); 540 XtManageChild(tab->child);
509 } 541 }
510 542
511 Widget ui_tabview_container_prepare(UiContainerPrivate *ctn, Arg *args, int *n) { 543 Widget ui_tabview_container_prepare(UiContainerPrivate *ctn, Arg *args, int *n) {
512 UiTabViewContainer *ct = (UiTabViewContainer*)ctn; 544 UiTabViewContainer *ct = (UiTabViewContainer*)ctn;

mercurial