1.1 --- a/Release/Growl/OpenGrowlPrefPane/AEVTBuilder.m Sun Sep 27 20:52:15 2009 -0700
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,296 +0,0 @@
1.4 -//
1.5 -// AEVTBuilder.m
1.6 -//
1.7 -// Created by Michael Ash (http://www.mikeash.com/)
1.8 -//
1.9 -// Copyright (c) 2005 Ultralingua
1.10 -//
1.11 -// This software is provided 'as-is', without any express or implied
1.12 -// warranty. In no event will the authors be held liable for any
1.13 -// damages arising from the use of this software.
1.14 -//
1.15 -// Permission is granted to anyone to use this software for any
1.16 -// purpose, including commercial applications, and to alter it and
1.17 -// redistribute it freely, subject to the following restrictions:
1.18 -//
1.19 -// 1. The origin of this software must not be misrepresented; you
1.20 -// must not claim that you wrote the original software. If you use
1.21 -// this software in a product, an acknowledgment in the product
1.22 -// documentation would be appreciated but is not required.
1.23 -//
1.24 -// 2. Altered source versions must be plainly marked as such, and
1.25 -// must not be misrepresented as being the original software.
1.26 -//
1.27 -// 3. This notice may not be removed or altered from any source
1.28 -// distribution.
1.29 -//
1.30 -// Please see http://www.cocoadev.com/index.pl?AEVTBuilder for
1.31 -// information on this code.
1.32 -//
1.33 -
1.34 -#import "AEVTBuilder.h"
1.35 -
1.36 -#import <stdarg.h>
1.37 -
1.38 -
1.39 -id AEVT = nil;
1.40 -
1.41 -id RECORD = nil;
1.42 -OSType ENDRECORD = 0;
1.43 -
1.44 -id KEY = nil;
1.45 -id TYPE = nil;
1.46 -id INT = nil;
1.47 -id ENUM = nil;
1.48 -id DESC = nil;
1.49 -id DATA = nil;
1.50 -id STRING = nil;
1.51 -
1.52 -
1.53 -
1.54 -@interface AEVTBuilder : NSObject {} @end
1.55 -
1.56 -@interface AEVTRecordBuilder : NSObject {} @end
1.57 -
1.58 -@interface AEVTKeyBuilder : NSObject {} @end
1.59 -
1.60 -@interface AEVTTypeBuilder : NSObject {} @end
1.61 -
1.62 -@interface AEVTIntBuilder : NSObject {} @end
1.63 -
1.64 -@interface AEVTEnumBuilder : NSObject {} @end
1.65 -
1.66 -@interface AEVTDescNullBuilder : NSObject {} @end
1.67 -
1.68 -@interface AEVTDataBuilder : NSObject {} @end
1.69 -
1.70 -@interface AEVTStringBuilder : NSObject {} @end
1.71 -
1.72 -@interface AEVTValue32 : NSObject {
1.73 - OSType type;
1.74 - OSType value;
1.75 -}
1.76 -
1.77 -+ valueWithType:(OSType)t value:(OSType)v;
1.78 -- initWithType:(OSType)t value:(OSType)v;
1.79 -
1.80 -- (OSType)type;
1.81 -- (OSType)value;
1.82 -
1.83 -@end
1.84 -
1.85 -
1.86 -@implementation AEVTBuilder
1.87 -
1.88 -+ (void)load
1.89 -{
1.90 - if(!AEVT)
1.91 - AEVT = self;
1.92 -}
1.93 -
1.94 -+ (NSAppleEventDescriptor *)class:(OSType)eventClass id:(OSType)eventId target:(ProcessSerialNumber)psn, ...
1.95 -{
1.96 - NSAppleEventDescriptor *targetDesc = [NSAppleEventDescriptor descriptorWithDescriptorType:'psn ' bytes:&psn length:sizeof(psn)];
1.97 - NSAppleEventDescriptor *descriptor = [NSAppleEventDescriptor
1.98 - appleEventWithEventClass:eventClass
1.99 - eventID:eventId
1.100 - targetDescriptor:targetDesc
1.101 - returnID:kAutoGenerateReturnID
1.102 - transactionID:kAnyTransactionID];
1.103 -
1.104 - va_list args;
1.105 - va_start(args, psn);
1.106 -
1.107 - id key;
1.108 - id value;
1.109 - for(;;)
1.110 - {
1.111 - key = va_arg(args, id);
1.112 - if(!key) break;
1.113 - value = va_arg(args, id);
1.114 -
1.115 - [descriptor setDescriptor:value forKeyword:[key unsignedIntValue]];
1.116 - }
1.117 -
1.118 - va_end(args);
1.119 -
1.120 - return descriptor;
1.121 -}
1.122 -
1.123 -@end
1.124 -
1.125 -@implementation AEVTRecordBuilder
1.126 -
1.127 -+ (void)load
1.128 -{
1.129 - if(!RECORD)
1.130 - RECORD = self;
1.131 -}
1.132 -
1.133 -+ (id):(OSType)ostype, ...
1.134 -{
1.135 - NSAppleEventDescriptor *descriptor = [NSAppleEventDescriptor recordDescriptor];
1.136 -
1.137 - va_list args;
1.138 - va_start(args, ostype);
1.139 -
1.140 - id key;
1.141 - id value;
1.142 - for(;;)
1.143 - {
1.144 - key = va_arg(args, id);
1.145 - if(!key) break;
1.146 - value = va_arg(args, id);
1.147 -
1.148 - [descriptor setDescriptor:value forKeyword:[key unsignedIntValue]];
1.149 - }
1.150 -
1.151 - va_end(args);
1.152 -
1.153 - AEDesc coercedDesc;
1.154 - OSStatus err = AECoerceDesc([descriptor aeDesc], ostype, &coercedDesc);
1.155 - if(err)
1.156 - {
1.157 - NSLog(@"Got error %d when calling AECoerceDesc");
1.158 - return nil;
1.159 - }
1.160 -
1.161 - NSAppleEventDescriptor *coercedDescriptor = [[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&coercedDesc];
1.162 -
1.163 - return [coercedDescriptor autorelease];
1.164 -}
1.165 -
1.166 -@end
1.167 -
1.168 -@implementation AEVTKeyBuilder
1.169 -
1.170 -+ (void)load
1.171 -{
1.172 - if(!KEY)
1.173 - KEY = self;
1.174 -}
1.175 -
1.176 -+ (id):(OSType)ostype, ...
1.177 -{
1.178 - return [NSNumber numberWithUnsignedInt:ostype];
1.179 -}
1.180 -
1.181 -@end
1.182 -
1.183 -@implementation AEVTTypeBuilder
1.184 -
1.185 -+ (void)load
1.186 -{
1.187 - if(!TYPE)
1.188 - TYPE = self;
1.189 -}
1.190 -
1.191 -+ (id):(OSType)ostype, ...
1.192 -{
1.193 - return [NSAppleEventDescriptor descriptorWithTypeCode:ostype];
1.194 -}
1.195 -
1.196 -@end
1.197 -
1.198 -@implementation AEVTIntBuilder
1.199 -
1.200 -+ (void)load
1.201 -{
1.202 - if(!INT)
1.203 - INT = self;
1.204 -}
1.205 -
1.206 -+ (id):(OSType)ostype, ...
1.207 -{
1.208 - return [NSAppleEventDescriptor descriptorWithInt32:ostype];
1.209 -}
1.210 -
1.211 -@end
1.212 -
1.213 -@implementation AEVTEnumBuilder
1.214 -
1.215 -+ (void)load
1.216 -{
1.217 - if(!ENUM)
1.218 - ENUM = self;
1.219 -}
1.220 -
1.221 -+ (id):(OSType)ostype, ...
1.222 -{
1.223 - return [NSAppleEventDescriptor descriptorWithEnumCode:ostype];
1.224 -}
1.225 -
1.226 -@end
1.227 -
1.228 -@implementation AEVTDescNullBuilder
1.229 -
1.230 -+ (void)load
1.231 -{
1.232 - if(!DESC)
1.233 - DESC = self;
1.234 -}
1.235 -
1.236 -+ (id)null
1.237 -{
1.238 - return [NSAppleEventDescriptor nullDescriptor];
1.239 -}
1.240 -
1.241 -@end
1.242 -
1.243 -@implementation AEVTDataBuilder
1.244 -
1.245 -+ (void)load
1.246 -{
1.247 - if(!DATA)
1.248 - DATA = self;
1.249 -}
1.250 -
1.251 -+ (id):(OSType)ostype, ...
1.252 -{
1.253 - va_list args;
1.254 - va_start(args, ostype);
1.255 -
1.256 - id data = va_arg(args, id);
1.257 -
1.258 - NSAppleEventDescriptor *descriptor = [NSAppleEventDescriptor descriptorWithDescriptorType:ostype data:data];
1.259 -
1.260 - va_end(args);
1.261 -
1.262 - return descriptor;
1.263 -}
1.264 -
1.265 -@end
1.266 -
1.267 -@implementation AEVTStringBuilder
1.268 -
1.269 -+ (void)load
1.270 -{
1.271 - if(!STRING)
1.272 - STRING = self;
1.273 -}
1.274 -
1.275 -+ (id):(NSString *)string
1.276 -{
1.277 - return [NSAppleEventDescriptor descriptorWithString:string];
1.278 -}
1.279 -
1.280 -@end
1.281 -
1.282 -
1.283 -@implementation NSAppleEventDescriptor (AEVTConvenienceMethods)
1.284 -
1.285 -- (NSAppleEventDescriptor *)sendWithImmediateReply
1.286 -{
1.287 - AppleEvent reply;
1.288 - OSStatus err = AESendMessage([self aeDesc], &reply, kAEWaitReply, kAEDefaultTimeout);
1.289 - NSAppleEventDescriptor *replyDescriptor = nil;
1.290 -
1.291 - if(err == noErr)
1.292 - {
1.293 - replyDescriptor = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&reply] autorelease];
1.294 - }
1.295 -
1.296 - return replyDescriptor;
1.297 -}
1.298 -
1.299 -@end