diff --git a/redo/ui_windows.h b/redo/ui_windows.h index 5d6d2850..8e576366 100644 --- a/redo/ui_windows.h +++ b/redo/ui_windows.h @@ -109,6 +109,9 @@ struct uiWindowsSizing { HWND CoordFrom; HWND CoordTo; }; +// Use these to create and destroy uiWindowsSizings. +_UI_EXTERN uiWindowsSizing *uiWindowsNewSizing(HWND hwnd); +_UI_EXTERN void uiWindowsFreeSizing(uiWindowsSizing *d); // Use these in your preferredSize() implementation with baseX and baseY. #define uiWindowsDlgUnitsToX(dlg, baseX) MulDiv((dlg), baseX, 4) #define uiWindowsDlgUnitsToY(dlg, baseY) MulDiv((dlg), baseY, 8) diff --git a/redo/windows/box.c b/redo/windows/box.c index 7f2803bb..e9c166fa 100644 --- a/redo/windows/box.c +++ b/redo/windows/box.c @@ -108,7 +108,7 @@ static void minimumSize(uiWindowsControl *c, uiWindowsSizing *d, intmax_t *width */ } -static void boxRelayout(uiWindowsControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiWindowsSizing *d) +static void boxRelayout(uiWindowsControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height) { /* TODO uibox *b = uiBox(c); @@ -228,13 +228,13 @@ static void boxContainerUpdateState(uiControl *c) void uiBoxAppend(uiBox *b, uiControl *c, int stretchy) { struct child *bc; +/* TODO uintptr_t zorder; int dozorder; uintmax_t i; // start the zorder with the *CURRENT* first child // this is in case we're adding a new first child -/* TODO dozorder = 0; if (b->controls->len != 0) { dozorder = 1; @@ -246,7 +246,7 @@ void uiBoxAppend(uiBox *b, uiControl *c, int stretchy) bc = newChild(c, uiControl(b), b->hwnd); ctrlSetStretchy(bc, stretchy); ptrArrayAppend(b->controls, bc); - uiControlQueueResize(uiControl(b)); + uiWindowsControlQueueRelayout(uiWindowsControl(b)); /* TODO // and now update the zorder for all controls @@ -265,7 +265,7 @@ void uiBoxDelete(uiBox *b, uintmax_t index) bc = ptrArrayIndex(b->controls, struct child *, index); ptrArrayDelete(b->controls, index); childRemove(bc); - uiControlQueueResize(uiControl(b)); + uiWindowsControlQueueRelayout(uiWindowsControl(b)); } int uiBoxPadded(uiBox *b) @@ -276,7 +276,7 @@ int uiBoxPadded(uiBox *b) void uiBoxSetPadded(uiBox *b, int padded) { b->padded = padded; - uiControlQueueResize(uiControl(b)); + uiWindowsControlQueueRelayout(uiWindowsControl(b)); } static uiBox *finishNewBox(int vertical) @@ -291,7 +291,8 @@ static uiBox *finishNewBox(int vertical) b->controls = newPtrArray(); uiWindowsFinishNewControl(b, uiBox); - // TODO + uiControl(b)->ContainerUpdateState = boxContainerUpdateState; + uiWindowsControl(b)->Relayout = boxRelayout; return b; } diff --git a/redo/windows/button.c b/redo/windows/button.c index 4906294f..f3c0846c 100644 --- a/redo/windows/button.c +++ b/redo/windows/button.c @@ -63,7 +63,7 @@ void uiButtonSetText(uiButton *b, const char *text) { uiWindowsUtilSetText(b->hwnd, text); // changing the text might necessitate a change in the button's size - uiControlQueueResize(uiControl(b)); + uiWindowsControlQueueRelayout(uiWindowsControl(b)); } void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *, void *), void *data) diff --git a/redo/windows/checkbox.c b/redo/windows/checkbox.c index bd7a1984..1009c914 100644 --- a/redo/windows/checkbox.c +++ b/redo/windows/checkbox.c @@ -60,7 +60,7 @@ void uiCheckboxSetText(uiCheckbox *c, const char *text) { uiWindowsUtilSetText(c->hwnd, text); // changing the text might necessitate a change in the checkbox's size - uiControlQueueResize(uiControl(c)); + uiWindowsControlQueueRelayout(uiWindowsControl(c)); } void uiCheckboxOnToggled(uiCheckbox *c, void (*f)(uiCheckbox *, void *), void *data) diff --git a/redo/windows/child.c b/redo/windows/child.c index 2d28e01b..1b6adb24 100644 --- a/redo/windows/child.c +++ b/redo/windows/child.c @@ -107,6 +107,11 @@ void childRelayout(struct child *c, intmax_t x, intmax_t y, intmax_t width, intm (*(wc->Relayout))(wc, x, y, width, height); } +void childQueueRelayout(struct child *c) +{ + uiWindowsControlQueueRelayout(uiWindowsControl(c->c)); +} + void childUpdateState(struct child *c) { controlUpdateState(c->c); @@ -125,7 +130,7 @@ int childMargined(struct child *c) void childSetMargined(struct child *c, int margined) { c->margined = margined; - uiControlQueueResize(c->c); + uiWindowsControlQueueRelayout(uiWindowsControl(c->c)); } int childFlag(struct child *c) diff --git a/redo/windows/entry.c b/redo/windows/entry.c index 01de551c..184efce3 100644 --- a/redo/windows/entry.c +++ b/redo/windows/entry.c @@ -92,7 +92,7 @@ uiEntry *uiNewEntry(void) TRUE); uiWindowsRegisterWM_COMMANDHandler(e->hwnd, onWM_COMMAND, uiControl(e)); - uiEntrySetOnChanged(e, defaultOnChanged, NULL); + uiEntryOnChanged(e, defaultOnChanged, NULL); uiWindowsFinishNewControl(e, uiEntry); diff --git a/redo/windows/group.c b/redo/windows/group.c index ab96a2ef..4299c95b 100644 --- a/redo/windows/group.c +++ b/redo/windows/group.c @@ -61,7 +61,7 @@ static void groupRelayout(uiWindowsControl *c, intmax_t x, intmax_t y, intmax_t if (g->child == NULL) return; - d = uiWindowsGetSizing(g->hwnd); + d = uiWindowsNewSizing(g->hwnd); if (g->margined) { x += uiWindowsDlgUnitsToX(groupXMargin, d->BaseX); y += uiWindowsDlgUnitsToY(groupYMarginTop, d->BaseY); @@ -94,7 +94,7 @@ void uiGroupSetTitle(uiGroup *g, const char *text) { uiWindowsUtilSetText(g->hwnd, text); // changing the text might necessitate a change in the groupbox's size - uiControlQueueResize(uiControl(g)); + uiWindowsControlQueueRelayout(uiWindowsControl(g)); } void uiGroupSetChild(uiGroup *g, uiControl *child) @@ -103,7 +103,7 @@ void uiGroupSetChild(uiGroup *g, uiControl *child) childRemove(g->child); g->child = newChild(child, uiControl(g), g->hwnd); if (g->child != NULL) - uiControlQueueResize(g->child); + uiWindowsControlQueueRelayout(uiWindowsControl(g)); } int uiGroupMargined(uiGroup *g) @@ -114,7 +114,7 @@ int uiGroupMargined(uiGroup *g) void uiGroupSetMargined(uiGroup *g, int margined) { g->margined = margined; - uiControlQueueResize(uiControl(g)); + uiWindowsControlQueueRelayout(uiWindowsControl(g)); } uiGroup *uiNewGroup(const char *text) diff --git a/redo/windows/label.c b/redo/windows/label.c index f80c207f..0bdff1bb 100644 --- a/redo/windows/label.c +++ b/redo/windows/label.c @@ -31,7 +31,7 @@ void uiLabelSetText(uiLabel *l, const char *text) { uiWindowsUtilSetText(l->hwnd, text); // changing the text might necessitate a change in the label's size - uiControlQueueResize(uiControl(l)); + uiWindowsControlQueueRelayout(uiWindowsControl(l)); } uiLabel *uiNewLabel(const char *text) diff --git a/redo/windows/menu.c b/redo/windows/menu.c index 32f820ba..bf1f8d0d 100644 --- a/redo/windows/menu.c +++ b/redo/windows/menu.c @@ -283,7 +283,6 @@ void runMenuEvent(WORD id, uiWindow *w) uiMenu *m; uiMenuItem *item; uintmax_t i, j; - uiMenuItem *umi; // this isn't optimal, but it works, and it should be just fine for most cases for (i = 0; i < len; i++) { diff --git a/redo/windows/spinbox.c b/redo/windows/spinbox.c index 245675e8..7f764ade 100644 --- a/redo/windows/spinbox.c +++ b/redo/windows/spinbox.c @@ -126,7 +126,7 @@ static void recreateUpDown(uiSpinbox *s) */ } -static void spinboxRelayout(uiControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height) +static void spinboxRelayout(uiWindowsControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height) { /* TODO uiSpinbox *s = uiSpinbox(c); @@ -210,6 +210,7 @@ uiSpinbox *uiNewSpinbox(intmax_t min, intmax_t max) s->inhibitChanged = FALSE; uiWindowsFinishNewControl(s, uiSpinbox); + uiWindowsControl(s)->Relayout = spinboxRelayout; return s; } diff --git a/redo/windows/tab.c b/redo/windows/tab.c index 6f398900..7e7761c9 100644 --- a/redo/windows/tab.c +++ b/redo/windows/tab.c @@ -38,7 +38,7 @@ static void showHidePage(uiTab *t, LRESULT which, int hide) else { ShowWindow(childTabPage(page), SW_SHOW); // we only resize the current page, so we have to do this here - uiControlQueueResize(page); + childQueueRelayout(page); } } @@ -62,7 +62,7 @@ static void onDestroy(uiTab *t) struct child *page; while (t->pages->len != 0) { - page = ptrArrayIndex(t->pages, uiControl *, 0); + page = ptrArrayIndex(t->pages, struct child *, 0); ptrArrayDelete(t->pages, 0); childDestroy(page); } @@ -83,8 +83,8 @@ static void minimumSize(uiWindowsControl *c, uiWindowsSizing *d, intmax_t *width maxwid = 0; maxht = 0; for (i = 0; i < t->pages->len; i++) { - page = ptrArrayIndex(t->pages, uiControl *, i); - uiControlPreferredSize(page, d, &pagewid, &pageht); + page = ptrArrayIndex(t->pages, struct child *, i); + childMinimumSize(page, d, &pagewid, &pageht); if (maxwid < pagewid) maxwid = pagewid; if (maxht < pageht) @@ -102,7 +102,7 @@ static void minimumSize(uiWindowsControl *c, uiWindowsSizing *d, intmax_t *width */ } -static void tabRelayout(uiControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height) +static void tabRelayout(uiWindowsControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height) { /* TODO uiTab *t = uiTab(c); @@ -115,7 +115,7 @@ static void tabRelayout(uiControl *c, intmax_t x, intmax_t y, intmax_t width, in n = curpage(t); if (n == (LRESULT) (-1)) return; - page = ptrArrayIndex(t->pages, uiControl *, n); + page = ptrArrayIndex(t->pages, struct child *, n); dchild = uiControlSizing(uiControl(t)); @@ -142,7 +142,7 @@ static void tabContainerUpdateState(uiControl *c) uintmax_t i; for (i = 0; i < t->pages->len; i++) { - page = ptrArrayIndex(t->pages, uiControl *, i); + page = ptrArrayIndex(t->pages, struct child *, i); childUpdateState(page); } } @@ -194,7 +194,7 @@ void uiTabDelete(uiTab *t, uintmax_t n) logLastError("error deleting uiTab tab in tabDelete()"); // now delete the page itself - page = ptrArrayIndex(t->pages, uiControl *, n); + page = ptrArrayIndex(t->pages, struct child *, n); ptrArrayDelete(t->pages, n); childRemove(page); } @@ -208,7 +208,7 @@ int uiTabMargined(uiTab *t, uintmax_t n) { struct child *page; - page = ptrArrayIndex(t->pages, uiControl *, n); + page = ptrArrayIndex(t->pages, struct child *, n); return childMargined(page); } @@ -216,7 +216,7 @@ void uiTabSetMargined(uiTab *t, uintmax_t n, int margined) { struct child *page; - page = ptrArrayIndex(t->pages, uiControl *, n); + page = ptrArrayIndex(t->pages, struct child *, n); childSetMargined(page, margined); } diff --git a/redo/windows/uipriv_windows.h b/redo/windows/uipriv_windows.h index 025cbc51..ebbef57e 100644 --- a/redo/windows/uipriv_windows.h +++ b/redo/windows/uipriv_windows.h @@ -103,6 +103,7 @@ extern void childDestroy(struct child *c); extern HWND childHWND(struct child *c); extern void childMinimumSize(struct child *c, uiWindowsSizing *d, intmax_t *width, intmax_t *height); extern void childRelayout(struct child *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height); +extern void childQueueRelayout(struct child *c); extern void childUpdateState(struct child *c); extern HWND childTabPage(struct child *c); extern int childMargined(struct child *c); diff --git a/redo/windows/window.c b/redo/windows/window.c index d8f354db..a828bb90 100644 --- a/redo/windows/window.c +++ b/redo/windows/window.c @@ -51,7 +51,7 @@ static LRESULT CALLBACK windowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARA if ((wp->flags & SWP_NOSIZE) != 0) break; if (w->child != NULL) - uiControlQueueResize(uiControl(w)); + childQueueRelayout(w->child); return 0; case WM_PRINTCLIENT: // we do no special painting; just erase the background @@ -115,7 +115,7 @@ static void windowCommitShow(uiControl *c) } w->shownOnce = TRUE; // make sure the child is the correct size - uiControlQueueResize(uiControl(w)); + uiWindowsControlQueueRelayout(uiWindowsControl(w)); ShowWindow(w->hwnd, nCmdShow); if (UpdateWindow(w->hwnd) == 0) logLastError("error calling UpdateWindow() after showing uiWindow for the first time in windowShow()"); @@ -126,7 +126,12 @@ static void windowContainerUpdateState(uiControl *c) uiWindow *w = uiWindow(c); if (w->child != NULL) - childContainerUpdateState(w->child); + childUpdateState(w->child); +} + +static void minimumSize(uiWindowsControl *c, uiWindowsSizing *d, intmax_t *width, intmax_t *height) +{ + // TODO } char *uiWindowTitle(uiWindow *w) @@ -152,7 +157,7 @@ void uiWindowSetChild(uiWindow *w, uiControl *child) childRemove(w->child); w->child = newChild(child, uiControl(w), w->hwnd); if (w->child != NULL) - uiControlQueueResize(w->child); + childQueueRelayout(w->child); } int uiWindowMargined(uiWindow *w) @@ -163,7 +168,7 @@ int uiWindowMargined(uiWindow *w) void uiWindowSetMargined(uiWindow *w, int margined) { w->margined = margined; - uiControlQueueResize(uiControl(w)); + uiWindowsControlQueueRelayout(uiWindowsControl(w)); } // from https://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing @@ -254,7 +259,7 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar) // and use the proper size setClientSize(w, width, height, hasMenubarBOOL, style, exstyle); - uiWindowSetOnClosing(w, defaultOnClosing, NULL); + uiWindowOnClosing(w, defaultOnClosing, NULL); uiWindowsFinishNewControl(w, uiWindow); uiControl(w)->CommitShow = windowCommitShow;