summaryrefslogtreecommitdiff
path: root/new/darwin
diff options
context:
space:
mode:
Diffstat (limited to 'new/darwin')
-rw-r--r--new/darwin/GNUmakeinc.mk19
-rw-r--r--new/darwin/alloc.m44
-rw-r--r--new/darwin/button.m86
-rw-r--r--new/darwin/checkbox.m107
-rw-r--r--new/darwin/entry.m73
-rw-r--r--new/darwin/init.m67
-rw-r--r--new/darwin/label.m59
-rw-r--r--new/darwin/main.m27
-rw-r--r--new/darwin/newcontrol.m231
-rw-r--r--new/darwin/parent.m118
-rw-r--r--new/darwin/tab.m73
-rw-r--r--new/darwin/text.m19
-rw-r--r--new/darwin/uipriv_darwin.h40
-rw-r--r--new/darwin/util.m20
-rw-r--r--new/darwin/window.m162
15 files changed, 0 insertions, 1145 deletions
diff --git a/new/darwin/GNUmakeinc.mk b/new/darwin/GNUmakeinc.mk
deleted file mode 100644
index 22ca1e3..0000000
--- a/new/darwin/GNUmakeinc.mk
+++ /dev/null
@@ -1,19 +0,0 @@
-OSMFILES = \
- alloc.m \
- button.m \
- checkbox.m \
- entry.m \
- init.m \
- label.m \
- main.m \
- newcontrol.m \
- parent.m \
- tab.m \
- text.m \
- util.m \
- window.m
-
-xCFLAGS += -mmacosx-version-min=10.7 -DMACOSX_DEPLOYMENT_TARGET=10.7
-xLDFLAGS += -mmacosx-version-min=10.7 -lobjc -framework Foundation -framework AppKit
-
-OUT = new
diff --git a/new/darwin/alloc.m b/new/darwin/alloc.m
deleted file mode 100644
index 8f539af..0000000
--- a/new/darwin/alloc.m
+++ /dev/null
@@ -1,44 +0,0 @@
-// 4 december 2014
-#import <stdio.h>
-#import "uipriv_darwin.h"
-
-void *uiAlloc(size_t size, const char *type)
-{
- void *out;
-
- out = malloc(size);
- if (out == NULL) {
- fprintf(stderr, "memory exhausted in uiAlloc() allocating %s\n", type);
- abort();
- }
- memset(out, 0, size);
- if (options.debugLogAllocations)
- fprintf(stderr, "%p alloc %s\n", out, type);
- return out;
-}
-
-void *uiRealloc(void *p, size_t size, const char *type)
-{
- void *out;
-
- if (p == NULL)
- return uiAlloc(size, type);
- out = realloc(p, size);
- if (out == NULL) {
- fprintf(stderr, "memory exhausted in uiRealloc() reallocating %s\n", type);
- abort();
- }
- // TODO zero the extra memory
- if (options.debugLogAllocations)
- fprintf(stderr, "%p realloc %p\n", p, out);
- return out;
-}
-
-void uiFree(void *p)
-{
- if (p == NULL)
- return;
- free(p);
- if (options.debugLogAllocations)
- fprintf(stderr, "%p free\n", p);
-}
diff --git a/new/darwin/button.m b/new/darwin/button.m
deleted file mode 100644
index 3ec8a54..0000000
--- a/new/darwin/button.m
+++ /dev/null
@@ -1,86 +0,0 @@
-// 7 april 2015
-#import "uipriv_darwin.h"
-
-@interface uiNSButton : NSButton
-@property uiButton *uiB;
-@property void (*uiOnClicked)(uiButton *, void *);
-@property void *uiOnClickedData;
-@end
-
-@implementation uiNSButton
-
-- (void)viewDidMoveToSuperview
-{
- if (uiDarwinControlFreeWhenAppropriate(uiControl(self.uiB), [self superview])) {
- [self setTarget:nil];
- self.uiB = NULL;
- }
- [super viewDidMoveToSuperview];
-}
-
-- (IBAction)uiButtonClicked:(id)sender
-{
- (*(self.uiOnClicked))(self.uiB, self.uiOnClickedData);
-}
-
-@end
-
-static void defaultOnClicked(uiButton *c, void *data)
-{
- // do nothing
-}
-
-static char *buttonText(uiButton *bb)
-{
- uiNSButton *b;
-
- b = (uiNSButton *) uiControlHandle(uiControl(bb));
- return uiDarwinNSStringToText([b title]);
-}
-
-static void buttonSetText(uiButton *bb, const char *text)
-{
- uiNSButton *b;
-
- b = (uiNSButton *) uiControlHandle(uiControl(bb));
- [b setTitle:toNSString(text)];
-}
-
-static void buttonOnClicked(uiButton *bb, void (*f)(uiButton *, void *), void *data)
-{
- uiNSButton *b;
-
- b = (uiNSButton *) uiControlHandle(uiControl(bb));
- b.uiOnClicked = f;
- b.uiOnClickedData = data;
-}
-
-uiButton *uiNewButton(const char *text)
-{
- uiButton *b;
- uiNSButton *bb;
-
- b = uiNew(uiButton);
-
- uiDarwinNewControl(uiControl(b), [uiNSButton class], NO, NO);
- bb = (uiNSButton *) uiControlHandle(uiControl(b));
-
- [bb setTitle:toNSString(text)];
- [bb setButtonType:NSMomentaryPushInButton];
- [bb setBordered:YES];
- [bb setBezelStyle:NSRoundedBezelStyle];
- setStandardControlFont((NSControl *) bb);
-
- [bb setTarget:bb];
- [bb setAction:@selector(uiButtonClicked:)];
-
- bb.uiOnClicked = defaultOnClicked;
-
- uiButton(b)->Text = buttonText;
- uiButton(b)->SetText = buttonSetText;
- uiButton(b)->OnClicked = buttonOnClicked;
-
- bb.uiB = b;
-
- return bb.uiB;
-}
diff --git a/new/darwin/checkbox.m b/new/darwin/checkbox.m
deleted file mode 100644
index a7ccfb3..0000000
--- a/new/darwin/checkbox.m
+++ /dev/null
@@ -1,107 +0,0 @@
-// 7 april 2015
-#import "uipriv_darwin.h"
-
-@interface uiCheckboxNSButton : NSButton
-@property uiCheckbox *uiC;
-@property void (*uiOnToggled)(uiCheckbox *, void *);
-@property void *uiOnToggledData;
-@end
-
-@implementation uiCheckboxNSButton
-
-- (void)viewDidMoveToSuperview
-{
- if (uiDarwinControlFreeWhenAppropriate(uiControl(self.uiC), [self superview])) {
- [self setTarget:nil];
- self.uiC = NULL;
- }
- [super viewDidMoveToSuperview];
-}
-
-- (IBAction)uiCheckboxToggled:(id)sender
-{
- (*(self.uiOnToggled))(self.uiC, self.uiOnToggledData);
-}
-
-@end
-
-static void defaultOnToggled(uiCheckbox *c, void *data)
-{
- // do nothing
-}
-
-static char *checkboxText(uiCheckbox *c)
-{
- uiCheckboxNSButton *cc;
-
- cc = (uiCheckboxNSButton *) uiControlHandle(uiControl(c));
- return uiDarwinNSStringToText([cc title]);
-}
-
-static void checkboxSetText(uiCheckbox *c, const char *text)
-{
- uiCheckboxNSButton *cc;
-
- cc = (uiCheckboxNSButton *) uiControlHandle(uiControl(c));
- [cc setTitle:toNSString(text)];
-}
-
-static void checkboxOnToggled(uiCheckbox *c, void (*f)(uiCheckbox *, void *), void *data)
-{
- uiCheckboxNSButton *cc;
-
- cc = (uiCheckboxNSButton *) uiControlHandle(uiControl(c));
- cc.uiOnToggled = f;
- cc.uiOnToggledData = data;
-}
-
-static int checkboxChecked(uiCheckbox *c)
-{
- uiCheckboxNSButton *cc;
-
- cc = (uiCheckboxNSButton *) uiControlHandle(uiControl(c));
- return [cc state] == NSOnState;
-}
-
-static void checkboxSetChecked(uiCheckbox *c, int checked)
-{
- uiCheckboxNSButton *cc;
- NSInteger state;
-
- cc = (uiCheckboxNSButton *) uiControlHandle(uiControl(c));
- state = NSOnState;
- if (!checked)
- state = NSOffState;
- [cc setState:state];
-}
-
-uiCheckbox *uiNewCheckbox(const char *text)
-{
- uiCheckbox *c;
- uiCheckboxNSButton *cc;
-
- c = uiNew(uiCheckbox);
-
- uiDarwinNewControl(uiControl(c), [uiCheckboxNSButton class], NO, NO);
- cc = (uiCheckboxNSButton *) uiControlHandle(uiControl(c));
-
- [cc setTitle:toNSString(text)];
- [cc setButtonType:NSSwitchButton];
- [cc setBordered:NO];
- setStandardControlFont((NSControl *) cc);
-
- [cc setTarget:cc];
- [cc setAction:@selector(uiCheckboxToggled:)];
-
- cc.uiOnToggled = defaultOnToggled;
-
- uiCheckbox(c)->Text = checkboxText;
- uiCheckbox(c)->SetText = checkboxSetText;
- uiCheckbox(c)->OnToggled = checkboxOnToggled;
- uiCheckbox(c)->Checked = checkboxChecked;
- uiCheckbox(c)->SetChecked = checkboxSetChecked;
-
- cc.uiC = c;
-
- return cc.uiC;
-}
diff --git a/new/darwin/entry.m b/new/darwin/entry.m
deleted file mode 100644
index 7189156..0000000
--- a/new/darwin/entry.m
+++ /dev/null
@@ -1,73 +0,0 @@
-// 9 april 2015
-#import "uipriv_darwin.h"
-
-@interface uiNSTextField : NSTextField
-@property uiEntry *uiE;
-@end
-
-@implementation uiNSTextField
-
-- (void)viewDidMoveToSuperview
-{
- if (uiDarwinControlFreeWhenAppropriate(uiControl(self.uiE), [self superview])) {
- [self setTarget:nil];
- self.uiE = NULL;
- }
- [super viewDidMoveToSuperview];
-}
-
-@end
-
-static char *entryText(uiEntry *e)
-{
- uiNSTextField *t;
-
- t = (uiNSTextField *) uiControlHandle(uiControl(e));
- return uiDarwinNSStringToText([t stringValue]);
-}
-
-static void entrySetText(uiEntry *e, const char *text)
-{
- uiNSTextField *t;
-
- t = (uiNSTextField *) uiControlHandle(uiControl(e));
- [t setStringValue:toNSString(text)];
-}
-
-// TOOD move elsewhere
-// these are based on interface builder defaults; my comments in the old code weren't very good so I don't really know what talked about what, sorry :/
-void finishNewTextField(NSTextField *t, BOOL isEntry)
-{
- setStandardControlFont((id) t);
-
- // THE ORDER OF THESE CALLS IS IMPORTANT; CHANGE IT AND THE BORDERS WILL DISAPPEAR
- [t setBordered:NO];
- [t setBezelStyle:NSTextFieldSquareBezel];
- [t setBezeled:isEntry];
-
- // we don't need to worry about substitutions/autocorrect here; see window_darwin.m for details
-
- [[t cell] setLineBreakMode:NSLineBreakByClipping];
- [[t cell] setScrollable:YES];
-}
-
-uiEntry *uiNewEntry(void)
-{
- uiEntry *e;
- uiNSTextField *t;
-
- e = uiNew(uiEntry);
-
- uiDarwinNewControl(uiControl(e), [uiNSTextField class], NO, NO);
- t = (uiNSTextField *) uiControlHandle(uiControl(e));
-
- [t setSelectable:YES]; // otherwise the setting is masked by the editable default of YES
- finishNewTextField((NSTextField *) t, YES);
-
- uiEntry(e)->Text = entryText;
- uiEntry(e)->SetText = entrySetText;
-
- t.uiE = e;
-
- return t.uiE;
-}
diff --git a/new/darwin/init.m b/new/darwin/init.m
deleted file mode 100644
index 4f14a0a..0000000
--- a/new/darwin/init.m
+++ /dev/null
@@ -1,67 +0,0 @@
-// 6 april 2015
-#import "uipriv_darwin.h"
-
-@interface uiApplication : NSApplication
-@end
-
-@implementation uiApplication
-
-// hey look! we're overriding terminate:!
-// we're going to make sure we can go back to main() whether Cocoa likes it or not!
-// and just how are we going to do that, hm?
-// (note: this is called after applicationShouldTerminate:)
-- (void)terminate:(id)sender
-{
- // yes that's right folks: DO ABSOLUTELY NOTHING.
- // the magic is [NSApp run] will just... stop.
-
- // for debugging
- NSLog(@"in terminate:");
-}
-
-@end
-
-@interface uiAppDelegate : NSObject <NSApplicationDelegate>
-@end
-
-@implementation uiAppDelegate
-
-- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)app
-{
- // for debugging
- NSLog(@"in applicationShouldTerminate:");
- return NSTerminateNow;
-}
-
-- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)app
-{
- return NO;
-}
-
-@end
-
-// we are not in control of the actual lifetimes and refcounts of NSViews (see http://stackoverflow.com/a/29523141/3408572)
-// when we're done with a view, it'll be added as a subview of this one, and this one will be released on application shutdown
-// we need this separate view because it's possible for controls to have no parent but still be alive
-NSView *destroyedControlsView;
-
-uiInitOptions options;
-
-const char *uiInit(uiInitOptions *o)
-{
- options = *o;
- [uiApplication sharedApplication];
- // don't check for a NO return; something (launch services?) causes running from application bundles to always return NO when asking to change activation policy, even if the change is to the same activation policy!
- // see https://github.com/andlabs/ui/issues/6
- [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
- [NSApp setDelegate:[uiAppDelegate new]];
-
- // we can use a stock NSView for this
- destroyedControlsView = [[NSView alloc] initWithFrame:NSZeroRect];
-
- return NULL;
-}
-
-void uiFreeInitError(const char *err)
-{
-}
diff --git a/new/darwin/label.m b/new/darwin/label.m
deleted file mode 100644
index 56780d0..0000000
--- a/new/darwin/label.m
+++ /dev/null
@@ -1,59 +0,0 @@
-// 9 april 2015
-#import "uipriv_darwin.h"
-
-@interface uiLabelNSTextField : NSTextField
-@property uiLabel *uiL;
-@end
-
-@implementation uiLabelNSTextField
-
-- (void)viewDidMoveToSuperview
-{
- if (uiDarwinControlFreeWhenAppropriate(uiControl(self.uiL), [self superview])) {
- [self setTarget:nil];
- self.uiL = NULL;
- }
- [super viewDidMoveToSuperview];
-}
-
-@end
-
-static char *labelText(uiLabel *l)
-{
- uiLabelNSTextField *t;
-
- t = (uiLabelNSTextField *) uiControlHandle(uiControl(l));
- return uiDarwinNSStringToText([t stringValue]);
-}
-
-static void labelSetText(uiLabel *l, const char *text)
-{
- uiLabelNSTextField *t;
-
- t = (uiLabelNSTextField *) uiControlHandle(uiControl(l));
- [t setStringValue:toNSString(text)];
-}
-
-uiLabel *uiNewLabel(const char *text)
-{
- uiLabel *l;
- uiLabelNSTextField *t;
-
- l = uiNew(uiLabel);
-
- uiDarwinNewControl(uiControl(l), [uiLabelNSTextField class], NO, NO);
- t = (uiLabelNSTextField *) uiControlHandle(uiControl(l));
-
- [t setStringValue:toNSString(text)];
- [t setEditable:NO];
- [t setSelectable:NO];
- [t setDrawsBackground:NO];
- finishNewTextField((NSTextField *) t, NO);
-
- uiLabel(l)->Text = labelText;
- uiLabel(l)->SetText = labelSetText;
-
- t.uiL = l;
-
- return t.uiL;
-}
diff --git a/new/darwin/main.m b/new/darwin/main.m
deleted file mode 100644
index 8663b58..0000000
--- a/new/darwin/main.m
+++ /dev/null
@@ -1,27 +0,0 @@
-// 6 april 2015
-#import "uipriv_darwin.h"
-
-// #qo LDFLAGS: -lobjc -framework Foundation -framework AppKit
-
-void uiMain(void)
-{
- [NSApp run];
-}
-
-void uiQuit(void)
-{
- NSEvent *e;
-
- [NSApp stop:NSApp];
- // stop: won't register until another event has passed; let's synthesize one
- e = [NSEvent otherEventWithType:NSApplicationDefined
- location:NSZeroPoint
- modifierFlags:0
- timestamp:[[NSProcessInfo processInfo] systemUptime]
- windowNumber:0
- context:[NSGraphicsContext currentContext]
- subtype:0
- data1:0
- data2:0];
- [NSApp postEvent:e atStart:NO]; // let pending events take priority (this is what PostQuitMessage() on Windows does so we have to do it here too for parity; thanks to mikeash in irc.freenode.net/#macdev for confirming that this parameter should indeed be NO)
-}
diff --git a/new/darwin/newcontrol.m b/new/darwin/newcontrol.m
deleted file mode 100644
index 12967c5..0000000
--- a/new/darwin/newcontrol.m
+++ /dev/null
@@ -1,231 +0,0 @@
-// 7 april 2015
-#include "uipriv_darwin.h"
-
-typedef struct singleView singleView;
-
-struct singleView {
- NSView *view;
- NSScrollView *scrollView;
- NSView *immediate; // the control that is added to the parent container; either view or scrollView
- uiParent *parent;
- BOOL userHid;
- BOOL containerHid;
- BOOL userDisabled;
- BOOL containerDisabled;
-};
-
-static void singleDestroy(uiControl *c)
-{
- singleView *s = (singleView *) (c->Internal);
-
- [destroyedControlsView addSubview:s->immediate];
-}
-
-static uintptr_t singleHandle(uiControl *c)
-{
- singleView *s = (singleView *) (c->Internal);
-
- return (uintptr_t) (s->view);
-}
-
-static void singleSetParent(uiControl *c, uiParent *parent)
-{
- singleView *s = (singleView *) (c->Internal);
- NSView *parentView;
- uiParent *oldparent;
-
- oldparent = s->parent;
- s->parent = parent;
- if (oldparent != NULL) {
- [s->immediate removeFromSuperview];
- uiParentUpdate(oldparent);
- }
- if (s->parent != NULL) {
- // TODO uiControlView(), uiParentView()
- parentView = (NSView *) uiParentHandle(s->parent);
- [parentView addSubview:s->immediate];
- uiParentUpdate(s->parent);
- }
-}
-
-// also good for NSBox and NSProgressIndicator
-static void singlePreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
-{
- singleView *s = (singleView *) (c->Internal);
- NSControl *control;
- NSRect r;
-
- control = (NSControl *) (s->view);
- [control sizeToFit];
- // use alignmentRect here instead of frame because we'll be resizing based on that
- r = [control alignmentRectForFrame:[control frame]];
- *width = (intmax_t) r.size.width;
- *height = (intmax_t) r.size.height;
-}
-
-static void singleResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d)
-{
- singleView *s = (singleView *) (c->Internal);
- NSRect frame;
-
- frame.origin.x = x;
- // mac os x coordinate system has (0,0) in the lower-left
- frame.origin.y = ([[s->immediate superview] bounds].size.height - height) - y;
- frame.size.width = width;
- frame.size.height = height;
- frame = [s->immediate frameForAlignmentRect:frame];
- [s->immediate setFrame:frame];
-}
-
-static int singleVisible(uiControl *c)
-{
- singleView *s = (singleView *) (c->Internal);
-
- if (s->userHid)
- return 0;
- return 1;
-}
-
-static void singleShow(uiControl *c)
-{
- singleView *s = (singleView *) (c->Internal);
-
- s->userHid = NO;
- if (!s->containerHid) {
- [s->immediate setHidden:NO];
- if (s->parent != NULL)
- uiParentUpdate(s->parent);
- }
-}
-
-static void singleHide(uiControl *c)
-{
- singleView *s = (singleView *) (c->Internal);
-
- s->userHid = YES;
- [s->immediate setHidden:YES];
- if (s->parent != NULL)
- uiParentUpdate(s->parent);
-}
-
-static void singleContainerShow(uiControl *c)
-{
- singleView *s = (singleView *) (c->Internal);
-
- s->containerHid = NO;
- if (!s->userHid) {
- [s->immediate setHidden:NO];
- if (s->parent != NULL)
- uiParentUpdate(s->parent);
- }
-}
-
-static void singleContainerHide(uiControl *c)
-{
- singleView *s = (singleView *) (c->Internal);
-
- s->containerHid = YES;
- [s->immediate setHidden:YES];
- if (s->parent != NULL)
- uiParentUpdate(s->parent);
-}
-
-static void enable(singleView *s)
-{
- if ([s->view respondsToSelector:@selector(setEnabled:)])
- [((NSControl *) (s->view)) setEnabled:YES];
-}
-
-static void disable(singleView *s)
-{
- if ([s->view respondsToSelector:@selector(setEnabled:)])
- [((NSControl *) (s->view)) setEnabled:NO];
-}
-
-static void singleEnable(uiControl *c)
-{
- singleView *s = (singleView *) (c->Internal);
-
- s->userDisabled = NO;
- if (!s->containerDisabled)
- enable(s);
-}
-
-static void singleDisable(uiControl *c)
-{
- singleView *s = (singleView *) (c->Internal);
-
- s->userDisabled = YES;
- disable(s);
-}
-
-static void singleContainerEnable(uiControl *c)
-{
- singleView *s = (singleView *) (c->Internal);
-
- s->containerDisabled = NO;
- if (!s->userDisabled)
- enable(s);
-}
-
-static void singleContainerDisable(uiControl *c)
-{
- singleView *s = (singleView *) (c->Internal);
-
- s->containerDisabled = YES;
- disable(s);
-}
-
-void uiDarwinNewControl(uiControl *c, Class class, BOOL inScrollView, BOOL scrollViewHasBorder)
-{
- singleView *s;
-
- s = uiNew(singleView);
- // thanks to autoxr and arwyn in irc.freenode.net/#macdev
- s->view = (NSView *) [[class alloc] initWithFrame:NSZeroRect];
- s->immediate = s->view;
-
- if (inScrollView) {
- s->scrollView = [[NSScrollView alloc] initWithFrame:NSZeroRect];
- [s->scrollView setDocumentView:s->view];
- [s->scrollView setHasHorizontalScroller:YES];
- [s->scrollView setHasVerticalScroller:YES];
- [s->scrollView setAutohidesScrollers:YES];
- if (scrollViewHasBorder)
- [s->scrollView setBorderType:NSBezelBorder];
- else
- [s->scrollView setBorderType:NSNoBorder];
- s->immediate = (NSView *) (s->scrollView);
- }
-
- // and keep a reference to s->immediate for when we remove the control from its parent
- [s->immediate retain];
-
- c->Internal = s;
- c->Destroy = singleDestroy;
- c->Handle = singleHandle;
- c->SetParent = singleSetParent;
- c->PreferredSize = singlePreferredSize;
- c->Resize = singleResize;
- c->Visible = singleVisible;
- c->Show = singleShow;
- c->Hide = singleHide;
- c->ContainerShow = singleContainerShow;
- c->ContainerHide = singleContainerHide;
- c->Enable = singleEnable;
- c->Disable = singleDisable;
- c->ContainerEnable = singleContainerEnable;
- c->ContainerDisable = singleContainerDisable;
-}
-
-BOOL uiDarwinControlFreeWhenAppropriate(uiControl *c, NSView *newSuperview)
-{
- singleView *s = (singleView *) (c->Internal);
-
- if (newSuperview == destroyedControlsView) {
- [s->immediate release]; // we don't need the reference anymore
- uiFree(s);
- return YES;
- }
- return NO;
-}
diff --git a/new/darwin/parent.m b/new/darwin/parent.m
deleted file mode 100644
index abf0e59..0000000
--- a/new/darwin/parent.m
+++ /dev/null
@@ -1,118 +0,0 @@
-// 4 august 2014
-#import "uipriv_darwin.h"
-
-// calling -[className] on the content views of NSWindow, NSTabItem, and NSBox all return NSView, so I'm assuming I just need to override these
-// fornunately:
-// - NSWindow resizing calls -[setFrameSize:] (but not -[setFrame:])
-// - NSTabView resizing calls both -[setFrame:] and -[setFrameSIze:] on the current tab
-// - NSTabView switching tabs calls both -[setFrame:] and -[setFrameSize:] on the new tab
-// so we just override setFrameSize:
-// thanks to mikeash and JtRip in irc.freenode.net/#macdev
-@interface uipParent : NSView {
-// TODO
-@public
- uiControl *child;
- intmax_t marginLeft;
- intmax_t marginTop;
- intmax_t marginRight;
- intmax_t marginBottom;
-}
-- (void)uiUpdateNow;
-@end
-
-@implementation uipParent
-
-uiLogObjCClassAllocations
-
-- (void)viewDidMoveToSuperview
-{
- // we can't just use nil because NSTabView will set page views to nil when they're tabbed away
- // this means that we have to explicitly move them to the destroyed controls view when we're done with them, and likewise in NSWindow
- if ([self superview] == destroyedControlsView)
- if (self->child != NULL) {
- uiControlDestroy(self->child);
- self->child = NULL;
- [self release];
- }
- [super viewDidMoveToSuperview];
-}
-
-- (void)setFrameSize:(NSSize)s
-{
- [super setFrameSize:s];
- [self uiUpdateNow];
-}
-
-// These are based on measurements from Interface Builder.
-// These seem to be based on Auto Layout constants, but I don't see an API that exposes these...
-// This one is 8 for most pairs of controls that I've tried; the only difference is between two pushbuttons, where it's 12...
-#define macXPadding 8
-// Likewise, this one appears to be 12 for pairs of push buttons...
-#define macYPadding 8
-
-- (void)uiUpdateNow
-{
- uiSizing d;
- intmax_t x, y, width, height;
-
- if (self->child == NULL)
- return;
- x = [self bounds].origin.x + self->marginLeft;
- y = [self bounds].origin.y + self->marginTop;
- width = [self bounds].size.width - (self->marginLeft + self->marginRight);
- height = [self bounds].size.height - (self->marginTop + self->marginBottom);
- d.xPadding = macXPadding;
- d.yPadding = macYPadding;
- uiControlResize(self->child, x, y, width, height, &d);
-}
-
-@end
-
-static uintptr_t parentHandle(uiParent *p)
-{
- uipParent *pp = (uipParent *) (p->Internal);
-
- return (uintptr_t) pp;
-}
-
-static void parentSetChild(uiParent *p, uiControl *child)
-{
- uipParent *pp = (uipParent *) (p->Internal);
-
- pp->child = child;
- if (pp->child != NULL)
- uiControlSetParent(child, p);
-}
-
-static void parentSetMargins(uiParent *p, intmax_t left, intmax_t top, intmax_t right, intmax_t bottom)
-{
- uipParent *pp = (uipParent *) (p->Internal);
-
- pp->marginLeft = left;
- pp->marginTop = top;
- pp->marginRight = right;
- pp->marginBottom = bottom;
-}
-
-static void parentUpdate(uiParent *p)
-{
- uipParent *pp = (uipParent *) (p->Internal);
-
- [pp uiUpdateNow];
-}
-
-uiParent *uiNewParent(uintptr_t osParent)
-{
- uiParent *p;
-
- p = uiNew(uiParent);
- p->Internal = [[uipParent alloc] initWithFrame:NSZeroRect];
- p->Handle = parentHandle;
- p->SetChild = parentSetChild;
- p->SetMargins = parentSetMargins;
- p->Update = parentUpdate;
- // don't use osParent; we'll need to call specific selectors to set the parent view
- // and keep the view alive so we can release it properly later
- [((uipParent *) (p->Internal)) retain];
- return p;
-} \ No newline at end of file
diff --git a/new/darwin/tab.m b/new/darwin/tab.m
deleted file mode 100644
index b84ee9a..0000000
--- a/new/darwin/tab.m
+++ /dev/null
@@ -1,73 +0,0 @@
-// 12 april 2015
-#import "uipriv_darwin.h"
-
-// TODO
-// - verify margins against extra space around the tab
-// - free child containers properly
-
-@interface uiNSTabView : NSTabView
-@property uiTab *uiT;
-@end
-
-@implementation uiNSTabView
-
-- (void)viewDidMoveToSuperview
-{
- // TODO free all tabs explicitly
- if (uiDarwinControlFreeWhenAppropriate(uiControl(self.uiT), [self superview]))
- self.uiT = NULL;
- [super viewDidMoveToSuperview];
-}
-
-@end
-
-// the default new control implementation uses -sizeToFit, which we don't have with NSTabView
-// fortunately, we do have -minimumSize
-static void preferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
-{
- uiNSTabView *tv;
- NSSize s;
-
- tv = (uiNSTabView *) uiControlHandle(c);
- s = [tv minimumSize];
- *width = (intmax_t) (s.width);
- *height = (intmax_t) (s.height);
-}
-
-static void tabAddPage(uiTab *t, const char *name, uiControl *child)
-{
- uiNSTabView *tv;
- uiParent *content;
- NSTabViewItem *i;
-
- content = uiNewParent(0);
- uiParentSetChild(content, child);
-
- i = [[NSTabViewItem alloc] initWithIdentifier:nil];
- [i setLabel:toNSString(name)];
- [i setView:((NSView *) uiParentHandle(content))];
- tv = (uiNSTabView *) uiControlHandle(uiControl(t));
- [tv addTabViewItem:i];
-}
-
-uiTab *uiNewTab(void)
-{
- uiTab *t;
- uiNSTabView *tv;
-
- t = uiNew(uiTab);
-
- uiDarwinNewControl(uiControl(t), [uiNSTabView class], NO, NO);
- tv = (uiNSTabView *) uiControlHandle(uiControl(t));
-
- // 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/text.m b/new/darwin/text.m
deleted file mode 100644
index f0d3dab..0000000
--- a/new/darwin/text.m
+++ /dev/null
@@ -1,19 +0,0 @@
-// 10 april 2015
-#import "uipriv_darwin.h"
-
-char *uiDarwinNSStringToText(NSString *s)
-{
- char *out;
-
- out = strdup([s UTF8String]);
- if (out == NULL) {
- fprintf(stderr, "memory exhausted in uiDarwinNSStringToText()\n");
- abort();
- }
- return out;
-}
-
-void uiFreeText(char *s)
-{
- free(s);
-}
diff --git a/new/darwin/uipriv_darwin.h b/new/darwin/uipriv_darwin.h
deleted file mode 100644
index 36de1f1..0000000
--- a/new/darwin/uipriv_darwin.h
+++ /dev/null
@@ -1,40 +0,0 @@
-// 6 january 2015
-#define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_7
-#define MAC_OS_X_VERSION_MAX_ALLOWED MAC_OS_X_VERSION_10_7
-#import <Cocoa/Cocoa.h>
-#import "../uipriv.h"
-#import "../ui_darwin.h"
-
-#define toNSString(str) [NSString stringWithUTF8String:(str)]
-#define fromNSString(str) [(str) UTF8String]
-
-#define uiLogObjCClassAllocations \
-+ (id)alloc \
-{ \
- id thing; \
- thing = [super alloc]; \
- if (options.debugLogAllocations) \
- fprintf(stderr, "%p alloc %s\n", thing, [[self className] UTF8String]); \
- return thing; \
-} \
-- (void)dealloc \
-{ \
- [super dealloc]; \
- if (options.debugLogAllocations) \
- fprintf(stderr, "%p free\n", self); \
-}
-
-// init_darwin.m
-extern NSView *destroyedControlsView;
-
-// util_darwin.m
-extern void setStandardControlFont(NSControl *);
-extern void disableAutocorrect(NSTextView *);
-
-// These are based on measurements from Interface Builder.
-// These seem to be based on Auto Layout constants, but I don't see an API that exposes these...
-#define macXMargin 20
-#define macYMargin 20
-
-// entry_darwin.m
-extern void finishNewTextField(NSTextField *, BOOL);
diff --git a/new/darwin/util.m b/new/darwin/util.m
deleted file mode 100644
index 906a0ea..0000000
--- a/new/darwin/util.m
+++ /dev/null
@@ -1,20 +0,0 @@
-// 7 april 2015
-#import "uipriv_darwin.h"
-
-// also fine for NSCells and NSTexts (NSTextViews)
-void setStandardControlFont(NSControl *control)
-{
- [control setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSRegularControlSize]]];
-}
-
-void disableAutocorrect(NSTextView *tv)
-{
- [tv setEnabledTextCheckingTypes:0];
- [tv setAutomaticDashSubstitutionEnabled:NO];
- // don't worry about automatic data detection; it won't change stringValue (thanks pretty_function in irc.freenode.net/#macdev)
- [tv setAutomaticSpellingCorrectionEnabled:NO];
- [tv setAutomaticTextReplacementEnabled:NO];
- [tv setAutomaticQuoteSubstitutionEnabled:NO];
- [tv setAutomaticLinkDetectionEnabled:NO];
- [tv setSmartInsertDeleteEnabled:NO];
-}
diff --git a/new/darwin/window.m b/new/darwin/window.m
deleted file mode 100644
index c243374..0000000
--- a/new/darwin/window.m
+++ /dev/null
@@ -1,162 +0,0 @@
-// 6 april 2015
-#import "uipriv_darwin.h"
-
-// TODO
-// - free chilld containers properly
-
-@interface uiWindowDelegate : NSObject <NSWindowDelegate>
-@property (assign) NSWindow *w;
-@property uiParent *content;
-@property int (*onClosing)(uiWindow *, void *);
-@property void *onClosingData;
-@property struct window *uiw;
-@end
-
-@implementation uiWindowDelegate
-
-uiLogObjCClassAllocations
-
-- (BOOL)windowShouldClose:(id)win
-{
- // return exact constants to be safe
- if ((*(self.onClosing))(uiWindow(self.uiw), self.onClosingData))
- return YES;
- return NO;
-}
-
-// after this method returns we assume the window will be released (see below), so we can go too
-- (void)windowWillClose:(NSNotification *)note
-{
- [self.w setDelegate:nil]; // see http://stackoverflow.com/a/29523141/3408572
-
- // when we reach this point, we need to ensure that all the window's children are destroyed (for OS parity)
- // because we need to set the content view's superview to the destroyed controls view to trigger deletion, we need to do this manually
- // first, replace the current content view...
- [self.w setContentView:[[NSView alloc] initWithFrame:NSZeroRect]];
- // ...then, trigger the deletion
- [destroyedControlsView addSubview:((NSView *) uiParentHandle(self.content))];
-
- uiFree(self.uiw);
- [self release];
-}
-
-@end
-
-struct window {
- uiWindow w;
- uiWindowDelegate *d;
- int margined;
-};
-
-static int defaultOnClosing(uiWindow *w, void *data)
-{
- return 1;
-}
-
-#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;
-
- 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 = windowOnClosing;
- uiWindow(d.uiw)->SetChild = windowSetChild;
- uiWindow(d.uiw)->Margined = windowMargined;
- uiWindow(d.uiw)->SetMargined = windowSetMargined;
-
- return uiWindow(d.uiw);
-}