-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNSAppleEventDescriptorHelperCategory.m
More file actions
176 lines (146 loc) · 4.9 KB
/
Copy pathNSAppleEventDescriptorHelperCategory.m
File metadata and controls
176 lines (146 loc) · 4.9 KB
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
171
172
173
174
175
176
///////////////////////////////////////////////////////////////////////////////
//
// DESCRIPTION
// Apple Event Descriptors helper
//
// COPYRIGHT
// Copyright (c) 2008 - 2020 Wacom Co., Ltd.
// All rights reserved
//
///////////////////////////////////////////////////////////////////////////////
#import "NSAppleEventDescriptorHelperCategory.h"
@implementation NSAppleEventDescriptor (WacomExtension)
//////////////////////////////////////////////////////////////////////////////
//
// Purpose:
// Create an autoreleased NSAppleEventDescriptor instance for an Apple Event
// object from type objType, key keyDesc, and form key.
//
// Parameters:
// objType_I - The object class of the desired Apple event objects.
// keyDesc_I - The key data for the object specifier.
// keyForm_I - The key form for the object specifier.
//
// Return:
// An NSAppleEventDescriptor instance or nil in case of error.
//
// Notes:
// This is used to create descriptor for an object that has no container.
//
+ (NSAppleEventDescriptor *) descriptorForObjectOfType:(DescType)objType_I
withKey:(NSAppleEventDescriptor *)keyDesc_I
ofForm:(DescType)keyForm_I
{
NSAppleEventDescriptor * __autoreleasing result = nil;
AEDesc resultDesc;
OSErr err = CreateObjSpecifier(objType_I,
(AEDesc*)[[NSAppleEventDescriptor nullDescriptor] aeDesc], // null descriptor means no container
keyForm_I,
(AEDesc*)[keyDesc_I aeDesc],
NO,
&resultDesc);
if (err == noErr)
{
result = [[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&resultDesc];
}
return result;
}
//////////////////////////////////////////////////////////////////////////////
//
// Purpose:
// Create an autoreleased NSAppleEventDescriptor instance for an Apple Event
// object from type objType, key keyDesc, and form key.
//
// Parameters:
// objType - The object class of the desired Apple event objects.
// keyDesc - The key data for the object specifier record.
// keyForm - The key form for the object specifier record.
// fromDesc - The container object of the requested Apple Event object.
//
// Return:
// An NSAppleEventDescriptor instance or nil in case of error.
//
+ (NSAppleEventDescriptor *) descriptorForObjectOfType:(DescType)objType_I
withKey:(NSAppleEventDescriptor *)keyDesc_I
ofForm:(DescType)keyForm_I
from:(NSAppleEventDescriptor *)fromDesc_I
{
NSAppleEventDescriptor * __autoreleasing result = nil;
AEDesc resultDesc;
OSErr err = CreateObjSpecifier(objType_I,
(AEDesc*)[fromDesc_I aeDesc],
keyForm_I,
(AEDesc*)[keyDesc_I aeDesc],
NO,
&resultDesc);
if (err == noErr)
{
result = [[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&resultDesc];
}
return result;
}
//////////////////////////////////////////////////////////////////////////////
//
// Purpose:
// Create and return an autoreleased NSAppleEventDescriptor that contains
// an UIInt32 value.
//
// Parameters:
// unsignedInt - The UInt32 value to place into the Apple Event descriptor.
//
// Return:
// An NSAppleEventDescriptor instance that represents an UIInt32 value.
//
+ (NSAppleEventDescriptor *)descriptorWithUInt32:(UInt32)unsignedInt_I
{
return [NSAppleEventDescriptor descriptorWithDescriptorType:typeUInt32
bytes:&unsignedInt_I length:sizeof(unsignedInt_I)];
}
//////////////////////////////////////////////////////////////////////////////
//
// Purpose:
// Send the Apple Event represented by this NSAppleEventDescriptor
// without waiting for a reply from the target.
//
// Parameters:
// priority - Priority for the delivery of the Apple Event.
// timeout - Timeout in ticks.
//
// Return:
// An OSErr code.
//
- (OSErr) sendWithPriority:(UInt32)__unused priority_I andTimeout:(UInt32)timeout_I
{
// Send the apple event without waiting for a reply.
return (OSErr)AESendMessage([self aeDesc], NULL, kAENoReply, timeout_I);
}
//////////////////////////////////////////////////////////////////////////////
//
// Purpose:
// Send the Apple Event represented by this NSAppleEventDescriptor.
// This method waits for a reply from the target and returns the reply
// as an NSAppleEventDescriptor.
//
// Parameters:
// priority - Priority for the delivery of the Apple Event.
// timeout - Timeout in ticks.
//
// Return:
// An autoreleased NSAppleEventDescriptor that contains the reply or
// nil if error occurs.
//
- (NSAppleEventDescriptor*) sendExpectingReplyWithPriority:(UInt32)__unused priority_I
andTimeout:(UInt32)timeout_I
{
NSAppleEventDescriptor * __autoreleasing result = nil;
AppleEvent resultDesc;
// send the apple event
OSStatus err = AESendMessage([self aeDesc], &resultDesc, kAEWaitReply, timeout_I);
// get the reply
if (err == noErr)
{
result = [[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&resultDesc];
}
return result;
}
@end