ui/common/context.c

Sat, 17 Sep 2016 19:57:55 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 17 Sep 2016 19:57:55 +0200
changeset 129
5babf09f5f19
parent 128
c284c15509a8
child 131
774b741984a2
permissions
-rw-r--r--

fixes stultus commit

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
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) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
64 UiContext *docctx = ui_document_context(document);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
65 if(!docctx) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
66 return;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
67 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
68 docctx->obj = ctx->obj;
128
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 121
diff changeset
69 docctx->parent = ctx;
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
70
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
71 if(ctx->document) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
72 uic_context_detach_document(ctx, ctx->document);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
73 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
74 //obj->document = document;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
75 ctx->document = document;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
76
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
77 UcxMapIterator i = ucx_map_iterator(docctx->vars);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
78 UiVar *var;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
79 UCX_MAP_FOREACH(key, var, i) {
128
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 121
diff changeset
80 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
81 if(v) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
82 if(v->isextern) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
83 fprintf(
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
84 stderr,
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
85 "UI Error: external variable cannot be moved\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 // check type
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
89 if(var->type != v->type) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
90 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
91 return;
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
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
94 // copy value
128
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 121
diff changeset
95 uic_move_var(v, var, TRUE);
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
96 var->from = v->from;
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 // TODO: free var struct
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
99 ucx_map_remove(ctx->vars, key);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
100 }
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 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
103
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
104 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
105 UiContext *docctx = ui_document_context(document);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
106 if(!docctx) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
107 fprintf(
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
108 stderr,
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
109 "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
110 return;
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 if(ctx->document != document) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
113 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
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
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
117 UcxMapIterator i = ucx_map_iterator(docctx->vars);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
118 UiVar *var;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
119 UCX_MAP_FOREACH(key, var, i) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
120 if(var->from && var->from != docctx->vars) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
121 // 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
122 UcxAllocator *a = var->from->allocator;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
123 UiVar *newvar = a->malloc(a->pool, sizeof(UiVar));
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
124 newvar->value = uic_create_value(a, var->type);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
125 uic_move_var(var, newvar, 0);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
126 newvar->type = var->type;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
127 newvar->from = var->from;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
128 newvar->isextern = 0;
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 ucx_map_put(var->from, key, newvar);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
131
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
132 //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
133 }
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
128
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 121
diff changeset
136 if(docctx->parent) {
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 121
diff changeset
137 docctx->parent->document = NULL;
53
62205699cd0e improved motif tabs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
138 }
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
139
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
140 docctx->obj = NULL;
128
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 121
diff changeset
141 docctx->parent = NULL;
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
142 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
143
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
144 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
145 // check document variables first
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
146 UiVar *var = NULL;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
147 UiContext *doc_ctx = ui_document_context(ctx->document);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
148 if(doc_ctx) {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
149 var = uic_get_var(doc_ctx, name);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
150 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
151
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
152 // check variables of this context
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
153 if(!var) {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
154 var = ucx_map_cstr_get(ctx->vars, name);
1
eb5269000bc8 added some document functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
155 }
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
156
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
157 return var;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
160 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
161 // 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
162 UcxMap *from = ctx->vars;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
163
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
164 UiVar *var = uic_get_var(ctx, name);
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
165 if(var) {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
166 // the value is registered
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
167
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
168 // a little type check
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
169 if(var->type != type) {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
170 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
171 return NULL;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
172 } else {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
173 // register the current document/wdata map
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
174 // 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
175 var->from = from;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
176
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
177 return var;
1
eb5269000bc8 added some document functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
178 }
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
179 } else {
108
fcf6d5fac8f5 radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 94
diff changeset
180 // 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
181 // 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
182 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
183 if(!value) {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
184 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
185 return NULL;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
186 }
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
187 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
188 var->value = value;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
189 var->type = type;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
190 var->isextern = 0;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
191 var->from = from;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
192 ucx_map_cstr_put(ctx->vars, name, var);
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
193 return var;
1
eb5269000bc8 added some document functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
194 }
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196
128
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 121
diff changeset
197 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
198 switch(from->type) {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
199 case UI_VAR_INTEGER: {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
200 //memcpy(to->value, from->value, sizeof(UiInteger));
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
201 UiInteger *f = from->value;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
202 UiInteger *t = to->value;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
203 t->get = f->get;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
204 t->set = f->set;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
205 t->obj = f->obj;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
206 if(set) {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
207 t->set(t, t->value);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
208 } else {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
209 //t->value = t->get(t);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
210 f->value = f->get(f);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
211 //t->value = 0;
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 break;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
214 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
215 case UI_VAR_STRING: {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
216 // TODO
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_TEXT: {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
220 UiText *f = from->value;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
221 UiText *t = to->value;
128
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 121
diff changeset
222 char *tvalue = t->value ? t->value : "";
90
2019fdbaadfd persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
223 int tpos = t->pos;
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
224 memcpy(t, f, sizeof(UiText));
128
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 121
diff changeset
225 if(set) {
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
226 t->set(t, tvalue);
90
2019fdbaadfd persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
227 t->setposition(t, tpos);
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
228 } else {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
229 f->value = f->get(f);
90
2019fdbaadfd persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
230 f->pos = f->position(f);
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
231 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
232 break;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
233 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
234 case UI_VAR_LIST: {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
235 UiListVar *f = from->value;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
236 UiListVar *t = to->value;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
237 UiList *list = t->listptr->list;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
238 UiObserver *observers = f->listptr->list->observers;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
239 t->listptr = f->listptr;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
240 if(set) {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
241 t->listptr->list = list;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
242 list->observers = observers;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
243 ui_notify(observers, list);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
244 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
245 break;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
246 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
247 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
248 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
249
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
250 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
251 UiVar *newvar = ucx_mempool_malloc(ctx->mempool, sizeof(UiVar));
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
252 newvar->isextern = 1;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
253 newvar->type = type;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
254 newvar->value = value;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
255 newvar->from = NULL;
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 uic_add_var(ctx, name, newvar, type, vs);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
258 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
259
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
260 void uic_add_var(
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
261 UiContext *ctx,
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
262 char *name,
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
263 UiVar *newvar,
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
264 int type,
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
265 size_t 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 // 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
268 // it to this context
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
269 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
270
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
271 if(var && var->from != ctx->vars) {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
272 // external variables cannot be moved
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
273 if(var->isextern) {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
274 fprintf(
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
275 stderr,
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
276 "UI Error: external variable %s "
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
277 "cannot be moved to the document.\n",
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
278 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 // check type
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
283 if(var->type != type) {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
284 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
285 return;
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
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
288 // override document var with window context var
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
289 memcpy(newvar->value, var->value, vs);
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 newvar->from = var->from;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
292
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
293 // TODO: free var struct
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
294 ucx_map_cstr_remove(var->from, name);
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
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
297 // finally, add the new variable to the document
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
298 ucx_map_cstr_put(ctx->vars, name, newvar);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
299 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
300
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
301 void* uic_create_value(UcxAllocator *a, int type) {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
302 switch(type) {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
303 case UI_VAR_INTEGER: {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
304 UiInteger *i = a->calloc(
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
305 a->pool,
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
306 1,
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
307 sizeof(UiInteger));
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
308 return i;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
309 }
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
310 case UI_VAR_STRING: {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
311 UiString *s = a->calloc(
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
312 a->pool,
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
313 1,
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
314 sizeof(UiInteger));
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
315 return s;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
316 }
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
317 case UI_VAR_TEXT: {
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
318 UiText *t = a->calloc(
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
319 a->pool,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
320 1,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
321 sizeof(UiText));
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
322 return t;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
323 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
324 case UI_VAR_LIST: {
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
325 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
326 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
327 l->listptr = lp;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
328 lp->list = NULL;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
329 // TODO: create empty list
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
330 return l;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
331 }
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
332 }
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
333 return NULL;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
334 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
335
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
336 // public API
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
337
111
40dbf1a7526a added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
338 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
339 ctx->close_callback = fnc;
40dbf1a7526a added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
340 ctx->close_data = udata;
40dbf1a7526a added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
341 }
40dbf1a7526a added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
342
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
343 int ui_getint(UiObject *obj, char *name) {
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
344 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
345 if(var) {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
346 if(var->type == UI_VAR_INTEGER) {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
347 UiInteger *i = var->value;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
348 if(i->get) {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
349 return i->get(i);
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: variable %s is not connected.\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(
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
358 stderr,
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
359 "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
360 name);
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
361 }
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
362 } else {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
363 fprintf(stderr, "UI Error: unkown variable %s.\n", name);
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
364 }
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
365 return 0;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
366 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
367
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
368 char* ui_getstr(UiObject *obj, char *name) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
369 UiVar *var = uic_get_var(obj->ctx, name);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
370 if(var) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
371 if(var->type == UI_VAR_STRING) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
372 UiString *s = var->value;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
373 if(s->get) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
374 return s->get(s);
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: variable %s is not connected.\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(
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
383 stderr,
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
384 "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
385 name);
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 } else {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
388 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
389 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
390 return NULL;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
391 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
392
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
393 char* ui_gettext(UiObject *obj, char *name) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
394 UiVar *var = uic_get_var(obj->ctx, name);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
395 if(var) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
396 if(var->type == UI_VAR_TEXT) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
397 UiText *s = var->value;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
398 if(s->get) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
399 return s->get(s);
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,
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
403 "UI Error: variable %s is not connected.\n",
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(
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
408 stderr,
88
04c81be1c5a0 added textarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
409 "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
410 name);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
411 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
412 } else {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
413 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
414 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
415 return NULL;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
416 }
20
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
417
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
418
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
419
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
420 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
421 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
422 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
423 }
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
424
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
425 // enable/disable group widgets
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
426 uic_check_group_widgets(ctx);
20
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
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
429 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
430 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
431 if(i != -1) {
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
432 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
433 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
434 }
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
435
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
436 // enable/disable group widgets
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
437 uic_check_group_widgets(ctx);
20
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
438 }
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
439
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
440 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
441 if(!ctx->groups) {
1cc365c34125 added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 111
diff changeset
442 return NULL;
1cc365c34125 added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 111
diff changeset
443 }
1cc365c34125 added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 111
diff changeset
444
20
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
445 int nelm = ucx_list_size(ctx->groups);
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
446 int *groups = calloc(sizeof(int), nelm);
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 i = 0;
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
449 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
450 groups[i++] = (intptr_t)elm->data;
20
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
451 }
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
452
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
453 *ngroups = nelm;
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
454 return groups;
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
455 }
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
456
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
457 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
458 int ngroups = 0;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
459 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
460
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
461 UCX_FOREACH(elm, ctx->group_widgets) {
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
462 UiGroupWidget *gw = elm->data;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
463 char *check = calloc(1, gw->numgroups);
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 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
466 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
467 if(groups[i] == gw->groups[k]) {
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
468 check[k] = 1;
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 }
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 int enable = 1;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
474 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
475 if(check[i] == 0) {
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
476 enable = 0;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
477 break;
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 ui_set_enabled(gw->widget, enable);
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
481 }
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
482
121
1cc365c34125 added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 111
diff changeset
483 if(groups) {
1cc365c34125 added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 111
diff changeset
484 free(groups);
1cc365c34125 added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 111
diff changeset
485 }
21
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
25
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
488 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
489 UcxMempool *mp = ctx->mempool;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
490 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
491
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
492 gw->widget = widget;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
493 gw->numgroups = ucx_list_size(groups);
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
494 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
495 int i = 0;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
496 UCX_FOREACH(elm, groups) {
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
497 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
498 }
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 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
501 mp->allocator,
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
502 ctx->group_widgets,
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
503 gw);
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
504 }
38
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
505
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
506 void* ui_malloc(UiContext *ctx, size_t size) {
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
507 return ctx ? ucx_mempool_malloc(ctx->mempool, size) : NULL;
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
508 }
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
509
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
510 void* ui_calloc(UiContext *ctx, size_t nelem, size_t elsize) {
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
511 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
512 }
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_free(UiContext *ctx, void *ptr) {
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
515 if(ctx) {
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
516 ucx_mempool_free(ctx->mempool, ptr);
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 }
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
519
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
520 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
521 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
522 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
523

mercurial