Wed, 08 Oct 2025 09:46:23 +0200
implement ui_show (win32)
| application/main.c | file | annotate | diff | comparison | revisions | |
| ui/common/context.c | file | annotate | diff | comparison | revisions | |
| ui/ui/toolkit.h | file | annotate | diff | comparison | revisions | |
| ui/ui/win32.h | file | annotate | diff | comparison | revisions | |
| ui/win32/container.h | file | annotate | diff | comparison | revisions | |
| ui/win32/grid.c | file | annotate | diff | comparison | revisions | |
| ui/win32/grid.h | file | annotate | diff | comparison | revisions | |
| ui/win32/objs.mk | file | annotate | diff | comparison | revisions | |
| ui/win32/toolkit.c | file | annotate | diff | comparison | revisions | |
| ui/win32/widget.c | file | annotate | diff | comparison | revisions | |
| ui/win32/widget.h | file | annotate | diff | comparison | revisions | |
| ui/win32/win32.c | file | annotate | diff | comparison | revisions | |
| ui/win32/win32.h | file | annotate | diff | comparison | revisions | |
| ui/win32/window.c | file | annotate | diff | comparison | revisions | |
| ui/win32/window.h | file | annotate | diff | comparison | revisions |
--- a/application/main.c Wed Oct 08 07:53:57 2025 +0200 +++ b/application/main.c Wed Oct 08 09:46:23 2025 +0200 @@ -1125,7 +1125,7 @@ void application_startup(UiEvent *event, void *data) { UiObject *obj = ui_window("Test w32", NULL); - + ui_show(obj); } int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
--- a/ui/common/context.c Wed Oct 08 07:53:57 2025 +0200 +++ b/ui/common/context.c Wed Oct 08 09:46:23 2025 +0200 @@ -109,7 +109,7 @@ while(var_ctx) { CxMapIterator i = cxMapIterator(var_ctx->vars); cx_foreach(CxMapEntry*, entry, i) { - printf("attach %.*s\n", (int)entry->key->len, entry->key->data); + printf("attach %.*s\n", (int)entry->key->len, (char*)entry->key->data); UiVar *var = entry->value; UiVar *docvar = cxMapGet(doc_ctx->vars, *entry->key); if(docvar) {
--- a/ui/ui/toolkit.h Wed Oct 08 07:53:57 2025 +0200 +++ b/ui/ui/toolkit.h Wed Oct 08 09:46:23 2025 +0200 @@ -88,13 +88,7 @@ #elif UI_WIN32 -#include <Windows.h> - -#define UIEXPORT __declspec(dllexport) - -typedef struct W32Widget { - HWND hwnd; -} W32Widget; +#include "win32.h" #define UIWIDGET W32Widget* #define UIWINDOW void*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/ui/win32.h Wed Oct 08 09:46:23 2025 +0200 @@ -0,0 +1,66 @@ +/* + * 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. + */ + +#ifndef UI_WIN32_H +#define UI_WIN32_H + +#include <Windows.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#define UIEXPORT __declspec(dllexport) + +typedef struct W32WidgetClass W32WidgetClass; +typedef struct W32Widget W32Widget; +typedef struct W32Size W32Size; + +struct W32Size { + int width; + int height; +}; + +struct W32WidgetClass { + void (*show)(W32Widget *widget, BOOLEAN show); + void (*enable)(W32Widget *widget, BOOLEAN enable); + W32Size (*get_preferred_size)(W32Widget *widget); + void (*destroy)(W32Widget *widget); +}; + +struct W32Widget { + W32WidgetClass *wclass; + HWND hwnd; + void *userdata; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* UI_WIN32_H */
--- a/ui/win32/container.h Wed Oct 08 07:53:57 2025 +0200 +++ b/ui/win32/container.h Wed Oct 08 09:46:23 2025 +0200 @@ -27,36 +27,16 @@ */ #ifndef CONTAINER_H - -#include "../ui/container.h" - #define CONTAINER_H -#define UI_APPLY_LAYOUT(layout, args) \ - layout.fill = args->fill; \ - layout.hexpand = args->hexpand; \ - layout.vexpand = args->vexpand; \ - layout.hfill = args->hfill; \ - layout.vfill = args->vfill; \ - layout.override_defaults = args->override_defaults; \ - layout.colspan = args->colspan; \ - layout.rowspan = args->rowspan - -typedef struct UiLayout UiLayout; +#include "../ui/container.h" +#include "grid.h" -struct UiLayout { - UiBool fill; - UiBool newline; - char *label; - UiBool hexpand; - UiBool vexpand; - UiBool hfill; - UiBool vfill; - UiBool override_defaults; - int width; - int colspan; - int rowspan; -}; +#ifdef __cplusplus +extern "C" { +#endif + + enum UiBoxOrientation { UI_BOX_VERTICAL = 0, @@ -82,10 +62,21 @@ struct UiContainerPrivate { UiContainerX container; - void (*prepare)(UiContainerPrivate*, UiRect*); - void (*add)(UiContainerPrivate*, UiRect*, W32Widget*); + HWND (*parent)(UiContainerPrivate*); + void (*add)(UiContainerPrivate*, W32Widget*, UiLayout*); UiContainerType type; UiLayout layout; }; +struct UiGridLayoutContainer { + UiContainerPrivate container; + UiGridLayout layout; + int x; + int y; +}; + +#ifdef __cplusplus +} +#endif + #endif //CONTAINER_H
--- a/ui/win32/grid.c Wed Oct 08 07:53:57 2025 +0200 +++ b/ui/win32/grid.c Wed Oct 08 09:46:23 2025 +0200 @@ -31,10 +31,10 @@ #include "../../ucx/cx/array_list.h" #include "../common/context.h" -UiGridLayout* ui_grid_container(UiObject *obj, HWND control, short padding, short columnspacing, short rowspacing) { - UiGridLayout *grid = cxZalloc(obj->ctx->allocator, sizeof(UiGridLayout)); +UiGridLayout* ui_grid_container(const CxAllocator *a, HWND control, short padding, short columnspacing, short rowspacing) { + UiGridLayout *grid = cxZalloc(a, sizeof(UiGridLayout)); grid->hwnd = control; - grid->widgets = cxArrayListCreate(obj->ctx->allocator, NULL, sizeof(GridElm), 32); + grid->widgets = cxArrayListCreate(a, NULL, sizeof(GridElm), 32); grid->padding = padding; grid->columnspacing = columnspacing; grid->rowspacing = rowspacing; @@ -50,10 +50,14 @@ { GridElm elm; elm.widget = widget; - elm.x = x; - elm.y = y; + elm.posx = 0; + elm.posy = 0; + elm.width = 0; + elm.height = 0; + elm.gridx = x; + elm.gridy = y; elm.layout = *layout; - cxListAdd(grid->widgets, elm); + cxListAdd(grid->widgets, &elm); } void ui_grid_layout(UiGridLayout *grid) {
--- a/ui/win32/grid.h Wed Oct 08 07:53:57 2025 +0200 +++ b/ui/win32/grid.h Wed Oct 08 09:46:23 2025 +0200 @@ -28,17 +28,10 @@ #ifndef GRID_H #define GRID_H -#include "container.h" +#include "../ui/win32.h" #include <stdbool.h> #include <cx/array_list.h> -typedef struct GridElm { - W32Widget *widget; - short x; - short y; - GridLayoutInfo layout; -} GridElm; - typedef struct GridLayoutInfo { short margin_left; short margin_right; @@ -46,14 +39,25 @@ short margin_bottom; short colspan; short rowspan; - short preferred_width; - short preferred_height; + int preferred_width; + int preferred_height; bool hexpand; bool vexpand; bool hfill; bool vfill; } GridLayoutInfo; +typedef struct GridElm { + W32Widget *widget; + int posx; + int posy; + int width; + int height; + short gridx; + short gridy; + GridLayoutInfo layout; +} GridElm; + typedef struct UiGridLayout { HWND hwnd; @@ -68,7 +72,7 @@ } UiGridLayout; -UiGridLayout* ui_grid_container(UiObject *obj, HWND control, short padding, short columnspacing, short rowspacing); +UiGridLayout* ui_grid_container(const CxAllocator *a, HWND control, short padding, short columnspacing, short rowspacing); void ui_grid_add_widget( UiGridLayout *grid,
--- a/ui/win32/objs.mk Wed Oct 08 07:53:57 2025 +0200 +++ b/ui/win32/objs.mk Wed Oct 08 09:46:23 2025 +0200 @@ -30,10 +30,13 @@ WIN32_OBJPRE = $(OBJ_DIR)$(WIN32_SRC_DIR) WIN32OBJ = toolkit.obj +WIN32OBJ += win32.obj +WIN32OBJ += widget.obj WIN32OBJ += window.obj WIN32OBJ += image.obj WIN32OBJ += container.obj WIN32OBJ += button.obj +WIN32OBJ += grid.obj TOOLKITOBJS += $(WIN32OBJ:%=$(WIN32_OBJPRE)%) TOOLKITSOURCE += $(WIN32OBJ:%.obj=win32/%.c)
--- a/ui/win32/toolkit.c Wed Oct 08 07:53:57 2025 +0200 +++ b/ui/win32/toolkit.c Wed Oct 08 09:46:23 2025 +0200 @@ -36,6 +36,8 @@ #include "../common/document.h" #include "../common/properties.h" +#include "../ui/widget.h" + #include <stdio.h> #include <stdlib.h> @@ -52,7 +54,6 @@ application_name = appname; uic_init_global_context(); - uic_docmgr_init(); uic_menu_init(); uic_toolbar_init(); uic_load_app_properties(); @@ -96,3 +97,7 @@ } uic_store_app_properties(); } + +void ui_show(UiObject *obj) { + ui_set_visible(obj->widget, TRUE); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/win32/widget.c Wed Oct 08 09:46:23 2025 +0200 @@ -0,0 +1,43 @@ +/* + * 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 "widget.h" + +void ui_set_enabled(UIWIDGET widget, UiBool enable) { + W32Widget *w = (W32Widget *)widget; + if (w->wclass->enable) { + w->wclass->enable(w, enable); + } +} + +void ui_set_visible(UIWIDGET widget, UiBool visible) { + W32Widget *w = (W32Widget *)widget; + if (w->wclass->show) { + w->wclass->show(w, visible); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/win32/widget.h Wed Oct 08 09:46:23 2025 +0200 @@ -0,0 +1,44 @@ +/* + * 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. + */ + +#ifndef WIDGET_H +#define WIDGET_H + +#include "toolkit.h" + +#ifdef __cplusplus +extern "C" { +#endif + + + +#ifdef __cplusplus +} +#endif + +#endif //WIDGET_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/win32/win32.c Wed Oct 08 09:46:23 2025 +0200 @@ -0,0 +1,60 @@ +/* + * 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 <stdlib.h> + +#include "win32.h" + +W32Widget* w32_widget_new(W32WidgetClass *wclass, HWND hwnd) { + return w32_widget_create(wclass, hwnd, sizeof(W32Widget)); +} + +void* w32_widget_create(W32WidgetClass *wclass, HWND hwnd, size_t obj_size) { + W32Widget *w = malloc(obj_size); + w->wclass = wclass; + w->hwnd = hwnd; + SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)w); + return w; +} + +void w32_widget_default_destroy(W32Widget *w) { + free(w); +} + +void w32_widget_default_show(W32Widget *w, BOOLEAN show) { + ShowWindow(w->hwnd, show ? SW_SHOW : SW_HIDE); +} + +void w32_widget_default_enable(W32Widget *w, BOOLEAN enable) { + // TODO +} + +W32Size w32_widget_default_get_preferred_size(W32Widget *widget) { + return (W32Size){0,0}; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/win32/win32.h Wed Oct 08 09:46:23 2025 +0200 @@ -0,0 +1,59 @@ +/* + * 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. + */ + +#ifndef UI_TK_WIN32_H +#define UI_TK_WIN32_H + +#include "../ui/win32.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Creates a standard W32Widget object for an HWND handle and stores the widget object as + * GWLP_USERDATA in the window. + */ +W32Widget* w32_widget_new(W32WidgetClass *wclass, HWND hwnd); + +/* + * Same as w32_widget_new, but uses obj_size for allocation, allowing to create objects + * derived from W32Widget. + */ +void* w32_widget_create(W32WidgetClass *wclass, HWND hwnd, size_t obj_size); + +void w32_widget_default_destroy(W32Widget *w); +void w32_widget_default_show(W32Widget *w, BOOLEAN show); +void w32_widget_default_enable(W32Widget *w, BOOLEAN enable); +W32Size w32_widget_default_get_preferred_size(W32Widget *widget); + +#ifdef __cplusplus +} +#endif + +#endif //UI_TK_WIN32_H
--- a/ui/win32/window.c Wed Oct 08 07:53:57 2025 +0200 +++ b/ui/win32/window.c Wed Oct 08 09:46:23 2025 +0200 @@ -36,6 +36,14 @@ #include <stdio.h> #include <stdlib.h> +#include "win32.h" + +static W32WidgetClass w32_toplevel_widget_class = { + .show = ui_window_widget_show, + .enable = NULL, + .get_preferred_size = NULL, + .destroy = w32_widget_default_destroy +}; static HINSTANCE hInstance; @@ -76,7 +84,7 @@ 0, "UiMainWindow", title, - WS_OVERLAPPEDWINDOW | WS_VISIBLE, + WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 800, @@ -85,9 +93,12 @@ NULL, hInstance, NULL); - - ShowWindow(hwnd, SW_SHOWNORMAL); + UpdateWindow(hwnd); + + W32Widget *widget = w32_widget_new(&w32_toplevel_widget_class, hwnd); + obj->widget = widget; + obj->ref = 1; return obj; } @@ -96,3 +107,6 @@ return create_window(title, window_data, FALSE); } +void ui_window_widget_show(W32Widget *w, BOOLEAN show) { + ShowWindow(w->hwnd, show ? SW_SHOWNORMAL : SW_HIDE); +}