forked from gnachman/iTerm2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FutureMethods.m
170 lines (144 loc) · 5.18 KB
/
FutureMethods.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
//
// FutureMethods.m
// iTerm
//
// Created by George Nachman on 8/29/11.
// Copyright 2011 Georgetech. All rights reserved.
//
#import "FutureMethods.h"
const int FutureNSWindowCollectionBehaviorStationary = (1 << 4); // value stolen from 10.6 SDK
@implementation NSWindow (Future)
- (void)futureSetRestorable:(BOOL)value
{
if ([self respondsToSelector:@selector(setRestorable:)]) {
NSMethodSignature *sig = [[self class] instanceMethodSignatureForSelector:@selector(setRestorable:)];
NSInvocation *inv = [NSInvocation invocationWithMethodSignature:sig];
[inv setTarget:self];
[inv setSelector:@selector(setRestorable:)];
[inv setArgument:&value atIndex:2];
[inv invoke];
}
}
- (void)futureSetRestorationClass:(Class)class
{
if ([self respondsToSelector:@selector(setRestorationClass:)]) {
[self performSelector:@selector(setRestorationClass:) withObject:class];
}
}
- (void)futureInvalidateRestorableState
{
if ([self respondsToSelector:@selector(invalidateRestorableState)]) {
[self performSelector:@selector(invalidateRestorableState)];
}
}
@end
@implementation NSView (Future)
- (void)futureSetAcceptsTouchEvents:(BOOL)value
{
if ([self respondsToSelector:@selector(setAcceptsTouchEvents:)]) {
NSMethodSignature *sig = [[self class] instanceMethodSignatureForSelector:@selector(setAcceptsTouchEvents:)];
NSInvocation *inv = [NSInvocation invocationWithMethodSignature:sig];
[inv setTarget:self];
[inv setSelector:@selector(setAcceptsTouchEvents:)];
[inv setArgument:&value atIndex:2];
[inv invoke];
}
}
- (void)futureSetWantsRestingTouches:(BOOL)value
{
if ([self respondsToSelector:@selector(setWantsRestingTouches:)]) {
NSMethodSignature *sig = [[self class] instanceMethodSignatureForSelector:@selector(setWantsRestingTouches:)];
NSInvocation *inv = [NSInvocation invocationWithMethodSignature:sig];
[inv setTarget:self];
[inv setSelector:@selector(setWantsRestingTouches:)];
[inv setArgument:&value atIndex:2];
[inv invoke];
}
}
@end
@implementation NSEvent (Future)
- (NSArray *)futureTouchesMatchingPhase:(int)phase inView:(NSView *)view
{
if ([self respondsToSelector:@selector(touchesMatchingPhase:inView:)]) {
NSMethodSignature *sig = [[self class] instanceMethodSignatureForSelector:@selector(touchesMatchingPhase:inView:)];
NSInvocation *inv = [NSInvocation invocationWithMethodSignature:sig];
[inv setTarget:self];
[inv setSelector:@selector(touchesMatchingPhase:inView:)];
[inv setArgument:&phase atIndex:2];
[inv setArgument:&view atIndex:3];
[inv invoke];
NSArray *result;
[inv getReturnValue:&result];
return result;
} else {
return [NSArray array];
}
}
@end
static FutureNSScrollerStyle GetScrollerStyle(id theObj)
{
NSMethodSignature *sig = [[NSScroller class] instanceMethodSignatureForSelector:@selector(scrollerStyle)];
NSInvocation *inv = [NSInvocation invocationWithMethodSignature:sig];
[inv setTarget:theObj];
[inv setSelector:@selector(scrollerStyle)];
[inv invoke];
FutureNSScrollerStyle result;
[inv getReturnValue:&result];
return result;
}
@implementation NSScroller (Future)
- (FutureNSScrollerStyle)futureScrollerStyle
{
if ([self respondsToSelector:@selector(scrollerStyle)]) {
return GetScrollerStyle(self);
} else {
return FutureNSScrollerStyleLegacy;
}
}
@end
@implementation NSScrollView (Future)
- (FutureNSScrollerStyle)futureScrollerStyle
{
if ([self respondsToSelector:@selector(scrollerStyle)]) {
return GetScrollerStyle(self);
} else {
return FutureNSScrollerStyleLegacy;
}
}
@end
@implementation CIImage (Future)
@end
@implementation NSObject (Future)
- (BOOL)performSelectorReturningBool:(SEL)selector withObjects:(NSArray *)objects {
NSMethodSignature *mySignature = [[self class] instanceMethodSignatureForSelector:selector];
NSInvocation *myInvocation = [NSInvocation invocationWithMethodSignature:mySignature];
[myInvocation setTarget:self];
[myInvocation setSelector:selector];
void *pointers[objects.count];
for (int i = 0; i < objects.count; i++) {
pointers[i] = [objects objectAtIndex:i];
[myInvocation setArgument:&pointers[i] // pointer to object
atIndex:i];
}
[myInvocation invoke];
BOOL result;
[myInvocation getReturnValue:&result];
return result;
}
- (void)performSelector:(SEL)selector takingNSInteger:(NSInteger)arg {
NSMethodSignature *mySignature = [[self class] instanceMethodSignatureForSelector:selector];
NSInvocation *myInvocation = [NSInvocation invocationWithMethodSignature:mySignature];
[myInvocation setTarget:self];
[myInvocation setSelector:selector];
[myInvocation setArgument:&arg
atIndex:2];
[myInvocation invoke];
}
@end
@implementation NSScroller (future)
- (void)futureSetKnobStyle:(NSInteger)newKnobStyle {
if ([self respondsToSelector:@selector(setKnobStyle:)]) {
[self performSelector:@selector(setKnobStyle:) takingNSInteger:newKnobStyle];
}
}
@end