From ab0a9102b4e810f772208ad72c0cc69f61017f3c Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 22 May 2016 20:02:47 -0400 Subject: [PATCH] Added a user bug for calling SetParent() on a uiWindow. --- README.md | 1 + common/GNUfiles.mk | 3 ++- common/userbugs.c | 8 ++++++++ darwin/window.m | 14 ++++++++++---- ui.h | 3 ++- unix/window.c | 14 ++++++++++---- windows/window.cpp | 14 ++++++++++---- 7 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 common/userbugs.c diff --git a/README.md b/README.md index c1ccf600..5c7dc679 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ This README is being written.
* Added `uiNewNonWrappingMultilineEntry()`, which creates a uiMultilineEntry that scrolls horizontally instead of wrapping lines. (This is not documented as being changeable after the fact on Windows, hence it's a creation-time choice.) * uiAreas on Windows and some internal Direct2D areas now respond to `WM_PRINTCLIENT` properly, which should hopefully increase the quality of screenshots. * uiDateTimePicker on GTK+ works properly on RTL layouts and no longer disappears off the bottom of the screen if not enough room is available. It will also no longer be marked for localization of the time format (what the separator should be and whether to use 24-hour time), as that information is not provided by the locale system. :( + * Added `uiUserBugCannotSetParentOnToplevel()`, which should be used by implementations of toplevel controls in their `SetParent()` implementations. This will also be the beginning of consolidating common user bug messages into a single place, though this will be one of the only few exported user bug functions. ## Runtime Requirements diff --git a/common/GNUfiles.mk b/common/GNUfiles.mk index 58f901c6..465c76e8 100644 --- a/common/GNUfiles.mk +++ b/common/GNUfiles.mk @@ -5,7 +5,8 @@ CFILES += \ common/control.c \ common/debug.c \ common/matrix.c \ - common/shouldquit.c + common/shouldquit.c \ + common/userbugs.c HFILES += \ common/controlsigs.h \ diff --git a/common/userbugs.c b/common/userbugs.c new file mode 100644 index 00000000..0a85874c --- /dev/null +++ b/common/userbugs.c @@ -0,0 +1,8 @@ +// 22 may 2016 +#include "../ui.h" +#include "uipriv.h" + +void uiUserBugCannotSetParentOnToplevel(const char *type) +{ + userbug("You cannot make a %s a child of another uiControl,", type); +} diff --git a/darwin/window.m b/darwin/window.m index 1ece3f1e..58bd63ac 100644 --- a/darwin/window.m +++ b/darwin/window.m @@ -98,10 +98,16 @@ static void uiWindowDestroy(uiControl *c) } uiDarwinControlDefaultHandle(uiWindow, window) -// TODO? -uiDarwinControlDefaultParent(uiWindow, window) -uiDarwinControlDefaultSetParent(uiWindow, window) -// end TODO + +uiControl *uiWindowParent(uiControl *c) +{ + return NULL; +} + +void uiWindowSetParent(uiControl *c, uiControl *parent) +{ + uiUserBugCannotSetParentOnToplevel("uiWindow"); +} static int uiWindowToplevel(uiControl *c) { diff --git a/ui.h b/ui.h index 6febeaa4..ad847b57 100644 --- a/ui.h +++ b/ui.h @@ -38,7 +38,6 @@ _UI_EXTERN void uiFreeInitError(const char *err); _UI_EXTERN void uiMain(void); _UI_EXTERN void uiQuit(void); -// TODO write a test for this after adding multiline entries _UI_EXTERN void uiQueueMain(void (*f)(void *data), void *data); _UI_EXTERN void uiOnShouldQuit(int (*f)(void *data), void *data); @@ -84,6 +83,8 @@ _UI_EXTERN void uiFreeControl(uiControl *); _UI_EXTERN void uiControlVerifySetParent(uiControl *, uiControl *); _UI_EXTERN int uiControlEnabledToUser(uiControl *); +_UI_EXTERN void uiUserBugCannotSetParentOnToplevel(const char *type); + typedef struct uiWindow uiWindow; #define uiWindow(this) ((uiWindow *) (this)) _UI_EXTERN char *uiWindowTitle(uiWindow *w); diff --git a/unix/window.c b/unix/window.c index 1ebe1eb7..cca767e8 100644 --- a/unix/window.c +++ b/unix/window.c @@ -56,10 +56,16 @@ static void uiWindowDestroy(uiControl *c) } uiUnixControlDefaultHandle(uiWindow) -// TODO? -uiUnixControlDefaultParent(uiWindow) -uiUnixControlDefaultSetParent(uiWindow) -// end TODO + +uiControl *uiWindowParent(uiControl *c) +{ + return NULL; +} + +void uiWindowSetParent(uiControl *c, uiControl *parent) +{ + uiUserBugCannotSetParentOnToplevel("uiWindow"); +} static int uiWindowToplevel(uiControl *c) { diff --git a/windows/window.cpp b/windows/window.cpp index 42475b6d..0906619a 100644 --- a/windows/window.cpp +++ b/windows/window.cpp @@ -161,10 +161,16 @@ static void uiWindowDestroy(uiControl *c) } uiWindowsControlDefaultHandle(uiWindow) -// TODO? -uiWindowsControlDefaultParent(uiWindow) -uiWindowsControlDefaultSetParent(uiWindow) -// end TODO + +uiControl *uiWindowParent(uiControl *c) +{ + return NULL; +} + +void uiWindowSetParent(uiControl *c, uiControl *parent) +{ + uiUserBugCannotSetParentOnToplevel("uiWindow"); +} static int uiWindowToplevel(uiControl *c) {