Wed, 09 Dec 2020 11:33:00 +0100
add .hgignore
0
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2017 Olaf Wintermann. All rights reserved. |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include <stdio.h> |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | #include <stdlib.h> |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | #include <string.h> |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | #include <inttypes.h> |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | #include "context.h" |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | #include "../ui/window.h" |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | #include "document.h" |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | #include "types.h" |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | UiContext* uic_context(UiObject *toplevel, UcxMempool *mp) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | UiContext *ctx = ucx_mempool_malloc(mp, sizeof(UiContext)); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | memset(ctx, 0, sizeof(UiContext)); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | ctx->mempool = mp; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | ctx->obj = toplevel; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | ctx->vars = ucx_map_new_a(mp->allocator, 16); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | ctx->attach_document = uic_context_attach_document; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | ctx->detach_document2 = uic_context_detach_document2; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | #ifdef UI_GTK |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | if(toplevel->widget) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | ctx->accel_group = gtk_accel_group_new(); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | gtk_window_add_accel_group(GTK_WINDOW(toplevel->widget), ctx->accel_group); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | #endif |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | return ctx; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | UiContext* uic_root_context(UiContext *ctx) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | return ctx->parent ? uic_root_context(ctx->parent) : ctx; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | void uic_context_attach_document(UiContext *ctx, void *document) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | ctx->documents = ucx_list_append_a(ctx->mempool->allocator, ctx->documents, document); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | ctx->document = ctx->documents->data; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | UiContext *doc_ctx = ui_document_context(document); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | // check if any parent context has an unbound variable with the same name |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | // as any document variable |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | UiContext *var_ctx = ctx; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | while(var_ctx) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | if(var_ctx->vars_unbound && var_ctx->vars_unbound->count > 0) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | UcxMapIterator i = ucx_map_iterator(var_ctx->vars_unbound); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | UiVar *var; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | // rmkeys holds all keys, that shall be removed from vars_unbound |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | UcxKey *rmkeys = calloc(var_ctx->vars_unbound->count, sizeof(UcxKey)); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | size_t numkeys = 0; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | UCX_MAP_FOREACH(key, var, i) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | UiVar *docvar = ucx_map_get(doc_ctx->vars, key); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | if(docvar) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | // bind var to document var |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | uic_copy_binding(var, docvar, TRUE); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | rmkeys[numkeys++] = key; // save the key for removal |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | // now that we may have bound some vars to the document, |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | // we can remove them from the unbound map |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | for(size_t k=0;k<numkeys;k++) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | ucx_map_remove(var_ctx->vars_unbound, rmkeys[k]); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | var_ctx = ctx->parent; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | static void uic_context_unbind_vars(UiContext *ctx) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | UcxMapIterator i = ucx_map_iterator(ctx->vars); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | UiVar *var; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | UCX_MAP_FOREACH(key, var, i) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | if(var->from && var->from_ctx) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | uic_save_var2(var); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | uic_copy_binding(var, var->from, FALSE); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | ucx_map_put(var->from_ctx->vars_unbound, key, var->from); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | var->from_ctx = ctx; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | UCX_FOREACH(elm, ctx->documents) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | UiContext *subctx = ui_document_context(elm->data); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | uic_context_unbind_vars(subctx); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | void uic_context_detach_document2(UiContext *ctx, void *document) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | // find the document in the documents list |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | UcxList *doc = NULL; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | UCX_FOREACH(elm, ctx->documents) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | if(elm->data == document) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | doc = elm; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | if(!doc) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | return; // document is not a subdocument of this context |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | ctx->documents = ucx_list_remove_a(ctx->mempool->allocator, ctx->documents, doc); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | ctx->document = ctx->documents ? ctx->documents->data : NULL; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | UiContext *docctx = ui_document_context(document); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | uic_context_unbind_vars(docctx); // unbind all doc/subdoc vars from the parent |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
136 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | void uic_context_detach_all(UiContext *ctx) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | UcxList *ls = ucx_list_clone(ctx->documents, NULL, NULL); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | UCX_FOREACH(elm, ls) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | ctx->detach_document2(ctx, elm->data); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | ucx_list_free(ls); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | static UiVar* ctx_getvar(UiContext *ctx, UcxKey key) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | UiVar *var = ucx_map_get(ctx->vars, key); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | if(!var) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | UCX_FOREACH(elm, ctx->documents) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | UiContext *subctx = ui_document_context(elm->data); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | var = ctx_getvar(subctx, key); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151 | if(var) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | return var; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | UiVar* uic_get_var(UiContext *ctx, char *name) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | UcxKey key = ucx_key(name, strlen(name)); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | return ctx_getvar(ctx, key); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | UiVar* uic_create_var(UiContext *ctx, char *name, UiVarType type) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | UiVar *var = uic_get_var(ctx, name); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | if(var) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | if(var->type == type) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | return var; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | } else { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | fprintf(stderr, "UiError: var '%s' already bound with different type\n", name); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | var = ui_malloc(ctx, sizeof(UiVar)); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | var->type = type; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | var->value = uic_create_value(ctx, type); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | var->from = NULL; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | var->from_ctx = ctx; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | if(!ctx->vars_unbound) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | ctx->vars_unbound = ucx_map_new_a(ctx->mempool->allocator, 16); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | ucx_map_cstr_put(ctx->vars_unbound, name, var); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | return var; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | void* uic_create_value(UiContext *ctx, UiVarType type) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | void *val = NULL; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | switch(type) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | case UI_VAR_SPECIAL: break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | case UI_VAR_INTEGER: { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193 | val = ui_int_new(ctx, NULL); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | case UI_VAR_DOUBLE: { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | val = ui_double_new(ctx, NULL); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | case UI_VAR_STRING: { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | val = ui_string_new(ctx, NULL); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | case UI_VAR_TEXT: { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | val = ui_text_new(ctx, NULL); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | case UI_VAR_LIST: { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | val = ui_list_new(ctx, NULL); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210 | break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | case UI_VAR_RANGE: { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | val = ui_range_new(ctx, NULL); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | return val; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
220 | void uic_copy_binding(UiVar *from, UiVar *to, UiBool copytodoc) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
221 | // check type |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
222 | if(from->type != to->type) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
223 | fprintf(stderr, "UI Error: var has incompatible type.\n"); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
224 | return; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
225 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
226 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
227 | void *fromvalue = from->value; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
228 | // update var |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
229 | if(copytodoc) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
230 | to->from = from; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
231 | to->from_ctx = from->from_ctx; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
232 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
233 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
234 | // copy binding |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
235 | // we don't copy the observer, because the from var has never one |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
236 | switch(from->type) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
237 | default: fprintf(stderr, "uic_copy_binding: wtf!\n"); break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
238 | case UI_VAR_SPECIAL: break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
239 | case UI_VAR_INTEGER: { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
240 | UiInteger *f = fromvalue; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
241 | UiInteger *t = to->value; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
242 | if(!f->obj) break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
243 | uic_int_copy(f, t); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
244 | t->set(t, t->value); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
245 | break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
246 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247 | case UI_VAR_DOUBLE: { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
248 | UiDouble *f = fromvalue; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
249 | UiDouble *t = to->value; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
250 | if(!f->obj) break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
251 | uic_double_copy(f, t); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
252 | t->set(t, t->value); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
253 | break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
254 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
255 | case UI_VAR_STRING: { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
256 | UiString *f = fromvalue; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
257 | UiString *t = to->value; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
258 | if(!f->obj) break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
259 | uic_string_copy(f, t); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
260 | char *tvalue = t->value.ptr ? t->value.ptr : ""; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
261 | t->set(t, tvalue); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
262 | break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
263 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
264 | case UI_VAR_TEXT: { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
265 | UiText *f = fromvalue; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
266 | UiText *t = to->value; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
267 | if(!f->obj) break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
268 | uic_text_copy(f, t); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
269 | char *tvalue = t->value.ptr ? t->value.ptr : ""; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
270 | t->set(t, tvalue); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
271 | t->setposition(t, t->pos); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
272 | break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
273 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
274 | case UI_VAR_LIST: { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
275 | UiList *f = fromvalue; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
276 | UiList *t = to->value; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
277 | if(!f->obj) break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
278 | uic_list_copy(f, t); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
279 | t->update(t, -1); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
280 | break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
281 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
282 | case UI_VAR_RANGE: { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
283 | UiRange *f = fromvalue; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
284 | UiRange *t = to->value; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
285 | if(!f->obj) break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
286 | uic_range_copy(f, t); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
287 | t->setextent(t, t->extent); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
288 | t->setrange(t, t->min, t->max); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
289 | t->set(t, t->value); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
290 | break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
291 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
292 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
293 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
294 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
295 | void uic_save_var2(UiVar *var) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
296 | switch(var->type) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
297 | case UI_VAR_SPECIAL: break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
298 | case UI_VAR_INTEGER: uic_int_save(var->value); break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
299 | case UI_VAR_DOUBLE: uic_double_save(var->value); break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
300 | case UI_VAR_STRING: uic_string_save(var->value); break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
301 | case UI_VAR_TEXT: uic_text_save(var->value); break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
302 | case UI_VAR_LIST: break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
303 | case UI_VAR_RANGE: uic_range_save(var->value); break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
304 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
305 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
306 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
307 | void uic_unbind_var(UiVar *var) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
308 | switch(var->type) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
309 | case UI_VAR_SPECIAL: break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
310 | case UI_VAR_INTEGER: uic_int_unbind(var->value); break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
311 | case UI_VAR_DOUBLE: uic_double_unbind(var->value); break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
312 | case UI_VAR_STRING: uic_string_unbind(var->value); break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
313 | case UI_VAR_TEXT: uic_text_unbind(var->value); break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
314 | case UI_VAR_LIST: uic_list_unbind(var->value); break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
315 | case UI_VAR_RANGE: uic_range_unbind(var->value); break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
316 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
317 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
318 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
319 | void uic_reg_var(UiContext *ctx, char *name, UiVarType type, void *value) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
320 | // TODO: do we need/want this? Why adding vars to a context after |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
321 | // widgets reference these? Workarounds: |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
322 | // 1. add vars to ctx before creating ui |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
323 | // 2. create ui, create new document with vars, attach doc |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
324 | // also it would be possible to create a function, that scans unbound vars |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
325 | // and connects them to available vars |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
326 | /* |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
327 | UiContext *rootctx = uic_root_context(ctx); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
328 | UiVar *b = NULL; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
329 | if(rootctx->bound) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
330 | // some widgets are already bound to some vars |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
331 | b = ucx_map_cstr_get(rootctx->bound, name); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
332 | if(b) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
333 | // a widget is bound to a var with this name |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
334 | // if ctx is the root context we can remove the var from bound |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
335 | // because set_doc or detach can't fuck things up |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
336 | if(ctx == rootctx) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
337 | ucx_map_cstr_remove(ctx->bound, name); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
338 | // TODO: free stuff |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
339 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
340 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
341 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
342 | */ |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
343 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
344 | // create new var and add it to doc's vars |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
345 | UiVar *var = ui_malloc(ctx, sizeof(UiVar)); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
346 | var->type = type; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
347 | var->value = value; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
348 | var->from = NULL; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
349 | var->from_ctx = ctx; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
350 | size_t oldcount = ctx->vars->count; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
351 | ucx_map_cstr_put(ctx->vars, name, var); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
352 | if(ctx->vars->count != oldcount + 1) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
353 | fprintf(stderr, "UiError: var '%s' already exists\n", name); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
354 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
355 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
356 | // TODO: remove? |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
357 | // a widget is already bound to a var with this name |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
358 | // copy the binding (like uic_context_set_document) |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
359 | /* |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
360 | if(b) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
361 | uic_copy_binding(b, var, TRUE); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
362 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
363 | */ |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
364 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
365 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
366 | void uic_remove_bound_var(UiContext *ctx, UiVar *var) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
367 | // TODO: implement |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
368 | printf("TODO: implement uic_remove_bound_var\n"); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
369 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
370 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
371 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
372 | // public API |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
373 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
374 | void ui_attach_document(UiContext *ctx, void *document) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
375 | uic_context_attach_document(ctx, document); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
376 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
377 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
378 | void ui_detach_document2(UiContext *ctx, void *document) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
379 | uic_context_detach_document2(ctx, document); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
380 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
381 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
382 | void ui_context_closefunc(UiContext *ctx, ui_callback fnc, void *udata) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
383 | ctx->close_callback = fnc; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
384 | ctx->close_data = udata; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
385 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
386 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
387 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
388 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
389 | void ui_set_group(UiContext *ctx, int group) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
390 | if(ucx_list_find(ctx->groups, (void*)(intptr_t)group, NULL, NULL) == -1) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
391 | ctx->groups = ucx_list_append_a(ctx->mempool->allocator, ctx->groups, (void*)(intptr_t)group); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
392 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
393 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
394 | // enable/disable group widgets |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
395 | uic_check_group_widgets(ctx); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
396 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
397 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
398 | void ui_unset_group(UiContext *ctx, int group) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
399 | int i = ucx_list_find(ctx->groups, (void*)(intptr_t)group, NULL, NULL); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
400 | if(i != -1) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
401 | UcxList *elm = ucx_list_get(ctx->groups, i); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
402 | ctx->groups = ucx_list_remove_a(ctx->mempool->allocator, ctx->groups, elm); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
403 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
404 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
405 | // enable/disable group widgets |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
406 | uic_check_group_widgets(ctx); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
407 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
408 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
409 | int* ui_active_groups(UiContext *ctx, int *ngroups) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
410 | if(!ctx->groups) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
411 | return NULL; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
412 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
413 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
414 | int nelm = ucx_list_size(ctx->groups); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
415 | int *groups = calloc(sizeof(int), nelm); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
416 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
417 | int i = 0; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
418 | UCX_FOREACH(elm, ctx->groups) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
419 | groups[i++] = (intptr_t)elm->data; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
420 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
421 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
422 | *ngroups = nelm; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
423 | return groups; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
424 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
425 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
426 | void uic_check_group_widgets(UiContext *ctx) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
427 | int ngroups = 0; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
428 | int *groups = ui_active_groups(ctx, &ngroups); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
429 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
430 | UCX_FOREACH(elm, ctx->group_widgets) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
431 | UiGroupWidget *gw = elm->data; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
432 | char *check = calloc(1, gw->numgroups); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
433 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
434 | for(int i=0;i<ngroups;i++) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
435 | for(int k=0;k<gw->numgroups;k++) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
436 | if(groups[i] == gw->groups[k]) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
437 | check[k] = 1; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
438 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
439 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
440 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
441 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
442 | int enable = 1; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
443 | for(int i=0;i<gw->numgroups;i++) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
444 | if(check[i] == 0) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
445 | enable = 0; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
446 | break; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
447 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
448 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
449 | ui_set_enabled(gw->widget, enable); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
450 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
451 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
452 | if(groups) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
453 | free(groups); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
454 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
455 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
456 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
457 | void uic_add_group_widget(UiContext *ctx, void *widget, UcxList *groups) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
458 | UcxMempool *mp = ctx->mempool; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
459 | UiGroupWidget *gw = ucx_mempool_malloc(mp, sizeof(UiGroupWidget)); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
460 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
461 | gw->widget = widget; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
462 | gw->numgroups = ucx_list_size(groups); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
463 | gw->groups = ucx_mempool_calloc(mp, gw->numgroups, sizeof(int)); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
464 | int i = 0; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
465 | UCX_FOREACH(elm, groups) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
466 | gw->groups[i++] = (intptr_t)elm->data; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
467 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
468 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
469 | ctx->group_widgets = ucx_list_append_a( |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
470 | mp->allocator, |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
471 | ctx->group_widgets, |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
472 | gw); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
473 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
474 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
475 | void* ui_malloc(UiContext *ctx, size_t size) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
476 | return ctx ? ucx_mempool_malloc(ctx->mempool, size) : NULL; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
477 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
478 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
479 | void* ui_calloc(UiContext *ctx, size_t nelem, size_t elsize) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
480 | return ctx ? ucx_mempool_calloc(ctx->mempool, nelem, elsize) : NULL; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
481 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
482 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
483 | void ui_free(UiContext *ctx, void *ptr) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
484 | if(ctx) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
485 | ucx_mempool_free(ctx->mempool, ptr); |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
486 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
487 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
488 | |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
489 | void* ui_realloc(UiContext *ctx, void *ptr, size_t size) { |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
490 | return ctx ? ucx_mempool_realloc(ctx->mempool, ptr, size) : NULL; |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
491 | } |
804d8803eade
add existing toolkit source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
492 |