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;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO add function names to errors
|
|
||||||
void resize(uiControl *control, HWND parent, RECT r)
|
void resize(uiControl *control, HWND parent, RECT r)
|
||||||
{
|
{
|
||||||
uiSizing d;
|
uiSizing d;
|
||||||
|
@ -66,20 +65,20 @@ void resize(uiControl *control, HWND parent, RECT r)
|
||||||
|
|
||||||
dc = GetDC(parent);
|
dc = GetDC(parent);
|
||||||
if (dc == NULL)
|
if (dc == NULL)
|
||||||
logLastError("error getting DC for preferred size calculations");
|
logLastError("error getting DC in resize()");
|
||||||
prevfont = (HFONT) SelectObject(dc, hMessageFont);
|
prevfont = (HFONT) SelectObject(dc, hMessageFont);
|
||||||
if (prevfont == NULL)
|
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)
|
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)
|
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.baseX = (int) ((size.cx / 26 + 1) / 2);
|
||||||
d.baseY = (int) tm.tmHeight;
|
d.baseY = (int) tm.tmHeight;
|
||||||
d.internalLeading = tm.tmInternalLeading;
|
d.internalLeading = tm.tmInternalLeading;
|
||||||
if (SelectObject(dc, prevfont) != hMessageFont)
|
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)
|
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);
|
(*(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];
|
char failbuf[256];
|
||||||
};
|
};
|
||||||
|
|
||||||
static void loadLastError(uiInitError *err, const char *message)
|
static uiInitError *loadLastError(uiInitError *err, const char *message)
|
||||||
{
|
{
|
||||||
DWORD le;
|
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
|
// 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);
|
snprintf(err->failbuf, 256, "error %s (last error %I32u)", message, le);
|
||||||
err->msg = err->failbuf;
|
err->msg = err->failbuf;
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
uiInitError *uiInit(uiInitOptions *o)
|
uiInitError *uiInit(uiInitOptions *o)
|
||||||
|
@ -33,13 +34,11 @@ uiInitError *uiInit(uiInitOptions *o)
|
||||||
HCURSOR hDefaultCursor;
|
HCURSOR hDefaultCursor;
|
||||||
NONCLIENTMETRICSW ncm;
|
NONCLIENTMETRICSW ncm;
|
||||||
|
|
||||||
err = (uiInitError *) uiAlloc(sizeof (uiInitError));
|
err = uiNew(uiInitError);
|
||||||
|
|
||||||
hInstance = GetModuleHandle(NULL);
|
hInstance = GetModuleHandle(NULL);
|
||||||
if (hInstance == NULL) {
|
if (hInstance == NULL)
|
||||||
loadLastError(err, "getting program HINSTANCE");
|
return loadLastError(err, "getting program HINSTANCE");
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
nCmdShow = SW_SHOWDEFAULT;
|
nCmdShow = SW_SHOWDEFAULT;
|
||||||
GetStartupInfoW(&si);
|
GetStartupInfoW(&si);
|
||||||
|
@ -47,40 +46,27 @@ uiInitError *uiInit(uiInitOptions *o)
|
||||||
nCmdShow = si.wShowWindow;
|
nCmdShow = si.wShowWindow;
|
||||||
|
|
||||||
// TODO add "in initCommonControls()" to each of the messages this returns
|
// TODO add "in initCommonControls()" to each of the messages this returns
|
||||||
// TODO make loadLastError() return err directly
|
|
||||||
ce = initCommonControls();
|
ce = initCommonControls();
|
||||||
if (ce != NULL) {
|
if (ce != NULL)
|
||||||
loadLastError(err, ce);
|
return loadLastError(err, ce);
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
hDefaultIcon = LoadIconW(NULL, IDI_APPLICATION);
|
hDefaultIcon = LoadIconW(NULL, IDI_APPLICATION);
|
||||||
if (hDefaultIcon == NULL) {
|
if (hDefaultIcon == NULL)
|
||||||
loadLastError(err, "loading default icon for window classes");
|
return loadLastError(err, "loading default icon for window classes");
|
||||||
return err;
|
|
||||||
}
|
|
||||||
hDefaultCursor = LoadCursorW(NULL, IDC_ARROW);
|
hDefaultCursor = LoadCursorW(NULL, IDC_ARROW);
|
||||||
if (hDefaultCursor == NULL) {
|
if (hDefaultCursor == NULL)
|
||||||
loadLastError(err, "loading default cursor for window classes");
|
return loadLastError(err, "loading default cursor for window classes");
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (registerWindowClass(hDefaultIcon, hDefaultCursor) == 0) {
|
if (registerWindowClass(hDefaultIcon, hDefaultCursor) == 0)
|
||||||
loadLastError(err, "registering uiWindow window class");
|
return loadLastError(err, "registering uiWindow window class");
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
ZeroMemory(&ncm, sizeof (NONCLIENTMETRICSW));
|
ZeroMemory(&ncm, sizeof (NONCLIENTMETRICSW));
|
||||||
ncm.cbSize = sizeof (NONCLIENTMETRICSW);
|
ncm.cbSize = sizeof (NONCLIENTMETRICSW);
|
||||||
if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof (NONCLIENTMETRICSW), &ncm, sizeof (NONCLIENTMETRICSW)) == 0) {
|
if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof (NONCLIENTMETRICSW), &ncm, sizeof (NONCLIENTMETRICSW)) == 0)
|
||||||
loadLastError(err, "getting default fonts");
|
return loadLastError(err, "getting default fonts");
|
||||||
return err;
|
|
||||||
}
|
|
||||||
hMessageFont = CreateFontIndirectW(&(ncm.lfMessageFont));
|
hMessageFont = CreateFontIndirectW(&(ncm.lfMessageFont));
|
||||||
if (hMessageFont == NULL) {
|
if (hMessageFont == NULL)
|
||||||
loadLastError(err, "loading default messagebox font; this is the default UI font");
|
return loadLastError(err, "loading default messagebox font; this is the default UI font");
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
// give each control a reasonable initial parent
|
// give each control a reasonable initial parent
|
||||||
// don't free the 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
|
[NSApp postEvent:e atStart:NO]; // let pending events take priority
|
||||||
// TODO really wait?
|
// 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();
|
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);
|
PostQuitMessage(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO move somewhere else
|
|
||||||
uintptr_t uiControlHandle(uiControl *c)
|
|
||||||
{
|
|
||||||
return (*(c->handle))(c);
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue