7#define DEF_UPDATEINTERVAL 0
41 rcSb.top += m_nSbTop.toPixelSize(
GetScale());
42 rcSb.bottom -= m_nSbBottom.toPixelSize(
GetScale());
46 rcSb.left += m_nSbLeft.toPixelSize(
GetScale());
47 rcSb.right -= m_nSbRight.toPixelSize(
GetScale());
59 return bVert ? (&m_siVer) : (&m_siHoz);
64 if (m_nSbArrowSize.isValid())
65 return m_nSbArrowSize.toPixelSize(
GetScale());
67 if (!m_pSkinSb->HasArrow())
69 return m_pSkinSb->GetIdealSize();
79 sbHandler.
OnDraw(pRT, SB_LINEUP);
80 sbHandler.
OnDraw(pRT, SScrollBarHandler::kSbRail);
81 sbHandler.
OnDraw(pRT, SB_THUMBTRACK);
82 sbHandler.
OnDraw(pRT, SB_LINEDOWN);
85 else if (iPart == SB_THUMBTRACK)
87 CRect rcRail = sbHandler.
GetPartRect(SScrollBarHandler::kSbRail);
89 sbHandler.
OnDraw(pRT, SScrollBarHandler::kSbRail);
90 sbHandler.
OnDraw(pRT, SB_THUMBTRACK);
93 else if (iPart == SB_PAGEDOWN || iPart == SB_PAGEUP)
97 sbHandler.
OnDraw(pRT, SScrollBarHandler::kSbRail);
104 sbHandler.
OnDraw(pRT, iPart);
117 SCROLLINFO &si = bVert ? m_siVer : m_siHoz;
118 CRect rcOldThumb = sbHandler.
GetPartRect(SB_THUMBTRACK);
120 CRect rcThumb = sbHandler.
GetPartRect(SB_THUMBTRACK);
122 rcUnion.UnionRect(rcOldThumb, rcThumb);
124 sbHandler.
OnDraw(pRT, SScrollBarHandler::kSbRail);
125 sbHandler.
OnDraw(pRT, SB_THUMBTRACK);
127 OnScroll(bVert, SB_THUMBTRACK, nPos);
132 SASSERT(iCmd != SB_THUMBTRACK);
148 if (m_fadeFrames > 0 && !m_fadeInterpolator)
150 m_fadeInterpolator.Attach(CREATEINTERPOLATOR(L
"Accelerate"));
152 return m_fadeInterpolator;
162 return m_bySbThumbTrackMinAlpha;
169 , m_wBarEnable(SSB_BOTH)
170 , m_dwUpdateInterval(DEF_UPDATEINTERVAL)
173 , m_sbVert(this, true)
174 , m_sbHorz(this, false)
176 , m_bySbThumbTrackMinAlpha(128)
178 m_nSbWid.setInvalid();
179 m_nSbArrowSize.setInvalid();
181 ISkinObj *pSkin = GETBUILTINSKIN(SKIN_SYS_SCROLLBAR);
185 memset(&m_siHoz, 0,
sizeof(SCROLLINFO));
186 memset(&m_siVer, 0,
sizeof(SCROLLINFO));
187 m_siHoz.nTrackPos = (DWORD)-1;
188 m_siVer.nTrackPos = (DWORD)-1;
194 m_wBarVisible |= wBar;
196 m_wBarVisible &= ~wBar;
205 m_wBarEnable |= wBar;
207 m_wBarEnable &= ~wBar;
223 return m_wBarEnable & (bVertical ? SSB_VERT : SSB_HORZ);
228 SCROLLINFO *psi = bVertical ? (&m_siVer) : (&m_siHoz);
229 if (si.fMask & SIF_RANGE)
234 if (si.fMask & SIF_PAGE)
235 psi->nPage = si.nPage;
236 if (si.fMask & SIF_POS)
238 if (si.fMask & SIF_TRACKPOS)
239 psi->nTrackPos = si.nTrackPos;
244 if (psi->nPos > (psi->nMax - (
int)psi->nPage + 1))
245 psi->nPos = (psi->nMax - psi->nPage + 1);
246 if (psi->nPos < psi->nMin)
247 psi->nPos = psi->nMin;
253 SCROLLINFO *psi = bVertical ? (&m_siVer) : (&m_siHoz);
256 if (nNewPos < psi->nMin)
258 if (nNewPos > psi->nMax - (
int)psi->nPage + 1)
259 nNewPos = psi->nMax - psi->nPage + 1;
262 BOOL bRet =
OnScroll(bVertical, SB_THUMBPOSITION, nNewPos);
278 const SCROLLINFO &si = bVertical ? m_siVer : m_siHoz;
279 return si.nTrackPos != -1 ? si.nTrackPos : si.nPos;
284 SCROLLINFO *psi = bVertical ? (&m_siVer) : (&m_siHoz);
286 bRedraw = bRedraw || psi->nMin != nMinPos || psi->nMax != nMaxPos;
290 if (psi->nPos < psi->nMin)
291 psi->nPos = psi->nMin;
292 if (psi->nPos > psi->nMax - (
int)psi->nPage + 1)
293 psi->nPos = psi->nMax - psi->nPage + 1;
305 const SCROLLINFO *psi = bVertical ? (&m_siVer) : (&m_siHoz);
307 *lpMaxPos = psi->nMax;
309 *lpMinPos = psi->nMin;
315 return m_wBarVisible & (bVertical ? SSB_VERT : SSB_HORZ);
320 int nRet = __baseCls::OnCreate(NULL);
323 return m_pSkinSb ? 0 : -1;
328 m_sbHorz.OnDestroy();
329 m_sbVert.OnDestroy();
335 __baseCls::OnNcPaint(pRT);
340 m_sbVert.OnDraw(pRT, SB_LINEUP);
341 m_sbVert.OnDraw(pRT, SScrollBarHandler::kSbRail);
342 m_sbVert.OnDraw(pRT, SB_THUMBTRACK);
343 m_sbVert.OnDraw(pRT, SB_LINEDOWN);
347 m_sbHorz.OnDraw(pRT, SB_LINEUP);
348 m_sbHorz.OnDraw(pRT, SScrollBarHandler::kSbRail);
349 m_sbHorz.OnDraw(pRT, SB_THUMBTRACK);
350 m_sbHorz.OnDraw(pRT, SB_LINEDOWN);
356 __baseCls::GetClientRect(&rcDest);
359 m_pSkinSb->DrawByState(pRT, rcDest,
SB_CORNOR);
375 if (m_dragSb != SSB_NULL)
377 return !m_rcClient.PtInRect(pt);
383 if (m_sbVert.OnMouseDown(point))
385 else if (m_sbHorz.OnMouseDown(point))
393 if (m_dragSb != SSB_NULL)
405 if (m_dragSb != SSB_NULL)
409 BOOL bInSbNew = rcSb.PtInRect(point);
411 if (bInSbNew != bInSbOld)
420 m_hitSb = bInSbNew ? m_dragSb : SSB_NULL;
424 if (m_sbVert.HitTest(point) != -1)
426 if (m_hitSb == SSB_NULL)
427 m_sbVert.OnMouseHover(point);
429 m_sbVert.OnMouseMove(point);
432 else if (m_sbHorz.HitTest(point) != -1)
434 if (m_hitSb == SSB_NULL)
435 m_sbHorz.OnMouseHover(point);
437 m_sbHorz.OnMouseMove(point);
442 if (m_hitSb != SSB_NULL)
454 if (m_dragSb != SSB_NULL)
456 if (m_hitSb == m_dragSb)
463 else if (m_hitSb != SSB_NULL)
489 short delta = m_zDelta / WHEEL_DELTA;
490 m_zDelta %= WHEEL_DELTA;
492 short nLines = delta > 0 ? delta : (-delta);
494 for (; i < nLines; i++)
497 if (!
OnScroll(bVertScroll, delta > 0 ? SB_LINEUP : SB_LINEDOWN, 0))
505 delta = (nLines - i) * WHEEL_DELTA * (delta > 0 ? 1 : -1);
511 ::SendMessage(hHost, WM_MOUSEMOVE, nFlags, MAKELPARAM(pt.x, pt.y));
512 ::SendMessage(hHost, WM_SETCURSOR, WPARAM(hHost), MAKELPARAM(HTCLIENT, WM_MOUSEMOVE));
519 SCROLLINFO *psi = bVertical ? (&m_siVer) : (&m_siHoz);
520 int nNewPos = psi->nPos;
530 nNewPos -= psi->nPage;
533 nNewPos += psi->nPage;
538 case SB_THUMBPOSITION:
546 nNewPos = psi->nMax - psi->nPage + 1;
550 if (nNewPos < psi->nMin)
552 if (nNewPos > psi->nMax - (
int)psi->nPage + 1)
553 nNewPos = psi->nMax - psi->nPage + 1;
557 if (nNewPos == psi->nPos)
571 if (cTimerID == IScrollBarHost::Timer_Go || cTimerID == IScrollBarHost::Timer_Wait)
573 SASSERT(m_dragSb != SSB_NULL);
581 DWORD dwTime = GetTickCount();
582 if (dwTime - m_dwUpdateTime >= m_dwUpdateInterval)
585 m_dwUpdateTime = dwTime;
592 if (!
IsVisible(TRUE) && m_dragSb != SSB_NULL)
613 return bLoading ? S_FALSE : S_OK;
618 return m_nScrollSpeed;
633 __baseCls::OnColorize(cr);
635 m_pSkinSb->OnColorize(cr);
640 __baseCls::OnScaleChanged(nScale);
652 if (m_nSbWid.isValid())
653 return m_nSbWid.toPixelSize(
GetScale());
655 return m_pSkinSb->GetIdealSize();
660 m_sbHorz.OnContainerChanged(pOldContainer, pNewContainer);
661 m_sbVert.OnContainerChanged(pOldContainer, pNewContainer);
668 m_ptOrigin = CPoint();
671 m_viewSize[0].setInvalid();
672 m_viewSize[1].setInvalid();
681 __baseCls::OnSize(nType, size);
688 EventScrollViewOriginChanged evt(
this);
689 evt.ptOldOrigin = ptOld;
690 evt.ptNewOrigin = ptNew;
696 EventScrollViewSizeChanged evt(
this);
697 evt.szOldViewSize = szOld;
698 evt.szNewViewSize = szNew;
708 if (pt.x > (
int)(m_siHoz.nMax - m_siHoz.nPage + 1))
709 pt.x = (int)(m_siHoz.nMax - m_siHoz.nPage + 1);
710 if (pt.y > (
int)(m_siVer.nMax - m_siVer.nPage + 1))
711 pt.y = (int)(m_siVer.nMax - m_siVer.nPage + 1);
712 if (m_ptOrigin.x == pt.x && m_ptOrigin.y == pt.y)
714 POINT ptOld = m_ptOrigin;
716 if (GetScrollPos(FALSE) != pt.x)
717 SetScrollPos(FALSE, m_ptOrigin.x, TRUE);
718 if (GetScrollPos(TRUE) != pt.y)
719 SetScrollPos(TRUE, m_ptOrigin.y, TRUE);
736 if (szView.cx == m_szView.cx && szView.cy == m_szView.cy)
739 CSize oldViewSize = m_szView;
756 CSize size = rcClient.Size();
757 m_wBarVisible = SSB_NULL;
758 CPoint ptOrigin = m_ptOrigin;
760 if (size.cy < m_szView.cy || (size.cy < m_szView.cy +
GetSbWidth() && size.cx < m_szView.cx))
763 m_wBarVisible |= SSB_VERT;
765 m_siVer.nMax = m_szView.cy - 1;
766 m_siVer.nPage = size.cy;
767 if (m_siVer.nPos + (
int)m_siVer.nPage > m_siVer.nMax)
769 m_siVer.nPos = m_siVer.nMax - m_siVer.nPage;
770 m_ptOrigin.y = m_siVer.nPos;
775 m_wBarVisible |= SSB_HORZ;
779 m_siHoz.nMax = m_szView.cx - 1;
781 if (m_siHoz.nPos + (
int)m_siHoz.nPage > m_siHoz.nMax)
783 m_siHoz.nPos = m_siHoz.nMax - m_siHoz.nPage;
784 m_ptOrigin.x = m_siHoz.nPos;
790 m_siHoz.nPage = size.cx;
792 m_siHoz.nMax = m_siHoz.nPage - 1;
800 m_siVer.nPage = size.cy;
802 m_siVer.nMax = size.cy - 1;
806 if (size.cx < m_szView.cx)
809 m_wBarVisible |= SSB_HORZ;
811 m_siHoz.nMax = m_szView.cx - 1;
812 m_siHoz.nPage = size.cx;
813 if (m_siHoz.nPos + (
int)m_siHoz.nPage > m_siHoz.nMax)
815 m_siHoz.nPos = m_siHoz.nMax - m_siHoz.nPage;
816 m_ptOrigin.x = m_siHoz.nPos;
822 m_siHoz.nPage = size.cx;
824 m_siHoz.nMax = m_siHoz.nPage - 1;
830 SetScrollPos(TRUE, m_siVer.nPos, TRUE);
831 SetScrollPos(FALSE, m_siHoz.nPos, TRUE);
835 if (m_ptOrigin.x != ptOrigin.x || m_ptOrigin.y != ptOrigin.y)
845 BOOL bRet = __baseCls::OnScroll(bVertical, uCode, nPos);
848 int nPos = GetScrollPos(bVertical);
849 CPoint ptOrigin = m_ptOrigin;
856 if (ptOrigin != m_ptOrigin)
859 if (uCode == SB_THUMBTRACK)
862 EventScroll evt(
this);
863 evt.bVertical = bVertical;
873 if (!(m_viewSize[0].isValid() && m_viewSize[1].isValid()))
877 rcWnd.DeflateRect(rcPadding);
880 if (m_viewSize[0].isMatchParent())
881 szView.cx = rcWnd.Width();
882 else if (m_viewSize[0].isWrapContent())
885 szView.cx = m_viewSize[0].toPixelSize(
GetScale());
887 if (m_viewSize[1].isMatchParent())
888 szView.cy = rcWnd.Height();
889 else if (m_viewSize[1].isWrapContent())
892 szView.cy = m_viewSize[1].toPixelSize(
GetScale());
894 if (m_viewSize[0].isWrapContent() || m_viewSize[1].isWrapContent())
896 CSize szCalc =
GetLayout()->MeasureChildren(
this, szView.cx, szView.cy);
897 if (m_viewSize[0].isWrapContent())
898 szView.cx = szCalc.cx;
899 if (m_viewSize[1].isWrapContent())
900 szView.cy = szCalc.cy;
903 if (szView.cy > rcWnd.Height() && m_viewSize[0].isMatchParent())
906 if (m_viewSize[1].isWrapContent())
909 CSize szCalc =
GetLayout()->MeasureChildren(
this, szView.cx, -1);
910 szView.cy = szCalc.cy;
913 else if (szView.cx > rcWnd.Width() && m_viewSize[1].isMatchParent())
916 if (m_viewSize[0].isWrapContent())
919 CSize szCalc =
GetLayout()->MeasureChildren(
this, -1, szView.cy);
920 szView.cx = szCalc.cx;
923 if (!m_viewSize[0].isSpecifiedSize())
924 szView.cx += rcPadding.left + rcPadding.right;
925 if (!m_viewSize[1].isSpecifiedSize())
926 szView.cy += rcPadding.top + rcPadding.bottom;
934 if (SplitString(strValue, L
',', values) != 2)
936 m_viewSize[0] = GETLAYOUTSIZE(values[0]);
937 m_viewSize[1] = GETLAYOUTSIZE(values[1]);
949 __baseCls::GetChildrenLayoutRect(&rcRet);
951 rcRet.OffsetRect(-m_ptOrigin.x, -m_ptOrigin.y);
952 rcRet.right = rcRet.left + m_szView.cx - rcPadding.left - rcPadding.right;
953 rcRet.bottom = rcRet.top + m_szView.cy - rcPadding.top - rcPadding.bottom;
960 __baseCls::UpdateChildrenPosition();
SOUI Panel with Scrollbar Support.
#define SB_CORNOR
Constant for scrollbar corner.
Smart pointer class for managing COM-style reference-counted objects.
BOOL addEvent(DWORD dwEventID, LPCWSTR pszEventHandlerName)
添加一个新事件到事件集
static LPCWSTR GetClassName()
void OnNcPaint(IRenderTarget *pRT)
Handles the WM_NCPAINT message.
int GetScrollPos(BOOL bVertical) SCONST OVERRIDE
Gets the scroll position for a scrollbar.
void OnNcLButtonDown(UINT nFlags, CPoint point)
Handles the WM_NCLBUTTONDOWN message.
virtual int GetScrollLineSize(BOOL bVertical)
Gets the line size for scrolling.
virtual CRect GetClientRect() const
Gets the client rectangle.
void SetScrollInfo(SCROLLINFO si, BOOL bVertical) OVERRIDE
Sets the scroll information for a scrollbar.
virtual void OnColorize(COLORREF cr)
Handles colorization events.
void OnScrollUpdateThumbTrack(BOOL bVert, int nPos) OVERRIDE
Updates the thumb track of the scrollbar.
int GetScrollBarArrowSize(BOOL bVert) SCONST OVERRIDE
Gets the arrow size for a scrollbar.
void OnNcMouseMove(UINT nFlags, CPoint point)
Handles the WM_NCMOUSEMOVE message.
ISwndContainer * GetScrollBarContainer() OVERRIDE
Gets the container for the scrollbar.
void OnEnable(BOOL bEnable, UINT uStatus)
Handles the WM_ENABLE message.
LRESULT OnNcCalcSize(BOOL bCalcValidRects, LPARAM lParam)
Handles the WM_NCCALCSIZE message.
void OnScrollKillTimer(BOOL bVert, char id) OVERRIDE
Kills a timer for the scrollbar.
BYTE GetScrollThumbTrackMinAlpha() SCONST OVERRIDE
Gets the minimum alpha value for the scrollbar thumb track.
virtual void OnScaleChanged(int nScale)
Handles scale change events.
SPanel()
Constructor for SPanel.
void OnShowWindow(BOOL bShow, UINT nStatus)
Handles the WM_SHOWWINDOW message.
ISkinObj * GetScrollBarSkin(BOOL bVert) SCONST OVERRIDE
Gets the skin for a scrollbar.
BOOL GetScrollRange(BOOL bVertical, LPINT lpMinPos, LPINT lpMaxPos) SCONST OVERRIDE
Gets the scroll range for a scrollbar.
BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
Handles the WM_MOUSEWHEEL message.
void OnTimer(char cTimerID)
Handles the WM_TIMER message.
void OnNcLButtonUp(UINT nFlags, CPoint pt)
Handles the WM_NCLBUTTONUP message.
void OnNcMouseLeave()
Handles the WM_NCMOUSELEAVE message.
int GetSbWidth() const
Gets the width of the scrollbar.
void OnHScroll(UINT nSBCode, UINT nPos, HWND hwnd)
Handles the WM_HSCROLL message.
BOOL HasScrollBar(BOOL bVertical) SCONST OVERRIDE
Checks if a scrollbar is present.
int GetScrollFadeFrames() SCONST OVERRIDE
Gets the number of fade frames for the scrollbar.
virtual BOOL OnNcHitTest(CPoint pt)
Handles the WM_NCHITTEST message.
const SCROLLINFO * GetScrollBarInfo(BOOL bVert) SCONST OVERRIDE
Gets the scroll information for a scrollbar.
void OnVScroll(UINT nSBCode, UINT nPos, HWND hwnd)
Handles the WM_VSCROLL message.
virtual BOOL OnScroll(BOOL bVertical, UINT uCode, int nPos)
Handles scroll events.
BOOL EnableScrollBar(int wBar, BOOL bEnable) OVERRIDE
Enables or disables a scrollbar.
int OnCreate(LPVOID)
Handles the WM_CREATE message.
CRect GetScrollBarRect(BOOL bVert) SCONST OVERRIDE
Gets the rectangle of a scrollbar.
void OnDestroy()
Handles the WM_DESTROY message.
BOOL SetScrollPos(BOOL bVertical, int nNewPos, BOOL bRedraw) OVERRIDE
Sets the scroll position for a scrollbar.
BOOL IsScrollBarEnable(BOOL bVertical) SCONST OVERRIDE
Checks if a scrollbar is enabled.
void ScrollUpdate()
Updates the scrollbar.
HRESULT OnAttrScrollbarSkin(SStringW strValue, BOOL bLoading)
Handles the scrollbar skin attribute.
virtual void OnContainerChanged(ISwndContainer *pOldContainer, ISwndContainer *pNewContainer)
Handles container change events.
void OnScrollCommand(BOOL bVert, int iCmd, int nPos) OVERRIDE
Handles scroll commands.
const IInterpolator * GetScrollInterpolator() SCONST OVERRIDE
Gets the interpolator for the scrollbar.
BOOL ShowScrollBar(int wBar, BOOL bShow) OVERRIDE
Shows or hides a scrollbar.
void OnScrollSetTimer(BOOL bVert, char id, UINT uElapse) OVERRIDE
Sets a timer for the scrollbar.
BOOL SetScrollRange(BOOL bVertical, int nMinPos, int nMaxPos, BOOL bRedraw) OVERRIDE
Sets the scroll range for a scrollbar.
void OnScrollUpdatePart(BOOL bVert, int iPart) OVERRIDE
Updates a part of the scrollbar.
A class representing an ASCII string.
BOOL SetTimer(char id, UINT uElapse) OVERRIDE
Sets a timer for the window.
BOOL FireEvent(IEvtArgs *evt) OVERRIDE
Fires an event.
virtual void OnContainerChanged(ISwndContainer *pOldContainer, ISwndContainer *pNewContainer)
Called when the container of the window changes.
void OnDestroy()
Handles the destruction of the window.
void UnlockUpdate() OVERRIDE
Unlocks updates to the window.
void ReleaseRenderTarget(IRenderTarget *pRT)
Releases the RenderTarget obtained via GetRenderTarget.
int GetScale() SCONST OVERRIDE
Retrieves the scale factor of the window.
BOOL IsVisible(BOOL bCheckParent=FALSE) SCONST OVERRIDE
Checks if the window is visible.
ISwndContainer * GetContainer() OVERRIDE
Retrieves the container associated with this window.
virtual CRect GetClientRect() const
Retrieves the client rectangle of the window.
BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
Handles the mouse wheel event.
LRESULT SSendMessage(UINT uMsg, WPARAM wParam=0, LPARAM lParam=0, BOOL *pbMsgHandled=NULL) OVERRIDE
Sends a message to the window.
void InvalidateRect(LPCRECT lprect) OVERRIDE
Invalidates a specific rectangle area of the window.
LayoutDirtyType m_layoutDirty
SWND SetCapture() OVERRIDE
Sets the window to capture the mouse.
BOOL IsDisabled(BOOL bCheckParent=FALSE) SCONST OVERRIDE
Checks if the window is disabled.
SEventSet * GetEventSet()
Retrieves the event set associated with the window.
BOOL KillTimer(char id) OVERRIDE
Kills a timer for the window.
void OnShowWindow(BOOL bShow, UINT nStatus)
Handles showing or hiding the window.
void Invalidate() OVERRIDE
Invalidates the entire window.
ILayout * GetLayout() OVERRIDE
Retrieves the layout object associated with the window.
void GetScaleSkin(SAutoRefPtr< ISkinObj > &pSkin, int nScale)
Retrieves a scaled skin object based on the current scale factor.
void OnEnable(BOOL bEnable, UINT nStatus)
Handles enabling or disabling the window.
void Update(BOOL bForce=FALSE) OVERRIDE
Updates the window.
const SwndStyle & GetStyle() const
Retrieves the style of the window.
void LockUpdate() OVERRIDE
Locks updates to the window.
BOOL ReleaseCapture() OVERRIDE
Releases the mouse capture from the window.
IRenderTarget * GetRenderTarget(LPCRECT pRc=NULL, GrtFlag gdcFlags=GRT_NODRAW, BOOL bClientRT=TRUE)
Retrieves a memory DC compatible with the SWND window.
CRect GetPadding() const
Retrieves the padding rectangle.
Interface for rendering target objects.
Interface for Skin Objects.
BOOL IsClass(LPCWSTR lpszName) SCONST PURE
Checks if the object is of a specified class type.
SOUI Window Container Interface.
HWND GetHostHwnd() PURE
Retrieves the handle to the host window.