public virtual void ReplaceSubviewWith(NSView oldView, NSView newView)
{
if (newView == oldView)
{
return;
}
/*
* NB. we implement the replacement in full rather than calling addSubview:
* since classes like NSBox override these methods but expect to be able to
* call [super replaceSubview:with:] safely.
*/
if (oldView == null)
{
/*
* 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.
*/
//RETAIN(newView);
newView.RemoveFromSuperview();
newView._ViewWillMoveToWindow(_window);
newView._ViewWillMoveToSuperview(this);
newView.SetNextResponder(this);
_sub_views.AddObject(newView);
_rFlags.has_subviews = 1;
newView.ResetCursorRects();
newView.SetNeedsDisplay(true);
newView._ViewDidMoveToWindow();
newView.ViewDidMoveToSuperview();
this.DidAddSubview(newView);
//RELEASE(newView);
}
else if (_sub_views.IndexOfObjectIdenticalTo(oldView) != NS.NotFound)
{
if (newView == null)
{
/*
* 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
{
uint index;
/*
* Ok - the standard case - we remove the newView from wherever it
* was (which may have been in this view), locate the position of
* the oldView (which may have changed due to the removal of the
* newView), remove the oldView, and insert the newView in it's
* place.
*/
//RETAIN(newView);
newView.RemoveFromSuperview();
index = _sub_views.IndexOfObjectIdenticalTo(oldView);
oldView.RemoveFromSuperview();
newView._ViewWillMoveToWindow(_window);
newView._ViewWillMoveToSuperview(this);
newView.SetNextResponder(this);
_sub_views.InsertObject(newView, index);
_rFlags.has_subviews = 1;
newView.ResetCursorRects();
newView.SetNeedsDisplay(true);
newView._ViewDidMoveToWindow();
newView.ViewDidMoveToSuperview();
this.DidAddSubview(newView);
//RELEASE(newView);
}
}
}