diff --git a/new/button_windows.c b/new/button_windows.c index 0bd3021..f89a197 100644 --- a/new/button_windows.c +++ b/new/button_windows.c @@ -37,7 +37,7 @@ static void preferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t * HWND hwnd; SIZE size; - hwnd = (HWND) uiControlHandle(c); + hwnd = uiControlHWND(c); // try the comctl32 version 6 way size.cx = 0; // explicitly ask for ideal size diff --git a/new/checkbox_windows.c b/new/checkbox_windows.c index 28433d2..951eee9 100644 --- a/new/checkbox_windows.c +++ b/new/checkbox_windows.c @@ -16,7 +16,7 @@ static BOOL onWM_COMMAND(uiControl *c, WORD code, LRESULT *lResult) return FALSE; // 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; if (SendMessage(hwnd, BM_GETCHECK, 0, 0) == BST_CHECKED) 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) { - *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); } @@ -106,7 +106,7 @@ int uiCheckboxChecked(uiControl *c) { HWND hwnd; - hwnd = (HWND) uiControlHandle(c); + hwnd = uiControlHWND(c); return SendMessage(hwnd, BM_GETCHECK, 0, 0) == BST_CHECKED; } @@ -115,7 +115,7 @@ void uiCheckboxSetChecked(uiControl *c, int checked) HWND hwnd; WPARAM check; - hwnd = (HWND) uiControlHandle(c); + hwnd = uiControlHWND(c); check = BST_CHECKED; if (!checked) check = BST_UNCHECKED; diff --git a/new/label_windows.c b/new/label_windows.c index 8108033..3d8a5cc 100644 --- a/new/label_windows.c +++ b/new/label_windows.c @@ -26,7 +26,7 @@ static void onWM_DESTROY(uiControl *c) 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); } diff --git a/new/newcontrol_windows.c b/new/newcontrol_windows.c index 1d48229..12a26f3 100644 --- a/new/newcontrol_windows.c +++ b/new/newcontrol_windows.c @@ -36,7 +36,7 @@ static void singleSetParent(uiControl *c, uiParent *parent) singleHWND *s = (singleHWND *) (c->internal); 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()"); uiParentUpdate(s->parent); } diff --git a/new/tab_windows.c b/new/tab_windows.c index 854e5e8..476f20b 100644 --- a/new/tab_windows.c +++ b/new/tab_windows.c @@ -24,15 +24,15 @@ static BOOL onWM_NOTIFY(uiControl *c, NMHDR *nm, LRESULT *lResult) switch (nm->code) { 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 - ShowWindow((HWND) uiParentHandle(t->pages[n].content), SW_HIDE); + ShowWindow(uiParentHWND(t->pages[n].content), SW_HIDE); *lResult = FALSE; // and allow the change return TRUE; 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 - 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 uiParentUpdate(t->pages[n].content); } @@ -63,7 +63,7 @@ static void resizeTab(uiControl *c, LONG width, LONG height) LRESULT n; RECT r; - hwnd = (HWND) uiControlHandle(c); + hwnd = uiControlHWND(c); n = SendMessageW(hwnd, TCM_GETCURSEL, 0, 0); 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 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()"); } @@ -129,7 +129,7 @@ uiControl *uiNewTab(void) t = uiNew(struct tab); c->data = t; - hwnd = (HWND) uiControlHandle(c); + hwnd = uiControlHWND(c); if ((*fv_SetWindowSubclass)(hwnd, tabSubProc, 0, (DWORD_PTR) c) == FALSE) 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[]"); } - hwnd = (HWND) uiControlHandle(c); + hwnd = uiControlHWND(c); n = SendMessageW(hwnd, TCM_GETITEMCOUNT, 0, 0); parent = uiNewParent((uintptr_t) hwnd); uiParentSetChild(parent, child); 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->len++; diff --git a/new/ui_windows.h b/new/ui_windows.h index 0fba593..70badb4 100644 --- a/new/ui_windows.h +++ b/new/ui_windows.h @@ -7,6 +7,10 @@ This file assumes that you have included and "ui.h" beforehand. It p #ifndef __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. // You will need to provide the preferredSize() method yourself. typedef struct uiWindowsNewControlParams uiWindowsNewControlParams; diff --git a/new/window_windows.c b/new/window_windows.c index a52debf..0bac04b 100644 --- a/new/window_windows.c +++ b/new/window_windows.c @@ -33,7 +33,7 @@ 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()"); - 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) logLastError("error resizing window content parent in uiWindowWndProc()"); return 0;