Hooked up resizing. Now to make a control that uses this.
This commit is contained in:
parent
a09430113f
commit
fecb7caa14
|
@ -33,4 +33,8 @@ struct uiWindowsNewControlParams {
|
||||||
};
|
};
|
||||||
uiControl *uiWindowsNewControl(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
|
#endif
|
||||||
|
|
|
@ -64,6 +64,7 @@ extern HWND initialParent;
|
||||||
// util_windows.c
|
// util_windows.c
|
||||||
extern WCHAR *toUTF16(const char *);
|
extern WCHAR *toUTF16(const char *);
|
||||||
extern BOOL sharedWndProc(HWND, UINT, WPARAM, LPARAM, LRESULT *);
|
extern BOOL sharedWndProc(HWND, UINT, WPARAM, LPARAM, LRESULT *);
|
||||||
|
extern void resize(uiControl *, HWND, RECT);
|
||||||
|
|
||||||
// comctl32_windows.c
|
// comctl32_windows.c
|
||||||
extern BOOL (*WINAPI fv_SetWindowSubclass)(HWND, SUBCLASSPROC, UINT_PTR, DWORD_PTR);
|
extern BOOL (*WINAPI fv_SetWindowSubclass)(HWND, SUBCLASSPROC, UINT_PTR, DWORD_PTR);
|
||||||
|
|
|
@ -70,3 +70,32 @@ BOOL sharedWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *
|
||||||
*/ }
|
*/ }
|
||||||
return FALSE;
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
struct uiWindow {
|
struct uiWindow {
|
||||||
HWND hwnd;
|
HWND hwnd;
|
||||||
|
uiControl *child;
|
||||||
BOOL shownOnce;
|
BOOL shownOnce;
|
||||||
int (*onClosing)(uiWindow *, void *);
|
int (*onClosing)(uiWindow *, void *);
|
||||||
void *onClosingData;
|
void *onClosingData;
|
||||||
|
@ -15,6 +16,8 @@ static LRESULT CALLBACK uiWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPA
|
||||||
uiWindow *w;
|
uiWindow *w;
|
||||||
CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam;
|
CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam;
|
||||||
LRESULT lResult;
|
LRESULT lResult;
|
||||||
|
WINDOWPOS *wp = (WINDOWPOS *) lParam;
|
||||||
|
RECT r;
|
||||||
|
|
||||||
w = (uiWindow *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
|
w = (uiWindow *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
|
||||||
if (w == NULL) {
|
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)
|
if (sharedWndProc(hwnd, uMsg, wParam, lParam, &lResult) != FALSE)
|
||||||
return lResult;
|
return lResult;
|
||||||
switch (uMsg) {
|
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:
|
case WM_CLOSE:
|
||||||
if (!(*(w->onClosing))(w, w->onClosingData))
|
if (!(*(w->onClosing))(w, w->onClosingData))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue