From 002d95c2c26823c200bc672a5dc1011004308e32 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 7 Apr 2015 22:19:24 -0400 Subject: [PATCH] Resolved a bunch of TODOs. Added one. --- new/container_windows.c | 13 ++++++----- new/control.c | 9 ++++++++ new/init_windows.c | 48 +++++++++++++++-------------------------- new/main_darwin.m | 6 ------ new/main_unix.c | 6 ------ new/main_windows.c | 6 ------ 6 files changed, 32 insertions(+), 56 deletions(-) create mode 100644 new/control.c diff --git a/new/container_windows.c b/new/container_windows.c index 90ebab1..2056653 100644 --- a/new/container_windows.c +++ b/new/container_windows.c @@ -55,7 +55,6 @@ BOOL sharedWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT * return FALSE; } -// TODO add function names to errors void resize(uiControl *control, HWND parent, RECT r) { uiSizing d; @@ -66,20 +65,20 @@ void resize(uiControl *control, HWND parent, RECT r) dc = GetDC(parent); if (dc == NULL) - logLastError("error getting DC for preferred size calculations"); + logLastError("error getting DC in resize()"); prevfont = (HFONT) SelectObject(dc, hMessageFont); if (prevfont == NULL) - logLastError("error loading control font into device context for preferred size calculation"); + logLastError("error loading control font into device context in resize()"); if (GetTextMetricsW(dc, &tm) == 0) - logLastError("error getting text metrics for preferred size calculations"); + logLastError("error getting text metrics in resize()"); if (GetTextExtentPoint32W(dc, L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 52, &size) == 0) - logLastError("error getting text extent point for preferred size calculations"); + logLastError("error getting text extent point in resize()"); d.baseX = (int) ((size.cx / 26 + 1) / 2); d.baseY = (int) tm.tmHeight; d.internalLeading = tm.tmInternalLeading; if (SelectObject(dc, prevfont) != hMessageFont) - logLastError("error restoring previous font into device context after preferred size calculations"); + logLastError("error restoring previous font into device context in resize()"); if (ReleaseDC(parent, dc) == 0) - logLastError("error releasing DC for preferred size calculations"); + logLastError("error releasing DC in resize()"); (*(control->resize))(control, r.left, r.top, r.right - r.left, r.bottom - r.top, &d); } diff --git a/new/control.c b/new/control.c new file mode 100644 index 0000000..c3ee677 --- /dev/null +++ b/new/control.c @@ -0,0 +1,9 @@ +// 7 april 2015 +#include "uipriv.h" + +uintptr_t uiControlHandle(uiControl *c) +{ + return (*(c->handle))(c); +} + +// TODO do this for the others diff --git a/new/init_windows.c b/new/init_windows.c index 7b01b1a..c484ed3 100644 --- a/new/init_windows.c +++ b/new/init_windows.c @@ -13,7 +13,7 @@ struct uiInitError { char failbuf[256]; }; -static void loadLastError(uiInitError *err, const char *message) +static uiInitError *loadLastError(uiInitError *err, const char *message) { DWORD le; @@ -22,6 +22,7 @@ static void loadLastError(uiInitError *err, const char *message) // TODO make sure argument is right; _snprintf_s() isn't supported on Windows XP snprintf(err->failbuf, 256, "error %s (last error %I32u)", message, le); err->msg = err->failbuf; + return err; } uiInitError *uiInit(uiInitOptions *o) @@ -33,13 +34,11 @@ uiInitError *uiInit(uiInitOptions *o) HCURSOR hDefaultCursor; NONCLIENTMETRICSW ncm; - err = (uiInitError *) uiAlloc(sizeof (uiInitError)); + err = uiNew(uiInitError); hInstance = GetModuleHandle(NULL); - if (hInstance == NULL) { - loadLastError(err, "getting program HINSTANCE"); - return err; - } + if (hInstance == NULL) + return loadLastError(err, "getting program HINSTANCE"); nCmdShow = SW_SHOWDEFAULT; GetStartupInfoW(&si); @@ -47,40 +46,27 @@ uiInitError *uiInit(uiInitOptions *o) nCmdShow = si.wShowWindow; // TODO add "in initCommonControls()" to each of the messages this returns - // TODO make loadLastError() return err directly ce = initCommonControls(); - if (ce != NULL) { - loadLastError(err, ce); - return err; - } + if (ce != NULL) + return loadLastError(err, ce); hDefaultIcon = LoadIconW(NULL, IDI_APPLICATION); - if (hDefaultIcon == NULL) { - loadLastError(err, "loading default icon for window classes"); - return err; - } + if (hDefaultIcon == NULL) + return loadLastError(err, "loading default icon for window classes"); hDefaultCursor = LoadCursorW(NULL, IDC_ARROW); - if (hDefaultCursor == NULL) { - loadLastError(err, "loading default cursor for window classes"); - return err; - } + if (hDefaultCursor == NULL) + return loadLastError(err, "loading default cursor for window classes"); - if (registerWindowClass(hDefaultIcon, hDefaultCursor) == 0) { - loadLastError(err, "registering uiWindow window class"); - return err; - } + if (registerWindowClass(hDefaultIcon, hDefaultCursor) == 0) + return loadLastError(err, "registering uiWindow window class"); ZeroMemory(&ncm, sizeof (NONCLIENTMETRICSW)); ncm.cbSize = sizeof (NONCLIENTMETRICSW); - if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof (NONCLIENTMETRICSW), &ncm, sizeof (NONCLIENTMETRICSW)) == 0) { - loadLastError(err, "getting default fonts"); - return err; - } + if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof (NONCLIENTMETRICSW), &ncm, sizeof (NONCLIENTMETRICSW)) == 0) + return loadLastError(err, "getting default fonts"); hMessageFont = CreateFontIndirectW(&(ncm.lfMessageFont)); - if (hMessageFont == NULL) { - loadLastError(err, "loading default messagebox font; this is the default UI font"); - return err; - } + if (hMessageFont == NULL) + return loadLastError(err, "loading default messagebox font; this is the default UI font"); // give each control a reasonable initial parent // don't free the initial parent! diff --git a/new/main_darwin.m b/new/main_darwin.m index 307b0a3..d19af08 100644 --- a/new/main_darwin.m +++ b/new/main_darwin.m @@ -26,9 +26,3 @@ void uiQuit(void) [NSApp postEvent:e atStart:NO]; // let pending events take priority // TODO really wait? } - -// TODO move somewhere else -uintptr_t uiControlHandle(uiControl *c) -{ - return (*(c->handle))(c); -} diff --git a/new/main_unix.c b/new/main_unix.c index aae049b..90374c7 100644 --- a/new/main_unix.c +++ b/new/main_unix.c @@ -12,9 +12,3 @@ void uiQuit(void) { gtk_main_quit(); } - -// TODO move somewhere else -uintptr_t uiControlHandle(uiControl *c) -{ - return (*(c->handle))(c); -} diff --git a/new/main_windows.c b/new/main_windows.c index 9c8132a..bd973b7 100644 --- a/new/main_windows.c +++ b/new/main_windows.c @@ -54,9 +54,3 @@ void uiQuit(void) { PostQuitMessage(0); } - -// TODO move somewhere else -uintptr_t uiControlHandle(uiControl *c) -{ - return (*(c->handle))(c); -}