ui/common/context.c

changeset 56
294d5515583a
parent 52
0c881944fa10
equal deleted inserted replaced
55:1ce14068ef31 56:294d5515583a
521 uic_add_group_widget(ctx, widget, enable, groups); 521 uic_add_group_widget(ctx, widget, enable, groups);
522 522
523 cxListDestroy(groups); 523 cxListDestroy(groups);
524 } 524 }
525 525
526 size_t uic_group_array_size(const int *groups) {
527 int i;
528 for(i=0;groups[i] >= 0;i++) { }
529 return i;
530 }
531
526 void uic_add_group_widget(UiContext *ctx, void *widget, ui_enablefunc enable, CxList *groups) { 532 void uic_add_group_widget(UiContext *ctx, void *widget, ui_enablefunc enable, CxList *groups) {
533 uic_add_group_widget_i(ctx, widget, enable, cxListAt(groups, 0), cxListSize(groups));
534 }
535
536 void uic_add_group_widget_i(UiContext *ctx, void *widget, ui_enablefunc enable, const int *groups, size_t numgroups) {
527 const CxAllocator *a = ctx->allocator; 537 const CxAllocator *a = ctx->allocator;
528 UiGroupWidget gw; 538 UiGroupWidget gw;
529 539
530 gw.widget = widget; 540 gw.widget = widget;
531 gw.enable = enable; 541 gw.enable = enable;
532 gw.numgroups = cxListSize(groups); 542 gw.numgroups = numgroups;
533 gw.groups = cxCalloc(a, gw.numgroups, sizeof(int)); 543 gw.groups = cxCalloc(a, numgroups, sizeof(int));
534 544
535 // copy groups 545 // copy groups
536 int *intgroups = cxListAt(groups, 0); 546 if(groups) {
537 if(intgroups) { 547 memcpy(gw.groups, groups, gw.numgroups * sizeof(int));
538 memcpy(gw.groups, intgroups, gw.numgroups * sizeof(int));
539 } 548 }
540 549
541 cxListAdd(ctx->group_widgets, &gw); 550 cxListAdd(ctx->group_widgets, &gw);
542 } 551 }
543 552
552 void* ui_calloc(UiContext *ctx, size_t nelem, size_t elsize) { 561 void* ui_calloc(UiContext *ctx, size_t nelem, size_t elsize) {
553 return ctx ? cxCalloc(ctx->allocator, nelem, elsize) : NULL; 562 return ctx ? cxCalloc(ctx->allocator, nelem, elsize) : NULL;
554 } 563 }
555 564
556 void ui_free(UiContext *ctx, void *ptr) { 565 void ui_free(UiContext *ctx, void *ptr) {
557 if(ctx) { 566 if(ctx && ptr) {
558 cxFree(ctx->allocator, ptr); 567 cxFree(ctx->allocator, ptr);
559 } 568 }
560 } 569 }
561 570
562 void* ui_realloc(UiContext *ctx, void *ptr, size_t size) { 571 void* ui_realloc(UiContext *ctx, void *ptr, size_t size) {

mercurial