resizeWithOldSuperviewSize: should call setFrame

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@6509 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Adam Fedor 2000-04-25 15:08:02 +00:00
parent 69a52bc498
commit 5d99b04838
2 changed files with 100 additions and 156 deletions

View file

@ -1,3 +1,15 @@
2000-04-25 Adam Fedor <fedor@gnu.org>
* Source/NSView.m (-_updateBoundsMatrix): New method from
common code in other methods.
(-setFrame:): Use it. Also check if frame actually changed before
doing something.
(-scaleUnitSquareToSize): Use it.
(-setBounds): Likewise.
(-setBoundsSize:): Likewise.
(-resizeWithOldSuperviewSize:) Likewise. Also use setFrame to actually
set the frame (This is apparently what OpenStep 4.2 does).
2000-04-24 Adam Fedor <fedor@gnu.org> 2000-04-24 Adam Fedor <fedor@gnu.org>
* Source/NSFont.m (-isEqual:): Implement. * Source/NSFont.m (-isEqual:): Implement.

View file

@ -570,8 +570,44 @@ GSSetDragTypes(NSView* obj, NSArray *types)
} }
} }
- (void) _updateBoundsMatrix
{
float sx;
float sy;
if (_bounds.size.width == 0)
{
if (_frame.size.width == 0)
sx = 1;
else
sx = FLT_MAX;
}
else
{
sx = _frame.size.width / _bounds.size.width;
}
if (_bounds.size.height == 0)
{
if (_frame.size.height == 0)
sy = 1;
else
sy = FLT_MAX;
}
else
{
sy = _frame.size.height / _bounds.size.height;
}
[_boundsMatrix scaleTo: sx : sy];
if (sx != 1 || sy != 1)
_is_rotated_or_scaled_from_base = YES;
}
- (void) setFrame: (NSRect)frameRect - (void) setFrame: (NSRect)frameRect
{ {
BOOL changedOrigin = NO;
BOOL changedSize = NO;
NSSize old_size = _frame.size; NSSize old_size = _frame.size;
if (frameRect.size.width < 0) if (frameRect.size.width < 0)
@ -584,19 +620,36 @@ GSSetDragTypes(NSView* obj, NSArray *types)
NSWarnMLog(@"given negative height", 0); NSWarnMLog(@"given negative height", 0);
frameRect.size.height = 0; frameRect.size.height = 0;
} }
if (_coordinates_valid)
{ if (NSMinX(_frame) != NSMinX(frameRect)
(*invalidateImp)(self, invalidateSel); || NSMinY(_frame) != NSMinY(frameRect))
} changedOrigin = YES;
if (NSWidth(_frame) != NSWidth(frameRect)
|| NSHeight(_frame) != NSHeight(frameRect))
changedSize = YES;
_frame = frameRect; _frame = frameRect;
_bounds.size = _frame.size; _bounds.size = _frame.size;
[_frameMatrix setFrameOrigin: _frame.origin]; if (changedOrigin)
[_frameMatrix setFrameOrigin: _frame.origin];
[self resizeSubviewsWithOldSize: old_size]; if (changedSize && _is_rotated_or_scaled_from_base)
if (_post_frame_changes) {
[[NSNotificationCenter defaultCenter] [self _updateBoundsMatrix];
postNotificationName: NSViewFrameDidChangeNotification }
object: self];
if (changedSize || changedOrigin)
{
if (_coordinates_valid)
{
(*invalidateImp)(self, invalidateSel);
}
[self resizeSubviewsWithOldSize: old_size];
if (_post_frame_changes)
[[NSNotificationCenter defaultCenter]
postNotificationName: NSViewFrameDidChangeNotification
object: self];
}
} }
- (void) setFrameOrigin: (NSPoint)newOrigin - (void) setFrameOrigin: (NSPoint)newOrigin
@ -680,9 +733,6 @@ GSSetDragTypes(NSView* obj, NSArray *types)
- (void) scaleUnitSquareToSize: (NSSize)newSize - (void) scaleUnitSquareToSize: (NSSize)newSize
{ {
float sx;
float sy;
if (newSize.width < 0) if (newSize.width < 0)
{ {
NSWarnMLog(@"given negative width", 0); NSWarnMLog(@"given negative width", 0);
@ -701,32 +751,8 @@ GSSetDragTypes(NSView* obj, NSArray *types)
_bounds.size.height = _frame.size.height / newSize.height; _bounds.size.height = _frame.size.height / newSize.height;
_is_rotated_or_scaled_from_base = YES; _is_rotated_or_scaled_from_base = YES;
if (_bounds.size.width == 0) [self _updateBoundsMatrix];
{
if (_frame.size.width == 0)
sx = 1;
else
sx = FLT_MAX;
}
else
{
sx = _frame.size.width / _bounds.size.width;
}
if (_bounds.size.height == 0)
{
if (_frame.size.height == 0)
sy = 1;
else
sy = FLT_MAX;
}
else
{
sy = _frame.size.height / _bounds.size.height;
}
[_boundsMatrix scaleBy: sx : sy];
if (_post_bounds_changes) if (_post_bounds_changes)
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
@ -736,8 +762,6 @@ GSSetDragTypes(NSView* obj, NSArray *types)
- (void) setBounds: (NSRect)aRect - (void) setBounds: (NSRect)aRect
{ {
float sx, sy;
if (aRect.size.width < 0) if (aRect.size.width < 0)
{ {
NSWarnMLog(@"given negative width", 0); NSWarnMLog(@"given negative width", 0);
@ -755,35 +779,7 @@ GSSetDragTypes(NSView* obj, NSArray *types)
_bounds = aRect; _bounds = aRect;
[_boundsMatrix [_boundsMatrix
setFrameOrigin: NSMakePoint(-_bounds.origin.x,-_bounds.origin.y)]; setFrameOrigin: NSMakePoint(-_bounds.origin.x,-_bounds.origin.y)];
[self _updateBoundsMatrix];
if (_bounds.size.width == 0)
{
if (_frame.size.width == 0)
sx = 1;
else
sx = FLT_MAX;
}
else
{
sx = _frame.size.width / _bounds.size.width;
}
if (_bounds.size.height == 0)
{
if (_frame.size.height == 0)
sy = 1;
else
sy = FLT_MAX;
}
else
{
sy = _frame.size.height / _bounds.size.height;
}
[_boundsMatrix scaleTo: sx : sy];
if (sx != 1 || sy != 1)
_is_rotated_or_scaled_from_base = YES;
if (_post_bounds_changes) if (_post_bounds_changes)
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
@ -811,8 +807,6 @@ GSSetDragTypes(NSView* obj, NSArray *types)
- (void) setBoundsSize: (NSSize)newSize - (void) setBoundsSize: (NSSize)newSize
{ {
float sx, sy;
if (newSize.width < 0) if (newSize.width < 0)
{ {
NSWarnMLog(@"given negative width", 0); NSWarnMLog(@"given negative width", 0);
@ -829,35 +823,7 @@ GSSetDragTypes(NSView* obj, NSArray *types)
} }
_bounds.size = newSize; _bounds.size = newSize;
[self _updateBoundsMatrix];
if (_bounds.size.width == 0)
{
if (_frame.size.width == 0)
sx = 1;
else
sx = FLT_MAX;
}
else
{
sx = _frame.size.width / _bounds.size.width;
}
if (_bounds.size.height == 0)
{
if (_frame.size.height == 0)
sy = 1;
else
sy = FLT_MAX;
}
else
{
sy = _frame.size.height / _bounds.size.height;
}
[_boundsMatrix scaleTo: sx : sy];
if (sx != 1 || sy != 1)
_is_rotated_or_scaled_from_base = YES;
if (_post_bounds_changes) if (_post_bounds_changes)
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
@ -1149,7 +1115,7 @@ GSSetDragTypes(NSView* obj, NSArray *types)
float change; float change;
float changePerOption; float changePerOption;
int options = 0; int options = 0;
NSSize old_size = _frame.size; NSRect newFrame, newBounds;
NSSize superViewFrameSize = [_super_view frame].size; NSSize superViewFrameSize = [_super_view frame].size;
BOOL changedOrigin = NO; BOOL changedOrigin = NO;
BOOL changedSize = NO; BOOL changedSize = NO;
@ -1157,6 +1123,8 @@ GSSetDragTypes(NSView* obj, NSArray *types)
if (_autoresizingMask == NSViewNotSizable) if (_autoresizingMask == NSViewNotSizable)
return; return;
newFrame = _frame;
newBounds = _bounds;
/* /*
* determine if and how the X axis can be resized * determine if and how the X axis can be resized
*/ */
@ -1177,18 +1145,18 @@ GSSetDragTypes(NSView* obj, NSArray *types)
if (_autoresizingMask & NSViewWidthSizable) if (_autoresizingMask & NSViewWidthSizable)
{ {
float oldFrameWidth = _frame.size.width; float oldFrameWidth = newFrame.size.width;
_frame.size.width += changePerOption; newFrame.size.width += changePerOption;
if (_is_rotated_or_scaled_from_base) if (_is_rotated_or_scaled_from_base)
_bounds.size.width *= _frame.size.width/oldFrameWidth; newBounds.size.width *= newFrame.size.width/oldFrameWidth;
else else
_bounds.size.width += changePerOption; newBounds.size.width += changePerOption;
changedSize = YES; changedSize = YES;
} }
if (_autoresizingMask & NSViewMinXMargin) if (_autoresizingMask & NSViewMinXMargin)
{ {
_frame.origin.x += changePerOption; newFrame.origin.x += changePerOption;
changedOrigin = YES; changedOrigin = YES;
} }
} }
@ -1214,13 +1182,13 @@ GSSetDragTypes(NSView* obj, NSArray *types)
if (_autoresizingMask & NSViewHeightSizable) if (_autoresizingMask & NSViewHeightSizable)
{ {
float oldFrameHeight = _frame.size.height; float oldFrameHeight = newFrame.size.height;
_frame.size.height += changePerOption; newFrame.size.height += changePerOption;
if (_is_rotated_or_scaled_from_base) if (_is_rotated_or_scaled_from_base)
_bounds.size.height *= _frame.size.height/oldFrameHeight; newBounds.size.height *= newFrame.size.height/oldFrameHeight;
else else
_bounds.size.height += changePerOption; newBounds.size.height += changePerOption;
changedSize = YES; changedSize = YES;
} }
if (_autoresizingMask & (NSViewMaxYMargin | NSViewMinYMargin)) if (_autoresizingMask & (NSViewMaxYMargin | NSViewMinYMargin))
@ -1229,7 +1197,7 @@ GSSetDragTypes(NSView* obj, NSArray *types)
{ {
if (_autoresizingMask & NSViewMaxYMargin) if (_autoresizingMask & NSViewMaxYMargin)
{ {
_frame.origin.y += changePerOption; newFrame.origin.y += changePerOption;
changedOrigin = YES; changedOrigin = YES;
} }
} }
@ -1237,56 +1205,17 @@ GSSetDragTypes(NSView* obj, NSArray *types)
{ {
if (_autoresizingMask & NSViewMinYMargin) if (_autoresizingMask & NSViewMinYMargin)
{ {
_frame.origin.y += changePerOption; newFrame.origin.y += changePerOption;
changedOrigin = YES; changedOrigin = YES;
} }
} }
} }
} }
[self setFrame: newFrame];
if (changedOrigin) /* Since setFrame sets the bounds itself, reset it correctly */
[_frameMatrix setFrameOrigin: _frame.origin]; _bounds = newBounds;
if (changedSize && _is_rotated_or_scaled_from_base) if (changedSize && _is_rotated_or_scaled_from_base)
{ [self _updateBoundsMatrix];
float sx;
float sy;
if (_bounds.size.width == 0)
{
if (_frame.size.width == 0)
sx = 1;
else
sx = FLT_MAX;
}
else
{
sx = _frame.size.width / _bounds.size.width;
}
if (_bounds.size.height == 0)
{
if (_frame.size.height == 0)
sy = 1;
else
sy = FLT_MAX;
}
else
{
sy = _frame.size.height / _bounds.size.height;
}
[_boundsMatrix scaleTo: sx : sy];
}
if (changedSize || changedOrigin)
{
if (_coordinates_valid)
{
(*invalidateImp)(self, invalidateSel);
}
[self resizeSubviewsWithOldSize: old_size];
}
} }
- (void) allocateGState - (void) allocateGState
@ -1369,6 +1298,9 @@ GSSetDragTypes(NSView* obj, NSArray *types)
h = NSHeight(rect); h = NSHeight(rect);
DPSrectviewclip(ctxt, x, y, w, h); DPSrectviewclip(ctxt, x, y, w, h);
/* Add any scaling due to the bounds matrix */
//[_boundsMatrix concat];
/* Allow subclases to make other modifications */ /* Allow subclases to make other modifications */
[self setUpGState]; [self setUpGState];
_renew_gstate = 0; _renew_gstate = 0;