Reworked container.cpp a bit to suit the new propagation system.

This commit is contained in:
Pietro Gagliardi 2016-04-28 17:18:51 -04:00
parent 3baa94476d
commit 447aa75dc6
2 changed files with 20 additions and 10 deletions

View File

@ -233,7 +233,7 @@ _UI_EXTERN void uiWindowsSizingDlgUnitsToPixels(uiWindowsSIzing *sizing, int *x,
_UI_EXTERN void uiWindowsSizingStandardPadding(uiWindowsSizing *sizing, int *x, int *y); _UI_EXTERN void uiWindowsSizingStandardPadding(uiWindowsSizing *sizing, int *x, int *y);
// TODO document // TODO document
_UI_EXTERN HWND uiWindowsMakeContainer(void (*onResize)(void *data), void *data); _UI_EXTERN HWND uiWindowsMakeContainer(uiWindowsControl *c, void (*onResize)(uiWindowsControl *));
// TODO document // TODO document
_UI_EXTERN BOOL uiWindowsControlTooSmall(uiWindowsControl *c); _UI_EXTERN BOOL uiWindowsControlTooSmall(uiWindowsControl *c);

View File

@ -6,8 +6,8 @@
// - uiRadioButtons // - uiRadioButtons
struct containerInit { struct containerInit {
void (*onResize)(void *data); uiWindowsControl *c;
void *data; void (*onResize)(uiWindowsControl *);
}; };
static LRESULT CALLBACK containerWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) static LRESULT CALLBACK containerWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
@ -17,9 +17,11 @@ static LRESULT CALLBACK containerWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LP
PAINTSTRUCT ps; PAINTSTRUCT ps;
CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam; CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam;
WINDOWPOS *wp = (WINDOWPOS *) lParam; WINDOWPOS *wp = (WINDOWPOS *) lParam;
MINMAXINFO *mm = (MINMAXINFO *) lParam;
struct containerInit *init; struct containerInit *init;
void (*onResize)(void *); uiWindowsControl *c;
void *data; void (*onResize)(uiWindowsControl *);
uintmax_t minwid, minht;
LRESULT lResult; LRESULT lResult;
if (handleParentMessages(hwnd, uMsg, wParam, lParam, &lResult) != FALSE) if (handleParentMessages(hwnd, uMsg, wParam, lParam, &lResult) != FALSE)
@ -28,15 +30,23 @@ static LRESULT CALLBACK containerWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LP
case WM_CREATE: case WM_CREATE:
init = (struct containerInit *) (cs->lpParam); init = (struct containerInit *) (cs->lpParam);
SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) (init->onResize)); SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) (init->onResize));
SetWindowLongPtrW(hwnd, 0, (LONG_PTR) (init->data)); SetWindowLongPtrW(hwnd, 0, (LONG_PTR) (init->c));
break; // defer to DefWindowProc() break; // defer to DefWindowProc()
case WM_WINDOWPOSCHANGED: case WM_WINDOWPOSCHANGED:
if ((wp->flags & SWP_NOSIZE) != 0) if ((wp->flags & SWP_NOSIZE) != 0)
break; // defer to DefWindowProc(); break; // defer to DefWindowProc();
onResize = (void (*)(void *)) GetWindowLongPtrW(hwnd, GWLP_USERDATA); onResize = (void (*)(uiControl *)) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
data = (void *) GetWindowLongPtrW(hwnd, 0); c = (uiWindowsControl *) GetWindowLongPtrW(hwnd, 0);
(*(onResize))(data); (*(onResize))(data);
return 0; return 0;
// TODO is this sufficient for SetWindowPos()?
case WM_GETMINMAXINFO:
lResult = DefWindowProcW(hwnd, uMsg, wParam, lParam);
c = (uiWindowsControl *) GetWindowLongPtrW(hwnd, 0);
uiWindowsControlMinimumSize(c, &minwid, &minht);
mmi->ptMinTrackSize.x = minwid;
mmi->ptMinTrackSize.y = minht;
return lResult;
case WM_PAINT: case WM_PAINT:
dc = BeginPaint(hwnd, &ps); dc = BeginPaint(hwnd, &ps);
if (dc == NULL) { if (dc == NULL) {
@ -86,13 +96,13 @@ void uninitContainer(void)
logLastError(L"error unregistering container window class"); logLastError(L"error unregistering container window class");
} }
HWND uiWindowsMakeContainer(void (*onResize)(void *data), void *data) HWND uiWindowsMakeContainer(uiWindowsControl *c, void (*onResize)(uiWindowsControl *))
{ {
struct containerInit init; struct containerInit init;
// TODO onResize cannot be NULL // TODO onResize cannot be NULL
init.c = c;
init.onResize = onResize; init.onResize = onResize;
init.data = data;
return uiWindowsEnsureCreateControlHWND(WS_EX_CONTROLPARENT, return uiWindowsEnsureCreateControlHWND(WS_EX_CONTROLPARENT,
containerClass, L"", containerClass, L"",
0, 0,