ui/gtk/container.c

branch
newapi
changeset 333
634e3ce80afe
parent 332
7e7c05af8f3a
child 336
56c12f44c2d3
equal deleted inserted replaced
332:7e7c05af8f3a 333:634e3ce80afe
359 gtk_notebook_set_current_page(nb, value); 359 gtk_notebook_set_current_page(nb, value);
360 i->value = gtk_notebook_get_current_page(nb); 360 i->value = gtk_notebook_get_current_page(nb);
361 } 361 }
362 362
363 363
364 #if GTK_MAJOR_VERSION >= 4
364 static int stack_set_page(GtkWidget *stack, int index) { 365 static int stack_set_page(GtkWidget *stack, int index) {
365 GtkSelectionModel *pages = gtk_stack_get_pages(GTK_STACK(stack)); 366 GtkSelectionModel *pages = gtk_stack_get_pages(GTK_STACK(stack));
366 GListModel *list = G_LIST_MODEL(pages); 367 GListModel *list = G_LIST_MODEL(pages);
367 GtkStackPage *page = g_list_model_get_item(list, index); 368 GtkStackPage *page = g_list_model_get_item(list, index);
368 if(page) { 369 if(page) {
414 GtkWidget *widget = i->obj; 415 GtkWidget *widget = i->obj;
415 if(stack_set_page(widget, value) >= 0) { 416 if(stack_set_page(widget, value) >= 0) {
416 i->value = value; 417 i->value = value;
417 } 418 }
418 } 419 }
420 #elif GTK_MAJOR_VERSION >= 3
421 static GtkWidget* stack_get_child(GtkWidget *stack, int index) {
422 GList *children = gtk_container_get_children(GTK_CONTAINER(stack));
423 if(children) {
424 return g_list_nth_data(children, index);
425 }
426 return NULL;
427 }
428
429 void ui_stack_tab_select(UIWIDGET tabview, int tab) {
430 GtkWidget *child = stack_get_child(tabview, tab);
431 if(child) {
432 gtk_stack_set_visible_child(GTK_STACK(tabview), child);
433 }
434 }
435
436 void ui_stack_tab_remove(UIWIDGET tabview, int tab) {
437 GtkWidget *child = stack_get_child(tabview, tab);
438 if(child) {
439 gtk_container_remove(GTK_CONTAINER(tabview), child);
440 }
441 }
442
443 void ui_stack_tab_add(UIWIDGET widget, int index, const char *name, UIWIDGET child) {
444 gtk_stack_add_titled(GTK_STACK(widget), child, name, name);
445 }
446
447 int64_t ui_stack_get(UiInteger *i) {
448 GtkWidget *visible = gtk_stack_get_visible_child(GTK_STACK(i->obj));
449 GList *children = gtk_container_get_children(GTK_CONTAINER(i->obj));
450 GList *elm = children;
451 int n = 0;
452 int64_t v = -1;
453 while(elm) {
454 GtkWidget *child = elm->data;
455 if(child == visible) {
456 v = n;
457 break;
458 }
459
460 elm = elm->next;
461 n++;
462 }
463 g_list_free(children);
464 i->value = v;
465 return v;
466 }
467
468 void ui_stack_set(UiInteger *i, int64_t value) {
469 GtkWidget *child = stack_get_child(i->obj, value);
470 if(child) {
471 gtk_stack_set_visible_child(GTK_STACK(i->obj), child);
472 i->value = value;
473 }
474 }
475
476 #endif
477
478
419 479
420 480
421 UiGtkTabView* ui_widget_get_tabview_data(UIWIDGET tabview) { 481 UiGtkTabView* ui_widget_get_tabview_data(UIWIDGET tabview) {
422 return g_object_get_data(G_OBJECT(tabview), "ui_tabview"); 482 return g_object_get_data(G_OBJECT(tabview), "ui_tabview");
423 } 483 }
462 #endif 522 #endif
463 break; 523 break;
464 } 524 }
465 case UI_TABVIEW_DEFAULT: /* fall through */ 525 case UI_TABVIEW_DEFAULT: /* fall through */
466 case UI_TABVIEW_NAVIGATION_TOP: /* fall through */ 526 case UI_TABVIEW_NAVIGATION_TOP: /* fall through */
527 case UI_TABVIEW_INVISIBLE: /* fall through */
467 case UI_TABVIEW_NAVIGATION_TOP2: { 528 case UI_TABVIEW_NAVIGATION_TOP2: {
468 widget = gtk_notebook_new(); 529 widget = gtk_notebook_new();
469 data_widget = widget; 530 data_widget = widget;
470 data->select_tab = ui_notebook_tab_select; 531 data->select_tab = ui_notebook_tab_select;
471 data->remove_tab = ui_notebook_tab_remove; 532 data->remove_tab = ui_notebook_tab_remove;
472 data->add_tab = ui_notebook_tab_add; 533 data->add_tab = ui_notebook_tab_add;
473 getfunc = ui_notebook_get; 534 getfunc = ui_notebook_get;
474 setfunc = ui_notebook_set; 535 setfunc = ui_notebook_set;
475 /* fall through */ 536 if(args.tabview == UI_TABVIEW_INVISIBLE) {
476 } 537 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(widget), FALSE);
477 case UI_TABVIEW_INVISIBLE: { 538 gtk_notebook_set_show_border(GTK_NOTEBOOK(widget), FALSE);
478 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(widget), FALSE); 539 }
479 gtk_notebook_set_show_border(GTK_NOTEBOOK(widget), FALSE);
480 break; 540 break;
481 } 541 }
482 } 542 }
483 543
484 UiObject* current = uic_current_obj(obj); 544 UiObject* current = uic_current_obj(obj);

mercurial