Exemple #1
0
 /// <summary>
 /// Find largest pane
 /// </summary>
 /// <remarks>largest by hypotenuse</remarks>
 private void _FindLargestPane(ref Size maxSize, ref DockablePane largestPane)
 {
     for (int index = 0; index < _children.Count; ++index)
     {
         Composition child = _children[index];
         if (child.Type != CompositionType.Terminal)
         {
             child._FindLargestPane(ref maxSize, ref largestPane);
         }
         else
         {
             Size sz = child._CalculateSpaceSize();
             if (_CalculateHypotenuse(maxSize) < _CalculateHypotenuse(sz))
             {
                 largestPane = child.AttachedPane;
                 maxSize     = sz;
             }
         }
     }
 }
Exemple #2
0
        /// <summary>
        /// Calculation space factors
        /// </summary>
        private void _CalculateSpaceFactors()
        {
            Size fullSize = _CalculateSpaceSize();

            if ((fullSize.Height <= 0.0) && (fullSize.Height == fullSize.Width))
            {
                return; // NOTE: exit
            }
            // minimal factor - page have min size
            double minFactor = (_type == CompositionType.Horizontal)?
                               (DockablePane.MIN_PANE_SIZE / Math.Max(fullSize.Height, 1)) :
                               (DockablePane.MIN_PANE_SIZE / Math.Max(fullSize.Width, 1));

            double increaseFactorValue = 0; // pages with min size increase with this value

            for (int index = 0; index < _children.Count; ++index)
            {
                Composition child     = _children[index];
                Size        childSize = child._CalculateSpaceSize();

                double newScale = (_type == CompositionType.Horizontal) ?
                                  (childSize.Height / Math.Max(fullSize.Height, 1)) :
                                  (childSize.Width / Math.Max(fullSize.Width, 1));
                // reset tinkle - 1%
                if (SPACE_FACTOR_TINKLE < Math.Abs(child.SpaceFactor - newScale))
                {
                    child.SpaceFactor = newScale;
                }

                if (child.SpaceFactor < minFactor)
                {
                    increaseFactorValue += minFactor - child.SpaceFactor;
                    child.SpaceFactor    = minFactor;
                }
            }

            // normalize factors - sum probably SPACE_FACTOR_FULL
            double sumFactor = 0.0;

            if (0 < increaseFactorValue)
            {
                // find count of pages for decreasing
                int decreaseCount = 0;
                for (int index = 0; index < _children.Count; ++index)
                {
                    if (minFactor + increaseFactorValue < _children[index].SpaceFactor)
                    {
                        ++decreaseCount;
                    }
                }

                // decrease big pages
                double decreaseFactor = increaseFactorValue / decreaseCount;
                for (int index = 0; index < _children.Count; ++index)
                {
                    Composition child = _children[index];
                    if (minFactor + decreaseFactor < child.SpaceFactor)
                    {
                        child.SpaceFactor -= decreaseFactor;
                    }

                    sumFactor += child.SpaceFactor;
                }
            }
            else
            {
                // callculate sum factors
                for (int index = 0; index < _children.Count; ++index)
                {
                    sumFactor += _children[index].SpaceFactor;
                }
            }

            _NormalizeSpaceFactors(sumFactor);
        }
Exemple #3
0
        /// <summary>
        /// Remove pane
        /// </summary>
        public bool Remove(DockablePane pane)
        {
            if (!_isInited)
            {
                return(false);
            }

            Debug.Assert(CompositionType.Terminal != _type);

            _CalculateSpaceFactors();

            bool isRemoved = false;

            // find terminal element to deleting
            Composition terminalComposition2Delete = null;

            for (int index = 0; index < _children.Count; ++index)
            {
                Composition currentComposition = _children[index];
                if (CompositionType.Terminal == currentComposition.Type)
                {
                    if (currentComposition.AttachedPane.Equals(pane))
                    {
                        terminalComposition2Delete = currentComposition;
                        break; // NOTE: founded
                    }
                }
                else
                {   // remove from child composition
                    if (currentComposition.Remove(pane))
                    {
                        isRemoved = true;
                        break;
                    }
                }
            }

            // remove terminal element
            if (null != terminalComposition2Delete)
            {
                _children.Remove(terminalComposition2Delete);
                isRemoved = true;

                if (1 == _children.Count)
                {   // change state to terminal
                    Composition lastChield = _children[0];
                    _children.Clear();
                    if (CompositionType.Terminal == lastChield.Type)
                    {
                        _type         = CompositionType.Terminal;
                        _attachedPane = lastChield.AttachedPane;
                    }
                    else
                    {
                        _type = lastChield.Type;
                        ICollection <Composition> children = lastChield.Children;
                        foreach (Composition child in children)
                        {
                            _children.Add(child);
                        }
                    }
                }
                else
                {
                    // recalculate new space factors
                    Size   sz       = _CalculateSpaceSize();
                    double fullSize = (_type == CompositionType.Horizontal) ? sz.Height : sz.Width;
                    fullSize += SPLITTER_SIZE;

                    double splitterFree = SPLITTER_SIZE / _children.Count;

                    Size freeSize = terminalComposition2Delete._CalculateSpaceSize();
                    for (int index = 0; index < _children.Count; ++index)
                    {
                        Composition child     = _children[index];
                        Size        childSize = child._CalculateSpaceSize();
                        child.SpaceFactor = (_type == CompositionType.Horizontal) ?
                                            ((childSize.Height + freeSize.Height * child.SpaceFactor + splitterFree) / Math.Max(fullSize, 1)) :
                                            ((childSize.Width + freeSize.Width * child.SpaceFactor + splitterFree) / Math.Max(fullSize, 1));
                    }
                }
            }
            else if (isRemoved)
            {   // normalize composition - if child presented as one line
                for (int index = 0; index < _children.Count; ++index)
                {
                    Composition currentChild = _children[index];
                    if (currentChild.Type == _type)
                    {
                        ICollection <Composition> children = currentChild.Children;
                        Debug.Assert(currentChild.Type != CompositionType.Terminal);
                        Debug.Assert(1 < currentChild.Children.Count);

                        Collection <Composition> fromRemoved = new Collection <Composition> ();
                        foreach (Composition child in children)
                        {
                            fromRemoved.Add(child);
                        }

                        _children.Remove(currentChild);
                        _children.InsertRange(index, fromRemoved);
                    }
                }

                _CalculateSpaceFactors();
            }

            Debug.Assert(_IsNormalized());
            return(isRemoved);
        }