ui/common/types.c

branch
newapi
changeset 215
1bd5534c395d
parent 174
0358f1d9c506
child 231
e160bb392148
equal deleted inserted replaced
214:279c0c81d3b1 215:1bd5534c395d
202 cxListDestroy(cols); 202 cxListDestroy(cols);
203 203
204 return info; 204 return info;
205 } 205 }
206 206
207 UiModel* ui_model_copy(UiContext *ctx, UiModel* model) {
208 const CxAllocator* a = ctx ? ctx->allocator : cxDefaultAllocator;
209
210 UiModel* newmodel = cxMalloc(a, sizeof(UiModel));
211 *newmodel = *model;
212
213 newmodel->types = cxCalloc(a, model->columns, sizeof(UiModelType));
214 memcpy(newmodel->types, model->types, model->columns);
215
216 newmodel->titles = cxCalloc(a, model->columns, sizeof(char*));
217 for (int i = 0; i < model->columns; i++) {
218 newmodel->titles[i] = model->titles[i] ? cx_strdup_a(a, cx_str(model->titles[i])).ptr : NULL;
219 }
220
221 return newmodel;
222 }
223
207 void ui_model_free(UiContext *ctx, UiModel *mi) { 224 void ui_model_free(UiContext *ctx, UiModel *mi) {
208 cxFree(ctx->allocator, mi->types); 225 const CxAllocator* a = ctx ? ctx->allocator : cxDefaultAllocator;
209 cxFree(ctx->allocator, mi->titles); 226 cxFree(a, mi->types);
210 cxFree(ctx->allocator, mi); 227 cxFree(a, mi->titles);
228 cxFree(a, mi);
211 } 229 }
212 230
213 // types 231 // types
214 232
215 // public functions 233 // public functions

mercurial