From fd846cb01f9cd1512b277fa8ecb61ad397ce6c4a Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 2 Jun 2015 17:42:51 -0400 Subject: [PATCH] Installed the Z-order stuff into box.c; tab order is now correct. There are some loose ends, though. --- redo/box.c | 19 +++++++++++++++++++ redo/windows/control.c | 12 ++++++++++-- redo/windows/tab.c | 1 + 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/redo/box.c b/redo/box.c index 2838606f..5888383a 100644 --- a/redo/box.c +++ b/redo/box.c @@ -233,6 +233,18 @@ static void boxAppend(uiBox *ss, uiControl *c, int stretchy) { struct box *b = (struct box *) ss; struct boxControl *bc; + 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 + dozorder = 0; + if (b->controls->len != 0) { + dozorder = 1; + bc = ptrArrayIndex(b->controls, struct boxControl *, 0); + zorder = uiControlStartZOrder(bc->c); + } bc = uiNew(struct boxControl); bc->c = c; @@ -240,6 +252,13 @@ static void boxAppend(uiBox *ss, uiControl *c, int stretchy) uiControlSetParent(bc->c, uiControl(b)); ptrArrayAppend(b->controls, bc); uiControlQueueResize(uiControl(b)); + + // and now update the zorder for all controls + if (dozorder) + for (i = 0; i < b->controls->len; i++) { + bc = ptrArrayIndex(b->controls, struct boxControl *, i); + zorder = uiControlSetZOrder(bc->c, zorder); + } } static void boxDelete(uiBox *ss, uintmax_t index) diff --git a/redo/windows/control.c b/redo/windows/control.c index 2efb0e72..a2426b94 100644 --- a/redo/windows/control.c +++ b/redo/windows/control.c @@ -109,11 +109,19 @@ static void singleHWNDCommitDisable(uiControl *c) uintptr_t uiWindowsUtilStartZOrder(HWND hwnd) { HWND insertAfter; + DWORD le; // see http://stackoverflow.com/questions/30491418/ + // also, the window at the beginning of the z-order has no previous window, so GetWindow() returns NULL + // we have to differentiate these error states + SetLastError(0); insertAfter = GetWindow(hwnd, GW_HWNDPREV); - if (insertAfter == NULL) - logLastError("error getting insert after window in uiWindowsUtilStartZOrder()"); + if (insertAfter == NULL) { + le = GetLastError(); + SetLastError(le); // just in case + if (le != 0) + logLastError("error getting insert after window in uiWindowsUtilStartZOrder()"); + } return (uintptr_t) insertAfter; } diff --git a/redo/windows/tab.c b/redo/windows/tab.c index 0fea50ed..c08e0905 100644 --- a/redo/windows/tab.c +++ b/redo/windows/tab.c @@ -3,6 +3,7 @@ // TODO // - dialog doesn't respond to WM_PRINTCLIENT in Windows Classic +// - can't seem to tab away anymore struct tab { uiTab t;