From ba6f2865df8edca756aab11721f41c8e0f912fa8 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 22 May 2020 22:43:33 -0400 Subject: [PATCH] Started reintegrating uiWindow on macOS. I didn't think the implData variable naming through... Also made uiWindow a mere typedef to uiControl; I'll need to copy the handle logic from Windows to make this robust, or something to that effect... --- {zOLD_darwin => darwin}/window.m | 82 +++++++++++++++++++++++++++----- doc/window.md | 4 +- ui.h | 2 +- 3 files changed, 74 insertions(+), 14 deletions(-) rename {zOLD_darwin => darwin}/window.m (87%) diff --git a/zOLD_darwin/window.m b/darwin/window.m similarity index 87% rename from zOLD_darwin/window.m rename to darwin/window.m index 1a048207..fe9d49e9 100644 --- a/zOLD_darwin/window.m +++ b/darwin/window.m @@ -3,9 +3,10 @@ #define defaultStyleMask (NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask) -struct uiWindow { - uiDarwinControl c; +struct windowImplData { NSWindow *window; + char *title; +#if 0 uiControl *child; int margined; int (*onClosing)(uiWindow *, void *); @@ -16,8 +17,11 @@ struct uiWindow { BOOL suppressSizeChanged; int fullscreen; int borderless; +#endif }; +#if 0 + @implementation uiprivNSWindow - (void)uiprivDoMove:(NSEvent *)initialEvent @@ -367,24 +371,25 @@ static void defaultOnPositionContentSizeChanged(uiWindow *w, void *data) // do nothing } -uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar) +#endif + +static bool windowInit(uiControl *c, void *implData, void *initData) { - uiWindow *w; + windowImplData *w = (windowImplData *) implData; - uiprivFinalizeMenus(); - - uiDarwinNewControl(uiWindow, w); - - w->window = [[uiprivNSWindow alloc] initWithContentRect:NSMakeRect(0, 0, (CGFloat) width, (CGFloat) height) + w->window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, TODO, TODO) styleMask:defaultStyleMask backing:NSBackingStoreBuffered defer:YES]; - [w->window setTitle:uiprivToNSString(title)]; + + w->title = NULL; + [w->window setTitle:@""]; // do NOT release when closed // we manually do this in uiWindowDestroy() above [w->window setReleasedWhenClosed:NO]; +#if 0 if (windowDelegate == nil) { windowDelegate = [[windowDelegateClass new] autorelease]; [uiprivDelegates addObject:windowDelegate]; @@ -392,10 +397,63 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar) [windowDelegate registerWindow:w]; uiWindowOnClosing(w, defaultOnClosing, NULL); uiWindowOnContentSizeChanged(w, defaultOnPositionContentSizeChanged, NULL); +#endif - return w; + return true; } +static void windowFree(uiControl *c, void *implData) +{ +} + +static void windowParentChanging(uiControl *c, void *implData, uiControl *oldParent) +{ +} + +static void windowParentChanged(uiControl *c, void *implData, uiControl *newParent) +{ +} + +static const uiControlVtable windowVtable = { + .Size = sizeof (uiControlVtable), + .Init = windowInit, + .Free = windowFree, + .ParentChanging = windowParentChanging, + .ParentChanged = windowParentChanged, +}; + +static const uiControlOSVtable windowOSVtable = { + .Size = sizeof (uiControlOSVtable), +}; + +static uint32_t windowType = 0; + +uint32_t uiWindowType(void) +{ + if (windowType == 0) + windowType = uiRegisterControlType("uiWindow", &windowVtable, &windowOSVtable, sizeof (windowImplData)); + return windowType; +} + +uiWindow *uiNewWindow(void) +{ + return (uiWindow *) uiNewControl(uiWindowType(), NULL); +} + +const char *uiWindowTitle(uiWindow *w) +{ + if (w->title == NULL) + return ""; + return w->title; +} + +void uiWindowSetTitle(uiWindow *w, const char *title) +{ + // TODO +} + +#if 0 + // utility function for menus uiWindow *uiprivWindowFromNSWindow(NSWindow *w) { @@ -405,3 +463,5 @@ uiWindow *uiprivWindowFromNSWindow(NSWindow *w) return NULL; return [windowDelegate lookupWindow:w]; } + +#endif diff --git a/doc/window.md b/doc/window.md index d336abc9..96920397 100644 --- a/doc/window.md +++ b/doc/window.md @@ -11,12 +11,12 @@ TODO ### `uiWindow` ```c -typedef struct uiWindow uiWindow; +typedef uiControl uiWindow; uiprivExtern uint32_t uiWindowType(void); #define uiWindow(obj) ((uiWindow *) uiCheckControlType((obj), uiWindowType())) ``` -`uiWindow` is an opaque `uiControl` type that represents a window. +`uiWindow` is a `uiControl` that represents a window. Windows are the highest level of a control hierarchy that is visibile on screen. All controls that are current visible are contained within a `uiWindow`, and it is the size and position of the window that ultimately decides their size and position (though a control's minimum size may contribute to this). Windows also have titles, which are used to identify the window to the user. diff --git a/ui.h b/ui.h index 95a3d501..566c98a8 100644 --- a/ui.h +++ b/ui.h @@ -66,7 +66,7 @@ uiprivExtern void uiControlFree(uiControl *c); uiprivExtern void uiControlSetParent(uiControl *c, uiControl *parent); uiprivExtern void *uiControlImplData(uiControl *c); -typedef struct uiWindow uiWindow; +typedef uiControl uiWindow; uiprivExtern uint32_t uiWindowType(void); #define uiWindow(obj) ((uiWindow *) uiCheckControlType((obj), uiWindowType()))