Пример #1
0
        public override void paintText(ref Graphics graphics, ref Bitmap bitmap)
        {
            Rectangle rcText    = mRectItem;
            int       newLeft   = rcText.Left + mTextPadding.Left;
            int       newRight  = rcText.Right - mTextPadding.Right;
            int       newTop    = rcText.Top + mTextPadding.Top;
            int       newBottom = rcText.Bottom - mTextPadding.Bottom;

            rcText.X      = newLeft;
            rcText.Width  = newRight - newLeft;
            rcText.Y      = newTop;
            rcText.Height = newBottom - newTop;

            if (mCurSel >= 0)
            {
                ControlUI   pControl = (ControlUI)mItems[mCurSel];
                IListItemUI pElement = (IListItemUI)pControl.getInterface("ListItem");
                if (pElement != null)
                {
                    pElement.drawItemText(ref graphics, ref bitmap, ref rcText);
                }
                else
                {
                    Rectangle rcOldPos = pControl.getPos();
                    pControl.setPos(rcText);
                    pControl.doPaint(ref graphics, ref bitmap, rcText);
                    pControl.setPos(rcOldPos);
                }
            }
        }
Пример #2
0
        public virtual void setFloatPos(int iIndex)
        {
            lock (lockObj)
            {
                // 因为CControlUI::SetPos对float的操作影响,这里不能对float组件添加滚动条的影响
                if (iIndex < 0 || iIndex >= mItems.Count)
                {
                    return;
                }

                ControlUI pControl = mItems[iIndex];

                if (!pControl.isVisible())
                {
                    return;
                }
                if (!pControl.isFloat())
                {
                    return;
                }

                Size      szXY   = pControl.getFixedXY();
                Size      sz     = new Size(pControl.getFixedWidth(), pControl.getFixedHeight());
                Rectangle rcCtrl = new Rectangle();
                int       right  = 0;
                int       bottom = 0;
                if (szXY.Width >= 0)
                {
                    rcCtrl.X = mRectItem.Left + szXY.Width;
                    right    = mRectItem.Left + szXY.Width + sz.Width;
                }
                else
                {
                    rcCtrl.X = mRectItem.Right + szXY.Width - sz.Width;
                    right    = mRectItem.Right + szXY.Width;
                }
                if (szXY.Height >= 0)
                {
                    rcCtrl.Y = mRectItem.Top + szXY.Height;
                    bottom   = mRectItem.Top + szXY.Height + sz.Height;
                }
                else
                {
                    rcCtrl.Y = mRectItem.Bottom + szXY.Height - sz.Height;
                    bottom   = mRectItem.Bottom + szXY.Height;
                }
                rcCtrl = new Rectangle(rcCtrl.X, rcCtrl.Y, right - rcCtrl.X, bottom - rcCtrl.Y);
                pControl.setPos(rcCtrl);
            }
        }
Пример #3
0
        public virtual void setScrollPos(Size szPos)
        {
            int cx = 0;
            int cy = 0;

            if (mVerticalScrollbar != null && mVerticalScrollbar.isVisible())
            {
                int iLastScrollPos = mVerticalScrollbar.getScrollPos();
                mVerticalScrollbar.setScrollPos(szPos.Height);
                cy = mVerticalScrollbar.getScrollPos() - iLastScrollPos;
            }

            if (mHorizontalScrollbar != null && mHorizontalScrollbar.isVisible())
            {
                int iLastScrollPos = mHorizontalScrollbar.getScrollPos();
                mHorizontalScrollbar.setScrollPos(szPos.Width);
                cx = mHorizontalScrollbar.getScrollPos() - iLastScrollPos;
            }

            if (cx == 0 && cy == 0)
            {
                return;
            }

            Rectangle rcPos;

            for (int it2 = 0; it2 < mItems.Count; it2++)
            {
                ControlUI pControl = (mItems[it2]);
                if (!pControl.isVisible())
                {
                    continue;
                }
                if (pControl.isFloat())
                {
                    continue;
                }

                rcPos = pControl.getPos();
                int       newLeft   = rcPos.Left - cx;
                int       newRight  = rcPos.Right - cx;
                int       newTop    = rcPos.Top - cy;
                int       newBottom = rcPos.Bottom - cy;
                Rectangle newRect   = new Rectangle(newLeft, newTop, newRight - newLeft, newBottom - newTop);
                pControl.setPos(newRect);
            }

            invalidate();
        }
Пример #4
0
        public override void setPos(Rectangle rc)
        {
            base.setPos(rc);

            if (mHeader == null)
            {
                return;
            }
            // Determine general list information and the size of header columns
            mListInfo.mColumns = Math.Min(mHeader.getCount(), UILIST_MAX_COLUMNS);
            // The header/columns may or may not be visible at runtime. In either case
            // we should determine the correct dimensions...

            if (!mHeader.isVisible())
            {
                mHeader.setInternVisible(true);
                mHeader.setPos(new Rectangle(rc.Left, 0, rc.Width, 0));
            }
            int iOffset = mList.getScrollPos().Width;

            for (int i = 0; i < mListInfo.mColumns; i++)
            {
                ControlUI pControl = (ControlUI)mHeader.getItemAt(i);
                if (!pControl.isVisible())
                {
                    continue;
                }
                if (pControl.isFloat())
                {
                    continue;
                }

                Rectangle rcPos = pControl.getPos();
                if (iOffset > 0)
                {
                    int newLeft  = rcPos.X - iOffset;
                    int newRight = rcPos.Right - iOffset;
                    rcPos.X     = newLeft;
                    rcPos.Width = newRight - newLeft;
                    pControl.setPos(rcPos);
                }
                mListInfo.mListColumn[i] = pControl.getPos();
            }
            if (!mHeader.isVisible())
            {
                mHeader.setInternVisible(false);
            }
        }
Пример #5
0
        public override void setPos(Rectangle rc)
        {
            setPos0(rc);
            rc = mRectItem;

            // Adjust for inset
            rc.X     += mRectInset.X;
            rc.Y     += mRectInset.Y;
            rc.Width  = rc.Right - mRectInset.Right - rc.X;
            rc.Height = rc.Bottom - mRectInset.Bottom - rc.Y;

            for (int it = 0; it < mItems.Count; it++)
            {
                ControlUI pControl = mItems[it];
                if (!pControl.isVisible())
                {
                    continue;
                }
                if (pControl.isFloat())
                {
                    setFloatPos(it);
                    continue;
                }

                if (it != mCurSel)
                {
                    continue;
                }

                Rectangle rcPadding = pControl.getPadding();
                rc.X     += rcPadding.Left;
                rc.Y     += rcPadding.Top;
                rc.Width  = rc.Right - rcPadding.Right - rc.X;
                rc.Height = rc.Bottom - rcPadding.Bottom - rc.Y;

                Size szAvailable = new Size(rc.Right - rc.Left, rc.Bottom - rc.Top);

                Size sz = pControl.estimateSize(szAvailable);
                if (sz.Width == 0)
                {
                    sz.Width = Math.Max(0, szAvailable.Width);
                }
                if (sz.Width < pControl.getMinWidth())
                {
                    sz.Width = pControl.getMinWidth();
                }
                if (sz.Width > pControl.getMaxWidth())
                {
                    sz.Width = pControl.getMaxWidth();
                }

                if (sz.Height == 0)
                {
                    sz.Height = Math.Max(0, szAvailable.Height);
                }
                if (sz.Height < pControl.getMinHeight())
                {
                    sz.Height = pControl.getMinHeight();
                }
                if (sz.Height > pControl.getMaxHeight())
                {
                    sz.Height = pControl.getMaxHeight();
                }

                Rectangle rcCtrl = new Rectangle(rc.Left, rc.Top, sz.Width, sz.Height);
                pControl.setPos(rcCtrl);
            }
        }
Пример #6
0
        public override void setPos(Rectangle rc)
        {
            setPos0(rc);
            rc = mRectItem;

            // Adjust for inset
            int newLeft   = rc.Left + mRectInset.Left;
            int newTop    = rc.Top + mRectInset.Top;
            int newRight  = rc.Right - mRectInset.Right;
            int newBottom = rc.Bottom - mRectInset.Bottom;

            rc.X      = newLeft;
            rc.Width  = newRight - newLeft;
            rc.Y      = newTop;
            rc.Height = newBottom - newTop;

            if (mItems.Count == 0)
            {
                processScrollbar(rc, 0, 0);
                return;
            }

            if (mVerticalScrollbar != null && mVerticalScrollbar.isVisible())
            {
                rc.Width -= mVerticalScrollbar.getFixedWidth();
            }
            if (mHorizontalScrollbar != null && mHorizontalScrollbar.isVisible())
            {
                rc.Height -= mHorizontalScrollbar.getFixedHeight();
            }

            // Determine the width of elements that are sizeable
            Size szAvailable = new Size(rc.Right - rc.Left, rc.Bottom - rc.Top);

            if (mHorizontalScrollbar != null && mHorizontalScrollbar.isVisible())
            {
                szAvailable.Width += mHorizontalScrollbar.getScrollRange();
            }

            int nAdjustables = 0;
            int cxFixed      = 0;
            int nEstimateNum = 0;

            for (int it1 = 0; it1 < mItems.Count; it1++)
            {
                ControlUI pControl = (mItems[it1]);
                if (!pControl.isVisible())
                {
                    continue;
                }
                if (pControl.isFloat())
                {
                    continue;
                }
                Size sz = pControl.estimateSize(szAvailable);
                if (sz.Width == 0)
                {
                    nAdjustables++;
                }
                else
                {
                    if (sz.Width < pControl.getMinWidth())
                    {
                        sz.Width = pControl.getMinWidth();
                    }
                    if (sz.Width > pControl.getMaxWidth())
                    {
                        sz.Width = pControl.getMaxWidth();
                    }
                }
                cxFixed += sz.Width + pControl.getPadding().Left + pControl.getPadding().Right;
                nEstimateNum++;
            }
            cxFixed += (nEstimateNum - 1) * mChildPadding;

            int cxExpand = 0;

            if (nAdjustables > 0)
            {
                cxExpand = (0 - (szAvailable.Width - cxFixed) / nAdjustables) > 0 ? 0 : ((szAvailable.Width - cxFixed) / nAdjustables);
            }
            // Position the elements
            Size szRemaining = szAvailable;
            int  iPosX       = rc.Left;

            if (mHorizontalScrollbar != null && mHorizontalScrollbar.isVisible())
            {
                iPosX -= mHorizontalScrollbar.getScrollPos();
            }
            int iAdjustable      = 0;
            int cxFixedRemaining = cxFixed;

            for (int it2 = 0; it2 < mItems.Count; it2++)
            {
                ControlUI pControl = (mItems[it2]);
                if (!pControl.isVisible())
                {
                    continue;
                }
                if (pControl.isFloat())
                {
                    setFloatPos(it2);
                    continue;
                }
                Rectangle rcPadding = pControl.getPadding();
                szRemaining.Width -= rcPadding.Left;
                Size sz = pControl.estimateSize(szRemaining);
                if (sz.Width == 0)
                {
                    iAdjustable++;
                    sz.Width = cxExpand;
                    // Distribute remaining to last element (usually round-off left-overs)
                    if (iAdjustable == nAdjustables)
                    {
                        sz.Width = (0 - (szRemaining.Width - rcPadding.Right - cxFixedRemaining)) > 0 ? 0 : szRemaining.Width - rcPadding.Right - cxFixedRemaining;
                    }
                    if (sz.Width < pControl.getMinWidth())
                    {
                        sz.Width = pControl.getMinWidth();
                    }
                    if (sz.Width > pControl.getMaxWidth())
                    {
                        sz.Width = pControl.getMaxWidth();
                    }
                }
                else
                {
                    if (sz.Width < pControl.getMinWidth())
                    {
                        sz.Width = pControl.getMinWidth();
                    }
                    if (sz.Width > pControl.getMaxWidth())
                    {
                        sz.Width = pControl.getMaxWidth();
                    }

                    cxFixedRemaining -= sz.Width;
                }

                sz.Height = (0 - (rc.Bottom - rc.Top - rcPadding.Top - rcPadding.Bottom)) > 0 ? 0 : rc.Bottom - rc.Top - rcPadding.Top - rcPadding.Bottom;

                if (sz.Height < pControl.getMinHeight())
                {
                    sz.Height = pControl.getMinHeight();
                }
                if (sz.Height > pControl.getMaxHeight())
                {
                    sz.Height = pControl.getMaxHeight();
                }

                Rectangle rcCtrl = new Rectangle(iPosX + rcPadding.Left,
                                                 rc.Top + rcPadding.Top,
                                                 sz.Width + rcPadding.Right,
                                                 sz.Height);

                pControl.setPos(rcCtrl);
                iPosX             += sz.Width + mChildPadding + rcPadding.Left + rcPadding.Right;
                szRemaining.Width -= sz.Width + mChildPadding + rcPadding.Right;
            }
        }
Пример #7
0
        public override void setScrollPos(Size szPos)
        {
            int cx = 0;
            int cy = 0;

            if (mVerticalScrollbar != null && mVerticalScrollbar.isVisible())
            {
                int iLastScrollPos = mVerticalScrollbar.getScrollPos();
                mVerticalScrollbar.setScrollPos(szPos.Height);
                cy = mVerticalScrollbar.getScrollPos() - iLastScrollPos;
            }

            if (mHorizontalScrollbar != null && mHorizontalScrollbar.isVisible())
            {
                int iLastScrollPos = mHorizontalScrollbar.getScrollPos();
                mHorizontalScrollbar.setScrollPos(szPos.Width);
                cx = mHorizontalScrollbar.getScrollPos() - iLastScrollPos;
            }

            if (cx == 0 && cy == 0)
            {
                return;
            }

            Rectangle rcPos;

            for (int it2 = 0; it2 < mItems.Count; it2++)
            {
                ControlUI pControl = mItems[it2];
                if (!pControl.isVisible())
                {
                    continue;
                }
                if (pControl.isFloat())
                {
                    continue;
                }

                rcPos = pControl.getPos();
                int newLeft   = rcPos.Left - cx;
                int newRight  = rcPos.Right - cx;
                int newTop    = rcPos.Top - cy;
                int newBottom = rcPos.Bottom - cy;

                rcPos.X      = newLeft;
                rcPos.Width  = newRight - newLeft;
                rcPos.Y      = newTop;
                rcPos.Height = newBottom - newTop;
                pControl.setPos(rcPos);
            }

            invalidate();

            if (cx != 0 && mOwner != null)
            {
                ListHeaderUI pHeader = mOwner.getHeader();
                if (pHeader == null)
                {
                    return;
                }
                TListInfoUI pInfo = mOwner.getListInfo();
                pInfo.mColumns = Math.Min(pHeader.getCount(), ListUI.UILIST_MAX_COLUMNS);

                if (!pHeader.isVisible())
                {
                    pHeader.setInternVisible(true);
                }
                for (int i = 0; i < pInfo.mColumns; i++)
                {
                    ControlUI pControl = pHeader.getItemAt(i);
                    if (!pControl.isVisible())
                    {
                        continue;
                    }
                    if (pControl.isFloat())
                    {
                        continue;
                    }

                    Rectangle rcPos1   = pControl.getPos();
                    int       newLeft  = rcPos1.Left - cx;
                    int       newRight = rcPos1.Right - cx;
                    rcPos1.X     = newLeft;
                    rcPos1.Width = newRight - newLeft;
                    pControl.setPos(rcPos1);
                    pInfo.mListColumn[i] = pControl.getPos();
                }
                if (!pHeader.isVisible())
                {
                    pHeader.setInternVisible(false);
                }
            }
        }
Пример #8
0
        public override void setPos(Rectangle rc)
        {
            setPos0(rc);
            rc = mRectItem;

            // Adjust for inset
            int newLeft   = rc.Left + mRectInset.Left;
            int newTop    = rc.Top + mRectInset.Top;
            int newRight  = rc.Right - mRectInset.Right;
            int newBottom = rc.Bottom - mRectInset.Bottom;

            rc.X      = newLeft;
            rc.Width  = newRight - newLeft;
            rc.Y      = newTop;
            rc.Height = newBottom - newTop;

            if (mVerticalScrollbar != null && mVerticalScrollbar.isVisible())
            {
                rc.Width = rc.Right - mVerticalScrollbar.getFixedWidth() - rc.Left;
            }
            if (mHorizontalScrollbar != null && mHorizontalScrollbar.isVisible())
            {
                rc.Height = rc.Bottom - mHorizontalScrollbar.getFixedHeight() - rc.Top;
            }

            // 计算最小大小
            Size szAvailable = new Size(rc.Right - rc.Left, rc.Bottom - rc.Top);

            if (mHorizontalScrollbar != null && mHorizontalScrollbar.isVisible())
            {
                szAvailable.Width += mHorizontalScrollbar.getScrollRange();
            }

            int cxNeeded     = 0;
            int nAdjustables = 0;
            int cyFixed      = 0;
            int nEstimateNum = 0;

            for (int it1 = 0; it1 < mItems.Count; it1++)
            {
                ControlUI pControl = mItems[it1];
                if (!pControl.isVisible())
                {
                    continue;
                }
                if (pControl.isFloat())
                {
                    continue;
                }
                Size sz = pControl.estimateSize(szAvailable);
                if (sz.Height == 0)
                {
                    nAdjustables++;
                }
                else
                {
                    if (sz.Height < pControl.getMinHeight())
                    {
                        sz.Height = pControl.getMinHeight();
                    }
                    if (sz.Height > pControl.getMaxHeight())
                    {
                        sz.Height = pControl.getMaxHeight();
                    }
                }
                cyFixed += sz.Height + pControl.getPadding().Top + pControl.getPadding().Bottom;

                Rectangle rcPadding = pControl.getPadding();
                sz.Width = Math.Max(sz.Width, 0);
                if (sz.Width < pControl.getMinWidth())
                {
                    sz.Width = pControl.getMinWidth();
                }
                if (sz.Width > pControl.getMaxWidth())
                {
                    sz.Width = pControl.getMaxWidth();
                }
                cxNeeded = Math.Max(cxNeeded, sz.Width);
                nEstimateNum++;
            }
            cyFixed += (nEstimateNum - 1) * mChildPadding;

            if (mOwner != null)
            {
                ListHeaderUI pHeader = mOwner.getHeader();
                if (pHeader != null && pHeader.getCount() > 0)
                {
                    cxNeeded = Math.Max(0, pHeader.estimateSize(new Size(rc.Right - rc.Left, rc.Bottom - rc.Top)).Width);
                }
            }

            // Place elements
            int cyNeeded = 0;
            int cyExpand = 0;

            if (nAdjustables > 0)
            {
                cyExpand = Math.Max(0, (szAvailable.Height - cyFixed) / nAdjustables);
            }
            // Position the elements
            Size szRemaining = szAvailable;
            int  iPosY       = rc.Top;

            if (mVerticalScrollbar != null && mVerticalScrollbar.isVisible())
            {
                iPosY -= mVerticalScrollbar.getScrollPos();
            }
            int iPosX = rc.Left;

            if (mHorizontalScrollbar != null && mHorizontalScrollbar.isVisible())
            {
                iPosX -= mHorizontalScrollbar.getScrollPos();
            }
            int iAdjustable      = 0;
            int cyFixedRemaining = cyFixed;

            for (int it2 = 0; it2 < mItems.Count; it2++)
            {
                ControlUI pControl = mItems[it2];
                if (!pControl.isVisible())
                {
                    continue;
                }
                if (pControl.isFloat())
                {
                    setFloatPos(it2);
                    continue;
                }

                Rectangle rcPadding = pControl.getPadding();
                szRemaining.Height -= rcPadding.Top;
                Size sz = pControl.estimateSize(szRemaining);
                if (sz.Height == 0)
                {
                    iAdjustable++;
                    sz.Height = cyExpand;
                    // Distribute remaining to last element (usually round-off left-overs)
                    if (iAdjustable == nAdjustables)
                    {
                        sz.Height = Math.Max(0, szRemaining.Height - rcPadding.Bottom - cyFixedRemaining);
                    }
                    if (sz.Height < pControl.getMinHeight())
                    {
                        sz.Height = pControl.getMinHeight();
                    }
                    if (sz.Height > pControl.getMaxHeight())
                    {
                        sz.Height = pControl.getMaxHeight();
                    }
                }
                else
                {
                    if (sz.Height < pControl.getMinHeight())
                    {
                        sz.Height = pControl.getMinHeight();
                    }
                    if (sz.Height > pControl.getMaxHeight())
                    {
                        sz.Height = pControl.getMaxHeight();
                    }
                    cyFixedRemaining -= sz.Height;
                }

                sz.Width = Math.Max(cxNeeded, szAvailable.Width - rcPadding.Left - rcPadding.Right);

                if (sz.Width < pControl.getMinWidth())
                {
                    sz.Width = pControl.getMinWidth();
                }
                if (sz.Width > pControl.getMaxWidth())
                {
                    sz.Width = pControl.getMaxWidth();
                }

                newLeft   = iPosX + rcPadding.Left;
                newRight  = iPosX + rcPadding.Left + sz.Width;
                newTop    = iPosY + rcPadding.Top;
                newBottom = iPosY + sz.Height + rcPadding.Top + rcPadding.Bottom;
                Rectangle rcCtrl = new Rectangle(newLeft,
                                                 newTop,
                                                 newRight - newLeft,
                                                 newBottom - newTop);
                pControl.setPos(rcCtrl);

                iPosY              += sz.Height + mChildPadding + rcPadding.Top + rcPadding.Bottom;
                cyNeeded           += sz.Height + rcPadding.Top + rcPadding.Bottom;
                szRemaining.Height -= sz.Height + mChildPadding + rcPadding.Bottom;
            }
            cyNeeded += (nEstimateNum - 1) * mChildPadding;

            if (mHorizontalScrollbar != null)
            {
                if (cxNeeded > rc.Right - rc.Left)
                {
                    if (mHorizontalScrollbar.isVisible())
                    {
                        mHorizontalScrollbar.setScrollRange(cxNeeded - (rc.Right - rc.Left));
                    }
                    else
                    {
                        mHorizontalScrollbar.setVisible(true);
                        mHorizontalScrollbar.setScrollRange(cxNeeded - (rc.Right - rc.Left));
                        mHorizontalScrollbar.setScrollPos(0);
                        newBottom = rc.Bottom - mHorizontalScrollbar.getFixedHeight();
                        rc.Height = newBottom - rc.Top;
                    }
                }
                else
                {
                    if (mHorizontalScrollbar.isVisible())
                    {
                        mHorizontalScrollbar.setVisible(false);
                        mHorizontalScrollbar.setScrollRange(0);
                        mHorizontalScrollbar.setScrollPos(0);
                        newBottom = rc.Bottom + mHorizontalScrollbar.getFixedHeight();
                        rc.Height = newBottom - rc.Top;
                    }
                }
            }

            // 计算滚动条大小
            processScrollbar(rc, cxNeeded, cyNeeded);
        }
Пример #9
0
        public override void setPos(Rectangle rc)
        {
            setPos0(rc);

            rc = mRectItem;

            // mRectInset 为垂直布局控件的边界限制,在使用时,要忽略Right和Bottom属性,而使用Width和Height
            int newLeft   = rc.Left + mRectInset.Left;
            int newTop    = rc.Top + mRectInset.Top;
            int newRight  = rc.Right - mRectInset.Right;
            int newBottom = rc.Bottom - mRectInset.Bottom;

            rc.X      = newLeft;
            rc.Width  = newRight - newLeft;
            rc.Y      = newTop;
            rc.Height = newBottom - newTop;

            if (mVerticalScrollbar != null && mVerticalScrollbar.isVisible())
            {
                newRight = rc.Right - mVerticalScrollbar.getFixedWidth();
                Rectangle newRect = new Rectangle(rc.Left, rc.Top, newRight - rc.Left, rc.Bottom - rc.Top);
                rc = newRect;
            }
            if (mHorizontalScrollbar != null && mHorizontalScrollbar.isVisible())
            {
                newBottom = rc.Bottom - mHorizontalScrollbar.getFixedHeight();
                Rectangle newRect = new Rectangle(rc.Left, rc.Top, rc.Width, newBottom - rc.Top);
                rc = newRect;
            }

            if (mItems.Count == 0)
            {
                processScrollbar(rc, 0, 0);
                return;
            }

            // Determine the minimum size
            Size szAvailable = new Size(rc.Right - rc.Left, rc.Bottom - rc.Top);

            if (mHorizontalScrollbar != null && mHorizontalScrollbar.isVisible())
            {
                szAvailable.Width += mHorizontalScrollbar.getScrollRange();
            }

            int nAdjustables = 0;
            int cyFixed      = 0;
            int nEstimateNum = 0;

            for (int it1 = 0; it1 < mItems.Count; it1++)
            {
                ControlUI pControl = mItems[it1];
                if (!pControl.isVisible())
                {
                    continue;
                }
                if (pControl.isFloat())
                {
                    continue;
                }
                Size sz = pControl.estimateSize(szAvailable);
                if (sz.Height == 0)
                {
                    nAdjustables++;
                }
                else
                {
                    if (sz.Height < pControl.getMinHeight())
                    {
                        sz.Height = pControl.getMinHeight();
                    }
                    if (sz.Height > pControl.getMaxHeight())
                    {
                        sz.Height = pControl.getMaxHeight();
                    }
                }
                cyFixed += sz.Height + pControl.getPadding().Top + pControl.getPadding().Bottom;
                nEstimateNum++;
            }
            cyFixed += (nEstimateNum - 1) * mChildPadding;

            // Place elements
            int cyNeeded = 0;
            int cyExpand = 0;

            if (nAdjustables > 0)
            {
                cyExpand = (0 - (szAvailable.Height - cyFixed) / nAdjustables) > 0 ? 0 : (szAvailable.Height - cyFixed) / nAdjustables;
            }
            // Position the elements
            Size szRemaining = szAvailable;
            int  iPosY       = rc.Top;

            if (mVerticalScrollbar != null && mVerticalScrollbar.isVisible())
            {
                iPosY -= mVerticalScrollbar.getScrollPos();
            }
            int iPosX = rc.Left;

            if (mHorizontalScrollbar != null && mHorizontalScrollbar.isVisible())
            {
                iPosX -= mHorizontalScrollbar.getScrollPos();
            }
            int iAdjustable      = 0;
            int cyFixedRemaining = cyFixed;

            for (int it2 = 0; it2 < mItems.Count; it2++)
            {
                ControlUI pControl = (mItems[it2]);
                if (!pControl.isVisible())
                {
                    continue;
                }
                if (pControl.isFloat())
                {
                    setFloatPos(it2);
                    continue;
                }

                Rectangle rcPadding = pControl.getPadding();
                szRemaining.Height -= rcPadding.Top;
                Size sz = pControl.estimateSize(szRemaining);
                if (sz.Height == 0)
                {
                    iAdjustable++;
                    sz.Height = cyExpand;
                    // Distribute remaining to last element (usually round-off left-overs)
                    if (iAdjustable == nAdjustables)
                    {
                        sz.Height = (0 - szRemaining.Height - rcPadding.Bottom - cyFixedRemaining) > 0 ? 0 : szRemaining.Height - rcPadding.Bottom - cyFixedRemaining;
                    }
                    if (sz.Height < pControl.getMinHeight())
                    {
                        sz.Height = pControl.getMinHeight();
                    }
                    if (sz.Height > pControl.getMaxHeight())
                    {
                        sz.Height = pControl.getMaxHeight();
                    }
                }
                else
                {
                    if (sz.Height < pControl.getMinHeight())
                    {
                        sz.Height = pControl.getMinHeight();
                    }
                    if (sz.Height > pControl.getMaxHeight())
                    {
                        sz.Height = pControl.getMaxHeight();
                    }
                    cyFixedRemaining -= sz.Height;
                }

                sz.Width = (0 - szAvailable.Width - rcPadding.Left - rcPadding.Right) > 0 ? 0 : (szAvailable.Width - rcPadding.Left - rcPadding.Right);

                if (sz.Width < pControl.getMinWidth())
                {
                    sz.Width = pControl.getMinWidth();
                }
                if (sz.Width > pControl.getMaxWidth())
                {
                    sz.Width = pControl.getMaxWidth();
                }
                Rectangle rcCtrl = new Rectangle(iPosX + rcPadding.Left,
                                                 iPosY + rcPadding.Top,
                                                 iPosX + rcPadding.Left + sz.Width - (iPosX + rcPadding.Left),
                                                 iPosY + sz.Height + rcPadding.Top + rcPadding.Bottom - (iPosY + rcPadding.Top));

                pControl.setPos(rcCtrl);

                iPosY              += sz.Height + mChildPadding + rcPadding.Top + rcPadding.Bottom;
                cyNeeded           += sz.Height + rcPadding.Top + rcPadding.Bottom;
                szRemaining.Height -= sz.Height + mChildPadding + rcPadding.Bottom;
            }
            cyNeeded += (nEstimateNum - 1) * mChildPadding;

            // 计算滚动条大小
            processScrollbar(rc, 0, cyNeeded);
        }
Пример #10
0
        public override void setPos(Rectangle rc)
        {
            setPos0(rc);

            rc = mRectItem;

            // Adjust for inset
            rc.X     += mRectInset.Left;
            rc.Width  = rc.Right - mRectInset.Right - rc.X;
            rc.Y     += mRectInset.Top;
            rc.Height = rc.Bottom - mRectInset.Bottom - rc.Y;

            if (mItems.Count == 0)
            {
                processScrollbar(rc, 0, 0);
                return;
            }

            if (mVerticalScrollbar != null && mVerticalScrollbar.isVisible())
            {
                rc.Width = rc.Right - mVerticalScrollbar.getFixedWidth() - rc.Left;
            }
            if (mHorizontalScrollbar != null && mHorizontalScrollbar.isVisible())
            {
                rc.Height = rc.Bottom - mHorizontalScrollbar.getFixedHeight() - rc.Top;
            }

            // Position the elements
            int cyNeeded = 0;
            int cxWidth  = (rc.Right - rc.Left) / mColumns;

            if (mHorizontalScrollbar != null && mHorizontalScrollbar.isVisible())
            {
                cxWidth = (rc.Right - rc.Left + mHorizontalScrollbar.getScrollRange()) / mColumns;;
            }

            int   cyHeight = 0;
            int   iCount   = 0;
            Point ptTile   = new Point(rc.Left, rc.Top);

            if (mVerticalScrollbar != null && mVerticalScrollbar.isVisible())
            {
                ptTile.Y -= mVerticalScrollbar.getScrollPos();
            }
            int iPosX = rc.Left;

            if (mHorizontalScrollbar != null && mHorizontalScrollbar.isVisible())
            {
                iPosX   -= mHorizontalScrollbar.getScrollPos();
                ptTile.X = iPosX;
            }
            for (int it1 = 0; it1 < mItems.Count; it1++)
            {
                ControlUI pControl = mItems[it1];
                if (!pControl.isVisible())
                {
                    continue;
                }
                if (pControl.isFloat())
                {
                    setFloatPos(it1);
                    continue;
                }
                Rectangle rcPadding;
                Size      szAvailable;
                Size      szTile;
                // Determine size
                Rectangle rcTile = new Rectangle(ptTile.X, ptTile.Y, ptTile.X + cxWidth, ptTile.Y);
                if ((iCount % mColumns) == 0)
                {
                    int iIndex = iCount;
                    for (int it2 = it1; it2 < mItems.Count; it2++)
                    {
                        ControlUI pLineControl = mItems[it2];
                        if (!pLineControl.isVisible())
                        {
                            continue;
                        }
                        if (pLineControl.isFloat())
                        {
                            continue;
                        }

                        rcPadding   = pLineControl.getPadding();
                        szAvailable = new Size(rcTile.Right - rcTile.Left - rcPadding.Left - rcPadding.Right, 9999);
                        if (iIndex == iCount || (iIndex + 1) % mColumns == 0)
                        {
                            szAvailable.Width -= mChildPadding / 2;
                        }
                        else
                        {
                            szAvailable.Width -= mChildPadding;
                        }

                        if (szAvailable.Width < pControl.getMinWidth())
                        {
                            szAvailable.Width = pControl.getMinWidth();
                        }
                        if (szAvailable.Width > pControl.getMaxWidth())
                        {
                            szAvailable.Width = pControl.getMaxWidth();
                        }

                        szTile = pLineControl.estimateSize(szAvailable);
                        if (szTile.Width < pControl.getMinWidth())
                        {
                            szTile.Width = pControl.getMinWidth();
                        }
                        if (szTile.Width > pControl.getMaxWidth())
                        {
                            szTile.Width = pControl.getMaxWidth();
                        }
                        if (szTile.Height < pControl.getMinHeight())
                        {
                            szTile.Height = pControl.getMinHeight();
                        }
                        if (szTile.Height > pControl.getMaxHeight())
                        {
                            szTile.Height = pControl.getMaxHeight();
                        }

                        cyHeight = Math.Max(cyHeight, szTile.Height + rcPadding.Top + rcPadding.Bottom);
                        if ((++iIndex % mColumns) == 0)
                        {
                            break;
                        }
                    }
                }

                rcPadding = pControl.getPadding();

                rcTile.X    += rcPadding.X + mChildPadding / 2;
                rcTile.Width = rcTile.Right - (rcPadding.Right + mChildPadding / 2) - rcTile.X;

                if ((iCount % mColumns) == 0)
                {
                    rcTile.X -= mChildPadding / 2;
                }

                if (((iCount + 1) % mColumns) == 0)
                {
                    rcTile.Width = rcTile.Right + mChildPadding / 2 - rcTile.X;
                }

                // Set position
                rcTile.Y      = ptTile.Y + rcPadding.Top;
                rcTile.Height = ptTile.Y + cyHeight - rcTile.Y;

                szAvailable = new Size(rcTile.Right - rcTile.Left, rcTile.Bottom - rcTile.Top);
                szTile      = pControl.estimateSize(szAvailable);
                if (szTile.Width == 0)
                {
                    szTile.Width = szAvailable.Width;
                }
                if (szTile.Height == 0)
                {
                    szTile.Height = szAvailable.Height;
                }
                if (szTile.Width < pControl.getMinWidth())
                {
                    szTile.Width = pControl.getMinWidth();
                }
                if (szTile.Width > pControl.getMaxWidth())
                {
                    szTile.Width = pControl.getMaxWidth();
                }
                if (szTile.Height < pControl.getMinHeight())
                {
                    szTile.Height = pControl.getMinHeight();
                }
                if (szTile.Height > pControl.getMaxHeight())
                {
                    szTile.Height = pControl.getMaxHeight();
                }
                Rectangle rcPos = new Rectangle((rcTile.Left + rcTile.Right - szTile.Width) / 2, (rcTile.Top + rcTile.Bottom - szTile.Height) / 2,
                                                (rcTile.Left + rcTile.Right - szTile.Width) / 2 + szTile.Width, (rcTile.Top + rcTile.Bottom - szTile.Height) / 2 + szTile.Height);
                pControl.setPos(rcPos);

                if ((++iCount % mColumns) == 0)
                {
                    ptTile.X  = iPosX;
                    ptTile.Y += cyHeight + mChildPadding;
                    cyHeight  = 0;
                }
                else
                {
                    ptTile.X += cxWidth;
                }
                cyNeeded = rcTile.Bottom - rc.Top;
                if (mVerticalScrollbar != null && mVerticalScrollbar.isVisible())
                {
                    cyNeeded += mVerticalScrollbar.getScrollPos();
                }
            }

            // 计算滚动条大小
            processScrollbar(rc, 0, cyNeeded);
        }