From 5e5415df001fb13f84567944736183704cbf469f Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 27 Apr 2015 22:06:13 -0400 Subject: [PATCH] Finished with windows/window.c migration. Let's try this thing! --- new/windows/OLDwindow.c | 64 ----------------------------------------- new/windows/window.c | 58 ++++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 65 deletions(-) delete mode 100644 new/windows/OLDwindow.c diff --git a/new/windows/OLDwindow.c b/new/windows/OLDwindow.c deleted file mode 100644 index bac769d1..00000000 --- a/new/windows/OLDwindow.c +++ /dev/null @@ -1,64 +0,0 @@ -// 6 april 2015 -#include "uipriv_windows.h" - -static LRESULT CALLBACK uiWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - struct window *w; - CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam; - WINDOWPOS *wp = (WINDOWPOS *) lParam; - RECT r; - HWND contenthwnd; - - w = (struct window *) GetWindowLongPtrW(hwnd, GWLP_USERDATA); - if (w == NULL) { - if (uMsg == WM_CREATE) - SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) (cs->lpCreateParams)); - // fall through to DefWindowProc() anyway - return DefWindowProcW(hwnd, uMsg, wParam, lParam); - } - switch (uMsg) { - case WM_COMMAND: - // not a menu - if (lParam != 0) - break; - if (HIWORD(wParam) != 0) - break; - runMenuEvent(LOWORD(wParam), uiWindow(w)); - return 0; - case WM_WINDOWPOSCHANGED: - if ((wp->flags & SWP_NOSIZE) != 0) - break; - // fall through - case msgUpdateChild: - if (GetClientRect(w->hwnd, &r) == 0) - logLastError("error getting window client rect for resize in uiWindowWndProc()"); - contenthwnd = uiOSContainerHWND(w->content); - if (MoveWindow(contenthwnd, r.left, r.top, r.right - r.left, r.bottom - r.top, TRUE) == 0) - logLastError("error resizing window content parent in uiWindowWndProc()"); - return 0; - case WM_CLOSE: - if (!(*(w->onClosing))(uiWindow(w), w->onClosingData)) - uiWindowDestroy(uiWindow(w)); - return 0; // we destroyed it already - case WM_DESTROY: - if (!w->canDestroy) - complain("attempt to destroy uiWindow at %p before uiWindowDestroy()", w); - uiFree(w); - break; // fall through to DefWindowProcW() - } - return DefWindowProcW(hwnd, uMsg, wParam, lParam); -} - -ATOM registerWindowClass(HICON hDefaultIcon, HCURSOR hDefaultCursor) -{ - WNDCLASSW wc; - - ZeroMemory(&wc, sizeof (WNDCLASSW)); - wc.lpszClassName = uiWindowClass; - wc.lpfnWndProc = uiWindowWndProc; - wc.hInstance = hInstance; - wc.hIcon = hDefaultIcon; - wc.hCursor = hDefaultCursor; - wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); - return RegisterClassW(&wc); -} diff --git a/new/windows/window.c b/new/windows/window.c index 71ff67d4..c2868e31 100644 --- a/new/windows/window.c +++ b/new/windows/window.c @@ -14,7 +14,62 @@ struct window { int margined; }; -// TODO window class and init functions +static LRESULT CALLBACK windowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + struct window *w; + CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam; + WINDOWPOS *wp = (WINDOWPOS *) lParam; + RECT r; + HWND boxhwnd; + + w = (struct window *) GetWindowLongPtrW(hwnd, GWLP_USERDATA); + if (w == NULL) { + if (uMsg == WM_CREATE) + SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) (cs->lpCreateParams)); + // fall through to DefWindowProc() anyway + return DefWindowProcW(hwnd, uMsg, wParam, lParam); + } + switch (uMsg) { + case WM_COMMAND: + // not a menu + if (lParam != 0) + break; + if (HIWORD(wParam) != 0) + break; + runMenuEvent(LOWORD(wParam), uiWindow(w)); + return 0; + case WM_WINDOWPOSCHANGED: + if ((wp->flags & SWP_NOSIZE) != 0) + break; + // fall through + case msgUpdateChild: + if (GetClientRect(w->hwnd, &r) == 0) + logLastError("error getting window client rect for resize in uiWindowWndProc()"); + boxhwnd = (HWND) uiControlHandle(uiControl(w->box)); + if (MoveWindow(boxhwnd, r.left, r.top, r.right - r.left, r.bottom - r.top, TRUE) == 0) + logLastError("error resizing uiWindow box in windowWndProc()"); + return 0; + case WM_CLOSE: + if (!(*(w->onClosing))(uiWindow(w), w->onClosingData)) + uiWindowDestroy(uiWindow(w)); + return 0; // we destroyed it already + } + return DefWindowProcW(hwnd, uMsg, wParam, lParam); +} + +ATOM registerWindowClass(HICON hDefaultIcon, HCURSOR hDefaultCursor) +{ + WNDCLASSW wc; + + ZeroMemory(&wc, sizeof (WNDCLASSW)); + wc.lpszClassName = windowClass; + wc.lpfnWndProc = windowWndProc; + wc.hInstance = hInstance; + wc.hIcon = hDefaultIcon; + wc.hCursor = hDefaultCursor; + wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); + return RegisterClassW(&wc); +} static int defaultOnClosing(uiWindow *w, void *data) { @@ -163,6 +218,7 @@ static void windowSetMargined(uiWindow *ww, int margined) binSetMargins(w->bin, 0, 0, 0, 0); } +// TODO destruction blocking uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar) { struct window *w;