--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/common/wrapper.c Sun Jul 20 22:04:39 2025 +0200 @@ -0,0 +1,220 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2025 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "wrapper.h" +#include "types.h" +#include <cx/list.h> +#include <string.h> + +/* ---------------------------- UiObject ---------------------------- */ + +UiContext* ui_object_get_context(UiObject *obj) { + return obj->ctx; +} + +void* ui_object_get_windowdata(UiObject *obj) { + return obj->window; +} + +void ui_object_set_windowdata(UiObject *obj, void *windowdata) { + obj->window = windowdata; +} + + +/* ---------------------------- UiList ---------------------------- */ + +void* ui_list_get_data(UiList *list) { + return list->data; +} + +void ui_list_set_data(UiList *list, void *data) { + list->data = data; +} + +void* ui_list_get_iter(UiList *list) { + return list->iter; +} + +void ui_list_set_iter(UiList *list, void *iter) { + list->iter = iter; +} + + +/* ------------------------------ UiSublist ------------------------------ */ + +UiSubList* ui_sublist_new(void) { + UiSubList *sublist = malloc(sizeof(UiSubList)); + memset(sublist, 0, sizeof(UiSubList)); + return sublist; +} + +void ui_sublist_set_value(UiSubList *sublist, UiList *value) { + sublist->value = value; +} + +void ui_sublist_set_varname(UiSubList *sublist, const char *varname) { + free((void*)sublist->varname); + sublist->varname = strdup(varname); +} + +void ui_sublist_set_header(UiSubList *sublist, const char *header) { + free((void*)sublist->header); + sublist->header = strdup(header); +} + +void ui_sublist_set_separator(UiSubList *sublist, UiBool separator) { + sublist->separator = separator; +} + +void ui_sublist_set_userdata(UiSubList *sublist, void *userdata) { + sublist->userdata = userdata; +} + +void ui_sublist_free(UiSubList *sublist) { + free((void*)sublist->varname); + free((void*)sublist->header); + free(sublist); +} + + +/* -------------------- Source list (UiList<UiSublist>) -------------------- */ + +UiList* ui_srclist_new(UiContext *ctx, const char *name) { + UiList *list = ui_list_new2(ctx, name, uic_ucx_list_init, NULL); + CxList *cxlist = list->data; + cxlist->collection.simple_destructor = (cx_destructor_func)ui_sublist_free; + return list; +} + +void ui_srclist_add(UiList *list, UiSubList *item) { + ui_list_append(list, item); +} + +void ui_srclist_insert(UiList *list, int index, UiSubList *item) { + CxList *cxlist = list->data; + cxListInsert(cxlist, index, item); +} + +void ui_srclist_remove(UiList *list, int index) { + CxList *cxlist = list->data; + cxListRemove(cxlist, index); +} + +void ui_srclist_clear(UiList *list) { + CxList *cxlist = list->data; + cxListClear(cxlist); +} + +int ui_srclist_size(UiList *list) { + return ui_list_count(list); +} + + +/* ---------------------------- UiSubListEventData ---------------------------- */ + +UiList* ui_sublist_event_get_list(UiSubListEventData *event) { + return event->list; +} + +int ui_sublist_event_get_sublist_index(UiSubListEventData *event) { + return event->sublist_index; +} + +int ui_sublist_event_get_row_index(UiSubListEventData *event) { + return event->row_index; +} + +void* ui_sublist_event_get_row_data(UiSubListEventData *event) { + return event->row_data; +} + +void* ui_sublist_event_get_sublist_userdata(UiSubListEventData *event) { + return event->sublist_userdata; +} + +void* ui_sublist_event_get_event_data(UiSubListEventData *event) { + return event->event_data; +} + + +/* ---------------------------- UiEvent ---------------------------- */ + +UiObject* ui_event_get_obj(UiEvent *event) { + return event->obj; +} + +void* ui_event_get_document(UiEvent *event) { + return event->document; +} + +void* ui_event_get_windowdata(UiEvent *event) { + return event->window; +} + +void* ui_event_get_eventdata(UiEvent *event) { + return event->eventdata; +} + +int ui_event_get_eventdatatype(UiEvent *event) { + return event->eventdatatype; +} + +int ui_event_get_int(UiEvent *event) { + return event->intval; +} + +int ui_event_get_set(UiEvent *event) { + return event->set; +} + + +/* ------------------------- SubListItem (public) ------------------------- */ + +void ui_sublist_item_set_icon(UiSubListItem *item, const char *icon) { + item->icon = icon ? strdup(icon) : NULL; +} + +void ui_sublist_item_set_label(UiSubListItem *item, const char *label) { + item->label = label ? strdup(label) : NULL; +} + +void ui_sublist_item_set_button_icon(UiSubListItem *item, const char *button_icon) { + item->button_icon = button_icon ? strdup(button_icon) : NULL; +} + +void ui_sublist_item_set_button_label(UiSubListItem *item, const char *button_label) { + item->button_label = button_label ? strdup(button_label) : NULL; +} + +void ui_sublist_item_set_badge(UiSubListItem *item, const char *badge) { + item->badge = badge ? strdup(badge) : NULL; +} + +void ui_sublist_item_set_eventdata(UiSubListItem *item, void *eventdata) { + item->eventdata = NULL; +}