Hooked up resizing. Now to make a control that uses this.

This commit is contained in:
Pietro Gagliardi 2015-04-07 03:39:47 -04:00
parent a09430113f
commit fecb7caa14
4 changed files with 46 additions and 0 deletions

View File

@ -33,4 +33,8 @@ struct uiWindowsNewControlParams {
};
uiControl *uiWindowsNewControl(uiWindowsNewControlParams *);
// use these in your preferredSize() implementation with baseX and baseY
#define uiDlgUnitToX(dlg, baseX) MulDiv((dlg), baseX, 4)
#define uiDlgUnitToY(dlg, baseY) MulDiv((dlg), baseY, 8)
#endif

View File

@ -64,6 +64,7 @@ extern HWND initialParent;
// util_windows.c
extern WCHAR *toUTF16(const char *);
extern BOOL sharedWndProc(HWND, UINT, WPARAM, LPARAM, LRESULT *);
extern void resize(uiControl *, HWND, RECT);
// comctl32_windows.c
extern BOOL (*WINAPI fv_SetWindowSubclass)(HWND, SUBCLASSPROC, UINT_PTR, DWORD_PTR);

View File

@ -70,3 +70,32 @@ BOOL sharedWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *
*/ }
return FALSE;
}
// TODO add function names
void resize(uiControl *control, HWND parent, RECT r)
{
uiSizing d;
HDC dc;
HFONT prevFont;
TEXTMETRICW tm;
SIZE size;
dc = GetDC(parent);
if (dc == NULL)
logLastError("error getting DC for preferred size calculations");
prevFont = (HFONT) SelectObject(dc, hMessageFont);
if (prevFont == NULL)
logLastError("error loading control font into device context for preferred size calculation");
if (GetTextMetricsW(dc, &tm) == 0)
logLastError("error getting text metrics for preferred size calculations");
if (GetTextExtentPoint32W(dc, L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 52, &size) == 0)
logLastError("error getting text extent point for preferred size calculations");
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");
if (ReleaseDC(parent, dc) == 0)
logLastError("error releasing DC for preferred size calculations");
(*(control->resize))(control, r.left, r.top, r.right - r.left, r.bottom - r.top, &d);
}

View File

@ -3,6 +3,7 @@
struct uiWindow {
HWND hwnd;
uiControl *child;
BOOL shownOnce;
int (*onClosing)(uiWindow *, void *);
void *onClosingData;
@ -15,6 +16,8 @@ static LRESULT CALLBACK uiWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPA
uiWindow *w;
CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam;
LRESULT lResult;
WINDOWPOS *wp = (WINDOWPOS *) lParam;
RECT r;
w = (uiWindow *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
if (w == NULL) {
@ -26,6 +29,15 @@ static LRESULT CALLBACK uiWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPA
if (sharedWndProc(hwnd, uMsg, wParam, lParam, &lResult) != FALSE)
return lResult;
switch (uMsg) {
case WM_WINDOWPOSCHANGING:
if (w->child == NULL)
break;
if ((wp->flags & SWP_NOSIZE) != 0)
break;
if (GetClientRect(w->hwnd, &r) == 0)
logLastError("error getting window client rect for resize in uiWindowWndProc()");
resize(w->child, w->hwnd, r);
return 0;
case WM_CLOSE:
if (!(*(w->onClosing))(w, w->onClosingData))
return 0;