Re: Highlighting NSImageCells in an NSMatrix
Re: Highlighting NSImageCells in an NSMatrix
- Subject: Re: Highlighting NSImageCells in an NSMatrix
- From: Alastair Houghton <email@hidden>
- Date: Tue, 3 Feb 2004 12:20:05 +0000
On 3 Feb 2004, at 11:41, Michael Becker wrote:
>
> I have an app that uses an NSMatrix subclass to display images. Here
>
> is the "setup" portion of the implementation...
>
>
>
>
This actually works, but I cannot use the bezeled borders. My images
>
have to be "just the image on plain white" and when selected, the
>
white cell background around the image should turn blue (or whatever).
>
>
I think I will have to subclass NSImageCell, override drawWithFrame:
>
or drawInteriorWithFrame:, and probably even override some
>
highlighting method to draw the blue background...
>
>
Lotta work for just highlighting a cell...
You're overstating the level of difficulty. Subclassing NSImageCell to
do what you want is *easy*:
@interface MBImageCell : NSImageCell
{
}
@end
@implementation MBImageCell
-(void)drawInteriorWithFrame:(NSRect)frame inView:(NSView *)controlView
{
if ([self isHighlighted]) {
[[NSColor selectedControlColor] set];
NSRectFill (frame);
}
[super drawInteriorWithFrame:frame inView:controlView];
}
@end
Obviously this was typed quickly in Mail and hasn't been tested, but I
think you get the idea. It is possible that NSImageCell's
-drawInteriorWithFrame:inView: doesn't do quite what you want, in which
case you might want to replace it with a call to one of NSImage's
methods, but otherwise I think it should work.
(BTW, you can turn the borders off using the -setBordered: and/or
-setBezeled: methods if you want to do so.)
Kind regards,
Alastair.
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.