--- a/ui/win32/toolkit.c Sun Dec 07 20:00:33 2025 +0100 +++ b/ui/win32/toolkit.c Sat Dec 13 15:58:58 2025 +0100 @@ -35,6 +35,7 @@ #include "../common/toolbar.h" #include "../common/document.h" #include "../common/properties.h" +#include "../common/app.h" #include "../ui/widget.h" @@ -45,13 +46,6 @@ static const char *application_name; -static ui_callback startup_func; -static void *startup_data; -static ui_callback open_func; -void *open_data; -static ui_callback exit_func; -void *exit_data; - static HFONT ui_font = NULL; void ui_init(const char *appname, int argc, char **argv) { @@ -62,9 +56,10 @@ uic_toolbar_init(); uic_load_app_properties(); - ui_window_init(); - - INITCOMMONCONTROLSEX icex = { sizeof(icex), ICC_WIN95_CLASSES }; + INITCOMMONCONTROLSEX icex = { + sizeof(icex), + ICC_WIN95_CLASSES | ICC_LISTVIEW_CLASSES | ICC_TREEVIEW_CLASSES | ICC_BAR_CLASSES | ICC_TAB_CLASSES | ICC_STANDARD_CLASSES | ICC_USEREX_CLASSES + }; InitCommonControlsEx(&icex); SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); @@ -72,6 +67,8 @@ NONCLIENTMETRICS ncm = { sizeof(ncm) }; SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, FALSE); ui_font = CreateFontIndirect(&ncm.lfMessageFont); + + ui_window_init(); } HFONT ui_win32_get_font(void) { @@ -88,25 +85,8 @@ return application_name; } -void ui_onstartup(ui_callback f, void *userdata) { - startup_func = f; - startup_data = userdata; -} - -void ui_onopen(ui_callback f, void *userdata) { - open_func = f; - open_data = userdata; -} - -void ui_onexit(ui_callback f, void *userdata) { - exit_func = f; - exit_data = userdata; -} - void ui_main() { - if(startup_func) { - startup_func(NULL, startup_data); - } + uic_application_startup(NULL); // event loop MSG msg; @@ -115,9 +95,7 @@ DispatchMessage(&msg); } - if(exit_func) { - exit_func(NULL, exit_data); - } + uic_application_exit(NULL); uic_store_app_properties(); } @@ -128,8 +106,11 @@ 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); + if (widget->wclass->eventproc(widget, hwnd, uMsg, wParam, lParam)) { + return 1; + } } + switch(uMsg) { case WM_DESTROY: { PostQuitMessage(0); @@ -141,16 +122,30 @@ if (cmdWidget && cmdWidget->wclass->eventproc) { cmdWidget->wclass->eventproc(cmdWidget, hwnd, uMsg, wParam, lParam); } + break; + } + case WM_NOTIFY: { + LPNMHDR hdr = (LPNMHDR)lParam; + HWND hwndCtrl = hdr->hwndFrom; + W32Widget *cmdWidget = (W32Widget*)GetWindowLongPtr(hwndCtrl, GWLP_USERDATA); + if (cmdWidget && cmdWidget->wclass->eventproc) { + cmdWidget->wclass->eventproc(cmdWidget, hwnd, uMsg, wParam, lParam); + } + break; } case WM_SIZE: { int width = LOWORD(lParam); int height = HIWORD(lParam); - if (widget->layout) { + if (widget && widget->layout) { widget->layout(widget->layoutmanager, width, height); } break; } - default: return DefWindowProc(hwnd, uMsg, wParam, lParam); + default: break;//return DefWindowProc(hwnd, uMsg, wParam, lParam); } - return 0; -} \ No newline at end of file + return DefWindowProc(hwnd, uMsg, wParam, lParam);; +} + +void ui_call_mainthread(ui_threadfunc tf, void* td) { + // TODO +}