From 69dbafe6f20e8d404848087d70da4c0dc96fecf0 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 26 Jul 2022 00:18:37 -0400 Subject: [PATCH] Oops forgot to commit this before midnight: started work on uiWindow children. --- common/uipriv.h | 2 ++ common/window.c | 22 ++++++++++++++++++++++ darwin/window.m | 37 +++++++++++++++++++++++++++++++++++-- doc/window.md | 24 +++++++++++++++++++++++- ui.h | 2 ++ 5 files changed, 84 insertions(+), 3 deletions(-) diff --git a/common/uipriv.h b/common/uipriv.h index 4b3abde4..4f815848 100644 --- a/common/uipriv.h +++ b/common/uipriv.h @@ -86,6 +86,8 @@ extern uint32_t uiprivSysWindowType(void); extern uiWindow *uiprivSysNewWindow(void); extern const char *uiprivSysWindowTitle(uiWindow *w); extern void uiprivSysWindowSetTitle(uiWindow *w, const char *title); +extern uiControl *uiprivSysWindowChild(uiWindow *w); +extern void uiprivSysWindowSetChild(uiWindow *w, uiControl *child); #ifdef __cplusplus } diff --git a/common/window.c b/common/window.c index 1149e0cb..016c1853 100644 --- a/common/window.c +++ b/common/window.c @@ -40,3 +40,25 @@ void uiWindowSetTitle(uiWindow *w, const char *title) } uiprivSysWindowSetTitle(w, title); } + +uiControl *uiWindowChild(uiWindow *w) +{ + if (!uiprivCheckInitializedAndThread()) + return NULL; + if (w == NULL) { + uiprivProgrammerErrorNullPointer("uiWindow", uiprivFunc); + return NULL; + } + return uiprivSysWindowChild(w); +} + +void uiWindowSetChild(uiWindow *w, uiControl *child) +{ + if (!uiprivCheckInitializedAndThread()) + return; + if (w == NULL) { + uiprivProgrammerErrorNullPointer("uiWindow", uiprivFunc); + return; + } + uiprivSysWindowSetChild(w, child); +} diff --git a/darwin/window.m b/darwin/window.m index 7e9ed548..21b365f7 100644 --- a/darwin/window.m +++ b/darwin/window.m @@ -6,8 +6,8 @@ struct windowImplData { NSWindow *window; char *title; -#if 0 uiControl *child; +#if 0 int margined; int (*onClosing)(uiWindow *, void *); void *onClosingData; @@ -377,7 +377,7 @@ static bool windowInit(uiControl *c, void *implData, void *initData) [wi->window setTitle:@""]; // do NOT release when closed - // we manually do this in uiWindowDestroy() above + // we manually do this in Free() below [wi->window setReleasedWhenClosed:NO]; #if 0 @@ -393,10 +393,25 @@ static bool windowInit(uiControl *c, void *implData, void *initData) return true; } +static void connectChild(struct windowImplData *wi) +{ + // TODO +} + +static void disconnectChild(struct winodwImplData *wi) +{ + // TODO +} + static void windowFree(uiControl *c, void *implData) { struct windowImplData *wi = (struct windowImplData *) implData; + if (wi->child != NULL) { + disconnectChild(wi); + uiControlFree(wi->child); + wi->child = NULL; + } if (wi->title != NULL) { uiprivFreeUTF8(wi->title); wi->title = NULL; @@ -469,6 +484,24 @@ void uiprivSysWindowSetTitle(uiWindow *w, const char *title) [wi->window setTitle:[NSString stringWithUTF8String:wi->title]]; } +uiControl *uiprivSysWindowChild(uiWindow *w) +{ + struct windowImplData *wi = (struct windowImplData *) uiControlImplData(uiControl(w)); + + return wi->child; +} + +void uiprivSysWindowSetChild(uiWindow *w, uiControl *child) +{ + struct windowImplData *wi = (struct windowImplData *) uiControlImplData(uiControl(w)); + + if (wi->child != NULL) + disconnectChild(wi); + wi->child = child; + if (wi->child != NULL) + connectChild(wi); +} + #if 0 // utility function for menus diff --git a/doc/window.md b/doc/window.md index f6dba0dc..4bdf63f5 100644 --- a/doc/window.md +++ b/doc/window.md @@ -56,4 +56,26 @@ void uiWindowSetTitle(uiWindow *w, const char *title); It is a programmer error to pass `NULL` for `title`. If `title` is not valid UTF-8, `U+FFFD` characters will be used to sanitize the string. -It is a programmer error to pass `NULL` for `w`. \ No newline at end of file +It is a programmer error to pass `NULL` for `w`. + +### `uiWindowChild()` + +```c +uiprivExtern uiControl *uiWindowChild(uiWindow *w); +``` + +`uiWindowChild()` returns the current child of `w`, or `NULL` if there is none. + +It is a programmer error to pass `NULL` for `w`. + +### `uiWindowSetChild()` + +```c +uiprivExtern void uiWindowSetChild(uiWindow *w, uiControl *child); +``` + +`uiWindowSetChild()` sets the child control of `w` to `child`. If `child` is `NULL`, `w` will have its child removed, and the window will be empty. If `w` already has a child, then the child is seamlessly swapped out, and the current child will be free to add to another parent. + +A window can only have one child control at a time, and that child will be given the entire area of the window. Multiple controls within a window are handled using the other container control types. + +It is a programmer error to pass `NULL` for `w`. It is also a programmer error to pass a control for `child` that is already the child of some other control. diff --git a/ui.h b/ui.h index 866249b5..3db2e51c 100644 --- a/ui.h +++ b/ui.h @@ -74,6 +74,8 @@ uiprivExtern uint32_t uiWindowType(void); uiprivExtern uiWindow *uiNewWindow(void); uiprivExtern const char *uiWindowTitle(uiWindow *w); uiprivExtern void uiWindowSetTitle(uiWindow *w, const char *title); +uiprivExtern uiControl *uiWindowChild(uiWindow *w); +uiprivExtern void uiWindowSetChild(uiWindow *w, uiControl *child); #ifdef __cplusplus }