Re: D.O. won't pass NSBezierPath ???
Re: D.O. won't pass NSBezierPath ???
- Subject: Re: D.O. won't pass NSBezierPath ???
- From: Aki Inoue <email@hidden>
- Date: Wed, 2 May 2001 11:11:03 -0700
Per,
NSBezierPath doesn't override -replacementObjectForPortCoder: method;
that means, instances of the class are always passed as proxy.
So, the drawing operation is actually performed in the process that
created the instance, that is not what you want in this case obviously.
What you need to do here is to pass your NSBezierPath objects 'bycopy'
to the server process.
You can create a NSBezierPath category like:
@implementation NSBezierPath (NSBezierPathDOCategory)
- (id)replacementObjectForPortCoder:(NSPortCoder)portCoder {
i ([portCoder isBycopy]) return self;
return [super replacementObjectForPortCoder:portCoder];
}
@end
And, your protocol declaration should be:
@protocol ConnectProtocol
- (void)send:(NString *)message;
- (void)displayGraph:(bycopy NSBezierPath *)graphPath;
@end
Please refer to NSPortCoder doc at
http://developer.apple.com/techpubs/macosx/Cocoa/Reference/Foundation/ObjC_classic/
Classes/NSPortCoder.html for further explanation.
Aki
On 2001.05.02, at 08:05, Per Persson wrote:
Hi,
I have a background in c-programming and lately I've spent some time
trying to get into the Obj-C/Cocoa way of life and so far the sun has
been shining on my journey... except for this little issue:
I want to send an NSBezierPath object from one app to another to have
it displayed. Making a connection and sending e.g. an NSString object
works fine but sending an NSBezierPath fails miserably... Either the
'send:' method works by pure luck or there is some fundamental
difference between an NSString and NSBezierPath.
Could anyone enlighten me?!
/Per
Excerpts from the code:
---- Protocol ----
@protocol ConnectProtocol
- (void) send:(NSString *)message;
- (void) displayGraph:(NSBezierPath *)graphPath;
@end
---- Receiver(server) -----
#import <Cocoa/Cocoa.h>
#import "connectProtocol"
@interface ReceiverObject : NSObject <ConnectProtocol>
{
IBOutlet id receiverOutlet;
NSConnection *myConnection;
}
/* Protocol methods */
- (void) send:(NSString *)message;
- (void) displayGraph:(NSBezierPath *)graphPath;
@end
#import "ReceiverObject.h"
#import "ReceiverView.h"
@implementation ReceiverObject
- (void)awakeFromNib
{
myConnection = [[NSConnection defaultConnection] retain];
[myConnection setRootObject:self];
if([myConnection registerName:@"Receiver"] == NO) {
NSLog(@"Error registering %s\n", @"Receiver");
}
}
- (void) send:(NSString *)message
{
if ([message isEqualTo:@"1"]) {
NSLog(@"Got 1\n");
[receiverOutlet setReceiverViewPath:[NSBezierPath
bezierPathWithRect:NSMakeRect(10,10,20,30)]];
} else {
NSLog(@"Got 0\n");
[receiverOutlet setReceiverViewPath:[NSBezierPath
bezierPathWithOvalInRect:NSMakeRect(10,10,20,30)]];
}
}
- (void) displayGraph:(NSBezierPath *)graphPath
{
[receiverOutlet setReceiverViewPath:graphPath];
}
@end
---- Sender(client) -----
#import <Cocoa/Cocoa.h>
#import "connectProtocol"
@interface SenderObject : NSObject
{
id theProxy;
}
- (IBAction)plot:(id)sender;
- (IBAction)set:(id)sender;
@end
#import "SenderObject.h"
@implementation SenderObject
-init
{
/* Set up connection */
theProxy = [[NSConnection
rootProxyForConnectionWithRegisteredName:@"Receiver" host:nil] retain];
/* Check availability */
if (theProxy) {
printf("Connected to Receiver\n");
} else {
printf("** NOT ** Connected to Receiver\n\n");
}
/* Set up communication rules... */
[theProxy setProtocolForProxy:@protocol(ConnectProtocol)];
return self;
}
- (IBAction)plot:(id)sender
{
NSBezierPath *aPath=[NSBezierPath bezierPath];
[aPath moveToPoint:NSMakePoint(0,0)];
[aPath lineToPoint:NSMakePoint(60,60)];
[aPath moveToPoint:NSMakePoint(0,60)];
[aPath lineToPoint:NSMakePoint(60,0)];
[theProxy displayGraph:aPath];
}
- (IBAction)set:(id)sender
{
[theProxy send:@"1"];
}
@end
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev