ui/common/context.c

Sat, 05 Dec 2020 10:34:10 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 05 Dec 2020 10:34:10 +0100
changeset 161
b1eac0878ce7
parent 154
8a4451fcb736
child 163
b70e2a77dea0
permissions
-rw-r--r--

fix crash on window close (GTK)

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 *
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
4 * Copyright 2017 Olaf Wintermann. All rights reserved.
0
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"
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
37 #include "types.h"
0
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
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 UiContext* uic_context(UiObject *toplevel, UcxMempool *mp) {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 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
42 memset(ctx, 0, sizeof(UiContext));
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 ctx->mempool = mp;
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
44 ctx->obj = toplevel;
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
45 ctx->vars = ucx_map_new_a(mp->allocator, 16);
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
47 ctx->set_document = uic_context_set_document;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
48 ctx->detach_document = uic_context_detach_document;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
49
18
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
50 #ifdef UI_GTK
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
51 if(toplevel->widget) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
52 ctx->accel_group = gtk_accel_group_new();
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
53 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
54 }
18
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
55 #endif
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
56
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 return ctx;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59
128
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 121
diff changeset
60 UiContext* uic_root_context(UiContext *ctx) {
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 121
diff changeset
61 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
62 }
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 121
diff changeset
63
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
64 void uic_context_set_document(UiContext *ctx, void *document) {
131
774b741984a2 detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
65 if(ctx->document == document) {
774b741984a2 detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
66 return;
774b741984a2 detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
67 }
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
68 if(ctx->document) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
69 uic_context_detach_document(ctx);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
70 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
71 ctx->document = document;
131
774b741984a2 detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
72
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
73 UiContext *docctx = ui_document_context(document);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
74 if(!docctx) {
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
75 fprintf(stderr, "UiError: uic_context_set_document: pointer is not a document\n");
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
76 return;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
77 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
78 docctx->obj = ctx->obj;
128
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 121
diff changeset
79 docctx->parent = ctx;
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
80
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
81 UiContext *root = uic_root_context(ctx);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
82 if(!root->bound || root->bound->count == 0) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
83 return;
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
84 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
85
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
86 // there are bound variables in the root ctx
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
87 // copy bindings with correct name to doc vars
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
88 UcxMapIterator i = ucx_map_iterator(docctx->vars);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
89 UiVar *var;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
90 UCX_MAP_FOREACH(key, var, i) {
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
91 UiVar *v = ucx_map_get(root->bound, key);
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
92 if(v) {
154
8a4451fcb736 fixes ui_textfield_set (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
93 // copy binding: after this, all doc vars with names of previously
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
94 // bound variables are bound to the widgets
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
95 // the widgets still hold a pointer to the root ctx vars, but this
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
96 // vars have a pointer to the document variable value - confusing
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
97 uic_copy_binding(v, var, TRUE);
52
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 }
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
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
102 void uic_context_detach_document(UiContext *ctx) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
103 if(!ctx->document) {
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
104 return;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
105 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
106
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
107 UiContext *docctx = ui_document_context(ctx->document);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
108 if(!docctx) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
109 fprintf(stderr, "UiError: Cannot detach document: no context\n");
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
110 return;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
111 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
112 ctx->document = NULL;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
113 docctx->parent = NULL;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
114 docctx->obj = NULL;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
115
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
116 // unbind all vars
52
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) {
141
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
120 uic_save_var(var);
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
121 if(var->from) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
122 // restore old root bound var val
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
123 var->from->value = var->from->orig_val;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
124 var->from->orig_val = NULL;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
125 // copy
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
126 uic_copy_binding(var, var->from, FALSE);
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
127 }
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
128 uic_unbind_var(var);
52
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 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
131
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
132 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
133 // check document variables first
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
134 UiVar *var = NULL;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
135 UiContext *doc_ctx = ui_document_context(ctx->document);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
136 if(doc_ctx) {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
137 var = uic_get_var(doc_ctx, name);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
138 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
139
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
140 // check variables of this context
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
141 if(!var) {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
142 var = ucx_map_cstr_get(ctx->vars, name);
1
eb5269000bc8 added some document functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
143 }
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
144
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
145 return var;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
148 UiVar* uic_create_var(UiContext *ctx, char *name, UiVarType type) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
149 // check if this context has a var with this name
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
150 // otherweise add it to the bound map
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
151 UiVar *cv = ucx_map_cstr_get(ctx->vars, name);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
152 if(cv) {
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
153 if(cv->type == type) {
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
154 return cv;
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
155 } else {
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
156 fprintf(stderr, "UiError: var '%s' already exists with different type\n", name);
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
157 }
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
158 }
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
159
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
160 UiVar *var;
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
161 if(ctx->bound) {
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
162 var = ucx_map_cstr_get(ctx->bound, name);
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
163 if(var) {
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
164 if(var->type != type) {
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
165 fprintf(stderr, "UiError: var '%s' already bound with different type\n", name);
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
166 } else {
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
167 return var;
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
168 }
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
169 }
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
170 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
171
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
172 // create var and add it to the bound map
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
173 // this map contains vars that are created by widgets
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
174 // the vars can later be moved to subdocuments
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
175 var = ui_malloc(ctx, sizeof(UiVar));
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
176 var->type = type;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
177 var->value = uic_create_value(ctx, type);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
178 var->orig_val = NULL;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
179 var->from = NULL; // not connected to a doc var
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
180
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
181 if(!ctx->bound) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
182 ctx->bound = ucx_map_new_a(ctx->mempool->allocator, 16);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
183 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
184 ucx_map_cstr_put(ctx->bound, name, var);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
185
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
186 // if a subdocument has a variable with this name, we must copy
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
187 // the binding to the doc var
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
188 UiContext *doc_ctx = ui_document_context(ctx->document);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
189 if(doc_ctx) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
190 UiVar *docvar = uic_get_var(doc_ctx, name);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
191 if(docvar) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
192 var->orig_val = var->value;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
193 var->value = docvar->value;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
194 docvar->from = var;
1
eb5269000bc8 added some document functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
195 }
eb5269000bc8 added some document functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
196 }
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
197
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
198 return var;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
201 void* uic_create_value(UiContext *ctx, UiVarType type) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
202 void *val = NULL;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
203 switch(type) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
204 case UI_VAR_INTEGER: {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
205 val = ui_int_new(ctx, NULL);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
206 break;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
207 }
145
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
208 case UI_VAR_DOUBLE: {
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
209 val = ui_double_new(ctx, NULL);
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
210 break;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
211 }
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
212 case UI_VAR_STRING: {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
213 val = ui_string_new(ctx, NULL);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
214 break;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
215 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
216 case UI_VAR_TEXT: {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
217 val = ui_text_new(ctx, NULL);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
218 break;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
219 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
220 case UI_VAR_LIST: {
146
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
221 val = ui_list_new(ctx, NULL);
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
222 break;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
223 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
224 case UI_VAR_RANGE: {
145
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
225 val = ui_range_new(ctx, NULL);
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
226 break;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
227 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
228 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
229 return val;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
230 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
231
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
232 void uic_copy_binding(UiVar *from, UiVar *to, UiBool copytodoc) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
233 if(copytodoc && from->from) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
234 fprintf(stderr, "UiError: var already connected to a document\n");
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
235 return;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
236 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
237
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
238 // check type
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
239 if(from->type != to->type) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
240 fprintf(stderr, "UI Error: var has incompatible type.\n");
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
241 return;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
242 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
243
146
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
244 void *fromvalue = from->value;
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
245 // update var
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
246 if(copytodoc) {
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
247 to->from = from;
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
248
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
249 from->orig_val = from->value;
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
250 from->value = to->value;
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
251 }
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
252
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
253 // copy binding
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
254 // we don't copy the observer, because the from var has never one
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
255 switch(from->type) {
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
256 default: fprintf(stderr, "uic_copy_binding: wtf!\n"); break;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
257 case UI_VAR_SPECIAL: break;
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
258 case UI_VAR_INTEGER: {
146
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
259 UiInteger *f = fromvalue;
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
260 UiInteger *t = to->value;
143
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
261 if(!f->obj) break;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
262 uic_int_copy(f, t);
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
263 t->set(t, t->value);
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
264 break;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
265 }
145
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
266 case UI_VAR_DOUBLE: {
146
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
267 UiDouble *f = fromvalue;
145
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
268 UiDouble *t = to->value;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
269 if(!f->obj) break;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
270 uic_double_copy(f, t);
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
271 t->set(t, t->value);
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
272 break;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
273 }
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
274 case UI_VAR_STRING: {
146
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
275 UiString *f = fromvalue;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
276 UiString *t = to->value;
143
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
277 if(!f->obj) break;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
278 uic_string_copy(f, t);
141
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
279 char *tvalue = t->value.ptr ? t->value.ptr : "";
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
280 t->set(t, tvalue);
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
281 break;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
282 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
283 case UI_VAR_TEXT: {
146
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
284 UiText *f = fromvalue;
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
285 UiText *t = to->value;
143
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
286 if(!f->obj) break;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
287 uic_text_copy(f, t);
141
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
288 char *tvalue = t->value.ptr ? t->value.ptr : "";
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
289 t->set(t, tvalue);
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
290 t->setposition(t, t->pos);
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
291 break;
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 case UI_VAR_LIST: {
146
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
294 UiList *f = fromvalue;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
295 UiList *t = to->value;
143
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
296 if(!f->obj) break;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
297 uic_list_copy(f, t);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
298 t->update(t, -1);
150
5cee4cb5ad79 fixes uic_copy_binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
299 break;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
300 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
301 case UI_VAR_RANGE: {
146
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
302 UiRange *f = fromvalue;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
303 UiRange *t = to->value;
143
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
304 if(!f->obj) break;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
305 uic_range_copy(f, t);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
306 t->setextent(t, t->extent);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
307 t->setrange(t, t->min, t->max);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
308 t->set(t, t->value);
150
5cee4cb5ad79 fixes uic_copy_binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
309 break;
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
310 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
311 }
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
312 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
313
141
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
314 void uic_save_var(UiVar *var) {
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
315 switch(var->type) {
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
316 case UI_VAR_INTEGER: uic_int_save(var->value); break;
145
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
317 case UI_VAR_DOUBLE: uic_double_save(var->value); break;
141
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
318 case UI_VAR_STRING: uic_string_save(var->value); break;
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
319 case UI_VAR_TEXT: uic_text_save(var->value); break;
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
320 case UI_VAR_LIST: break;
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
321 case UI_VAR_RANGE: uic_range_save(var->value); break;
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
322 }
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
323 }
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
324
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
325 void uic_unbind_var(UiVar *var) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
326 switch(var->type) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
327 case UI_VAR_INTEGER: uic_int_unbind(var->value); break;
145
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
328 case UI_VAR_DOUBLE: uic_double_unbind(var->value); break;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
329 case UI_VAR_STRING: uic_string_unbind(var->value); break;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
330 case UI_VAR_TEXT: uic_text_unbind(var->value); break;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
331 case UI_VAR_LIST: uic_list_unbind(var->value); break;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
332 case UI_VAR_RANGE: uic_range_unbind(var->value); break;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
333 }
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
334 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
335
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
336 void uic_reg_var(UiContext *ctx, char *name, UiVarType type, void *value) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
337 UiContext *rootctx = uic_root_context(ctx);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
338
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
339 UiVar *b = NULL;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
340 if(rootctx->bound) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
341 // some widgets are already bound to some vars
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
342 b = ucx_map_cstr_get(rootctx->bound, name);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
343 if(b) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
344 // a widget is bound to a var with this name
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
345 // if ctx is the root context we can remove the var from bound
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
346 // because set_doc or detach can't fuck things up
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
347 if(ctx == rootctx) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
348 ucx_map_cstr_remove(ctx->bound, name);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
349 // TODO: free stuff
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
350 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
351 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
352 }
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
353
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
354 // create new var and add it to doc's vars
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
355 UiVar *var = ui_malloc(ctx, sizeof(UiVar));
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
356 var->from = NULL;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
357 var->orig_val = NULL;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
358 var->type = type;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
359 var->value = value;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
360 size_t oldcount = ctx->vars->count;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
361 ucx_map_cstr_put(ctx->vars, name, var);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
362 if(ctx->vars->count != oldcount + 1) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
363 fprintf(stderr, "UiError: var '%s' already exists\n", name);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
364 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
365
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
366 // a widget is already bound to a var with this name
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
367 // copy the binding (like uic_context_set_document)
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
368 if(b) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
369 uic_copy_binding(b, var, TRUE);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
370 }
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
371 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
372
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
373 void uic_remove_bound_var(UiContext *ctx, UiVar *var) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
374 // TODO: implement
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
375 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
376
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
377
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
378 // public API
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
379
111
40dbf1a7526a added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
380 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
381 ctx->close_callback = fnc;
40dbf1a7526a added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
382 ctx->close_data = udata;
40dbf1a7526a added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
383 }
40dbf1a7526a added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
384
20
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
385
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
386
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
387 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
388 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
389 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
390 }
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
391
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
392 // enable/disable group widgets
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
393 uic_check_group_widgets(ctx);
20
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
394 }
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
395
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
396 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
397 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
398 if(i != -1) {
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
399 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
400 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
401 }
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
402
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
403 // enable/disable group widgets
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
404 uic_check_group_widgets(ctx);
20
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
405 }
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
406
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
407 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
408 if(!ctx->groups) {
1cc365c34125 added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 111
diff changeset
409 return NULL;
1cc365c34125 added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 111
diff changeset
410 }
1cc365c34125 added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 111
diff changeset
411
20
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
412 int nelm = ucx_list_size(ctx->groups);
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
413 int *groups = calloc(sizeof(int), nelm);
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
414
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
415 int i = 0;
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
416 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
417 groups[i++] = (intptr_t)elm->data;
20
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 *ngroups = nelm;
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
421 return groups;
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
422 }
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
423
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
424 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
425 int ngroups = 0;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
426 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
427
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
428 UCX_FOREACH(elm, ctx->group_widgets) {
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
429 UiGroupWidget *gw = elm->data;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
430 char *check = calloc(1, gw->numgroups);
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
431
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
432 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
433 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
434 if(groups[i] == gw->groups[k]) {
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
435 check[k] = 1;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
436 }
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
437 }
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
438 }
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
439
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
440 int enable = 1;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
441 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
442 if(check[i] == 0) {
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
443 enable = 0;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
444 break;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
445 }
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 ui_set_enabled(gw->widget, enable);
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
448 }
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
449
121
1cc365c34125 added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 111
diff changeset
450 if(groups) {
1cc365c34125 added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 111
diff changeset
451 free(groups);
1cc365c34125 added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 111
diff changeset
452 }
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
453 }
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
454
25
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
455 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
456 UcxMempool *mp = ctx->mempool;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
457 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
458
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
459 gw->widget = widget;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
460 gw->numgroups = ucx_list_size(groups);
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
461 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
462 int i = 0;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
463 UCX_FOREACH(elm, groups) {
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
464 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
465 }
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
466
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
467 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
468 mp->allocator,
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
469 ctx->group_widgets,
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
470 gw);
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
471 }
38
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
472
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
473 void* ui_malloc(UiContext *ctx, size_t size) {
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
474 return ctx ? ucx_mempool_malloc(ctx->mempool, size) : NULL;
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
475 }
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
476
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
477 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
478 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
479 }
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
480
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
481 void ui_free(UiContext *ctx, void *ptr) {
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
482 if(ctx) {
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
483 ucx_mempool_free(ctx->mempool, ptr);
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
484 }
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
485 }
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
486
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
487 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
488 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
489 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
490

mercurial