Implemented uiWindowSetMargined() on Windows.

This commit is contained in:
Pietro Gagliardi 2015-04-09 13:51:01 -04:00
parent 9c2fe78f78
commit 73f6841272
3 changed files with 30 additions and 4 deletions

View File

@ -55,7 +55,7 @@ BOOL sharedWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *
return FALSE;
}
void resize(uiControl *control, HWND parent, RECT r)
void resize(uiControl *control, HWND parent, RECT r, RECT margin)
{
uiSizing d;
HDC dc;
@ -83,6 +83,10 @@ void resize(uiControl *control, HWND parent, RECT r)
logLastError("error restoring previous font into device context in resize()");
if (ReleaseDC(parent, dc) == 0)
logLastError("error releasing DC in resize()");
r.left += uiDlgUnitToX(margin.left, d.baseX);
r.top += uiDlgUnitToY(margin.top, d.baseY);
r.right -= uiDlgUnitToX(margin.right, d.baseX);
r.bottom -= uiDlgUnitToY(margin.bottom, d.baseY);
(*(control->resize))(control, r.left, r.top, r.right - r.left, r.bottom - r.top, &d);
}

View File

@ -59,7 +59,7 @@ struct uiSizing {
int baseY;
LONG internalLeading;
};
extern void resize(uiControl *, HWND, RECT);
extern void resize(uiControl *, HWND, RECT, RECT);
// comctl32_windows.c
extern BOOL (*WINAPI fv_SetWindowSubclass)(HWND, SUBCLASSPROC, UINT_PTR, DWORD_PTR);

View File

@ -7,17 +7,21 @@ struct uiWindow {
BOOL shownOnce;
int (*onClosing)(uiWindow *, void *);
void *onClosingData;
int margined;
};
#define uiWindowClass L"uiWindowClass"
// TODO get source
#define windowMargin 7
static LRESULT CALLBACK uiWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
uiWindow *w;
CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam;
LRESULT lResult;
WINDOWPOS *wp = (WINDOWPOS *) lParam;
RECT r;
RECT r, margin;
w = (uiWindow *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
if (w == NULL) {
@ -38,7 +42,17 @@ static LRESULT CALLBACK uiWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPA
break;
if (GetClientRect(w->hwnd, &r) == 0)
logLastError("error getting window client rect for resize in uiWindowWndProc()");
resize(w->child, w->hwnd, r);
margin.left = 0;
margin.top = 0;
margin.right = 0;
margin.bottom = 0;
if (w->margined) {
margin.left = windowMargin;
margin.top = windowMargin;
margin.right = windowMargin;
margin.bottom = windowMargin;
}
resize(w->child, w->hwnd, r, margin);
return 0;
case WM_CLOSE:
if (!(*(w->onClosing))(w, w->onClosingData))
@ -165,3 +179,11 @@ void uiWindowSetChild(uiWindow *w, uiControl *c)
w->child = c;
(*(w->child->setParent))(w->child, (uintptr_t) (w->hwnd));
}
// TODO uiWindowMargined
void uiWindowSetMargined(uiWindow *w, int margined)
{
w->margined = margined;
updateParent((uintptr_t) (w->hwnd));
}