ui/gtk/list.c

changeset 937
06e03c7e39db
parent 890
8d30cbd1c465
child 939
fdc6a46100a3
equal deleted inserted replaced
936:d40a72210be8 937:06e03c7e39db
2158 UiListBoxSubList *sublist_ptr = cxListAt(uilistbox->sublists, cxListSize(sublists)-1); 2158 UiListBoxSubList *sublist_ptr = cxListAt(uilistbox->sublists, cxListSize(sublists)-1);
2159 if(uisublist.var && uisublist.var->value) { 2159 if(uisublist.var && uisublist.var->value) {
2160 UiList *list = uisublist.var->value; 2160 UiList *list = uisublist.var->value;
2161 list->obj = sublist_ptr; 2161 list->obj = sublist_ptr;
2162 list->update = ui_listbox_list_update; 2162 list->update = ui_listbox_list_update;
2163 list->getselection = ui_listbox_list_getselection;
2164 list->setselection = ui_listbox_list_setselection;
2163 } 2165 }
2164 } 2166 }
2165 2167
2166 UIEXPORT UIWIDGET ui_sourcelist_create(UiObject *obj, UiSourceListArgs *args) { 2168 UIEXPORT UIWIDGET ui_sourcelist_create(UiObject *obj, UiSourceListArgs *args) {
2167 #ifdef UI_GTK3 2169 #ifdef UI_GTK3
2221 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->dynamic_sublist, args->varname, UI_VAR_LIST); 2223 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->dynamic_sublist, args->varname, UI_VAR_LIST);
2222 if(var) { 2224 if(var) {
2223 UiList *list = var->value; 2225 UiList *list = var->value;
2224 list->obj = uilistbox; 2226 list->obj = uilistbox;
2225 list->update = ui_listbox_dynamic_update; 2227 list->update = ui_listbox_dynamic_update;
2228 list->getselection = ui_listbox_dynamic_getselection;
2229 list->setselection = ui_listbox_dynamic_setselection;
2226 2230
2227 ui_listbox_dynamic_update(list, -1); 2231 ui_listbox_dynamic_update(list, -1);
2228 } 2232 }
2229 } 2233 }
2230 2234
2290 add_sublist(uilistbox, new_sublists, sublist); 2294 add_sublist(uilistbox, new_sublists, sublist);
2291 sublist = list->next(list); 2295 sublist = list->next(list);
2292 } 2296 }
2293 2297
2294 ui_listbox_update(uilistbox, 0, cxListSize(uilistbox->sublists)); 2298 ui_listbox_update(uilistbox, 0, cxListSize(uilistbox->sublists));
2299 }
2300
2301 void ui_listbox_dynamic_setselection(UiList *list, UiListSelection sel) {
2302 UiListBox *uilistbox = list->obj;
2303 if(sel.count > 0) {
2304 GtkListBoxRow *row = gtk_list_box_get_row_at_index(uilistbox->listbox, sel.rows[0]);
2305 if(row) {
2306 gtk_list_box_select_row(uilistbox->listbox, row);
2307 }
2308 } else {
2309 gtk_list_box_unselect_all(uilistbox->listbox);
2310 }
2311 }
2312
2313 UiListSelection ui_listbox_dynamic_getselection(UiList *list) {
2314 UiListSelection sel = { 0, NULL };
2315 UiListBox *uilistbox = list->obj;
2316 GtkListBoxRow *row = gtk_list_box_get_selected_row(uilistbox->listbox);
2317 if(row) {
2318 sel.count = 1;
2319 sel.rows = malloc(sizeof(int));
2320 sel.rows[0] = gtk_list_box_row_get_index(row);
2321 }
2322 return sel;
2295 } 2323 }
2296 2324
2297 void ui_listbox_update(UiListBox *listbox, int from, int to) { 2325 void ui_listbox_update(UiListBox *listbox, int from, int to) {
2298 CxIterator i = cxListIterator(listbox->sublists); 2326 CxIterator i = cxListIterator(listbox->sublists);
2299 size_t pos = 0; 2327 size_t pos = 0;
2657 } 2685 }
2658 2686
2659 ui_sourcelist_update_finished(); 2687 ui_sourcelist_update_finished();
2660 } 2688 }
2661 2689
2690 void ui_listbox_list_setselection(UiList *list, UiListSelection sel) {
2691 UiListBoxSubList *sublist = list->obj;
2692 UiListBox *uilistbox = sublist->listbox;
2693 if(sel.count > 0) {
2694 int index = sel.rows[0];
2695 if(index < sublist->numitems) {
2696 int global_index = sublist->startpos + index;
2697 GtkListBoxRow *row = gtk_list_box_get_row_at_index(uilistbox->listbox, global_index);
2698 if(row) {
2699 gtk_list_box_select_row(uilistbox->listbox, row);
2700 }
2701 }
2702 } else {
2703 gtk_list_box_unselect_all(uilistbox->listbox);
2704 }
2705 }
2706
2707 UiListSelection ui_listbox_list_getselection(UiList *list) {
2708 UiListSelection sel = { 0, NULL };
2709 UiListBoxSubList *sublist = list->obj;
2710 UiListBox *uilistbox = sublist->listbox;
2711 GtkListBoxRow *row = gtk_list_box_get_selected_row(uilistbox->listbox);
2712 if(row) {
2713 int index = gtk_list_box_row_get_index(row);
2714 size_t startpos = sublist->startpos;
2715 if(index >= startpos && index < startpos+sublist->numitems) {
2716 sel.count = 1;
2717 sel.rows = malloc(sizeof(int));
2718 sel.rows[0] = index - startpos;
2719 }
2720 }
2721 return sel;
2722 }
2723
2662 void ui_listbox_row_activate(GtkListBox *self, GtkListBoxRow *row, gpointer user_data) { 2724 void ui_listbox_row_activate(GtkListBox *self, GtkListBoxRow *row, gpointer user_data) {
2663 UiEventDataExt *data = g_object_get_data(G_OBJECT(row), "ui-listbox-row-eventdata"); 2725 UiEventDataExt *data = g_object_get_data(G_OBJECT(row), "ui-listbox-row-eventdata");
2664 if(!data) { 2726 if(!data) {
2665 return; 2727 return;
2666 } 2728 }

mercurial