コード例 #1
0
ファイル: ListUI.cs プロジェクト: weimingtom/QUILib
        public ListUI()
        {
            mCallback             = null;
            mCurSel               = -1;
            mExpandedItem         = -1;
            mList                 = new ListBodyUI(this);
            mHeader               = new ListHeaderUI();
            mListInfo             = new TListInfoUI();
            mListInfo.mListColumn = new Dictionary <int, Rectangle>();

            add(mHeader);
            base.add(mList);

            mListInfo.mColumns           = 0;
            mListInfo.mFontIdx           = -1;
            mListInfo.mTextStyle         = (int)FormatFlags.DT_VCENTER; // m_uTextStyle(DT_VCENTER | DT_END_ELLIPSIS)
            mListInfo.mTextColor         = Color.FromArgb(0xFF, 00, 00, 00).ToArgb();
            mListInfo.mBkColor           = 0;
            mListInfo.mSelectedTextColor = Color.FromArgb(0xFF, 00, 00, 00).ToArgb();
            mListInfo.mSelectedBkColor   = Color.FromArgb(0xFF, 0xC1, 0xE3, 0xFF).ToArgb();
            mListInfo.mHotTextColor      = Color.FromArgb(0xFF, 0x00, 0x00, 0x00).ToArgb();
            mListInfo.mHotBkColor        = Color.FromArgb(0xFF, 0xE9, 0xF5, 0xFF).ToArgb();
            mListInfo.mDisabledTextColor = Color.FromArgb(0xFF, 0xCC, 0xCC, 0xCC).ToArgb();
            mListInfo.mDisabledBkColor   = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF).ToArgb();
            mListInfo.mLineColor         = 0;
            mListInfo.mShowHtml          = false;
            mListInfo.mExpandable        = false;
            mListInfo.mMultiExpandable   = false;

            mScrollSelect = false;
        }
コード例 #2
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);
                }
            }
        }
コード例 #3
0
        public static ControlUI getControl(string typeName)
        {
            ControlUI newControl = null;
            int       len        = typeName.Length;

            switch (len)
            {
            case 4:
            {
                if (typeName == "Edit")
                {
                    newControl = new EditUI();
                }
                else if (typeName == "List")
                {
                    newControl = new ListUI();
                }
                else if (typeName == "Text")
                {
                    newControl = new TextUI();
                }

                break;
            }

            case 5:
            {
                if (typeName == "Combo")
                {
                    newControl = new ComboUI();
                }
                else if (typeName == "Label")
                {
                    newControl = new LabelUI();
                }
                break;
            }

            case 6:
            {
                if (typeName == "Button")
                {
                    newControl = new ButtonUI();
                }
                else if (typeName == "Option")
                {
                    newControl = new OptionUI();
                }
                else if (typeName == "Slider")
                {
                    newControl = new SliderUI();
                }

                break;
            }

            case 7:
            {
                if (typeName == "Control")
                {
                    newControl = new ControlUI();
                }
                else if (typeName == "ActiveX")
                {
                    newControl = new ActiveXUI();
                }
                break;
            }

            case 8:
            {
                if (typeName == "Progress")
                {
                    newControl = new ProgressUI();
                }
                break;
            }

            case 9:
            {
                if (typeName == "Container")
                {
                    newControl = new ContainerUI();
                }
                else if (typeName == "TabLayout")
                {
                    newControl = new TabLayoutUI();
                }

                break;
            }

            case 10:
            {
                if (typeName == "ListHeader")
                {
                    newControl = new ListHeaderUI();
                }
                else if (typeName == "TileLayout")
                {
                    newControl = new TileLayoutUI();
                }

                break;
            }

            case 12:
            {
                if (typeName == "DialogLayout")
                {
                    newControl = new DialogLayoutUI();
                }
                break;
            }

            case 14:
            {
                if (typeName == "VerticalLayout")
                {
                    newControl = new VerticalLayoutUI();
                }
                else if (typeName == "ListHeaderItem")
                {
                    newControl = new ListHeaderItemUI();
                }

                break;
            }

            case 15:
            {
                if (typeName == "ListTextElement")
                {
                    newControl = new ListTextElementUI();
                }
                break;
            }

            case 16:
            {
                if (typeName == "HorizontalLayout")
                {
                    newControl = new HorizontalLayoutUI();
                }
                else if (typeName == "ListLabelElement")
                {
                    newControl = new ListLabelElementUI();
                }

                break;
            }

            case 17:
            {
                if (typeName == "ListExpandElement")
                {
                    newControl = new ListExpandElementUI();
                }
                break;
            }

            case 20:
            {
                if (typeName == "ListContainerElement")
                {
                    newControl = new ListContainerElementUI();
                }
                break;
            }
            }

            return(newControl);
        }
コード例 #4
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);
        }