accessibility_core 0.4.3 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,16 +1,16 @@
1
+ #ifndef ACCESSIBILITY_BRIDGE
2
+ #define ACCESSIBILITY_BRIDGE
3
+
1
4
  #include "ruby.h"
2
5
  #import <Cocoa/Cocoa.h>
3
6
 
4
-
5
7
  // these functions are available on MacRuby as well as MRI
6
- void spin(double seconds);
8
+ void spin(const double seconds);
7
9
 
8
10
  // initialize all the dynamic data (e.g. class pointers)
9
11
  void Init_bridge();
10
12
 
11
13
 
12
- #ifdef NOT_MACRUBY
13
-
14
14
  extern VALUE rb_cData;
15
15
  extern VALUE rb_cAttributedString;
16
16
  extern VALUE rb_mAccessibility;
@@ -35,141 +35,139 @@ extern ID sel_to_s;
35
35
  extern ID sel_parse;
36
36
 
37
37
 
38
- #define WRAP_OBJC(klass, finalizer) do { \
39
- return Data_Wrap_Struct(klass, NULL, finalizer, (void*)obj); \
40
- } while (false);
38
+ #define WRAP_OBJC(klass, finalizer) \
39
+ return Data_Wrap_Struct(klass, NULL, finalizer, (void*)obj);
41
40
 
42
- #define UNWRAP_OBJC(klass) do { \
41
+ #define UNWRAP_OBJC(klass) \
43
42
  klass* unwrapped; \
44
43
  Data_Get_Struct(obj, klass, unwrapped); \
45
- return unwrapped; \
46
- } while (false);
44
+ return unwrapped;
47
45
 
48
- #define OBJC_EQUALITY(type, unwrapper) do { \
46
+ #define OBJC_EQUALITY(type, unwrapper) \
49
47
  if (CLASS_OF(other) == type) \
50
48
  if ([unwrapper(self) isEqual:unwrapper(other)]) \
51
49
  return Qtrue; \
52
- return Qfalse; \
53
- } while (false);
54
-
55
- #define WRAP_ARRAY(wrapper) do { \
56
- CFTypeRef obj = NULL; \
57
- CFIndex length = CFArrayGetCount(array); \
58
- VALUE ary = rb_ary_new2(length); \
59
- \
60
- for (CFIndex idx = 0; idx < length; idx++) { \
61
- obj = CFArrayGetValueAtIndex(array, idx); \
62
- CFRetain(obj); \
63
- rb_ary_store(ary, idx, wrapper(obj)); \
64
- } \
65
- \
66
- return ary; \
67
- } while (false);
68
-
69
-
70
- void cf_finalizer(void* obj);
71
- void objc_finalizer(void* obj);
72
-
73
- VALUE wrap_unknown(CFTypeRef obj);
74
- CFTypeRef unwrap_unknown(VALUE obj);
75
-
76
- VALUE wrap_point(CGPoint point);
77
- CGPoint unwrap_point(VALUE point);
78
-
79
- VALUE wrap_size(CGSize size);
80
- CGSize unwrap_size(VALUE size);
81
-
82
- VALUE wrap_rect(CGRect rect);
83
- VALUE coerce_to_rect(VALUE obj);
84
- CGRect unwrap_rect(VALUE rect);
85
-
86
- VALUE convert_cf_range(CFRange range);
87
- CFRange convert_rb_range(VALUE range);
88
-
89
- VALUE wrap_value_point(AXValueRef value);
90
- VALUE wrap_value_size(AXValueRef value);
91
- VALUE wrap_value_rect(AXValueRef value);
92
- VALUE wrap_value_range(AXValueRef value);
93
- VALUE wrap_value_error(AXValueRef value);
94
- VALUE wrap_value(AXValueRef value);
95
- VALUE wrap_array_values(CFArrayRef array);
96
-
97
- AXValueRef unwrap_value_point(VALUE val);
98
- AXValueRef unwrap_value_size(VALUE val);
99
- AXValueRef unwrap_value_rect(VALUE val);
100
- AXValueRef unwrap_value_range(VALUE val);
101
- AXValueRef unwrap_value(VALUE value);
102
-
103
- VALUE wrap_ref(AXUIElementRef ref);
104
- VALUE wrap_array_refs(CFArrayRef array);
105
- AXUIElementRef unwrap_ref(VALUE obj);
106
-
107
- VALUE wrap_string(CFStringRef string);
108
- VALUE wrap_nsstring(NSString* string);
109
- VALUE wrap_array_strings(CFArrayRef array);
110
- VALUE wrap_array_nsstrings(NSArray* ary);
111
- CFStringRef unwrap_string(VALUE string);
112
- NSString* unwrap_nsstring(VALUE string);
113
-
114
- VALUE wrap_long(CFNumberRef num);
115
- VALUE wrap_long_long(CFNumberRef num);
116
- VALUE wrap_float(CFNumberRef num);
50
+ return Qfalse;
51
+
52
+ #define WRAP_ARRAY(wrapper) \
53
+ const CFIndex length = CFArrayGetCount(array); \
54
+ const VALUE new_ary = rb_ary_new2(length); \
55
+ \
56
+ for (CFIndex idx = 0; idx < length; idx++) { \
57
+ CFTypeRef const obj = CFArrayGetValueAtIndex(array, idx); \
58
+ CFRetain(obj); \
59
+ rb_ary_store(new_ary, idx, wrapper(obj)); \
60
+ } \
61
+ \
62
+ return new_ary;
63
+
64
+
65
+ static void __attribute__ ((unused))
66
+ cf_finalizer(void* obj) { CFRelease((CFTypeRef)obj); }
67
+
68
+ static void __attribute__ ((unused))
69
+ objc_finalizer(void* obj) { [(id)obj release]; }
70
+
71
+ VALUE wrap_unknown(CFTypeRef const obj);
72
+ CFTypeRef unwrap_unknown(const VALUE obj);
73
+
74
+ VALUE wrap_point(const CGPoint point);
75
+ CGPoint unwrap_point(const VALUE point);
76
+
77
+ VALUE wrap_size(const CGSize size);
78
+ CGSize unwrap_size(const VALUE size);
79
+
80
+ VALUE wrap_rect(const CGRect rect);
81
+ VALUE coerce_to_rect(const VALUE obj);
82
+ CGRect unwrap_rect(const VALUE rect);
83
+
84
+ VALUE convert_cf_range(const CFRange range);
85
+ CFRange convert_rb_range(const VALUE range);
86
+
87
+ VALUE wrap_value_point(AXValueRef const value);
88
+ VALUE wrap_value_size(AXValueRef const value);
89
+ VALUE wrap_value_rect(AXValueRef const value);
90
+ VALUE wrap_value_range(AXValueRef const value);
91
+ VALUE wrap_value_error(AXValueRef const value);
92
+ VALUE wrap_value(AXValueRef const value);
93
+ VALUE wrap_array_values(CFArrayRef const array);
94
+
95
+ AXValueRef unwrap_value_point(const VALUE val);
96
+ AXValueRef unwrap_value_size(const VALUE val);
97
+ AXValueRef unwrap_value_rect(const VALUE val);
98
+ AXValueRef unwrap_value_range(const VALUE val);
99
+ AXValueRef unwrap_value(const VALUE value);
100
+
101
+ VALUE wrap_ref(AXUIElementRef const ref);
102
+ VALUE wrap_array_refs(CFArrayRef const array);
103
+ AXUIElementRef unwrap_ref(const VALUE obj);
104
+
105
+ VALUE wrap_string(CFStringRef const string);
106
+ VALUE wrap_nsstring(NSString* const string);
107
+ VALUE wrap_array_strings(CFArrayRef const array);
108
+ VALUE wrap_array_nsstrings(NSArray* const ary);
109
+ CFStringRef unwrap_string(const VALUE string);
110
+ NSString* unwrap_nsstring(const VALUE string);
111
+
112
+ VALUE wrap_long(CFNumberRef const num);
113
+ VALUE wrap_long_long(CFNumberRef const num);
114
+ VALUE wrap_float(CFNumberRef const num);
117
115
  // Generic CFNumber wrapper, use it if you do not
118
116
  // know the primitive type of number
119
- VALUE wrap_number(CFNumberRef number);
120
- VALUE wrap_array_numbers(CFArrayRef array);
121
-
122
- CFNumberRef unwrap_long(VALUE num);
123
- CFNumberRef unwrap_long_long(VALUE num);
124
- CFNumberRef unwrap_float(VALUE num);
125
- CFNumberRef unwrap_number(VALUE number);
126
-
127
- VALUE wrap_url(CFURLRef url);
128
- VALUE wrap_nsurl(NSURL* url);
129
- CFURLRef unwrap_url(VALUE url);
130
- NSURL* unwrap_nsurl(VALUE url);
131
- VALUE wrap_array_urls(CFArrayRef array);
132
-
133
- VALUE wrap_date(CFDateRef date);
134
- VALUE wrap_nsdate(NSDate* date);
135
- VALUE wrap_array_dates(CFArrayRef array);
136
- CFDateRef unwrap_date(VALUE date);
137
-
138
- VALUE wrap_boolean(CFBooleanRef bool_val);
139
- VALUE wrap_array_booleans(CFArrayRef array);
140
- CFBooleanRef unwrap_boolean(VALUE bool_val);
141
-
142
- VALUE wrap_data(CFDataRef data);
143
- VALUE wrap_nsdata(NSData* data);
144
- CFDataRef unwrap_data(VALUE data);
145
- NSData* unwrap_nsdata(VALUE data);
117
+ VALUE wrap_number(CFNumberRef const number);
118
+ VALUE wrap_array_numbers(CFArrayRef const array);
119
+
120
+ CFNumberRef unwrap_long(const VALUE num);
121
+ CFNumberRef unwrap_long_long(const VALUE num);
122
+ CFNumberRef unwrap_float(const VALUE num);
123
+ CFNumberRef unwrap_number(const VALUE number);
124
+
125
+ VALUE wrap_url(CFURLRef const url);
126
+ VALUE wrap_nsurl(NSURL* const url);
127
+ CFURLRef unwrap_url(const VALUE url);
128
+ NSURL* unwrap_nsurl(const VALUE url);
129
+ VALUE wrap_array_urls(CFArrayRef const array);
130
+
131
+ VALUE wrap_date(CFDateRef const date);
132
+ VALUE wrap_nsdate(NSDate* const date);
133
+ VALUE wrap_array_dates(CFArrayRef const array);
134
+ CFDateRef unwrap_date(const VALUE date);
135
+
136
+ VALUE wrap_boolean(CFBooleanRef const bool_val);
137
+ VALUE wrap_array_booleans(CFArrayRef const array);
138
+ CFBooleanRef unwrap_boolean(const VALUE bool_val);
139
+
140
+ VALUE wrap_data(CFDataRef const data);
141
+ VALUE wrap_nsdata(NSData* const data);
142
+ CFDataRef unwrap_data(const VALUE data);
143
+ NSData* unwrap_nsdata(const VALUE data);
146
144
 
147
145
  // this function assumes that arrays are homogeneous;
148
146
  // which is usually the case coming from the CF world
149
- VALUE wrap_array(CFArrayRef array);
150
-
151
- VALUE wrap_dictionary(NSDictionary* dict);
152
- VALUE wrap_array_dictionaries(CFArrayRef array);
153
-
154
- VALUE to_ruby(CFTypeRef obj);
155
- CFTypeRef to_ax(VALUE obj);
156
-
157
- VALUE wrap_screen(NSScreen* screen);
158
- VALUE wrap_array_screens(CFArrayRef array);
159
- NSScreen* unwrap_screen(VALUE screen);
160
-
161
- VALUE wrap_attributed_string(CFAttributedStringRef string);
162
- VALUE wrap_nsattributed_string(NSAttributedString* string);
163
- VALUE wrap_array_attributed_strings(CFArrayRef array);
164
- VALUE wrap_array_nsattributed_strings(NSArray* ary);
165
- CFAttributedStringRef unwrap_attributed_string(VALUE string);
166
- NSAttributedString* unwrap_nsattributed_string(VALUE string);
167
-
168
- VALUE wrap_data(CFDataRef data);
169
- VALUE wrap_nsdata(NSData* data);
170
- VALUE wrap_array_data(CFArrayRef array);
171
- VALUE wrap_array_nsdata(NSArray* array);
172
- CFDataRef unwrap_data(VALUE data);
173
- NSData* unwrap_nsdata(VALUE data);
147
+ VALUE wrap_array(CFArrayRef const array);
148
+
149
+ VALUE wrap_dictionary(NSDictionary* const dict);
150
+ VALUE wrap_array_dictionaries(CFArrayRef const array);
151
+
152
+ VALUE to_ruby(CFTypeRef const obj);
153
+ CFTypeRef to_ax(const VALUE obj);
154
+
155
+ VALUE wrap_screen(NSScreen* const screen);
156
+ VALUE wrap_array_screens(CFArrayRef const array);
157
+ NSScreen* unwrap_screen(const VALUE screen);
158
+
159
+ VALUE wrap_attributed_string(CFAttributedStringRef const string);
160
+ VALUE wrap_nsattributed_string(NSAttributedString* const string);
161
+ VALUE wrap_array_attributed_strings(CFArrayRef const array);
162
+ VALUE wrap_array_nsattributed_strings(NSArray* const ary);
163
+ CFAttributedStringRef unwrap_attributed_string(const VALUE string);
164
+ NSAttributedString* unwrap_nsattributed_string(const VALUE string);
165
+
166
+ VALUE wrap_data(CFDataRef const data);
167
+ VALUE wrap_nsdata(NSData* const data);
168
+ VALUE wrap_array_data(CFArrayRef const array);
169
+ VALUE wrap_array_nsdata(NSArray* const array);
170
+ CFDataRef unwrap_data(const VALUE data);
171
+ NSData* unwrap_nsdata(const VALUE data);
174
172
 
175
173
  #endif
@@ -4,19 +4,14 @@ $CFLAGS << ' -std=c99 -Wall -Werror -pedantic -ObjC'
4
4
  $LIBS << ' -framework CoreFoundation -framework ApplicationServices -framework Cocoa'
5
5
  $LIBS << ' -framework CoreGraphics' unless `sw_vers -productVersion`.to_f == 10.7
6
6
 
7
- if RUBY_ENGINE == 'macruby'
8
- $CFLAGS << ' -fobjc-gc'
9
- else
10
- unless RbConfig::CONFIG["CC"].match /clang/
11
- clang = `which clang`.chomp
12
- if clang.empty?
13
- raise "Clang not installed. Cannot build C extension"
14
- else
15
- RbConfig::MAKEFILE_CONFIG["CC"] = clang
16
- RbConfig::MAKEFILE_CONFIG["CXX"] = clang
17
- end
7
+ unless RbConfig::CONFIG["CC"].match(/clang/)
8
+ clang = `which clang`.chomp
9
+ if clang.empty?
10
+ raise "Clang not installed. Cannot build C extension"
11
+ else
12
+ RbConfig::MAKEFILE_CONFIG["CC"] = clang
13
+ RbConfig::MAKEFILE_CONFIG["CXX"] = clang
18
14
  end
19
- $CFLAGS << ' -DNOT_MACRUBY'
20
15
  end
21
16
 
22
17
  create_makefile 'accessibility/bridge/bridge'
@@ -3,8 +3,6 @@
3
3
  #import <Cocoa/Cocoa.h>
4
4
 
5
5
 
6
- #ifdef NOT_MACRUBY /* This entire extension is pointless when running on MacRuby */
7
-
8
6
  static ID ivar_attrs;
9
7
  static ID ivar_param_attrs;
10
8
  static ID ivar_actions;
@@ -23,124 +21,96 @@ static ID rate_zomg;
23
21
 
24
22
  static
25
23
  VALUE
26
- handle_error(VALUE self, AXError code)
24
+ handle_error(VALUE self, const AXError code)
27
25
  {
28
26
  @autoreleasepool {
29
- NSString* description = (NSString*)CFCopyDescription(unwrap_ref(self));
27
+ NSString* const description =
28
+ (NSString* const)CFCopyDescription(unwrap_ref(self));
30
29
  [description autorelease];
31
30
 
32
- const char* inspected_self = CFStringGetCStringPtr(
33
- (CFStringRef)description,
34
- kCFStringEncodingUTF8
35
- );
31
+ const char* const inspected_self = description.UTF8String;
36
32
 
37
- switch (code)
38
- {
39
- case kAXErrorSuccess:
40
- rb_raise(
41
- rb_eRuntimeError,
42
- "internal accessibility_core error"
43
- );
44
- case kAXErrorFailure:
45
- rb_raise(
46
- rb_eRuntimeError,
47
- "An accessibility system failure, possibly an allocation " \
33
+ switch (code) {
34
+ case kAXErrorSuccess:
35
+ rb_raise(rb_eRuntimeError,
36
+ "internal accessibility_core error");
37
+
38
+ case kAXErrorFailure:
39
+ rb_raise(rb_eRuntimeError,
40
+ "An accessibility system failure, possibly an allocation "
48
41
  "failure, occurred with %s; stopping to be safe",
49
- inspected_self
50
- );
51
- case kAXErrorIllegalArgument:
52
- rb_raise(
53
- rb_eArgError,
42
+ inspected_self);
43
+
44
+ case kAXErrorIllegalArgument:
45
+ rb_raise(rb_eArgError,
54
46
  "illegal argument was passed to the method for %s",
55
- inspected_self
56
- );
57
- case kAXErrorInvalidUIElement:
58
- rb_raise(
59
- rb_eArgError,
47
+ inspected_self);
48
+
49
+ case kAXErrorInvalidUIElement:
50
+ rb_raise(rb_eArgError,
60
51
  "invalid element `%s' (probably dead)",
61
- inspected_self
62
- );
63
- case kAXErrorInvalidUIElementObserver:
64
- rb_raise(
65
- rb_eArgError,
52
+ inspected_self);
53
+
54
+ case kAXErrorInvalidUIElementObserver:
55
+ rb_raise(rb_eArgError,
66
56
  "invalid observer passed to the method for %s",
67
- inspected_self
68
- );
69
- case kAXErrorCannotComplete:
57
+ inspected_self);
58
+
59
+ case kAXErrorCannotComplete:
70
60
  spin(0);
71
- pid_t pid = 0;
61
+
62
+ pid_t pid = 0;
72
63
  AXUIElementGetPid(unwrap_ref(self), &pid);
73
- NSRunningApplication* app = [NSRunningApplication runningApplicationWithProcessIdentifier:pid];
64
+ NSRunningApplication* const app =
65
+ [NSRunningApplication runningApplicationWithProcessIdentifier:pid];
66
+
74
67
  if (app)
75
- rb_raise(
76
- rb_eRuntimeError,
77
- "accessibility messaging failure. " \
78
- "Perhaps the application is busy on unresponsive?"
79
- );
68
+ rb_raise(rb_eRuntimeError,
69
+ "accessibility messaging failure. "
70
+ "Perhaps the application is busy on unresponsive?");
80
71
  else
81
- rb_raise(
82
- rb_eRuntimeError,
83
- "application for pid=%d is no longer running. " \
84
- "Maybe it crashed?",
85
- pid
86
- );
87
- case kAXErrorAttributeUnsupported:
88
- rb_raise(
89
- rb_eArgError,
90
- "attribute unsupported"
91
- );
92
- case kAXErrorActionUnsupported:
93
- rb_raise(
94
- rb_eArgError,
95
- "action unsupported"
96
- );
97
- case kAXErrorNotificationUnsupported:
98
- rb_raise(
99
- rb_eArgError,
100
- "notification unsupported"
101
- );
102
- case kAXErrorNotImplemented:
103
- rb_raise(
104
- rb_eNotImpError,
105
- "method not supported by the receiver"
106
- );
107
- case kAXErrorNotificationAlreadyRegistered:
108
- rb_raise(
109
- rb_eArgError,
110
- "notification has already been registered"
111
- );
112
- case kAXErrorNotificationNotRegistered:
113
- rb_raise(
114
- rb_eRuntimeError,
115
- "notification is not registered yet"
116
- );
117
- case kAXErrorAPIDisabled:
118
- rb_raise(
119
- rb_eRuntimeError,
120
- "AXAPI has been disabled"
121
- );
122
- case kAXErrorNoValue:
123
- rb_raise(
124
- rb_eRuntimeError,
125
- "accessibility_core internal error; " \
126
- "should be handled internally"
127
- );
128
- case kAXErrorParameterizedAttributeUnsupported:
129
- rb_raise(
130
- rb_eArgError,
131
- "parameterized attribute unsupported"
132
- );
133
- case kAXErrorNotEnoughPrecision:
134
- rb_raise(
135
- rb_eRuntimeError,
136
- "AXAPI said there was not enough precision ¯\\(°_o)/¯"
137
- );
138
- default:
139
- rb_raise(
140
- rb_eRuntimeError,
72
+ rb_raise(rb_eRuntimeError,
73
+ "application for pid=%d is no longer running. "
74
+ "Maybe it crashed?",
75
+ pid);
76
+
77
+ case kAXErrorAttributeUnsupported:
78
+ rb_raise(rb_eArgError, "attribute unsupported");
79
+
80
+ case kAXErrorActionUnsupported:
81
+ rb_raise(rb_eArgError, "action unsupported");
82
+
83
+ case kAXErrorNotificationUnsupported:
84
+ rb_raise(rb_eArgError, "notification unsupported");
85
+
86
+ case kAXErrorNotImplemented:
87
+ rb_raise(rb_eNotImpError, "method not supported by the receiver");
88
+
89
+ case kAXErrorNotificationAlreadyRegistered:
90
+ rb_raise(rb_eArgError, "notification has already been registered");
91
+
92
+ case kAXErrorNotificationNotRegistered:
93
+ rb_raise(rb_eRuntimeError, "notification is not registered yet");
94
+
95
+ case kAXErrorAPIDisabled:
96
+ rb_raise(rb_eRuntimeError, "AXAPI has been disabled");
97
+
98
+ case kAXErrorNoValue:
99
+ rb_raise(rb_eRuntimeError,
100
+ "accessibility_core internal error; "
101
+ "should be handled internally");
102
+
103
+ case kAXErrorParameterizedAttributeUnsupported:
104
+ rb_raise(rb_eArgError, "parameterized attribute unsupported");
105
+
106
+ case kAXErrorNotEnoughPrecision:
107
+ rb_raise(rb_eRuntimeError,
108
+ "AXAPI said there was not enough precision ¯\\(°_o)/¯");
109
+
110
+ default:
111
+ rb_raise(rb_eRuntimeError,
141
112
  "accessibility_core majorly goofed [%d]",
142
- code
143
- );
113
+ (int)code);
144
114
  }
145
115
  }
146
116
 
@@ -761,7 +731,6 @@ rb_acore_equality(VALUE self, VALUE other)
761
731
  return Qtrue;
762
732
  return Qfalse;
763
733
  }
764
- #endif
765
734
 
766
735
 
767
736
  void
@@ -769,7 +738,6 @@ Init_core()
769
738
  {
770
739
  Init_bridge();
771
740
 
772
- #ifdef NOT_MACRUBY
773
741
  #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_9
774
742
  if (!AXAPIEnabled())
775
743
  rb_raise(
@@ -871,5 +839,4 @@ Init_core()
871
839
  rb_define_method(rb_cElement, "element_at", rb_acore_element_at, 1);
872
840
  rb_define_method(rb_cElement, "==", rb_acore_equality, 1);
873
841
 
874
- #endif
875
842
  }