ui/common/context.c

changeset 1016
ccde46662db7
parent 976
e2763e880938
equal deleted inserted replaced
1015:b459361d98ad 1016:ccde46662db7
57 UiContext* uic_context(UiObject *toplevel, CxMempool *mp) { 57 UiContext* uic_context(UiObject *toplevel, CxMempool *mp) {
58 UiContext *ctx = cxMalloc(mp->allocator, sizeof(UiContext)); 58 UiContext *ctx = cxMalloc(mp->allocator, sizeof(UiContext));
59 memset(ctx, 0, sizeof(UiContext)); 59 memset(ctx, 0, sizeof(UiContext));
60 ctx->mp = mp; 60 ctx->mp = mp;
61 ctx->allocator = mp->allocator; 61 ctx->allocator = mp->allocator;
62 ctx->destroy_handler = cxArrayListCreate(ctx->allocator, NULL, sizeof(UiDestroyHandler), 16); 62 ctx->destroy_handler = cxArrayListCreate(ctx->allocator, sizeof(UiDestroyHandler), 16);
63 ctx->obj = toplevel; 63 ctx->obj = toplevel;
64 ctx->vars = cxHashMapCreate(mp->allocator, CX_STORE_POINTERS, 16); 64 ctx->vars = cxHashMapCreate(mp->allocator, CX_STORE_POINTERS, 16);
65 65
66 ctx->documents = cxLinkedListCreate(mp->allocator, cx_cmp_ptr, CX_STORE_POINTERS); 66 ctx->documents = cxLinkedListCreate(mp->allocator, CX_STORE_POINTERS);
67 ctx->state_widgets = cxLinkedListCreate(mp->allocator, cx_cmp_ptr, sizeof(UiStateWidget)); 67 ctx->state_widgets = cxLinkedListCreate(mp->allocator, sizeof(UiStateWidget));
68 ctx->states = cxArrayListCreate(mp->allocator, cx_cmp_int, sizeof(int), 32); 68 ctx->states = cxArrayListCreate(mp->allocator, sizeof(int), 32);
69 cxSetCompareFunc(ctx->states, cx_cmp_int);
69 70
70 ctx->attach_document = uic_context_attach_document; 71 ctx->attach_document = uic_context_attach_document;
71 ctx->detach_document2 = uic_context_detach_document; 72 ctx->detach_document2 = uic_context_detach_document;
72 73
73 #if UI_GTK2 || UI_GTK3 74 #if UI_GTK2 || UI_GTK3
171 docctx->parent = NULL; 172 docctx->parent = NULL;
172 } 173 }
173 174
174 void uic_context_detach_all(UiContext *ctx) { 175 void uic_context_detach_all(UiContext *ctx) {
175 // copy list 176 // copy list
176 CxList *ls = cxLinkedListCreate(cxDefaultAllocator, NULL, CX_STORE_POINTERS); 177 CxList *ls = cxLinkedListCreate(cxDefaultAllocator, CX_STORE_POINTERS);
177 CxIterator i = cxListIterator(ctx->documents); 178 CxIterator i = cxListIterator(ctx->documents);
178 cx_foreach(void *, doc, i) { 179 cx_foreach(void *, doc, i) {
179 cxListAdd(ls, doc); 180 cxListAdd(ls, doc);
180 } 181 }
181 182
588 void ui_widget_set_states(UiContext *ctx, UIWIDGET widget, ui_enablefunc enable, ...) { 589 void ui_widget_set_states(UiContext *ctx, UIWIDGET widget, ui_enablefunc enable, ...) {
589 if(enable == NULL) { 590 if(enable == NULL) {
590 enable = (ui_enablefunc)ui_set_enabled; 591 enable = (ui_enablefunc)ui_set_enabled;
591 } 592 }
592 // get states 593 // get states
593 CxList *states = cxArrayListCreate(cxDefaultAllocator, NULL, sizeof(int), 16); 594 CxList *states = cxArrayListCreate(cxDefaultAllocator, sizeof(int), 16);
594 va_list ap; 595 va_list ap;
595 va_start(ap, enable); 596 va_start(ap, enable);
596 int state; 597 int state;
597 while((state = va_arg(ap, int)) != -1) { 598 while((state = va_arg(ap, int)) != -1) {
598 cxListAdd(states, &state); 599 cxListAdd(states, &state);
606 607
607 void ui_widget_set_states2(UiContext *ctx, UIWIDGET widget, ui_enablefunc enable, const int *states, int nstates) { 608 void ui_widget_set_states2(UiContext *ctx, UIWIDGET widget, ui_enablefunc enable, const int *states, int nstates) {
608 if(enable == NULL) { 609 if(enable == NULL) {
609 enable = (ui_enablefunc)ui_set_enabled; 610 enable = (ui_enablefunc)ui_set_enabled;
610 } 611 }
611 CxList *ls = cxArrayListCreate(cxDefaultAllocator, NULL, sizeof(int), nstates); 612 CxList *ls = cxArrayListCreate(cxDefaultAllocator, sizeof(int), nstates);
612 for(int i=0;i<nstates;i++) { 613 for(int i=0;i<nstates;i++) {
613 cxListAdd(ls, states+i); 614 cxListAdd(ls, states+i);
614 } 615 }
615 uic_add_state_widget(ctx, widget, enable, ls); 616 uic_add_state_widget(ctx, widget, enable, ls);
616 cxListFree(ls); 617 cxListFree(ls);

mercurial