From d92fdfbb9cf6c78d15b07c6ae386e81b3a7096df Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 10 Sep 1999 05:18:32 +0000 Subject: [PATCH] [-cellSize] implemented git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@4864 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 4 ++ Source/NSButtonCell.m | 106 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) diff --git a/ChangeLog b/ChangeLog index 6e30567f3..41d423615 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +iThu Sep 9 1999 Nicola Pero + + * Source/NSButtonCell.m: implemented missing method ([-cellSize]). + 1999-09-09 Gerrit van Dyk * Headers/NSComboBox.h: Added NSComboBox diff --git a/Source/NSButtonCell.m b/Source/NSButtonCell.m index 7972f969f..050adc148 100644 --- a/Source/NSButtonCell.m +++ b/Source/NSButtonCell.m @@ -548,6 +548,112 @@ } } +- (NSSize) cellSize +{ + NSSize s; + NSSize borderSize; + BOOL showAlternate = NO; + unsigned mask; + NSImage *imageToDisplay; + NSString *titleToDisplay; + NSSize imageSize; + NSSize titleSize; + + // + // The following code must be kept in sync with -drawInteriorWithFrame + // + + if ([self isHighlighted]) + mask = [self highlightsBy]; + else + mask = [self showsStateBy]; + if (mask & NSContentsCellMask) + showAlternate = [self state]; + + if (showAlternate || [self isHighlighted]) + { + imageToDisplay = [self alternateImage]; + if (!imageToDisplay) + imageToDisplay = [self image]; + titleToDisplay = [self alternateTitle]; + if (titleToDisplay == nil || [titleToDisplay isEqual: @""]) + titleToDisplay = [self title]; + } + else + { + imageToDisplay = [self image]; + titleToDisplay = [self title]; + } + + if (imageToDisplay) + imageSize = [imageToDisplay size]; + else + imageSize = NSZeroSize; + + if (titleToDisplay) + titleSize = NSMakeSize ([cell_font widthOfString: titleToDisplay], + [cell_font pointSize]); + else + titleSize = NSZeroSize; + + switch ([self imagePosition]) + { + case NSNoImage: + s = titleSize; + break; + + case NSImageOnly: + s = imageSize; + break; + + case NSImageLeft: + case NSImageRight: + s.width = imageSize.width + titleSize.width + xDist; + if (imageSize.height > titleSize.height) + s.height = imageSize.height; + else + s.height = titleSize.height; + break; + + case NSImageBelow: + case NSImageAbove: + if (imageSize.width > titleSize.width) + s.height = imageSize.width; + else + s.width = titleSize.width; + s.height = imageSize.height + titleSize.height; // + yDist ?? + break; + + case NSImageOverlaps: + if (imageSize.width > titleSize.width) + s.width = imageSize.width; + else + s.width = titleSize.width; + + if (imageSize.height > titleSize.height) + s.height = imageSize.height; + else + s.height = titleSize.height; + + break; + } + + // Add spacing between text/image and border + s.width += 2 * xDist; + s.height += 2 * yDist; + + // Get border size + if ([self isBordered]) + borderSize = [NSCell sizeForBorderType: NSBezelBorder]; + else + borderSize = [NSCell sizeForBorderType: NSNoBorder]; + + // Add border size + s.width += 2 * borderSize.width; + s.height += 2 * borderSize.height; + + return s; +} - (id) copyWithZone: (NSZone*)zone {