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