Re: Subclassing NSControl
Re: Subclassing NSControl
- Subject: Re: Subclassing NSControl
- From: Scott Anguish <email@hidden>
- Date: Wed, 14 May 2003 04:14:10 -0400
On Wednesday, May 14, 2003, at 03:51 AM, Lorenzo wrote:
Hi,
I have two own subclasses:
MYTextField subclass of NSTextField
MYImageView subclass of NSImageView
For many of their behaviours these 2 classes work the same way,
e.g. they respond to the mouse clicks the same way,
if the user clicks holding down the Control key, a pop-up menu
appears...
So I thought to group these 2 subclasses under a superClass "MYBox",
and to describe the common behaviours (like mouseDown, mouseUp)
in this new superClass "MYBox".
You can't really do that. NSTextField and NSImageView both inherit
from NSControl.
what you could do is have your own subclasses of NSTextField and
NSImageView and then have the mouseDown: and mouseUp: methods in your
subclasses call a procedure (yep, an old fashion procedure) passing the
sender and it's parameters
void CommonMouseDownHandler(NSEvent *theEvent, NSControl *sender)
void CommonMouseUpHandler(NSEvent *theEvent, NSControl *sender)
this would let you put all the code in a single shared location, and
still give you all the objective-C goodness of calling the objects..
You could even use class methods and make it into a class if you
wanted to (but I don't see the advantage in this case... maybe if you
had a single set of shared data that they needed to access a singleton
might make sense)
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.