diff options
| author | Pietro Gagliardi <[email protected]> | 2014-07-02 22:53:03 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-07-02 22:53:03 -0400 |
| commit | 8a81650b3da7ce00725336df9e03b38e935c5a65 (patch) | |
| tree | 08af843f0460e7226f305cf7162021ef54e8c3f7 /objc_darwin.m | |
| parent | 4dd5ceb11d62bd6b9af4847936314a9d8c45707f (diff) | |
Moved it all back; the preemptive multitaksing during an event handler kills us on all platforms. Going to have to restrict ALL GUI accss to happening from one t hread, so going to need to drop uitask entirely and have just a start() callback for startup code and a post() function for posting requests to windows (like channel sends but into a perpetual buffer).
Diffstat (limited to 'objc_darwin.m')
| -rw-r--r-- | objc_darwin.m | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/objc_darwin.m b/objc_darwin.m new file mode 100644 index 0000000..c2d3d6f --- /dev/null +++ b/objc_darwin.m @@ -0,0 +1,75 @@ +// 15 may 2014 + +#include "objc_darwin.h" +#import <Foundation/NSString.h> +#import <AppKit/NSView.h> +#import <AppKit/NSScrollView.h> + +#define to(T, x) ((T *) (x)) +#define _toNSString(x) to(NSString, (x)) +#define toNSView(x) to(NSView, (x)) +#define toNSScrollView(x) to(NSScrollView, (x)) + +// because the only way to make a new NSControl/NSView is with a frame (it gets overridden later) +NSRect dummyRect; + +// this can be called before our NSApp is created, so keep a pool to keep 10.6 happy +id toNSString(char *str) +{ + NSAutoreleasePool *pool; + NSString *s; + + pool = [NSAutoreleasePool new]; + s = [NSString stringWithUTF8String:str]; + [s retain]; // keep alive after releasing the pool + [pool release]; + return s; +} + +char *fromNSString(id str) +{ + return [_toNSString(str) UTF8String]; +} + +void display(id view) +{ + [toNSView(view) display]; +} + +struct xrect frame(id view) +{ + NSRect r; + struct xrect s; + + r = [toNSView(view) frame]; + s.x = (intptr_t) r.origin.x; + s.y = (intptr_t) r.origin.y; + s.width = (intptr_t) r.size.width; + s.height = (intptr_t) r.size.height; + return s; +} + +id makeScrollView(id content) +{ + NSScrollView *scrollview; + + scrollview = [[NSScrollView alloc] + initWithFrame:dummyRect]; + [scrollview setHasHorizontalScroller:YES]; + [scrollview setHasVerticalScroller:YES]; + [scrollview setAutohidesScrollers:YES]; + // Interface Builder sets this for NSTableViews; we also want this on Areas + [scrollview setDrawsBackground:YES]; + [scrollview setDocumentView:toNSView(content)]; + return scrollview; +} + +void giveScrollViewBezelBorder(id scrollview) +{ + [toNSScrollView(scrollview) setBorderType:NSBezelBorder]; +} + +id scrollViewContent(id scrollview) +{ + return [toNSScrollView(scrollview) documentView]; +} |
