From a226c80993be2a59f9214d1ac570406bc9d35964 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 29 May 2016 19:55:53 -0400 Subject: [PATCH] More TODO resolution and elimination and delegation and explanation. --- windows/combobox.cpp | 7 ++----- windows/editablecombo.cpp | 13 +++++-------- windows/fontbutton.cpp | 2 +- windows/group.cpp | 22 ++++++++++++++++------ windows/init.cpp | 15 ++++++++------- windows/main.cpp | 16 +++++++++------- windows/menu.cpp | 14 ++++++++------ windows/utilwin.cpp | 5 +++-- 8 files changed, 52 insertions(+), 42 deletions(-) diff --git a/windows/combobox.cpp b/windows/combobox.cpp index cb09e00d..ac10f211 100644 --- a/windows/combobox.cpp +++ b/windows/combobox.cpp @@ -1,9 +1,6 @@ // 20 may 2015 #include "uipriv_windows.hpp" -// TODO -// - is there extra space on the bottom? - // we as Common Controls 6 users don't need to worry about the height of comboboxes; see http://blogs.msdn.com/b/oldnewthing/archive/2006/03/10/548537.aspx struct uiCombobox { @@ -36,8 +33,8 @@ void uiComboboxDestroy(uiControl *cc) uiWindowsControlAllDefaultsExceptDestroy(uiCombobox) // from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing -#define comboboxWidth 107 /* this is actually the shorter progress bar width, but Microsoft only indicates as wide as necessary; TODO */ -#define comboboxHeight 14 +#define comboboxWidth 107 /* this is actually the shorter progress bar width, but Microsoft only indicates as wide as necessary; LONGTERM */ +#define comboboxHeight 14 /* LONGTERM: is this too high? */ static void uiComboboxMinimumSize(uiWindowsControl *cc, intmax_t *width, intmax_t *height) { diff --git a/windows/editablecombo.cpp b/windows/editablecombo.cpp index 4c3820d1..38d38aab 100644 --- a/windows/editablecombo.cpp +++ b/windows/editablecombo.cpp @@ -1,9 +1,6 @@ // 20 may 2015 #include "uipriv_windows.hpp" -// TODO -// - is there extra space on the bottom? - // we as Common Controls 6 users don't need to worry about the height of comboboxes; see http://blogs.msdn.com/b/oldnewthing/archive/2006/03/10/548537.aspx struct uiEditableCombobox { @@ -19,11 +16,11 @@ static BOOL onWM_COMMAND(uiControl *cc, HWND hwnd, WORD code, LRESULT *lResult) if (code == CBN_SELCHANGE) { // like on OS X, this is sent before the edit has been updated :( - // TODO error check - PostMessage(parentOf(hwnd), + if (PostMessage(parentOf(hwnd), WM_COMMAND, MAKEWPARAM(GetWindowLongPtrW(hwnd, GWLP_ID), CBN_EDITCHANGE), - (LPARAM) hwnd); + (LPARAM) hwnd) == 0) + logLastError(L"error posting CBN_EDITCHANGE after CBN_SELCHANGE"); *lResult = 0; return TRUE; } @@ -46,8 +43,8 @@ void uiEditableComboboxDestroy(uiControl *cc) uiWindowsControlAllDefaultsExceptDestroy(uiEditableCombobox) // from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing -#define comboboxWidth 107 /* this is actually the shorter progress bar width, but Microsoft only indicates as wide as necessary; TODO */ -#define comboboxHeight 14 +#define comboboxWidth 107 /* this is actually the shorter progress bar width, but Microsoft only indicates as wide as necessary; LONGTERM */ +#define comboboxHeight 14 /* LONGTERM: is this too high? */ static void uiEditableComboboxMinimumSize(uiWindowsControl *cc, intmax_t *width, intmax_t *height) { diff --git a/windows/fontbutton.cpp b/windows/fontbutton.cpp index c4f841db..b0f2c047 100644 --- a/windows/fontbutton.cpp +++ b/windows/fontbutton.cpp @@ -25,7 +25,7 @@ static void updateFontButtonLabel(uiFontButton *b) WCHAR *text; text = fontDialogParamsToString(&(b->params)); - setWindowText(text); + setWindowText(b->hwnd, text); uiFree(text); // changing the text might necessitate a change in the button's size diff --git a/windows/group.cpp b/windows/group.cpp index 3af67acd..b1e4c653 100644 --- a/windows/group.cpp +++ b/windows/group.cpp @@ -93,15 +93,18 @@ static void uiGroupMinimumSize(uiWindowsControl *c, intmax_t *width, intmax_t *h { uiGroup *g = uiGroup(c); int mx, mtop, mbottom; + intmax_t labelWidth; *width = 0; *height = 0; if (g->child != NULL) uiWindowsControlMinimumSize(uiWindowsControl(g->child), width, height); + labelWidth = uiWindowsWindowTextWidth(g->hwnd); + if (*width < labelWidth) // don't clip the label; it doesn't ellipsize + *width = labelWidth; groupMargins(g, &mx, &mtop, &mbottom); *width += 2 * mx; *height += mtop + mbottom; - // TODO label width? and when? } static void uiGroupMinimumSizeChanged(uiWindowsControl *c) @@ -159,18 +162,25 @@ void uiGroupSetMargined(uiGroup *g, int margined) static LRESULT CALLBACK groupSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) { uiGroup *g = uiGroup(dwRefData); + WINDOWPOS *wp = (WINDOWPOS *) lParam; + MINMAXINFO *mmi = (MINMAXINFO *) lParam; + intmax_t minwid, minht; LRESULT lResult; if (handleParentMessages(hwnd, uMsg, wParam, lParam, &lResult) != FALSE) return lResult; switch (uMsg) { case WM_WINDOWPOSCHANGED: - // TODO check - // TODO add check in container.c + if ((wp->flags & SWP_NOSIZE) != 0) + break; groupRelayout(g); - // TODO is this right? - break; - // TODO WM_GETMINMAXINFO + return 0; + case WM_GETMINMAXINFO: + lResult = DefWindowProcW(hwnd, uMsg, wParam, lParam); + uiWindowsControlMinimumSize(uiWindowsControl(g), &minwid, &minht); + mmi->ptMinTrackSize.x = minwid; + mmi->ptMinTrackSize.y = minht; + return lResult; case WM_NCDESTROY: if (RemoveWindowSubclass(hwnd, groupSubProc, uIdSubclass) == FALSE) logLastError(L"error removing groupbox subclass"); diff --git a/windows/init.cpp b/windows/init.cpp index 2de75c4f..c91929f9 100644 --- a/windows/init.cpp +++ b/windows/init.cpp @@ -6,7 +6,7 @@ int nCmdShow; HFONT hMessageFont; -// TODO needed? +// LONGTERM needed? HBRUSH hollowBrush; // the returned pointer is actually to the second character @@ -38,7 +38,7 @@ static const char *initerr(const char *message, const WCHAR *label, DWORD value) #define ieLastErr(msg) initerr("=" msg, L"GetLastError() ==", GetLastError()) #define ieHRESULT(msg, hr) initerr("=" msg, L"HRESULT", (DWORD) hr) -// TODO make common +// LONGTERM make common uiInitOptions options; #define wantedICCClasses ( \ @@ -70,6 +70,8 @@ const char *uiInit(uiInitOptions *o) if ((si.dwFlags & STARTF_USESHOWWINDOW) != 0) nCmdShow = si.wShowWindow; + // LONGTERM set DPI awareness + hDefaultIcon = LoadIconW(NULL, IDI_APPLICATION); if (hDefaultIcon == NULL) return ieLastErr("loading default icon for window classes"); @@ -79,7 +81,7 @@ const char *uiInit(uiInitOptions *o) ce = initUtilWindow(hDefaultIcon, hDefaultCursor); if (ce != NULL) - return ieLastErr("TODO use ce here"); + return initerr(ce, L"GetLastError() ==", GetLastError()); if (registerWindowClass(hDefaultIcon, hDefaultCursor) == 0) return ieLastErr("registering uiWindow window class"); @@ -92,9 +94,8 @@ const char *uiInit(uiInitOptions *o) if (hMessageFont == NULL) return ieLastErr("loading default messagebox font; this is the default UI font"); - // TODO rewrite this error message if (initContainer(hDefaultIcon, hDefaultCursor) == 0) - return ieLastErr("initializing uiMakeContainer() window class"); + return ieLastErr("initializing uiWindowsMakeContainer() window class"); hollowBrush = (HBRUSH) GetStockObject(HOLLOW_BRUSH); if (hollowBrush == NULL) @@ -109,8 +110,8 @@ const char *uiInit(uiInitOptions *o) hr = CoInitialize(NULL); if (hr != S_OK && hr != S_FALSE) return ieHRESULT("initializing COM", hr); - // TODO initialize COM security - // TODO (windows vista) turn off COM exception handling + // LONGTERM initialize COM security + // LONGTERM (windows vista) turn off COM exception handling hr = initDraw(); if (hr != S_OK) diff --git a/windows/main.cpp b/windows/main.cpp index 3edd8635..1db790cb 100644 --- a/windows/main.cpp +++ b/windows/main.cpp @@ -45,13 +45,15 @@ void unregisterMessageFilter(void) static void processMessage(MSG *msg) { - HWND active; + HWND correctParent; - // TODO really active? or parentToplevel(msg->hwnd)? - active = GetActiveWindow(); - if (active != NULL) - // TODO find documentation that says IsDialogMessage() calls CallMsgFilter() for us, because that's what's happening - if (IsDialogMessage(active, msg) != 0) + if (msg->hwnd != NULL) + correctParent = parentToplevel(msg->hwnd); + else // just to be safe + correctParent = GetActiveWindow(); + if (correctParent != NULL) + // this calls our mesage filter above for us + if (IsDialogMessage(correctParent, msg) != 0) return; TranslateMessage(msg); DispatchMessageW(msg); @@ -118,6 +120,6 @@ void uiQuit(void) void uiQueueMain(void (*f)(void *data), void *data) { if (PostMessageW(utilWindow, msgQueued, (WPARAM) f, (LPARAM) data) == 0) - // TODO this is likely not safe to call across threads (allocates memory) + // LONGTERM this is likely not safe to call across threads (allocates memory) logLastError(L"error queueing function to run on main thread"); } diff --git a/windows/menu.cpp b/windows/menu.cpp index 484bf756..bfac0129 100644 --- a/windows/menu.cpp +++ b/windows/menu.cpp @@ -1,7 +1,7 @@ // 24 april 2015 #include "uipriv_windows.hpp" -// TODO migrate to std::vector +// LONGTERM migrate to std::vector static uiMenu **menus = NULL; static uintmax_t len = 0; @@ -146,10 +146,12 @@ static uiMenuItem *newItem(uiMenu *m, int type, const char *name) curID++; } - // TODO copy this from the unix one - item->onClicked = defaultOnClicked; - if (item->type == typeQuit) + if (item->type == typeQuit) { + // can't call uiMenuItemOnClicked() here item->onClicked = onQuitClicked; + item->onClickedData = NULL; + } else + uiMenuItemOnClicked(item, defaultOnClicked, NULL); return item; } @@ -185,7 +187,7 @@ uiMenuItem *uiMenuAppendPreferencesItem(uiMenu *m) uiMenuItem *uiMenuAppendAboutItem(uiMenu *m) { if (hasAbout) - // TODO place these userbug strings in a header? + // TODO place these userbug strings in a header userbug("You can not have multiple About menu items in a program."); hasAbout = TRUE; newItem(m, typeSeparator, NULL); @@ -350,7 +352,7 @@ void uninitMenus(void) for (j = 0; j < m->len; j++) { item = m->items[j]; if (item->len != 0) - // TODO userbug()? + // LONGTERM userbug()? implbug("menu item %p (%ws) still has uiWindows attached; did you forget to destroy some windows?", item, item->name); if (item->name != NULL) uiFree(item->name); diff --git a/windows/utilwin.cpp b/windows/utilwin.cpp index 992eea68..414ae83a 100644 --- a/windows/utilwin.cpp +++ b/windows/utilwin.cpp @@ -51,7 +51,8 @@ const char *initUtilWindow(HICON hDefaultIcon, HCURSOR hDefaultCursor) wc.hCursor = hDefaultCursor; wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); if (RegisterClass(&wc) == 0) - return "registering utility window class"; + // see init.cpp for an explanation of the =s + return "=registering utility window class"; utilWindow = CreateWindowExW(0, utilWindowClass, L"libui utility window", @@ -59,7 +60,7 @@ const char *initUtilWindow(HICON hDefaultIcon, HCURSOR hDefaultCursor) 0, 0, 100, 100, NULL, NULL, hInstance, NULL); if (utilWindow == NULL) - return "creating utility window"; + return "=creating utility window"; // and just to be safe EnableWindow(utilWindow, FALSE);