Tidied to get rid of pretty useless private method

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@4871 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-09-11 10:08:56 +00:00
parent 2c2b3d0a20
commit af0c1f62e9
6 changed files with 166 additions and 109 deletions

View file

@ -1,3 +1,10 @@
Sat Sep 11 11:20:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Headers/AppKit/NSCell.h: Removed ([-_drawImage:inFrame:])
* Source/NSCell.m: Removed ([-_drawImage:inFrame:])
* Source/NSButtonCell.m: Don't use ([-_drawImage:inFrame:])
* Source/NSPopUpButtonCell.m: Don't use ([-_drawImage:inFrame:])
Sat Sep 11 1999 Nicola Pero <n.pero@mi.flashnet.it> Sat Sep 11 1999 Nicola Pero <n.pero@mi.flashnet.it>
* Source/NSControl.m ([-sizeToFit]): implemented method. * Source/NSControl.m ([-sizeToFit]): implemented method.

View file

@ -356,7 +356,6 @@ enum {
// //
@interface NSCell (PrivateMethods) @interface NSCell (PrivateMethods)
- (void) _drawImage: (NSImage*)anImage inFrame: (NSRect)aRect;
- (void) _drawText: (NSString*)aString inFrame: (NSRect)aRect; - (void) _drawText: (NSString*)aString inFrame: (NSRect)aRect;
@end @end

View file

@ -415,9 +415,10 @@
BOOL showAlternate = NO; BOOL showAlternate = NO;
unsigned mask; unsigned mask;
NSImage *imageToDisplay; NSImage *imageToDisplay;
NSRect imageRect;
NSString *titleToDisplay; NSString *titleToDisplay;
NSRect titleRect;
NSSize imageSize = {0, 0}; NSSize imageSize = {0, 0};
NSRect rect;
NSColor *backgroundColor = nil; NSColor *backgroundColor = nil;
// transparent buttons never draw // transparent buttons never draw
@ -430,14 +431,14 @@
if ([self state]) if ([self state])
{ {
if ( [self showsStateBy] if ( [self showsStateBy]
& (NSChangeGrayCellMask | NSChangeBackgroundCellMask) ) & (NSChangeGrayCellMask | NSChangeBackgroundCellMask) )
backgroundColor = [NSColor selectedControlColor]; backgroundColor = [NSColor selectedControlColor];
} }
if ([self isHighlighted]) if ([self isHighlighted])
{ {
if ( [self highlightsBy] if ( [self highlightsBy]
& (NSChangeGrayCellMask | NSChangeBackgroundCellMask) ) & (NSChangeGrayCellMask | NSChangeBackgroundCellMask) )
backgroundColor = [NSColor selectedControlColor]; backgroundColor = [NSColor selectedControlColor];
} }
@ -448,11 +449,13 @@
[backgroundColor set]; [backgroundColor set];
NSRectFill(cellFrame); NSRectFill(cellFrame);
// Determine the image and the title that will be /*
// displayed. If the NSContentsCellMask is set the * Determine the image and the title that will be
// image and title are swapped only if state is 1 or * displayed. If the NSContentsCellMask is set the
// if highlighting is set (when a button is pushed it's * image and title are swapped only if state is 1 or
// content is changed to the face of reversed state). * if highlighting is set (when a button is pushed it's
* content is changed to the face of reversed state).
*/
if ([self isHighlighted]) if ([self isHighlighted])
mask = [self highlightsBy]; mask = [self highlightsBy];
else else
@ -481,70 +484,77 @@
[imageToDisplay setBackgroundColor: backgroundColor]; [imageToDisplay setBackgroundColor: backgroundColor];
} }
rect = NSMakeRect (cellFrame.origin.x, cellFrame.origin.y,
imageSize.width, imageSize.height);
switch ([self imagePosition]) switch ([self imagePosition])
{ {
case NSNoImage: case NSNoImage:
// draw title only imageToDisplay = nil;
[self _drawText: titleToDisplay inFrame: cellFrame]; titleRect = cellFrame;
break; break;
case NSImageOnly: case NSImageOnly:
// draw image only titleToDisplay = nil;
[self _drawImage: imageToDisplay inFrame: cellFrame]; imageRect = cellFrame;
break; break;
case NSImageLeft: case NSImageLeft:
// draw image to the left of the title imageRect.origin = cellFrame.origin;
rect.origin = cellFrame.origin; imageRect.size.width = imageSize.width;
rect.size.width = imageSize.width; imageRect.size.height = cellFrame.size.height;
rect.size.height = cellFrame.size.height;
[self _drawImage: imageToDisplay inFrame: rect];
// draw title titleRect = imageRect;
rect.origin.x += imageSize.width + xDist; titleRect.origin.x += imageSize.width + xDist;
rect.size.width = cellFrame.size.width - imageSize.width - xDist; titleRect.size.width = cellFrame.size.width - imageSize.width - xDist;
[self _drawText: titleToDisplay inFrame: rect]; break;
break;
case NSImageRight: case NSImageRight:
// draw image to the right of the title imageRect.origin.x = NSMaxX(cellFrame) - imageSize.width;
rect.origin.x = NSMaxX (cellFrame) - imageSize.width; imageRect.origin.y = cellFrame.origin.y;
rect.origin.y = cellFrame.origin.y; imageRect.size.width = imageSize.width;
rect.size.width = imageSize.width; imageRect.size.height = cellFrame.size.height;
rect.size.height = cellFrame.size.height;
[self _drawImage: imageToDisplay inFrame: rect];
// draw title titleRect.origin = cellFrame.origin;
rect.origin = cellFrame.origin; titleRect.size.width = cellFrame.size.width - imageSize.width - xDist;
rect.size.width = cellFrame.size.width - imageSize.width - xDist; titleRect.size.height = cellFrame.size.height;
rect.size.height = cellFrame.size.height; break;
[self _drawText: titleToDisplay inFrame: rect];
break;
case NSImageBelow: case NSImageBelow:
// draw image below title imageRect = cellFrame;
cellFrame.size.height /= 2; imageRect.size.height /= 2;
[self _drawImage: imageToDisplay inFrame: cellFrame]; titleRect = imageRect;
cellFrame.origin.y += cellFrame.size.height; titleRect.origin.y += titleRect.size.height;
[self _drawText: titleToDisplay inFrame: cellFrame]; break;
break;
case NSImageAbove: case NSImageAbove:
// draw image above title titleRect = cellFrame;
cellFrame.size.height /= 2; titleRect.size.height /= 2;
[self _drawText: titleToDisplay inFrame: cellFrame]; imageRect = titleRect;
cellFrame.origin.y += cellFrame.size.height; imageRect.origin.y += imageRect.size.height;
[self _drawImage: imageToDisplay inFrame: cellFrame]; break;
break;
case NSImageOverlaps: case NSImageOverlaps:
// draw title over the image titleRect = cellFrame;
[self _drawImage: imageToDisplay inFrame: cellFrame]; imageRect = cellFrame;
[self _drawText: titleToDisplay inFrame: cellFrame]; break;
break; }
if (imageToDisplay != nil)
{
NSSize size;
NSPoint position;
size = [imageToDisplay size];
position.x = MAX(NSMidX(imageRect) - (size.width/2.),0.);
position.y = MAX(NSMidY(imageRect) - (size.height/2.),0.);
/*
* 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.
*/
if ([control_view isFlipped])
position.y += size.height;
[imageToDisplay compositeToPoint: position operation: NSCompositeCopy];
}
if (titleToDisplay != nil)
{
[self _drawText: titleToDisplay inFrame: titleRect];
} }
} }

View file

@ -681,34 +681,6 @@ static Class cellClass;
[title drawInRect: cellFrame withAttributes: dict]; [title drawInRect: cellFrame withAttributes: dict];
} }
static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
{
NSPoint p;
p.x = MAX(NSMidX(outerRect) - (innerSize.width/2.),0.);
p.y = MAX(NSMidY(outerRect) - (innerSize.height/2.),0.);
return p;
}
// Draw image centered in frame.
- (void) _drawImage: (NSImage *) image inFrame: (NSRect) cellFrame
{
NSSize size;
NSPoint position;
if (!image)
return;
size = [image size];
position = centerSizeInRect(size, cellFrame);
/*
* 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.
*/
if ([control_view isFlipped])
position.y += size.height;
[image compositeToPoint: position operation: NSCompositeCopy];
}
- (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView - (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
{ {
cellFrame = [self drawingRectForBounds: cellFrame]; cellFrame = [self drawingRectForBounds: cellFrame];
@ -732,13 +704,31 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
switch ([self type]) switch ([self type])
{ {
case NSTextCellType: case NSTextCellType:
[self _drawText: [self stringValue] inFrame: cellFrame]; [self _drawText: [self stringValue] inFrame: cellFrame];
break; break;
case NSImageCellType: case NSImageCellType:
[self _drawImage: cell_image inFrame: cellFrame]; if (cell_image)
break; {
NSSize size;
NSPoint position;
size = [cell_image size];
position.x = MAX(NSMidX(cellFrame) - (size.width/2.),0.);
position.y = MAX(NSMidY(cellFrame) - (size.height/2.),0.);
/*
* 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.
*/
if ([control_view isFlipped])
position.y += size.height;
[cell_image compositeToPoint: position operation: NSCompositeCopy];
}
break;
case NSNullCellType: case NSNullCellType:
break; break;
} }
} }

View file

@ -255,6 +255,7 @@ static BOOL usesUserKeyEquivalents = YES;
NSGraphicsContext *ctxt = GSCurrentContext(); NSGraphicsContext *ctxt = GSCurrentContext();
NSRect floodRect = cellFrame; NSRect floodRect = cellFrame;
NSString *keyQ = nil; NSString *keyQ = nil;
NSColor *backColor;
NSDrawButton(cellFrame, cellFrame); NSDrawButton(cellFrame, cellFrame);
@ -265,12 +266,13 @@ static BOOL usesUserKeyEquivalents = YES;
if (cell_highlighted) if (cell_highlighted)
{ {
[[NSColor selectedMenuItemColor] set]; backColor = [NSColor selectedMenuItemColor];
} }
else else
{ {
[[NSColor controlColor] set]; backColor = [NSColor controlColor];
} }
[backColor set];
NSRectFill(floodRect); NSRectFill(floodRect);
if ([self isEnabled]) if ([self isEnabled])
@ -293,14 +295,30 @@ static BOOL usesUserKeyEquivalents = YES;
DPSmoveto(ctxt, cellFrame.origin.x + 5, cellFrame.origin.y + 6); DPSmoveto(ctxt, cellFrame.origin.x + 5, cellFrame.origin.y + 6);
DPSshow(ctxt, [[self title] cString]); DPSshow(ctxt, [[self title] cString]);
if (mcell_has_submenu) { if (mcell_has_submenu)
floodRect.origin.x = cellFrame.size.width - 12; {
floodRect.origin.y += 5; NSSize size;
floodRect.size.height = 7; NSPoint position;
floodRect.size.width = 7; NSImage *im = [NSImage imageNamed:@"common_3DArrowRight"];
[self _drawImage:[NSImage imageNamed:@"common_3DArrowRight"] inFrame:floodRect]; floodRect.origin.x = cellFrame.size.width - 12;
} else if (keyQ = [self keyEquivalent]) { floodRect.origin.y += 5;
floodRect.size.height = 7;
floodRect.size.width = 7;
[im setBackgroundColor: backColor];
size = [im size];
position.x = MAX(NSMidX(floodRect) - (size.width/2.),0.);
position.y = MAX(NSMidY(floodRect) - (size.height/2.),0.);
/*
* 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.
*/
if ([control_view isFlipped])
position.y += size.height;
[im compositeToPoint: position operation: NSCompositeCopy];
}
else if (keyQ = [self keyEquivalent]) {
floodRect.origin.x = cellFrame.size.width - 12; floodRect.origin.x = cellFrame.size.width - 12;
floodRect.origin.y += 5; floodRect.origin.y += 5;
floodRect.size.height = 7; floodRect.size.height = 7;

View file

@ -60,6 +60,8 @@
inView: (NSView*)view inView: (NSView*)view
{ {
NSGraphicsContext *ctxt = GSCurrentContext(); NSGraphicsContext *ctxt = GSCurrentContext();
NSColor *backColor;
NSImage *toDraw = nil;
NSRect rect = cellFrame; NSRect rect = cellFrame;
NSRect arect = cellFrame; NSRect arect = cellFrame;
NSPoint point; NSPoint point;
@ -73,17 +75,31 @@
if (cell_highlighted) if (cell_highlighted)
{ {
[[NSColor selectedMenuItemColor] set]; backColor = [NSColor selectedMenuItemColor];
} }
else else
{ {
[[NSColor controlColor] set]; backColor = [NSColor controlColor];
} }
[backColor set];
NSRectFill(arect); NSRectFill(arect);
if (cell_image) if (cell_image)
{ {
[self _drawImage:cell_image inFrame:cellFrame]; NSSize size;
NSPoint position;
[cell_image setBackgroundColor: backColor];
size = [cell_image size];
position.x = MAX(NSMidX(cellFrame) - (size.width/2.),0.);
position.y = MAX(NSMidY(cellFrame) - (size.height/2.),0.);
/*
* 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.
*/
if ([control_view isFlipped])
position.y += size.height;
[cell_image compositeToPoint: position operation: NSCompositeCopy];
rect.size.width = 5; // calc image rect rect.size.width = 5; // calc image rect
rect.size.height = 11; rect.size.height = 11;
@ -125,16 +141,16 @@
if ([[[popb selectedItem] representedObject] isEqual: contents]) if ([[[popb selectedItem] representedObject] isEqual: contents])
{ {
if ([popb pullsDown] == NO) if ([popb pullsDown] == NO)
[super _drawImage:[NSImage imageNamed:@"common_Nibble"] inFrame:rect]; toDraw = [NSImage imageNamed:@"common_Nibble"];
else else
[super _drawImage:[NSImage imageNamed:@"common_3DArrowDown"] inFrame:rect]; toDraw = [NSImage imageNamed:@"common_3DArrowDown"];
} }
else if ([[[popb selectedItem] representedObject] isEqual: cell_image]) else if ([[[popb selectedItem] representedObject] isEqual: cell_image])
{ {
if ([popb pullsDown] == NO) if ([popb pullsDown] == NO)
[super _drawImage:[NSImage imageNamed:@"common_UpAndDownArrowSmall.tiff"] inFrame:rect]; toDraw = [NSImage imageNamed:@"common_UpAndDownArrowSmall.tiff"];
else else
[super _drawImage:[NSImage imageNamed:@"common_DownArrowSmall"] inFrame:rect]; toDraw = [NSImage imageNamed:@"common_DownArrowSmall"];
} }
} }
else if ([view isKindOfClass:[NSPopUpButton class]]) else if ([view isKindOfClass:[NSPopUpButton class]])
@ -143,17 +159,34 @@
isEqual: contents]) isEqual: contents])
{ {
if ([(NSPopUpButton *)view pullsDown] == NO) if ([(NSPopUpButton *)view pullsDown] == NO)
[super _drawImage:[NSImage imageNamed:@"common_Nibble"] inFrame:rect]; toDraw = [NSImage imageNamed:@"common_Nibble"];
else else
[super _drawImage:[NSImage imageNamed:@"common_3DArrowDown"] inFrame:rect]; toDraw = [NSImage imageNamed:@"common_3DArrowDown"];
} }
else if ([[[(NSPopUpButton *)view selectedItem] representedObject] isEqual: cell_image]) else if ([[[(NSPopUpButton *)view selectedItem] representedObject] isEqual: cell_image])
{ {
if ([(NSPopUpButton *)view pullsDown] == NO) if ([(NSPopUpButton *)view pullsDown] == NO)
[super _drawImage:[NSImage imageNamed:@"common_UpAndDownArrowSmall"] inFrame:rect]; toDraw = [NSImage imageNamed:@"common_UpAndDownArrowSmall"];
else else
[super _drawImage:[NSImage imageNamed:@"common_DownArrowSmall"] inFrame:rect]; toDraw = [NSImage imageNamed:@"common_DownArrowSmall"];
} }
} }
if (toDraw != nil)
{
NSSize size;
NSPoint position;
[toDraw setBackgroundColor: backColor];
size = [toDraw size];
position.x = MAX(NSMidX(rect) - (size.width/2.),0.);
position.y = MAX(NSMidY(rect) - (size.height/2.),0.);
/*
* 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.
*/
if ([control_view isFlipped])
position.y += size.height;
[toDraw compositeToPoint: position operation: NSCompositeCopy];
}
} }
@end @end