home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 18.ddi / MFC / SRC / VIEWSCRL.CP_ / VIEWSCRL.CP
Encoding:
Text File  |  1993-02-08  |  16.8 KB  |  681 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library. 
  2. // Copyright (C) 1992 Microsoft Corporation 
  3. // All rights reserved. 
  4. //  
  5. // This source code is only intended as a supplement to the 
  6. // Microsoft Foundation Classes Reference and Microsoft 
  7. // QuickHelp and/or WinHelp documentation provided with the library. 
  8. // See these sources for detailed information regarding the 
  9. // Microsoft Foundation Classes product. 
  10.  
  11. #include "stdafx.h"
  12.  
  13. #ifdef AFX_CORE3_SEG
  14. #pragma code_seg(AFX_CORE3_SEG)
  15. #endif
  16.  
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char BASED_CODE THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CScrollView
  24.  
  25. IMPLEMENT_DYNAMIC(CScrollView, CView)
  26.  
  27. BEGIN_MESSAGE_MAP(CScrollView, CView)
  28.     //{{AFX_MSG_MAP(CScrollView)
  29.     ON_WM_SIZE()
  30.     ON_WM_HSCROLL()
  31.     ON_WM_VSCROLL()
  32.     //}}AFX_MSG_MAP
  33. END_MESSAGE_MAP()
  34.  
  35. // Special mapping modes just for CScrollView implementation
  36. #define MM_NONE             0
  37. #define MM_SCALETOFIT       (-1)
  38.     // standard GDI mapping modes are > 0
  39.  
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CScrollView construction/destruction
  42.  
  43. CScrollView::CScrollView()
  44. {
  45.     // Init everything to zero
  46.     AFX_ZERO_INIT_OBJECT(CView);
  47.  
  48.     m_nMapMode = MM_NONE;
  49. }
  50.  
  51. CScrollView::~CScrollView()
  52. {
  53. }
  54.  
  55.  
  56. /////////////////////////////////////////////////////////////////////////////
  57. // CScrollView painting
  58.  
  59. void CScrollView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
  60. {
  61.     ASSERT_VALID(pDC);
  62.  
  63. #ifdef _DEBUG
  64.     if (m_nMapMode == MM_NONE)
  65.     {
  66.         TRACE0("Error: must call SetScrollSizes() or SetScaleToFitSize()"
  67.             " before painting scroll view\n");
  68.         ASSERT(FALSE);
  69.         return;
  70.     }
  71. #endif //_DEBUG
  72.     ASSERT(m_totalLog.cx >= 0 && m_totalLog.cy >= 0);
  73.     ASSERT(m_totalDev.cx >= 0 && m_totalDev.cx >= 0);
  74.     switch (m_nMapMode)
  75.     {
  76.     case MM_SCALETOFIT:
  77.         pDC->SetMapMode(MM_ANISOTROPIC);
  78.         pDC->SetWindowExt(m_totalLog);  // window is in logical coordinates
  79.         pDC->SetViewportExt(m_totalDev);
  80.         if (m_totalDev.cx == 0 || m_totalDev.cy == 0)
  81.             TRACE0("Warning: CScrollView scaled to nothing\n");
  82.         break;
  83.  
  84.     default:
  85.         ASSERT(m_nMapMode > 0);
  86.         pDC->SetMapMode(m_nMapMode);
  87.         break;
  88.     }
  89.  
  90.     CPoint ptVpOrg(0, 0);       // assume no shift for printing
  91.     if (!pDC->IsPrinting())
  92.     {
  93.         ASSERT(pDC->GetWindowOrg() == CPoint(0,0));
  94.  
  95.         // by default shift viewport origin in negative direction of scroll
  96.         ptVpOrg = -GetDeviceScrollPosition();
  97.  
  98.         if (m_bCenter)
  99.         {
  100.             CRect rect;
  101.             GetClientRect(&rect);
  102.  
  103.             // if client area is larger than total device size,
  104.             // override scroll positions to place origin such that
  105.             // output is centered in the window
  106.             if (m_totalDev.cx < rect.Width())
  107.                 ptVpOrg.x = (rect.Width() - m_totalDev.cx) / 2;
  108.             if (m_totalDev.cy < rect.Height())
  109.                 ptVpOrg.y = (rect.Height() - m_totalDev.cy) / 2;
  110.         }
  111.     }
  112.     pDC->SetViewportOrg(ptVpOrg);
  113.  
  114.     CView::OnPrepareDC(pDC, pInfo);     // For default Printing behavior
  115. }
  116.  
  117. /////////////////////////////////////////////////////////////////////////////
  118. // Set mode and scaling/scrolling sizes
  119.  
  120. void CScrollView::SetScaleToFitSize(SIZE sizeTotal)
  121. {
  122.     ASSERT(sizeTotal.cx >= 0 && sizeTotal.cy >= 0);
  123.     ASSERT(m_hWnd != NULL);
  124.     m_nMapMode = MM_SCALETOFIT;     // special internal value
  125.     m_totalLog = sizeTotal;
  126.  
  127.     // reset and turn any scroll bars off
  128.     if (m_hWnd != NULL && (GetStyle() & (WS_HSCROLL|WS_VSCROLL)))
  129.     {
  130.         SetScrollPos(SB_HORZ, 0);
  131.         SetScrollPos(SB_VERT, 0);
  132.         EnableScrollBarCtrl(SB_BOTH, FALSE);
  133.         ASSERT((GetStyle() & (WS_HSCROLL|WS_VSCROLL)) == 0);
  134.     }
  135.  
  136.     CRect rectT;
  137.     GetClientRect(rectT);
  138.     m_totalDev = rectT.Size();
  139.  
  140.     if (m_hWnd != NULL)
  141.     {
  142.         // window has been created, invalidate
  143.         UpdateBars();
  144.         Invalidate(TRUE);
  145.     }
  146. }
  147.  
  148. const SIZE AFXAPI_DATA CScrollView::sizeDefault = {0,0};
  149.  
  150. void CScrollView::SetScrollSizes(int nMapMode, SIZE sizeTotal,
  151.     const SIZE& sizePage, const SIZE& sizeLine)
  152. {
  153.     ASSERT(sizeTotal.cx >= 0 && sizeTotal.cy >= 0);
  154.     ASSERT(nMapMode > 0);
  155.     ASSERT(nMapMode != MM_ISOTROPIC && nMapMode != MM_ANISOTROPIC);
  156.  
  157.     int nOldMapMode = m_nMapMode;
  158.     m_nMapMode = nMapMode;
  159.     m_totalLog = sizeTotal;
  160.  
  161.     //BLOCK: convert logical coordinate space to device coordinates
  162.     {
  163.         CWindowDC dc(NULL);
  164.         ASSERT(m_nMapMode > 0);
  165.         dc.SetMapMode(m_nMapMode);
  166.  
  167.         // total size
  168.         m_totalDev = m_totalLog;
  169.         dc.LPtoDP((LPPOINT)&m_totalDev);
  170.         m_pageDev = sizePage;
  171.         dc.LPtoDP((LPPOINT)&m_pageDev);
  172.         m_lineDev = sizeLine;
  173.         dc.LPtoDP((LPPOINT)&m_lineDev);
  174.         if (m_totalDev.cy < 0)
  175.             m_totalDev.cy = -m_totalDev.cy;
  176.         if (m_pageDev.cy < 0)
  177.             m_pageDev.cy = -m_pageDev.cy;
  178.         if (m_lineDev.cy < 0)
  179.             m_lineDev.cy = -m_lineDev.cy;
  180.     } // release DC here
  181.  
  182.     // now adjust device specific sizes
  183.     ASSERT(m_totalDev.cx >= 0 && m_totalDev.cy >= 0);
  184.     if (m_pageDev.cx == 0)
  185.         m_pageDev.cx = m_totalDev.cx / 10;
  186.     if (m_pageDev.cy == 0)
  187.         m_pageDev.cy = m_totalDev.cy / 10;
  188.     if (m_lineDev.cx == 0)
  189.         m_lineDev.cx = m_pageDev.cx / 10;
  190.     if (m_lineDev.cy == 0)
  191.         m_lineDev.cy = m_pageDev.cy / 10;
  192.  
  193.     if (m_hWnd != NULL)
  194.     {
  195.         // window has been created, invalidate now
  196.         UpdateBars();
  197.         if (nOldMapMode != m_nMapMode)
  198.             Invalidate(TRUE);
  199.     }
  200. }
  201.  
  202. /////////////////////////////////////////////////////////////////////////////
  203. // Getting information
  204.  
  205. CPoint CScrollView::GetScrollPosition() const   // logical coordinates
  206. {
  207.     if (m_nMapMode == MM_SCALETOFIT)
  208.     {
  209.         return CPoint(0, 0);    // must be 0,0
  210.     }
  211.  
  212.     CPoint pt = GetDeviceScrollPosition();
  213.     // pt may be negative if m_bCenter is set
  214.     
  215.     if (m_nMapMode != MM_TEXT)
  216.     {
  217.         ASSERT(m_nMapMode > 0); // must be set
  218.         CWindowDC dc(NULL);
  219.         dc.SetMapMode(m_nMapMode);
  220.         dc.DPtoLP((LPPOINT)&pt);
  221.     }
  222.     return pt;
  223. }
  224.  
  225. void CScrollView::ScrollToPosition(POINT pt)    // logical coordinates
  226. {
  227.     ASSERT(m_nMapMode > 0);     // not allowed for shrink to fit
  228.     if (m_nMapMode != MM_TEXT)
  229.     {
  230.         CWindowDC dc(NULL);
  231.         dc.SetMapMode(m_nMapMode);
  232.         dc.LPtoDP((LPPOINT)&pt);
  233.     }
  234.  
  235.     // now in device coordinates - limit if out of range
  236.     int xMin, xMax, yMin, yMax;
  237.     GetScrollRange(SB_HORZ, &xMin, &xMax);
  238.     GetScrollRange(SB_VERT, &yMin, &yMax);
  239.     ASSERT(xMin == 0 && yMin == 0);
  240.     if (pt.x < 0)
  241.         pt.x = 0;
  242.     else if (pt.x > xMax)
  243.         pt.x = xMax;
  244.     if (pt.y < 0)
  245.         pt.y = 0;
  246.     else if (pt.y > yMax)
  247.         pt.y = yMax;
  248.  
  249.     ScrollToDevicePosition(pt);
  250. }
  251.  
  252. CPoint CScrollView::GetDeviceScrollPosition() const
  253. {
  254.     CPoint pt(GetScrollPos(SB_HORZ), GetScrollPos(SB_VERT));
  255.     ASSERT(pt.x >= 0 && pt.y >= 0);
  256.  
  257.     if (m_bCenter)
  258.     {
  259.         CRect rect;
  260.         GetClientRect(&rect);
  261.  
  262.         // if client area is larger than total device size,
  263.         // the scroll positions are overridden to place origin such that
  264.         // output is centered in the window
  265.         // GetDeviceScrollPosition() must reflect this
  266.  
  267.         if (m_totalDev.cx < rect.Width())
  268.             pt.x = -((rect.Width() - m_totalDev.cx) / 2);
  269.         if (m_totalDev.cy < rect.Height())
  270.             pt.y = -((rect.Height() - m_totalDev.cy) / 2);
  271.     }
  272.  
  273.     return pt;
  274. }
  275.  
  276. void CScrollView::GetDeviceScrollSizes(int& nMapMode, SIZE& sizeTotal,
  277.             SIZE& sizePage, SIZE& sizeLine) const
  278. {
  279.     if (m_nMapMode <= 0)
  280.         TRACE0("Warning: CScrollView::GetDeviceScrollSizes returning "
  281.             "invalid mapping mode\n");
  282.     nMapMode = m_nMapMode;
  283.     sizeTotal = m_totalDev;
  284.     sizePage = m_pageDev;
  285.     sizeLine = m_lineDev;
  286. }
  287.  
  288. void CScrollView::ScrollToDevicePosition(POINT ptDev)
  289. {
  290.     ASSERT(ptDev.x >= 0);
  291.     ASSERT(ptDev.y >= 0);
  292.  
  293.     int xOrig = SetScrollPos(SB_HORZ, ptDev.x);
  294.     int yOrig = SetScrollPos(SB_VERT, ptDev.y);
  295.     ScrollWindow(xOrig - ptDev.x, yOrig - ptDev.y);
  296. }
  297.  
  298. /////////////////////////////////////////////////////////////////////////////
  299. // Other helpers
  300.  
  301. void CScrollView::FillOutsideRect(CDC* pDC, CBrush* pBrush)
  302. {
  303.     ASSERT_VALID(pDC);
  304.     ASSERT_VALID(pBrush);
  305.     // Fill Rect outside the image
  306.     CRect rect;
  307.     GetClientRect(rect);
  308.     ASSERT(rect.left == 0 && rect.top == 0);
  309.     rect.left = m_totalDev.cy;
  310.     if (!rect.IsRectEmpty())
  311.         pDC->FillRect(rect, pBrush);    // vertical strip along the side
  312.     rect.left = 0;
  313.     rect.right = m_totalDev.cy;
  314.     rect.top = m_totalDev.cy;
  315.     if (!rect.IsRectEmpty())
  316.         pDC->FillRect(rect, pBrush);    // horizontal strip along the bottom
  317. }
  318.  
  319. void CScrollView::ResizeParentToFit(BOOL bShrinkOnly)
  320. {
  321.     // adjust parent rect so client rect is appropriate size
  322.     ASSERT(m_nMapMode != MM_NONE);  // mapping mode must be known
  323.  
  324.     CFrameWnd* pFrame = GetParentFrame();
  325.     ASSERT(pFrame != NULL);
  326.     CRect rectView;
  327.     GetClientRect(rectView);
  328.     ASSERT(rectView.left == 0 && rectView.top == 0);
  329.     CRect rectFrame;
  330.     pFrame->GetWindowRect(rectFrame);
  331.     CSize size = rectFrame.Size();
  332.     if (!bShrinkOnly || rectView.right > m_totalDev.cx)
  333.         size.cx -= (rectView.right - m_totalDev.cx);
  334.     if (!bShrinkOnly || rectView.bottom > m_totalDev.cy)
  335.         size.cy -= (rectView.bottom - m_totalDev.cy);
  336.     pFrame->SetWindowPos(NULL, 0, 0, size.cx, size.cy,
  337.         SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE);
  338. }
  339.  
  340.  
  341. /////////////////////////////////////////////////////////////////////////////
  342.  
  343. void CScrollView::OnSize(UINT nType, int cx, int cy)
  344. {
  345.     CView::OnSize(nType, cx, cy);
  346.     if (m_nMapMode == MM_SCALETOFIT)
  347.     {
  348.         // force recalculation of scale to fit parameters
  349.         SetScaleToFitSize(m_totalLog);
  350.     }
  351.     else
  352.     {
  353.         // UpdateBars() handles locking out recursion
  354.         UpdateBars();
  355.     }
  356. }
  357.  
  358. /////////////////////////////////////////////////////////////////////////////
  359. // Scrolling Helpers
  360.  
  361. void CScrollView::CenterOnPoint(CPoint ptCenter) // center in device coords
  362. {
  363.     CRect rect;
  364.     GetClientRect(&rect);           // find size of client window
  365.     
  366.     int xDesired = ptCenter.x - rect.Width() / 2;
  367.     int yDesired = ptCenter.y - rect.Height() / 2;
  368.  
  369.     DWORD dwStyle = GetStyle();
  370.  
  371.     if ((dwStyle & WS_HSCROLL) == 0 || xDesired < 0)
  372.     {
  373.         xDesired = 0;
  374.     }
  375.     else
  376.     {
  377.         int xMin, xMax;
  378.         GetScrollRange(SB_HORZ, &xMin, &xMax);
  379.         ASSERT(xMin == 0);
  380.         if (xDesired > xMax)
  381.             xDesired = xMax;
  382.     }
  383.  
  384.     if ((dwStyle & WS_VSCROLL) == 0 || yDesired < 0)
  385.     {
  386.         yDesired = 0;
  387.     }
  388.     else
  389.     {
  390.         int yMin, yMax;
  391.         GetScrollRange(SB_VERT, &yMin, &yMax);
  392.         ASSERT(yMin == 0);
  393.         if (yDesired > yMax)
  394.             yDesired = yMax;
  395.     }
  396.  
  397.     ASSERT(xDesired >= 0);
  398.     ASSERT(yDesired >= 0);
  399.  
  400.     int xOrig = SetScrollPos(SB_HORZ, xDesired);
  401.     int yOrig = SetScrollPos(SB_VERT, yDesired);
  402. }
  403.  
  404.  
  405. /////////////////////////////////////////////////////////////////////////////
  406. // Tie to scrollbars and CWnd behaviour
  407.  
  408. BOOL CScrollView::GetTrueClientSize(CSize& size, CSize& sizeSb)
  409.     // return TRUE if enough room to add scrollbars if needed
  410. {
  411.     CRect rect;
  412.     GetClientRect(&rect);
  413.     ASSERT(rect.top == 0 && rect.left == 0);
  414.     size.cx = rect.right;
  415.     size.cy = rect.bottom;
  416.     sizeSb.cx = sizeSb.cy = 0;
  417.     DWORD dwStyle = GetStyle();
  418.  
  419.     // first calculate the size of a potential scrollbar
  420.         // (scroll bar controls do not get turned on/off)
  421.     if (GetScrollBarCtrl(SB_VERT) == NULL)
  422.     {
  423.         // vert scrollbars will impact client area of this window
  424.         sizeSb.cx = afxData.cxVScroll;
  425.         if (dwStyle & WS_BORDER)
  426.             sizeSb.cx -= CX_BORDER;
  427.         if (dwStyle & WS_VSCROLL)
  428.             size.cx += sizeSb.cx;       // currently on - adjust now
  429.     }
  430.     if (GetScrollBarCtrl(SB_HORZ) == NULL)
  431.     {
  432.         // horz scrollbars will impact client area of this window
  433.         sizeSb.cy = afxData.cyHScroll;
  434.         if (dwStyle & WS_BORDER)
  435.             sizeSb.cy -= CY_BORDER;
  436.         if (dwStyle & WS_HSCROLL)
  437.             size.cy += sizeSb.cy;       // currently on - adjust now
  438.     }
  439.  
  440.     // return TRUE if enough room
  441.     return (size.cx > sizeSb.cx && size.cy > sizeSb.cy);
  442. }
  443.  
  444. void CScrollView::UpdateBars()
  445. {
  446.     // UpdateBars may cause window to be resized - ignore those resizings
  447.     if (m_bInsideUpdate)
  448.         return;         // Do not allow recursive calls
  449.  
  450.     // Lock out recursion
  451.     m_bInsideUpdate = TRUE;
  452.  
  453.     // update the horizontal to reflect reality
  454.     // NOTE: turning on/off the scrollbars will cause 'OnSize' callbacks
  455.     ASSERT(m_totalDev.cx >= 0 && m_totalDev.cx >= 0);
  456.  
  457.     CSize sizeClient;
  458.     CSize sizeSb;
  459.  
  460.     if (!GetTrueClientSize(sizeClient, sizeSb))
  461.     {
  462.         // no room for scroll bars (common for zero sized elements)
  463.         CRect rect;
  464.         GetClientRect(&rect);
  465.         if (rect.right > 0 && rect.bottom > 0)
  466.         {
  467.             // if entire client area is not invisible, assume we have
  468.             //  control over our scrollbars
  469.             EnableScrollBarCtrl(SB_BOTH, FALSE);
  470.         }
  471.         m_bInsideUpdate = FALSE;
  472.         return;
  473.     }
  474.  
  475.     // enough room to add scrollbars
  476.     CSize sizeRange = m_totalDev - sizeClient;
  477.         // > 0 => need to scroll
  478.     CPoint ptMove = GetDeviceScrollPosition();
  479.                         // point to move to (start at current scroll pos)
  480.  
  481.     BOOL bNeedH = sizeRange.cx > 0;
  482.     if (bNeedH)
  483.         sizeRange.cy += sizeSb.cy;          // need room for a scroll bar
  484.     else
  485.         ptMove.x = 0;                       // jump back to origin
  486.  
  487.     BOOL bNeedV = sizeRange.cy > 0;
  488.     if (bNeedV)
  489.         sizeRange.cx += sizeSb.cx;
  490.     else
  491.         ptMove.y = 0;                       // jump back to origin
  492.  
  493.     if (bNeedV && !bNeedH && sizeRange.cx > 0)
  494.     {
  495.         // need a horizontal scrollbar after all
  496.         bNeedH = TRUE;
  497.         sizeRange.cy += sizeSb.cy;
  498.     }
  499.  
  500.     // if current scroll position will be past the limit, scroll to limit
  501.     if (sizeRange.cx > 0 && ptMove.x >= sizeRange.cx)
  502.         ptMove.x = sizeRange.cx;
  503.     if (sizeRange.cy > 0 && ptMove.y >= sizeRange.cy)
  504.         ptMove.y = sizeRange.cy;
  505.  
  506.     // first scroll the window as needed
  507.     ScrollToDevicePosition(ptMove); // will set the scroll bar positions too
  508.  
  509.     // now update the bars as appropriate
  510.     EnableScrollBarCtrl(SB_HORZ, bNeedH);
  511.     if (bNeedH)
  512.         SetScrollRange(SB_HORZ, 0, sizeRange.cx, TRUE);
  513.  
  514.     EnableScrollBarCtrl(SB_VERT, bNeedV);
  515.  
  516.     if (bNeedV)
  517.         SetScrollRange(SB_VERT, 0, sizeRange.cy, TRUE);
  518.  
  519.     // Remove recursion lockout
  520.     m_bInsideUpdate = FALSE;
  521. }
  522.  
  523. /////////////////////////////////////////////////////////////////////////////
  524. // CScrollView scrolling
  525.  
  526. void CScrollView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  527. {
  528.     ASSERT(pScrollBar == GetScrollBarCtrl(SB_HORZ));    // may be null
  529.     OnScroll(SB_HORZ, nSBCode, nPos);
  530. }
  531.  
  532. void CScrollView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  533. {
  534.     ASSERT(pScrollBar == GetScrollBarCtrl(SB_VERT));    // may be null
  535.     OnScroll(SB_VERT, nSBCode, nPos);
  536. }
  537.  
  538. void CScrollView::OnScroll(int nBar, UINT nSBCode, UINT nPos)
  539. {
  540.     ASSERT(nBar == SB_HORZ || nBar == SB_VERT);
  541.     BOOL bHorz = (nBar == SB_HORZ);
  542.  
  543.     int zOrig, z;   // z = x or y depending on 'nBar'
  544.     int zMin, zMax;
  545.     zOrig = z = GetScrollPos(nBar);
  546.     GetScrollRange(nBar, &zMin, &zMax);
  547.     ASSERT(zMin == 0);
  548.     if (zMax <= 0)
  549.     {
  550.         TRACE0("Warning: no scroll range - ignoring scroll message\n");
  551.         ASSERT(z == 0);     // must be at top
  552.         return;
  553.     }
  554.  
  555.     switch (nSBCode)
  556.     {
  557.     case SB_TOP:
  558.         z = 0;
  559.         break;
  560.  
  561.     case SB_BOTTOM:
  562.         z = zMax;
  563.         break;
  564.         
  565.     case SB_LINEUP:
  566.         z -= bHorz ? m_lineDev.cx : m_lineDev.cy;
  567.         break;
  568.  
  569.     case SB_LINEDOWN:
  570.         z += bHorz ? m_lineDev.cx : m_lineDev.cy;
  571.         break;
  572.  
  573.     case SB_PAGEUP:
  574.         z -= bHorz ? m_pageDev.cx : m_pageDev.cy;
  575.         break;
  576.  
  577.     case SB_PAGEDOWN:
  578.         z += bHorz ? m_pageDev.cx : m_pageDev.cy;
  579.         break;
  580.  
  581.     case SB_THUMBTRACK:
  582.         z = nPos;
  583.         break;
  584.  
  585.     default:        // ignore other notifications
  586.         return;
  587.     }
  588.  
  589.     if (z < 0)
  590.         z = 0;
  591.     else if (z > zMax)
  592.         z = zMax;
  593.  
  594.     if (z != zOrig)
  595.     {
  596.         if (bHorz)
  597.             ScrollWindow(-(z-zOrig), 0);
  598.         else
  599.             ScrollWindow(0, -(z-zOrig));
  600.         SetScrollPos(nBar, z);
  601.         UpdateWindow();
  602.     }
  603. }
  604.  
  605.  
  606.  
  607. /////////////////////////////////////////////////////////////////////////////
  608. // CScrollView diagnostics
  609.  
  610. #ifdef _DEBUG
  611. void CScrollView::Dump(CDumpContext& dc) const
  612. {
  613.     ASSERT_VALID(this);
  614.  
  615.     CView::Dump(dc);
  616.  
  617.     AFX_DUMP1(dc, "\nm_totalLog = ", m_totalLog);
  618.     AFX_DUMP1(dc, "\nm_totalDev = ", m_totalDev);
  619.     AFX_DUMP1(dc, "\nm_pageDev = ", m_pageDev);
  620.     AFX_DUMP1(dc, "\nm_lineDev = ", m_lineDev);
  621.     AFX_DUMP1(dc, "\nm_bCenter = ", m_bCenter);
  622.     AFX_DUMP1(dc, "\nm_bInsideUpdate = ", m_bInsideUpdate);
  623.     AFX_DUMP0(dc, "\nm_nMapMode = ");
  624.     switch (m_nMapMode)
  625.     {
  626.     case MM_NONE:
  627.         AFX_DUMP0(dc, "MM_NONE");
  628.         break;
  629.     case MM_SCALETOFIT:
  630.         AFX_DUMP0(dc, "MM_SCALETOFIT");
  631.         break;
  632.     case MM_TEXT:
  633.         AFX_DUMP0(dc, "MM_TEXT");
  634.         break;
  635.     case MM_LOMETRIC:
  636.         AFX_DUMP0(dc, "MM_LOMETRIC");
  637.         break;
  638.     case MM_HIMETRIC:
  639.         AFX_DUMP0(dc, "MM_HIMETRIC");
  640.         break;
  641.     case MM_LOENGLISH:
  642.         AFX_DUMP0(dc, "MM_LOENGLISH");
  643.         break;
  644.     case MM_HIENGLISH:
  645.         AFX_DUMP0(dc, "MM_HIENGLISH");
  646.         break;
  647.     case MM_TWIPS:
  648.         AFX_DUMP0(dc, "MM_TWIPS");
  649.         break;
  650.     default:
  651.         AFX_DUMP0(dc, "*unknown*");
  652.         break;
  653.     }
  654. }
  655.  
  656. void CScrollView::AssertValid() const
  657. {
  658.     CView::AssertValid();
  659.  
  660.     switch (m_nMapMode)
  661.     {
  662.     case MM_NONE:
  663.     case MM_SCALETOFIT:
  664.     case MM_TEXT:
  665.     case MM_LOMETRIC:
  666.     case MM_HIMETRIC:
  667.     case MM_LOENGLISH:
  668.     case MM_HIENGLISH:
  669.     case MM_TWIPS:
  670.         break;
  671.     case MM_ISOTROPIC:
  672.     case MM_ANISOTROPIC:
  673.         ASSERT(FALSE); // illegal mapping mode
  674.     default:
  675.         ASSERT(FALSE); // unknown mapping mode
  676.     }
  677. }
  678. #endif //_DEBUG
  679.  
  680. /////////////////////////////////////////////////////////////////////////////
  681.