From eaf8875b3f3e90b933fd8589617b6b3aeab2854e Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 2 Sep 2015 12:59:57 -0400 Subject: [PATCH] More boilerplate for uiTab parent changes: added a way to rearrange the Z-order of the current control. --- redo/ui_windows.h | 9 +++++++++ redo/windows/box.c | 8 ++++++++ redo/windows/control.c | 11 +++++++++++ redo/windows/group.c | 9 +++++++++ redo/windows/tab.c | 13 +++++++++++++ redo/windows/window.c | 9 +++++++++ 6 files changed, 59 insertions(+) diff --git a/redo/ui_windows.h b/redo/ui_windows.h index 0bc231f8..9c3b6d74 100644 --- a/redo/ui_windows.h +++ b/redo/ui_windows.h @@ -16,6 +16,7 @@ struct uiWindowsControl { void (*MinimumSize)(uiWindowsControl *, uiWindowsSizing *, intmax_t *, intmax_t *); void (*Relayout)(uiWindowsControl *, intmax_t, intmax_t, intmax_t, intmax_t); void (*AssignControlIDZOrder)(uiWindowsControl *, LONG_PTR *, HWND *); + void (*ArrangeChildrenControlIDsZOrder)(uiWindowsControl *); }; _UI_EXTERN uintmax_t uiWindowsControlType(void); #define uiWindowsControl(this) ((uiWindowsControl *) uiIsA((this), uiWindowsControlType(), 1)) @@ -59,6 +60,10 @@ _UI_EXTERN void uiWindowsControlQueueRelayout(uiWindowsControl *); uiWindowsEnsureAssignControlIDZOrder(type(c)->hwnd, *controlID, *insertAfter); \ (*controlID)++; \ *insertAfter = type(c)->hwnd; \ + } \ + static void _ ## type ## ArrangeChildrenControlIDsZOrder(uiWindowsControl *c) \ + { \ + /* do nothing */ \ } #define uiWindowsDefineControl(type, typefn) \ @@ -72,6 +77,7 @@ _UI_EXTERN void uiWindowsControlQueueRelayout(uiWindowsControl *); uiWindowsControl(variable)->MinimumSize = minimumSize; \ uiWindowsControl(variable)->Relayout = _ ## type ## Relayout; \ uiWindowsControl(variable)->AssignControlIDZOrder = _ ## type ## AssignControlIDZOrder; \ + uiWindowsControl(variable)->ArrangeChildrenControlIDsZOrder = _ ## type ## ArrangeChildrenControlIDsZOrder; \ uiWindowsFinishControl(uiControl(variable)); // This is a function used to set up a control. @@ -93,6 +99,9 @@ _UI_EXTERN void uiWindowsEnsureMoveWindow(HWND hwnd, intmax_t x, intmax_t y, int // libui handles errors for you. _UI_EXTERN void uiWindowsEnsureAssignControlIDZOrder(HWND hwnd, LONG_PTR controlID, HWND insertAfter); +// Use this to tell a control's parent that the control needs to rearrange its Z-order. +_UI_EXTERN void uiWindowsRearrangeControlIDsZOrder(uiControl *); + //////////////////////////////////////////// /////////////////// TODO /////////////////// //////////////////////////////////////////// diff --git a/redo/windows/box.c b/redo/windows/box.c index 011c2234..67e2abee 100644 --- a/redo/windows/box.c +++ b/redo/windows/box.c @@ -230,6 +230,13 @@ static void redoControlIDsZOrder(uiBox *b) } } +static void boxArrangeChildrenControlIDsZOrder(uiWindowsControl *c) +{ + uiBox *b = uiBox(c); + + redoControlIDsZOrder(b); +} + void uiBoxAppend(uiBox *b, uiControl *c, int stretchy) { struct child *bc; @@ -277,6 +284,7 @@ static uiBox *finishNewBox(int vertical) uiWindowsFinishNewControl(b, uiBox); uiControl(b)->ContainerUpdateState = boxContainerUpdateState; uiWindowsControl(b)->Relayout = boxRelayout; + uiWindowsControl(b)->ArrangeChildrenControlIDsZOrder = boxArrangeChildrenControlIDsZOrder; return b; } diff --git a/redo/windows/control.c b/redo/windows/control.c index 5ec6f074..54e7cd0d 100644 --- a/redo/windows/control.c +++ b/redo/windows/control.c @@ -74,3 +74,14 @@ void uiWindowsUtilSetText(HWND hwnd, const char *text) logLastError("error setting control text in uiWindowsControlSetText()"); uiFree(wtext); } + +void uiWindowsRearrangeControlIDsZOrder(uiControl *c) +{ + uiWindowsControl *wc; + + c = uiControlParent(c); + if (c == NULL) + return; + wc = uiWindowsControl(c); + (*(wc->ArrangeChildrenControlIDsZOrder))(wc); +} diff --git a/redo/windows/group.c b/redo/windows/group.c index 5df03022..e25dee2e 100644 --- a/redo/windows/group.c +++ b/redo/windows/group.c @@ -85,6 +85,14 @@ static void groupContainerUpdateState(uiControl *c) childUpdateState(g->child); } +static void groupArrangeChildrenControlIDsZOrder(uiWindowsControl *c) +{ + uiGroup *g = uiGroup(c); + + if (g->child != NULL) + childSetSoleControlID(g->child); +} + char *uiGroupTitle(uiGroup *g) { return uiWindowsUtilText(g->hwnd); @@ -155,6 +163,7 @@ uiGroup *uiNewGroup(const char *text) uiWindowsFinishNewControl(g, uiGroup); uiControl(g)->ContainerUpdateState = groupContainerUpdateState; uiWindowsControl(g)->Relayout = groupRelayout; + uiWindowsControl(g)->ArrangeChildrenControlIDsZOrder = groupArrangeChildrenControlIDsZOrder; return g; } diff --git a/redo/windows/tab.c b/redo/windows/tab.c index d6f483ef..0e517ccb 100644 --- a/redo/windows/tab.c +++ b/redo/windows/tab.c @@ -141,6 +141,18 @@ static void tabContainerUpdateState(uiControl *c) } } +static void tabArrangeChildrenControlIDsZOrder(uiWindowsControl *c) +{ + uiTab *t = uiTab(c); + struct child *page; + uintmax_t i; + + for (i = 0; i < t->pages->len; i++) { + page = ptrArrayIndex(t->pages, struct child *, i); + childSetSoleControlID(page); + } +} + void uiTabAppend(uiTab *t, const char *name, uiControl *child) { uiTabInsertAt(t, name, t->pages->len, child); @@ -234,6 +246,7 @@ uiTab *uiNewTab(void) uiWindowsFinishNewControl(t, uiTab); uiControl(t)->ContainerUpdateState = tabContainerUpdateState; uiWindowsControl(t)->Relayout = tabRelayout; + uiWindowsControl(t)->ArrangeChildrenControlIDsZOrder = tabArrangeChildrenControlIDsZOrder; return t; } diff --git a/redo/windows/window.c b/redo/windows/window.c index fedbb576..e2914afe 100644 --- a/redo/windows/window.c +++ b/redo/windows/window.c @@ -168,6 +168,14 @@ static void windowRelayout(uiWindowsControl *c, intmax_t x, intmax_t y, intmax_t uiWindowsFreeSizing(d); } +static void windowArrangeChildrenControlIDsZOrder(uiWindowsControl *c) +{ + uiWindow *w = uiWindow(c); + + if (w->child != NULL) + childSetSoleControlID(w->child); +} + char *uiWindowTitle(uiWindow *w) { return uiWindowsUtilText(w->hwnd); @@ -276,6 +284,7 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar) uiControl(w)->CommitShow = windowCommitShow; uiControl(w)->ContainerUpdateState = windowContainerUpdateState; uiWindowsControl(w)->Relayout = windowRelayout; + uiWindowsControl(w)->ArrangeChildrenControlIDsZOrder = windowArrangeChildrenControlIDsZOrder; return w; }