//-------------------------------------------------------------- void CBMRegEditView::UpdateRow(int nInvalidRow) { int nRowCount = GetRowCount(); if (nRowCount != m_nPrevRowCount) { UpdateScrollSizes(); m_nPrevRowCount = nRowCount; } CClientDC dc(this); OnPrepareDC(&dc); int nFirstRow, nLastRow; CRect rectClient; GetClientRect(&rectClient); dc.DPtoLP(&rectClient); RectLPtoRowRange(rectClient, nFirstRow, nLastRow, FALSE); POINT pt; pt.x = 0; BOOL bNeedToScroll = TRUE; if (nInvalidRow < nFirstRow) pt.y = RowToYPos(nInvalidRow); else if (nInvalidRow > nLastRow) pt.y=max(0,RowToYPos(nInvalidRow+1) - rectClient.Height()); else bNeedToScroll = FALSE; if (bNeedToScroll) { ScrollToDevicePosition(pt); OnPrepareDC(&dc); } CRect rectInvalid = RowToWndRect(&dc, nInvalidRow); rectInvalid.left=23; rectInvalid.right=37; InvalidateRect(&rectInvalid); int nSelectedRow = GetActReg(); if (m_nPrevSelectedRow != nSelectedRow) { CRect rectOldSelection = RowToWndRect(&dc, m_nPrevSelectedRow); rectOldSelection.left=23; rectOldSelection.right=37; InvalidateRect(&rectOldSelection); m_nPrevSelectedRow = nSelectedRow; } }
void CScrollWnd::ScrollToPosition(POINT pt) // logical coordinates { ASSERT(m_nMapMode > 0); // not allowed for shrink to fit if (m_nMapMode != MM_TEXT) { CWindowDC dc(NULL); dc.SetMapMode(m_nMapMode); dc.LPtoDP((LPPOINT)&pt); } // now in device coordinates - limit if out of range int xMax = GetScrollLimit(SB_HORZ); int yMax = GetScrollLimit(SB_VERT); if (pt.x < 0) pt.x = 0; else if (pt.x > xMax) pt.x = xMax; if (pt.y < 0) pt.y = 0; else if (pt.y > yMax) pt.y = yMax; ScrollToDevicePosition(pt); }
void CScrollWnd::UpdateBars() { // UpdateBars may cause window to be resized - ignore those resizings if (m_bInsideUpdate) return; // Do not allow recursive calls // Lock out recursion m_bInsideUpdate = TRUE; // update the horizontal to reflect reality // NOTE: turning on/off the scrollbars will cause 'OnSize' callbacks ASSERT(m_totalDev.cx >= 0 && m_totalDev.cy >= 0); CRect rectClient; BOOL bCalcClient = TRUE; // allow parent to do inside-out layout first CWnd* pParentWnd = GetParent(); if (pParentWnd != NULL) { // if parent window responds to this message, use just // client area for scroll bar calc -- not "true" client area if ((BOOL)pParentWnd->SendMessage(WM_RECALCPARENT, 0, (LPARAM)(LPCRECT)&rectClient) != 0) { // use rectClient instead of GetTrueClientSize for // client size calculation. bCalcClient = FALSE; } } CSize sizeClient; CSize sizeSb; if (bCalcClient) { // get client rect if (!GetTrueClientSize(sizeClient, sizeSb)) { // no room for scroll bars (common for zero sized elements) CRect rect; GetClientRect(&rect); if (rect.right > 0 && rect.bottom > 0) { // if entire client area is not invisible, assume we have // control over our scrollbars EnableScrollBarCtrl(SB_BOTH, FALSE); } m_bInsideUpdate = FALSE; return; } } else { // let parent window determine the "client" rect GetScrollBarSizes(sizeSb); sizeClient.cx = rectClient.right - rectClient.left; sizeClient.cy = rectClient.bottom - rectClient.top; } // enough room to add scrollbars CSize sizeRange; CPoint ptMove; CSize needSb; // get the current scroll bar state given the true client area GetScrollBarState(sizeClient, needSb, sizeRange, ptMove, bCalcClient); if (needSb.cx) sizeClient.cy -= sizeSb.cy; if (needSb.cy) sizeClient.cx -= sizeSb.cx; // first scroll the window as needed ScrollToDevicePosition(ptMove); // will set the scroll bar positions too // this structure needed to update the scrollbar page range SCROLLINFO info; info.fMask = SIF_PAGE|SIF_RANGE; info.nMin = 0; // now update the bars as appropriate EnableScrollBarCtrl(SB_HORZ, needSb.cx); if (needSb.cx) { info.nPage = sizeClient.cx; info.nMax = m_totalDev.cx-1; if (!SetScrollInfo(SB_HORZ, &info, TRUE)) SetScrollRange(SB_HORZ, 0, sizeRange.cx, TRUE); } EnableScrollBarCtrl(SB_VERT, needSb.cy); if (needSb.cy) { info.nPage = sizeClient.cy; info.nMax = m_totalDev.cy-1; if (!SetScrollInfo(SB_VERT, &info, TRUE)) SetScrollRange(SB_VERT, 0, sizeRange.cy, TRUE); } // remove recursion lockout m_bInsideUpdate = FALSE; }
void CXTPPropertyPage::UpdateBars() { if (m_totalDev == CSize(0, 0) || !m_bCreated) return; // UpdateBars may cause window to be resized - ignore those resizings if (m_bInsideUpdate) return; // Do not allow recursive calls // Lock out recursion m_bInsideUpdate = TRUE; // update the horizontal to reflect reality // NOTE: turning on/off the scrollbars will cause 'OnSize' callbacks ASSERT(m_totalDev.cx >= 0 && m_totalDev.cy >= 0); CRect rectClient; BOOL bCalcClient = TRUE; CSize sizeClient; CSize sizeSb; // get client rect if (!GetTrueClientSize(sizeClient, sizeSb)) { // no room for scroll bars (common for zero sized elements) CRect rect; GetClientRect(&rect); if (rect.right > 0 && rect.bottom > 0) { // if entire client area is not invisible, assume we have // control over our scrollbars EnableScrollBarCtrl(SB_BOTH, FALSE); } m_bInsideUpdate = FALSE; return; } // enough room to add scrollbars CSize sizeRange; CPoint ptMove; CSize needSb; // get the current scroll bar state given the true client area GetScrollBarState(sizeClient, needSb, sizeRange, ptMove, bCalcClient); if (needSb.cx) sizeClient.cy -= sizeSb.cy; if (needSb.cy) sizeClient.cx -= sizeSb.cx; // first scroll the window as needed ScrollToDevicePosition(ptMove); // will set the scroll bar positions too // this structure needed to update the scrollbar page range SCROLLINFO info; info.fMask = SIF_PAGE|SIF_RANGE; info.nMin = 0; // now update the bars as appropriate EnableScrollBarCtrl(SB_HORZ, needSb.cx); if (needSb.cx) { info.nPage = sizeClient.cx; info.nMax = m_totalDev.cx-1; if (!SetScrollInfo(SB_HORZ, &info, TRUE)) SetScrollRange(SB_HORZ, 0, sizeRange.cx, TRUE); } EnableScrollBarCtrl(SB_VERT, needSb.cy); if (needSb.cy) { info.nPage = sizeClient.cy; info.nMax = m_totalDev.cy-1; if (!SetScrollInfo(SB_VERT, &info, TRUE)) SetScrollRange(SB_VERT, 0, sizeRange.cy, TRUE); } // remove recursion lockout m_bInsideUpdate = FALSE; }
void CJevView::OnUpdate( CView* pSender, LPARAM lHint, CObject* pHint ) { TRACE( "Entering OnUpdate\n" ); int lsr, plsr, par, ar; CJevDoc* pDoc = GetDocument(); CClientDC dc( this ); OnPrepareDC( &dc ); if( pHint != 0 && pHint->IsKindOf(RUNTIME_CLASS(CUpdateHint)) ) { CUpdateHint* pCUpdateHint = (CUpdateHint*) pHint; switch( lHint ) { TRACE("OnUpdate: lHint-'%d'\n", (int)lHint ); case HINT_DELETE_ACTIVE_RECORD: UpdateScrollSizes(); InvalidateRecord( &dc, pDoc->njeGetActiveRecord(), pCUpdateHint->iHint1); break; case HINT_INSERT_ACTIVE_RECORD: //InvalidateRecord( &dc, m_posPrevActiveRecord ); UpdateScrollSizes(); //InvalidateRecord( &dc, pDoc->posGetActiveRecord() ); m_njePrevLastSelectedRecord = pDoc -> njeGetLastSelectedRecord(); Invalidate(); break; case HINT_CHANGE_ACTIVE_RECORD: UpdateScrollSizes(); InvalidateRecord( &dc, pDoc->njeGetActiveRecord() ); break; case HINT_NAVIGATION_KEY: lsr = pDoc -> njeGetLastSelectedRecord(); par = m_njePrevActiveRecord; ar = pDoc -> njeGetActiveRecord(); TRACE("lsr=%d, par=%d\n", lsr,par); if( lsr < par ) { INVALIDATERANGE( lsr, par-1 ); } else if( lsr > par ) { INVALIDATERANGE( par+1, lsr); } if( ar != par ) { // Previous InvalidateRecord( &dc, par ); // Newly actived InvalidateRecord( &dc, ar ); m_njePrevActiveRecord = ar; } break; case HINT_LAST_SELECTED_RECORD: plsr = m_njePrevLastSelectedRecord; lsr = pDoc -> njeGetLastSelectedRecord(); ar = pDoc -> njeGetActiveRecord(); if( plsr > ar ) { if( lsr > plsr ) { INVALIDATERANGE( plsr+1, lsr); } else if( lsr >= ar && lsr < plsr ) { INVALIDATERANGE( lsr+1, plsr ); } else if( lsr < ar ) { INVALIDATERANGE( lsr+1, plsr ); } else TRACE( "plsr>ar: no Invalidate Records selected!\n"); } else if( plsr < ar ) { if( lsr < plsr ) { INVALIDATERANGE( lsr, plsr-1 ); } else if( lsr > plsr && lsr <= ar ) { INVALIDATERANGE( plsr, lsr-1 ); } else if( lsr > ar ) { INVALIDATERANGE( plsr, lsr ); } else TRACE( "plsr<ar: no Invalidate Records selected!\n"); } else if( plsr == ar) { if( lsr < ar ) { INVALIDATERANGE( lsr, ar-1 ); } else if( lsr > ar ) { INVALIDATERANGE( ar+1, lsr ); } else TRACE(" plsr == ar: no Invalidate Records Selectec!\n"); } m_njePrevLastSelectedRecord = pDoc -> njeGetLastSelectedRecord(); break; default: TRACE("OnUpdate: Unexpected Hint-'%d'\n", (int)lHint ); break; } //return; } // Get the first and last record index displayed inthe Client area // int nyFirstLogicalDisplayLine, nyLastLogicalDisplayLine; CRect rectClient; GetClientRect( &rectClient ); dc.DPtoLP( &rectClient ); nyFirstLogicalDisplayLine = rectClient.top / m_cyChar; nyLastLogicalDisplayLine = (rectClient.bottom-1) / m_cyChar; TRACE( "FirstRec=%d, LastRec=%d\n", nyFirstLogicalDisplayLine, nyLastLogicalDisplayLine ); TRACE( "top=%d, bottom=%d\n", rectClient.top, rectClient.bottom); // Scroll, if necessary, so that the selected row is visible POINT pt; pt.x = 0; pt.y = 0; BOOL bNeedToScroll = TRUE; int nyActiveRecordDispLine, njelActiveRecord, nSubAcct; int NJE = pDoc->njeGetActiveRecord(); pDoc->MapNJEToDispLine( NJE, nyActiveRecordDispLine, nSubAcct ); TRACE( "nyActiveRecordDispLine=%d, njelActiveRecord=%d, m_njelPrevActiveRecord=%d\n", nyActiveRecordDispLine, njelActiveRecord, m_njePrevActiveRecord ); if( njelActiveRecord < 0 ) { bNeedToScroll = FALSE; } else if( nyActiveRecordDispLine < nyFirstLogicalDisplayLine ) { pt.y = nyActiveRecordDispLine * m_cyChar; } else if( nyActiveRecordDispLine > nyLastLogicalDisplayLine ) { pt.y = max( 0, (nyActiveRecordDispLine+1)*m_cyChar - rectClient.Height() ); } else { bNeedToScroll = FALSE; } TRACE( "bNeedToScroll=%d, pt.y=%d\n", bNeedToScroll, pt.y ); if( bNeedToScroll ) { TRACE( "OnUpdate: Scrolling\n"); ScrollToDevicePosition( pt ); OnPrepareDC( &dc ); } TRACE( "Leaving OnUpdate\n" ); }