Bugfix and optimisations

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@4232 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-05-09 07:50:04 +00:00
parent 02aed28501
commit 977ca1a87e
2 changed files with 154 additions and 109 deletions

View file

@ -1,3 +1,9 @@
Sun May 9 9:13:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSView.m: Further optimisations, plus bugfix to ensure that
a view and it's children are moved to window 'nil' when the view is
removed from it's superview.
Fri May 7 21:25:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk> Fri May 7 21:25:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
Large and complex changes made in order to speed up operation of the Large and complex changes made in order to speed up operation of the

View file

@ -280,17 +280,17 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
if ([window firstResponder] == self) if ([window firstResponder] == self)
[window makeFirstResponder: window]; [window makeFirstResponder: window];
[self retain];
[super_view->sub_views removeObjectIdenticalTo: self]; [super_view->sub_views removeObjectIdenticalTo: self];
if ([super_view->sub_views count] == 0) if ([super_view->sub_views count] == 0)
super_view->_rFlags.has_subviews = 0; super_view->_rFlags.has_subviews = 0;
super_view = nil; super_view = nil;
[self viewWillMoveToWindow: nil]; [self viewWillMoveToWindow: nil];
[self release];
} }
- (void) removeFromSuperview - (void) removeFromSuperview
{ {
NSWindow *win;
/* /*
* We MUST make sure that coordinates are invalidated even if we have * We MUST make sure that coordinates are invalidated even if we have
* no superview - cos they may have been rebuilt since we lost the * no superview - cos they may have been rebuilt since we lost the
@ -307,13 +307,13 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
if ([window firstResponder] == self) if ([window firstResponder] == self)
[window makeFirstResponder: window]; [window makeFirstResponder: window];
[super_view setNeedsDisplayInRect: frame]; [super_view setNeedsDisplayInRect: frame];
[self retain];
[super_view->sub_views removeObjectIdenticalTo: self]; [super_view->sub_views removeObjectIdenticalTo: self];
if ([super_view->sub_views count] == 0) if ([super_view->sub_views count] == 0)
super_view->_rFlags.has_subviews = 0; super_view->_rFlags.has_subviews = 0;
win = window;
window = nil;
super_view = nil; super_view = nil;
[self viewWillMoveToWindow: nil];
[self release];
} }
- (void) replaceSubview: (NSView*)oldView with: (NSView*)newView - (void) replaceSubview: (NSView*)oldView with: (NSView*)newView
@ -394,19 +394,20 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
- (void) viewWillMoveToWindow: (NSWindow*)newWindow - (void) viewWillMoveToWindow: (NSWindow*)newWindow
{ {
unsigned count;
window = newWindow; window = newWindow;
if (_rFlags.has_subviews)
count = [sub_views count];
if (count > 0)
{ {
unsigned i; unsigned count = [sub_views count];
NSView* array[count];
[sub_views getObjects: array]; if (count > 0)
for (i = 0; i < count; ++i) {
[array[i] viewWillMoveToWindow: newWindow]; unsigned i;
NSView *array[count];
[sub_views getObjects: array];
for (i = 0; i < count; ++i)
[array[i] viewWillMoveToWindow: newWindow];
}
} }
} }
@ -883,17 +884,20 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
// resize subviews only if we are supposed to and we have never been rotated // resize subviews only if we are supposed to and we have never been rotated
- (void) resizeSubviewsWithOldSize: (NSSize)oldSize - (void) resizeSubviewsWithOldSize: (NSSize)oldSize
{ {
id e, o; if (_rFlags.has_subviews)
if ([self autoresizesSubviews] == NO || is_rotated_from_base == YES)
return;
e = [sub_views objectEnumerator];
o = [e nextObject];
while (o)
{ {
[o resizeWithOldSuperviewSize: oldSize]; // Resize the subview id e, o;
if ([self autoresizesSubviews] == NO || is_rotated_from_base == YES)
return;
e = [sub_views objectEnumerator];
o = [e nextObject]; o = [e nextObject];
while (o)
{
[o resizeWithOldSuperviewSize: oldSize];
o = [e nextObject];
}
} }
} }
@ -1080,12 +1084,26 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
return NO; return NO;
} }
- (void)display - (void) display
{ {
if (!window) if (window)
return; {
NSRect rect;
[self displayRect: bounds]; /*
* Display the entire view - if there is nothing marked as needing
* display, that's just the visible rect. If there is an area needing
* display, do the entire area so that the view will no longer need
* be marked as needing display.
*/
if (coordinates_valid == NO)
[self _rebuildCoordinates];
if (needs_display)
rect = NSUnionRect(invalidRect, visibleRect);
else
rect = visibleRect;
[self displayRect: rect];
}
} }
- (void) displayIfNeeded - (void) displayIfNeeded
@ -1099,8 +1117,11 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
else else
{ {
NSView *firstOpaque = [self opaqueAncestor]; NSView *firstOpaque = [self opaqueAncestor];
NSRect rect = bounds; NSRect rect;
if (coordinates_valid == NO)
[self _rebuildCoordinates];
rect = NSUnionRect(invalidRect, visibleRect);
rect = [firstOpaque convertRect: rect fromView: self]; rect = [firstOpaque convertRect: rect fromView: self];
[firstOpaque displayIfNeededInRectIgnoringOpacity: rect]; [firstOpaque displayIfNeededInRectIgnoringOpacity: rect];
} }
@ -1111,7 +1132,12 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
{ {
if (needs_display) if (needs_display)
{ {
[self displayIfNeededInRectIgnoringOpacity: bounds]; NSRect rect;
if (coordinates_valid == NO)
[self _rebuildCoordinates];
rect = NSUnionRect(invalidRect, visibleRect);
[self displayIfNeededInRectIgnoringOpacity: rect];
} }
} }
@ -1157,54 +1183,57 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
[self unlockFocus]; [self unlockFocus];
} }
count = [sub_views count]; if (_rFlags.has_subviews)
if (count > 0)
{ {
NSView* array[count]; count = [sub_views count];
if (count > 0)
[sub_views getObjects: array];
for (i = 0; i < count; i++)
{ {
NSRect isect; NSView* array[count];
NSView *subview = array[i];
NSRect subviewFrame = subview->frame;
if ([subview->frameMatrix isRotated]) [sub_views getObjects: array];
{
[subview->frameMatrix boundingRectFor: subviewFrame
result: &subviewFrame];
}
/* for (i = 0; i < count; i++)
* Having drawn ourself into the rect, we must make sure that
* subviews overlapping the area are redrawn.
*/
isect = NSIntersectionRect(redrawRect, subviewFrame);
if (NSIsEmptyRect(isect) == NO)
{ {
isect = [subview convertRect: isect NSRect isect;
fromView: self]; NSView *subview = array[i];
NSRect subviewFrame = subview->frame;
if ([subview->frameMatrix isRotated])
{
[subview->frameMatrix boundingRectFor: subviewFrame
result: &subviewFrame];
}
/* /*
* hack the ivars of the subview directly for speed. * Having drawn ourself into the rect, we must make sure that
* subviews overlapping the area are redrawn.
*/ */
subview->needs_display = YES; isect = NSIntersectionRect(redrawRect, subviewFrame);
subview->invalidRect = NSUnionRect(subview->invalidRect,
isect);
}
if (subview->needs_display)
{
isect = NSIntersectionRect(aRect, subviewFrame);
if (NSIsEmptyRect(isect) == NO) if (NSIsEmptyRect(isect) == NO)
{ {
isect = [subview convertRect: isect isect = [subview convertRect: isect
fromView: self]; fromView: self];
[subview displayIfNeededInRectIgnoringOpacity: isect]; /*
* hack the ivars of the subview directly for speed.
*/
subview->needs_display = YES;
subview->invalidRect = NSUnionRect(subview->invalidRect,
isect);
} }
if (subview->needs_display) if (subview->needs_display)
{ {
stillNeedsDisplay = YES; isect = NSIntersectionRect(aRect, subviewFrame);
if (NSIsEmptyRect(isect) == NO)
{
isect = [subview convertRect: isect
fromView: self];
[subview displayIfNeededInRectIgnoringOpacity: isect];
}
if (subview->needs_display)
{
stillNeedsDisplay = YES;
}
} }
} }
} }
@ -1258,33 +1287,37 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
[self drawRect: aRect]; [self drawRect: aRect];
[self unlockFocus]; [self unlockFocus];
count = [sub_views count]; if (_rFlags.has_subviews)
if (count > 0)
{ {
NSView* array[count]; count = [sub_views count];
[sub_views getObjects: array]; if (count > 0)
for (i = 0; i < count; ++i)
{ {
NSView *subview = array[i]; NSView* array[count];
NSRect subviewFrame = subview->frame;
NSRect intersection;
if ([subview->frameMatrix isRotated]) [sub_views getObjects: array];
[subview->frameMatrix boundingRectFor: subviewFrame
result: &subviewFrame];
intersection = NSIntersectionRect(aRect, subviewFrame); for (i = 0; i < count; ++i)
if (NSIsEmptyRect(intersection) == NO)
{ {
intersection = [subview convertRect: intersection fromView: self]; NSView *subview = array[i];
[subview displayRectIgnoringOpacity: intersection]; NSRect subviewFrame = subview->frame;
} NSRect intersection;
if (subview->needs_display)
{ if ([subview->frameMatrix isRotated])
stillNeedsDisplay = YES; [subview->frameMatrix boundingRectFor: subviewFrame
result: &subviewFrame];
intersection = NSIntersectionRect(aRect, subviewFrame);
if (NSIsEmptyRect(intersection) == NO)
{
intersection = [subview convertRect: intersection
fromView: self];
[subview displayRectIgnoringOpacity: intersection];
}
if (subview->needs_display)
{
stillNeedsDisplay = YES;
}
} }
} }
} }
@ -1469,7 +1502,7 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
if ([array[i] tag] == aTag) if ([array[i] tag] == aTag)
return array[i]; return array[i];
} }
*level++; *level += 1;
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
NSView *v; NSView *v;
@ -1478,7 +1511,7 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
if (v != nil) if (v != nil)
return v; return v;
} }
*level--; *level -= 1;
} }
return nil; return nil;
} }
@ -1494,7 +1527,7 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
{ {
view = self; view = self;
} }
else else if (_rFlags.has_subviews)
{ {
unsigned count = [sub_views count]; unsigned count = [sub_views count];
@ -1564,19 +1597,22 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
p = [self convertPoint: aPoint fromView: super_view]; p = [self convertPoint: aPoint fromView: super_view];
count = [sub_views count]; // Check our sub_views if (_rFlags.has_subviews)
if (count > 0)
{ {
NSView* array[count]; count = [sub_views count]; // Check our sub_views
if (count > 0)
[sub_views getObjects: array];
while (count > 0)
{ {
w = array[--count]; NSView* array[count];
v = [w hitTest: p];
if (v) [sub_views getObjects: array];
break;
while (count > 0)
{
w = array[--count];
v = [w hitTest: p];
if (v)
break;
}
} }
} }
if (v) // mouse is either in the subview or within self if (v) // mouse is either in the subview or within self
@ -1988,19 +2024,22 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
unsigned count; unsigned count;
coordinates_valid = NO; coordinates_valid = NO;
count = [sub_views count]; if (_rFlags.has_subviews)
if (count > 0)
{ {
NSView* array[count]; count = [sub_views count];
unsigned i; if (count > 0)
[sub_views getObjects: array];
for (i = 0; i < count; i++)
{ {
NSView *sub = array[i]; NSView* array[count];
unsigned i;
if (sub->coordinates_valid == YES) [sub_views getObjects: array];
(*invalidateImp)(sub, invalidateSel); for (i = 0; i < count; i++)
{
NSView *sub = array[i];
if (sub->coordinates_valid == YES)
(*invalidateImp)(sub, invalidateSel);
}
} }
} }
} }