2001-12-17 14:31:42 +00:00
|
|
|
|
/** Implementation of NSNotification for GNUstep
|
1996-03-03 01:41:01 +00:00
|
|
|
|
Copyright (C) 1996 Free Software Foundation, Inc.
|
|
|
|
|
|
1996-04-17 20:17:45 +00:00
|
|
|
|
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
|
1996-03-03 01:41:01 +00:00
|
|
|
|
Created: March 1996
|
1996-02-13 16:09:50 +00:00
|
|
|
|
|
1996-05-12 00:56:10 +00:00
|
|
|
|
This file is part of the GNUstep Base Library.
|
1996-02-13 16:09:50 +00:00
|
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
Library General Public License for more details.
|
1996-03-03 01:41:01 +00:00
|
|
|
|
|
1996-02-13 16:09:50 +00:00
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
|
License along with this library; if not, write to the Free
|
1999-09-09 02:56:20 +00:00
|
|
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
2001-12-18 16:54:15 +00:00
|
|
|
|
|
|
|
|
|
<title>NSNotification class reference</title>
|
|
|
|
|
$Date$ $Revision$
|
1996-03-03 01:41:01 +00:00
|
|
|
|
*/
|
1996-02-13 16:09:50 +00:00
|
|
|
|
|
1997-11-06 00:51:23 +00:00
|
|
|
|
#include <config.h>
|
1996-02-13 16:09:50 +00:00
|
|
|
|
#include <Foundation/NSNotification.h>
|
1999-06-17 13:17:28 +00:00
|
|
|
|
#include <Foundation/NSCoder.h>
|
1998-07-28 17:51:55 +00:00
|
|
|
|
#include <Foundation/NSString.h>
|
1996-02-13 16:09:50 +00:00
|
|
|
|
|
2002-06-06 14:02:59 +00:00
|
|
|
|
@implementation NSNotification (GNUstep)
|
|
|
|
|
/* <init />
|
|
|
|
|
* Initialise a newly created notification.
|
|
|
|
|
*/
|
1999-06-17 13:17:28 +00:00
|
|
|
|
- (id) initWithName: (NSString*)name
|
|
|
|
|
object: (id)object
|
2001-12-17 14:31:42 +00:00
|
|
|
|
userInfo: (NSDictionary*)info
|
1998-07-21 17:56:48 +00:00
|
|
|
|
{
|
2002-06-06 14:02:59 +00:00
|
|
|
|
_name = [name copyWithZone: GSObjCZone(self)];
|
1999-06-17 13:17:28 +00:00
|
|
|
|
_object = TEST_RETAIN(object);
|
|
|
|
|
_info = TEST_RETAIN(info);
|
1998-07-21 17:56:48 +00:00
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-06 14:02:59 +00:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation NSNotification
|
|
|
|
|
|
1998-07-21 17:56:48 +00:00
|
|
|
|
- (void) dealloc
|
|
|
|
|
{
|
1999-05-06 19:37:45 +00:00
|
|
|
|
RELEASE(_name);
|
1999-06-17 13:17:28 +00:00
|
|
|
|
TEST_RELEASE(_object);
|
|
|
|
|
TEST_RELEASE(_info);
|
1998-07-21 17:56:48 +00:00
|
|
|
|
[super dealloc];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Creating autoreleased Notification objects. */
|
|
|
|
|
|
1999-06-17 13:17:28 +00:00
|
|
|
|
+ (NSNotification*) notificationWithName: (NSString*)name
|
|
|
|
|
object: (id)object
|
2001-12-17 14:31:42 +00:00
|
|
|
|
userInfo: (NSDictionary*)info
|
1998-07-21 17:56:48 +00:00
|
|
|
|
{
|
1999-07-03 19:59:44 +00:00
|
|
|
|
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
|
|
|
|
|
initWithName: name object: object userInfo: info]);
|
1998-07-21 17:56:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-06-17 13:17:28 +00:00
|
|
|
|
+ (NSNotification*) notificationWithName: (NSString*)name
|
|
|
|
|
object: (id)object
|
1998-07-21 17:56:48 +00:00
|
|
|
|
{
|
1999-05-06 19:37:45 +00:00
|
|
|
|
return [self notificationWithName: name object: object userInfo: nil];
|
1998-07-21 17:56:48 +00:00
|
|
|
|
}
|
1996-02-13 16:09:50 +00:00
|
|
|
|
|
1998-07-21 17:56:48 +00:00
|
|
|
|
|
|
|
|
|
/* Querying a Notification object. */
|
|
|
|
|
|
|
|
|
|
- (NSString*) name
|
|
|
|
|
{
|
|
|
|
|
return _name;
|
|
|
|
|
}
|
|
|
|
|
|
1999-06-17 13:17:28 +00:00
|
|
|
|
- (id) object
|
1998-07-21 17:56:48 +00:00
|
|
|
|
{
|
|
|
|
|
return _object;
|
|
|
|
|
}
|
|
|
|
|
|
1999-06-17 13:17:28 +00:00
|
|
|
|
- (NSDictionary*) userInfo
|
1998-07-21 17:56:48 +00:00
|
|
|
|
{
|
|
|
|
|
return _info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* NSCopying protocol. */
|
|
|
|
|
|
1999-06-17 13:17:28 +00:00
|
|
|
|
- (id) copyWithZone: (NSZone*)zone
|
1996-02-13 16:09:50 +00:00
|
|
|
|
{
|
1998-07-21 17:56:48 +00:00
|
|
|
|
if (NSShouldRetainWithZone (self, zone))
|
|
|
|
|
return [self retain];
|
|
|
|
|
|
|
|
|
|
return [[[self class] allocWithZone: zone]
|
1999-06-17 13:17:28 +00:00
|
|
|
|
initWithName: _name
|
|
|
|
|
object: _object
|
|
|
|
|
userInfo: _info];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* NSCoding protocol - the MacOS-X documentation says it should conform,
|
|
|
|
|
* but how can we meaningfully encode/decode the object and userInfo.
|
|
|
|
|
* We do it anyway - at least it should make sense over DO.
|
|
|
|
|
*/
|
|
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
|
|
|
|
{
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(id) at: &_name];
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(id) at: &_object];
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(id) at: &_info];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) initWithCoder: (NSCoder*)aCoder
|
|
|
|
|
{
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(id) at: &_name];
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(id) at: &_object];
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(id) at: &_info];
|
|
|
|
|
return self;
|
1996-02-13 16:09:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|