Resolved a bunch of TODOs. Added one.
This commit is contained in:
parent
5719004a97
commit
002d95c2c2
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
|
@ -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!
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -12,9 +12,3 @@ void uiQuit(void)
|
|||
{
|
||||
gtk_main_quit();
|
||||
}
|
||||
|
||||
// TODO move somewhere else
|
||||
uintptr_t uiControlHandle(uiControl *c)
|
||||
{
|
||||
return (*(c->handle))(c);
|
||||
}
|
||||
|
|
|
@ -54,9 +54,3 @@ void uiQuit(void)
|
|||
{
|
||||
PostQuitMessage(0);
|
||||
}
|
||||
|
||||
// TODO move somewhere else
|
||||
uintptr_t uiControlHandle(uiControl *c)
|
||||
{
|
||||
return (*(c->handle))(c);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue