forked from andlabs/ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobjc_darwin.m
84 lines (69 loc) · 2 KB
/
objc_darwin.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// 15 may 2014
#include "objc_darwin.h"
#import <Foundation/NSString.h>
// see delegateuitask_darwin.m
// in this case, NSScrollView.h includes NSApplication.h
#import <AppKit/NSView.h>
#ifdef MAC_OS_X_VERSION_10_7
#undef MAC_OS_X_VERSION_MIN_REQUIRED
#undef MAC_OS_X_VERSION_MAX_ALLOWED
#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
#endif
#import <AppKit/NSApplication.h>
#undef MAC_OS_X_VERSION_MIN_REQUIRED
#undef MAC_OS_X_VERSION_MAX_ALLOWED
#define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_6
#define MAC_OS_X_VERSION_MAX_ALLOWED MAC_OS_X_VERSION_10_6
#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;
id toNSString(char *str)
{
return [NSString stringWithUTF8String:str];
}
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];
}