1 /*****************************************************************************
6 * Created by Martin Kahr on 11.03.06 under a MIT-style license.
7 * Copyright (c) 2006 martinkahr.com. All rights reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 *****************************************************************************
29 * Note that changes made by any members or contributors of the VideoLAN team
30 * (i.e. changes that were exclusively checked in to one of VideoLAN's source code
31 * repositories) are licensed under the GNU General Public License version 2,
32 * or (at your option) any later version.
33 * Thus, the following statements apply to our changes:
35 * Copyright (C) 2006-2009 the VideoLAN team
36 * Authors: Eric Petit <titer@m0k.org>
37 * Felix Kühne <fkuehne at videolan dot org>
39 * This program is free software; you can redistribute it and/or modify
40 * it under the terms of the GNU General Public License as published by
41 * the Free Software Foundation; either version 2 of the License, or
42 * (at your option) any later version.
44 * This program is distributed in the hope that it will be useful,
45 * but WITHOUT ANY WARRANTY; without even the implied warranty of
46 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47 * GNU General Public License for more details.
49 * You should have received a copy of the GNU General Public License
50 * along with this program; if not, write to the Free Software
51 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
52 *****************************************************************************/
54 #import "AppleRemote.h"
56 /* this was added by the VideoLAN team to ensure Leopard-compatibility and is VLC-only */
59 const char* AppleRemoteDeviceName = "AppleIRController";
60 const int REMOTE_SWITCH_COOKIE=19;
61 const NSTimeInterval DEFAULT_MAXIMUM_CLICK_TIME_DIFFERENCE=0.35;
62 const NSTimeInterval HOLD_RECOGNITION_TIME_INTERVAL=0.4;
64 @implementation AppleRemote
66 #pragma public interface
69 if ( self = [super init] ) {
70 openInExclusiveMode = YES;
72 hidDeviceInterface = NULL;
73 cookieToButtonMapping = [[NSMutableDictionary alloc] init];
75 /* we're on Leopard and need to use a different set of cookies then we used to on Tiger and earlier */
76 [cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonVolume_Plus] forKey:@"31_29_28_18_"];
77 [cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonVolume_Minus] forKey:@"31_30_28_18_"];
78 [cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMenu] forKey:@"31_20_18_31_20_18_"];
79 [cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlay] forKey:@"31_21_18_31_21_18_"];
80 [cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonRight] forKey:@"31_22_18_31_22_18_"];
81 [cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonLeft] forKey:@"31_23_18_31_23_18_"];
82 [cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonRight_Hold] forKey:@"31_18_4_2_"];
83 [cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonLeft_Hold] forKey:@"31_18_3_2_"];
84 [cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMenu_Hold] forKey:@"31_18_31_18_"];
85 [cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlay_Sleep] forKey:@"35_31_18_35_31_18_"];
86 [cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteControl_Switched] forKey:@"19_"];
89 [self setSimulatesPlusMinusHold: YES];
90 maxClickTimeDifference = DEFAULT_MAXIMUM_CLICK_TIME_DIFFERENCE;
97 [self stopListening:self];
98 [cookieToButtonMapping release];
106 - (BOOL) isRemoteAvailable {
107 io_object_t hidDevice = [self findAppleRemoteDevice];
108 if (hidDevice != 0) {
109 IOObjectRelease(hidDevice);
116 - (BOOL) isListeningToRemote {
117 return (hidDeviceInterface != NULL && allCookies != NULL && queue != NULL);
120 - (void) setListeningToRemote: (BOOL) value {
122 [self stopListening:self];
124 [self startListening:self];
128 /* Delegates are not retained!
129 * http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/chapter_6_section_4.html
130 * Delegating objects do not (and should not) retain their delegates.
131 * However, clients of delegating objects (applications, usually) are responsible for ensuring that their delegates are around
132 * to receive delegation messages. To do this, they may have to retain the delegate. */
133 - (void) setDelegate: (id) _delegate {
134 if (_delegate && [_delegate respondsToSelector:@selector(appleRemoteButton:pressedDown:clickCount:)]==NO) return;
136 delegate = _delegate;
142 - (BOOL) isOpenInExclusiveMode {
143 return openInExclusiveMode;
145 - (void) setOpenInExclusiveMode: (BOOL) value {
146 openInExclusiveMode = value;
149 - (BOOL) clickCountingEnabled {
150 return clickCountEnabledButtons != 0;
152 - (void) setClickCountingEnabled: (BOOL) value {
154 [self setClickCountEnabledButtons: kRemoteButtonVolume_Plus | kRemoteButtonVolume_Minus | kRemoteButtonPlay | kRemoteButtonLeft | kRemoteButtonRight | kRemoteButtonMenu];
156 [self setClickCountEnabledButtons: 0];
160 - (unsigned int) clickCountEnabledButtons {
161 return clickCountEnabledButtons;
163 - (void) setClickCountEnabledButtons: (unsigned int)value {
164 clickCountEnabledButtons = value;
167 - (NSTimeInterval) maximumClickCountTimeDifference {
168 return maxClickTimeDifference;
170 - (void) setMaximumClickCountTimeDifference: (NSTimeInterval) timeDiff {
171 maxClickTimeDifference = timeDiff;
174 - (BOOL) processesBacklog {
175 return processesBacklog;
177 - (void) setProcessesBacklog: (BOOL) value {
178 processesBacklog = value;
181 - (BOOL) listeningOnAppActivate {
182 id appDelegate = [NSApp delegate];
183 return (appDelegate!=nil && [appDelegate isKindOfClass: [AppleRemoteApplicationDelegate class]]);
185 - (void) setListeningOnAppActivate: (BOOL) value {
187 if ([self listeningOnAppActivate]) return;
188 AppleRemoteApplicationDelegate* appDelegate = [[AppleRemoteApplicationDelegate alloc] initWithApplicationDelegate: [NSApp delegate]];
189 /* NSApp does not retain its delegate therefore we keep retain count on 1 */
190 [NSApp setDelegate: appDelegate];
192 if ([self listeningOnAppActivate]==NO) return;
193 AppleRemoteApplicationDelegate* appDelegate = (AppleRemoteApplicationDelegate*)[NSApp delegate];
194 id previousAppDelegate = [appDelegate applicationDelegate];
195 [NSApp setDelegate: previousAppDelegate];
196 [appDelegate release];
200 - (BOOL) simulatesPlusMinusHold {
201 return simulatePlusMinusHold;
203 - (void) setSimulatesPlusMinusHold: (BOOL) value {
204 simulatePlusMinusHold = value;
207 - (IBAction) startListening: (id) sender {
208 if ([self isListeningToRemote]) return;
210 io_object_t hidDevice = [self findAppleRemoteDevice];
211 if (hidDevice == 0) return;
213 if ([self createInterfaceForDevice:hidDevice] == NULL) {
217 if ([self initializeCookies]==NO) {
221 if ([self openDevice]==NO) {
227 [self stopListening:self];
230 IOObjectRelease(hidDevice);
233 - (IBAction) stopListening: (id) sender {
234 if (eventSource != NULL) {
235 CFRunLoopRemoveSource(CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
236 CFRelease(eventSource);
240 (*queue)->stop(queue);
243 (*queue)->dispose(queue);
245 //release the queue we allocated
246 (*queue)->Release(queue);
251 if (allCookies != nil) {
252 [allCookies autorelease];
256 if (hidDeviceInterface != NULL) {
258 (*hidDeviceInterface)->close(hidDeviceInterface);
260 //release the interface
261 (*hidDeviceInterface)->Release(hidDeviceInterface);
263 hidDeviceInterface = NULL;
269 @implementation AppleRemote (Singleton)
271 static AppleRemote* sharedInstance=nil;
273 + (AppleRemote*) sharedRemote {
274 @synchronized(self) {
275 if (sharedInstance == nil) {
276 sharedInstance = [[self alloc] init];
279 return sharedInstance;
281 + (id)allocWithZone:(NSZone *)zone {
282 @synchronized(self) {
283 if (sharedInstance == nil) {
284 return [super allocWithZone:zone];
287 return sharedInstance;
289 - (id)copyWithZone:(NSZone *)zone {
295 - (NSUInteger)retainCount {
296 return UINT_MAX; //denotes an object that cannot be released
307 @implementation AppleRemote (PrivateMethods)
309 - (void) setRemoteId: (int) value {
313 - (IOHIDQueueInterface**) queue {
317 - (IOHIDDeviceInterface**) hidDeviceInterface {
318 return hidDeviceInterface;
322 - (NSDictionary*) cookieToButtonMapping {
323 return cookieToButtonMapping;
326 - (NSString*) validCookieSubstring: (NSString*) cookieString {
327 if (cookieString == nil || [cookieString length] == 0) return nil;
328 NSEnumerator* keyEnum = [[self cookieToButtonMapping] keyEnumerator];
330 while(key = [keyEnum nextObject]) {
331 NSRange range = [cookieString rangeOfString:key];
332 if (range.location == 0) return key;
337 - (void) sendSimulatedPlusMinusEvent: (id) time {
338 BOOL startSimulateHold = NO;
339 AppleRemoteEventIdentifier event = lastPlusMinusEvent;
340 @synchronized(self) {
341 startSimulateHold = (lastPlusMinusEvent>0 && lastPlusMinusEventTime == [time doubleValue]);
343 if (startSimulateHold) {
344 lastEventSimulatedHold = YES;
345 event = (event==kRemoteButtonVolume_Plus) ? kRemoteButtonVolume_Plus_Hold : kRemoteButtonVolume_Minus_Hold;
346 [delegate appleRemoteButton:event pressedDown: YES clickCount: 1];
350 - (void) sendRemoteButtonEvent: (AppleRemoteEventIdentifier) event pressedDown: (BOOL) pressedDown {
352 if (simulatePlusMinusHold) {
353 if (event == kRemoteButtonVolume_Plus || event == kRemoteButtonVolume_Minus) {
355 lastPlusMinusEvent = event;
356 lastPlusMinusEventTime = [NSDate timeIntervalSinceReferenceDate];
357 [self performSelector:@selector(sendSimulatedPlusMinusEvent:)
358 withObject:[NSNumber numberWithDouble:lastPlusMinusEventTime]
359 afterDelay:HOLD_RECOGNITION_TIME_INTERVAL];
362 if (lastEventSimulatedHold) {
363 event = (event==kRemoteButtonVolume_Plus) ? kRemoteButtonVolume_Plus_Hold : kRemoteButtonVolume_Minus_Hold;
364 lastPlusMinusEvent = 0;
365 lastEventSimulatedHold = NO;
367 @synchronized(self) {
368 lastPlusMinusEvent = 0;
376 if (([self clickCountEnabledButtons] & event) == event) {
377 if (pressedDown==NO && (event == kRemoteButtonVolume_Minus || event == kRemoteButtonVolume_Plus)) {
378 return; // this one is triggered automatically by the handler
380 NSNumber* eventNumber;
381 NSNumber* timeNumber;
382 @synchronized(self) {
383 lastClickCountEventTime = [NSDate timeIntervalSinceReferenceDate];
384 if (lastClickCountEvent == event) {
385 eventClickCount = eventClickCount + 1;
389 lastClickCountEvent = event;
390 timeNumber = [NSNumber numberWithDouble:lastClickCountEventTime];
391 eventNumber= [NSNumber numberWithUnsignedInt:event];
393 [self performSelector: @selector(executeClickCountEvent:)
394 withObject: [NSArray arrayWithObjects:eventNumber, timeNumber, nil]
395 afterDelay: maxClickTimeDifference];
397 [delegate appleRemoteButton:event pressedDown: pressedDown clickCount:1];
402 - (void) executeClickCountEvent: (NSArray*) values {
403 AppleRemoteEventIdentifier event = [[values objectAtIndex: 0] unsignedIntValue];
404 NSTimeInterval eventTimePoint = [[values objectAtIndex: 1] doubleValue];
406 BOOL finishedClicking = NO;
407 int finalClickCount = eventClickCount;
409 @synchronized(self) {
410 finishedClicking = (event != lastClickCountEvent || eventTimePoint == lastClickCountEventTime);
411 if (finishedClicking) eventClickCount = 0;
414 if (finishedClicking) {
415 [delegate appleRemoteButton:event pressedDown: YES clickCount:finalClickCount];
416 if ([self simulatesPlusMinusHold]==NO && (event == kRemoteButtonVolume_Minus || event == kRemoteButtonVolume_Plus)) {
417 // trigger a button release event, too
418 [NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow:0.1]];
419 [delegate appleRemoteButton:event pressedDown: NO clickCount:finalClickCount];
425 - (void) handleEventWithCookieString: (NSString*) cookieString sumOfValues: (SInt32) sumOfValues {
427 if (previousRemainingCookieString) {
428 cookieString = [previousRemainingCookieString stringByAppendingString: cookieString];
429 NSLog(@"New cookie string is %@", cookieString);
430 [previousRemainingCookieString release], previousRemainingCookieString=nil;
432 if (cookieString == nil || [cookieString length] == 0) return;
433 NSNumber* buttonId = [[self cookieToButtonMapping] objectForKey: cookieString];
434 if (buttonId != nil) {
435 [self sendRemoteButtonEvent: [buttonId intValue] pressedDown: (sumOfValues>0)];
437 // let's see if a number of events are stored in the cookie string. this does
438 // happen when the main thread is too busy to handle all incoming events in time.
439 NSString* subCookieString;
440 NSString* lastSubCookieString=nil;
441 while(subCookieString = [self validCookieSubstring: cookieString]) {
442 cookieString = [cookieString substringFromIndex: [subCookieString length]];
443 lastSubCookieString = subCookieString;
444 if (processesBacklog) [self handleEventWithCookieString: subCookieString sumOfValues:sumOfValues];
446 if (processesBacklog == NO && lastSubCookieString != nil) {
447 // process the last event of the backlog and assume that the button is not pressed down any longer.
448 // The events in the backlog do not seem to be in order and therefore (in rare cases) the last event might be
449 // a button pressed down event while in reality the user has released it.
450 // NSLog(@"processing last event of backlog");
451 [self handleEventWithCookieString: lastSubCookieString sumOfValues:0];
453 if ([cookieString length] > 0) {
454 NSLog(@"Unknown button for cookiestring %@", cookieString);
461 /* Callback method for the device queue
462 Will be called for any event of any type (cookie) to which we subscribe
464 static void QueueCallbackFunction(void* target, IOReturn result, void* refcon, void* sender) {
465 AppleRemote* remote = (AppleRemote*)target;
467 IOHIDEventStruct event;
468 AbsoluteTime zeroTime = {0,0};
469 NSMutableString* cookieString = [NSMutableString string];
470 SInt32 sumOfValues = 0;
471 while (result == kIOReturnSuccess)
473 result = (*[remote queue])->getNextEvent([remote queue], &event, zeroTime, 0);
474 if ( result != kIOReturnSuccess )
477 //printf("%d %d %d\n", event.elementCookie, event.value, event.longValue);
479 if (REMOTE_SWITCH_COOKIE == (int)event.elementCookie) {
480 [remote setRemoteId: event.value];
481 [remote handleEventWithCookieString: @"19_" sumOfValues: 0];
483 if (((int)event.elementCookie)!=5) {
484 sumOfValues+=event.value;
485 [cookieString appendString:[NSString stringWithFormat:@"%d_", event.elementCookie]];
490 [remote handleEventWithCookieString: cookieString sumOfValues: sumOfValues];
493 @implementation AppleRemote (IOKitMethods)
495 - (IOHIDDeviceInterface**) createInterfaceForDevice: (io_object_t) hidDevice {
497 IOCFPlugInInterface** plugInInterface = NULL;
498 HRESULT plugInResult = S_OK;
500 IOReturn ioReturnValue = kIOReturnSuccess;
502 hidDeviceInterface = NULL;
504 ioReturnValue = IOObjectGetClass(hidDevice, className);
506 if (ioReturnValue != kIOReturnSuccess) {
507 NSLog(@"Error: Failed to get class name.");
511 ioReturnValue = IOCreatePlugInInterfaceForService(hidDevice,
512 kIOHIDDeviceUserClientTypeID,
513 kIOCFPlugInInterfaceID,
516 if (ioReturnValue == kIOReturnSuccess)
518 //Call a method of the intermediate plug-in to create the device interface
519 plugInResult = (*plugInInterface)->QueryInterface(plugInInterface, CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID), (LPVOID) &hidDeviceInterface);
521 if (plugInResult != S_OK) {
522 NSLog(@"Error: Couldn't create HID class device interface");
525 if (plugInInterface) (*plugInInterface)->Release(plugInInterface);
527 return hidDeviceInterface;
530 - (io_object_t) findAppleRemoteDevice {
531 CFMutableDictionaryRef hidMatchDictionary = NULL;
532 IOReturn ioReturnValue = kIOReturnSuccess;
533 io_iterator_t hidObjectIterator = 0;
534 io_object_t hidDevice = 0;
536 // Set up a matching dictionary to search the I/O Registry by class
537 // name for all HID class devices
538 hidMatchDictionary = IOServiceMatching(AppleRemoteDeviceName);
540 // Now search I/O Registry for matching devices.
541 ioReturnValue = IOServiceGetMatchingServices(kIOMasterPortDefault, hidMatchDictionary, &hidObjectIterator);
543 if ((ioReturnValue == kIOReturnSuccess) && (hidObjectIterator != 0)) {
544 hidDevice = IOIteratorNext(hidObjectIterator);
547 // release the iterator
548 IOObjectRelease(hidObjectIterator);
553 - (BOOL) initializeCookies {
554 IOHIDDeviceInterface122** handle = (IOHIDDeviceInterface122**)hidDeviceInterface;
555 IOHIDElementCookie cookie;
559 NSArray* elements = nil;
560 NSDictionary* element;
563 if (!handle || !(*handle)) return NO;
565 /* Copy all elements, since we're grabbing most of the elements
566 * for this device anyway, and thus, it's faster to iterate them
567 * ourselves. When grabbing only one or two elements, a matching
568 * dictionary should be passed in here instead of NULL. */
569 success = (*handle)->copyMatchingElements(handle, NULL, (CFArrayRef*)&elements);
571 if (success == kIOReturnSuccess) {
573 [elements autorelease];
575 cookies = calloc(NUMBER_OF_APPLE_REMOTE_ACTIONS, sizeof(IOHIDElementCookie));
576 memset(cookies, 0, sizeof(IOHIDElementCookie) * NUMBER_OF_APPLE_REMOTE_ACTIONS);
578 allCookies = [[NSMutableArray alloc] init];
580 for (i=0; i< [elements count]; i++) {
581 element = [elements objectAtIndex:i];
584 object = [element valueForKey: (NSString*)CFSTR(kIOHIDElementCookieKey) ];
585 if (object == nil || ![object isKindOfClass:[NSNumber class]]) continue;
586 if (object == 0 || CFGetTypeID(object) != CFNumberGetTypeID()) continue;
587 cookie = (IOHIDElementCookie) [object longValue];
590 object = [element valueForKey: (NSString*)CFSTR(kIOHIDElementUsageKey) ];
591 if (object == nil || ![object isKindOfClass:[NSNumber class]]) continue;
592 usage = [object longValue];
595 object = [element valueForKey: (NSString*)CFSTR(kIOHIDElementUsagePageKey) ];
596 if (object == nil || ![object isKindOfClass:[NSNumber class]]) continue;
597 usagePage = [object longValue];
599 [allCookies addObject: [NSNumber numberWithInt:(int)cookie]];
608 - (BOOL) openDevice {
611 IOHIDOptionsType openMode = kIOHIDOptionsTypeNone;
612 if ([self isOpenInExclusiveMode]) openMode = kIOHIDOptionsTypeSeizeDevice;
613 IOReturn ioReturnValue = (*hidDeviceInterface)->open(hidDeviceInterface, openMode);
615 if (ioReturnValue == KERN_SUCCESS) {
616 queue = (*hidDeviceInterface)->allocQueue(hidDeviceInterface);
618 result = (*queue)->create(queue, 0, 12); //depth: maximum number of elements in queue before oldest elements in queue begin to be lost.
621 for(i=0; i<[allCookies count]; i++) {
622 IOHIDElementCookie cookie = (IOHIDElementCookie)[[allCookies objectAtIndex:i] intValue];
623 (*queue)->addElement(queue, cookie, 0);
626 // add callback for async events
627 ioReturnValue = (*queue)->createAsyncEventSource(queue, &eventSource);
628 if (ioReturnValue == KERN_SUCCESS) {
629 ioReturnValue = (*queue)->setEventCallout(queue,QueueCallbackFunction, self, NULL);
630 if (ioReturnValue == KERN_SUCCESS) {
631 CFRunLoopAddSource(CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
632 //start data delivery to queue
633 (*queue)->start(queue);
636 NSLog(@"Error when setting event callout");
639 NSLog(@"Error when creating async event source");
642 NSLog(@"Error when opening device");
650 @implementation AppleRemoteApplicationDelegate
652 - (id) initWithApplicationDelegate: (id) delegate {
653 if (self = [super init]) {
654 applicationDelegate = [delegate retain];
661 [applicationDelegate release];
665 - (id) applicationDelegate {
666 return applicationDelegate;
669 - (void)applicationWillBecomeActive:(NSNotification *)aNotification {
670 if ([applicationDelegate respondsToSelector: @selector(applicationWillBecomeActive:)]) {
671 [applicationDelegate applicationWillBecomeActive: aNotification];
674 - (void)applicationDidBecomeActive:(NSNotification *)aNotification {
675 [[AppleRemote sharedRemote] setListeningToRemote: YES];
677 if ([applicationDelegate respondsToSelector: @selector(applicationDidBecomeActive:)]) {
678 [applicationDelegate applicationDidBecomeActive: aNotification];
681 - (void)applicationWillResignActive:(NSNotification *)aNotification {
682 [[AppleRemote sharedRemote] setListeningToRemote: NO];
684 if ([applicationDelegate respondsToSelector: @selector(applicationWillResignActive:)]) {
685 [applicationDelegate applicationWillResignActive: aNotification];
688 - (void)applicationDidResignActive:(NSNotification *)aNotification {
689 if ([applicationDelegate respondsToSelector: @selector(applicationDidResignActive:)]) {
690 [applicationDelegate applicationDidResignActive: aNotification];
694 - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector {
695 NSMethodSignature* signature = [super methodSignatureForSelector: aSelector];
696 if (signature == nil && applicationDelegate != nil) {
697 signature = [applicationDelegate methodSignatureForSelector: aSelector];
702 - (void)forwardInvocation:(NSInvocation *)invocation {
703 SEL aSelector = [invocation selector];
705 if (applicationDelegate==nil || [applicationDelegate respondsToSelector:aSelector]==NO) {
706 [super forwardInvocation: invocation];
710 [invocation invokeWithTarget:applicationDelegate];