Mon, 23 Jan 2017 10:50:22 +0100
adds drawingarea (WPF)
0 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
4 | * Copyright 2014 Olaf Wintermann. All rights reserved. | |
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> |
0 | 33 | |
34 | #include "context.h" | |
35 | #include "../ui/window.h" | |
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
36 | #include "document.h" |
0 | 37 | |
38 | ||
39 | UiContext* uic_context(UiObject *toplevel, UcxMempool *mp) { | |
40 | 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
|
41 | memset(ctx, 0, sizeof(UiContext)); |
0 | 42 | ctx->mempool = mp; |
37
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
43 | ctx->obj = toplevel; |
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
44 | ctx->vars = ucx_map_new_a(mp->allocator, 16); |
0 | 45 | |
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
46 | ctx->set_document = uic_context_set_document; |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
47 | ctx->detach_document = uic_context_detach_document; |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
48 | |
18
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
49 | #ifdef UI_GTK |
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
50 | if(toplevel->widget) { |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
51 | ctx->accel_group = gtk_accel_group_new(); |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
52 | 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
|
53 | } |
18
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
54 | #endif |
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
55 | |
0 | 56 | return ctx; |
57 | } | |
58 | ||
128
c284c15509a8
fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
59 | UiContext* uic_root_context(UiContext *ctx) { |
c284c15509a8
fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
60 | 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
|
61 | } |
c284c15509a8
fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
62 | |
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
63 | void uic_context_set_document(UiContext *ctx, void *document) { |
131
774b741984a2
detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
64 | if(ctx->document == document) { |
774b741984a2
detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
65 | return; |
774b741984a2
detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
66 | } |
774b741984a2
detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
67 | |
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
68 | UiContext *docctx = ui_document_context(document); |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
69 | if(!docctx) { |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
70 | return; |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
71 | } |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
72 | docctx->obj = ctx->obj; |
128
c284c15509a8
fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
73 | docctx->parent = ctx; |
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
74 | |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
75 | if(ctx->document) { |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
76 | uic_context_detach_document(ctx, ctx->document); |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
77 | } |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
78 | //obj->document = document; |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
79 | ctx->document = document; |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
80 | |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
81 | UcxMapIterator i = ucx_map_iterator(docctx->vars); |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
82 | UiVar *var; |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
83 | UCX_MAP_FOREACH(key, var, i) { |
128
c284c15509a8
fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
84 | UiVar *v = ucx_map_get(uic_root_context(ctx)->vars, key); |
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
85 | if(v) { |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
86 | if(v->isextern) { |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
87 | fprintf( |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
88 | stderr, |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
89 | "UI Error: external variable cannot be moved\n"); |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
90 | return; |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
91 | } |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
92 | // check type |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
93 | if(var->type != v->type) { |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
94 | fprintf(stderr, "UI Error: var has incompatible type.\n"); |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
95 | return; |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
96 | } |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
97 | |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
98 | // copy value |
128
c284c15509a8
fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
99 | uic_move_var(v, var, TRUE); |
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
100 | var->from = v->from; |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
101 | |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
102 | // TODO: free var struct |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
103 | ucx_map_remove(ctx->vars, key); |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
104 | } |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
105 | } |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
106 | } |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
107 | |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
108 | void uic_context_detach_document(UiContext *ctx, void *document) { |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
109 | UiContext *docctx = ui_document_context(document); |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
110 | if(!docctx) { |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
111 | fprintf( |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
112 | stderr, |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
113 | "UiError: ui_detach_document: document is not registered\n"); |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
114 | return; |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
115 | } |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
116 | if(ctx->document != document) { |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
117 | fprintf(stderr, "UiError: ui_detach_document: wrong document\n"); |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
118 | return; |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
119 | } |
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 | UcxMapIterator i = ucx_map_iterator(docctx->vars); |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
122 | UiVar *var; |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
123 | UCX_MAP_FOREACH(key, var, i) { |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
124 | if(var->from && var->from != docctx->vars) { |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
125 | // this var is bind to an outer widget, so we move it |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
126 | UcxAllocator *a = var->from->allocator; |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
127 | UiVar *newvar = a->malloc(a->pool, sizeof(UiVar)); |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
128 | newvar->value = uic_create_value(a, var->type); |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
129 | uic_move_var(var, newvar, 0); |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
130 | newvar->type = var->type; |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
131 | newvar->from = var->from; |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
132 | newvar->isextern = 0; |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
133 | |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
134 | ucx_map_put(var->from, key, newvar); |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
135 | |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
136 | //ucx_map_remove(doc->vars, key); // TODO: dont remove! |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
137 | } |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
138 | } |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
139 | |
128
c284c15509a8
fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
140 | if(docctx->parent) { |
c284c15509a8
fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
141 | docctx->parent->document = NULL; |
53
62205699cd0e
improved motif tabs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
142 | } |
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
143 | |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
144 | docctx->obj = NULL; |
128
c284c15509a8
fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
145 | docctx->parent = NULL; |
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
146 | } |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
147 | |
37
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
148 | UiVar* uic_get_var(UiContext *ctx, char *name) { |
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
149 | // check document variables first |
37
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
150 | UiVar *var = NULL; |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
151 | UiContext *doc_ctx = ui_document_context(ctx->document); |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
152 | if(doc_ctx) { |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
153 | var = uic_get_var(doc_ctx, name); |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
154 | } |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
155 | |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
156 | // check variables of this context |
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
157 | if(!var) { |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
158 | var = ucx_map_cstr_get(ctx->vars, name); |
1
eb5269000bc8
added some document functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
159 | } |
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
160 | |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
161 | return var; |
0 | 162 | } |
163 | ||
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
164 | UiVar* uic_connect_var(UiContext *ctx, char *name, int type) { |
37
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
165 | // TODO: get current map (Document Container, Tabbed Pane) |
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
166 | UcxMap *from = ctx->vars; |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
167 | |
37
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
168 | UiVar *var = uic_get_var(ctx, name); |
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
169 | if(var) { |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
170 | // the value is registered |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
171 | |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
172 | // a little type check |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
173 | if(var->type != type) { |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
174 | fprintf(stderr, "UI Error: var %s has incompatible type.\n", name); |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
175 | return NULL; |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
176 | } else { |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
177 | // register the current document/wdata map |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
178 | // if the document is closed, the var will be moved to this map |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
179 | var->from = from; |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
180 | |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
181 | return var; |
1
eb5269000bc8
added some document functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
182 | } |
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
183 | } else { |
108
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
184 | // create an empty value and add it to the context variables |
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
185 | // it can be moved to the document vars later |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
186 | void *value = uic_create_value(ctx->mempool->allocator, type); |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
187 | if(!value) { |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
188 | fprintf(stderr, "UI Error: Cannot create empty value.\n"); |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
189 | return NULL; |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
190 | } |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
191 | UiVar *var = ucx_mempool_malloc(ctx->mempool, sizeof(UiVar)); |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
192 | var->value = value; |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
193 | var->type = type; |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
194 | var->isextern = 0; |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
195 | var->from = from; |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
196 | ucx_map_cstr_put(ctx->vars, name, var); |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
197 | return var; |
1
eb5269000bc8
added some document functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
198 | } |
0 | 199 | } |
200 | ||
128
c284c15509a8
fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
201 | void uic_move_var(UiVar *from, UiVar *to, UiBool set) { |
37
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
202 | switch(from->type) { |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
203 | case UI_VAR_INTEGER: { |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
204 | //memcpy(to->value, from->value, sizeof(UiInteger)); |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
205 | UiInteger *f = from->value; |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
206 | UiInteger *t = to->value; |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
207 | t->get = f->get; |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
208 | t->set = f->set; |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
209 | t->obj = f->obj; |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
210 | if(set) { |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
211 | t->set(t, t->value); |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
212 | } else { |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
213 | //t->value = t->get(t); |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
214 | f->value = f->get(f); |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
215 | //t->value = 0; |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
216 | } |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
217 | break; |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
218 | } |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
219 | case UI_VAR_STRING: { |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
220 | // TODO |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
221 | break; |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
222 | } |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
223 | case UI_VAR_TEXT: { |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
224 | UiText *f = from->value; |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
225 | UiText *t = to->value; |
128
c284c15509a8
fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
226 | char *tvalue = t->value ? t->value : ""; |
90
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
227 | int tpos = t->pos; |
37
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
228 | memcpy(t, f, sizeof(UiText)); |
128
c284c15509a8
fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
229 | if(set) { |
37
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
230 | t->set(t, tvalue); |
90
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
231 | t->setposition(t, tpos); |
37
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
232 | } else { |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
233 | f->value = f->get(f); |
90
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
234 | f->pos = f->position(f); |
131
774b741984a2
detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
235 | f->set = NULL; |
774b741984a2
detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
236 | f->get = NULL; |
774b741984a2
detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
237 | f->setposition = NULL; |
774b741984a2
detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
238 | f->position = NULL; |
37
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
239 | } |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
240 | break; |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
241 | } |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
242 | case UI_VAR_LIST: { |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
243 | UiListVar *f = from->value; |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
244 | UiListVar *t = to->value; |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
245 | UiList *list = t->listptr->list; |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
246 | UiObserver *observers = f->listptr->list->observers; |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
247 | t->listptr = f->listptr; |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
248 | if(set) { |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
249 | t->listptr->list = list; |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
250 | list->observers = observers; |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
251 | ui_notify(observers, list); |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
252 | } |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
253 | break; |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
254 | } |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
255 | } |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
256 | } |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
257 | |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
258 | void uic_reg_var(UiContext *ctx, char *name, int type, size_t vs, void *value) { |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
259 | UiVar *newvar = ucx_mempool_malloc(ctx->mempool, sizeof(UiVar)); |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
260 | newvar->isextern = 1; |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
261 | newvar->type = type; |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
262 | newvar->value = value; |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
263 | newvar->from = NULL; |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
264 | |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
265 | uic_add_var(ctx, name, newvar, type, vs); |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
266 | } |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
267 | |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
268 | void uic_add_var( |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
269 | UiContext *ctx, |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
270 | char *name, |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
271 | UiVar *newvar, |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
272 | int type, |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
273 | size_t vs) |
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 | // if a parent context has a variable with this name, we remove it and put |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
276 | // it to this context |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
277 | UiVar *var = ctx->obj ? uic_get_var(ctx->obj->ctx, name) : NULL; |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
278 | |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
279 | if(var && var->from != ctx->vars) { |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
280 | // external variables cannot be moved |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
281 | if(var->isextern) { |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
282 | fprintf( |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
283 | stderr, |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
284 | "UI Error: external variable %s " |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
285 | "cannot be moved to the document.\n", |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
286 | name); |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
287 | return; |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
288 | } |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
289 | |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
290 | // check type |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
291 | if(var->type != type) { |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
292 | fprintf(stderr, "UI Error: var %s has incompatible type.\n", name); |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
293 | return; |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
294 | } |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
295 | |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
296 | // override document var with window context var |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
297 | memcpy(newvar->value, var->value, vs); |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
298 | |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
299 | newvar->from = var->from; |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
300 | |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
301 | // TODO: free var struct |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
302 | ucx_map_cstr_remove(var->from, name); |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
303 | } |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
304 | |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
305 | // finally, add the new variable to the document |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
306 | ucx_map_cstr_put(ctx->vars, name, newvar); |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
307 | } |
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
308 | |
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
309 | void* uic_create_value(UcxAllocator *a, int type) { |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
310 | switch(type) { |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
311 | case UI_VAR_INTEGER: { |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
312 | UiInteger *i = a->calloc( |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
313 | a->pool, |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
314 | 1, |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
315 | sizeof(UiInteger)); |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
316 | return i; |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
317 | } |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
318 | case UI_VAR_STRING: { |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
319 | UiString *s = a->calloc( |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
320 | a->pool, |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
321 | 1, |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
322 | sizeof(UiInteger)); |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
323 | return s; |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
324 | } |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
325 | case UI_VAR_TEXT: { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
326 | UiText *t = a->calloc( |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
327 | a->pool, |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
328 | 1, |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
329 | sizeof(UiText)); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
330 | return t; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
331 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
332 | case UI_VAR_LIST: { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
333 | UiListVar *l = a->malloc(a->pool, sizeof(UiListVar)); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
334 | UiListPtr *lp = a->malloc(a->pool, sizeof(UiListPtr)); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
335 | l->listptr = lp; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
336 | lp->list = NULL; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
337 | // TODO: create empty list |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
338 | return l; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
339 | } |
0 | 340 | } |
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
341 | return NULL; |
0 | 342 | } |
343 | ||
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
344 | // public API |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
345 | |
111
40dbf1a7526a
added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
346 | 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
|
347 | ctx->close_callback = fnc; |
40dbf1a7526a
added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
348 | ctx->close_data = udata; |
40dbf1a7526a
added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
349 | } |
40dbf1a7526a
added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
350 | |
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
351 | int ui_getint(UiObject *obj, char *name) { |
37
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
352 | UiVar *var = uic_get_var(obj->ctx, name); |
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
353 | if(var) { |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
354 | if(var->type == UI_VAR_INTEGER) { |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
355 | UiInteger *i = var->value; |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
356 | if(i->get) { |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
357 | return i->get(i); |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
358 | } else { |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
359 | fprintf( |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
360 | stderr, |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
361 | "UI Error: variable %s is not connected.\n", |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
362 | name); |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
363 | } |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
364 | } else { |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
365 | fprintf( |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
366 | stderr, |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
367 | "UI Error: requested variable %s is not an integer.\n", |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
368 | name); |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
369 | } |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
370 | } else { |
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
371 | fprintf(stderr, "UI Error: unkown variable %s.\n", name); |
0 | 372 | } |
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
373 | return 0; |
0 | 374 | } |
375 | ||
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
376 | char* ui_getstr(UiObject *obj, char *name) { |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
377 | UiVar *var = uic_get_var(obj->ctx, name); |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
378 | if(var) { |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
379 | if(var->type == UI_VAR_STRING) { |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
380 | UiString *s = var->value; |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
381 | if(s->get) { |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
382 | return s->get(s); |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
383 | } else { |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
384 | fprintf( |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
385 | stderr, |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
386 | "UI Error: variable %s is not connected.\n", |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
387 | name); |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
388 | } |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
389 | } else { |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
390 | fprintf( |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
391 | stderr, |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
392 | "UI Error: requested variable %s is not an string.\n", |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
393 | name); |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
394 | } |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
395 | } else { |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
396 | fprintf(stderr, "UI Error: unkown variable %s.\n", name); |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
397 | } |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
398 | return NULL; |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
399 | } |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
400 | |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
401 | char* ui_gettext(UiObject *obj, char *name) { |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
402 | UiVar *var = uic_get_var(obj->ctx, name); |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
403 | if(var) { |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
404 | if(var->type == UI_VAR_TEXT) { |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
405 | UiText *s = var->value; |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
406 | if(s->get) { |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
407 | return s->get(s); |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
408 | } else { |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
409 | fprintf( |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
410 | stderr, |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
411 | "UI Error: variable %s is not connected.\n", |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
412 | name); |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
413 | } |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
414 | } else { |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
415 | fprintf( |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
416 | stderr, |
88
04c81be1c5a0
added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
53
diff
changeset
|
417 | "UI Error: requested variable %s is not a text.\n", |
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
418 | name); |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
419 | } |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
420 | } else { |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
421 | fprintf(stderr, "UI Error: unkown variable %s.\n", name); |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
422 | } |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
423 | return NULL; |
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
424 | } |
20
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
425 | |
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 | |
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
428 | 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
|
429 | 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
|
430 | 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
|
431 | } |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
432 | |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
433 | // enable/disable group widgets |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
434 | uic_check_group_widgets(ctx); |
20
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
435 | } |
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
436 | |
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
437 | 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
|
438 | 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
|
439 | if(i != -1) { |
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
440 | 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
|
441 | 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
|
442 | } |
21
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 | // enable/disable group widgets |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
445 | uic_check_group_widgets(ctx); |
20
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
446 | } |
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
447 | |
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
448 | 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
|
449 | if(!ctx->groups) { |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
111
diff
changeset
|
450 | return NULL; |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
111
diff
changeset
|
451 | } |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
111
diff
changeset
|
452 | |
20
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
453 | int nelm = ucx_list_size(ctx->groups); |
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
454 | int *groups = calloc(sizeof(int), nelm); |
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
455 | |
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
456 | int i = 0; |
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
457 | 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
|
458 | groups[i++] = (intptr_t)elm->data; |
20
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
459 | } |
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
460 | |
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
461 | *ngroups = nelm; |
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
462 | return groups; |
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
463 | } |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
464 | |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
465 | 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
|
466 | int ngroups = 0; |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
467 | 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
|
468 | |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
469 | UCX_FOREACH(elm, ctx->group_widgets) { |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
470 | UiGroupWidget *gw = elm->data; |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
471 | char *check = calloc(1, gw->numgroups); |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
472 | |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
473 | 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
|
474 | 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
|
475 | if(groups[i] == gw->groups[k]) { |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
476 | check[k] = 1; |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
477 | } |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
478 | } |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
479 | } |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
480 | |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
481 | int enable = 1; |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
482 | 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
|
483 | if(check[i] == 0) { |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
484 | enable = 0; |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
485 | break; |
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 | } |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
488 | ui_set_enabled(gw->widget, enable); |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
489 | } |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
490 | |
121
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
111
diff
changeset
|
491 | if(groups) { |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
111
diff
changeset
|
492 | free(groups); |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
111
diff
changeset
|
493 | } |
21
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 | |
25
78ae3efe463f
added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
496 | void uic_add_group_widget(UiContext *ctx, void *widget, UcxList *groups) { |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
497 | UcxMempool *mp = ctx->mempool; |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
498 | 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
|
499 | |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
500 | gw->widget = widget; |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
501 | gw->numgroups = ucx_list_size(groups); |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
502 | 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
|
503 | int i = 0; |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
504 | UCX_FOREACH(elm, groups) { |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
505 | 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
|
506 | } |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
507 | |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
508 | 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
|
509 | mp->allocator, |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
510 | ctx->group_widgets, |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
511 | gw); |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
512 | } |
38
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 | void* ui_malloc(UiContext *ctx, size_t size) { |
8ccdde37275b
added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
515 | return ctx ? ucx_mempool_malloc(ctx->mempool, size) : NULL; |
8ccdde37275b
added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
516 | } |
8ccdde37275b
added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
517 | |
8ccdde37275b
added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
518 | 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
|
519 | 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
|
520 | } |
8ccdde37275b
added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
521 | |
8ccdde37275b
added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
522 | void ui_free(UiContext *ctx, void *ptr) { |
8ccdde37275b
added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
523 | if(ctx) { |
8ccdde37275b
added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
524 | ucx_mempool_free(ctx->mempool, ptr); |
8ccdde37275b
added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
525 | } |
8ccdde37275b
added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
526 | } |
8ccdde37275b
added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
527 | |
8ccdde37275b
added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
528 | 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
|
529 | 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
|
530 | } |
4e66271541e8
added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
531 |