Allow text and image in NSBrowserCell at the same time.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@20567 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
FredKiefer 2005-01-17 00:07:50 +00:00
parent 41cf0b9454
commit 93c60072c7
2 changed files with 44 additions and 36 deletions

View file

@ -1,3 +1,10 @@
2005-01-17 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSBrowserCell.m (-setType:): New method, does nothing to
allow image and text at once (MacOSX 10.2 behaviour).
(-drawInteriorWithFrame:inView:): Draw an image or alternate image,
if provided and draw the text as well.
2005-01-16 Fred Kiefer <FredKiefer@gmx.de> 2005-01-16 Fred Kiefer <FredKiefer@gmx.de>
* Images/common_ClosedHandCursor.tiff: Replaced by new image files by * Images/common_ClosedHandCursor.tiff: Replaced by new image files by

View file

@ -216,16 +216,25 @@ static NSFont *_leafFont;
_cell.state = YES; _cell.state = YES;
} }
- (void) setType: (NSCellType)aType
{
/* We do nothing here (we match the Mac OS X behavior) because with
* NSBrowserCell GNUstep implementation the cell may contain an image
* and text at the same time.
*/
}
/* /*
* Displaying * Displaying
*/ */
- (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView *)controlView - (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView *)controlView
{ {
NSRect title_rect = cellFrame; NSRect title_rect = cellFrame;
NSImage *image = nil; NSImage *branch_image = nil;
NSImage *cell_image = nil;
NSColor *backColor; NSColor *backColor;
NSWindow *cvWin = [controlView window]; NSWindow *cvWin = [controlView window];
BOOL showsFirstResponder;
if (!cvWin) if (!cvWin)
return; return;
@ -235,76 +244,68 @@ static NSFont *_leafFont;
backColor = [self highlightColorInView: controlView]; backColor = [self highlightColorInView: controlView];
[backColor set]; [backColor set];
if (!_browsercell_is_leaf) if (!_browsercell_is_leaf)
image = [isa highlightedBranchImage]; branch_image = [isa highlightedBranchImage];
cell_image = [self alternateImage];
} }
else else
{ {
backColor = [cvWin backgroundColor]; backColor = [cvWin backgroundColor];
[backColor set]; [backColor set];
if (!_browsercell_is_leaf) if (!_browsercell_is_leaf)
image = [isa branchImage]; branch_image = [isa branchImage];
cell_image = [self image];
} }
// Clear the background // Clear the background
NSRectFill(cellFrame); NSRectFill(cellFrame);
showsFirstResponder = _cell.shows_first_responder;
// Draw the branch image if there is one // Draw the branch image if there is one
if (image) if (branch_image)
{ {
NSRect image_rect; NSSize size;
NSPoint position;
image_rect.origin = cellFrame.origin; size = [branch_image size];
image_rect.size = [image size]; position.x = MAX(NSMaxX(title_rect) - size.width - 4.0, 0.);
image_rect.origin.x += cellFrame.size.width - image_rect.size.width - 4.0; position.y = MAX(NSMidY(title_rect) - (size.height/2.), 0.);
image_rect.origin.y
+= (cellFrame.size.height - image_rect.size.height) / 2.0;
/* /*
* Images are always drawn with their bottom-left corner at the origin * Images are always drawn with their bottom-left corner at the origin
* so we must adjust the position to take account of a flipped view. * so we must adjust the position to take account of a flipped view.
*/ */
if ([controlView isFlipped]) if ([controlView isFlipped])
image_rect.origin.y += image_rect.size.height; position.y += size.height;
[image compositeToPoint: image_rect.origin [branch_image compositeToPoint: position operation: NSCompositeSourceOver];
operation: NSCompositeSourceOver];
title_rect.size.width -= image_rect.size.width + 8; title_rect.size.width -= size.width + 8;
} }
// Skip 2 points from the left border // Skip 2 points from the left border
title_rect.origin.x += 2; title_rect.origin.x += 2;
title_rect.size.width -= 2; title_rect.size.width -= 2;
// Draw the body of the cell // Draw the cell image if there is one
if ((_cell.type == NSImageCellType) if (cell_image)
&& (_cell.is_highlighted || _cell.state)
&& _alternateImage)
{ {
// Draw the alternateImage
NSSize size; NSSize size;
NSPoint position; NSPoint position;
size = [_alternateImage size]; size = [cell_image size];
position.x = MAX(NSMidX(title_rect) - (size.width/2.),0.); position.x = NSMinX(title_rect);
position.y = MAX(NSMidY(title_rect) - (size.height/2.),0.); position.y = MAX(NSMidY(title_rect) - (size.height/2.),0.);
if ([controlView isFlipped]) if ([controlView isFlipped])
position.y += size.height; position.y += size.height;
[_alternateImage compositeToPoint: position [cell_image compositeToPoint: position operation: NSCompositeSourceOver];
operation: NSCompositeSourceOver];
}
else
{
// Draw image, or text
_cell.shows_first_responder = NO;
[super drawInteriorWithFrame: title_rect inView: controlView]; title_rect.origin.x += size.width + 4;
} title_rect.size.width -= size.width + 4;
}
if (showsFirstResponder == YES) // Draw the body of the cell
[self _drawAttributedText: [self attributedStringValue]
inFrame: title_rect];
if (_cell.shows_first_responder == YES)
NSDottedFrameRect(cellFrame); NSDottedFrameRect(cellFrame);
_cell.shows_first_responder = showsFirstResponder;
} }
- (BOOL) isOpaque - (BOOL) isOpaque