ui/common/context.c

changeset 2
ea89bbb0c4c8
parent 0
804d8803eade
child 3
c04433993fbb
--- a/ui/common/context.c	Wed Dec 09 11:33:00 2020 +0100
+++ b/ui/common/context.c	Thu Dec 10 13:43:25 2020 +0100
@@ -36,6 +36,16 @@
 #include "document.h"
 #include "types.h"
 
+static UiContext* global_context;
+
+void uic_init_global_context(void) {
+    UcxMempool *mp = ucx_mempool_new(32);
+    global_context = uic_context(NULL, mp);
+}
+
+UiContext* ui_global_context(void) {
+    return global_context;
+}
 
 UiContext* uic_context(UiObject *toplevel, UcxMempool *mp) {
     UiContext *ctx = ucx_mempool_malloc(mp, sizeof(UiContext));
@@ -48,7 +58,7 @@
     ctx->detach_document2 = uic_context_detach_document2;
     
 #ifdef UI_GTK
-    if(toplevel->widget) {
+    if(toplevel && toplevel->widget) {
         ctx->accel_group = gtk_accel_group_new();
         gtk_window_add_accel_group(GTK_WINDOW(toplevel->widget), ctx->accel_group);
     }
@@ -156,12 +166,12 @@
     return var;
 }
 
-UiVar* uic_get_var(UiContext *ctx, char *name) {
+UiVar* uic_get_var(UiContext *ctx, const char *name) {
     UcxKey key = ucx_key(name, strlen(name));
     return ctx_getvar(ctx, key);
 }
 
-UiVar* uic_create_var(UiContext *ctx, char *name, UiVarType type) {
+UiVar* uic_create_var(UiContext *ctx, const char *name, UiVarType type) {
     UiVar *var = uic_get_var(ctx, name);
     if(var) {
         if(var->type == type) {

mercurial