199 tableview->selection.count = 0; |
199 tableview->selection.count = 0; |
200 tableview->selection.rows = NULL; |
200 tableview->selection.rows = NULL; |
201 return tableview; |
201 return tableview; |
202 } |
202 } |
203 |
203 |
|
204 static void listview_copy_static_elements(UiListView *listview, char **elm, size_t nelm) { |
|
205 listview->elements = calloc(nelm, sizeof(char*)); |
|
206 listview->nelm = nelm; |
|
207 for(int i=0;i<nelm;i++) { |
|
208 listview->elements[i] = strdup(elm[i]); |
|
209 } |
|
210 } |
|
211 |
204 UIWIDGET ui_listview_create(UiObject *obj, UiListArgs args) { |
212 UIWIDGET ui_listview_create(UiObject *obj, UiListArgs args) { |
205 UiObject* current = uic_current_obj(obj); |
213 UiObject* current = uic_current_obj(obj); |
206 |
214 |
207 // to simplify things and share code with ui_table_create, we also |
215 // to simplify things and share code with ui_table_create, we also |
208 // use a UiModel for the listview |
216 // use a UiModel for the listview |
246 list->update = ui_listview_update2; |
254 list->update = ui_listview_update2; |
247 list->getselection = ui_listview_getselection2; |
255 list->getselection = ui_listview_getselection2; |
248 list->setselection = ui_listview_setselection2; |
256 list->setselection = ui_listview_setselection2; |
249 |
257 |
250 ui_update_liststore(ls, list); |
258 ui_update_liststore(ls, list); |
|
259 } else if (args.static_elements && args.static_nelm > 0) { |
|
260 listview_copy_static_elements(listview, args.static_elements, args.static_nelm); |
|
261 listview->model->getvalue = ui_strmodel_getvalue; // force strmodel |
|
262 ui_update_liststore_static(ls, listview->elements, listview->nelm); |
251 } |
263 } |
252 |
264 |
253 // event handling |
265 // event handling |
254 if(args.onactivate) { |
266 if(args.onactivate) { |
255 // columnview and listview can use the same callback function, because |
267 // columnview and listview can use the same callback function, because |
321 list->update = ui_listview_update2; |
333 list->update = ui_listview_update2; |
322 list->getselection = ui_combobox_getselection; |
334 list->getselection = ui_combobox_getselection; |
323 list->setselection = ui_combobox_setselection; |
335 list->setselection = ui_combobox_setselection; |
324 |
336 |
325 ui_update_liststore(ls, list); |
337 ui_update_liststore(ls, list); |
|
338 } else if (args.static_elements && args.static_nelm > 0) { |
|
339 listview_copy_static_elements(listview, args.static_elements, args.static_nelm); |
|
340 listview->model->getvalue = ui_strmodel_getvalue; // force strmodel |
|
341 ui_update_liststore_static(ls, listview->elements, listview->nelm); |
326 } |
342 } |
327 |
343 |
328 // event handling |
344 // event handling |
329 if(args.onactivate) { |
345 if(args.onactivate) { |
330 g_signal_connect(view, "activate", G_CALLBACK(ui_columnview_activate), listview); |
346 g_signal_connect(view, "notify::selected", G_CALLBACK(ui_dropdown_notify), listview); |
331 } |
347 } |
332 |
348 |
333 // add widget to parent |
349 // add widget to parent |
334 UI_APPLY_LAYOUT1(current, args); |
350 UI_APPLY_LAYOUT1(current, args); |
335 current->container->add(current->container, view, FALSE); |
351 current->container->add(current->container, view, FALSE); |
476 view->selection.rows = newselection; |
492 view->selection.rows = newselection; |
477 } else { |
493 } else { |
478 free(newselection); |
494 free(newselection); |
479 } |
495 } |
480 } |
496 } |
|
497 |
|
498 void ui_dropdown_notify(GtkWidget *dropdown, GObject *pspec, gpointer userdata) { |
|
499 UiListView *view = userdata; |
|
500 guint index = gtk_drop_down_get_selected(GTK_DROP_DOWN(dropdown)); |
|
501 GObject *item = gtk_drop_down_get_selected_item(GTK_DROP_DOWN(dropdown)); |
|
502 if(item && view->onactivate) { |
|
503 ObjWrapper *eventdata = (ObjWrapper*)item; |
|
504 UiEvent event; |
|
505 event.obj = view->obj; |
|
506 event.document = event.obj->ctx->document; |
|
507 event.window = event.obj->window; |
|
508 event.intval = index; |
|
509 event.eventdata = eventdata->data; |
|
510 view->onactivate(&event, view->onactivatedata); |
|
511 } |
|
512 } |
|
513 |
481 |
514 |
482 void ui_columnview_activate(void *ignore, guint position, gpointer userdata) { |
515 void ui_columnview_activate(void *ignore, guint position, gpointer userdata) { |
483 UiListView *view = userdata; |
516 UiListView *view = userdata; |
484 if(view->selection.count == 0) { |
517 if(view->selection.count == 0) { |
485 listview_update_selection(view); |
518 listview_update_selection(view); |
519 void *elm = list->first(list); |
552 void *elm = list->first(list); |
520 while(elm) { |
553 while(elm) { |
521 ObjWrapper *obj = obj_wrapper_new(elm); |
554 ObjWrapper *obj = obj_wrapper_new(elm); |
522 g_list_store_append(liststore, obj); |
555 g_list_store_append(liststore, obj); |
523 elm = list->next(list); |
556 elm = list->next(list); |
|
557 } |
|
558 } |
|
559 |
|
560 void ui_update_liststore_static(GListStore *liststore, char **elm, size_t nelm) { |
|
561 g_list_store_remove_all(liststore); |
|
562 for(int i=0;i<nelm;i++) { |
|
563 ObjWrapper *obj = obj_wrapper_new(elm[i]); |
|
564 g_list_store_append(liststore, obj); |
524 } |
565 } |
525 } |
566 } |
526 |
567 |
527 void ui_listview_update2(UiList *list, int i) { |
568 void ui_listview_update2(UiList *list, int i) { |
528 UiListView *view = list->obj; |
569 UiListView *view = list->obj; |
1494 } |
1535 } |
1495 */ |
1536 */ |
1496 |
1537 |
1497 void ui_listview_destroy(GtkWidget *w, UiListView *v) { |
1538 void ui_listview_destroy(GtkWidget *w, UiListView *v) { |
1498 //gtk_tree_view_set_model(GTK_TREE_VIEW(w), NULL); |
1539 //gtk_tree_view_set_model(GTK_TREE_VIEW(w), NULL); |
1499 ui_destroy_boundvar(v->obj->ctx, v->var); |
1540 if(v->var) { |
|
1541 ui_destroy_boundvar(v->obj->ctx, v->var); |
|
1542 } |
|
1543 if(v->elements) { |
|
1544 for(int i=0;i<v->nelm;i++) { |
|
1545 free(v->elements[i]); |
|
1546 } |
|
1547 free(v->elements); |
|
1548 } |
1500 #if GTK_CHECK_VERSION(4, 10, 0) |
1549 #if GTK_CHECK_VERSION(4, 10, 0) |
1501 free(v->columns); |
1550 free(v->columns); |
1502 #endif |
1551 #endif |
1503 free(v->selection.rows); |
1552 free(v->selection.rows); |
1504 free(v); |
1553 free(v); |