ui/gtk/tree.c

branch
newapi
changeset 270
9389313ac00f
parent 269
3380100e20f5
child 278
a8faf8757450
equal deleted inserted replaced
269:3380100e20f5 270:9389313ac00f
553 } 553 }
554 554
555 555
556 /* --------------------------- ComboBox --------------------------- */ 556 /* --------------------------- ComboBox --------------------------- */
557 557
558 UIWIDGET ui_combobox_deprecated(UiObject *obj, UiList *list, ui_getvaluefunc getvalue, ui_callback f, void *udata) { 558 UIWIDGET ui_combobox_create(UiObject *obj, UiListArgs args) {
559 UiVar *var = malloc(sizeof(UiVar)); 559 UiObject* current = uic_current_obj(obj);
560 var->value = list; 560
561 var->type = UI_VAR_SPECIAL;
562 return ui_combobox_var(obj, var, getvalue, f, udata);
563 }
564
565 UIWIDGET ui_combobox_nv(UiObject *obj, char *varname, ui_getvaluefunc getvalue, ui_callback f, void *udata) {
566 UiVar *var = uic_create_var(obj->ctx, varname, UI_VAR_LIST);
567 if(var) {
568 return ui_combobox_var(obj, var, getvalue, f, udata);
569 } else {
570 // TODO: error
571 }
572 return NULL;
573 }
574
575 UIWIDGET ui_combobox_var(UiObject *obj, UiVar *var, ui_getvaluefunc getvalue, ui_callback f, void *udata) {
576 /*
577 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1); 561 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1);
578 model->getvalue = getvalue; 562 model->getvalue = args.getvalue;
579 UiList *list = var ? var->value : NULL; 563
580 GtkListStore *store = create_list_store(list, model); 564 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST);
581 565
582 //GtkWidget *combobox = ui_create_combobox(obj, listmodel, f, udata); 566 GtkWidget *combobox = ui_create_combobox(obj, model, var, args.onactivate, args.onactivatedata);
583 UiContainer *ct = uic_get_current_container(obj); 567 UI_APPLY_LAYOUT1(current, args);
584 ct->add(ct, combobox, FALSE); 568 current->container->add(current->container, combobox, FALSE);
569 current->container->current = combobox;
585 return combobox; 570 return combobox;
586 */ 571 }
587 return NULL; 572
588 } 573 GtkWidget* ui_create_combobox(UiObject *obj, UiModel *model, UiVar *var, ui_callback f, void *udata) {
589 574 GtkWidget *combobox = gtk_combo_box_new();
590 GtkWidget* ui_create_combobox(UiObject *obj, GtkListStore *store, ui_callback f, void *udata) { 575
591 GtkWidget *combobox = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
592
593 UiListView *uicbox = malloc(sizeof(UiListView)); 576 UiListView *uicbox = malloc(sizeof(UiListView));
594 uicbox->obj = obj; 577 uicbox->obj = obj;
595 uicbox->widget = combobox; 578 uicbox->widget = combobox;
596 // TODO 579
597 //uicbox->var = model->var; 580 UiList *list = var ? var->value : NULL;
598 //uicbox->model = model->model; 581 GtkListStore *listmodel = create_list_store(list, model);
582
583 if(listmodel) {
584 gtk_combo_box_set_model(GTK_COMBO_BOX(combobox), GTK_TREE_MODEL(listmodel));
585 }
586
587 uicbox->var = var;
588 uicbox->model = model;
599 589
600 g_signal_connect( 590 g_signal_connect(
601 combobox, 591 combobox,
602 "destroy", 592 "destroy",
603 G_CALLBACK(ui_combobox_destroy), 593 G_CALLBACK(ui_combobox_destroy),
604 uicbox); 594 uicbox);
605 595
606 // bind var 596 // bind var
607 //UiList *list = model->var->value; 597 if(list) {
608 //list->update = ui_combobox_modelupdate; 598 list->update = ui_combobox_modelupdate;
609 //list->obj = uicbox; 599 list->obj = uicbox;
600 }
610 601
611 GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); 602 GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
612 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox), renderer, TRUE); 603 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox), renderer, TRUE);
613 gtk_cell_layout_set_attributes( 604 gtk_cell_layout_set_attributes(
614 GTK_CELL_LAYOUT(combobox), 605 GTK_CELL_LAYOUT(combobox),

mercurial