34 #include "context.h" |
34 #include "context.h" |
35 #include "../ui/window.h" |
35 #include "../ui/window.h" |
36 #include "document.h" |
36 #include "document.h" |
37 #include "types.h" |
37 #include "types.h" |
38 |
38 |
|
39 static UiContext* global_context; |
|
40 |
|
41 void uic_init_global_context(void) { |
|
42 UcxMempool *mp = ucx_mempool_new(32); |
|
43 global_context = uic_context(NULL, mp); |
|
44 } |
|
45 |
|
46 UiContext* ui_global_context(void) { |
|
47 return global_context; |
|
48 } |
39 |
49 |
40 UiContext* uic_context(UiObject *toplevel, UcxMempool *mp) { |
50 UiContext* uic_context(UiObject *toplevel, UcxMempool *mp) { |
41 UiContext *ctx = ucx_mempool_malloc(mp, sizeof(UiContext)); |
51 UiContext *ctx = ucx_mempool_malloc(mp, sizeof(UiContext)); |
42 memset(ctx, 0, sizeof(UiContext)); |
52 memset(ctx, 0, sizeof(UiContext)); |
43 ctx->mempool = mp; |
53 ctx->mempool = mp; |
46 |
56 |
47 ctx->attach_document = uic_context_attach_document; |
57 ctx->attach_document = uic_context_attach_document; |
48 ctx->detach_document2 = uic_context_detach_document2; |
58 ctx->detach_document2 = uic_context_detach_document2; |
49 |
59 |
50 #ifdef UI_GTK |
60 #ifdef UI_GTK |
51 if(toplevel->widget) { |
61 if(toplevel && toplevel->widget) { |
52 ctx->accel_group = gtk_accel_group_new(); |
62 ctx->accel_group = gtk_accel_group_new(); |
53 gtk_window_add_accel_group(GTK_WINDOW(toplevel->widget), ctx->accel_group); |
63 gtk_window_add_accel_group(GTK_WINDOW(toplevel->widget), ctx->accel_group); |
54 } |
64 } |
55 #endif |
65 #endif |
56 |
66 |
154 } |
164 } |
155 } |
165 } |
156 return var; |
166 return var; |
157 } |
167 } |
158 |
168 |
159 UiVar* uic_get_var(UiContext *ctx, char *name) { |
169 UiVar* uic_get_var(UiContext *ctx, const char *name) { |
160 UcxKey key = ucx_key(name, strlen(name)); |
170 UcxKey key = ucx_key(name, strlen(name)); |
161 return ctx_getvar(ctx, key); |
171 return ctx_getvar(ctx, key); |
162 } |
172 } |
163 |
173 |
164 UiVar* uic_create_var(UiContext *ctx, char *name, UiVarType type) { |
174 UiVar* uic_create_var(UiContext *ctx, const char *name, UiVarType type) { |
165 UiVar *var = uic_get_var(ctx, name); |
175 UiVar *var = uic_get_var(ctx, name); |
166 if(var) { |
176 if(var) { |
167 if(var->type == type) { |
177 if(var->type == type) { |
168 return var; |
178 return var; |
169 } else { |
179 } else { |