Fill out NSBox implementation.

Minor bug fixes.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@2536 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Scott Christley 1997-10-20 22:01:25 +00:00
parent 4ca0835d49
commit 502453429f
7 changed files with 372 additions and 13 deletions

View file

@ -1,4 +1,19 @@
Thu Oct 16 12:28:00 1997 Scott Christley <scottc@stetson.net-community.com>
Mon Oct 20 14:32:55 1997 Scott Christley <scottc@net-community.com>
* Fill out NSBox implementation.
* Headers/gnustep/gui/NSCell.h (+sizeForBorderType:): New method.
* Source/NSCell.m (+sizeForBorderType:): New method.
* Source/NSBox.m: Fill out implementation.
* Source/NSTextField.m (-initWithFrame:,-setTextCursor:,-dealloc):
Correct retain/release behavior of cursor.
* Source/NSTextFieldCell.m (-cellSize): Implement.
* Source/NSView.m (-removeTrackingRect:): Comment out release
of object as we haven't retained it.
Thu Oct 16 12:28:00 1997 Scott Christley <scottc@net-community.com>
* config.mak.in: Delete.
* Headers/gnustep/gui/NSScrollView.h: Correct datatype.

View file

@ -328,5 +328,15 @@ enum {
@end
//
// Methods the backend should implement
//
@interface NSCell (GNUstepBackend)
// Returns the size of a border
+ (NSSize)sizeForBorderType:(NSBorderType)aType;
@end
#endif // _GNUstep_H_NSCell

View file

@ -33,6 +33,10 @@
#include <AppKit/NSBox.h>
#include <AppKit/NSTextFieldCell.h>
@interface NSBox (Private)
- (NSRect)calcSizes;
@end
@implementation NSBox
//
@ -55,6 +59,11 @@
[super initWithFrame:frameRect];
cell = [[NSTextFieldCell alloc] initTextCell:@"Title"];
[cell setAlignment: NSCenterTextAlignment];
[cell setBordered: NO];
[cell setEditable: NO];
[cell setDrawsBackground: YES];
[cell setBackgroundColor: [window backgroundColor]];
offsets.width = 5;
offsets.height = 5;
border_rect = bounds;
@ -88,22 +97,36 @@
- (void)setBorderType:(NSBorderType)aType
{
border_type = aType;
if (border_type != aType)
{
border_type = aType;
[content_view setFrame: [self calcSizes]];
[self setNeedsDisplay: YES];
}
}
- (void)setTitle:(NSString *)aString
{
[cell setStringValue:aString];
[content_view setFrame: [self calcSizes]];
[self setNeedsDisplay: YES];
}
- (void)setTitleFont:(NSFont *)fontObj
{
[cell setFont:fontObj];
[content_view setFrame: [self calcSizes]];
[self setNeedsDisplay: YES];
}
- (void)setTitlePosition:(NSTitlePosition)aPosition
{
title_position = aPosition;
if (title_position != aPosition)
{
title_position = aPosition;
[content_view setFrame: [self calcSizes]];
[self setNeedsDisplay: YES];
}
}
- (NSString *)title
@ -146,8 +169,6 @@
- (void)setContentView:(NSView *)aView
{
NSRect r;
if (content_view)
{
// Tell view that it is no longer in a window
@ -168,16 +189,14 @@
[content_view setSuperview:self];
[content_view setNextResponder:self];
[content_view viewWillMoveToWindow:window];
r.origin.x = bounds.origin.x + offsets.width;
r.origin.y = bounds.origin.y + offsets.height;
r.size.width = bounds.size.width - (2 * offsets.width);
r.size.height = bounds.size.height - (2 * offsets.height);
[content_view setFrame:r];
[content_view setFrame: [self calcSizes]];
}
- (void)setContentViewMargins:(NSSize)offsetSize
{
offsets = offsetSize;
[content_view setFrame: [self calcSizes]];
[self setNeedsDisplay: YES];
}
//
@ -185,10 +204,38 @@
//
- (void)setFrameFromContentFrame:(NSRect)contentFrame
{
// First calc the sizes to see how much we are off by
NSRect r = [self calcSizes];
NSRect f = [self frame];
// Add the difference to the frame
f.size.width = f.size.width + (contentFrame.size.width - r.size.width);
f.size.height = f.size.height + (contentFrame.size.height - r.size.height);
[self setFrame: f];
}
- (void)sizeToFit
{}
{
NSRect r = NSZeroRect;
id o, e = [[content_view subviews] objectEnumerator];
// Loop through subviews and calculate rect to encompass all
while ((o = [e nextObject]))
{
NSRect f = [o frame];
if (f.origin.x < r.origin.x)
r.origin.x = f.origin.x;
if (f.origin.y < f.origin.y)
r.origin.y = f.origin.y;
if ((f.origin.x + f.size.width) > (r.origin.x + r.size.width))
r.size.width = (f.origin.x + f.size.width) - r.origin.x;
if ((f.origin.y + f.size.height) > (r.origin.y + r.size.height))
r.size.height = (f.origin.y + f.size.height) - r.origin.y;
}
[self setFrameFromContentFrame: r];
}
//
// Managing the NSView Hierarchy
@ -239,3 +286,238 @@
}
@end
@implementation NSBox (Private)
- (NSRect)calcSizes
{
NSRect r = NSZeroRect;
switch (title_position)
{
case NSNoTitle:
{
NSSize borderSize = [NSCell sizeForBorderType: border_type];
border_rect = bounds;
title_rect = NSZeroRect;
// Add the offsets to the border rect
r.origin.x = border_rect.origin.x + offsets.width + borderSize.width;
r.origin.y = border_rect.origin.y + offsets.height + borderSize.height;
r.size.width = border_rect.size.width - (2 * offsets.width)
- (2 * borderSize.width);
r.size.height = border_rect.size.height - (2 * offsets.height)
- (2 * borderSize.height);
break;
}
case NSAboveTop:
{
NSSize titleSize = [cell cellSize];
NSSize borderSize = [NSCell sizeForBorderType: border_type];
float c;
// Add spacer around title
titleSize.width += 1;
titleSize.height += 1;
// Adjust border rect by title cell
border_rect = bounds;
border_rect.size.height -= titleSize.height + borderSize.height;
// Add the offsets to the border rect
r.origin.x = border_rect.origin.x + offsets.width + borderSize.width;
r.origin.y = border_rect.origin.y + offsets.height + borderSize.height;
r.size.width = border_rect.size.width - (2 * offsets.width)
- (2 * borderSize.width);
r.size.height = border_rect.size.height - (2 * offsets.height)
- (2 * borderSize.height);
// center the title cell
c = (bounds.size.width - titleSize.width) / 2;
if (c < 0) c = 0;
title_rect.origin.x = bounds.origin.x + c;
title_rect.origin.y = bounds.origin.y + border_rect.size.height
+ borderSize.height;
title_rect.size = titleSize;
break;
}
case NSBelowTop:
{
NSSize titleSize = [cell cellSize];
NSSize borderSize = [NSCell sizeForBorderType: border_type];
float c;
// Add spacer around title
titleSize.width += 1;
titleSize.height += 1;
// Adjust border rect by title cell
border_rect = bounds;
// Add the offsets to the border rect
r.origin.x = border_rect.origin.x + offsets.width + borderSize.width;
r.origin.y = border_rect.origin.y + offsets.height + borderSize.height;
r.size.width = border_rect.size.width - (2 * offsets.width)
- (2 * borderSize.width);
r.size.height = border_rect.size.height - (2 * offsets.height)
- (2 * borderSize.height);
// Adjust by the title size
r.size.height -= titleSize.height + borderSize.height;
// center the title cell
c = (border_rect.size.width - titleSize.width) / 2;
if (c < 0) c = 0;
title_rect.origin.x = border_rect.origin.x + c;
title_rect.origin.y = border_rect.origin.y + border_rect.size.height
- titleSize.height - borderSize.height;
title_rect.size = titleSize;
break;
}
case NSAtTop:
{
NSSize titleSize = [cell cellSize];
NSSize borderSize = [NSCell sizeForBorderType: border_type];
float c;
// Add spacer around title
titleSize.width += 1;
titleSize.height += 1;
border_rect = bounds;
// Adjust by the title size
border_rect.size.height -= titleSize.height / 2;
// Add the offsets to the border rect
r.origin.x = border_rect.origin.x + offsets.width + borderSize.width;
r.origin.y = border_rect.origin.y + offsets.height + borderSize.height;
r.size.width = border_rect.size.width - (2 * offsets.width)
- (2 * borderSize.width);
r.size.height = border_rect.size.height - (2 * offsets.height)
- (2 * borderSize.height);
// Adjust by the title size
r.size.height -= (titleSize.height / 2) + borderSize.height;
// center the title cell
c = (border_rect.size.width - titleSize.width) / 2;
if (c < 0) c = 0;
title_rect.origin.x = border_rect.origin.x + c;
title_rect.origin.y = border_rect.origin.y + border_rect.size.height
- (titleSize.height / 2);
title_rect.size = titleSize;
break;
}
case NSAtBottom:
{
NSSize titleSize = [cell cellSize];
NSSize borderSize = [NSCell sizeForBorderType: border_type];
float c;
// Add spacer around title
titleSize.width += 1;
titleSize.height += 1;
border_rect = bounds;
// Adjust by the title size
border_rect.origin.y += titleSize.height / 2;
border_rect.size.height -= titleSize.height / 2;
// Add the offsets to the border rect
r.origin.x = border_rect.origin.x + offsets.width + borderSize.width;
r.origin.y = border_rect.origin.y + offsets.height + borderSize.height;
r.size.width = border_rect.size.width - (2 * offsets.width)
- (2 * borderSize.width);
r.size.height = border_rect.size.height - (2 * offsets.height)
- (2 * borderSize.height);
// Adjust by the title size
r.origin.y += (titleSize.height / 2) + borderSize.height;
r.size.height -= (titleSize.height / 2) + borderSize.height;
// center the title cell
c = (border_rect.size.width - titleSize.width) / 2;
if (c < 0) c = 0;
title_rect.origin.x = c;
title_rect.origin.y = 0;
title_rect.size = titleSize;
break;
}
case NSBelowBottom:
{
NSSize titleSize = [cell cellSize];
NSSize borderSize = [NSCell sizeForBorderType: border_type];
float c;
// Add spacer around title
titleSize.width += 1;
titleSize.height += 1;
// Adjust by the title
border_rect = bounds;
border_rect.origin.y += titleSize.height + borderSize.height;
border_rect.size.height -= titleSize.height + borderSize.height;
// Add the offsets to the border rect
r.origin.x = border_rect.origin.x + offsets.width + borderSize.width;
r.origin.y = border_rect.origin.y + offsets.height + borderSize.height;
r.size.width = border_rect.size.width - (2 * offsets.width)
- (2 * borderSize.width);
r.size.height = border_rect.size.height - (2 * offsets.height)
- (2 * borderSize.height);
// center the title cell
c = (border_rect.size.width - titleSize.width) / 2;
if (c < 0) c = 0;
title_rect.origin.x = c;
title_rect.origin.y = 0;
title_rect.size = titleSize;
break;
}
case NSAboveBottom:
{
NSSize titleSize = [cell cellSize];
NSSize borderSize = [NSCell sizeForBorderType: border_type];
float c;
// Add spacer around title
titleSize.width += 1;
titleSize.height += 1;
border_rect = bounds;
// Add the offsets to the border rect
r.origin.x = border_rect.origin.x + offsets.width + borderSize.width;
r.origin.y = border_rect.origin.y + offsets.height + borderSize.height;
r.size.width = border_rect.size.width - (2 * offsets.width)
- (2 * borderSize.width);
r.size.height = border_rect.size.height - (2 * offsets.height)
- (2 * borderSize.height);
// Adjust by the title size
r.origin.y += titleSize.height + borderSize.height;
r.size.height -= titleSize.height + borderSize.height;
// center the title cell
c = (border_rect.size.width - titleSize.width) / 2;
if (c < 0) c = 0;
title_rect.origin.x = border_rect.origin.x + c;
title_rect.origin.y = border_rect.origin.y + borderSize.height;
title_rect.size = titleSize;
break;
}
}
return r;
}
@end

View file

@ -883,3 +883,16 @@
}
@end
//
// Methods the backend should implement
//
@implementation NSCell (GNUstepBackend)
// Returns the size of a border
+ (NSSize)sizeForBorderType:(NSBorderType)aType
{
return NSZeroSize;
}
@end

View file

@ -84,16 +84,24 @@ id gnustep_gui_nstextfield_cell_class = nil;
// set our cell
[self setCell:[[gnustep_gui_nstextfield_cell_class new] autorelease]];
[cell setState:1];
text_cursor = [NSCursor IBeamCursor];
text_cursor = [[NSCursor IBeamCursor] retain];
return self;
}
- (void)dealloc
{
[text_cursor release];
[super dealloc];
}
//
// Creating copies
//
- (void)setTextCursor:(NSCursor *)aCursor
{
[aCursor retain];
[text_cursor release];
text_cursor = aCursor;
}

View file

@ -103,6 +103,37 @@
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
//

View file

@ -1125,7 +1125,7 @@ static NSRecursiveLock *gnustep_gui_nsview_lock = nil;
m = (TrackingRectangle *)[tracking_rects objectAtIndex:i];
if ([m tag] == tag)
{
[m release];
//[m release];
[tracking_rects removeObjectAtIndex:i];
return;
}