ui/common/types.c

changeset 1168
2f9d8af6a499
parent 1142
e2a6707aa1e0
child 1172
e1c1559f2522
equal deleted inserted replaced
1167:f0e901f7d1b7 1168:2f9d8af6a499
119 119
120 UiList* ui_list_new2(UiContext *ctx, const char *name, ui_list_init_func listinit, void *userdata) { 120 UiList* ui_list_new2(UiContext *ctx, const char *name, ui_list_init_func listinit, void *userdata) {
121 UiList *list = ui_malloc(ctx, sizeof(UiList)); 121 UiList *list = ui_malloc(ctx, sizeof(UiList));
122 memset(list, 0, sizeof(UiList)); 122 memset(list, 0, sizeof(UiList));
123 listinit(ctx, list, userdata); 123 listinit(ctx, list, userdata);
124 list->save_selection = TRUE;
124 125
125 if(name && ctx) { 126 if(name && ctx) {
126 uic_reg_var(ctx, name, UI_VAR_LIST, list); 127 uic_reg_var(ctx, name, UI_VAR_LIST, list);
127 } 128 }
128 129
135 } else if(!default_list_destroy) { 136 } else if(!default_list_destroy) {
136 uic_ucx_list_destroy(ctx, list, NULL); 137 uic_ucx_list_destroy(ctx, list, NULL);
137 } else { 138 } else {
138 default_list_destroy(ctx, list, default_list_destroy_userdata); 139 default_list_destroy(ctx, list, default_list_destroy_userdata);
139 } 140 }
141 ui_list_selection_free(list->saved_selection);
140 ui_free(ctx, list); 142 ui_free(ctx, list);
141 } 143 }
142 144
143 void* ui_list_first(UiList *list) { 145 void* ui_list_first(UiList *list) {
144 list->iter = (void*)(intptr_t)0; 146 list->iter = (void*)(intptr_t)0;
215 list->observers = ui_add_observer(list->observers, f, data); 217 list->observers = ui_add_observer(list->observers, f, data);
216 } 218 }
217 219
218 void ui_list_notify(UiList *list) { 220 void ui_list_notify(UiList *list) {
219 ui_notify(list->observers, list); 221 ui_notify(list->observers, list);
222 }
223
224 void ui_list_clear_saved_selection(UiList *list) {
225 ui_list_selection_free(list->saved_selection);
226 list->saved_selection = NULL;
220 } 227 }
221 228
222 229
223 typedef struct { 230 typedef struct {
224 int type; 231 int type;
804 r->setrange = NULL; 811 r->setrange = NULL;
805 r->obj = NULL; 812 r->obj = NULL;
806 } 813 }
807 814
808 void uic_list_unbind(UiList *l) { 815 void uic_list_unbind(UiList *l) {
816 // save selection
817 ui_list_selection_free(l->saved_selection);
818 if(l->getselection && l->save_selection) {
819 l->saved_selection = ui_list_get_selection_allocated(l);
820 } else {
821 l->saved_selection = NULL;
822 }
823
824 // unbind
809 l->update = NULL; 825 l->update = NULL;
810 l->getselection = NULL; 826 l->getselection = NULL;
811 l->setselection = NULL; 827 l->setselection = NULL;
812 l->obj = NULL; 828 l->obj = NULL;
813 } 829 }
815 void uic_generic_unbind(UiGeneric *g) { 831 void uic_generic_unbind(UiGeneric *g) {
816 g->get = NULL; 832 g->get = NULL;
817 g->get_type = NULL; 833 g->get_type = NULL;
818 g->set = NULL; 834 g->set = NULL;
819 g->obj = NULL; 835 g->obj = NULL;
836 }
837
838
839
840 UiListSelection* ui_list_get_selection_allocated(UiList *list) {
841 UiListSelection *sel = malloc(sizeof(UiListSelection));
842 *sel = ui_list_get_selection(list);
843 return sel;
844
845 }
846
847 void ui_list_selection_free(UiListSelection *sel) {
848 if(!sel) {
849 return;
850 }
851 ui_listselection_free(*sel);
852 free(sel);
820 } 853 }
821 854
822 855
823 UIEXPORT int ui_list_getselection(UiList *list) { 856 UIEXPORT int ui_list_getselection(UiList *list) {
824 int selection = -1; 857 int selection = -1;

mercurial