ui/common/types.c

changeset 1090
ab2e458df182
parent 1088
09459f07ab11
equal deleted inserted replaced
1089:a3db51a94b37 1090:ab2e458df182
222 } UiColumn; 222 } UiColumn;
223 223
224 UiModel* ui_model(UiContext *ctx, ...) { 224 UiModel* ui_model(UiContext *ctx, ...) {
225 UiModel *info = ui_calloc(ctx, 1, sizeof(UiModel)); 225 UiModel *info = ui_calloc(ctx, 1, sizeof(UiModel));
226 info->ctx = ctx; 226 info->ctx = ctx;
227 info->ref = 1;
227 228
228 va_list ap; 229 va_list ap;
229 va_start(ap, ctx); 230 va_start(ap, ctx);
230 231
231 CxList *cols = cxArrayListCreate(cxDefaultAllocator, sizeof(UiColumn), 32); 232 CxList *cols = cxArrayListCreate(cxDefaultAllocator, sizeof(UiColumn), 32);
273 } 274 }
274 275
275 UiModel* ui_model_new(UiContext *ctx) { 276 UiModel* ui_model_new(UiContext *ctx) {
276 UiModel *info = ui_calloc(ctx, 1, sizeof(UiModel)); 277 UiModel *info = ui_calloc(ctx, 1, sizeof(UiModel));
277 info->ctx = ctx; 278 info->ctx = ctx;
279 info->ref = 1;
278 info->alloc = UI_MODEL_DEFAULT_ALLOC_SIZE; 280 info->alloc = UI_MODEL_DEFAULT_ALLOC_SIZE;
279 info->types = ui_calloc(ctx, UI_MODEL_DEFAULT_ALLOC_SIZE, sizeof(UiModelType)); 281 info->types = ui_calloc(ctx, UI_MODEL_DEFAULT_ALLOC_SIZE, sizeof(UiModelType));
280 info->titles = ui_calloc(ctx, UI_MODEL_DEFAULT_ALLOC_SIZE, sizeof(char*)); 282 info->titles = ui_calloc(ctx, UI_MODEL_DEFAULT_ALLOC_SIZE, sizeof(char*));
281 info->columnsize = ui_calloc(ctx, UI_MODEL_DEFAULT_ALLOC_SIZE, sizeof(int)); 283 info->columnsize = ui_calloc(ctx, UI_MODEL_DEFAULT_ALLOC_SIZE, sizeof(int));
282 return info; 284 return info;
369 } 371 }
370 } 372 }
371 373
372 void ui_model_free(UiModel *mi) { 374 void ui_model_free(UiModel *mi) {
373 UiContext *ctx = mi->ctx; 375 UiContext *ctx = mi->ctx;
374 const CxAllocator* a = ctx->allocator; 376 const CxAllocator* a = ctx ? ctx->allocator : cxDefaultAllocator;
375 for(int i=0;i<mi->columns;i++) { 377 for(int i=0;i<mi->columns;i++) {
376 ui_free(ctx, mi->titles[i]); 378 ui_free(ctx, mi->titles[i]);
377 } 379 }
378 UiModelChangeObserver *obs = mi->observer; 380 UiModelChangeObserver *obs = mi->observer;
379 while(obs) { 381 while(obs) {

mercurial