ui/common/types.c

changeset 140
c03c338a7dcf
parent 116
480354705c2f
child 141
cc2170ea05ad
equal deleted inserted replaced
139:dbde25a5bc53 140:c03c338a7dcf
1 /* 1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 * 3 *
4 * Copyright 2014 Olaf Wintermann. All rights reserved. 4 * Copyright 2017 Olaf Wintermann. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met: 7 * modification, are permitted provided that the following conditions are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include <stdio.h> 29 #include <stdio.h>
30 #include <stdlib.h> 30 #include <stdlib.h>
31 #include <string.h>
31 #include <stdarg.h> 32 #include <stdarg.h>
32 33
33 #include "../../ucx/list.h" 34 #include "../../ucx/list.h"
34 #include "../ui/tree.h" 35 #include "../ui/tree.h"
35 #include "types.h" 36 #include "types.h"
91 list->observers = NULL; 92 list->observers = NULL;
92 93
93 list->data = NULL; 94 list->data = NULL;
94 list->iter = NULL; 95 list->iter = NULL;
95 96
97 list->update = NULL;
98 list->obj = NULL;
99
96 return list; 100 return list;
97 } 101 }
98 102
99 void ui_list_free(UiList *list) { 103 void ui_list_free(UiList *list) {
100 ucx_list_free(list->data); 104 ucx_list_free(list->data);
197 void ui_model_info_free(UiContext *ctx, UiModelInfo *mi) { 201 void ui_model_info_free(UiContext *ctx, UiModelInfo *mi) {
198 ucx_mempool_free(ctx->mempool, mi->types); 202 ucx_mempool_free(ctx->mempool, mi->types);
199 ucx_mempool_free(ctx->mempool, mi->titles); 203 ucx_mempool_free(ctx->mempool, mi->titles);
200 ucx_mempool_free(ctx->mempool, mi); 204 ucx_mempool_free(ctx->mempool, mi);
201 } 205 }
206
207 // types
208
209 // public functions
210 UiInteger* ui_int_new(UiContext *ctx, char *name) {
211 UiInteger *i = ui_malloc(ctx, sizeof(UiInteger));
212 memset(i, 0, sizeof(UiInteger));
213 if(name) {
214 uic_reg_var(ctx, name, UI_VAR_INTEGER, i);
215 }
216 return i;
217 }
218
219 UiString* ui_string_new(UiContext *ctx, char *name) {
220 UiString *s = ui_malloc(ctx, sizeof(UiString));
221 memset(s, 0, sizeof(UiString));
222 if(name) {
223 uic_reg_var(ctx, name, UI_VAR_STRING, s);
224 }
225 return s;
226 }
227
228 UiText* ui_text_new(UiContext *ctx, char *name) {
229 UiText *t = ui_malloc(ctx, sizeof(UiText));
230 memset(t, 0, sizeof(UiText));
231 if(name) {
232 uic_reg_var(ctx, name, UI_VAR_TEXT, t);
233 }
234 return t;
235 }
236
237
238 // private functions
239 void uic_int_copy(UiInteger *from, UiInteger *to) {
240 to->get = from->get;
241 to->set = from->set;
242 to->obj = from->obj;
243 }
244
245 void uic_string_copy(UiString *from, UiString *to) {
246 to->get = from->get;
247 to->set = from->set;
248 to->obj = from->obj;
249 }
250
251 void uic_text_copy(UiText *from, UiText *to) {
252 to->get = from->get;
253 to->set = from->set;
254 to->getsubstr = from->getsubstr;
255 to->insert = from->insert;
256 to->setposition = from->setposition;
257 to->position = from->position;
258 to->selection = from->selection;
259 to->length = from->length;
260 to->remove = from->remove;
261
262 to->obj = from->obj;
263 // do not copy the undo manager
264 }
265
266 void uic_range_copy(UiRange *from, UiRange *to) {
267 to->get = from->get;
268 to->set = from->set;
269 to->setrange = from->setrange;
270 to->setextent = from->setextent;
271 to->obj = from->obj;
272 }
273
274 void uic_list_copy(UiList *from, UiList *to) {
275 to->update = from->update;
276 to->obj = from->obj;
277 }
278
279
280 void uic_int_unbind(UiInteger *i) {
281 i->value = i->get(i);
282 i->get = NULL;
283 i->set = NULL;
284 i->obj = NULL;
285 }
286
287 void uic_string_unbind(UiString *s) {
288 s->value = s->get(s);
289 s->get = NULL;
290 s->set = NULL;
291 s->obj = NULL;
292 }
293
294 void uic_text_unbind(UiText *t) {
295 t->value = t->get(t);
296 t->set = NULL;
297 t->get = NULL;
298 t->getsubstr = NULL;
299 t->insert = NULL;
300 t->setposition = NULL;
301 t->position = NULL;
302 t->selection = NULL;
303 t->length = NULL;
304 t->remove = NULL;
305 t->obj = NULL;
306 }
307
308 void uic_range_unbind(UiRange *r) {
309 r->value = r->get(r);
310 r->get = NULL;
311 r->set = NULL;
312 r->setextent = NULL;
313 r->setrange = NULL;
314 r->obj = NULL;
315 }
316
317 void uic_list_unbind(UiList *l) {
318 l->update = NULL;
319 l->obj = NULL;
320 }

mercurial