ui/common/context.c

Sun, 24 Jan 2016 19:23:49 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 24 Jan 2016 19:23:49 +0100
changeset 112
fdd33964b35f
parent 111
40dbf1a7526a
child 121
1cc365c34125
permissions
-rw-r--r--

added radio buttons (Motif)

0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2014 Olaf Wintermann. All rights reserved.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
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
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include "context.h"
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
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
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 UiContext* uic_context(UiObject *toplevel, UcxMempool *mp) {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
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
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
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
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
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
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 return ctx;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
59 void uic_context_set_document(UiContext *ctx, void *document) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
60 UiContext *docctx = ui_document_context(document);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
61 if(!docctx) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
62 return;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
63 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
64 docctx->obj = ctx->obj;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
65
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
66 if(ctx->document) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
67 uic_context_detach_document(ctx, ctx->document);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
68 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
69 //obj->document = document;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
70 ctx->document = document;
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 UcxMapIterator i = ucx_map_iterator(docctx->vars);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
73 UiVar *var;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
74 UCX_MAP_FOREACH(key, var, i) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
75 UiVar *v = ucx_map_get(ctx->vars, key);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
76 if(v) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
77 if(v->isextern) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
78 fprintf(
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
79 stderr,
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
80 "UI Error: external variable cannot be moved\n");
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
81 return;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
82 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
83 // check type
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
84 if(var->type != v->type) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
85 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
86 return;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
87 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
88
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
89 // copy value
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
90 uic_move_var(v, var, 1);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
91 var->from = v->from;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
92
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
93 // TODO: free var struct
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
94 ucx_map_remove(ctx->vars, key);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
95 }
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
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
99 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
100 UiContext *docctx = ui_document_context(document);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
101 if(!docctx) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
102 fprintf(
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
103 stderr,
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
104 "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
105 return;
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 if(ctx->document != document) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
108 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
109 return;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
110 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
111
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
112 UcxMapIterator i = ucx_map_iterator(docctx->vars);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
113 UiVar *var;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
114 UCX_MAP_FOREACH(key, var, i) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
115 if(var->from && var->from != docctx->vars) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
116 // 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
117 UcxAllocator *a = var->from->allocator;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
118 UiVar *newvar = a->malloc(a->pool, sizeof(UiVar));
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
119 newvar->value = uic_create_value(a, var->type);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
120 uic_move_var(var, newvar, 0);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
121 newvar->type = var->type;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
122 newvar->from = var->from;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
123 newvar->isextern = 0;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
124
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
125 ucx_map_put(var->from, key, newvar);
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 //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
128 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
129 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
130
53
62205699cd0e improved motif tabs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
131 if(docctx->obj) {
62205699cd0e improved motif tabs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
132 docctx->obj->ctx->document = NULL;
62205699cd0e improved motif tabs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
133 }
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
134
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
135 docctx->obj = NULL;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
136 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
137
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
138 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
139 // check document variables first
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
140 UiVar *var = NULL;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
141 UiContext *doc_ctx = ui_document_context(ctx->document);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
142 if(doc_ctx) {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
143 var = uic_get_var(doc_ctx, name);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
144 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
145
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
146 // check variables of this context
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
147 if(!var) {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
148 var = ucx_map_cstr_get(ctx->vars, name);
1
eb5269000bc8 added some document functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
149 }
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
150
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
151 return var;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
154 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
155 // 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
156 UcxMap *from = ctx->vars;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
157
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
158 UiVar *var = uic_get_var(ctx, name);
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
159 if(var) {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
160 // the value is registered
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
161
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
162 // a little type check
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
163 if(var->type != type) {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
164 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
165 return NULL;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
166 } else {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
167 // register the current document/wdata map
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
168 // 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
169 var->from = from;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
170
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
171 return var;
1
eb5269000bc8 added some document functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
172 }
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
173 } else {
108
fcf6d5fac8f5 radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 94
diff changeset
174 // 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
175 // 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
176 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
177 if(!value) {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
178 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
179 return NULL;
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 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
182 var->value = value;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
183 var->type = type;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
184 var->isextern = 0;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
185 var->from = from;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
186 ucx_map_cstr_put(ctx->vars, name, var);
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
187 return var;
1
eb5269000bc8 added some document functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
188 }
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
191 void uic_move_var(UiVar *from, UiVar *to, int set) {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
192 switch(from->type) {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
193 case UI_VAR_INTEGER: {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
194 //memcpy(to->value, from->value, sizeof(UiInteger));
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
195 UiInteger *f = from->value;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
196 UiInteger *t = to->value;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
197 t->get = f->get;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
198 t->set = f->set;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
199 t->obj = f->obj;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
200 if(set) {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
201 t->set(t, t->value);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
202 } else {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
203 //t->value = t->get(t);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
204 f->value = f->get(f);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
205 //t->value = 0;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
206 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
207 break;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
208 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
209 case UI_VAR_STRING: {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
210 // TODO
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
211 break;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
212 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
213 case UI_VAR_TEXT: {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
214 UiText *f = from->value;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
215 UiText *t = to->value;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
216 char *tvalue = t->value;
90
2019fdbaadfd persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
217 int tpos = t->pos;
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
218 memcpy(t, f, sizeof(UiText));
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
219 if(set && tvalue) {
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
220 t->set(t, tvalue);
90
2019fdbaadfd persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
221 t->setposition(t, tpos);
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
222 } else {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
223 f->value = f->get(f);
90
2019fdbaadfd persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
224 f->pos = f->position(f);
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
225 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
226 break;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
227 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
228 case UI_VAR_LIST: {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
229 UiListVar *f = from->value;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
230 UiListVar *t = to->value;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
231 UiList *list = t->listptr->list;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
232 UiObserver *observers = f->listptr->list->observers;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
233 t->listptr = f->listptr;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
234 if(set) {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
235 t->listptr->list = list;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
236 list->observers = observers;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
237 ui_notify(observers, list);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
238 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
239 break;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
240 }
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 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
243
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
244 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
245 UiVar *newvar = ucx_mempool_malloc(ctx->mempool, sizeof(UiVar));
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
246 newvar->isextern = 1;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
247 newvar->type = type;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
248 newvar->value = value;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
249 newvar->from = NULL;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
250
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
251 uic_add_var(ctx, name, newvar, type, vs);
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
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
254 void uic_add_var(
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
255 UiContext *ctx,
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
256 char *name,
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
257 UiVar *newvar,
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
258 int type,
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
259 size_t vs)
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
260 {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
261 // 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
262 // it to this context
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
263 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
264
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
265 if(var && var->from != ctx->vars) {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
266 // external variables cannot be moved
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
267 if(var->isextern) {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
268 fprintf(
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
269 stderr,
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
270 "UI Error: external variable %s "
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
271 "cannot be moved to the document.\n",
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
272 name);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
273 return;
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
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
276 // check type
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
277 if(var->type != type) {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
278 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
279 return;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
280 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
281
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
282 // override document var with window context var
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
283 memcpy(newvar->value, var->value, vs);
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 newvar->from = var->from;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
286
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
287 // TODO: free var struct
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
288 ucx_map_cstr_remove(var->from, name);
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
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
291 // finally, add the new variable to the document
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
292 ucx_map_cstr_put(ctx->vars, name, newvar);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
293 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
294
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
295 void* uic_create_value(UcxAllocator *a, int type) {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
296 switch(type) {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
297 case UI_VAR_INTEGER: {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
298 UiInteger *i = a->calloc(
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
299 a->pool,
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
300 1,
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
301 sizeof(UiInteger));
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
302 return i;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
303 }
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
304 case UI_VAR_STRING: {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
305 UiString *s = a->calloc(
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
306 a->pool,
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
307 1,
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
308 sizeof(UiInteger));
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
309 return s;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
310 }
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
311 case UI_VAR_TEXT: {
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
312 UiText *t = a->calloc(
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
313 a->pool,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
314 1,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
315 sizeof(UiText));
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
316 return t;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
317 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
318 case UI_VAR_LIST: {
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
319 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
320 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
321 l->listptr = lp;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
322 lp->list = NULL;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
323 // TODO: create empty list
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
324 return l;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
325 }
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
326 }
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
327 return NULL;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
328 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
329
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
330 // public API
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
331
111
40dbf1a7526a added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
332 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
333 ctx->close_callback = fnc;
40dbf1a7526a added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
334 ctx->close_data = udata;
40dbf1a7526a added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
335 }
40dbf1a7526a added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
336
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
337 int ui_getint(UiObject *obj, char *name) {
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
338 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
339 if(var) {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
340 if(var->type == UI_VAR_INTEGER) {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
341 UiInteger *i = var->value;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
342 if(i->get) {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
343 return i->get(i);
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
344 } else {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
345 fprintf(
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
346 stderr,
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
347 "UI Error: variable %s is not connected.\n",
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
348 name);
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
349 }
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
350 } else {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
351 fprintf(
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
352 stderr,
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
353 "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
354 name);
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
355 }
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
356 } else {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
357 fprintf(stderr, "UI Error: unkown variable %s.\n", name);
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
358 }
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
359 return 0;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
360 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
361
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
362 char* ui_getstr(UiObject *obj, char *name) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
363 UiVar *var = uic_get_var(obj->ctx, name);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
364 if(var) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
365 if(var->type == UI_VAR_STRING) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
366 UiString *s = var->value;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
367 if(s->get) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
368 return s->get(s);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
369 } else {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
370 fprintf(
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
371 stderr,
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
372 "UI Error: variable %s is not connected.\n",
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
373 name);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
374 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
375 } else {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
376 fprintf(
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
377 stderr,
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
378 "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
379 name);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
380 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
381 } else {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
382 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
383 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
384 return NULL;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
385 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
386
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
387 char* ui_gettext(UiObject *obj, char *name) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
388 UiVar *var = uic_get_var(obj->ctx, name);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
389 if(var) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
390 if(var->type == UI_VAR_TEXT) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
391 UiText *s = var->value;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
392 if(s->get) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
393 return s->get(s);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
394 } else {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
395 fprintf(
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
396 stderr,
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
397 "UI Error: variable %s is not connected.\n",
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
398 name);
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 } else {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
401 fprintf(
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
402 stderr,
88
04c81be1c5a0 added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
403 "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
404 name);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
405 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
406 } else {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
407 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
408 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
409 return NULL;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
410 }
20
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
411
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
412
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
413
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
414 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
415 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
416 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
417 }
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
418
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
419 // enable/disable group widgets
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
420 uic_check_group_widgets(ctx);
20
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
421 }
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
422
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
423 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
424 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
425 if(i != -1) {
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
426 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
427 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
428 }
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
429
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
430 // enable/disable group widgets
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
431 uic_check_group_widgets(ctx);
20
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
432 }
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
433
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
434 int* ui_active_groups(UiContext *ctx, int *ngroups) {
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
435 int nelm = ucx_list_size(ctx->groups);
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
436 int *groups = calloc(sizeof(int), nelm);
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
437
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
438 int i = 0;
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
439 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
440 groups[i++] = (intptr_t)elm->data;
20
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
441 }
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
442
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
443 *ngroups = nelm;
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
444 return groups;
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
445 }
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
446
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
447 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
448 int ngroups = 0;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
449 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
450
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
451 UCX_FOREACH(elm, ctx->group_widgets) {
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
452 UiGroupWidget *gw = elm->data;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
453 char *check = calloc(1, gw->numgroups);
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
454
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
455 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
456 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
457 if(groups[i] == gw->groups[k]) {
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
458 check[k] = 1;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
459 }
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 }
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
462
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
463 int enable = 1;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
464 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
465 if(check[i] == 0) {
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
466 enable = 0;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
467 break;
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 }
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
470 ui_set_enabled(gw->widget, enable);
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
471 }
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 free(groups);
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
474 }
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
475
25
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
476 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
477 UcxMempool *mp = ctx->mempool;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
478 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
479
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
480 gw->widget = widget;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
481 gw->numgroups = ucx_list_size(groups);
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
482 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
483 int i = 0;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
484 UCX_FOREACH(elm, groups) {
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
485 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
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 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
489 mp->allocator,
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
490 ctx->group_widgets,
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
491 gw);
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
492 }
38
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
493
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
494 void* ui_malloc(UiContext *ctx, size_t size) {
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
495 return ctx ? ucx_mempool_malloc(ctx->mempool, size) : NULL;
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
496 }
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
497
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
498 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
499 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
500 }
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_free(UiContext *ctx, void *ptr) {
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
503 if(ctx) {
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
504 ucx_mempool_free(ctx->mempool, ptr);
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 }
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
507
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
508 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
509 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
510 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
511

mercurial