Auto-resize fixes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3424 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1998-12-09 06:42:19 +00:00
parent 436496e3d3
commit 3f83e799bc
4 changed files with 836 additions and 750 deletions

View file

@ -1,3 +1,9 @@
Wed Dec 9 7:00:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* NSView.m: Complete rewrite of auto-resize code - now works!
* NSBox.m: Fix to make auto-resize work.
* GNUAlertPanel.m: Minor tidying for auto-resize.
Tue Dec 8 1998 Felipe A. Rodriguez <far@ix.netcom.com>
* NSScroller.m move backend code into frontend, polish code, remove ifdefs.

View file

@ -135,6 +135,8 @@ static GNUAlertPanel *reusableAlertPanel = nil;
NSRect rect;
NSBox *box;
[self setMaxSize: r.size];
[self setMinSize: r.size];
[self setTitle: @" "];
content = [self contentView];
@ -201,7 +203,7 @@ static GNUAlertPanel *reusableAlertPanel = nil;
rect.origin.x = 8.0;
messageField = [[NSTextField alloc] initWithFrame: rect];
[messageField setAutoresizingMask:
NSViewWidthSizable | NSViewHeightSizable];
NSViewWidthSizable | NSViewHeightSizable | NSViewMaxYMargin];
[messageField setEditable: NO];
[messageField setSelectable: NO];
[messageField setBordered: NO];

View file

@ -226,6 +226,12 @@
[self setFrameFromContentFrame: r];
}
- (void) resizeWithOldSuperviewSize: (NSSize)oldSize
{
[super resizeWithOldSuperviewSize: oldSize];
[content_view setFrame: [self calcSizes]];
}
//
// Managing the NSView Hierarchy
//

View file

@ -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,73 +623,145 @@ id e, o; // to and we have never
o = [e nextObject];
while (o)
{
NSRect b = [o bounds];
NSSize old_size = b.size; // Resize the subview
// Then tell it to
[o resizeWithOldSuperviewSize: oldSize]; // resize it's subviews
[o resizeSubviewsWithOldSize: old_size];
o = [e nextObject];
}
}
- (void)resizeWithOldSuperviewSize:(NSSize)oldSize // preliminary FIX ME
- (void) resizeWithOldSuperviewSize: (NSSize)oldSize
{
float change, changePerOption;
int options = 0;
// 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 X axis
if(autoresizingMask & NSViewWidthSizable) // can be resized
options++;
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 = [super_view frame].size.width - oldSize.width;
changePerOption = floor(change/options);
if(autoresizingMask & NSViewWidthSizable)
frame.size.width += changePerOption;
if(autoresizingMask & NSViewMinXMargin)
frame.origin.x += changePerOption;
if(autoresizingMask & NSViewMaxXMargin)
frame.size.width += changePerOption;
bounds.size.width = frame.size.width;
}
// determine if Y axis
options = 0; // can be resized
if(autoresizingMask & NSViewHeightSizable)
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 = [super_view frame].size.height - oldSize.height;
changePerOption = floor(change/options);
if(autoresizingMask & NSViewHeightSizable)
frame.size.height += changePerOption;
if(autoresizingMask & NSViewMinYMargin)
frame.origin.y += changePerOption;
if(autoresizingMask & NSViewMaxYMargin)
frame.size.height += changePerOption;
bounds.size.height = frame.size.height;
}
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)
{
[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];
}
}
- (void)allocateGState {} // implemented by the
@ -702,7 +774,7 @@ int options = 0;
- (BOOL)canDraw
{ // not implemented per
if(window) // OS spec FIX ME
if (window) // OS spec FIX ME
return YES;
else
return NO;
@ -710,7 +782,7 @@ int options = 0;
- (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
@ -722,9 +794,9 @@ int options = 0;
[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
@ -750,10 +822,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];
@ -765,12 +837,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
@ -800,7 +872,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;
@ -811,7 +883,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];
}
}