mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-02 15:30:59 +00:00
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:
parent
977f5519f1
commit
67ac649c75
1 changed files with 824 additions and 778 deletions
244
Source/NSView.m
244
Source/NSView.m
|
@ -612,9 +612,9 @@ PSMatrix* matrix;
|
|||
post_bounds_changes = flag;
|
||||
}
|
||||
|
||||
- (void)resizeSubviewsWithOldSize:(NSSize)oldSize // resize subviews only
|
||||
- (void) resizeSubviewsWithOldSize: (NSSize)oldSize // resize subviews only
|
||||
{ // if we are supposed
|
||||
id e, o; // to and we have never
|
||||
id e, o; // to and we have never
|
||||
// been rotated
|
||||
if (![self autoresizesSubviews] && !is_rotated_from_base)
|
||||
return;
|
||||
|
@ -623,105 +623,151 @@ id e, o; // to and we have never
|
|||
o = [e nextObject];
|
||||
while (o)
|
||||
{
|
||||
[o resizeWithOldSuperviewSize: oldSize]; // Resize the subview
|
||||
[o resizeWithOldSuperviewSize: oldSize]; // resize it's subviews
|
||||
o = [e nextObject];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)resizeWithOldSuperviewSize:(NSSize)oldSize // preliminary FIX ME
|
||||
- (void) resizeWithOldSuperviewSize: (NSSize)oldSize
|
||||
{
|
||||
float change, changePerOption;
|
||||
int options = 0;
|
||||
NSSize old_size = bounds.size;
|
||||
NSSize superViewBoundsSize = [super_view bounds].size;
|
||||
BOOL changedOrigin = NO;
|
||||
BOOL changedSize = NO;
|
||||
// do nothing if view
|
||||
if(autoresizingMask == NSViewNotSizable) // is not resizable
|
||||
float changex;
|
||||
float changey;
|
||||
NSSize old_size = bounds.size;
|
||||
BOOL changedOrigin = NO;
|
||||
BOOL changedSize = NO;
|
||||
|
||||
if (autoresizingMask == NSViewNotSizable)
|
||||
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)
|
||||
{
|
||||
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];
|
||||
changex = [super_view bounds].size.width - oldSize.width;
|
||||
changey = [super_view bounds].size.height - oldSize.height;
|
||||
|
||||
// adjust the X axis
|
||||
fprintf (stderr, "NSView resizeWithOldSuperviewSize: \n");
|
||||
fprintf (stderr, "Change x,y (%1.2f, %1.2f)\n", changex, changey);
|
||||
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.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
|
||||
|
@ -734,7 +780,7 @@ BOOL changedSize = NO;
|
|||
|
||||
- (BOOL)canDraw
|
||||
{ // not implemented per
|
||||
if(window) // OS spec FIX ME
|
||||
if (window) // OS spec FIX ME
|
||||
return YES;
|
||||
else
|
||||
return NO;
|
||||
|
@ -742,7 +788,7 @@ BOOL changedSize = NO;
|
|||
|
||||
- (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
|
||||
|
||||
[self displayRect:[self visibleRect]]; // display visible rect
|
||||
|
@ -754,9 +800,9 @@ BOOL changedSize = NO;
|
|||
[self displayIfNeededIgnoringOpacity]; // view which is and
|
||||
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];
|
||||
NSRect rect = invalidRect; // convert rect into
|
||||
|
@ -782,10 +828,10 @@ int i = 0, count; // of our sub views if
|
|||
{ // need of display with
|
||||
NSView* subview = [sub_views objectAtIndex:i]; // setNeedsDisplay or
|
||||
// stNeedsDisplayInRect
|
||||
if(subview->needs_display)
|
||||
if (subview->needs_display)
|
||||
{
|
||||
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
|
||||
else
|
||||
[subview displayIfNeededIgnoringOpacity];
|
||||
|
@ -797,12 +843,12 @@ int i = 0, count; // of our sub views if
|
|||
{
|
||||
int i = 0, count; // display self and all
|
||||
// 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
|
||||
// need of display with
|
||||
if (needs_display) // setNeedsDisplay or
|
||||
{ // 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 drawRect:invalidRect]; // rect that needs to
|
||||
|
@ -832,7 +878,7 @@ int i = 0, count; // display self and all
|
|||
[subview displayRect:intersection];
|
||||
} // subview does not intersect
|
||||
else // invalidRect but it may be
|
||||
if(subview->needs_display) // marked as needing display
|
||||
if (subview->needs_display) // marked as needing display
|
||||
[subview displayIfNeededIgnoringOpacity];
|
||||
}
|
||||
invalidRect = NSZeroRect;
|
||||
|
@ -843,7 +889,7 @@ int i = 0, count; // display self and all
|
|||
{
|
||||
NSView* subview = [sub_views objectAtIndex:i];
|
||||
// a subview contains a
|
||||
if(subview->needs_display) // view needing display
|
||||
if (subview->needs_display) // view needing display
|
||||
[subview displayIfNeededIgnoringOpacity];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue