add container event proc (win32)

Tue, 28 Oct 2025 13:53:59 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 28 Oct 2025 13:53:59 +0100
changeset 880
9c99ff36513f
parent 879
d3acaa5fc3d8
child 881
e0bbf466915f

add container event proc (win32)

ui/win32/button.c file | annotate | diff | comparison | revisions
ui/win32/container.c file | annotate | diff | comparison | revisions
ui/win32/text.c file | annotate | diff | comparison | revisions
ui/win32/toolkit.c file | annotate | diff | comparison | revisions
ui/win32/toolkit.h file | annotate | diff | comparison | revisions
ui/win32/window.c file | annotate | diff | comparison | revisions
--- a/ui/win32/button.c	Tue Oct 28 13:23:54 2025 +0100
+++ b/ui/win32/button.c	Tue Oct 28 13:53:59 2025 +0100
@@ -51,10 +51,10 @@
     HWND hwnd = CreateWindow(
             "BUTTON",
             args->label,
-            WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
+            WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
             0, 0, 100, 30,
             parent,
-            (HMENU)0,
+            (HMENU)1,
             hInstance,
             NULL);
     ui_win32_set_ui_font(hwnd);
@@ -85,6 +85,9 @@
 void ui_button_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
     UiWidget *w = (UiWidget*)widget;
 
+    printf("button eventproc\n");
+    fflush(stdout);
+
     UiEvent e;
     e.obj = w->obj;
     e.document = e.obj->ctx->document;
--- a/ui/win32/container.c	Tue Oct 28 13:23:54 2025 +0100
+++ b/ui/win32/container.c	Tue Oct 28 13:53:59 2025 +0100
@@ -139,6 +139,7 @@
             NULL,
             hInstance,
             NULL);
+    SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)ui_default_eventproc);
 
     W32Widget *widget = w32_widget_new(&grid_layout_widget_class, hwnd);
     ui_container_add(container, widget, &layout);
--- a/ui/win32/text.c	Tue Oct 28 13:23:54 2025 +0100
+++ b/ui/win32/text.c	Tue Oct 28 13:53:59 2025 +0100
@@ -28,7 +28,7 @@
 
 #include "text.h"
 
-static W32WidgetClass button_widget_class = {
+static W32WidgetClass textfield_widget_class = {
     .eventproc = ui_textfield_eventproc,
     .enable = w32_widget_default_enable,
     .show = w32_widget_default_show,
@@ -55,7 +55,7 @@
             NULL);
     ui_win32_set_ui_font(hwnd);
 
-    W32Widget *widget = w32_widget_create(&button_widget_class, hwnd, sizeof(UiTextField));
+    W32Widget *widget = w32_widget_create(&textfield_widget_class, hwnd, sizeof(UiTextField));
     ui_container_add(container, widget, &layout);
 
     UiTextField *textfield = (UiTextField*)widget;
--- a/ui/win32/toolkit.c	Tue Oct 28 13:23:54 2025 +0100
+++ b/ui/win32/toolkit.c	Tue Oct 28 13:53:59 2025 +0100
@@ -123,4 +123,34 @@
 
 void ui_show(UiObject *obj) {
     ui_set_visible(obj->widget, TRUE);
+}
+
+LRESULT CALLBACK ui_default_eventproc(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;
+        }
+        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;
 }
\ No newline at end of file
--- a/ui/win32/toolkit.h	Tue Oct 28 13:23:54 2025 +0100
+++ b/ui/win32/toolkit.h	Tue Oct 28 13:53:59 2025 +0100
@@ -53,6 +53,8 @@
     int64_t intvalue;
 } UiWidget;
 
+LRESULT CALLBACK ui_default_eventproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
+
 HFONT ui_win32_get_font(void);
 void ui_win32_set_ui_font(HWND control);
 
--- a/ui/win32/window.c	Tue Oct 28 13:23:54 2025 +0100
+++ b/ui/win32/window.c	Tue Oct 28 13:53:59 2025 +0100
@@ -52,41 +52,12 @@
 
 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;
-        }
-		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;
-}
 
 void ui_window_init(void) {
 	hInstance = GetModuleHandle(NULL);
 	
 	WNDCLASSEX wc = { sizeof(WNDCLASSEX) };
-    wc.lpfnWndProc = WindowProc;
+    wc.lpfnWndProc = ui_default_eventproc;
     wc.hInstance = hInstance;
     wc.lpszClassName = mainWindowClass;
     wc.hCursor = LoadCursor(NULL, IDC_ARROW);

mercurial