summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2015-04-07 03:39:47 -0400
committerPietro Gagliardi <[email protected]>2015-04-07 03:39:47 -0400
commit54dd1f40017dc31cc5f302cf67cd15ecb562daa1 (patch)
tree10da4eb50f3dd26dfd4e1f01f1c9aa4bc1067c68
parentc4045909606cbc7733846ef7ca482d27bddd2e30 (diff)
Hooked up resizing. Now to make a control that uses this.
-rw-r--r--new/ui_windows.h4
-rw-r--r--new/uipriv_windows.h1
-rw-r--r--new/util_windows.c29
-rw-r--r--new/window_windows.c12
4 files changed, 46 insertions, 0 deletions
diff --git a/new/ui_windows.h b/new/ui_windows.h
index 330b7cb..6186a61 100644
--- a/new/ui_windows.h
+++ b/new/ui_windows.h
@@ -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
diff --git a/new/uipriv_windows.h b/new/uipriv_windows.h
index c7527c0..d415100 100644
--- a/new/uipriv_windows.h
+++ b/new/uipriv_windows.h
@@ -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);
diff --git a/new/util_windows.c b/new/util_windows.c
index 6292967..39bffc3 100644
--- a/new/util_windows.c
+++ b/new/util_windows.c
@@ -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);
+}
diff --git a/new/window_windows.c b/new/window_windows.c
index c0ca6c3..d5f675e 100644
--- a/new/window_windows.c
+++ b/new/window_windows.c
@@ -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;