ExtScrollWnd.cpp
上传用户:sesekoo
上传日期:2020-07-18
资源大小:21543k
文件大小:206k
- ) const
- {
- ASSERT_VALID( this );
- ASSERT( nBar == SB_HORZ || nBar == SB_VERT );
- CScrollBar * pScrollBarWnd = GetScrollBarCtrl( nBar );
- if( pScrollBarWnd != NULL )
- {
- // if( bTrackPos
- // && pScrollBarWnd->IsKindOf( RUNTIME_CLASS(CExtScrollBar) )
- // && ((CExtScrollBar*)pScrollBarWnd)->m_nHelperTrackPos != -1
- // )
- // return ((CExtScrollBar*)pScrollBarWnd)->m_nHelperTrackPos;
- if( m_bUse32BitScrollInfo )
- {
- SCROLLINFO _scroll_info;
- ::memset( &_scroll_info, 0, sizeof(SCROLLINFO) );
- _scroll_info.cbSize = sizeof(SCROLLINFO);
- if( pScrollBarWnd->GetScrollInfo(
- &_scroll_info,
- bTrackPos ? SIF_TRACKPOS : SIF_POS
- )
- )
- {
- LONG nRetVal = (LONG)
- ( bTrackPos
- ? _scroll_info.nTrackPos
- : _scroll_info.nPos
- );
- return nRetVal;
- }
- //ASSERT( FALSE );
- } // if( m_bUse32BitScrollInfo )
- LONG nRetVal = (LONG)
- pScrollBarWnd->GetScrollPos();
- return nRetVal;
- } // if( pScrollBarWnd != NULL )
- DWORD dwWndStyle = CWnd::GetStyle();
- if( ( nBar == SB_HORZ && (dwWndStyle & WS_HSCROLL) == 0 )
- || ( nBar == SB_VERT && (dwWndStyle & WS_VSCROLL) == 0 )
- )
- return 0;
- if( m_bUse32BitScrollInfo )
- {
- SCROLLINFO _scroll_info;
- ::memset( &_scroll_info, 0, sizeof(SCROLLINFO) );
- _scroll_info.cbSize = sizeof(SCROLLINFO);
- if( ( const_cast < CExtScrollWnd * > ( this ) ) ->
- CWnd::GetScrollInfo(
- nBar,
- &_scroll_info,
- bTrackPos ? SIF_TRACKPOS : SIF_POS
- )
- )
- {
- LONG nRetVal = (LONG)
- ( bTrackPos
- ? _scroll_info.nTrackPos
- : _scroll_info.nPos
- );
- return nRetVal;
- }
- //ASSERT( FALSE );
- } // if( m_bUse32BitScrollInfo )
- LONG nRetVal = (LONG)
- ( ( const_cast < CExtScrollWnd * > ( this ) ) ->
- CWnd::GetScrollPos( nBar )
- );
- return nRetVal;
- }
- void CExtScrollWnd::ScrollPos32Set(
- int nBar,
- LONG nPos,
- bool bRedraw // = true
- )
- {
- ASSERT_VALID( this );
- ASSERT( nBar == SB_HORZ || nBar == SB_VERT );
- CScrollBar * pScrollBarWnd = GetScrollBarCtrl( nBar );
- if( pScrollBarWnd != NULL )
- {
- if( m_bUse32BitScrollInfo )
- {
- SCROLLINFO _scroll_info;
- ::memset( &_scroll_info, 0, sizeof(SCROLLINFO) );
- _scroll_info.cbSize = sizeof(SCROLLINFO);
- _scroll_info.fMask = SIF_POS;
- _scroll_info.nPos = (int)nPos;
- if( pScrollBarWnd->SetScrollInfo(
- &_scroll_info,
- bRedraw ? TRUE : FALSE
- )
- )
- return;
- //ASSERT( FALSE );
- } // if( m_bUse32BitScrollInfo )
- pScrollBarWnd->SetScrollPos(
- (int)nPos,
- bRedraw ? TRUE : FALSE
- );
- return;
- } // if( pScrollBarWnd != NULL )
- if( m_bUse32BitScrollInfo )
- {
- SCROLLINFO _scroll_info;
- ::memset( &_scroll_info, 0, sizeof(SCROLLINFO) );
- _scroll_info.cbSize = sizeof(SCROLLINFO);
- _scroll_info.fMask = SIF_POS;
- _scroll_info.nPos = (int)nPos;
- if( CWnd::SetScrollInfo(
- nBar,
- &_scroll_info,
- bRedraw ? TRUE : FALSE
- )
- )
- return;
- //ASSERT( FALSE );
- } // if( m_bUse32BitScrollInfo )
- CWnd::SetScrollPos(
- nBar,
- (int)nPos,
- bRedraw ? TRUE : FALSE
- );
- }
- CPoint CExtScrollWnd::OnSwGetScrollPos() const
- {
- ASSERT_VALID( this );
- CPoint pt(
- ScrollPos32Get( SB_HORZ ),
- ScrollPos32Get( SB_VERT )
- );
- ASSERT( pt.x >= 0 && pt.y >= 0 );
- //LONG xMaxValue = ScrollLimit32Get( SB_HORZ );
- //LONG yMaxValue = ScrollLimit32Get( SB_VERT );
- // pt.x = min( pt.x, xMaxValue );
- // pt.y = min( pt.y, yMaxValue );
- return pt;
- }
- CPoint CExtScrollWnd::OnSwGetScrollPaintPos() const
- {
- ASSERT_VALID( this );
- return OnSwGetScrollPos();
- }
- CRect CExtScrollWnd::OnSwRecalcLayout(
- bool bDoLayout,
- LPCRECT pRectClientSrc // = NULL
- )
- {
- ASSERT_VALID( this );
- if( GetSafeHwnd() == NULL )
- return CRect( *pRectClientSrc );
- if( bDoLayout )
- {
- CScrollBar * pScrollBarWndH = GetScrollBarCtrl( SB_HORZ );
- CScrollBar * pScrollBarWndV = GetScrollBarCtrl( SB_VERT );
- if( pScrollBarWndH != NULL && pScrollBarWndV != NULL )
- {
- CExtScrollBar * pExtScrollBarWndH = DYNAMIC_DOWNCAST( CExtScrollBar, pScrollBarWndH );
- CExtScrollBar * pExtScrollBarWndV = DYNAMIC_DOWNCAST( CExtScrollBar, pScrollBarWndV );
- if( pExtScrollBarWndH != NULL && pExtScrollBarWndV != NULL )
- {
- pExtScrollBarWndH->SyncReservedSpace( pExtScrollBarWndV );
- pExtScrollBarWndV->SyncReservedSpace( pExtScrollBarWndH );
- } // if( pExtScrollBarWndH != NULL && pExtScrollBarWndV != NULL )
- } // if( pScrollBarWndH != NULL && pScrollBarWndV != NULL )
- } // if( bDoLayout )
- CRect rcClient;
- if( pRectClientSrc != NULL )
- rcClient = *pRectClientSrc;
- else
- CWnd::GetClientRect( &rcClient );
- CWnd::RepositionBars(
- 0,
- 0x0FFFF,
- AFX_IDW_PANE_FIRST,
- bDoLayout ? CWnd::reposDefault : CWnd::reposQuery,
- &rcClient,
- &rcClient,
- TRUE
- );
- return rcClient;
- }
- CRect CExtScrollWnd::OnSwGetClientRect() const
- {
- ASSERT_VALID( this );
- CRect rcClient =
- ( const_cast < CExtScrollWnd * > ( this ) )
- -> OnSwRecalcLayout( false );
- return rcClient;
- }
- bool CExtScrollWnd::OnSwHasScrollBar( bool bHorz ) const
- {
- ASSERT_VALID( this );
- CScrollBar * pScrollBarWnd = GetScrollBarCtrl( bHorz ? SB_HORZ : SB_VERT );
- if( pScrollBarWnd != NULL )
- {
- if( pScrollBarWnd->IsWindowEnabled() )
- return true;
- return false;
- } // if( pScrollBarWnd != NULL )
- DWORD dwWndStyle = CWnd::GetStyle();
- DWORD dwTestStyle = bHorz ? WS_HSCROLL : WS_VSCROLL;
- if( ( dwWndStyle & dwTestStyle ) != 0 )
- return true;
- return false;
- }
- bool CExtScrollWnd::OnSwCanAutoHideScrollBar( bool bHorz ) const
- {
- ASSERT_VALID( this );
- bHorz;
- return true;
- }
- void CExtScrollWnd::OnSwEnableScrollBarCtrl( int nBar, bool bEnable )
- {
- ASSERT_VALID( this );
- ASSERT( nBar == SB_HORZ || nBar == SB_VERT || nBar == SB_BOTH );
- if( ! IsWindowEnabled() )
- bEnable = false;
- DWORD dwWndStyle = CWnd::GetStyle();
- CPoint ptMove = OnSwGetScrollPos();
- CScrollBar * pScrollBarWndH = GetScrollBarCtrl( SB_HORZ );
- CScrollBar * pScrollBarWndV = GetScrollBarCtrl( SB_VERT );
- if( nBar == SB_HORZ || nBar == SB_BOTH )
- {
- if( (!bEnable) && ptMove.x != 0 )
- {
- ptMove.x = 0;
- OnSwSetScrollPos( ptMove );
- } // if( (!bEnable) && ptMove.x != 0 )
- if( pScrollBarWndH != NULL )
- {
- if( (dwWndStyle & WS_HSCROLL) != 0 )
- CWnd::ShowScrollBar( SB_HORZ, FALSE );
- bool bAreadyEnabled = pScrollBarWndH->IsWindowEnabled() ? true : false;
- if( !( ( bAreadyEnabled && bEnable )
- || ( (!bAreadyEnabled) && (!bEnable) )
- )
- )
- {
- pScrollBarWndH->EnableWindow( bEnable ? TRUE : FALSE );
- if( OnSwCanAutoHideScrollBar(true) )
- pScrollBarWndH->ShowWindow( bEnable ? SW_SHOW : SW_HIDE );
- else if( bEnable && (pScrollBarWndH->GetStyle()&WS_VISIBLE) == 0 )
- pScrollBarWndH->ShowWindow( SW_SHOW );
- }
- } // if( pScrollBarWndH != NULL )
- else
- {
- if( OnSwCanAutoHideScrollBar(true) )
- CWnd::ShowScrollBar(
- SB_HORZ,
- bEnable ? TRUE : FALSE
- );
- else
- CWnd::EnableScrollBar(
- SB_HORZ,
- bEnable ? ESB_ENABLE_BOTH : ESB_DISABLE_BOTH
- );
- } // else from if( pScrollBarWndH != NULL )
- } // if( nBar == SB_HORZ || nBar == SB_BOTH )
- if( nBar == SB_VERT || nBar == SB_BOTH )
- {
- if( (!bEnable) && ptMove.y != 0 )
- {
- ptMove.y = 0;
- OnSwSetScrollPos( ptMove );
- } // if( (!bEnable) && ptMove.y != 0 )
- if( pScrollBarWndV != NULL )
- {
- if( (dwWndStyle & WS_VSCROLL) != 0 )
- CWnd::ShowScrollBar( SB_VERT, FALSE );
- bool bAreadyEnabled = pScrollBarWndV->IsWindowEnabled() ? true : false;
- if( !( ( bAreadyEnabled && bEnable )
- || ( (!bAreadyEnabled) && (!bEnable) )
- )
- )
- {
- pScrollBarWndV->EnableWindow( bEnable ? TRUE : FALSE );
- if( OnSwCanAutoHideScrollBar(false) )
- pScrollBarWndV->ShowWindow( bEnable ? SW_SHOW : SW_HIDE );
- else if( bEnable && (pScrollBarWndV->GetStyle()&WS_VISIBLE) == 0 )
- pScrollBarWndV->ShowWindow( SW_SHOW );
- }
- } // if( pScrollBarWndV != NULL )
- else
- {
- if( OnSwCanAutoHideScrollBar(false) )
- CWnd::ShowScrollBar(
- SB_VERT,
- bEnable ? TRUE : FALSE
- );
- else
- CWnd::EnableScrollBar(
- SB_VERT,
- bEnable ? ESB_ENABLE_BOTH : ESB_DISABLE_BOTH
- );
- } // else from if( pScrollBarWndV != NULL )
- } // if( nBar == SB_VERT || nBar == SB_BOTH )
- CExtScrollBar * pExtScrollBarWndH = DYNAMIC_DOWNCAST( CExtScrollBar, pScrollBarWndH );
- CExtScrollBar * pExtScrollBarWndV = DYNAMIC_DOWNCAST( CExtScrollBar, pScrollBarWndV );
- if( pExtScrollBarWndH != NULL && pExtScrollBarWndV != NULL )
- {
- pExtScrollBarWndH->SyncReservedSpace( pExtScrollBarWndV );
- pExtScrollBarWndV->SyncReservedSpace( pExtScrollBarWndH );
- } // if( pExtScrollBarWndH != NULL && pExtScrollBarWndV != NULL )
- }
- void CExtScrollWnd::OnSwSetScrollPos( POINT pt )
- {
- ASSERT_VALID( this );
- ASSERT( pt.x >= 0 && pt.y >= 0 );
- int xOrgValue = ScrollPos32Get( SB_HORZ );
- ScrollPos32Set( SB_HORZ, pt.x );
- int yOrgValue = ScrollPos32Get( SB_VERT );
- ScrollPos32Set( SB_VERT, pt.y );
- OnSwDoScrollWindow( xOrgValue - pt.x, yOrgValue - pt.y );
- }
- UINT CExtScrollWnd::OnSwCalcMouseScrollLines(
- UINT fFlags,
- short zDelta,
- CPoint point
- )
- {
- ASSERT_VALID( this );
- fFlags;
- zDelta;
- point;
- return g_PaintManager.GetMouseWheelScrollLines();
- }
- bool CExtScrollWnd::OnSwDoMouseWheel(
- UINT fFlags,
- short zDelta,
- CPoint point
- )
- {
- ASSERT_VALID( this );
- point;
- if( CExtPopupMenuWnd::IsMenuTracking() )
- {
- CExtPopupMenuWnd * pPopup = CExtPopupMenuSite::g_DefPopupMenuSite.GetInstance();
- if( pPopup == NULL )
- return false;
- bool bFound = false;
- CWnd * pWnd = GetParent();
- for( ; pWnd != NULL; pWnd = pWnd->GetParent() )
- {
- if( pWnd == pPopup )
- {
- bFound = true;
- break;
- }
- }
- if( ! bFound )
- return false;
- } // if( CExtPopupMenuWnd::IsMenuTracking() )
- else if( (fFlags&(MK_CONTROL)) != 0
- || CExtToolControlBar::g_bMenuTracking
- )
- return false;
- if( ! ( OnSwHasScrollBar(true) || OnSwHasScrollBar(false) ) )
- return false;
- bool bResult = false;
- UINT uWheelScrollLines =
- OnSwCalcMouseScrollLines(
- fFlags,
- zDelta,
- point
- );
- if( OnSwHasScrollBar(false)
- && ( (fFlags&(MK_SHIFT)) == 0 )
- )
- {
- int nDisplacement;
- int nToScroll =
- ::MulDiv( -zDelta, uWheelScrollLines, WHEEL_DELTA );
- if( nToScroll == -1
- || uWheelScrollLines == WHEEL_PAGESCROLL
- )
- {
- nDisplacement = OnSwGetPageSize( -1 ).cy;
- if( zDelta > 0 )
- nDisplacement = -nDisplacement;
- }
- else
- {
- nDisplacement =
- nToScroll * OnSwGetLineSize( 1 ).cy;
- nDisplacement =
- min(
- nDisplacement,
- OnSwGetPageSize( 1 ).cy
- );
- }
- bResult =
- OnSwDoScrollBy(
- CSize( 0, nDisplacement ),
- true
- );
- }
- else if(
- OnSwHasScrollBar( true )
- && ( (fFlags&(MK_SHIFT)) != 0 )
- )
- {
- int nDisplacement;
- int nToScroll =
- ::MulDiv( -zDelta, uWheelScrollLines, WHEEL_DELTA );
- if( nToScroll == -1
- || uWheelScrollLines == WHEEL_PAGESCROLL
- )
- {
- nDisplacement = OnSwGetPageSize( -1 ).cx;
- if( zDelta > 0 )
- nDisplacement = -nDisplacement;
- }
- else
- {
- nDisplacement =
- nToScroll * OnSwGetLineSize( 1 ).cx;
- nDisplacement =
- min(
- nDisplacement,
- OnSwGetPageSize( 1 ).cx
- );
- }
- bResult =
- OnSwDoScrollBy(
- CSize( nDisplacement, 0 ),
- true
- );
- }
- if( bResult )
- {
- OnSwInvalidate( m_bScrollErase );
- if( m_bScrollUpdateWindow )
- OnSwUpdateWindow();
- }
- return bResult;
- }
- bool CExtScrollWnd::OnSwDoScroll(
- UINT nScrollCode,
- UINT nPos,
- bool bDoScroll // = true
- )
- {
- ASSERT_VALID( this );
- LONG xPos, xOrgValue, yPos, yOrgValue;
- xOrgValue = xPos = ScrollPos32Get( SB_HORZ );
- switch( LOBYTE(nScrollCode) )
- {
- case SB_ENDSCROLL: break;
- case SB_TOP: xPos = 0; break;
- case SB_BOTTOM: xPos = __EXT_SCROLL_NUMERIC_MAX; break;
- case SB_LINEUP: xPos -= OnSwGetLineSize( -1 ).cx; break;
- case SB_LINEDOWN: xPos += OnSwGetLineSize( 1 ).cx; break;
- case SB_PAGEUP: xPos -= OnSwGetPageSize( -1 ).cx; break;
- case SB_PAGEDOWN: xPos += OnSwGetPageSize( 1 ).cx; break;
- case SB_THUMBTRACK:
- if( ! OnSwQueryThumbTrackEnabled(true) )
- break;
- case SB_THUMBPOSITION:
- if( m_bUse32BitScrollInfo )
- nPos = ScrollPos32Get( SB_HORZ, true );
- xPos = nPos;
- break;
- }
- yOrgValue = yPos = ScrollPos32Get( SB_VERT );
- switch( HIBYTE(nScrollCode) )
- {
- case SB_ENDSCROLL: break;
- case SB_TOP: yPos = 0; break;
- case SB_BOTTOM: yPos = __EXT_SCROLL_NUMERIC_MAX; break;
- case SB_LINEUP: yPos -= OnSwGetLineSize( -1 ).cy; break;
- case SB_LINEDOWN: yPos += OnSwGetLineSize( 1 ).cy; break;
- case SB_PAGEUP: yPos -= OnSwGetPageSize( -1 ).cy; break;
- case SB_PAGEDOWN: yPos += OnSwGetPageSize( 1 ).cy; break;
- case SB_THUMBTRACK:
- if( ! OnSwQueryThumbTrackEnabled(false) )
- break;
- case SB_THUMBPOSITION:
- if( m_bUse32BitScrollInfo )
- nPos = ScrollPos32Get( SB_VERT, true );
- yPos = nPos;
- break;
- }
- bool bResult =
- OnSwDoScrollBy(
- CSize( xPos - xOrgValue, yPos - yOrgValue ),
- bDoScroll
- );
- if( bResult && bDoScroll && m_bScrollUpdateWindow )
- OnSwUpdateWindow();
- return bResult;
- }
- bool CExtScrollWnd::OnSwDoScrollBy(
- CSize sizeScroll,
- bool bDoScroll // = true
- )
- {
- ASSERT_VALID( this );
- int xMaxValue, xOrgValue, xPos, yMaxValue, yOrgValue, yPos;
- if( ! OnSwHasScrollBar(false) )
- sizeScroll.cy = 0;
- if( ! OnSwHasScrollBar(true) )
- sizeScroll.cx = 0;
- // adjust current positions
- xOrgValue = xPos = ScrollPos32Get( SB_HORZ );
- xMaxValue = ScrollLimit32Get( SB_HORZ );
- xPos += sizeScroll.cx;
- if( xPos < 0 )
- xPos = 0;
- else if( xPos > xMaxValue )
- xPos = xMaxValue;
- yOrgValue = yPos = ScrollPos32Get( SB_VERT );
- yMaxValue = ScrollLimit32Get( SB_VERT );
- yPos += sizeScroll.cy;
- if( yPos < 0 )
- yPos = 0;
- else if( yPos > yMaxValue )
- yPos = yMaxValue;
- if( xPos == xOrgValue && yPos == yOrgValue )
- return false;
- if( bDoScroll )
- {
- OnSwDoScrollWindow( xOrgValue - xPos, yOrgValue - yPos );
- if( xPos != xOrgValue )
- ScrollPos32Set( SB_HORZ, xPos );
- if( yPos != yOrgValue )
- ScrollPos32Set( SB_VERT, yPos );
- }
- return true;
- }
- CSize CExtScrollWnd::OnSwGetScrollBarSizes() const
- {
- ASSERT_VALID( this );
- CSize sizeSb( 0, 0 );
- DWORD dwWndStyle = CWnd::GetStyle();
- if( GetScrollBarCtrl(SB_HORZ) == NULL )
- {
- sizeSb.cx = afxData.cxVScroll;
- if( dwWndStyle & WS_BORDER )
- sizeSb.cx -= __EXT_MFC_CX_BORDER;
- } // if( GetScrollBarCtrl(SB_HORZ) == NULL )
- if( GetScrollBarCtrl(SB_VERT) == NULL )
- {
- sizeSb.cy = afxData.cyHScroll;
- if( dwWndStyle & WS_BORDER )
- sizeSb.cy -= __EXT_MFC_CY_BORDER;
- } // if( GetScrollBarCtrl(SB_VERT) == NULL )
- return sizeSb;
- }
- bool CExtScrollWnd::OnSwCalcClientSizes(
- CSize & size,
- CSize & sizeSb
- )
- {
- // return true if enough room to add scrollbars if needed
- ASSERT_VALID( this );
- CRect rcClient = OnSwGetClientRect();
- size = rcClient.Size();
- sizeSb = OnSwGetScrollBarSizes();
- if( sizeSb.cx != 0
- && OnSwHasScrollBar( false )
- )
- size.cx += sizeSb.cx;
- if( sizeSb.cy != 0
- && OnSwHasScrollBar( true )
- )
- size.cy += sizeSb.cy;
- // return
- // ( size.cx > sizeSb.cx && size.cy > sizeSb.cy )
- // ? true : false;
- return true;
- }
- bool CExtScrollWnd::OnSwQueryThumbTrackEnabled( bool bHorz ) const
- {
- ASSERT_VALID( this );
- bHorz;
- return true;
- }
- void CExtScrollWnd::OnSwGetScrollBarState(
- CSize sizeClient,
- CSize & sizeNeedSB,
- CSize & sizeRange,
- CPoint & ptMove,
- bool bInsideClient
- ) const
- {
- ASSERT_VALID( this );
- CSize sizeSb = OnSwGetScrollBarSizes();
- sizeRange = OnSwGetTotalSize() - sizeClient;
- ptMove = OnSwGetScrollPos();
- bool bNeedH = sizeRange.cx > 0;
- if( !bNeedH )
- ptMove.x = 0;
- else if( bInsideClient )
- sizeRange.cy += sizeSb.cy;
- bool bNeedV = sizeRange.cy > 0;
- if( !bNeedV )
- ptMove.y = 0;
- else if ( bInsideClient )
- sizeRange.cx += sizeSb.cx;
- if( bNeedV && (!bNeedH) && sizeRange.cx > 0 )
- {
- ASSERT( bInsideClient );
- bNeedH = true;
- sizeRange.cy += sizeSb.cy;
- } // if( bNeedV && (!bNeedH) && sizeRange.cx > 0 )
- if( sizeRange.cx > 0 && ptMove.x >= sizeRange.cx )
- ptMove.x = sizeRange.cx;
- if( sizeRange.cy > 0 && ptMove.y >= sizeRange.cy )
- ptMove.y = sizeRange.cy;
- sizeNeedSB.cx = bNeedH;
- sizeNeedSB.cy = bNeedV;
- }
- void CExtScrollWnd::OnSwUpdateScrollBars()
- {
- ASSERT_VALID( this );
- if( m_nUpdateScrollBars > 1 )
- return;
- m_nUpdateScrollBars ++;
- ASSERT( OnSwGetTotalSize().cx >= 0 && OnSwGetTotalSize().cy >= 0 );
- CRect rcClient;
- bool bCalcClient = true;
- CWnd * pParentWnd = GetParent();
- if( pParentWnd != NULL
- && (BOOL)pParentWnd->SendMessage(
- WM_RECALCPARENT,
- 0,
- (LPARAM)(LPCRECT)&rcClient
- ) != 0
- )
- bCalcClient = false;
- CSize sizeClient;
- CSize sizeSb;
- if( bCalcClient )
- {
- if( ! OnSwCalcClientSizes( sizeClient, sizeSb ) )
- { // no room for scroll bars
- CRect rcClient2 = OnSwGetClientRect();
- if( rcClient2.Width() > 0 && rcClient2.Height() > 0 )
- {
- OnSwEnableScrollBarCtrl( SB_BOTH, false );
- OnSwRecalcLayout( true );
- }
- m_nUpdateScrollBars --;
- return;
- }
- }
- else
- { // let parent window determine the "client" rect
- sizeSb = OnSwGetScrollBarSizes();
- sizeClient.cx = rcClient.right - rcClient.left;
- sizeClient.cy = rcClient.bottom - rcClient.top;
- }
- // if enough room to add scrollbars
- CSize sizeRange;
- CPoint ptMove;
- CSize sizeNeedSB;
- OnSwGetScrollBarState(
- sizeClient,
- sizeNeedSB,
- sizeRange,
- ptMove,
- bCalcClient
- );
- if( sizeNeedSB.cx )
- sizeClient.cy -= sizeSb.cy;
- if( sizeNeedSB.cy )
- sizeClient.cx -= sizeSb.cx;
- // scroll window + update
- OnSwSetScrollPos( ptMove );
- // the scrollbar page range
- SCROLLINFO _scroll_info;
- ::memset( &_scroll_info, 0, sizeof(SCROLLINFO) );
- _scroll_info.cbSize = sizeof(SCROLLINFO);
- _scroll_info.fMask = SIF_PAGE|SIF_RANGE;
- _scroll_info.nMin = 0;
- // update bars
- OnSwEnableScrollBarCtrl( SB_HORZ, sizeNeedSB.cx ? true : false );
- if( sizeNeedSB.cx )
- {
- _scroll_info.nPage = sizeClient.cx;
- _scroll_info.nMax = OnSwGetTotalSize().cx - 1;
- if( ! OnSwScrollInfoAdjust(
- SB_HORZ,
- _scroll_info,
- true
- )
- )
- OnSwSetScrollRange(
- SB_HORZ,
- 0,
- sizeRange.cx,
- true
- );
- } // if( sizeNeedSB.cx )
- OnSwEnableScrollBarCtrl( SB_VERT, sizeNeedSB.cy ? true : false );
- if( sizeNeedSB.cy )
- {
- _scroll_info.nPage = sizeClient.cy;
- _scroll_info.nMax = OnSwGetTotalSize().cy - 1;
- if( ! OnSwScrollInfoAdjust(
- SB_VERT,
- _scroll_info,
- true
- )
- )
- OnSwSetScrollRange(
- SB_VERT,
- 0,
- sizeRange.cy,
- true
- );
- } // if( sizeNeedSB.cy )
- OnSwRecalcLayout( true );
- m_nUpdateScrollBars --;
- }
- void CExtScrollWnd::OnSwDoScrollWindow(
- int xAmount,
- int yAmount,
- LPCRECT lpRect, // = NULL
- LPCRECT lpClipRect // = NULL
- )
- {
- ASSERT_VALID( this );
- if( m_bScrollPhysical )
- CWnd::ScrollWindow(
- xAmount,
- yAmount,
- lpRect,
- lpClipRect
- );
- if( m_bScrollInvalidate )
- OnSwInvalidate( m_bScrollErase );
- if( m_bScrollUpdateWindow )
- OnSwUpdateWindow();
- }
- void CExtScrollWnd::OnSwInvalidate( bool bErase )
- {
- ASSERT_VALID( this );
- if( GetSafeHwnd() == NULL )
- return;
- if( ! IsWindowVisible() )
- return;
- CScrollBar * pScrollBarWndH = GetScrollBarCtrl( SB_HORZ );
- CScrollBar * pScrollBarWndV = GetScrollBarCtrl( SB_VERT );
- if( pScrollBarWndH != NULL
- && ( pScrollBarWndH->GetStyle() & WS_VISIBLE ) == 0
- )
- pScrollBarWndH = NULL;
- if( pScrollBarWndV != NULL
- && ( pScrollBarWndV->GetStyle() & WS_VISIBLE ) == 0
- )
- pScrollBarWndV = NULL;
- if( pScrollBarWndH == NULL && pScrollBarWndV == NULL )
- {
- CWnd::Invalidate( bErase ? TRUE : FALSE );
- return;
- } // if( pScrollBarWndH == NULL && pScrollBarWndV == NULL )
- CRect rcClientReal;
- CWnd::GetClientRect( &rcClientReal );
- CRgn rgnInvalidate;
- if( !rgnInvalidate.CreateRectRgnIndirect(&rcClientReal) )
- {
- CWnd::Invalidate( bErase ? TRUE : FALSE );
- return;
- }
- if( pScrollBarWndH != NULL )
- {
- CRect rcBar;
- pScrollBarWndH->GetWindowRect( &rcBar );
- ScreenToClient( &rcBar );
- CRgn rgnBar;
- if( (! rgnBar.CreateRectRgnIndirect(&rcBar) )
- || rgnInvalidate.CombineRgn(
- &rgnInvalidate,
- &rgnBar,
- RGN_DIFF
- ) == ERROR
- )
- {
- CWnd::Invalidate( bErase ? TRUE : FALSE );
- return;
- }
- } // if( pScrollBarWndH != NULL )
- if( pScrollBarWndV != NULL )
- {
- CRect rcBar;
- pScrollBarWndV->GetWindowRect( &rcBar );
- ScreenToClient( &rcBar );
- CRgn rgnBar;
- if( (! rgnBar.CreateRectRgnIndirect(&rcBar) )
- || rgnInvalidate.CombineRgn(
- &rgnInvalidate,
- &rgnBar,
- RGN_DIFF
- ) == ERROR
- )
- {
- CWnd::Invalidate( bErase ? TRUE : FALSE );
- return;
- }
- } // if( pScrollBarWndV != NULL )
- CWnd::InvalidateRgn( &rgnInvalidate, bErase ? TRUE : FALSE );
- }
- void CExtScrollWnd::OnSwUpdateWindow()
- {
- ASSERT_VALID( this );
- if( GetSafeHwnd() == NULL )
- return;
- UpdateWindow();
- }
- void CExtScrollWnd::OnSwDoRedraw()
- {
- ASSERT_VALID( this );
- if( GetSafeHwnd() == NULL )
- return;
- if( m_bRedrawInvalidate )
- OnSwInvalidate( m_bRedrawErase );
- if( m_bRedrawUpdateWindow )
- OnSwUpdateWindow();
- }
- void CExtScrollWnd::OnSwPaint( CDC & dc )
- {
- ASSERT_VALID( this );
- ASSERT( dc.GetSafeHdc() != NULL );
- dc;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CExtScrollWnd message handlers
- void CExtScrollWnd::OnSize(UINT nType, int cx, int cy)
- {
- CWnd::OnSize(nType, cx, cy);
- if( nType != SIZE_MINIMIZED )
- {
- bool bH1 = OnSwHasScrollBar( true ), bV1 = OnSwHasScrollBar( false );
- OnSwRecalcLayout( true );
- OnSwUpdateScrollBars();
- bool bH2 = OnSwHasScrollBar( true ), bV2 = OnSwHasScrollBar( false );
- if( bH1 != bH2 || bV1 != bV2 )
- OnSwUpdateScrollBars();
- OnSwDoRedraw();
- }
- }
- void CExtScrollWnd::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- if( pScrollBar != NULL
- && pScrollBar->SendChildNotifyLastMsg()
- )
- return;
- if( pScrollBar != GetScrollBarCtrl(SB_HORZ) )
- return;
- if( nSBCode == SB_ENDSCROLL )
- return;
- OnSwDoScroll( MAKEWORD( nSBCode, -1 ), nPos );
- if( nSBCode == SB_ENDSCROLL
- && ( ! OnSwQueryThumbTrackEnabled( true ) )
- )
- OnSwInvalidate( false );
- }
- void CExtScrollWnd::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- if( pScrollBar != NULL
- && pScrollBar->SendChildNotifyLastMsg()
- )
- return;
- if( pScrollBar != GetScrollBarCtrl(SB_VERT) )
- return;
- if( nSBCode == SB_ENDSCROLL )
- return;
- OnSwDoScroll( MAKEWORD( -1, nSBCode ), nPos );
- if( nSBCode == SB_ENDSCROLL
- && ( ! OnSwQueryThumbTrackEnabled( false ) )
- )
- OnSwInvalidate( false );
- }
- BOOL CExtScrollWnd::OnMouseWheel(UINT fFlags, short zDelta, CPoint point)
- {
- return
- OnSwDoMouseWheel( fFlags, zDelta, point )
- ? true : false;
- }
- BOOL CExtScrollWnd::OnEraseBkgnd(CDC* pDC)
- {
- if( m_bEatErasing )
- return TRUE;
- return CWnd::OnEraseBkgnd(pDC);
- }
- void CExtScrollWnd::OnPaint()
- {
- bool bSingleBufferPaint = false;
- CPaintDC dcPaint( this );
- CExtPaintManager::stat_ExcludeChildAreas(
- dcPaint.m_hDC,
- m_hWnd,
- CExtPaintManager::stat_DefExcludeChildAreaCallback
- );
- CRect rcAreaBetweenScrollBarWindows( 0, 0, 0, 0 );
- CScrollBar * pScrollBarH = GetScrollBarCtrl( SB_HORZ );
- CScrollBar * pScrollBarV = GetScrollBarCtrl( SB_VERT );
- if( pScrollBarH->GetSafeHwnd() != NULL
- && pScrollBarV->GetSafeHwnd() != NULL
- && ( pScrollBarH->GetStyle() & WS_VISIBLE ) != 0
- && ( pScrollBarV->GetStyle() & WS_VISIBLE ) != 0
- )
- {
- CRect rcH, rcV;
- pScrollBarH->GetWindowRect( &rcH );
- pScrollBarV->GetWindowRect( &rcV );
- ScreenToClient( &rcH );
- ScreenToClient( &rcV );
- rcAreaBetweenScrollBarWindows.SetRect( rcV.left, rcH.top, rcV.right, rcH.bottom );
- } // if( pScrollBarH->GetSafeHwnd() != NULL ...
- CPoint ptSp = OnSwGetScrollPaintPos();
- if( m_bBufferedPainting )
- {
- CRect rcClient;
- GetClientRect( &rcClient );
- CExtMemoryDC dc( &dcPaint, m_bClientCB ? (&rcClient) : NULL );
- ASSERT( dc.GetSafeHdc() != NULL );
- if( dc.GetSafeHdc() != NULL )
- {
- CPoint ptVpOld( dc.SetViewportOrg( -ptSp ) );
- OnSwPaint( dc );
- dc.SetViewportOrg( ptVpOld );
- if( (! rcAreaBetweenScrollBarWindows.IsRectEmpty() )
- && dc.RectVisible( &rcAreaBetweenScrollBarWindows )
- )
- OnSwPaintAreaBetweenScrollBarWindows(
- dc,
- rcAreaBetweenScrollBarWindows
- );
- } // if( dc.GetSafeHdc() != NULL )
- else
- bSingleBufferPaint = true;
- } // if( m_bBufferedPainting )
- else
- bSingleBufferPaint = true;
- if( bSingleBufferPaint )
- {
- CPoint ptVpOld( dcPaint.SetViewportOrg( -ptSp ) );
- OnSwPaint( dcPaint );
- dcPaint.SetViewportOrg( ptVpOld );
- if( (! rcAreaBetweenScrollBarWindows.IsRectEmpty() )
- && dcPaint.RectVisible( &rcAreaBetweenScrollBarWindows )
- )
- OnSwPaintAreaBetweenScrollBarWindows(
- dcPaint,
- rcAreaBetweenScrollBarWindows
- );
- } // if( bSingleBufferPaint )
- }
- LRESULT CExtScrollWnd::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- if( message == WM_PRINT || message == WM_PRINTCLIENT )
- {
- CDC * pDC = CDC::FromHandle( (HDC)wParam );
- if( (lParam&(PRF_CLIENT|PRF_ERASEBKGND)) != 0 )
- {
- OnSwPaint( *pDC );
- CScrollBar * pScrollBarH = GetScrollBarCtrl( SB_HORZ );
- CScrollBar * pScrollBarV = GetScrollBarCtrl( SB_VERT );
- if( pScrollBarH->GetSafeHwnd() != NULL
- && pScrollBarV->GetSafeHwnd() != NULL
- && ( pScrollBarH->GetStyle() & WS_VISIBLE ) != 0
- && ( pScrollBarV->GetStyle() & WS_VISIBLE ) != 0
- )
- {
- CRect rcH, rcV;
- pScrollBarH->GetWindowRect( &rcH );
- pScrollBarV->GetWindowRect( &rcV );
- ScreenToClient( &rcH );
- ScreenToClient( &rcV );
- CRect rcAreaBetweenScrollBarWindows( rcV.left, rcH.top, rcV.right, rcH.bottom );
- if( (! rcAreaBetweenScrollBarWindows.IsRectEmpty() )
- && pDC->RectVisible( &rcAreaBetweenScrollBarWindows )
- )
- OnSwPaintAreaBetweenScrollBarWindows(
- *pDC,
- rcAreaBetweenScrollBarWindows
- );
- } // if( pScrollBarH->GetSafeHwnd() != NULL ...
- }
- if( (lParam&PRF_CHILDREN) != 0 )
- CExtPaintManager::stat_PrintChildren(
- m_hWnd,
- message,
- pDC->GetSafeHdc(),
- lParam,
- false
- );
- return (!0);
- }
- return CWnd::WindowProc(message, wParam, lParam);
- }
- void CExtScrollWnd::OnSwPaintAreaBetweenScrollBarWindows(
- CDC & dc,
- const RECT & rcAreaBetweenScrollBarWindows
- )
- {
- ASSERT_VALID( this );
- ASSERT( GetSafeHwnd() != NULL );
- ASSERT( dc.GetSafeHdc() != NULL );
- CRect rc = rcAreaBetweenScrollBarWindows;
- CExtMemoryDC dcMem( &dc, &rc );
- CExtPaintManager * pPM = PmBridge_GetPM();
- ASSERT_VALID( pPM );
- if( (! pPM->GetCb2DbTransparentMode(this ) )
- || (! pPM->PaintDockerBkgnd( true, dcMem, this ) )
- //|| (! pPM->PaintDocumentClientAreaBkgnd( dcMem, this ) )
- )
- dc.FillSolidRect(
- &rc,
- pPM->GetColor(
- CExtPaintManager::CLR_3DFACE_OUT,
- this
- )
- );
- }
- BOOL CExtScrollWnd::PreTranslateMessage(MSG* pMsg)
- {
- if( pMsg->message == WM_MOUSEWHEEL
- && GetSafeHwnd() != NULL
- && CExtPopupMenuWnd::TestHoverEnabledFromActiveHWND(
- GetSafeHwnd()
- )
- )
- {
- CPoint point = pMsg->lParam;
- HWND hWnd = ::WindowFromPoint( point );
- if( hWnd != NULL && hWnd == m_hWnd )
- {
- UINT fFlags = LOWORD(pMsg->wParam);
- short zDelta = HIWORD(pMsg->wParam);
- if( OnSwDoMouseWheel( fFlags, zDelta, point ) )
- return TRUE;
- }
- }
-
- return CWnd::PreTranslateMessage(pMsg);
- }
- void CExtScrollWnd::OnSwEnsurePointAvail( CPoint point )
- {
- ASSERT_VALID( this );
- if( GetSafeHwnd() == NULL)
- return;
- if( ! ::IsWindow( GetSafeHwnd() ) )
- return;
- if( ! ( OnSwHasScrollBar(false) || OnSwHasScrollBar(true) ) )
- return;
- CRect rcClient;
- CWnd::GetClientRect( &rcClient );
- // if( rcClient.PtInRect(point) )
- // return;
- CPoint ptScrollOrg( OnSwGetScrollPos() );
- CPoint ptScroll( ptScrollOrg );
- CSize sizeTotal( OnSwGetTotalSize() );
- if( OnSwHasScrollBar(true) )
- {
- if( point.x < 0 )
- ptScroll.x += point.x;
- else if( point.x > rcClient.Width() )
- ptScroll.x += point.x - rcClient.Width();
- if( ptScroll.x < 0 )
- ptScroll.x = 0;
- else if( ptScroll.x > sizeTotal.cx )
- ptScroll.x = sizeTotal.cx;
- } // if( OnSwHasScrollBar(true) )
- if( OnSwHasScrollBar(false) )
- {
- if( point.y < 0 )
- ptScroll.y += point.y;
- else if( point.y > rcClient.Height() )
- ptScroll.y += point.y - rcClient.Height();
- if( ptScroll.y < 0 )
- ptScroll.y = 0;
- else if( ptScroll.y > sizeTotal.cy )
- ptScroll.y = sizeTotal.cy;
- } // if( OnSwHasScrollBar(false) )
- if( ptScrollOrg != ptScroll )
- OnSwSetScrollPos( ptScroll );
- }
- #if (!defined __EXT_MFC_NO_SCROLLITEMWND)
- /////////////////////////////////////////////////////////////////////////////
- // CExtScrollItemWnd window & CExtScrollItemCacheInfo helper
- CExtScrollItemCacheInfo::CExtScrollItemCacheInfo(
- LONG nPosH, // = 0L
- LONG nMaxH, // = 0L
- LONG nPageSizeH, // = 0L
- LONG nPosV, // = 0L
- LONG nMaxV, // = 0L
- LONG nPageSizeV, // = 0L
- bool bBeginH, // = false
- bool bEndH, // = false
- bool bBeginV, // = false
- bool bEndV // = false
- )
- : m_nPosH( nPosH )
- , m_nMaxH( nMaxH )
- , m_nPageSizeH( nPageSizeH )
- , m_nPosV( nPosV )
- , m_nMaxV( nMaxV )
- , m_nPageSizeV( nPageSizeV )
- , m_bBeginH( bBeginH )
- , m_bEndH( bEndH )
- , m_bBeginV( bBeginV )
- , m_bEndV( bEndV )
- {
- ASSERT( IsValid() );
- }
- CExtScrollItemCacheInfo::CExtScrollItemCacheInfo(
- const CExtScrollItemCacheInfo & other
- )
- {
- (*this) = other;
- ASSERT( IsValid() );
- }
- void CExtScrollItemCacheInfo::Assign(
- const CExtScrollItemCacheInfo & other,
- bool bAssignH, // = true
- bool bAssignV // = true
- )
- {
- if( bAssignH )
- {
- m_nPosH = other.m_nPosH;
- m_nMaxH = other.m_nMaxH;
- m_nPageSizeH = other.m_nPageSizeH;
- m_bBeginH = other.m_bBeginH;
- m_bEndH = other.m_bEndH;
- } // if( bAssignH )
- if( bAssignV )
- {
- m_nPosV = other.m_nPosV;
- m_nMaxV = other.m_nMaxV;
- m_nPageSizeV = other.m_nPageSizeV;
- m_bBeginV = other.m_bBeginV;
- m_bEndV = other.m_bEndV;
- } // if( bAssignV )
- ASSERT( IsValid() );
- }
- void CExtScrollItemCacheInfo::AssignH(
- const CExtScrollItemCacheInfo & other
- )
- {
- Assign( other, true, false );
- }
- void CExtScrollItemCacheInfo::AssignV(
- const CExtScrollItemCacheInfo & other
- )
- {
- Assign( other, false, true );
- }
- CExtScrollItemCacheInfo & CExtScrollItemCacheInfo::operator = (
- const CExtScrollItemCacheInfo & other
- )
- {
- Assign( other );
- return (*this);
- }
- bool CExtScrollItemCacheInfo::operator == (
- const CExtScrollItemCacheInfo & other
- ) const
- {
- return IsEqual( other );
- }
- bool CExtScrollItemCacheInfo::operator != (
- const CExtScrollItemCacheInfo & other
- ) const
- {
- return ( ! IsEqual( other ) );
- }
- void CExtScrollItemCacheInfo::Empty(
- bool bEmptyH, // = true
- bool bEmptyV // = true
- )
- {
- ASSERT( IsValid() );
- if( bEmptyH )
- {
- m_nPosH = 0L;
- m_nMaxH = 0L;
- m_nPageSizeH = 0L;
- m_bBeginH = false;
- m_bEndH = false;
- } // if( bEmptyH )
- if( bEmptyV )
- {
- m_nPosV = 0L;
- m_nMaxV = 0L;
- m_nPageSizeV = 0L;
- m_bBeginV = false;
- m_bEndV = false;
- } // if( bEmptyV )
- }
- void CExtScrollItemCacheInfo::EmptyH()
- {
- ASSERT( IsValid() );
- Empty( true, false );
- }
- void CExtScrollItemCacheInfo::EmptyV()
- {
- ASSERT( IsValid() );
- Empty( false, true );
- }
- bool CExtScrollItemCacheInfo::IsEmpty(
- bool bCheckEmptyH, // = true
- bool bCheckEmptyV // = true
- ) const
- {
- ASSERT( IsValid() );
- if( ( bCheckEmptyH
- && m_nMaxH != 0L
- )
- || ( bCheckEmptyV
- && m_nMaxV != 0L
- )
- )
- return false;
- return true;
- }
- bool CExtScrollItemCacheInfo::IsEmptyH() const
- {
- ASSERT( IsValid() );
- return IsEmpty( true, false );
- }
- bool CExtScrollItemCacheInfo::IsEmptyV() const
- {
- ASSERT( IsValid() );
- return IsEmpty( false, true );
- }
- bool CExtScrollItemCacheInfo::IsValid() const
- {
- if( m_nPosH >= 0L
- && m_nPosV >= 0L
- && m_nMaxH >= 0L
- && m_nMaxV >= 0L
- && m_nPageSizeH >= 0L
- && m_nPageSizeV >= 0L
- && 0L <= m_nPosH && m_nPosH <= m_nMaxH
- && 0L <= m_nPosV && m_nPosV <= m_nMaxV
- )
- return true;
- return false;
- }
- bool CExtScrollItemCacheInfo::IsEqual( // static
- const CExtScrollItemCacheInfo & left,
- const CExtScrollItemCacheInfo & right,
- bool bComparePosH, // = true
- bool bComparePosV, // = true
- bool bCompareMaxH, // = true
- bool bCompareMaxV, // = true
- bool bComparePageSizeH, // = true
- bool bComparePageSizeV, // = true
- bool bCompareBofH, // = false
- bool bCompareBofV, // = false
- bool bCompareEofH, // = false
- bool bCompareEofV // = false
- )
- {
- ASSERT( left.IsValid() );
- ASSERT( left.IsValid() );
- if( ( bComparePosH
- && left.m_nPosH != right.m_nPosH
- )
- || ( bComparePosV
- && left.m_nPosV != right.m_nPosV
- )
- || ( bCompareMaxH
- && left.m_nMaxH != right.m_nMaxH
- )
- || ( bCompareMaxV
- && left.m_nMaxV != right.m_nMaxV
- )
- || ( bComparePageSizeH
- && left.m_nPageSizeH != right.m_nPageSizeH
- )
- || ( bComparePageSizeV
- && left.m_nPageSizeV != right.m_nPageSizeV
- )
- || ( bCompareBofH
- && left.m_bBeginH != right.m_bBeginH
- )
- || ( bCompareBofV
- && left.m_bBeginV != right.m_bBeginV
- )
- || ( bCompareEofH
- && left.m_bEndH != right.m_bEndH
- )
- || ( bCompareEofV
- && left.m_bEndV != right.m_bEndV
- )
- )
- return false;
- return true;
- }
- bool CExtScrollItemCacheInfo::IsEqual(
- const CExtScrollItemCacheInfo & other,
- bool bComparePosH, // = true
- bool bComparePosV, // = true
- bool bCompareMaxH, // = true
- bool bCompareMaxV, // = true
- bool bComparePageSizeH, // = true
- bool bComparePageSizeV, // = true
- bool bCompareBofH, // = false
- bool bCompareBofV, // = false
- bool bCompareEofH, // = false
- bool bCompareEofV // = false
- ) const
- {
- return
- IsEqual(
- *this, other,
- bComparePosH, bComparePosV,
- bCompareMaxH, bCompareMaxV,
- bComparePageSizeH, bComparePageSizeV,
- bCompareBofH, bCompareBofV,
- bCompareEofH, bCompareEofV
- );
- }
- LONG CExtScrollItemCacheInfo::GetExtentH() const
- {
- ASSERT( IsValid() );
- return (m_nMaxH + m_nPageSizeH);
- }
- LONG CExtScrollItemCacheInfo::GetExtentV() const
- {
- ASSERT( IsValid() );
- return (m_nMaxV + m_nPageSizeV);
- }
- LONG CExtScrollItemCacheInfo::GetPosChangingH(
- const CExtScrollItemCacheInfo & _sciOld
- ) const
- {
- ASSERT( IsValid() );
- return (m_nPosH - _sciOld.m_nPosH);
- }
- LONG CExtScrollItemCacheInfo::GetPosChangingV(
- const CExtScrollItemCacheInfo & _sciOld
- ) const
- {
- ASSERT( IsValid() );
- return (m_nPosV - _sciOld.m_nPosV);
- }
- LONG CExtScrollItemCacheInfo::GetMaxChangingH(
- const CExtScrollItemCacheInfo & _sciOld
- ) const
- {
- ASSERT( IsValid() );
- return (m_nMaxH - _sciOld.m_nMaxH);
- }
- LONG CExtScrollItemCacheInfo::GetMaxChangingV(
- const CExtScrollItemCacheInfo & _sciOld
- ) const
- {
- ASSERT( IsValid() );
- return (m_nMaxV - _sciOld.m_nMaxV);
- }
- LONG CExtScrollItemCacheInfo::GetExtentChangingH(
- const CExtScrollItemCacheInfo & _sciOld
- ) const
- {
- ASSERT( IsValid() );
- LONG nExtentThis = GetExtentH();
- LONG nExtentOld = _sciOld.GetExtentH();
- return (nExtentThis - nExtentOld);
- }
- LONG CExtScrollItemCacheInfo::GetExtentChangingV(
- const CExtScrollItemCacheInfo & _sciOld
- ) const
- {
- ASSERT( IsValid() );
- LONG nExtentThis = GetExtentV();
- LONG nExtentOld = _sciOld.GetExtentV();
- return (nExtentThis - nExtentOld);
- }
- LONG CExtScrollItemCacheInfo::GetPageSizeChangingH(
- const CExtScrollItemCacheInfo & _sciOld
- ) const
- {
- ASSERT( IsValid() );
- return (m_nPageSizeH - _sciOld.m_nPageSizeH);
- }
- LONG CExtScrollItemCacheInfo::GetPageSizeChangingV(
- const CExtScrollItemCacheInfo & _sciOld
- ) const
- {
- ASSERT( IsValid() );
- return (m_nPageSizeV - _sciOld.m_nPageSizeV);
- }
- bool CExtScrollItemCacheInfo::IsShiftToBofH(
- const CExtScrollItemCacheInfo & _sciOld
- ) const
- {
- ASSERT( IsValid() );
- return (m_bBeginH&&(!_sciOld.m_bBeginH)) ? true : false;
- }
- bool CExtScrollItemCacheInfo::IsShiftToBofV(
- const CExtScrollItemCacheInfo & _sciOld
- ) const
- {
- ASSERT( IsValid() );
- return (m_bBeginV&&(!_sciOld.m_bBeginV)) ? true : false;
- }
- bool CExtScrollItemCacheInfo::IsShiftToEofH(
- const CExtScrollItemCacheInfo & _sciOld
- ) const
- {
- ASSERT( IsValid() );
- return (m_bEndH&&(!_sciOld.m_bEndH)) ? true : false;
- }
- bool CExtScrollItemCacheInfo::IsShiftToEofV(
- const CExtScrollItemCacheInfo & _sciOld
- ) const
- {
- ASSERT( IsValid() );
- return (m_bEndV&&(!_sciOld.m_bEndV)) ? true : false;
- }
- void CExtScrollItemCacheInfo::FlipHV()
- {
- ASSERT( IsValid() );
- LONG nTemp;
- bool bTemp;
-
- nTemp = m_nPosH;
- m_nPosH = m_nPosV;
- m_nPosV = nTemp;
- nTemp = m_nMaxH;
- m_nMaxH = m_nMaxV;
- m_nMaxV = nTemp;
- nTemp = m_nPageSizeH;
- m_nPageSizeH = m_nPageSizeV;
- m_nPageSizeV = nTemp;
- bTemp = m_bBeginH;
- m_bBeginH = m_bBeginV;
- m_bBeginV = bTemp;
- bTemp = m_bEndH;
- m_bEndH = m_bEndV;
- m_bEndV = bTemp;
-
- ASSERT( IsValid() );
- }
- IMPLEMENT_DYNCREATE( CExtScrollItemWnd, CExtScrollWnd );
- CExtScrollItemWnd::CExtScrollItemWnd()
- : m_bDirectCreateCall( false )
- , m_dwScrollItemWndStyle( 0L )
- , m_dwScrollItemWndStyleEx( 0L )
- , m_bExtractResourceStyles( true )
- {
- VERIFY( RegisterScrollItemWndClass() );
- }
- CExtScrollItemWnd::~CExtScrollItemWnd()
- {
- }
- BEGIN_MESSAGE_MAP(CExtScrollItemWnd,CExtScrollWnd)
- //{{AFX_MSG_MAP(CExtScrollItemWnd)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- bool CExtScrollItemWnd::g_bScrollItemWndClassRegistered = false;
- bool CExtScrollItemWnd::RegisterScrollItemWndClass()
- {
- if( g_bScrollItemWndClassRegistered )
- return true;
- WNDCLASS _wndClassInfo;
- HINSTANCE hInst = ::AfxGetInstanceHandle();
- if( ! ::GetClassInfo( hInst, __EXT_SCROLLITEMWND_CLASS_NAME, &_wndClassInfo ) )
- {
- _wndClassInfo.style = CS_GLOBALCLASS|CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW;
- _wndClassInfo.lpfnWndProc = ::DefWindowProc;
- _wndClassInfo.cbClsExtra = _wndClassInfo.cbWndExtra = 0;
- _wndClassInfo.hInstance = hInst;
- _wndClassInfo.hIcon = NULL;
- _wndClassInfo.hCursor = ::LoadCursor( NULL, IDC_ARROW );
- ASSERT( _wndClassInfo.hCursor != NULL );
- _wndClassInfo.hbrBackground = NULL;
- _wndClassInfo.lpszMenuName = NULL;
- _wndClassInfo.lpszClassName = __EXT_SCROLLITEMWND_CLASS_NAME;
- if( ! ::AfxRegisterClass( &_wndClassInfo ) )
- {
- ASSERT( FALSE );
- //AfxThrowResourceException();
- return false;
- }
- }
- g_bScrollItemWndClassRegistered = true;
- return true;
- }
- BOOL CExtScrollItemWnd::Create(
- CWnd * pParentWnd,
- const RECT & rcWnd, // = CRect( 0, 0, 0, 0 )
- UINT nDlgCtrlID, // = UINT( __EXT_MFC_IDC_STATIC )
- DWORD dwScrollItemWndStyle, // = 0L
- DWORD dwWindowStyle, // = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN
- CCreateContext * pContext // = NULL
- )
- {
- ASSERT_VALID( this );
- pContext;
- if( ! RegisterScrollItemWndClass() )
- {
- ASSERT( FALSE );
- return FALSE;
- }
- m_bDirectCreateCall = true;
- m_dwScrollItemWndStyle = dwScrollItemWndStyle;
- if( ! CWnd::CreateEx( 0L, __EXT_SCROLLITEMWND_CLASS_NAME, _T(""), dwWindowStyle, rcWnd, pParentWnd, nDlgCtrlID ) )
- {
- ASSERT( FALSE );
- return FALSE;
- }
- if( !_CreateHelper() )
- {
- ASSERT( FALSE );
- AfxThrowMemoryException();
- }
- return TRUE;
- }
- BOOL CExtScrollItemWnd::PreCreateWindow(CREATESTRUCT& cs)
- {
- ASSERT_VALID( this );
- if( ( !RegisterScrollItemWndClass() )
- || ( !CWnd::PreCreateWindow(cs) )
- )
- {
- ASSERT( FALSE );
- return FALSE;
- }
-
- cs.lpszClass = __EXT_SCROLLITEMWND_CLASS_NAME;
- cs.style |= WS_CLIPSIBLINGS|WS_CLIPCHILDREN;
- return TRUE;
- }
- bool CExtScrollItemWnd::_CreateHelper()
- {
- ASSERT_VALID( this );
- OnSwUpdateScrollBars();
- OnSwDoRedraw();
- return true;
- }
- void CExtScrollItemWnd::PreSubclassWindow()
- {
- ASSERT_VALID( this );
- CWnd::PreSubclassWindow();
- if( m_bDirectCreateCall )
- return;
- if( m_bExtractResourceStyles )
- {
- __EXT_MFC_LONG_PTR dwStyle = ::__EXT_MFC_GetWindowLong( m_hWnd, GWL_STYLE );
- m_dwScrollItemWndStyle = DWORD( dwStyle & __EXTMFC_ALL_FORM_MOVABLE_WND_STYLES );
- ::__EXT_MFC_SetWindowLong( m_hWnd, GWL_STYLE, dwStyle & (~__EXTMFC_ALL_FORM_MOVABLE_WND_STYLES) );
- } // if( m_bExtractResourceStyles )
-
- if( !_CreateHelper() )
- {
- ASSERT( FALSE );
- AfxThrowMemoryException();
- } // if( !Create() )
- }
- DWORD CExtScrollItemWnd::SiwGetStyle() const
- {
- ASSERT( this != NULL );
- return m_dwScrollItemWndStyle;
- }
- DWORD CExtScrollItemWnd::SiwModifyStyle(
- DWORD dwStyleAdd,
- DWORD dwStyleRemove, // = 0L
- bool bUpdateWnd // = true
- )
- {
- ASSERT( this != NULL );
- DWORD dwScrollItemWndStyleOld = SiwGetStyle();
- if( dwStyleAdd == 0 && dwStyleRemove == 0 )
- return dwScrollItemWndStyleOld;
- m_dwScrollItemWndStyle &= ~dwStyleRemove;
- m_dwScrollItemWndStyle |= dwStyleAdd;
- if( bUpdateWnd
- && GetSafeHwnd() != NULL
- && ::IsWindow( GetSafeHwnd() )
- )
- {
- OnSwUpdateScrollBars();
- OnSwDoRedraw();
- }
- return dwScrollItemWndStyleOld;
- }
- DWORD CExtScrollItemWnd::SiwGetStyleEx() const
- {
- ASSERT( this != NULL );
- return m_dwScrollItemWndStyleEx;
- }
- DWORD CExtScrollItemWnd::SiwModifyStyleEx(
- DWORD dwStyleExAdd,
- DWORD dwStyleExRemove, // = 0L
- bool bUpdateWnd // = true
- )
- {
- ASSERT( this != NULL );
- DWORD dwScrollItemWndStyleExOld = SiwGetStyle();
- if( dwStyleExAdd == 0 && dwStyleExRemove == 0 )
- return dwScrollItemWndStyleExOld;
- m_dwScrollItemWndStyleEx &= ~dwStyleExRemove;
- m_dwScrollItemWndStyleEx |= dwStyleExAdd;
- if( bUpdateWnd
- && GetSafeHwnd() != NULL
- && ::IsWindow( GetSafeHwnd() )
- )
- {
- OnSwUpdateScrollBars();
- OnSwDoRedraw();
- }
- return dwScrollItemWndStyleExOld;
- }
- DWORD CExtScrollItemWnd::SiwScrollTypeHGet() const
- {
- ASSERT( this != NULL );
- DWORD dwScrollItemWndStyle = SiwGetStyle();
- return (dwScrollItemWndStyle&__ESIS_STH_MASK);
- }
- DWORD CExtScrollItemWnd::SiwScrollTypeVGet() const
- {
- ASSERT( this != NULL );
- DWORD dwScrollItemWndStyle = SiwGetStyle();
- return ((dwScrollItemWndStyle&__ESIS_STV_MASK) >> __ESIW_ST_BIT_COUNT);
- }
- DWORD CExtScrollItemWnd::SiwScrollTypeHSet(
- DWORD dwScrollTypeNew,
- bool bUpdateWnd // = true
- )
- {
- ASSERT( this != NULL );
- dwScrollTypeNew &= __ESIW_ST_MASK;
- DWORD dwScrollTypeOld = SiwScrollTypeHGet();
- if( dwScrollTypeNew == dwScrollTypeOld )
- return dwScrollTypeOld;
- SiwModifyStyle(
- dwScrollTypeNew,
- __ESIS_STH_MASK,
- bUpdateWnd
- );
- return dwScrollTypeOld;
- }
- DWORD CExtScrollItemWnd::SiwScrollTypeVSet(
- DWORD dwScrollTypeNew,
- bool bUpdateWnd // = true
- )
- {
- ASSERT( this != NULL );
- dwScrollTypeNew &= __ESIW_ST_MASK;
- DWORD dwScrollTypeOld = SiwScrollTypeVGet();
- if( dwScrollTypeNew == dwScrollTypeOld )
- return dwScrollTypeOld;
- SiwModifyStyle(
- dwScrollTypeNew << __ESIW_ST_BIT_COUNT,
- __ESIS_STV_MASK,
- bUpdateWnd
- );
- return dwScrollTypeOld;
- }
- bool CExtScrollItemWnd::SiwPreferHorizontalWalkGet() const
- {
- ASSERT_VALID( this );
- bool bPreferHorizontalWalk =
- ( (SiwGetStyle() & __ESIS_PREFER_HORZ_WALK) != 0 )
- ? true : false;
- return bPreferHorizontalWalk;
- }
- bool CExtScrollItemWnd::SiwPreferHorizontalWalkSet(
- bool bPreferHorizontalWalk
- )
- {
- bool bPreferHorizontalWalkOld = SiwPreferHorizontalWalkGet();
- if( (bPreferHorizontalWalk && bPreferHorizontalWalkOld)
- || ((!bPreferHorizontalWalk) && (!bPreferHorizontalWalkOld))
- )
- return bPreferHorizontalWalkOld;
- SiwModifyStyle(
- ( (bPreferHorizontalWalk) ? __ESIS_PREFER_HORZ_WALK : 0 ),
- __ESIS_PREFER_HORZ_WALK,
- false
- );
- return bPreferHorizontalWalkOld;
- }
- CSize CExtScrollItemWnd::OnSwGetLineSize( int nDirection ) const
- {
- ASSERT_VALID( this );
- nDirection;
- static const CSize g_sizePixelScrollStep( 3, 3 );
- CSize _sizeLine( 0, 0 );
- DWORD dwScrollType = SiwScrollTypeHGet();
- if( dwScrollType == __ESIW_ST_PIXEL )
- _sizeLine.cx = g_sizePixelScrollStep.cx;
- else if( dwScrollType == __ESIW_ST_ITEM
- || dwScrollType == __ESIW_ST_VIRTUAL
- )
- _sizeLine.cx = 1;
- dwScrollType = SiwScrollTypeVGet();
- if( dwScrollType == __ESIW_ST_PIXEL )
- _sizeLine.cy = g_sizePixelScrollStep.cy;
- else if( dwScrollType == __ESIW_ST_ITEM
- || dwScrollType == __ESIW_ST_VIRTUAL
- )
- _sizeLine.cy = 1;
- return _sizeLine;
- }
- void CExtScrollItemWnd::OnSwUpdateScrollBars()
- {
- ASSERT_VALID( this );
- if( GetSafeHwnd() == NULL )
- return;
- if( m_nUpdateScrollBars > 1 )
- return;
- m_nUpdateScrollBars ++;
- ASSERT( OnSwGetTotalSize().cx >= 0 && OnSwGetTotalSize().cy >= 0 );
- CRect rcClient;
- bool bCalcClient = true;
- CWnd * pParentWnd = GetParent();
- if( pParentWnd != NULL
- && (BOOL)pParentWnd->SendMessage(
- WM_RECALCPARENT,
- 0,
- (LPARAM)(LPCRECT)&rcClient
- ) != 0
- )
- bCalcClient = false;
- CSize sizeClient;
- CSize sizeSb;
- if( bCalcClient )
- {
- if( !OnSwCalcClientSizes( sizeClient, sizeSb ) )
- { // no room for scroll bars
- CRect rcClient2 = OnSwGetClientRect();
- if( rcClient2.Width() > 0 && rcClient2.Height()> 0 )
- {
- OnSwEnableScrollBarCtrl( SB_BOTH, false );
- OnSwRecalcLayout( true );
- }
- m_nUpdateScrollBars --;
- return;
- }
- }
- else
- { // let parent window determine the "client" rect
- sizeSb = OnSwGetScrollBarSizes();
- sizeClient.cx = rcClient.right - rcClient.left;
- sizeClient.cy = rcClient.bottom - rcClient.top;
- }
- DWORD dwScrollTypeH = SiwScrollTypeHGet();
- DWORD dwScrollTypeV = SiwScrollTypeVGet();
- if( dwScrollTypeH == __ESIW_ST_ITEM || dwScrollTypeV == __ESIW_ST_ITEM )
- {
- CSize _sizeVR = OnSiwGetVisibleRange().Size();
- if( dwScrollTypeH == __ESIW_ST_ITEM )
- sizeClient.cx = _sizeVR.cx;
- if( dwScrollTypeV == __ESIW_ST_ITEM )
- sizeClient.cy = _sizeVR.cy;
- } // if( dwScrollTypeH == __ESIW_ST_ITEM || dwScrollTypeV == __ESIW_ST_ITEM )
- bool bHasSbH0 = OnSwHasScrollBar( true );
- bool bHasSbV0 = OnSwHasScrollBar( false );
- // if enough room to add scrollbars
- CSize sizeRange;
- CPoint ptMove;
- CSize sizeNeedSB;
- OnSwGetScrollBarState(
- sizeClient,
- sizeNeedSB,
- sizeRange,
- ptMove,
- bCalcClient
- );
- // if( bCalcClient )
- // {
- // if( sizeNeedSB.cx != 0
- // && dwScrollTypeV == __ESIW_ST_PIXEL
- // //&& bHasSbH0
- // )
- // sizeClient.cy -= sizeSb.cy;
- // if( sizeNeedSB.cy != 0
- // && dwScrollTypeH == __ESIW_ST_PIXEL
- // //&& bHasSbV0
- // )
- // sizeClient.cx -= sizeSb.cx;
- // } // if( bCalcClient )
- // scroll window + update
- CPoint ptCurrScrollPos = OnSwGetScrollPos();
- if( ptMove != ptCurrScrollPos )
- OnSwSetScrollPos( ptMove );
- // the scrollbar page range
- SCROLLINFO _scroll_info;
- ::memset( &_scroll_info, 0, sizeof(SCROLLINFO) );
- _scroll_info.cbSize = sizeof(SCROLLINFO);
- _scroll_info.fMask = SIF_PAGE|SIF_RANGE;
- _scroll_info.nMin = 0;
- //DWORD dwScrollTypeH = SiwScrollTypeHGet();
- //DWORD dwScrollTypeV = SiwScrollTypeVGet();
- CSize _sizeTotalISR = OnSwGetTotalSize();
- if( _sizeTotalISR.cx < 0 )
- _sizeTotalISR.cx = __EXT_SCROLL_NUMERIC_MAX;
- if( _sizeTotalISR.cy < 0 )
- _sizeTotalISR.cy = __EXT_SCROLL_NUMERIC_MAX;
- CSize _sizePageISR = OnSwGetPageSize( 0 );
- // update bars
- if( dwScrollTypeH == __ESIW_ST_NONE )
- OnSwEnableScrollBarCtrl( SB_HORZ, false );
- else if( dwScrollTypeH == __ESIW_ST_PIXEL )
- {
- OnSwEnableScrollBarCtrl( SB_HORZ, sizeNeedSB.cx ? true : false );
- if( sizeNeedSB.cx )
- {
- _scroll_info.nPage = sizeClient.cx;
- _scroll_info.nMax = OnSwGetTotalSize().cx - 1;
- if( bHasSbH0 && bHasSbV0 )
- _scroll_info.nMax += OnSwGetScrollBarSizes().cx;
- if( ! OnSwScrollInfoAdjust(
- SB_HORZ,
- _scroll_info,
- true
- )
- )
- OnSwSetScrollRange(
- SB_HORZ,
- 0,
- sizeRange.cx,
- true
- );
- } // if( sizeNeedSB.cx )
- } // else if( dwScrollTypeH == __ESIW_ST_PIXEL )
- else if( dwScrollTypeH == __ESIW_ST_ITEM )
- {
- if( _sizeTotalISR.cx > _sizePageISR.cx )
- {
- ASSERT( _sizePageISR.cx >= 0 );
- OnSwEnableScrollBarCtrl( SB_HORZ, true );
- _scroll_info.nPage = _sizePageISR.cx;
- _scroll_info.nMax = _sizeTotalISR.cx - 1;
- if( ! OnSwScrollInfoAdjust(
- SB_HORZ,
- _scroll_info,
- true
- )
- )
- OnSwSetScrollRange(
- SB_HORZ,
- 0,
- _sizeTotalISR.cx,
- true
- );
- }
- else
- OnSwEnableScrollBarCtrl( SB_HORZ, false );
- } // else if( dwScrollTypeH == __ESIW_ST_ITEM )
- else
- { // if __ESIW_ST_VIRTUAL
- ASSERT( dwScrollTypeH == __ESIW_ST_VIRTUAL );
- bool bBOF = OnSiwQueryVirtualBOF( true );
- bool bEOF = OnSiwQueryVirtualEOF( true );
- bool bEnableSB = true;
- if( bBOF )
- {
- if( bEOF )
- bEnableSB = false;
- else
- _scroll_info.nPos = 0;
- } // if( bBOF )
- else
- {
- if( bEOF )
- _scroll_info.nPos = __EXT_SCROLL_NUMERIC_MAX - 1;
- else
- _scroll_info.nPos = __EXT_SCROLL_NUMERIC_MAX / 2;
- } // else from if( bBOF )
- if( bEnableSB )
- {
- OnSwEnableScrollBarCtrl( SB_HORZ, true );
- _scroll_info.fMask = SIF_PAGE|SIF_RANGE|SIF_POS;
- _scroll_info.nPage = _sizePageISR.cx;
- _scroll_info.nMax = __EXT_SCROLL_NUMERIC_MAX;
- if( ! OnSwScrollInfoAdjust(
- SB_HORZ,
- _scroll_info,
- true
- )
- )
- OnSwSetScrollRange(
- SB_HORZ,
- 0,
- _sizeTotalISR.cx,
- true
- );
- } // if( bEnableSB )
- else
- OnSwEnableScrollBarCtrl( SB_HORZ, false );
- } // if __ESIW_ST_VIRTUAL
- // recalc for vertical parms
- _sizeTotalISR = OnSwGetTotalSize();
- if( _sizeTotalISR.cx < 0 )
- _sizeTotalISR.cx = __EXT_SCROLL_NUMERIC_MAX;
- if( _sizeTotalISR.cy < 0 )
- _sizeTotalISR.cy = __EXT_SCROLL_NUMERIC_MAX;
- _sizePageISR = OnSwGetPageSize( 0 );
- if( dwScrollTypeV == __ESIW_ST_NONE )
- OnSwEnableScrollBarCtrl( SB_VERT, false );
- else if( dwScrollTypeV == __ESIW_ST_PIXEL )
- {
- OnSwEnableScrollBarCtrl( SB_VERT, sizeNeedSB.cy ? true : false );
- if( sizeNeedSB.cy )
- {
- _scroll_info.nPage = sizeClient.cy;
- _scroll_info.nMax = OnSwGetTotalSize().cy - 1;
- if( bHasSbH0 && bHasSbV0 )
- _scroll_info.nMax += OnSwGetScrollBarSizes().cy;
- if( ! OnSwScrollInfoAdjust(
- SB_VERT,
- _scroll_info,
- true
- )
- )
- OnSwSetScrollRange(
- SB_VERT,
- 0,
- sizeRange.cy,
- true
- );
- } // if( sizeNeedSB.cy )
- } // else if( dwScrollTypeV == __ESIW_ST_PIXEL )
- else if( dwScrollTypeV == __ESIW_ST_ITEM )
- {
- if( _sizeTotalISR.cy > _sizePageISR.cy )
- {
- ASSERT( _sizePageISR.cy >= 0 );
- OnSwEnableScrollBarCtrl( SB_VERT, true );
- _scroll_info.nPage = _sizePageISR.cy;
- _scroll_info.nMax = _sizeTotalISR.cy - 1;
- if( ! OnSwScrollInfoAdjust(
- SB_VERT,
- _scroll_info,
- true
- )
- )
- OnSwSetScrollRange(
- SB_VERT,
- 0,
- _sizeTotalISR.cy,
- true
- );
- }
- else
- OnSwEnableScrollBarCtrl( SB_VERT, false );
- } // else if( dwScrollTypeV == __ESIW_ST_ITEM )
- else
- { // if __ESIW_ST_VIRTUAL
- ASSERT( dwScrollTypeV == __ESIW_ST_VIRTUAL );
- bool bBOF = OnSiwQueryVirtualBOF( false );
- bool bEOF = OnSiwQueryVirtualEOF( false );
- bool bEnableSB = true;
- if( bBOF )
- {
- if( bEOF )
- bEnableSB = false;
- else
- _scroll_info.nPos = 0;
- } // if( bBOF )
- else
- {
- if( bEOF )
- _scroll_info.nPos = __EXT_SCROLL_NUMERIC_MAX - 1;
- else
- _scroll_info.nPos = __EXT_SCROLL_NUMERIC_MAX / 2;
- } // else from if( bBOF )
- if( bEnableSB )
- {
- OnSwEnableScrollBarCtrl( SB_VERT, true );
- _scroll_info.fMask = SIF_PAGE|SIF_RANGE|SIF_POS;
- _scroll_info.nPage = _sizePageISR.cy;
- _scroll_info.nMax = __EXT_SCROLL_NUMERIC_MAX;
- if( ! OnSwScrollInfoAdjust(
- SB_VERT,
- _scroll_info,
- true
- )
- )
- OnSwSetScrollRange(
- SB_VERT,
- 0,
- _sizeTotalISR.cy,
- true
- );
- } // if( bEnableSB )
- else
- OnSwEnableScrollBarCtrl( SB_VERT, false );
- } // if __ESIW_ST_VIRTUAL
- // adjust virtual position and cache state
- // if( dwScrollTypeH == __ESIW_ST_VIRTUAL
- // || dwScrollTypeV == __ESIW_ST_VIRTUAL
- // )
- OnSwDoScrollBy( CSize(0,0), false );
- OnSwRecalcLayout( true );
- bool bHasSbH1 = OnSwHasScrollBar( true );
- bool bHasSbV1 = OnSwHasScrollBar( false );
- if( bHasSbH0 != bHasSbH1
- || bHasSbV0 != bHasSbV1
- // || dwScrollTypeH == __ESIW_ST_VIRTUAL
- // || dwScrollTypeV == __ESIW_ST_VIRTUAL
- )
- OnSwUpdateScrollBars();
- else
- {
- if( ( bHasSbH1 && GetScrollBarCtrl( SB_HORZ )->GetSafeHwnd() == NULL )
- || ( bHasSbV1 && GetScrollBarCtrl( SB_VERT )->GetSafeHwnd() == NULL )
- )
- SendMessage( WM_NCPAINT );
- }
- m_nUpdateScrollBars --;
- }
- bool CExtScrollItemWnd::SiwAutohideScrollBarGet( bool bHorz ) const
- {
- ASSERT_VALID( this );
- if( bHorz )
- {
- if( ( SiwGetStyle() & __ESIS_DISABLE_AUTOHIDE_SB_H ) != 0 )
- return false;
- } // if( bHorz )
- else
- {
- if( ( SiwGetStyle() & __ESIS_DISABLE_AUTOHIDE_SB_V ) != 0 )
- return false;
- } // else from if( bHorz )
- return true;
- }
- bool CExtScrollItemWnd::SiwAutohideScrollBarSet(
- bool bHorz,
- bool bAutoHide // = true
- )
- {
- ASSERT_VALID( this );
- bool bAutohideScrollBarOld = SiwThumbTrackEnabledGet( bHorz );
- if( (bAutohideScrollBarOld && bAutoHide)
- || ((!bAutohideScrollBarOld) && (!bAutoHide))
- )
- return bAutohideScrollBarOld;
- DWORD dwRemove = bHorz ? __ESIS_DISABLE_AUTOHIDE_SB_H : __ESIS_DISABLE_AUTOHIDE_SB_V;
- DWORD dwAdd = bAutoHide ? 0L : dwRemove;
- SiwModifyStyle( dwAdd, dwRemove, false );
- return bAutohideScrollBarOld;
- }
- bool CExtScrollItemWnd::SiwThumbTrackEnabledGet( bool bHorz ) const
- {
- ASSERT_VALID( this );
- if( bHorz )
- {
- if( ( SiwGetStyle() & __ESIS_DISABLE_THUMBTRACK_H ) != 0 )
- return false;
- } // if( bHorz )
- else
- {
- if( ( SiwGetStyle() & __ESIS_DISABLE_THUMBTRACK_V ) != 0 )
- return false;
- } // else from if( bHorz )
- return true;
- }
- bool CExtScrollItemWnd::SiwThumbTrackEnabledSet(
- bool bHorz,
- bool bEnabled // = true
- )
- {
- ASSERT_VALID( this );
- bool bThumbTrackEnabledOld = SiwThumbTrackEnabledGet( bHorz );
- if( (bThumbTrackEnabledOld && bEnabled)
- || ((!bThumbTrackEnabledOld) && (!bEnabled))
- )
- return bThumbTrackEnabledOld;
- DWORD dwRemove = bHorz ? __ESIS_DISABLE_THUMBTRACK_H : __ESIS_DISABLE_THUMBTRACK_V;
- DWORD dwAdd = bEnabled ? 0L : dwRemove;
- SiwModifyStyle( dwAdd, dwRemove, false );
- return bThumbTrackEnabledOld;
- }
- bool CExtScrollItemWnd::OnSwQueryThumbTrackEnabled( bool bHorz ) const
- {
- ASSERT_VALID( this );
- if( ! SiwThumbTrackEnabledGet( bHorz ) )
- return false;
- DWORD dwScrollType = bHorz
- ? SiwScrollTypeHGet()
- : SiwScrollTypeVGet()
- ;
- if( dwScrollType == __ESIW_ST_VIRTUAL )
- {
- CScrollBar * pScrollBar =
- GetScrollBarCtrl(
- bHorz
- ? SB_HORZ
- : SB_VERT
- );
- if( pScrollBar->GetSafeHwnd() != NULL )
- {
- CExtScrollBar * pExtScrollBar =
- DYNAMIC_DOWNCAST(
- CExtScrollBar,
- pScrollBar
- );
- if( pExtScrollBar != NULL
- && pExtScrollBar->m_bCompleteRepaint
- )
- return true;
- } // if( pScrollBar->GetSafeHwnd() != NULL )
- return false;
- } // if( dwScrollType == __ESIW_ST_VIRTUAL )
- return true;
- }
- CSize CExtScrollItemWnd::OnSwGetTotalSize() const
- {
- ASSERT_VALID( this );
- CSize _sizeTotalISR( 0, 0 );
- DWORD dwScrollTypeH = SiwScrollTypeHGet();
- DWORD dwScrollTypeV = SiwScrollTypeVGet();
- if( dwScrollTypeH == __ESIW_ST_VIRTUAL )
- _sizeTotalISR.cx = __EXT_SCROLL_NUMERIC_MAX;
- if( dwScrollTypeV == __ESIW_ST_VIRTUAL )
- _sizeTotalISR.cy = __EXT_SCROLL_NUMERIC_MAX;
- return _sizeTotalISR;
- }
- CSize CExtScrollItemWnd::OnSwGetPageSize( int nDirection ) const
- {
- ASSERT_VALID( this );
- CRect rcClient = OnSwGetClientRect();
- if( rcClient.right < rcClient.left )
- rcClient.right = rcClient.left;
- if( rcClient.bottom < rcClient.top )
- rcClient.bottom = rcClient.top;
- CSize _sizeClient = rcClient.Size();
- CSize _sizePage = OnSiwCalcPageMetrics( nDirection );
- DWORD dwScrollTypeH = SiwScrollTypeHGet();
- DWORD dwScrollTypeV = SiwScrollTypeVGet();
- if( dwScrollTypeH == __ESIW_ST_NONE )
- _sizePage.cx = 0;
- else if( dwScrollTypeH == __ESIW_ST_PIXEL )
- _sizePage.cx = _sizeClient.cx;
- else if( dwScrollTypeH == __ESIW_ST_ITEM )
- {
- } // else if( dwScrollTypeH == __ESIW_ST_ITEM )
- else
- { // if __ESIW_ST_VIRTUAL
- ASSERT( dwScrollTypeH == __ESIW_ST_VIRTUAL );
- } // if __ESIW_ST_VIRTUAL
-
- if( dwScrollTypeV == __ESIW_ST_NONE )
- _sizePage.cy = 0;
- else if( dwScrollTypeV == __ESIW_ST_PIXEL )
- _sizePage.cy = _sizeClient.cy;
- else if( dwScrollTypeV == __ESIW_ST_ITEM )
- {
- } // else if( dwScrollTypeV == __ESIW_ST_ITEM )
- else
- { // if __ESIW_ST_VIRTUAL
- ASSERT( dwScrollTypeV == __ESIW_ST_VIRTUAL );
- } // if __ESIW_ST_VIRTUAL
- return _sizePage;
- }
- CSize CExtScrollItemWnd::OnSiwCalcItemSize() const
- {
- ASSERT_VALID( this );
- return CSize( 0, 0 );
- }
- CSize CExtScrollItemWnd::OnSiwCalcPageMetrics( int nDirection ) const
- {
- ASSERT_VALID( this );
- nDirection;
- CSize _sizeItem = OnSiwCalcItemSize();
- ASSERT( _sizeItem.cx >= 0 && _sizeItem.cy >= 0 );
- CRect rcClient = OnSwGetClientRect();
- CSize _sizeClient = rcClient.Size();
- if( _sizeClient.cx < 0 )
- _sizeClient.cx = 0;
- if( _sizeClient.cy < 0 )
- _sizeClient.cy = 0;
- CSize _sizePageMetrics(
- ( _sizeItem.cx == 0 ) ? 0 : ( _sizeClient.cx / _sizeItem.cx ),
- ( _sizeItem.cy == 0 ) ? 0 : ( _sizeClient.cy / _sizeItem.cy )
- );
- if( _sizeItem.cx != 0 )
- {
- if( _sizePageMetrics.cx == 0 )
- _sizePageMetrics.cx = 1;
- }
- else
- _sizePageMetrics.cx = 0;
- if( _sizeItem.cy != 0 )
- {
- if( _sizePageMetrics.cy == 0 )
- _sizePageMetrics.cy = 1;
- }
- else
- _sizePageMetrics.cy = 0;
- return _sizePageMetrics;
- }
- bool CExtScrollItemWnd::OnSiwQueryVirtualBOF( bool bHorz ) const
- {
- ASSERT_VALID( this );
- if( bHorz )
- {
- DWORD dwScrollTypeH = SiwScrollTypeHGet();
- if( dwScrollTypeH != __ESIW_ST_VIRTUAL )
- return true;
- } // if( bHorz )
- else
- {
- DWORD dwScrollTypeV = SiwScrollTypeVGet();
- if( dwScrollTypeV != __ESIW_ST_VIRTUAL )
- return true;
- } // else from if( bHorz )
- return false;
- }
- bool CExtScrollItemWnd::OnSiwQueryVirtualEOF( bool bHorz ) const
- {
- ASSERT_VALID( this );
- if( bHorz )
- {
- DWORD dwScrollTypeH = SiwScrollTypeHGet();
- if( dwScrollTypeH != __ESIW_ST_VIRTUAL )
- return true;
- } // if( bHorz )
- else
- {
- DWORD dwScrollTypeV = SiwScrollTypeVGet();
- if( dwScrollTypeV != __ESIW_ST_VIRTUAL )
- return true;
- } // else from if( bHorz )
- return false;
- }
- INT CExtScrollItemWnd::OnSiwQueryItemExtentH(
- LONG nColNo,
- INT * p_nExtraSpaceBefore, // = NULL
- INT * p_nExtraSpaceAfter // = NULL
- ) const
- {
- ASSERT_VALID( this );
- ASSERT( nColNo >= 0 );
- nColNo;
- if( p_nExtraSpaceBefore != NULL )
- (*p_nExtraSpaceBefore) = 0;
- if( p_nExtraSpaceAfter != NULL )
- (*p_nExtraSpaceAfter) = 0;
- return 0;
- }
- INT CExtScrollItemWnd::OnSiwQueryItemExtentV(
- LONG nRowNo,
- INT * p_nExtraSpaceBefore, // = NULL
- INT * p_nExtraSpaceAfter // = NULL
- ) const
- {
- ASSERT_VALID( this );
- ASSERT( nRowNo >= 0 );
- nRowNo;
- if( p_nExtraSpaceBefore != NULL )
- (*p_nExtraSpaceBefore) = 0;
- if( p_nExtraSpaceAfter != NULL )
- (*p_nExtraSpaceAfter) = 0;
- return 0;
- }
- bool CExtScrollItemWnd::OnSiwVirtualEndTestH( LONG nColNo, LPARAM lParam ) const
- {
- ASSERT_VALID( this );
- ASSERT( nColNo >= 0 );
- nColNo;
- lParam;
- return false;
- }
- bool CExtScrollItemWnd::OnSiwVirtualEndTestV( LONG nRowNo, LPARAM lParam ) const
- {
- ASSERT_VALID( this );
- ASSERT( nRowNo >= 0 );
- nRowNo;
- lParam;
- return false;
- }
- bool CExtScrollItemWnd::OnSiwWalkCell(
- CDC & dc,
- LPVOID pQueryData,
- LONG nVisibleColNo,
- LONG nVisibleRowNo,
- LONG nColNo,
- LONG nRowNo,
- const RECT & rcCellExtra,
- const RECT & rcCell,
- const RECT & rcVisibleRange,
- bool & bVirtualRightReached,
- bool & bVirtualBottomReached,
- DWORD dwAreaFlags,
- bool bFocusedControl
- ) const
- {
- ASSERT_VALID( this );
- ASSERT( dc.GetSafeHdc() != NULL || pQueryData != NULL );
- //ASSERT( nVisibleColNo >= 0 );
- //ASSERT( nVisibleRowNo >= 0 );
- ASSERT( nColNo >= 0 );
- ASSERT( nRowNo >= 0 );
- // ASSERT( rcCell.right >= rcCell.left );
- // ASSERT( rcCell.bottom >= rcCell.top );
- ASSERT( rcCellExtra.right >= rcCellExtra.left );
- ASSERT( rcCellExtra.bottom >= rcCellExtra.top );
- ASSERT( rcCellExtra.left <= rcCell.left );
- ASSERT( rcCellExtra.top <= rcCell.top );
- ASSERT( rcCellExtra.right >= rcCell.right );
- ASSERT( rcCellExtra.bottom >= rcCell.bottom );
- dc;
- pQueryData;
- nVisibleColNo;
- nVisibleRowNo;
- nColNo;
- nRowNo;
- rcCellExtra;
- rcCell;
- rcVisibleRange;
- bVirtualRightReached;
- bVirtualBottomReached;
- dwAreaFlags;
- bFocusedControl;
- // if( pQueryData != NULL )
- // return false; // no default hit-testing implementation
- // bVirtualRightReached = OnSiwVirtualEndTestH( nColNo, LPARAM(dwAreaFlags) );
- // if( bVirtualRightReached )
- // return false;
- // bVirtualBottomReached = OnSiwVirtualEndTestV( nRowNo, LPARAM(dwAreaFlags) );
- // if( bVirtualBottomReached )
- // return false;
- // if( rcCell.right == rcCell.left
- // || rcCell.bottom == rcCell.top
- // )
- // return false;
- // if( ! dc.RectVisible( &rcCell ) )
- // return false;
- //COLORREF clrLT = OnSiwGetSysColor( COLOR_3DHIGHLIGHT );
- //COLORREF clrRB = OnSiwGetSysColor( COLOR_3DSHADOW );
- //COLORREF clrFace = OnSiwGetSysColor( COLOR_3DFACE );
- // dc.FillSolidRect( &rcCell, clrFace );
- //CString sCellText;
- // sCellText.Format( _T("%08d-%08d"), nColNo, nRowNo );
- // dc.DrawText(
- // sCellText,
- // (LPRECT)&rcCell,
- // DT_SINGLELINE|DT_CENTER|DT_VCENTER
- // );
- // dc.Draw3dRect( &rcCell, clrLT, clrRB );
- return false;
- }
- bool CExtScrollItemWnd::OnSiwWalkItemsH(
- CDC & dc,
- LPVOID pQueryData,
- const RECT & rcRowExtra,
- const RECT & rcRow,
- LONG nVisibleRowNo,
- LONG nRowNo,
- const RECT & rcVisibleRange,
- bool & bVirtualBottomReached,
- DWORD dwAreaFlags,
- bool bFocusedControl
- ) const
- {
- ASSERT_VALID( this );
- ASSERT( dc.GetSafeHdc() != NULL || pQueryData != NULL );
- //ASSERT( nVisibleRowNo >= 0 );
- ASSERT( nRowNo >= 0 );
- ASSERT( rcRow.right >= rcRow.left );
- ASSERT( rcRow.bottom >= rcRow.top );
- ASSERT( rcRowExtra.right >= rcRowExtra.left );
- ASSERT( rcRowExtra.bottom >= rcRowExtra.top );
- ASSERT( rcRowExtra.left <= rcRow.left );
- ASSERT( rcRowExtra.top <= rcRow.top );
- ASSERT( rcRowExtra.right >= rcRow.right );
- ASSERT( rcRowExtra.bottom >= rcRow.bottom );
- bVirtualBottomReached = OnSiwVirtualEndTestV( nRowNo, LPARAM(dwAreaFlags) );
- if( bVirtualBottomReached )
- return false;
- if( rcRowExtra.right == rcRowExtra.left
- || rcRowExtra.bottom == rcRowExtra.top
- )
- return false;
- if( dc.GetSafeHdc() == NULL )
- return false; // no hit-test like query support
- if( ! dc.RectVisible( &rcRow ) )
- return false;
- CRect rcClient = OnSwGetClientRect();
- LONG nVisibleColNo = 0;
- LONG nColNo = rcVisibleRange.left;
- bool bVirtualRightReached = false;
- CRect rcCellExtra(
- rcClient.left,
- rcRowExtra.top,
- rcClient.left,
- rcRowExtra.bottom
- );
- for( ; nColNo <= rcVisibleRange.right; nColNo++, nVisibleColNo++ )
- {
- INT nExtraSpaceBefore = 0, nExtraSpaceAfter = 0;
- INT nColWidth =
- OnSiwQueryItemExtentH(
- nColNo,
- &nExtraSpaceBefore,
- &nExtraSpaceAfter
- );
- ASSERT( nColWidth >= 0 );
- ASSERT( nExtraSpaceBefore >= 0 );
- ASSERT( nExtraSpaceAfter >= 0 );
- rcCellExtra.right += nColWidth;
- if( rcCellExtra.right < rcClient.left
- || rcCellExtra.left > rcClient.right
- )
- continue;
- CRect rcCell(
- rcCellExtra.left + nExtraSpaceBefore,
- rcRow.top,
- rcCellExtra.right - nExtraSpaceAfter,
- rcRow.bottom
- );
- OnSiwWalkCell(
- dc,
- pQueryData,
- nVisibleColNo,
- nVisibleRowNo,
- nColNo,
- nRowNo,
- rcCellExtra,
- rcCell,
- rcVisibleRange,
- bVirtualRightReached,
- bVirtualBottomReached,
- dwAreaFlags,
- bFocusedControl
- );
- if( bVirtualRightReached || bVirtualBottomReached )
- break;
- rcCellExtra.left = rcCellExtra.right;
- } // for( ; nColNo <= rcVisibleRange.right; nColNo++, nVisibleColNo++ )
- return false;
- }
- bool CExtScrollItemWnd::OnSiwWalkItemsV(
- CDC & dc,
- LPVOID pQueryData,
- const RECT & rcColExtra,
- const RECT & rcCol,
- LONG nVisibleColNo,
- LONG nColNo,
- const RECT & rcVisibleRange,
- bool & bVirtualRightReached,
- DWORD dwAreaFlags,
- bool bFocusedControl
- ) const
- {
- ASSERT_VALID( this );
- ASSERT( dc.GetSafeHdc() != NULL || pQueryData != NULL );
- //ASSERT( nVisibleColNo >= 0 );
- ASSERT( nColNo >= 0 );
- ASSERT( rcCol.right >= rcCol.left );
- ASSERT( rcCol.bottom >= rcCol.top );
- ASSERT( rcColExtra.right >= rcColExtra.left );
- ASSERT( rcColExtra.bottom >= rcColExtra.top );
- ASSERT( rcColExtra.left <= rcCol.left );
- ASSERT( rcColExtra.top <= rcCol.top );
- ASSERT( rcColExtra.right >= rcCol.right );
- ASSERT( rcColExtra.bottom >= rcCol.bottom );
- bVirtualRightReached = OnSiwVirtualEndTestH( nColNo, LPARAM(dwAreaFlags) );
- if( bVirtualRightReached )
- return false;
- if( rcColExtra.right == rcColExtra.left
- || rcColExtra.bottom == rcColExtra.top
- )
- return false;
- if( dc.GetSafeHdc() == NULL )
- return false; // no hit-test like query support
- if( ! dc.RectVisible( &rcCol ) )
- return false;
- CRect rcClient = OnSwGetClientRect();
- LONG nVisibleRowNo = 0;
- LONG nRowNo = rcVisibleRange.top;
- bool bVirtualBottomReached = false;
- CRect rcCellExtra(
- rcColExtra.left,
- rcClient.top,
- rcColExtra.right,
- rcClient.top
- );
- for( ; nRowNo <= rcVisibleRange.bottom; nRowNo++, nVisibleRowNo++ )
- {
- INT nExtraSpaceBefore = 0, nExtraSpaceAfter = 0;
- INT nRowHeight =
- OnSiwQueryItemExtentV(
- nRowNo,
- &nExtraSpaceBefore,
- &nExtraSpaceAfter
- );
- ASSERT( nRowHeight >= 0 );
- ASSERT( nExtraSpaceBefore >= 0 );
- ASSERT( nExtraSpaceAfter >= 0 );
- rcCellExtra.bottom += nRowHeight;
- if( rcCellExtra.right < rcClient.left
- || rcCellExtra.left > rcClient.right
- )
- continue;
- CRect rcCell(
- rcCol.left,
- rcCellExtra.top + nExtraSpaceBefore,
- rcCol.right,
- rcCellExtra.bottom - nExtraSpaceAfter
- );
- OnSiwWalkCell(
- dc,
- pQueryData,
- nVisibleColNo,
- nVisibleRowNo,
- nColNo,
- nRowNo,
- rcCellExtra,
- rcCell,
- rcVisibleRange,
- bVirtualRightReached,
- bVirtualBottomReached,
- dwAreaFlags,
- bFocusedControl
- );
- if( bVirtualRightReached || bVirtualBottomReached )
- break;
- rcCellExtra.top = rcCellExtra.bottom;
- } // for( ; nRowNo <= rcVisibleRange.bottom; nRowNo++, nVisibleRowNo++ )
- return false;
- }
- bool CExtScrollItemWnd::OnSiwQueryFocusedControlState() const
- {
- ASSERT_VALID( this );
- if( m_hWnd == NULL || (! ::IsWindow(m_hWnd) ) )
- return false;
- HWND hWndFocus = ::GetFocus();
- if( m_hWnd == hWndFocus
- || ::IsChild( m_hWnd, hWndFocus )
- )
- return true;
- return false;
- }
- void CExtScrollItemWnd::OnSiwDrawFocusRect(
- CDC &dc,
- LPCRECT pRect,
- CObject * pObjSrc, // = NULL
- LPARAM lParam // = 0L
- ) const
- {
- ASSERT_VALID( this );
- ASSERT_VALID( (&dc) );
- ASSERT( dc.GetSafeHdc() != NULL );
- #ifdef _DEBUG
- if( pObjSrc != NULL )
- {
- ASSERT_VALID( pObjSrc );
- }
- #endif // _DEBUG
- pObjSrc;
- lParam;
- COLORREF clrTextOld =
- dc.SetTextColor( RGB(255,255,255) );
- COLORREF clrBkOld =
- dc.SetBkColor( RGB(0,0,0) );
- dc.DrawFocusRect( pRect );
- dc.SetBkColor( clrBkOld );
- dc.SetTextColor( clrTextOld );
- }
- COLORREF CExtScrollItemWnd::OnSiwGetReadOnlyTextColor() const
- {
- ASSERT_VALID( this );
- // return OnSiwGetSysColor( COLOR_BTNTEXT );
- // return OnSiwGetSysColor( COLOR_3DSHADOW );
- return OnSiwGetSysColor( COLOR_3DSHADOW );
- }
- COLORREF CExtScrollItemWnd::OnSiwGetReadOnlyBackgroundColor() const
- {
- ASSERT_VALID( this );
- // return OnSiwGetSysColor( COLOR_WINDOW );
- // return OnSiwGetSysColor( COLOR_3DFACE );
- return OnSiwGetSysColor( COLOR_WINDOW );
- }
- COLORREF CExtScrollItemWnd::OnSiwGetSysColor( int nIndex ) const
- {
- ASSERT_VALID( this );
- DWORD dwSiwGetStyleEx = SiwGetStyleEx();
- bool bUsedPmColors =
- ( (dwSiwGetStyleEx&__EGWS_EX_PM_COLORS) != 0 )
- ? true : false;
- COLORREF clr = bUsedPmColors
- ? PmBridge_GetPM()->GetColor( nIndex, (CObject*)this )
- : ( ::GetSysColor( nIndex ) )
- ;
- return clr;
- }
- // nLighterOrDarker is related to COLOR_3DFACE brush:
- // -3 - darkest, -2 - darker, -1 - dark,
- // 1 - light, 2 - lighter, 3 - lightest
- CBrush & CExtScrollItemWnd::OnSiwGetLighterOrDarkerBrush( int nLighterOrDarker ) const
- {
- ASSERT_VALID( this );
- DWORD dwSiwGetStyleEx = SiwGetStyleEx();
- bool bUsedPmColors =
- ( (dwSiwGetStyleEx&__EGWS_EX_PM_COLORS) != 0 )
- ? true : false;
- switch( nLighterOrDarker )
- {
- case -3:
- return bUsedPmColors ? PmBridge_GetPM()->m_brushDarkestDefault : PmBridge_GetPM()->m_brushDarkestSystem;
- case -2:
- return bUsedPmColors ? PmBridge_GetPM()->m_brushDarkerDefault : PmBridge_GetPM()->m_brushDarkerSystem;
- case -1:
- return bUsedPmColors ? PmBridge_GetPM()->m_brushDarkDefault : PmBridge_GetPM()->m_brushDarkSystem;
- case 1:
- return bUsedPmColors ? PmBridge_GetPM()->m_brushLightDefault: PmBridge_GetPM()->m_brushLightSystem;
- case 2:
- return bUsedPmColors ? PmBridge_GetPM()->m_brushLighterDefault : PmBridge_GetPM()->m_brushLighterSystem;
- default:
- ASSERT( nLighterOrDarker == 3 );
- return bUsedPmColors ? PmBridge_GetPM()->m_brushLightestDefault : PmBridge_GetPM()->m_brushLightestSystem;
- } // switch( nLighterOrDarker )
- }
- CFont & CExtScrollItemWnd::OnSiwGetDefaultFont() const
- {
- ASSERT_VALID( this );
- CFont * pFont = NULL;
- if( GetSafeHwnd() != NULL )
- pFont = GetFont();
- return ( pFont->GetSafeHandle() != NULL ) ? (*pFont) : PmBridge_GetPM()->m_FontNormal;
- }
- void CExtScrollItemWnd::OnSwPaint( CDC & dc )
- {
- ASSERT_VALID( this );
- ASSERT( dc.GetSafeHdc() != NULL );
- bool bFocusedControl = OnSiwQueryFocusedControlState();
- OnSiwPaintBackground( dc, bFocusedControl );
- OnSiwPaintForeground( dc, bFocusedControl );
- }
- void CExtScrollItemWnd::OnSiwPaintBackground(
- CDC & dc,
- bool bFocusedControl
- ) const
- {
- ASSERT_VALID( this );
- ASSERT( dc.GetSafeHdc() != NULL );
- bFocusedControl;
- CRect rcRealClient;
- CWnd::GetClientRect( &rcRealClient );
- if( ! dc.RectVisible(&rcRealClient) )
- return;
- CRect rcClient = OnSwGetClientRect();
- if( rcClient != rcRealClient )
- {
- COLORREF clrEntire = OnSiwGetSysColor( COLOR_3DFACE );
- dc.FillSolidRect( &rcRealClient, clrEntire );
- } // if( rcClient != rcRealClient )
- if( dc.RectVisible(&rcClient) )
- {
- COLORREF clrWindow =
- OnSiwGetSysColor( IsWindowEnabled() ? COLOR_WINDOW : COLOR_3DFACE );
- dc.FillSolidRect( &rcClient, clrWindow );
- } // if( dc.RectVisible(&rcClient) )
- }
- void CExtScrollItemWnd::OnSiwPaintForeground(
- CDC & dc,
- bool bFocusedControl
- ) const
- {
- ASSERT_VALID( this );
- ASSERT( dc.GetSafeHdc() != NULL );
- CRect rcClient = OnSwGetClientRect();
- if( ! dc.RectVisible(&rcClient) )
- return;
- CRect rcVisibleRange = OnSiwGetVisibleRange();
- ASSERT( rcVisibleRange.left <= rcVisibleRange.right );
- ASSERT( rcVisibleRange.top <= rcVisibleRange.bottom );
- CSize _sizeItem = OnSiwCalcItemSize();
- ASSERT( _sizeItem.cx >= 0 && _sizeItem.cy >= 0 );
- if( !( rcVisibleRange.left <= rcVisibleRange.right
- && rcVisibleRange.top <= rcVisibleRange.bottom
- && _sizeItem.cx > 0
- && _sizeItem.cy > 0
- )
- )
- return;
- DWORD dwScrollTypeH = SiwScrollTypeHGet();
- DWORD dwScrollTypeV = SiwScrollTypeVGet();
- if( ( dwScrollTypeH == __ESIW_ST_NONE
- || dwScrollTypeH == __ESIW_ST_PIXEL
- )
- && ( dwScrollTypeV == __ESIW_ST_NONE
- || dwScrollTypeV == __ESIW_ST_PIXEL
- )
- )
- return;
- bool bPreferHorizontalWalk = SiwPreferHorizontalWalkGet();
- if( bPreferHorizontalWalk )
- {
- if( dwScrollTypeH == __ESIW_ST_NONE
- || dwScrollTypeH == __ESIW_ST_PIXEL
- )
- bPreferHorizontalWalk = false;
- } // if( bPreferHorizontalWalk )
- else
- {
- if( dwScrollTypeV == __ESIW_ST_NONE
- || dwScrollTypeV == __ESIW_ST_PIXEL
- )
- bPreferHorizontalWalk = true;
- } // else from if( bPreferHorizontalWalk )
- CRgn rgnClientClip;
- if( rgnClientClip.CreateRectRgnIndirect(&rcClient) )
- dc.SelectClipRgn( &rgnClientClip );
- COLORREF clrText = OnSiwGetSysColor( COLOR_BTNTEXT );
- int nOldBkMode = dc.SetBkMode( TRANSPARENT );
- COLORREF clrTextOld = dc.SetTextColor( clrText );
- CFont * pOldFont = dc.SelectObject( &( OnSiwGetDefaultFont() ) );
- if( bPreferHorizontalWalk )
- {
- LONG nColNo = rcVisibleRange.left;
- LONG nVisibleColNo = 0;
- bool bVirtualRightReached = false;
- CRect rcColExtra(
- rcClient.left,
- rcClient.top,
- rcClient.left,
- rcClient.bottom
- );
- for( ; nColNo <= rcVisibleRange.right; nColNo ++, nVisibleColNo++ )
- {
- INT nExtraSpaceBefore = 0, nExtraSpaceAfter = 0;
- INT nColWidth =
- OnSiwQueryItemExtentH(
- nColNo,
- &nExtraSpaceBefore,
- &nExtraSpaceAfter
- );
- ASSERT( nColWidth >= 0 );
- ASSERT( nExtraSpaceBefore >= 0 );
- ASSERT( nExtraSpaceAfter >= 0 );
- if( nColWidth == 0 )
- continue;
- rcColExtra.right += nColWidth;
- CRect rcCol( rcColExtra );
- rcCol.DeflateRect(
- nExtraSpaceBefore,
- 0,
- nExtraSpaceAfter,
- 0
- );
- ASSERT( rcCol.left <= rcCol.right );
- OnSiwWalkItemsV(
- dc,
- NULL,
- rcColExtra,
- rcCol,
- nVisibleColNo,
- nColNo,
- rcVisibleRange,
- bVirtualRightReached,
- 0L,
- bFocusedControl
- );
- if( bVirtualRightReached )
- break;
- rcColExtra.left = rcColExtra.right;
- }
- } // if( bPreferHorizontalWalk )
- else
- {
- LONG nRowNo = rcVisibleRange.top;
- LONG nVisibleRowNo = 0;
- bool bVirtualBottomReached = false;
- CRect rcRowExtra(
- rcClient.left,
- rcClient.top,
- rcClient.right,
- rcClient.top
- );
- for( ; nRowNo <= rcVisibleRange.bottom; nRowNo ++, nVisibleRowNo++ )
- {
- INT nExtraSpaceBefore = 0, nExtraSpaceAfter = 0;
- INT nRowHeight =
- OnSiwQueryItemExtentV(
- nRowNo,
- &nExtraSpaceBefore,
- &nExtraSpaceAfter
- );
- ASSERT( nRowHeight >= 0 );
- ASSERT( nExtraSpaceBefore >= 0 );
- ASSERT( nExtraSpaceAfter >= 0 );
- if( nRowHeight == 0 )
- continue;
- rcRowExtra.bottom += nRowHeight;
- CRect rcRow( rcRowExtra );
- rcRow.DeflateRect(
- 0,
- nExtraSpaceBefore,
- 0,
- nExtraSpaceAfter
- );
- ASSERT( rcRow.top <= rcRow.bottom );
- OnSiwWalkItemsH(
- dc,
- NULL,
- rcRowExtra,
- rcRow,
- nVisibleRowNo,
- nRowNo,
- rcVisibleRange,
- bVirtualBottomReached,
- 0L,
- bFocusedControl
- );
- if( bVirtualBottomReached )
- break;
- rcRowExtra.top = rcRowExtra.bottom;
- }
- } // else from if( bPreferHorizontalWalk )
- dc.SelectObject( pOldFont );
- dc.SetTextColor( clrTextOld );
- dc.SetBkMode( nOldBkMode );
- dc.SelectClipRgn( NULL );
- }
- bool CExtScrollItemWnd::OnSwDoScroll(
- UINT nScrollCode,
- UINT nPos,
- bool bDoScroll // = true
- )
- {
- ASSERT_VALID( this );
- DWORD dwScrollTypeH = SiwScrollTypeHGet();
- DWORD dwScrollTypeV = SiwScrollTypeVGet();
- LONG xPos, xOrgValue, yPos, yOrgValue;
- xOrgValue = xPos = ScrollPos32Get( SB_HORZ );
- switch( LOBYTE(nScrollCode) )
- {
- case SB_ENDSCROLL: break;
- case SB_TOP: xPos = 0; break;
- case SB_BOTTOM: xPos = __EXT_SCROLL_NUMERIC_MAX; break;
- case SB_LINEUP: xPos -= OnSwGetLineSize( -1 ).cx; break;
- case SB_LINEDOWN: xPos += OnSwGetLineSize( 1 ).cx; break;
- case SB_PAGEUP: xPos -= OnSwGetPageSize( -1 ).cx; break;
- case SB_PAGEDOWN:
- {
- LONG nPageSize = OnSwGetPageSize( 1 ).cx;
- if( dwScrollTypeH != __ESIW_ST_VIRTUAL )
- {
- CExtScrollBar * pExtSB = DYNAMIC_DOWNCAST( CExtScrollBar, GetScrollBarCtrl(SB_HORZ) );
- if( pExtSB->GetSafeHwnd() != NULL
- && ::GetCapture() == pExtSB->m_hWnd
- )
- xPos = ScrollPos32Get( SB_HORZ, true );
- xPos += nPageSize;
- }
- else
- {
- if( (__EXT_SCROLL_NUMERIC_MAX - nPageSize) < xPos )
- xPos = __EXT_SCROLL_NUMERIC_MAX;
- else
- xPos += nPageSize;
- } // else from if( dwScrollTypeH != __ESIW_ST_VIRTUAL )
- }
- break;
- case SB_THUMBTRACK:
- if( ! OnSwQueryThumbTrackEnabled(true) )
- return false;
- case SB_THUMBPOSITION:
- if( dwScrollTypeH != __ESIW_ST_VIRTUAL )
- {
- if( m_bUse32BitScrollInfo )
- nPos = ScrollPos32Get( SB_HORZ, true );
- xPos = nPos;
- } // if( dwScrollTypeH != __ESIW_ST_VIRTUAL )
- else
- {
- if( nPos <= 0 )
- xPos = 0;
- else
- xPos = __EXT_SCROLL_NUMERIC_MAX;
- } // else from if( dwScrollTypeH != __ESIW_ST_VIRTUAL )
- break;
- }
- yOrgValue = yPos = ScrollPos32Get( SB_VERT );
- switch( HIBYTE(nScrollCode) )
- {
- case SB_ENDSCROLL: break;
- case SB_TOP: yPos = 0; break;
- case SB_BOTTOM: yPos = __EXT_SCROLL_NUMERIC_MAX; break;
- case SB_LINEUP: yPos -= OnSwGetLineSize( -1 ).cy; break;
- case SB_LINEDOWN: yPos += OnSwGetLineSize( 1 ).cy; break;
- case SB_PAGEUP: yPos -= OnSwGetPageSize( -1 ).cy; break;
- case SB_PAGEDOWN:
- {
- LONG nPageSize = OnSwGetPageSize( 1 ).cy;
- if( dwScrollTypeV != __ESIW_ST_VIRTUAL )
- {
- CExtScrollBar * pExtSB = DYNAMIC_DOWNCAST( CExtScrollBar, GetScrollBarCtrl(SB_VERT) );
- if( pExtSB->GetSafeHwnd() != NULL
- && ::GetCapture() == pExtSB->m_hWnd
- )
- yPos = ScrollPos32Get( SB_VERT, true );
- yPos += nPageSize;
- }
- else
- {
- if( (__EXT_SCROLL_NUMERIC_MAX - nPageSize) < yPos )
- yPos = __EXT_SCROLL_NUMERIC_MAX;
- else
- yPos += nPageSize;
- } // else from if( dwScrollTypeV != __ESIW_ST_VIRTUAL )
- }
- break;
- case SB_THUMBTRACK:
- if( ! OnSwQueryThumbTrackEnabled(false) )
- return false;
- case SB_THUMBPOSITION:
- if( dwScrollTypeV != __ESIW_ST_VIRTUAL )
- {
- if( m_bUse32BitScrollInfo )
- nPos = ScrollPos32Get( SB_VERT, true );
- yPos = (int)nPos;
- } // if( dwScrollTypeV != __ESIW_ST_VIRTUAL )
- else
- {
- if( nPos <= 0 )
- yPos = 0;
- else
- yPos = __EXT_SCROLL_NUMERIC_MAX;
- } // else from if( dwScrollTypeV != __ESIW_ST_VIRTUAL )
- break;
- }
- bool bResult = OnSwDoScrollBy( CSize( xPos - xOrgValue, yPos - yOrgValue ), bDoScroll );
- if( bResult && bDoScroll && m_bScrollUpdateWindow )
- OnSwUpdateWindow();
- return bResult;
- }
- bool CExtScrollItemWnd::SiwFireCacheChanging(
- LONG nScrollPosNewX, // = -1L // if <0L - use current
- LONG nScrollPosNewY, // = -1L // if <0L - use current
- bool bUpdate // = true
- )
- {
- ASSERT_VALID( this );
- LONG xMaxValue = 0L, xPos = 0L, xPosOld = 0L,
- yMaxValue = 0L, yPos = 0L, yPosOld = 0L;
- if( bUpdate || OnSwHasScrollBar(true) )
- {
- xPos = ScrollPos32Get( SB_HORZ );
- xMaxValue = ScrollLimit32Get( SB_HORZ );
- if( nScrollPosNewX >= 0L )
- {
- xPosOld = xPos;
- xPos = nScrollPosNewX;
- } // if( nScrollPosNewX >= 0L )
- if( xPos < 0 )
- xPos = 0;
- else if( xPos > xMaxValue )
- xPos = xMaxValue;
- if( bUpdate && xPos != xPosOld )
- ScrollPos32Set( SB_HORZ, xPos, false );
- } // if( bUpdate || OnSwHasScrollBar(true) )
- if( bUpdate || OnSwHasScrollBar(false) )
- {
- yPos = ScrollPos32Get( SB_VERT );
- yMaxValue = ScrollLimit32Get( SB_VERT );
- if( nScrollPosNewY >= 0L )
- {
- yPosOld = yPos;
- yPos = nScrollPosNewY;
- } // if( nScrollPosNewY >= 0L )
- if( yPos < 0 )
- yPos = 0;
- else if( yPos > yMaxValue )
- yPos = yMaxValue;
- if( bUpdate && yPos != yPosOld )
- ScrollPos32Set( SB_VERT, yPos, false );
- } // if( bUpdate || OnSwHasScrollBar(false) )
- bool bBeginX = ( (xPos == 0) ? true : false ),
- bBeginY = ( (yPos == 0) ? true : false ),
- bEndX = ( (xPos == xMaxValue && xMaxValue > 0) ? true : false ),
- bEndY = ( (yPos == yMaxValue && yMaxValue > 0) ? true : false );
- CSize _sizePage = OnSwGetPageSize( 0 );
- if( _sizePage.cx < 0 )
- _sizePage.cx = 0;
- if( _sizePage.cy < 0 )
- _sizePage.cy = 0;
- m_sciLast.Empty();
- bool bRetVal =
- _NotifyCacheChanged(
- xPos, xPosOld, xMaxValue, _sizePage.cx,
- yPos, yPosOld, yMaxValue, _sizePage.cy,
- bBeginX, bEndX,
- bBeginY, bEndY
- );
- if( bUpdate )
- {
- OnSwUpdateScrollBars();
- OnSwDoRedraw();
- } // if( bUpdate )
- return bRetVal;
- }
- bool CExtScrollItemWnd::OnSwDoScrollBy(
- CSize sizeScroll,
- bool bDoScroll // = true
- )
- {
- ASSERT_VALID( this );
- LONG xMaxValue, xOrgValue, xPos, yMaxValue, yOrgValue, yPos;
- if( ! OnSwHasScrollBar(false) )
- sizeScroll.cy = 0;
- if( ! OnSwHasScrollBar(true) )
- sizeScroll.cx = 0;
- xOrgValue = xPos = ScrollPos32Get( SB_HORZ );
- xMaxValue = ScrollLimit32Get( SB_HORZ );
- xPos += sizeScroll.cx;
- if( xPos < 0 )
- xPos = 0;
- else if( xPos > xMaxValue )
- xPos = xMaxValue;
- yOrgValue = yPos = ScrollPos32Get( SB_VERT );
- yMaxValue = ScrollLimit32Get( SB_VERT );
- yPos += sizeScroll.cy;
- if( yPos < 0 )
- yPos = 0;
- else if( yPos > yMaxValue )
- yPos = yMaxValue;
-
- bool bBeginX = ( (xPos == 0) ? true : false ),
- bBeginY = ( (yPos == 0) ? true : false ),
- bEndX = ( (xPos == xMaxValue && xMaxValue > 0) ? true : false ),
- bEndY = ( (yPos == yMaxValue && yMaxValue > 0) ? true : false );
- CSize _sizePage = OnSwGetPageSize( 0 );
- bool bRetVal =
- _NotifyCacheChanged(
- xPos, xOrgValue, xMaxValue, _sizePage.cx,
- yPos, yOrgValue, yMaxValue, _sizePage.cy,
- bBeginX, bEndX,
- bBeginY, bEndY
- );
- if( !bRetVal )
- return false;
- if( xPos == xOrgValue
- && yPos == yOrgValue
- )
- return true; //false;
- if( bDoScroll )
- {
- CSize sizeItem = OnSiwCalcItemSize();
- int xAmount = xOrgValue - xPos;
- int yAmount = yOrgValue - yPos;
- xAmount *= sizeItem.cx;
- yAmount *= sizeItem.cy;
- OnSwDoScrollWindow( xAmount, yAmount );
- if( xPos != xOrgValue )
- ScrollPos32Set( SB_HORZ, xPos );
- if( yPos != yOrgValue )
- ScrollPos32Set( SB_VERT, yPos );
- } // if( bDoScroll )
- return true;
- }
- CPoint CExtScrollItemWnd::OnSwGetScrollPaintPos() const
- {
- ASSERT_VALID( this );
- return CPoint( 0, 0 );
- }
- CRect CExtScrollItemWnd::OnSiwGetFrozenRange() const
- {
- ASSERT_VALID( this );
- return CRect( 0, 0, 0, 0 );
- }
- CRect CExtScrollItemWnd::OnSiwGetVisibleRange() const
- {
- ASSERT_VALID( this );
- CRect rcFrozenRange = OnSiwGetFrozenRange();
- ASSERT(
- rcFrozenRange.top >= 0
- && rcFrozenRange.bottom >= 0
- && rcFrozenRange.left >= 0
- && rcFrozenRange.right >= 0
- );
- DWORD dwScrollTypeH = SiwScrollTypeHGet();
- DWORD dwScrollTypeV = SiwScrollTypeVGet();
- CSize _sizeTotal = OnSwGetTotalSize();
- CSize _sizePage = OnSiwCalcPageMetrics( 0 );
- CSize _sizeRange(
- (dwScrollTypeH == __ESIW_ST_NONE) ? _sizeTotal.cx : ( min( _sizeTotal.cx, _sizePage.cx ) ),
- (dwScrollTypeV == __ESIW_ST_NONE) ? _sizeTotal.cy : ( min( _sizeTotal.cy, _sizePage.cy ) )
- );
- CPoint ptMove = OnSwGetScrollPos();
- CRect rcVisibleRange( ptMove, _sizeRange );
- if( ((ULONG)rcVisibleRange.right) >= ((ULONG)_sizeTotal.cx)
- && dwScrollTypeH != __ESIW_ST_NONE
- && dwScrollTypeH != __ESIW_ST_VIRTUAL
- )
- rcVisibleRange.right = _sizeTotal.cx-1;
- if( ((ULONG)rcVisibleRange.right) < ((ULONG)rcVisibleRange.left) )
- rcVisibleRange.right = rcVisibleRange.left;
- if( ((ULONG)rcVisibleRange.bottom) >= ((ULONG)_sizeTotal.cy)
- && dwScrollTypeV != __ESIW_ST_NONE
- && dwScrollTypeV != __ESIW_ST_VIRTUAL
- )
- rcVisibleRange.bottom = _sizeTotal.cy-1;
- if( ((ULONG)rcVisibleRange.bottom) < ((ULONG)rcVisibleRange.top) )
- rcVisibleRange.bottom = rcVisibleRange.top;
- if( dwScrollTypeH == __ESIW_ST_VIRTUAL )
- rcVisibleRange.OffsetRect( -rcVisibleRange.left, 0 );
- if( dwScrollTypeV == __ESIW_ST_VIRTUAL )
- rcVisibleRange.OffsetRect( 0, -rcVisibleRange.top );
- rcVisibleRange.OffsetRect( rcFrozenRange.left, rcFrozenRange.top );
- return rcVisibleRange;
- }
- void CExtScrollItemWnd::OnSwGetScrollBarState(
- CSize sizeClient,
- CSize & sizeNeedSB,
- CSize & sizeRange,
- CPoint & ptMove,
- bool bInsideClient
- ) const
- {
- ASSERT_VALID( this );
- DWORD dwScrollTypeH = SiwScrollTypeHGet();
- DWORD dwScrollTypeV = SiwScrollTypeVGet();
- bool bHasSbH0 = OnSwHasScrollBar( true );
- bool bHasSbV0 = OnSwHasScrollBar( false );
- CSize sizeSb = OnSwGetScrollBarSizes();
- CSize sizeTotal = OnSwGetTotalSize();
- sizeRange = sizeTotal - sizeClient;
- ptMove = OnSwGetScrollPos();
- bool bNeedH = sizeRange.cx > 0;
- if( !bNeedH )
- ptMove.x = 0;
- else if(
- bInsideClient
- && dwScrollTypeV == __ESIW_ST_PIXEL
- && ( bHasSbH0 )
- )
- sizeRange.cy += sizeSb.cy;
- bool bNeedV = sizeRange.cy > 0;
- if( ! bNeedV )
- ptMove.y = 0;
- else if (
- bInsideClient
- && dwScrollTypeH == __ESIW_ST_PIXEL
- && ( bHasSbV0 )
- )
- sizeRange.cx += sizeSb.cx;
- if( bNeedV
- && (!bNeedH)
- && sizeRange.cx > 0
- )
- {
- ASSERT( bInsideClient );
- bNeedH = true;
- if( dwScrollTypeV == __ESIW_ST_PIXEL )
- {
- sizeRange.cy += sizeSb.cy;
- }
- } // if( bNeedV ...
- if( sizeRange.cx > 0 && ptMove.x >= sizeRange.cx )
- ptMove.x = sizeRange.cx;
- if( sizeRange.cy > 0 && ptMove.y >= sizeRange.cy )
- ptMove.y = sizeRange.cy;
- if( bNeedH || bNeedV )
- {
- CSize sizePage = OnSwGetPageSize( 0 );
- CSize sizePxClient( 0, 0 );
- if( dwScrollTypeH == __ESIW_ST_PIXEL || dwScrollTypeV == __ESIW_ST_PIXEL )
- {
- sizePxClient = OnSwGetClientRect().Size();
- }
- if( bNeedH )
- {
- if( dwScrollTypeH == __ESIW_ST_PIXEL )
- {
- if( OnSwHasScrollBar( true ) )
- sizePxClient.cx += sizeSb.cx;
- sizePage.cx = max( sizePage.cx, sizePxClient.cx );
- }
- if( sizeTotal.cx < sizePage.cx )
- {
- bNeedH = false;
- ptMove.x = 0;
- }
- }
- if( bNeedV )
- {
- if( dwScrollTypeV == __ESIW_ST_PIXEL )
- {
- if( OnSwHasScrollBar( false ) )
- sizePxClient.cy += sizeSb.cy;
- sizePage.cy = max( sizePage.cy, sizePxClient.cy );
- }
- if( sizeTotal.cy < sizePage.cy )
- {
- bNeedV = false;
- ptMove.y = 0;
- }
- }
- }
- sizeNeedSB.cx = bNeedH;
- sizeNeedSB.cy = bNeedV;
- CPoint ptMove_ISR = OnSwGetScrollPos();
- if( dwScrollTypeH == __ESIW_ST_ITEM
- || dwScrollTypeH == __ESIW_ST_VIRTUAL
- )
- ptMove.x = ptMove_ISR.x;
- else if( dwScrollTypeH == __ESIW_ST_NONE )
- sizeNeedSB.cx = 0;
-
- if( dwScrollTypeV == __ESIW_ST_ITEM
- || dwScrollTypeV == __ESIW_ST_VIRTUAL
- )
- ptMove.y = ptMove_ISR.y;
- else if( dwScrollTypeV == __ESIW_ST_NONE )
- sizeNeedSB.cy = 0;
- }
- bool CExtScrollItemWnd::OnSwCanAutoHideScrollBar( bool bHorz ) const
- {
- ASSERT_VALID( this );
- return SiwAutohideScrollBarGet( bHorz );
- }
- bool CExtScrollItemWnd::_NotifyCacheChanged(
- LONG nPosH,
- LONG nPosOldH,
- LONG nMaxH,
- LONG nPageSizeH,
- LONG nPosV,
- LONG nPosOldV,
- LONG nMaxV,
- LONG nPageSizeV,
- bool bBeginH,
- bool bEndH,
- bool bBeginV,
- bool bEndV
- )
- {
- ASSERT_VALID( this );
- nPosOldH;
- nPosOldV;
- ASSERT(
- nPosH >= 0L
- && nPosOldH >= 0L
- && nPosV >= 0L
- && nPosOldV >= 0L
- && nMaxH >= 0L
- && nMaxV >= 0L
- && nPageSizeH >= 0L
- && nPageSizeV >= 0L
- );
- ASSERT( 0L <= nPosH && nPosH <= nMaxH );
- ASSERT( 0L <= nPosOldH && nPosOldH <= nMaxH );
- ASSERT( 0L <= nPosV && nPosV <= nMaxV );
- ASSERT( 0L <= nPosOldV && nPosOldV <= nMaxV );
- //DWORD dwScrollTypeH = SiwScrollTypeHGet();
- DWORD dwScrollTypeV = SiwScrollTypeVGet();
- if( dwScrollTypeV != __ESIW_ST_NONE
- && dwScrollTypeV != __ESIW_ST_PIXEL
- && OnSwHasScrollBar( false )
- )
- {
- if( nPosV < nMaxV )
- {
- nPageSizeV++;
- }
- }
- CExtScrollItemCacheInfo _sciNew(
- nPosH,
- nMaxH,
- nPageSizeH,
- nPosV,
- nMaxV,
- nPageSizeV,
- bBeginH,
- bEndH,
- bBeginV,
- bEndV
- );
- ASSERT( _sciNew.IsValid() );
- if( m_sciLast == _sciNew )
- return true;
- if( ! OnSiwCacheChanged( _sciNew, m_sciLast ) )
- return false;
- m_sciLast = _sciNew;
- return true;
- }
- bool CExtScrollItemWnd::OnSiwCacheChanged(
- const CExtScrollItemCacheInfo & _sciNew,
- const CExtScrollItemCacheInfo & _sciOld
- )
- {
- ASSERT_VALID( this );
- ASSERT( _sciNew.IsValid() );
- ASSERT( _sciOld.IsValid() );
- _sciNew;
- _sciOld;
- ///////////////////////////////////////////////////////////////////////
- /// DEBUG BLOCK (BEGIN): verify cache notification is valid
- ///////////////////////////////////////////////////////////////////////
- #ifdef _DEBUG
- LONG nPosChangingH = _sciNew.m_nPosH - _sciOld.m_nPosH;
- LONG nPosChangingV = _sciNew.m_nPosV - _sciOld.m_nPosV;
- ASSERT( nPosChangingH == _sciNew.GetPosChangingH(_sciOld) );
- ASSERT( nPosChangingV == _sciNew.GetPosChangingV(_sciOld) );
- LONG nPageSizeChangingH = _sciNew.m_nPageSizeH - _sciOld.m_nPageSizeH;
- LONG nPageSizeChangingV = _sciNew.m_nPageSizeV - _sciOld.m_nPageSizeV;
- ASSERT( nPageSizeChangingH == _sciNew.GetPageSizeChangingH(_sciOld) );
- ASSERT( nPageSizeChangingV == _sciNew.GetPageSizeChangingV(_sciOld) );
- LONG nMaxChangingH = _sciNew.m_nMaxH - _sciOld.m_nMaxH;
- LONG nMaxChangingV = _sciNew.m_nMaxV - _sciOld.m_nMaxV;
- ASSERT( nMaxChangingH == _sciNew.GetMaxChangingH(_sciOld) );
- ASSERT( nMaxChangingV == _sciNew.GetMaxChangingV(_sciOld) );
- LONG nExtentH_New = _sciNew.m_nMaxH + _sciNew.m_nPageSizeH;
- LONG nExtentH_Old = _sciOld.m_nMaxH + _sciOld.m_nPageSizeH;
- LONG nExtentV_New = _sciNew.m_nMaxV + _sciNew.m_nPageSizeV;
- LONG nExtentV_Old = _sciOld.m_nMaxV + _sciOld.m_nPageSizeV;
- LONG nExtentChangingH = nExtentH_New - nExtentH_Old;
- LONG nExtentChangingV = nExtentV_New - nExtentV_Old;
- ASSERT( nExtentChangingH == _sciNew.GetExtentChangingH(_sciOld) );
- ASSERT( nExtentChangingV == _sciNew.GetExtentChangingV(_sciOld) );
- if( nPosChangingH == 0L
- && nPosChangingV == 0L
- && nPageSizeChangingH == 0L
- && nPageSizeChangingV == 0L
- && nMaxChangingH == 0L
- && nMaxChangingV == 0L
- && nExtentChangingH == 0L
- && nExtentChangingV == 0L
- )
- {
- ASSERT( FALSE );
- }
- //CString strTrace;
- // strTrace.Format(
- // _T(" --> CExtScrollItemWnd::OnSiwCacheChanged()n")
- // _T(" --> nPosNewH=%08ld nMaxH=%08ld PG=%08ld BEGIN=%s END=%sn")
- // _T(" --> nPosNewV=%08ld nMaxV=%08ld PG=%08ld BEGIN=%s END=%sn")
- // ,
- // _sciNew.m_nPosH, _sciNew.m_nMaxH, _sciNew.m_nPageSizeH,
- // _sciNew.m_bBeginH ? _T("yes") : _T("not"),
- // _sciNew.m_bEndH ? _T("yes") : _T("not"),
- // _sciNew.m_nPosV, _sciNew.m_nMaxV, _sciNew.m_nPageSizeV,
- // _sciNew.m_bBeginV ? _T("yes") : _T("not"),
- // _sciNew.m_bEndV ? _T("yes") : _T("not")
- // );
- // TRACE0( LPCTSTR(strTrace) );
- #endif // _DEBUG
- ///////////////////////////////////////////////////////////////////////
- /// DEBUG BLOCK (END): verify cache notification is valid
- ///////////////////////////////////////////////////////////////////////
- return true;
- }
- #endif // (!defined __EXT_MFC_NO_SCROLLITEMWND)
- #if (!defined __EXT_MFC_NO_SCROLLCONAINERWND)
- /////////////////////////////////////////////////////////////////////////////
- // CExtScrollContainerWnd
- IMPLEMENT_DYNCREATE( CExtScrollContainerWnd, CExtScrollWnd );
- CExtScrollContainerWnd::CExtScrollContainerWnd()
- : m_sizeToScroll( 0, 0 )
- , m_clrBkColor( COLORREF(-1L) )
- , m_bAutoDelete( false )
- , m_bRedirectPreTranslateMessage( false )
- , m_bRedirectOnCmdMsg( false )
- , m_bRedirectFocus( true )
- , m_bSynchronizeEnabledState( false )
- , m_nScrollRedrawFlags( RDW_INVALIDATE|RDW_UPDATENOW|RDW_ERASE|RDW_ERASENOW|RDW_ALLCHILDREN )
- {
- }
- CExtScrollContainerWnd::~CExtScrollContainerWnd()
- {
- }
- BEGIN_MESSAGE_MAP( CExtScrollContainerWnd, CExtScrollWnd )
- //{{AFX_MSG_MAP(CExtScrollContainerWnd)
- ON_WM_CREATE()
- ON_WM_SETFOCUS()
- ON_WM_ENABLE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- BOOL CExtScrollContainerWnd::PreCreateWindow(CREATESTRUCT& cs)
- {
- if( ! CExtScrollWnd::PreCreateWindow( cs ) )
- return FALSE;
- cs.dwExStyle &= ~(WS_EX_CLIENTEDGE|WS_EX_STATICEDGE);
- cs.dwExStyle |= WS_EX_CONTROLPARENT;
- cs.style &= ~(WS_BORDER);
- cs.style |= WS_CLIPSIBLINGS|WS_CLIPCHILDREN;
- cs.lpszClass = ::AfxRegisterWndClass( CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, ::LoadCursor( NULL, IDC_ARROW ), NULL, NULL );
- return TRUE;
- }
- CPoint CExtScrollContainerWnd::OnSwGetScrollPaintPos() const
- {
- ASSERT_VALID( this );
- return CPoint( 0, 0 );
- }
- void CExtScrollContainerWnd::OnSwPaint( CDC & dc )
- {
- ASSERT_VALID( this );
- if( m_clrBkColor != COLORREF(-1L) )
- {
- CRect rcClient;
- GetClientRect( &rcClient );
- dc.FillSolidRect(
- &rcClient,
- m_clrBkColor
- );
- return;
- }
- if( ! g_PaintManager->PaintDockerBkgnd(
- true,
- dc,
- this
- )
- )
- {
- CRect rcClient;
- GetClientRect( &rcClient );
- dc.FillSolidRect(
- &rcClient,
- g_PaintManager->GetColor( COLOR_BTNFACE, this )
- );
- }
- }
- void CExtScrollContainerWnd::OnSwPaintAreaBetweenScrollBarWindows(
- CDC & dc,
- const RECT & rcAreaBetweenScrollBarWindows
- )
- {
- ASSERT_VALID( this );
- dc.FillSolidRect(
- &rcAreaBetweenScrollBarWindows,
- g_PaintManager->GetColor( COLOR_BTNFACE, this )
- );
- }
- CSize CExtScrollContainerWnd::OnSwGetTotalSize() const
- {
- ASSERT_VALID( this );
- return m_sizeToScroll;
- }
- CSize CExtScrollContainerWnd::OnSwGetPageSize( int nDirection ) const
- {
- ASSERT_VALID( this );
- nDirection;
- return CSize( 100, 100 );
- }
- CSize CExtScrollContainerWnd::OnSwGetLineSize( int nDirection ) const
- {
- ASSERT_VALID( this );
- nDirection;
- return CSize( 1, 1 );
- }
- CScrollBar * CExtScrollContainerWnd::GetScrollBarCtrl(int nBar) const
- {
- ASSERT_VALID( this );
- if( m_hWnd == NULL || (! ::IsWindow(m_hWnd) ) )
- return NULL;
- ASSERT( nBar == SB_HORZ || nBar == SB_VERT );
- if( nBar == SB_HORZ )
- {
- if( m_wndScrollBarH.GetSafeHwnd() != NULL )
- return ( const_cast < CExtScrollBar * > ( &m_wndScrollBarH ) );
- } // if( nBar == SB_HORZ )
- else
- {
- if( m_wndScrollBarV.GetSafeHwnd() != NULL )
- return ( const_cast < CExtScrollBar * > ( &m_wndScrollBarV ) );
- } // else from if( nBar == SB_HORZ )
- return NULL;
- }
- void CExtScrollContainerWnd::PreSubclassWindow()
- {
- CExtScrollWnd::PreSubclassWindow();
- }
- void CExtScrollContainerWnd::PostNcDestroy()
- {
- CExtScrollWnd::PostNcDestroy();
- if( m_bAutoDelete )
- delete this;
- }
- void CExtScrollContainerWnd::OnSetFocus( CWnd * pOldWnd )
- {
- CExtScrollWnd::OnSetFocus( pOldWnd );
- if( ! m_bRedirectFocus )
- return;
- CWnd * pWndToScroll = OnGetWndToScroll();
- if( pWndToScroll == NULL )
- return;
- pWndToScroll->SetFocus();
- }
- void CExtScrollContainerWnd::OnEnable( BOOL bEnable )
- {
- CExtScrollWnd::OnEnable( bEnable );
- if( ! m_bSynchronizeEnabledState )
- return;
- CWnd * pWndToScroll = OnGetWndToScroll();
- if( pWndToScroll == NULL )
- return;
- pWndToScroll->EnableWindow( bEnable );
- }
- BOOL CExtScrollContainerWnd::PreTranslateMessage( MSG * pMsg )
- {
- if( m_bRedirectPreTranslateMessage )
- {
- CWnd * pWndToScroll = OnGetWndToScroll();
- if( pWndToScroll != NULL
- && pWndToScroll->PreTranslateMessage( pMsg )
- )
- return TRUE;
- }
- return CExtScrollWnd::PreTranslateMessage( pMsg );
- }
- BOOL CExtScrollContainerWnd::OnCmdMsg( UINT nID, int nCode, void * pExtra, AFX_CMDHANDLERINFO * pHandlerInfo )
- {
- if( m_bRedirectOnCmdMsg )
- {
- CWnd * pWndToScroll = OnGetWndToScroll();
- if( pWndToScroll != NULL
- && pWndToScroll->OnCmdMsg( nID, nCode, pExtra, pHandlerInfo )
- )
- return TRUE;
- }
- return CExtScrollWnd::OnCmdMsg( nID, nCode, pExtra, pHandlerInfo );
- }
- int CExtScrollContainerWnd::OnCreate( LPCREATESTRUCT lpCreateStruct )
- {
- if( CExtScrollWnd::OnCreate( lpCreateStruct ) == -1 )
- return -1;
-
- m_wndScrollBarH.m_eSO = CExtScrollBar::__ESO_BOTTOM;
- m_wndScrollBarV.m_eSO = CExtScrollBar::__ESO_RIGHT;
- if( ! m_wndScrollBarV.Create(
- WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|SBS_VERT|SBS_RIGHTALIGN,
- CRect(0,0,0,0),
- this,
- 1
- )
- )
- {
- ASSERT( FALSE );
- return -1;
- }
- if( ! m_wndScrollBarH.Create(
- WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|SBS_HORZ|SBS_BOTTOMALIGN,
- CRect(0,0,0,0),
- this,
- 2
- )
- )
- {
- ASSERT( FALSE );
- return -1;
- }
- m_wndScrollBarH.SyncReservedSpace( &m_wndScrollBarV );
- m_wndScrollBarV.SyncReservedSpace( &m_wndScrollBarH );
- if( ! m_wndCorner.Create(
- _T(""),
- WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS,
- CRect(0,0,0,0),
- this,
- 3
- )
- )
- {
- ASSERT( FALSE );
- return -1;
- }
- OnSwRecalcLayout( true );
-
- return 0;
- }
- CRect CExtScrollContainerWnd::OnSwRecalcLayout(
- bool bDoLayout,
- LPCRECT pRectClientSrc // = NULL
- )
- {
- ASSERT_VALID( this );
- CWnd * pWndToScroll = OnGetWndToScroll();
- if( m_sizeToScroll.cx == 0 && m_sizeToScroll.cy == 0 )
- {
- if( pWndToScroll != NULL )
- {
- ASSERT_VALID( pWndToScroll );
- CRect rcWnd;
- pWndToScroll->GetWindowRect( &rcWnd );
- m_sizeToScroll = rcWnd.Size();
- } // if( pWndToScroll != NULL )
- } // if( m_sizeToScroll.cx == 0 && m_sizeToScroll.cy == 0 )
- else
- {
- if( pWndToScroll == NULL )
- m_sizeToScroll.cx = m_sizeToScroll.cy = 0;
- } // else from if( m_sizeToScroll.cx == 0 && m_sizeToScroll.cy == 0 )
- CRect rc = CExtScrollWnd::OnSwRecalcLayout( bDoLayout, pRectClientSrc );
- if( ( ! bDoLayout)
- || m_sizeToScroll.cx == 0
- || m_sizeToScroll.cy == 0
- )
- return rc;
- ASSERT_VALID( pWndToScroll );
- CSize _sizeFree = rc.Size();
- CSize _sizeEffective(
- max( _sizeFree.cx, m_sizeToScroll.cx ),
- max( _sizeFree.cy, m_sizeToScroll.cy )
- );
- LONG lPosHorz = ScrollPos32Get( SB_HORZ );
- LONG lPosVert = ScrollPos32Get( SB_VERT );
- CSize sizeSB( 0, 0 );
- if( m_wndCorner.GetSafeHwnd() != NULL
- && m_wndScrollBarH.GetSafeHwnd() != NULL
- && m_wndScrollBarV.GetSafeHwnd() != NULL
- )
- {
- CRect rcCorner( 0, 0, 0, 0 ), rcSBH( 0, 0, 0, 0 ), rcSBV( 0, 0, 0, 0 );
- bool bVisibleH = ( ( m_wndScrollBarH.GetStyle() & WS_VISIBLE ) != 0 ) ? true : false;
- bool bVisibleV = ( ( m_wndScrollBarV.GetStyle() & WS_VISIBLE ) != 0 ) ? true : false;
- if( bVisibleH )
- {
- m_wndScrollBarH.GetWindowRect( &rcSBH );
- sizeSB.cy = rcSBH.Height();
- }
- if( bVisibleV )
- {
- m_wndScrollBarV.GetWindowRect( &rcSBV );
- sizeSB.cx = rcSBV.Width();
- }
- if( bVisibleH && bVisibleV )
- {
- rcCorner.SetRect( rcSBV.left, rcSBH.top, rcSBV.right, rcSBH.bottom );
- ScreenToClient( &rcCorner );
- }
- if( ! rcCorner.IsRectEmpty() )
- m_wndCorner.SetWindowPos(
- &wndTop,
- rcCorner.left, rcCorner.top, rcCorner.Width(), rcCorner.Height(),
- SWP_NOACTIVATE|SWP_SHOWWINDOW
- );
- else if( ( m_wndCorner.GetStyle() & WS_VISIBLE ) != 0 )
- m_wndCorner.ShowWindow( SW_HIDE );
- }
- if( m_bSynchronizeEnabledState )
- {
- BOOL bEnabledContainer = IsWindowEnabled();
- BOOL bEnabledWndToScroll = pWndToScroll->IsWindowEnabled();
- if( ( bEnabledContainer && (!bEnabledWndToScroll) )
- || ( (!bEnabledContainer) && bEnabledWndToScroll )
- )
- pWndToScroll->EnableWindow( bEnabledContainer );
- }
- COLORREF clrCornerBk = m_wndCorner.GetBkColor();
- if( m_clrBkColor != clrCornerBk )
- m_wndCorner.SetBkColor( m_clrBkColor );
- if( bDoLayout )
- {
- if( _sizeFree.cx >= m_sizeToScroll.cx )
- {
- _sizeFree.cx -= sizeSB.cx;
- _sizeEffective.cx = max( _sizeFree.cx, m_sizeToScroll.cx );
- }
- if( _sizeFree.cy >= m_sizeToScroll.cy )
- {
- _sizeFree.cy -= sizeSB.cy;
- _sizeEffective.cy = max( _sizeFree.cy, m_sizeToScroll.cy );
- }
- //pWndToScroll->MoveWindow( -lPosHorz, -lPosVert, _sizeEffective.cx, _sizeEffective.cy );
- pWndToScroll->SetWindowPos( &CWnd::wndBottom, -lPosHorz, -lPosVert, _sizeEffective.cx, _sizeEffective.cy, SWP_SHOWWINDOW );
- OnSwUpdateScrollBars();
- }
- return rc;
- }
- bool CExtScrollContainerWnd::OnSwDoScrollBy(
- CSize sizeScroll,
- bool bDoScroll // = true
- )
- {
- ASSERT_VALID( this );
- CExtScrollWnd::OnSwDoScrollBy(sizeScroll,bDoScroll);
- if( m_sizeToScroll.cx == 0
- || m_sizeToScroll.cy == 0
- )
- return true;
- CWnd * pWndToScroll = OnGetWndToScroll();
- ASSERT_VALID( pWndToScroll );
- CRect rc = OnSwGetClientRect();
- CSize _sizeFree = rc.Size();
- CSize _sizeEffective(
- max( _sizeFree.cx, m_sizeToScroll.cx ),
- max( _sizeFree.cy, m_sizeToScroll.cy )
- );
- LONG lPosHorz = ScrollPos32Get( SB_HORZ );
- LONG lPosVert = ScrollPos32Get( SB_VERT );
- //pWndToScroll->MoveWindow( -lPosHorz, -lPosVert, _sizeEffective.cx, _sizeEffective.cy );
- pWndToScroll->SetWindowPos( &CWnd::wndBottom, -lPosHorz, -lPosVert, _sizeEffective.cx, _sizeEffective.cy, SWP_SHOWWINDOW );
- if( m_nScrollRedrawFlags != 0 )
- RedrawWindow( NULL, NULL, m_nScrollRedrawFlags );
- return true;
- }
- bool CExtScrollContainerWnd::Create(
- CWnd * pWndParent,
- const RECT & rc,
- UINT nDlgCtrlID // = AFX_IDW_PANE_FIRST
- )
- {
- ASSERT_VALID( this );
- if( GetSafeHwnd() != NULL )
- {
- ASSERT( FALSE );
- return false;
- }
- if( ! CWnd::Create(
- NULL, NULL, WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN,
- rc, pWndParent, nDlgCtrlID )
- )
- {
- ASSERT( FALSE );
- return false;
- }
- return true;
- }
- CWnd * CExtScrollContainerWnd::OnGetWndToScroll()
- {
- ASSERT_VALID( this );
- CWnd * pWndToScroll = GetWindow( GW_CHILD );
- for( ; pWndToScroll != NULL; pWndToScroll = pWndToScroll->GetWindow( GW_HWNDNEXT ) )
- {
- if( pWndToScroll->IsKindOf( RUNTIME_CLASS( CExtScrollBar ) )
- || LPVOID(pWndToScroll) == LPVOID(&m_wndCorner)
- )
- continue;
- return pWndToScroll;
- }
- return NULL;
- }
- #endif // (!defined __EXT_MFC_NO_SCROLLCONAINERWND)
- #endif // (!defined __EXT_MFC_NO_SCROLLWND)