• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: D.O. won't pass NSBezierPath ???
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: D.O. won't pass NSBezierPath ???


  • Subject: Re: D.O. won't pass NSBezierPath ???
  • From: Per Persson <email@hidden>
  • Date: Thu, 3 May 2001 01:13:31 +0200

All I can say is WOW! Obj-C and Cocoa is COOL!
Once the override was there, it took me < 2 hours to write a basic Aqua graphics server for gnuplot 3.8.
I choose a port of a gnuplot server to test graphics and interapp-messaging and expected to spend days to get it to work...

Thanks for your help!

/Per
"Why, oh why, have I spent all those years coding in c?"

On onsdag, maj 2, 2001, at 08:11 , Aki Inoue wrote:

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


References: 
 >Re: D.O. won't pass NSBezierPath ??? (From: Aki Inoue <email@hidden>)

  • Prev by Date: Re: D.O. won't pass NSBezierPath ???
  • Next by Date: Learning Cocoa <first Post?>
  • Previous by thread: Re: D.O. won't pass NSBezierPath ???
  • Next by thread: Re: D.O. won't pass NSBezierPath ???
  • Index(es):
    • Date
    • Thread