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> Tue Dec 8 1998 Felipe A. Rodriguez <far@ix.netcom.com>
* NSScroller.m move backend code into frontend, polish code, remove ifdefs. * NSScroller.m move backend code into frontend, polish code, remove ifdefs.

View file

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

View file

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

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,73 +623,145 @@ id e, o; // to and we have never
o = [e nextObject]; o = [e nextObject];
while (o) 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 resizeWithOldSuperviewSize: oldSize]; // resize it's subviews
[o resizeSubviewsWithOldSize: old_size];
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;
// do nothing if view NSSize old_size = bounds.size;
if(autoresizingMask == NSViewNotSizable) // is not resizable BOOL changedOrigin = NO;
BOOL changedSize = NO;
if (autoresizingMask == NSViewNotSizable)
return; 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) changex = [super_view bounds].size.width - oldSize.width;
frame.size.width += changePerOption; changey = [super_view bounds].size.height - oldSize.height;
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;
}
// 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)
{
[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 - (void)allocateGState {} // implemented by the
@ -702,7 +774,7 @@ int options = 0;
- (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;
@ -710,7 +782,7 @@ int options = 0;
- (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
@ -722,9 +794,9 @@ int options = 0;
[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
@ -750,10 +822,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];
@ -765,12 +837,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
@ -800,7 +872,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;
@ -811,7 +883,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];
} }
} }