Added tests for the uiWindow methods being called after init/on the right thread. To actually implement those, wrote OS-independent wrappers for the uiWindow functions. This will likely become a pattern throughout libui...

This commit is contained in:
Pietro Gagliardi 2020-05-25 22:35:25 -04:00
parent 0dd4bec2af
commit de3598df80
5 changed files with 52 additions and 6 deletions

View File

@ -6,6 +6,7 @@ libui_sources += [
'common/errors.c',
'common/main.c',
'common/utf8.c',
'common/window.c',
'common/third_party/utf.c',
]

View File

@ -81,6 +81,12 @@ extern uiControlOSVtable *uiprivControlOSVtable(uiControl *c);
extern char *uiprivSanitizeUTF8(const char *str);
extern void uiprivFreeUTF8(char *sanitized);
// window.c
extern uint32_t uiprivSysWindowType(void);
extern uiWindow *uiprivSysNewWindow(void);
extern const char *uiprivSysWindowTitle(uiWindow *w);
extern void uiprivSysWindowSetTitle(uiWindow *w, const char *title);
#ifdef __cplusplus
}
#endif

33
common/window.c Normal file
View File

@ -0,0 +1,33 @@
// 25 may 2020
#include "uipriv.h"
uint32_t uiWindowType(void)
{
if (!uiprivCheckInitializedAndThread())
return 0;
return uiprivSysWindowType();
}
uiWindow *uiNewWindow(void)
{
if (!uiprivCheckInitializedAndThread())
return NULL;
return uiprivSysNewWindow();
}
const char *uiWindowTitle(uiWindow *w)
{
if (!uiprivCheckInitializedAndThread())
return NULL;
// TODO check for w == NULL?
return uiprivSysWindowTitle(w);
}
void uiWindowSetTitle(uiWindow *w, const char *title)
{
if (!uiprivCheckInitializedAndThread())
return;
// TODO check for w == NULL?
// TODO other errors
uiprivSysWindowSetTitle(w, title);
}

View File

@ -21,6 +21,7 @@ struct windowImplData {
};
#if 0
// skip {
@implementation uiprivNSWindow
@ -152,8 +153,6 @@ static void uiWindowDestroy(uiControl *c)
uiFreeControl(uiControl(w));
}
uiDarwinControlDefaultHandle(uiWindow, window)
uiControl *uiWindowParent(uiControl *c)
{
return NULL;
@ -361,6 +360,7 @@ static void defaultOnPositionContentSizeChanged(uiWindow *w, void *data)
// do nothing
}
// } skip
#endif
static bool windowInit(uiControl *c, void *implData, void *initData)
@ -437,19 +437,19 @@ static const uiControlOSVtable windowOSVtable = {
static uint32_t windowType = 0;
uint32_t uiWindowType(void)
uint32_t uiprivSysWindowType(void)
{
if (windowType == 0)
windowType = uiRegisterControlType("uiWindow", &windowVtable, &windowOSVtable, sizeof (struct windowImplData));
return windowType;
}
uiWindow *uiNewWindow(void)
uiWindow *uiprivSysNewWindow(void)
{
return (uiWindow *) uiNewControl(uiWindowType(), NULL);
}
const char *uiWindowTitle(uiWindow *w)
const char *uiprivSysWindowTitle(uiWindow *w)
{
struct windowImplData *wi = (struct windowImplData *) uiControlImplData(uiControl(w));
@ -459,7 +459,7 @@ const char *uiWindowTitle(uiWindow *w)
return wi->title;
}
void uiWindowSetTitle(uiWindow *w, const char *title)
void uiprivSysWindowSetTitle(uiWindow *w, const char *title)
{
struct windowImplData *wi = (struct windowImplData *) uiControlImplData(uiControl(w));

View File

@ -15,3 +15,9 @@ allcallsCase(uiNewControl, 0, NULL)
allcallsCase(uiControlFree, NULL)
allcallsCase(uiControlSetParent, NULL, NULL)
allcallsCase(uiControlImplData, NULL)
allcallsCase(uiWindowType, /* no arguments */)
allcallsCase(uiNewWindow, /* no arguments */)
allcallsCase(uiWindowTitle, NULL)
allcallsCase(uiWindowSetTitle, NULL, NULL)