ui/gtk/list.c

changeset 1136
e6fc42b4248d
parent 1057
b0bc313dea43
equal deleted inserted replaced
1135:2b1574ae72b5 1136:e6fc42b4248d
31 #include <string.h> 31 #include <string.h>
32 #include <stdarg.h> 32 #include <stdarg.h>
33 33
34 #include "../common/context.h" 34 #include "../common/context.h"
35 #include "../common/object.h" 35 #include "../common/object.h"
36 #include "../common/action.h"
36 #include "container.h" 37 #include "container.h"
37 38
38 #include <cx/array_list.h> 39 #include <cx/array_list.h>
39 #include <cx/linked_list.h> 40 #include <cx/linked_list.h>
40 41
81 tableview->obj = obj; 82 tableview->obj = obj;
82 tableview->model = args->model; 83 tableview->model = args->model;
83 tableview->multiselection = args->multiselection; 84 tableview->multiselection = args->multiselection;
84 tableview->onactivate = args->onactivate; 85 tableview->onactivate = args->onactivate;
85 tableview->onactivatedata = args->onactivatedata; 86 tableview->onactivatedata = args->onactivatedata;
87 tableview->onactivate_action = args->onactivate_action ? strdup(args->onactivate_action) : NULL;
86 tableview->onselection = args->onselection; 88 tableview->onselection = args->onselection;
87 tableview->onselectiondata = args->onselectiondata; 89 tableview->onselectiondata = args->onselectiondata;
90 tableview->onselection_action = args->onselection_action ? strdup(args->onselection_action) : NULL;
88 tableview->ondragstart = args->ondragstart; 91 tableview->ondragstart = args->ondragstart;
89 tableview->ondragstartdata = args->ondragstartdata; 92 tableview->ondragstartdata = args->ondragstartdata;
93 tableview->ondragstart_action = args->ondragstart_action ? strdup(args->ondragstart_action) : NULL;
90 tableview->ondragcomplete = args->ondragcomplete; 94 tableview->ondragcomplete = args->ondragcomplete;
91 tableview->ondragcompletedata = args->ondragcompletedata; 95 tableview->ondragcompletedata = args->ondragcompletedata;
96 tableview->ondragcomplete_action = args->ondragcomplete_action ? strdup(args->ondragcomplete_action) : NULL;
92 tableview->ondrop = args->ondrop; 97 tableview->ondrop = args->ondrop;
93 tableview->ondropdata = args->ondropdata; 98 tableview->ondropdata = args->ondropdata;
99 tableview->ondrop_action = args->ondrop_action ? strdup(args->ondrop_action) : NULL;
94 tableview->selection.count = 0; 100 tableview->selection.count = 0;
95 tableview->selection.rows = NULL; 101 tableview->selection.rows = NULL;
96 tableview->current_row = -1; 102 tableview->current_row = -1;
97 tableview->getstyle = args->getstyle; 103 tableview->getstyle = args->getstyle;
98 tableview->getstyledata = args->getstyledata; 104 tableview->getstyledata = args->getstyledata;
506 listview->getvalue = str_getvalue; // force string values 512 listview->getvalue = str_getvalue; // force string values
507 ui_update_liststore_static(ls, listview->elements, listview->nelm); 513 ui_update_liststore_static(ls, listview->elements, listview->nelm);
508 } 514 }
509 515
510 // event handling 516 // event handling
511 if(args->onactivate) { 517 if(args->onactivate || args->onactivate_action) {
512 // columnview and listview can use the same callback function, because 518 // columnview and listview can use the same callback function, because
513 // the first parameter (which is technically a different pointer type) 519 // the first parameter (which is technically a different pointer type)
514 // is ignored 520 // is ignored
515 g_signal_connect(view, "activate", G_CALLBACK(ui_columnview_activate), listview); 521 g_signal_connect(view, "activate", G_CALLBACK(ui_columnview_activate), listview);
516 } 522 }
804 810
805 gtk_bitset_unref(bitset); 811 gtk_bitset_unref(bitset);
806 return sel; 812 return sel;
807 } 813 }
808 814
809 static void listview_event(ui_callback cb, void *cbdata, UiListView *view) { 815 static void listview_event(ui_callback cb, void *cbdata, const char *action, UiListView *view) {
810 UiEvent event; 816 UiEvent event;
811 event.obj = view->obj; 817 event.obj = view->obj;
812 event.document = event.obj->ctx->document; 818 event.document = event.obj->ctx->document;
813 event.window = event.obj->window; 819 event.window = event.obj->window;
814 event.intval = view->selection.count; 820 event.intval = view->selection.count;
815 event.eventdata = &view->selection; 821 event.eventdata = &view->selection;
816 event.eventdatatype = UI_EVENT_DATA_LIST_SELECTION; 822 event.eventdatatype = UI_EVENT_DATA_LIST_SELECTION;
817 event.set = ui_get_setop(); 823 event.set = ui_get_setop();
818 if(cb) { 824 if(cb) {
819 cb(&event, cbdata); 825 cb(&event, cbdata);
826 }
827
828 if(action) {
829 uic_action_callback(&event, action);
820 } 830 }
821 } 831 }
822 832
823 static void listview_update_selection(UiListView *view) { 833 static void listview_update_selection(UiListView *view) {
824 free(view->selection.rows); 834 free(view->selection.rows);
866 void ui_columnview_activate(void *ignore, guint position, gpointer userdata) { 876 void ui_columnview_activate(void *ignore, guint position, gpointer userdata) {
867 UiListView *view = userdata; 877 UiListView *view = userdata;
868 if(view->selection.count == 0) { 878 if(view->selection.count == 0) {
869 listview_update_selection(view); 879 listview_update_selection(view);
870 } 880 }
871 listview_event(view->onactivate, view->onactivatedata, view); 881 listview_event(view->onactivate, view->onactivatedata, view->onactivate_action, view);
872 } 882 }
873 883
874 void ui_listview_selection_changed(GtkSelectionModel* self, guint position, guint n_items, gpointer userdata) { 884 void ui_listview_selection_changed(GtkSelectionModel* self, guint position, guint n_items, gpointer userdata) {
875 UiListView *view = userdata; 885 UiListView *view = userdata;
876 listview_update_selection(view); 886 listview_update_selection(view);
877 if(ui_selection_events_is_enabled()) { 887 if(ui_selection_events_is_enabled()) {
878 listview_event(view->onselection, view->onselectiondata, view); 888 listview_event(view->onselection, view->onselectiondata, view->onselection_action, view);
879 } 889 }
880 } 890 }
881 891
882 void ui_dropdown_activate(GtkDropDown* self, gpointer userdata) { 892 void ui_dropdown_activate(GtkDropDown* self, gpointer userdata) {
883 UiListView *view = userdata; 893 UiListView *view = userdata;
2169 free(t); 2179 free(t);
2170 } 2180 }
2171 */ 2181 */
2172 2182
2173 void ui_listview_destroy(GtkWidget *w, UiListView *v) { 2183 void ui_listview_destroy(GtkWidget *w, UiListView *v) {
2184 free(v->onactivate_action);
2185 free(v->onselection_action);
2186 free(v->ondragstart_action);
2187 free(v->ondragcomplete_action);
2188 free(v->ondrop_action);
2174 //gtk_tree_view_set_model(GTK_TREE_VIEW(w), NULL); 2189 //gtk_tree_view_set_model(GTK_TREE_VIEW(w), NULL);
2175 if(v->var) { 2190 if(v->var) {
2176 ui_destroy_boundvar(v->obj->ctx, v->var); 2191 ui_destroy_boundvar(v->obj->ctx, v->var);
2177 } 2192 }
2178 if(v->model) { 2193 if(v->model) {

mercurial