LRESULT CDComView::OnDocUpdate(WPARAM nNumNewLinesCleared, LPARAM) { CRect rcClient; CPoint ptScroll; CDComDoc *pDoc; CMainFrame *pMainFrm = (CMainFrame *)AfxGetMainWnd(); if (pMainFrm) { m_sizeCharDimensions = pMainFrm->GetLineDimentions("a", 1); } pDoc = GetDocument(); if (pDoc) { pDoc->m_cLineBuffer.Enter(); ptScroll = GetDeviceScrollPosition(); if ((nNumNewLinesCleared) && (IsScrollBarAtBottom() == false)) { ptScroll.y -= m_sizeCharDimensions.cy * nNumNewLinesCleared; ScrollToPosition(ptScroll); } GetClientRect(&rcClient); SetCaretPos(ptScroll, rcClient); SetScrollSizes(); pDoc->m_cLineBuffer.Exit(); } return 0; }
void CResizableFormView::GetTotalClientRect(LPRECT lpRect) const { GetClientRect(lpRect); // get dialog template's size // (this is set in CFormView::Create) CSize sizeTotal, sizePage, sizeLine; int nMapMode = 0; GetDeviceScrollSizes(nMapMode, sizeTotal, sizePage, sizeLine); // otherwise, give the correct size if scrollbars active if (nMapMode < 0) // scrollbars disabled return; // enlarge reported client area when needed CRect rect(lpRect); if (rect.Width() < sizeTotal.cx) rect.right = rect.left + sizeTotal.cx; if (rect.Height() < sizeTotal.cy) rect.bottom = rect.top + sizeTotal.cy; rect.OffsetRect(-GetDeviceScrollPosition()); *lpRect = rect; }
void CAutoPFAView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) { // TODO: Add your specialized code here and/or call the base class CScrollView::OnPrepareDC(pDC, pInfo); pDC->SetMapMode(MM_ANISOTROPIC); CPoint ptVpOrg(0, 0); ptVpOrg = -GetDeviceScrollPosition(); pDC->SetViewportOrg(ptVpOrg); int xLogPixPerInch = pDC->GetDeviceCaps(LOGPIXELSX); int yLogPixPerInch = pDC->GetDeviceCaps(LOGPIXELSY); pDC->SetWindowExt(xLogPixPerInch,yLogPixPerInch); pDC->SetViewportExt( (int)(xLogPixPerInch*m_Scale), (int)(yLogPixPerInch*m_Scale)); m_xWindowExt = xLogPixPerInch; m_yWindowExt = yLogPixPerInch; m_xWindowOrg = 0; m_xViewOrg = ptVpOrg.x; m_yWindowOrg = 0; m_yViewOrg = ptVpOrg.y; m_xViewExt = xLogPixPerInch*m_Scale; m_yViewExt = yLogPixPerInch*m_Scale; CAutoPFADoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); CFont Font; Font.CreateFontIndirect(&pDoc->m_workSpaceRef.GetFont()); pDC->SelectObject(&Font); pDC->SetBkMode(TRANSPARENT); pDC->SetTextAlign(TA_CENTER); }
CPoint CScrollView::GetScrollPosition() const /*******************************************/ { CPoint pt = GetDeviceScrollPosition(); CWindowDC dc( NULL ); dc.SetMapMode( m_nMapMode ); dc.DPtoLP( &pt ); return( pt ); }
void CScrollWnd::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) { ASSERT_VALID(pDC); #ifdef _DEBUG if (m_nMapMode == MM_NONE) { TRACE0("Error: must call SetScrollSizes() or SetScaleToFitSize()"); TRACE0("\tbefore painting scroll Wnd.\n"); ASSERT(FALSE); return; } #endif //_DEBUG ASSERT(m_totalDev.cx >= 0 && m_totalDev.cy >= 0); switch (m_nMapMode) { case MM_SCALETOFIT: pDC->SetMapMode(MM_ANISOTROPIC); pDC->SetWindowExt(m_totalLog); // window is in logical coordinates pDC->SetViewportExt(m_totalDev); if (m_totalDev.cx == 0 || m_totalDev.cy == 0) TRACE0("Warning: CScrollWnd scaled to nothing.\n"); break; default: ASSERT(m_nMapMode > 0); pDC->SetMapMode(m_nMapMode); break; } CPoint ptVpOrg(0, 0); // assume no shift for printing if (!pDC->IsPrinting()) { ASSERT(pDC->GetWindowOrg() == CPoint(0,0)); // by default shift Viewport origin in negative direction of scroll ptVpOrg = -GetDeviceScrollPosition(); if (m_bCenter) { CRect rect; GetClientRect(&rect); // if client area is larger than total device size, // override scroll positions to place origin such that // output is centered in the window if (m_totalDev.cx < rect.Width()) ptVpOrg.x = (rect.Width() - m_totalDev.cx) / 2; if (m_totalDev.cy < rect.Height()) ptVpOrg.y = (rect.Height() - m_totalDev.cy) / 2; } } pDC->SetViewportOrg(ptVpOrg); // CWnd::OnPrepareDC(pDC, pInfo); // For default Printing behavior }
void CTestTaskView::OnLButtonUp(UINT flags, CPoint point) { if (GetCapture() == this) { ReleaseCapture(); CPoint tmp = GetDeviceScrollPosition(); _end = point + tmp; Invalidate(); } }
wxPoint CBigScrollView::GetDeviceOrg() const { // not zero if client area is larger than total device size wxPoint pointOrg = GetDeviceScrollPosition(); if (pointOrg.x > 0) pointOrg.x = 0; if (pointOrg.y > 0) pointOrg.y = 0; pointOrg.x = abs(pointOrg.x); pointOrg.y = abs(pointOrg.y); return pointOrg; }
void CDComView::OnDraw(CDC* dc) { CRect rcBounds; GetClientRect(&rcBounds); int nFirstLine; int nLastLine; CRect rcClient; CDComDoc* pDoc = GetDocument(); CPoint ptScroll; SDComCfg *pDComCfg; CFont font; CMainFrame *pMainFrm = (CMainFrame *)AfxGetMainWnd(); if (dc->IsPrinting()) { dc->SetMapMode(MM_LOENGLISH); } else { dc->SetMapMode(MM_TEXT); } ASSERT_VALID(pMainFrm); if (!pMainFrm) { return; } ASSERT_VALID(pDoc); if (!pDoc) { return; } pDComCfg = pMainFrm->GetConfig(); if (!dc->IsPrinting()) { dc->SetBkColor(pDComCfg->m_crBack); } CMyMemDC pDC(dc); font.CreateFontIndirect(&pDComCfg->m_logfont); pDC->SelectObject(font); font.DeleteObject(); pDoc->m_cLineBuffer.Enter(); ptScroll = GetDeviceScrollPosition(); GetClientRect(&rcClient); nFirstLine = ptScroll.y / m_sizeCharDimensions.cy; nLastLine = nFirstLine + (rcClient.Height() / m_sizeCharDimensions.cy) + 1; DrawLines(nFirstLine, nLastLine, pDComCfg, pDC); pDoc->m_cLineBuffer.Exit(); }
void CScrollWnd::ClientToDocument(CPoint &pt) { ASSERT(m_nMapMode > 0); // not allowed for shrink to fit CPoint ptScr = GetDeviceScrollPosition(); pt += ptScr; if (m_nMapMode != MM_TEXT) { CWindowDC dc(NULL); dc.SetMapMode(m_nMapMode); dc.DPtoLP((LPPOINT)&pt); } }
wxPoint CBigScrollView::GetLogPosition(wxPoint Point) const { // return the true point position (scroll view + offset) wxPoint point = (m_nMapMode != MM_NONE) ? GetDeviceScrollPosition(): wxPoint(0, 0); Point += point; if (m_nMapMode != MM_TEXT) { wxASSERT(m_nMapMode > 0); // must be set CWindowDC dc(NULL); dc.SetMapMode(m_nMapMode); dc.DPtoLP(&Point); } Point += m_Offset; return Point; }
void CBigScrollView::GetLogClientRect(wxRect *pRect) const { // return the true client rectangle (scroll view + offset) GetClientRect(pRect); wxPoint point = (m_nMapMode != MM_NONE) ? GetDeviceScrollPosition(): wxPoint(0, 0); pRect->OffsetRect(point.x, point.y); if (m_nMapMode != MM_TEXT) { wxASSERT(m_nMapMode > 0); // must be set CWindowDC dc(NULL); dc.SetMapMode(m_nMapMode); dc.DPtoLP(pRect); } pRect->OffsetRect(m_Offset); }
void CTestTaskView::OnMouseMove(UINT flags, CPoint point) { if (GetCapture() == this) { CPoint tmp = GetDeviceScrollPosition(); CPoint buff = _end - tmp; _end = point; CRect rect; GetWindowRect(&rect); CPoint vec = CPoint(0, 0); if ((_end.x > (rect.right - rect.left) || _end.x < 0) || (_end.y >(rect.bottom - rect.top) || _end.y < 0)) { CPoint the_line = _end - _previous; if (_end.x > (rect.right - rect.left) || _end.x < 0) { if (the_line.y < 0) vec = CPoint(0, -1); else vec = CPoint(0, 1); } else if (_end.y > (rect.bottom - rect.top) || _end.y < 0) { if (the_line.x > 0) vec = CPoint(1, 0); else vec = CPoint(-1, 0); } double alpha = acos((double)(walter::scalar_multiplication(the_line, vec) / (walter::length(the_line) * walter::length(vec)))); CPoint shift_scroll = walter::const_multiplication(the_line, cos(alpha)); if (shift_scroll != CPoint(0, 0)) { walter::normalize(shift_scroll); ScrollToPosition(GetScrollPosition() + shift_scroll); } } _end += tmp; Invalidate(); } }
// helper to return the state of the scrollbars without actually changing // the state of the scrollbars void CScrollWnd::GetScrollBarState(CSize sizeClient, CSize& needSb, CSize& sizeRange, CPoint& ptMove, BOOL bInsideClient) { // get scroll bar sizes (the part that is in the client area) CSize sizeSb; GetScrollBarSizes(sizeSb); // enough room to add scrollbars sizeRange = m_totalDev - sizeClient; // > 0 => need to scroll ptMove = GetDeviceScrollPosition(); // point to move to (start at current scroll pos) BOOL bNeedH = sizeRange.cx > 0; if (!bNeedH) ptMove.x = 0; // jump back to origin else if (bInsideClient) sizeRange.cy += sizeSb.cy; // need room for a scroll bar BOOL bNeedV = sizeRange.cy > 0; if (!bNeedV) ptMove.y = 0; // jump back to origin else if (bInsideClient) sizeRange.cx += sizeSb.cx; // need room for a scroll bar if (bNeedV && !bNeedH && sizeRange.cx > 0) { ASSERT(bInsideClient); // need a horizontal scrollbar after all bNeedH = TRUE; sizeRange.cy += sizeSb.cy; } // if current scroll position will be past the limit, scroll to limit if (sizeRange.cx > 0 && ptMove.x >= sizeRange.cx) ptMove.x = sizeRange.cx; if (sizeRange.cy > 0 && ptMove.y >= sizeRange.cy) ptMove.y = sizeRange.cy; // now update the bars as appropriate needSb.cx = bNeedH; needSb.cy = bNeedV; // needSb, sizeRange, and ptMove area now all updated }
CPoint CScrollWnd::GetScrollPosition() const // logical coordinates { if (m_nMapMode == MM_SCALETOFIT) { return CPoint(0, 0); // must be 0,0 } CPoint pt = GetDeviceScrollPosition(); // pt may be negative if m_bCenter is set if (m_nMapMode != MM_TEXT) { ASSERT(m_nMapMode > 0); // must be set CWindowDC dc(NULL); dc.SetMapMode(m_nMapMode); dc.DPtoLP((LPPOINT)&pt); } return pt; }
void CScrollView::OnPrepareDC( CDC *pDC, CPrintInfo *pInfo ) /**********************************************************/ { if( !pDC->IsPrinting() ) { if( m_nMapMode == -1 ) { CRect rect; GetClientRect( &rect ); pDC->SetMapMode( MM_ANISOTROPIC ); pDC->SetViewportExt( rect.Width(), rect.Height() ); pDC->SetWindowExt( m_totalLog ); } else { CPoint pt = GetDeviceScrollPosition(); pDC->SetMapMode( m_nMapMode ); pDC->SetViewportOrg( -pt ); } } CView::OnPrepareDC( pDC, pInfo ); }
// Finds page pointed to and convert to 1:1 screen device units BOOL CPreviewView::FindPageRect(CPoint& point, UINT& nPage) { if (m_nZoomState != ZOOM_OUT) point += (CSize)GetDeviceScrollPosition(); for (nPage = 0; nPage < m_nPages; nPage++) { if (m_pPageInfo[nPage].rectScreen.PtInRect(point)) { // adjust point for page position point -= (CSize)m_pPageInfo[nPage].rectScreen.TopLeft(); // convert to 1:1 point.x = MulDiv(point.x, m_pPageInfo[nPage].sizeScaleRatio.cy, m_pPageInfo[nPage].sizeScaleRatio.cx); point.y = MulDiv(point.y, m_pPageInfo[nPage].sizeScaleRatio.cy, m_pPageInfo[nPage].sizeScaleRatio.cx); return TRUE; } } return FALSE; }
void CDComView::UpdateSelectionRange(CPoint point, bool bResetRange, bool bDoubleClickDown) { CDComDoc *pDoc; CPoint ptScroll; SSelection sSelection; ptScroll = GetDeviceScrollPosition(); pDoc = GetDocument(); if (pDoc) { sSelection.x = (point.x + ptScroll.x) / m_sizeCharDimensions.cx; sSelection.y = (point.y + ptScroll.y) / m_sizeCharDimensions.cy; if (bResetRange) { pDoc->m_cLineBuffer.ResetSelectionRange(sSelection, bDoubleClickDown); } else { pDoc->m_cLineBuffer.SetSelectionRange(sSelection); } } }
void CAutoScrollView::AutoScroll(UINT nRefMessage) { MSG msg; // dummmy message structure to process incoming // messages while autoscrolling. CPoint ptScrollPos, // Current scroll position - logical units ptDevScrollPos, // Current scroll position - device units ptCursorPos; // Current mouse cursor position CRect rc; // Client area long dx, dy; // Scrolling increment SIZE sizeTotal, // CScrollView scroll data sizePage, sizeLine; int nMapMode, // Mapping mode nMapFactor, // Accounts for mapping mode xMin, xMax, yMin, yMax; // Scroll range if (!m_bAutoScroll) return; msg.message = 0; // forces at least one loop. SetCapture(); GetDeviceScrollSizes(nMapMode, sizeTotal, sizePage, sizeLine); // We keep track of the scroll range because CScrollView::ScrollToPosition always // try to scroll even if the scroll limit has been reached. This results in screen // flickering when ScrollWindow is called. GetScrollRange(SB_HORZ, &xMin, &xMax); GetScrollRange(SB_VERT, &yMin, &yMax); // Process all messages until the relevant mouse button // has been released. nRefMessage depends on which button // has been used to trigger autoscrolling. // while (msg.message != nRefMessage) BOOL bSawRefMessage = FALSE; while (!bSawRefMessage) { // Process incoming messages until autoscroll button is released // You cannot peek here because it may process an invalidate // due to the scrolling. /* if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } */ ptScrollPos = GetScrollPosition(); ptDevScrollPos = GetDeviceScrollPosition(); GetCursorPos(&ptCursorPos); ScreenToClient(&ptCursorPos); GetClientRect(&rc); dx = 0L; dy = 0L; if ((ptCursorPos.y < 0) && (ptDevScrollPos.y != yMin)) // Cursor is above client area dy = min(-sizeLine.cy, max(-sizePage.cy, (ptCursorPos.y/10) * sizeLine.cy)); else if ((ptCursorPos.y > rc.bottom) && (ptDevScrollPos.y != yMax)) // Cursor is below client area dy = max(sizeLine.cy, min(sizePage.cy, ((ptCursorPos.y - rc.bottom)/10) * sizeLine.cy)); // otherwise we can't scroll anyway if ((ptCursorPos.x < 0) && (ptDevScrollPos.x != xMin)) // Cursor is on the left of the client area dx = min(-sizeLine.cx, max(-sizePage.cx, (ptCursorPos.x/10) * sizeLine.cx)); else if ((ptCursorPos.x > rc.right) && (ptDevScrollPos.x != xMax)) // Cursor is on the right of the client area dx = max(sizeLine.cx, min(sizePage.cx, ((ptCursorPos.x - rc.right)/10) * sizeLine.cx)); // otherwise we can't scroll anyway // if mouse cursor is dragging outside the client area, scrolling occurs if ((dx != 0) || (dy != 0)) { // Flip the Y coordinate if we're not in MM_TEXT nMapFactor = (nMapMode == MM_TEXT) ? 1 : -1; ptScrollPos.y += (int) dy * nMapFactor; ptScrollPos.x += (int) dx; m_bIsScrolling = TRUE; OnAutoScroll(ptCursorPos, TRUE); ScrollToPosition(ptScrollPos); while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); // if (msg.message == nRefMessage) break; if (msg.message == nRefMessage) bSawRefMessage = TRUE; } // if (!bSawRefMessage) OnAutoScroll(ptCursorPos, FALSE); } else { while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); // if (msg.message == nRefMessage) break; if (msg.message == nRefMessage) bSawRefMessage = TRUE; } m_bIsScrolling = FALSE; } } ReleaseCapture(); m_bIsScrolling = FALSE; }
void CPreviewView::OnDraw(CDC* pDC) { ASSERT_VALID(pDC); // don't do anything if not fully initialized if (m_pPrintView == NULL || m_dcPrint.m_hDC == NULL) return; CPoint ViewportOrg = pDC->GetViewportOrg(); CPen rectPen; rectPen.CreatePen(PS_SOLID, 2, GetSysColor(COLOR_WINDOWFRAME)); CPen shadowPen; shadowPen.CreatePen(PS_SOLID, 3, GetSysColor(COLOR_BTNSHADOW)); m_pPreviewInfo->m_bContinuePrinting = TRUE; // do this once each paint for (UINT nPage = 0; nPage < m_nPages; nPage++) { int nSavedState = m_dcPrint.SaveDC(); // Save pristine state of DC // Use paint DC for print preview output m_pPreviewDC->SetOutputDC(pDC->GetSafeHdc()); m_pPreviewInfo->m_nCurPage = m_nCurrentPage + nPage; // Only call PrepareDC if within page range, otherwise use default // rect to draw page rectangle if (m_nCurrentPage + nPage <= m_pPreviewInfo->GetMaxPage()) m_pPrintView->OnPrepareDC(m_pPreviewDC, m_pPreviewInfo); // Set up drawing rect to entire page (in logical coordinates) m_pPreviewInfo->m_rectDraw.SetRect(0, 0, m_pPreviewDC->GetDeviceCaps(HORZRES), m_pPreviewDC->GetDeviceCaps(VERTRES)); m_pPreviewDC->DPtoLP(&m_pPreviewInfo->m_rectDraw); // Draw empty page on screen pDC->SaveDC(); // save the output dc state CSize* pRatio = &m_pPageInfo[nPage].sizeScaleRatio; CRect* pRect = &m_pPageInfo[nPage].rectScreen; if (pRatio->cx == 0) { // page position has not been determined PositionPage(nPage); // compute page position if (m_nZoomState != ZOOM_OUT) ViewportOrg = -GetDeviceScrollPosition(); } pDC->SetMapMode(MM_TEXT); // Page Rectangle is in screen device coords pDC->SetViewportOrg(ViewportOrg); pDC->SetWindowOrg(0, 0); pDC->SelectStockObject(HOLLOW_BRUSH); pDC->SelectObject(&rectPen); pDC->Rectangle(pRect); pDC->SelectObject(&shadowPen); pDC->MoveTo(pRect->right + 1, pRect->top + 3); pDC->LineTo(pRect->right + 1, pRect->bottom + 1); pDC->MoveTo(pRect->left + 3, pRect->bottom + 1); pDC->LineTo(pRect->right + 1, pRect->bottom + 1); // erase background to white (most paper is white) CRect rectFill = *pRect; rectFill.left += 1; rectFill.top += 1; rectFill.right -= 2; rectFill.bottom -= 2; ::FillRect(pDC->m_hDC, rectFill, (HBRUSH)GetStockObject(WHITE_BRUSH)); pDC->RestoreDC(-1); // restore to synchronized state if (!m_pPreviewInfo->m_bContinuePrinting || m_nCurrentPage + nPage > m_pPreviewInfo->GetMaxPage()) { m_pPreviewDC->ReleaseOutputDC(); m_dcPrint.RestoreDC(nSavedState); // restore to untouched state // if the first page is not displayable, back up one page // but never go below 1 if (nPage == 0 && m_nCurrentPage > 1) SetCurrentPage(m_nCurrentPage - 1, TRUE); break; } // Display page number OnDisplayPageNumber(m_nCurrentPage, nPage + 1); // Set scale ratio for this page m_pPreviewDC->SetScaleRatio(pRatio->cx, pRatio->cy); CSize PrintOffset; VERIFY(m_pPreviewDC->Escape(GETPRINTINGOFFSET, 0, NULL, (LPVOID)&PrintOffset)); m_pPreviewDC->PrinterDPtoScreenDP((LPPOINT)&PrintOffset); PrintOffset += (CSize)pRect->TopLeft(); PrintOffset += CSize(1, 1); PrintOffset += (CSize)ViewportOrg; // For Scrolling m_pPreviewDC->SetTopLeftOffset(PrintOffset); m_pPreviewDC->ClipToPage(); m_pPrintView->OnPrint(m_pPreviewDC, m_pPreviewInfo); m_pPreviewDC->ReleaseOutputDC(); m_dcPrint.RestoreDC(nSavedState); // restore to untouched state } rectPen.DeleteObject(); shadowPen.DeleteObject(); }
void CTestTaskView::OnLButtonDown(UINT flags, CPoint point) { CPoint tmp = GetDeviceScrollPosition(); _previous = point + tmp; SetCapture(); }