public override Slice BecomeReal(int index)
{
CheckDisposed();
// We stand in for the slice at 'index', and that is to be replaced. But we might stand for earlier
// slices too: how many indicates what we have to add to m_ihvoMin.
// Note: I (RandyR) don't think the same one can stand in for multiple dummies now.
// We don't use a dummy slice in more than one place.
// Each are created individually, if more than one is needed.
int ihvo = m_ihvoMin;
for (int islice = index - 1; islice >= 0 && ContainingDataTree.Slices[islice] == this; islice--)
ihvo++;
int hvo = m_cache.DomainDataByFlid.get_VecItem(m_obj.Hvo, m_flid, ihvo);
// In the course of becoming real, we may get disposed. That clears m_path, which
// has various bad effects on called objects that are trying to use it, as well as
// causing failure here when we try to remove the thing we added temporarily.
// Work with a copy, so Dispose can't get at it.
var path = new ArrayList(m_path);
if (ihvo == m_ihvoMin)
{
// made the first element real. Increment start ihvo: the first thing we are a
// dummy for got one greater
m_ihvoMin++;
}
else if (index < ContainingDataTree.Slices.Count && ContainingDataTree.Slices[index + 1] == this)
{
// Any occurrences after index get replaced by a new one with suitable ihvoMin.
// Note this must be done before we insert an unknown number of extra slices
// by calling CreateSlicesFor.
var dosRep = new DummyObjectSlice(m_indent, m_node, path,
m_obj, m_flid, ihvo + 1, m_layoutName, m_layoutChoiceField, m_caller) {Cache = Cache, ParentSlice = ParentSlice};
for (int islice = index + 1;
islice < ContainingDataTree.Slices.Count && ContainingDataTree.Slices[islice] == this;
islice++)
{
ContainingDataTree.RawSetSlice(islice, dosRep);
}
}
// Save these, we may get disposed soon, can't get them from member data any more.
DataTree containingTree = ContainingDataTree;
Control parent = Parent;
var parentSlice = ParentSlice;
path.Add(hvo);
var objItem = ContainingDataTree.Cache.ServiceLocator.GetInstance<ICmObjectRepository>().GetObject(hvo);
Point oldPos = ContainingDataTree.AutoScrollPosition;
ContainingDataTree.CreateSlicesFor(objItem, parentSlice, m_layoutName, m_layoutChoiceField, m_indent, index + 1, path,
new ObjSeqHashMap(), m_caller);
// If inserting slices somehow altered the scroll position, for example as the
// silly Panel tries to make the selected control visible, put it back!
if (containingTree.AutoScrollPosition != oldPos)
containingTree.AutoScrollPosition = new Point(-oldPos.X, -oldPos.Y);
// No need to remove, we added to copy.
//m_path.RemoveAt(m_path.Count - 1);
return containingTree.Slices.Count > index + 1 ? containingTree.Slices[index + 1] as Slice : null;
}