[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: -setTarget: and -setAction: of NSImageView
From: |
Alexander Malmberg |
Subject: |
Re: -setTarget: and -setAction: of NSImageView |
Date: |
Tue, 23 Dec 2003 21:28:48 +0100 |
Kazunobu Kuriyama wrote:
> Hi,
>
> Because I still don't understand the reason why GNUstep's
> NSImageView need to raise an exception when it receives either
> -setTarget: or -setAction:, let me continue the discussion
> a little bit further.
>
> According to the specifications at http://developer.apple.com,
> we know that
> (1) Almost all concrete classes inherited from NSControl are
> implemented using NSCell.
No, using a subclass of NSCell. NSImageView uses NSImageCell by default,
but you can also use any other cell class you like, or a custom cell
class.
> (2) -setTarget: and -setAction: methods of NSCell are to
> raise an exception.
True.
> (3) However, NSActionCell, a subclass of NSCell, have to
> receive these methods.
Yes, NSActionCell responds by settings its target/action to the provided
target/action.
> In addition, there's another stuff to be noted. Seeing an
> example of usage of NSImageView in page 239 of the book,
> S. Anguish, E.M. Buck, and D.A. Yacktman, "Cocoa Programming",
> SAMS, 2002, we know that an NSImageView can receive both
> -setTarget: and -setAction: methods. (The source code of
> the example can be downloaded from http://www.cocoaprogramming.net. )
The relevant parts are:
- (id)initWithPath:(NSString *)aPath
...
// Configure the loaded objects
[imageView setTarget:self];
[imageView setAction:@selector(noteImageWasDropped:)];
...
and
...
- (IBAction)noteImageWasDropped:(id)sender
/*" Called by document's image view when the image changes. "*/
...
which makes this a bit clearer. It seems that apple have extended
NSImageView/NSImageCell to send the cell's action when a new image is
dropped on the image view. The Cocoa "Image view" docs (but not the
NSImageView or NSImageCell docs) also mention this.
Thus, the fact that NSImageCell's -setTarget:/-setAction: no longer
raise an exception is merely a consequence of the fact that NSImageCell
now actually uses a target and an action.
> The current GNUstep implementation of NSImageView uses
> NSCell. In this sense, the current behaior, that is,
> to raise an exception, is (superficially) consistent to
> the specs. However, it doesn't conform to the behavior
> of the Cocoa's genuine NSImageView.
But they didn't just change the behavior of -setTarget:/-setAction: to
not raise exceptions. Instead (which is what I've been trying to get at
from the start), the relevant behavior change in this case is
"NSImageCell has no target/action" to "NSImageView/NSImageCell sends its
action when an image is dropped on it, if it is editable".
> Consequently, IMHO, NSImageView should be reimplemented
> using NSActionCell, instead of NSCell, so that it can
> receive the two method mentioned above.
Having NSImageCell be a subclass of NSActionCell makes sense now that
NSImageCell has a target and an action. However, it would be contrary to
all (non-GNUstep) documentation, so I'm skeptical. Either way, the
effects on custom cell classes and encoding/decoding of the involved
classes needs to be looked at carefully first.
> Having said so, because the specs says neither that NSImageView
> should use NSCell nor that it should use NSActionCell, one cannot
> obviously say which implementation is right.
Although I'm not sure that it's explicitly documented anywhere, it's
very clear that NSImageView uses NSImageCell. (Consider eg.
-setImageScaling:; neither NSCell nor NSActionCell implement it.)
> The currrent
> implementation might be superior to the Cocoa's in terms of
> some unknown broader point of view.
>
> But it is clearly better for GNUstep to be as close as possible
> to Cocoa's AppKit unless there's some reason for making GNUstep
> distinguishable from Cocoa.
Making NSImageCell a subclass of NSActionCell would be very
distinguishable. :)
> I hope this email makes clearer what I want to say in previous
> emails in this thread.
Yes, we now know the full behavior change, so we can now Think Hard
about what to do about it. Thanks! :)
- Alexander Malmberg