Sun, 08 Dec 2013 11:20:41 +0000
added some document functions
application/Makefile | file | annotate | diff | comparison | revisions | |
application/main.c | file | annotate | diff | comparison | revisions | |
ui/common/context.c | file | annotate | diff | comparison | revisions | |
ui/common/context.h | file | annotate | diff | comparison | revisions | |
ui/common/document.c | file | annotate | diff | comparison | revisions | |
ui/common/document.h | file | annotate | diff | comparison | revisions | |
ui/common/objs.mk | file | annotate | diff | comparison | revisions | |
ui/gtk/toolkit.c | file | annotate | diff | comparison | revisions | |
ui/motif/toolkit.c | file | annotate | diff | comparison | revisions | |
ui/ui/toolkit.h | file | annotate | diff | comparison | revisions |
--- a/application/Makefile Sat Dec 07 12:14:59 2013 +0100 +++ b/application/Makefile Sun Dec 08 11:20:41 2013 +0000 @@ -37,7 +37,7 @@ all: ../build/bin/mk12 -../build/bin/mk12: $(OBJ) +../build/bin/mk12: $(OBJ) $(BUILD_ROOT)/build/lib/libuitk.a $(LD) -o ../build/bin/mk12$(APP_EXT) $(OBJ) -L$(BUILD_ROOT)/build/lib -luitk -lucx $(LDFLAGS) ../build/application/%.$(OBJ_EXT): %.c
--- a/application/main.c Sat Dec 07 12:14:59 2013 +0100 +++ b/application/main.c Sun Dec 08 11:20:41 2013 +0000 @@ -58,6 +58,9 @@ ui_menuitem("Close", action_close, NULL); UiObject *window = ui_window("Mod0", NULL); + + + //ui_window_addint(window, "check1"); ui_show(window); ui_main();
--- a/ui/common/context.c Sat Dec 07 12:14:59 2013 +0100 +++ b/ui/common/context.c Sun Dec 08 11:20:41 2013 +0000 @@ -33,9 +33,6 @@ #include "context.h" #include "../ui/window.h" -void uic_docmgr_init() { - -} UiContext* uic_context(UiObject *toplevel, UcxMempool *mp) { UiContext *ctx = ucx_mempool_malloc(mp, sizeof(UiContext)); @@ -50,14 +47,22 @@ } UiVar* uic_getvar(UiObject *obj, char *name) { + if(!obj) { + return NULL; + } return ucx_map_cstr_get(obj->ctx->vars, name); } -UiVar* uic_addplaceholder(UiObject *obj, char *name) { - UiVar *var = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiVar)); - var->type = -1; - var->value = NULL; - ucx_map_cstr_put(obj->ctx->vars, name, var); +void uic_rmvar(UiObject *obj, char *name) { + if(obj) { + UiVar *var = uic_getvar(obj, name); + if(var) { + if(var->isextern) { + ucx_mempool_free(obj->ctx->mempool, var->value); + } + ucx_mempool_free(obj->ctx->mempool, var); + } + } } void ui_window_addint(UiObject *obj, char *name) { @@ -66,7 +71,11 @@ return; } UiInteger *i = ucx_mempool_calloc(obj->ctx->mempool, 1, sizeof(UiInteger)); - ui_window_regint(obj, name, i); + UiVar *var = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiVar)); + var->value = i; + var->type = 1; + var->isextern = 0; + ucx_map_cstr_put(obj->ctx->vars, name, var); } void ui_window_regint(UiObject *obj, char *name, UiInteger *i) { @@ -77,6 +86,7 @@ UiVar *var = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiVar)); var->value = i; var->type = 1; + var->isextern = 1; ucx_map_cstr_put(obj->ctx->vars, name, var); }
--- a/ui/common/context.h Sat Dec 07 12:14:59 2013 +0100 +++ b/ui/common/context.h Sun Dec 08 11:20:41 2013 +0000 @@ -37,8 +37,7 @@ extern "C" { #endif -typedef struct UiDocument UiDocument; -typedef struct UiVar UiVar; +typedef struct UiVar UiVar; struct UiContext { UiObject *toplevel; @@ -47,22 +46,16 @@ UcxMap *vars; // key: char* value: UiVar* }; -struct UiDocument { - UcxMempool *mempool; - UcxAllocator *allocator; - UcxMap *vars; // key: char* value: UiVar* -}; - struct UiVar { void *value; int type; + int isextern; }; -void uic_docmgr_init(); UiContext* uic_context(UiObject *toplevel, UcxMempool *mp); UiVar* uic_getvar(UiObject *obj, char *name); -UiVar* uic_addplaceholder(UiObject *obj, char *name); +void uic_rmvar(UiObject *obj, char *name); #ifdef __cplusplus
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/common/document.c Sun Dec 08 11:20:41 2013 +0000 @@ -0,0 +1,117 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2014 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "document.h" + +static UcxMap *documents; + +void uic_docmgr_init() { + documents = ucx_map_new(32); +} + +void* ui_document_create(UiObject *obj, size_t size) { + UcxMempool *mp = ucx_mempool_new(256); + UiDocument *uidoc = ucx_mempool_malloc(mp, sizeof(UiDocument)); + uidoc->obj = obj; + uidoc->allocator = ucx_mempool_allocator(mp); + uidoc->mempool = mp; + uidoc->vars = ucx_map_new_a(uidoc->allocator, 16); + + void *document = ucx_mempool_calloc(mp, 1, size); + ucx_map_put(documents, ucx_key(&document, sizeof(void*)), uidoc); + return document; +} + +void ui_document_destroy(void *doc) { + // TODO +} + +void* ui_document_malloc(void *doc, size_t size) { + UiDocument *uidoc = ucx_map_get(documents, ucx_key(&doc, sizeof(void*))); + return ucx_mempool_malloc(uidoc->mempool, size); +} + +void* ui_document_calloc(void *doc, size_t nelem, size_t elsize) { + UiDocument *uidoc = ucx_map_get(documents, ucx_key(&doc, sizeof(void*))); + return ucx_mempool_calloc(uidoc->mempool, nelem, elsize); +} + +void ui_document_free(void *doc, void *ptr) { + UiDocument *uidoc = ucx_map_get(documents, ucx_key(&doc, sizeof(void*))); + ucx_mempool_free(uidoc->mempool, ptr); +} + +void* ui_document_realloc(void *doc, void *ptr, size_t size) { + UiDocument *uidoc = ucx_map_get(documents, ucx_key(&doc, sizeof(void*))); + return ucx_mempool_realloc(uidoc->mempool, ptr, size); +} + + +UiVar* uic_document_getvar(UiDocument *doc, char *name) { + return ucx_map_cstr_get(doc->vars, name); +} + +void ui_document_addint(void *doc, char *name) { + UiDocument *uidoc = ucx_map_get(documents, ucx_key(&doc, sizeof(void*))); + if(!uidoc) { + return; + } + + UiVar *dvar = uic_document_getvar(uidoc, name); + UiVar *wvar = uic_getvar(uidoc->obj, name); + if(!dvar) { + UiVar *var = ucx_mempool_malloc(uidoc->mempool, sizeof(UiVar)); + var->isextern = 0; + var->type = 1; + UiInteger *i = ucx_mempool_calloc(uidoc->mempool, 1, sizeof(UiVar)); + if(wvar && !wvar->isextern) { + *i = *(UiInteger*)wvar->value; + } + } + + if(wvar && wvar->isextern) { + fprintf(stderr, "UI Error: window variable moved to document!\n"); + } + uic_rmvar(uidoc->obj, name); +} + +void ui_document_regint(void *doc, char *name, UiInteger *i) { + +} + +void ui_document_setint(void *doc, char *name, int val) { + +} + +int ui_document_getint(void *doc, char *name) { + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/common/document.h Sun Dec 08 11:20:41 2013 +0000 @@ -0,0 +1,57 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2014 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef DOCUMENT_H +#define DOCUMENT_H + +#include "../ui/toolkit.h" +#include "context.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct UiDocument UiDocument; + +struct UiDocument { + UiObject *obj; + UcxMempool *mempool; + UcxAllocator *allocator; + UcxMap *vars; // key: char* value: UiVar* +}; + +void uic_docmgr_init(); +UiVar* uic_document_getvar(UiDocument *doc, char *name); + + +#ifdef __cplusplus +} +#endif + +#endif /* DOCUMENT_H */ +
--- a/ui/common/objs.mk Sat Dec 07 12:14:59 2013 +0100 +++ b/ui/common/objs.mk Sun Dec 08 11:20:41 2013 +0000 @@ -30,6 +30,7 @@ COMMON_OBJPRE = $(OBJ_DIR)$(COMMON_SRC_DIR) COMMON_OBJ = context.o +COMMON_OBJ += document.o #COMMON_OBJ = observer.o #COMMON_OBJ += list.o
--- a/ui/gtk/toolkit.c Sat Dec 07 12:14:59 2013 +0100 +++ b/ui/gtk/toolkit.c Sun Dec 08 11:20:41 2013 +0000 @@ -30,7 +30,7 @@ #include <stdlib.h> #include "toolkit.h" -#include "../common/context.h" +#include "../common/document.h" static char *application_name;
--- a/ui/motif/toolkit.c Sat Dec 07 12:14:59 2013 +0100 +++ b/ui/motif/toolkit.c Sun Dec 08 11:20:41 2013 +0000 @@ -30,7 +30,7 @@ #include <stdlib.h> #include "toolkit.h" -#include "../common/context.h" +#include "../common/document.h" static XtAppContext app; static Display *display;
--- a/ui/ui/toolkit.h Sat Dec 07 12:14:59 2013 +0100 +++ b/ui/ui/toolkit.h Sun Dec 08 11:20:41 2013 +0000 @@ -107,11 +107,19 @@ void ui_show(UiObject *obj); void* ui_document_create(UiObject *obj, size_t size); +void ui_document_destroy(void *doc); + void* ui_document_malloc(void *doc, size_t size); void* ui_document_calloc(void *doc, size_t nelem, size_t elsize); void ui_document_free(void *doc, void *ptr); void* ui_document_realloc(void *doc, void *ptr, size_t size); +void ui_document_addint(void *doc, char *name); +void ui_document_regint(void *doc, char *name, UiInteger *i); +void ui_document_setint(void *doc, char *name, int val); +int ui_document_getint(void *doc, char *name); + + #ifdef __cplusplus } #endif