ui/gtk/list.c

changeset 594
fc854e0ab924
parent 593
7061c9cf3b52
child 598
7b03db81caf8
equal deleted inserted replaced
593:7061c9cf3b52 594:fc854e0ab924
187 } 187 }
188 g_signal_connect(selection_model, "selection-changed", G_CALLBACK(ui_listview_selection_changed), listview); 188 g_signal_connect(selection_model, "selection-changed", G_CALLBACK(ui_listview_selection_changed), listview);
189 return selection_model; 189 return selection_model;
190 } 190 }
191 191
192 static UiListView* create_listview(UiObject *obj, UiListArgs args) { 192 static UiListView* create_listview(UiObject *obj, UiListArgs *args) {
193 UiListView *tableview = malloc(sizeof(UiListView)); 193 UiListView *tableview = malloc(sizeof(UiListView));
194 memset(tableview, 0, sizeof(UiListView)); 194 memset(tableview, 0, sizeof(UiListView));
195 tableview->obj = obj; 195 tableview->obj = obj;
196 tableview->model = args.model; 196 tableview->model = args->model;
197 tableview->onactivate = args.onactivate; 197 tableview->onactivate = args->onactivate;
198 tableview->onactivatedata = args.onactivatedata; 198 tableview->onactivatedata = args->onactivatedata;
199 tableview->onselection = args.onselection; 199 tableview->onselection = args->onselection;
200 tableview->onselectiondata = args.onselectiondata; 200 tableview->onselectiondata = args->onselectiondata;
201 tableview->ondragstart = args.ondragstart; 201 tableview->ondragstart = args->ondragstart;
202 tableview->ondragstartdata = args.ondragstartdata; 202 tableview->ondragstartdata = args->ondragstartdata;
203 tableview->ondragcomplete = args.ondragcomplete; 203 tableview->ondragcomplete = args->ondragcomplete;
204 tableview->ondragcompletedata = args.ondragcompletedata; 204 tableview->ondragcompletedata = args->ondragcompletedata;
205 tableview->ondrop = args.ondrop; 205 tableview->ondrop = args->ondrop;
206 tableview->ondropdata = args.ondropsdata; 206 tableview->ondropdata = args->ondropsdata;
207 tableview->selection.count = 0; 207 tableview->selection.count = 0;
208 tableview->selection.rows = NULL; 208 tableview->selection.rows = NULL;
209 return tableview; 209 return tableview;
210 } 210 }
211 211
212 UIWIDGET ui_listview_create(UiObject *obj, UiListArgs args) { 212 UIWIDGET ui_listview_create(UiObject *obj, UiListArgs *args) {
213 UiObject* current = uic_current_obj(obj); 213 UiObject* current = uic_current_obj(obj);
214 214
215 // 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
216 // use a UiModel for the listview 216 // use a UiModel for the listview
217 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1); 217 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1);
218 model->getvalue = args.getvalue ? args.getvalue : ui_strmodel_getvalue; 218 model->getvalue = args->getvalue ? args->getvalue : ui_strmodel_getvalue;
219 args.model = model; 219 args->model = model;
220 220
221 GListStore *ls = g_list_store_new(G_TYPE_OBJECT); 221 GListStore *ls = g_list_store_new(G_TYPE_OBJECT);
222 UiListView *listview = create_listview(obj, args); 222 UiListView *listview = create_listview(obj, args);
223 223
224 listview->columns = malloc(sizeof(UiColData)); 224 listview->columns = malloc(sizeof(UiColData));
228 228
229 GtkListItemFactory *factory = gtk_signal_list_item_factory_new(); 229 GtkListItemFactory *factory = gtk_signal_list_item_factory_new();
230 g_signal_connect(factory, "setup", G_CALLBACK(column_factory_setup), listview->columns); 230 g_signal_connect(factory, "setup", G_CALLBACK(column_factory_setup), listview->columns);
231 g_signal_connect(factory, "bind", G_CALLBACK(column_factory_bind), listview->columns); 231 g_signal_connect(factory, "bind", G_CALLBACK(column_factory_bind), listview->columns);
232 232
233 GtkSelectionModel *selection_model = create_selection_model(listview, ls, args.multiselection); 233 GtkSelectionModel *selection_model = create_selection_model(listview, ls, args->multiselection);
234 GtkWidget *view = gtk_list_view_new(GTK_SELECTION_MODEL(selection_model), factory); 234 GtkWidget *view = gtk_list_view_new(GTK_SELECTION_MODEL(selection_model), factory);
235 235
236 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST); 236 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args->list, args->varname, UI_VAR_LIST);
237 237
238 // init listview 238 // init listview
239 listview->widget = view; 239 listview->widget = view;
240 listview->var = var; 240 listview->var = var;
241 listview->liststore = ls; 241 listview->liststore = ls;
254 list->update = ui_listview_update2; 254 list->update = ui_listview_update2;
255 list->getselection = ui_listview_getselection2; 255 list->getselection = ui_listview_getselection2;
256 list->setselection = ui_listview_setselection2; 256 list->setselection = ui_listview_setselection2;
257 257
258 ui_update_liststore(ls, list); 258 ui_update_liststore(ls, list);
259 } else if (args.static_elements && args.static_nelm > 0) { 259 } else if (args->static_elements && args->static_nelm > 0) {
260 listview_copy_static_elements(listview, args.static_elements, args.static_nelm); 260 listview_copy_static_elements(listview, args->static_elements, args->static_nelm);
261 listview->model->getvalue = ui_strmodel_getvalue; // force strmodel 261 listview->model->getvalue = ui_strmodel_getvalue; // force strmodel
262 ui_update_liststore_static(ls, listview->elements, listview->nelm); 262 ui_update_liststore_static(ls, listview->elements, listview->nelm);
263 } 263 }
264 264
265 // event handling 265 // event handling
266 if(args.onactivate) { 266 if(args->onactivate) {
267 // columnview and listview can use the same callback function, because 267 // columnview and listview can use the same callback function, because
268 // the first parameter (which is technically a different pointer type) 268 // the first parameter (which is technically a different pointer type)
269 // is ignored 269 // is ignored
270 g_signal_connect(view, "activate", G_CALLBACK(ui_columnview_activate), listview); 270 g_signal_connect(view, "activate", G_CALLBACK(ui_columnview_activate), listview);
271 } 271 }
272 if(args.contextmenu) { 272 if(args->contextmenu) {
273 UIMENU menu = ui_contextmenu_create(args.contextmenu, obj, view); 273 UIMENU menu = ui_contextmenu_create(args->contextmenu, obj, view);
274 ui_widget_set_contextmenu(view, menu); 274 ui_widget_set_contextmenu(view, menu);
275 } 275 }
276 276
277 // add widget to parent 277 // add widget to parent
278 GtkWidget *scroll_area = SCROLLEDWINDOW_NEW(); 278 GtkWidget *scroll_area = SCROLLEDWINDOW_NEW();
280 GTK_SCROLLED_WINDOW(scroll_area), 280 GTK_SCROLLED_WINDOW(scroll_area),
281 GTK_POLICY_AUTOMATIC, 281 GTK_POLICY_AUTOMATIC,
282 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS 282 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS
283 SCROLLEDWINDOW_SET_CHILD(scroll_area, view); 283 SCROLLEDWINDOW_SET_CHILD(scroll_area, view);
284 284
285 UI_APPLY_LAYOUT1(current, args); 285 UI_APPLY_LAYOUT2(current, args);
286 current->container->add(current->container, scroll_area, FALSE); 286 current->container->add(current->container, scroll_area, FALSE);
287 287
288 // ct->current should point to view, not scroll_area, to make it possible 288 // ct->current should point to view, not scroll_area, to make it possible
289 // to add a context menu 289 // to add a context menu
290 current->container->current = view; 290 current->container->current = view;
291 291
292 return scroll_area; 292 return scroll_area;
293 } 293 }
294 294
295 UIWIDGET ui_combobox_create(UiObject *obj, UiListArgs args) { 295 UIWIDGET ui_combobox_create(UiObject *obj, UiListArgs *args) {
296 UiObject* current = uic_current_obj(obj); 296 UiObject* current = uic_current_obj(obj);
297 297
298 // to simplify things and share code with ui_tableview_create, we also 298 // to simplify things and share code with ui_tableview_create, we also
299 // use a UiModel for the listview 299 // use a UiModel for the listview
300 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1); 300 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1);
301 model->getvalue = args.getvalue ? args.getvalue : ui_strmodel_getvalue; 301 model->getvalue = args->getvalue ? args->getvalue : ui_strmodel_getvalue;
302 args.model = model; 302 args->model = model;
303 303
304 GListStore *ls = g_list_store_new(G_TYPE_OBJECT); 304 GListStore *ls = g_list_store_new(G_TYPE_OBJECT);
305 UiListView *listview = create_listview(obj, args); 305 UiListView *listview = create_listview(obj, args);
306 306
307 listview->columns = malloc(sizeof(UiColData)); 307 listview->columns = malloc(sizeof(UiColData));
314 g_signal_connect(factory, "bind", G_CALLBACK(column_factory_bind), listview->columns); 314 g_signal_connect(factory, "bind", G_CALLBACK(column_factory_bind), listview->columns);
315 315
316 GtkWidget *view = gtk_drop_down_new(G_LIST_MODEL(ls), NULL); 316 GtkWidget *view = gtk_drop_down_new(G_LIST_MODEL(ls), NULL);
317 gtk_drop_down_set_factory(GTK_DROP_DOWN(view), factory); 317 gtk_drop_down_set_factory(GTK_DROP_DOWN(view), factory);
318 318
319 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST); 319 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args->list, args->varname, UI_VAR_LIST);
320 320
321 // init listview 321 // init listview
322 listview->widget = view; 322 listview->widget = view;
323 listview->var = var; 323 listview->var = var;
324 listview->liststore = ls; 324 listview->liststore = ls;
337 list->update = ui_listview_update2; 337 list->update = ui_listview_update2;
338 list->getselection = ui_combobox_getselection; 338 list->getselection = ui_combobox_getselection;
339 list->setselection = ui_combobox_setselection; 339 list->setselection = ui_combobox_setselection;
340 340
341 ui_update_liststore(ls, list); 341 ui_update_liststore(ls, list);
342 } else if (args.static_elements && args.static_nelm > 0) { 342 } else if (args->static_elements && args->static_nelm > 0) {
343 listview_copy_static_elements(listview, args.static_elements, args.static_nelm); 343 listview_copy_static_elements(listview, args->static_elements, args->static_nelm);
344 listview->model->getvalue = ui_strmodel_getvalue; // force strmodel 344 listview->model->getvalue = ui_strmodel_getvalue; // force strmodel
345 ui_update_liststore_static(ls, listview->elements, listview->nelm); 345 ui_update_liststore_static(ls, listview->elements, listview->nelm);
346 } 346 }
347 347
348 // event handling 348 // event handling
349 if(args.onactivate) { 349 if(args->onactivate) {
350 g_signal_connect(view, "notify::selected", G_CALLBACK(ui_dropdown_notify), listview); 350 g_signal_connect(view, "notify::selected", G_CALLBACK(ui_dropdown_notify), listview);
351 } 351 }
352 352
353 // add widget to parent 353 // add widget to parent
354 UI_APPLY_LAYOUT1(current, args); 354 UI_APPLY_LAYOUT2(current, args);
355 current->container->add(current->container, view, FALSE); 355 current->container->add(current->container, view, FALSE);
356 return view; 356 return view;
357 } 357 }
358 358
359 void ui_listview_select(UIWIDGET listview, int index) { 359 void ui_listview_select(UIWIDGET listview, int index) {
363 363
364 void ui_combobox_select(UIWIDGET dropdown, int index) { 364 void ui_combobox_select(UIWIDGET dropdown, int index) {
365 gtk_drop_down_set_selected(GTK_DROP_DOWN(dropdown), index); 365 gtk_drop_down_set_selected(GTK_DROP_DOWN(dropdown), index);
366 } 366 }
367 367
368 UIWIDGET ui_table_create(UiObject *obj, UiListArgs args) { 368 UIWIDGET ui_table_create(UiObject *obj, UiListArgs *args) {
369 UiObject* current = uic_current_obj(obj); 369 UiObject* current = uic_current_obj(obj);
370 370
371 GListStore *ls = g_list_store_new(G_TYPE_OBJECT); 371 GListStore *ls = g_list_store_new(G_TYPE_OBJECT);
372 //g_list_store_append(ls, v1); 372 //g_list_store_append(ls, v1);
373 373
374 // create obj to store all relevant data we need for handling events 374 // create obj to store all relevant data we need for handling events
375 // and list updates 375 // and list updates
376 UiListView *tableview = create_listview(obj, args); 376 UiListView *tableview = create_listview(obj, args);
377 377
378 GtkSelectionModel *selection_model = create_selection_model(tableview, ls, args.multiselection); 378 GtkSelectionModel *selection_model = create_selection_model(tableview, ls, args->multiselection);
379 GtkWidget *view = gtk_column_view_new(GTK_SELECTION_MODEL(selection_model)); 379 GtkWidget *view = gtk_column_view_new(GTK_SELECTION_MODEL(selection_model));
380 380
381 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST); 381 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args->list, args->varname, UI_VAR_LIST);
382 382
383 // init tableview 383 // init tableview
384 tableview->widget = view; 384 tableview->widget = view;
385 tableview->var = var; 385 tableview->var = var;
386 tableview->liststore = ls; 386 tableview->liststore = ls;
391 G_CALLBACK(ui_listview_destroy), 391 G_CALLBACK(ui_listview_destroy),
392 tableview); 392 tableview);
393 393
394 394
395 // create columns from UiModel 395 // create columns from UiModel
396 UiModel *model = args.model; 396 UiModel *model = args->model;
397 int columns = model ? model->columns : 0; 397 int columns = model ? model->columns : 0;
398 398
399 tableview->columns = calloc(columns, sizeof(UiColData)); 399 tableview->columns = calloc(columns, sizeof(UiColData));
400 400
401 int addi = 0; 401 int addi = 0;
437 437
438 ui_update_liststore(ls, list); 438 ui_update_liststore(ls, list);
439 } 439 }
440 440
441 // event handling 441 // event handling
442 if(args.onactivate) { 442 if(args->onactivate) {
443 g_signal_connect(view, "activate", G_CALLBACK(ui_columnview_activate), tableview); 443 g_signal_connect(view, "activate", G_CALLBACK(ui_columnview_activate), tableview);
444 } 444 }
445 if(args.contextmenu) { 445 if(args->contextmenu) {
446 UIMENU menu = ui_contextmenu_create(args.contextmenu, obj, view); 446 UIMENU menu = ui_contextmenu_create(args->contextmenu, obj, view);
447 ui_widget_set_contextmenu(view, menu); 447 ui_widget_set_contextmenu(view, menu);
448 } 448 }
449 449
450 // add widget to parent 450 // add widget to parent
451 GtkWidget *scroll_area = SCROLLEDWINDOW_NEW(); 451 GtkWidget *scroll_area = SCROLLEDWINDOW_NEW();
453 GTK_SCROLLED_WINDOW(scroll_area), 453 GTK_SCROLLED_WINDOW(scroll_area),
454 GTK_POLICY_AUTOMATIC, 454 GTK_POLICY_AUTOMATIC,
455 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS 455 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS
456 SCROLLEDWINDOW_SET_CHILD(scroll_area, view); 456 SCROLLEDWINDOW_SET_CHILD(scroll_area, view);
457 457
458 UI_APPLY_LAYOUT1(current, args); 458 UI_APPLY_LAYOUT2(current, args);
459 current->container->add(current->container, scroll_area, FALSE); 459 current->container->add(current->container, scroll_area, FALSE);
460 460
461 // ct->current should point to view, not scroll_area, to make it possible 461 // ct->current should point to view, not scroll_area, to make it possible
462 // to add a context menu 462 // to add a context menu
463 current->container->current = view; 463 current->container->current = view;
778 778
779 return store; 779 return store;
780 } 780 }
781 781
782 782
783 UIWIDGET ui_listview_create(UiObject *obj, UiListArgs args) { 783 UIWIDGET ui_listview_create(UiObject *obj, UiListArgs *args) {
784 UiObject* current = uic_current_obj(obj); 784 UiObject* current = uic_current_obj(obj);
785 785
786 // create treeview 786 // create treeview
787 GtkWidget *view = gtk_tree_view_new(); 787 GtkWidget *view = gtk_tree_view_new();
788 ui_set_name_and_style(view, args.name, args.style_class); 788 ui_set_name_and_style(view, args->name, args->style_class);
789 ui_set_widget_groups(obj->ctx, view, args.groups); 789 ui_set_widget_groups(obj->ctx, view, args->groups);
790 GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); 790 GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
791 GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes(NULL, renderer, "text", 0, NULL); 791 GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes(NULL, renderer, "text", 0, NULL);
792 gtk_tree_view_append_column(GTK_TREE_VIEW(view), column); 792 gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
793 793
794 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE); 794 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
801 #else 801 #else
802 // TODO: implement for gtk2 802 // TODO: implement for gtk2
803 #endif 803 #endif
804 804
805 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1); 805 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1);
806 model->getvalue = args.getvalue ? args.getvalue : ui_strmodel_getvalue; 806 model->getvalue = args->getvalue ? args->getvalue : ui_strmodel_getvalue;
807 807
808 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST); 808 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args->list, args->varname, UI_VAR_LIST);
809 809
810 UiList *list = var ? var->value : NULL; 810 UiList *list = var ? var->value : NULL;
811 GtkListStore *listmodel = create_list_store(list, model); 811 GtkListStore *listmodel = create_list_store(list, model);
812 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(listmodel)); 812 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(listmodel));
813 g_object_unref(listmodel); 813 g_object_unref(listmodel);
833 list->obj = listview; 833 list->obj = listview;
834 834
835 // add callback 835 // add callback
836 UiTreeEventData *event = malloc(sizeof(UiTreeEventData)); 836 UiTreeEventData *event = malloc(sizeof(UiTreeEventData));
837 event->obj = obj; 837 event->obj = obj;
838 event->activate = args.onactivate; 838 event->activate = args->onactivate;
839 event->activatedata = args.onactivatedata; 839 event->activatedata = args->onactivatedata;
840 event->selection = args.onselection; 840 event->selection = args->onselection;
841 event->selectiondata = args.onselectiondata; 841 event->selectiondata = args->onselectiondata;
842 g_signal_connect( 842 g_signal_connect(
843 view, 843 view,
844 "destroy", 844 "destroy",
845 G_CALLBACK(ui_destroy_userdata), 845 G_CALLBACK(ui_destroy_userdata),
846 event); 846 event);
847 847
848 if(args.onactivate) { 848 if(args->onactivate) {
849 g_signal_connect( 849 g_signal_connect(
850 view, 850 view,
851 "row-activated", 851 "row-activated",
852 G_CALLBACK(ui_listview_activate_event), 852 G_CALLBACK(ui_listview_activate_event),
853 event); 853 event);
854 } 854 }
855 if(args.onselection) { 855 if(args->onselection) {
856 GtkTreeSelection *selection = gtk_tree_view_get_selection( 856 GtkTreeSelection *selection = gtk_tree_view_get_selection(
857 GTK_TREE_VIEW(view)); 857 GTK_TREE_VIEW(view));
858 g_signal_connect( 858 g_signal_connect(
859 selection, 859 selection,
860 "changed", 860 "changed",
861 G_CALLBACK(ui_listview_selection_event), 861 G_CALLBACK(ui_listview_selection_event),
862 event); 862 event);
863 } 863 }
864 if(args.contextmenu) { 864 if(args->contextmenu) {
865 UIMENU menu = ui_contextmenu_create(args.contextmenu, obj, view); 865 UIMENU menu = ui_contextmenu_create(args->contextmenu, obj, view);
866 ui_widget_set_contextmenu(view, menu); 866 ui_widget_set_contextmenu(view, menu);
867 } 867 }
868 868
869 869
870 // add widget to the current container 870 // add widget to the current container
873 GTK_SCROLLED_WINDOW(scroll_area), 873 GTK_SCROLLED_WINDOW(scroll_area),
874 GTK_POLICY_AUTOMATIC, 874 GTK_POLICY_AUTOMATIC,
875 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS 875 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS
876 SCROLLEDWINDOW_SET_CHILD(scroll_area, view); 876 SCROLLEDWINDOW_SET_CHILD(scroll_area, view);
877 877
878 UI_APPLY_LAYOUT1(current, args); 878 UI_APPLY_LAYOUT2(current, args);
879 current->container->add(current->container, scroll_area, FALSE); 879 current->container->add(current->container, scroll_area, FALSE);
880 880
881 // ct->current should point to view, not scroll_area, to make it possible 881 // ct->current should point to view, not scroll_area, to make it possible
882 // to add a context menu 882 // to add a context menu
883 current->container->current = view; 883 current->container->current = view;
894 894
895 void ui_combobox_select(UIWIDGET dropdown, int index) { 895 void ui_combobox_select(UIWIDGET dropdown, int index) {
896 gtk_combo_box_set_active(GTK_COMBO_BOX(dropdown), index); 896 gtk_combo_box_set_active(GTK_COMBO_BOX(dropdown), index);
897 } 897 }
898 898
899 UIWIDGET ui_table_create(UiObject *obj, UiListArgs args) { 899 UIWIDGET ui_table_create(UiObject *obj, UiListArgs *args) {
900 UiObject* current = uic_current_obj(obj); 900 UiObject* current = uic_current_obj(obj);
901 901
902 // create treeview 902 // create treeview
903 GtkWidget *view = gtk_tree_view_new(); 903 GtkWidget *view = gtk_tree_view_new();
904 904
905 UiModel *model = args.model; 905 UiModel *model = args->model;
906 int columns = model ? model->columns : 0; 906 int columns = model ? model->columns : 0;
907 907
908 int addi = 0; 908 int addi = 0;
909 for(int i=0;i<columns;i++) { 909 for(int i=0;i<columns;i++) {
910 GtkTreeViewColumn *column = NULL; 910 GtkTreeViewColumn *column = NULL;
957 //gtk_tree_view_set_activate_on_single_click(GTK_TREE_VIEW(view), TRUE); 957 //gtk_tree_view_set_activate_on_single_click(GTK_TREE_VIEW(view), TRUE);
958 #else 958 #else
959 959
960 #endif 960 #endif
961 961
962 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST); 962 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args->list, args->varname, UI_VAR_LIST);
963 963
964 UiList *list = var ? var->value : NULL; 964 UiList *list = var ? var->value : NULL;
965 GtkListStore *listmodel = create_list_store(list, model); 965 GtkListStore *listmodel = create_list_store(list, model);
966 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(listmodel)); 966 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(listmodel));
967 g_object_unref(listmodel); 967 g_object_unref(listmodel);
975 memset(tableview, 0, sizeof(UiListView)); 975 memset(tableview, 0, sizeof(UiListView));
976 tableview->obj = obj; 976 tableview->obj = obj;
977 tableview->widget = view; 977 tableview->widget = view;
978 tableview->var = var; 978 tableview->var = var;
979 tableview->model = model; 979 tableview->model = model;
980 tableview->ondragstart = args.ondragstart; 980 tableview->ondragstart = args->ondragstart;
981 tableview->ondragstartdata = args.ondragstartdata; 981 tableview->ondragstartdata = args->ondragstartdata;
982 tableview->ondragcomplete = args.ondragcomplete; 982 tableview->ondragcomplete = args->ondragcomplete;
983 tableview->ondragcompletedata = args.ondragcompletedata; 983 tableview->ondragcompletedata = args->ondragcompletedata;
984 tableview->ondrop = args.ondrop; 984 tableview->ondrop = args->ondrop;
985 tableview->ondropdata = args.ondropsdata; 985 tableview->ondropdata = args->ondropsdata;
986 tableview->selection.count = 0; 986 tableview->selection.count = 0;
987 tableview->selection.rows = NULL; 987 tableview->selection.rows = NULL;
988 g_signal_connect( 988 g_signal_connect(
989 view, 989 view,
990 "destroy", 990 "destroy",
998 list->obj = tableview; 998 list->obj = tableview;
999 999
1000 // add callback 1000 // add callback
1001 UiTreeEventData *event = ui_malloc(obj->ctx, sizeof(UiTreeEventData)); 1001 UiTreeEventData *event = ui_malloc(obj->ctx, sizeof(UiTreeEventData));
1002 event->obj = obj; 1002 event->obj = obj;
1003 event->activate = args.onactivate; 1003 event->activate = args->onactivate;
1004 event->selection = args.onselection; 1004 event->selection = args->onselection;
1005 event->activatedata = args.onactivatedata; 1005 event->activatedata = args->onactivatedata;
1006 event->selectiondata = args.onselectiondata; 1006 event->selectiondata = args->onselectiondata;
1007 if(args.onactivate) { 1007 if(args->onactivate) {
1008 g_signal_connect( 1008 g_signal_connect(
1009 view, 1009 view,
1010 "row-activated", 1010 "row-activated",
1011 G_CALLBACK(ui_listview_activate_event), 1011 G_CALLBACK(ui_listview_activate_event),
1012 event); 1012 event);
1013 } 1013 }
1014 if(args.onselection) { 1014 if(args->onselection) {
1015 GtkTreeSelection *selection = gtk_tree_view_get_selection( 1015 GtkTreeSelection *selection = gtk_tree_view_get_selection(
1016 GTK_TREE_VIEW(view)); 1016 GTK_TREE_VIEW(view));
1017 g_signal_connect( 1017 g_signal_connect(
1018 selection, 1018 selection,
1019 "changed", 1019 "changed",
1021 event); 1021 event);
1022 } 1022 }
1023 // TODO: destroy callback 1023 // TODO: destroy callback
1024 1024
1025 1025
1026 if(args.ondragstart) { 1026 if(args->ondragstart) {
1027 ui_listview_add_dnd(tableview, &args); 1027 ui_listview_add_dnd(tableview, &args);
1028 } 1028 }
1029 if(args.ondrop) { 1029 if(args->ondrop) {
1030 ui_listview_enable_drop(tableview, &args); 1030 ui_listview_enable_drop(tableview, &args);
1031 } 1031 }
1032 1032
1033 GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(view)); 1033 GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(view));
1034 if(args.multiselection) { 1034 if(args->multiselection) {
1035 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE); 1035 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
1036 } 1036 }
1037 1037
1038 // add widget to the current container 1038 // add widget to the current container
1039 GtkWidget *scroll_area = SCROLLEDWINDOW_NEW(); 1039 GtkWidget *scroll_area = SCROLLEDWINDOW_NEW();
1041 GTK_SCROLLED_WINDOW(scroll_area), 1041 GTK_SCROLLED_WINDOW(scroll_area),
1042 GTK_POLICY_AUTOMATIC, 1042 GTK_POLICY_AUTOMATIC,
1043 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS 1043 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS
1044 SCROLLEDWINDOW_SET_CHILD(scroll_area, view); 1044 SCROLLEDWINDOW_SET_CHILD(scroll_area, view);
1045 1045
1046 if(args.contextmenu) { 1046 if(args->contextmenu) {
1047 UIMENU menu = ui_contextmenu_create(args.contextmenu, obj, scroll_area); 1047 UIMENU menu = ui_contextmenu_create(args->contextmenu, obj, scroll_area);
1048 #if GTK_MAJOR_VERSION >= 4 1048 #if GTK_MAJOR_VERSION >= 4
1049 ui_widget_set_contextmenu(scroll_area, menu); 1049 ui_widget_set_contextmenu(scroll_area, menu);
1050 #else 1050 #else
1051 ui_widget_set_contextmenu(view, menu); 1051 ui_widget_set_contextmenu(view, menu);
1052 #endif 1052 #endif
1053 } 1053 }
1054 1054
1055 UI_APPLY_LAYOUT1(current, args); 1055 UI_APPLY_LAYOUT2(current, args);
1056 current->container->add(current->container, scroll_area, FALSE); 1056 current->container->add(current->container, scroll_area, FALSE);
1057 1057
1058 // ct->current should point to view, not scroll_area, to make it possible 1058 // ct->current should point to view, not scroll_area, to make it possible
1059 // to add a context menu 1059 // to add a context menu
1060 current->container->current = view; 1060 current->container->current = view;
1100 1100
1101 1101
1102 1102
1103 /* --------------------------- ComboBox --------------------------- */ 1103 /* --------------------------- ComboBox --------------------------- */
1104 1104
1105 UIWIDGET ui_combobox_create(UiObject *obj, UiListArgs args) { 1105 UIWIDGET ui_combobox_create(UiObject *obj, UiListArgs *args) {
1106 UiObject* current = uic_current_obj(obj); 1106 UiObject* current = uic_current_obj(obj);
1107 1107
1108 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1); 1108 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1);
1109 model->getvalue = args.getvalue ? args.getvalue : ui_strmodel_getvalue; 1109 model->getvalue = args->getvalue ? args->getvalue : ui_strmodel_getvalue;
1110 1110
1111 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST); 1111 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args->list, args->varname, UI_VAR_LIST);
1112 1112
1113 GtkWidget *combobox = ui_create_combobox(obj, model, var, args.static_elements, args.static_nelm, args.onactivate, args.onactivatedata); 1113 GtkWidget *combobox = ui_create_combobox(obj, model, var, args->static_elements, args->static_nelm, args->onactivate, args->onactivatedata);
1114 ui_set_name_and_style(combobox, args.name, args.style_class); 1114 ui_set_name_and_style(combobox, args->name, args->style_class);
1115 ui_set_widget_groups(obj->ctx, combobox, args.groups); 1115 ui_set_widget_groups(obj->ctx, combobox, args->groups);
1116 UI_APPLY_LAYOUT1(current, args); 1116 UI_APPLY_LAYOUT2(current, args);
1117 current->container->add(current->container, combobox, FALSE); 1117 current->container->add(current->container, combobox, FALSE);
1118 current->container->current = combobox; 1118 current->container->current = combobox;
1119 return combobox; 1119 return combobox;
1120 } 1120 }
1121 1121
1756 } 1756 }
1757 1757
1758 cxListAdd(sublists, &uisublist); 1758 cxListAdd(sublists, &uisublist);
1759 } 1759 }
1760 1760
1761 UIEXPORT UIWIDGET ui_sourcelist_create(UiObject *obj, UiSourceListArgs args) { 1761 UIEXPORT UIWIDGET ui_sourcelist_create(UiObject *obj, UiSourceListArgs *args) {
1762 UiObject* current = uic_current_obj(obj); 1762 UiObject* current = uic_current_obj(obj);
1763 1763
1764 #ifdef UI_GTK3 1764 #ifdef UI_GTK3
1765 GtkWidget *listbox = g_object_new(ui_sidebar_list_box_get_type(), NULL); 1765 GtkWidget *listbox = g_object_new(ui_sidebar_list_box_get_type(), NULL);
1766 #else 1766 #else
1767 GtkWidget *listbox = gtk_list_box_new(); 1767 GtkWidget *listbox = gtk_list_box_new();
1768 #endif 1768 #endif
1769 if(!args.style_class) { 1769 if(!args->style_class) {
1770 #if GTK_MAJOR_VERSION >= 4 1770 #if GTK_MAJOR_VERSION >= 4
1771 WIDGET_ADD_CSS_CLASS(listbox, "navigation-sidebar"); 1771 WIDGET_ADD_CSS_CLASS(listbox, "navigation-sidebar");
1772 #else 1772 #else
1773 WIDGET_ADD_CSS_CLASS(listbox, "sidebar"); 1773 WIDGET_ADD_CSS_CLASS(listbox, "sidebar");
1774 #endif 1774 #endif
1775 } 1775 }
1776 gtk_list_box_set_header_func(GTK_LIST_BOX(listbox), listbox_create_header, NULL, NULL); 1776 gtk_list_box_set_header_func(GTK_LIST_BOX(listbox), listbox_create_header, NULL, NULL);
1777 GtkWidget *scroll_area = SCROLLEDWINDOW_NEW(); 1777 GtkWidget *scroll_area = SCROLLEDWINDOW_NEW();
1778 SCROLLEDWINDOW_SET_CHILD(scroll_area, listbox); 1778 SCROLLEDWINDOW_SET_CHILD(scroll_area, listbox);
1779 1779
1780 ui_set_name_and_style(listbox, args.name, args.style_class); 1780 ui_set_name_and_style(listbox, args->name, args->style_class);
1781 ui_set_widget_groups(obj->ctx, listbox, args.groups); 1781 ui_set_widget_groups(obj->ctx, listbox, args->groups);
1782 UI_APPLY_LAYOUT1(current, args); 1782 UI_APPLY_LAYOUT2(current, args);
1783 current->container->add(current->container, scroll_area, TRUE); 1783 current->container->add(current->container, scroll_area, TRUE);
1784 1784
1785 UiListBox *uilistbox = malloc(sizeof(UiListBox)); 1785 UiListBox *uilistbox = malloc(sizeof(UiListBox));
1786 uilistbox->obj = obj; 1786 uilistbox->obj = obj;
1787 uilistbox->listbox = GTK_LIST_BOX(listbox); 1787 uilistbox->listbox = GTK_LIST_BOX(listbox);
1788 uilistbox->getvalue = args.getvalue; 1788 uilistbox->getvalue = args->getvalue;
1789 uilistbox->onactivate = args.onactivate; 1789 uilistbox->onactivate = args->onactivate;
1790 uilistbox->onactivatedata = args.onactivatedata; 1790 uilistbox->onactivatedata = args->onactivatedata;
1791 uilistbox->onbuttonclick = args.onbuttonclick; 1791 uilistbox->onbuttonclick = args->onbuttonclick;
1792 uilistbox->onbuttonclickdata = args.onbuttonclickdata; 1792 uilistbox->onbuttonclickdata = args->onbuttonclickdata;
1793 uilistbox->sublists = cxArrayListCreateSimple(sizeof(UiListBoxSubList), 4); 1793 uilistbox->sublists = cxArrayListCreateSimple(sizeof(UiListBoxSubList), 4);
1794 uilistbox->sublists->collection.advanced_destructor = (cx_destructor_func2)sublist_destroy; 1794 uilistbox->sublists->collection.advanced_destructor = (cx_destructor_func2)sublist_destroy;
1795 uilistbox->sublists->collection.destructor_data = obj; 1795 uilistbox->sublists->collection.destructor_data = obj;
1796 uilistbox->first_row = NULL; 1796 uilistbox->first_row = NULL;
1797 1797
1798 if(args.sublists) { 1798 if(args->sublists) {
1799 // static sublist initalization 1799 // static sublist initalization
1800 if(args.numsublists == 0 && args.sublists) { 1800 if(args->numsublists == 0 && args->sublists) {
1801 args.numsublists = INT_MAX; 1801 args->numsublists = INT_MAX;
1802 } 1802 }
1803 for(int i=0;i<args.numsublists;i++) { 1803 for(int i=0;i<args->numsublists;i++) {
1804 UiSubList sublist = args.sublists[i]; 1804 UiSubList sublist = args->sublists[i];
1805 if(!sublist.varname && !sublist.value) { 1805 if(!sublist.varname && !sublist.value) {
1806 break; 1806 break;
1807 } 1807 }
1808 1808
1809 add_sublist(uilistbox, uilistbox->sublists, &sublist); 1809 add_sublist(uilistbox, uilistbox->sublists, &sublist);
1810 } 1810 }
1811 1811
1812 // fill items 1812 // fill items
1813 ui_listbox_update(uilistbox, 0, cxListSize(uilistbox->sublists)); 1813 ui_listbox_update(uilistbox, 0, cxListSize(uilistbox->sublists));
1814 } else { 1814 } else {
1815 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.dynamic_sublist, args.varname, UI_VAR_LIST); 1815 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args->dynamic_sublist, args->varname, UI_VAR_LIST);
1816 if(var) { 1816 if(var) {
1817 UiList *list = var->value; 1817 UiList *list = var->value;
1818 list->obj = uilistbox; 1818 list->obj = uilistbox;
1819 list->update = ui_listbox_dynamic_update; 1819 list->update = ui_listbox_dynamic_update;
1820 1820
1832 listbox, 1832 listbox,
1833 "destroy", 1833 "destroy",
1834 G_CALLBACK(ui_destroy_sourcelist), 1834 G_CALLBACK(ui_destroy_sourcelist),
1835 uilistbox); 1835 uilistbox);
1836 1836
1837 if(args.onactivate) { 1837 if(args->onactivate) {
1838 g_signal_connect( 1838 g_signal_connect(
1839 listbox, 1839 listbox,
1840 "row-activated", 1840 "row-activated",
1841 G_CALLBACK(ui_listbox_row_activate), 1841 G_CALLBACK(ui_listbox_row_activate),
1842 NULL); 1842 NULL);

mercurial