| 2176 if(data->callback2) { |
2176 if(data->callback2) { |
| 2177 data->callback2(&event, data->userdata2); |
2177 data->callback2(&event, data->userdata2); |
| 2178 } |
2178 } |
| 2179 } |
2179 } |
| 2180 |
2180 |
| 2181 static GtkWidget* create_listbox_row(UiListBox *listbox, UiListBoxSubList *sublist, UiSubListItem *item, int index) { |
2181 static void listbox_fill_row(UiListBox *listbox, GtkWidget *row, UiListBoxSubList *sublist, UiSubListItem *item, int index) { |
| 2182 GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10); |
2182 GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10); |
| 2183 if(item->icon) { |
2183 if(item->icon) { |
| 2184 GtkWidget *icon = ICON_IMAGE(item->icon); |
2184 GtkWidget *icon = ICON_IMAGE(item->icon); |
| 2185 BOX_ADD(hbox, icon); |
2185 BOX_ADD(hbox, icon); |
| 2186 } |
2186 } |
| 2188 gtk_widget_set_halign(label, GTK_ALIGN_START); |
2188 gtk_widget_set_halign(label, GTK_ALIGN_START); |
| 2189 BOX_ADD_EXPAND(hbox, label); |
2189 BOX_ADD_EXPAND(hbox, label); |
| 2190 if(item->badge) { |
2190 if(item->badge) { |
| 2191 |
2191 |
| 2192 } |
2192 } |
| 2193 GtkWidget *row = gtk_list_box_row_new(); |
|
| 2194 LISTBOX_ROW_SET_CHILD(row, hbox); |
2193 LISTBOX_ROW_SET_CHILD(row, hbox); |
| 2195 |
2194 |
| 2196 // signals |
2195 // signals |
| 2197 UiEventDataExt *event = malloc(sizeof(UiEventDataExt)); |
2196 UiEventDataExt *event = malloc(sizeof(UiEventDataExt)); |
| 2198 memset(event, 0, sizeof(UiEventDataExt)); |
2197 memset(event, 0, sizeof(UiEventDataExt)); |
| 2239 "clicked", |
2238 "clicked", |
| 2240 G_CALLBACK(listbox_button_clicked), |
2239 G_CALLBACK(listbox_button_clicked), |
| 2241 event |
2240 event |
| 2242 ); |
2241 ); |
| 2243 } |
2242 } |
| 2244 |
2243 } |
| 2245 return row; |
2244 |
| |
2245 static void update_sublist_item(UiListBox *listbox, UiListBoxSubList *sublist, int index) { |
| |
2246 GtkListBoxRow *row = gtk_list_box_get_row_at_index(listbox->listbox, sublist->startpos + index); |
| |
2247 if(!row) { |
| |
2248 return; |
| |
2249 } |
| |
2250 UiList *list = sublist->var->value; |
| |
2251 if(!list) { |
| |
2252 return; |
| |
2253 } |
| |
2254 |
| |
2255 void *elm = list->get(list, index); |
| |
2256 UiSubListItem item = { NULL, NULL, NULL, NULL, NULL, NULL }; |
| |
2257 if(listbox->getvalue) { |
| |
2258 listbox->getvalue(list, sublist->userdata, elm, index, &item, listbox->getvaluedata); |
| |
2259 } else { |
| |
2260 item.label = strdup(elm); |
| |
2261 } |
| |
2262 |
| |
2263 LISTBOX_ROW_REMOVE_CHILD(row); |
| |
2264 |
| |
2265 listbox_fill_row(listbox, GTK_WIDGET(row), sublist, &item, index); |
| |
2266 |
| |
2267 // cleanup |
| |
2268 free(item.label); |
| |
2269 free(item.icon); |
| |
2270 free(item.button_label); |
| |
2271 free(item.button_icon); |
| |
2272 free(item.badge); |
| 2246 } |
2273 } |
| 2247 |
2274 |
| 2248 void ui_listbox_update_sublist(UiListBox *listbox, UiListBoxSubList *sublist, size_t listbox_insert_index) { |
2275 void ui_listbox_update_sublist(UiListBox *listbox, UiListBoxSubList *sublist, size_t listbox_insert_index) { |
| 2249 // clear sublist |
2276 // clear sublist |
| 2250 CxIterator r = cxListIterator(sublist->widgets); |
2277 CxIterator r = cxListIterator(sublist->widgets); |
| 2287 } else { |
2314 } else { |
| 2288 item.label = strdup(elm); |
2315 item.label = strdup(elm); |
| 2289 } |
2316 } |
| 2290 |
2317 |
| 2291 // create listbox item |
2318 // create listbox item |
| 2292 GtkWidget *row = create_listbox_row(listbox, sublist, &item, (int)index); |
2319 GtkWidget *row = gtk_list_box_row_new(); |
| |
2320 listbox_fill_row(listbox, row, sublist, &item, (int)index); |
| 2293 if(index == 0) { |
2321 if(index == 0) { |
| 2294 // first row in the sublist, set ui_listbox data to the row |
2322 // first row in the sublist, set ui_listbox data to the row |
| 2295 // which is then used by the headerfunc |
2323 // which is then used by the headerfunc |
| 2296 g_object_set_data(G_OBJECT(row), "ui_listbox", listbox); |
2324 g_object_set_data(G_OBJECT(row), "ui_listbox", listbox); |
| 2297 g_object_set_data(G_OBJECT(row), "ui_listbox_sublist", sublist); |
2325 g_object_set_data(G_OBJECT(row), "ui_listbox_sublist", sublist); |
| 2321 sublist->numitems = cxListSize(sublist->widgets); |
2349 sublist->numitems = cxListSize(sublist->widgets); |
| 2322 } |
2350 } |
| 2323 |
2351 |
| 2324 void ui_listbox_list_update(UiList *list, int i) { |
2352 void ui_listbox_list_update(UiList *list, int i) { |
| 2325 UiListBoxSubList *sublist = list->obj; |
2353 UiListBoxSubList *sublist = list->obj; |
| 2326 ui_listbox_update_sublist(sublist->listbox, sublist, sublist->startpos); |
2354 if(i < 0) { |
| 2327 size_t pos = 0; |
2355 ui_listbox_update_sublist(sublist->listbox, sublist, sublist->startpos); |
| 2328 CxIterator it = cxListIterator(sublist->listbox->sublists); |
2356 size_t pos = 0; |
| 2329 cx_foreach(UiListBoxSubList *, ls, it) { |
2357 CxIterator it = cxListIterator(sublist->listbox->sublists); |
| 2330 ls->startpos = pos; |
2358 cx_foreach(UiListBoxSubList *, ls, it) { |
| 2331 pos += sublist->numitems; |
2359 ls->startpos = pos; |
| 2332 } |
2360 pos += ls->numitems; |
| 2333 |
2361 } |
| |
2362 } else { |
| |
2363 update_sublist_item(sublist->listbox, sublist, i); |
| |
2364 } |
| 2334 } |
2365 } |
| 2335 |
2366 |
| 2336 void ui_listbox_row_activate(GtkListBox *self, GtkListBoxRow *row, gpointer user_data) { |
2367 void ui_listbox_row_activate(GtkListBox *self, GtkListBoxRow *row, gpointer user_data) { |
| 2337 UiEventDataExt *data = g_object_get_data(G_OBJECT(row), "ui-listbox-row-eventdata"); |
2368 UiEventDataExt *data = g_object_get_data(G_OBJECT(row), "ui-listbox-row-eventdata"); |
| 2338 if(!data) { |
2369 if(!data) { |