-
Notifications
You must be signed in to change notification settings - Fork 6
/
bridge.h
170 lines (135 loc) · 5.69 KB
/
bridge.h
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
#pragma once
#include "ruby.h"
#import <Cocoa/Cocoa.h>
// these functions are available on MacRuby as well as MRI
void spin(const double seconds);
// initialize all the dynamic data (e.g. class pointers)
void Init_bridge();
extern VALUE rb_cData;
extern VALUE rb_cAttributedString;
extern VALUE rb_mAccessibility;
extern VALUE rb_cElement;
extern VALUE rb_cCGPoint;
extern VALUE rb_cCGSize;
extern VALUE rb_cCGRect;
extern VALUE rb_mURI; // URI module
extern VALUE rb_cURI; // URI::Generic class
extern VALUE rb_cScreen;
extern ID sel_x;
extern ID sel_y;
extern ID sel_width;
extern ID sel_height;
extern ID sel_origin;
extern ID sel_size;
extern ID sel_to_point;
extern ID sel_to_size;
extern ID sel_to_rect;
extern ID sel_to_s;
extern ID sel_parse;
#define WRAP_OBJC(klass, finalizer) \
return Data_Wrap_Struct(klass, NULL, finalizer, (void*)obj);
#define UNWRAP_OBJC(klass) \
klass* unwrapped; \
Data_Get_Struct(obj, klass, unwrapped); \
return unwrapped;
#define OBJC_EQUALITY(type, unwrapper) \
if (CLASS_OF(other) == type) \
if ([unwrapper(self) isEqual:unwrapper(other)]) \
return Qtrue; \
return Qfalse;
#define WRAP_ARRAY(wrapper) \
const CFIndex length = CFArrayGetCount(array); \
const VALUE new_ary = rb_ary_new2(length); \
\
for (CFIndex idx = 0; idx < length; idx++) { \
CFTypeRef const obj = CFArrayGetValueAtIndex(array, idx); \
CFRetain(obj); \
rb_ary_store(new_ary, idx, wrapper(obj)); \
} \
\
return new_ary;
static void __attribute__ ((unused))
cf_finalizer(void* obj) { CFRelease((CFTypeRef)obj); }
static void __attribute__ ((unused))
objc_finalizer(void* obj) { [(id)obj release]; }
VALUE wrap_unknown(CFTypeRef const obj);
CFTypeRef unwrap_unknown(const VALUE obj);
VALUE wrap_point(const CGPoint point);
CGPoint unwrap_point(const VALUE point);
VALUE wrap_size(const CGSize size);
CGSize unwrap_size(const VALUE size);
VALUE wrap_rect(const CGRect rect);
VALUE coerce_to_rect(const VALUE obj);
CGRect unwrap_rect(const VALUE rect);
VALUE convert_cf_range(const CFRange range);
CFRange convert_rb_range(const VALUE range);
VALUE wrap_value_point(AXValueRef const value);
VALUE wrap_value_size(AXValueRef const value);
VALUE wrap_value_rect(AXValueRef const value);
VALUE wrap_value_range(AXValueRef const value);
VALUE wrap_value_error(AXValueRef const value);
VALUE wrap_value(AXValueRef const value);
VALUE wrap_array_values(CFArrayRef const array);
AXValueRef unwrap_value_point(const VALUE val);
AXValueRef unwrap_value_size(const VALUE val);
AXValueRef unwrap_value_rect(const VALUE val);
AXValueRef unwrap_value_range(const VALUE val);
AXValueRef unwrap_value(const VALUE value);
VALUE wrap_ref(AXUIElementRef const ref);
VALUE wrap_array_refs(CFArrayRef const array);
AXUIElementRef unwrap_ref(const VALUE obj);
VALUE wrap_string(CFStringRef const string);
VALUE wrap_nsstring(NSString* const string);
VALUE wrap_array_strings(CFArrayRef const array);
VALUE wrap_array_nsstrings(NSArray* const ary);
CFStringRef unwrap_string(const VALUE string);
NSString* unwrap_nsstring(const VALUE string);
VALUE wrap_long(CFNumberRef const num);
VALUE wrap_long_long(CFNumberRef const num);
VALUE wrap_float(CFNumberRef const num);
// Generic CFNumber wrapper, use it if you do not
// know the primitive type of number
VALUE wrap_number(CFNumberRef const number);
VALUE wrap_array_numbers(CFArrayRef const array);
CFNumberRef unwrap_long(const VALUE num);
CFNumberRef unwrap_long_long(const VALUE num);
CFNumberRef unwrap_float(const VALUE num);
CFNumberRef unwrap_number(const VALUE number);
VALUE wrap_url(CFURLRef const url);
VALUE wrap_nsurl(NSURL* const url);
CFURLRef unwrap_url(const VALUE url);
NSURL* unwrap_nsurl(const VALUE url);
VALUE wrap_array_urls(CFArrayRef const array);
VALUE wrap_date(CFDateRef const date);
VALUE wrap_nsdate(NSDate* const date);
VALUE wrap_array_dates(CFArrayRef const array);
CFDateRef unwrap_date(const VALUE date);
VALUE wrap_boolean(CFBooleanRef const bool_val);
VALUE wrap_array_booleans(CFArrayRef const array);
CFBooleanRef unwrap_boolean(const VALUE bool_val);
VALUE wrap_data(CFDataRef const data);
VALUE wrap_nsdata(NSData* const data);
CFDataRef unwrap_data(const VALUE data);
NSData* unwrap_nsdata(const VALUE data);
// this function assumes that arrays are homogeneous;
// which is usually the case coming from the CF world
VALUE wrap_array(CFArrayRef const array);
VALUE wrap_dictionary(NSDictionary* const dict);
VALUE wrap_array_dictionaries(CFArrayRef const array);
VALUE to_ruby(CFTypeRef const obj);
CFTypeRef to_ax(const VALUE obj);
VALUE wrap_screen(NSScreen* const screen);
VALUE wrap_array_screens(CFArrayRef const array);
NSScreen* unwrap_screen(const VALUE screen);
VALUE wrap_attributed_string(CFAttributedStringRef const string);
VALUE wrap_nsattributed_string(NSAttributedString* const string);
VALUE wrap_array_attributed_strings(CFArrayRef const array);
VALUE wrap_array_nsattributed_strings(NSArray* const ary);
CFAttributedStringRef unwrap_attributed_string(const VALUE string);
NSAttributedString* unwrap_nsattributed_string(const VALUE string);
VALUE wrap_data(CFDataRef const data);
VALUE wrap_nsdata(NSData* const data);
VALUE wrap_array_data(CFArrayRef const array);
VALUE wrap_array_nsdata(NSArray* const array);
CFDataRef unwrap_data(const VALUE data);
NSData* unwrap_nsdata(const VALUE data);