Nocolas patch for cell size calculation, plus some tidying

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@4869 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 1999-09-11 05:25:53 +00:00
parent dd6369058e
commit 63b1e96172
5 changed files with 168 additions and 121 deletions

View file

@ -1,3 +1,21 @@
Sat Sep 11 1999 Nicola Pero <n.pero@mi.flashnet.it>
* Source/NSControl.m ([-sizeToFit]): implemented method.
* Source/NSCell.m ([-cellSize]): implemented method.
([-drawingRectForBounds:]): implemented method.
([-imageRectForBounds:]): implemented method.
([-titleRectForBounds:]): implemented method.
([-drawInteriorWithFrame:inView:]): bug fix; calculate the drawing
rect (the cell frame minus the borders) correctly (by invoking
drawingRectForBounds:). Previously, xDist was incorrectly used
instead of the width of the border, and yDist instead of the
height of the border.
* NSButtonCell.m ([-drawingRectForBounds:]): implemented method.
([-drawInteriorWithFrame:inView:]): same bug fix as above.
* NSTextFieldCell.m ([-cellSize]): removed method; it is no longer
needed. Now [-cellSize] is inherited from the NSCell class.
([-drawInteriorWithFrame:inView:]): same bug fix as above.
1999-09-10 Carl Lindberg <Carl.Lindberg@hbo.com> 1999-09-10 Carl Lindberg <Carl.Lindberg@hbo.com>
* Source/NSDocument.m: new file, implementation. * Source/NSDocument.m: new file, implementation.

View file

@ -424,7 +424,7 @@
if ([self isTransparent]) if ([self isTransparent])
return; return;
cellFrame = NSInsetRect(cellFrame, xDist, yDist); cellFrame = [self drawingRectForBounds: cellFrame];
// determine the background color // determine the background color
if ([self state]) if ([self state])
@ -638,7 +638,7 @@
break; break;
} }
// Add spacing between text/image and border // Add some spacing between text/image and border
s.width += 2 * xDist; s.width += 2 * xDist;
s.height += 2 * yDist; s.height += 2 * yDist;
@ -654,6 +654,18 @@
return s; return s;
} }
- (NSRect) drawingRectForBounds: (NSRect)theRect
{
NSSize borderSize;
// Get border size
if (cell_bordered)
borderSize = [NSCell sizeForBorderType: NSBezelBorder];
else
borderSize = [NSCell sizeForBorderType: NSNoBorder];
return NSInsetRect (theRect, borderSize.width, borderSize.height);
}
- (id) copyWithZone: (NSZone*)zone - (id) copyWithZone: (NSZone*)zone
{ {

View file

@ -7,8 +7,10 @@
Author: Scott Christley <scottc@net-community.com> Author: Scott Christley <scottc@net-community.com>
Date: 1996 Date: 1996
Author: Felipe A. Rodriguez <far@ix.netcom.com> Modifications: Felipe A. Rodriguez <far@ix.netcom.com>
Date: August 1998 Date: August 1998
Rewrite: Multiple authors
Date: 1999
This file is part of the GNUstep GUI Library. This file is part of the GNUstep GUI Library.
@ -58,16 +60,18 @@ static NSColor *clearCol = nil;
@implementation NSCell @implementation NSCell
static Class imageClass; static Class imageClass;
static Class cellClass;
// /*
// Class methods * Class methods
// */
+ (void) initialize + (void) initialize
{ {
if (self == [NSCell class]) if (self == [NSCell class])
{ {
[self setVersion: 1]; [self setVersion: 1];
imageClass = [NSImage class]; imageClass = [NSImage class];
cellClass = [NSCell class];
} }
} }
@ -76,9 +80,9 @@ static Class imageClass;
return NO; return NO;
} }
// /*
// Instance methods * Instance methods
// */
- _init - _init
{ {
cell_type = NSNullCellType; cell_type = NSNullCellType;
@ -159,41 +163,85 @@ static Class imageClass;
[super dealloc]; [super dealloc];
} }
// /*
// Determining Component Sizes * Determining Component Sizes
// */
- (void) calcDrawInfo: (NSRect)aRect - (void) calcDrawInfo: (NSRect)aRect
{ {
} }
- (NSSize) cellSize - (NSSize) cellSize
{ {
return NSZeroSize; NSSize borderSize, s;
// Get border size
if (cell_bordered)
borderSize = [callClass sizeForBorderType: NSLineBorder];
else if (cell_bezeled)
borderSize = [callClass sizeForBorderType: NSBezelBorder];
else
borderSize = [callClass sizeForBorderType: NSNoBorder];
// Get Content Size
switch (cell_type)
{
case NSTextCellType:
s = NSMakeSize([cell_font widthOfString: contents],
[cell_font pointSize]);
// If text, add in a distance between text and borders
// otherwise the text will mess up with the borders
s.width += 2 * xDist;
s.height += 2 * yDist;
break;
case NSImageCellType:
s = [cell_image size];
break;
case NSNullCellType:
s = NSZeroSize;
break;
}
// Add in border size
s.width += 2 * borderSize.width;
s.height += 2 * borderSize.height;
return s;
} }
- (NSSize) cellSizeForBounds: (NSRect)aRect - (NSSize) cellSizeForBounds: (NSRect)aRect
{ {
// TODO
return NSZeroSize; return NSZeroSize;
} }
- (NSRect) drawingRectForBounds: (NSRect)theRect - (NSRect) drawingRectForBounds: (NSRect)theRect
{ {
return NSZeroRect; NSSize borderSize;
// Get border size
if (cell_bordered)
borderSize = [callClass sizeForBorderType: NSLineBorder];
else if (cell_bezeled)
borderSize = [callClass sizeForBorderType: NSBezelBorder];
else
borderSize = [callClass sizeForBorderType: NSNoBorder];
return NSInsetRect (theRect, borderSize.width, borderSize.height);
} }
- (NSRect) imageRectForBounds: (NSRect)theRect - (NSRect) imageRectForBounds: (NSRect)theRect
{ {
return NSZeroRect; return [self drawingRectForBounds: theRect];
} }
- (NSRect) titleRectForBounds: (NSRect)theRect - (NSRect) titleRectForBounds: (NSRect)theRect
{ {
return NSZeroRect; return [self drawingRectForBounds: theRect];
} }
// /*
// Setting the NSCell's Type * Setting the NSCell's Type
// */
- (void) setType: (NSCellType)aType - (void) setType: (NSCellType)aType
{ {
cell_type = aType; cell_type = aType;
@ -204,9 +252,9 @@ static Class imageClass;
return cell_type; return cell_type;
} }
// /*
// Setting the NSCell's State * Setting the NSCell's State
// */
- (void) setState: (int)value - (void) setState: (int)value
{ {
cell_state = value; cell_state = value;
@ -217,9 +265,9 @@ static Class imageClass;
return cell_state; return cell_state;
} }
// /*
// Enabling and Disabling the NSCell * Enabling and Disabling the NSCell
// */
- (BOOL) isEnabled - (BOOL) isEnabled
{ {
return cell_enabled; return cell_enabled;
@ -230,17 +278,17 @@ static Class imageClass;
cell_enabled = flag; cell_enabled = flag;
} }
// /*
// Determining the first responder * Determining the first responder
// */
- (BOOL) acceptsFirstResponder - (BOOL) acceptsFirstResponder
{ {
return cell_enabled; return cell_enabled;
} }
// /*
// Setting the Image * Setting the Image
// */
- (NSImage*) image - (NSImage*) image
{ {
return cell_image; return cell_image;
@ -255,9 +303,9 @@ static Class imageClass;
[self setType: NSImageCellType]; [self setType: NSImageCellType];
} }
// /*
// Setting the NSCell's Value * Setting the NSCell's Value
// */
- (double) doubleValue - (double) doubleValue
{ {
return [contents doubleValue]; return [contents doubleValue];
@ -313,9 +361,9 @@ static Class imageClass;
contents = _string; contents = _string;
} }
// /*
// Interacting with Other NSCells * Interacting with Other NSCells
// */
- (void) takeDoubleValueFrom: (id)sender - (void) takeDoubleValueFrom: (id)sender
{ {
[self setDoubleValue: [sender doubleValue]]; [self setDoubleValue: [sender doubleValue]];
@ -336,9 +384,9 @@ static Class imageClass;
[self setStringValue: [sender stringValue]]; [self setStringValue: [sender stringValue]];
} }
// /*
// Modifying Text Attributes * Modifying Text Attributes
// */
- (NSTextAlignment) alignment - (NSTextAlignment) alignment
{ {
return text_align; return text_align;
@ -413,9 +461,9 @@ static Class imageClass;
return NO; return NO;
} }
// /*
// Editing Text * Editing Text
// */
- (NSText*) setUpFieldEditorAttributes: (NSText*)textObject - (NSText*) setUpFieldEditorAttributes: (NSText*)textObject
{ {
return nil; return nil;
@ -482,9 +530,9 @@ static Class imageClass;
[textObject display]; [textObject display];
} }
// /*
// Validating Input * Validating Input
// */
- (int) entryType - (int) entryType
{ {
return entry_type; return entry_type;
@ -500,9 +548,9 @@ static Class imageClass;
entry_type = aType; entry_type = aType;
} }
// /*
// Formatting Data * Formatting Data
// */
- (void) setFloatingPointFormat: (BOOL)autoRange - (void) setFloatingPointFormat: (BOOL)autoRange
left: (unsigned int)leftDigits left: (unsigned int)leftDigits
right: (unsigned int)rightDigits right: (unsigned int)rightDigits
@ -512,9 +560,9 @@ static Class imageClass;
cell_float_right = rightDigits; cell_float_right = rightDigits;
} }
// /*
// Modifying Graphic Attributes * Modifying Graphic Attributes
// */
- (BOOL) isBezeled - (BOOL) isBezeled
{ {
return cell_bezeled; return cell_bezeled;
@ -544,9 +592,9 @@ static Class imageClass;
cell_bezeled = NO; cell_bezeled = NO;
} }
// /*
// Setting Parameters * Setting Parameters
// */
- (int) cellAttribute: (NSCellAttribute)aParameter - (int) cellAttribute: (NSCellAttribute)aParameter
{ {
return 0; return 0;
@ -556,9 +604,9 @@ static Class imageClass;
{ {
} }
// /*
// Displaying * Displaying
// */
- (NSView*) controlView - (NSView*) controlView
{ {
return control_view; return control_view;
@ -663,8 +711,8 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
- (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView - (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
{ {
cellFrame = NSInsetRect(cellFrame, xDist, yDist); cellFrame = [self drawingRectForBounds: cellFrame];
// Clear the cell frame // Clear the cell frame
if ([self isOpaque]) if ([self isOpaque])
{ {
@ -735,9 +783,9 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
} }
} }
// /*
// Target and Action * Target and Action
// */
- (SEL) action - (SEL) action
{ {
return NULL; return NULL;
@ -803,9 +851,9 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
[self highlight: NO withFrame: [cv frame] inView: cv]; [self highlight: NO withFrame: [cv frame] inView: cv];
} }
// /*
// Assigning a Tag * Assigning a Tag
// */
- (void) setTag: (int)anInt - (void) setTag: (int)anInt
{ {
[NSException raise: NSInternalInconsistencyException [NSException raise: NSInternalInconsistencyException
@ -817,17 +865,17 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
return -1; return -1;
} }
// /*
// Handling Keyboard Alternatives * Handling Keyboard Alternatives
// */
- (NSString*) keyEquivalent - (NSString*) keyEquivalent
{ {
return @""; return @"";
} }
// /*
// Tracking the Mouse * Tracking the Mouse
// */
- (BOOL) continueTracking: (NSPoint)lastPoint - (BOOL) continueTracking: (NSPoint)lastPoint
at: (NSPoint)currentPoint at: (NSPoint)currentPoint
inView: (NSView *)controlView inView: (NSView *)controlView
@ -1010,16 +1058,16 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
return NO; // Otherwise return NO return NO; // Otherwise return NO
} }
// /*
// Managing the Cursor * Managing the Cursor
// */
- (void) resetCursorRect: (NSRect)cellFrame inView: (NSView *)controlView - (void) resetCursorRect: (NSRect)cellFrame inView: (NSView *)controlView
{ {
} }
// /*
// Comparing to Another NSCell * Comparing to Another NSCell
// */
- (NSComparisonResult) compare: (id)otherCell - (NSComparisonResult) compare: (id)otherCell
{ {
if ([otherCell isKindOfClass: [NSCell class]] == NO) if ([otherCell isKindOfClass: [NSCell class]] == NO)
@ -1032,9 +1080,9 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
return [contents compare: ((NSCell*)otherCell)->contents]; return [contents compare: ((NSCell*)otherCell)->contents];
} }
// /*
// Using the NSCell to Represent an Object * Using the NSCell to Represent an Object
// */
- (id) representedObject - (id) representedObject
{ {
return represented_object; return represented_object;
@ -1075,9 +1123,9 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
return c; return c;
} }
// /*
// NSCoding protocol * NSCoding protocol
// */
- (void) encodeWithCoder: (NSCoder*)aCoder - (void) encodeWithCoder: (NSCoder*)aCoder
{ {
[aCoder encodeObject: contents]; [aCoder encodeObject: contents];
@ -1129,9 +1177,9 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
@end @end
// /*
// Methods the backend should implement * Methods the backend should implement
// */
@implementation NSCell (GNUstepBackend) @implementation NSCell (GNUstepBackend)
+ (NSSize) sizeForBorderType: (NSBorderType)aType + (NSSize) sizeForBorderType: (NSBorderType)aType
@ -1151,3 +1199,4 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
} }
@end @end

View file

@ -296,6 +296,7 @@ static Class cellClass;
- (void) sizeToFit - (void) sizeToFit
{ {
[self setFrameSize: [cell cellSize]];
} }
/* /*

View file

@ -97,37 +97,6 @@
return c; return c;
} }
//
// Determining Component Sizes
//
- (NSSize) cellSize
{
NSFont *f;
NSSize borderSize, s;
// Get border size
if ([self isBordered])
{
if ([self isBezeled])
borderSize = [NSCell sizeForBorderType: NSBezelBorder];
else
borderSize = [NSCell sizeForBorderType: NSLineBorder];
}
else
borderSize = [NSCell sizeForBorderType: NSNoBorder];
// Get size of text with a little buffer space
f = [self font];
s = NSMakeSize([f widthOfString: [self stringValue]] + 2,
[f pointSize] + 2);
// Add in border size
s.width += 2 * borderSize.width;
s.height += 2 * borderSize.height;
return s;
}
// //
// Modifying Graphic Attributes // Modifying Graphic Attributes
// //
@ -226,10 +195,8 @@
{ {
if (draw_background) if (draw_background)
{ {
NSRect backgroundRect = NSInsetRect(cellFrame, xDist, yDist);
[background_color set]; [background_color set];
NSRectFill(backgroundRect); NSRectFill ([self drawingRectForBounds: cellFrame]);
} }
[super drawInteriorWithFrame: cellFrame inView: controlView]; [super drawInteriorWithFrame: cellFrame inView: controlView];
} }