Ejemplo n.º 1
0
        public void Add(DockablePane pane, DockablePane relativePane, Dock relativeDock)
        {
            if (!_isInited)
            {
                return;
            }

            _CalculateSpaceFactors();

            if (CompositionType.Terminal == _type)
            {
                if (_attachedPane.Equals(relativePane))
                {
                    _Add(pane, relativeDock);
                }
            }
            else
            {
                // find relative terminal element index
                int relativeIndex = -1;
                for (int index = 0; index < _children.Count; ++index)
                {
                    Composition currentComposition = _children[index];
                    if (CompositionType.Terminal == currentComposition.Type)
                    {
                        if (currentComposition.AttachedPane.Equals(relativePane))
                        {
                            relativeIndex = index;
                            break; // NOTE: founded
                        }
                    }
                    else
                    {
                        currentComposition.Add(pane, relativePane, relativeDock);
                    }
                }

                // add new item
                if (-1 != relativeIndex)
                {
                    if (_DoesAdding2Line(relativeDock))
                    {   // add new item to current linear composition
                        // left\top insert to relative position, other - insert after relive

                        Composition newComposition = new Composition(this, pane);

                        _children[relativeIndex].SpaceFactor *= DEFAULT_SPACE_FACTOR; // new child requared part of relative pane
                        newComposition.SpaceFactor            = _children[relativeIndex].SpaceFactor;

                        int insertIndex = ((Dock.Left == relativeDock) || (Dock.Top == relativeDock)) ?
                                          relativeIndex : relativeIndex + 1;
                        _children.Insert(insertIndex, newComposition);
                    }
                    else
                    {   // add new pane to terminal composition
                        _children[relativeIndex].Add(pane, relativeDock);
                    }
                }

                Debug.Assert(_IsNormalized());
            }
        }