From e2ffe78e8708b3c8514c2804cbe77fdf3e63938c Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 16 Apr 2015 14:50:05 -0400 Subject: [PATCH] Migrated darwin/tab.m and darwin/window.m. Now to test. --- new/darwin/tab.m | 44 +++++++------- new/darwin/window.m | 141 +++++++++++++++++++++++++------------------- 2 files changed, 103 insertions(+), 82 deletions(-) diff --git a/new/darwin/tab.m b/new/darwin/tab.m index c36181e..98dd733 100644 --- a/new/darwin/tab.m +++ b/new/darwin/tab.m @@ -6,7 +6,7 @@ // - free child containers properly @interface uiNSTabView : NSTabView -@property uiControl *uiC; +@property uiTab *uiT; @end @implementation uiNSTabView @@ -14,7 +14,7 @@ - (void)viewDidMoveToSuperview { // TODO free all tabs explicitly - if (uiDarwinControlFreeWhenAppropriate(self.uiC, [self superview])) + if (uiDarwinControlFreeWhenAppropriate(uiControl(self.uiT), [self superview])) self.uiC = NULL; [super viewDidMoveToSuperview]; } @@ -34,23 +34,7 @@ static void preferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t * *height = (intmax_t) (s.height); } -uiControl *uiNewTab(void) -{ - uiControl *c; - uiNSTabView *t; - - c = uiDarwinNewControl([uiNSTabView class], NO, NO); - c->preferredSize = preferredSize; - t = (uiNSTabView *) uiControlHandle(c); - t.uiC = c; - - // also good for NSTabView (same selector and everything) - setStandardControlFont((NSControl *) t); - - return c; -} - -void uiTabAddPage(uiControl *c, const char *name, uiControl *child) +static void tabAddPage(uiTab *t, const char *name, uiControl *child) { uiNSTabView *tv; uiParent *content; @@ -62,6 +46,26 @@ void uiTabAddPage(uiControl *c, const char *name, uiControl *child) i = [[NSTabViewItem alloc] initWithIdentifier:nil]; [i setLabel:toNSString(name)]; [i setView:((NSView *) uiParentHandle(content))]; - tv = (uiNSTabView *) uiControlHandle(c); + tv = (uiNSTabView *) uiControlHandle(uiControl(t)); [tv addTabViewItem:i]; } + +uiTab *uiNewTab(void) +{ + uiTab *t; + uiNSTabView *tv; + + uiDarwinNewControl(uiControl(t), [uiNSTabView class], NO, NO); + tv = (uiNSTabView *) uiControlHandle(c); + + // also good for NSTabView (same selector and everything) + setStandardControlFont((NSControl *) tv); + + uiControl(t)->PreferredSize = preferredSize; + + uiTab(t)->AddPage = tabAddPage; + + tv.uiT = t; + + return tv.uiT; +} 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,7 +53,69 @@ static int defaultOnClosing(uiWindow *w, void *data) return 1; } -uiWindow *uiNewWindow(char *title, int width, int height) +#define D (((struct window *) w)->d) + +static void windowDestroy(uiWindow *w) +{ + [D.w close]; +} + +static uintptr_t windowHandle(uiWindow *w) +{ + return (uintptr_t) (D.w); +} + +static char *windowTitle(uiWindow *w) +{ + return uiDarwinNSStringToText([D.w title]); +} + +static void windowSetTitle(uiWindow *w, const char *title) +{ + [D.w setTitle:toNSString(title)]; +} + +static void windowShow(uiWindow *w) +{ + [D.w makeKeyAndOrderFront:D.w]; +} + +static void windowHide(uiWindow *w) +{ + [D.w orderOut:D.w]; +} + +static void windowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data) +{ + D.onClosing = f; + D.onClosingData = data; +} + +static void windowSetChild(uiWindow *w, uiControl *c) +{ + uiParentSetChild(D.content, c); +} + +static int windowMargined(uiWindow *ww) +{ + struct window *w = (struct window *) ww; + + return w->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); + else + uiParentSetMargins(D.content, 0, 0, 0, 0); + uiParentUpdate(D.content); +} + +uiWindow *uiNewWindow(const char *title, int width, int height) { uiWindowDelegate *d; @@ -81,65 +144,19 @@ uiWindow *uiNewWindow(char *title, int width, int height) d.onClosing = defaultOnClosing; [d.w setDelegate:d]; - d.uiw = uiNew(uiWindow); + 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; } - -#define D w->d - -void uiWindowDestroy(uiWindow *w) -{ - [D.w close]; -} - -uintptr_t uiWindowHandle(uiWindow *w) -{ - return (uintptr_t) (D.w); -} - -char *uiWindowTitle(uiWindow *w) -{ - return uiDarwinNSStringToText([D.w title]); -} - -void uiWindowSetTitle(uiWindow *w, const char *title) -{ - [D.w setTitle:toNSString(title)]; -} - -void uiWindowShow(uiWindow *w) -{ - [D.w makeKeyAndOrderFront:D.w]; -} - -void uiWindowHide(uiWindow *w) -{ - [D.w orderOut:D.w]; -} - -void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data) -{ - D.onClosing = f; - D.onClosingData = data; -} - -void uiWindowSetChild(uiWindow *w, uiControl *c) -{ - uiParentSetChild(D.content, c); -} - -int uiWindowMargined(uiWindow *w) -{ - return w->margined; -} - -void uiWindowSetMargined(uiWindow *w, int margined) -{ - w->margined = margined; - if (w->margined) - uiParentSetMargins(D.content, macXMargin, macYMargin, macXMargin, macYMargin); - else - uiParentSetMargins(D.content, 0, 0, 0, 0); - uiParentUpdate(D.content); -}