resizeWithOldSuperviewSize: revert to previous code (in order to fix bug

introduced when MaxX or Y is specified but not Min.  Added reliable
code to avoid fractional values.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3431 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1998-12-12 06:40:23 +00:00
parent 977f5519f1
commit 67ac649c75

View file

@ -612,9 +612,9 @@ PSMatrix* matrix;
post_bounds_changes = flag; post_bounds_changes = flag;
} }
- (void)resizeSubviewsWithOldSize:(NSSize)oldSize // resize subviews only - (void) resizeSubviewsWithOldSize: (NSSize)oldSize // resize subviews only
{ // if we are supposed { // if we are supposed
id e, o; // to and we have never id e, o; // to and we have never
// been rotated // been rotated
if (![self autoresizesSubviews] && !is_rotated_from_base) if (![self autoresizesSubviews] && !is_rotated_from_base)
return; return;
@ -623,105 +623,151 @@ id e, o; // to and we have never
o = [e nextObject]; o = [e nextObject];
while (o) while (o)
{ {
[o resizeWithOldSuperviewSize: oldSize]; // Resize the subview [o resizeWithOldSuperviewSize: oldSize]; // resize it's subviews
o = [e nextObject]; o = [e nextObject];
} }
} }
- (void)resizeWithOldSuperviewSize:(NSSize)oldSize // preliminary FIX ME - (void) resizeWithOldSuperviewSize: (NSSize)oldSize
{ {
float change, changePerOption; float changex;
int options = 0; float changey;
NSSize old_size = bounds.size; NSSize old_size = bounds.size;
NSSize superViewBoundsSize = [super_view bounds].size; BOOL changedOrigin = NO;
BOOL changedOrigin = NO; BOOL changedSize = NO;
BOOL changedSize = NO;
// do nothing if view if (autoresizingMask == NSViewNotSizable)
if(autoresizingMask == NSViewNotSizable) // is not resizable
return; return;
// determine if and how
if(autoresizingMask & NSViewWidthSizable) // the X axis can be
options++; // resized
if(autoresizingMask & NSViewMinXMargin)
options++;
if(autoresizingMask & NSViewMaxXMargin)
options++;
// adjust the X axis if
if(options >= 1) // any X options are
{ // set in the mask
change = superViewBoundsSize.width - oldSize.width;
changePerOption = floor(change/options);
if(autoresizingMask & NSViewWidthSizable) changex = [super_view bounds].size.width - oldSize.width;
{ changey = [super_view bounds].size.height - oldSize.height;
frame.size.width += changePerOption;
bounds.size.width += changePerOption;
changedSize = YES;
}
if(autoresizingMask & NSViewMinXMargin)
{
frame.origin.x += changePerOption;
changedOrigin = YES;
}
if(autoresizingMask & NSViewMaxXMargin)
{
frame.origin.x += changePerOption;
changedOrigin = YES;
}
}
// determine if and how
options = 0; // the Y axis can be
if(autoresizingMask & NSViewHeightSizable) // resized
options++;
if(autoresizingMask & NSViewMinYMargin)
options++;
if(autoresizingMask & NSViewMaxYMargin)
options++;
// adjust the Y axis if
if(options >= 1) // any Y options are
{ // set in the mask
change = superViewBoundsSize.height - oldSize.height;
changePerOption = floor(change/options);
if(autoresizingMask & NSViewHeightSizable)
{
frame.size.height += changePerOption;
bounds.size.height += changePerOption;
changedSize = YES;
}
if(autoresizingMask & NSViewMinYMargin)
{
frame.origin.y += changePerOption;
changedOrigin = YES;
}
if(autoresizingMask & NSViewMaxYMargin)
{
frame.origin.y += changePerOption;
changedOrigin = YES;
}
}
if (changedOrigin)
[frameMatrix setFrameOrigin: frame.origin];
if (changedSize)
{
float sx = frame.size.width / bounds.size.width;
float sy = frame.size.height / bounds.size.height;
[boundsMatrix scaleTo: sx : sy];
}
if (changedSize || changedOrigin)
[self resizeSubviewsWithOldSize: old_size];
// adjust the X axis
fprintf (stderr, "NSView resizeWithOldSuperviewSize: \n"); fprintf (stderr, "NSView resizeWithOldSuperviewSize: \n");
fprintf (stderr, "Change x,y (%1.2f, %1.2f)\n", changex, changey);
fprintf (stderr, fprintf (stderr,
"NSView: frame origin (%1.2f, %1.2f), size (%1.2f, %1.2f)\n", "NSView: old origin (%1.2f, %1.2f), size (%1.2f, %1.2f)\n",
frame.origin.x, frame.origin.y, frame.origin.x, frame.origin.y,
frame.size.width, frame.size.height); frame.size.width, frame.size.height);
fprintf (stderr, "NSView: old size (%1.2f, %1.2f)\n",
oldSize.width, oldSize.height); if (changex)
{
if (autoresizingMask & NSViewWidthSizable)
{
float change;
if (autoresizingMask & NSViewMinXMargin)
{
if (autoresizingMask & NSViewMaxXMargin)
{
change = changex/3.0;
}
else
{
change = changex/2.0;
}
frame.origin.x += change;
changedOrigin = YES;
}
else if (autoresizingMask & NSViewMaxXMargin)
{
change = changex/2.0;
}
else
{
change = changex;
}
bounds.size.width *= (frame.size.width + change);
bounds.size.width /= frame.size.width;
frame.size.width += change;
changedSize = YES;
}
else if (autoresizingMask & NSViewMinXMargin)
{
if (autoresizingMask & NSViewMaxXMargin)
{
frame.origin.x += changex/2.0;
}
else
{
frame.origin.x += changex;
}
changedOrigin = YES;
}
}
if (changey)
{
if (autoresizingMask & NSViewHeightSizable)
{
float change;
if (autoresizingMask & NSViewMinYMargin)
{
if (autoresizingMask & NSViewMaxYMargin)
{
change = changey/3.0;
}
else
{
change = changey/2.0;
}
frame.origin.y += change;
changedOrigin = YES;
}
else if (autoresizingMask & NSViewMaxYMargin)
{
change = changey/2.0;
}
else
{
change = changey;
}
bounds.size.height *= (frame.size.height + change);
bounds.size.height /= frame.size.height;
frame.size.height += change;
changedSize = YES;
}
else if (autoresizingMask & NSViewMinYMargin)
{
if (autoresizingMask & NSViewMaxYMargin)
{
frame.origin.y += changey/2.0;
}
else
{
frame.origin.y += changey;
}
changedOrigin = YES;
}
}
fprintf (stderr,
"NSView: new origin (%1.2f, %1.2f), size (%1.2f, %1.2f)\n",
frame.origin.x, frame.origin.y,
frame.size.width, frame.size.height);
if (changedOrigin)
{
frame.origin.x = floor(frame.origin.x);
frame.origin.y = floor(frame.origin.y);
[frameMatrix setFrameOrigin: frame.origin];
}
if (changedSize)
{
float sx;
float sy;
frame.size.width = floor(frame.size.width);
frame.size.height = floor(frame.size.height);
sx = frame.size.width / bounds.size.width;
sy = frame.size.height / bounds.size.height;
[boundsMatrix scaleTo: sx : sy];
}
if (changedSize || changedOrigin)
{
[self resizeSubviewsWithOldSize: old_size];
}
} }
- (void)allocateGState {} // implemented by the - (void)allocateGState {} // implemented by the
@ -734,7 +780,7 @@ BOOL changedSize = NO;
- (BOOL)canDraw - (BOOL)canDraw
{ // not implemented per { // not implemented per
if(window) // OS spec FIX ME if (window) // OS spec FIX ME
return YES; return YES;
else else
return NO; return NO;
@ -742,7 +788,7 @@ BOOL changedSize = NO;
- (void)display // not per spec FIX ME - (void)display // not per spec FIX ME
{ {
if(!window) // do nothing if not in if (!window) // do nothing if not in
return; // a window's heirarchy return; // a window's heirarchy
[self displayRect:[self visibleRect]]; // display visible rect [self displayRect:[self visibleRect]]; // display visible rect
@ -754,9 +800,9 @@ BOOL changedSize = NO;
[self displayIfNeededIgnoringOpacity]; // view which is and [self displayIfNeededIgnoringOpacity]; // view which is and
else // begin drawing there else // begin drawing there
{ {
if(needs_display) if (needs_display)
{ {
if(invalidRect.size.width > 0 && invalidRect.size.height > 0) if (invalidRect.size.width > 0 && invalidRect.size.height > 0)
{ {
NSView *firstOpaque = [self opaqueAncestor]; NSView *firstOpaque = [self opaqueAncestor];
NSRect rect = invalidRect; // convert rect into NSRect rect = invalidRect; // convert rect into
@ -782,10 +828,10 @@ int i = 0, count; // of our sub views if
{ // need of display with { // need of display with
NSView* subview = [sub_views objectAtIndex:i]; // setNeedsDisplay or NSView* subview = [sub_views objectAtIndex:i]; // setNeedsDisplay or
// stNeedsDisplayInRect // stNeedsDisplayInRect
if(subview->needs_display) if (subview->needs_display)
{ {
NSRect rect = subview->invalidRect; NSRect rect = subview->invalidRect;
if(rect.size.width > 0 && rect.size.height > 0) if (rect.size.width > 0 && rect.size.height > 0)
[subview displayRect:rect]; // display invalid rect [subview displayRect:rect]; // display invalid rect
else else
[subview displayIfNeededIgnoringOpacity]; [subview displayIfNeededIgnoringOpacity];
@ -797,12 +843,12 @@ int i = 0, count; // of our sub views if
{ {
int i = 0, count; // display self and all int i = 0, count; // display self and all
// of our sub views if // of our sub views if
if(!window) // any part of self has if (!window) // any part of self has
return; // been marked to be in return; // been marked to be in
// need of display with // need of display with
if (needs_display) // setNeedsDisplay or if (needs_display) // setNeedsDisplay or
{ // stNeedsDisplayInRect { // stNeedsDisplayInRect
if(invalidRect.size.width > 0 && invalidRect.size.height > 0) if (invalidRect.size.width > 0 && invalidRect.size.height > 0)
{ {
[self lockFocus]; // self has an invalid [self lockFocus]; // self has an invalid
[self drawRect:invalidRect]; // rect that needs to [self drawRect:invalidRect]; // rect that needs to
@ -832,7 +878,7 @@ int i = 0, count; // display self and all
[subview displayRect:intersection]; [subview displayRect:intersection];
} // subview does not intersect } // subview does not intersect
else // invalidRect but it may be else // invalidRect but it may be
if(subview->needs_display) // marked as needing display if (subview->needs_display) // marked as needing display
[subview displayIfNeededIgnoringOpacity]; [subview displayIfNeededIgnoringOpacity];
} }
invalidRect = NSZeroRect; invalidRect = NSZeroRect;
@ -843,7 +889,7 @@ int i = 0, count; // display self and all
{ {
NSView* subview = [sub_views objectAtIndex:i]; NSView* subview = [sub_views objectAtIndex:i];
// a subview contains a // a subview contains a
if(subview->needs_display) // view needing display if (subview->needs_display) // view needing display
[subview displayIfNeededIgnoringOpacity]; [subview displayIfNeededIgnoringOpacity];
} }
} }