ui/gtk/container.c

branch
newapi
changeset 332
7e7c05af8f3a
parent 331
cdad8b7e83db
child 333
634e3ce80afe
equal deleted inserted replaced
331:cdad8b7e83db 332:7e7c05af8f3a
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 static int stack_set_page(GtkWidget *stack, int index) {
365 GtkSelectionModel *pages = gtk_stack_get_pages(GTK_STACK(stack));
366 GListModel *list = G_LIST_MODEL(pages);
367 GtkStackPage *page = g_list_model_get_item(list, index);
368 if(page) {
369 gtk_stack_set_visible_child(GTK_STACK(stack), gtk_stack_page_get_child(page));
370 } else {
371 fprintf(stderr, "UI Error: ui_stack_set value out of bounds\n");
372 return -1;
373 }
374 return index;
375 }
376
364 void ui_stack_tab_select(UIWIDGET tabview, int tab) { 377 void ui_stack_tab_select(UIWIDGET tabview, int tab) {
365 378 stack_set_page(tabview, tab);
366 } 379 }
367 380
368 void ui_stack_tab_remove(UIWIDGET tabview, int tab) { 381 void ui_stack_tab_remove(UIWIDGET tabview, int tab) {
369 382 GtkStack *stack = GTK_STACK(tabview);
383 GtkWidget *current = gtk_stack_get_visible_child(stack);
384 GtkSelectionModel *pages = gtk_stack_get_pages(stack);
385 GListModel *list = G_LIST_MODEL(pages);
386 GtkStackPage *page = g_list_model_get_item(list, tab);
387 if(page) {
388 gtk_stack_remove(stack, gtk_stack_page_get_child(page));
389 }
370 } 390 }
371 391
372 void ui_stack_tab_add(UIWIDGET widget, int index, const char *name, UIWIDGET child) { 392 void ui_stack_tab_add(UIWIDGET widget, int index, const char *name, UIWIDGET child) {
373 GtkStackPage *page = gtk_stack_add_titled(GTK_STACK(widget), child, name, name); 393 (void)gtk_stack_add_titled(GTK_STACK(widget), child, name, name);
374 } 394 }
375 395
376 int64_t ui_stack_get(UiInteger *i) { 396 int64_t ui_stack_get(UiInteger *i) {
377 397 GtkStack *stack = GTK_STACK(i->obj);
398 GtkWidget *current = gtk_stack_get_visible_child(stack);
399 GtkSelectionModel *pages = gtk_stack_get_pages(stack);
400 GListModel *list = G_LIST_MODEL(pages);
401 int nitems = g_list_model_get_n_items(list);
402 for(int p=0;p<nitems;p++) {
403 GtkStackPage *page = g_list_model_get_item(list, p);
404 GtkWidget *child = gtk_stack_page_get_child(page);
405 if(child == current) {
406 i->value = p;
407 break;
408 }
409 }
410 return i->value;
378 } 411 }
379 412
380 void ui_stack_set(UiInteger *i, int64_t value) { 413 void ui_stack_set(UiInteger *i, int64_t value) {
381 414 GtkWidget *widget = i->obj;
415 if(stack_set_page(widget, value) >= 0) {
416 i->value = value;
417 }
382 } 418 }
383 419
384 420
385 UiGtkTabView* ui_widget_get_tabview_data(UIWIDGET tabview) { 421 UiGtkTabView* ui_widget_get_tabview_data(UIWIDGET tabview) {
386 return g_object_get_data(G_OBJECT(tabview), "ui_tabview"); 422 return g_object_get_data(G_OBJECT(tabview), "ui_tabview");
449 if(args.value || args.varname) { 485 if(args.value || args.varname) {
450 UiVar *var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_INTEGER); 486 UiVar *var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_INTEGER);
451 UiInteger *i = var->value; 487 UiInteger *i = var->value;
452 i->get = getfunc; 488 i->get = getfunc;
453 i->set = setfunc; 489 i->set = setfunc;
454 i->obj = widget; 490 i->obj = data_widget;
455 } 491 }
456 492
457 g_object_set_data(G_OBJECT(widget), "ui_tabview", data); 493 g_object_set_data(G_OBJECT(widget), "ui_tabview", data);
458 data->widget = data_widget; 494 data->widget = data_widget;
459 data->subcontainer = args.subcontainer; 495 data->subcontainer = args.subcontainer;

mercurial