Finished the Windows uiParent conversion, I think. Now to test.
This commit is contained in:
parent
dcf581eb14
commit
365e61dad2
|
@ -8,7 +8,7 @@ struct tab {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct tabPage {
|
struct tabPage {
|
||||||
uiControl *child;
|
uiParent *content;
|
||||||
};
|
};
|
||||||
|
|
||||||
static BOOL onWM_COMMAND(uiControl *c, WORD code, LRESULT *lResult)
|
static BOOL onWM_COMMAND(uiControl *c, WORD code, LRESULT *lResult)
|
||||||
|
@ -26,15 +26,15 @@ static BOOL onWM_NOTIFY(uiControl *c, NMHDR *nm, LRESULT *lResult)
|
||||||
case TCN_SELCHANGING:
|
case TCN_SELCHANGING:
|
||||||
n = SendMessageW((HWND) uiControlHandle(c), TCM_GETCURSEL, 0, 0);
|
n = SendMessageW((HWND) uiControlHandle(c), TCM_GETCURSEL, 0, 0);
|
||||||
if (n != (LRESULT) (-1)) // if we're changing to a real tab
|
if (n != (LRESULT) (-1)) // if we're changing to a real tab
|
||||||
uiControlContainerHide(t->pages[n].child);
|
ShowWindow((HWND) uiParentHandle(t->pages[n].content), SW_HIDE);
|
||||||
*lResult = FALSE; // and allow the change
|
*lResult = FALSE; // and allow the change
|
||||||
return TRUE;
|
return TRUE;
|
||||||
case TCN_SELCHANGE:
|
case TCN_SELCHANGE:
|
||||||
n = SendMessageW((HWND) uiControlHandle(c), TCM_GETCURSEL, 0, 0);
|
n = SendMessageW((HWND) uiControlHandle(c), TCM_GETCURSEL, 0, 0);
|
||||||
if (n != (LRESULT) (-1)) { // if we're changing to a real tab
|
if (n != (LRESULT) (-1)) { // if we're changing to a real tab
|
||||||
uiControlContainerShow(t->pages[n].child);
|
ShowWindow((HWND) uiParentHandle(t->pages[n].content), SW_SHOW);
|
||||||
// because we only resize the current child on resize, we'll need to trigger an update here
|
// because we only resize the current child on resize, we'll need to trigger an update here
|
||||||
updateParent(uiControlHandle(c));
|
uiParentUpdate(t->pages[n].content);
|
||||||
}
|
}
|
||||||
*lResult = 0;
|
*lResult = 0;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -61,7 +61,7 @@ static void resizeTab(uiControl *c, LONG width, LONG height)
|
||||||
struct tab *t = (struct tab *) (c->data);
|
struct tab *t = (struct tab *) (c->data);
|
||||||
HWND hwnd;
|
HWND hwnd;
|
||||||
LRESULT n;
|
LRESULT n;
|
||||||
RECT r, margin;
|
RECT r;
|
||||||
|
|
||||||
hwnd = (HWND) uiControlHandle(c);
|
hwnd = (HWND) uiControlHandle(c);
|
||||||
|
|
||||||
|
@ -78,29 +78,16 @@ static void resizeTab(uiControl *c, LONG width, LONG height)
|
||||||
// convert to the display rectangle
|
// convert to the display rectangle
|
||||||
SendMessageW(hwnd, TCM_ADJUSTRECT, FALSE, (LPARAM) (&r));
|
SendMessageW(hwnd, TCM_ADJUSTRECT, FALSE, (LPARAM) (&r));
|
||||||
|
|
||||||
margin.left = 0;
|
if (MoveWindow((HWND) uiParentHandle(t->pages[n].content), r.leftm r.top, r.right - r.left, r.bottom - r.top, TRUE) == 0)
|
||||||
margin.top = 0;
|
logLastError("error resizing current tab page in resizeTab()");
|
||||||
margin.right = 0;
|
|
||||||
margin.bottom = 0;
|
|
||||||
/*TODO if (w->margined) {
|
|
||||||
margin.left = windowMargin;
|
|
||||||
margin.top = windowMargin;
|
|
||||||
margin.right = windowMargin;
|
|
||||||
margin.bottom = windowMargin;
|
|
||||||
}
|
|
||||||
*/ resize(t->pages[n].child, hwnd, r, margin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// and finally, because we are a container, we have to handle resizes and updates
|
// and finally, because we have to resize parents, we have to handle resizes and updates
|
||||||
static LRESULT CALLBACK tabSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
|
static LRESULT CALLBACK tabSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
|
||||||
{
|
{
|
||||||
uiControl *c = (uiControl *) dwRefData;
|
uiControl *c = (uiControl *) dwRefData;
|
||||||
LRESULT lResult;
|
|
||||||
WINDOWPOS *wp = (WINDOWPOS *) lParam;
|
WINDOWPOS *wp = (WINDOWPOS *) lParam;
|
||||||
RECT r;
|
|
||||||
|
|
||||||
if (sharedWndProc(hwnd, uMsg, wParam, lParam, &lResult) != FALSE)
|
|
||||||
return lResult;
|
|
||||||
switch (uMsg) {
|
switch (uMsg) {
|
||||||
case WM_WINDOWPOSCHANGED:
|
case WM_WINDOWPOSCHANGED:
|
||||||
if ((wp->flags & SWP_NOSIZE) != 0)
|
if ((wp->flags & SWP_NOSIZE) != 0)
|
||||||
|
@ -110,12 +97,6 @@ static LRESULT CALLBACK tabSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l
|
||||||
// we have the window rect width as part of the WINDOWPOS; resize
|
// we have the window rect width as part of the WINDOWPOS; resize
|
||||||
resizeTab(c, wp->cx, wp->cy);
|
resizeTab(c, wp->cx, wp->cy);
|
||||||
return lResult;
|
return lResult;
|
||||||
case msgUpdateChild:
|
|
||||||
if (GetWindowRect((HWND) uiControlHandle(c), &r) == 0)
|
|
||||||
logLastError("error getting window rect for Tab resize in tabSubProc()");
|
|
||||||
// though these are in screen coordinates, we only need the width and height
|
|
||||||
resizeTab(c, r.right - r.left, r.bottom - r.top);
|
|
||||||
return 0;
|
|
||||||
case WM_NCDESTROY:
|
case WM_NCDESTROY:
|
||||||
if ((*fv_RemoveWindowSubclass)(hwnd, tabSubProc, uIdSubclass) == FALSE)
|
if ((*fv_RemoveWindowSubclass)(hwnd, tabSubProc, uIdSubclass) == FALSE)
|
||||||
logLastError("error removing Tab resize handling subclass in tabSubProc()");
|
logLastError("error removing Tab resize handling subclass in tabSubProc()");
|
||||||
|
@ -162,6 +143,7 @@ void uiTabAddPage(uiControl *c, const char *name, uiControl *child)
|
||||||
HWND hwnd;
|
HWND hwnd;
|
||||||
TCITEMW item;
|
TCITEMW item;
|
||||||
LRESULT n;
|
LRESULT n;
|
||||||
|
uiParent *parent;
|
||||||
WCHAR *wname;
|
WCHAR *wname;
|
||||||
|
|
||||||
if (t->len >= t->cap) {
|
if (t->len >= t->cap) {
|
||||||
|
@ -172,10 +154,11 @@ void uiTabAddPage(uiControl *c, const char *name, uiControl *child)
|
||||||
hwnd = (HWND) uiControlHandle(c);
|
hwnd = (HWND) uiControlHandle(c);
|
||||||
n = SendMessageW(hwnd, TCM_GETITEMCOUNT, 0, 0);
|
n = SendMessageW(hwnd, TCM_GETITEMCOUNT, 0, 0);
|
||||||
|
|
||||||
t->pages[t->len].child = child;
|
parent = uiNewParent((uintptr_t) hwnd);
|
||||||
uiControlSetParent(t->pages[t->len].child, (uintptr_t) hwnd);
|
uiParentSetChild(parent, child);
|
||||||
if (n != 0) // if this isn't the first page, we have to hide the other controls
|
if (n != 0) // if this isn't the first page, we have to hide the other controls
|
||||||
uiControlContainerHide(t->pages[t->len].child);
|
ShowWindow((HWND) uiParentHandle(parent), SW_HIDE);
|
||||||
|
t->pages[t->len].content = parent;
|
||||||
t->len++;
|
t->len++;
|
||||||
|
|
||||||
ZeroMemory(&item, sizeof (TCITEMW));
|
ZeroMemory(&item, sizeof (TCITEMW));
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
struct uiWindow {
|
struct uiWindow {
|
||||||
HWND hwnd;
|
HWND hwnd;
|
||||||
uiControl *child;
|
uiParent *content;
|
||||||
BOOL shownOnce;
|
BOOL shownOnce;
|
||||||
int (*onClosing)(uiWindow *, void *);
|
int (*onClosing)(uiWindow *, void *);
|
||||||
void *onClosingData;
|
void *onClosingData;
|
||||||
|
@ -12,16 +12,11 @@ struct uiWindow {
|
||||||
|
|
||||||
#define uiWindowClass L"uiWindowClass"
|
#define uiWindowClass L"uiWindowClass"
|
||||||
|
|
||||||
// from https://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
|
||||||
#define windowMargin 7
|
|
||||||
|
|
||||||
static LRESULT CALLBACK uiWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
static LRESULT CALLBACK uiWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
uiWindow *w;
|
uiWindow *w;
|
||||||
CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam;
|
CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam;
|
||||||
LRESULT lResult;
|
|
||||||
WINDOWPOS *wp = (WINDOWPOS *) lParam;
|
WINDOWPOS *wp = (WINDOWPOS *) lParam;
|
||||||
RECT r, margin;
|
|
||||||
|
|
||||||
w = (uiWindow *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
|
w = (uiWindow *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
|
||||||
if (w == NULL) {
|
if (w == NULL) {
|
||||||
|
@ -30,29 +25,13 @@ static LRESULT CALLBACK uiWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPA
|
||||||
// fall through to DefWindowProc() anyway
|
// fall through to DefWindowProc() anyway
|
||||||
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
||||||
}
|
}
|
||||||
if (sharedWndProc(hwnd, uMsg, wParam, lParam, &lResult) != FALSE)
|
|
||||||
return lResult;
|
|
||||||
switch (uMsg) {
|
switch (uMsg) {
|
||||||
case WM_WINDOWPOSCHANGED:
|
case WM_WINDOWPOSCHANGED:
|
||||||
if ((wp->flags & SWP_NOSIZE) != 0)
|
|
||||||
break;
|
|
||||||
// fall through
|
|
||||||
case msgUpdateChild:
|
|
||||||
if (w->child == NULL)
|
|
||||||
break;
|
|
||||||
if (GetClientRect(w->hwnd, &r) == 0)
|
if (GetClientRect(w->hwnd, &r) == 0)
|
||||||
logLastError("error getting window client rect for resize in uiWindowWndProc()");
|
logLastError("error getting window client rect for resize in uiWindowWndProc()");
|
||||||
margin.left = 0;
|
contenthwnd = (HWND) uiParentHandle(content);
|
||||||
margin.top = 0;
|
if (MoveWindow(contenthwnd, r.left, r.top, r.right - r.left, r.bottom - r.top, TRUE) == 0)
|
||||||
margin.right = 0;
|
logLastError("error resizing window content parent in uiWindowWndProc()");
|
||||||
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;
|
return 0;
|
||||||
case WM_CLOSE:
|
case WM_CLOSE:
|
||||||
if (!(*(w->onClosing))(w, w->onClosingData))
|
if (!(*(w->onClosing))(w, w->onClosingData))
|
||||||
|
@ -114,8 +93,10 @@ uiWindow *uiNewWindow(char *title, int width, int height)
|
||||||
NULL, NULL, hInstance, w);
|
NULL, NULL, hInstance, w);
|
||||||
if (w->hwnd == NULL)
|
if (w->hwnd == NULL)
|
||||||
logLastError("error creating window in uiWindow()");
|
logLastError("error creating window in uiWindow()");
|
||||||
|
|
||||||
uiFree(wtitle);
|
uiFree(wtitle);
|
||||||
|
|
||||||
|
w->content = uiNewParent((uintptr_t) (w->hwnd));
|
||||||
|
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,8 +156,8 @@ void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data)
|
||||||
|
|
||||||
void uiWindowSetChild(uiWindow *w, uiControl *c)
|
void uiWindowSetChild(uiWindow *w, uiControl *c)
|
||||||
{
|
{
|
||||||
w->child = c;
|
uiParentSetChild(w->content, c);
|
||||||
uiControlSetParent(w->child, (uintptr_t) (w->hwnd));
|
uiParentUpdate(w->content);
|
||||||
}
|
}
|
||||||
|
|
||||||
int uiWindowMargined(uiWindow *w)
|
int uiWindowMargined(uiWindow *w)
|
||||||
|
@ -184,8 +165,15 @@ int uiWindowMargined(uiWindow *w)
|
||||||
return w->margined;
|
return w->margined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// from https://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
||||||
|
#define windowMargin 7
|
||||||
|
|
||||||
void uiWindowSetMargined(uiWindow *w, int margined)
|
void uiWindowSetMargined(uiWindow *w, int margined)
|
||||||
{
|
{
|
||||||
w->margined = margined;
|
w->margined = margined;
|
||||||
updateParent((uintptr_t) (w->hwnd));
|
if (w->margined)
|
||||||
|
uiParentSetMargins(w->content, windowMargin, windowMargin, windowMargin, windowMargin);
|
||||||
|
else
|
||||||
|
uiParentSetMargins(w->content, 0, 0, 0, 0);
|
||||||
|
uiParentUpdate(w->content);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue