ui/common/context.c

Sun, 22 Dec 2024 11:49:59 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 22 Dec 2024 11:49:59 +0100
branch
newapi
changeset 420
28a5920bebe0
parent 406
0ebf9d7b23e8
permissions
-rw-r--r--

implement menu itemlist (Motif)

0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
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>
169
fe49cff3c571 refactor widget groups/document tree (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
33 #include <stdarg.h>
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
35 #include <cx/array_list.h>
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
36 #include <cx/compare.h>
187
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
37 #include <cx/mempool.h>
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
38
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 #include "context.h"
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 #include "../ui/window.h"
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
41 #include "document.h"
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
42 #include "types.h"
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43
379
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
44
167
161511838ea6 add new toolbar toggle button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 164
diff changeset
45 static UiContext* global_context;
161511838ea6 add new toolbar toggle button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 164
diff changeset
46
161511838ea6 add new toolbar toggle button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 164
diff changeset
47 void uic_init_global_context(void) {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
48 CxMempool *mp = cxBasicMempoolCreate(32);
187
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
49 global_context = uic_context(NULL, mp);
167
161511838ea6 add new toolbar toggle button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 164
diff changeset
50 }
161511838ea6 add new toolbar toggle button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 164
diff changeset
51
161511838ea6 add new toolbar toggle button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 164
diff changeset
52 UiContext* ui_global_context(void) {
161511838ea6 add new toolbar toggle button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 164
diff changeset
53 return global_context;
161511838ea6 add new toolbar toggle button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 164
diff changeset
54 }
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55
187
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
56 UiContext* uic_context(UiObject *toplevel, CxMempool *mp) {
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
57 UiContext *ctx = cxMalloc(mp->allocator, sizeof(UiContext));
111
40dbf1a7526a added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
58 memset(ctx, 0, sizeof(UiContext));
187
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
59 ctx->mp = mp;
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
60 ctx->allocator = mp->allocator;
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
61 ctx->obj = toplevel;
187
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
62 ctx->vars = cxHashMapCreate(mp->allocator, CX_STORE_POINTERS, 16);
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
63
187
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
64 ctx->documents = cxLinkedListCreate(mp->allocator, cx_cmp_intptr, CX_STORE_POINTERS);
392
df62b7205bd3 fix UiList binding copy and missing GTK table setselection method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 387
diff changeset
65 ctx->group_widgets = cxLinkedListCreate(mp->allocator, cx_cmp_ptr, sizeof(UiGroupWidget));
187
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
66 ctx->groups = cxArrayListCreate(mp->allocator, cx_cmp_int, sizeof(int), 32);
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
68 ctx->attach_document = uic_context_attach_document;
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
69 ctx->detach_document2 = uic_context_detach_document2;
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
70
293
736c962f1011 initial gtk4 porting, incomplete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 249
diff changeset
71 #if UI_GTK2 || UI_GTK3
167
161511838ea6 add new toolbar toggle button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 164
diff changeset
72 if(toplevel && toplevel->widget) {
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
73 ctx->accel_group = gtk_accel_group_new();
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
74 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
75 }
18
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
76 #endif
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
77
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 return ctx;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80
128
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 121
diff changeset
81 UiContext* uic_root_context(UiContext *ctx) {
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 121
diff changeset
82 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
83 }
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 121
diff changeset
84
365
004b5dd01f6a clear context states before closing a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 350
diff changeset
85 void uic_context_prepare_close(UiContext *ctx) {
004b5dd01f6a clear context states before closing a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 350
diff changeset
86 cxListClear(ctx->groups);
004b5dd01f6a clear context states before closing a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 350
diff changeset
87 cxListClear(ctx->group_widgets);
004b5dd01f6a clear context states before closing a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 350
diff changeset
88 }
004b5dd01f6a clear context states before closing a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 350
diff changeset
89
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
90 void uic_context_attach_document(UiContext *ctx, void *document) {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
91 cxListAdd(ctx->documents, document);
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
92 ctx->document = document;
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
93
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
94 UiContext *doc_ctx = ui_document_context(document);
131
774b741984a2 detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
95
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
96 // check if any parent context has an unbound variable with the same name
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
97 // as any document variable
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
98 UiContext *var_ctx = ctx;
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
99 while(var_ctx) {
325
99a93a9250c4 fix build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
100 if(var_ctx->vars_unbound && cxMapSize(var_ctx->vars_unbound) > 0) {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
101 CxIterator i = cxMapIterator(var_ctx->vars_unbound);
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
102 cx_foreach(CxMapEntry*, entry, i) {
420
28a5920bebe0 implement menu itemlist (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
103 printf("attach %s\n", entry->key->data);
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
104 UiVar *var = entry->value;
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
105 UiVar *docvar = cxMapGet(doc_ctx->vars, *entry->key);
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
106 if(docvar) {
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
107 // bind var to document var
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
108 uic_copy_binding(var, docvar, TRUE);
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
109 cxIteratorFlagRemoval(i);
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
110 }
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
111 }
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
112 }
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
113
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
114 var_ctx = ctx->parent;
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
115 }
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
116 }
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
117
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
118 static void uic_context_unbind_vars(UiContext *ctx) {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
119 CxIterator i = cxMapIterator(ctx->vars);
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
120 cx_foreach(CxMapEntry*, entry, i) {
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
121 UiVar *var = entry->value;
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
122 if(var->from && var->from_ctx) {
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
123 uic_save_var2(var);
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
124 uic_copy_binding(var, var->from, FALSE);
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
125 cxMapPut(var->from_ctx->vars_unbound, *entry->key, var->from);
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
126 var->from_ctx = ctx;
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
127 }
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
128 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
129
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
130 if(ctx->documents) {
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
131 i = cxListIterator(ctx->documents);
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
132 cx_foreach(void *, doc, i) {
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
133 UiContext *subctx = ui_document_context(doc);
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
134 uic_context_unbind_vars(subctx);
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
135 }
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
136 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
137 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
138
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
139 void uic_context_detach_document2(UiContext *ctx, void *document) {
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
140 // find the document in the documents list
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
141 ssize_t docIndex = cxListFind(ctx->documents, document);
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
142 if(docIndex < 0) {
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
143 return;
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
144 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
145
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
146 cxListRemove(ctx->documents, docIndex);
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
147 ctx->document = cxListAt(ctx->documents, 0);
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
148
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
149 UiContext *docctx = ui_document_context(document);
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
150 uic_context_unbind_vars(docctx); // unbind all doc/subdoc vars from the parent
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
151 }
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
152
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
153 void uic_context_detach_all(UiContext *ctx) {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
154 // copy list
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
155 CxList *ls = cxLinkedListCreate(cxDefaultAllocator, NULL, CX_STORE_POINTERS);
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
156 CxIterator i = cxListIterator(ctx->documents);
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
157 cx_foreach(void *, doc, i) {
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
158 cxListAdd(ls, doc);
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
159 }
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
160
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
161 // detach documents
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
162 i = cxListIterator(ls);
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
163 cx_foreach(void *, doc, i) {
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
164 ctx->detach_document2(ctx, doc);
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
165 }
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
166
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
167 cxListDestroy(ls);
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
168 }
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
169
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
170 static UiVar* ctx_getvar(UiContext *ctx, CxHashKey key) {
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
171 UiVar *var = cxMapGet(ctx->vars, key);
335
91d4f0391282 add new textarea (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 325
diff changeset
172 if(!var && ctx->documents) {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
173 CxIterator i = cxListIterator(ctx->documents);
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
174 cx_foreach(void *, doc, i) {
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
175 UiContext *subctx = ui_document_context(doc);
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
176 var = ctx_getvar(subctx, key);
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
177 if(var) {
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
178 break;
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
179 }
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
180 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
181 }
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
182 return var;
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
183 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
184
167
161511838ea6 add new toolbar toggle button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 164
diff changeset
185 UiVar* uic_get_var(UiContext *ctx, const char *name) {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
186 CxHashKey key = cx_hash_key(name, strlen(name));
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
187 return ctx_getvar(ctx, key);
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189
167
161511838ea6 add new toolbar toggle button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 164
diff changeset
190 UiVar* uic_create_var(UiContext *ctx, const char *name, UiVarType type) {
406
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
191 if(ctx->vars_unbound) {
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
192 UiVar *unbound = cxMapGet(ctx->vars_unbound, name);
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
193 if(unbound) {
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
194 return unbound;
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
195 }
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
196 }
0ebf9d7b23e8 add first code of the new Motif implementation, implement buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
197
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
198 UiVar *var = uic_get_var(ctx, name);
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
199 if(var) {
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
200 if(var->type == type) {
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
201 return var;
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
202 } else {
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
203 fprintf(stderr, "UiError: var '%s' already bound with different type\n", name);
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
204 }
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
205 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
206
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
207 var = ui_malloc(ctx, sizeof(UiVar));
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
208 var->type = type;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
209 var->value = uic_create_value(ctx, type);
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
210 var->from = NULL;
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
211 var->from_ctx = ctx;
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
212
372
4657ec1229f2 fix incorrect UiVar destruction
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 365
diff changeset
213 cxMempoolSetDestructor(var, (cx_destructor_func)uic_unbind_var);
187
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
214
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
215 if(!ctx->vars_unbound) {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
216 ctx->vars_unbound = cxHashMapCreate(ctx->allocator, CX_STORE_POINTERS, 16);
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
217 }
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
218 cxMapPut(ctx->vars_unbound, name, var);
140
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 return var;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222
187
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
223 UiVar* uic_create_value_var(UiContext* ctx, void* value) {
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
224 UiVar *var = (UiVar*)ui_malloc(ctx, sizeof(UiVar));
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
225 var->from = NULL;
350
70305d427f25 fix ui_scrolledwindow (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 343
diff changeset
226 var->from_ctx = ctx;
187
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
227 var->value = value;
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
228 var->type = UI_VAR_SPECIAL;
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
229 return var;
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
230 }
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
231
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
232 void* uic_create_value(UiContext *ctx, UiVarType type) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
233 void *val = NULL;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
234 switch(type) {
164
1d912f78fd1d fix some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 163
diff changeset
235 case UI_VAR_SPECIAL: break;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
236 case UI_VAR_INTEGER: {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
237 val = ui_int_new(ctx, NULL);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
238 break;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
239 }
145
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
240 case UI_VAR_DOUBLE: {
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
241 val = ui_double_new(ctx, NULL);
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
242 break;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
243 }
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
244 case UI_VAR_STRING: {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
245 val = ui_string_new(ctx, NULL);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
246 break;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
247 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
248 case UI_VAR_TEXT: {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
249 val = ui_text_new(ctx, NULL);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
250 break;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
251 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
252 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
253 val = ui_list_new(ctx, NULL);
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
254 break;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
255 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
256 case UI_VAR_RANGE: {
145
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
257 val = ui_range_new(ctx, NULL);
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
258 break;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
259 }
337
2904fba2708b add UiGeneric var type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
260 case UI_VAR_GENERIC: {
2904fba2708b add UiGeneric var type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
261 val = ui_generic_new(ctx, NULL);
2904fba2708b add UiGeneric var type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
262 }
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
263 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
264 return val;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
265 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
266
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
267
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
268 UiVar* uic_widget_var(UiContext* toplevel, UiContext* current, void* value, const char* varname, UiVarType type) {
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
269 if (value) {
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
270 return uic_create_value_var(current, value);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
271 }
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
272 if (varname) {
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
273 return uic_create_var(toplevel, varname, type);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
274 }
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
275 return NULL;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
276 }
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
277
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
278
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
279 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
280 // check type
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
281 if(from->type != to->type) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
282 fprintf(stderr, "UI Error: var has incompatible type.\n");
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
283 return;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
284 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
285
146
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
286 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
287 // update var
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
288 if(copytodoc) {
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
289 to->from = from;
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
290 to->from_ctx = from->from_ctx;
146
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
291 }
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 145
diff changeset
292
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
293 // copy binding
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
294 // 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
295 switch(from->type) {
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
296 default: fprintf(stderr, "uic_copy_binding: wtf!\n"); break;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
297 case UI_VAR_SPECIAL: break;
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
298 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
299 UiInteger *f = fromvalue;
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
300 UiInteger *t = to->value;
143
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
301 if(!f->obj) break;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
302 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
303 t->set(t, t->value);
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
304 break;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
305 }
145
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
306 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
307 UiDouble *f = fromvalue;
145
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
308 UiDouble *t = to->value;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
309 if(!f->obj) break;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
310 uic_double_copy(f, t);
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
311 t->set(t, t->value);
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
312 break;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 143
diff changeset
313 }
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
314 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
315 UiString *f = fromvalue;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
316 UiString *t = to->value;
143
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
317 if(!f->obj) break;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
318 uic_string_copy(f, t);
141
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
319 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
320 t->set(t, tvalue);
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
321 break;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
322 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
323 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
324 UiText *f = fromvalue;
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
325 UiText *t = to->value;
143
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
326 if(!f->obj) break;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
327 uic_text_copy(f, t);
141
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
328 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
329 t->set(t, tvalue);
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
330 t->setposition(t, t->pos);
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
331 break;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
332 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
333 case UI_VAR_LIST: {
232
e2b33055113f fix list binding not copied correctly when attaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 192
diff changeset
334 // TODO: not sure how correct this is
e2b33055113f fix list binding not copied correctly when attaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 192
diff changeset
335
239
5dd24929f9f6 fix list binding copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
336 UiList *f = from->value;
5dd24929f9f6 fix list binding copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
337 UiList *t = to->value;
5dd24929f9f6 fix list binding copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
338 if (f->obj) {
5dd24929f9f6 fix list binding copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
339 t->obj = f->obj;
5dd24929f9f6 fix list binding copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
340 t->update = f->update;
249
4df7c366cff7 copy UiList getselection fptr in uic_copy_binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
341 t->getselection = f->getselection;
392
df62b7205bd3 fix UiList binding copy and missing GTK table setselection method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 387
diff changeset
342 t->setselection = f->setselection;
239
5dd24929f9f6 fix list binding copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
343 }
5dd24929f9f6 fix list binding copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
344
232
e2b33055113f fix list binding not copied correctly when attaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 192
diff changeset
345 UiVar tmp = *from;
e2b33055113f fix list binding not copied correctly when attaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 192
diff changeset
346 *from = *to;
e2b33055113f fix list binding not copied correctly when attaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 192
diff changeset
347 *to = tmp;
e2b33055113f fix list binding not copied correctly when attaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 192
diff changeset
348
239
5dd24929f9f6 fix list binding copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
349 UiList* t2 = to->value;
5dd24929f9f6 fix list binding copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
350 ui_notify(t2->observers, NULL);
232
e2b33055113f fix list binding not copied correctly when attaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 192
diff changeset
351
150
5cee4cb5ad79 fixes uic_copy_binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
352 break;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
353 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
354 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
355 UiRange *f = fromvalue;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
356 UiRange *t = to->value;
143
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
357 if(!f->obj) break;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
358 uic_range_copy(f, t);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
359 t->setextent(t, t->extent);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
360 t->setrange(t, t->min, t->max);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
361 t->set(t, t->value);
150
5cee4cb5ad79 fixes uic_copy_binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
362 break;
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
363 }
337
2904fba2708b add UiGeneric var type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
364 case UI_VAR_GENERIC: {
2904fba2708b add UiGeneric var type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
365 UiGeneric *f = fromvalue;
2904fba2708b add UiGeneric var type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
366 UiGeneric *t = to->value;
2904fba2708b add UiGeneric var type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
367 if(!f->obj) break;
2904fba2708b add UiGeneric var type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
368 uic_generic_copy(f, t);
2904fba2708b add UiGeneric var type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
369 t->set(t, t->value, t->type);
2904fba2708b add UiGeneric var type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
370 break;
2904fba2708b add UiGeneric var type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
371 }
37
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 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
374
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
375 void uic_save_var2(UiVar *var) {
141
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
376 switch(var->type) {
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
377 case UI_VAR_SPECIAL: break;
141
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
378 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
379 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
380 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
381 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
382 case UI_VAR_LIST: break;
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
383 case UI_VAR_RANGE: uic_range_save(var->value); break;
337
2904fba2708b add UiGeneric var type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
384 case UI_VAR_GENERIC: uic_generic_save(var->value); break;
141
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
385 }
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
386 }
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
387
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
388 void uic_unbind_var(UiVar *var) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
389 switch(var->type) {
164
1d912f78fd1d fix some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 163
diff changeset
390 case UI_VAR_SPECIAL: break;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
391 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
392 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
393 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
394 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
395 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
396 case UI_VAR_RANGE: uic_range_unbind(var->value); break;
337
2904fba2708b add UiGeneric var type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 335
diff changeset
397 case UI_VAR_GENERIC: uic_generic_unbind(var->value); break;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
398 }
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
399 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
400
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
401 void uic_reg_var(UiContext *ctx, char *name, UiVarType type, void *value) {
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
402 // TODO: do we need/want this? Why adding vars to a context after
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
403 // widgets reference these? Workarounds:
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
404 // 1. add vars to ctx before creating ui
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
405 // 2. create ui, create new document with vars, attach doc
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
406 // also it would be possible to create a function, that scans unbound vars
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
407 // and connects them to available vars
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
408 /*
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
409 UiContext *rootctx = uic_root_context(ctx);
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
410 UiVar *b = NULL;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
411 if(rootctx->bound) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
412 // some widgets are already bound to some vars
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
413 b = ucx_map_cstr_get(rootctx->bound, name);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
414 if(b) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
415 // 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
416 // 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
417 // 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
418 if(ctx == rootctx) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
419 ucx_map_cstr_remove(ctx->bound, name);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
420 // TODO: free stuff
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
421 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
422 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
423 }
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
424 */
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
425
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
426 // 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
427 UiVar *var = ui_malloc(ctx, sizeof(UiVar));
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
428 var->type = type;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
429 var->value = value;
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
430 var->from = NULL;
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
431 var->from_ctx = ctx;
325
99a93a9250c4 fix build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
432 size_t oldcount = cxMapSize(ctx->vars);
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
433 cxMapPut(ctx->vars, name, var);
325
99a93a9250c4 fix build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
434 if(cxMapSize(ctx->vars) != oldcount + 1) {
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
435 fprintf(stderr, "UiError: var '%s' already exists\n", name);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
436 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
437
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
438 // TODO: remove?
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
439 // 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
440 // copy the binding (like uic_context_set_document)
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
441 /*
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
442 if(b) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
443 uic_copy_binding(b, var, TRUE);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
444 }
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
445 */
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
446 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
447
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
448 void uic_remove_bound_var(UiContext *ctx, UiVar *var) {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
449 // TODO
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
450 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
451
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
452
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
453 // public API
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
454
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
455 void ui_attach_document(UiContext *ctx, void *document) {
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
456 uic_context_attach_document(ctx, document);
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
457 }
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
458
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
459 void ui_detach_document2(UiContext *ctx, void *document) {
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
460 uic_context_detach_document2(ctx, document);
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
461 }
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
462
111
40dbf1a7526a added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
463 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
464 ctx->close_callback = fnc;
40dbf1a7526a added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
465 ctx->close_data = udata;
40dbf1a7526a added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
466 }
40dbf1a7526a added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
467
247
4b21af9d8c5a call context close handler on window close (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
468 UIEXPORT void ui_context_destroy(UiContext *ctx) {
4b21af9d8c5a call context close handler on window close (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
469 cxMempoolDestroy(ctx->mp);
4b21af9d8c5a call context close handler on window close (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
470 }
4b21af9d8c5a call context close handler on window close (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
471
20
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
472
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
473 void ui_set_group(UiContext *ctx, int group) {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
474 if(cxListFind(ctx->groups, &group) == -1) {
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
475 cxListAdd(ctx->groups, &group);
20
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
476 }
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
477
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
478 // enable/disable group widgets
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
479 uic_check_group_widgets(ctx);
20
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
480 }
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
481
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
482 void ui_unset_group(UiContext *ctx, int group) {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
483 int i = cxListFind(ctx->groups, &group);
20
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
484 if(i != -1) {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
485 cxListRemove(ctx->groups, i);
20
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
486 }
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
487
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
488 // enable/disable group widgets
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
489 uic_check_group_widgets(ctx);
20
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
490 }
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
491
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
492 int* ui_active_groups(UiContext *ctx, int *ngroups) {
325
99a93a9250c4 fix build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
493 *ngroups = cxListSize(ctx->groups);
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
494 return cxListAt(ctx->groups, 0);
20
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
495 }
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
496
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
497 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
498 int ngroups = 0;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
499 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
500
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
501 CxIterator i = cxListIterator(ctx->group_widgets);
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
502 cx_foreach(UiGroupWidget *, gw, i) {
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
503 char *check = calloc(1, gw->numgroups);
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
504
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
505 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
506 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
507 if(groups[i] == gw->groups[k]) {
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
508 check[k] = 1;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
509 }
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
510 }
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
511 }
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
512
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
513 int enable = 1;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
514 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
515 if(check[i] == 0) {
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
516 enable = 0;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
517 break;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
518 }
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
519 }
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
520 free(check);
168
1b99acacc5bb refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 167
diff changeset
521 gw->enable(gw->widget, enable);
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
522 }
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
523 }
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
524
168
1b99acacc5bb refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 167
diff changeset
525 void ui_widget_set_groups(UiContext *ctx, UIWIDGET widget, ui_enablefunc enable, ...) {
1b99acacc5bb refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 167
diff changeset
526 // get groups
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
527 CxList *groups = cxArrayListCreate(cxDefaultAllocator, NULL, sizeof(int), 16);
168
1b99acacc5bb refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 167
diff changeset
528 va_list ap;
1b99acacc5bb refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 167
diff changeset
529 va_start(ap, enable);
1b99acacc5bb refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 167
diff changeset
530 int group;
1b99acacc5bb refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 167
diff changeset
531 while((group = va_arg(ap, int)) != -1) {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
532 cxListAdd(groups, &group);
168
1b99acacc5bb refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 167
diff changeset
533 }
1b99acacc5bb refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 167
diff changeset
534 va_end(ap);
1b99acacc5bb refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 167
diff changeset
535
1b99acacc5bb refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 167
diff changeset
536 uic_add_group_widget(ctx, widget, enable, groups);
1b99acacc5bb refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 167
diff changeset
537
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
538 cxListDestroy(groups);
168
1b99acacc5bb refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 167
diff changeset
539 }
1b99acacc5bb refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 167
diff changeset
540
343
54f5d7eb1335 implement widget groups for buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 342
diff changeset
541 size_t uic_group_array_size(const int *groups) {
54f5d7eb1335 implement widget groups for buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 342
diff changeset
542 int i;
54f5d7eb1335 implement widget groups for buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 342
diff changeset
543 for(i=0;groups[i] >= 0;i++) { }
54f5d7eb1335 implement widget groups for buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 342
diff changeset
544 return i;
54f5d7eb1335 implement widget groups for buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 342
diff changeset
545 }
54f5d7eb1335 implement widget groups for buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 342
diff changeset
546
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
547 void uic_add_group_widget(UiContext *ctx, void *widget, ui_enablefunc enable, CxList *groups) {
343
54f5d7eb1335 implement widget groups for buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 342
diff changeset
548 uic_add_group_widget_i(ctx, widget, enable, cxListAt(groups, 0), cxListSize(groups));
54f5d7eb1335 implement widget groups for buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 342
diff changeset
549 }
54f5d7eb1335 implement widget groups for buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 342
diff changeset
550
54f5d7eb1335 implement widget groups for buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 342
diff changeset
551 void uic_add_group_widget_i(UiContext *ctx, void *widget, ui_enablefunc enable, const int *groups, size_t numgroups) {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
552 const CxAllocator *a = ctx->allocator;
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
553 UiGroupWidget gw;
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
554
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
555 gw.widget = widget;
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
556 gw.enable = enable;
343
54f5d7eb1335 implement widget groups for buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 342
diff changeset
557 gw.numgroups = numgroups;
54f5d7eb1335 implement widget groups for buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 342
diff changeset
558 gw.groups = cxCalloc(a, numgroups, sizeof(int));
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
559
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
560 // copy groups
343
54f5d7eb1335 implement widget groups for buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 342
diff changeset
561 if(groups) {
54f5d7eb1335 implement widget groups for buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 342
diff changeset
562 memcpy(gw.groups, groups, gw.numgroups * sizeof(int));
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
563 }
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
564
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
565 cxListAdd(ctx->group_widgets, &gw);
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
566 }
38
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
567
392
df62b7205bd3 fix UiList binding copy and missing GTK table setselection method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 387
diff changeset
568 void uic_remove_group_widget(UiContext *ctx, void *widget) {
df62b7205bd3 fix UiList binding copy and missing GTK table setselection method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 387
diff changeset
569 (void)cxListFindRemove(ctx->group_widgets, widget);
df62b7205bd3 fix UiList binding copy and missing GTK table setselection method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 387
diff changeset
570 }
df62b7205bd3 fix UiList binding copy and missing GTK table setselection method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 387
diff changeset
571
342
99f83fbf48e9 implement context destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 341
diff changeset
572 UIEXPORT void *ui_allocator(UiContext *ctx) {
387
80edb1a93f7a add public function for getting the UiContext UCX mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
573 return (void*)ctx->allocator;
80edb1a93f7a add public function for getting the UiContext UCX mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
574 }
80edb1a93f7a add public function for getting the UiContext UCX mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
575
80edb1a93f7a add public function for getting the UiContext UCX mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
576 void* ui_cx_mempool(UiContext *ctx) {
80edb1a93f7a add public function for getting the UiContext UCX mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
577 return ctx->mp;
341
c7427cadabd3 make ui_getappdir() and ui_configfile() public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 337
diff changeset
578 }
c7427cadabd3 make ui_getappdir() and ui_configfile() public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 337
diff changeset
579
38
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
580 void* ui_malloc(UiContext *ctx, size_t size) {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
581 return ctx ? cxMalloc(ctx->allocator, size) : NULL;
38
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
582 }
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
583
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
584 void* ui_calloc(UiContext *ctx, size_t nelem, size_t elsize) {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
585 return ctx ? cxCalloc(ctx->allocator, nelem, elsize) : NULL;
38
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
586 }
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
587
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
588 void ui_free(UiContext *ctx, void *ptr) {
350
70305d427f25 fix ui_scrolledwindow (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 343
diff changeset
589 if(ctx && ptr) {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
590 cxFree(ctx->allocator, ptr);
38
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
591 }
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
592 }
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
593
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
594 void* ui_realloc(UiContext *ctx, void *ptr, size_t size) {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
595 return ctx ? cxRealloc(ctx->allocator, ptr, size) : NULL;
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
596 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
597
342
99f83fbf48e9 implement context destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 341
diff changeset
598 UIEXPORT char* ui_strdup(UiContext *ctx, const char *str) {
99f83fbf48e9 implement context destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 341
diff changeset
599 if(!ctx) {
99f83fbf48e9 implement context destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 341
diff changeset
600 return NULL;
99f83fbf48e9 implement context destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 341
diff changeset
601 }
99f83fbf48e9 implement context destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 341
diff changeset
602 cxstring s = cx_str(str);
99f83fbf48e9 implement context destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 341
diff changeset
603 cxmutstr d = cx_strdup_a(ctx->allocator, s);
99f83fbf48e9 implement context destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 341
diff changeset
604 return d.ptr;
99f83fbf48e9 implement context destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 341
diff changeset
605 }

mercurial