ui/common/context.c

Mon, 19 May 2014 21:15:43 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 19 May 2014 21:15:43 +0200
changeset 48
0b8ac9d6d473
parent 39
4e66271541e8
child 52
25e5390cce41
permissions
-rw-r--r--

added threads (Cocoa)

0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2014 Olaf Wintermann. All rights reserved.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <string.h>
20
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
32 #include <inttypes.h>
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include "context.h"
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "../ui/window.h"
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
36 #include "document.h"
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 UiContext* uic_context(UiObject *toplevel, UcxMempool *mp) {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 UiContext *ctx = ucx_mempool_malloc(mp, sizeof(UiContext));
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 ctx->mempool = mp;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
43 ctx->obj = toplevel;
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
44 ctx->vars = ucx_map_new_a(mp->allocator, 16);
20
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
45 ctx->groups = NULL;
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
46 ctx->group_widgets = NULL;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47
18
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
48 #ifdef UI_GTK
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
49 ctx->accel_group = gtk_accel_group_new();
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
50 gtk_window_add_accel_group(GTK_WINDOW(toplevel->widget), ctx->accel_group);
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
51 #endif
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
52
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 return ctx;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
56 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
57 // check document variables first
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
58 UiVar *var = NULL;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
59 UiContext *doc_ctx = ui_document_context(ctx->document);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
60 if(doc_ctx) {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
61 var = uic_get_var(doc_ctx, name);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
62 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
63
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
64 // check variables of this context
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
65 if(!var) {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
66 var = ucx_map_cstr_get(ctx->vars, name);
1
eb5269000bc8 added some document functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
67 }
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
68
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
69 return var;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
72 UiVar* uic_connect_var(UiContext *ctx, char *name, int type) {
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
73 // TODO: get current map (Document Container, Tabbed Pane)
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
74 UcxMap *from = ctx->vars;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
75
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
76 UiVar *var = uic_get_var(ctx, name);
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
77 if(var) {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
78 // the value is registered
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
79
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
80 // a little type check
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
81 if(var->type != type) {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
82 fprintf(stderr, "UI Error: var %s has incompatible type.\n", name);
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
83 return NULL;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
84 } else {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
85 // register the current document/wdata map
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
86 // if the document is closed, the var will be moved to this map
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
87 var->from = from;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
88
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
89 return var;
1
eb5269000bc8 added some document functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
90 }
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
91 } else {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
92 // create an empty value and add it first to the window variables
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
93 // it can be moved to the document vars later
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
94 void *value = uic_create_value(ctx->mempool->allocator, type);
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
95 if(!value) {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
96 fprintf(stderr, "UI Error: Cannot create empty value.\n");
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
97 return NULL;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
98 }
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
99 UiVar *var = ucx_mempool_malloc(ctx->mempool, sizeof(UiVar));
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
100 var->value = value;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
101 var->type = type;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
102 var->isextern = 0;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
103 var->from = from;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
104 ucx_map_cstr_put(ctx->vars, name, var);
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
105 return var;
1
eb5269000bc8 added some document functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
106 }
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
109 void uic_move_var(UiVar *from, UiVar *to, int set) {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
110 switch(from->type) {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
111 case UI_VAR_INTEGER: {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
112 //memcpy(to->value, from->value, sizeof(UiInteger));
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
113 UiInteger *f = from->value;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
114 UiInteger *t = to->value;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
115 t->get = f->get;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
116 t->set = f->set;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
117 t->obj = f->obj;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
118 if(set) {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
119 t->set(t, t->value);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
120 } else {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
121 //t->value = t->get(t);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
122 f->value = f->get(f);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
123 //t->value = 0;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
124 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
125 break;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
126 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
127 case UI_VAR_STRING: {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
128 // TODO
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
129 break;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
130 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
131 case UI_VAR_TEXT: {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
132 UiText *f = from->value;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
133 UiText *t = to->value;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
134 char *tvalue = t->value;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
135 memcpy(t, f, sizeof(UiText));
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
136 if(set) {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
137 t->set(t, tvalue);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
138 } else {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
139 f->value = f->get(f);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
140 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
141 break;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
142 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
143 case UI_VAR_LIST: {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
144 UiListVar *f = from->value;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
145 UiListVar *t = to->value;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
146 UiList *list = t->listptr->list;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
147 UiObserver *observers = f->listptr->list->observers;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
148 t->listptr = f->listptr;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
149 if(set) {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
150 t->listptr->list = list;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
151 list->observers = observers;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
152 ui_notify(observers, list);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
153 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
154 break;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
155 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
156 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
157 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
158
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
159 void uic_reg_var(UiContext *ctx, char *name, int type, size_t vs, void *value) {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
160 UiVar *newvar = ucx_mempool_malloc(ctx->mempool, sizeof(UiVar));
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
161 newvar->isextern = 1;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
162 newvar->type = type;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
163 newvar->value = value;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
164 newvar->from = NULL;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
165
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
166 uic_add_var(ctx, name, newvar, type, vs);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
167 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
168
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
169 void uic_add_var(
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
170 UiContext *ctx,
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
171 char *name,
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
172 UiVar *newvar,
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
173 int type,
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
174 size_t vs)
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
175 {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
176 // if a parent context has a variable with this name, we remove it and put
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
177 // it to this context
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
178 UiVar *var = ctx->obj ? uic_get_var(ctx->obj->ctx, name) : NULL;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
179
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
180 if(var && var->from != ctx->vars) {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
181 // external variables cannot be moved
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
182 if(var->isextern) {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
183 fprintf(
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
184 stderr,
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
185 "UI Error: external variable %s "
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
186 "cannot be moved to the document.\n",
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
187 name);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
188 return;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
189 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
190
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
191 // check type
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
192 if(var->type != type) {
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
193 fprintf(stderr, "UI Error: var %s has incompatible type.\n", name);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
194 return;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
195 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
196
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
197 // override document var with window context var
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
198 memcpy(newvar->value, var->value, vs);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
199
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
200 newvar->from = var->from;
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
201
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
202 // TODO: free var struct
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
203 ucx_map_cstr_remove(var->from, name);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
204 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
205
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
206 // finally, add the new variable to the document
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
207 ucx_map_cstr_put(ctx->vars, name, newvar);
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
208 }
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
209
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
210 void* uic_create_value(UcxAllocator *a, int type) {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
211 switch(type) {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
212 case UI_VAR_INTEGER: {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
213 UiInteger *i = a->calloc(
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
214 a->pool,
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
215 1,
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
216 sizeof(UiInteger));
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
217 return i;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
218 }
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
219 case UI_VAR_STRING: {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
220 UiString *s = a->calloc(
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
221 a->pool,
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
222 1,
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
223 sizeof(UiInteger));
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
224 return s;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
225 }
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
226 case UI_VAR_TEXT: {
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
227 UiText *t = a->calloc(
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
228 a->pool,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
229 1,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
230 sizeof(UiText));
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
231 return t;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
232 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
233 case UI_VAR_LIST: {
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
234 UiListVar *l = a->malloc(a->pool, sizeof(UiListVar));
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
235 UiListPtr *lp = a->malloc(a->pool, sizeof(UiListPtr));
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
236 l->listptr = lp;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
237 lp->list = NULL;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
238 // TODO: create empty list
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
239 return l;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
240 }
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241 }
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
242 return NULL;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
245 // public API
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
246
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
247 int ui_getint(UiObject *obj, char *name) {
37
56016468753d refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
248 UiVar *var = uic_get_var(obj->ctx, name);
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
249 if(var) {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
250 if(var->type == UI_VAR_INTEGER) {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
251 UiInteger *i = var->value;
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
252 if(i->get) {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
253 return i->get(i);
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
254 } else {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
255 fprintf(
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
256 stderr,
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
257 "UI Error: variable %s is not connected.\n",
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
258 name);
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
259 }
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
260 } else {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
261 fprintf(
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
262 stderr,
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
263 "UI Error: requested variable %s is not an integer.\n",
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
264 name);
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
265 }
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
266 } else {
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
267 fprintf(stderr, "UI Error: unkown variable %s.\n", name);
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268 }
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
269 return 0;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271
20
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
272
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
273
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
274
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
275 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
276 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
277 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
278 }
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
279
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
280 // enable/disable group widgets
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
281 uic_check_group_widgets(ctx);
20
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
282 }
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
283
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
284 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
285 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
286 if(i != -1) {
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
287 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
288 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
289 }
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
290
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
291 // enable/disable group widgets
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
292 uic_check_group_widgets(ctx);
20
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
293 }
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
294
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
295 int* ui_active_groups(UiContext *ctx, int *ngroups) {
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
296 int nelm = ucx_list_size(ctx->groups);
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
297 int *groups = calloc(sizeof(int), nelm);
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
298
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
299 int i = 0;
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
300 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
301 groups[i++] = (intptr_t)elm->data;
20
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
302 }
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
303
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
304 *ngroups = nelm;
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
305 return groups;
2dda1ad6dc7a added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
306 }
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
307
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
308 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
309 int ngroups = 0;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
310 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
311
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
312 UCX_FOREACH(elm, ctx->group_widgets) {
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
313 UiGroupWidget *gw = elm->data;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
314 char *check = calloc(1, gw->numgroups);
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
315
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
316 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
317 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
318 if(groups[i] == gw->groups[k]) {
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
319 check[k] = 1;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
320 }
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
321 }
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
322 }
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
323
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
324 int enable = 1;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
325 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
326 if(check[i] == 0) {
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
327 enable = 0;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
328 break;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
329 }
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
330 }
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
331 ui_set_enabled(gw->widget, enable);
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
332 }
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
333
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
334 free(groups);
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
335 }
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
336
25
78ae3efe463f added groups for toolbar items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
337 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
338 UcxMempool *mp = ctx->mempool;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
339 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
340
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
341 gw->widget = widget;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
342 gw->numgroups = ucx_list_size(groups);
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
343 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
344 int i = 0;
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
345 UCX_FOREACH(elm, groups) {
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
346 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
347 }
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
348
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
349 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
350 mp->allocator,
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
351 ctx->group_widgets,
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
352 gw);
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
353 }
38
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
354
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
355 void* ui_malloc(UiContext *ctx, size_t size) {
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
356 return ctx ? ucx_mempool_malloc(ctx->mempool, size) : NULL;
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
357 }
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
358
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
359 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
360 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
361 }
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
362
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
363 void ui_free(UiContext *ctx, void *ptr) {
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
364 if(ctx) {
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
365 ucx_mempool_free(ctx->mempool, ptr);
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
366 }
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
367 }
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
368
8ccdde37275b added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
369 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
370 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
371 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
372

mercurial