Re: NSBrowserCell subclasses
Re: NSBrowserCell subclasses
- Subject: Re: NSBrowserCell subclasses
- From: Chuck Pisula <email@hidden>
- Date: Mon, 7 May 2001 10:37:10 -0700
Checking isHighlighted works fine for me. Here is what I do:
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView
*)controlView {
if (iconImage != nil) {
NSSize imageSize = [iconImage size];
NSRect imageFrame, highlightRect, textFrame;
// Divide the cell into 2 parts, the image part (on the left) and
the text part.
NSDivideRect(cellFrame, &imageFrame, &textFrame, ICON_INSET_HORIZ +
ICON_TEXT_SPACING + imageSize.width, NSMinXEdge);
imageFrame.origin.x += ICON_INSET_HORIZ;
imageFrame.size = imageSize;
// Adjust the image frame top account for the fact that we may or
may not be in a flipped control view, since when compositing
// the online documentation states: "The image will have the
orientation of the base coordinate system, regardless of the destination
coordinates".
if ([controlView isFlipped]) imageFrame.origin.y +=
ceil((textFrame.size.height + imageFrame.size.height) / 2);
else imageFrame.origin.y += ceil((textFrame.size.height -
imageFrame.size.height) / 2);
// Depending on the current state, set the color we will highlight
with.
if ([self isHighlighted]) {
// use highlightColorInView instead of [NSColor
selectedControlColor] since NSBrowserCell slightly dims all cells except
those in the right most column.
// The return value from highlightColorInView will return the
appropriate one for you.
[[self highlightColorInView: controlView] set];
} else {
[[NSColor controlBackgroundColor] set];
}
// Draw the highligh, bu only the portion that won't be caught by
the call to [super drawInteriorWithFrame:...] below. No need to draw
parts 2 times!
highlightRect = NSMakeRect(NSMinX(cellFrame), NSMinY(cellFrame),
NSWidth(cellFrame) - NSWidth(textFrame), NSHeight(cellFrame));
NSRectFill(highlightRect);
// Blit the image.
[iconImage compositeToPoint:imageFrame.origin
operation:NSCompositeSourceOver];
// Have NSBrowser kindly draw the text part, since it knows how to
do that for us, no need to re-invent what it knows how to do.
[super drawInteriorWithFrame:textFrame inView:controlView];
} else {
// Atleast draw something if we couldn't find an icon. You may
want to do something more intelligent.
[super drawInteriorWithFrame:cellFrame inView:controlView];
}
}
HTH
-chuck
On Saturday, May 5, 2001, at 06:20 PM, Richard Schreyer wrote:
Today I created a subclass of NSBrowserCell which, in
-drawInteriorWithFrame, cuts roughly 60 pixels off of the right edge of
the cell frame, in order to place some additional stuff there. I took
the reduced cell frame, and ran the standard implementation of
-drawInteriorWithFrame it so it would draw the normal icon/text on the
left side.
Right now, my problem is that I can't get the highlighting right on the
part I am drawing. I found -highlightColorInView in the NSBrowserCell
header to get the right color, but I don't know which cells I should to
apply this color to.
Calling -isHighlighted only returns Yes on the active column in the
NSBrowser, not the previous columns, which I need to draw the lighter
highlight color in.
I also checked to see if the NSBrowserCells were mixed state, but it
appears not. Does anyone know how to tell if the column should be
highlighted, if it's not the active (right-most) column?
Before I also tried drawing the entire cell myself (and ended up with
the same problem) but I also had problems because the NSBrowserDelegate
-willDisplayCell method was no longer being called when the information
needed to be updated, so my code was only drawing the out of date info.
It seems that the -willDisplayCell method is called by
-drawInteriorWithFrame, and I don't know how to get all the info
necessary for my -drawInteriorWithFrame subclass to call it instead.
If anyone can help with any of these problems, It would help a lot,
Richard Schreyer
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev