--- a/ui/win32/window.c Sat Oct 04 14:54:25 2025 +0200 +++ b/ui/win32/window.c Sun Oct 19 21:20:08 2025 +0200 @@ -27,7 +27,9 @@ */ #include "window.h" -#include "Windows.h" +#include <Windows.h> + +#include "container.h" #include "../common/object.h" @@ -36,18 +38,46 @@ #include <stdio.h> #include <stdlib.h> +#include "win32.h" + +static W32WidgetClass w32_toplevel_widget_class = { + .eventproc = ui_window_widget_event, + .show = ui_window_widget_show, + .enable = NULL, + .get_preferred_size = NULL, + .destroy = w32_widget_default_destroy +}; static HINSTANCE hInstance; static const char *mainWindowClass = "UiMainWindow"; LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { + W32Widget *widget = (W32Widget*)GetWindowLongPtr(hwnd, GWLP_USERDATA); + if (widget && widget->wclass->eventproc) { + widget->wclass->eventproc(widget, hwnd, uMsg, wParam, lParam); + } switch(uMsg) { - case WM_DESTROY: - PostQuitMessage(0); - break; - default: - return DefWindowProc(hwnd, uMsg, wParam, lParam); + case WM_DESTROY: { + PostQuitMessage(0); + break; + } + case WM_COMMAND: { + HWND hwndCtrl = (HWND)lParam; + W32Widget *cmdWidget = (W32Widget*)GetWindowLongPtr(hwndCtrl, GWLP_USERDATA); + if (cmdWidget && cmdWidget->wclass->eventproc) { + cmdWidget->wclass->eventproc(cmdWidget, hwnd, uMsg, wParam, lParam); + } + } + case WM_SIZE: { + int width = LOWORD(lParam); + int height = HIWORD(lParam); + if (widget->layout) { + widget->layout(widget->layoutmanager, width, height); + } + break; + } + default: return DefWindowProc(hwnd, uMsg, wParam, lParam); } return 0; } @@ -60,7 +90,7 @@ wc.hInstance = hInstance; wc.lpszClassName = mainWindowClass; wc.hCursor = LoadCursor(NULL, IDC_ARROW); - wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); + wc.hbrBackground = GetSysColorBrush(COLOR_BTNFACE); if(!RegisterClassExA(&wc)) { MessageBox(NULL, "RegisterClassEx failed", "Error", MB_ICONERROR); @@ -71,12 +101,12 @@ static UiObject* create_window(const char *title, void *window_data, bool simple) { UiObject *obj = uic_object_new_toplevel(); obj->window = window_data; - + HWND hwnd = CreateWindowExA( 0, "UiMainWindow", title, - WS_OVERLAPPEDWINDOW | WS_VISIBLE, + WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 800, @@ -85,10 +115,20 @@ NULL, hInstance, NULL); - - ShowWindow(hwnd, SW_SHOWNORMAL); + UpdateWindow(hwnd); - + + UiContainerX *container = ui_box_container_create(obj, hwnd, UI_BOX_VERTICAL, 0, INSETS_ZERO); + uic_object_push_container(obj, container); + UiBoxContainer *box = (UiBoxContainer*)container; + + UiWindow *widget = w32_widget_create(&w32_toplevel_widget_class, hwnd, sizeof(UiWindow)); + widget->obj = obj; + widget->widget.layout = (W32LayoutFunc)ui_grid_layout; + widget->widget.layoutmanager = box->layout; + obj->widget = (W32Widget*)widget; + obj->ref = 1; + return obj; } @@ -96,3 +136,11 @@ return create_window(title, window_data, FALSE); } + +void ui_window_widget_event(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { + //UiWindow *window = (UiWindow*)widget; +} + +void ui_window_widget_show(W32Widget *w, BOOLEAN show) { + ShowWindow(w->hwnd, show ? SW_SHOWNORMAL : SW_HIDE); +}