Fix helper: get rid of direct casts to HWND to make errors more obvious.
This commit is contained in:
parent
cfc3afe09f
commit
da23756a6a
|
@ -37,7 +37,7 @@ static void preferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *
|
||||||
HWND hwnd;
|
HWND hwnd;
|
||||||
SIZE size;
|
SIZE size;
|
||||||
|
|
||||||
hwnd = (HWND) uiControlHandle(c);
|
hwnd = uiControlHWND(c);
|
||||||
|
|
||||||
// try the comctl32 version 6 way
|
// try the comctl32 version 6 way
|
||||||
size.cx = 0; // explicitly ask for ideal size
|
size.cx = 0; // explicitly ask for ideal size
|
||||||
|
|
|
@ -16,7 +16,7 @@ static BOOL onWM_COMMAND(uiControl *c, WORD code, LRESULT *lResult)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
// we didn't use BS_AUTOCHECKBOX (see controls_windows.go) so we have to manage the check state ourselves
|
// we didn't use BS_AUTOCHECKBOX (see controls_windows.go) so we have to manage the check state ourselves
|
||||||
hwnd = (HWND) uiControlHandle(c);
|
hwnd = uiControlHWND(c);
|
||||||
check = BST_CHECKED;
|
check = BST_CHECKED;
|
||||||
if (SendMessage(hwnd, BM_GETCHECK, 0, 0) == BST_CHECKED)
|
if (SendMessage(hwnd, BM_GETCHECK, 0, 0) == BST_CHECKED)
|
||||||
check = BST_UNCHECKED;
|
check = BST_UNCHECKED;
|
||||||
|
@ -46,7 +46,7 @@ static void onWM_DESTROY(uiControl *c)
|
||||||
|
|
||||||
static void preferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
|
static void preferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
|
||||||
{
|
{
|
||||||
*width = uiDlgUnitsToX(checkboxXFromLeftOfBoxToLeftOfLabel, d->sys->baseX) + uiWindowsWindowTextWidth((HWND) uiControlHandle(c));
|
*width = uiDlgUnitsToX(checkboxXFromLeftOfBoxToLeftOfLabel, d->sys->baseX) + uiWindowsWindowTextWidth(uiControlHWND(c));
|
||||||
*height = uiDlgUnitsToY(checkboxHeight, d->sys->baseY);
|
*height = uiDlgUnitsToY(checkboxHeight, d->sys->baseY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ int uiCheckboxChecked(uiControl *c)
|
||||||
{
|
{
|
||||||
HWND hwnd;
|
HWND hwnd;
|
||||||
|
|
||||||
hwnd = (HWND) uiControlHandle(c);
|
hwnd = uiControlHWND(c);
|
||||||
return SendMessage(hwnd, BM_GETCHECK, 0, 0) == BST_CHECKED;
|
return SendMessage(hwnd, BM_GETCHECK, 0, 0) == BST_CHECKED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ void uiCheckboxSetChecked(uiControl *c, int checked)
|
||||||
HWND hwnd;
|
HWND hwnd;
|
||||||
WPARAM check;
|
WPARAM check;
|
||||||
|
|
||||||
hwnd = (HWND) uiControlHandle(c);
|
hwnd = uiControlHWND(c);
|
||||||
check = BST_CHECKED;
|
check = BST_CHECKED;
|
||||||
if (!checked)
|
if (!checked)
|
||||||
check = BST_UNCHECKED;
|
check = BST_UNCHECKED;
|
||||||
|
|
|
@ -26,7 +26,7 @@ static void onWM_DESTROY(uiControl *c)
|
||||||
|
|
||||||
static void preferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
|
static void preferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
|
||||||
{
|
{
|
||||||
*width = uiWindowsWindowTextWidth((HWND) uiControlHandle(c));
|
*width = uiWindowsWindowTextWidth(uiControlHWND(c));
|
||||||
*height = uiDlgUnitsToY(labelHeight, d->sys->baseY);
|
*height = uiDlgUnitsToY(labelHeight, d->sys->baseY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ static void singleSetParent(uiControl *c, uiParent *parent)
|
||||||
singleHWND *s = (singleHWND *) (c->internal);
|
singleHWND *s = (singleHWND *) (c->internal);
|
||||||
|
|
||||||
s->parent = parent;
|
s->parent = parent;
|
||||||
if (SetParent(s->hwnd, (HWND) uiParentHandle(s->parent)) == NULL)
|
if (SetParent(s->hwnd, uiParentHWND(s->parent)) == NULL)
|
||||||
logLastError("error setting control parent in singleSetParent()");
|
logLastError("error setting control parent in singleSetParent()");
|
||||||
uiParentUpdate(s->parent);
|
uiParentUpdate(s->parent);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,15 +24,15 @@ static BOOL onWM_NOTIFY(uiControl *c, NMHDR *nm, LRESULT *lResult)
|
||||||
|
|
||||||
switch (nm->code) {
|
switch (nm->code) {
|
||||||
case TCN_SELCHANGING:
|
case TCN_SELCHANGING:
|
||||||
n = SendMessageW((HWND) uiControlHandle(c), TCM_GETCURSEL, 0, 0);
|
n = SendMessageW(uiControlHWND(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
|
||||||
ShowWindow((HWND) uiParentHandle(t->pages[n].content), SW_HIDE);
|
ShowWindow(uiParentHWND(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(uiControlHWND(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
|
||||||
ShowWindow((HWND) uiParentHandle(t->pages[n].content), SW_SHOW);
|
ShowWindow(uiParentHWND(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
|
||||||
uiParentUpdate(t->pages[n].content);
|
uiParentUpdate(t->pages[n].content);
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ static void resizeTab(uiControl *c, LONG width, LONG height)
|
||||||
LRESULT n;
|
LRESULT n;
|
||||||
RECT r;
|
RECT r;
|
||||||
|
|
||||||
hwnd = (HWND) uiControlHandle(c);
|
hwnd = uiControlHWND(c);
|
||||||
|
|
||||||
n = SendMessageW(hwnd, TCM_GETCURSEL, 0, 0);
|
n = SendMessageW(hwnd, TCM_GETCURSEL, 0, 0);
|
||||||
if (n == (LRESULT) (-1)) // no child selected; do nothing
|
if (n == (LRESULT) (-1)) // no child selected; do nothing
|
||||||
|
@ -78,7 +78,7 @@ 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));
|
||||||
|
|
||||||
if (MoveWindow((HWND) uiParentHandle(t->pages[n].content), r.left, r.top, r.right - r.left, r.bottom - r.top, TRUE) == 0)
|
if (MoveWindow(uiParentHWND(t->pages[n].content), r.left, r.top, r.right - r.left, r.bottom - r.top, TRUE) == 0)
|
||||||
logLastError("error resizing current tab page in resizeTab()");
|
logLastError("error resizing current tab page in resizeTab()");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ uiControl *uiNewTab(void)
|
||||||
t = uiNew(struct tab);
|
t = uiNew(struct tab);
|
||||||
c->data = t;
|
c->data = t;
|
||||||
|
|
||||||
hwnd = (HWND) uiControlHandle(c);
|
hwnd = uiControlHWND(c);
|
||||||
if ((*fv_SetWindowSubclass)(hwnd, tabSubProc, 0, (DWORD_PTR) c) == FALSE)
|
if ((*fv_SetWindowSubclass)(hwnd, tabSubProc, 0, (DWORD_PTR) c) == FALSE)
|
||||||
logLastError("error subclassing Tab to give it its own resize handler in uiNewTab()");
|
logLastError("error subclassing Tab to give it its own resize handler in uiNewTab()");
|
||||||
|
|
||||||
|
@ -152,13 +152,13 @@ void uiTabAddPage(uiControl *c, const char *name, uiControl *child)
|
||||||
t->pages = (struct tabPage *) uiRealloc(t->pages, t->cap * sizeof (struct tabPage), "struct tabPage[]");
|
t->pages = (struct tabPage *) uiRealloc(t->pages, t->cap * sizeof (struct tabPage), "struct tabPage[]");
|
||||||
}
|
}
|
||||||
|
|
||||||
hwnd = (HWND) uiControlHandle(c);
|
hwnd = uiControlHWND(c);
|
||||||
n = SendMessageW(hwnd, TCM_GETITEMCOUNT, 0, 0);
|
n = SendMessageW(hwnd, TCM_GETITEMCOUNT, 0, 0);
|
||||||
|
|
||||||
parent = uiNewParent((uintptr_t) hwnd);
|
parent = uiNewParent((uintptr_t) hwnd);
|
||||||
uiParentSetChild(parent, child);
|
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
|
||||||
ShowWindow((HWND) uiParentHandle(parent), SW_HIDE);
|
ShowWindow(uiParentHWND(parent), SW_HIDE);
|
||||||
t->pages[t->len].content = parent;
|
t->pages[t->len].content = parent;
|
||||||
t->len++;
|
t->len++;
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,10 @@ This file assumes that you have included <windows.h> and "ui.h" beforehand. It p
|
||||||
#ifndef __UI_UI_WINDOWS_H__
|
#ifndef __UI_UI_WINDOWS_H__
|
||||||
#define __UI_UI_WINDOWS_H__
|
#define __UI_UI_WINDOWS_H__
|
||||||
|
|
||||||
|
// Correctness macros.
|
||||||
|
#define uiControlHWND(c) ((HWND) uiControlHandle(c))
|
||||||
|
#define uiParentHWND(p) ((HWND) uiParentHandle(p))
|
||||||
|
|
||||||
// uiWindowsNewControl() creates a new uiControl with the given Windows API control inside.
|
// uiWindowsNewControl() creates a new uiControl with the given Windows API control inside.
|
||||||
// You will need to provide the preferredSize() method yourself.
|
// You will need to provide the preferredSize() method yourself.
|
||||||
typedef struct uiWindowsNewControlParams uiWindowsNewControlParams;
|
typedef struct uiWindowsNewControlParams uiWindowsNewControlParams;
|
||||||
|
|
|
@ -33,7 +33,7 @@ static LRESULT CALLBACK uiWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPA
|
||||||
break;
|
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()");
|
||||||
contenthwnd = (HWND) uiParentHandle(w->content);
|
contenthwnd = uiParentHWND(w->content);
|
||||||
if (MoveWindow(contenthwnd, r.left, r.top, r.right - r.left, r.bottom - r.top, TRUE) == 0)
|
if (MoveWindow(contenthwnd, r.left, r.top, r.right - r.left, r.bottom - r.top, TRUE) == 0)
|
||||||
logLastError("error resizing window content parent in uiWindowWndProc()");
|
logLastError("error resizing window content parent in uiWindowWndProc()");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue