| 1257 } |
1257 } |
| 1258 |
1258 |
| 1259 return store; |
1259 return store; |
| 1260 } |
1260 } |
| 1261 |
1261 |
| |
1262 static void ui_destroy_tree_eventdata(GtkWidget *object, UiTreeEventData *data) { |
| |
1263 free(data->activate_action); |
| |
1264 free(data->selection_action); |
| |
1265 free(data); |
| |
1266 } |
| 1262 |
1267 |
| 1263 UIWIDGET ui_listview_create(UiObject *obj, UiListArgs *args) { |
1268 UIWIDGET ui_listview_create(UiObject *obj, UiListArgs *args) { |
| 1264 // create treeview |
1269 // create treeview |
| 1265 GtkWidget *view = gtk_tree_view_new(); |
1270 GtkWidget *view = gtk_tree_view_new(); |
| 1266 ui_set_name_and_style(view, args->name, args->style_class); |
1271 ui_set_name_and_style(view, args->name, args->style_class); |
| 1314 // add callback |
1319 // add callback |
| 1315 UiTreeEventData *event = malloc(sizeof(UiTreeEventData)); |
1320 UiTreeEventData *event = malloc(sizeof(UiTreeEventData)); |
| 1316 event->obj = obj; |
1321 event->obj = obj; |
| 1317 event->activate = args->onactivate; |
1322 event->activate = args->onactivate; |
| 1318 event->activatedata = args->onactivatedata; |
1323 event->activatedata = args->onactivatedata; |
| |
1324 event->activate_action = args->onactivate_action ? strdup(args->onactivate_action) : NULL; |
| 1319 event->selection = args->onselection; |
1325 event->selection = args->onselection; |
| 1320 event->selectiondata = args->onselectiondata; |
1326 event->selectiondata = args->onselectiondata; |
| |
1327 event->selection_action = args->onselection_action ? strdup(args->onselection_action) : NULL; |
| 1321 g_signal_connect( |
1328 g_signal_connect( |
| 1322 view, |
1329 view, |
| 1323 "destroy", |
1330 "destroy", |
| 1324 G_CALLBACK(ui_destroy_userdata), |
1331 G_CALLBACK(ui_destroy_tree_eventdata), |
| 1325 event); |
1332 event); |
| 1326 |
1333 if(args->onactivate || args->onactivate_action) { |
| 1327 if(args->onactivate) { |
|
| 1328 g_signal_connect( |
1334 g_signal_connect( |
| 1329 view, |
1335 view, |
| 1330 "row-activated", |
1336 "row-activated", |
| 1331 G_CALLBACK(ui_listview_activate_event), |
1337 G_CALLBACK(ui_listview_activate_event), |
| 1332 event); |
1338 event); |
| 1333 } |
1339 } |
| 1334 if(args->onselection) { |
1340 if(args->onselection || args->onselection_action) { |
| 1335 GtkTreeSelection *selection = gtk_tree_view_get_selection( |
1341 GtkTreeSelection *selection = gtk_tree_view_get_selection( |
| 1336 GTK_TREE_VIEW(view)); |
1342 GTK_TREE_VIEW(view)); |
| 1337 g_signal_connect( |
1343 g_signal_connect( |
| 1338 selection, |
1344 selection, |
| 1339 "changed", |
1345 "changed", |
| 1541 list->getselection = ui_listview_getselection; |
1547 list->getselection = ui_listview_getselection; |
| 1542 list->setselection = ui_listview_setselection; |
1548 list->setselection = ui_listview_setselection; |
| 1543 list->obj = tableview; |
1549 list->obj = tableview; |
| 1544 |
1550 |
| 1545 // add callback |
1551 // add callback |
| 1546 UiTreeEventData *event = ui_malloc(obj->ctx, sizeof(UiTreeEventData)); |
1552 UiTreeEventData *event = malloc(sizeof(UiTreeEventData)); |
| 1547 event->obj = obj; |
1553 event->obj = obj; |
| 1548 event->activate = args->onactivate; |
1554 event->activate = args->onactivate; |
| |
1555 event->activatedata = args->onactivatedata; |
| |
1556 event->activate_action = args->onactivate_action ? strdup(args->onactivate_action) : NULL; |
| 1549 event->selection = args->onselection; |
1557 event->selection = args->onselection; |
| 1550 event->activatedata = args->onactivatedata; |
|
| 1551 event->selectiondata = args->onselectiondata; |
1558 event->selectiondata = args->onselectiondata; |
| 1552 if(args->onactivate) { |
1559 event->selection_action = args->onselection_action ? strdup(args->onselection_action) : NULL; |
| |
1560 g_signal_connect( |
| |
1561 view, |
| |
1562 "destroy", |
| |
1563 G_CALLBACK(ui_destroy_tree_eventdata), |
| |
1564 event); |
| |
1565 if(args->onactivate || args->onactivate_action) { |
| 1553 g_signal_connect( |
1566 g_signal_connect( |
| 1554 view, |
1567 view, |
| 1555 "row-activated", |
1568 "row-activated", |
| 1556 G_CALLBACK(ui_listview_activate_event), |
1569 G_CALLBACK(ui_listview_activate_event), |
| 1557 event); |
1570 event); |
| 1558 } |
1571 } |
| 1559 if(args->onselection) { |
1572 if(args->onselection || args->onselection_action) { |
| 1560 GtkTreeSelection *selection = gtk_tree_view_get_selection( |
1573 GtkTreeSelection *selection = gtk_tree_view_get_selection( |
| 1561 GTK_TREE_VIEW(view)); |
1574 GTK_TREE_VIEW(view)); |
| 1562 g_signal_connect( |
1575 g_signal_connect( |
| 1563 selection, |
1576 selection, |
| 1564 "changed", |
1577 "changed", |
| 1565 G_CALLBACK(ui_listview_selection_event), |
1578 G_CALLBACK(ui_listview_selection_event), |
| 1566 event); |
1579 event); |
| 1567 } |
1580 } |
| 1568 // TODO: destroy callback |
|
| 1569 |
|
| 1570 |
1581 |
| 1571 if(args->ondragstart) { |
1582 if(args->ondragstart) { |
| 1572 ui_listview_add_dnd(tableview, args); |
1583 ui_listview_add_dnd(tableview, args); |
| 1573 } |
1584 } |
| 1574 if(args->ondrop) { |
1585 if(args->ondrop) { |
| 1798 e.window = event->obj->window; |
1809 e.window = event->obj->window; |
| 1799 e.document = event->obj->ctx->document; |
1810 e.document = event->obj->ctx->document; |
| 1800 e.eventdata = &selection; |
1811 e.eventdata = &selection; |
| 1801 e.intval = selection.count > 0 ? selection.rows[0] : -1; |
1812 e.intval = selection.count > 0 ? selection.rows[0] : -1; |
| 1802 e.set = ui_get_setop(); |
1813 e.set = ui_get_setop(); |
| 1803 event->activate(&e, event->activatedata); |
1814 |
| 1804 |
1815 if(event->activate) { |
| 1805 if(selection.count > 0) { |
1816 event->activate(&e, event->activatedata); |
| 1806 free(selection.rows); |
1817 } |
| 1807 } |
1818 if(event->activate_action) { |
| |
1819 uic_action_callback(&e, event->activate_action); |
| |
1820 } |
| |
1821 |
| |
1822 free(selection.rows); |
| 1808 } |
1823 } |
| 1809 |
1824 |
| 1810 void ui_listview_selection_event( |
1825 void ui_listview_selection_event( |
| 1811 GtkTreeSelection *treeselection, |
1826 GtkTreeSelection *treeselection, |
| 1812 UiTreeEventData *event) |
1827 UiTreeEventData *event) |
| 1822 e.window = event->obj->window; |
1837 e.window = event->obj->window; |
| 1823 e.document = event->obj->ctx->document; |
1838 e.document = event->obj->ctx->document; |
| 1824 e.eventdata = &selection; |
1839 e.eventdata = &selection; |
| 1825 e.intval = selection.count > 0 ? selection.rows[0] : -1; |
1840 e.intval = selection.count > 0 ? selection.rows[0] : -1; |
| 1826 e.set = ui_get_setop(); |
1841 e.set = ui_get_setop(); |
| 1827 event->selection(&e, event->selectiondata); |
1842 if(event->selection) { |
| 1828 |
1843 event->selection(&e, event->selectiondata); |
| 1829 if(selection.count > 0) { |
1844 } |
| 1830 free(selection.rows); |
1845 if(event->selection_action) { |
| 1831 } |
1846 uic_action_callback(&e, event->selection_action); |
| |
1847 } |
| |
1848 |
| |
1849 free(selection.rows); |
| 1832 } |
1850 } |
| 1833 |
1851 |
| 1834 UiListSelection ui_listview_get_selection( |
1852 UiListSelection ui_listview_get_selection( |
| 1835 GtkTreeSelection *selection, |
1853 GtkTreeSelection *selection, |
| 1836 UiTreeEventData *event) |
1854 UiTreeEventData *event) |