git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@4000 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-03-31 06:01:58 +00:00
parent 2add338172
commit a0e8d526a3
2 changed files with 124 additions and 27 deletions

View file

@ -1,3 +1,9 @@
Wed Mar 31 17:32:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSView: ([-viewWithTag:]) complete rewrite to find nearest
matching view at any depth as it should.
([-replaceSubview:with:]) minor rewrite and tidy up.
Tue Mar 30 14:00:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk> Tue Mar 30 14:00:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSCell.m: Position image correctly in flipped views. * Source/NSCell.m: Position image correctly in flipped views.

View file

@ -312,7 +312,7 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
- (void) replaceSubview: (NSView*)oldView with: (NSView*)newView - (void) replaceSubview: (NSView*)oldView with: (NSView*)newView
{ {
if (!newView) if (newView == oldView)
return; return;
/* /*
@ -320,8 +320,13 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
* since classes like NSBox override these methods but expect to be able to * since classes like NSBox override these methods but expect to be able to
* call [super replaceSubview: with: ] safely. * call [super replaceSubview: with: ] safely.
*/ */
if (!oldView) if (oldView == nil)
{ {
/*
* Strictly speaking, the docs say that if 'oldView' is not a subview
* of the receiver then we do nothing - but here we add newView anyway.
* So a replacement with no oldView is an addition.
*/
[newView retain]; [newView retain];
[newView removeFromSuperview]; [newView removeFromSuperview];
[newView viewWillMoveToWindow: window]; [newView viewWillMoveToWindow: window];
@ -332,22 +337,39 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
[newView setNeedsDisplay: YES]; [newView setNeedsDisplay: YES];
[newView release]; [newView release];
} }
else if (oldView != newView else if ([sub_views indexOfObjectIdenticalTo: oldView] != NSNotFound)
&& [sub_views indexOfObjectIdenticalTo: oldView] != NSNotFound)
{ {
unsigned index; if (newView == nil)
{
/*
* If there is no new view to add - we just remove the old one.
* So a replacement with no newView is a removal.
*/
[oldView removeFromSuperview];
}
else
{
unsigned index;
[newView retain]; /*
[newView removeFromSuperview]; * Ok - the standard case - we remove the newView from wherever it
index = [sub_views indexOfObjectIdenticalTo: oldView]; * was (which may have been in this view), locate the position of
[oldView removeFromSuperview]; * the oldView (which may have changed due to the removal of the
[newView viewWillMoveToWindow: window]; * newView), remove the oldView, and insert the newView in it's
[newView viewWillMoveToSuperview: self]; * place.
[newView setNextResponder: self]; */
[sub_views addObject: newView]; [newView retain];
[newView resetCursorRects]; [newView removeFromSuperview];
[newView setNeedsDisplay: YES]; index = [sub_views indexOfObjectIdenticalTo: oldView];
[newView release]; [oldView removeFromSuperview];
[newView viewWillMoveToWindow: window];
[newView viewWillMoveToSuperview: self];
[newView setNextResponder: self];
[sub_views addObject: newView];
[newView resetCursorRects];
[newView setNeedsDisplay: YES];
[newView release];
}
} }
} }
@ -1417,27 +1439,96 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
- (void) resetCursorRects - (void) resetCursorRects
{} {}
- (id) viewWithTag: (int)aTag static NSView* findByTag(NSView *view, int aTag, unsigned *level)
{ {
unsigned i, count; unsigned i, count;
NSArray *sub = [view subviews];
count = [sub_views count]; count = [sub count];
if (count > 0) if (count > 0)
{ {
NSView* array[count]; NSView *array[count];
[sub_views getObjects: array]; [sub getObjects: array];
for (i = 0; i < count; ++i) for (i = 0; i < count; i++)
{ {
NSView *view = array[i]; if ([array[i] tag] == aTag)
return array[i];
}
*level++;
for (i = 0; i < count; i++)
{
NSView *v;
if ([view tag] == aTag) v = findByTag(array[i], aTag, level);
return view; if (v != nil)
return v;
}
*level--;
}
return nil;
}
- (id) viewWithTag: (int)aTag
{
NSView *view = nil;
/*
* If we have the specified tag - return self.
*/
if ([self tag] == aTag)
{
view = self;
}
else
{
unsigned count = [sub_views count];
if (count > 0)
{
NSView *array[count];
unsigned i;
[sub_views getObjects: array];
/*
* Quick check to see if any of our direct descendents has the tag.
*/
for (i = 0; i < count; i++)
{
view = array[i];
if ([view tag] == aTag)
break;
}
if (view == nil)
{
unsigned level = 0xffffffff;
/*
* Ok - do it the long way - search the while tree for each of
* our descendents and see which has the closest view matching
* the tag.
*/
for (i = 0; i < count; i++)
{
unsigned l = 0;
NSView *v;
v = findByTag(array[i], aTag, &l);
if (v != nil && l < level)
{
view = v;
level = l;
}
}
}
} }
} }
return view;
return nil;
} }
// //