mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-01 16:21:56 +00:00
Bugfix in contentview sizing.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3898 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
576950e10b
commit
c51f88e0a8
2 changed files with 82 additions and 64 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Thu Mar 11 11:35:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||||
|
|
||||||
|
* Source/NSBox.m: Tidied and added code to prevent attempts to set
|
||||||
|
contentview to negative dimensions.
|
||||||
|
|
||||||
Wed Mar 10 12:56:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
Wed Mar 10 12:56:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||||
|
|
||||||
* Source/NSAffineTransform.m: Improved debug logging.
|
* Source/NSAffineTransform.m: Improved debug logging.
|
||||||
|
|
141
Source/NSBox.m
141
Source/NSBox.m
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
#include <gnustep/gui/config.h>
|
#include <gnustep/gui/config.h>
|
||||||
#include <Foundation/NSArray.h>
|
#include <Foundation/NSArray.h>
|
||||||
|
#include <Foundation/NSException.h>
|
||||||
#include <Foundation/NSString.h>
|
#include <Foundation/NSString.h>
|
||||||
|
|
||||||
#include <AppKit/NSBox.h>
|
#include <AppKit/NSBox.h>
|
||||||
|
@ -35,7 +36,7 @@
|
||||||
#include <AppKit/NSTextFieldCell.h>
|
#include <AppKit/NSTextFieldCell.h>
|
||||||
|
|
||||||
@interface NSBox (Private)
|
@interface NSBox (Private)
|
||||||
- (NSRect)calcSizes;
|
- (NSRect) calcSizes;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation NSBox
|
@implementation NSBox
|
||||||
|
@ -43,39 +44,39 @@
|
||||||
//
|
//
|
||||||
// Class methods
|
// Class methods
|
||||||
//
|
//
|
||||||
+ (void)initialize
|
+ (void) initialize
|
||||||
{
|
{
|
||||||
if (self == [NSBox class])
|
if (self == [NSBox class])
|
||||||
{
|
{
|
||||||
// Initial version
|
// Initial version
|
||||||
[self setVersion:1];
|
[self setVersion: 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Instance methods
|
// Instance methods
|
||||||
//
|
//
|
||||||
- initWithFrame:(NSRect)frameRect
|
- (id) initWithFrame: (NSRect)frameRect
|
||||||
{
|
{
|
||||||
[super initWithFrame:frameRect];
|
[super initWithFrame: frameRect];
|
||||||
|
|
||||||
cell = [[NSTextFieldCell alloc] initTextCell:@"Title"];
|
cell = [[NSTextFieldCell alloc] initTextCell: @"Title"];
|
||||||
[cell setAlignment: NSCenterTextAlignment];
|
[cell setAlignment: NSCenterTextAlignment];
|
||||||
[cell setBordered: NO];
|
[cell setBordered: NO];
|
||||||
[cell setEditable: NO];
|
[cell setEditable: NO];
|
||||||
[cell setDrawsBackground: YES];
|
[cell setDrawsBackground: YES];
|
||||||
[cell setBackgroundColor: [window backgroundColor]];
|
[cell setBackgroundColor: [window backgroundColor]];
|
||||||
offsets.width = 5;
|
offsets.width = 5;
|
||||||
offsets.height = 5;
|
offsets.height = 5;
|
||||||
border_rect = bounds;
|
border_rect = bounds;
|
||||||
border_type = NSLineBorder;
|
border_type = NSLineBorder;
|
||||||
title_position = NSAtTop;
|
title_position = NSAtTop;
|
||||||
title_rect = NSZeroRect;
|
title_rect = NSZeroRect;
|
||||||
content_view = [NSView new];
|
content_view = [NSView new];
|
||||||
[super addSubview:content_view];
|
[super addSubview: content_view];
|
||||||
[content_view release];
|
[content_view release];
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
|
@ -89,17 +90,17 @@
|
||||||
//
|
//
|
||||||
// Getting and Modifying the Border and Title
|
// Getting and Modifying the Border and Title
|
||||||
//
|
//
|
||||||
- (NSRect)borderRect
|
- (NSRect) borderRect
|
||||||
{
|
{
|
||||||
return border_rect;
|
return border_rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSBorderType)borderType
|
- (NSBorderType) borderType
|
||||||
{
|
{
|
||||||
return border_type;
|
return border_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setBorderType:(NSBorderType)aType
|
- (void) setBorderType: (NSBorderType)aType
|
||||||
{
|
{
|
||||||
if (border_type != aType)
|
if (border_type != aType)
|
||||||
{
|
{
|
||||||
|
@ -109,21 +110,21 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setTitle:(NSString *)aString
|
- (void) setTitle: (NSString *)aString
|
||||||
{
|
{
|
||||||
[cell setStringValue:aString];
|
[cell setStringValue: aString];
|
||||||
[content_view setFrame: [self calcSizes]];
|
[content_view setFrame: [self calcSizes]];
|
||||||
[self setNeedsDisplay: YES];
|
[self setNeedsDisplay: YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setTitleFont:(NSFont *)fontObj
|
- (void) setTitleFont: (NSFont *)fontObj
|
||||||
{
|
{
|
||||||
[cell setFont:fontObj];
|
[cell setFont: fontObj];
|
||||||
[content_view setFrame: [self calcSizes]];
|
[content_view setFrame: [self calcSizes]];
|
||||||
[self setNeedsDisplay: YES];
|
[self setNeedsDisplay: YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setTitlePosition:(NSTitlePosition)aPosition
|
- (void) setTitlePosition: (NSTitlePosition)aPosition
|
||||||
{
|
{
|
||||||
if (title_position != aPosition)
|
if (title_position != aPosition)
|
||||||
{
|
{
|
||||||
|
@ -133,27 +134,27 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *)title
|
- (NSString*) title
|
||||||
{
|
{
|
||||||
return [cell stringValue];
|
return [cell stringValue];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)titleCell
|
- (id) titleCell
|
||||||
{
|
{
|
||||||
return cell;
|
return cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSFont *)titleFont
|
- (NSFont*) titleFont
|
||||||
{
|
{
|
||||||
return [cell font];
|
return [cell font];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSTitlePosition)titlePosition
|
- (NSTitlePosition) titlePosition
|
||||||
{
|
{
|
||||||
return title_position;
|
return title_position;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSRect)titleRect
|
- (NSRect) titleRect
|
||||||
{
|
{
|
||||||
return title_rect;
|
return title_rect;
|
||||||
}
|
}
|
||||||
|
@ -161,17 +162,17 @@
|
||||||
//
|
//
|
||||||
// Setting and Placing the Content View
|
// Setting and Placing the Content View
|
||||||
//
|
//
|
||||||
- (id)contentView
|
- (id) contentView
|
||||||
{
|
{
|
||||||
return content_view;
|
return content_view;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSSize)contentViewMargins
|
- (NSSize) contentViewMargins
|
||||||
{
|
{
|
||||||
return offsets;
|
return offsets;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setContentView:(NSView *)aView
|
- (void) setContentView: (NSView*)aView
|
||||||
{
|
{
|
||||||
if (aView)
|
if (aView)
|
||||||
{
|
{
|
||||||
|
@ -181,8 +182,11 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setContentViewMargins:(NSSize)offsetSize
|
- (void) setContentViewMargins: (NSSize)offsetSize
|
||||||
{
|
{
|
||||||
|
NSAssert(offsetSize.width >= 0 && offsetSize.height >= 0,
|
||||||
|
@"illegal margins supplied");
|
||||||
|
|
||||||
offsets = offsetSize;
|
offsets = offsetSize;
|
||||||
[content_view setFrame: [self calcSizes]];
|
[content_view setFrame: [self calcSizes]];
|
||||||
[self setNeedsDisplay: YES];
|
[self setNeedsDisplay: YES];
|
||||||
|
@ -191,12 +195,15 @@
|
||||||
//
|
//
|
||||||
// Resizing the Box
|
// Resizing the Box
|
||||||
//
|
//
|
||||||
- (void)setFrameFromContentFrame:(NSRect)contentFrame
|
- (void) setFrameFromContentFrame: (NSRect)contentFrame
|
||||||
{
|
{
|
||||||
// First calc the sizes to see how much we are off by
|
// First calc the sizes to see how much we are off by
|
||||||
NSRect r = [self calcSizes];
|
NSRect r = [self calcSizes];
|
||||||
NSRect f = [self frame];
|
NSRect f = [self frame];
|
||||||
|
|
||||||
|
NSAssert(contentFrame.size.width >= 0 && contentFrame.size.height >= 0,
|
||||||
|
@"illegal content frame supplied");
|
||||||
|
|
||||||
// Add the difference to the frame
|
// Add the difference to the frame
|
||||||
f.size.width = f.size.width + (contentFrame.size.width - r.size.width);
|
f.size.width = f.size.width + (contentFrame.size.width - r.size.width);
|
||||||
f.size.height = f.size.height + (contentFrame.size.height - r.size.height);
|
f.size.height = f.size.height + (contentFrame.size.height - r.size.height);
|
||||||
|
@ -204,7 +211,7 @@
|
||||||
[self setFrame: f];
|
[self setFrame: f];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sizeToFit
|
- (void) sizeToFit
|
||||||
{
|
{
|
||||||
NSRect r = NSZeroRect;
|
NSRect r = NSZeroRect;
|
||||||
id o, e = [[content_view subviews] objectEnumerator];
|
id o, e = [[content_view subviews] objectEnumerator];
|
||||||
|
@ -255,40 +262,41 @@
|
||||||
//
|
//
|
||||||
// Displaying
|
// Displaying
|
||||||
//
|
//
|
||||||
- (void)drawRect:(NSRect)rect
|
- (void) drawRect: (NSRect)rect
|
||||||
{
|
{
|
||||||
|
rect = NSIntersectionRect(bounds, rect);
|
||||||
// Fill inside
|
// Fill inside
|
||||||
[[window backgroundColor] set];
|
[[window backgroundColor] set];
|
||||||
NSRectFill(bounds);
|
NSRectFill(rect);
|
||||||
|
|
||||||
// Draw border
|
// Draw border
|
||||||
switch(border_type)
|
switch (border_type)
|
||||||
{
|
{
|
||||||
case NSNoBorder:
|
case NSNoBorder:
|
||||||
break;
|
break;
|
||||||
case NSLineBorder:
|
case NSLineBorder:
|
||||||
NSFrameRect(border_rect);
|
NSFrameRect(border_rect);
|
||||||
break;
|
break;
|
||||||
case NSBezelBorder:
|
case NSBezelBorder:
|
||||||
NSDrawGrayBezel(border_rect, bounds);
|
NSDrawGrayBezel(border_rect, rect);
|
||||||
break;
|
break;
|
||||||
case NSGrooveBorder:
|
case NSGrooveBorder:
|
||||||
NSDrawGroove(border_rect, bounds);
|
NSDrawGroove(border_rect, rect);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw title
|
// Draw title
|
||||||
switch(title_position)
|
switch (title_position)
|
||||||
{
|
{
|
||||||
case NSNoTitle:
|
case NSNoTitle:
|
||||||
// Nothing to do
|
// Nothing to do
|
||||||
break;
|
break;
|
||||||
case NSAboveTop:
|
case NSAboveTop:
|
||||||
case NSAtTop:
|
case NSAtTop:
|
||||||
case NSBelowTop:
|
case NSBelowTop:
|
||||||
case NSAboveBottom:
|
case NSAboveBottom:
|
||||||
case NSAtBottom:
|
case NSAtBottom:
|
||||||
case NSBelowBottom:
|
case NSBelowBottom:
|
||||||
[cell setBackgroundColor: [window backgroundColor]];
|
[cell setBackgroundColor: [window backgroundColor]];
|
||||||
[cell drawWithFrame: title_rect inView: self];
|
[cell drawWithFrame: title_rect inView: self];
|
||||||
}
|
}
|
||||||
|
@ -337,7 +345,7 @@
|
||||||
|
|
||||||
switch (title_position)
|
switch (title_position)
|
||||||
{
|
{
|
||||||
case NSNoTitle:
|
case NSNoTitle:
|
||||||
{
|
{
|
||||||
NSSize borderSize = [NSCell sizeForBorderType: border_type];
|
NSSize borderSize = [NSCell sizeForBorderType: border_type];
|
||||||
border_rect = bounds;
|
border_rect = bounds;
|
||||||
|
@ -353,7 +361,7 @@
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NSAboveTop:
|
case NSAboveTop:
|
||||||
{
|
{
|
||||||
NSSize titleSize = [cell cellSize];
|
NSSize titleSize = [cell cellSize];
|
||||||
NSSize borderSize = [NSCell sizeForBorderType: border_type];
|
NSSize borderSize = [NSCell sizeForBorderType: border_type];
|
||||||
|
@ -385,7 +393,7 @@
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NSBelowTop:
|
case NSBelowTop:
|
||||||
{
|
{
|
||||||
NSSize titleSize = [cell cellSize];
|
NSSize titleSize = [cell cellSize];
|
||||||
NSSize borderSize = [NSCell sizeForBorderType: border_type];
|
NSSize borderSize = [NSCell sizeForBorderType: border_type];
|
||||||
|
@ -419,7 +427,7 @@
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NSAtTop:
|
case NSAtTop:
|
||||||
{
|
{
|
||||||
NSSize titleSize = [cell cellSize];
|
NSSize titleSize = [cell cellSize];
|
||||||
NSSize borderSize = [NSCell sizeForBorderType: border_type];
|
NSSize borderSize = [NSCell sizeForBorderType: border_type];
|
||||||
|
@ -455,7 +463,7 @@
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NSAtBottom:
|
case NSAtBottom:
|
||||||
{
|
{
|
||||||
NSSize titleSize = [cell cellSize];
|
NSSize titleSize = [cell cellSize];
|
||||||
NSSize borderSize = [NSCell sizeForBorderType: border_type];
|
NSSize borderSize = [NSCell sizeForBorderType: border_type];
|
||||||
|
@ -492,7 +500,7 @@
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NSBelowBottom:
|
case NSBelowBottom:
|
||||||
{
|
{
|
||||||
NSSize titleSize = [cell cellSize];
|
NSSize titleSize = [cell cellSize];
|
||||||
NSSize borderSize = [NSCell sizeForBorderType: border_type];
|
NSSize borderSize = [NSCell sizeForBorderType: border_type];
|
||||||
|
@ -524,7 +532,7 @@
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NSAboveBottom:
|
case NSAboveBottom:
|
||||||
{
|
{
|
||||||
NSSize titleSize = [cell cellSize];
|
NSSize titleSize = [cell cellSize];
|
||||||
NSSize borderSize = [NSCell sizeForBorderType: border_type];
|
NSSize borderSize = [NSCell sizeForBorderType: border_type];
|
||||||
|
@ -559,6 +567,11 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (r.size.width < 0)
|
||||||
|
r.size.width = 0;
|
||||||
|
if (r.size.height < 0)
|
||||||
|
r.size.height = 0;
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue