461 gtk_tree_view_set_model(GTK_TREE_VIEW(view->widget), GTK_TREE_MODEL(store)); |
463 gtk_tree_view_set_model(GTK_TREE_VIEW(view->widget), GTK_TREE_MODEL(store)); |
462 g_object_unref(G_OBJECT(store)); |
464 g_object_unref(G_OBJECT(store)); |
463 // TODO: free old model |
465 // TODO: free old model |
464 } |
466 } |
465 |
467 |
|
468 UiListSelection ui_listview_getselection(UiList *list) { |
|
469 UiListView *view = list->obj; |
|
470 UiListSelection selection = ui_listview_selection( |
|
471 gtk_tree_view_get_selection(GTK_TREE_VIEW(view->widget)), |
|
472 NULL); |
|
473 return selection; |
|
474 } |
|
475 |
466 void ui_listview_destroy(GtkWidget *w, UiListView *v) { |
476 void ui_listview_destroy(GtkWidget *w, UiListView *v) { |
467 gtk_tree_view_set_model(GTK_TREE_VIEW(w), NULL); |
477 gtk_tree_view_set_model(GTK_TREE_VIEW(w), NULL); |
468 ui_destroy_boundvar(v->obj->ctx, v->var); |
478 ui_destroy_boundvar(v->obj->ctx, v->var); |
469 // TODO: destroy model? |
479 // TODO: destroy model? |
470 free(v); |
480 free(v); |
482 GtkTreeView *treeview, |
492 GtkTreeView *treeview, |
483 GtkTreePath *path, |
493 GtkTreePath *path, |
484 GtkTreeViewColumn *column, |
494 GtkTreeViewColumn *column, |
485 UiTreeEventData *event) |
495 UiTreeEventData *event) |
486 { |
496 { |
487 UiListSelection *selection = ui_listview_selection( |
497 UiListSelection selection = ui_listview_selection( |
488 gtk_tree_view_get_selection(treeview), |
498 gtk_tree_view_get_selection(treeview), |
489 event); |
499 event); |
490 |
500 |
491 UiEvent e; |
501 UiEvent e; |
492 e.obj = event->obj; |
502 e.obj = event->obj; |
493 e.window = event->obj->window; |
503 e.window = event->obj->window; |
494 e.document = event->obj->ctx->document; |
504 e.document = event->obj->ctx->document; |
495 e.eventdata = selection; |
505 e.eventdata = &selection; |
496 e.intval = selection->count > 0 ? selection->rows[0] : -1; |
506 e.intval = selection.count > 0 ? selection.rows[0] : -1; |
497 event->activate(&e, event->activatedata); |
507 event->activate(&e, event->activatedata); |
498 |
508 |
499 if(selection->count > 0) { |
509 if(selection.count > 0) { |
500 free(selection->rows); |
510 free(selection.rows); |
501 } |
511 } |
502 free(selection); |
|
503 } |
512 } |
504 |
513 |
505 void ui_listview_selection_event( |
514 void ui_listview_selection_event( |
506 GtkTreeSelection *treeselection, |
515 GtkTreeSelection *treeselection, |
507 UiTreeEventData *event) |
516 UiTreeEventData *event) |
508 { |
517 { |
509 UiListSelection *selection = ui_listview_selection(treeselection, event); |
518 UiListSelection selection = ui_listview_selection(treeselection, event); |
510 |
519 |
511 UiEvent e; |
520 UiEvent e; |
512 e.obj = event->obj; |
521 e.obj = event->obj; |
513 e.window = event->obj->window; |
522 e.window = event->obj->window; |
514 e.document = event->obj->ctx->document; |
523 e.document = event->obj->ctx->document; |
515 e.eventdata = selection; |
524 e.eventdata = &selection; |
516 e.intval = selection->count > 0 ? selection->rows[0] : -1; |
525 e.intval = selection.count > 0 ? selection.rows[0] : -1; |
517 event->selection(&e, event->selectiondata); |
526 event->selection(&e, event->selectiondata); |
518 |
527 |
519 if(selection->count > 0) { |
528 if(selection.count > 0) { |
520 free(selection->rows); |
529 free(selection.rows); |
521 } |
530 } |
522 free(selection); |
531 } |
523 } |
532 |
524 |
533 UiListSelection ui_listview_selection( |
525 UiListSelection* ui_listview_selection( |
|
526 GtkTreeSelection *selection, |
534 GtkTreeSelection *selection, |
527 UiTreeEventData *event) |
535 UiTreeEventData *event) |
528 { |
536 { |
529 GList *rows = gtk_tree_selection_get_selected_rows(selection, NULL); |
537 GList *rows = gtk_tree_selection_get_selected_rows(selection, NULL); |
530 |
538 |
531 UiListSelection *ls = malloc(sizeof(UiListSelection)); |
539 UiListSelection ls; |
532 ls->count = g_list_length(rows); |
540 ls.count = g_list_length(rows); |
533 ls->rows = calloc(ls->count, sizeof(int)); |
541 ls.rows = calloc(ls.count, sizeof(int)); |
534 GList *r = rows; |
542 GList *r = rows; |
535 int i = 0; |
543 int i = 0; |
536 while(r) { |
544 while(r) { |
537 GtkTreePath *path = r->data; |
545 GtkTreePath *path = r->data; |
538 ls->rows[i] = ui_tree_path_list_index(path); |
546 ls.rows[i] = ui_tree_path_list_index(path); |
539 r = r->next; |
547 r = r->next; |
540 i++; |
548 i++; |
541 } |
549 } |
542 return ls; |
550 return ls; |
543 } |
551 } |