Finished migrating window.cpp. A few utility functions came along for the ride. Maybe child.cpp won't be needed...?
This commit is contained in:
parent
78b49ae04d
commit
3563dd74e7
|
@ -36,7 +36,7 @@ static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
|
||||||
if (uMsg == WM_WINDOWPOSCHANGED) {
|
if (uMsg == WM_WINDOWPOSCHANGED) {
|
||||||
if ((wp->flags & SWP_NOSIZE) != 0)
|
if ((wp->flags & SWP_NOSIZE) != 0)
|
||||||
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
||||||
if (GetClientRect(a->hwnd, &client) == 0)
|
if (getClientRect(a->hwnd, &client) == 0)
|
||||||
logLastError(L"error getting client rect of uiArea for WM_WINDOWPOSCHANGED handling");
|
logLastError(L"error getting client rect of uiArea for WM_WINDOWPOSCHANGED handling");
|
||||||
areaDrawOnResize(a, &client);
|
areaDrawOnResize(a, &client);
|
||||||
areaScrollOnResize(a, &client);
|
areaScrollOnResize(a, &client);
|
||||||
|
|
|
@ -94,7 +94,7 @@ static void onWM_PRINTCLIENT(uiArea *a)
|
||||||
{
|
{
|
||||||
RECT client;
|
RECT client;
|
||||||
|
|
||||||
if (GetClientRect(a->hwnd, &client) == 0)
|
if (getClientRect(a->hwnd, &client) == 0)
|
||||||
logLastError(L"error getting client rect");
|
logLastError(L"error getting client rect");
|
||||||
//TODO doPaint(a, (HDC) wParam, &client);
|
//TODO doPaint(a, (HDC) wParam, &client);
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ static void areaMouseEvent(uiArea *a, uintmax_t down, uintmax_t up, WPARAM wPar
|
||||||
if (a->capturing) {
|
if (a->capturing) {
|
||||||
clientpt.x = GET_X_LPARAM(lParam);
|
clientpt.x = GET_X_LPARAM(lParam);
|
||||||
clientpt.y = GET_Y_LPARAM(lParam);
|
clientpt.y = GET_Y_LPARAM(lParam);
|
||||||
if (GetClientRect(a->hwnd, &client) == 0)
|
if (getClientRect(a->hwnd, &client) == 0)
|
||||||
logLastError(L"error getting uiAreaclient rect for mouse crossing on capture on drag");
|
logLastError(L"error getting uiAreaclient rect for mouse crossing on capture on drag");
|
||||||
inClient = PtInRect(&client, clientpt);
|
inClient = PtInRect(&client, clientpt);
|
||||||
if (inClient && !a->inside) {
|
if (inClient && !a->inside) {
|
||||||
|
|
|
@ -128,7 +128,7 @@ static void hscrollParams(uiArea *a, struct scrollParams *p)
|
||||||
ZeroMemory(p, sizeof (struct scrollParams));
|
ZeroMemory(p, sizeof (struct scrollParams));
|
||||||
p->pos = &(a->hscrollpos);
|
p->pos = &(a->hscrollpos);
|
||||||
// TODO get rid of these and replace with points
|
// TODO get rid of these and replace with points
|
||||||
if (GetClientRect(a->hwnd, &r) == 0)
|
if (getClientRect(a->hwnd, &r) == 0)
|
||||||
logLastError(L"error getting area client rect");
|
logLastError(L"error getting area client rect");
|
||||||
p->pagesize = r.right - r.left;
|
p->pagesize = r.right - r.left;
|
||||||
p->length = a->scrollWidth;
|
p->length = a->scrollWidth;
|
||||||
|
@ -174,7 +174,7 @@ static void vscrollParams(uiArea *a, struct scrollParams *p)
|
||||||
|
|
||||||
ZeroMemory(p, sizeof (struct scrollParams));
|
ZeroMemory(p, sizeof (struct scrollParams));
|
||||||
p->pos = &(a->vscrollpos);
|
p->pos = &(a->vscrollpos);
|
||||||
if (GetClientRect(a->hwnd, &r) == 0)
|
if (getClientRect(a->hwnd, &r) == 0)
|
||||||
logLastError(L"error getting area client rect");
|
logLastError(L"error getting area client rect");
|
||||||
p->pagesize = r.bottom - r.top;
|
p->pagesize = r.bottom - r.top;
|
||||||
p->length = a->scrollHeight;
|
p->length = a->scrollHeight;
|
||||||
|
|
|
@ -50,7 +50,7 @@ static LRESULT CALLBACK containerWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LP
|
||||||
return 0;
|
return 0;
|
||||||
// tab controls use this to draw the background of the tab area
|
// tab controls use this to draw the background of the tab area
|
||||||
case WM_PRINTCLIENT:
|
case WM_PRINTCLIENT:
|
||||||
if (GetClientRect(hwnd, &r) == 0) {
|
if (getClientRect(hwnd, &r) == 0) {
|
||||||
logLastError(L"error getting client rect");
|
logLastError(L"error getting client rect");
|
||||||
// likewise
|
// likewise
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -51,7 +51,7 @@ ID2D1HwndRenderTarget *makeHWNDRenderTarget(HWND hwnd)
|
||||||
if (ReleaseDC(hwnd, dc) == 0)
|
if (ReleaseDC(hwnd, dc) == 0)
|
||||||
logLastError(L"error releasing DC for finding DPI");
|
logLastError(L"error releasing DC for finding DPI");
|
||||||
|
|
||||||
if (GetClientRect(hwnd, &r) == 0)
|
if (getClientRect(hwnd, &r) == 0)
|
||||||
logLastError(L"error getting current size of window");
|
logLastError(L"error getting current size of window");
|
||||||
|
|
||||||
ZeroMemory(&hprops, sizeof (D2D1_HWND_RENDER_TARGET_PROPERTIES));
|
ZeroMemory(&hprops, sizeof (D2D1_HWND_RENDER_TARGET_PROPERTIES));
|
||||||
|
|
|
@ -495,7 +495,7 @@ static struct fontDialog *beginFontDialog(HWND hwnd, LPARAM lParam)
|
||||||
samplePlacement = GetDlgItem(f->hwnd, rcFontSamplePlacement);
|
samplePlacement = GetDlgItem(f->hwnd, rcFontSamplePlacement);
|
||||||
if (samplePlacement == NULL)
|
if (samplePlacement == NULL)
|
||||||
logLastError(L"error getting sample placement static control handle");
|
logLastError(L"error getting sample placement static control handle");
|
||||||
if (GetWindowRect(samplePlacement, &(f->sampleRect)) == 0)
|
if (getWindowRect(samplePlacement, &(f->sampleRect)) == 0)
|
||||||
logLastError(L"error getting sample placement");
|
logLastError(L"error getting sample placement");
|
||||||
mapWindowRect(NULL, f->hwnd, &(f->sampleRect));
|
mapWindowRect(NULL, f->hwnd, &(f->sampleRect));
|
||||||
uiWindowsEnsureDestroyWindow(samplePlacement);
|
uiWindowsEnsureDestroyWindow(samplePlacement);
|
||||||
|
|
|
@ -33,7 +33,7 @@ static HRESULT parentDraw(HDC dc, HWND parent, struct parentDraw *pd)
|
||||||
{
|
{
|
||||||
RECT r;
|
RECT r;
|
||||||
|
|
||||||
if (GetClientRect(parent, &r) == 0)
|
if (getClientRect(parent, &r) == 0)
|
||||||
return logLastError(L"error getting parent's client rect");
|
return logLastError(L"error getting parent's client rect");
|
||||||
pd->cdc = CreateCompatibleDC(dc);
|
pd->cdc = CreateCompatibleDC(dc);
|
||||||
if (pd->cdc == NULL)
|
if (pd->cdc == NULL)
|
||||||
|
@ -86,7 +86,7 @@ static HBRUSH getControlBackgroundBrush(HWND hwnd, HDC dc)
|
||||||
|
|
||||||
// now figure out where the control is relative to the parent so we can align the brush properly
|
// now figure out where the control is relative to the parent so we can align the brush properly
|
||||||
// if anything fails, give up and return the brush as-is
|
// if anything fails, give up and return the brush as-is
|
||||||
if (GetWindowRect(hwnd, &hwndScreenRect) == 0) {
|
if (getWindowRect(hwnd, &hwndScreenRect) == 0) {
|
||||||
logLastError(L"error getting control window rect");
|
logLastError(L"error getting control window rect");
|
||||||
return brush;
|
return brush;
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,8 @@ extern void clientSizeToWindowSize(HWND hwnd, intmax_t *width, intmax_t *height,
|
||||||
extern HWND parentOf(HWND child);
|
extern HWND parentOf(HWND child);
|
||||||
extern HWND parentToplevel(HWND child);
|
extern HWND parentToplevel(HWND child);
|
||||||
extern void setWindowInsertAfter(HWND hwnd, HWND insertAfter);
|
extern void setWindowInsertAfter(HWND hwnd, HWND insertAfter);
|
||||||
|
extern void getClientRect(HWND, RECT *);
|
||||||
|
extern void getWindowRect(HWND, RECT *);
|
||||||
|
|
||||||
// text.cpp
|
// text.cpp
|
||||||
extern WCHAR *windowTextAndLen(HWND hwnd, LRESULT *len);
|
extern WCHAR *windowTextAndLen(HWND hwnd, LRESULT *len);
|
||||||
|
|
|
@ -16,6 +16,23 @@ struct uiWindow {
|
||||||
BOOL hasMenubar;
|
BOOL hasMenubar;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// from https://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
||||||
|
#define windowMargin 7
|
||||||
|
|
||||||
|
static void windowMargins(uiWindow *w, int *mx, int *my)
|
||||||
|
{
|
||||||
|
uiWindowsSizing sizing;
|
||||||
|
|
||||||
|
*mx = 0;
|
||||||
|
*my = 0;
|
||||||
|
if (!w->margined)
|
||||||
|
return;
|
||||||
|
uiWindowsGetSizing(w->hwnd, &sizing);
|
||||||
|
*mx = windowMargin;
|
||||||
|
*my = windowMargin;
|
||||||
|
uiWindowsSizingDlgUnitsToPixels(&sizing, mx, my);
|
||||||
|
}
|
||||||
|
|
||||||
static void windowRelayout(uiWindow *w)
|
static void windowRelayout(uiWindow *w)
|
||||||
{
|
{
|
||||||
uiWindow *w = uiWindow(c);
|
uiWindow *w = uiWindow(c);
|
||||||
|
@ -28,20 +45,14 @@ static void windowRelayout(uiWindow *w)
|
||||||
return;
|
return;
|
||||||
x = 0;
|
x = 0;
|
||||||
y = 0;
|
y = 0;
|
||||||
if (GetClientRect(w->hwnd, &r) == 0)
|
getClientRect(w->hwnd, &r);
|
||||||
/* TODO */;
|
|
||||||
width = r.right - r.left;
|
width = r.right - r.left;
|
||||||
height = r.bottom - r.top;
|
height = r.bottom - r.top;
|
||||||
if (w->margined) {
|
windowMargins(w, &mx, &my);
|
||||||
uiWindowsGetSizing(w->hwnd, &sizing);
|
x += mx;
|
||||||
mx = windowMargin;
|
y += my;
|
||||||
my = windowMargin;
|
width -= 2 * mx;
|
||||||
uiWindowsSizingDlgUnitsToPixels(&sizing, &mx, &my);
|
height -= 2 * my;
|
||||||
x += mx;
|
|
||||||
y += my;
|
|
||||||
width -= 2 * mx;
|
|
||||||
height -= 2 * my;
|
|
||||||
}
|
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,9 +213,6 @@ uiWindowsControlDefaultSyncEnableState(uiWindow)
|
||||||
// TODO
|
// TODO
|
||||||
uiWindowsControlDefaultSetParentHWND(uiWindow)
|
uiWindowsControlDefaultSetParentHWND(uiWindow)
|
||||||
|
|
||||||
// from https://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
|
||||||
#define windowMargin 7
|
|
||||||
|
|
||||||
static void uiWindowMinimumSize(uiWindowsControl *c, intmax_t *width, intmax_t *height)
|
static void uiWindowMinimumSize(uiWindowsControl *c, intmax_t *width, intmax_t *height)
|
||||||
{
|
{
|
||||||
uiWindow *w = uiWindow(c);
|
uiWindow *w = uiWindow(c);
|
||||||
|
@ -215,15 +223,9 @@ static void uiWindowMinimumSize(uiWindowsControl *c, intmax_t *width, intmax_t *
|
||||||
*height = 0;
|
*height = 0;
|
||||||
if (w->child != NULL)
|
if (w->child != NULL)
|
||||||
uiWindowsControlMinimumSize(uiWindowsControl(w->child), width, height);
|
uiWindowsControlMinimumSize(uiWindowsControl(w->child), width, height);
|
||||||
if (w->margined) {
|
windowMargins(w, &mx, &my);
|
||||||
uiWindowsGetSizing(w->hwnd, &sizing);
|
*width += 2 * mx;
|
||||||
mx = windowMargin;
|
*height += 2 * my;
|
||||||
my = windowMargin;
|
|
||||||
uiWindowsSizingDlgUnitsToPixels(&sizing, &mx, &my);
|
|
||||||
*width += 2 * mx;
|
|
||||||
*height += 2 * my;
|
|
||||||
}
|
|
||||||
uiWindowsFreeSizing(d);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void uiWindowChildMinimumSizeChanged(uiWindowsControl *c)
|
static void uiWindowChildMinimumSizeChanged(uiWindowsControl *c)
|
||||||
|
@ -232,24 +234,28 @@ static void uiWindowChildMinimumSizeChanged(uiWindowsControl *c)
|
||||||
intmax_t width, height;
|
intmax_t width, height;
|
||||||
RECT r;
|
RECT r;
|
||||||
BOOL needsGrowing;
|
BOOL needsGrowing;
|
||||||
|
int mx, my;
|
||||||
|
|
||||||
uiWindowsControlMinimumSize(uiWindowsControl(w->child), &width, &height);
|
uiWindowsControlMinimumSize(uiWindowsControl(w->child), &width, &height);
|
||||||
if (GetClientRect(w->hwnd, &r) == 0)
|
windowMargns(w, &mx, &my);
|
||||||
/* TODO */;
|
width += 2 * mx;
|
||||||
|
height += 2 * my;
|
||||||
|
getClientRect(w->hwnd, &r);
|
||||||
// TODO discount margins
|
// TODO discount margins
|
||||||
needsGrowing = FALSE;
|
needsGrowing = FALSE;
|
||||||
if ((r.right - r.left) < width)
|
if ((r.right - r.left) < width)
|
||||||
needsGrowing = TRUE;
|
needsGrowing = TRUE;
|
||||||
if ((r.bottom - r.top) < height)
|
if ((r.bottom - r.top) < height)
|
||||||
needsGrowing = TRUE;
|
needsGrowing = TRUE;
|
||||||
if (needsGrowing)
|
if (!needsGrowing)
|
||||||
/* TODO */;
|
return;
|
||||||
|
// TODO figure out what to do with this function
|
||||||
|
// maybe split it into two so WM_GETMINMAXINFO can use it?
|
||||||
|
ensureMinimumWindowSize(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
uiWindowsDefaultAssignControlIDZorder(uiWindow)
|
uiWindowsDefaultAssignControlIDZorder(uiWindow)
|
||||||
|
|
||||||
///////// TODO CONTINUE HERE
|
|
||||||
|
|
||||||
char *uiWindowTitle(uiWindow *w)
|
char *uiWindowTitle(uiWindow *w)
|
||||||
{
|
{
|
||||||
return uiWindowsWindowText(w->hwnd);
|
return uiWindowsWindowText(w->hwnd);
|
||||||
|
@ -269,12 +275,21 @@ void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data)
|
||||||
|
|
||||||
void uiWindowSetChild(uiWindow *w, uiControl *child)
|
void uiWindowSetChild(uiWindow *w, uiControl *child)
|
||||||
{
|
{
|
||||||
if (w->child != NULL)
|
LONG_PTR id;
|
||||||
childRemove(w->child);
|
HWND dummy;
|
||||||
w->child = newChild(child, uiControl(w), w->hwnd);
|
|
||||||
if (w->child != NULL) {
|
if (w->child != NULL) {
|
||||||
childSetSoleControlID(w->child);
|
uiControlSetParent(w->child, NULL);
|
||||||
childQueueRelayout(w->child);
|
uiWindowsControlSetParentHWND(uiWindowsControl(w->child), NULL);
|
||||||
|
}
|
||||||
|
w->child = child;
|
||||||
|
if (w->child != NULL) {
|
||||||
|
uiControlSetParent(w->child, uiControl(w));
|
||||||
|
uiWindowsControlSetParentHWND(uiWindowsControl(w->child), w->hwnd);
|
||||||
|
id = 100;
|
||||||
|
dummy = NULL;
|
||||||
|
uiWindowsControlAssignControlIDZOrder(uiWindowsControl(w->child), &id, &dummy);
|
||||||
|
windowRelayout(w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,7 +301,7 @@ int uiWindowMargined(uiWindow *w)
|
||||||
void uiWindowSetMargined(uiWindow *w, int margined)
|
void uiWindowSetMargined(uiWindow *w, int margined)
|
||||||
{
|
{
|
||||||
w->margined = margined;
|
w->margined = margined;
|
||||||
uiWindowsControlQueueRelayout(uiWindowsControl(w));
|
windowRelayout(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
// see http://blogs.msdn.com/b/oldnewthing/archive/2003/09/11/54885.aspx and http://blogs.msdn.com/b/oldnewthing/archive/2003/09/13/54917.aspx
|
// see http://blogs.msdn.com/b/oldnewthing/archive/2003/09/11/54885.aspx and http://blogs.msdn.com/b/oldnewthing/archive/2003/09/13/54917.aspx
|
||||||
|
@ -319,7 +334,7 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
|
||||||
WCHAR *wtitle;
|
WCHAR *wtitle;
|
||||||
BOOL hasMenubarBOOL;
|
BOOL hasMenubarBOOL;
|
||||||
|
|
||||||
w = (uiWindow *) uiNewControl(uiWindow);
|
uiWindowsNewControl(uiWindow, w);
|
||||||
|
|
||||||
hasMenubarBOOL = FALSE;
|
hasMenubarBOOL = FALSE;
|
||||||
if (hasMenubar)
|
if (hasMenubar)
|
||||||
|
@ -354,26 +369,17 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
|
||||||
|
|
||||||
uiWindowOnClosing(w, defaultOnClosing, NULL);
|
uiWindowOnClosing(w, defaultOnClosing, NULL);
|
||||||
|
|
||||||
uiWindowsFinishNewControl(w, uiWindow);
|
|
||||||
uiControl(w)->CommitShow = windowCommitShow;
|
|
||||||
uiControl(w)->ContainerUpdateState = windowContainerUpdateState;
|
|
||||||
uiWindowsControl(w)->Relayout = windowRelayout;
|
|
||||||
uiWindowsControl(w)->ArrangeChildrenControlIDsZOrder = windowArrangeChildrenControlIDsZOrder;
|
|
||||||
|
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
// this cannot queue a resize because it's called by the resize handler
|
// this cannot queue a resize because it's called by the resize handler
|
||||||
void ensureMinimumWindowSize(uiWindow *w)
|
void ensureMinimumWindowSize(uiWindow *w)
|
||||||
{
|
{
|
||||||
uiWindowsControl *c;
|
|
||||||
intmax_t width, height;
|
intmax_t width, height;
|
||||||
RECT r;
|
RECT r;
|
||||||
|
|
||||||
c = uiWindowsControl(w);
|
uiWindowsControlMinimumSize(uiWindowsControl(w), &width, &height);
|
||||||
(*(c->MinimumSize))(c, NULL, &width, &height);
|
getClientRect(w->hwnd, &r);
|
||||||
if (GetClientRect(w->hwnd, &r) == 0)
|
|
||||||
logLastError(L"error getting client rect");
|
|
||||||
if (width < (r.right - r.left)) // preserve width if larger
|
if (width < (r.right - r.left)) // preserve width if larger
|
||||||
width = r.right - r.left;
|
width = r.right - r.left;
|
||||||
if (height < (r.bottom - r.top)) // preserve height if larger
|
if (height < (r.bottom - r.top)) // preserve height if larger
|
||||||
|
|
|
@ -120,3 +120,28 @@ void setWindowInsertAfter(HWND hwnd, HWND insertAfter)
|
||||||
if (SetWindowPos(hwnd, insertAfter, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOSIZE) == 0)
|
if (SetWindowPos(hwnd, insertAfter, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOSIZE) == 0)
|
||||||
logLastError(L"error reordering window");
|
logLastError(L"error reordering window");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// do these function even error out in any case other than invalid parameters?! I thought all windows had rects
|
||||||
|
void getClientRect(HWND hwnd, RECT *r)
|
||||||
|
{
|
||||||
|
if (GetClientRect(hwnd, r) == 0) {
|
||||||
|
logLastError(L"error getting window client rect");
|
||||||
|
// zero out the rect on error just to be safe
|
||||||
|
r->left = 0;
|
||||||
|
r->top = 0;
|
||||||
|
r->right = 0;
|
||||||
|
r->bottom = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void getWindowRect(HWND hwnd, RECT *r)
|
||||||
|
{
|
||||||
|
if (GetWindowRect(hwnd, r) == 0) {
|
||||||
|
logLastError(L"error getting window rect");
|
||||||
|
// zero out the rect on error just to be safe
|
||||||
|
r->left = 0;
|
||||||
|
r->top = 0;
|
||||||
|
r->right = 0;
|
||||||
|
r->bottom = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue