change w32 eventproc signature + fix grid repaint bug (Win32)

Thu, 27 Nov 2025 15:15:09 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 27 Nov 2025 15:15:09 +0100
changeset 938
be4c88ded783
parent 937
06e03c7e39db
child 939
fdc6a46100a3

change w32 eventproc signature + fix grid repaint bug (Win32)

application/main.c file | annotate | diff | comparison | revisions
ui/ui/win32.h file | annotate | diff | comparison | revisions
ui/win32/button.c file | annotate | diff | comparison | revisions
ui/win32/button.h file | annotate | diff | comparison | revisions
ui/win32/container.c file | annotate | diff | comparison | revisions
ui/win32/container.h file | annotate | diff | comparison | revisions
ui/win32/list.c file | annotate | diff | comparison | revisions
ui/win32/list.h file | annotate | diff | comparison | revisions
ui/win32/text.c file | annotate | diff | comparison | revisions
ui/win32/text.h file | annotate | diff | comparison | revisions
ui/win32/toolkit.c 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 Nov 26 19:39:37 2025 +0100
+++ b/application/main.c	Thu Nov 27 15:15:09 2025 +0100
@@ -1235,7 +1235,14 @@
         //UiModel *model = ui_model(obj->ctx, UI_STRING, "Name", UI_STRING, "Email", -1);
         //ui_table(obj, .fill = TRUE, .varname = "persons", .model = model, .getvalue = person_getvalue, .onselection = list_onselection);
         //ui_model_free(obj->ctx, model);
-        ui_combobox(obj, .varname = "persons", .getvalue = person_getvalue, .onactivate = list_onselection);
+        ui_combobox(obj, .varname = "persons", .getvalue = person_getvalue, .onactivate = list_onselection, .hexpand = TRUE, .hfill = TRUE);
+
+        ui_button(obj, .label = "Test 1");
+        ui_newline(obj);
+
+        ui_button(obj, .label = "Button 1", .hfill = TRUE);
+        ui_button(obj, .label = "Button 2");
+        ui_button(obj, .label = "Button 2");
     }
 
 
--- a/ui/ui/win32.h	Wed Nov 26 19:39:37 2025 +0100
+++ b/ui/ui/win32.h	Thu Nov 27 15:15:09 2025 +0100
@@ -49,7 +49,7 @@
 };
 
 struct W32WidgetClass {
-    void (*eventproc)(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
+    int (*eventproc)(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
     void (*show)(W32Widget *widget, BOOLEAN show);
     void (*enable)(W32Widget *widget, BOOLEAN enable);
     W32Size (*get_preferred_size)(W32Widget *widget);
--- a/ui/win32/button.c	Wed Nov 26 19:39:37 2025 +0100
+++ b/ui/win32/button.c	Thu Nov 27 15:15:09 2025 +0100
@@ -100,11 +100,11 @@
     return size;
 }
 
-void ui_button_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
+int ui_button_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
     UiWidget *w = (UiWidget*)widget;
 
     if (uMsg != WM_COMMAND) {
-        return;
+        return 0;
     }
 
     UiEvent e;
@@ -119,6 +119,8 @@
     if (w->callback) {
         w->callback(&e, w->callbackdata);
     }
+
+    return 0;
 }
 
 static UIWIDGET create_togglebutton(UiObject *obj, UiToggleArgs *args, unsigned long type) {
@@ -187,9 +189,9 @@
     i->value = v;
 }
 
-void ui_togglebutton_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
+int ui_togglebutton_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
     if (uMsg != WM_COMMAND) {
-        return;
+        return 0;
     }
     UiWidget *w = (UiWidget*)widget;
 
@@ -205,6 +207,8 @@
     if (w->callback) {
         w->callback(&e, w->callbackdata);
     }
+
+    return 0;
 }
 
 
@@ -256,15 +260,15 @@
     return widget;
 }
 
-void ui_radiobutton_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
+int ui_radiobutton_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
     if (uMsg != WM_COMMAND) {
-        return;
+        return 0;
     }
     UiWidget *w = (UiWidget*)widget;
 
     int checked = SendMessage(w->widget.hwnd, BM_GETCHECK, 0, 0);
     if (!checked) {
-        return; // ignore uncheck events
+        return 0; // ignore uncheck events
     }
 
     int b = 0;
@@ -296,6 +300,8 @@
     if (w->callback) {
         w->callback(&e, w->callbackdata);
     }
+
+    return 0;
 }
 
 int64_t ui_radiobutton_get(UiInteger *i) {
--- a/ui/win32/button.h	Wed Nov 26 19:39:37 2025 +0100
+++ b/ui/win32/button.h	Thu Nov 27 15:15:09 2025 +0100
@@ -34,14 +34,14 @@
 
 W32Size ui_button_get_preferred_size(W32Widget *widget);
 
-void ui_button_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
+int ui_button_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
 
 int64_t ui_togglebutton_get(UiInteger *i);
 void ui_togglebutton_set(UiInteger *i, int64_t v);
-void ui_togglebutton_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
+int ui_togglebutton_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
 
 int64_t ui_radiobutton_get(UiInteger *i);
 void ui_radiobutton_set(UiInteger *i, int64_t v);
-void ui_radiobutton_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
+int ui_radiobutton_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
 
 #endif //BUTTON_H
--- a/ui/win32/container.c	Wed Nov 26 19:39:37 2025 +0100
+++ b/ui/win32/container.c	Thu Nov 27 15:15:09 2025 +0100
@@ -62,12 +62,16 @@
     ctn->container.newline = FALSE;
 }
 
-void ui_grid_widget_event(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
-    HDC hdc = (HDC)wParam;
-    UiGridWidget *grid = (UiGridWidget*)widget;
-    RECT rc;
-    GetClientRect(hwnd, &rc);
-    FillRect(hdc, &rc, grid->brush);
+int ui_grid_widget_event(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
+    if (uMsg == WM_ERASEBKGND) {
+        HDC hdc = (HDC)wParam;
+        UiGridWidget *grid = (UiGridWidget*)widget;
+        RECT rc;
+        GetClientRect(hwnd, &rc);
+        FillRect(hdc, &rc, grid->brush);
+        return 1;
+    }
+    return 0;
 }
 
 W32Size ui_grid_layout_get_preferred_size(W32Widget *widget) {
--- a/ui/win32/container.h	Wed Nov 26 19:39:37 2025 +0100
+++ b/ui/win32/container.h	Thu Nov 27 15:15:09 2025 +0100
@@ -98,7 +98,7 @@
 HWND ui_container_get_parent(UiContainerPrivate *ctn);
 void ui_container_add(UiContainerPrivate *ctn, W32Widget *widget, UiLayout *layout);
 
-void ui_grid_widget_event(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
+int ui_grid_widget_event(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
 W32Size ui_grid_layout_get_preferred_size(W32Widget *widget);
 
 UiContainerX* ui_box_container_create(UiObject *obj, HWND hwnd, UiBoxOrientation orientation, short spacing, GridEdgeInsets padding);
--- a/ui/win32/list.c	Wed Nov 26 19:39:37 2025 +0100
+++ b/ui/win32/list.c	Thu Nov 27 15:15:09 2025 +0100
@@ -196,7 +196,7 @@
 }
 
 // listview class event proc
-void ui_listview_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
+int ui_listview_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
     UiListView *listview = (UiListView*)widget;
     switch (uMsg) {
         case WM_NOTIFY: {
@@ -249,6 +249,8 @@
             break;
         }
     }
+
+    return 0;
 }
 
 W32Size ui_listview_get_preferred_size(W32Widget *widget) {
@@ -391,8 +393,8 @@
     return (W32Widget*)dropdown;
 }
 
-void ui_dropdown_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
-
+int ui_dropdown_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
+    return 0;
 }
 
 W32Size ui_dropdown_get_preferred_size(W32Widget *widget) {
--- a/ui/win32/list.h	Wed Nov 26 19:39:37 2025 +0100
+++ b/ui/win32/list.h	Thu Nov 27 15:15:09 2025 +0100
@@ -62,14 +62,14 @@
     void* ondropdata;
 } UiListView;
 
-void ui_listview_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
+int ui_listview_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
 W32Size ui_listview_get_preferred_size(W32Widget *widget);
 
 void ui_listview_update(UiList *list, int row);
 UiListSelection ui_listview_getselection(UiList *list);
 void ui_listview_setselection(UiList *list, UiListSelection selection);
 
-void ui_dropdown_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
+int ui_dropdown_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
 W32Size ui_dropdown_get_preferred_size(W32Widget *widget);
 
 void ui_dropdown_update(UiList *list, int row);
--- a/ui/win32/text.c	Wed Nov 26 19:39:37 2025 +0100
+++ b/ui/win32/text.c	Thu Nov 27 15:15:09 2025 +0100
@@ -84,8 +84,8 @@
     return (W32Size){ .width = textfield->width, .height = 32};
 }
 
-void ui_textfield_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
-
+int ui_textfield_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
+    return 0;
 }
 
 char* ui_textfield_get(UiString *s) {
--- a/ui/win32/text.h	Wed Nov 26 19:39:37 2025 +0100
+++ b/ui/win32/text.h	Thu Nov 27 15:15:09 2025 +0100
@@ -39,7 +39,7 @@
 } UiTextField;
 
 W32Size ui_textfield_get_preferred_size(W32Widget *widget);
-void ui_textfield_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
+int ui_textfield_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
 
 char* ui_textfield_get(UiString *s);
 void ui_textfield_set(UiString *s, const char *value);
--- a/ui/win32/toolkit.c	Wed Nov 26 19:39:37 2025 +0100
+++ b/ui/win32/toolkit.c	Thu Nov 27 15:15:09 2025 +0100
@@ -129,11 +129,13 @@
 }
 
 LRESULT CALLBACK ui_default_eventproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
-    fflush(stdout);
     W32Widget *widget = (W32Widget*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
     if (widget && widget->wclass->eventproc) {
-        widget->wclass->eventproc(widget, hwnd, uMsg, wParam, lParam);
+        if (widget->wclass->eventproc(widget, hwnd, uMsg, wParam, lParam)) {
+            return 1;
+        }
     }
+
     switch(uMsg) {
         case WM_DESTROY: {
             PostQuitMessage(0);
@@ -164,7 +166,7 @@
             }
             break;
         }
-        default: return DefWindowProc(hwnd, uMsg, wParam, lParam);
+        default: break;//return DefWindowProc(hwnd, uMsg, wParam, lParam);
     }
-    return 0;
+    return DefWindowProc(hwnd, uMsg, wParam, lParam);;
 }
\ No newline at end of file
--- a/ui/win32/window.c	Wed Nov 26 19:39:37 2025 +0100
+++ b/ui/win32/window.c	Thu Nov 27 15:15:09 2025 +0100
@@ -108,8 +108,9 @@
 }
 
 
-void ui_window_widget_event(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
+int ui_window_widget_event(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
 	//UiWindow *window = (UiWindow*)widget;
+	return 0;
 }
 
 void ui_window_widget_show(W32Widget *w, BOOLEAN show) {
--- a/ui/win32/window.h	Wed Nov 26 19:39:37 2025 +0100
+++ b/ui/win32/window.h	Thu Nov 27 15:15:09 2025 +0100
@@ -48,7 +48,7 @@
 
 void ui_window_init(void);
 
-void ui_window_widget_event(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
+int ui_window_widget_event(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
 void ui_window_widget_show(W32Widget *w, BOOLEAN show);
 
 #ifdef	__cplusplus

mercurial