public override bool addAt(ControlUI pControl, int iIndex) { // Override the AddAt() method so we can add items specifically to // the intended widgets. Headers and are assumed to be // answer the correct interface so we can add multiple list headers. if (pControl.getInterface("ListHeader") != null) { return(base.addAt(pControl, iIndex)); } // We also need to recognize header sub-items if (pControl.getClass() == "ListHeaderItemUI") { return(mHeader.addAt(pControl, iIndex)); } if (!mList.addAt(pControl, iIndex)) { return(false); } // The list items should know about us IListItemUI pListItem = (IListItemUI)pControl.getInterface("ListItem"); if (pListItem != null) { pListItem.setOwner(this); pListItem.setIndex(iIndex); } for (int i = iIndex + 1; i < mList.getCount(); ++i) { ControlUI p = mList.getItemAt(i); pListItem = (IListItemUI)p.getInterface("ListItem"); if (pListItem != null) { pListItem.setIndex(pListItem.getIndex() + 1); } } return(true); }
public override bool removeAt(int iIndex) { if (!mList.removeAt(iIndex)) { return(false); } for (int i = iIndex; i < mList.getCount(); ++i) { ControlUI p = mList.getItemAt(i); IListItemUI pListItem = (IListItemUI)p.getInterface("ListItem"); if (pListItem != null) { pListItem.setIndex(pListItem.getIndex() - 1); } } selectItem(findSelectable(mCurSel, false)); ensureVisible(mCurSel); return(true); }
public override bool remove(ControlUI pControl) { if (pControl.getInterface("ListHeader") != null) { return(base.remove(pControl)); } // We also need to recognize header sub-items if (pControl.getClass() == "ListHeaderItemUI") { return(mHeader.remove(pControl)); } int iIndex = mList.getItemIndex(pControl); if (iIndex == -1) { return(false); } if (!mList.removeAt(iIndex)) { return(false); } for (int i = iIndex; i < mList.getCount(); ++i) { ControlUI p = mList.getItemAt(i); IListItemUI pListItem = (IListItemUI)p.getInterface("ListItem"); if (pListItem != null) { pListItem.setIndex(pListItem.getIndex() - 1); } } selectItem(findSelectable(mCurSel, false)); ensureVisible(mCurSel); return(true); }
public override bool addAt(ControlUI pControl, int iIndex) { bool ret = base.addAt(pControl, iIndex); if (!ret) { return(ret); } if (mCurSel == -1 && pControl.isVisible()) { mCurSel = getItemIndex(pControl); } else if (mCurSel != -1 && iIndex <= mCurSel) { mCurSel += 1; } else { pControl.setVisible(false); } return(ret); }
public override bool add(ControlUI pControl) { // Override the Add() method so we can add items specifically to // the intended widgets. Headers are assumed to be // answer the correct interface so we can add multiple list headers. if (pControl.getInterface("ListHeader") != null) { if (mHeader != pControl && mHeader.getCount() == 0) { { // 把旧的表头控件属性赋予到新的表头控件 pControl.setBackImage(mHeader.getBackImage()); pControl.setVisible(mHeader.isVisible()); } base.remove(mHeader); mHeader = null; mHeader = (ListHeaderUI)(pControl); } return(base.addAt(pControl, 0)); } // We also need to recognize header sub-items if (pControl.getClass() == "ListHeaderItemUI") { return(mHeader.add(pControl)); } // The list items should know about us IListItemUI pListItem = (IListItemUI)pControl.getInterface("ListItem"); if (pListItem != null) { pListItem.setOwner(this); pListItem.setIndex(getCount()); } return(mList.add(pControl)); }
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); } }
public override void setOwner(ControlUI pOwner) { base.setOwner(pOwner); mOwner = (IListUI)pOwner.getInterface("List"); }
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); }
public virtual void setOwner(ControlUI pOwner) { mOwner = (IListOwnerUI)pOwner.getInterface("ListOwner"); }
public void setStretchMode(ControlUI control, UInt32 mode) { }
public override ControlUI findControl(FINDCONTROLPROC proc, ref object data, uint flags) { ControlUI pResult = null; if ((flags & ControlFlag.UIFIND_VISIBLE) != 0 && isVisible() == false) { return(null); } if ((flags & ControlFlag.UIFIND_ENABLED) != 0 && isVisible() == false) { return(null); } if ((flags & ControlFlag.UIFIND_HITTEST) != 0) { // 检测水平滚动条控件 Point pos = (Point)data; if (mRectItem.Contains(pos) == false) { return(null); } if (!mMouseChildEnabled) { if (mVerticalScrollbar != null) { pResult = mVerticalScrollbar.findControl(proc, ref data, flags); } if (pResult == null && mHorizontalScrollbar != null) { pResult = mHorizontalScrollbar.findControl(proc, ref data, flags); } if (pResult == null) { pResult = base.findControl(proc, ref data, flags); } return(pResult); } } // 检测垂直滚动条控件 if (mVerticalScrollbar != null) { pResult = mVerticalScrollbar.findControl(proc, ref data, flags); } if (pResult == null && mHorizontalScrollbar != null) { pResult = mHorizontalScrollbar.findControl(proc, ref data, flags); } if (pResult != null) { return(pResult); } if ((flags & ControlFlag.UIFIND_ME_FIRST) != 0) { pResult = base.findControl(proc, ref data, flags); if (pResult != null) { return(pResult); } } if ((flags & ControlFlag.UIFIND_TOP_FIRST) != 0) { for (int i = mItems.Count - 1; i >= 0; i--) { pResult = mItems[i].findControl(proc, ref data, flags); if (pResult != null) { return(pResult); } } } else { foreach (var item in mItems) { pResult = item.findControl(proc, ref data, flags); if (pResult != null) { return(pResult); } } } if (pResult == null) { pResult = base.findControl(proc, ref data, flags); } return(pResult); }
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); } } }
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); }
public void init(ComboUI pOwner) { mOwner = pOwner; mVerticalLayout = null; mOldSel = mOwner.getCurSel(); // 使用显示器坐标显示组合控件窗口 Size szDrop = mOwner.getDropBoxSize(); Rectangle rcOwner = pOwner.getPos(); Rectangle rc = rcOwner; rc.Y = rc.Bottom; rc.Height = szDrop.Height; if (szDrop.Width > 0) { rc.Width = rc.Left + szDrop.Width - rc.X; } Size szAvailable = new Size(rc.Right - rc.Left, rc.Bottom - rc.Top); int cyFixed = 0; for (int it = 0; it < pOwner.getCount(); it++) { ControlUI pControl = (ControlUI)pOwner.getItemAt(it); if (!pControl.isVisible()) { continue; } Size sz = pControl.estimateSize(szAvailable); cyFixed += sz.Height; } cyFixed += 4; // CVerticalLayoutUI 默认的Inset 调整 rc.Height = Math.Min(cyFixed, szDrop.Height); rc = mOwner.getManager().getPaintWindow().RectangleToScreen(rc); Rectangle rcMonitor = Screen.PrimaryScreen.Bounds; Rectangle rcWork = Screen.PrimaryScreen.WorkingArea; rcWork.Offset(-rcWork.Left, -rcWork.Top); if (rc.Bottom > rcWork.Bottom) { rc.X = rcOwner.X; rc.Width = rcOwner.Right - rc.X; if (szDrop.Width > 0) { rc.Width = szDrop.Width; } rc.Y = rcOwner.Y - Math.Min(cyFixed, szDrop.Height); rc.Height = rcOwner.Top - rc.Y; rc = mOwner.getManager().getPaintWindow().RectangleToScreen(rc); } this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.ShowInTaskbar = false; mRectClient = rc; this.StartPosition = FormStartPosition.Manual; this.ClientSize = new Size(rc.Width, rc.Height); this.Location = new Point(rc.Left, rc.Top); this.TopMost = true; this.Show(); }
public bool onMessageHandle(int uMsg, ref object wParam, ref object lParam, ref int lRes) { if (uMsg == (int)WindowMessage.WM_CREATE) { Form frm = this; mManager.init(ref frm); // 给下拉列表子控件树重新设置父容器以及资源管理器,在组合框窗口关闭后需要还原该子树控件的父容器以及资源管理器 mVerticalLayout = new VerticalLayoutUI(); mManager.useParentResource(mOwner.getManager()); mVerticalLayout.setManager(mManager, null); string pDefaultAttributes = mOwner.getManager().getDefaultAttributeList("VerticalLayout"); if (pDefaultAttributes != "") { mVerticalLayout.applyAttributeList(pDefaultAttributes); } mVerticalLayout.setInset(new Rectangle(2, 2, 0, 0)); mVerticalLayout.setBackColor(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF)); mVerticalLayout.setBorderColor(Color.FromArgb(0xFF, 0x85, 0xE4, 0xFF)); mVerticalLayout.setBorderSize(2); mVerticalLayout.setAutoDestroy(false); mVerticalLayout.enableScrollBar(); mVerticalLayout.applyAttributeList(mOwner.getDropBoxAttributeList()); for (int i = 0; i < mOwner.getCount(); i++) { mVerticalLayout.add((ControlUI)mOwner.getItemAt(i)); } ControlUI rootNode = (ControlUI)mVerticalLayout; mManager.attachDialog(ref rootNode); this.ClientSize = new Size(mRectClient.Width, mRectClient.Height); return(true); } else if (uMsg == (int)WindowMessage.WM_SIZE) { this.ClientSize = new Size(mRectClient.Width, mRectClient.Height); return(true); } else if (uMsg == (int)WindowMessage.WM_ERASEBKGND) { lRes = 1; return(true); } else if (uMsg == (int)WindowMessage.WM_CLOSE) { mOwner.setManager(mOwner.getManager(), mOwner.getParent()); mOwner.setPos(mOwner.getPos()); mOwner.setFocus(); } else if (uMsg == (int)WindowMessage.WM_LBUTTONUP) { Point pt = Control.MousePosition; pt = mManager.getPaintWindow().PointToClient(pt); ControlUI pControl = mManager.findControl(ref pt); if (pControl != null && pControl.getClass() != "ScrollbarUI") { PaintManagerUI.PostMessage(this.Handle, (int)WindowMessage.WM_KILLFOCUS, 0, 0); } } else if (uMsg == (int)WindowMessage.WM_KEYDOWN) { IntPtr ptr = (IntPtr)wParam; int c = (int)ptr; char cc = (char)int.Parse(c.ToString()); switch ((Keys)cc) { case Keys.Escape: mOwner.selectItem(mOldSel); ensureVisible(mOldSel); PaintManagerUI.PostMessage(this.Handle, (int)WindowMessage.WM_KILLFOCUS, 0, 0); break; case Keys.Return: PaintManagerUI.PostMessage(this.Handle, (int)WindowMessage.WM_KILLFOCUS, 0, 0); break; default: TEventUI newEvent = new TEventUI(); newEvent.mType = (int)EVENTTYPE_UI.UIEVENT_KEYDOWN; newEvent.mKey = cc; mOwner.eventProc(ref newEvent); ensureVisible(mOwner.getCurSel()); return(true); } } else if (uMsg == (int)WindowMessage.WM_MOUSEWHEEL) { IntPtr ptr = (IntPtr)wParam; int c = (int)ptr; int zDelta = (int)(short)HIWORD(c); TEventUI newEvent = new TEventUI(); newEvent.mType = (int)EVENTTYPE_UI.UIEVENT_SCROLLWHEEL; newEvent.mWParam = makeLong(zDelta < 0 ? (int)ScrollBarCommands.SB_LINEDOWN : (int)ScrollBarCommands.SB_LINEUP, 0); newEvent.mLParam = lParam; newEvent.mTimestamp = PaintManagerUI.GetTickCount(); mOwner.eventProc(ref newEvent); ensureVisible(mOwner.getCurSel()); return(true); } else if (uMsg == (int)WindowMessage.WM_KILLFOCUS) { close(); } if (mManager != null && mManager.messageHandler((uint)uMsg, ref wParam, ref lParam, ref lRes)) { return(true); } return(false); }
public override void eventProc(ref TEventUI newEvent) { if (!isMouseEnabled() && newEvent.mType > (int)EVENTTYPE_UI.UIEVENT__MOUSEBEGIN && newEvent.mType < (int)EVENTTYPE_UI.UIEVENT__MOUSEEND) { if (mParent != null) { mParent.eventProc(ref newEvent); } else { base.eventProc(ref newEvent); } return; } if (newEvent.mType == (int)EVENTTYPE_UI.UIEVENT_SETCURSOR && isEnabled()) { if (mManager.getPaintWindow().Cursor != Cursors.IBeam) { mManager.getPaintWindow().Cursor = Cursors.IBeam; } return; } if (newEvent.mType == (int)EVENTTYPE_UI.UIEVENT_WINDOWSIZE) { ControlUI ctlUI = null; if (mWindow != null) { mManager.setFocus(ref ctlUI); } } if (newEvent.mType == (int)EVENTTYPE_UI.UIEVENT_SCROLLWHEEL) { ControlUI ctlUI = null; if (mWindow != null) { mManager.setFocus(ref ctlUI); } } if (newEvent.mType == (int)EVENTTYPE_UI.UIEVENT_SETFOCUS && isEnabled()) { if (mWindow != null) { return; } mWindow = new EditWnd(); mWindow.init(this); invalidate(); } if (newEvent.mType == (int)EVENTTYPE_UI.UIEVENT_KILLFOCUS && isEnabled()) { invalidate(); } if (newEvent.mType == (int)EVENTTYPE_UI.UIEVENT_BUTTONDOWN || newEvent.mType == (int)EVENTTYPE_UI.UIEVENT_DBLCLICK) { if (isEnabled()) { if (isFocused() && mWindow == null) { mWindow = new EditWnd(); mWindow.init(this); } else if (mWindow == null) { //POINT pt = event.ptMouse; //pt.x -= m_rcItem.left + m_rcTextPadding.left; //pt.y -= m_rcItem.top + m_rcTextPadding.top; //::SendMessage(*m_pWindow, WM_LBUTTONDOWN, event.wParam, MAKELPARAM(pt.x, pt.y)); } } return; } if (newEvent.mType == (int)EVENTTYPE_UI.UIEVENT_MOUSEMOVE) { return; } if (newEvent.mType == (int)EVENTTYPE_UI.UIEVENT_BUTTONUP) { return; } if (newEvent.mType == (int)EVENTTYPE_UI.UIEVENT_MOUSEENTER) { if (isEnabled()) { mButtonState |= (int)ControlFlag.UISTATE_HOT; invalidate(); } return; } if (newEvent.mType == (int)EVENTTYPE_UI.UIEVENT_MOUSELEAVE) { if (isEnabled()) { mButtonState &= (int)ControlFlag.UISTATE_HOT; invalidate(); } return; } base.eventProc(ref newEvent); }
public override void eventProc(ref TEventUI newEvent) { if (!isMouseEnabled() && newEvent.mType > (int)EventTypeUI.UIEVENT__MOUSEBEGIN && newEvent.mType < (int)EventTypeUI.UIEVENT__MOUSEEND) { if (mOwner != null) { mOwner.eventProc(ref newEvent); } else { base.eventProc(ref newEvent); } return; } if (newEvent.mType == (int)EventTypeUI.UIEVENT_KILLFOCUS) { return; } if (newEvent.mType == (int)EventTypeUI.UIEVENT_BUTTONDOWN || newEvent.mType == (int)EventTypeUI.UIEVENT_DBLCLICK) { if (!isEnabled()) { return; } if (mRectButton1.Contains(newEvent.mMousePos)) { mButton1State |= (int)PaintFlags.UISTATE_PUSHED; setValue(mCurValue + 1); } else if (mRectButton2.Contains(newEvent.mMousePos)) { mButton2State |= (int)PaintFlags.UISTATE_PUSHED; setValue(mCurValue - 1); } else if (isFocused() && mWindow == null) { mWindow = new NumericUpDownWnd(); mWindow.init(this); } return; } if (newEvent.mType == (int)EventTypeUI.UIEVENT_BUTTONUP) { if ((mButton1State & (int)PaintFlags.UISTATE_PUSHED) != 0) { mButton1State &= ~(int)PaintFlags.UISTATE_PUSHED; invalidate(); } else if ((mButton2State & (int)PaintFlags.UISTATE_PUSHED) != 0) { mButton2State &= ~(int)PaintFlags.UISTATE_PUSHED; invalidate(); } return; } if (newEvent.mType == (int)EventTypeUI.UIEVENT_MOUSEENTER) { if (isEnabled()) { mButton1State |= (int)PaintFlags.UISTATE_HOT; mButton2State |= (int)PaintFlags.UISTATE_HOT; invalidate(); } return; } if (newEvent.mType == (int)EventTypeUI.UIEVENT_MOUSELEAVE) { if (isEnabled()) { mButton1State &= ~(int)PaintFlags.UISTATE_HOT; mButton2State &= ~(int)PaintFlags.UISTATE_HOT; invalidate(); } return; } if (newEvent.mType == (int)EVENTTYPE_UI.UIEVENT_SCROLLWHEEL) { ControlUI ctlUI = null; if (mWindow != null) { closeEditWnd(); mManager.setFocus(ref ctlUI); } } if (mOwner != null) { mOwner.eventProc(ref newEvent); } else { base.eventProc(ref newEvent); } }
public override void eventProc(ref TEventUI newEvent) { if (!isMouseEnabled() && newEvent.mType > (int)EVENTTYPE_UI.UIEVENT__MOUSEBEGIN && newEvent.mType < (int)EVENTTYPE_UI.UIEVENT__MOUSEEND) { if (mParent != null) { mParent.eventProc(ref newEvent); } else { base.eventProc(ref newEvent); } return; } if (newEvent.mType == (int)EVENTTYPE_UI.UIEVENT_SETCURSOR && isEnabled()) { if (mManager.getPaintWindow().Cursor != Cursors.IBeam) { mManager.getPaintWindow().Cursor = Cursors.IBeam; } return; } if (newEvent.mType == (int)EVENTTYPE_UI.UIEVENT_WINDOWSIZE) { ControlUI ctlUI = null; if (mWindow != null) { mManager.setFocus(ref ctlUI); } } if (newEvent.mType == (int)EVENTTYPE_UI.UIEVENT_SCROLLWHEEL) { ControlUI ctlUI = null; if (mWindow != null) { closeEditWnd(); mManager.setFocus(ref ctlUI); } } if (newEvent.mType == (int)EVENTTYPE_UI.UIEVENT_SETFOCUS && isEnabled()) { if (mWindow != null) { return; } mWindow = new EditWnd(); mWindow.init(this); if (OnCharMessageEvent != null) { mWindow.OnCharMessageEvent = OnCharMessageEvent; } invalidate(); } if (newEvent.mType == (int)EVENTTYPE_UI.UIEVENT_KILLFOCUS && isEnabled()) { invalidate(); } if (newEvent.mType == (int)EVENTTYPE_UI.UIEVENT_BUTTONDOWN || newEvent.mType == (int)EVENTTYPE_UI.UIEVENT_DBLCLICK) { if (isEnabled()) { if (isFocused() && mWindow == null) { mWindow = new EditWnd(); mWindow.init(this); if (OnCharMessageEvent != null) { mWindow.OnCharMessageEvent = OnCharMessageEvent; } } } return; } if (newEvent.mType == (int)EVENTTYPE_UI.UIEVENT_MOUSEMOVE) { return; } if (newEvent.mType == (int)EVENTTYPE_UI.UIEVENT_BUTTONUP) { return; } if (newEvent.mType == (int)EVENTTYPE_UI.UIEVENT_MOUSEENTER) { if (isEnabled()) { mButtonState |= (int)ControlFlag.UISTATE_HOT; invalidate(); } return; } if (newEvent.mType == (int)EVENTTYPE_UI.UIEVENT_MOUSELEAVE) { if (isEnabled()) { mButtonState &= (int)ControlFlag.UISTATE_HOT; invalidate(); } return; } base.eventProc(ref newEvent); }
public override void doPaint(ref Graphics graphics, ref Bitmap bitmap, Rectangle rectPaint) { Rectangle rcTemp; if (rectPaint.IntersectsWith(mRectItem) == false) { return; } rcTemp = rectPaint; rcTemp.Intersect(mRectItem); RenderClip clip = new RenderClip(); RenderClip.generateClip(ref graphics, rcTemp, ref clip); base.doPaint(ref graphics, ref bitmap, rectPaint); if (mItems.Count > 0) { Rectangle rc = mRectItem; int newLeft = rc.Left + mRectInset.Left; int newRight = rc.Right - mRectInset.Right; int newTop = rc.Top + mRectInset.Top; 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; } // 绘制子控件 if (rectPaint.IntersectsWith(rc) == false) { for (int i = mItems.Count - 1; i >= 0; i--) { ControlUI item = mItems[i]; if (item.isVisible() == false) { continue; } if (rectPaint.IntersectsWith(item.getPos()) == false) { continue; } if (item.isFloat()) { if (mRectItem.IntersectsWith(item.getPos()) == false) { continue; } item.doPaint(ref graphics, ref bitmap, rectPaint); } } } else { RenderClip childClip = new RenderClip(); RenderClip.generateClip(ref graphics, rcTemp, ref childClip); for (int i = mItems.Count - 1; i >= 0; i--) { ControlUI item = mItems[i]; if (item.isVisible() == false) { continue; } if (rectPaint.IntersectsWith(item.getPos()) == false) { continue; } if (item.isFloat()) { if (mRectItem.IntersectsWith(item.getPos()) == false) { continue; } RenderClip.useOldClipBegin(ref graphics, ref childClip); item.doPaint(ref graphics, ref bitmap, rectPaint); RenderClip.useOldClipEnd(ref graphics, ref childClip); } else { if (rc.IntersectsWith(item.getPos()) == false) { continue; } item.doPaint(ref graphics, ref bitmap, rectPaint); } } } } if (mVerticalScrollbar != null && mVerticalScrollbar.isVisible()) { if (rectPaint.IntersectsWith(mVerticalScrollbar.getPos())) { mVerticalScrollbar.doPaint(ref graphics, ref bitmap, rectPaint); } } if (mHorizontalScrollbar != null && mHorizontalScrollbar.isVisible()) { if (rectPaint.IntersectsWith(mHorizontalScrollbar.getPos())) { mHorizontalScrollbar.doPaint(ref graphics, ref bitmap, rectPaint); } } }
public virtual void setManager(PaintManagerUI manager, ControlUI parent) { mManager = manager; mParent = parent; }
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; } }
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); }
public override void eventProc(ref TEventUI newEvent) { if (mSepWidth != 0) { if (newEvent.mType == (int)EVENTTYPE_UI.UIEVENT_BUTTONDOWN && isEnabled()) { Rectangle rcSeparator = getThumbRect(false); if (rcSeparator.Contains(newEvent.mMousePos)) { mButtonState |= (int)PaintFlags.UISTATE_CAPTURED; mLastMouse = newEvent.mMousePos; mRectNewPos = mRectItem; if (!mImmMode && mManager != null) { ControlUI ctl = this; mManager.addPostPaint(ref ctl); } return; } } if (newEvent.mType == (int)EVENTTYPE_UI.UIEVENT_BUTTONUP) { if ((mButtonState & (int)PaintFlags.UISTATE_CAPTURED) != 0) { mButtonState &= ~(int)PaintFlags.UISTATE_CAPTURED; mRectItem = mRectNewPos; if (!mImmMode && mManager != null) { mManager.removePostPaint(this); } needParentUpdate(); return; } } if (newEvent.mType == (int)EVENTTYPE_UI.UIEVENT_MOUSEMOVE) { if ((mButtonState & (int)PaintFlags.UISTATE_CAPTURED) != 0) { int cx = newEvent.mMousePos.X - mLastMouse.X; mLastMouse = newEvent.mMousePos; Rectangle rc = mRectNewPos; if (mSepWidth >= 0) { if (cx > 0 && newEvent.mMousePos.X < mRectNewPos.Right - mSepWidth) { return; } if (cx < 0 && newEvent.mMousePos.X > mRectNewPos.Right) { return; } rc.Width = rc.Right + cx - rc.Left; if (rc.Right - rc.Left <= getMinWidth()) { if (mRectNewPos.Right - mRectNewPos.Left <= getMinWidth()) { return; } rc.Width = getMinWidth(); } if (rc.Right - rc.Left >= getMaxWidth()) { if (mRectNewPos.Right - mRectNewPos.Left >= getMaxWidth()) { return; } rc.Width = getMaxWidth(); } } else { if (cx > 0 && newEvent.mMousePos.X < mRectNewPos.Left) { return; } if (cx < 0 && newEvent.mMousePos.X > mRectNewPos.Left - mSepWidth) { return; } rc.X += cx; if (rc.Right - rc.Left <= getMinWidth()) { if (mRectNewPos.Right - mRectNewPos.Left <= getMinWidth()) { return; } rc.X = rc.Right - getMinWidth(); } if (rc.Right - rc.Left >= getMaxWidth()) { if (mRectNewPos.Right - mRectNewPos.Left >= getMaxWidth()) { return; } rc.X = rc.Right - getMaxWidth(); } } Rectangle rcInvalidate = getThumbRect(true); mRectNewPos = rc; mXYFixed.Width = mRectNewPos.Right - mRectNewPos.Left; if (mImmMode) { mRectItem = mRectNewPos; needParentUpdate(); } else { rcInvalidate.Intersect(getThumbRect(true)); rcInvalidate.Intersect(getThumbRect(false)); if (mManager != null) { mManager.invalidate(ref rcInvalidate); } } return; } } if (newEvent.mType == (int)EVENTTYPE_UI.UIEVENT_SETCURSOR) { Rectangle rcSeparator = getThumbRect(false); if (isEnabled() && rcSeparator.Contains(newEvent.mMousePos)) { if (mManager.getPaintWindow().Cursor != Cursors.SizeWE) { mManager.getPaintWindow().Cursor = Cursors.SizeWE; } return; } } } base.eventProc(ref newEvent); }
// 广度优先搜索XML节点树创建相应的控件树,过滤非控件节点 protected ControlUI parse(ref MarkupNode parentNode, ref ControlUI parentControl, ref PaintManagerUI manager) { if (parentNode == null) { throw new Exception("对象未赋值"); } ControlUI ctlParent = null; { //parentControl.setManager(manager, null); Queue <MarkupNode> queueNode = new Queue <MarkupNode>(); Queue <ControlUI> queueControl = new Queue <ControlUI>(); queueNode.Enqueue(parentNode); queueControl.Enqueue(parentControl); while (queueNode.Count > 0) { MarkupNode curNode = queueNode.Dequeue(); ControlUI curParentControl = queueControl.Dequeue(); List <MarkupNode> listNode = curNode.getChildList(); // 访问根节点 if (listNode != null && listNode.Count > 0) { // 子节点入队 foreach (var node in listNode) { // 过滤非控件节点 if (node.getName() == "Window" || node.getName() == "Image" || node.getName() == "Font" || node.getName() == "Default") { continue; } ControlUI newControl = null; { queueNode.Enqueue(node); // 创建控件,加入控件树后入队 newControl = getControl(node.getName()); if (newControl != null && newControl is ControlUI) { queueControl.Enqueue(newControl); newControl.setManager(manager, curParentControl); if (curParentControl != null) { IContainerUI container = (IContainerUI)curParentControl.getInterface("IContainer"); container.add(newControl); } else { if (ctlParent != null) { throw new Exception("不能有两个根容器"); } ctlParent = newControl; } } else if (mCallback != null) { newControl = mCallback.createControl(node.getName(), manager); if (newControl == null) { throw new Exception("未知控件类型"); } queueControl.Enqueue(newControl); newControl.setManager(manager, curParentControl); if (curParentControl != null) { IContainerUI container = (IContainerUI)curParentControl.getInterface("IContainer"); container.add(newControl); } else { if (ctlParent != null) { throw new Exception("不能有两个根容器"); } ctlParent = newControl; } } else { throw new Exception("未知控件类型"); } } { // 设置属性 if (manager != null) { //newControl.setManager(manager, curParentControl); string defaultAttributes = manager.getDefaultAttributeList(node.getName()); if (defaultAttributes != "") { newControl.applyAttributeList(defaultAttributes); } } List <XMLAttribute> listAttr = node.getAttributeList(); foreach (var attr in listAttr) { newControl.addAttribute(attr.getName(), attr.getValue()); newControl.setAttribute(attr.getName(), attr.getValue()); } } } } } } return(ctlParent); }
protected void setPos0(Rectangle rc) { if (rc.Right < rc.Left) { int left = rc.Left; rc.Width = 0; rc.X = left; } if (rc.Bottom < rc.Top) { int top = rc.Top; rc.Height = 0; rc.Y = top; } Rectangle invalidateRc = mRectItem; if (invalidateRc.IsEmpty) { invalidateRc = rc; } mRectItem = rc; if (mManager == null) { return; } ControlUI pParent = null; if (mFloat) { if (!mFloatSetPos) { mFloatSetPos = true; mManager.sendNotify(this, "setpos"); mFloatSetPos = false; } pParent = getParent(); if (pParent != null) { Rectangle rcParentPos = pParent.getPos(); if (mXY.Width >= 0) { mXY.Width = mRectItem.Left - rcParentPos.Left; } else { mXY.Width = mRectItem.Right - rcParentPos.Right; } if (mXY.Height >= 0) { mXY.Height = mRectItem.Top - rcParentPos.Top; } else { mXY.Height = mRectItem.Bottom - rcParentPos.Bottom; } } } mUpdateNeeded = false; // NOTE: SetPos() is usually called during the WM_PAINT cycle where all controls are // being laid out. Calling UpdateLayout() again would be wrong. Refreshing the // window won't hurt (if we're already inside WM_PAINT we'll just validate it out). invalidateRc.Intersect(mRectItem); pParent = this; Rectangle rcTemp; Rectangle rcParent; while ((pParent = pParent.getParent()) != null) { rcTemp = invalidateRc; rcParent = pParent.getPos(); if (rcTemp.IntersectsWith(rcParent) == false) { rcTemp.Intersect(rcParent); invalidateRc.Intersect(rcTemp); } else { return; } } mManager.invalidate(ref invalidateRc); }
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); }
public override void invalidate() { if (!isVisible()) { return; } if (getParent() != null) { ContainerUI pParentContainer = (ContainerUI)getParent().getInterface("Container"); if (pParentContainer != null) { Rectangle rc = pParentContainer.getPos(); Rectangle rcInset = pParentContainer.getInset(); int newLeft = rc.Left + rcInset.Left; int newRight = rc.Right - rcInset.Right; int newTop = rc.Top + rcInset.Top; int newBottom = rc.Bottom - rcInset.Bottom; rc.X = newLeft; rc.Width = newRight - newLeft; rc.Y = newTop; rc.Height = newBottom - newTop; ScrollbarUI pVerticalScrollbar = pParentContainer.getVerticalScrollbar(); if (pVerticalScrollbar != null && pVerticalScrollbar.isVisible()) { rc.Width = rc.Right - pVerticalScrollbar.getFixedWidth() - rc.Left; } ScrollbarUI pHorizontalScrollbar = pParentContainer.getHorizontalScrollbar(); if (pHorizontalScrollbar != null && pHorizontalScrollbar.isVisible()) { rc.Height = rc.Bottom - pHorizontalScrollbar.getFixedHeight() - rc.Top; } Rectangle invalidateRc = mRectItem; if (!invalidateRc.IntersectsWith(mRectItem)) { return; } invalidateRc.Intersect(mRectItem); ControlUI pParent = getParent(); Rectangle rcTemp; Rectangle rcParent; while ((pParent = pParent.getParent()) != null) { rcTemp = invalidateRc; rcParent = pParent.getPos(); if (!rcTemp.IntersectsWith(rcParent)) { return; } invalidateRc.Intersect(rcParent); } if (mManager != null) { mManager.invalidate(ref invalidateRc); } } else { base.invalidate(); } } else { base.invalidate(); } }
public override void doPaint(ref Graphics graphics, ref Bitmap bitmap, Rectangle rectPaint) { lock (lockObj) { Rectangle rcTemp = rectPaint; rcTemp.Intersect(mRectItem); if (rcTemp.IsEmpty == true) { return; } Region oldRgn = graphics.Clip.Clone(); graphics.IntersectClip(rcTemp); base.doPaint(ref graphics, ref bitmap, rectPaint); if (mItems.Count > 0) { Rectangle rc = mRectItem; int newLeft = rc.Left + mRectInset.Left; int newRight = rc.Right - mRectInset.Right; int newTop = rc.Top + mRectInset.Top; 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 -= mVerticalScrollbar.getFixedWidth(); } if (mHorizontalScrollbar != null && mHorizontalScrollbar.isVisible()) { rc.Height -= mHorizontalScrollbar.getFixedHeight(); } // 绘制子控件 rcTemp = rectPaint; rcTemp.Intersect(rc); if (rcTemp.IsEmpty == true) { foreach (var item in mItems) { if (item.isVisible() == false) { continue; } if (rectPaint.IntersectsWith(item.getPos()) == false) { continue; } if (item.isFloat()) { if (mRectItem.IntersectsWith(item.getPos()) == false) { continue; } item.doPaint(ref graphics, ref bitmap, rectPaint); } } } else { Region oldRgn1 = graphics.Clip.Clone(); graphics.IntersectClip(rcTemp); for (int i = 0; i < mItems.Count; i++) { ControlUI item = mItems[i]; if (item.isVisible() == false) { continue; } if (rectPaint.IntersectsWith(item.getPos()) == false) { continue; } if (item.isFloat()) { if (mRectItem.IntersectsWith(item.getPos()) == false) { continue; } Region oldRgn2 = graphics.Clip; graphics.Clip = oldRgn1; item.doPaint(ref graphics, ref bitmap, rectPaint); graphics.Clip = oldRgn2; } else { if (rc.IntersectsWith(item.getPos()) == false) { continue; } item.doPaint(ref graphics, ref bitmap, rectPaint); } } graphics.Clip = oldRgn1; } } if (mVerticalScrollbar != null && mVerticalScrollbar.isVisible()) { if (rectPaint.IntersectsWith(mVerticalScrollbar.getPos())) { mVerticalScrollbar.doPaint(ref graphics, ref bitmap, rectPaint); } } if (mHorizontalScrollbar != null && mHorizontalScrollbar.isVisible()) { if (rectPaint.IntersectsWith(mHorizontalScrollbar.getPos())) { mHorizontalScrollbar.doPaint(ref graphics, ref bitmap, rectPaint); } } graphics.Clip = oldRgn; } }