D.O. won't pass NSBezierPath ???
D.O. won't pass NSBezierPath ???
- Subject: D.O. won't pass NSBezierPath ???
- From: Per Persson <email@hidden>
- Date: Wed, 2 May 2001 17:05:06 +0200
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