Sun, 07 Dec 2025 19:20:48 +0100
implement radiobutton (Client)
| 0 | 1 | /* |
| 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
| 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 | 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without | |
| 7 | * modification, are permitted provided that the following conditions are met: | |
| 8 | * | |
| 9 | * 1. Redistributions of source code must retain the above copyright | |
| 10 | * notice, this list of conditions and the following disclaimer. | |
| 11 | * | |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
| 13 | * notice, this list of conditions and the following disclaimer in the | |
| 14 | * documentation and/or other materials provided with the distribution. | |
| 15 | * | |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
| 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 26 | * POSSIBILITY OF SUCH DAMAGE. | |
| 27 | */ | |
| 28 | ||
| 29 | #include <stdio.h> | |
| 30 | #include <stdlib.h> | |
| 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 | 34 | |
| 174 | 35 | #include <cx/array_list.h> |
| 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 | 38 | |
| 0 | 39 | #include "context.h" |
| 40 | #include "../ui/window.h" | |
|
793
f33f05cd0548
add missing widget.h include
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
775
diff
changeset
|
41 | #include "../ui/widget.h" |
|
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
42 | #include "document.h" |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
43 | #include "types.h" |
| 0 | 44 | |
|
379
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
45 | |
|
167
161511838ea6
add new toolbar toggle button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
164
diff
changeset
|
46 | static UiContext* global_context; |
|
161511838ea6
add new toolbar toggle button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
164
diff
changeset
|
47 | |
|
161511838ea6
add new toolbar toggle button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
164
diff
changeset
|
48 | void uic_init_global_context(void) { |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
49 | CxMempool *mp = cxMempoolCreateSimple(32); |
|
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
50 | global_context = uic_context(NULL, mp); |
|
167
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 | |
|
161511838ea6
add new toolbar toggle button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
164
diff
changeset
|
53 | UiContext* ui_global_context(void) { |
|
161511838ea6
add new toolbar toggle button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
164
diff
changeset
|
54 | return global_context; |
|
161511838ea6
add new toolbar toggle button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
164
diff
changeset
|
55 | } |
| 0 | 56 | |
|
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
57 | UiContext* uic_context(UiObject *toplevel, CxMempool *mp) { |
|
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
58 | 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
|
59 | memset(ctx, 0, sizeof(UiContext)); |
|
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
60 | ctx->mp = mp; |
|
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
61 | ctx->allocator = mp->allocator; |
|
557
e6415fd4af4b
implement new menu itemlist binding (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
62 | ctx->destroy_handler = cxArrayListCreate(ctx->allocator, NULL, sizeof(UiDestroyHandler), 16); |
|
37
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
63 | ctx->obj = toplevel; |
|
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
64 | ctx->vars = cxHashMapCreate(mp->allocator, CX_STORE_POINTERS, 16); |
| 174 | 65 | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
66 | ctx->documents = cxLinkedListCreate(mp->allocator, cx_cmp_ptr, CX_STORE_POINTERS); |
|
966
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
67 | ctx->state_widgets = cxLinkedListCreate(mp->allocator, cx_cmp_ptr, sizeof(UiStateWidget)); |
|
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
68 | ctx->states = cxArrayListCreate(mp->allocator, cx_cmp_int, sizeof(int), 32); |
| 0 | 69 | |
|
163
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
70 | ctx->attach_document = uic_context_attach_document; |
|
623
1ebc781c7d17
rename ui_detach_document2 to ui_detach_document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
622
diff
changeset
|
71 | ctx->detach_document2 = uic_context_detach_document; |
|
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
72 | |
|
293
736c962f1011
initial gtk4 porting, incomplete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
73 | #if UI_GTK2 || UI_GTK3 |
|
167
161511838ea6
add new toolbar toggle button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
164
diff
changeset
|
74 | if(toplevel && toplevel->widget) { |
|
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
75 | ctx->accel_group = gtk_accel_group_new(); |
|
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
76 | 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
|
77 | } |
|
18
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
78 | #endif |
|
06be29a56f8b
added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
79 | |
| 0 | 80 | return ctx; |
| 81 | } | |
| 82 | ||
|
128
c284c15509a8
fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
83 | UiContext* uic_root_context(UiContext *ctx) { |
|
c284c15509a8
fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
84 | 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
|
85 | } |
|
c284c15509a8
fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
86 | |
|
557
e6415fd4af4b
implement new menu itemlist binding (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
87 | void uic_context_add_destructor(UiContext *ctx, cx_destructor_func func, void *data) { |
|
e6415fd4af4b
implement new menu itemlist binding (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
88 | UiDestroyHandler handler; |
|
e6415fd4af4b
implement new menu itemlist binding (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
89 | handler.destructor = func; |
|
e6415fd4af4b
implement new menu itemlist binding (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
90 | handler.data = data; |
|
e6415fd4af4b
implement new menu itemlist binding (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
91 | cxListAdd(ctx->destroy_handler, &handler); |
|
e6415fd4af4b
implement new menu itemlist binding (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
92 | } |
|
e6415fd4af4b
implement new menu itemlist binding (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
93 | |
|
365
004b5dd01f6a
clear context states before closing a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
94 | void uic_context_prepare_close(UiContext *ctx) { |
|
966
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
95 | cxListClear(ctx->states); |
|
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
96 | cxListClear(ctx->state_widgets); |
|
365
004b5dd01f6a
clear context states before closing a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
97 | } |
|
004b5dd01f6a
clear context states before closing a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
98 | |
|
163
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
99 | void uic_context_attach_document(UiContext *ctx, void *document) { |
|
960
e88ca7dfa943
add single-document-mode to UiContext
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
916
diff
changeset
|
100 | if(ctx->single_document_mode) { |
|
e88ca7dfa943
add single-document-mode to UiContext
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
916
diff
changeset
|
101 | if(ctx->document) { |
|
e88ca7dfa943
add single-document-mode to UiContext
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
916
diff
changeset
|
102 | uic_context_detach_document(ctx, ctx->document); |
|
e88ca7dfa943
add single-document-mode to UiContext
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
916
diff
changeset
|
103 | } |
|
e88ca7dfa943
add single-document-mode to UiContext
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
916
diff
changeset
|
104 | } |
|
e88ca7dfa943
add single-document-mode to UiContext
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
916
diff
changeset
|
105 | |
| 174 | 106 | cxListAdd(ctx->documents, document); |
| 107 | ctx->document = document; | |
|
163
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
108 | |
|
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
109 | UiContext *doc_ctx = ui_document_context(document); |
|
474
971dd0f3a117
fix UiContext detaching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
110 | doc_ctx->parent = ctx; |
|
131
774b741984a2
detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
111 | |
|
796
4d04cb879daa
remove separate ctx vars_unbound map
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
793
diff
changeset
|
112 | // if a document variable has the same name as a parent variable, |
|
4d04cb879daa
remove separate ctx vars_unbound map
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
793
diff
changeset
|
113 | // move the bindings to the document |
|
163
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
114 | UiContext *var_ctx = ctx; |
|
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
115 | while(var_ctx) { |
|
796
4d04cb879daa
remove separate ctx vars_unbound map
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
793
diff
changeset
|
116 | CxMapIterator i = cxMapIterator(var_ctx->vars); |
|
4d04cb879daa
remove separate ctx vars_unbound map
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
793
diff
changeset
|
117 | cx_foreach(CxMapEntry*, entry, i) { |
|
813
6d9066951cdb
implement ui_show (win32)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
796
diff
changeset
|
118 | printf("attach %.*s\n", (int)entry->key->len, (char*)entry->key->data); |
|
796
4d04cb879daa
remove separate ctx vars_unbound map
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
793
diff
changeset
|
119 | UiVar *var = entry->value; |
|
4d04cb879daa
remove separate ctx vars_unbound map
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
793
diff
changeset
|
120 | UiVar *docvar = cxMapGet(doc_ctx->vars, *entry->key); |
|
4d04cb879daa
remove separate ctx vars_unbound map
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
793
diff
changeset
|
121 | if(docvar) { |
|
4d04cb879daa
remove separate ctx vars_unbound map
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
793
diff
changeset
|
122 | // bind var to document var |
|
902
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
123 | uic_copy_var_binding(var, docvar, TRUE); |
|
796
4d04cb879daa
remove separate ctx vars_unbound map
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
793
diff
changeset
|
124 | cxIteratorFlagRemoval(i); |
|
163
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
125 | } |
|
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
126 | } |
|
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
127 | |
|
474
971dd0f3a117
fix UiContext detaching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
128 | var_ctx = var_ctx->parent; |
|
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
129 | } |
|
163
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
130 | } |
|
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
131 | |
|
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
132 | static void uic_context_unbind_vars(UiContext *ctx) { |
|
906
edfdf9776da9
disable onchange events when detaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
905
diff
changeset
|
133 | ui_onchange_events_enable(FALSE); |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
134 | CxMapIterator mi = cxMapIterator(ctx->vars); |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
135 | cx_foreach(CxMapEntry*, entry, mi) { |
|
906
edfdf9776da9
disable onchange events when detaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
905
diff
changeset
|
136 | printf("detach %.*s\n", (int)entry->key->len, (char*)entry->key->data); |
| 174 | 137 | UiVar *var = entry->value; |
|
553
90e38db0c755
rework uic_copy_binding and refactore menu itemlists to bind directly to lists without using observers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
507
diff
changeset
|
138 | // var->from && var->from_ctx && var->from_ctx != ctx |
|
796
4d04cb879daa
remove separate ctx vars_unbound map
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
793
diff
changeset
|
139 | uic_save_var(var); |
|
553
90e38db0c755
rework uic_copy_binding and refactore menu itemlists to bind directly to lists without using observers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
507
diff
changeset
|
140 | if(var->from) { |
|
902
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
141 | uic_copy_var_binding(var, var->from, FALSE); |
|
796
4d04cb879daa
remove separate ctx vars_unbound map
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
793
diff
changeset
|
142 | cxMapPut(var->from->from_ctx->vars, *entry->key, var->from); |
|
553
90e38db0c755
rework uic_copy_binding and refactore menu itemlists to bind directly to lists without using observers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
507
diff
changeset
|
143 | var->from = NULL; |
|
163
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
144 | } |
|
906
edfdf9776da9
disable onchange events when detaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
905
diff
changeset
|
145 | uic_unbind_var(var); |
|
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
146 | } |
|
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
147 | |
| 174 | 148 | if(ctx->documents) { |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
149 | CxIterator i = cxListIterator(ctx->documents); |
| 174 | 150 | cx_foreach(void *, doc, i) { |
| 151 | UiContext *subctx = ui_document_context(doc); | |
| 152 | uic_context_unbind_vars(subctx); | |
| 153 | } | |
|
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
154 | } |
|
906
edfdf9776da9
disable onchange events when detaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
905
diff
changeset
|
155 | |
|
edfdf9776da9
disable onchange events when detaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
905
diff
changeset
|
156 | ui_onchange_events_enable(TRUE); |
|
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
157 | } |
|
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
158 | |
|
623
1ebc781c7d17
rename ui_detach_document2 to ui_detach_document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
622
diff
changeset
|
159 | void uic_context_detach_document(UiContext *ctx, void *document) { |
|
163
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
160 | // find the document in the documents list |
|
476
31213068c2ba
fix build (WINUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
161 | size_t docIndex = cxListFind(ctx->documents, document); |
|
31213068c2ba
fix build (WINUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
474
diff
changeset
|
162 | if(!cxListIndexValid(ctx->documents, docIndex)) { |
| 174 | 163 | return; |
|
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
164 | } |
|
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
165 | |
| 174 | 166 | cxListRemove(ctx->documents, docIndex); |
| 167 | ctx->document = cxListAt(ctx->documents, 0); | |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
168 | |
|
163
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
169 | UiContext *docctx = ui_document_context(document); |
|
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
170 | uic_context_unbind_vars(docctx); // unbind all doc/subdoc vars from the parent |
|
474
971dd0f3a117
fix UiContext detaching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
171 | docctx->parent = NULL; |
|
163
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
172 | } |
|
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
173 | |
|
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
174 | void uic_context_detach_all(UiContext *ctx) { |
| 174 | 175 | // copy list |
| 176 | CxList *ls = cxLinkedListCreate(cxDefaultAllocator, NULL, CX_STORE_POINTERS); | |
| 177 | CxIterator i = cxListIterator(ctx->documents); | |
| 178 | cx_foreach(void *, doc, i) { | |
| 179 | cxListAdd(ls, doc); | |
|
163
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
180 | } |
| 174 | 181 | |
| 182 | // detach documents | |
| 183 | i = cxListIterator(ls); | |
| 184 | cx_foreach(void *, doc, i) { | |
| 185 | ctx->detach_document2(ctx, doc); | |
| 186 | } | |
| 187 | ||
| 440 | 188 | cxListFree(ls); |
|
163
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
189 | } |
|
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
190 | |
| 174 | 191 | static UiVar* ctx_getvar(UiContext *ctx, CxHashKey key) { |
| 192 | UiVar *var = cxMapGet(ctx->vars, key); | |
|
335
91d4f0391282
add new textarea (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
325
diff
changeset
|
193 | if(!var && ctx->documents) { |
| 174 | 194 | CxIterator i = cxListIterator(ctx->documents); |
| 195 | cx_foreach(void *, doc, i) { | |
| 196 | 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
|
197 | var = ctx_getvar(subctx, key); |
|
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
198 | if(var) { |
|
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
199 | break; |
|
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
200 | } |
|
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
201 | } |
|
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
202 | } |
|
163
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
203 | return var; |
|
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
204 | } |
|
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
205 | |
|
167
161511838ea6
add new toolbar toggle button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
164
diff
changeset
|
206 | UiVar* uic_get_var(UiContext *ctx, const char *name) { |
| 174 | 207 | 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
|
208 | return ctx_getvar(ctx, key); |
| 0 | 209 | } |
| 210 | ||
|
976
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
211 | UiVar* uic_get_var_t(UiContext *ctx,const char *name, UiVarType type) { |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
212 | UiVar *var = uic_get_var(ctx, name); |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
213 | if(var && var->type == type) { |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
214 | return var; |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
215 | } |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
216 | return NULL; |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
217 | } |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
218 | |
|
167
161511838ea6
add new toolbar toggle button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
164
diff
changeset
|
219 | UiVar* uic_create_var(UiContext *ctx, const char *name, UiVarType type) { |
|
163
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
220 | 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
|
221 | if(var) { |
|
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
222 | if(var->type == type) { |
|
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
223 | return var; |
|
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
224 | } else { |
|
163
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
225 | 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
|
226 | } |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
227 | } |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
228 | |
|
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
229 | var = ui_malloc(ctx, sizeof(UiVar)); |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
230 | var->type = type; |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
231 | var->value = uic_create_value(ctx, type); |
|
553
90e38db0c755
rework uic_copy_binding and refactore menu itemlists to bind directly to lists without using observers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
507
diff
changeset
|
232 | var->original_value = NULL; |
|
163
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
233 | var->from = NULL; |
|
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
234 | var->from_ctx = ctx; |
|
902
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
235 | var->bound = FALSE; |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
236 | |
|
906
edfdf9776da9
disable onchange events when detaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
905
diff
changeset
|
237 | cxMempoolSetDestructor(var, (cx_destructor_func)uic_unbind_var); // TODO: use another destructor that cleans the value (UiString free, UiText destroy, ...) |
|
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
238 | |
|
796
4d04cb879daa
remove separate ctx vars_unbound map
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
793
diff
changeset
|
239 | cxMapPut(ctx->vars, name, var); |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
240 | |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
241 | return var; |
| 0 | 242 | } |
| 243 | ||
|
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
244 | UiVar* uic_create_value_var(UiContext* ctx, void* value) { |
|
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
245 | UiVar *var = (UiVar*)ui_malloc(ctx, sizeof(UiVar)); |
|
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
246 | var->from = NULL; |
|
350
70305d427f25
fix ui_scrolledwindow (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
343
diff
changeset
|
247 | var->from_ctx = ctx; |
|
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
248 | var->value = value; |
|
553
90e38db0c755
rework uic_copy_binding and refactore menu itemlists to bind directly to lists without using observers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
507
diff
changeset
|
249 | var->original_value = NULL; |
|
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
250 | var->type = UI_VAR_SPECIAL; |
|
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
251 | return var; |
|
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
252 | } |
|
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
253 | |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
254 | void* uic_create_value(UiContext *ctx, UiVarType type) { |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
255 | void *val = NULL; |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
256 | switch(type) { |
|
164
1d912f78fd1d
fix some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
163
diff
changeset
|
257 | case UI_VAR_SPECIAL: break; |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
258 | case UI_VAR_INTEGER: { |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
259 | val = ui_int_new(ctx, NULL); |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
260 | break; |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
261 | } |
|
145
853685152c1d
adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
143
diff
changeset
|
262 | case UI_VAR_DOUBLE: { |
|
853685152c1d
adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
143
diff
changeset
|
263 | val = ui_double_new(ctx, NULL); |
|
853685152c1d
adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
143
diff
changeset
|
264 | break; |
|
853685152c1d
adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
143
diff
changeset
|
265 | } |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
266 | case UI_VAR_STRING: { |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
267 | val = ui_string_new(ctx, NULL); |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
268 | break; |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
269 | } |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
270 | case UI_VAR_TEXT: { |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
271 | val = ui_text_new(ctx, NULL); |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
272 | break; |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
273 | } |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
274 | 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
|
275 | val = ui_list_new(ctx, NULL); |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
276 | break; |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
277 | } |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
278 | case UI_VAR_RANGE: { |
|
145
853685152c1d
adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
143
diff
changeset
|
279 | val = ui_range_new(ctx, NULL); |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
280 | break; |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
281 | } |
|
337
2904fba2708b
add UiGeneric var type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
335
diff
changeset
|
282 | case UI_VAR_GENERIC: { |
|
2904fba2708b
add UiGeneric var type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
335
diff
changeset
|
283 | val = ui_generic_new(ctx, NULL); |
|
2904fba2708b
add UiGeneric var type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
335
diff
changeset
|
284 | } |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
285 | } |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
286 | return val; |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
287 | } |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
288 | |
|
902
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
289 | // destroys a value, that was created by uic_create_value |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
290 | void uic_destroy_value(UiContext *ctx, UiVarType type, void *value) { |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
291 | switch(type) { |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
292 | default: { |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
293 | ui_free(ctx, value); |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
294 | break; |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
295 | } |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
296 | case UI_VAR_SPECIAL: break; |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
297 | case UI_VAR_STRING: { |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
298 | UiString *s = value; |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
299 | if(s->value.free) { |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
300 | s->value.free(s->value.ptr); |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
301 | } |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
302 | ui_free(ctx, value); |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
303 | } |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
304 | case UI_VAR_TEXT: { |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
305 | UiText *t = value; |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
306 | if(t->value.free) { |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
307 | t->value.free(t->value.ptr); |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
308 | t->value.free = NULL; |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
309 | t->value.ptr = NULL; |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
310 | } |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
311 | if(t->destroy) { |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
312 | t->destroy(t); |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
313 | } |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
314 | ui_free(ctx, value); |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
315 | } |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
316 | case UI_VAR_LIST: { |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
317 | ui_list_free(ctx, value); |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
318 | break; |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
319 | } |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
320 | } |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
321 | } |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
322 | |
|
192
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
323 | |
|
796
4d04cb879daa
remove separate ctx vars_unbound map
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
793
diff
changeset
|
324 | UiVar* uic_widget_var(UiContext *toplevel, UiContext *current, void *value, const char *varname, UiVarType type) { |
|
192
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
325 | if (value) { |
|
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
326 | return uic_create_value_var(current, value); |
|
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
327 | } |
|
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
328 | if (varname) { |
|
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
329 | return uic_create_var(toplevel, varname, type); |
|
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
330 | } |
|
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
331 | return NULL; |
|
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
332 | } |
|
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
333 | |
|
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
334 | |
|
902
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
335 | void uic_copy_var_binding(UiVar *from, UiVar *to, UiBool copytodoc) { |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
336 | // check type |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
337 | if(from->type != to->type) { |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
338 | fprintf(stderr, "UI Error: var has incompatible type.\n"); |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
339 | return; |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
340 | } |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
341 | |
|
146
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
145
diff
changeset
|
342 | void *fromvalue = from->value; |
|
553
90e38db0c755
rework uic_copy_binding and refactore menu itemlists to bind directly to lists without using observers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
507
diff
changeset
|
343 | void *tovalue = to->value; |
|
146
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
145
diff
changeset
|
344 | // update var |
|
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
145
diff
changeset
|
345 | if(copytodoc) { |
|
553
90e38db0c755
rework uic_copy_binding and refactore menu itemlists to bind directly to lists without using observers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
507
diff
changeset
|
346 | to->from = from; // from which UiVar are the bindings copied |
|
90e38db0c755
rework uic_copy_binding and refactore menu itemlists to bind directly to lists without using observers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
507
diff
changeset
|
347 | from->original_value = fromvalue; // save original value otherwise it would be lost |
|
90e38db0c755
rework uic_copy_binding and refactore menu itemlists to bind directly to lists without using observers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
507
diff
changeset
|
348 | // widgets store a reference to the UiVar with their value |
|
90e38db0c755
rework uic_copy_binding and refactore menu itemlists to bind directly to lists without using observers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
507
diff
changeset
|
349 | // the UiVar object must be updated to contain the current value object |
|
90e38db0c755
rework uic_copy_binding and refactore menu itemlists to bind directly to lists without using observers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
507
diff
changeset
|
350 | from->value = tovalue; |
|
90e38db0c755
rework uic_copy_binding and refactore menu itemlists to bind directly to lists without using observers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
507
diff
changeset
|
351 | } else { |
|
90e38db0c755
rework uic_copy_binding and refactore menu itemlists to bind directly to lists without using observers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
507
diff
changeset
|
352 | if(to->original_value) { |
|
90e38db0c755
rework uic_copy_binding and refactore menu itemlists to bind directly to lists without using observers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
507
diff
changeset
|
353 | to->value = to->original_value; |
|
90e38db0c755
rework uic_copy_binding and refactore menu itemlists to bind directly to lists without using observers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
507
diff
changeset
|
354 | tovalue = to->value; |
|
90e38db0c755
rework uic_copy_binding and refactore menu itemlists to bind directly to lists without using observers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
507
diff
changeset
|
355 | } |
|
146
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
145
diff
changeset
|
356 | } |
|
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
145
diff
changeset
|
357 | |
|
906
edfdf9776da9
disable onchange events when detaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
905
diff
changeset
|
358 | uic_copy_value_binding(from->type, fromvalue, tovalue); |
|
902
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
359 | } |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
360 | |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
361 | void uic_copy_value_binding(UiVarType type, void *from, void *to) { |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
362 | ui_setop_enable(TRUE); |
|
507
7f380a3ac9a1
enable setop in uic_copy_binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
492
diff
changeset
|
363 | |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
364 | // copy binding |
|
902
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
365 | // we don't copy the observer, because the from value never has oberservers |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
366 | switch(type) { |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
367 | default: fprintf(stderr, "uic_copy_binding: wtf!\n"); break; |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
368 | case UI_VAR_SPECIAL: break; |
|
37
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
369 | case UI_VAR_INTEGER: { |
|
902
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
370 | UiInteger *f = from; |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
371 | UiInteger *t = to; |
|
143
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
372 | if(!f->obj) break; |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
373 | 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
|
374 | t->set(t, t->value); |
|
37
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
375 | break; |
|
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
376 | } |
|
145
853685152c1d
adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
143
diff
changeset
|
377 | case UI_VAR_DOUBLE: { |
|
902
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
378 | UiDouble *f = from; |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
379 | UiDouble *t = to; |
|
145
853685152c1d
adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
143
diff
changeset
|
380 | if(!f->obj) break; |
|
853685152c1d
adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
143
diff
changeset
|
381 | uic_double_copy(f, t); |
|
853685152c1d
adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
143
diff
changeset
|
382 | t->set(t, t->value); |
|
853685152c1d
adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
143
diff
changeset
|
383 | break; |
|
853685152c1d
adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
143
diff
changeset
|
384 | } |
|
37
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
385 | case UI_VAR_STRING: { |
|
902
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
386 | UiString *f = from; |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
387 | UiString *t = to; |
|
143
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
388 | if(!f->obj) break; |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
389 | uic_string_copy(f, t); |
|
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
390 | char *tvalue = t->value.ptr ? t->value.ptr : ""; |
|
553
90e38db0c755
rework uic_copy_binding and refactore menu itemlists to bind directly to lists without using observers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
507
diff
changeset
|
391 | char *fvalue = f->value.ptr ? f->value.ptr : ""; |
|
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
392 | t->set(t, tvalue); |
|
37
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
393 | break; |
|
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
394 | } |
|
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
395 | case UI_VAR_TEXT: { |
|
902
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
396 | UiText *f = from; |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
397 | UiText *t = to; |
|
143
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
398 | if(!f->obj) break; |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
399 | uic_text_copy(f, t); |
|
486
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
476
diff
changeset
|
400 | t->restore(t); |
|
37
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
401 | break; |
|
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
402 | } |
|
553
90e38db0c755
rework uic_copy_binding and refactore menu itemlists to bind directly to lists without using observers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
507
diff
changeset
|
403 | case UI_VAR_LIST: { |
|
902
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
404 | UiList *f = from; |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
405 | UiList *t = to; |
|
553
90e38db0c755
rework uic_copy_binding and refactore menu itemlists to bind directly to lists without using observers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
507
diff
changeset
|
406 | uic_list_copy(f, t); |
|
90e38db0c755
rework uic_copy_binding and refactore menu itemlists to bind directly to lists without using observers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
507
diff
changeset
|
407 | ui_list_update(t); |
|
150
5cee4cb5ad79
fixes uic_copy_binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
408 | break; |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
409 | } |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
410 | case UI_VAR_RANGE: { |
|
902
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
411 | UiRange *f = from; |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
412 | UiRange *t = to; |
|
143
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
413 | if(!f->obj) break; |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
414 | uic_range_copy(f, t); |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
415 | t->setextent(t, t->extent); |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
416 | t->setrange(t, t->min, t->max); |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
417 | t->set(t, t->value); |
|
150
5cee4cb5ad79
fixes uic_copy_binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
418 | break; |
|
37
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
419 | } |
|
337
2904fba2708b
add UiGeneric var type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
335
diff
changeset
|
420 | case UI_VAR_GENERIC: { |
|
902
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
421 | UiGeneric *f = from; |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
422 | UiGeneric *t = to; |
|
337
2904fba2708b
add UiGeneric var type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
335
diff
changeset
|
423 | if(!f->obj) break; |
|
2904fba2708b
add UiGeneric var type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
335
diff
changeset
|
424 | uic_generic_copy(f, t); |
|
2904fba2708b
add UiGeneric var type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
335
diff
changeset
|
425 | t->set(t, t->value, t->type); |
|
2904fba2708b
add UiGeneric var type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
335
diff
changeset
|
426 | break; |
|
2904fba2708b
add UiGeneric var type
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
335
diff
changeset
|
427 | } |
|
37
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
428 | } |
|
507
7f380a3ac9a1
enable setop in uic_copy_binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
492
diff
changeset
|
429 | |
|
7f380a3ac9a1
enable setop in uic_copy_binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
492
diff
changeset
|
430 | ui_setop_enable(FALSE); |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
431 | } |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
432 | |
|
796
4d04cb879daa
remove separate ctx vars_unbound map
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
793
diff
changeset
|
433 | void uic_save_var(UiVar *var) { |
|
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
434 | switch(var->type) { |
|
163
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
435 | case UI_VAR_SPECIAL: break; |
|
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
436 | 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
|
437 | 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
|
438 | 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
|
439 | 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
|
440 | case UI_VAR_LIST: break; |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
441 | 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
|
442 | 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
|
443 | } |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
444 | } |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
445 | |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
446 | void uic_unbind_var(UiVar *var) { |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
447 | switch(var->type) { |
|
164
1d912f78fd1d
fix some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
163
diff
changeset
|
448 | case UI_VAR_SPECIAL: break; |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
449 | 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
|
450 | 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
|
451 | 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
|
452 | 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
|
453 | 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
|
454 | 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
|
455 | 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
|
456 | } |
|
37
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
457 | } |
|
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
458 | |
|
902
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
459 | const char *uic_type2str(UiVarType type) { |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
460 | switch(type) { |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
461 | default: return ""; |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
462 | case UI_VAR_INTEGER: return "int"; |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
463 | case UI_VAR_DOUBLE: return "double"; |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
464 | case UI_VAR_STRING: return "string"; |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
465 | case UI_VAR_TEXT: return "text"; |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
466 | case UI_VAR_LIST: return "list"; |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
467 | case UI_VAR_RANGE: return "range"; |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
468 | case UI_VAR_GENERIC: return "generic"; |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
469 | } |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
470 | } |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
471 | |
|
622
9090faa4094b
make var name parameters const
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
557
diff
changeset
|
472 | void uic_reg_var(UiContext *ctx, const char *name, UiVarType type, void *value) { |
|
902
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
473 | UiVar *var = cxMapGet(ctx->vars, name); |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
474 | if(!var) { |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
475 | // create new var and add it to the context var map |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
476 | var = ui_malloc(ctx, sizeof(UiVar)); |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
477 | cxMapPut(ctx->vars, name, var); |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
478 | } else { |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
479 | // override var with new value |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
480 | if(var->type != type) { |
|
916
6fdcf1cbbec9
fix wrong fprintf arg
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
906
diff
changeset
|
481 | fprintf(stderr, "Error: var %s type mismatch: %s - %s\n", name, uic_type2str(var->type), uic_type2str(type)); |
|
902
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
482 | return; |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
483 | } |
|
902
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
484 | if(var->bound) { |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
485 | fprintf(stderr, "Error: var %s already bound\n", name); |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
486 | return; |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
487 | } |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
488 | UiInteger *prev_value = var->value; |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
489 | uic_copy_value_binding(type, prev_value, value); |
|
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
490 | uic_destroy_value(var->from_ctx, var->type, var->value); |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
491 | } |
|
37
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
492 | |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
493 | var->type = type; |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
494 | var->value = value; |
|
163
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
495 | var->from = NULL; |
|
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
496 | var->from_ctx = ctx; |
|
902
6872b59217a7
fix var creation when a widget is already bound to this var name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
885
diff
changeset
|
497 | var->bound = TRUE; |
|
37
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
498 | } |
|
56016468753d
refactored value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
499 | |
|
2
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
500 | // public API |
|
eeb50c534497
added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
501 | |
|
960
e88ca7dfa943
add single-document-mode to UiContext
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
916
diff
changeset
|
502 | void* ui_context_get_document(UiContext *ctx) { |
|
e88ca7dfa943
add single-document-mode to UiContext
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
916
diff
changeset
|
503 | return ctx->document; |
|
e88ca7dfa943
add single-document-mode to UiContext
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
916
diff
changeset
|
504 | } |
|
e88ca7dfa943
add single-document-mode to UiContext
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
916
diff
changeset
|
505 | |
|
e88ca7dfa943
add single-document-mode to UiContext
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
916
diff
changeset
|
506 | void ui_context_single_attachment_mode(UiContext *ctx, UiBool enable) { |
|
e88ca7dfa943
add single-document-mode to UiContext
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
916
diff
changeset
|
507 | ctx->single_document_mode = enable; |
|
e88ca7dfa943
add single-document-mode to UiContext
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
916
diff
changeset
|
508 | } |
|
e88ca7dfa943
add single-document-mode to UiContext
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
916
diff
changeset
|
509 | |
|
163
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
510 | 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
|
511 | uic_context_attach_document(ctx, document); |
|
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
512 | } |
|
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
513 | |
|
623
1ebc781c7d17
rename ui_detach_document2 to ui_detach_document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
622
diff
changeset
|
514 | void ui_detach_document(UiContext *ctx, void *document) { |
|
1ebc781c7d17
rename ui_detach_document2 to ui_detach_document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
622
diff
changeset
|
515 | uic_context_detach_document(ctx, document); |
|
163
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
516 | } |
|
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
154
diff
changeset
|
517 | |
|
111
40dbf1a7526a
added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
518 | 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
|
519 | ctx->close_callback = fnc; |
|
40dbf1a7526a
added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
520 | ctx->close_data = udata; |
|
40dbf1a7526a
added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
521 | } |
|
40dbf1a7526a
added close handler to UiContext (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
522 | |
|
624
8086681cabfb
add function for getting the UiContext parent context
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
623
diff
changeset
|
523 | void ui_context_destroy(UiContext *ctx) { |
|
557
e6415fd4af4b
implement new menu itemlist binding (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
524 | CxIterator i = cxListIterator(ctx->destroy_handler); |
|
e6415fd4af4b
implement new menu itemlist binding (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
525 | cx_foreach(UiDestroyHandler *, h, i) { |
|
e6415fd4af4b
implement new menu itemlist binding (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
526 | h->destructor(h->data); |
|
e6415fd4af4b
implement new menu itemlist binding (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
527 | } |
| 440 | 528 | cxMempoolFree(ctx->mp); |
|
247
4b21af9d8c5a
call context close handler on window close (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
529 | } |
|
4b21af9d8c5a
call context close handler on window close (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
530 | |
|
624
8086681cabfb
add function for getting the UiContext parent context
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
623
diff
changeset
|
531 | UiContext* ui_context_parent(UiContext *ctx) { |
|
8086681cabfb
add function for getting the UiContext parent context
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
623
diff
changeset
|
532 | return ctx->parent; |
|
8086681cabfb
add function for getting the UiContext parent context
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
623
diff
changeset
|
533 | } |
|
8086681cabfb
add function for getting the UiContext parent context
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
623
diff
changeset
|
534 | |
|
20
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
535 | |
|
967
ff4a8d10307b
rename ui_set_group/ui_unset_group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
966
diff
changeset
|
536 | void ui_set_state(UiContext *ctx, int state) { |
|
ff4a8d10307b
rename ui_set_group/ui_unset_group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
966
diff
changeset
|
537 | if(!cxListIndexValid(ctx->states, cxListFind(ctx->states, &state))) { |
|
ff4a8d10307b
rename ui_set_group/ui_unset_group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
966
diff
changeset
|
538 | cxListAdd(ctx->states, &state); |
|
20
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
539 | } |
|
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
540 | |
|
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
541 | // enable/disable group widgets |
|
966
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
542 | uic_check_state_widgets(ctx); |
|
20
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
543 | } |
|
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
544 | |
|
967
ff4a8d10307b
rename ui_set_group/ui_unset_group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
966
diff
changeset
|
545 | void ui_unset_state(UiContext *ctx, int state) { |
|
ff4a8d10307b
rename ui_set_group/ui_unset_group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
966
diff
changeset
|
546 | int i = cxListFind(ctx->states, &state); |
|
20
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
547 | if(i != -1) { |
|
966
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
548 | cxListRemove(ctx->states, i); |
|
20
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
549 | } |
|
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
550 | |
|
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
551 | // enable/disable group widgets |
|
966
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
552 | uic_check_state_widgets(ctx); |
|
20
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
553 | } |
|
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
554 | |
|
967
ff4a8d10307b
rename ui_set_group/ui_unset_group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
966
diff
changeset
|
555 | int* ui_active_states(UiContext *ctx, int *nstates) { |
|
ff4a8d10307b
rename ui_set_group/ui_unset_group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
966
diff
changeset
|
556 | *nstates = cxListSize(ctx->states); |
|
966
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
557 | return cxListAt(ctx->states, 0); |
|
20
2dda1ad6dc7a
added groups for menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
558 | } |
|
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
559 | |
|
966
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
560 | void uic_check_state_widgets(UiContext *ctx) { |
|
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
561 | int ngroups = 0; |
|
967
ff4a8d10307b
rename ui_set_group/ui_unset_group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
966
diff
changeset
|
562 | int *groups = ui_active_states(ctx, &ngroups); |
|
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
563 | |
|
966
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
564 | CxIterator i = cxListIterator(ctx->state_widgets); |
|
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
565 | cx_foreach(UiStateWidget *, gw, i) { |
|
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
566 | char *check = calloc(1, gw->numstates); |
|
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
567 | |
|
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
568 | for(int i=0;i<ngroups;i++) { |
|
966
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
569 | for(int k=0;k<gw->numstates;k++) { |
|
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
570 | if(groups[i] == gw->states[k]) { |
|
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
571 | check[k] = 1; |
|
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
572 | } |
|
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
573 | } |
|
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
574 | } |
|
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
575 | |
|
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
576 | int enable = 1; |
|
966
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
577 | for(int i=0;i<gw->numstates;i++) { |
|
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
578 | if(check[i] == 0) { |
|
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
579 | enable = 0; |
|
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
580 | break; |
|
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
581 | } |
|
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
582 | } |
| 174 | 583 | free(check); |
|
168
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
167
diff
changeset
|
584 | gw->enable(gw->widget, enable); |
|
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
585 | } |
|
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
586 | } |
|
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
587 | |
|
966
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
588 | void ui_widget_set_states(UiContext *ctx, UIWIDGET widget, ui_enablefunc enable, ...) { |
|
775
c39e71be2e18
allow NULL as enablefunc in ui_widget_set_groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
774
diff
changeset
|
589 | if(enable == NULL) { |
|
c39e71be2e18
allow NULL as enablefunc in ui_widget_set_groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
774
diff
changeset
|
590 | enable = (ui_enablefunc)ui_set_enabled; |
|
c39e71be2e18
allow NULL as enablefunc in ui_widget_set_groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
774
diff
changeset
|
591 | } |
|
966
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
592 | // get states |
|
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
593 | CxList *states = cxArrayListCreate(cxDefaultAllocator, NULL, sizeof(int), 16); |
|
168
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
167
diff
changeset
|
594 | va_list ap; |
|
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
167
diff
changeset
|
595 | va_start(ap, enable); |
|
966
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
596 | int state; |
|
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
597 | while((state = va_arg(ap, int)) != -1) { |
|
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
598 | cxListAdd(states, &state); |
|
168
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
167
diff
changeset
|
599 | } |
|
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
167
diff
changeset
|
600 | va_end(ap); |
|
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
167
diff
changeset
|
601 | |
|
966
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
602 | uic_add_state_widget(ctx, widget, enable, states); |
|
168
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
167
diff
changeset
|
603 | |
|
966
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
604 | cxListFree(states); |
|
168
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
167
diff
changeset
|
605 | } |
|
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
167
diff
changeset
|
606 | |
|
966
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
607 | void ui_widget_set_states2(UiContext *ctx, UIWIDGET widget, ui_enablefunc enable, const int *states, int nstates) { |
|
775
c39e71be2e18
allow NULL as enablefunc in ui_widget_set_groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
774
diff
changeset
|
608 | if(enable == NULL) { |
|
c39e71be2e18
allow NULL as enablefunc in ui_widget_set_groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
774
diff
changeset
|
609 | enable = (ui_enablefunc)ui_set_enabled; |
|
c39e71be2e18
allow NULL as enablefunc in ui_widget_set_groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
774
diff
changeset
|
610 | } |
|
966
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
611 | CxList *ls = cxArrayListCreate(cxDefaultAllocator, NULL, sizeof(int), nstates); |
|
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
612 | for(int i=0;i<nstates;i++) { |
|
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
613 | cxListAdd(ls, states+i); |
|
774
4531a342c5b3
add ui_widget_set_visibility_states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
624
diff
changeset
|
614 | } |
|
966
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
615 | uic_add_state_widget(ctx, widget, enable, ls); |
|
774
4531a342c5b3
add ui_widget_set_visibility_states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
624
diff
changeset
|
616 | cxListFree(ls); |
|
4531a342c5b3
add ui_widget_set_visibility_states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
624
diff
changeset
|
617 | } |
|
4531a342c5b3
add ui_widget_set_visibility_states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
624
diff
changeset
|
618 | |
|
885
28ecfe5399ae
make states array parameter const for ui_widget_set_visibility_states/ui_widget_set_groups2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
875
diff
changeset
|
619 | void ui_widget_set_visibility_states(UiContext *ctx, UIWIDGET widget, const int *states, int nstates) { |
|
966
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
620 | ui_widget_set_states2(ctx, widget, (ui_enablefunc)ui_set_visible, states, nstates); |
|
774
4531a342c5b3
add ui_widget_set_visibility_states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
624
diff
changeset
|
621 | } |
|
4531a342c5b3
add ui_widget_set_visibility_states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
624
diff
changeset
|
622 | |
|
966
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
623 | size_t uic_state_array_size(const int *states) { |
|
343
54f5d7eb1335
implement widget groups for buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
342
diff
changeset
|
624 | int i; |
|
966
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
625 | for(i=0;states[i] >= 0;i++) { } |
|
343
54f5d7eb1335
implement widget groups for buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
342
diff
changeset
|
626 | return i; |
|
54f5d7eb1335
implement widget groups for buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
342
diff
changeset
|
627 | } |
|
54f5d7eb1335
implement widget groups for buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
342
diff
changeset
|
628 | |
|
966
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
629 | void uic_add_state_widget(UiContext *ctx, void *widget, ui_enablefunc enable, CxList *states) { |
|
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
630 | uic_add_state_widget_i(ctx, widget, enable, cxListAt(states, 0), cxListSize(states)); |
|
343
54f5d7eb1335
implement widget groups for buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
342
diff
changeset
|
631 | } |
|
54f5d7eb1335
implement widget groups for buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
342
diff
changeset
|
632 | |
|
966
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
633 | void uic_add_state_widget_i(UiContext *ctx, void *widget, ui_enablefunc enable, const int *states, size_t numstates) { |
| 174 | 634 | const CxAllocator *a = ctx->allocator; |
|
966
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
635 | UiStateWidget gw; |
|
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
636 | |
| 174 | 637 | gw.widget = widget; |
| 638 | gw.enable = enable; | |
|
966
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
639 | gw.numstates = numstates; |
|
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
640 | gw.states = cxCalloc(a, numstates, sizeof(int)); |
| 174 | 641 | |
|
966
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
642 | // copy states |
|
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
643 | if(states) { |
|
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
644 | memcpy(gw.states, states, gw.numstates * sizeof(int)); |
|
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
645 | } |
|
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
646 | |
|
966
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
647 | cxListAdd(ctx->state_widgets, &gw); |
|
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
648 | } |
|
38
8ccdde37275b
added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
649 | |
|
966
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
650 | void uic_remove_state_widget(UiContext *ctx, void *widget) { |
|
e411ed7c5f10
rename groups to states
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
960
diff
changeset
|
651 | (void)cxListFindRemove(ctx->state_widgets, widget); |
|
392
df62b7205bd3
fix UiList binding copy and missing GTK table setselection method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
387
diff
changeset
|
652 | } |
|
df62b7205bd3
fix UiList binding copy and missing GTK table setselection method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
387
diff
changeset
|
653 | |
|
342
99f83fbf48e9
implement context destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
341
diff
changeset
|
654 | 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
|
655 | return (void*)ctx->allocator; |
|
80edb1a93f7a
add public function for getting the UiContext UCX mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
656 | } |
|
80edb1a93f7a
add public function for getting the UiContext UCX mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
657 | |
|
80edb1a93f7a
add public function for getting the UiContext UCX mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
658 | 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
|
659 | return ctx->mp; |
|
341
c7427cadabd3
make ui_getappdir() and ui_configfile() public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
337
diff
changeset
|
660 | } |
|
c7427cadabd3
make ui_getappdir() and ui_configfile() public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
337
diff
changeset
|
661 | |
|
38
8ccdde37275b
added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
662 | void* ui_malloc(UiContext *ctx, size_t size) { |
| 174 | 663 | return ctx ? cxMalloc(ctx->allocator, size) : NULL; |
|
38
8ccdde37275b
added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
664 | } |
|
8ccdde37275b
added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
665 | |
|
8ccdde37275b
added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
666 | void* ui_calloc(UiContext *ctx, size_t nelem, size_t elsize) { |
| 174 | 667 | return ctx ? cxCalloc(ctx->allocator, nelem, elsize) : NULL; |
|
38
8ccdde37275b
added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
668 | } |
|
8ccdde37275b
added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
669 | |
|
8ccdde37275b
added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
670 | void ui_free(UiContext *ctx, void *ptr) { |
|
350
70305d427f25
fix ui_scrolledwindow (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
343
diff
changeset
|
671 | if(ctx && ptr) { |
| 174 | 672 | cxFree(ctx->allocator, ptr); |
|
38
8ccdde37275b
added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
673 | } |
|
8ccdde37275b
added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
674 | } |
|
8ccdde37275b
added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
675 | |
|
8ccdde37275b
added some allocation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
676 | void* ui_realloc(UiContext *ctx, void *ptr, size_t size) { |
| 174 | 677 | return ctx ? cxRealloc(ctx->allocator, ptr, size) : NULL; |
|
39
4e66271541e8
added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
678 | } |
|
4e66271541e8
added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
679 | |
|
875
0575ca45f1bb
add cleanup/destroy handler for UiString, UiText and UiGeneric
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
813
diff
changeset
|
680 | char* ui_strdup(UiContext *ctx, const char *str) { |
|
342
99f83fbf48e9
implement context destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
341
diff
changeset
|
681 | if(!ctx) { |
|
99f83fbf48e9
implement context destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
341
diff
changeset
|
682 | return NULL; |
|
99f83fbf48e9
implement context destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
341
diff
changeset
|
683 | } |
|
99f83fbf48e9
implement context destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
341
diff
changeset
|
684 | cxstring s = cx_str(str); |
|
99f83fbf48e9
implement context destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
341
diff
changeset
|
685 | cxmutstr d = cx_strdup_a(ctx->allocator, s); |
|
99f83fbf48e9
implement context destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
341
diff
changeset
|
686 | return d.ptr; |
|
99f83fbf48e9
implement context destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
341
diff
changeset
|
687 | } |
|
875
0575ca45f1bb
add cleanup/destroy handler for UiString, UiText and UiGeneric
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
813
diff
changeset
|
688 | |
|
0575ca45f1bb
add cleanup/destroy handler for UiString, UiText and UiGeneric
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
813
diff
changeset
|
689 | void ui_reg_destructor(UiContext *ctx, void *data, ui_destructor_func destr) { |
|
0575ca45f1bb
add cleanup/destroy handler for UiString, UiText and UiGeneric
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
813
diff
changeset
|
690 | cxMempoolRegister(ctx->mp, data, (cx_destructor_func)destr); |
|
0575ca45f1bb
add cleanup/destroy handler for UiString, UiText and UiGeneric
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
813
diff
changeset
|
691 | } |
|
0575ca45f1bb
add cleanup/destroy handler for UiString, UiText and UiGeneric
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
813
diff
changeset
|
692 | |
|
0575ca45f1bb
add cleanup/destroy handler for UiString, UiText and UiGeneric
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
813
diff
changeset
|
693 | void ui_set_destructor(void *mem, ui_destructor_func destr) { |
|
0575ca45f1bb
add cleanup/destroy handler for UiString, UiText and UiGeneric
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
813
diff
changeset
|
694 | cxMempoolSetDestructor(mem, (cx_destructor_func)destr); |
|
0575ca45f1bb
add cleanup/destroy handler for UiString, UiText and UiGeneric
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
813
diff
changeset
|
695 | } |
|
976
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
696 | |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
697 | UiInteger* ui_get_int_var(UiContext *ctx, const char *name) { |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
698 | UiVar *var = uic_get_var_t(ctx, name, UI_VAR_INTEGER); |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
699 | return var ? var->value : NULL; |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
700 | } |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
701 | |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
702 | UiDouble* ui_get_double_var(UiContext *ctx, const char *name) { |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
703 | UiVar *var = uic_get_var_t(ctx, name, UI_VAR_DOUBLE); |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
704 | return var ? var->value : NULL; |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
705 | } |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
706 | |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
707 | UiString* ui_get_string_var(UiContext *ctx, const char *name) { |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
708 | UiVar *var = uic_get_var_t(ctx, name, UI_VAR_STRING); |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
709 | return var ? var->value : NULL; |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
710 | } |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
711 | |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
712 | UiText* ui_get_text_var(UiContext *ctx, const char *name) { |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
713 | UiVar *var = uic_get_var_t(ctx, name, UI_VAR_TEXT); |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
714 | return var ? var->value : NULL; |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
715 | } |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
716 | |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
717 | UiRange* ui_get_range_var(UiContext *ctx, const char *name) { |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
718 | UiVar *var = uic_get_var_t(ctx, name, UI_VAR_RANGE); |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
719 | return var ? var->value : NULL; |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
720 | } |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
721 | |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
722 | UiGeneric* ui_get_generic_var(UiContext *ctx, const char *name) { |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
723 | UiVar *var = uic_get_var_t(ctx, name, UI_VAR_GENERIC); |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
724 | return var ? var->value : NULL; |
|
e2763e880938
implement radiobutton (Client)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
967
diff
changeset
|
725 | } |