diff --git a/ui_windows.h b/ui_windows.h index f4e630fa..b1a6362f 100644 --- a/ui_windows.h +++ b/ui_windows.h @@ -17,12 +17,14 @@ typedef struct uiWindowsControl uiWindowsControl; struct uiWindowsControl { uiControl c; uiControl *parent; + // TODO this should be int on both os x and windows BOOL enabled; BOOL visible; void (*SyncEnableState)(uiWindowsControl *, int); void (*SetParentHWND)(uiWindowsControl *, HWND); + // TODO consider changing these from intmax_t to int void (*MinimumSize)(uiWindowsControl *, intmax_t *, intmax_t *); - void (*MinimumSizeChanged)(uiWIndowsControl *); + void (*MinimumSizeChanged)(uiWindowsControl *); void (*LayoutRect)(uiWindowsControl *c, RECT *r); void (*AssignControlIDZOrder)(uiWindowsControl *, LONG_PTR *, HWND *); }; @@ -72,13 +74,13 @@ _UI_EXTERN void uiWindowsControlAssignControlIDZOrder(uiWindowsControl *, LONG_P #define uiWindowsControlDefaultShow(type) \ static void type ## Show(uiControl *c) \ { \ - uiWindowsControl(c)->visible = YES; \ + uiWindowsControl(c)->visible = 1; \ ShowWindow(type(c)->hwnd, SW_SHOW); \ } #define uiWindowsControlDefaultHide(type) \ static void type ## Hide(uiControl *c) \ { \ - uiWindowsControl(c)->visible = NO; \ + uiWindowsControl(c)->visible = 0; \ ShowWindow(type(c)->hwnd, SW_HIDE); \ } #define uiWindowsControlDefaultEnabled(type) \ @@ -89,13 +91,13 @@ _UI_EXTERN void uiWindowsControlAssignControlIDZOrder(uiWindowsControl *, LONG_P #define uiWindowsControlDefaultEnable(type) \ static void type ## Enable(uiControl *c) \ { \ - uiWindowsControl(c)->enabled = YES; \ + uiWindowsControl(c)->enabled = 1; \ uiWindowsControlSyncEnableState(uiWindowsControl(c), uiControlEnabledToUser(c)); \ } #define uiWindowsControlDefaultDisable(type) \ static void type ## Disable(uiControl *c) \ { \ - uiWindowsControl(c)->enabled = NO; \ + uiWindowsControl(c)->enabled = 0; \ uiWindowsControlSyncEnableState(uiWindowsControl(c), uiControlEnabledToUser(c)); \ } #define uiWindowsControlDefaultSyncEnableState(type) \ @@ -112,7 +114,7 @@ _UI_EXTERN void uiWindowsControlAssignControlIDZOrder(uiWindowsControl *, LONG_P } // note that there is no uiWindowsControlDefaultMinimumSize(); you MUST define this yourself! #define uiWindowsControlDefaultMinimumSizeChanged(type) \ - static void type ## MinimumSizeChanged)(uiWIndowsControl *c) \ + static void type ## MinimumSizeChanged(uiWindowsControl *c) \ { \ if (uiWindowsControlTooSmall(c)) { \ uiWindowsControlContinueMinimumSizeChanged(c); \ @@ -126,10 +128,10 @@ _UI_EXTERN void uiWindowsControlAssignControlIDZOrder(uiWindowsControl *, LONG_P /* use the window rect as we include the non-client area in the sizes */ \ uiWindowsEnsureGetWindowRect(type(c)->hwnd, r); \ } -#define uiWindowsControlDefaultAssignControlIDZorder(type) \ - static void type ## AssignControlIDZOrder)(uiWindowsControl *c, LONG_PTR *controlID, HWND *insertAfter) \ +#define uiWindowsControlDefaultAssignControlIDZOrder(type) \ + static void type ## AssignControlIDZOrder(uiWindowsControl *c, LONG_PTR *controlID, HWND *insertAfter) \ { \ - uiWindowsEnsureAssignControlIDZOrder(c, controlID, insertAfter); \ + uiWindowsEnsureAssignControlIDZOrder(type(c)->hwnd, controlID, insertAfter); \ } #define uiWindowsControlAllDefaultsExceptDestroy(type) \ @@ -147,7 +149,7 @@ _UI_EXTERN void uiWindowsControlAssignControlIDZOrder(uiWindowsControl *, LONG_P uiWindowsControlDefaultSetParentHWND(type) \ uiWindowsControlDefaultMinimumSizeChanged(type) \ uiWindowsControlDefaultLayoutRect(type) \ - uiWindowsControlDefaultAssignControlIDZorder(type) + uiWindowsControlDefaultAssignControlIDZOrder(type) #define uiWindowsControlAllDefaults(type) \ uiWindowsControlDefaultDestroy(type) \ @@ -170,10 +172,11 @@ _UI_EXTERN void uiWindowsControlAssignControlIDZOrder(uiWindowsControl *, LONG_P uiWindowsControl(var)->SyncEnableState = type ## SyncEnableState; \ uiWindowsControl(var)->SetParentHWND = type ## SetParentHWND; \ uiWindowsControl(var)->MinimumSize = type ## MinimumSize; \ - uiWindowsControl(var)->ChildMinimumSizeChanged = type ## ChildMinimumSizeChanged; \ - uiWindowsControl(var)->AssignControlIDZOrder = type ## AssignControlIDZorder; \ - uiWindowsControl(var)->visible = YES; \ - uiWindowsControl(var)->enabled = YES; + uiWindowsControl(var)->MinimumSizeChanged = type ## MinimumSizeChanged; \ + uiWindowsControl(var)->LayoutRect = type ## LayoutRect; \ + uiWindowsControl(var)->AssignControlIDZOrder = type ## AssignControlIDZOrder; \ + uiWindowsControl(var)->visible = 1; \ + uiWindowsControl(var)->enabled = 1; // TODO document _UI_EXTERN uiWindowsControl *uiWindowsAllocControl(size_t n, uint32_t typesig, const char *typenamestr); @@ -229,7 +232,7 @@ struct uiWindowsSizing { LONG InternalLeading; }; _UI_EXTERN void uiWindowsGetSizing(HWND hwnd, uiWindowsSizing *sizing); -_UI_EXTERN void uiWindowsSizingDlgUnitsToPixels(uiWindowsSIzing *sizing, int *x, int *y); +_UI_EXTERN void uiWindowsSizingDlgUnitsToPixels(uiWindowsSizing *sizing, int *x, int *y); _UI_EXTERN void uiWindowsSizingStandardPadding(uiWindowsSizing *sizing, int *x, int *y); // TODO document @@ -242,6 +245,9 @@ _UI_EXTERN void uiWindowsControlContinueMinimumSizeChanged(uiWindowsControl *c); // TODO document _UI_EXTERN void uiWindowsControlAssignSoleControlIDZOrder(uiWindowsControl *); +// TODO document +_UI_EXTERN BOOL uiWindowsShouldStopSyncEnableState(uiWindowsControl *c, int enabled); + #ifdef __cplusplus } #endif diff --git a/windows/area.cpp b/windows/area.cpp index 82af0f79..2d301855 100644 --- a/windows/area.cpp +++ b/windows/area.cpp @@ -32,8 +32,7 @@ static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM if (uMsg == WM_WINDOWPOSCHANGED) { if ((wp->flags & SWP_NOSIZE) != 0) return DefWindowProcW(hwnd, uMsg, wParam, lParam); - if (uiWindowsEnsureGetClientRect(a->hwnd, &client) == 0) - logLastError(L"error getting client rect of uiArea for WM_WINDOWPOSCHANGED handling"); + uiWindowsEnsureGetClientRect(a->hwnd, &client); areaDrawOnResize(a, &client); areaScrollOnResize(a, &client); return 0; diff --git a/windows/areadraw.cpp b/windows/areadraw.cpp index 414d23a1..90a8fe28 100644 --- a/windows/areadraw.cpp +++ b/windows/areadraw.cpp @@ -94,8 +94,7 @@ static void onWM_PRINTCLIENT(uiArea *a) { RECT client; - if (uiWindowsEnsureGetClientRect(a->hwnd, &client) == 0) - logLastError(L"error getting client rect"); + uiWindowsEnsureGetClientRect(a->hwnd, &client); //TODO doPaint(a, (HDC) wParam, &client); } diff --git a/windows/areaevents.cpp b/windows/areaevents.cpp index 991a2c86..386b49f8 100644 --- a/windows/areaevents.cpp +++ b/windows/areaevents.cpp @@ -85,8 +85,7 @@ static void areaMouseEvent(uiArea *a, uintmax_t down, uintmax_t up, WPARAM wPar if (a->capturing) { clientpt.x = GET_X_LPARAM(lParam); clientpt.y = GET_Y_LPARAM(lParam); - if (uiWindowsEnsureGetClientRect(a->hwnd, &client) == 0) - logLastError(L"error getting uiAreaclient rect for mouse crossing on capture on drag"); + uiWindowsEnsureGetClientRect(a->hwnd, &client); inClient = PtInRect(&client, clientpt); if (inClient && !a->inside) { a->inside = TRUE; diff --git a/windows/areascroll.cpp b/windows/areascroll.cpp index 48b2c29c..782755a9 100644 --- a/windows/areascroll.cpp +++ b/windows/areascroll.cpp @@ -128,8 +128,7 @@ static void hscrollParams(uiArea *a, struct scrollParams *p) ZeroMemory(p, sizeof (struct scrollParams)); p->pos = &(a->hscrollpos); // TODO get rid of these and replace with points - if (uiWindowsEnsureGetClientRect(a->hwnd, &r) == 0) - logLastError(L"error getting area client rect"); + uiWindowsEnsureGetClientRect(a->hwnd, &r); p->pagesize = r.right - r.left; p->length = a->scrollWidth; p->wheelCarry = &(a->hwheelCarry); @@ -174,8 +173,7 @@ static void vscrollParams(uiArea *a, struct scrollParams *p) ZeroMemory(p, sizeof (struct scrollParams)); p->pos = &(a->vscrollpos); - if (uiWindowsEnsureGetClientRect(a->hwnd, &r) == 0) - logLastError(L"error getting area client rect"); + uiWindowsEnsureGetClientRect(a->hwnd, &r); p->pagesize = r.bottom - r.top; p->length = a->scrollHeight; p->wheelCarry = &(a->vwheelCarry); diff --git a/windows/box.cpp b/windows/box.cpp index e3705d96..01413ebe 100644 --- a/windows/box.cpp +++ b/windows/box.cpp @@ -18,6 +18,8 @@ struct uiBox { static void boxPadding(uiBox *b, int *xpadding, int *ypadding) { + uiWindowsSizing sizing; + *xpadding = 0; *ypadding = 0; if (b->padded) { @@ -103,7 +105,7 @@ static void boxRelayout(uiBox *b) for (const struct boxChild &bc : *(b->controls)) { if (!uiControlVisible(bc.c)) continue; - uiWindowsEnsureMoveWIndowDuringResize((HWND) uiControlHandle(bc.c), x, y, bc.width, bc.height); + uiWindowsEnsureMoveWindowDuringResize((HWND) uiControlHandle(bc.c), x, y, bc.width, bc.height); if (b->vertical) y += bc.height + ypadding; else @@ -212,7 +214,7 @@ static void uiBoxMinimumSize(uiWindowsControl *c, intmax_t *width, intmax_t *hei static void uiBoxMinimumSizeChanged(uiWindowsControl *c) { - uiBox *t = uiBox(c); + uiBox *b = uiBox(c); if (uiWindowsControlTooSmall(uiWindowsControl(b))) { uiWindowsControlContinueMinimumSizeChanged(uiWindowsControl(b)); @@ -222,7 +224,7 @@ static void uiBoxMinimumSizeChanged(uiWindowsControl *c) } uiWindowsControlDefaultLayoutRect(uiBox) -uiWindowsControlDefaultAssignControlIDZorder(uiBox) +uiWindowsControlDefaultAssignControlIDZOrder(uiBox) static void boxArrangeChildren(uiBox *b) { @@ -233,7 +235,7 @@ static void boxArrangeChildren(uiBox *b) controlID = 100; insertAfter = NULL; for (const struct boxChild &bc : *(b->controls)) - uiWindowsControlAssignControlIDZOrder(uiWindwsControl(bc.c), &controlID, &insertAfter); + uiWindowsControlAssignControlIDZOrder(uiWindowsControl(bc.c), &controlID, &insertAfter); } void uiBoxAppend(uiBox *b, uiControl *c, int stretchy) @@ -256,7 +258,7 @@ void uiBoxDelete(uiBox *b, uintmax_t index) c = (*(b->controls))[index].c; uiControlSetParent(c, NULL); uiWindowsControlSetParentHWND(uiWindowsControl(c), NULL); - b->controls->erase(b->controls->begin() + Index); + b->controls->erase(b->controls->begin() + index); boxArrangeChildren(b); uiWindowsControlMinimumSizeChanged(uiWindowsControl(b)); } @@ -272,7 +274,7 @@ void uiBoxSetPadded(uiBox *b, int padded) uiWindowsControlMinimumSizeChanged(uiWindowsControl(b)); } -static void onResize(uiControl *c) +static void onResize(uiWindowsControl *c) { boxRelayout(uiBox(c)); } @@ -283,10 +285,10 @@ static uiBox *finishNewBox(int vertical) uiWindowsNewControl(uiBox, b); - b->hwnd = uiWIndowsMakeContainer(uiControl(b), onResize); + b->hwnd = uiWindowsMakeContainer(uiWindowsControl(b), onResize); b->vertical = vertical; - b->controls = newPtrArray(); + b->controls = new std::vector; return b; } diff --git a/windows/button.cpp b/windows/button.cpp index 37e31574..057d8763 100644 --- a/windows/button.cpp +++ b/windows/button.cpp @@ -25,7 +25,7 @@ static void uiButtonDestroy(uiControl *c) uiWindowsUnregisterWM_COMMANDHandler(b->hwnd); uiWindowsEnsureDestroyWindow(b->hwnd); - uiFreeControl(b->hwnd); + uiFreeControl(uiControl(b)); } uiWindowsControlAllDefaultsExceptDestroy(uiButton) diff --git a/windows/checkbox.cpp b/windows/checkbox.cpp index 59e44caa..7c30c113 100644 --- a/windows/checkbox.cpp +++ b/windows/checkbox.cpp @@ -32,7 +32,7 @@ static void uiCheckboxDestroy(uiControl *cc) uiCheckbox *c = uiCheckbox(cc); uiWindowsUnregisterWM_COMMANDHandler(c->hwnd); - uiWindowsEnsureDestroyHWND(c->hwnd); + uiWindowsEnsureDestroyWindow(c->hwnd); uiFreeControl(uiControl(c)); } @@ -43,7 +43,7 @@ uiWindowsControlAllDefaultsExceptDestroy(uiCheckbox) // from http://msdn.microsoft.com/en-us/library/windows/desktop/bb226818%28v=vs.85%29.aspx #define checkboxXFromLeftOfBoxToLeftOfLabel 12 -static void uiCheckboxinimumSize(uiWindowsControl *cc, intmax_t *width, intmax_t *height) +static void uiCheckboxMinimumSize(uiWindowsControl *cc, intmax_t *width, intmax_t *height) { uiCheckbox *c = uiCheckbox(cc); uiWindowsSizing sizing; diff --git a/windows/container.cpp b/windows/container.cpp index 0775c4fd..31c93a23 100644 --- a/windows/container.cpp +++ b/windows/container.cpp @@ -4,6 +4,8 @@ // Code for the HWND of the following uiControls: // - uiBox // - uiRadioButtons +// - uiSpinbox +// - uiTab struct containerInit { uiWindowsControl *c; @@ -17,27 +19,27 @@ static LRESULT CALLBACK containerWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LP PAINTSTRUCT ps; CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam; WINDOWPOS *wp = (WINDOWPOS *) lParam; - MINMAXINFO *mm = (MINMAXINFO *) lParam; + MINMAXINFO *mmi = (MINMAXINFO *) lParam; struct containerInit *init; uiWindowsControl *c; void (*onResize)(uiWindowsControl *); - uintmax_t minwid, minht; + intmax_t minwid, minht; LRESULT lResult; if (handleParentMessages(hwnd, uMsg, wParam, lParam, &lResult) != FALSE) return lResult; switch (uMsg) { case WM_CREATE: - init = (struct containerInit *) (cs->lpParam); + init = (struct containerInit *) (cs->lpCreateParams); SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) (init->onResize)); SetWindowLongPtrW(hwnd, 0, (LONG_PTR) (init->c)); break; // defer to DefWindowProc() case WM_WINDOWPOSCHANGED: if ((wp->flags & SWP_NOSIZE) != 0) break; // defer to DefWindowProc(); - onResize = (void (*)(uiControl *)) GetWindowLongPtrW(hwnd, GWLP_USERDATA); + onResize = (void (*)(uiWindowsControl *)) GetWindowLongPtrW(hwnd, GWLP_USERDATA); c = (uiWindowsControl *) GetWindowLongPtrW(hwnd, 0); - (*(onResize))(data); + (*(onResize))(c); return 0; case WM_GETMINMAXINFO: lResult = DefWindowProcW(hwnd, uMsg, wParam, lParam); @@ -59,11 +61,7 @@ static LRESULT CALLBACK containerWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LP return 0; // tab controls use this to draw the background of the tab area case WM_PRINTCLIENT: - if (uiWindowsEnsureGetClientRect(hwnd, &r) == 0) { - logLastError(L"error getting client rect"); - // likewise - break; - } + uiWindowsEnsureGetClientRect(hwnd, &r); paintContainerBackground(hwnd, (HDC) wParam, &r); return 0; case WM_ERASEBKGND: diff --git a/windows/control.cpp b/windows/control.cpp index 9a175e69..2afbbc27 100644 --- a/windows/control.cpp +++ b/windows/control.cpp @@ -13,10 +13,10 @@ void uiWindowsControlSetParentHWND(uiWindowsControl *c, HWND parent) void uiWindowsControlMinimumSize(uiWindowsControl *c, intmax_t *width, intmax_t *height) { - (*(c->MinimumSize))(c, widdth, height); + (*(c->MinimumSize))(c, width, height); } -void uiWindowsControlMinimumSizeChanged(uiWIndowsControl *c) +void uiWindowsControlMinimumSizeChanged(uiWindowsControl *c) { (*(c->MinimumSizeChanged))(c); } @@ -28,7 +28,7 @@ void uiWindowsControlLayoutRect(uiWindowsControl *c, RECT *r) void uiWindowsControlAssignControlIDZOrder(uiWindowsControl *c, LONG_PTR *controlID, HWND *insertAfter) { - (*(c->AssignControlIDZorder))(c, controlID, insertAfter); + (*(c->AssignControlIDZOrder))(c, controlID, insertAfter); } HWND uiWindowsEnsureCreateControlHWND(DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, HINSTANCE hInstance, LPVOID lpParam, BOOL useStandardControlFont) @@ -57,18 +57,21 @@ HWND uiWindowsEnsureCreateControlHWND(DWORD dwExStyle, LPCWSTR lpClassName, LPCW // choose a value distinct from uiWindowSignature #define uiWindowsControlSignature 0x4D53576E -uiWindowsControl *uiWindowsNewControl(size_t n, uint32_t typesig, const char *typenamestr) +uiWindowsControl *uiWindowsAllocControl(size_t n, uint32_t typesig, const char *typenamestr) { return uiWindowsControl(uiAllocControl(n, uiWindowsControlSignature, typesig, typenamestr)); } -void uiWindowsControlNotifyMinimumSizeChanged(uiWindowsControl *c) +BOOL uiWindowsShouldStopSyncEnableState(uiWindowsControl *c, BOOL enabled) { - uiControl *parent; + int ce; - parent = uiControlParent(uiControl(c)); - if (parent != NULL) - uiWindowsControlChildMinimumSizeChanged(uiWindowsControl(parent)); + ce = uiControlEnabled(uiControl(c)); + // only stop if we're going from disabled back to enabled; don't stop under any other condition + // (if we stop when going from enabled to disabled then enabled children of a disabled control won't get disabled at the OS level) + if (!ce && enabled) + return TRUE; + return FALSE; } void uiWindowsControlAssignSoleControlIDZOrder(uiWindowsControl *c) @@ -78,7 +81,7 @@ void uiWindowsControlAssignSoleControlIDZOrder(uiWindowsControl *c) controlID = 100; insertAfter = NULL; - uiWindowsControlAssignControlIDZorder(c, &controlID, &insertAfter); + uiWindowsControlAssignControlIDZOrder(c, &controlID, &insertAfter); } BOOL uiWindowsControlTooSmall(uiWindowsControl *c) diff --git a/windows/datetimepicker.cpp b/windows/datetimepicker.cpp index dcd6372f..b81cfe6f 100644 --- a/windows/datetimepicker.cpp +++ b/windows/datetimepicker.cpp @@ -104,7 +104,7 @@ static void uiDateTimePickerDestroy(uiControl *c) uiWindowsUnregisterReceiveWM_WININICHANGE(d->hwnd); uiWindowsEnsureDestroyWindow(d->hwnd); - uiFreeControl(d); + uiFreeControl(uiControl(d)); } uiWindowsControlAllDefaultsExceptDestroy(uiDateTimePicker) diff --git a/windows/draw.cpp b/windows/draw.cpp index a16dbd93..cc581706 100644 --- a/windows/draw.cpp +++ b/windows/draw.cpp @@ -51,8 +51,7 @@ ID2D1HwndRenderTarget *makeHWNDRenderTarget(HWND hwnd) if (ReleaseDC(hwnd, dc) == 0) logLastError(L"error releasing DC for finding DPI"); - if (uiWindowsEnsureGetClientRect(hwnd, &r) == 0) - logLastError(L"error getting current size of window"); + uiWindowsEnsureGetClientRect(hwnd, &r); ZeroMemory(&hprops, sizeof (D2D1_HWND_RENDER_TARGET_PROPERTIES)); hprops.hwnd = hwnd; diff --git a/windows/fontdialog.cpp b/windows/fontdialog.cpp index affeba97..feb264f0 100644 --- a/windows/fontdialog.cpp +++ b/windows/fontdialog.cpp @@ -495,8 +495,7 @@ static struct fontDialog *beginFontDialog(HWND hwnd, LPARAM lParam) samplePlacement = GetDlgItem(f->hwnd, rcFontSamplePlacement); if (samplePlacement == NULL) logLastError(L"error getting sample placement static control handle"); - if (uiWindowsEnsureGetWindowRect(samplePlacement, &(f->sampleRect)) == 0) - logLastError(L"error getting sample placement"); + uiWindowsEnsureGetWindowRect(samplePlacement, &(f->sampleRect)); mapWindowRect(NULL, f->hwnd, &(f->sampleRect)); uiWindowsEnsureDestroyWindow(samplePlacement); f->sampleBox = newD2DScratch(f->hwnd, &(f->sampleRect), (HMENU) rcFontSamplePlacement, fontDialogSampleSubProc, (DWORD_PTR) f); diff --git a/windows/group.cpp b/windows/group.cpp index 87ef0eec..3af67acd 100644 --- a/windows/group.cpp +++ b/windows/group.cpp @@ -23,48 +23,34 @@ struct uiGroup { static void groupMargins(uiGroup *g, int *mx, int *mtop, int *mbottom) { uiWindowsSizing sizing; - int dummy; *mx = groupUnmarginedXMargin; *mtop = groupUnmarginedYMarginTop; *mbottom = groupUnmarginedYMarginBottom; - dummy = 1; // for the bottom conversion if (g->margined) { *mx = groupXMargin; *mtop = groupYMarginTop; *mbottom = groupYMarginBottom; } - uiWindowsControlGetSizing(uiWindowsControl(g), &sizing); + uiWindowsGetSizing(g->hwnd, &sizing); uiWindowsSizingDlgUnitsToPixels(&sizing, mx, mtop); - uiWindowsSizingDlgUnitsToPixels(&sizing, &dummy, mbottom); + uiWindowsSizingDlgUnitsToPixels(&sizing, NULL, mbottom); } static void groupRelayout(uiGroup *g) { - uiGroup *g = uiGroup(c); - uiWindowsSizing *d; - - uiWindowsEnsureMoveWindowDuringResize(g->hwnd, x, y, width, height); + RECT r; + int mx, mtop, mbottom; if (g->child == NULL) return; - - d = uiWindowsNewSizing(g->hwnd); - x = 0; // make relative to the top-left corner of the groupbox - y = 0; - if (g->margined) { - x += uiWindowsDlgUnitsToX(groupXMargin, d->BaseX); - y += uiWindowsDlgUnitsToY(groupYMarginTop, d->BaseY); - width -= 2 * uiWindowsDlgUnitsToX(groupXMargin, d->BaseX); - height -= uiWindowsDlgUnitsToY(groupYMarginTop, d->BaseY) + uiWindowsDlgUnitsToY(groupYMarginBottom, d->BaseY); - } else { - x += uiWindowsDlgUnitsToX(groupUnmarginedXMargin, d->BaseX); - y += uiWindowsDlgUnitsToY(groupUnmarginedYMarginTop, d->BaseY); - width -= 2 * uiWindowsDlgUnitsToX(groupUnmarginedXMargin, d->BaseX); - height -= uiWindowsDlgUnitsToY(groupUnmarginedYMarginTop, d->BaseY) + uiWindowsDlgUnitsToY(groupUnmarginedYMarginBottom, d->BaseY); - } - uiWindowsFreeSizing(d); - childRelayout(g->child, x, y, width, height); + uiWindowsEnsureGetClientRect(g->hwnd, &r); + groupMargins(g, &mx, &mtop, &mbottom); + r.left += mx; + r.top += mtop; + r.right -= mx; + r.bottom -= mbottom; + uiWindowsEnsureMoveWindowDuringResize((HWND) uiControlHandle(g->child), r.left, r.top, r.right - r.left, r.bottom - r.top); } static void uiGroupDestroy(uiControl *c) @@ -130,15 +116,7 @@ static void uiGroupMinimumSizeChanged(uiWindowsControl *c) } uiWindowsControlDefaultLayoutRect(uiGroup) -uiWindowsControlDefaultAssignControlIDZorder(uiGroup) - -static void groupArrangeChildrenControlIDsZOrder(uiWindowsControl *c) -{ - uiGroup *g = uiGroup(c); - - if (g->child != NULL) - childSetSoleControlID(g->child); -} +uiWindowsControlDefaultAssignControlIDZOrder(uiGroup) char *uiGroupTitle(uiGroup *g) { @@ -163,7 +141,7 @@ void uiGroupSetChild(uiGroup *g, uiControl *child) uiControlSetParent(g->child, uiControl(g)); uiWindowsControlSetParentHWND(uiWindowsControl(g->child), g->hwnd); uiWindowsControlAssignSoleControlIDZOrder(uiWindowsControl(g->child)); - uiWindowsControlChildMinimumSizeChanged(uiWindowsControl(g)); + uiWindowsControlMinimumSizeChanged(uiWindowsControl(g)); } } @@ -175,7 +153,7 @@ int uiGroupMargined(uiGroup *g) void uiGroupSetMargined(uiGroup *g, int margined) { g->margined = margined; - uiWindowsControlChildMinimumSizeChanged(uiWindowsControl(g)); + uiWindowsControlMinimumSizeChanged(uiWindowsControl(g)); } static LRESULT CALLBACK groupSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) diff --git a/windows/label.cpp b/windows/label.cpp index c64b903f..6a401b0f 100644 --- a/windows/label.cpp +++ b/windows/label.cpp @@ -20,7 +20,7 @@ static void uiLabelMinimumSize(uiWindowsControl *c, intmax_t *width, intmax_t *h *width = uiWindowsWindowTextWidth(l->hwnd); y = labelHeight; uiWindowsGetSizing(l->hwnd, &sizing); - uiWindowsSizingDlgUnitsToY(&sizing, NULL, &y); + uiWindowsSizingDlgUnitsToPixels(&sizing, NULL, &y); *height = y; } diff --git a/windows/multilineentry.cpp b/windows/multilineentry.cpp index 4d9e0d8a..38908f38 100644 --- a/windows/multilineentry.cpp +++ b/windows/multilineentry.cpp @@ -34,14 +34,14 @@ static void uiMultilineEntryDestroy(uiControl *c) uiFreeControl(uiControl(e)); } -uiWindowsControlAllDefaultsExceptDestroy(uiEntry) +uiWindowsControlAllDefaultsExceptDestroy(uiMultilineEntry) // from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing #define entryWidth 107 /* this is actually the shorter progress bar width, but Microsoft only indicates as wide as necessary */ // TODO change this for multiline text boxes #define entryHeight 14 -static void minimumSize(uiWindowsControl *c, uiWindowsSizing *d, intmax_t *width, intmax_t *height) +static void uiMultilineEntryMinimumSize(uiWindowsControl *c, intmax_t *width, intmax_t *height) { uiMultilineEntry *e = uiMultilineEntry(c); uiWindowsSizing sizing; diff --git a/windows/parent.cpp b/windows/parent.cpp index bff08f17..bde6fb94 100644 --- a/windows/parent.cpp +++ b/windows/parent.cpp @@ -33,8 +33,7 @@ static HRESULT parentDraw(HDC dc, HWND parent, struct parentDraw *pd) { RECT r; - if (uiWindowsEnsureGetClientRect(parent, &r) == 0) - return logLastError(L"error getting parent's client rect"); + uiWindowsEnsureGetClientRect(parent, &r); pd->cdc = CreateCompatibleDC(dc); if (pd->cdc == NULL) return logLastError(L"error creating compatible DC"); @@ -86,10 +85,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 // if anything fails, give up and return the brush as-is - if (uiWindowsEnsureGetWindowRect(hwnd, &hwndScreenRect) == 0) { - logLastError(L"error getting control window rect"); - return brush; - } + uiWindowsEnsureGetWindowRect(hwnd, &hwndScreenRect); // this will be in screen coordinates; convert to parent coordinates mapWindowRect(NULL, parent, &hwndScreenRect); if (SetBrushOrgEx(dc, -hwndScreenRect.left, -hwndScreenRect.top, NULL) == 0) diff --git a/windows/radiobuttons.cpp b/windows/radiobuttons.cpp index 50bff56b..d68aabe7 100644 --- a/windows/radiobuttons.cpp +++ b/windows/radiobuttons.cpp @@ -141,14 +141,14 @@ void uiRadioButtonsAppend(uiRadioButtons *r, const char *text) hInstance, NULL, TRUE); uiFree(wtext); - uiWindowsEnsureSetParent(hwnd, r->hwnd); + uiWindowsEnsureSetParentHWND(hwnd, r->hwnd); uiWindowsRegisterWM_COMMANDHandler(hwnd, onWM_COMMAND, uiControl(r)); r->hwnds->push_back(hwnd); radiobuttonsArrangeChildren(r); uiWindowsControlMinimumSizeChanged(uiWindowsControl(r)); } -static void onResize(uiControl *c) +static void onResize(uiWindowsControl *c) { radiobuttonsRelayout(uiRadioButtons(c)); } @@ -159,7 +159,7 @@ uiRadioButtons *uiNewRadioButtons(void) uiWindowsNewControl(uiRadioButtons, r); - r->hwnd = uiWindowsMakeContainer(uiControl(r), onResize); + r->hwnd = uiWindowsMakeContainer(uiWindowsControl(r), onResize); r->hwnds = new std::vector; diff --git a/windows/sizing.cpp b/windows/sizing.cpp index fd3358d3..a0abdb46 100644 --- a/windows/sizing.cpp +++ b/windows/sizing.cpp @@ -2,7 +2,7 @@ #include "uipriv_windows.hpp" // TODO rework the error handling -void uiWindowsGetSizing(HWND hwnd, uiWindowsSizing *sizing); +void uiWindowsGetSizing(HWND hwnd, uiWindowsSizing *sizing) { HDC dc; HFONT prevfont; @@ -22,22 +22,20 @@ void uiWindowsGetSizing(HWND hwnd, uiWindowsSizing *sizing); if (GetTextExtentPoint32W(dc, L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 52, &size) == 0) logLastError(L"error getting text extent point"); - d->BaseX = (int) ((size.cx / 26 + 1) / 2); - d->BaseY = (int) tm.tmHeight; - d->InternalLeading = tm.tmInternalLeading; + sizing->BaseX = (int) ((size.cx / 26 + 1) / 2); + sizing->BaseY = (int) tm.tmHeight; + sizing->InternalLeading = tm.tmInternalLeading; if (SelectObject(dc, prevfont) != hMessageFont) logLastError(L"error restoring previous font into device context"); if (ReleaseDC(hwnd, dc) == 0) logLastError(L"error releasing DC"); - - return d; } #define dlgUnitsToX(dlg, baseX) MulDiv((dlg), (baseX), 4) #define dlgUnitsToY(dlg, baseY) MulDiv((dlg), (baseY), 8) -void uiWindowsSizingDlgUnitsToPixels(uiWindowsSIzing *sizing, int *x, int *y) +void uiWindowsSizingDlgUnitsToPixels(uiWindowsSizing *sizing, int *x, int *y) { if (x != NULL) *x = dlgUnitsToX(*x, sizing->BaseX); diff --git a/windows/slider.cpp b/windows/slider.cpp index cc9aacb6..83017e3b 100644 --- a/windows/slider.cpp +++ b/windows/slider.cpp @@ -17,7 +17,7 @@ static BOOL onWM_HSCROLL(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult) return TRUE; } -static void uiSliderDestroy(uiControl *s) +static void uiSliderDestroy(uiControl *c) { uiSlider *s = uiSlider(c); @@ -72,7 +72,7 @@ uiSlider *uiNewSlider(intmax_t min, intmax_t max) { uiSlider *s; - uiSliderNewControl(uiSlider, s); + uiWindowsNewControl(uiSlider, s); s->hwnd = uiWindowsEnsureCreateControlHWND(0, TRACKBAR_CLASSW, L"", diff --git a/windows/spinbox.cpp b/windows/spinbox.cpp index fc9a4779..9118d1d7 100644 --- a/windows/spinbox.cpp +++ b/windows/spinbox.cpp @@ -143,7 +143,6 @@ static void recreateUpDown(uiSpinbox *s) static void spinboxRelayout(uiSpinbox *s) { - uiSpinbox *s = uiSpinbox(c); RECT r; // make the edit fill the container first; the new updown will resize it @@ -175,7 +174,7 @@ void uiSpinboxOnChanged(uiSpinbox *s, void (*f)(uiSpinbox *, void *), void *data s->onChangedData = data; } -static void onResize(uiControl *c) +static void onResize(uiWindowsControl *c) { spinboxRelayout(uiSpinbox(c)); } @@ -189,7 +188,7 @@ uiSpinbox *uiNewSpinbox(intmax_t min, intmax_t max) uiWindowsNewControl(uiSpinbox, s); - s->hwnd = uiWindowsMakeContainer(uiControl(s), onResize); + s->hwnd = uiWindowsMakeContainer(uiWindowsControl(s), onResize); s->edit = uiWindowsEnsureCreateControlHWND(WS_EX_CLIENTEDGE, L"edit", L"", @@ -197,12 +196,11 @@ uiSpinbox *uiNewSpinbox(intmax_t min, intmax_t max) ES_AUTOHSCROLL | ES_LEFT | ES_NOHIDESEL | WS_TABSTOP, hInstance, NULL, TRUE); - uiWindowsEnsureSetParent(s->edit, s->hwnd); + uiWindowsEnsureSetParentHWND(s->edit, s->hwnd); uiWindowsRegisterWM_COMMANDHandler(s->hwnd, onWM_COMMAND, uiControl(s)); uiSpinboxOnChanged(s, defaultOnChanged, NULL); - s->parent = utilWindow; recreateUpDown(s); s->inhibitChanged = TRUE; SendMessageW(s->updown, UDM_SETRANGE32, (WPARAM) min, (LPARAM) max); diff --git a/windows/tab.cpp b/windows/tab.cpp index 54b19869..53aaeadb 100644 --- a/windows/tab.cpp +++ b/windows/tab.cpp @@ -28,14 +28,12 @@ static struct tabPage *tabPage(uiTab *t, intmax_t i) static void tabPageRect(uiTab *t, RECT *r) { - RECT r; - // this rect needs to be in parent window coordinates, but TCM_ADJUSTRECT wants a window rect, which is screen coordinates // because we have each page as a sibling of the tab, use the tab's own rect as the input rect - uiWindowsEnsureGetWindowRect(t->tabHWND, &r); - SendMessageW(t->tabHWND, TCM_ADJUSTRECT, (WPARAM) FALSE, (LPARAM) (&r)); + uiWindowsEnsureGetWindowRect(t->tabHWND, r); + SendMessageW(t->tabHWND, TCM_ADJUSTRECT, (WPARAM) FALSE, (LPARAM) r); // and get it in terms of the container instead of the screen - mapWindowRect(NULL, t->hwnd, &r); + mapWindowRect(NULL, t->hwnd, r); } static void tabRelayout(uiTab *t) @@ -91,7 +89,7 @@ static void uiTabDestroy(uiControl *c) uiTab *t = uiTab(c); uiControl *child; - for (struc ttabPage *&page : *(t->pages)) { + for (struct tabPage *&page : *(t->pages)) { child = page->child; tabPageDestroy(page); if (child != NULL) { @@ -143,7 +141,7 @@ static void uiTabMinimumSize(uiWindowsControl *c, intmax_t *width, intmax_t *hei pageht = 0; if (t->pages->size() != 0) { page = tabPage(t, curpage(t)); - childMinimumSize(page, d, &pagewid, &pageht); + tabPageMinimumSize(page, &pagewid, &pageht); } r.left = 0; @@ -168,7 +166,7 @@ static void uiTabMinimumSizeChanged(uiWindowsControl *c) } uiWindowsControlDefaultLayoutRect(uiTab) -uiWindowsControlDefaultAssignControlIDZorder(uiTab) +uiWindowsControlDefaultAssignControlIDZOrder(uiTab) static void tabArrangePages(uiTab *t) { @@ -176,9 +174,9 @@ static void tabArrangePages(uiTab *t) HWND insertAfter = NULL; // TODO is this first or last? - uiWindowsEnsureAssignControlIDZOrder(t->tabHWND, &cid, &after); + uiWindowsEnsureAssignControlIDZOrder(t->tabHWND, &controlID, &insertAfter); for (struct tabPage *&page : *(t->pages)) - uiWindowsEnsureAssignControlIDZOrder(page->hwnd, &cid, &after); + uiWindowsEnsureAssignControlIDZOrder(page->hwnd, &controlID, &insertAfter); } void uiTabAppend(uiTab *t, const char *name, uiControl *child) @@ -200,7 +198,7 @@ void uiTabInsertAt(uiTab *t, const char *name, uintmax_t n, uiControl *child) uiControlSetParent(child, uiControl(t)); page = newTabPage(child); - uiWindowsEnsureSetParent(page->hwnd, t->hwnd); + uiWindowsEnsureSetParentHWND(page->hwnd, t->hwnd); t->pages->insert(t->pages->begin() + n, page); // TODO adjust tabpage.cpp to set the sole control ID tabArrangePages(t); @@ -223,7 +221,7 @@ void uiTabInsertAt(uiTab *t, const char *name, uintmax_t n, uiControl *child) void uiTabDelete(uiTab *t, uintmax_t n) { - struct child *page; + struct tabPage *page; // first delete the tab from the tab control // if this is the current tab, no tab will be selected, which is good @@ -250,12 +248,12 @@ int uiTabMargined(uiTab *t, uintmax_t n) void uiTabSetMargined(uiTab *t, uintmax_t n, int margined) { - struct tabPage *page + struct tabPage *page; page = tabPage(t, n); page->margined = margined; // even if the page doesn't have a child it might still have a new minimum size with margins; this is the easiest way to verify it - uiWindowsControlChildMinimumSizeChanged(uiWindowsControl(t)); + uiWindowsControlMinimumSizeChanged(uiWindowsControl(t)); } static void onResize(uiWindowsControl *c) @@ -276,7 +274,7 @@ uiTab *uiNewTab(void) TCS_TOOLTIPS | WS_TABSTOP, hInstance, NULL, TRUE); - uiWindowsEnsureSetParent(t->tabHWND, t->hwnd); + uiWindowsEnsureSetParentHWND(t->tabHWND, t->hwnd); uiWindowsRegisterWM_NOTIFYHandler(t->tabHWND, onWM_NOTIFY, uiControl(t)); diff --git a/windows/tabpage.cpp b/windows/tabpage.cpp index a996ac83..4780147a 100644 --- a/windows/tabpage.cpp +++ b/windows/tabpage.cpp @@ -20,7 +20,7 @@ static void tabPageMargins(struct tabPage *tp, int *mx, int *my) uiWindowsSizingDlgUnitsToPixels(&sizing, mx, my); } -static void tabRelayout(struct tabPage *tp) +static void tabPageRelayout(struct tabPage *tp) { RECT r; int mx, my; @@ -50,7 +50,7 @@ static INT_PTR CALLBACK dlgproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPar if (uMsg == WM_INITDIALOG) { tp = (struct tabPage *) lParam; tp->hwnd = hwnd; - SetWindowLongPtrW(hwnd, DWLP_USERDATA, (LONG_PTR) tp); + SetWindowLongPtrW(hwnd, DWLP_USER, (LONG_PTR) tp); return TRUE; } if (handleParentMessages(hwnd, uMsg, wParam, lParam, &lResult) != FALSE) { @@ -58,7 +58,7 @@ static INT_PTR CALLBACK dlgproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPar return TRUE; } if (uMsg == WM_WINDOWPOSCHANGED) { - tp = (struct tabPage *) GetWindowLongPtrW(hwnd, DWLP_USERDATA); + tp = (struct tabPage *) GetWindowLongPtrW(hwnd, DWLP_USER); tabPageRelayout(tp); // pretend the dialog hasn't handled this just in case it needs to do something special return FALSE; @@ -87,11 +87,11 @@ struct tabPage *newTabPage(uiControl *child) // unfortunately this needs to be a proper dialog for EnableThemeDialogTexture() to work; CreateWindowExW() won't suffice if (CreateDialogParamW(hInstance, MAKEINTRESOURCE(rcTabPageDialog), - utilWindow, dlgproc, tp) == NULL) + utilWindow, dlgproc, (LPARAM) tp) == NULL) logLastError(L"error creating tab page"); tp->child = child; - uiControlSetParentHWND(uiWindowsControl(tp->child), tp->hwnd); + uiWindowsEnsureSetParentHWND((HWND) uiControlHandle(tp->child), tp->hwnd); hr = EnableThemeDialogTexture(tp->hwnd, ETDT_ENABLE | ETDT_USETABTEXTURE | ETDT_ENABLETAB); if (hr != S_OK) diff --git a/windows/window.cpp b/windows/window.cpp index a33c76f1..ca0e5c07 100644 --- a/windows/window.cpp +++ b/windows/window.cpp @@ -35,7 +35,6 @@ static void windowMargins(uiWindow *w, int *mx, int *my) static void windowRelayout(uiWindow *w) { - uiWindow *w = uiWindow(c); uiWindowsSizing sizing; int x, y, width, height; RECT r; @@ -234,7 +233,7 @@ static void uiWindowMinimumSizeChanged(uiWindowsControl *c) { uiWindow *w = uiWindow(c); - if (uiWindowsControlTooSmall(uiWindowsControl(w)) { + if (uiWindowsControlTooSmall(uiWindowsControl(w))) { // TODO figure out what to do with this function // maybe split it into two so WM_GETMINMAXINFO can use it? ensureMinimumWindowSize(w); @@ -244,7 +243,7 @@ static void uiWindowMinimumSizeChanged(uiWindowsControl *c) windowRelayout(w); } -static void uiWindowLayoutRect(uiWindowsControl *w, RECT *r) +static void uiWindowLayoutRect(uiWindowsControl *c, RECT *r) { uiWindow *w = uiWindow(c); @@ -252,7 +251,7 @@ static void uiWindowLayoutRect(uiWindowsControl *w, RECT *r) uiWindowsEnsureGetClientRect(w->hwnd, r); } -uiWindowsControlDefaultAssignControlIDZorder(uiWindow) +uiWindowsControlDefaultAssignControlIDZOrder(uiWindow) char *uiWindowTitle(uiWindow *w) {