diff options
| author | Pietro Gagliardi <[email protected]> | 2015-04-16 14:50:05 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2015-04-16 14:50:05 -0400 |
| commit | e2ffe78e8708b3c8514c2804cbe77fdf3e63938c (patch) | |
| tree | 3505f1c82309c7e5b47c93c77068ff096acc51d7 /new/darwin/window.m | |
| parent | 0660104659c17852035233617ce9885339c93d7c (diff) | |
Migrated darwin/tab.m and darwin/window.m. Now to test.
Diffstat (limited to 'new/darwin/window.m')
| -rw-r--r-- | new/darwin/window.m | 111 |
1 files changed, 64 insertions, 47 deletions
diff --git a/new/darwin/window.m b/new/darwin/window.m index b0cab11..af644c0 100644 --- a/new/darwin/window.m +++ b/new/darwin/window.m @@ -9,7 +9,7 @@ @property uiParent *content; @property int (*onClosing)(uiWindow *, void *); @property void *onClosingData; -@property uiWindow *uiw; +@property struct window *uiw; @end @implementation uiWindowDelegate @@ -42,7 +42,8 @@ uiLogObjCClassAllocations @end -struct uiWindow { +struct window { + uiWindow w; uiWindowDelegate *d; int margined; }; @@ -52,90 +53,60 @@ static int defaultOnClosing(uiWindow *w, void *data) return 1; } -uiWindow *uiNewWindow(char *title, int width, int height) -{ - uiWindowDelegate *d; - - d = [uiWindowDelegate new]; - - d.w = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, (CGFloat) width, (CGFloat) height) - styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask) - backing:NSBackingStoreBuffered - defer:YES]; - [d.w setTitle:toNSString(title)]; - - // we do not want substitutions - // text fields, labels, etc. take their smart quotes and other autocorrect settings from their parent window, which provides a shared "field editor" - // so we have to turn them off here - // thanks akempgen in irc.freenode.net/#macdev - // for some reason, this selector returns NSText but is documented to return NSTextView... - // NOTE: if you disagree with me about disabling substitutions, start a github issue with why and I'll be happy to consider it - disableAutocorrect((NSTextView *) [d.w fieldEditor:YES forObject:nil]); +#define D (((struct window *) w)->d) - // this is what will destroy the window on close - [d.w setReleasedWhenClosed:YES]; - - d.content = uiNewParent(0); - [d.w setContentView:((NSView *) uiParentHandle(d.content))]; - - d.onClosing = defaultOnClosing; - [d.w setDelegate:d]; - - d.uiw = uiNew(uiWindow); - d.uiw->d = d; - return d.uiw; -} - -#define D w->d - -void uiWindowDestroy(uiWindow *w) +static void windowDestroy(uiWindow *w) { [D.w close]; } -uintptr_t uiWindowHandle(uiWindow *w) +static uintptr_t windowHandle(uiWindow *w) { return (uintptr_t) (D.w); } -char *uiWindowTitle(uiWindow *w) +static char *windowTitle(uiWindow *w) { return uiDarwinNSStringToText([D.w title]); } -void uiWindowSetTitle(uiWindow *w, const char *title) +static void windowSetTitle(uiWindow *w, const char *title) { [D.w setTitle:toNSString(title)]; } -void uiWindowShow(uiWindow *w) +static void windowShow(uiWindow *w) { [D.w makeKeyAndOrderFront:D.w]; } -void uiWindowHide(uiWindow *w) +static void windowHide(uiWindow *w) { [D.w orderOut:D.w]; } -void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data) +static void windowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data) { D.onClosing = f; D.onClosingData = data; } -void uiWindowSetChild(uiWindow *w, uiControl *c) +static void windowSetChild(uiWindow *w, uiControl *c) { uiParentSetChild(D.content, c); } -int uiWindowMargined(uiWindow *w) +static int windowMargined(uiWindow *ww) { + struct window *w = (struct window *) ww; + return w->margined; } -void uiWindowSetMargined(uiWindow *w, int margined) +static void windowSetMargined(uiWindow *ww, int margined) { + struct window *w = (struct window *) ww; + w->margined = margined; if (w->margined) uiParentSetMargins(D.content, macXMargin, macYMargin, macXMargin, macYMargin); @@ -143,3 +114,49 @@ void uiWindowSetMargined(uiWindow *w, int margined) uiParentSetMargins(D.content, 0, 0, 0, 0); uiParentUpdate(D.content); } + +uiWindow *uiNewWindow(const char *title, int width, int height) +{ + uiWindowDelegate *d; + + d = [uiWindowDelegate new]; + + d.w = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, (CGFloat) width, (CGFloat) height) + styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask) + backing:NSBackingStoreBuffered + defer:YES]; + [d.w setTitle:toNSString(title)]; + + // we do not want substitutions + // text fields, labels, etc. take their smart quotes and other autocorrect settings from their parent window, which provides a shared "field editor" + // so we have to turn them off here + // thanks akempgen in irc.freenode.net/#macdev + // for some reason, this selector returns NSText but is documented to return NSTextView... + // NOTE: if you disagree with me about disabling substitutions, start a github issue with why and I'll be happy to consider it + disableAutocorrect((NSTextView *) [d.w fieldEditor:YES forObject:nil]); + + // this is what will destroy the window on close + [d.w setReleasedWhenClosed:YES]; + + d.content = uiNewParent(0); + [d.w setContentView:((NSView *) uiParentHandle(d.content))]; + + d.onClosing = defaultOnClosing; + [d.w setDelegate:d]; + + d.uiw = uiNew(struct window); + d.uiw->d = d; + + uiWindow(d.uiw)->Destroy = windowDestroy; + uiWindow(d.uiw)->Handle = windowHandle; + uiWindow(d.uiw)->Title = windowTitle; + uiWindow(d.uiw)->SetTitle = windowSetTitle; + uiWindow(d.uiw)->Show = windowShow; + uiWindow(d.uiw)->Hide = windowHide; + uiWindow(d.uiw)->OnClosing = windowSetOnClosing; + uiWindow(d.uiw)->SetChild = windowSetChild; + uiWindow(d.uiw)->Margined = windowMargined; + uiWindow(d.uiw)->SetMargined = windowSetMargined; + + return d.uiw; +} |
